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/bind.h" |
| 11 #include "base/bind_helpers.h" |
10 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
11 #include "base/logging.h" | 13 #include "base/logging.h" |
12 #include "base/mac/mac_logging.h" | 14 #include "base/mac/mac_logging.h" |
| 15 #include "base/time/time.h" |
13 #include "media/audio/mac/audio_manager_mac.h" | 16 #include "media/audio/mac/audio_manager_mac.h" |
14 #include "media/base/audio_pull_fifo.h" | 17 #include "media/base/audio_pull_fifo.h" |
15 | 18 |
16 namespace media { | 19 namespace media { |
17 | 20 |
18 static void ZeroBufferList(AudioBufferList* buffer_list) { | 21 static void ZeroBufferList(AudioBufferList* buffer_list) { |
19 for (size_t i = 0; i < buffer_list->mNumberBuffers; ++i) { | 22 for (size_t i = 0; i < buffer_list->mNumberBuffers; ++i) { |
20 memset(buffer_list->mBuffers[i].mData, | 23 memset(buffer_list->mBuffers[i].mData, |
21 0, | 24 0, |
22 buffer_list->mBuffers[i].mDataByteSize); | 25 buffer_list->mBuffers[i].mDataByteSize); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 manager_->ReleaseOutputStream(this); | 144 manager_->ReleaseOutputStream(this); |
142 } | 145 } |
143 | 146 |
144 void AUHALStream::Start(AudioSourceCallback* callback) { | 147 void AUHALStream::Start(AudioSourceCallback* callback) { |
145 DCHECK(callback); | 148 DCHECK(callback); |
146 if (!audio_unit_) { | 149 if (!audio_unit_) { |
147 DLOG(ERROR) << "Open() has not been called successfully"; | 150 DLOG(ERROR) << "Open() has not been called successfully"; |
148 return; | 151 return; |
149 } | 152 } |
150 | 153 |
| 154 // Check if we should defer Start() for http://crbug.com/160920. |
| 155 if (manager_->ShouldDeferOutputStreamStart()) { |
| 156 // Use a cancellable closure so that if Stop() is called before Start() |
| 157 // actually runs, we can cancel the pending start. |
| 158 DCHECK(deferred_start_cb_.IsCancelled()); |
| 159 deferred_start_cb_.Reset( |
| 160 base::Bind(&AUHALStream::Start, base::Unretained(this), callback)); |
| 161 manager_->GetTaskRunner()->PostDelayedTask( |
| 162 FROM_HERE, deferred_start_cb_.callback(), base::TimeDelta::FromSeconds( |
| 163 AudioManagerMac::kStartDelayInSecsForPowerEvents)); |
| 164 return; |
| 165 } |
| 166 |
151 stopped_ = false; | 167 stopped_ = false; |
152 audio_fifo_.reset(); | 168 audio_fifo_.reset(); |
153 { | 169 { |
154 base::AutoLock auto_lock(source_lock_); | 170 base::AutoLock auto_lock(source_lock_); |
155 source_ = callback; | 171 source_ = callback; |
156 } | 172 } |
157 | 173 |
158 OSStatus result = AudioOutputUnitStart(audio_unit_); | 174 OSStatus result = AudioOutputUnitStart(audio_unit_); |
159 if (result == noErr) | 175 if (result == noErr) |
160 return; | 176 return; |
161 | 177 |
162 Stop(); | 178 Stop(); |
163 OSSTATUS_DLOG(ERROR, result) << "AudioOutputUnitStart() failed."; | 179 OSSTATUS_DLOG(ERROR, result) << "AudioOutputUnitStart() failed."; |
164 callback->OnError(this); | 180 callback->OnError(this); |
165 } | 181 } |
166 | 182 |
167 void AUHALStream::Stop() { | 183 void AUHALStream::Stop() { |
| 184 deferred_start_cb_.Cancel(); |
168 if (stopped_) | 185 if (stopped_) |
169 return; | 186 return; |
170 | 187 |
171 OSStatus result = AudioOutputUnitStop(audio_unit_); | 188 OSStatus result = AudioOutputUnitStop(audio_unit_); |
172 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) | 189 OSSTATUS_DLOG_IF(ERROR, result != noErr, result) |
173 << "AudioOutputUnitStop() failed."; | 190 << "AudioOutputUnitStop() failed."; |
174 if (result != noErr) | 191 if (result != noErr) |
175 source_->OnError(this); | 192 source_->OnError(this); |
176 | 193 |
177 base::AutoLock auto_lock(source_lock_); | 194 base::AutoLock auto_lock(source_lock_); |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 result = AudioUnitInitialize(audio_unit_); | 545 result = AudioUnitInitialize(audio_unit_); |
529 if (result != noErr) { | 546 if (result != noErr) { |
530 OSSTATUS_DLOG(ERROR, result) << "AudioUnitInitialize() failed."; | 547 OSSTATUS_DLOG(ERROR, result) << "AudioUnitInitialize() failed."; |
531 return false; | 548 return false; |
532 } | 549 } |
533 | 550 |
534 return true; | 551 return true; |
535 } | 552 } |
536 | 553 |
537 } // namespace media | 554 } // namespace media |
OLD | NEW |