diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-14 13:51:29 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-14 13:51:29 +0000 |
commit | 4504807dc2c05a12bea92e791e7c2a5a94f4234d (patch) | |
tree | 3579136c154b41f622bbc4380f0e037d3942aa61 /content/renderer/media/video_capture_impl_unittest.cc | |
parent | bc6c00cab62fc382d84df8477e8d82f62df2a4e4 (diff) | |
download | chromium_src-4504807dc2c05a12bea92e791e7c2a5a94f4234d.zip chromium_src-4504807dc2c05a12bea92e791e7c2a5a94f4234d.tar.gz chromium_src-4504807dc2c05a12bea92e791e7c2a5a94f4234d.tar.bz2 |
Eliminate video capture thread in renderer
The main motivation of this change is to remove the video capture thread
in the renderer. All users of a video capture device already handles the
video frame on their thread. There is no need to call the clients with
an additional thread.
Summary of this change:
* Video capture thread eliminated
VideoCaptureImpl now runs on the IO thread. Clients are called on the
IO thread.
* Simplified VideoCaptureImplManager
We still need to keep this object for the purpose of sharing a
VideoCaptureImpl object with multiple clients. It should own these
objects and maintain the usage count. A couple clean up items are done
on this class:
* It doesn't own the video capture thread now.
* It is now a render thread only object.
* It maintains refcount of a VideoCaptureImpl explicitly.
* It is no longer refcounted.
* Clients access it through RenderThreadImpl. Which ensures usage is
on the render thread.
* New VideoCaptureHandle class
Object of this class is returned by VideoCaptureImplManager to give
access to a media::VideoCapture object. It is purely a wrapper and
helps to do refcounting on the render thread.
Testing:
Added unit tests for VideoCaptureImplManager to test refcounting.
Also updated unit test for VideoCaptureImpl due to the threading
changes.
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=244074
Review URL: https://codereview.chromium.org/120893002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244687 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer/media/video_capture_impl_unittest.cc')
-rw-r--r-- | content/renderer/media/video_capture_impl_unittest.cc | 198 |
1 files changed, 62 insertions, 136 deletions
diff --git a/content/renderer/media/video_capture_impl_unittest.cc b/content/renderer/media/video_capture_impl_unittest.cc index 713b3a0..2c9c75a 100644 --- a/content/renderer/media/video_capture_impl_unittest.cc +++ b/content/renderer/media/video_capture_impl_unittest.cc @@ -3,15 +3,18 @@ // found in the LICENSE file. #include "base/message_loop/message_loop.h" +#include "base/run_loop.h" #include "content/child/child_process.h" #include "content/common/media/video_capture_messages.h" #include "content/renderer/media/video_capture_impl.h" +#include "media/base/bind_to_current_loop.h" +#include "media/video/capture/mock_video_capture_event_handler.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" using ::testing::_; using ::testing::AtLeast; -using ::testing::Return; +using media::MockVideoCaptureEventHandler; namespace content { @@ -29,36 +32,13 @@ class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter { DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureMessageFilter); }; -class MockVideoCaptureClient : public media::VideoCapture::EventHandler { - public: - MockVideoCaptureClient() {} - virtual ~MockVideoCaptureClient() {} - - // EventHandler implementation. - MOCK_METHOD1(OnStarted, void(media::VideoCapture* capture)); - MOCK_METHOD1(OnStopped, void(media::VideoCapture* capture)); - MOCK_METHOD1(OnPaused, void(media::VideoCapture* capture)); - MOCK_METHOD2(OnError, void(media::VideoCapture* capture, int error_code)); - MOCK_METHOD1(OnRemoved, void(media::VideoCapture* capture)); - MOCK_METHOD2(OnFrameReady, - void(media::VideoCapture* capture, - const scoped_refptr<media::VideoFrame>& frame)); - MOCK_METHOD2(OnDeviceInfoReceived, - void(media::VideoCapture* capture, - const media::VideoCaptureFormat& device_info)); - - private: - DISALLOW_COPY_AND_ASSIGN(MockVideoCaptureClient); -}; - 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.get(), filter) {} + : VideoCaptureImpl(id, filter) {} virtual ~MockVideoCaptureImpl() {} // Override Send() to mimic device to send events. @@ -102,15 +82,13 @@ class VideoCaptureImplTest : public ::testing::Test { params_large_.requested_format = media::VideoCaptureFormat( gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); - message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_IO)); - message_loop_proxy_ = base::MessageLoopProxy::current().get(); child_process_.reset(new ChildProcess()); message_filter_ = new MockVideoCaptureMessageFilter; session_id_ = 1; video_capture_impl_ = new MockVideoCaptureImpl( - session_id_, message_loop_proxy_, message_filter_.get()); + session_id_, message_filter_.get()); video_capture_impl_->device_id_ = 2; } @@ -120,8 +98,8 @@ class VideoCaptureImplTest : public ::testing::Test { } protected: - scoped_ptr<base::MessageLoop> message_loop_; - scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; + base::MessageLoop message_loop_; + base::RunLoop run_loop_; scoped_ptr<ChildProcess> child_process_; scoped_refptr<MockVideoCaptureMessageFilter> message_filter_; media::VideoCaptureSessionId session_id_; @@ -135,141 +113,89 @@ class VideoCaptureImplTest : public ::testing::Test { TEST_F(VideoCaptureImplTest, Simple) { // Execute SetCapture() and StopCapture() for one client. - scoped_ptr<MockVideoCaptureClient> client(new MockVideoCaptureClient); + scoped_ptr<MockVideoCaptureEventHandler> client( + new MockVideoCaptureEventHandler); - EXPECT_CALL(*client, OnStarted(_)) - .WillOnce(Return()); + EXPECT_CALL(*client, OnStarted(_)); + EXPECT_CALL(*client, OnStopped(_)); + EXPECT_CALL(*client, OnRemoved(_)); video_capture_impl_->StartCapture(client.get(), params_small_); - message_loop_->RunUntilIdle(); - - EXPECT_CALL(*client, OnStopped(_)) - .WillOnce(Return()); - EXPECT_CALL(*client, OnRemoved(_)) - .WillOnce(Return()); - video_capture_impl_->StopCapture(client.get()); - message_loop_->RunUntilIdle(); + video_capture_impl_->DeInit( + media::BindToCurrentLoop(run_loop_.QuitClosure())); + run_loop_.Run(); } TEST_F(VideoCaptureImplTest, TwoClientsInSequence) { // Execute SetCapture() and StopCapture() for 2 clients in sequence. - scoped_ptr<MockVideoCaptureClient> client(new MockVideoCaptureClient); - - EXPECT_CALL(*client, OnStarted(_)) - .WillOnce(Return()); - - video_capture_impl_->StartCapture(client.get(), params_small_); - message_loop_->RunUntilIdle(); + scoped_ptr<MockVideoCaptureEventHandler> client1( + new MockVideoCaptureEventHandler); + scoped_ptr<MockVideoCaptureEventHandler> client2( + new MockVideoCaptureEventHandler); + + EXPECT_CALL(*client1, OnStarted(_)); + EXPECT_CALL(*client1, OnStopped(_)); + EXPECT_CALL(*client1, OnRemoved(_)); + EXPECT_CALL(*client2, OnStarted(_)); + EXPECT_CALL(*client2, OnStopped(_)); + EXPECT_CALL(*client2, OnRemoved(_)); - EXPECT_CALL(*client, OnStopped(_)) - .WillOnce(Return()); - EXPECT_CALL(*client, OnRemoved(_)) - .WillOnce(Return()); - - video_capture_impl_->StopCapture(client.get()); - message_loop_->RunUntilIdle(); - - EXPECT_CALL(*client, OnStarted(_)) - .WillOnce(Return()); - - video_capture_impl_->StartCapture(client.get(), params_small_); - message_loop_->RunUntilIdle(); - - EXPECT_CALL(*client, OnStopped(_)) - .WillOnce(Return()); - EXPECT_CALL(*client, OnRemoved(_)) - .WillOnce(Return()); - - video_capture_impl_->StopCapture(client.get()); - message_loop_->RunUntilIdle(); + video_capture_impl_->StartCapture(client1.get(), params_small_); + video_capture_impl_->StopCapture(client1.get()); + video_capture_impl_->StartCapture(client2.get(), params_small_); + video_capture_impl_->StopCapture(client2.get()); + video_capture_impl_->DeInit( + media::BindToCurrentLoop(run_loop_.QuitClosure())); + run_loop_.Run(); } TEST_F(VideoCaptureImplTest, LargeAndSmall) { // Execute SetCapture() and StopCapture() for 2 clients simultaneously. // The large client starts first and stops first. - scoped_ptr<MockVideoCaptureClient> client_small(new MockVideoCaptureClient); - scoped_ptr<MockVideoCaptureClient> client_large(new MockVideoCaptureClient); - - EXPECT_CALL(*client_large, OnStarted(_)) - .WillOnce(Return()); - EXPECT_CALL(*client_small, OnStarted(_)) - .WillOnce(Return()); + scoped_ptr<MockVideoCaptureEventHandler> client_small( + new MockVideoCaptureEventHandler); + scoped_ptr<MockVideoCaptureEventHandler> client_large( + new MockVideoCaptureEventHandler); + + EXPECT_CALL(*client_large, OnStarted(_)); + EXPECT_CALL(*client_small, OnStarted(_)); + EXPECT_CALL(*client_large, OnStopped(_)); + EXPECT_CALL(*client_large, OnRemoved(_)); + EXPECT_CALL(*client_small, OnStopped(_)); + EXPECT_CALL(*client_small, OnRemoved(_)); video_capture_impl_->StartCapture(client_large.get(), params_large_); video_capture_impl_->StartCapture(client_small.get(), params_small_); - message_loop_->RunUntilIdle(); - - EXPECT_CALL(*client_large, OnStopped(_)) - .WillOnce(Return()); - EXPECT_CALL(*client_large, OnRemoved(_)) - .WillOnce(Return()); - EXPECT_CALL(*client_small, OnStopped(_)) - .WillOnce(Return()); - EXPECT_CALL(*client_small, OnRemoved(_)) - .WillOnce(Return()); - video_capture_impl_->StopCapture(client_large.get()); video_capture_impl_->StopCapture(client_small.get()); - message_loop_->RunUntilIdle(); + video_capture_impl_->DeInit( + media::BindToCurrentLoop(run_loop_.QuitClosure())); + run_loop_.Run(); } TEST_F(VideoCaptureImplTest, SmallAndLarge) { // Execute SetCapture() and StopCapture() for 2 clients simultaneously. // The small client starts first and stops first. - scoped_ptr<MockVideoCaptureClient> client_small(new MockVideoCaptureClient); - scoped_ptr<MockVideoCaptureClient> client_large(new MockVideoCaptureClient); - - EXPECT_CALL(*client_large, OnStarted(_)) - .WillOnce(Return()); - EXPECT_CALL(*client_small, OnStarted(_)) - .WillOnce(Return()); + scoped_ptr<MockVideoCaptureEventHandler> client_small( + new MockVideoCaptureEventHandler); + scoped_ptr<MockVideoCaptureEventHandler> client_large( + new MockVideoCaptureEventHandler); + + EXPECT_CALL(*client_small, OnStarted(_)); + EXPECT_CALL(*client_large, OnStarted(_)); + EXPECT_CALL(*client_small, OnStopped(_)); + EXPECT_CALL(*client_small, OnRemoved(_)); + EXPECT_CALL(*client_large, OnStopped(_)); + EXPECT_CALL(*client_large, OnRemoved(_)); video_capture_impl_->StartCapture(client_small.get(), params_small_); video_capture_impl_->StartCapture(client_large.get(), params_large_); - message_loop_->RunUntilIdle(); - - EXPECT_CALL(*client_large, OnStopped(_)) - .WillOnce(Return()); - EXPECT_CALL(*client_large, OnRemoved(_)) - .WillOnce(Return()); - EXPECT_CALL(*client_small, OnStopped(_)) - .WillOnce(Return()); - EXPECT_CALL(*client_small, OnRemoved(_)) - .WillOnce(Return()); - video_capture_impl_->StopCapture(client_small.get()); video_capture_impl_->StopCapture(client_large.get()); - message_loop_->RunUntilIdle(); -} - -TEST_F(VideoCaptureImplTest, TwoClientsWithSameSize) { - // Execute SetCapture() and StopCapture() for 2 clients simultaneously. - // The client1 starts first and stops first. - scoped_ptr<MockVideoCaptureClient> client1(new MockVideoCaptureClient); - scoped_ptr<MockVideoCaptureClient> client2(new MockVideoCaptureClient); - - EXPECT_CALL(*client1, OnStarted(_)) - .WillOnce(Return()); - EXPECT_CALL(*client2, OnStarted(_)) - .WillOnce(Return()); - - video_capture_impl_->StartCapture(client1.get(), params_small_); - video_capture_impl_->StartCapture(client2.get(), params_small_); - message_loop_->RunUntilIdle(); - - EXPECT_CALL(*client1, OnStopped(_)) - .WillOnce(Return()); - EXPECT_CALL(*client1, OnRemoved(_)) - .WillOnce(Return()); - EXPECT_CALL(*client2, OnStopped(_)) - .WillOnce(Return()); - EXPECT_CALL(*client2, OnRemoved(_)) - .WillOnce(Return()); - - video_capture_impl_->StopCapture(client1.get()); - video_capture_impl_->StopCapture(client2.get()); - message_loop_->RunUntilIdle(); + video_capture_impl_->DeInit( + media::BindToCurrentLoop(run_loop_.QuitClosure())); + run_loop_.Run(); } } // namespace content |