Chromium Code Reviews| Index: media/audio/mac/audio_output_mac.cc |
| diff --git a/media/audio/mac/audio_output_mac.cc b/media/audio/mac/audio_output_mac.cc |
| index 7f96735a495d6771b1e027740129cb7dcc95806a..daf84dabac8e7fea8b531f86efc86374f1165f35 100644 |
| --- a/media/audio/mac/audio_output_mac.cc |
| +++ b/media/audio/mac/audio_output_mac.cc |
| @@ -53,7 +53,8 @@ PCMQueueOutAudioOutputStream::PCMQueueOutAudioOutputStream( |
| should_swizzle_(false), |
| should_down_mix_(false), |
| stopped_event_(true /* manual reset */, false /* initial state */), |
| - num_buffers_left_(kNumBuffers) { |
| + num_buffers_left_(kNumBuffers), |
| + audio_bus_(AudioBus::Create(params)) { |
| // We must have a manager. |
| DCHECK(manager_); |
| // A frame is one sample across all channels. In interleaved audio the per |
| @@ -409,11 +410,25 @@ void PCMQueueOutAudioOutputStream::RenderCallback(void* p_this, |
| // Adjust the number of pending bytes by subtracting the amount played. |
| if (!static_cast<AudioQueueUserData*>(buffer->mUserData)->empty_buffer) |
| audio_stream->pending_bytes_ -= buffer->mAudioDataByteSize; |
| + uint32 filled = 0; |
| uint32 capacity = buffer->mAudioDataBytesCapacity; |
| - // TODO(sergeyu): Specify correct hardware delay for AudioBuffersState. |
| - uint32 filled = source->OnMoreData( |
| - reinterpret_cast<uint8*>(buffer->mAudioData), capacity, |
| - AudioBuffersState(audio_stream->pending_bytes_, 0)); |
| + { |
| + // Since RenderCallback may be reentrant, we need to ensure the AudioBus |
| + // we're sharing is safe for this instance. OnMoreData() offers no |
| + // guarantee of thread safety as well. |
| + base::AutoLock lock(audio_stream->audio_bus_lock_); |
|
Chris Rogers
2012/08/28 22:32:05
Please remove lock - it's not necessary from a thr
Chris Rogers
2012/08/28 22:36:39
To elaborate about removing the lock, the audio_bu
DaleCurtis
2012/08/29 04:34:43
Done.
|
| + |
| + AudioBus* audio_bus = audio_stream->audio_bus_.get(); |
| + DCHECK_EQ( |
| + audio_bus->frames() * audio_stream->format_.mBytesPerFrame, capacity); |
| + // TODO(sergeyu): Specify correct hardware delay for AudioBuffersState. |
| + int frames_filled = source->OnMoreData( |
| + audio_bus, AudioBuffersState(audio_stream->pending_bytes_, 0)); |
| + filled = frames_filled * audio_stream->format_.mBytesPerFrame; |
| + audio_bus->ToInterleaved( |
| + frames_filled, audio_stream->format_.mBitsPerChannel / 8, |
| + buffer->mAudioData); |
| + } |
| // In order to keep the callback running, we need to provide a positive amount |
| // of data to the audio queue. To simulate the behavior of Windows, we write |