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

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

Issue 1973503003: (Relanding) Restores larger output buffer size when output stream requiring smaller size is closed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improved comments Created 4 years, 7 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
OLDNEW
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/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 if (configured) 115 if (configured)
116 hardware_latency_frames_ = GetHardwareLatency(); 116 hardware_latency_frames_ = GetHardwareLatency();
117 117
118 return configured; 118 return configured;
119 } 119 }
120 120
121 void AUHALStream::Close() { 121 void AUHALStream::Close() {
122 DCHECK(thread_checker_.CalledOnValidThread()); 122 DCHECK(thread_checker_.CalledOnValidThread());
123 DVLOG(1) << "Close"; 123 DVLOG(1) << "Close";
124 CloseAudioUnit(); 124 CloseAudioUnit();
125 // Notify the audio manager about an upcoming call to ReleaseOutputStream()
126 // and also provide the device ID of the utilized audio device. This is a
127 // trick to ensure that the audio manager only tries to increase the native
128 // I/O buffer size for real audio streams and not for e.g. fake streams.
129 manager_->PrepareForAttemptToIncreaseIOBufferSize(device_);
o1ka 2016/05/12 11:30:17 Ah ok, I see what you mean. Could we simplify it a
o1ka 2016/05/12 12:04:15 (Actually, it should be named differently, because
henrika (OOO until Aug 14) 2016/05/12 13:02:08 Well, that does not seem that strict but OK I can
henrika (OOO until Aug 14) 2016/05/12 13:02:08 Good idea. Done.
125 // Inform the audio manager that we have been closed. This will cause our 130 // Inform the audio manager that we have been closed. This will cause our
126 // destruction. 131 // destruction.
127 manager_->ReleaseOutputStream(this); 132 manager_->ReleaseOutputStream(this);
128 } 133 }
129 134
130 void AUHALStream::Start(AudioSourceCallback* callback) { 135 void AUHALStream::Start(AudioSourceCallback* callback) {
131 DCHECK(thread_checker_.CalledOnValidThread()); 136 DCHECK(thread_checker_.CalledOnValidThread());
132 DVLOG(1) << "Start"; 137 DVLOG(1) << "Start";
133 DCHECK(callback); 138 DCHECK(callback);
134 if (!audio_unit_) { 139 if (!audio_unit_) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 OSSTATUS_DLOG(ERROR, result) << "AudioOutputUnitStart() failed."; 173 OSSTATUS_DLOG(ERROR, result) << "AudioOutputUnitStart() failed.";
169 callback->OnError(this); 174 callback->OnError(this);
170 } 175 }
171 176
172 void AUHALStream::Stop() { 177 void AUHALStream::Stop() {
173 DCHECK(thread_checker_.CalledOnValidThread()); 178 DCHECK(thread_checker_.CalledOnValidThread());
174 deferred_start_cb_.Cancel(); 179 deferred_start_cb_.Cancel();
175 if (stopped_) 180 if (stopped_)
176 return; 181 return;
177 DVLOG(1) << "Stop"; 182 DVLOG(1) << "Stop";
183 DVLOG(2) << "number_of_frames: " << number_of_frames_;
178 OSStatus result = AudioOutputUnitStop(audio_unit_); 184 OSStatus result = AudioOutputUnitStop(audio_unit_);
179 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) 185 OSSTATUS_DLOG_IF(ERROR, result != noErr, result)
180 << "AudioOutputUnitStop() failed."; 186 << "AudioOutputUnitStop() failed.";
181 if (result != noErr) 187 if (result != noErr)
182 source_->OnError(this); 188 source_->OnError(this);
183 ReportAndResetStats(); 189 ReportAndResetStats();
184 base::AutoLock auto_lock(source_lock_); 190 base::AutoLock auto_lock(source_lock_);
185 source_ = NULL; 191 source_ = NULL;
186 stopped_ = true; 192 stopped_ = true;
187 } 193 }
(...skipping 23 matching lines...) Expand all
211 // If the stream parameters change for any reason, we need to insert a FIFO 217 // If the stream parameters change for any reason, we need to insert a FIFO
212 // since the OnMoreData() pipeline can't handle frame size changes. 218 // since the OnMoreData() pipeline can't handle frame size changes.
213 if (number_of_frames != number_of_frames_) { 219 if (number_of_frames != number_of_frames_) {
214 // Create a FIFO on the fly to handle any discrepancies in callback rates. 220 // Create a FIFO on the fly to handle any discrepancies in callback rates.
215 if (!audio_fifo_) { 221 if (!audio_fifo_) {
216 // TODO(grunell): We'll only care about the first buffer size change, 222 // TODO(grunell): We'll only care about the first buffer size change,
217 // any further changes will be ignored. It would be nice to have all 223 // any further changes will be ignored. It would be nice to have all
218 // changes reflected in UMA stats. 224 // changes reflected in UMA stats.
219 number_of_frames_requested_ = number_of_frames; 225 number_of_frames_requested_ = number_of_frames;
220 DVLOG(1) << "Audio frame size changed from " << number_of_frames_ 226 DVLOG(1) << "Audio frame size changed from " << number_of_frames_
221 << " to " << number_of_frames 227 << " to " << number_of_frames << " adding FIFO to compensate.";
222 << "; adding FIFO to compensate.";
223 audio_fifo_.reset(new AudioPullFifo( 228 audio_fifo_.reset(new AudioPullFifo(
224 output_channels_, 229 output_channels_,
225 number_of_frames_, 230 number_of_frames_,
226 base::Bind(&AUHALStream::ProvideInput, base::Unretained(this)))); 231 base::Bind(&AUHALStream::ProvideInput, base::Unretained(this))));
227 } 232 }
228 } 233 }
229 234
230 // Make |output_bus_| wrap the output AudioBufferList. 235 // Make |output_bus_| wrap the output AudioBufferList.
231 WrapBufferList(data, output_bus_.get(), number_of_frames); 236 WrapBufferList(data, output_bus_.get(), number_of_frames);
232 237
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 OSStatus result = AudioUnitUninitialize(audio_unit_); 551 OSStatus result = AudioUnitUninitialize(audio_unit_);
547 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) 552 OSSTATUS_DLOG_IF(ERROR, result != noErr, result)
548 << "AudioUnitUninitialize() failed."; 553 << "AudioUnitUninitialize() failed.";
549 result = AudioComponentInstanceDispose(audio_unit_); 554 result = AudioComponentInstanceDispose(audio_unit_);
550 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) 555 OSSTATUS_DLOG_IF(ERROR, result != noErr, result)
551 << "AudioComponentInstanceDispose() failed."; 556 << "AudioComponentInstanceDispose() failed.";
552 audio_unit_ = 0; 557 audio_unit_ = 0;
553 } 558 }
554 559
555 } // namespace media 560 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698