| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "content/child/child_process.h" | 10 #include "content/child/child_process.h" |
| 11 #include "content/common/media/video_capture_messages.h" | 11 #include "content/common/media/video_capture_messages.h" |
| 12 #include "content/common/video_capture.mojom.h" | 12 #include "content/common/video_capture.mojom.h" |
| 13 #include "content/renderer/media/video_capture_impl.h" | 13 #include "content/renderer/media/video_capture_impl.h" |
| 14 #include "media/base/bind_to_current_loop.h" | 14 #include "media/base/bind_to_current_loop.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 using ::testing::_; | 18 using ::testing::_; |
| 19 using ::testing::SaveArg; |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 | 22 |
| 23 const int kSessionId = 1; |
| 24 |
| 22 // Mock implementation of the Mojo service. TODO(mcasas): Replace completely | 25 // Mock implementation of the Mojo service. TODO(mcasas): Replace completely |
| 23 // MockVideoCaptureMessageFilter, https://crbug.com/651897 | 26 // MockVideoCaptureMessageFilter, https://crbug.com/651897 |
| 24 class MockMojoVideoCaptureHost : public mojom::VideoCaptureHost { | 27 class MockMojoVideoCaptureHost : public mojom::VideoCaptureHost { |
| 25 public: | 28 public: |
| 26 MockMojoVideoCaptureHost() = default; | 29 MockMojoVideoCaptureHost() = default; |
| 27 | 30 |
| 31 MOCK_METHOD3(Start, void(int32_t, int32_t, const media::VideoCaptureParams&)); |
| 28 MOCK_METHOD1(Stop, void(int32_t)); | 32 MOCK_METHOD1(Stop, void(int32_t)); |
| 29 MOCK_METHOD1(Pause, void(int32_t)); | 33 MOCK_METHOD1(Pause, void(int32_t)); |
| 34 MOCK_METHOD3(Resume, |
| 35 void(int32_t, int32_t, const media::VideoCaptureParams&)); |
| 30 MOCK_METHOD1(RequestRefreshFrame, void(int32_t)); | 36 MOCK_METHOD1(RequestRefreshFrame, void(int32_t)); |
| 31 | 37 |
| 32 private: | 38 private: |
| 33 DISALLOW_COPY_AND_ASSIGN(MockMojoVideoCaptureHost); | 39 DISALLOW_COPY_AND_ASSIGN(MockMojoVideoCaptureHost); |
| 34 }; | 40 }; |
| 35 | 41 |
| 36 class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter { | 42 class MockVideoCaptureMessageFilter : public VideoCaptureMessageFilter { |
| 37 public: | 43 public: |
| 38 MockVideoCaptureMessageFilter() : VideoCaptureMessageFilter() {} | 44 MockVideoCaptureMessageFilter() : VideoCaptureMessageFilter() {} |
| 39 | 45 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 50 class VideoCaptureImplTest : public ::testing::Test { | 56 class VideoCaptureImplTest : public ::testing::Test { |
| 51 public: | 57 public: |
| 52 class MockVideoCaptureImpl : public VideoCaptureImpl { | 58 class MockVideoCaptureImpl : public VideoCaptureImpl { |
| 53 public: | 59 public: |
| 54 MockVideoCaptureImpl(const media::VideoCaptureSessionId id, | 60 MockVideoCaptureImpl(const media::VideoCaptureSessionId id, |
| 55 VideoCaptureMessageFilter* filter) | 61 VideoCaptureMessageFilter* filter) |
| 56 : VideoCaptureImpl(id, filter, base::ThreadTaskRunnerHandle::Get()), | 62 : VideoCaptureImpl(id, filter, base::ThreadTaskRunnerHandle::Get()), |
| 57 received_buffer_count_(0) {} | 63 received_buffer_count_(0) {} |
| 58 ~MockVideoCaptureImpl() override {} | 64 ~MockVideoCaptureImpl() override {} |
| 59 | 65 |
| 60 // Override Send() to mimic device to send events. | |
| 61 void Send(IPC::Message* message) override { | 66 void Send(IPC::Message* message) override { |
| 62 // In this method, messages are sent to the according handlers as if | |
| 63 // we are the device. | |
| 64 bool handled = true; | 67 bool handled = true; |
| 65 IPC_BEGIN_MESSAGE_MAP(MockVideoCaptureImpl, *message) | 68 IPC_BEGIN_MESSAGE_MAP(MockVideoCaptureImpl, *message) |
| 66 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Start, DeviceStartCapture) | |
| 67 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady, | 69 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady, |
| 68 DeviceReceiveEmptyBuffer) | 70 DeviceReceiveEmptyBuffer) |
| 69 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceSupportedFormats, | 71 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceSupportedFormats, |
| 70 DeviceGetSupportedFormats) | 72 DeviceGetSupportedFormats) |
| 71 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceFormatsInUse, | 73 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceFormatsInUse, |
| 72 DeviceGetFormatsInUse) | 74 DeviceGetFormatsInUse) |
| 73 IPC_MESSAGE_UNHANDLED(handled = false) | 75 IPC_MESSAGE_UNHANDLED(handled = false) |
| 74 IPC_END_MESSAGE_MAP() | 76 IPC_END_MESSAGE_MAP() |
| 75 EXPECT_TRUE(handled); | 77 EXPECT_TRUE(handled); |
| 76 delete message; | 78 delete message; |
| 77 } | 79 } |
| 78 | 80 |
| 79 void DeviceStartCapture(int device_id, | |
| 80 media::VideoCaptureSessionId session_id, | |
| 81 const media::VideoCaptureParams& params) { | |
| 82 OnStateChanged(VIDEO_CAPTURE_STATE_STARTED); | |
| 83 capture_params_ = params; | |
| 84 } | |
| 85 | |
| 86 void DeviceReceiveEmptyBuffer(int device_id, | 81 void DeviceReceiveEmptyBuffer(int device_id, |
| 87 int buffer_id, | 82 int buffer_id, |
| 88 const gpu::SyncToken& release_sync_token, | 83 const gpu::SyncToken& release_sync_token, |
| 89 double consumer_resource_utilization) { | 84 double consumer_resource_utilization) { |
| 90 received_buffer_count_++; | 85 received_buffer_count_++; |
| 91 } | 86 } |
| 92 | 87 |
| 93 void DeviceGetSupportedFormats(int device_id, | 88 void DeviceGetSupportedFormats(int device_id, |
| 94 media::VideoCaptureSessionId session_id) { | 89 media::VideoCaptureSessionId session_id) { |
| 95 // When the mock message filter receives a request for the device | 90 // When the mock message filter receives a request for the device |
| 96 // supported formats, replies immediately with an empty format list. | 91 // supported formats, replies immediately with an empty format list. |
| 97 OnDeviceSupportedFormatsEnumerated(media::VideoCaptureFormats()); | 92 OnDeviceSupportedFormatsEnumerated(media::VideoCaptureFormats()); |
| 98 } | 93 } |
| 99 | 94 |
| 100 void DeviceGetFormatsInUse(int device_id, | 95 void DeviceGetFormatsInUse(int device_id, |
| 101 media::VideoCaptureSessionId session_id) { | 96 media::VideoCaptureSessionId session_id) { |
| 102 OnDeviceFormatsInUseReceived(media::VideoCaptureFormats()); | 97 OnDeviceFormatsInUseReceived(media::VideoCaptureFormats()); |
| 103 } | 98 } |
| 104 | 99 |
| 105 void ReceiveStateChangeMessage(VideoCaptureState state) { | 100 void ReceiveStateChangeMessage(VideoCaptureState state) { |
| 106 OnStateChanged(state); | 101 OnStateChanged(state); |
| 107 } | 102 } |
| 108 | 103 |
| 109 int received_buffer_count() const { return received_buffer_count_; } | 104 int received_buffer_count() const { return received_buffer_count_; } |
| 110 | 105 |
| 111 const media::VideoCaptureParams& capture_params() const { | |
| 112 return capture_params_; | |
| 113 } | |
| 114 | |
| 115 private: | 106 private: |
| 116 int received_buffer_count_; | 107 int received_buffer_count_; |
| 117 media::VideoCaptureParams capture_params_; | |
| 118 }; | 108 }; |
| 119 | 109 |
| 120 VideoCaptureImplTest() | 110 VideoCaptureImplTest() |
| 121 : child_process_(new ChildProcess()), | 111 : message_filter_(new MockVideoCaptureMessageFilter), |
| 122 message_filter_(new MockVideoCaptureMessageFilter), | |
| 123 session_id_(1), | |
| 124 video_capture_impl_( | 112 video_capture_impl_( |
| 125 new MockVideoCaptureImpl(session_id_, message_filter_.get())) { | 113 new MockVideoCaptureImpl(kSessionId, message_filter_.get())) { |
| 126 params_small_.requested_format = media::VideoCaptureFormat( | 114 params_small_.requested_format = media::VideoCaptureFormat( |
| 127 gfx::Size(176, 144), 30, media::PIXEL_FORMAT_I420); | 115 gfx::Size(176, 144), 30, media::PIXEL_FORMAT_I420); |
| 128 params_large_.requested_format = media::VideoCaptureFormat( | 116 params_large_.requested_format = media::VideoCaptureFormat( |
| 129 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 117 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
| 130 | 118 |
| 131 video_capture_impl_->SetVideoCaptureHostForTesting( | 119 video_capture_impl_->SetVideoCaptureHostForTesting( |
| 132 &mock_video_capture_host_); | 120 &mock_video_capture_host_); |
| 133 video_capture_impl_->device_id_ = 2; | 121 video_capture_impl_->device_id_ = 2; |
| 134 } | 122 } |
| 135 | 123 |
| 136 protected: | 124 protected: |
| 137 MOCK_METHOD2(OnFrameReady, | 125 MOCK_METHOD2(OnFrameReady, |
| 138 void(const scoped_refptr<media::VideoFrame>&, base::TimeTicks)); | 126 void(const scoped_refptr<media::VideoFrame>&, base::TimeTicks)); |
| 139 MOCK_METHOD1(OnStateUpdate, void(VideoCaptureState)); | 127 MOCK_METHOD1(OnStateUpdate, void(VideoCaptureState)); |
| 140 MOCK_METHOD1(OnDeviceFormatsInUse, | 128 MOCK_METHOD1(OnDeviceFormatsInUse, void(const media::VideoCaptureFormats&)); |
| 141 void(const media::VideoCaptureFormats&)); | |
| 142 MOCK_METHOD1(OnDeviceSupportedFormats, | 129 MOCK_METHOD1(OnDeviceSupportedFormats, |
| 143 void(const media::VideoCaptureFormats&)); | 130 void(const media::VideoCaptureFormats&)); |
| 144 | 131 |
| 145 void StartCapture(int client_id, const media::VideoCaptureParams& params) { | 132 void StartCapture(int client_id, const media::VideoCaptureParams& params) { |
| 146 video_capture_impl_->StartCapture( | 133 video_capture_impl_->StartCapture( |
| 147 client_id, params, base::Bind(&VideoCaptureImplTest::OnStateUpdate, | 134 client_id, params, base::Bind(&VideoCaptureImplTest::OnStateUpdate, |
| 148 base::Unretained(this)), | 135 base::Unretained(this)), |
| 149 base::Bind(&VideoCaptureImplTest::OnFrameReady, | 136 base::Bind(&VideoCaptureImplTest::OnFrameReady, |
| 150 base::Unretained(this))); | 137 base::Unretained(this))); |
| 151 } | 138 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 176 |
| 190 void GetDeviceFormatsInUse() { | 177 void GetDeviceFormatsInUse() { |
| 191 const base::Callback<void(const media::VideoCaptureFormats&)> | 178 const base::Callback<void(const media::VideoCaptureFormats&)> |
| 192 callback = base::Bind( | 179 callback = base::Bind( |
| 193 &VideoCaptureImplTest::OnDeviceFormatsInUse, | 180 &VideoCaptureImplTest::OnDeviceFormatsInUse, |
| 194 base::Unretained(this)); | 181 base::Unretained(this)); |
| 195 video_capture_impl_->GetDeviceFormatsInUse(callback); | 182 video_capture_impl_->GetDeviceFormatsInUse(callback); |
| 196 } | 183 } |
| 197 | 184 |
| 198 const base::MessageLoop message_loop_; | 185 const base::MessageLoop message_loop_; |
| 199 const std::unique_ptr<ChildProcess> child_process_; | 186 const ChildProcess child_process_; |
| 200 const scoped_refptr<MockVideoCaptureMessageFilter> message_filter_; | 187 const scoped_refptr<MockVideoCaptureMessageFilter> message_filter_; |
| 201 const media::VideoCaptureSessionId session_id_; | |
| 202 std::unique_ptr<MockVideoCaptureImpl> video_capture_impl_; | 188 std::unique_ptr<MockVideoCaptureImpl> video_capture_impl_; |
| 203 MockMojoVideoCaptureHost mock_video_capture_host_; | 189 MockMojoVideoCaptureHost mock_video_capture_host_; |
| 204 media::VideoCaptureParams params_small_; | 190 media::VideoCaptureParams params_small_; |
| 205 media::VideoCaptureParams params_large_; | 191 media::VideoCaptureParams params_large_; |
| 206 | 192 |
| 207 private: | 193 private: |
| 208 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplTest); | 194 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplTest); |
| 209 }; | 195 }; |
| 210 | 196 |
| 211 TEST_F(VideoCaptureImplTest, Simple) { | 197 TEST_F(VideoCaptureImplTest, Simple) { |
| 212 // Execute SetCapture() and StopCapture() for one client. | |
| 213 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)); | 198 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)); |
| 214 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)); | 199 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)); |
| 200 EXPECT_CALL(mock_video_capture_host_, Start(_, kSessionId, params_small_)); |
| 215 EXPECT_CALL(mock_video_capture_host_, Stop(_)); | 201 EXPECT_CALL(mock_video_capture_host_, Stop(_)); |
| 216 | 202 |
| 217 StartCapture(0, params_small_); | 203 StartCapture(0, params_small_); |
| 218 StopCapture(0); | 204 StopCapture(0); |
| 219 } | 205 } |
| 220 | 206 |
| 221 TEST_F(VideoCaptureImplTest, TwoClientsInSequence) { | 207 TEST_F(VideoCaptureImplTest, TwoClientsInSequence) { |
| 222 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2); | 208 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2); |
| 223 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2); | 209 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2); |
| 210 EXPECT_CALL(mock_video_capture_host_, Start(_, kSessionId, params_small_)); |
| 224 EXPECT_CALL(mock_video_capture_host_, Stop(_)); | 211 EXPECT_CALL(mock_video_capture_host_, Stop(_)); |
| 225 | 212 |
| 226 StartCapture(0, params_small_); | 213 StartCapture(0, params_small_); |
| 227 StopCapture(0); | 214 StopCapture(0); |
| 228 StartCapture(1, params_small_); | 215 StartCapture(1, params_small_); |
| 229 StopCapture(1); | 216 StopCapture(1); |
| 230 } | 217 } |
| 231 | 218 |
| 232 TEST_F(VideoCaptureImplTest, LargeAndSmall) { | 219 TEST_F(VideoCaptureImplTest, LargeAndSmall) { |
| 233 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2); | 220 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2); |
| 234 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2); | 221 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2); |
| 222 EXPECT_CALL(mock_video_capture_host_, Start(_, kSessionId, params_large_)); |
| 235 EXPECT_CALL(mock_video_capture_host_, Stop(_)); | 223 EXPECT_CALL(mock_video_capture_host_, Stop(_)); |
| 236 | 224 |
| 237 StartCapture(0, params_large_); | 225 StartCapture(0, params_large_); |
| 238 StopCapture(0); | 226 StopCapture(0); |
| 239 StartCapture(1, params_small_); | 227 StartCapture(1, params_small_); |
| 240 StopCapture(1); | 228 StopCapture(1); |
| 241 } | 229 } |
| 242 | 230 |
| 243 TEST_F(VideoCaptureImplTest, SmallAndLarge) { | 231 TEST_F(VideoCaptureImplTest, SmallAndLarge) { |
| 244 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2); | 232 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2); |
| 245 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2); | 233 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2); |
| 234 EXPECT_CALL(mock_video_capture_host_, Start(_, kSessionId, params_small_)); |
| 246 EXPECT_CALL(mock_video_capture_host_, Stop(_)); | 235 EXPECT_CALL(mock_video_capture_host_, Stop(_)); |
| 247 | 236 |
| 248 StartCapture(0, params_small_); | 237 StartCapture(0, params_small_); |
| 249 StopCapture(0); | 238 StopCapture(0); |
| 250 StartCapture(1, params_large_); | 239 StartCapture(1, params_large_); |
| 251 StopCapture(1); | 240 StopCapture(1); |
| 252 } | 241 } |
| 253 | 242 |
| 254 // Check that a request to GetDeviceSupportedFormats() ends up eventually in the | 243 // Checks that a request to GetDeviceSupportedFormats() ends up eventually in |
| 255 // provided callback. | 244 // the provided callback. |
| 256 TEST_F(VideoCaptureImplTest, GetDeviceFormats) { | 245 TEST_F(VideoCaptureImplTest, GetDeviceFormats) { |
| 257 EXPECT_CALL(*this, OnDeviceSupportedFormats(_)); | 246 EXPECT_CALL(*this, OnDeviceSupportedFormats(_)); |
| 258 | 247 |
| 259 GetDeviceSupportedFormats(); | 248 GetDeviceSupportedFormats(); |
| 260 } | 249 } |
| 261 | 250 |
| 262 // Check that two requests to GetDeviceSupportedFormats() end up eventually | 251 // Checks that two requests to GetDeviceSupportedFormats() end up eventually |
| 263 // calling the provided callbacks. | 252 // calling the provided callbacks. |
| 264 TEST_F(VideoCaptureImplTest, TwoClientsGetDeviceFormats) { | 253 TEST_F(VideoCaptureImplTest, TwoClientsGetDeviceFormats) { |
| 265 EXPECT_CALL(*this, OnDeviceSupportedFormats(_)).Times(2); | 254 EXPECT_CALL(*this, OnDeviceSupportedFormats(_)).Times(2); |
| 266 | 255 |
| 267 GetDeviceSupportedFormats(); | 256 GetDeviceSupportedFormats(); |
| 268 GetDeviceSupportedFormats(); | 257 GetDeviceSupportedFormats(); |
| 269 } | 258 } |
| 270 | 259 |
| 271 // Check that a request to GetDeviceFormatsInUse() ends up eventually in the | 260 // Checks that a request to GetDeviceFormatsInUse() ends up eventually in the |
| 272 // provided callback. | 261 // provided callback. |
| 273 TEST_F(VideoCaptureImplTest, GetDeviceFormatsInUse) { | 262 TEST_F(VideoCaptureImplTest, GetDeviceFormatsInUse) { |
| 274 EXPECT_CALL(*this, OnDeviceFormatsInUse(_)); | 263 EXPECT_CALL(*this, OnDeviceFormatsInUse(_)); |
| 275 | 264 |
| 276 GetDeviceFormatsInUse(); | 265 GetDeviceFormatsInUse(); |
| 277 } | 266 } |
| 278 | 267 |
| 279 TEST_F(VideoCaptureImplTest, BufferReceived) { | 268 TEST_F(VideoCaptureImplTest, BufferReceived) { |
| 269 base::SharedMemory shm; |
| 270 const size_t frame_size = media::VideoFrame::AllocationSize( |
| 271 media::PIXEL_FORMAT_I420, params_small_.requested_format.frame_size); |
| 272 ASSERT_TRUE(shm.CreateAndMapAnonymous(frame_size)); |
| 273 |
| 280 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)); | 274 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)); |
| 281 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)); | 275 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)); |
| 282 EXPECT_CALL(*this, OnFrameReady(_, _)); | 276 EXPECT_CALL(*this, OnFrameReady(_, _)); |
| 277 EXPECT_CALL(mock_video_capture_host_, Start(_, kSessionId, params_small_)); |
| 283 EXPECT_CALL(mock_video_capture_host_, Stop(_)); | 278 EXPECT_CALL(mock_video_capture_host_, Stop(_)); |
| 284 | 279 |
| 285 const gfx::Size size(1280, 720); | 280 StartCapture(0, params_small_); |
| 286 | |
| 287 // Create a fake shared memory for buffer. | |
| 288 base::SharedMemory shm; | |
| 289 const size_t frame_size = media::VideoFrame::AllocationSize( | |
| 290 media::PIXEL_FORMAT_I420, size); | |
| 291 ASSERT_TRUE(shm.CreateAndMapAnonymous(frame_size)); | |
| 292 | |
| 293 media::VideoCaptureParams params; | |
| 294 params.requested_format = media::VideoCaptureFormat( | |
| 295 size, 30, media::PIXEL_FORMAT_I420); | |
| 296 | |
| 297 StartCapture(0, params); | |
| 298 NewBuffer(0, shm); | 281 NewBuffer(0, shm); |
| 299 BufferReceived(0, size); | 282 BufferReceived(0, params_small_.requested_format.frame_size); |
| 300 StopCapture(0); | 283 StopCapture(0); |
| 301 BufferDestroyed(0); | 284 BufferDestroyed(0); |
| 302 } | 285 } |
| 303 | 286 |
| 304 TEST_F(VideoCaptureImplTest, BufferReceivedAfterStop) { | 287 TEST_F(VideoCaptureImplTest, BufferReceivedAfterStop) { |
| 288 base::SharedMemory shm; |
| 289 const size_t frame_size = media::VideoFrame::AllocationSize( |
| 290 media::PIXEL_FORMAT_I420, params_large_.requested_format.frame_size); |
| 291 ASSERT_TRUE(shm.CreateAndMapAnonymous(frame_size)); |
| 292 |
| 305 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)); | 293 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)); |
| 306 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)); | 294 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)); |
| 307 EXPECT_CALL(*this, OnFrameReady(_, _)).Times(0); | 295 EXPECT_CALL(*this, OnFrameReady(_, _)).Times(0); |
| 296 EXPECT_CALL(mock_video_capture_host_, Start(_, kSessionId, params_large_)); |
| 308 EXPECT_CALL(mock_video_capture_host_, Stop(_)); | 297 EXPECT_CALL(mock_video_capture_host_, Stop(_)); |
| 309 | 298 |
| 310 // Create a fake shared memory for buffer. | |
| 311 base::SharedMemory shm; | |
| 312 const size_t i420_frame_size = media::VideoFrame::AllocationSize( | |
| 313 media::PIXEL_FORMAT_I420, params_large_.requested_format.frame_size); | |
| 314 ASSERT_TRUE(shm.CreateAndMapAnonymous(i420_frame_size)); | |
| 315 | |
| 316 StartCapture(0, params_large_); | 299 StartCapture(0, params_large_); |
| 317 NewBuffer(0, shm); | 300 NewBuffer(0, shm); |
| 318 StopCapture(0); | 301 StopCapture(0); |
| 319 BufferReceived(0, params_large_.requested_format.frame_size); | 302 BufferReceived(0, params_large_.requested_format.frame_size); |
| 320 BufferDestroyed(0); | 303 BufferDestroyed(0); |
| 321 | 304 |
| 322 EXPECT_EQ(this->video_capture_impl_->received_buffer_count(), 1); | 305 EXPECT_EQ(this->video_capture_impl_->received_buffer_count(), 1); |
| 323 } | 306 } |
| 324 | 307 |
| 325 TEST_F(VideoCaptureImplTest, AlreadyStarted) { | 308 TEST_F(VideoCaptureImplTest, AlreadyStarted) { |
| 309 media::VideoCaptureParams params = {}; |
| 326 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2); | 310 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)).Times(2); |
| 327 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2); | 311 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)).Times(2); |
| 312 EXPECT_CALL(mock_video_capture_host_, Start(_, kSessionId, _)) |
| 313 .WillOnce(SaveArg<2>(¶ms)); |
| 328 EXPECT_CALL(mock_video_capture_host_, Stop(_)); | 314 EXPECT_CALL(mock_video_capture_host_, Stop(_)); |
| 329 | 315 |
| 330 StartCapture(0, params_small_); | 316 StartCapture(0, params_small_); |
| 331 StartCapture(1, params_large_); | 317 StartCapture(1, params_large_); |
| 332 StopCapture(0); | 318 StopCapture(0); |
| 333 StopCapture(1); | 319 StopCapture(1); |
| 334 DCHECK(video_capture_impl_->capture_params().requested_format.frame_size == | 320 DCHECK(params.requested_format == params_small_.requested_format); |
| 335 params_small_.requested_format.frame_size); | |
| 336 } | 321 } |
| 337 | 322 |
| 338 TEST_F(VideoCaptureImplTest, EndedBeforeStop) { | 323 TEST_F(VideoCaptureImplTest, EndedBeforeStop) { |
| 339 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)); | 324 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)); |
| 340 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)); | 325 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STOPPED)); |
| 326 EXPECT_CALL(mock_video_capture_host_, Start(_, kSessionId, params_small_)); |
| 341 | 327 |
| 342 StartCapture(0, params_small_); | 328 StartCapture(0, params_small_); |
| 343 | 329 |
| 344 // Receive state change message from browser. | |
| 345 video_capture_impl_->ReceiveStateChangeMessage(VIDEO_CAPTURE_STATE_ENDED); | 330 video_capture_impl_->ReceiveStateChangeMessage(VIDEO_CAPTURE_STATE_ENDED); |
| 346 | 331 |
| 347 StopCapture(0); | 332 StopCapture(0); |
| 348 } | 333 } |
| 349 | 334 |
| 350 TEST_F(VideoCaptureImplTest, ErrorBeforeStop) { | 335 TEST_F(VideoCaptureImplTest, ErrorBeforeStop) { |
| 351 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)); | 336 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_STARTED)); |
| 352 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_ERROR)); | 337 EXPECT_CALL(*this, OnStateUpdate(VIDEO_CAPTURE_STATE_ERROR)); |
| 338 EXPECT_CALL(mock_video_capture_host_, Start(_, kSessionId, params_small_)); |
| 353 | 339 |
| 354 StartCapture(0, params_small_); | 340 StartCapture(0, params_small_); |
| 355 | 341 |
| 356 // Receive state change message from browser. | |
| 357 video_capture_impl_->ReceiveStateChangeMessage(VIDEO_CAPTURE_STATE_ERROR); | 342 video_capture_impl_->ReceiveStateChangeMessage(VIDEO_CAPTURE_STATE_ERROR); |
| 358 | 343 |
| 359 StopCapture(0); | 344 StopCapture(0); |
| 360 } | 345 } |
| 361 | 346 |
| 362 } // namespace content | 347 } // namespace content |
| OLD | NEW |