Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: talk/app/webrtc/test/fakeaudiocapturemodule_unittest.cc

Issue 1230503003: Update a ton of audio code to use size_t more correctly and in general reduce (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Resync Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « talk/app/webrtc/test/fakeaudiocapturemodule.cc ('k') | talk/media/base/audiorenderer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } 49 }
50 50
51 virtual void SetUp() { 51 virtual void SetUp() {
52 fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); 52 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
53 EXPECT_TRUE(fake_audio_capture_module_.get() != NULL); 53 EXPECT_TRUE(fake_audio_capture_module_.get() != NULL);
54 } 54 }
55 55
56 // Callbacks inherited from webrtc::AudioTransport. 56 // Callbacks inherited from webrtc::AudioTransport.
57 // ADM is pushing data. 57 // ADM is pushing data.
58 int32_t RecordedDataIsAvailable(const void* audioSamples, 58 int32_t RecordedDataIsAvailable(const void* audioSamples,
59 const uint32_t nSamples, 59 const size_t nSamples,
60 const uint8_t nBytesPerSample, 60 const size_t nBytesPerSample,
61 const uint8_t nChannels, 61 const uint8_t nChannels,
62 const uint32_t samplesPerSec, 62 const uint32_t samplesPerSec,
63 const uint32_t totalDelayMS, 63 const uint32_t totalDelayMS,
64 const int32_t clockDrift, 64 const int32_t clockDrift,
65 const uint32_t currentMicLevel, 65 const uint32_t currentMicLevel,
66 const bool keyPressed, 66 const bool keyPressed,
67 uint32_t& newMicLevel) override { 67 uint32_t& newMicLevel) override {
68 rtc::CritScope cs(&crit_); 68 rtc::CritScope cs(&crit_);
69 rec_buffer_bytes_ = nSamples * nBytesPerSample; 69 rec_buffer_bytes_ = nSamples * nBytesPerSample;
70 if ((rec_buffer_bytes_ == 0) || 70 if ((rec_buffer_bytes_ == 0) ||
71 (rec_buffer_bytes_ > FakeAudioCaptureModule::kNumberSamples * 71 (rec_buffer_bytes_ > FakeAudioCaptureModule::kNumberSamples *
72 FakeAudioCaptureModule::kNumberBytesPerSample)) { 72 FakeAudioCaptureModule::kNumberBytesPerSample)) {
73 ADD_FAILURE(); 73 ADD_FAILURE();
74 return -1; 74 return -1;
75 } 75 }
76 memcpy(rec_buffer_, audioSamples, rec_buffer_bytes_); 76 memcpy(rec_buffer_, audioSamples, rec_buffer_bytes_);
77 ++push_iterations_; 77 ++push_iterations_;
78 newMicLevel = currentMicLevel; 78 newMicLevel = currentMicLevel;
79 return 0; 79 return 0;
80 } 80 }
81 81
82 // ADM is pulling data. 82 // ADM is pulling data.
83 int32_t NeedMorePlayData(const uint32_t nSamples, 83 int32_t NeedMorePlayData(const size_t nSamples,
84 const uint8_t nBytesPerSample, 84 const size_t nBytesPerSample,
85 const uint8_t nChannels, 85 const uint8_t nChannels,
86 const uint32_t samplesPerSec, 86 const uint32_t samplesPerSec,
87 void* audioSamples, 87 void* audioSamples,
88 uint32_t& nSamplesOut, 88 size_t& nSamplesOut,
89 int64_t* elapsed_time_ms, 89 int64_t* elapsed_time_ms,
90 int64_t* ntp_time_ms) override { 90 int64_t* ntp_time_ms) override {
91 rtc::CritScope cs(&crit_); 91 rtc::CritScope cs(&crit_);
92 ++pull_iterations_; 92 ++pull_iterations_;
93 const uint32_t audio_buffer_size = nSamples * nBytesPerSample; 93 const size_t audio_buffer_size = nSamples * nBytesPerSample;
94 const uint32_t bytes_out = RecordedDataReceived() ? 94 const size_t bytes_out = RecordedDataReceived() ?
95 CopyFromRecBuffer(audioSamples, audio_buffer_size): 95 CopyFromRecBuffer(audioSamples, audio_buffer_size):
96 GenerateZeroBuffer(audioSamples, audio_buffer_size); 96 GenerateZeroBuffer(audioSamples, audio_buffer_size);
97 nSamplesOut = bytes_out / nBytesPerSample; 97 nSamplesOut = bytes_out / nBytesPerSample;
98 *elapsed_time_ms = 0; 98 *elapsed_time_ms = 0;
99 *ntp_time_ms = 0; 99 *ntp_time_ms = 0;
100 return 0; 100 return 0;
101 } 101 }
102 102
103 int push_iterations() const { 103 int push_iterations() const {
104 rtc::CritScope cs(&crit_); 104 rtc::CritScope cs(&crit_);
105 return push_iterations_; 105 return push_iterations_;
106 } 106 }
107 int pull_iterations() const { 107 int pull_iterations() const {
108 rtc::CritScope cs(&crit_); 108 rtc::CritScope cs(&crit_);
109 return pull_iterations_; 109 return pull_iterations_;
110 } 110 }
111 111
112 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_; 112 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
113 113
114 private: 114 private:
115 bool RecordedDataReceived() const { 115 bool RecordedDataReceived() const {
116 return rec_buffer_bytes_ != 0; 116 return rec_buffer_bytes_ != 0;
117 } 117 }
118 int32_t GenerateZeroBuffer(void* audio_buffer, uint32_t audio_buffer_size) { 118 size_t GenerateZeroBuffer(void* audio_buffer, size_t audio_buffer_size) {
119 memset(audio_buffer, 0, audio_buffer_size); 119 memset(audio_buffer, 0, audio_buffer_size);
120 return audio_buffer_size; 120 return audio_buffer_size;
121 } 121 }
122 int32_t CopyFromRecBuffer(void* audio_buffer, uint32_t audio_buffer_size) { 122 size_t CopyFromRecBuffer(void* audio_buffer, size_t audio_buffer_size) {
123 EXPECT_EQ(audio_buffer_size, rec_buffer_bytes_); 123 EXPECT_EQ(audio_buffer_size, rec_buffer_bytes_);
124 const uint32_t min_buffer_size = min(audio_buffer_size, rec_buffer_bytes_); 124 const size_t min_buffer_size = min(audio_buffer_size, rec_buffer_bytes_);
125 memcpy(audio_buffer, rec_buffer_, min_buffer_size); 125 memcpy(audio_buffer, rec_buffer_, min_buffer_size);
126 return min_buffer_size; 126 return min_buffer_size;
127 } 127 }
128 128
129 mutable rtc::CriticalSection crit_; 129 mutable rtc::CriticalSection crit_;
130 130
131 int push_iterations_; 131 int push_iterations_;
132 int pull_iterations_; 132 int pull_iterations_;
133 133
134 char rec_buffer_[FakeAudioCaptureModule::kNumberSamples * 134 char rec_buffer_[FakeAudioCaptureModule::kNumberSamples *
135 FakeAudioCaptureModule::kNumberBytesPerSample]; 135 FakeAudioCaptureModule::kNumberBytesPerSample];
136 uint32_t rec_buffer_bytes_; 136 size_t rec_buffer_bytes_;
137 }; 137 };
138 138
139 TEST_F(FakeAdmTest, TestProccess) { 139 TEST_F(FakeAdmTest, TestProccess) {
140 // Next process call must be some time in the future (or now). 140 // Next process call must be some time in the future (or now).
141 EXPECT_LE(0, fake_audio_capture_module_->TimeUntilNextProcess()); 141 EXPECT_LE(0, fake_audio_capture_module_->TimeUntilNextProcess());
142 // Process call updates TimeUntilNextProcess() but there are no guarantees on 142 // Process call updates TimeUntilNextProcess() but there are no guarantees on
143 // timing so just check that Process can ba called successfully. 143 // timing so just check that Process can ba called successfully.
144 EXPECT_LE(0, fake_audio_capture_module_->Process()); 144 EXPECT_LE(0, fake_audio_capture_module_->Process());
145 } 145 }
146 146
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 207
208 EXPECT_EQ(0, fake_audio_capture_module_->InitRecording()); 208 EXPECT_EQ(0, fake_audio_capture_module_->InitRecording());
209 EXPECT_EQ(0, fake_audio_capture_module_->StartRecording()); 209 EXPECT_EQ(0, fake_audio_capture_module_->StartRecording());
210 210
211 EXPECT_TRUE_WAIT(push_iterations() > 0, kMsInSecond); 211 EXPECT_TRUE_WAIT(push_iterations() > 0, kMsInSecond);
212 EXPECT_TRUE_WAIT(pull_iterations() > 0, kMsInSecond); 212 EXPECT_TRUE_WAIT(pull_iterations() > 0, kMsInSecond);
213 213
214 EXPECT_EQ(0, fake_audio_capture_module_->StopPlayout()); 214 EXPECT_EQ(0, fake_audio_capture_module_->StopPlayout());
215 EXPECT_EQ(0, fake_audio_capture_module_->StopRecording()); 215 EXPECT_EQ(0, fake_audio_capture_module_->StopRecording());
216 } 216 }
OLDNEW
« no previous file with comments | « talk/app/webrtc/test/fakeaudiocapturemodule.cc ('k') | talk/media/base/audiorenderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698