Index: content/renderer/pepper/pepper_platform_audio_input_impl.cc |
diff --git a/content/renderer/pepper/pepper_platform_audio_input_impl.cc b/content/renderer/pepper/pepper_platform_audio_input_impl.cc |
index d9d73263d86fbcbf3cd84c7f32b22de06cf016c4..d1bdf553a4aa1b4225aca75125303eb59a8a2be5 100644 |
--- a/content/renderer/pepper/pepper_platform_audio_input_impl.cc |
+++ b/content/renderer/pepper/pepper_platform_audio_input_impl.cc |
@@ -9,10 +9,8 @@ |
#include "base/message_loop_proxy.h" |
#include "build/build_config.h" |
#include "content/common/child_process.h" |
-#include "content/common/media/audio_messages.h" |
#include "content/renderer/media/audio_input_message_filter.h" |
#include "content/renderer/pepper/pepper_plugin_delegate_impl.h" |
-#include "content/renderer/render_thread_impl.h" |
#include "media/audio/audio_manager_base.h" |
namespace content { |
@@ -55,6 +53,10 @@ void PepperPlatformAudioInputImpl::StopCapture() { |
void PepperPlatformAudioInputImpl::ShutDown() { |
DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); |
+ // Make sure we don't call shutdown more than once. |
+ if (!client_) |
+ return; |
+ |
// Called on the main thread to stop all audio callbacks. We must only change |
// the client on the main thread, and the delegates from the I/O thread. |
client_ = NULL; |
@@ -77,9 +79,8 @@ void PepperPlatformAudioInputImpl::OnStreamCreated( |
DCHECK(length); |
if (base::MessageLoopProxy::current() != main_message_loop_proxy_) { |
- // No need to check |shutdown_called_| here. If shutdown has occurred, |
- // |client_| will be NULL and the handles will be cleaned up on the main |
- // thread. |
+ // If shutdown has occurred, |client_| will be NULL and the handles will be |
+ // cleaned up on the main thread. |
main_message_loop_proxy_->PostTask( |
FROM_HERE, |
base::Bind(&PepperPlatformAudioInputImpl::OnStreamCreated, this, |
@@ -107,7 +108,7 @@ void PepperPlatformAudioInputImpl::OnDeviceReady(const std::string& device_id) { |
DCHECK(ChildProcess::current()->io_message_loop_proxy()-> |
BelongsToCurrentThread()); |
- if (shutdown_called_) |
+ if (!ipc_) |
return; |
if (device_id.empty()) { |
@@ -117,12 +118,12 @@ void PepperPlatformAudioInputImpl::OnDeviceReady(const std::string& device_id) { |
this)); |
} else { |
// We will be notified by OnStreamCreated(). |
- ipc_->CreateStream(stream_id_, params_, device_id, false); |
+ ipc_->CreateStream(this, params_, device_id, false); |
} |
} |
void PepperPlatformAudioInputImpl::OnIPCClosed() { |
- ipc_ = NULL; |
+ ipc_.reset(); |
} |
PepperPlatformAudioInputImpl::~PepperPlatformAudioInputImpl() { |
@@ -131,19 +132,14 @@ PepperPlatformAudioInputImpl::~PepperPlatformAudioInputImpl() { |
// Although these members should be accessed on a specific thread (either the |
// main thread or the I/O thread), it should be fine to examine their value |
// here. |
- DCHECK_EQ(0, stream_id_); |
+ DCHECK(!ipc_); |
DCHECK(!client_); |
DCHECK(label_.empty()); |
- DCHECK(shutdown_called_); |
} |
PepperPlatformAudioInputImpl::PepperPlatformAudioInputImpl() |
: client_(NULL), |
- stream_id_(0), |
- render_view_id_(MSG_ROUTING_NONE), |
- main_message_loop_proxy_(base::MessageLoopProxy::current()), |
- shutdown_called_(false) { |
- ipc_ = RenderThreadImpl::current()->audio_input_message_filter(); |
+ main_message_loop_proxy_(base::MessageLoopProxy::current()) { |
} |
bool PepperPlatformAudioInputImpl::Initialize( |
@@ -157,8 +153,11 @@ bool PepperPlatformAudioInputImpl::Initialize( |
if (!plugin_delegate || !client) |
return false; |
+ ipc_ = AudioInputMessageFilter::Get()->CreateAudioInputIPC( |
+ plugin_delegate->GetRoutingID()); |
+ CHECK(ipc_); |
+ |
plugin_delegate_ = plugin_delegate; |
- render_view_id_ = plugin_delegate_->GetRoutingID(); |
client_ = client; |
params_.Reset(media::AudioParameters::AUDIO_PCM_LINEAR, |
@@ -185,21 +184,16 @@ void PepperPlatformAudioInputImpl::InitializeOnIOThread(int session_id) { |
DCHECK(ChildProcess::current()->io_message_loop_proxy()-> |
BelongsToCurrentThread()); |
- if (shutdown_called_) |
+ if (!ipc_) |
return; |
- // Make sure we don't call init more than once. |
- DCHECK_EQ(0, stream_id_); |
- stream_id_ = ipc_->AddDelegate(this); |
- DCHECK_NE(0, stream_id_); |
- |
if (!session_id) { |
// We will be notified by OnStreamCreated(). |
- ipc_->CreateStream(stream_id_, params_, |
- media::AudioManagerBase::kDefaultDeviceId, false); |
+ ipc_->CreateStream( |
+ this, params_, media::AudioManagerBase::kDefaultDeviceId, false); |
} else { |
// We will be notified by OnDeviceReady(). |
- ipc_->StartDevice(stream_id_, session_id); |
+ ipc_->StartDevice(this, session_id); |
} |
} |
@@ -207,10 +201,8 @@ void PepperPlatformAudioInputImpl::StartCaptureOnIOThread() { |
DCHECK(ChildProcess::current()->io_message_loop_proxy()-> |
BelongsToCurrentThread()); |
- if (stream_id_) { |
- ipc_->AssociateStreamWithConsumer(stream_id_, render_view_id_); |
- ipc_->RecordStream(stream_id_); |
- } |
+ if (ipc_) |
+ ipc_->RecordStream(); |
} |
void PepperPlatformAudioInputImpl::StopCaptureOnIOThread() { |
@@ -218,24 +210,17 @@ void PepperPlatformAudioInputImpl::StopCaptureOnIOThread() { |
BelongsToCurrentThread()); |
// TODO(yzshen): We cannot re-start capturing if the stream is closed. |
- if (stream_id_) |
- ipc_->CloseStream(stream_id_); |
+ if (ipc_) { |
+ ipc_->CloseStream(); |
+ ipc_.reset(); |
+ } |
} |
void PepperPlatformAudioInputImpl::ShutDownOnIOThread() { |
DCHECK(ChildProcess::current()->io_message_loop_proxy()-> |
BelongsToCurrentThread()); |
- // Make sure we don't call shutdown more than once. |
- if (shutdown_called_) |
- return; |
- shutdown_called_ = true; |
- |
- if (stream_id_) { |
- ipc_->CloseStream(stream_id_); |
- ipc_->RemoveDelegate(stream_id_); |
- stream_id_ = 0; |
- } |
+ StopCaptureOnIOThread(); |
main_message_loop_proxy_->PostTask( |
FROM_HERE, |