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

Unified Diff: content/renderer/media/audio_input_message_filter.cc

Issue 12383016: Merge AssociateStreamWithProducer message into CreateStream message for both audio output and input. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments. Created 7 years, 9 months 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/audio_input_message_filter.cc
diff --git a/content/renderer/media/audio_input_message_filter.cc b/content/renderer/media/audio_input_message_filter.cc
index 58dcc2ec7a06e789bec9d398a3f906e7f8fbad09..f85ff31d1f9446be9a996e15b2bc253fe3049c48 100644
--- a/content/renderer/media/audio_input_message_filter.cc
+++ b/content/renderer/media/audio_input_message_filter.cc
@@ -11,24 +11,43 @@
namespace content {
-AudioInputMessageFilter* AudioInputMessageFilter::filter_ = NULL;
+namespace {
+const int kStreamIDNotSet = -1;
+}
+
+class AudioInputMessageFilter::AudioInputIPCImpl
+ : public NON_EXPORTED_BASE(media::AudioInputIPC) {
+ public:
+ AudioInputIPCImpl(const scoped_refptr<AudioInputMessageFilter>& filter,
+ int render_view_id);
+ virtual ~AudioInputIPCImpl();
+
+ // media::AudioInputIPC implementation.
+ virtual void CreateStream(media::AudioInputIPCDelegate* delegate,
+ const media::AudioParameters& params,
+ const std::string& device_id,
+ bool automatic_gain_control) OVERRIDE;
+ virtual void StartDevice(media::AudioInputIPCDelegate* delegate,
+ int session_id) OVERRIDE;
+ virtual void RecordStream() OVERRIDE;
+ virtual void SetVolume(double volume) OVERRIDE;
+ virtual void CloseStream() OVERRIDE;
+
+ private:
+ const scoped_refptr<AudioInputMessageFilter> filter_;
+ const int render_view_id_;
+ int stream_id_;
+};
AudioInputMessageFilter::AudioInputMessageFilter(
const scoped_refptr<base::MessageLoopProxy>& io_message_loop)
: channel_(NULL),
- io_message_loop_(io_message_loop) {
- DCHECK(!filter_);
- filter_ = this;
-}
+ io_message_loop_(io_message_loop) {}
AudioInputMessageFilter::~AudioInputMessageFilter() {
- DCHECK_EQ(filter_, this);
- filter_ = NULL;
-}
-
-// static.
-AudioInputMessageFilter* AudioInputMessageFilter::Get() {
- return filter_;
+ // Safe on any thread since a ref-count of zero implies no concurrent access
+ // is possible:
+ CHECK(delegates_.IsEmpty());
DaleCurtis 2013/03/07 21:02:58 This may be safe, but will fail the DCHECK(CalledO
miu 2013/04/16 00:07:36 Oh, duh. I was looking at the IDMap code and saw
}
void AudioInputMessageFilter::Send(IPC::Message* message) {
@@ -146,45 +165,70 @@ void AudioInputMessageFilter::OnDeviceStarted(int stream_id,
delegate->OnDeviceReady(device_id);
}
-int AudioInputMessageFilter::AddDelegate(
- media::AudioInputIPCDelegate* delegate) {
- DCHECK(io_message_loop_->BelongsToCurrentThread());
- return delegates_.Add(delegate);
-}
+AudioInputMessageFilter::AudioInputIPCImpl::AudioInputIPCImpl(
+ const scoped_refptr<AudioInputMessageFilter>& filter, int render_view_id)
+ : filter_(filter),
+ render_view_id_(render_view_id),
+ stream_id_(kStreamIDNotSet) {}
-void AudioInputMessageFilter::RemoveDelegate(int id) {
- DCHECK(io_message_loop_->BelongsToCurrentThread());
- delegates_.Remove(id);
-}
+AudioInputMessageFilter::AudioInputIPCImpl::~AudioInputIPCImpl() {}
-void AudioInputMessageFilter::CreateStream(int stream_id,
- const media::AudioParameters& params,
- const std::string& device_id,
- bool automatic_gain_control) {
- Send(new AudioInputHostMsg_CreateStream(
- stream_id, params, device_id, automatic_gain_control));
+scoped_ptr<media::AudioInputIPC> AudioInputMessageFilter::CreateAudioInputIPC(
+ int render_view_id) {
+ DCHECK_GT(render_view_id, 0);
+ return scoped_ptr<media::AudioInputIPC>(
+ new AudioInputIPCImpl(this, render_view_id));
}
-void AudioInputMessageFilter::AssociateStreamWithConsumer(int stream_id,
- int render_view_id) {
- Send(new AudioInputHostMsg_AssociateStreamWithConsumer(
- stream_id, render_view_id));
+void AudioInputMessageFilter::AudioInputIPCImpl::CreateStream(
+ media::AudioInputIPCDelegate* delegate,
+ const media::AudioParameters& params,
+ const std::string& device_id,
+ bool automatic_gain_control) {
+ DCHECK(filter_->io_message_loop_->BelongsToCurrentThread());
+ DCHECK(delegate);
+
+ // TODO(miu): This ugliness is due to the "start device" then "create stream"
+ // hacking that's been done for audio input. Major IPC/impl clean-up is
+ // needed here. http://crbug.com/179597.
+ if (stream_id_ == kStreamIDNotSet) {
+ stream_id_ = filter_->delegates_.Add(delegate);
+ } else {
+ // Security CHECK, not a DCHECK, since using the StartDevice() path requires
+ // that permissions are obtained in the browser process. This confirms the
+ // delegate that called StartDevice() is the same one doing the CreateStream
+ // operation here.
+ CHECK_EQ(delegate, filter_->delegates_.Lookup(stream_id_));
+ }
+ filter_->Send(new AudioInputHostMsg_CreateStream(
+ stream_id_, render_view_id_, params, device_id, automatic_gain_control));
}
-void AudioInputMessageFilter::StartDevice(int stream_id, int session_id) {
- Send(new AudioInputHostMsg_StartDevice(stream_id, session_id));
+void AudioInputMessageFilter::AudioInputIPCImpl::StartDevice(
+ media::AudioInputIPCDelegate* delegate,
+ int session_id) {
+ DCHECK(delegate);
+ DCHECK_EQ(stream_id_, kStreamIDNotSet);
+ stream_id_ = filter_->delegates_.Add(delegate);
+ filter_->Send(new AudioInputHostMsg_StartDevice(stream_id_, session_id));
}
-void AudioInputMessageFilter::RecordStream(int stream_id) {
- Send(new AudioInputHostMsg_RecordStream(stream_id));
+void AudioInputMessageFilter::AudioInputIPCImpl::RecordStream() {
+ DCHECK_NE(stream_id_, kStreamIDNotSet);
DaleCurtis 2013/03/07 21:02:58 Instead of DCHECK should these methods just fire a
miu 2013/04/16 00:07:36 Same thing, right? (see base/logging.h:752)
+ filter_->Send(new AudioInputHostMsg_RecordStream(stream_id_));
}
-void AudioInputMessageFilter::CloseStream(int stream_id) {
- Send(new AudioInputHostMsg_CloseStream(stream_id));
+void AudioInputMessageFilter::AudioInputIPCImpl::SetVolume(double volume) {
+ DCHECK_NE(stream_id_, kStreamIDNotSet);
+ filter_->Send(new AudioInputHostMsg_SetVolume(stream_id_, volume));
}
-void AudioInputMessageFilter::SetVolume(int stream_id, double volume) {
- Send(new AudioInputHostMsg_SetVolume(stream_id, volume));
+void AudioInputMessageFilter::AudioInputIPCImpl::CloseStream() {
+ DCHECK(filter_->io_message_loop_->BelongsToCurrentThread());
+ DCHECK_NE(stream_id_, kStreamIDNotSet);
+ filter_->Send(new AudioInputHostMsg_CloseStream(stream_id_));
+ filter_->delegates_.Remove(stream_id_);
+ stream_id_ = kStreamIDNotSet;
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698