Chromium Code Reviews| Index: content/renderer/media/audio_device.cc |
| =================================================================== |
| --- content/renderer/media/audio_device.cc (revision 111890) |
| +++ content/renderer/media/audio_device.cc (working copy) |
| @@ -25,7 +25,8 @@ |
| callback_(callback), |
| audio_delay_milliseconds_(0), |
| volume_(1.0), |
| - stream_id_(0) { |
| + stream_id_(0), |
| + memory_length_(0) { |
| filter_ = RenderThreadImpl::current()->audio_message_filter(); |
| audio_data_.reserve(channels); |
| for (int i = 0; i < channels; ++i) { |
| @@ -56,6 +57,7 @@ |
| } |
| bool AudioDevice::Stop() { |
| + DCHECK(MessageLoop::current() != ChildProcess::current()->io_message_loop()); |
| // Max waiting time for Stop() to complete. If this time limit is passed, |
| // we will stop waiting and return false. It ensures that Stop() can't block |
| // the calling thread forever. |
| @@ -70,15 +72,16 @@ |
| // We wait here for the IO task to be completed to remove race conflicts |
| // with OnLowLatencyCreated() and to ensure that Stop() acts as a synchronous |
| // function call. |
| - if (completion.TimedWait(kMaxTimeOut)) { |
| - if (audio_thread_.get()) { |
| - socket_->Close(); |
| - audio_thread_->Join(); |
| - audio_thread_.reset(NULL); |
| + if (!completion.TimedWait(kMaxTimeOut)) { |
| + LOG(WARNING) << "Failed to shut down audio output on IO thread"; |
|
tommi (sloooow) - chröme
2011/12/01 14:40:45
LOG(ERROR)?
no longer working on chromium
2011/12/02 10:16:30
Done.
|
| + } |
| + |
| + if (audio_thread_.get()) { |
| + { |
| + base::SyncSocket socket(socket_handle_); |
|
henrika (OOO until Aug 14)
2011/12/01 14:57:13
A comment perhaps?
no longer working on chromium
2011/12/02 10:16:30
Done.
|
| } |
| - } else { |
| - LOG(ERROR) << "Failed to shut down audio output on IO thread"; |
| - return false; |
| + audio_thread_->Join(); |
| + audio_thread_.reset(NULL); |
| } |
| return true; |
|
Ami GONE FROM CHROMIUM
2011/12/01 17:25:28
FWIW, this function can't return false anymore aft
no longer working on chromium
2011/12/02 10:16:30
Done.
|
| @@ -176,14 +179,12 @@ |
| return; |
| } |
| - shared_memory_.reset(new base::SharedMemory(handle, false)); |
| - shared_memory_->Map(length); |
| + shared_memory_handle_ = handle; |
| + memory_length_ = length; |
| DCHECK_GE(length, buffer_size_ * sizeof(int16) * channels_); |
| - socket_.reset(new base::SyncSocket(socket_handle)); |
| - // Allow the client to pre-populate the buffer. |
| - FireRenderCallback(); |
| + socket_handle_ = socket_handle; |
| audio_thread_.reset( |
|
tommi (sloooow) - chröme
2011/12/01 14:40:45
maybe we should dcheck at the top that the audio t
no longer working on chromium
2011/12/02 10:16:30
Done.
|
| new base::DelegateSimpleThread(this, "renderer_audio_thread")); |
| @@ -206,21 +207,28 @@ |
| void AudioDevice::Run() { |
| audio_thread_->SetThreadPriority(base::kThreadPriority_RealtimeAudio); |
| + base::SharedMemory shared_memory(shared_memory_handle_, false); |
| + shared_memory.Map(memory_length_); |
| + // Allow the client to pre-populate the buffer. |
| + FireRenderCallback(static_cast<int16*>(shared_memory.memory())); |
|
tommi (sloooow) - chröme
2011/12/01 14:40:45
reinterpret_cast?
no longer working on chromium
2011/12/02 10:16:30
Done.
|
| + |
| + base::SyncSocket socket(socket_handle_); |
| + |
| int pending_data; |
| const int samples_per_ms = static_cast<int>(sample_rate_) / 1000; |
| const int bytes_per_ms = channels_ * (bits_per_sample_ / 8) * samples_per_ms; |
| - while ((sizeof(pending_data) == socket_->Receive(&pending_data, |
| - sizeof(pending_data))) && |
| + while ((sizeof(pending_data) == socket.Receive(&pending_data, |
| + sizeof(pending_data))) && |
| (pending_data >= 0)) { |
| // Convert the number of pending bytes in the render buffer |
| // into milliseconds. |
| audio_delay_milliseconds_ = pending_data / bytes_per_ms; |
| - FireRenderCallback(); |
| + FireRenderCallback(static_cast<int16*>(shared_memory.memory())); |
|
tommi (sloooow) - chröme
2011/12/01 14:40:45
same here
no longer working on chromium
2011/12/02 10:16:30
Done.
|
| } |
| } |
| -void AudioDevice::FireRenderCallback() { |
| +void AudioDevice::FireRenderCallback(int16* data) { |
| TRACE_EVENT0("audio", "AudioDevice::FireRenderCallback"); |
| if (callback_) { |
| @@ -229,7 +237,7 @@ |
| // Interleave, scale, and clip to int16. |
| media::InterleaveFloatToInt16(audio_data_, |
| - static_cast<int16*>(shared_memory_data()), |
| + data, |
| buffer_size_); |
| } |
| } |