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

Side by Side Diff: media/audio/audio_low_latency_input_output_unittest.cc

Issue 344583002: Modifies AudioInputCallback::OnData and use media::AudioBus instead of plain byte vector (Relanding) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added extra non-pure OnData API Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « media/audio/audio_io.h ('k') | media/audio/cras/cras_input.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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/environment.h" 6 #include "base/environment.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 state.input_delay_ms, 177 state.input_delay_ms,
178 state.output_delay_ms); 178 state.output_delay_ms);
179 ++elements_written; 179 ++elements_written;
180 } 180 }
181 181
182 base::CloseFile(text_file); 182 base::CloseFile(text_file);
183 } 183 }
184 184
185 // AudioInputStream::AudioInputCallback. 185 // AudioInputStream::AudioInputCallback.
186 virtual void OnData(AudioInputStream* stream, 186 virtual void OnData(AudioInputStream* stream,
187 const uint8* src, uint32 size, 187 const AudioBus* src,
188 uint32 hardware_delay_bytes, 188 uint32 hardware_delay_bytes,
189 double volume) OVERRIDE { 189 double volume) OVERRIDE {
190 base::AutoLock lock(lock_); 190 base::AutoLock lock(lock_);
191 191
192 // Update three components in the AudioDelayState for this recorded 192 // Update three components in the AudioDelayState for this recorded
193 // audio packet. 193 // audio packet.
194 const base::TimeTicks now_time = base::TimeTicks::Now(); 194 const base::TimeTicks now_time = base::TimeTicks::Now();
195 const int diff = (now_time - previous_write_time_).InMilliseconds(); 195 const int diff = (now_time - previous_write_time_).InMilliseconds();
196 previous_write_time_ = now_time; 196 previous_write_time_ = now_time;
197 if (input_elements_to_write_ < kMaxDelayMeasurements) { 197 if (input_elements_to_write_ < kMaxDelayMeasurements) {
198 delay_states_[input_elements_to_write_].delta_time_ms = diff; 198 delay_states_[input_elements_to_write_].delta_time_ms = diff;
199 delay_states_[input_elements_to_write_].buffer_delay_ms = 199 delay_states_[input_elements_to_write_].buffer_delay_ms =
200 BytesToMilliseconds(buffer_->forward_bytes()); 200 BytesToMilliseconds(buffer_->forward_bytes());
201 delay_states_[input_elements_to_write_].input_delay_ms = 201 delay_states_[input_elements_to_write_].input_delay_ms =
202 BytesToMilliseconds(hardware_delay_bytes); 202 BytesToMilliseconds(hardware_delay_bytes);
203 ++input_elements_to_write_; 203 ++input_elements_to_write_;
204 } 204 }
205 205
206 // TODO(henrika): fix this and use AudioFifo instead.
206 // Store the captured audio packet in a seekable media buffer. 207 // Store the captured audio packet in a seekable media buffer.
207 if (!buffer_->Append(src, size)) { 208 // if (!buffer_->Append(src, size)) {
208 // An attempt to write outside the buffer limits has been made. 209 // An attempt to write outside the buffer limits has been made.
209 // Double the buffer capacity to ensure that we have a buffer large 210 // Double the buffer capacity to ensure that we have a buffer large
210 // enough to handle the current sample test scenario. 211 // enough to handle the current sample test scenario.
211 buffer_->set_forward_capacity(2 * buffer_->forward_capacity()); 212 // buffer_->set_forward_capacity(2 * buffer_->forward_capacity());
212 buffer_->Clear(); 213 // buffer_->Clear();
213 } 214 // }
214 } 215 }
215 216
216 virtual void OnError(AudioInputStream* stream) OVERRIDE {} 217 virtual void OnError(AudioInputStream* stream) OVERRIDE {}
217 218
218 // AudioOutputStream::AudioSourceCallback. 219 // AudioOutputStream::AudioSourceCallback.
219 virtual int OnMoreData(AudioBus* audio_bus, 220 virtual int OnMoreData(AudioBus* audio_bus,
220 AudioBuffersState buffers_state) OVERRIDE { 221 AudioBuffersState buffers_state) OVERRIDE {
221 base::AutoLock lock(lock_); 222 base::AutoLock lock(lock_);
222 223
223 // Update one component in the AudioDelayState for the packet 224 // Update one component in the AudioDelayState for the packet
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 438
438 // All Close() operations that run on the mocked audio thread, 439 // All Close() operations that run on the mocked audio thread,
439 // should be synchronous and not post additional close tasks to 440 // should be synchronous and not post additional close tasks to
440 // mocked the audio thread. Hence, there is no need to call 441 // mocked the audio thread. Hence, there is no need to call
441 // message_loop()->RunUntilIdle() after the Close() methods. 442 // message_loop()->RunUntilIdle() after the Close() methods.
442 aos->Close(); 443 aos->Close();
443 ais->Close(); 444 ais->Close();
444 } 445 }
445 446
446 } // namespace media 447 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_io.h ('k') | media/audio/cras/cras_input.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698