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

Unified Diff: content/browser/renderer_host/media/video_capture_controller_unittest.cc

Issue 23551011: From Video Capture, abolish OnFrameInfo and enable resolution changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix constant declaration issue. Created 7 years, 2 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/browser/renderer_host/media/video_capture_controller_unittest.cc
diff --git a/content/browser/renderer_host/media/video_capture_controller_unittest.cc b/content/browser/renderer_host/media/video_capture_controller_unittest.cc
index 1bb4c20f0ac611790a3a89f1c743685a1533c81d..7d3a7da03caf1e1c077b59411789cf11ba7cffd1 100644
--- a/content/browser/renderer_host/media/video_capture_controller_unittest.cc
+++ b/content/browser/renderer_host/media/video_capture_controller_unittest.cc
@@ -40,8 +40,8 @@ class MockVideoCaptureControllerEventHandler
// These mock methods are delegated to by our fake implementation of
// VideoCaptureControllerEventHandler, to be used in EXPECT_CALL().
MOCK_METHOD1(DoBufferCreated, void(const VideoCaptureControllerID&));
+ MOCK_METHOD1(DoBufferDestroyed, void(const VideoCaptureControllerID&));
MOCK_METHOD1(DoBufferReady, void(const VideoCaptureControllerID&));
- MOCK_METHOD1(DoFrameInfo, void(const VideoCaptureControllerID&));
MOCK_METHOD1(DoEnded, void(const VideoCaptureControllerID&));
MOCK_METHOD1(DoError, void(const VideoCaptureControllerID&));
@@ -53,19 +53,19 @@ class MockVideoCaptureControllerEventHandler
int length, int buffer_id) OVERRIDE {
DoBufferCreated(id);
}
+ virtual void OnBufferDestroyed(const VideoCaptureControllerID& id,
+ int buffer_id) OVERRIDE {
+ DoBufferDestroyed(id);
+ }
virtual void OnBufferReady(const VideoCaptureControllerID& id,
int buffer_id,
- base::Time timestamp) OVERRIDE {
+ base::Time timestamp,
+ const media::VideoCaptureFormat& format) OVERRIDE {
DoBufferReady(id);
base::MessageLoop::current()->PostTask(FROM_HERE,
base::Bind(&VideoCaptureController::ReturnBuffer,
base::Unretained(controller_), id, this, buffer_id));
}
- virtual void OnFrameInfo(
- const VideoCaptureControllerID& id,
- const media::VideoCaptureCapability& format) OVERRIDE {
- DoFrameInfo(id);
- }
virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE {
DoEnded(id);
// OnEnded() must respond by (eventually) unregistering the client.
@@ -222,6 +222,8 @@ TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) {
media::VideoCaptureParams session_1 = session_100;
session_1.session_id = 1;
+ gfx::Size capture_resolution(444, 200);
+
// The device format needn't match the VideoCaptureParams (the camera can do
// what it wants). Pick something random to use for OnFrameInfo.
media::VideoCaptureCapability device_format(
@@ -238,83 +240,64 @@ TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) {
base::kNullProcessHandle, session_100);
controller_->AddClient(client_b_route_1, client_b_.get(),
base::kNullProcessHandle, session_300);
- ASSERT_EQ(2, controller_->GetClientCount());
+ controller_->AddClient(client_a_route_2, client_a_.get(),
+ base::kNullProcessHandle, session_200);
+ ASSERT_EQ(3, controller_->GetClientCount());
- // The OnFrameInfo() event from the device, when processed by the controller,
- // should generate client OnFrameInfo() and OnBufferCreated() events.
+ // Now, simulate an incoming captured frame from the capture device. As a side
+ // effect this will cause the first buffer to be shared with clients.
+ uint8 frame_no = 1;
+ scoped_refptr<media::VideoFrame> frame;
+ frame = device_->ReserveOutputBuffer(capture_resolution);
+ ASSERT_TRUE(frame);
+ media::FillYUV(frame, frame_no++, 0x22, 0x44);
{
InSequence s;
- EXPECT_CALL(*client_a_, DoFrameInfo(client_a_route_1)).Times(1);
- EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(kPoolSize);
+ EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1);
+ EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1);
}
{
InSequence s;
- EXPECT_CALL(*client_b_, DoFrameInfo(client_b_route_1)).Times(1);
- EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(kPoolSize);
+ EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1);
+ EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1);
}
- device_->OnFrameInfo(device_format);
- base::RunLoop().RunUntilIdle();
- Mock::VerifyAndClearExpectations(client_a_.get());
- Mock::VerifyAndClearExpectations(client_b_.get());
-
- // When a third clients is subsequently added, the frame info and buffers
- // should immediately be shared to the new clients.
{
InSequence s;
- EXPECT_CALL(*client_a_, DoFrameInfo(client_a_route_2)).Times(1);
- EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(kPoolSize);
+ EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1);
+ EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1);
}
- controller_->AddClient(client_a_route_2, client_a_.get(),
- base::kNullProcessHandle, session_200);
- Mock::VerifyAndClearExpectations(client_a_.get());
-
- // Now, simulate an incoming captured frame from the capture device.
- uint8 frame_no = 1;
- scoped_refptr<media::VideoFrame> frame;
- frame = device_->ReserveOutputBuffer();
- ASSERT_TRUE(frame);
- media::FillYUV(frame, frame_no++, 0x22, 0x44);
device_->OnIncomingCapturedVideoFrame(frame, base::Time());
frame = NULL;
- // The buffer should be delivered to the clients in any order.
- EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1);
- EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1);
- EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1);
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(client_a_.get());
Mock::VerifyAndClearExpectations(client_b_.get());
- // Second frame. In this case pretend that the VideoFrame pointer is held
- // by the device for a long delay. This shouldn't affect anything.
- frame = device_->ReserveOutputBuffer();
+ // Second frame which ought to use the same shared memory buffer. In this case
+ // pretend that the VideoFrame pointer is held by the device for a long delay.
+ // This shouldn't affect anything.
+ frame = device_->ReserveOutputBuffer(capture_resolution);
ASSERT_TRUE(frame);
media::FillYUV(frame, frame_no++, 0x22, 0x44);
device_->OnIncomingCapturedVideoFrame(frame, base::Time());
// The buffer should be delivered to the clients in any order.
EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1);
- EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1);
EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1);
+ EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1);
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(client_a_.get());
Mock::VerifyAndClearExpectations(client_b_.get());
frame = NULL;
- // Add a fourth client now that some frames have come through. It should get
- // the buffer info, but it won't get any frames until new ones are captured.
- {
- InSequence s;
- EXPECT_CALL(*client_b_, DoFrameInfo(client_b_route_2)).Times(1);
- EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize);
- }
+ // Add a fourth client now that some frames have come through.
controller_->AddClient(client_b_route_2, client_b_.get(),
base::kNullProcessHandle, session_1);
Mock::VerifyAndClearExpectations(client_b_.get());
// Third, fourth, and fifth frames. Pretend they all arrive at the same time.
for (int i = 0; i < kPoolSize; i++) {
- frame = device_->ReserveOutputBuffer();
+ frame = device_->ReserveOutputBuffer(capture_resolution);
ASSERT_TRUE(frame);
ASSERT_EQ(media::VideoFrame::I420, frame->format());
media::FillYUV(frame, frame_no++, 0x22, 0x44);
@@ -322,11 +305,20 @@ TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) {
}
// ReserveOutputBuffer ought to fail now, because the pool is depleted.
- ASSERT_FALSE(device_->ReserveOutputBuffer());
+ ASSERT_FALSE(device_->ReserveOutputBuffer(capture_resolution));
+
+ // The new client needs to be told of 3 buffers; the old clients only 2.
+ EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize);
+ EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(kPoolSize);
+ EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1))
+ .Times(kPoolSize - 1);
EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(kPoolSize);
+ EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2))
+ .Times(kPoolSize - 1);
EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(kPoolSize);
+ EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1))
+ .Times(kPoolSize - 1);
EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(kPoolSize);
- EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(kPoolSize);
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(client_a_.get());
Mock::VerifyAndClearExpectations(client_b_.get());
@@ -338,11 +330,11 @@ TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) {
EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1);
controller_->StopSession(300);
// Queue up another frame.
- frame = device_->ReserveOutputBuffer();
+ frame = device_->ReserveOutputBuffer(capture_resolution);
ASSERT_TRUE(frame);
media::FillYUV(frame, frame_no++, 0x22, 0x44);
device_->OnIncomingCapturedVideoFrame(frame, base::Time());
- frame = device_->ReserveOutputBuffer();
+ frame = device_->ReserveOutputBuffer(capture_resolution);
{
// Kill A2 via session close (posts a task to disconnect, but A2 must not
// be sent either of these two frames)..
@@ -421,16 +413,14 @@ TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) {
10, 10, 25, media::PIXEL_FORMAT_ARGB, 10, false,
media::ConstantResolutionVideoCaptureDevice);
- // Start the device and get as far as exchanging buffers with the subprocess.
- // Then, signal an error and deliver the frame. The error should be propagated
- // to clients; the frame should not be.
- device_->OnFrameInfo(device_format);
- EXPECT_CALL(*client_a_, DoFrameInfo(route_id)).Times(1);
- EXPECT_CALL(*client_a_, DoBufferCreated(route_id)).Times(kPoolSize);
+ // Start the device. Then, before the first frame, signal an error and deliver
+ // the frame. The error should be propagated to clients; the frame should not
+ // be.
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(client_a_.get());
- scoped_refptr<media::VideoFrame> frame = device_->ReserveOutputBuffer();
+ scoped_refptr<media::VideoFrame> frame =
+ device_->ReserveOutputBuffer(gfx::Size(320, 240));
ASSERT_TRUE(frame);
device_->OnError();

Powered by Google App Engine
This is Rietveld 408576698