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

Side by Side Diff: content/browser/renderer_host/media/video_capture_controller_unittest.cc

Issue 2613793007: Revert of [Mojo Video Capture] Simplify media::VideoCaptureDevice::Client:Buffer to a struct (Closed)
Patch Set: Created 3 years, 11 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 unified diff | Download patch
OLDNEW
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 "content/browser/renderer_host/media/video_capture_controller.h" 7 #include "content/browser/renderer_host/media/video_capture_controller.h"
8 8
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 : public media::VideoFrameConsumerFeedbackObserver { 108 : public media::VideoFrameConsumerFeedbackObserver {
109 public: 109 public:
110 MOCK_METHOD2(OnUtilizationReport, 110 MOCK_METHOD2(OnUtilizationReport,
111 void(int frame_feedback_id, double utilization)); 111 void(int frame_feedback_id, double utilization));
112 }; 112 };
113 113
114 class MockFrameBufferPool : public media::FrameBufferPool { 114 class MockFrameBufferPool : public media::FrameBufferPool {
115 public: 115 public:
116 MOCK_METHOD1(SetBufferHold, void(int buffer_id)); 116 MOCK_METHOD1(SetBufferHold, void(int buffer_id));
117 MOCK_METHOD1(ReleaseBufferHold, void(int buffer_id)); 117 MOCK_METHOD1(ReleaseBufferHold, void(int buffer_id));
118 MOCK_METHOD1(GetHandleForTransit,
119 mojo::ScopedSharedBufferHandle(int buffer_id));
118 }; 120 };
119 121
120 // Test class. 122 // Test class.
121 class VideoCaptureControllerTest 123 class VideoCaptureControllerTest
122 : public testing::Test, 124 : public testing::Test,
123 public testing::WithParamInterface<media::VideoPixelFormat> { 125 public testing::WithParamInterface<media::VideoPixelFormat> {
124 public: 126 public:
125 VideoCaptureControllerTest() {} 127 VideoCaptureControllerTest() {}
126 ~VideoCaptureControllerTest() override {} 128 ~VideoCaptureControllerTest() override {}
127 129
(...skipping 15 matching lines...) Expand all
143 base::Bind(&media::VideoFrameReceiver::OnIncomingCapturedVideoFrame, 145 base::Bind(&media::VideoFrameReceiver::OnIncomingCapturedVideoFrame,
144 controller_->GetWeakPtrForIOThread())))); 146 controller_->GetWeakPtrForIOThread()))));
145 auto frame_receiver_observer = base::MakeUnique<MockFrameBufferPool>(); 147 auto frame_receiver_observer = base::MakeUnique<MockFrameBufferPool>();
146 mock_frame_receiver_observer_ = frame_receiver_observer.get(); 148 mock_frame_receiver_observer_ = frame_receiver_observer.get();
147 controller_->SetFrameBufferPool(std::move(frame_receiver_observer)); 149 controller_->SetFrameBufferPool(std::move(frame_receiver_observer));
148 auto consumer_feedback_observer = 150 auto consumer_feedback_observer =
149 base::MakeUnique<MockConsumerFeedbackObserver>(); 151 base::MakeUnique<MockConsumerFeedbackObserver>();
150 mock_consumer_feedback_observer_ = consumer_feedback_observer.get(); 152 mock_consumer_feedback_observer_ = consumer_feedback_observer.get();
151 controller_->SetConsumerFeedbackObserver( 153 controller_->SetConsumerFeedbackObserver(
152 std::move(consumer_feedback_observer)); 154 std::move(consumer_feedback_observer));
153 client_a_.reset( 155 client_a_.reset(new MockVideoCaptureControllerEventHandler(
154 new MockVideoCaptureControllerEventHandler(controller_.get())); 156 controller_.get()));
155 client_b_.reset( 157 client_b_.reset(new MockVideoCaptureControllerEventHandler(
156 new MockVideoCaptureControllerEventHandler(controller_.get())); 158 controller_.get()));
157 } 159 }
158 160
159 void TearDown() override { base::RunLoop().RunUntilIdle(); } 161 void TearDown() override { base::RunLoop().RunUntilIdle(); }
160 162
161 TestBrowserThreadBundle bundle_; 163 TestBrowserThreadBundle bundle_;
162 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_; 164 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_;
163 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; 165 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_;
164 std::unique_ptr<VideoCaptureController> controller_; 166 std::unique_ptr<VideoCaptureController> controller_;
165 std::unique_ptr<media::VideoCaptureDevice::Client> device_client_; 167 std::unique_ptr<media::VideoCaptureDevice::Client> device_client_;
166 MockFrameBufferPool* mock_frame_receiver_observer_; 168 MockFrameBufferPool* mock_frame_receiver_observer_;
(...skipping 21 matching lines...) Expand all
188 // Intentionally use the same route ID for two of the clients: the device_ids 190 // Intentionally use the same route ID for two of the clients: the device_ids
189 // are a per-VideoCaptureHost namespace, and can overlap across hosts. 191 // are a per-VideoCaptureHost namespace, and can overlap across hosts.
190 const VideoCaptureControllerID client_a_route_1(44); 192 const VideoCaptureControllerID client_a_route_1(44);
191 const VideoCaptureControllerID client_a_route_2(30); 193 const VideoCaptureControllerID client_a_route_2(30);
192 const VideoCaptureControllerID client_b_route_1(30); 194 const VideoCaptureControllerID client_b_route_1(30);
193 const VideoCaptureControllerID client_b_route_2(1); 195 const VideoCaptureControllerID client_b_route_2(1);
194 196
195 // Clients in controller: [] 197 // Clients in controller: []
196 ASSERT_EQ(0, controller_->GetClientCount()) 198 ASSERT_EQ(0, controller_->GetClientCount())
197 << "Client count should initially be zero."; 199 << "Client count should initially be zero.";
198 controller_->AddClient(client_a_route_1, client_a_.get(), 100, session_100); 200 controller_->AddClient(client_a_route_1,
201 client_a_.get(),
202 100,
203 session_100);
199 // Clients in controller: [A/1] 204 // Clients in controller: [A/1]
200 ASSERT_EQ(1, controller_->GetClientCount()) 205 ASSERT_EQ(1, controller_->GetClientCount())
201 << "Adding client A/1 should bump client count."; 206 << "Adding client A/1 should bump client count.";
202 controller_->AddClient(client_a_route_2, client_a_.get(), 200, session_200); 207 controller_->AddClient(client_a_route_2,
208 client_a_.get(),
209 200,
210 session_200);
203 // Clients in controller: [A/1, A/2] 211 // Clients in controller: [A/1, A/2]
204 ASSERT_EQ(2, controller_->GetClientCount()) 212 ASSERT_EQ(2, controller_->GetClientCount())
205 << "Adding client A/2 should bump client count."; 213 << "Adding client A/2 should bump client count.";
206 controller_->AddClient(client_b_route_1, client_b_.get(), 300, session_300); 214 controller_->AddClient(client_b_route_1,
215 client_b_.get(),
216 300,
217 session_300);
207 // Clients in controller: [A/1, A/2, B/1] 218 // Clients in controller: [A/1, A/2, B/1]
208 ASSERT_EQ(3, controller_->GetClientCount()) 219 ASSERT_EQ(3, controller_->GetClientCount())
209 << "Adding client B/1 should bump client count."; 220 << "Adding client B/1 should bump client count.";
210 ASSERT_EQ(200, controller_->RemoveClient(client_a_route_2, client_a_.get())) 221 ASSERT_EQ(200,
222 controller_->RemoveClient(client_a_route_2, client_a_.get()))
211 << "Removing client A/1 should return its session_id."; 223 << "Removing client A/1 should return its session_id.";
212 // Clients in controller: [A/1, B/1] 224 // Clients in controller: [A/1, B/1]
213 ASSERT_EQ(2, controller_->GetClientCount()); 225 ASSERT_EQ(2, controller_->GetClientCount());
214 ASSERT_EQ(static_cast<int>(kInvalidMediaCaptureSessionId), 226 ASSERT_EQ(static_cast<int>(kInvalidMediaCaptureSessionId),
215 controller_->RemoveClient(client_a_route_2, client_a_.get())) 227 controller_->RemoveClient(client_a_route_2, client_a_.get()))
216 << "Removing a nonexistant client should fail."; 228 << "Removing a nonexistant client should fail.";
217 // Clients in controller: [A/1, B/1] 229 // Clients in controller: [A/1, B/1]
218 ASSERT_EQ(2, controller_->GetClientCount()); 230 ASSERT_EQ(2, controller_->GetClientCount());
219 ASSERT_EQ(300, controller_->RemoveClient(client_b_route_1, client_b_.get())) 231 ASSERT_EQ(300,
232 controller_->RemoveClient(client_b_route_1, client_b_.get()))
220 << "Removing client B/1 should return its session_id."; 233 << "Removing client B/1 should return its session_id.";
221 // Clients in controller: [A/1] 234 // Clients in controller: [A/1]
222 ASSERT_EQ(1, controller_->GetClientCount()); 235 ASSERT_EQ(1, controller_->GetClientCount());
223 controller_->AddClient(client_b_route_2, client_b_.get(), 400, session_400); 236 controller_->AddClient(client_b_route_2,
237 client_b_.get(),
238 400,
239 session_400);
224 // Clients in controller: [A/1, B/2] 240 // Clients in controller: [A/1, B/2]
225 241
226 EXPECT_CALL(*client_a_, DoEnded(client_a_route_1)).Times(1); 242 EXPECT_CALL(*client_a_, DoEnded(client_a_route_1)).Times(1);
227 controller_->StopSession(100); // Session 100 == client A/1 243 controller_->StopSession(100); // Session 100 == client A/1
228 Mock::VerifyAndClearExpectations(client_a_.get()); 244 Mock::VerifyAndClearExpectations(client_a_.get());
229 ASSERT_EQ(2, controller_->GetClientCount()) 245 ASSERT_EQ(2, controller_->GetClientCount())
230 << "Client should be closed but still exist after StopSession."; 246 << "Client should be closed but still exist after StopSession.";
231 // Clients in controller: [A/1 (closed, removal pending), B/2] 247 // Clients in controller: [A/1 (closed, removal pending), B/2]
232 base::RunLoop().RunUntilIdle(); 248 base::RunLoop().RunUntilIdle();
233 // Clients in controller: [B/2] 249 // Clients in controller: [B/2]
234 ASSERT_EQ(1, controller_->GetClientCount()) 250 ASSERT_EQ(1, controller_->GetClientCount())
235 << "Client A/1 should be deleted by now."; 251 << "Client A/1 should be deleted by now.";
236 controller_->StopSession(200); // Session 200 does not exist anymore 252 controller_->StopSession(200); // Session 200 does not exist anymore
237 // Clients in controller: [B/2] 253 // Clients in controller: [B/2]
238 ASSERT_EQ(1, controller_->GetClientCount()) 254 ASSERT_EQ(1, controller_->GetClientCount())
239 << "Stopping non-existant session 200 should be a no-op."; 255 << "Stopping non-existant session 200 should be a no-op.";
240 controller_->StopSession(256); // Session 256 never existed. 256 controller_->StopSession(256); // Session 256 never existed.
241 // Clients in controller: [B/2] 257 // Clients in controller: [B/2]
242 ASSERT_EQ(1, controller_->GetClientCount()) 258 ASSERT_EQ(1, controller_->GetClientCount())
243 << "Stopping non-existant session 256 should be a no-op."; 259 << "Stopping non-existant session 256 should be a no-op.";
244 ASSERT_EQ(static_cast<int>(kInvalidMediaCaptureSessionId), 260 ASSERT_EQ(static_cast<int>(kInvalidMediaCaptureSessionId),
245 controller_->RemoveClient(client_a_route_1, client_a_.get())) 261 controller_->RemoveClient(client_a_route_1, client_a_.get()))
246 << "Removing already-removed client A/1 should fail."; 262 << "Removing already-removed client A/1 should fail.";
247 // Clients in controller: [B/2] 263 // Clients in controller: [B/2]
248 ASSERT_EQ(1, controller_->GetClientCount()) 264 ASSERT_EQ(1, controller_->GetClientCount())
249 << "Removing non-existant session 200 should be a no-op."; 265 << "Removing non-existant session 200 should be a no-op.";
250 ASSERT_EQ(400, controller_->RemoveClient(client_b_route_2, client_b_.get())) 266 ASSERT_EQ(400,
267 controller_->RemoveClient(client_b_route_2, client_b_.get()))
251 << "Removing client B/2 should return its session_id."; 268 << "Removing client B/2 should return its session_id.";
252 // Clients in controller: [] 269 // Clients in controller: []
253 ASSERT_EQ(0, controller_->GetClientCount()) 270 ASSERT_EQ(0, controller_->GetClientCount())
254 << "Client count should return to zero after all clients are gone."; 271 << "Client count should return to zero after all clients are gone.";
255 } 272 }
256 273
257 // This test will connect and disconnect several clients while simulating an 274 // This test will connect and disconnect several clients while simulating an
258 // active capture device being started and generating frames. It runs on one 275 // active capture device being started and generating frames. It runs on one
259 // thread and is intended to behave deterministically. 276 // thread and is intended to behave deterministically.
260 TEST_P(VideoCaptureControllerTest, NormalCaptureMultipleClients) { 277 TEST_P(VideoCaptureControllerTest, NormalCaptureMultipleClients) {
(...skipping 11 matching lines...) Expand all
272 289
273 media::VideoCaptureParams session_1 = session_100; 290 media::VideoCaptureParams session_1 = session_100;
274 291
275 media::VideoCaptureFormat device_format(gfx::Size(444, 200), 25, format); 292 media::VideoCaptureFormat device_format(gfx::Size(444, 200), 25, format);
276 293
277 const VideoCaptureControllerID client_a_route_1(0xa1a1a1a1); 294 const VideoCaptureControllerID client_a_route_1(0xa1a1a1a1);
278 const VideoCaptureControllerID client_a_route_2(0xa2a2a2a2); 295 const VideoCaptureControllerID client_a_route_2(0xa2a2a2a2);
279 const VideoCaptureControllerID client_b_route_1(0xb1b1b1b1); 296 const VideoCaptureControllerID client_b_route_1(0xb1b1b1b1);
280 const VideoCaptureControllerID client_b_route_2(0xb2b2b2b2); 297 const VideoCaptureControllerID client_b_route_2(0xb2b2b2b2);
281 298
282 controller_->AddClient(client_a_route_1, client_a_.get(), 100, session_100); 299 controller_->AddClient(client_a_route_1,
283 controller_->AddClient(client_b_route_1, client_b_.get(), 300, session_300); 300 client_a_.get(),
284 controller_->AddClient(client_a_route_2, client_a_.get(), 200, session_200); 301 100,
302 session_100);
303 controller_->AddClient(client_b_route_1,
304 client_b_.get(),
305 300,
306 session_300);
307 controller_->AddClient(client_a_route_2,
308 client_a_.get(),
309 200,
310 session_200);
285 ASSERT_EQ(3, controller_->GetClientCount()); 311 ASSERT_EQ(3, controller_->GetClientCount());
286 312
287 // Now, simulate an incoming captured buffer from the capture device. As a 313 // Now, simulate an incoming captured buffer from the capture device. As a
288 // side effect this will cause the first buffer to be shared with clients. 314 // side effect this will cause the first buffer to be shared with clients.
289 uint8_t buffer_no = 1; 315 uint8_t buffer_no = 1;
290 const int arbitrary_frame_feedback_id = 101; 316 const int arbitrary_frame_feedback_id = 101;
291 ASSERT_EQ(0.0, device_client_->GetBufferPoolUtilization()); 317 ASSERT_EQ(0.0, device_client_->GetBufferPoolUtilization());
292 media::VideoCaptureDevice::Client::Buffer buffer = 318 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer(
293 device_client_->ReserveOutputBuffer( 319 device_client_->ReserveOutputBuffer(device_format.frame_size,
294 device_format.frame_size, device_format.pixel_format, 320 device_format.pixel_format,
295 device_format.pixel_storage, arbitrary_frame_feedback_id); 321 device_format.pixel_storage,
296 ASSERT_TRUE(buffer.is_valid()); 322 arbitrary_frame_feedback_id));
297 auto buffer_access = buffer.handle_provider()->GetHandleForInProcessAccess(); 323 ASSERT_TRUE(buffer.get());
298 ASSERT_EQ(1.0 / kPoolSize, device_client_->GetBufferPoolUtilization()); 324 ASSERT_EQ(1.0 / kPoolSize, device_client_->GetBufferPoolUtilization());
299 memset(buffer_access->data(), buffer_no++, buffer_access->mapped_size()); 325 memset(buffer->data(), buffer_no++, buffer->mapped_size());
300 { 326 {
301 InSequence s; 327 InSequence s;
302 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); 328 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1);
303 EXPECT_CALL(*client_a_, 329 EXPECT_CALL(*client_a_,
304 DoBufferReady(client_a_route_1, device_format.frame_size)) 330 DoBufferReady(client_a_route_1, device_format.frame_size))
305 .Times(1); 331 .Times(1);
306 } 332 }
307 { 333 {
308 InSequence s; 334 InSequence s;
309 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); 335 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1);
310 EXPECT_CALL(*client_b_, 336 EXPECT_CALL(*client_b_,
311 DoBufferReady(client_b_route_1, device_format.frame_size)) 337 DoBufferReady(client_b_route_1, device_format.frame_size))
312 .Times(1); 338 .Times(1);
313 } 339 }
314 { 340 {
315 InSequence s; 341 InSequence s;
316 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); 342 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1);
317 EXPECT_CALL(*client_a_, 343 EXPECT_CALL(*client_a_,
318 DoBufferReady(client_a_route_2, device_format.frame_size)) 344 DoBufferReady(client_a_route_2, device_format.frame_size))
319 .Times(1); 345 .Times(1);
320 } 346 }
321 client_a_->resource_utilization_ = 0.5; 347 client_a_->resource_utilization_ = 0.5;
322 client_b_->resource_utilization_ = -1.0; 348 client_b_->resource_utilization_ = -1.0;
323 { 349 {
324 InSequence s; 350 InSequence s;
325 EXPECT_CALL(*mock_frame_receiver_observer_, SetBufferHold(buffer.id())) 351 EXPECT_CALL(*mock_frame_receiver_observer_, SetBufferHold(buffer->id()))
326 .Times(1); 352 .Times(1);
327 // Expect VideoCaptureController to call the load observer with a 353 // Expect VideoCaptureController to call the load observer with a
328 // resource utilization of 0.5 (the largest of all reported values). 354 // resource utilization of 0.5 (the largest of all reported values).
329 EXPECT_CALL(*mock_consumer_feedback_observer_, 355 EXPECT_CALL(*mock_consumer_feedback_observer_,
330 OnUtilizationReport(arbitrary_frame_feedback_id, 0.5)) 356 OnUtilizationReport(arbitrary_frame_feedback_id, 0.5))
331 .Times(1); 357 .Times(1);
332 EXPECT_CALL(*mock_frame_receiver_observer_, ReleaseBufferHold(buffer.id())) 358 EXPECT_CALL(*mock_frame_receiver_observer_, ReleaseBufferHold(buffer->id()))
333 .Times(1); 359 .Times(1);
334 } 360 }
335 361
336 device_client_->OnIncomingCapturedBuffer(std::move(buffer), device_format, 362 device_client_->OnIncomingCapturedBuffer(std::move(buffer),
337 arbitrary_reference_time_, 363 device_format,
338 arbitrary_timestamp_); 364 arbitrary_reference_time_,
365 arbitrary_timestamp_);
339 366
340 base::RunLoop().RunUntilIdle(); 367 base::RunLoop().RunUntilIdle();
341 Mock::VerifyAndClearExpectations(client_a_.get()); 368 Mock::VerifyAndClearExpectations(client_a_.get());
342 Mock::VerifyAndClearExpectations(client_b_.get()); 369 Mock::VerifyAndClearExpectations(client_b_.get());
343 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_); 370 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_);
344 Mock::VerifyAndClearExpectations(mock_frame_receiver_observer_); 371 Mock::VerifyAndClearExpectations(mock_frame_receiver_observer_);
345 372
346 // Second buffer which ought to use the same shared memory buffer. In this 373 // Second buffer which ought to use the same shared memory buffer. In this
347 // case pretend that the Buffer pointer is held by the device for a long 374 // case pretend that the Buffer pointer is held by the device for a long
348 // delay. This shouldn't affect anything. 375 // delay. This shouldn't affect anything.
349 const int arbitrary_frame_feedback_id_2 = 102; 376 const int arbitrary_frame_feedback_id_2 = 102;
350 media::VideoCaptureDevice::Client::Buffer buffer2 = 377 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 =
351 device_client_->ReserveOutputBuffer( 378 device_client_->ReserveOutputBuffer(device_format.frame_size,
352 device_format.frame_size, device_format.pixel_format, 379 device_format.pixel_format,
353 device_format.pixel_storage, arbitrary_frame_feedback_id_2); 380 device_format.pixel_storage,
354 ASSERT_TRUE(buffer2.is_valid()); 381 arbitrary_frame_feedback_id_2);
355 auto buffer2_access = 382 ASSERT_TRUE(buffer2.get());
356 buffer2.handle_provider()->GetHandleForInProcessAccess(); 383 memset(buffer2->data(), buffer_no++, buffer2->mapped_size());
357 memset(buffer2_access->data(), buffer_no++, buffer2_access->mapped_size());
358 client_a_->resource_utilization_ = 0.5; 384 client_a_->resource_utilization_ = 0.5;
359 client_b_->resource_utilization_ = 3.14; 385 client_b_->resource_utilization_ = 3.14;
360 // Expect VideoCaptureController to call the load observer with a 386 // Expect VideoCaptureController to call the load observer with a
361 // resource utilization of 3.14 (the largest of all reported values). 387 // resource utilization of 3.14 (the largest of all reported values).
362 { 388 {
363 InSequence s; 389 InSequence s;
364 EXPECT_CALL(*mock_frame_receiver_observer_, SetBufferHold(buffer2.id())) 390 EXPECT_CALL(*mock_frame_receiver_observer_, SetBufferHold(buffer2->id()))
365 .Times(1); 391 .Times(1);
366 // Expect VideoCaptureController to call the load observer with a 392 // Expect VideoCaptureController to call the load observer with a
367 // resource utilization of 3.14 (the largest of all reported values). 393 // resource utilization of 3.14 (the largest of all reported values).
368 EXPECT_CALL(*mock_consumer_feedback_observer_, 394 EXPECT_CALL(*mock_consumer_feedback_observer_,
369 OnUtilizationReport(arbitrary_frame_feedback_id_2, 3.14)) 395 OnUtilizationReport(arbitrary_frame_feedback_id_2, 3.14))
370 .Times(1); 396 .Times(1);
371 EXPECT_CALL(*mock_frame_receiver_observer_, ReleaseBufferHold(buffer2.id())) 397 EXPECT_CALL(*mock_frame_receiver_observer_,
398 ReleaseBufferHold(buffer2->id()))
372 .Times(1); 399 .Times(1);
373 } 400 }
374 401
375 device_client_->OnIncomingCapturedBuffer(std::move(buffer2), device_format, 402 device_client_->OnIncomingCapturedBuffer(std::move(buffer2),
376 arbitrary_reference_time_, 403 device_format,
377 arbitrary_timestamp_); 404 arbitrary_reference_time_,
405 arbitrary_timestamp_);
378 406
379 // The buffer should be delivered to the clients in any order. 407 // The buffer should be delivered to the clients in any order.
380 { 408 {
381 InSequence s; 409 InSequence s;
382 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); 410 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1);
383 EXPECT_CALL(*client_a_, 411 EXPECT_CALL(*client_a_,
384 DoBufferReady(client_a_route_1, device_format.frame_size)) 412 DoBufferReady(client_a_route_1, device_format.frame_size))
385 .Times(1); 413 .Times(1);
386 } 414 }
387 { 415 {
(...skipping 10 matching lines...) Expand all
398 DoBufferReady(client_a_route_2, device_format.frame_size)) 426 DoBufferReady(client_a_route_2, device_format.frame_size))
399 .Times(1); 427 .Times(1);
400 } 428 }
401 base::RunLoop().RunUntilIdle(); 429 base::RunLoop().RunUntilIdle();
402 Mock::VerifyAndClearExpectations(client_a_.get()); 430 Mock::VerifyAndClearExpectations(client_a_.get());
403 Mock::VerifyAndClearExpectations(client_b_.get()); 431 Mock::VerifyAndClearExpectations(client_b_.get());
404 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_); 432 Mock::VerifyAndClearExpectations(mock_consumer_feedback_observer_);
405 Mock::VerifyAndClearExpectations(mock_frame_receiver_observer_); 433 Mock::VerifyAndClearExpectations(mock_frame_receiver_observer_);
406 434
407 // Add a fourth client now that some buffers have come through. 435 // Add a fourth client now that some buffers have come through.
408 controller_->AddClient(client_b_route_2, client_b_.get(), 1, session_1); 436 controller_->AddClient(client_b_route_2,
437 client_b_.get(),
438 1,
439 session_1);
409 Mock::VerifyAndClearExpectations(client_b_.get()); 440 Mock::VerifyAndClearExpectations(client_b_.get());
410 441
411 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. 442 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time.
412 for (int i = 0; i < kPoolSize; i++) { 443 for (int i = 0; i < kPoolSize; i++) {
413 const int arbitrary_frame_feedback_id = 200 + i; 444 const int arbitrary_frame_feedback_id = 200 + i;
414 media::VideoCaptureDevice::Client::Buffer buffer = 445 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer =
415 device_client_->ReserveOutputBuffer( 446 device_client_->ReserveOutputBuffer(device_format.frame_size,
416 device_format.frame_size, device_format.pixel_format, 447 device_format.pixel_format,
417 device_format.pixel_storage, arbitrary_frame_feedback_id); 448 device_format.pixel_storage,
418 ASSERT_TRUE(buffer.is_valid()); 449 arbitrary_frame_feedback_id);
419 auto buffer_access = 450 ASSERT_TRUE(buffer.get());
420 buffer.handle_provider()->GetHandleForInProcessAccess(); 451 memset(buffer->data(), buffer_no++, buffer->mapped_size());
421 memset(buffer_access->data(), buffer_no++, buffer_access->mapped_size()); 452 device_client_->OnIncomingCapturedBuffer(std::move(buffer),
422 device_client_->OnIncomingCapturedBuffer(std::move(buffer), device_format, 453 device_format,
423 arbitrary_reference_time_, 454 arbitrary_reference_time_,
424 arbitrary_timestamp_); 455 arbitrary_timestamp_);
425 } 456 }
426 // ReserveOutputBuffer ought to fail now, because the pool is depleted. 457 // ReserveOutputBuffer ought to fail now, because the pool is depleted.
427 ASSERT_FALSE(device_client_ 458 ASSERT_FALSE(device_client_
428 ->ReserveOutputBuffer( 459 ->ReserveOutputBuffer(device_format.frame_size,
429 device_format.frame_size, device_format.pixel_format, 460 device_format.pixel_format,
430 device_format.pixel_storage, arbitrary_frame_feedback_id) 461 device_format.pixel_storage,
431 .is_valid()); 462 arbitrary_frame_feedback_id)
463 .get());
432 464
433 // The new client needs to be notified of the creation of |kPoolSize| buffers; 465 // The new client needs to be notified of the creation of |kPoolSize| buffers;
434 // the old clients only |kPoolSize - 2|. 466 // the old clients only |kPoolSize - 2|.
435 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); 467 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize);
436 EXPECT_CALL(*client_b_, 468 EXPECT_CALL(*client_b_,
437 DoBufferReady(client_b_route_2, device_format.frame_size)) 469 DoBufferReady(client_b_route_2, device_format.frame_size))
438 .Times(kPoolSize); 470 .Times(kPoolSize);
439 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) 471 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1))
440 .Times(kPoolSize - 2); 472 .Times(kPoolSize - 2);
441 EXPECT_CALL(*client_a_, 473 EXPECT_CALL(*client_a_,
(...skipping 13 matching lines...) Expand all
455 Mock::VerifyAndClearExpectations(client_a_.get()); 487 Mock::VerifyAndClearExpectations(client_a_.get());
456 Mock::VerifyAndClearExpectations(client_b_.get()); 488 Mock::VerifyAndClearExpectations(client_b_.get());
457 489
458 // Now test the interaction of client shutdown and buffer delivery. 490 // Now test the interaction of client shutdown and buffer delivery.
459 // Kill A1 via renderer disconnect (synchronous). 491 // Kill A1 via renderer disconnect (synchronous).
460 controller_->RemoveClient(client_a_route_1, client_a_.get()); 492 controller_->RemoveClient(client_a_route_1, client_a_.get());
461 // Kill B1 via session close (posts a task to disconnect). 493 // Kill B1 via session close (posts a task to disconnect).
462 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); 494 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1);
463 controller_->StopSession(300); 495 controller_->StopSession(300);
464 // Queue up another buffer. 496 // Queue up another buffer.
465 media::VideoCaptureDevice::Client::Buffer buffer3 = 497 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer3 =
466 device_client_->ReserveOutputBuffer( 498 device_client_->ReserveOutputBuffer(device_format.frame_size,
467 device_format.frame_size, device_format.pixel_format, 499 device_format.pixel_format,
468 device_format.pixel_storage, arbitrary_frame_feedback_id); 500 device_format.pixel_storage,
469 ASSERT_TRUE(buffer3.is_valid()); 501 arbitrary_frame_feedback_id);
470 auto buffer3_access = 502 ASSERT_TRUE(buffer3.get());
471 buffer3.handle_provider()->GetHandleForInProcessAccess(); 503 memset(buffer3->data(), buffer_no++, buffer3->mapped_size());
472 memset(buffer3_access->data(), buffer_no++, buffer3_access->mapped_size()); 504 device_client_->OnIncomingCapturedBuffer(std::move(buffer3),
473 device_client_->OnIncomingCapturedBuffer(std::move(buffer3), device_format, 505 device_format,
474 arbitrary_reference_time_, 506 arbitrary_reference_time_,
475 arbitrary_timestamp_); 507 arbitrary_timestamp_);
476 508
477 media::VideoCaptureDevice::Client::Buffer buffer4 = 509 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer4 =
478 device_client_->ReserveOutputBuffer( 510 device_client_->ReserveOutputBuffer(device_format.frame_size,
479 device_format.frame_size, device_format.pixel_format, 511 device_format.pixel_format,
480 device_format.pixel_storage, arbitrary_frame_feedback_id); 512 device_format.pixel_storage,
513 arbitrary_frame_feedback_id);
481 { 514 {
482 // Kill A2 via session close (posts a task to disconnect, but A2 must not 515 // Kill A2 via session close (posts a task to disconnect, but A2 must not
483 // be sent either of these two buffers). 516 // be sent either of these two buffers).
484 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); 517 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1);
485 controller_->StopSession(200); 518 controller_->StopSession(200);
486 } 519 }
487 ASSERT_TRUE(buffer4.is_valid()); 520 ASSERT_TRUE(buffer4.get());
488 auto buffer4_access = 521 memset(buffer4->data(), buffer_no++, buffer4->mapped_size());
489 buffer4.handle_provider()->GetHandleForInProcessAccess(); 522 device_client_->OnIncomingCapturedBuffer(std::move(buffer4),
490 memset(buffer4_access->data(), buffer_no++, buffer4_access->mapped_size()); 523 device_format,
491 device_client_->OnIncomingCapturedBuffer(std::move(buffer4), device_format, 524 arbitrary_reference_time_,
492 arbitrary_reference_time_, 525 arbitrary_timestamp_);
493 arbitrary_timestamp_);
494 // B2 is the only client left, and is the only one that should 526 // B2 is the only client left, and is the only one that should
495 // get the buffer. 527 // get the buffer.
496 EXPECT_CALL(*client_b_, 528 EXPECT_CALL(*client_b_,
497 DoBufferReady(client_b_route_2, device_format.frame_size)) 529 DoBufferReady(client_b_route_2, device_format.frame_size))
498 .Times(2); 530 .Times(2);
499 base::RunLoop().RunUntilIdle(); 531 base::RunLoop().RunUntilIdle();
500 Mock::VerifyAndClearExpectations(client_a_.get()); 532 Mock::VerifyAndClearExpectations(client_a_.get());
501 Mock::VerifyAndClearExpectations(client_b_.get()); 533 Mock::VerifyAndClearExpectations(client_b_.get());
502 } 534 }
503 535
(...skipping 25 matching lines...) Expand all
529 // Second client connects after the error state. It also should get told of 561 // Second client connects after the error state. It also should get told of
530 // the error. 562 // the error.
531 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); 563 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1);
532 controller_->AddClient(route_id, client_b_.get(), 200, session_200); 564 controller_->AddClient(route_id, client_b_.get(), 200, session_200);
533 base::RunLoop().RunUntilIdle(); 565 base::RunLoop().RunUntilIdle();
534 Mock::VerifyAndClearExpectations(client_b_.get()); 566 Mock::VerifyAndClearExpectations(client_b_.get());
535 567
536 media::VideoCaptureFormat device_format( 568 media::VideoCaptureFormat device_format(
537 capture_resolution, arbitrary_frame_rate_, media::PIXEL_FORMAT_I420, 569 capture_resolution, arbitrary_frame_rate_, media::PIXEL_FORMAT_I420,
538 media::PIXEL_STORAGE_CPU); 570 media::PIXEL_STORAGE_CPU);
539 const int arbitrary_frame_feedback_id = 101; 571 const int arbitrary_frame_feedback_id = 101;
540 media::VideoCaptureDevice::Client::Buffer buffer = 572 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer(
541 device_client_->ReserveOutputBuffer( 573 device_client_->ReserveOutputBuffer(device_format.frame_size,
542 device_format.frame_size, device_format.pixel_format, 574 device_format.pixel_format,
543 device_format.pixel_storage, arbitrary_frame_feedback_id); 575 device_format.pixel_storage,
544 device_client_->OnIncomingCapturedBuffer(std::move(buffer), device_format, 576 arbitrary_frame_feedback_id));
545 arbitrary_reference_time_, 577 device_client_->OnIncomingCapturedBuffer(std::move(buffer),
546 arbitrary_timestamp_); 578 device_format,
579 arbitrary_reference_time_,
580 arbitrary_timestamp_);
547 581
548 base::RunLoop().RunUntilIdle(); 582 base::RunLoop().RunUntilIdle();
549 } 583 }
550 584
551 // Exercises the OnError() codepath of VideoCaptureController, and tests the 585 // Exercises the OnError() codepath of VideoCaptureController, and tests the
552 // behavior of various operations after the error state has been signalled. 586 // behavior of various operations after the error state has been signalled.
553 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { 587 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) {
554 media::VideoCaptureParams session_100; 588 media::VideoCaptureParams session_100;
555 session_100.requested_format = media::VideoCaptureFormat( 589 session_100.requested_format = media::VideoCaptureFormat(
556 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); 590 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420);
557 591
558 media::VideoCaptureParams session_200 = session_100; 592 media::VideoCaptureParams session_200 = session_100;
559 593
560 const VideoCaptureControllerID route_id(0x99); 594 const VideoCaptureControllerID route_id(0x99);
561 595
562 // Start with one client. 596 // Start with one client.
563 controller_->AddClient(route_id, client_a_.get(), 100, session_100); 597 controller_->AddClient(route_id, client_a_.get(), 100, session_100);
564 598
565 // Start the device. Then, before the first buffer, signal an error and 599 // Start the device. Then, before the first buffer, signal an error and
566 // deliver the buffer. The error should be propagated to clients; the buffer 600 // deliver the buffer. The error should be propagated to clients; the buffer
567 // should not be. 601 // should not be.
568 base::RunLoop().RunUntilIdle(); 602 base::RunLoop().RunUntilIdle();
569 Mock::VerifyAndClearExpectations(client_a_.get()); 603 Mock::VerifyAndClearExpectations(client_a_.get());
570 604
571 media::VideoCaptureFormat device_format( 605 media::VideoCaptureFormat device_format(
572 gfx::Size(10, 10), arbitrary_frame_rate_, media::PIXEL_FORMAT_I420); 606 gfx::Size(10, 10), arbitrary_frame_rate_, media::PIXEL_FORMAT_I420);
573 const int arbitrary_frame_feedback_id = 101; 607 const int arbitrary_frame_feedback_id = 101;
574 media::VideoCaptureDevice::Client::Buffer buffer = 608 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer(
575 device_client_->ReserveOutputBuffer( 609 device_client_->ReserveOutputBuffer(device_format.frame_size,
576 device_format.frame_size, device_format.pixel_format, 610 device_format.pixel_format,
577 device_format.pixel_storage, arbitrary_frame_feedback_id); 611 device_format.pixel_storage,
578 ASSERT_TRUE(buffer.is_valid()); 612 arbitrary_frame_feedback_id));
613 ASSERT_TRUE(buffer.get());
579 614
580 device_client_->OnError(FROM_HERE, "Test Error"); 615 device_client_->OnError(FROM_HERE, "Test Error");
581 device_client_->OnIncomingCapturedBuffer(std::move(buffer), device_format, 616 device_client_->OnIncomingCapturedBuffer(std::move(buffer),
582 arbitrary_reference_time_, 617 device_format,
583 arbitrary_timestamp_); 618 arbitrary_reference_time_,
619 arbitrary_timestamp_);
584 620
585 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); 621 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1);
586 base::RunLoop().RunUntilIdle(); 622 base::RunLoop().RunUntilIdle();
587 Mock::VerifyAndClearExpectations(client_a_.get()); 623 Mock::VerifyAndClearExpectations(client_a_.get());
588 624
589 // Second client connects after the error state. It also should get told of 625 // Second client connects after the error state. It also should get told of
590 // the error. 626 // the error.
591 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); 627 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1);
592 controller_->AddClient(route_id, client_b_.get(), 200, session_200); 628 controller_->AddClient(route_id, client_b_.get(), 200, session_200);
593 Mock::VerifyAndClearExpectations(client_b_.get()); 629 Mock::VerifyAndClearExpectations(client_b_.get());
594 } 630 }
595 631
596 } // namespace content 632 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698