Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: media/audio/mac/audio_low_latency_input_mac.cc

Issue 1668373003: Improved error handling in AUAudioInputStream::Open() for Mac OSX (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.
118 if (audio_unit_)
119 return false;
120 117
121 // Verify that we have a valid device. 118 // Verify that we are not already opened. Send appropriate error code to
122 if (input_device_id_ == kAudioObjectUnknown) { 119 // HandleError() to ensure that the error type is added to UMA stats where
123 NOTREACHED() << "Device ID is unknown"; 120 // the frequency of error codes can be analyzed.
121 if (audio_unit_) {
122 HandleError(kAudioUnitErr_Initialized);
tommi (sloooow) - chröme 2016/02/05 12:29:30 I'm not sure this is a good idea. HandleError()
henrika (OOO until Aug 14) 2016/02/05 12:50:51 Done.
124 return false; 123 return false;
125 } 124 }
126 125
126 // Verify that we have a valid device. Send appropriate error code to
127 // HandleError() to ensure that the error type is added to UMA stats.
128 if (input_device_id_ == kAudioObjectUnknown) {
129 NOTREACHED() << "Device ID is unknown";
130 HandleError(kAudioUnitErr_InvalidElement);
131 return false;
132 }
133
127 // The requested sample-rate must match the hardware sample-rate. 134 // The requested sample-rate must match the hardware sample-rate.
128 int sample_rate = 135 int sample_rate =
129 AudioManagerMac::HardwareSampleRateForDevice(input_device_id_); 136 AudioManagerMac::HardwareSampleRateForDevice(input_device_id_);
130 if (sample_rate != format_.mSampleRate) { 137 if (sample_rate != format_.mSampleRate) {
131 // Add UMA stat for the case when we detect a mismatch in sample rates, 138 // 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 139 // 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 140 // one used when constructing this object. In addition, return false since
134 // the current design does not support changes in the native sample rate 141 // the current design does not support changes in the native sample rate
135 // between construction and calls to Open(). 142 // between construction and calls to Open().
136 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.InputInvalidSampleRateMac", sample_rate); 143 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.InputInvalidSampleRateMac", sample_rate);
137 NOTREACHED() << "Requested sample-rate: " << format_.mSampleRate 144 NOTREACHED() << "Requested sample-rate: " << format_.mSampleRate
138 << " must match the hardware sample-rate: " << sample_rate; 145 << " must match the hardware sample-rate: " << sample_rate;
146 HandleError(kAudioUnitErr_InvalidParameter);
henrika (OOO until Aug 14) 2016/02/05 12:16:28 Adding one extra here since we can then see the re
tommi (sloooow) - chröme 2016/02/05 12:29:30 Acknowledged.
139 return false; 147 return false;
140 } 148 }
141 149
142 // Start by obtaining an AudioOuputUnit using an AUHAL component description. 150 // Start by obtaining an AudioOuputUnit using an AUHAL component description.
143 151
144 // Description for the Audio Unit we want to use (AUHAL in this case). 152 // Description for the Audio Unit we want to use (AUHAL in this case).
145 // The kAudioUnitSubType_HALOutput audio unit interfaces to any audio device. 153 // The kAudioUnitSubType_HALOutput audio unit interfaces to any audio device.
146 // The user specifies which audio device to track. The audio unit can do 154 // 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 155 // 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. 156 // the output side, bus 1 is used to get audio input from the device.
149 AudioComponentDescription desc = { 157 AudioComponentDescription desc = {
150 kAudioUnitType_Output, 158 kAudioUnitType_Output,
151 kAudioUnitSubType_HALOutput, 159 kAudioUnitSubType_HALOutput,
152 kAudioUnitManufacturer_Apple, 160 kAudioUnitManufacturer_Apple,
153 0, 161 0,
154 0 162 0
155 }; 163 };
156 164
165 // Find a component that meets the description in |desc|.
157 AudioComponent comp = AudioComponentFindNext(nullptr, &desc); 166 AudioComponent comp = AudioComponentFindNext(nullptr, &desc);
158 DCHECK(comp); 167 DCHECK(comp);
168 if (!comp) {
169 HandleError(kAudioComponentErr_InstanceInvalidated);
170 return false;
171 }
159 172
160 // Get access to the service provided by the specified Audio Unit. 173 // Get access to the service provided by the specified Audio Unit.
161 OSStatus result = AudioComponentInstanceNew(comp, &audio_unit_); 174 OSStatus result = AudioComponentInstanceNew(comp, &audio_unit_);
162 if (result) { 175 if (result) {
163 HandleError(result); 176 HandleError(result);
164 return false; 177 return false;
165 } 178 }
166 179
167 // Initialize the AUHAL before making any changes or using it. The audio unit 180 // 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 181 // 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
923 manager_->low_latency_input_streams()); 936 manager_->low_latency_input_streams());
924 UMA_HISTOGRAM_COUNTS_1000("Media.Audio.NumberOfBasicInputStreamsMac", 937 UMA_HISTOGRAM_COUNTS_1000("Media.Audio.NumberOfBasicInputStreamsMac",
925 manager_->basic_input_streams()); 938 manager_->basic_input_streams());
926 // TODO(henrika): this value will currently always report true. It should be 939 // TODO(henrika): this value will currently always report true. It should be
927 // fixed when we understand the problem better. 940 // fixed when we understand the problem better.
928 UMA_HISTOGRAM_BOOLEAN("Media.Audio.AutomaticGainControlMac", 941 UMA_HISTOGRAM_BOOLEAN("Media.Audio.AutomaticGainControlMac",
929 GetAutomaticGainControl()); 942 GetAutomaticGainControl());
930 } 943 }
931 944
932 } // namespace media 945 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698