| 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_input_stream.h" | 5 #include "media/audio/virtual_audio_input_stream.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/message_loop/message_loop_proxy.h" | |
| 13 #include "media/audio/virtual_audio_output_stream.h" | 12 #include "media/audio/virtual_audio_output_stream.h" |
| 14 | 13 |
| 15 namespace media { | 14 namespace media { |
| 16 | 15 |
| 17 // LoopbackAudioConverter works similar to AudioConverter and converts input | 16 // LoopbackAudioConverter works similar to AudioConverter and converts input |
| 18 // streams to different audio parameters. Then, the LoopbackAudioConverter can | 17 // streams to different audio parameters. Then, the LoopbackAudioConverter can |
| 19 // be used as an input to another AudioConverter. This allows us to | 18 // be used as an input to another AudioConverter. This allows us to |
| 20 // use converted audio from AudioOutputStreams as input to an AudioConverter. | 19 // use converted audio from AudioOutputStreams as input to an AudioConverter. |
| 21 // For example, this allows converting multiple streams into a common format and | 20 // For example, this allows converting multiple streams into a common format and |
| 22 // using the converted audio as input to another AudioConverter (i.e. a mixer). | 21 // using the converted audio as input to another AudioConverter (i.e. a mixer). |
| (...skipping 20 matching lines...) Expand all Loading... |
| 43 return 1.0; | 42 return 1.0; |
| 44 } | 43 } |
| 45 | 44 |
| 46 AudioConverter audio_converter_; | 45 AudioConverter audio_converter_; |
| 47 | 46 |
| 48 DISALLOW_COPY_AND_ASSIGN(LoopbackAudioConverter); | 47 DISALLOW_COPY_AND_ASSIGN(LoopbackAudioConverter); |
| 49 }; | 48 }; |
| 50 | 49 |
| 51 VirtualAudioInputStream::VirtualAudioInputStream( | 50 VirtualAudioInputStream::VirtualAudioInputStream( |
| 52 const AudioParameters& params, | 51 const AudioParameters& params, |
| 53 const scoped_refptr<base::MessageLoopProxy>& worker_loop, | 52 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner, |
| 54 const AfterCloseCallback& after_close_cb) | 53 const AfterCloseCallback& after_close_cb) |
| 55 : worker_loop_(worker_loop), | 54 : worker_task_runner_(worker_task_runner), |
| 56 after_close_cb_(after_close_cb), | 55 after_close_cb_(after_close_cb), |
| 57 callback_(NULL), | 56 callback_(NULL), |
| 58 buffer_(new uint8[params.GetBytesPerBuffer()]), | 57 buffer_(new uint8[params.GetBytesPerBuffer()]), |
| 59 params_(params), | 58 params_(params), |
| 60 mixer_(params_, params_, false), | 59 mixer_(params_, params_, false), |
| 61 num_attached_output_streams_(0), | 60 num_attached_output_streams_(0), |
| 62 fake_consumer_(worker_loop_, params_) { | 61 fake_consumer_(worker_task_runner_, params_) { |
| 63 DCHECK(params_.IsValid()); | 62 DCHECK(params_.IsValid()); |
| 64 DCHECK(worker_loop_.get()); | 63 DCHECK(worker_task_runner_.get()); |
| 65 | 64 |
| 66 // VAIS can be constructed on any thread, but will DCHECK that all | 65 // VAIS can be constructed on any thread, but will DCHECK that all |
| 67 // AudioInputStream methods are called from the same thread. | 66 // AudioInputStream methods are called from the same thread. |
| 68 thread_checker_.DetachFromThread(); | 67 thread_checker_.DetachFromThread(); |
| 69 } | 68 } |
| 70 | 69 |
| 71 VirtualAudioInputStream::~VirtualAudioInputStream() { | 70 VirtualAudioInputStream::~VirtualAudioInputStream() { |
| 72 DCHECK(!callback_); | 71 DCHECK(!callback_); |
| 73 | 72 |
| 74 // Sanity-check: Contract for Add/RemoveOutputStream() requires that all | 73 // Sanity-check: Contract for Add/RemoveOutputStream() requires that all |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 base::AutoLock scoped_lock(converter_network_lock_); | 125 base::AutoLock scoped_lock(converter_network_lock_); |
| 127 | 126 |
| 128 DCHECK(converters_.find(output_params) != converters_.end()); | 127 DCHECK(converters_.find(output_params) != converters_.end()); |
| 129 converters_[output_params]->RemoveInput(stream); | 128 converters_[output_params]->RemoveInput(stream); |
| 130 | 129 |
| 131 --num_attached_output_streams_; | 130 --num_attached_output_streams_; |
| 132 DCHECK_LE(0, num_attached_output_streams_); | 131 DCHECK_LE(0, num_attached_output_streams_); |
| 133 } | 132 } |
| 134 | 133 |
| 135 void VirtualAudioInputStream::PumpAudio(AudioBus* audio_bus) { | 134 void VirtualAudioInputStream::PumpAudio(AudioBus* audio_bus) { |
| 136 DCHECK(worker_loop_->BelongsToCurrentThread()); | 135 DCHECK(worker_task_runner_->BelongsToCurrentThread()); |
| 137 DCHECK(callback_); | 136 DCHECK(callback_); |
| 138 | 137 |
| 139 { | 138 { |
| 140 base::AutoLock scoped_lock(converter_network_lock_); | 139 base::AutoLock scoped_lock(converter_network_lock_); |
| 141 mixer_.Convert(audio_bus); | 140 mixer_.Convert(audio_bus); |
| 142 } | 141 } |
| 143 audio_bus->ToInterleaved(params_.frames_per_buffer(), | 142 audio_bus->ToInterleaved(params_.frames_per_buffer(), |
| 144 params_.bits_per_sample() / 8, | 143 params_.bits_per_sample() / 8, |
| 145 buffer_.get()); | 144 buffer_.get()); |
| 146 callback_->OnData(this, | 145 callback_->OnData(this, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 return 1.0; | 178 return 1.0; |
| 180 } | 179 } |
| 181 | 180 |
| 182 void VirtualAudioInputStream::SetAutomaticGainControl(bool enabled) {} | 181 void VirtualAudioInputStream::SetAutomaticGainControl(bool enabled) {} |
| 183 | 182 |
| 184 bool VirtualAudioInputStream::GetAutomaticGainControl() { | 183 bool VirtualAudioInputStream::GetAutomaticGainControl() { |
| 185 return false; | 184 return false; |
| 186 } | 185 } |
| 187 | 186 |
| 188 } // namespace media | 187 } // namespace media |
| OLD | NEW |