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 06233334abfbc78636467e4d591ace795b092bf2..f57cfdbf06d6023197f8a6222d41713e61b95c51 100644 |
--- a/content/browser/renderer_host/media/video_capture_host_unittest.cc |
+++ b/content/browser/renderer_host/media/video_capture_host_unittest.cc |
@@ -106,17 +106,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; |
} |
@@ -157,9 +159,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); |
@@ -179,15 +181,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); |
} |
@@ -197,17 +219,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_; |
}; |
@@ -322,27 +337,17 @@ 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())); |
media::VideoCaptureParams params; |
- params.width = 352; |
- params.height = 288; |
- params.frame_rate = 30; |
+ params.requested_format = media::VideoCaptureFormat( |
+ 352, 288, 30, media::ConstantResolutionVideoCaptureDevice); |
params.session_id = opened_session_id_; |
host_->OnStartCapture(kDeviceId, params); |
run_loop.Run(); |
@@ -355,9 +360,8 @@ class VideoCaptureHostTest : public testing::Test { |
base::RunLoop run_loop; |
EXPECT_CALL(*host_, OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_STOPPED)); |
media::VideoCaptureParams params; |
- params.width = 352; |
- params.height = 288; |
- params.frame_rate = 30; |
+ params.requested_format = media::VideoCaptureFormat( |
+ 352, 288, 30, media::ConstantResolutionVideoCaptureDevice); |
params.session_id = opened_session_id_; |
host_->OnStartCapture(kDeviceId, params); |
host_->OnStopCapture(kDeviceId); |
@@ -367,22 +371,17 @@ 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())); |
media::VideoCaptureParams params; |
- params.width = width; |
- params.height = height; |
- params.frame_rate = frame_rate; |
+ params.requested_format = media::VideoCaptureFormat( |
+ width, height, frame_rate, media::ConstantResolutionVideoCaptureDevice); |
params.session_id = opened_session_id_; |
host_->SetDumpVideo(true); |
host_->OnStartCapture(kDeviceId, params); |
@@ -396,19 +395,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(); |