| 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" |
| 11 #include "base/mac/mac_logging.h" | 11 #include "base/mac/mac_logging.h" |
| 12 #include "media/audio/mac/audio_manager_mac.h" | 12 #include "media/audio/mac/audio_manager_mac.h" |
| 13 #include "media/base/audio_bus.h" |
| 13 #include "media/base/data_buffer.h" | 14 #include "media/base/data_buffer.h" |
| 14 | 15 |
| 15 namespace media { | 16 namespace media { |
| 16 | 17 |
| 17 static std::ostream& operator<<(std::ostream& os, | 18 static std::ostream& operator<<(std::ostream& os, |
| 18 const AudioStreamBasicDescription& format) { | 19 const AudioStreamBasicDescription& format) { |
| 19 os << "sample rate : " << format.mSampleRate << std::endl | 20 os << "sample rate : " << format.mSampleRate << std::endl |
| 20 << "format ID : " << format.mFormatID << std::endl | 21 << "format ID : " << format.mFormatID << std::endl |
| 21 << "format flags : " << format.mFormatFlags << std::endl | 22 << "format flags : " << format.mFormatFlags << std::endl |
| 22 << "bytes per packet : " << format.mBytesPerPacket << std::endl | 23 << "bytes per packet : " << format.mBytesPerPacket << std::endl |
| 23 << "frames per packet : " << format.mFramesPerPacket << std::endl | 24 << "frames per packet : " << format.mFramesPerPacket << std::endl |
| 24 << "bytes per frame : " << format.mBytesPerFrame << std::endl | 25 << "bytes per frame : " << format.mBytesPerFrame << std::endl |
| 25 << "channels per frame: " << format.mChannelsPerFrame << std::endl | 26 << "channels per frame: " << format.mChannelsPerFrame << std::endl |
| 26 << "bits per channel : " << format.mBitsPerChannel; | 27 << "bits per channel : " << format.mBitsPerChannel; |
| 27 return os; | 28 return os; |
| 28 } | 29 } |
| 29 | 30 |
| 30 // See "Technical Note TN2091 - Device input using the HAL Output Audio Unit" | 31 // See "Technical Note TN2091 - Device input using the HAL Output Audio Unit" |
| 31 // http://developer.apple.com/library/mac/#technotes/tn2091/_index.html | 32 // http://developer.apple.com/library/mac/#technotes/tn2091/_index.html |
| 32 // for more details and background regarding this implementation. | 33 // for more details and background regarding this implementation. |
| 33 | 34 |
| 34 AUAudioInputStream::AUAudioInputStream( | 35 AUAudioInputStream::AUAudioInputStream(AudioManagerMac* manager, |
| 35 AudioManagerMac* manager, | 36 const AudioParameters& input_params, |
| 36 const AudioParameters& input_params, | 37 const AudioParameters& output_params, |
| 37 const AudioParameters& output_params, | 38 AudioDeviceID audio_device_id) |
| 38 AudioDeviceID audio_device_id) | |
| 39 : manager_(manager), | 39 : manager_(manager), |
| 40 sink_(NULL), | 40 sink_(NULL), |
| 41 audio_unit_(0), | 41 audio_unit_(0), |
| 42 input_device_id_(audio_device_id), | 42 input_device_id_(audio_device_id), |
| 43 started_(false), | 43 started_(false), |
| 44 hardware_latency_frames_(0), | 44 hardware_latency_frames_(0), |
| 45 fifo_delay_bytes_(0), | 45 fifo_delay_bytes_(0), |
| 46 number_of_channels_in_frame_(0) { | 46 number_of_channels_in_frame_(0), |
| 47 audio_bus_(media::AudioBus::Create(input_params)) { |
| 47 DCHECK(manager_); | 48 DCHECK(manager_); |
| 48 | 49 |
| 49 // Set up the desired (output) format specified by the client. | 50 // Set up the desired (output) format specified by the client. |
| 50 format_.mSampleRate = input_params.sample_rate(); | 51 format_.mSampleRate = input_params.sample_rate(); |
| 51 format_.mFormatID = kAudioFormatLinearPCM; | 52 format_.mFormatID = kAudioFormatLinearPCM; |
| 52 format_.mFormatFlags = kLinearPCMFormatFlagIsPacked | | 53 format_.mFormatFlags = kLinearPCMFormatFlagIsPacked | |
| 53 kLinearPCMFormatFlagIsSignedInteger; | 54 kLinearPCMFormatFlagIsSignedInteger; |
| 54 format_.mBitsPerChannel = input_params.bits_per_sample(); | 55 format_.mBitsPerChannel = input_params.bits_per_sample(); |
| 55 format_.mChannelsPerFrame = input_params.channels(); | 56 format_.mChannelsPerFrame = input_params.channels(); |
| 56 format_.mFramesPerPacket = 1; // uncompressed audio | 57 format_.mFramesPerPacket = 1; // uncompressed audio |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 // Accumulate captured audio in FIFO until we can match the output size | 536 // Accumulate captured audio in FIFO until we can match the output size |
| 536 // requested by the client. | 537 // requested by the client. |
| 537 fifo_->Append(audio_data, buffer.mDataByteSize); | 538 fifo_->Append(audio_data, buffer.mDataByteSize); |
| 538 | 539 |
| 539 // Deliver recorded data to the client as soon as the FIFO contains a | 540 // Deliver recorded data to the client as soon as the FIFO contains a |
| 540 // sufficient amount. | 541 // sufficient amount. |
| 541 if (fifo_->forward_bytes() >= requested_size_bytes_) { | 542 if (fifo_->forward_bytes() >= requested_size_bytes_) { |
| 542 // Read from FIFO into temporary data buffer. | 543 // Read from FIFO into temporary data buffer. |
| 543 fifo_->Read(data_->writable_data(), requested_size_bytes_); | 544 fifo_->Read(data_->writable_data(), requested_size_bytes_); |
| 544 | 545 |
| 546 // Copy captured (and interleaved) data into deinterleaved audio bus. |
| 547 audio_bus_->FromInterleaved( |
| 548 data_->data(), audio_bus_->frames(), format_.mBitsPerChannel / 8); |
| 549 |
| 545 // Deliver data packet, delay estimation and volume level to the user. | 550 // Deliver data packet, delay estimation and volume level to the user. |
| 546 sink_->OnData(this, | 551 sink_->OnData( |
| 547 data_->data(), | 552 this, audio_bus_.get(), capture_delay_bytes, normalized_volume); |
| 548 requested_size_bytes_, | |
| 549 capture_delay_bytes, | |
| 550 normalized_volume); | |
| 551 } | 553 } |
| 552 | 554 |
| 553 return noErr; | 555 return noErr; |
| 554 } | 556 } |
| 555 | 557 |
| 556 int AUAudioInputStream::HardwareSampleRate() { | 558 int AUAudioInputStream::HardwareSampleRate() { |
| 557 // Determine the default input device's sample-rate. | 559 // Determine the default input device's sample-rate. |
| 558 AudioDeviceID device_id = kAudioObjectUnknown; | 560 AudioDeviceID device_id = kAudioObjectUnknown; |
| 559 UInt32 info_size = sizeof(device_id); | 561 UInt32 info_size = sizeof(device_id); |
| 560 | 562 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 kAudioDevicePropertyScopeInput, | 684 kAudioDevicePropertyScopeInput, |
| 683 static_cast<UInt32>(channel) | 685 static_cast<UInt32>(channel) |
| 684 }; | 686 }; |
| 685 OSStatus result = AudioObjectIsPropertySettable(input_device_id_, | 687 OSStatus result = AudioObjectIsPropertySettable(input_device_id_, |
| 686 &property_address, | 688 &property_address, |
| 687 &is_settable); | 689 &is_settable); |
| 688 return (result == noErr) ? is_settable : false; | 690 return (result == noErr) ? is_settable : false; |
| 689 } | 691 } |
| 690 | 692 |
| 691 } // namespace media | 693 } // namespace media |
| OLD | NEW |