OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "media/audio/virtual_audio_output_stream.h" |
| 6 |
| 7 #include "base/message_loop.h" |
| 8 #include "media/audio/audio_manager_base.h" |
| 9 #include "media/audio/virtual_audio_input_stream.h" |
| 10 |
| 11 namespace media { |
| 12 |
| 13 // static |
| 14 VirtualAudioOutputStream* VirtualAudioOutputStream::MakeStream( |
| 15 AudioManagerBase* manager, const AudioParameters& params, |
| 16 base::MessageLoopProxy* message_loop, VirtualAudioInputStream* target) { |
| 17 return new VirtualAudioOutputStream(manager, params, message_loop, target); |
| 18 } |
| 19 |
| 20 VirtualAudioOutputStream::VirtualAudioOutputStream( |
| 21 AudioManagerBase* manager, const AudioParameters& params, |
| 22 base::MessageLoopProxy* message_loop, VirtualAudioInputStream* target) |
| 23 : audio_manager_(manager), message_loop_(message_loop), callback_(NULL), |
| 24 params_(params), target_input_stream_(target), volume_(1.0f), |
| 25 attached_(false) { |
| 26 } |
| 27 |
| 28 VirtualAudioOutputStream::~VirtualAudioOutputStream() { |
| 29 DCHECK(!callback_); |
| 30 DCHECK(!attached_); |
| 31 } |
| 32 |
| 33 bool VirtualAudioOutputStream::Open() { |
| 34 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 35 return true; |
| 36 } |
| 37 |
| 38 void VirtualAudioOutputStream::Start(AudioSourceCallback* callback) { |
| 39 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 40 DCHECK(!attached_); |
| 41 callback_ = callback; |
| 42 target_input_stream_->AddOutputStream(this, params_); |
| 43 attached_ = true; |
| 44 } |
| 45 |
| 46 void VirtualAudioOutputStream::Stop() { |
| 47 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 48 DCHECK(attached_); |
| 49 callback_ = NULL; |
| 50 target_input_stream_->RemoveOutputStream(this, params_); |
| 51 attached_ = false; |
| 52 } |
| 53 |
| 54 void VirtualAudioOutputStream::Close() { |
| 55 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 56 audio_manager_->ReleaseOutputStream(this); |
| 57 } |
| 58 |
| 59 void VirtualAudioOutputStream::SetVolume(double volume) { |
| 60 volume_ = volume; |
| 61 } |
| 62 |
| 63 void VirtualAudioOutputStream::GetVolume(double* volume) { |
| 64 *volume = volume_; |
| 65 } |
| 66 |
| 67 double VirtualAudioOutputStream::ProvideInput(AudioBus* audio_bus, |
| 68 base::TimeDelta buffer_delay) { |
| 69 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 70 DCHECK(callback_); |
| 71 |
| 72 int frames = callback_->OnMoreData(audio_bus, AudioBuffersState()); |
| 73 if (frames < audio_bus->frames()) |
| 74 audio_bus->ZeroFramesPartial(frames, audio_bus->frames() - frames); |
| 75 |
| 76 return frames > 0 ? volume_ : 0; |
| 77 } |
| 78 |
| 79 } // namespace media |
OLD | NEW |