| 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/mac_logging.h" | 10 #include "base/mac/mac_logging.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 107 } |
| 108 | 108 |
| 109 AUAudioInputStream::~AUAudioInputStream() { | 109 AUAudioInputStream::~AUAudioInputStream() { |
| 110 DVLOG(1) << "~dtor"; | 110 DVLOG(1) << "~dtor"; |
| 111 } | 111 } |
| 112 | 112 |
| 113 // Obtain and open the AUHAL AudioOutputUnit for recording. | 113 // Obtain and open the AUHAL AudioOutputUnit for recording. |
| 114 bool AUAudioInputStream::Open() { | 114 bool AUAudioInputStream::Open() { |
| 115 DCHECK(thread_checker_.CalledOnValidThread()); | 115 DCHECK(thread_checker_.CalledOnValidThread()); |
| 116 DVLOG(1) << "Open"; | 116 DVLOG(1) << "Open"; |
| 117 // Verify that we are not already opened. | 117 DCHECK(!audio_unit_); |
| 118 if (audio_unit_) | |
| 119 return false; | |
| 120 | 118 |
| 121 // Verify that we have a valid device. | 119 // Verify that we have a valid device. Send appropriate error code to |
| 120 // HandleError() to ensure that the error type is added to UMA stats. |
| 122 if (input_device_id_ == kAudioObjectUnknown) { | 121 if (input_device_id_ == kAudioObjectUnknown) { |
| 123 NOTREACHED() << "Device ID is unknown"; | 122 NOTREACHED() << "Device ID is unknown"; |
| 123 HandleError(kAudioUnitErr_InvalidElement); |
| 124 return false; | 124 return false; |
| 125 } | 125 } |
| 126 | 126 |
| 127 // The requested sample-rate must match the hardware sample-rate. | 127 // The requested sample-rate must match the hardware sample-rate. |
| 128 int sample_rate = | 128 int sample_rate = |
| 129 AudioManagerMac::HardwareSampleRateForDevice(input_device_id_); | 129 AudioManagerMac::HardwareSampleRateForDevice(input_device_id_); |
| 130 if (sample_rate != format_.mSampleRate) { | 130 if (sample_rate != format_.mSampleRate) { |
| 131 // Add UMA stat for the case when we detect a mismatch in sample rates, | 131 // Add UMA stat for the case when we detect a mismatch in sample rates, |
| 132 // i.e., when the actual/current native sample rate is different from the | 132 // i.e., when the actual/current native sample rate is different from the |
| 133 // one used when constructing this object. In addition, return false since | 133 // one used when constructing this object. In addition, return false since |
| 134 // the current design does not support changes in the native sample rate | 134 // the current design does not support changes in the native sample rate |
| 135 // between construction and calls to Open(). | 135 // between construction and calls to Open(). |
| 136 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.InputInvalidSampleRateMac", sample_rate); | 136 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.InputInvalidSampleRateMac", sample_rate); |
| 137 NOTREACHED() << "Requested sample-rate: " << format_.mSampleRate | 137 NOTREACHED() << "Requested sample-rate: " << format_.mSampleRate |
| 138 << " must match the hardware sample-rate: " << sample_rate; | 138 << " must match the hardware sample-rate: " << sample_rate; |
| 139 HandleError(kAudioUnitErr_InvalidParameter); |
| 139 return false; | 140 return false; |
| 140 } | 141 } |
| 141 | 142 |
| 142 // Start by obtaining an AudioOuputUnit using an AUHAL component description. | 143 // Start by obtaining an AudioOuputUnit using an AUHAL component description. |
| 143 | 144 |
| 144 // Description for the Audio Unit we want to use (AUHAL in this case). | 145 // Description for the Audio Unit we want to use (AUHAL in this case). |
| 145 // The kAudioUnitSubType_HALOutput audio unit interfaces to any audio device. | 146 // The kAudioUnitSubType_HALOutput audio unit interfaces to any audio device. |
| 146 // The user specifies which audio device to track. The audio unit can do | 147 // The user specifies which audio device to track. The audio unit can do |
| 147 // input from the device as well as output to the device. Bus 0 is used for | 148 // input from the device as well as output to the device. Bus 0 is used for |
| 148 // the output side, bus 1 is used to get audio input from the device. | 149 // the output side, bus 1 is used to get audio input from the device. |
| 149 AudioComponentDescription desc = { | 150 AudioComponentDescription desc = { |
| 150 kAudioUnitType_Output, | 151 kAudioUnitType_Output, |
| 151 kAudioUnitSubType_HALOutput, | 152 kAudioUnitSubType_HALOutput, |
| 152 kAudioUnitManufacturer_Apple, | 153 kAudioUnitManufacturer_Apple, |
| 153 0, | 154 0, |
| 154 0 | 155 0 |
| 155 }; | 156 }; |
| 156 | 157 |
| 158 // Find a component that meets the description in |desc|. |
| 157 AudioComponent comp = AudioComponentFindNext(nullptr, &desc); | 159 AudioComponent comp = AudioComponentFindNext(nullptr, &desc); |
| 158 DCHECK(comp); | 160 DCHECK(comp); |
| 161 if (!comp) { |
| 162 HandleError(kAudioUnitErr_NoConnection); |
| 163 return false; |
| 164 } |
| 159 | 165 |
| 160 // Get access to the service provided by the specified Audio Unit. | 166 // Get access to the service provided by the specified Audio Unit. |
| 161 OSStatus result = AudioComponentInstanceNew(comp, &audio_unit_); | 167 OSStatus result = AudioComponentInstanceNew(comp, &audio_unit_); |
| 162 if (result) { | 168 if (result) { |
| 163 HandleError(result); | 169 HandleError(result); |
| 164 return false; | 170 return false; |
| 165 } | 171 } |
| 166 | 172 |
| 167 // Initialize the AUHAL before making any changes or using it. The audio unit | 173 // Initialize the AUHAL before making any changes or using it. The audio unit |
| 168 // will be initialized once more as last operation in this method but that is | 174 // will be initialized once more as last operation in this method but that is |
| (...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 manager_->low_latency_input_streams()); | 929 manager_->low_latency_input_streams()); |
| 924 UMA_HISTOGRAM_COUNTS_1000("Media.Audio.NumberOfBasicInputStreamsMac", | 930 UMA_HISTOGRAM_COUNTS_1000("Media.Audio.NumberOfBasicInputStreamsMac", |
| 925 manager_->basic_input_streams()); | 931 manager_->basic_input_streams()); |
| 926 // TODO(henrika): this value will currently always report true. It should be | 932 // TODO(henrika): this value will currently always report true. It should be |
| 927 // fixed when we understand the problem better. | 933 // fixed when we understand the problem better. |
| 928 UMA_HISTOGRAM_BOOLEAN("Media.Audio.AutomaticGainControlMac", | 934 UMA_HISTOGRAM_BOOLEAN("Media.Audio.AutomaticGainControlMac", |
| 929 GetAutomaticGainControl()); | 935 GetAutomaticGainControl()); |
| 930 } | 936 } |
| 931 | 937 |
| 932 } // namespace media | 938 } // namespace media |
| OLD | NEW |