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

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

Issue 1427543002: Modified old wait sync point functions to also accept new sync tokens. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Folded sync_point into sync_tokens Created 5 years, 1 month 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 DoBufferDestroyed(id); 79 DoBufferDestroyed(id);
80 } 80 }
81 void OnBufferReady(VideoCaptureControllerID id, 81 void OnBufferReady(VideoCaptureControllerID id,
82 int buffer_id, 82 int buffer_id,
83 const scoped_refptr<media::VideoFrame>& frame, 83 const scoped_refptr<media::VideoFrame>& frame,
84 const base::TimeTicks& timestamp) override { 84 const base::TimeTicks& timestamp) override {
85 if (!frame->HasTextures()) { 85 if (!frame->HasTextures()) {
86 EXPECT_EQ(frame->format(), media::PIXEL_FORMAT_I420); 86 EXPECT_EQ(frame->format(), media::PIXEL_FORMAT_I420);
87 DoI420BufferReady(id, frame->coded_size()); 87 DoI420BufferReady(id, frame->coded_size());
88 base::ThreadTaskRunnerHandle::Get()->PostTask( 88 base::ThreadTaskRunnerHandle::Get()->PostTask(
89 FROM_HERE, base::Bind(&VideoCaptureController::ReturnBuffer, 89 FROM_HERE,
90 base::Unretained(controller_), id, this, 90 base::Bind(&VideoCaptureController::ReturnBuffer,
91 buffer_id, 0, resource_utilization_)); 91 base::Unretained(controller_), id, this, buffer_id, 0,
92 gpu::SyncToken(), resource_utilization_));
92 } else { 93 } else {
93 EXPECT_EQ(frame->format(), media::PIXEL_FORMAT_ARGB); 94 EXPECT_EQ(frame->format(), media::PIXEL_FORMAT_ARGB);
94 DoTextureBufferReady(id, frame->coded_size()); 95 DoTextureBufferReady(id, frame->coded_size());
95 base::ThreadTaskRunnerHandle::Get()->PostTask( 96 base::ThreadTaskRunnerHandle::Get()->PostTask(
96 FROM_HERE, base::Bind(&VideoCaptureController::ReturnBuffer, 97 FROM_HERE, base::Bind(&VideoCaptureController::ReturnBuffer,
97 base::Unretained(controller_), id, this, 98 base::Unretained(controller_), id, this,
98 buffer_id, frame->mailbox_holder(0).sync_point, 99 buffer_id, frame->mailbox_holder(0).sync_token,
99 resource_utilization_)); 100 resource_utilization_));
100 } 101 }
101 } 102 }
102 void OnEnded(VideoCaptureControllerID id) override { 103 void OnEnded(VideoCaptureControllerID id) override {
103 DoEnded(id); 104 DoEnded(id);
104 // OnEnded() must respond by (eventually) unregistering the client. 105 // OnEnded() must respond by (eventually) unregistering the client.
105 base::ThreadTaskRunnerHandle::Get()->PostTask( 106 base::ThreadTaskRunnerHandle::Get()->PostTask(
106 FROM_HERE, 107 FROM_HERE,
107 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), 108 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient),
108 base::Unretained(controller_), id, this)); 109 base::Unretained(controller_), id, this));
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 ASSERT_EQ(1, controller_->GetClientCount()) 255 ASSERT_EQ(1, controller_->GetClientCount())
255 << "Removing non-existant session 200 should be a no-op."; 256 << "Removing non-existant session 200 should be a no-op.";
256 ASSERT_EQ(400, 257 ASSERT_EQ(400,
257 controller_->RemoveClient(client_b_route_2, client_b_.get())) 258 controller_->RemoveClient(client_b_route_2, client_b_.get()))
258 << "Removing client B/2 should return its session_id."; 259 << "Removing client B/2 should return its session_id.";
259 // Clients in controller: [] 260 // Clients in controller: []
260 ASSERT_EQ(0, controller_->GetClientCount()) 261 ASSERT_EQ(0, controller_->GetClientCount())
261 << "Client count should return to zero after all clients are gone."; 262 << "Client count should return to zero after all clients are gone.";
262 } 263 }
263 264
264 static void CacheSyncPoint(uint32* called_release_sync_point, 265 static void CacheSyncToken(gpu::SyncToken* called_release_sync_token,
265 uint32 release_sync_point) { 266 const gpu::SyncToken& release_sync_token) {
266 *called_release_sync_point = release_sync_point; 267 *called_release_sync_token = release_sync_token;
267 } 268 }
268 269
269 // This test will connect and disconnect several clients while simulating an 270 // This test will connect and disconnect several clients while simulating an
270 // active capture device being started and generating frames. It runs on one 271 // active capture device being started and generating frames. It runs on one
271 // thread and is intended to behave deterministically. 272 // thread and is intended to behave deterministically.
272 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { 273 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) {
273 // VideoCaptureController::ReturnBuffer() uses ImageTransportFactory. 274 // VideoCaptureController::ReturnBuffer() uses ImageTransportFactory.
274 #if !defined(OS_ANDROID) 275 #if !defined(OS_ANDROID)
275 ImageTransportFactory::InitializeForUnitTests( 276 ImageTransportFactory::InitializeForUnitTests(
276 scoped_ptr<ImageTransportFactory>(new NoTransportImageTransportFactory)); 277 scoped_ptr<ImageTransportFactory>(new NoTransportImageTransportFactory));
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = 519 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer =
519 device_->ReserveOutputBuffer(capture_resolution, 520 device_->ReserveOutputBuffer(capture_resolution,
520 media::PIXEL_FORMAT_I420, 521 media::PIXEL_FORMAT_I420,
521 media::PIXEL_STORAGE_CPU); 522 media::PIXEL_STORAGE_CPU);
522 ASSERT_TRUE(buffer.get()); 523 ASSERT_TRUE(buffer.get());
523 video_frame = 524 video_frame =
524 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer->data())); 525 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer->data()));
525 device_->OnIncomingCapturedVideoFrame(buffer.Pass(), video_frame, 526 device_->OnIncomingCapturedVideoFrame(buffer.Pass(), video_frame,
526 base::TimeTicks()); 527 base::TimeTicks());
527 } 528 }
528 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); 529 std::vector<gpu::SyncToken> mailbox_synctokens(mailbox_buffers);
529 std::vector<uint32> release_syncpoints(mailbox_buffers); 530 std::vector<gpu::SyncToken> release_synctokens(mailbox_buffers);
530 for (int i = 0; i < mailbox_buffers; ++i) { 531 for (int i = 0; i < mailbox_buffers; ++i) {
531 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = 532 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer =
532 device_->ReserveOutputBuffer(capture_resolution, 533 device_->ReserveOutputBuffer(capture_resolution,
533 media::PIXEL_FORMAT_ARGB, 534 media::PIXEL_FORMAT_ARGB,
534 media::PIXEL_STORAGE_TEXTURE); 535 media::PIXEL_STORAGE_TEXTURE);
535 ASSERT_TRUE(buffer.get()); 536 ASSERT_TRUE(buffer.get());
536 #if !defined(OS_ANDROID) 537 #if !defined(OS_ANDROID)
537 mailbox_syncpoints[i] = 538 mailbox_synctokens[i] = gpu::SyncToken(
538 ImageTransportFactory::GetInstance()->GetGLHelper()->InsertSyncPoint(); 539 ImageTransportFactory::GetInstance()->GetGLHelper()->InsertSyncPoint());
539 #endif 540 #endif
540 device_->OnIncomingCapturedVideoFrame( 541 device_->OnIncomingCapturedVideoFrame(
541 buffer.Pass(), 542 buffer.Pass(),
542 WrapMailboxBuffer(gpu::MailboxHolder(gpu::Mailbox::Generate(), 0, 543 WrapMailboxBuffer(gpu::MailboxHolder(gpu::Mailbox::Generate(),
543 mailbox_syncpoints[i]), 544 mailbox_synctokens[i], 0),
544 base::Bind(&CacheSyncPoint, &release_syncpoints[i]), 545 base::Bind(&CacheSyncToken, &release_synctokens[i]),
545 capture_resolution), 546 capture_resolution),
546 base::TimeTicks()); 547 base::TimeTicks());
547 } 548 }
548 // ReserveOutputBuffers ought to fail now regardless of buffer format, because 549 // ReserveOutputBuffers ought to fail now regardless of buffer format, because
549 // the pool is depleted. 550 // the pool is depleted.
550 ASSERT_FALSE( 551 ASSERT_FALSE(
551 device_->ReserveOutputBuffer(capture_resolution, 552 device_->ReserveOutputBuffer(capture_resolution,
552 media::PIXEL_FORMAT_I420, 553 media::PIXEL_FORMAT_I420,
553 media::PIXEL_STORAGE_CPU).get()); 554 media::PIXEL_STORAGE_CPU).get());
554 ASSERT_FALSE( 555 ASSERT_FALSE(
555 device_->ReserveOutputBuffer(capture_resolution, 556 device_->ReserveOutputBuffer(capture_resolution,
556 media::PIXEL_FORMAT_ARGB, 557 media::PIXEL_FORMAT_ARGB,
557 media::PIXEL_STORAGE_TEXTURE).get()); 558 media::PIXEL_STORAGE_TEXTURE).get());
558 EXPECT_CALL(*client_b_, 559 EXPECT_CALL(*client_b_,
559 DoI420BufferReady(client_b_route_2, capture_resolution)) 560 DoI420BufferReady(client_b_route_2, capture_resolution))
560 .Times(shm_buffers); 561 .Times(shm_buffers);
561 EXPECT_CALL(*client_b_, 562 EXPECT_CALL(*client_b_,
562 DoTextureBufferReady(client_b_route_2, capture_resolution)) 563 DoTextureBufferReady(client_b_route_2, capture_resolution))
563 .Times(mailbox_buffers); 564 .Times(mailbox_buffers);
564 #if !defined(OS_ANDROID) 565 #if !defined(OS_ANDROID)
565 EXPECT_CALL(*client_b_, DoBufferDestroyed(client_b_route_2)); 566 EXPECT_CALL(*client_b_, DoBufferDestroyed(client_b_route_2));
566 #endif 567 #endif
567 base::RunLoop().RunUntilIdle(); 568 base::RunLoop().RunUntilIdle();
568 for (size_t i = 0; i < mailbox_syncpoints.size(); ++i) { 569 for (size_t i = 0; i < mailbox_synctokens.size(); ++i) {
569 // A new release sync point must be inserted when the video frame is 570 // A new release sync point must be inserted when the video frame is
570 // returned to the Browser process. 571 // returned to the Browser process.
571 // See: MockVideoCaptureControllerEventHandler::OnMailboxBufferReady() and 572 // See: MockVideoCaptureControllerEventHandler::OnMailboxBufferReady() and
572 // VideoCaptureController::ReturnBuffer() 573 // VideoCaptureController::ReturnBuffer()
573 ASSERT_NE(mailbox_syncpoints[i], release_syncpoints[i]); 574 ASSERT_NE(mailbox_synctokens[i], release_synctokens[i]);
574 } 575 }
575 Mock::VerifyAndClearExpectations(client_b_.get()); 576 Mock::VerifyAndClearExpectations(client_b_.get());
576 577
577 #if !defined(OS_ANDROID) 578 #if !defined(OS_ANDROID)
578 ImageTransportFactory::Terminate(); 579 ImageTransportFactory::Terminate();
579 #endif 580 #endif
580 } 581 }
581 582
582 // Exercises the OnError() codepath of VideoCaptureController, and tests the 583 // Exercises the OnError() codepath of VideoCaptureController, and tests the
583 // behavior of various operations after the error state has been signalled. 584 // behavior of various operations after the error state has been signalled.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 663
663 // Second client connects after the error state. It also should get told of 664 // Second client connects after the error state. It also should get told of
664 // the error. 665 // the error.
665 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); 666 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1);
666 controller_->AddClient( 667 controller_->AddClient(
667 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); 668 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200);
668 Mock::VerifyAndClearExpectations(client_b_.get()); 669 Mock::VerifyAndClearExpectations(client_b_.get());
669 } 670 }
670 671
671 } // namespace content 672 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698