Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
|
miu
2016/05/02 20:06:14
No "(c)" in copyright headers anymore.
qiangchen
2016/05/03 16:58:23
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/audio/virtual_audio_sink.h" | |
| 6 | |
| 7 #include "base/callback_helpers.h" | |
| 8 #include "media/audio/virtual_audio_input_stream.h" | |
| 9 | |
| 10 namespace media { | |
| 11 | |
| 12 static const base::TimeDelta kBufferSize = base::TimeDelta::FromSeconds(1); | |
|
miu
2016/05/02 20:06:14
1. How were these values chosen? Please document
qiangchen
2016/05/03 16:58:23
Done.
| |
| 13 static const base::TimeDelta kClockAccuracy = | |
| 14 base::TimeDelta::FromMilliseconds(1); | |
| 15 static const base::TimeDelta kAdjustTime = base::TimeDelta::FromSeconds(1); | |
| 16 | |
| 17 VirtualAudioSink::VirtualAudioSink(AudioParameters param, | |
| 18 VirtualAudioInputStream* target, | |
| 19 AfterCloseCallback callback) | |
| 20 : params_(param), | |
| 21 target_(target), | |
| 22 shifter_(kBufferSize, | |
| 23 kClockAccuracy, | |
| 24 kAdjustTime, | |
| 25 param.sample_rate(), | |
| 26 param.channels()), | |
| 27 after_close_callback_(callback) { | |
| 28 target_->AddInputProvider(this, params_); | |
| 29 } | |
| 30 | |
| 31 VirtualAudioSink::~VirtualAudioSink() {} | |
| 32 | |
| 33 void VirtualAudioSink::Close() { | |
| 34 target_->RemoveInputProvider(this, params_); | |
| 35 AfterCloseCallback cb = base::ResetAndReturn(&after_close_callback_); | |
|
miu
2016/05/02 20:06:13
You're making another copy of the callback here. P
qiangchen
2016/05/03 16:58:23
Done.
| |
| 36 if (!cb.is_null()) | |
| 37 cb.Run(this); | |
| 38 } | |
| 39 | |
| 40 void VirtualAudioSink::OnData(const AudioBus& source, | |
| 41 base::TimeTicks reference_time) { | |
| 42 std::unique_ptr<AudioBus> source_copy = AudioBus::Create(params_); | |
| 43 source.CopyTo(source_copy.get()); | |
| 44 shifter_.Push(std::move(source_copy), reference_time); | |
| 45 } | |
| 46 | |
| 47 double VirtualAudioSink::ProvideInput(AudioBus* audio_bus, | |
| 48 base::TimeDelta buffer_delay) { | |
| 49 shifter_.Pull(audio_bus, base::TimeTicks::Now() + buffer_delay); | |
| 50 return 1; | |
| 51 } | |
| 52 } | |
| OLD | NEW |