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 |
| 10 namespace media { |
| 11 |
| 12 // static |
| 13 VirtualAudioOutputStream* VirtualAudioOutputStream::MakeStream( |
| 14 AudioManagerBase* manager, const AudioParameters& params) { |
| 15 return new VirtualAudioOutputStream(manager, params); |
| 16 } |
| 17 |
| 18 VirtualAudioOutputStream::VirtualAudioOutputStream( |
| 19 AudioManagerBase* manager, const AudioParameters& params) |
| 20 : audio_manager_(manager), |
| 21 callback_(NULL), |
| 22 volume_(1.0f) { |
| 23 } |
| 24 |
| 25 VirtualAudioOutputStream::~VirtualAudioOutputStream() { |
| 26 DCHECK(!callback_); |
| 27 } |
| 28 |
| 29 bool VirtualAudioOutputStream::Open() { |
| 30 DCHECK(audio_manager_->GetMessageLoop()->BelongsToCurrentThread()); |
| 31 return true; |
| 32 } |
| 33 |
| 34 void VirtualAudioOutputStream::Start(AudioSourceCallback* callback) { |
| 35 DCHECK(audio_manager_->GetMessageLoop()->BelongsToCurrentThread()); |
| 36 callback_ = callback; |
| 37 } |
| 38 |
| 39 void VirtualAudioOutputStream::Stop() { |
| 40 DCHECK(audio_manager_->GetMessageLoop()->BelongsToCurrentThread()); |
| 41 callback_ = NULL; |
| 42 } |
| 43 |
| 44 void VirtualAudioOutputStream::Close() { |
| 45 DCHECK(!callback_); |
| 46 DCHECK(audio_manager_->GetMessageLoop()->BelongsToCurrentThread()); |
| 47 audio_manager_->ReleaseVirtualOutputStream(this); |
| 48 } |
| 49 |
| 50 void VirtualAudioOutputStream::SetVolume(double volume) { |
| 51 volume_ = static_cast<float>(volume); |
| 52 } |
| 53 |
| 54 void VirtualAudioOutputStream::GetVolume(double* volume) { |
| 55 *volume = volume_; |
| 56 } |
| 57 |
| 58 double VirtualAudioOutputStream::ProvideInput( |
| 59 AudioBus* audio_bus, base::TimeDelta buffer_delay) { |
| 60 DCHECK(audio_manager_->GetMessageLoop()->BelongsToCurrentThread()); |
| 61 if (!callback_) |
| 62 return 0; |
| 63 |
| 64 int frames = callback_->OnMoreData(audio_bus, AudioBuffersState()); |
| 65 if (frames < audio_bus->frames()) |
| 66 audio_bus->ZeroFramesPartial(frames, audio_bus->frames() - frames); |
| 67 |
| 68 return frames > 0 ? 1 : 0; |
| 69 } |
| 70 |
| 71 } // namespace media |
OLD | NEW |