OLD | NEW |
---|---|
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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 // Double the buffer capacity to ensure that we have a buffer large | 216 // Double the buffer capacity to ensure that we have a buffer large |
217 // enough to handle the current sample test scenario. | 217 // enough to handle the current sample test scenario. |
218 // buffer_->set_forward_capacity(2 * buffer_->forward_capacity()); | 218 // buffer_->set_forward_capacity(2 * buffer_->forward_capacity()); |
219 // buffer_->Clear(); | 219 // buffer_->Clear(); |
220 // } | 220 // } |
221 } | 221 } |
222 | 222 |
223 void OnError(AudioInputStream* stream) override {} | 223 void OnError(AudioInputStream* stream) override {} |
224 | 224 |
225 // AudioOutputStream::AudioSourceCallback. | 225 // AudioOutputStream::AudioSourceCallback. |
226 int OnMoreData(AudioBus* audio_bus, | 226 int OnMoreData(base::TimeTicks target_playout_time, |
227 uint32_t total_bytes_delay, | 227 int /* prior_frames_skipped */, |
228 uint32_t frames_skipped) override { | 228 AudioBus* dest) override { |
229 base::AutoLock lock(lock_); | 229 base::AutoLock lock(lock_); |
230 | 230 |
231 base::TimeDelta output_delay = target_playout_time - base::TimeTicks::Now(); | |
chcunningham
2016/07/29 01:21:09
Guard against negative?
jameswest
2016/08/26 02:08:47
Done.
| |
232 | |
231 // Update one component in the AudioDelayState for the packet | 233 // Update one component in the AudioDelayState for the packet |
232 // which is about to be played out. | 234 // which is about to be played out. |
233 if (output_elements_to_write_ < kMaxDelayMeasurements) { | 235 if (output_elements_to_write_ < kMaxDelayMeasurements) { |
234 delay_states_[output_elements_to_write_].output_delay_ms = | 236 delay_states_[output_elements_to_write_].output_delay_ms = |
235 BytesToMilliseconds(total_bytes_delay); | 237 output_delay.InMilliseconds(); |
236 ++output_elements_to_write_; | 238 ++output_elements_to_write_; |
237 } | 239 } |
238 | 240 |
239 int size; | 241 int size; |
240 const uint8_t* source; | 242 const uint8_t* source; |
241 // Read the data from the seekable media buffer which contains | 243 // Read the data from the seekable media buffer which contains |
242 // captured data at the same size and sample rate as the output side. | 244 // captured data at the same size and sample rate as the output side. |
243 if (buffer_->GetCurrentChunk(&source, &size) && size > 0) { | 245 if (buffer_->GetCurrentChunk(&source, &size) && size > 0) { |
244 EXPECT_EQ(channels_, audio_bus->channels()); | 246 EXPECT_EQ(channels_, dest->channels()); |
245 size = std::min(audio_bus->frames() * frame_size_, size); | 247 size = std::min(dest->frames() * frame_size_, size); |
246 EXPECT_EQ(static_cast<size_t>(size) % sizeof(*audio_bus->channel(0)), 0U); | 248 EXPECT_EQ(static_cast<size_t>(size) % sizeof(*dest->channel(0)), 0U); |
247 audio_bus->FromInterleaved( | 249 dest->FromInterleaved(source, size / frame_size_, |
248 source, size / frame_size_, frame_size_ / channels_); | 250 frame_size_ / channels_); |
249 buffer_->Seek(size); | 251 buffer_->Seek(size); |
250 return size / frame_size_; | 252 return size / frame_size_; |
251 } | 253 } |
252 | 254 |
253 return 0; | 255 return 0; |
254 } | 256 } |
255 | 257 |
256 void OnError(AudioOutputStream* stream) override {} | 258 void OnError(AudioOutputStream* stream) override {} |
257 | 259 |
258 protected: | 260 protected: |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
439 | 441 |
440 // All Close() operations that run on the mocked audio thread, | 442 // All Close() operations that run on the mocked audio thread, |
441 // should be synchronous and not post additional close tasks to | 443 // should be synchronous and not post additional close tasks to |
442 // mocked the audio thread. Hence, there is no need to call | 444 // mocked the audio thread. Hence, there is no need to call |
443 // message_loop()->RunUntilIdle() after the Close() methods. | 445 // message_loop()->RunUntilIdle() after the Close() methods. |
444 aos->Close(); | 446 aos->Close(); |
445 ais->Close(); | 447 ais->Close(); |
446 } | 448 } |
447 | 449 |
448 } // namespace media | 450 } // namespace media |
OLD | NEW |