| Index: media/audio/mac/audio_auhal_mac.cc
|
| diff --git a/media/audio/mac/audio_auhal_mac.cc b/media/audio/mac/audio_auhal_mac.cc
|
| index 0e13ab56ba08a33da1cc4fad0e6006982597fff2..41fc57c553f8d0ba8a4b0a48000cedb10c01b49a 100644
|
| --- a/media/audio/mac/audio_auhal_mac.cc
|
| +++ b/media/audio/mac/audio_auhal_mac.cc
|
| @@ -18,14 +18,6 @@
|
|
|
| namespace media {
|
|
|
| -static void ZeroBufferList(AudioBufferList* buffer_list) {
|
| - for (size_t i = 0; i < buffer_list->mNumberBuffers; ++i) {
|
| - memset(buffer_list->mBuffers[i].mData,
|
| - 0,
|
| - buffer_list->mBuffers[i].mDataByteSize);
|
| - }
|
| -}
|
| -
|
| static void WrapBufferList(AudioBufferList* buffer_list,
|
| AudioBus* bus,
|
| int frames) {
|
| @@ -51,7 +43,6 @@ AUHALStream::AUHALStream(
|
| AudioDeviceID device)
|
| : manager_(manager),
|
| params_(params),
|
| - input_channels_(params_.input_channels()),
|
| output_channels_(params_.channels()),
|
| number_of_frames_(params_.frames_per_buffer()),
|
| source_(NULL),
|
| @@ -60,14 +51,12 @@ AUHALStream::AUHALStream(
|
| volume_(1),
|
| hardware_latency_frames_(0),
|
| stopped_(false),
|
| - input_buffer_list_(NULL),
|
| current_hardware_pending_bytes_(0) {
|
| // We must have a manager.
|
| DCHECK(manager_);
|
|
|
| VLOG(1) << "AUHALStream::AUHALStream()";
|
| VLOG(1) << "Device: " << device;
|
| - VLOG(1) << "Input channels: " << input_channels_;
|
| VLOG(1) << "Output channels: " << output_channels_;
|
| VLOG(1) << "Sample rate: " << params_.sample_rate();
|
| VLOG(1) << "Buffer size: " << number_of_frames_;
|
| @@ -77,27 +66,15 @@ AUHALStream::~AUHALStream() {
|
| }
|
|
|
| bool AUHALStream::Open() {
|
| - // Get the total number of input and output channels that the
|
| + // Get the total number of output channels that the
|
| // hardware supports.
|
| - int device_input_channels;
|
| - bool got_input_channels = AudioManagerMac::GetDeviceChannels(
|
| - device_,
|
| - kAudioDevicePropertyScopeInput,
|
| - &device_input_channels);
|
| -
|
| int device_output_channels;
|
| bool got_output_channels = AudioManagerMac::GetDeviceChannels(
|
| device_,
|
| kAudioDevicePropertyScopeOutput,
|
| &device_output_channels);
|
|
|
| - // Sanity check the requested I/O channels.
|
| - if (!got_input_channels ||
|
| - input_channels_ < 0 || input_channels_ > device_input_channels) {
|
| - LOG(ERROR) << "AudioDevice does not support requested input channels.";
|
| - return false;
|
| - }
|
| -
|
| + // Sanity check the requested output channels.
|
| if (!got_output_channels ||
|
| output_channels_ <= 0 || output_channels_ > device_output_channels) {
|
| LOG(ERROR) << "AudioDevice does not support requested output channels.";
|
| @@ -113,7 +90,10 @@ bool AUHALStream::Open() {
|
| return false;
|
| }
|
|
|
| - CreateIOBusses();
|
| + // The output bus will wrap the AudioBufferList given to us in
|
| + // the Render() callback.
|
| + DCHECK_GT(output_channels_, 0);
|
| + output_bus_ = AudioBus::CreateWrapper(output_channels_);
|
|
|
| bool configured = ConfigureAUHAL();
|
| if (configured)
|
| @@ -123,13 +103,6 @@ bool AUHALStream::Open() {
|
| }
|
|
|
| void AUHALStream::Close() {
|
| - if (input_buffer_list_) {
|
| - input_buffer_list_storage_.reset();
|
| - input_buffer_list_ = NULL;
|
| - input_bus_.reset(NULL);
|
| - output_bus_.reset(NULL);
|
| - }
|
| -
|
| if (audio_unit_) {
|
| OSStatus result = AudioUnitUninitialize(audio_unit_);
|
| OSSTATUS_DLOG_IF(ERROR, result != noErr, result)
|
| @@ -212,7 +185,7 @@ OSStatus AUHALStream::Render(
|
| const AudioTimeStamp* output_time_stamp,
|
| UInt32 bus_number,
|
| UInt32 number_of_frames,
|
| - AudioBufferList* io_data) {
|
| + AudioBufferList* data) {
|
| TRACE_EVENT0("audio", "AUHALStream::Render");
|
|
|
| // If the stream parameters change for any reason, we need to insert a FIFO
|
| @@ -227,27 +200,10 @@ OSStatus AUHALStream::Render(
|
| number_of_frames_,
|
| base::Bind(&AUHALStream::ProvideInput, base::Unretained(this))));
|
| }
|
| -
|
| - // Synchronous IO is not supported in this state.
|
| - if (input_channels_ > 0)
|
| - input_bus_->Zero();
|
| - } else {
|
| - if (input_channels_ > 0 && input_buffer_list_) {
|
| - // Get the input data. |input_buffer_list_| is wrapped
|
| - // to point to the data allocated in |input_bus_|.
|
| - OSStatus result = AudioUnitRender(audio_unit_,
|
| - flags,
|
| - output_time_stamp,
|
| - 1,
|
| - number_of_frames,
|
| - input_buffer_list_);
|
| - if (result != noErr)
|
| - ZeroBufferList(input_buffer_list_);
|
| - }
|
| }
|
|
|
| // Make |output_bus_| wrap the output AudioBufferList.
|
| - WrapBufferList(io_data, output_bus_.get(), number_of_frames);
|
| + WrapBufferList(data, output_bus_.get(), number_of_frames);
|
|
|
| // Update the playout latency.
|
| const double playout_latency_frames = GetPlayoutLatency(output_time_stamp);
|
| @@ -270,8 +226,7 @@ void AUHALStream::ProvideInput(int frame_delay, AudioBus* dest) {
|
| }
|
|
|
| // Supply the input data and render the output data.
|
| - source_->OnMoreIOData(
|
| - input_bus_.get(),
|
| + source_->OnMoreData(
|
| dest,
|
| AudioBuffersState(0,
|
| current_hardware_pending_bytes_ +
|
| @@ -370,52 +325,6 @@ double AUHALStream::GetPlayoutLatency(
|
| return (delay_frames + hardware_latency_frames_);
|
| }
|
|
|
| -void AUHALStream::CreateIOBusses() {
|
| - if (input_channels_ > 0) {
|
| - // Allocate storage for the AudioBufferList used for the
|
| - // input data from the input AudioUnit.
|
| - // We allocate enough space for with one AudioBuffer per channel.
|
| - size_t buffer_list_size = offsetof(AudioBufferList, mBuffers[0]) +
|
| - (sizeof(AudioBuffer) * input_channels_);
|
| - input_buffer_list_storage_.reset(new uint8[buffer_list_size]);
|
| -
|
| - input_buffer_list_ =
|
| - reinterpret_cast<AudioBufferList*>(input_buffer_list_storage_.get());
|
| - input_buffer_list_->mNumberBuffers = input_channels_;
|
| -
|
| - // |input_bus_| allocates the storage for the PCM input data.
|
| - input_bus_ = AudioBus::Create(input_channels_, number_of_frames_);
|
| -
|
| - // Make the AudioBufferList point to the memory in |input_bus_|.
|
| - UInt32 buffer_size_bytes = input_bus_->frames() * sizeof(Float32);
|
| - for (size_t i = 0; i < input_buffer_list_->mNumberBuffers; ++i) {
|
| - input_buffer_list_->mBuffers[i].mNumberChannels = 1;
|
| - input_buffer_list_->mBuffers[i].mDataByteSize = buffer_size_bytes;
|
| - input_buffer_list_->mBuffers[i].mData = input_bus_->channel(i);
|
| - }
|
| - }
|
| -
|
| - // The output bus will wrap the AudioBufferList given to us in
|
| - // the Render() callback.
|
| - DCHECK_GT(output_channels_, 0);
|
| - output_bus_ = AudioBus::CreateWrapper(output_channels_);
|
| -}
|
| -
|
| -bool AUHALStream::EnableIO(bool enable, UInt32 scope) {
|
| - // See Apple technote for details about the EnableIO property.
|
| - // Note that we use bus 1 for input and bus 0 for output:
|
| - // http://developer.apple.com/library/mac/#technotes/tn2091/_index.html
|
| - UInt32 enable_IO = enable ? 1 : 0;
|
| - OSStatus result = AudioUnitSetProperty(
|
| - audio_unit_,
|
| - kAudioOutputUnitProperty_EnableIO,
|
| - scope,
|
| - (scope == kAudioUnitScope_Input) ? 1 : 0,
|
| - &enable_IO,
|
| - sizeof(enable_IO));
|
| - return (result == noErr);
|
| -}
|
| -
|
| bool AUHALStream::SetStreamFormat(
|
| AudioStreamBasicDescription* desc,
|
| int channels,
|
| @@ -446,8 +355,7 @@ bool AUHALStream::SetStreamFormat(
|
| }
|
|
|
| bool AUHALStream::ConfigureAUHAL() {
|
| - if (device_ == kAudioObjectUnknown ||
|
| - (input_channels_ == 0 && output_channels_ == 0))
|
| + if (device_ == kAudioObjectUnknown || output_channels_ == 0)
|
| return false;
|
|
|
| AudioComponentDescription desc = {
|
| @@ -467,10 +375,19 @@ bool AUHALStream::ConfigureAUHAL() {
|
| return false;
|
| }
|
|
|
| - // Enable input and output as appropriate.
|
| - if (!EnableIO(input_channels_ > 0, kAudioUnitScope_Input))
|
| - return false;
|
| - if (!EnableIO(output_channels_ > 0, kAudioUnitScope_Output))
|
| + // Enable output as appropriate.
|
| + // See Apple technote for details about the EnableIO property.
|
| + // Note that we use bus 1 for input and bus 0 for output:
|
| + // http://developer.apple.com/library/mac/#technotes/tn2091/_index.html
|
| + UInt32 enable_IO = 1;
|
| + result = AudioUnitSetProperty(
|
| + audio_unit_,
|
| + kAudioOutputUnitProperty_EnableIO,
|
| + kAudioUnitScope_Output,
|
| + 0,
|
| + &enable_IO,
|
| + sizeof(enable_IO));
|
| + if (result != noErr)
|
| return false;
|
|
|
| // Set the device to be used with the AUHAL AudioUnit.
|
| @@ -490,20 +407,11 @@ bool AUHALStream::ConfigureAUHAL() {
|
| // (element) numbers:
|
| // http://developer.apple.com/library/mac/#technotes/tn2091/_index.html
|
|
|
| - if (input_channels_ > 0) {
|
| - if (!SetStreamFormat(&input_format_,
|
| - input_channels_,
|
| - kAudioUnitScope_Output,
|
| - 1))
|
| - return false;
|
| - }
|
| -
|
| - if (output_channels_ > 0) {
|
| - if (!SetStreamFormat(&output_format_,
|
| - output_channels_,
|
| - kAudioUnitScope_Input,
|
| - 0))
|
| - return false;
|
| + if (!SetStreamFormat(&output_format_,
|
| + output_channels_,
|
| + kAudioUnitScope_Input,
|
| + 0)) {
|
| + return false;
|
| }
|
|
|
| // Set the buffer frame size.
|
|
|