| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_auhal_mac.h" | 5 #include "media/audio/mac/audio_auhal_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/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 params_(params), | 65 params_(params), |
| 66 input_channels_(params_.input_channels()), | 66 input_channels_(params_.input_channels()), |
| 67 output_channels_(params_.channels()), | 67 output_channels_(params_.channels()), |
| 68 number_of_frames_(params_.frames_per_buffer()), | 68 number_of_frames_(params_.frames_per_buffer()), |
| 69 source_(NULL), | 69 source_(NULL), |
| 70 device_(device), | 70 device_(device), |
| 71 audio_unit_(0), | 71 audio_unit_(0), |
| 72 volume_(1), | 72 volume_(1), |
| 73 hardware_latency_frames_(0), | 73 hardware_latency_frames_(0), |
| 74 stopped_(false), | 74 stopped_(false), |
| 75 notified_for_possible_device_change_(false), |
| 75 input_buffer_list_(NULL) { | 76 input_buffer_list_(NULL) { |
| 76 // We must have a manager. | 77 // We must have a manager. |
| 77 DCHECK(manager_); | 78 DCHECK(manager_); |
| 78 | 79 |
| 79 VLOG(1) << "AUHALStream::AUHALStream()"; | 80 VLOG(1) << "AUHALStream::AUHALStream()"; |
| 80 VLOG(1) << "Device: " << device; | 81 VLOG(1) << "Device: " << device; |
| 81 VLOG(1) << "Input channels: " << input_channels_; | 82 VLOG(1) << "Input channels: " << input_channels_; |
| 82 VLOG(1) << "Output channels: " << output_channels_; | 83 VLOG(1) << "Output channels: " << output_channels_; |
| 83 VLOG(1) << "Sample rate: " << params_.sample_rate(); | 84 VLOG(1) << "Sample rate: " << params_.sample_rate(); |
| 84 VLOG(1) << "Buffer size: " << number_of_frames_; | 85 VLOG(1) << "Buffer size: " << number_of_frames_; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 } | 153 } |
| 153 | 154 |
| 154 void AUHALStream::Start(AudioSourceCallback* callback) { | 155 void AUHALStream::Start(AudioSourceCallback* callback) { |
| 155 DCHECK(callback); | 156 DCHECK(callback); |
| 156 if (!audio_unit_) { | 157 if (!audio_unit_) { |
| 157 DLOG(ERROR) << "Open() has not been called successfully"; | 158 DLOG(ERROR) << "Open() has not been called successfully"; |
| 158 return; | 159 return; |
| 159 } | 160 } |
| 160 | 161 |
| 161 stopped_ = false; | 162 stopped_ = false; |
| 163 notified_for_possible_device_change_ = false; |
| 162 { | 164 { |
| 163 base::AutoLock auto_lock(source_lock_); | 165 base::AutoLock auto_lock(source_lock_); |
| 164 source_ = callback; | 166 source_ = callback; |
| 165 } | 167 } |
| 166 | 168 |
| 167 AudioOutputUnitStart(audio_unit_); | 169 AudioOutputUnitStart(audio_unit_); |
| 168 } | 170 } |
| 169 | 171 |
| 170 void AUHALStream::Stop() { | 172 void AUHALStream::Stop() { |
| 171 if (stopped_) | 173 if (stopped_) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 202 // This can happen if we've suddenly changed sample-rates. | 204 // This can happen if we've suddenly changed sample-rates. |
| 203 // The stream should be stopping very soon. | 205 // The stream should be stopping very soon. |
| 204 // | 206 // |
| 205 // Unfortunately AUAudioInputStream and AUHALStream share the frame | 207 // Unfortunately AUAudioInputStream and AUHALStream share the frame |
| 206 // size set by kAudioDevicePropertyBufferFrameSize above on a per process | 208 // size set by kAudioDevicePropertyBufferFrameSize above on a per process |
| 207 // basis. What this means is that the |number_of_frames| value may be | 209 // basis. What this means is that the |number_of_frames| value may be |
| 208 // larger or smaller than the value set during ConfigureAUHAL(). | 210 // larger or smaller than the value set during ConfigureAUHAL(). |
| 209 // In this case either audio input or audio output will be broken, | 211 // In this case either audio input or audio output will be broken, |
| 210 // so just output silence. | 212 // so just output silence. |
| 211 ZeroBufferList(io_data); | 213 ZeroBufferList(io_data); |
| 214 |
| 215 // In case we missed a device notification, notify the AudioManager that the |
| 216 // device has changed. HandleDeviceChanges() will check to make sure the |
| 217 // device has actually changed before taking any action. |
| 218 if (!notified_for_possible_device_change_) { |
| 219 notified_for_possible_device_change_ = true; |
| 220 manager_->GetMessageLoop()->PostTask(FROM_HERE, base::Bind( |
| 221 &AudioManagerMac::HandleDeviceChanges, base::Unretained(manager_))); |
| 222 } |
| 223 |
| 212 return noErr; | 224 return noErr; |
| 213 } | 225 } |
| 214 | 226 |
| 215 if (input_channels_ > 0 && input_buffer_list_) { | 227 if (input_channels_ > 0 && input_buffer_list_) { |
| 216 // Get the input data. |input_buffer_list_| is wrapped | 228 // Get the input data. |input_buffer_list_| is wrapped |
| 217 // to point to the data allocated in |input_bus_|. | 229 // to point to the data allocated in |input_bus_|. |
| 218 OSStatus result = AudioUnitRender( | 230 OSStatus result = AudioUnitRender( |
| 219 audio_unit_, | 231 audio_unit_, |
| 220 flags, | 232 flags, |
| 221 output_time_stamp, | 233 output_time_stamp, |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 0, | 533 0, |
| 522 &callback, | 534 &callback, |
| 523 sizeof(callback)); | 535 sizeof(callback)); |
| 524 if (result != noErr) | 536 if (result != noErr) |
| 525 return false; | 537 return false; |
| 526 | 538 |
| 527 return true; | 539 return true; |
| 528 } | 540 } |
| 529 | 541 |
| 530 } // namespace media | 542 } // namespace media |
| OLD | NEW |