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 // Unit test for VideoCaptureController. | 5 // Unit test for VideoCaptureController. |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 : public VideoCaptureControllerEventHandler { | 33 : public VideoCaptureControllerEventHandler { |
34 public: | 34 public: |
35 explicit MockVideoCaptureControllerEventHandler( | 35 explicit MockVideoCaptureControllerEventHandler( |
36 VideoCaptureController* controller) | 36 VideoCaptureController* controller) |
37 : controller_(controller) {} | 37 : controller_(controller) {} |
38 virtual ~MockVideoCaptureControllerEventHandler() {} | 38 virtual ~MockVideoCaptureControllerEventHandler() {} |
39 | 39 |
40 // These mock methods are delegated to by our fake implementation of | 40 // These mock methods are delegated to by our fake implementation of |
41 // VideoCaptureControllerEventHandler, to be used in EXPECT_CALL(). | 41 // VideoCaptureControllerEventHandler, to be used in EXPECT_CALL(). |
42 MOCK_METHOD1(DoBufferCreated, void(const VideoCaptureControllerID&)); | 42 MOCK_METHOD1(DoBufferCreated, void(const VideoCaptureControllerID&)); |
| 43 MOCK_METHOD1(DoBufferDestroyed, void(const VideoCaptureControllerID&)); |
43 MOCK_METHOD1(DoBufferReady, void(const VideoCaptureControllerID&)); | 44 MOCK_METHOD1(DoBufferReady, void(const VideoCaptureControllerID&)); |
44 MOCK_METHOD1(DoFrameInfo, void(const VideoCaptureControllerID&)); | |
45 MOCK_METHOD1(DoEnded, void(const VideoCaptureControllerID&)); | 45 MOCK_METHOD1(DoEnded, void(const VideoCaptureControllerID&)); |
46 MOCK_METHOD1(DoError, void(const VideoCaptureControllerID&)); | 46 MOCK_METHOD1(DoError, void(const VideoCaptureControllerID&)); |
47 | 47 |
48 virtual void OnError(const VideoCaptureControllerID& id) OVERRIDE { | 48 virtual void OnError(const VideoCaptureControllerID& id) OVERRIDE { |
49 DoError(id); | 49 DoError(id); |
50 } | 50 } |
51 virtual void OnBufferCreated(const VideoCaptureControllerID& id, | 51 virtual void OnBufferCreated(const VideoCaptureControllerID& id, |
52 base::SharedMemoryHandle handle, | 52 base::SharedMemoryHandle handle, |
53 int length, int buffer_id) OVERRIDE { | 53 int length, int buffer_id) OVERRIDE { |
54 DoBufferCreated(id); | 54 DoBufferCreated(id); |
55 } | 55 } |
| 56 virtual void OnBufferDestroyed(const VideoCaptureControllerID& id, |
| 57 int buffer_id) OVERRIDE { |
| 58 DoBufferDestroyed(id); |
| 59 } |
56 virtual void OnBufferReady(const VideoCaptureControllerID& id, | 60 virtual void OnBufferReady(const VideoCaptureControllerID& id, |
57 int buffer_id, | 61 int buffer_id, |
58 base::Time timestamp) OVERRIDE { | 62 base::Time timestamp, |
| 63 const media::VideoCaptureFormat& format) OVERRIDE { |
59 DoBufferReady(id); | 64 DoBufferReady(id); |
60 base::MessageLoop::current()->PostTask(FROM_HERE, | 65 base::MessageLoop::current()->PostTask(FROM_HERE, |
61 base::Bind(&VideoCaptureController::ReturnBuffer, | 66 base::Bind(&VideoCaptureController::ReturnBuffer, |
62 base::Unretained(controller_), id, this, buffer_id)); | 67 base::Unretained(controller_), id, this, buffer_id)); |
63 } | 68 } |
64 virtual void OnFrameInfo( | |
65 const VideoCaptureControllerID& id, | |
66 const media::VideoCaptureCapability& format) OVERRIDE { | |
67 DoFrameInfo(id); | |
68 } | |
69 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE { | 69 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE { |
70 DoEnded(id); | 70 DoEnded(id); |
71 // OnEnded() must respond by (eventually) unregistering the client. | 71 // OnEnded() must respond by (eventually) unregistering the client. |
72 base::MessageLoop::current()->PostTask(FROM_HERE, | 72 base::MessageLoop::current()->PostTask(FROM_HERE, |
73 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), | 73 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), |
74 base::Unretained(controller_), id, this)); | 74 base::Unretained(controller_), id, this)); |
75 } | 75 } |
76 | 76 |
77 VideoCaptureController* controller_; | 77 VideoCaptureController* controller_; |
78 }; | 78 }; |
(...skipping 28 matching lines...) Expand all Loading... |
107 | 107 |
108 private: | 108 private: |
109 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); | 109 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); |
110 }; | 110 }; |
111 | 111 |
112 // A simple test of VideoCaptureController's ability to add, remove, and keep | 112 // A simple test of VideoCaptureController's ability to add, remove, and keep |
113 // track of clients. | 113 // track of clients. |
114 TEST_F(VideoCaptureControllerTest, AddAndRemoveClients) { | 114 TEST_F(VideoCaptureControllerTest, AddAndRemoveClients) { |
115 media::VideoCaptureParams session_100; | 115 media::VideoCaptureParams session_100; |
116 session_100.session_id = 100; | 116 session_100.session_id = 100; |
117 session_100.width = 320; | 117 session_100.requested_format = media::VideoCaptureFormat( |
118 session_100.height = 240; | 118 320, 240, 30, media::ConstantResolutionVideoCaptureDevice); |
119 session_100.frame_rate = 30; | |
120 | 119 |
121 media::VideoCaptureParams session_200 = session_100; | 120 media::VideoCaptureParams session_200 = session_100; |
122 session_200.session_id = 200; | 121 session_200.session_id = 200; |
123 | 122 |
124 media::VideoCaptureParams session_300 = session_100; | 123 media::VideoCaptureParams session_300 = session_100; |
125 session_300.session_id = 300; | 124 session_300.session_id = 300; |
126 | 125 |
127 media::VideoCaptureParams session_400 = session_100; | 126 media::VideoCaptureParams session_400 = session_100; |
128 session_400.session_id = 400; | 127 session_400.session_id = 400; |
129 | 128 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 ASSERT_EQ(0, controller_->GetClientCount()) | 201 ASSERT_EQ(0, controller_->GetClientCount()) |
203 << "Client count should return to zero after all clients are gone."; | 202 << "Client count should return to zero after all clients are gone."; |
204 } | 203 } |
205 | 204 |
206 // This test will connect and disconnect several clients while simulating an | 205 // This test will connect and disconnect several clients while simulating an |
207 // active capture device being started and generating frames. It runs on one | 206 // active capture device being started and generating frames. It runs on one |
208 // thread and is intended to behave deterministically. | 207 // thread and is intended to behave deterministically. |
209 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { | 208 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { |
210 media::VideoCaptureParams session_100; | 209 media::VideoCaptureParams session_100; |
211 session_100.session_id = 100; | 210 session_100.session_id = 100; |
212 session_100.width = 320; | 211 session_100.requested_format = media::VideoCaptureFormat( |
213 session_100.height = 240; | 212 320, 240, 30, media::ConstantResolutionVideoCaptureDevice); |
214 session_100.frame_rate = 30; | |
215 | 213 |
216 media::VideoCaptureParams session_200 = session_100; | 214 media::VideoCaptureParams session_200 = session_100; |
217 session_200.session_id = 200; | 215 session_200.session_id = 200; |
218 | 216 |
219 media::VideoCaptureParams session_300 = session_100; | 217 media::VideoCaptureParams session_300 = session_100; |
220 session_300.session_id = 300; | 218 session_300.session_id = 300; |
221 | 219 |
222 media::VideoCaptureParams session_1 = session_100; | 220 media::VideoCaptureParams session_1 = session_100; |
223 session_1.session_id = 1; | 221 session_1.session_id = 1; |
224 | 222 |
| 223 gfx::Size capture_resolution(444, 200); |
| 224 |
225 // The device format needn't match the VideoCaptureParams (the camera can do | 225 // The device format needn't match the VideoCaptureParams (the camera can do |
226 // what it wants). Pick something random to use for OnFrameInfo. | 226 // what it wants). Pick something random to use for OnFrameInfo. |
227 media::VideoCaptureCapability device_format( | 227 media::VideoCaptureCapability device_format( |
228 10, 10, 25, media::PIXEL_FORMAT_RGB24, 10, false, | 228 10, 10, 25, media::PIXEL_FORMAT_RGB24, 10, false, |
229 media::ConstantResolutionVideoCaptureDevice); | 229 media::ConstantResolutionVideoCaptureDevice); |
230 | 230 |
231 const VideoCaptureControllerID client_a_route_1(0xa1a1a1a1); | 231 const VideoCaptureControllerID client_a_route_1(0xa1a1a1a1); |
232 const VideoCaptureControllerID client_a_route_2(0xa2a2a2a2); | 232 const VideoCaptureControllerID client_a_route_2(0xa2a2a2a2); |
233 const VideoCaptureControllerID client_b_route_1(0xb1b1b1b1); | 233 const VideoCaptureControllerID client_b_route_1(0xb1b1b1b1); |
234 const VideoCaptureControllerID client_b_route_2(0xb2b2b2b2); | 234 const VideoCaptureControllerID client_b_route_2(0xb2b2b2b2); |
235 | 235 |
236 // Start with two clients. | 236 // Start with two clients. |
237 controller_->AddClient(client_a_route_1, client_a_.get(), | 237 controller_->AddClient(client_a_route_1, client_a_.get(), |
238 base::kNullProcessHandle, session_100); | 238 base::kNullProcessHandle, session_100); |
239 controller_->AddClient(client_b_route_1, client_b_.get(), | 239 controller_->AddClient(client_b_route_1, client_b_.get(), |
240 base::kNullProcessHandle, session_300); | 240 base::kNullProcessHandle, session_300); |
241 ASSERT_EQ(2, controller_->GetClientCount()); | 241 controller_->AddClient(client_a_route_2, client_a_.get(), |
| 242 base::kNullProcessHandle, session_200); |
| 243 ASSERT_EQ(3, controller_->GetClientCount()); |
242 | 244 |
243 // The OnFrameInfo() event from the device, when processed by the controller, | 245 // Now, simulate an incoming captured frame from the capture device. As a side |
244 // should generate client OnFrameInfo() and OnBufferCreated() events. | 246 // effect this will cause the first buffer to be shared with clients. |
| 247 uint8 frame_no = 1; |
| 248 scoped_refptr<media::VideoFrame> frame; |
| 249 frame = device_->ReserveOutputBuffer(capture_resolution); |
| 250 ASSERT_TRUE(frame); |
| 251 media::FillYUV(frame, frame_no++, 0x22, 0x44); |
245 { | 252 { |
246 InSequence s; | 253 InSequence s; |
247 EXPECT_CALL(*client_a_, DoFrameInfo(client_a_route_1)).Times(1); | 254 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); |
248 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(kPoolSize); | 255 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1); |
249 } | 256 } |
250 { | 257 { |
251 InSequence s; | 258 InSequence s; |
252 EXPECT_CALL(*client_b_, DoFrameInfo(client_b_route_1)).Times(1); | 259 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); |
253 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(kPoolSize); | 260 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); |
254 } | 261 } |
255 device_->OnFrameInfo(device_format); | 262 { |
| 263 InSequence s; |
| 264 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); |
| 265 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); |
| 266 } |
| 267 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); |
| 268 frame = NULL; |
| 269 |
256 base::RunLoop().RunUntilIdle(); | 270 base::RunLoop().RunUntilIdle(); |
257 Mock::VerifyAndClearExpectations(client_a_.get()); | 271 Mock::VerifyAndClearExpectations(client_a_.get()); |
258 Mock::VerifyAndClearExpectations(client_b_.get()); | 272 Mock::VerifyAndClearExpectations(client_b_.get()); |
259 | 273 |
260 // When a third clients is subsequently added, the frame info and buffers | 274 // Second frame which ought to use the same shared memory buffer. In this case |
261 // should immediately be shared to the new clients. | 275 // pretend that the VideoFrame pointer is held by the device for a long delay. |
262 { | 276 // This shouldn't affect anything. |
263 InSequence s; | 277 frame = device_->ReserveOutputBuffer(capture_resolution); |
264 EXPECT_CALL(*client_a_, DoFrameInfo(client_a_route_2)).Times(1); | |
265 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(kPoolSize); | |
266 } | |
267 controller_->AddClient(client_a_route_2, client_a_.get(), | |
268 base::kNullProcessHandle, session_200); | |
269 Mock::VerifyAndClearExpectations(client_a_.get()); | |
270 | |
271 // Now, simulate an incoming captured frame from the capture device. | |
272 uint8 frame_no = 1; | |
273 scoped_refptr<media::VideoFrame> frame; | |
274 frame = device_->ReserveOutputBuffer(); | |
275 ASSERT_TRUE(frame); | |
276 media::FillYUV(frame, frame_no++, 0x22, 0x44); | |
277 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); | |
278 frame = NULL; | |
279 | |
280 // The buffer should be delivered to the clients in any order. | |
281 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1); | |
282 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); | |
283 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); | |
284 base::RunLoop().RunUntilIdle(); | |
285 Mock::VerifyAndClearExpectations(client_a_.get()); | |
286 Mock::VerifyAndClearExpectations(client_b_.get()); | |
287 | |
288 // Second frame. In this case pretend that the VideoFrame pointer is held | |
289 // by the device for a long delay. This shouldn't affect anything. | |
290 frame = device_->ReserveOutputBuffer(); | |
291 ASSERT_TRUE(frame); | 278 ASSERT_TRUE(frame); |
292 media::FillYUV(frame, frame_no++, 0x22, 0x44); | 279 media::FillYUV(frame, frame_no++, 0x22, 0x44); |
293 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); | 280 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); |
294 | 281 |
295 // The buffer should be delivered to the clients in any order. | 282 // The buffer should be delivered to the clients in any order. |
296 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1); | 283 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1); |
| 284 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); |
297 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); | 285 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); |
298 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); | |
299 base::RunLoop().RunUntilIdle(); | 286 base::RunLoop().RunUntilIdle(); |
300 Mock::VerifyAndClearExpectations(client_a_.get()); | 287 Mock::VerifyAndClearExpectations(client_a_.get()); |
301 Mock::VerifyAndClearExpectations(client_b_.get()); | 288 Mock::VerifyAndClearExpectations(client_b_.get()); |
302 frame = NULL; | 289 frame = NULL; |
303 | 290 |
304 // Add a fourth client now that some frames have come through. It should get | 291 // Add a fourth client now that some frames have come through. |
305 // the buffer info, but it won't get any frames until new ones are captured. | |
306 { | |
307 InSequence s; | |
308 EXPECT_CALL(*client_b_, DoFrameInfo(client_b_route_2)).Times(1); | |
309 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); | |
310 } | |
311 controller_->AddClient(client_b_route_2, client_b_.get(), | 292 controller_->AddClient(client_b_route_2, client_b_.get(), |
312 base::kNullProcessHandle, session_1); | 293 base::kNullProcessHandle, session_1); |
313 Mock::VerifyAndClearExpectations(client_b_.get()); | 294 Mock::VerifyAndClearExpectations(client_b_.get()); |
314 | 295 |
315 // Third, fourth, and fifth frames. Pretend they all arrive at the same time. | 296 // Third, fourth, and fifth frames. Pretend they all arrive at the same time. |
316 for (int i = 0; i < kPoolSize; i++) { | 297 for (int i = 0; i < kPoolSize; i++) { |
317 frame = device_->ReserveOutputBuffer(); | 298 frame = device_->ReserveOutputBuffer(capture_resolution); |
318 ASSERT_TRUE(frame); | 299 ASSERT_TRUE(frame); |
319 ASSERT_EQ(media::VideoFrame::I420, frame->format()); | 300 ASSERT_EQ(media::VideoFrame::I420, frame->format()); |
320 media::FillYUV(frame, frame_no++, 0x22, 0x44); | 301 media::FillYUV(frame, frame_no++, 0x22, 0x44); |
321 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); | 302 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); |
322 | 303 |
323 } | 304 } |
324 // ReserveOutputBuffer ought to fail now, because the pool is depleted. | 305 // ReserveOutputBuffer ought to fail now, because the pool is depleted. |
325 ASSERT_FALSE(device_->ReserveOutputBuffer()); | 306 ASSERT_FALSE(device_->ReserveOutputBuffer(capture_resolution)); |
| 307 |
| 308 // The new client needs to be told of 3 buffers; the old clients only 2. |
| 309 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); |
| 310 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(kPoolSize); |
| 311 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) |
| 312 .Times(kPoolSize - 1); |
326 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(kPoolSize); | 313 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(kPoolSize); |
| 314 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)) |
| 315 .Times(kPoolSize - 1); |
327 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(kPoolSize); | 316 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(kPoolSize); |
| 317 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)) |
| 318 .Times(kPoolSize - 1); |
328 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(kPoolSize); | 319 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(kPoolSize); |
329 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(kPoolSize); | |
330 base::RunLoop().RunUntilIdle(); | 320 base::RunLoop().RunUntilIdle(); |
331 Mock::VerifyAndClearExpectations(client_a_.get()); | 321 Mock::VerifyAndClearExpectations(client_a_.get()); |
332 Mock::VerifyAndClearExpectations(client_b_.get()); | 322 Mock::VerifyAndClearExpectations(client_b_.get()); |
333 | 323 |
334 // Now test the interaction of client shutdown and frame delivery. | 324 // Now test the interaction of client shutdown and frame delivery. |
335 // Kill A1 via renderer disconnect (synchronous). | 325 // Kill A1 via renderer disconnect (synchronous). |
336 controller_->RemoveClient(client_a_route_1, client_a_.get()); | 326 controller_->RemoveClient(client_a_route_1, client_a_.get()); |
337 // Kill B1 via session close (posts a task to disconnect). | 327 // Kill B1 via session close (posts a task to disconnect). |
338 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); | 328 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); |
339 controller_->StopSession(300); | 329 controller_->StopSession(300); |
340 // Queue up another frame. | 330 // Queue up another frame. |
341 frame = device_->ReserveOutputBuffer(); | 331 frame = device_->ReserveOutputBuffer(capture_resolution); |
342 ASSERT_TRUE(frame); | 332 ASSERT_TRUE(frame); |
343 media::FillYUV(frame, frame_no++, 0x22, 0x44); | 333 media::FillYUV(frame, frame_no++, 0x22, 0x44); |
344 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); | 334 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); |
345 frame = device_->ReserveOutputBuffer(); | 335 frame = device_->ReserveOutputBuffer(capture_resolution); |
346 { | 336 { |
347 // Kill A2 via session close (posts a task to disconnect, but A2 must not | 337 // Kill A2 via session close (posts a task to disconnect, but A2 must not |
348 // be sent either of these two frames).. | 338 // be sent either of these two frames).. |
349 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); | 339 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); |
350 controller_->StopSession(200); | 340 controller_->StopSession(200); |
351 } | 341 } |
352 ASSERT_TRUE(frame); | 342 ASSERT_TRUE(frame); |
353 media::FillYUV(frame, frame_no++, 0x22, 0x44); | 343 media::FillYUV(frame, frame_no++, 0x22, 0x44); |
354 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); | 344 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); |
355 // B2 is the only client left, and is the only one that should | 345 // B2 is the only client left, and is the only one that should |
356 // get the frame. | 346 // get the frame. |
357 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(2); | 347 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(2); |
358 base::RunLoop().RunUntilIdle(); | 348 base::RunLoop().RunUntilIdle(); |
359 Mock::VerifyAndClearExpectations(client_a_.get()); | 349 Mock::VerifyAndClearExpectations(client_a_.get()); |
360 Mock::VerifyAndClearExpectations(client_b_.get()); | 350 Mock::VerifyAndClearExpectations(client_b_.get()); |
361 } | 351 } |
362 | 352 |
363 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 353 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
364 // behavior of various operations after the error state has been signalled. | 354 // behavior of various operations after the error state has been signalled. |
365 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { | 355 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { |
366 media::VideoCaptureParams session_100; | 356 media::VideoCaptureParams session_100; |
367 session_100.session_id = 100; | 357 session_100.session_id = 100; |
368 session_100.width = 320; | 358 session_100.requested_format = media::VideoCaptureFormat( |
369 session_100.height = 240; | 359 320, 240, 30, media::ConstantResolutionVideoCaptureDevice); |
370 session_100.frame_rate = 30; | |
371 | 360 |
372 media::VideoCaptureParams session_200 = session_100; | 361 media::VideoCaptureParams session_200 = session_100; |
373 session_200.session_id = 200; | 362 session_200.session_id = 200; |
374 | 363 |
375 const VideoCaptureControllerID route_id(0x99); | 364 const VideoCaptureControllerID route_id(0x99); |
376 | 365 |
377 // Start with one client. | 366 // Start with one client. |
378 controller_->AddClient(route_id, client_a_.get(), | 367 controller_->AddClient(route_id, client_a_.get(), |
379 base::kNullProcessHandle, session_100); | 368 base::kNullProcessHandle, session_100); |
380 device_->OnError(); | 369 device_->OnError(); |
(...skipping 16 matching lines...) Expand all Loading... |
397 | 386 |
398 device_->OnFrameInfo(device_format); | 387 device_->OnFrameInfo(device_format); |
399 base::RunLoop().RunUntilIdle(); | 388 base::RunLoop().RunUntilIdle(); |
400 } | 389 } |
401 | 390 |
402 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 391 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
403 // behavior of various operations after the error state has been signalled. | 392 // behavior of various operations after the error state has been signalled. |
404 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { | 393 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { |
405 media::VideoCaptureParams session_100; | 394 media::VideoCaptureParams session_100; |
406 session_100.session_id = 100; | 395 session_100.session_id = 100; |
407 session_100.width = 320; | 396 session_100.requested_format = media::VideoCaptureFormat( |
408 session_100.height = 240; | 397 320, 240, 30, media::ConstantResolutionVideoCaptureDevice); |
409 session_100.frame_rate = 30; | |
410 | 398 |
411 media::VideoCaptureParams session_200 = session_100; | 399 media::VideoCaptureParams session_200 = session_100; |
412 session_200.session_id = 200; | 400 session_200.session_id = 200; |
413 | 401 |
414 const VideoCaptureControllerID route_id(0x99); | 402 const VideoCaptureControllerID route_id(0x99); |
415 | 403 |
416 // Start with one client. | 404 // Start with one client. |
417 controller_->AddClient(route_id, client_a_.get(), | 405 controller_->AddClient(route_id, client_a_.get(), |
418 base::kNullProcessHandle, session_100); | 406 base::kNullProcessHandle, session_100); |
419 // OnFrameInfo from the VCD should become a no-op after the error occurs. | 407 // OnFrameInfo from the VCD should become a no-op after the error occurs. |
420 media::VideoCaptureCapability device_format( | 408 media::VideoCaptureCapability device_format( |
421 10, 10, 25, media::PIXEL_FORMAT_ARGB, 10, false, | 409 10, 10, 25, media::PIXEL_FORMAT_ARGB, 10, false, |
422 media::ConstantResolutionVideoCaptureDevice); | 410 media::ConstantResolutionVideoCaptureDevice); |
423 | 411 |
424 // Start the device and get as far as exchanging buffers with the subprocess. | 412 // Start the device. Then, before the first frame, signal an error and deliver |
425 // Then, signal an error and deliver the frame. The error should be propagated | 413 // the frame. The error should be propagated to clients; the frame should not |
426 // to clients; the frame should not be. | 414 // be. |
427 device_->OnFrameInfo(device_format); | |
428 EXPECT_CALL(*client_a_, DoFrameInfo(route_id)).Times(1); | |
429 EXPECT_CALL(*client_a_, DoBufferCreated(route_id)).Times(kPoolSize); | |
430 base::RunLoop().RunUntilIdle(); | 415 base::RunLoop().RunUntilIdle(); |
431 Mock::VerifyAndClearExpectations(client_a_.get()); | 416 Mock::VerifyAndClearExpectations(client_a_.get()); |
432 | 417 |
433 scoped_refptr<media::VideoFrame> frame = device_->ReserveOutputBuffer(); | 418 scoped_refptr<media::VideoFrame> frame = |
| 419 device_->ReserveOutputBuffer(gfx::Size(320, 240)); |
434 ASSERT_TRUE(frame); | 420 ASSERT_TRUE(frame); |
435 | 421 |
436 device_->OnError(); | 422 device_->OnError(); |
437 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); | 423 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); |
438 frame = NULL; | 424 frame = NULL; |
439 | 425 |
440 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); | 426 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); |
441 base::RunLoop().RunUntilIdle(); | 427 base::RunLoop().RunUntilIdle(); |
442 Mock::VerifyAndClearExpectations(client_a_.get()); | 428 Mock::VerifyAndClearExpectations(client_a_.get()); |
443 | 429 |
444 // Second client connects after the error state. It also should get told of | 430 // Second client connects after the error state. It also should get told of |
445 // the error. | 431 // the error. |
446 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 432 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
447 controller_->AddClient(route_id, client_b_.get(), | 433 controller_->AddClient(route_id, client_b_.get(), |
448 base::kNullProcessHandle, session_200); | 434 base::kNullProcessHandle, session_200); |
449 Mock::VerifyAndClearExpectations(client_b_.get()); | 435 Mock::VerifyAndClearExpectations(client_b_.get()); |
450 } | 436 } |
451 | 437 |
452 } // namespace content | 438 } // namespace content |
OLD | NEW |