| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/audio/mac/audio_low_latency_input_mac.h" | 5 #include "media/audio/mac/audio_low_latency_input_mac.h" |
| 6 | 6 |
| 7 #include <CoreServices/CoreServices.h> | 7 #include <CoreServices/CoreServices.h> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 : manager_(manager), | 35 : manager_(manager), |
| 36 sink_(NULL), | 36 sink_(NULL), |
| 37 audio_unit_(0), | 37 audio_unit_(0), |
| 38 input_device_id_(audio_device_id), | 38 input_device_id_(audio_device_id), |
| 39 started_(false), | 39 started_(false), |
| 40 hardware_latency_frames_(0), | 40 hardware_latency_frames_(0), |
| 41 number_of_channels_in_frame_(0) { | 41 number_of_channels_in_frame_(0) { |
| 42 DCHECK(manager_); | 42 DCHECK(manager_); |
| 43 | 43 |
| 44 // Set up the desired (output) format specified by the client. | 44 // Set up the desired (output) format specified by the client. |
| 45 format_.mSampleRate = params.sample_rate; | 45 format_.mSampleRate = params.sample_rate(); |
| 46 format_.mFormatID = kAudioFormatLinearPCM; | 46 format_.mFormatID = kAudioFormatLinearPCM; |
| 47 format_.mFormatFlags = kLinearPCMFormatFlagIsPacked | | 47 format_.mFormatFlags = kLinearPCMFormatFlagIsPacked | |
| 48 kLinearPCMFormatFlagIsSignedInteger; | 48 kLinearPCMFormatFlagIsSignedInteger; |
| 49 format_.mBitsPerChannel = params.bits_per_sample; | 49 format_.mBitsPerChannel = params.bits_per_sample(); |
| 50 format_.mChannelsPerFrame = params.channels; | 50 format_.mChannelsPerFrame = params.channels(); |
| 51 format_.mFramesPerPacket = 1; // uncompressed audio | 51 format_.mFramesPerPacket = 1; // uncompressed audio |
| 52 format_.mBytesPerPacket = (format_.mBitsPerChannel * | 52 format_.mBytesPerPacket = (format_.mBitsPerChannel * |
| 53 params.channels) / 8; | 53 params.channels()) / 8; |
| 54 format_.mBytesPerFrame = format_.mBytesPerPacket; | 54 format_.mBytesPerFrame = format_.mBytesPerPacket; |
| 55 format_.mReserved = 0; | 55 format_.mReserved = 0; |
| 56 | 56 |
| 57 DVLOG(1) << "Desired ouput format: " << format_; | 57 DVLOG(1) << "Desired ouput format: " << format_; |
| 58 | 58 |
| 59 // Calculate the number of sample frames per callback. | 59 // Calculate the number of sample frames per callback. |
| 60 number_of_frames_ = params.GetPacketSize() / format_.mBytesPerPacket; | 60 number_of_frames_ = params.GetBytesPerBuffer() / format_.mBytesPerPacket; |
| 61 DVLOG(1) << "Number of frames per callback: " << number_of_frames_; | 61 DVLOG(1) << "Number of frames per callback: " << number_of_frames_; |
| 62 | 62 |
| 63 // Derive size (in bytes) of the buffers that we will render to. | 63 // Derive size (in bytes) of the buffers that we will render to. |
| 64 UInt32 data_byte_size = number_of_frames_ * format_.mBytesPerFrame; | 64 UInt32 data_byte_size = number_of_frames_ * format_.mBytesPerFrame; |
| 65 DVLOG(1) << "Size of data buffer in bytes : " << data_byte_size; | 65 DVLOG(1) << "Size of data buffer in bytes : " << data_byte_size; |
| 66 | 66 |
| 67 // Allocate AudioBuffers to be used as storage for the received audio. | 67 // Allocate AudioBuffers to be used as storage for the received audio. |
| 68 // The AudioBufferList structure works as a placeholder for the | 68 // The AudioBufferList structure works as a placeholder for the |
| 69 // AudioBuffer structure, which holds a pointer to the actual data buffer. | 69 // AudioBuffer structure, which holds a pointer to the actual data buffer. |
| 70 audio_data_buffer_.reset(new uint8[data_byte_size]); | 70 audio_data_buffer_.reset(new uint8[data_byte_size]); |
| 71 audio_buffer_list_.mNumberBuffers = 1; | 71 audio_buffer_list_.mNumberBuffers = 1; |
| 72 | 72 |
| 73 AudioBuffer* audio_buffer = audio_buffer_list_.mBuffers; | 73 AudioBuffer* audio_buffer = audio_buffer_list_.mBuffers; |
| 74 audio_buffer->mNumberChannels = params.channels; | 74 audio_buffer->mNumberChannels = params.channels(); |
| 75 audio_buffer->mDataByteSize = data_byte_size; | 75 audio_buffer->mDataByteSize = data_byte_size; |
| 76 audio_buffer->mData = audio_data_buffer_.get(); | 76 audio_buffer->mData = audio_data_buffer_.get(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 AUAudioInputStream::~AUAudioInputStream() {} | 79 AUAudioInputStream::~AUAudioInputStream() {} |
| 80 | 80 |
| 81 // Obtain and open the AUHAL AudioOutputUnit for recording. | 81 // Obtain and open the AUHAL AudioOutputUnit for recording. |
| 82 bool AUAudioInputStream::Open() { | 82 bool AUAudioInputStream::Open() { |
| 83 // Verify that we are not already opened. | 83 // Verify that we are not already opened. |
| 84 if (audio_unit_) | 84 if (audio_unit_) |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 ((capture_latency_frames + 0.5) * format_.mBytesPerFrame); | 439 ((capture_latency_frames + 0.5) * format_.mBytesPerFrame); |
| 440 DCHECK(audio_data); | 440 DCHECK(audio_data); |
| 441 if (!audio_data) | 441 if (!audio_data) |
| 442 return kAudioUnitErr_InvalidElement; | 442 return kAudioUnitErr_InvalidElement; |
| 443 | 443 |
| 444 sink_->OnData(this, audio_data, buffer.mDataByteSize, capture_delay_bytes); | 444 sink_->OnData(this, audio_data, buffer.mDataByteSize, capture_delay_bytes); |
| 445 | 445 |
| 446 return noErr; | 446 return noErr; |
| 447 } | 447 } |
| 448 | 448 |
| 449 double AUAudioInputStream::HardwareSampleRate() { | 449 int AUAudioInputStream::HardwareSampleRate() { |
| 450 // Determine the default input device's sample-rate. | 450 // Determine the default input device's sample-rate. |
| 451 AudioDeviceID device_id = kAudioObjectUnknown; | 451 AudioDeviceID device_id = kAudioObjectUnknown; |
| 452 UInt32 info_size = sizeof(device_id); | 452 UInt32 info_size = sizeof(device_id); |
| 453 | 453 |
| 454 AudioObjectPropertyAddress default_input_device_address = { | 454 AudioObjectPropertyAddress default_input_device_address = { |
| 455 kAudioHardwarePropertyDefaultInputDevice, | 455 kAudioHardwarePropertyDefaultInputDevice, |
| 456 kAudioObjectPropertyScopeGlobal, | 456 kAudioObjectPropertyScopeGlobal, |
| 457 kAudioObjectPropertyElementMaster | 457 kAudioObjectPropertyElementMaster |
| 458 }; | 458 }; |
| 459 OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject, | 459 OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 477 result = AudioObjectGetPropertyData(device_id, | 477 result = AudioObjectGetPropertyData(device_id, |
| 478 &nominal_sample_rate_address, | 478 &nominal_sample_rate_address, |
| 479 0, | 479 0, |
| 480 0, | 480 0, |
| 481 &info_size, | 481 &info_size, |
| 482 &nominal_sample_rate); | 482 &nominal_sample_rate); |
| 483 DCHECK_EQ(result, 0); | 483 DCHECK_EQ(result, 0); |
| 484 if (result) | 484 if (result) |
| 485 return 0.0; | 485 return 0.0; |
| 486 | 486 |
| 487 return nominal_sample_rate; | 487 return static_cast<int>(nominal_sample_rate); |
| 488 } | 488 } |
| 489 | 489 |
| 490 double AUAudioInputStream::GetHardwareLatency() { | 490 double AUAudioInputStream::GetHardwareLatency() { |
| 491 if (!audio_unit_ || input_device_id_ == kAudioObjectUnknown) { | 491 if (!audio_unit_ || input_device_id_ == kAudioObjectUnknown) { |
| 492 DLOG(WARNING) << "Audio unit object is NULL or device ID is unknown"; | 492 DLOG(WARNING) << "Audio unit object is NULL or device ID is unknown"; |
| 493 return 0.0; | 493 return 0.0; |
| 494 } | 494 } |
| 495 | 495 |
| 496 // Get audio unit latency. | 496 // Get audio unit latency. |
| 497 Float64 audio_unit_latency_sec = 0.0; | 497 Float64 audio_unit_latency_sec = 0.0; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 AudioObjectPropertyAddress property_address = { | 575 AudioObjectPropertyAddress property_address = { |
| 576 kAudioDevicePropertyVolumeScalar, | 576 kAudioDevicePropertyVolumeScalar, |
| 577 kAudioDevicePropertyScopeInput, | 577 kAudioDevicePropertyScopeInput, |
| 578 static_cast<UInt32>(channel) | 578 static_cast<UInt32>(channel) |
| 579 }; | 579 }; |
| 580 OSStatus result = AudioObjectIsPropertySettable(input_device_id_, | 580 OSStatus result = AudioObjectIsPropertySettable(input_device_id_, |
| 581 &property_address, | 581 &property_address, |
| 582 &is_settable); | 582 &is_settable); |
| 583 return (result == noErr) ? is_settable : false; | 583 return (result == noErr) ? is_settable : false; |
| 584 } | 584 } |
| OLD | NEW |