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