| Index: content/renderer/media/audio_renderer_impl.cc
|
| ===================================================================
|
| --- content/renderer/media/audio_renderer_impl.cc (revision 90366)
|
| +++ content/renderer/media/audio_renderer_impl.cc (working copy)
|
| @@ -6,6 +6,7 @@
|
|
|
| #include <math.h>
|
|
|
| +#include "content/common/child_process.h"
|
| #include "content/common/media/audio_messages.h"
|
| #include "content/renderer/render_thread.h"
|
| #include "content/renderer/render_view.h"
|
| @@ -24,19 +25,17 @@
|
|
|
| } // namespace
|
|
|
| -AudioRendererImpl::AudioRendererImpl(AudioMessageFilter* filter)
|
| +AudioRendererImpl::AudioRendererImpl()
|
| : AudioRendererBase(),
|
| bytes_per_second_(0),
|
| - filter_(filter),
|
| stream_id_(0),
|
| shared_memory_(NULL),
|
| shared_memory_size_(0),
|
| - io_loop_(filter->message_loop()),
|
| stopped_(false),
|
| pending_request_(false),
|
| prerolling_(false),
|
| preroll_bytes_(0) {
|
| - DCHECK(io_loop_);
|
| + filter_ = RenderThread::current()->audio_message_filter();
|
| }
|
|
|
| AudioRendererImpl::~AudioRendererImpl() {
|
| @@ -56,7 +55,8 @@
|
|
|
| bytes_per_second_ = params.GetBytesPerSecond();
|
|
|
| - io_loop_->PostTask(FROM_HERE,
|
| + ChildProcess::current()->io_message_loop()->PostTask(
|
| + FROM_HERE,
|
| NewRunnableMethod(this, &AudioRendererImpl::CreateStreamTask, params));
|
| return true;
|
| }
|
| @@ -67,9 +67,8 @@
|
| return;
|
| stopped_ = true;
|
|
|
| - // We should never touch |io_loop_| after being stopped, so post our final
|
| - // task to clean up.
|
| - io_loop_->PostTask(FROM_HERE,
|
| + ChildProcess::current()->io_message_loop()->PostTask(
|
| + FROM_HERE,
|
| NewRunnableMethod(this, &AudioRendererImpl::DestroyTask));
|
| }
|
|
|
| @@ -85,7 +84,8 @@
|
| AudioRendererBase::ConsumeAudioSamples(buffer_in);
|
|
|
| // Post a task to render thread to notify a packet reception.
|
| - io_loop_->PostTask(FROM_HERE,
|
| + ChildProcess::current()->io_message_loop()->PostTask(
|
| + FROM_HERE,
|
| NewRunnableMethod(this, &AudioRendererImpl::NotifyPacketReadyTask));
|
| }
|
|
|
| @@ -93,7 +93,7 @@
|
| DCHECK(rate >= 0.0f);
|
|
|
| base::AutoLock auto_lock(lock_);
|
| - // Handle the case where we stopped due to |io_loop_| dying.
|
| + // Handle the case where we stopped due to IO message loop dying.
|
| if (stopped_) {
|
| AudioRendererBase::SetPlaybackRate(rate);
|
| return;
|
| @@ -103,19 +103,21 @@
|
| // Play: GetPlaybackRate() == 0.0 && rate != 0.0
|
| // Pause: GetPlaybackRate() != 0.0 && rate == 0.0
|
| if (GetPlaybackRate() == 0.0f && rate != 0.0f) {
|
| - io_loop_->PostTask(FROM_HERE,
|
| - NewRunnableMethod(this, &AudioRendererImpl::PlayTask));
|
| + ChildProcess::current()->io_message_loop()->PostTask(
|
| + FROM_HERE,
|
| + NewRunnableMethod(this, &AudioRendererImpl::PlayTask));
|
| } else if (GetPlaybackRate() != 0.0f && rate == 0.0f) {
|
| // Pause is easy, we can always pause.
|
| - io_loop_->PostTask(FROM_HERE,
|
| - NewRunnableMethod(this, &AudioRendererImpl::PauseTask));
|
| + ChildProcess::current()->io_message_loop()->PostTask(
|
| + FROM_HERE,
|
| + NewRunnableMethod(this, &AudioRendererImpl::PauseTask));
|
| }
|
| AudioRendererBase::SetPlaybackRate(rate);
|
|
|
| // If we are playing, give a kick to try fulfilling the packet request as
|
| // the previous packet request may be stalled by a pause.
|
| if (rate > 0.0f) {
|
| - io_loop_->PostTask(
|
| + ChildProcess::current()->io_message_loop()->PostTask(
|
| FROM_HERE,
|
| NewRunnableMethod(this, &AudioRendererImpl::NotifyPacketReadyTask));
|
| }
|
| @@ -127,7 +129,8 @@
|
| if (stopped_)
|
| return;
|
|
|
| - io_loop_->PostTask(FROM_HERE,
|
| + ChildProcess::current()->io_message_loop()->PostTask(
|
| + FROM_HERE,
|
| NewRunnableMethod(this, &AudioRendererImpl::PauseTask));
|
| }
|
|
|
| @@ -138,7 +141,8 @@
|
| if (stopped_)
|
| return;
|
|
|
| - io_loop_->PostTask(FROM_HERE,
|
| + ChildProcess::current()->io_message_loop()->PostTask(
|
| + FROM_HERE,
|
| NewRunnableMethod(this, &AudioRendererImpl::SeekTask));
|
| }
|
|
|
| @@ -150,11 +154,13 @@
|
| return;
|
|
|
| if (GetPlaybackRate() != 0.0f) {
|
| - io_loop_->PostTask(FROM_HERE,
|
| - NewRunnableMethod(this, &AudioRendererImpl::PlayTask));
|
| + ChildProcess::current()->io_message_loop()->PostTask(
|
| + FROM_HERE,
|
| + NewRunnableMethod(this, &AudioRendererImpl::PlayTask));
|
| } else {
|
| - io_loop_->PostTask(FROM_HERE,
|
| - NewRunnableMethod(this, &AudioRendererImpl::PauseTask));
|
| + ChildProcess::current()->io_message_loop()->PostTask(
|
| + FROM_HERE,
|
| + NewRunnableMethod(this, &AudioRendererImpl::PauseTask));
|
| }
|
| }
|
|
|
| @@ -162,14 +168,14 @@
|
| base::AutoLock auto_lock(lock_);
|
| if (stopped_)
|
| return;
|
| - io_loop_->PostTask(FROM_HERE,
|
| - NewRunnableMethod(
|
| - this, &AudioRendererImpl::SetVolumeTask, volume));
|
| + ChildProcess::current()->io_message_loop()->PostTask(
|
| + FROM_HERE,
|
| + NewRunnableMethod(this, &AudioRendererImpl::SetVolumeTask, volume));
|
| }
|
|
|
| void AudioRendererImpl::OnCreated(base::SharedMemoryHandle handle,
|
| uint32 length) {
|
| - DCHECK(MessageLoop::current() == io_loop_);
|
| + DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop());
|
|
|
| base::AutoLock auto_lock(lock_);
|
| if (stopped_)
|
| @@ -187,7 +193,7 @@
|
| }
|
|
|
| void AudioRendererImpl::OnRequestPacket(AudioBuffersState buffers_state) {
|
| - DCHECK(MessageLoop::current() == io_loop_);
|
| + DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop());
|
|
|
| {
|
| base::AutoLock auto_lock(lock_);
|
| @@ -201,7 +207,7 @@
|
| }
|
|
|
| void AudioRendererImpl::OnStateChanged(AudioStreamState state) {
|
| - DCHECK(MessageLoop::current() == io_loop_);
|
| + DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop());
|
|
|
| base::AutoLock auto_lock(lock_);
|
| if (stopped_)
|
| @@ -232,7 +238,7 @@
|
| }
|
|
|
| void AudioRendererImpl::CreateStreamTask(const AudioParameters& audio_params) {
|
| - DCHECK(MessageLoop::current() == io_loop_);
|
| + DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop());
|
|
|
| base::AutoLock auto_lock(lock_);
|
| if (stopped_)
|
| @@ -241,58 +247,57 @@
|
| // Make sure we don't call create more than once.
|
| DCHECK_EQ(0, stream_id_);
|
| stream_id_ = filter_->AddDelegate(this);
|
| - io_loop_->AddDestructionObserver(this);
|
| + ChildProcess::current()->io_message_loop()->AddDestructionObserver(this);
|
|
|
| AudioParameters params_to_send(audio_params);
|
| // Let the browser choose packet size.
|
| params_to_send.samples_per_packet = 0;
|
|
|
| - filter_->Send(new AudioHostMsg_CreateStream(
|
| - 0, stream_id_, params_to_send, false));
|
| + Send(new AudioHostMsg_CreateStream(stream_id_, params_to_send, false));
|
| }
|
|
|
| void AudioRendererImpl::PlayTask() {
|
| - DCHECK(MessageLoop::current() == io_loop_);
|
| + DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop());
|
|
|
| - filter_->Send(new AudioHostMsg_PlayStream(0, stream_id_));
|
| + Send(new AudioHostMsg_PlayStream(stream_id_));
|
| }
|
|
|
| void AudioRendererImpl::PauseTask() {
|
| - DCHECK(MessageLoop::current() == io_loop_);
|
| + DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop());
|
|
|
| - filter_->Send(new AudioHostMsg_PauseStream(0, stream_id_));
|
| + Send(new AudioHostMsg_PauseStream(stream_id_));
|
| }
|
|
|
| void AudioRendererImpl::SeekTask() {
|
| - DCHECK(MessageLoop::current() == io_loop_);
|
| + DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop());
|
|
|
| // We have to pause the audio stream before we can flush.
|
| - filter_->Send(new AudioHostMsg_PauseStream(0, stream_id_));
|
| - filter_->Send(new AudioHostMsg_FlushStream(0, stream_id_));
|
| + Send(new AudioHostMsg_PauseStream(stream_id_));
|
| + Send(new AudioHostMsg_FlushStream(stream_id_));
|
| }
|
|
|
| void AudioRendererImpl::DestroyTask() {
|
| - DCHECK(MessageLoop::current() == io_loop_);
|
| + DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop());
|
|
|
| // Make sure we don't call destroy more than once.
|
| DCHECK_NE(0, stream_id_);
|
| filter_->RemoveDelegate(stream_id_);
|
| - filter_->Send(new AudioHostMsg_CloseStream(0, stream_id_));
|
| - io_loop_->RemoveDestructionObserver(this);
|
| + Send(new AudioHostMsg_CloseStream(stream_id_));
|
| + ChildProcess::current()->io_message_loop()->RemoveDestructionObserver(this);
|
| stream_id_ = 0;
|
| }
|
|
|
| void AudioRendererImpl::SetVolumeTask(double volume) {
|
| - DCHECK(MessageLoop::current() == io_loop_);
|
| + DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop());
|
|
|
| base::AutoLock auto_lock(lock_);
|
| if (stopped_)
|
| return;
|
| - filter_->Send(new AudioHostMsg_SetVolume(0, stream_id_, volume));
|
| + Send(new AudioHostMsg_SetVolume(stream_id_, volume));
|
| }
|
|
|
| void AudioRendererImpl::NotifyPacketReadyTask() {
|
| - DCHECK(MessageLoop::current() == io_loop_);
|
| + DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop());
|
|
|
| base::AutoLock auto_lock(lock_);
|
| if (stopped_)
|
| @@ -331,12 +336,12 @@
|
| request_buffers_state_.pending_bytes == 0);
|
| pending_request_ = false;
|
| // Then tell browser process we are done filling into the buffer.
|
| - filter_->Send(new AudioHostMsg_NotifyPacketReady(0, stream_id_, filled));
|
| + Send(new AudioHostMsg_NotifyPacketReady(stream_id_, filled));
|
| }
|
| }
|
|
|
| void AudioRendererImpl::WillDestroyCurrentMessageLoop() {
|
| - DCHECK(MessageLoop::current() == io_loop_);
|
| + DCHECK(MessageLoop::current() == ChildProcess::current()->io_message_loop());
|
|
|
| // We treat the IO loop going away the same as stopping.
|
| base::AutoLock auto_lock(lock_);
|
| @@ -346,3 +351,7 @@
|
| stopped_ = true;
|
| DestroyTask();
|
| }
|
| +
|
| +void AudioRendererImpl::Send(IPC::Message* message) {
|
| + filter_->Send(message);
|
| +}
|
|
|