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

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

Issue 11478019: Revert 171681 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years 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 | Annotate | Revision Log
« no previous file with comments | « media/audio/mac/audio_input_mac.h ('k') | 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_input_mac.h" 5 #include "media/audio/mac/audio_input_mac.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/mac/mac_logging.h" 9 #include "base/mac/mac_logging.h"
10 #include "media/audio/audio_manager_base.h" 10 #include "media/audio/audio_manager_base.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 UInt32 num_packets, 185 UInt32 num_packets,
186 const AudioStreamPacketDescription* packet_desc) { 186 const AudioStreamPacketDescription* packet_desc) {
187 DCHECK_EQ(audio_queue_, audio_queue); 187 DCHECK_EQ(audio_queue_, audio_queue);
188 DCHECK(audio_buffer->mAudioData); 188 DCHECK(audio_buffer->mAudioData);
189 if (!callback_) { 189 if (!callback_) {
190 // This can happen if Stop() was called without start. 190 // This can happen if Stop() was called without start.
191 DCHECK_EQ(0U, audio_buffer->mAudioDataByteSize); 191 DCHECK_EQ(0U, audio_buffer->mAudioDataByteSize);
192 return; 192 return;
193 } 193 }
194 194
195 if (audio_buffer->mAudioDataByteSize) { 195 if (audio_buffer->mAudioDataByteSize)
196 // The AudioQueue API may use a large internal buffer and repeatedly call us
197 // back to back once that internal buffer is filled. When this happens the
198 // renderer client does not have enough time to read data back from the
199 // shared memory before the next write comes along. If HandleInputBuffer()
200 // is called too frequently, Sleep() to simulate realtime input and ensure
201 // the shared memory doesn't get trampled.
202 // TODO(dalecurtis): This is a HACK. Long term the AudioQueue path is going
203 // away in favor of the AudioUnit based AUAudioInputStream(). Tracked by
204 // http://crbug.com/161383
205 base::TimeDelta elapsed = base::Time::Now() - last_fill_;
206 base::TimeDelta buffer_length = base::TimeDelta::FromMilliseconds(
207 audio_buffer->mAudioDataByteSize * base::Time::kMillisecondsPerSecond /
208 static_cast<float>(format_.mBytesPerFrame * format_.mSampleRate));
209 if (elapsed < buffer_length)
210 base::PlatformThread::Sleep(buffer_length - elapsed);
211
212 callback_->OnData(this, 196 callback_->OnData(this,
213 reinterpret_cast<const uint8*>(audio_buffer->mAudioData), 197 reinterpret_cast<const uint8*>(audio_buffer->mAudioData),
214 audio_buffer->mAudioDataByteSize, 198 audio_buffer->mAudioDataByteSize,
215 audio_buffer->mAudioDataByteSize, 199 audio_buffer->mAudioDataByteSize,
216 0.0); 200 0.0);
217
218 last_fill_ = base::Time::Now();
219 }
220 // Recycle the buffer. 201 // Recycle the buffer.
221 OSStatus err = QueueNextBuffer(audio_buffer); 202 OSStatus err = QueueNextBuffer(audio_buffer);
222 if (err != noErr) { 203 if (err != noErr) {
223 if (err == kAudioQueueErr_EnqueueDuringReset) { 204 if (err == kAudioQueueErr_EnqueueDuringReset) {
224 // This is the error you get if you try to enqueue a buffer and the 205 // This is the error you get if you try to enqueue a buffer and the
225 // queue has been closed. Not really a problem if indeed the queue 206 // queue has been closed. Not really a problem if indeed the queue
226 // has been closed. 207 // has been closed.
227 // TODO(joth): PCMQueueOutAudioOutputStream uses callback_ to provide an 208 // TODO(joth): PCMQueueOutAudioOutputStream uses callback_ to provide an
228 // extra guard for this situation, but it seems to introduce more 209 // extra guard for this situation, but it seems to introduce more
229 // complications than it solves (memory barrier issues accessing it from 210 // complications than it solves (memory barrier issues accessing it from
230 // multiple threads, looses the means to indicate OnClosed to client). 211 // multiple threads, looses the means to indicate OnClosed to client).
231 // Should determine if we need to do something equivalent here. 212 // Should determine if we need to do something equivalent here.
232 return; 213 return;
233 } 214 }
234 HandleError(err); 215 HandleError(err);
235 } 216 }
236 } 217 }
237 218
238 } // namespace media 219 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/mac/audio_input_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698