| 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 "media/audio/virtual_audio_input_stream.h" | 10 #include "media/audio/virtual_audio_input_stream.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 buffer_delay / | 84 buffer_delay / |
| 85 base::TimeDelta::FromSeconds(1); | 85 base::TimeDelta::FromSeconds(1); |
| 86 const int frames = callback_->OnMoreData( | 86 const int frames = callback_->OnMoreData( |
| 87 audio_bus, static_cast<uint32_t>(upstream_delay_in_bytes), 0); | 87 audio_bus, static_cast<uint32_t>(upstream_delay_in_bytes), 0); |
| 88 if (frames < audio_bus->frames()) | 88 if (frames < audio_bus->frames()) |
| 89 audio_bus->ZeroFramesPartial(frames, audio_bus->frames() - frames); | 89 audio_bus->ZeroFramesPartial(frames, audio_bus->frames() - frames); |
| 90 | 90 |
| 91 return frames > 0 ? volume_ : 0; | 91 return frames > 0 ? volume_ : 0; |
| 92 } | 92 } |
| 93 | 93 |
| 94 static const base::TimeDelta kBufferSize = base::TimeDelta::FromSeconds(1); |
| 95 static const base::TimeDelta kClockAccuracy = |
| 96 base::TimeDelta::FromMilliseconds(1); |
| 97 static const base::TimeDelta kAdjustTime = base::TimeDelta::FromSeconds(1); |
| 98 |
| 99 LoopbackSink::LoopbackSink(AudioParameters param, |
| 100 VirtualAudioInputStream* target, |
| 101 AfterCloseCallback callback) |
| 102 : started_(false), |
| 103 params_(param), |
| 104 target_(target), |
| 105 shifter_(new AudioShifter(kBufferSize, |
| 106 kClockAccuracy, |
| 107 kAdjustTime, |
| 108 param.sample_rate(), |
| 109 param.channels())), |
| 110 after_close_callback_(callback) {} |
| 111 |
| 112 LoopbackSink::~LoopbackSink() {} |
| 113 |
| 114 void LoopbackSink::Start() { |
| 115 started_ = true; |
| 116 target_->AddOutputStream(this, params_); |
| 117 } |
| 118 |
| 119 void LoopbackSink::Stop() { |
| 120 target_->RemoveOutputStream(this, params_); |
| 121 started_ = false; |
| 122 } |
| 123 |
| 124 void LoopbackSink::Close() { |
| 125 if (started_) |
| 126 Stop(); |
| 127 AfterCloseCallback cb = after_close_callback_; |
| 128 if (!cb.is_null()) |
| 129 cb.Run(this); |
| 130 } |
| 131 |
| 132 void LoopbackSink::OnData(AudioInputStream* stream, |
| 133 const AudioBus* source, |
| 134 uint32_t hardware_delay_bytes, |
| 135 double volume) { |
| 136 printf("Sink: Input Data\n"); |
| 137 std::unique_ptr<AudioBus> source_copy = AudioBus::Create(params_); |
| 138 source->CopyTo(source_copy.get()); |
| 139 shifter_->Push(std::move(source_copy), base::TimeTicks::Now()); |
| 140 } |
| 141 |
| 142 void LoopbackSink::OnError(AudioInputStream* stream) {} |
| 143 |
| 144 double LoopbackSink::ProvideInput(AudioBus* audio_bus, |
| 145 base::TimeDelta buffer_delay) { |
| 146 printf("Sink: Output Data Start\n"); |
| 147 shifter_->Pull(audio_bus, base::TimeTicks::Now()); |
| 148 printf("Sink: Output Data Finish\n"); |
| 149 return 1; |
| 150 } |
| 151 |
| 94 } // namespace media | 152 } // namespace media |
| OLD | NEW |