This source file includes following definitions.
- volume_
- Open
- Start
- Stop
- Close
- SetVolume
- GetVolume
- ProvideInput
#include "media/audio/virtual_audio_output_stream.h"
#include "base/logging.h"
#include "media/audio/virtual_audio_input_stream.h"
namespace media {
VirtualAudioOutputStream::VirtualAudioOutputStream(
const AudioParameters& params, VirtualAudioInputStream* target,
const AfterCloseCallback& after_close_cb)
: params_(params), target_input_stream_(target),
after_close_cb_(after_close_cb), callback_(NULL), volume_(1.0f) {
DCHECK(params_.IsValid());
DCHECK(target);
thread_checker_.DetachFromThread();
}
VirtualAudioOutputStream::~VirtualAudioOutputStream() {
DCHECK(!callback_);
}
bool VirtualAudioOutputStream::Open() {
DCHECK(thread_checker_.CalledOnValidThread());
return true;
}
void VirtualAudioOutputStream::Start(AudioSourceCallback* callback) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!callback_);
callback_ = callback;
target_input_stream_->AddOutputStream(this, params_);
}
void VirtualAudioOutputStream::Stop() {
DCHECK(thread_checker_.CalledOnValidThread());
if (callback_) {
target_input_stream_->RemoveOutputStream(this, params_);
callback_ = NULL;
}
}
void VirtualAudioOutputStream::Close() {
DCHECK(thread_checker_.CalledOnValidThread());
Stop();
if (!after_close_cb_.is_null()) {
const AfterCloseCallback cb = after_close_cb_;
after_close_cb_.Reset();
cb.Run(this);
}
}
void VirtualAudioOutputStream::SetVolume(double volume) {
DCHECK(thread_checker_.CalledOnValidThread());
volume_ = volume;
}
void VirtualAudioOutputStream::GetVolume(double* volume) {
DCHECK(thread_checker_.CalledOnValidThread());
*volume = volume_;
}
double VirtualAudioOutputStream::ProvideInput(AudioBus* audio_bus,
base::TimeDelta buffer_delay) {
DCHECK(callback_);
const int frames = callback_->OnMoreData(audio_bus, AudioBuffersState());
if (frames < audio_bus->frames())
audio_bus->ZeroFramesPartial(frames, audio_bus->frames() - frames);
return frames > 0 ? volume_ : 0;
}
}