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

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

Issue 2101303004: Pass delay and timestamp to AudioSourceCallback::OnMoreData. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Changes based on comments Created 4 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
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <algorithm>
8 #include <memory> 9 #include <memory>
9 10
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/environment.h" 12 #include "base/environment.h"
12 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/path_service.h" 15 #include "base/path_service.h"
15 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
16 #include "base/test/test_timeouts.h" 17 #include "base/test/test_timeouts.h"
17 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 // Double the buffer capacity to ensure that we have a buffer large 217 // Double the buffer capacity to ensure that we have a buffer large
217 // enough to handle the current sample test scenario. 218 // enough to handle the current sample test scenario.
218 // buffer_->set_forward_capacity(2 * buffer_->forward_capacity()); 219 // buffer_->set_forward_capacity(2 * buffer_->forward_capacity());
219 // buffer_->Clear(); 220 // buffer_->Clear();
220 // } 221 // }
221 } 222 }
222 223
223 void OnError(AudioInputStream* stream) override {} 224 void OnError(AudioInputStream* stream) override {}
224 225
225 // AudioOutputStream::AudioSourceCallback. 226 // AudioOutputStream::AudioSourceCallback.
226 int OnMoreData(AudioBus* audio_bus, 227 int OnMoreData(base::TimeTicks target_playout_time,
227 uint32_t total_bytes_delay, 228 int /* prior_frames_skipped */,
228 uint32_t frames_skipped) override { 229 AudioBus* dest) override {
229 base::AutoLock lock(lock_); 230 base::AutoLock lock(lock_);
230 231
232 base::TimeDelta output_delay = std::max(
233 target_playout_time - base::TimeTicks::Now(), base::TimeDelta());
234
231 // Update one component in the AudioDelayState for the packet 235 // Update one component in the AudioDelayState for the packet
232 // which is about to be played out. 236 // which is about to be played out.
233 if (output_elements_to_write_ < kMaxDelayMeasurements) { 237 if (output_elements_to_write_ < kMaxDelayMeasurements) {
234 delay_states_[output_elements_to_write_].output_delay_ms = 238 delay_states_[output_elements_to_write_].output_delay_ms =
235 BytesToMilliseconds(total_bytes_delay); 239 output_delay.InMilliseconds();
236 ++output_elements_to_write_; 240 ++output_elements_to_write_;
237 } 241 }
238 242
239 int size; 243 int size;
240 const uint8_t* source; 244 const uint8_t* source;
241 // Read the data from the seekable media buffer which contains 245 // Read the data from the seekable media buffer which contains
242 // captured data at the same size and sample rate as the output side. 246 // captured data at the same size and sample rate as the output side.
243 if (buffer_->GetCurrentChunk(&source, &size) && size > 0) { 247 if (buffer_->GetCurrentChunk(&source, &size) && size > 0) {
244 EXPECT_EQ(channels_, audio_bus->channels()); 248 EXPECT_EQ(channels_, dest->channels());
245 size = std::min(audio_bus->frames() * frame_size_, size); 249 size = std::min(dest->frames() * frame_size_, size);
246 EXPECT_EQ(static_cast<size_t>(size) % sizeof(*audio_bus->channel(0)), 0U); 250 EXPECT_EQ(static_cast<size_t>(size) % sizeof(*dest->channel(0)), 0U);
247 audio_bus->FromInterleaved( 251 dest->FromInterleaved(source, size / frame_size_,
248 source, size / frame_size_, frame_size_ / channels_); 252 frame_size_ / channels_);
249 buffer_->Seek(size); 253 buffer_->Seek(size);
250 return size / frame_size_; 254 return size / frame_size_;
251 } 255 }
252 256
253 return 0; 257 return 0;
254 } 258 }
255 259
256 void OnError(AudioOutputStream* stream) override {} 260 void OnError(AudioOutputStream* stream) override {}
257 261
258 protected: 262 protected:
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 443
440 // All Close() operations that run on the mocked audio thread, 444 // All Close() operations that run on the mocked audio thread,
441 // should be synchronous and not post additional close tasks to 445 // should be synchronous and not post additional close tasks to
442 // mocked the audio thread. Hence, there is no need to call 446 // mocked the audio thread. Hence, there is no need to call
443 // message_loop()->RunUntilIdle() after the Close() methods. 447 // message_loop()->RunUntilIdle() after the Close() methods.
444 aos->Close(); 448 aos->Close();
445 ais->Close(); 449 ais->Close();
446 } 450 }
447 451
448 } // namespace media 452 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698