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