Index: content/browser/renderer_host/media/video_capture_host_unittest.cc |
diff --git a/content/browser/renderer_host/media/video_capture_host_unittest.cc b/content/browser/renderer_host/media/video_capture_host_unittest.cc |
index 524234182f496bda859b989b7d05c8c3638f9d09..4307e5ff99bc374dd02db3bd96f2584f7e985e87 100644 |
--- a/content/browser/renderer_host/media/video_capture_host_unittest.cc |
+++ b/content/browser/renderer_host/media/video_capture_host_unittest.cc |
@@ -105,17 +105,19 @@ class MockVideoCaptureHost : public VideoCaptureHost { |
MOCK_METHOD4(OnNewBufferCreated, |
void(int device_id, base::SharedMemoryHandle handle, |
int length, int buffer_id)); |
- MOCK_METHOD3(OnBufferFilled, |
- void(int device_id, int buffer_id, base::Time timestamp)); |
+ MOCK_METHOD2(OnBufferFreed, |
+ void(int device_id, int buffer_id)); |
+ MOCK_METHOD4(OnBufferFilled, |
+ void(int device_id, int buffer_id, base::Time timestamp, |
+ const media::VideoCaptureFormat& format)); |
MOCK_METHOD2(OnStateChanged, void(int device_id, VideoCaptureState state)); |
- MOCK_METHOD1(OnDeviceInfo, void(int device_id)); |
// Use class DumpVideo to write I420 video to file. |
void SetDumpVideo(bool enable) { |
dump_video_ = enable; |
} |
- void SetReturnReceviedDibs(bool enable) { |
+ void SetReturnReceivedDibs(bool enable) { |
return_buffers_ = enable; |
} |
@@ -156,9 +158,9 @@ class MockVideoCaptureHost : public VideoCaptureHost { |
bool handled = true; |
IPC_BEGIN_MESSAGE_MAP(MockVideoCaptureHost, *message) |
IPC_MESSAGE_HANDLER(VideoCaptureMsg_NewBuffer, OnNewBufferCreatedDispatch) |
+ IPC_MESSAGE_HANDLER(VideoCaptureMsg_FreeBuffer, OnBufferFreedDispatch) |
IPC_MESSAGE_HANDLER(VideoCaptureMsg_BufferReady, OnBufferFilledDispatch) |
IPC_MESSAGE_HANDLER(VideoCaptureMsg_StateChanged, OnStateChangedDispatch) |
- IPC_MESSAGE_HANDLER(VideoCaptureMsg_DeviceInfo, OnDeviceInfoDispatch) |
IPC_MESSAGE_UNHANDLED(handled = false) |
IPC_END_MESSAGE_MAP() |
EXPECT_TRUE(handled); |
@@ -178,15 +180,35 @@ class MockVideoCaptureHost : public VideoCaptureHost { |
filled_dib_[buffer_id] = dib; |
} |
- void OnBufferFilledDispatch(int device_id, int buffer_id, |
- base::Time timestamp) { |
+ void OnBufferFreedDispatch(int device_id, int buffer_id) { |
+ OnBufferFreed(device_id, buffer_id); |
+ |
+ std::map<int, base::SharedMemory*>::iterator it = |
+ filled_dib_.find(buffer_id); |
+ ASSERT_TRUE(it != filled_dib_.end()); |
+ delete it->second; |
+ filled_dib_.erase(it); |
+ } |
+ |
+ void OnBufferFilledDispatch(int device_id, |
+ int buffer_id, |
+ base::Time timestamp, |
+ const media::VideoCaptureFormat& frame_format) { |
+ base::SharedMemory* dib = filled_dib_[buffer_id]; |
+ ASSERT_TRUE(dib != NULL); |
if (dump_video_) { |
- base::SharedMemory* dib = filled_dib_[buffer_id]; |
- ASSERT_TRUE(dib != NULL); |
+ if (!format_.IsValid()) { |
+ dumper_.StartDump(frame_format.width, frame_format.height); |
+ format_ = frame_format; |
+ } |
+ ASSERT_EQ(format_.width, frame_format.width) |
+ << "Dump format does not handle variable resolution."; |
+ ASSERT_EQ(format_.height, frame_format.height) |
+ << "Dump format does not handle variable resolution.";; |
dumper_.NewVideoFrame(dib->memory()); |
} |
- OnBufferFilled(device_id, buffer_id, timestamp); |
+ OnBufferFilled(device_id, buffer_id, timestamp, frame_format); |
if (return_buffers_) { |
VideoCaptureHost::OnReceiveEmptyBuffer(device_id, buffer_id); |
} |
@@ -196,17 +218,10 @@ class MockVideoCaptureHost : public VideoCaptureHost { |
OnStateChanged(device_id, state); |
} |
- void OnDeviceInfoDispatch(int device_id, |
- media::VideoCaptureParams params) { |
- if (dump_video_) { |
- dumper_.StartDump(params.width, params.height); |
- } |
- OnDeviceInfo(device_id); |
- } |
- |
std::map<int, base::SharedMemory*> filled_dib_; |
bool return_buffers_; |
bool dump_video_; |
+ media::VideoCaptureFormat format_; |
DumpVideo dumper_; |
}; |
@@ -321,20 +336,11 @@ class VideoCaptureHostTest : public testing::Test { |
protected: |
void StartCapture() { |
- InSequence s; |
- // 1. First - get info about the new resolution |
- EXPECT_CALL(*host_, OnDeviceInfo(kDeviceId)); |
- |
- // 2. Change state to started |
- EXPECT_CALL(*host_, OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_STARTED)); |
- |
- // 3. Newly created buffers will arrive. |
EXPECT_CALL(*host_, OnNewBufferCreated(kDeviceId, _, _, _)) |
.Times(AnyNumber()).WillRepeatedly(Return()); |
- // 4. First filled buffer will arrive. |
base::RunLoop run_loop; |
- EXPECT_CALL(*host_, OnBufferFilled(kDeviceId, _, _)) |
+ EXPECT_CALL(*host_, OnBufferFilled(kDeviceId, _, _, _)) |
.Times(AnyNumber()).WillOnce(ExitMessageLoop( |
message_loop_, run_loop.QuitClosure())); |
@@ -366,15 +372,11 @@ class VideoCaptureHostTest : public testing::Test { |
#ifdef DUMP_VIDEO |
void CaptureAndDumpVideo(int width, int height, int frame_rate) { |
InSequence s; |
- // 1. First - get info about the new resolution |
- EXPECT_CALL(*host_, OnDeviceInfo(kDeviceId)); |
- |
- // 2. Change state to started |
- EXPECT_CALL(*host_, OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_STARTED)); |
+ EXPECT_CALL(*host_.get(), OnNewBufferCreated(kDeviceId, _, _, _)) |
+ .Times(AnyNumber()).WillRepeatedly(Return()); |
- // 3. First filled buffer will arrive. |
base::RunLoop run_loop; |
- EXPECT_CALL(*host_, OnBufferFilled(kDeviceId, _, _)) |
+ EXPECT_CALL(*host_, OnBufferFilled(kDeviceId, _, _, _)) |
.Times(AnyNumber()) |
.WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure())); |
@@ -395,19 +397,19 @@ class VideoCaptureHostTest : public testing::Test { |
.WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure())); |
host_->OnStopCapture(kDeviceId); |
- host_->SetReturnReceviedDibs(true); |
+ host_->SetReturnReceivedDibs(true); |
host_->ReturnReceivedDibs(kDeviceId); |
run_loop.Run(); |
- host_->SetReturnReceviedDibs(false); |
+ host_->SetReturnReceivedDibs(false); |
// Expect the VideoCaptureDevice has been stopped |
EXPECT_EQ(0u, host_->entries_.size()); |
} |
void NotifyPacketReady() { |
base::RunLoop run_loop; |
- EXPECT_CALL(*host_, OnBufferFilled(kDeviceId, _, _)) |
+ EXPECT_CALL(*host_, OnBufferFilled(kDeviceId, _, _, _)) |
.Times(AnyNumber()).WillOnce(ExitMessageLoop( |
message_loop_, run_loop.QuitClosure())) |
.RetiresOnSaturation(); |