diff options
author | wjia@google.com <wjia@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-08 20:58:46 +0000 |
---|---|---|
committer | wjia@google.com <wjia@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-08 20:58:46 +0000 |
commit | e25f4d7436f1ecb7a75b555d25e10ae77555aef7 (patch) | |
tree | dbe9e1ac201d663cb5c78eaa5afee5992a4820a1 /content/renderer/media | |
parent | 70c8099bd6a3beb917a5e8f37a4da08d0fbb9e0c (diff) | |
download | chromium_src-e25f4d7436f1ecb7a75b555d25e10ae77555aef7.zip chromium_src-e25f4d7436f1ecb7a75b555d25e10ae77555aef7.tar.gz chromium_src-e25f4d7436f1ecb7a75b555d25e10ae77555aef7.tar.bz2 |
create one video capture message filter per renderer process
BUG=none
TEST=try bots
Review URL: http://codereview.chromium.org/7058055
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88396 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer/media')
-rw-r--r-- | content/renderer/media/video_capture_impl.cc | 21 | ||||
-rw-r--r-- | content/renderer/media/video_capture_impl.h | 1 | ||||
-rw-r--r-- | content/renderer/media/video_capture_impl_manager.cc | 37 | ||||
-rw-r--r-- | content/renderer/media/video_capture_impl_unittest.cc | 30 |
4 files changed, 35 insertions, 54 deletions
diff --git a/content/renderer/media/video_capture_impl.cc b/content/renderer/media/video_capture_impl.cc index da02e2f..aed3ef7 100644 --- a/content/renderer/media/video_capture_impl.cc +++ b/content/renderer/media/video_capture_impl.cc @@ -68,7 +68,7 @@ void VideoCaptureImpl::Init() { void VideoCaptureImpl::DeInit(Task* task) { if (state_ == kStarted) - message_filter_->Send(new VideoCaptureHostMsg_Stop(0, device_id_)); + Send(new VideoCaptureHostMsg_Stop(0, device_id_)); base::MessageLoopProxy* io_message_loop_proxy = ChildProcess::current()->io_message_loop_proxy(); @@ -229,8 +229,7 @@ void VideoCaptureImpl::OnBufferReceived(TransportDIB::Handle handle, } if (state_ != kStarted) { - message_filter_->Send( - new VideoCaptureHostMsg_BufferReady(0, device_id_, handle)); + Send(new VideoCaptureHostMsg_BufferReady(0, device_id_, handle)); return; } @@ -259,8 +258,7 @@ void VideoCaptureImpl::OnBufferReceived(TransportDIB::Handle handle, it->first->OnBufferReady(this, buffer); } - message_filter_->Send( - new VideoCaptureHostMsg_BufferReady(0, device_id_, handle)); + Send(new VideoCaptureHostMsg_BufferReady(0, device_id_, handle)); } void VideoCaptureImpl::OnStateChanged( @@ -342,7 +340,7 @@ void VideoCaptureImpl::StopDevice() { if (state_ == kStarted) { state_ = kStopping; - message_filter_->Send(new VideoCaptureHostMsg_Stop(0, device_id_)); + Send(new VideoCaptureHostMsg_Stop(0, device_id_)); width_ = height_ = 0; } } @@ -369,7 +367,7 @@ void VideoCaptureImpl::StartCaptureInternal() { params.height = height_; params.session_id = session_id_; - message_filter_->Send(new VideoCaptureHostMsg_Start(0, device_id_, params)); + Send(new VideoCaptureHostMsg_Start(0, device_id_, params)); state_ = kStarted; for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); it++) { it->first->OnStarted(this); @@ -384,3 +382,12 @@ void VideoCaptureImpl::RemoveDelegateOnIOThread(Task* task) { base::ScopedTaskRunner task_runner(task); message_filter_->RemoveDelegate(this); } + +void VideoCaptureImpl::Send(IPC::Message* message) { + base::MessageLoopProxy* io_message_loop_proxy = + ChildProcess::current()->io_message_loop_proxy(); + + io_message_loop_proxy->PostTask(FROM_HERE, + NewRunnableMethod(message_filter_.get(), + &VideoCaptureMessageFilter::Send, message)); +} diff --git a/content/renderer/media/video_capture_impl.h b/content/renderer/media/video_capture_impl.h index 68549ef..fd4750c 100644 --- a/content/renderer/media/video_capture_impl.h +++ b/content/renderer/media/video_capture_impl.h @@ -76,6 +76,7 @@ class VideoCaptureImpl void StartCaptureInternal(); void AddDelegateOnIOThread(); void RemoveDelegateOnIOThread(Task* task); + virtual void Send(IPC::Message* message); scoped_refptr<VideoCaptureMessageFilter> message_filter_; media::VideoCaptureSessionId session_id_; diff --git a/content/renderer/media/video_capture_impl_manager.cc b/content/renderer/media/video_capture_impl_manager.cc index b8611a6..9985d75 100644 --- a/content/renderer/media/video_capture_impl_manager.cc +++ b/content/renderer/media/video_capture_impl_manager.cc @@ -5,44 +5,9 @@ #include "content/renderer/media/video_capture_impl_manager.h" #include "base/memory/singleton.h" -#include "content/common/child_process.h" -#include "content/common/child_thread.h" -#include "content/common/video_capture_messages.h" -#include "content/common/view_messages.h" +#include "content/renderer/video_capture_message_filter_creator.h" #include "media/base/message_loop_factory_impl.h" -namespace { - -// VideoCaptureMessageFilterCreator is to be used as a singleton so we can get -// access to a shared VideoCaptureMessageFilter. -// Example usage: -// VideoCaptureMessageFilter* filter = -// VideoCaptureMessageFilterCreator::SharedFilter(); - -class VideoCaptureMessageFilterCreator { - public: - VideoCaptureMessageFilterCreator() { - int routing_id; - ChildThread::current()->Send( - new ViewHostMsg_GenerateRoutingID(&routing_id)); - filter_ = new VideoCaptureMessageFilter(routing_id); - filter_->AddFilter(); - } - - static VideoCaptureMessageFilter* SharedFilter() { - return GetInstance()->filter_.get(); - } - - static VideoCaptureMessageFilterCreator* GetInstance() { - return Singleton<VideoCaptureMessageFilterCreator>::get(); - } - - private: - scoped_refptr<VideoCaptureMessageFilter> filter_; -}; - -} // namespace - VideoCaptureImplManager::VideoCaptureImplManager() { ml_factory_.reset(new media::MessageLoopFactoryImpl()); ml_proxy_ = ml_factory_->GetMessageLoopProxy("VC manager"); diff --git a/content/renderer/media/video_capture_impl_unittest.cc b/content/renderer/media/video_capture_impl_unittest.cc index e3db8b6..b513425 100644 --- a/content/renderer/media/video_capture_impl_unittest.cc +++ b/content/renderer/media/video_capture_impl_unittest.cc @@ -13,9 +13,8 @@ using ::testing::Return; #define DEFAULT_CAPABILITY {176, 144, 30, 0, media::VideoFrame::I420, \ false, false } -ACTION_P(DeleteMessage, return_value) { +ACTION(DeleteMessage) { delete arg0; - return return_value; } class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter { @@ -25,7 +24,6 @@ class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter { // Filter implementation. MOCK_METHOD1(Send, bool(IPC::Message* message)); - MOCK_METHOD0(ReadyToSend, bool()); private: DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureMessageFilter); @@ -54,6 +52,18 @@ class MockVideoCaptureClient : public media::VideoCapture::EventHandler { class VideoCaptureImplTest : public ::testing::Test { public: + class MockVideoCaptureImpl : public VideoCaptureImpl { + public: + MockVideoCaptureImpl(const media::VideoCaptureSessionId id, + scoped_refptr<base::MessageLoopProxy> ml_proxy, + VideoCaptureMessageFilter* filter) + : VideoCaptureImpl(id, ml_proxy, filter) { + } + virtual ~MockVideoCaptureImpl() {} + + MOCK_METHOD1(Send, void(IPC::Message* message)); + }; + VideoCaptureImplTest() { message_loop_.reset(new MessageLoop(MessageLoop::TYPE_IO)); message_loop_proxy_ = @@ -62,8 +72,9 @@ class VideoCaptureImplTest : public ::testing::Test { message_filter_ = new MockVideoCaptureMessageFilter; session_id_ = 1; - video_capture_impl_ = new VideoCaptureImpl(session_id_, message_loop_proxy_, - message_filter_); + video_capture_impl_ = new MockVideoCaptureImpl(session_id_, + message_loop_proxy_, + message_filter_); video_capture_impl_->device_id_ = 2; } @@ -77,7 +88,7 @@ class VideoCaptureImplTest : public ::testing::Test { scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; scoped_refptr<MockVideoCaptureMessageFilter> message_filter_; media::VideoCaptureSessionId session_id_; - VideoCaptureImpl* video_capture_impl_; + MockVideoCaptureImpl* video_capture_impl_; private: DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplTest); @@ -89,11 +100,8 @@ TEST_F(VideoCaptureImplTest, Simple) { scoped_ptr<MockVideoCaptureClient> client(new MockVideoCaptureClient); media::VideoCapture::VideoCaptureCapability capability = DEFAULT_CAPABILITY; - EXPECT_CALL(*message_filter_, Send(_)) - .WillRepeatedly(DeleteMessage(true)); - - EXPECT_CALL(*message_filter_, ReadyToSend()) - .WillRepeatedly(Return(true)); + EXPECT_CALL(*video_capture_impl_, Send(_)) + .WillRepeatedly(DeleteMessage()); EXPECT_CALL(*client, OnStarted(_)) .WillOnce(Return()); |