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 "media/audio/virtual_audio_output_stream.h" | 5 #include "media/audio/virtual_audio_output_stream.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/time/time.h" |
10 #include "media/audio/virtual_audio_input_stream.h" | 11 #include "media/audio/virtual_audio_input_stream.h" |
11 | 12 |
12 namespace media { | 13 namespace media { |
13 | 14 |
14 VirtualAudioOutputStream::VirtualAudioOutputStream( | 15 VirtualAudioOutputStream::VirtualAudioOutputStream( |
15 const AudioParameters& params, VirtualAudioInputStream* target, | 16 const AudioParameters& params, VirtualAudioInputStream* target, |
16 const AfterCloseCallback& after_close_cb) | 17 const AfterCloseCallback& after_close_cb) |
17 : params_(params), target_input_stream_(target), | 18 : params_(params), target_input_stream_(target), |
18 after_close_cb_(after_close_cb), callback_(NULL), volume_(1.0f) { | 19 after_close_cb_(after_close_cb), callback_(NULL), volume_(1.0f) { |
19 DCHECK(params_.IsValid()); | 20 DCHECK(params_.IsValid()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 DCHECK(thread_checker_.CalledOnValidThread()); | 73 DCHECK(thread_checker_.CalledOnValidThread()); |
73 *volume = volume_; | 74 *volume = volume_; |
74 } | 75 } |
75 | 76 |
76 double VirtualAudioOutputStream::ProvideInput(AudioBus* audio_bus, | 77 double VirtualAudioOutputStream::ProvideInput(AudioBus* audio_bus, |
77 uint32_t frames_delayed) { | 78 uint32_t frames_delayed) { |
78 // Note: This method may be invoked on any one thread, depending on the | 79 // Note: This method may be invoked on any one thread, depending on the |
79 // platform. | 80 // platform. |
80 DCHECK(callback_); | 81 DCHECK(callback_); |
81 | 82 |
82 const uint32_t upstream_delay_in_bytes = | 83 const base::TimeTicks target_playout_time = |
83 params_.GetBytesPerFrame() * frames_delayed; | 84 base::TimeTicks::Now() + |
84 const int frames = | 85 base::TimeDelta::FromMicroseconds(frames_delayed * |
85 callback_->OnMoreData(audio_bus, upstream_delay_in_bytes, 0); | 86 base::Time::kMicrosecondsPerSecond / |
| 87 params_.sample_rate()); |
| 88 const int frames = callback_->OnMoreData(target_playout_time, 0, audio_bus); |
86 if (frames < audio_bus->frames()) | 89 if (frames < audio_bus->frames()) |
87 audio_bus->ZeroFramesPartial(frames, audio_bus->frames() - frames); | 90 audio_bus->ZeroFramesPartial(frames, audio_bus->frames() - frames); |
88 | 91 |
89 return frames > 0 ? volume_ : 0; | 92 return frames > 0 ? volume_ : 0; |
90 } | 93 } |
91 | 94 |
92 } // namespace media | 95 } // namespace media |
OLD | NEW |