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

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

Issue 175223003: HW Video: Make media::VideoFrame handle the sync point of the compositor as well as webgl (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: rebase to ToT Created 6 years, 7 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 <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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 const media::VideoCaptureFormat& format, 63 const media::VideoCaptureFormat& format,
64 base::TimeTicks timestamp) OVERRIDE { 64 base::TimeTicks timestamp) OVERRIDE {
65 DoBufferReady(id); 65 DoBufferReady(id);
66 base::MessageLoop::current()->PostTask( 66 base::MessageLoop::current()->PostTask(
67 FROM_HERE, 67 FROM_HERE,
68 base::Bind(&VideoCaptureController::ReturnBuffer, 68 base::Bind(&VideoCaptureController::ReturnBuffer,
69 base::Unretained(controller_), 69 base::Unretained(controller_),
70 id, 70 id,
71 this, 71 this,
72 buffer_id, 72 buffer_id,
73 0)); 73 std::vector<uint32>()));
74 } 74 }
75 virtual void OnMailboxBufferReady(const VideoCaptureControllerID& id, 75 virtual void OnMailboxBufferReady(const VideoCaptureControllerID& id,
76 int buffer_id, 76 int buffer_id,
77 const gpu::MailboxHolder& mailbox_holder, 77 const gpu::MailboxHolder& mailbox_holder,
78 const media::VideoCaptureFormat& format, 78 const media::VideoCaptureFormat& format,
79 base::TimeTicks timestamp) OVERRIDE { 79 base::TimeTicks timestamp) OVERRIDE {
80 DoMailboxBufferReady(id); 80 DoMailboxBufferReady(id);
81 // Use a very different syncpoint value when returning a new syncpoint. 81 // Use a very different syncpoint value when returning a new syncpoint.
82 const uint32 new_sync_point = ~mailbox_holder.sync_point; 82 std::vector<uint32> release_sync_points;
83 release_sync_points.push_back(~mailbox_holder.sync_point);
83 base::MessageLoop::current()->PostTask( 84 base::MessageLoop::current()->PostTask(
84 FROM_HERE, 85 FROM_HERE,
85 base::Bind(&VideoCaptureController::ReturnBuffer, 86 base::Bind(&VideoCaptureController::ReturnBuffer,
86 base::Unretained(controller_), 87 base::Unretained(controller_),
87 id, 88 id,
88 this, 89 this,
89 buffer_id, 90 buffer_id,
90 new_sync_point)); 91 release_sync_points));
91 } 92 }
92 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE { 93 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE {
93 DoEnded(id); 94 DoEnded(id);
94 // OnEnded() must respond by (eventually) unregistering the client. 95 // OnEnded() must respond by (eventually) unregistering the client.
95 base::MessageLoop::current()->PostTask(FROM_HERE, 96 base::MessageLoop::current()->PostTask(FROM_HERE,
96 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), 97 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient),
97 base::Unretained(controller_), id, this)); 98 base::Unretained(controller_), id, this));
98 } 99 }
99 100
100 VideoCaptureController* controller_; 101 VideoCaptureController* controller_;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 ASSERT_EQ(1, controller_->GetClientCount()) 256 ASSERT_EQ(1, controller_->GetClientCount())
256 << "Removing non-existant session 200 should be a no-op."; 257 << "Removing non-existant session 200 should be a no-op.";
257 ASSERT_EQ(400, 258 ASSERT_EQ(400,
258 controller_->RemoveClient(client_b_route_2, client_b_.get())) 259 controller_->RemoveClient(client_b_route_2, client_b_.get()))
259 << "Removing client B/2 should return its session_id."; 260 << "Removing client B/2 should return its session_id.";
260 // Clients in controller: [] 261 // Clients in controller: []
261 ASSERT_EQ(0, controller_->GetClientCount()) 262 ASSERT_EQ(0, controller_->GetClientCount())
262 << "Client count should return to zero after all clients are gone."; 263 << "Client count should return to zero after all clients are gone.";
263 } 264 }
264 265
265 static void CacheSyncPoint(uint32* sync_value, 266 static void CacheSyncPoint(std::vector<uint32>* called_release_sync_points,
266 scoped_ptr<gpu::MailboxHolder> mailbox_holder) { 267 const std::vector<uint32>& release_sync_points) {
267 *sync_value = mailbox_holder->sync_point; 268 DCHECK(called_release_sync_points->empty());
269 called_release_sync_points->assign(release_sync_points.begin(),
270 release_sync_points.end());
268 } 271 }
269 272
270 // This test will connect and disconnect several clients while simulating an 273 // This test will connect and disconnect several clients while simulating an
271 // active capture device being started and generating frames. It runs on one 274 // active capture device being started and generating frames. It runs on one
272 // thread and is intended to behave deterministically. 275 // thread and is intended to behave deterministically.
273 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { 276 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) {
274 media::VideoCaptureParams session_100; 277 media::VideoCaptureParams session_100;
275 session_100.requested_format = media::VideoCaptureFormat( 278 session_100.requested_format = media::VideoCaptureFormat(
276 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); 279 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420);
277 280
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 device_->OnIncomingCapturedVideoFrame( 477 device_->OnIncomingCapturedVideoFrame(
475 buffer, 478 buffer,
476 media::VideoCaptureFormat(capture_resolution, 479 media::VideoCaptureFormat(capture_resolution,
477 device_format.frame_rate, 480 device_format.frame_rate,
478 media::PIXEL_FORMAT_I420), 481 media::PIXEL_FORMAT_I420),
479 WrapI420Buffer(buffer, capture_resolution), 482 WrapI420Buffer(buffer, capture_resolution),
480 base::TimeTicks()); 483 base::TimeTicks());
481 buffer = NULL; 484 buffer = NULL;
482 } 485 }
483 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); 486 std::vector<uint32> mailbox_syncpoints(mailbox_buffers);
484 std::vector<uint32> mailbox_syncpoints_new(mailbox_buffers); 487 std::vector<std::vector<uint32> > release_syncpoint_vectors(mailbox_buffers);
485 for (int i = 0; i < mailbox_buffers; ++i) { 488 for (int i = 0; i < mailbox_buffers; ++i) {
486 buffer = device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, 489 buffer = device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE,
487 gfx::Size(0, 0)); 490 gfx::Size(0, 0));
488 ASSERT_TRUE(buffer); 491 ASSERT_TRUE(buffer);
489 mailbox_syncpoints[i] = i; 492 mailbox_syncpoints[i] = i;
490 device_->OnIncomingCapturedVideoFrame( 493 device_->OnIncomingCapturedVideoFrame(
491 buffer, 494 buffer,
492 media::VideoCaptureFormat(capture_resolution, 495 media::VideoCaptureFormat(capture_resolution,
493 device_format.frame_rate, 496 device_format.frame_rate,
494 media::PIXEL_FORMAT_TEXTURE), 497 media::PIXEL_FORMAT_TEXTURE),
495 WrapMailboxBuffer( 498 WrapMailboxBuffer(
496 buffer, 499 buffer,
497 make_scoped_ptr(new gpu::MailboxHolder( 500 make_scoped_ptr(new gpu::MailboxHolder(
498 gpu::Mailbox(), 0, mailbox_syncpoints[i])), 501 gpu::Mailbox(), 0, mailbox_syncpoints[i])),
499 base::Bind(&CacheSyncPoint, &mailbox_syncpoints_new[i]), 502 base::Bind(&CacheSyncPoint, &release_syncpoint_vectors[i]),
500 capture_resolution), 503 capture_resolution),
501 base::TimeTicks()); 504 base::TimeTicks());
502 buffer = NULL; 505 buffer = NULL;
503 } 506 }
504 // ReserveOutputBuffers ought to fail now regardless of buffer format, because 507 // ReserveOutputBuffers ought to fail now regardless of buffer format, because
505 // the pool is depleted. 508 // the pool is depleted.
506 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, 509 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420,
507 capture_resolution)); 510 capture_resolution));
508 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, 511 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE,
509 gfx::Size(0, 0))); 512 gfx::Size(0, 0)));
510 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(shm_buffers); 513 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(shm_buffers);
511 EXPECT_CALL(*client_b_, DoMailboxBufferReady(client_b_route_2)) 514 EXPECT_CALL(*client_b_, DoMailboxBufferReady(client_b_route_2))
512 .Times(mailbox_buffers); 515 .Times(mailbox_buffers);
513 base::RunLoop().RunUntilIdle(); 516 base::RunLoop().RunUntilIdle();
514 for (size_t i = 0; i < mailbox_syncpoints.size(); ++i) { 517 for (size_t i = 0; i < mailbox_syncpoints.size(); ++i) {
515 // See: MockVideoCaptureControllerEventHandler::OnMailboxBufferReady() 518 // See: MockVideoCaptureControllerEventHandler::OnMailboxBufferReady()
516 ASSERT_EQ(mailbox_syncpoints[i], ~mailbox_syncpoints_new[i]); 519 ASSERT_EQ(1u, release_syncpoint_vectors[i].size());
520 ASSERT_EQ(mailbox_syncpoints[i], ~release_syncpoint_vectors[i][0]);
517 } 521 }
518 Mock::VerifyAndClearExpectations(client_b_.get()); 522 Mock::VerifyAndClearExpectations(client_b_.get());
519 } 523 }
520 524
521 // Exercises the OnError() codepath of VideoCaptureController, and tests the 525 // Exercises the OnError() codepath of VideoCaptureController, and tests the
522 // behavior of various operations after the error state has been signalled. 526 // behavior of various operations after the error state has been signalled.
523 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { 527 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) {
524 media::VideoCaptureParams session_100; 528 media::VideoCaptureParams session_100;
525 session_100.requested_format = media::VideoCaptureFormat( 529 session_100.requested_format = media::VideoCaptureFormat(
526 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); 530 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 609
606 // Second client connects after the error state. It also should get told of 610 // Second client connects after the error state. It also should get told of
607 // the error. 611 // the error.
608 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); 612 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1);
609 controller_->AddClient( 613 controller_->AddClient(
610 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); 614 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200);
611 Mock::VerifyAndClearExpectations(client_b_.get()); 615 Mock::VerifyAndClearExpectations(client_b_.get());
612 } 616 }
613 617
614 } // namespace content 618 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698