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

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

Issue 1157193002: RESOURCE_UTILIZATION in VideoFrameMetadata, a consumer feedback signal. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@video_frame_done_callback
Patch Set: Created 5 years, 6 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"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
16 #include "content/browser/renderer_host/media/media_stream_provider.h" 16 #include "content/browser/renderer_host/media/media_stream_provider.h"
17 #include "content/browser/renderer_host/media/video_capture_controller.h" 17 #include "content/browser/renderer_host/media/video_capture_controller.h"
18 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" 18 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h"
19 #include "content/browser/renderer_host/media/video_capture_manager.h" 19 #include "content/browser/renderer_host/media/video_capture_manager.h"
20 #include "content/common/gpu/client/gl_helper.h" 20 #include "content/common/gpu/client/gl_helper.h"
21 #include "content/common/media/media_stream_options.h" 21 #include "content/common/media/media_stream_options.h"
22 #include "content/public/test/test_browser_thread_bundle.h" 22 #include "content/public/test/test_browser_thread_bundle.h"
23 #include "gpu/command_buffer/common/mailbox_holder.h" 23 #include "gpu/command_buffer/common/mailbox_holder.h"
24 #include "media/base/video_capture_types.h" 24 #include "media/base/video_capture_types.h"
25 #include "media/base/video_frame_metadata.h"
25 #include "media/base/video_util.h" 26 #include "media/base/video_util.h"
26 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 29
29 #if !defined(OS_ANDROID) 30 #if !defined(OS_ANDROID)
30 #include "content/browser/compositor/test/no_transport_image_transport_factory.h " 31 #include "content/browser/compositor/test/no_transport_image_transport_factory.h "
31 #endif 32 #endif
32 33
33 using ::testing::_; 34 using ::testing::_;
34 using ::testing::InSequence; 35 using ::testing::InSequence;
35 using ::testing::Mock; 36 using ::testing::Mock;
36 using ::testing::SaveArg; 37 using ::testing::SaveArg;
37 38
38 namespace content { 39 namespace content {
39 40
40 class MockVideoCaptureControllerEventHandler 41 class MockVideoCaptureControllerEventHandler
41 : public VideoCaptureControllerEventHandler { 42 : public VideoCaptureControllerEventHandler {
42 public: 43 public:
43 explicit MockVideoCaptureControllerEventHandler( 44 explicit MockVideoCaptureControllerEventHandler(
44 VideoCaptureController* controller) 45 VideoCaptureController* controller)
45 : controller_(controller) {} 46 : controller_(controller),
47 stress_level_(-1.0) {}
46 ~MockVideoCaptureControllerEventHandler() override {} 48 ~MockVideoCaptureControllerEventHandler() override {}
47 49
48 // These mock methods are delegated to by our fake implementation of 50 // These mock methods are delegated to by our fake implementation of
49 // VideoCaptureControllerEventHandler, to be used in EXPECT_CALL(). 51 // VideoCaptureControllerEventHandler, to be used in EXPECT_CALL().
50 MOCK_METHOD1(DoBufferCreated, void(VideoCaptureControllerID)); 52 MOCK_METHOD1(DoBufferCreated, void(VideoCaptureControllerID));
51 MOCK_METHOD1(DoBufferDestroyed, void(VideoCaptureControllerID)); 53 MOCK_METHOD1(DoBufferDestroyed, void(VideoCaptureControllerID));
52 MOCK_METHOD2(DoBufferReady, void(VideoCaptureControllerID, const gfx::Size&)); 54 MOCK_METHOD2(DoBufferReady, void(VideoCaptureControllerID, const gfx::Size&));
53 MOCK_METHOD1(DoMailboxBufferReady, void(VideoCaptureControllerID)); 55 MOCK_METHOD1(DoMailboxBufferReady, void(VideoCaptureControllerID));
54 MOCK_METHOD1(DoEnded, void(VideoCaptureControllerID)); 56 MOCK_METHOD1(DoEnded, void(VideoCaptureControllerID));
55 MOCK_METHOD1(DoError, void(VideoCaptureControllerID)); 57 MOCK_METHOD1(DoError, void(VideoCaptureControllerID));
(...skipping 17 matching lines...) Expand all
73 const base::TimeTicks& timestamp, 75 const base::TimeTicks& timestamp,
74 scoped_ptr<base::DictionaryValue> metadata) override { 76 scoped_ptr<base::DictionaryValue> metadata) override {
75 DoBufferReady(id, coded_size); 77 DoBufferReady(id, coded_size);
76 base::MessageLoop::current()->PostTask( 78 base::MessageLoop::current()->PostTask(
77 FROM_HERE, 79 FROM_HERE,
78 base::Bind(&VideoCaptureController::ReturnBuffer, 80 base::Bind(&VideoCaptureController::ReturnBuffer,
79 base::Unretained(controller_), 81 base::Unretained(controller_),
80 id, 82 id,
81 this, 83 this,
82 buffer_id, 84 buffer_id,
83 0)); 85 0,
86 stress_level_));
84 } 87 }
85 void OnMailboxBufferReady( 88 void OnMailboxBufferReady(
86 VideoCaptureControllerID id, 89 VideoCaptureControllerID id,
87 int buffer_id, 90 int buffer_id,
88 const gpu::MailboxHolder& mailbox_holder, 91 const gpu::MailboxHolder& mailbox_holder,
89 const gfx::Size& packed_frame_size, 92 const gfx::Size& packed_frame_size,
90 const base::TimeTicks& timestamp, 93 const base::TimeTicks& timestamp,
91 scoped_ptr<base::DictionaryValue> metadata) override { 94 scoped_ptr<base::DictionaryValue> metadata) override {
92 DoMailboxBufferReady(id); 95 DoMailboxBufferReady(id);
93 base::MessageLoop::current()->PostTask( 96 base::MessageLoop::current()->PostTask(
94 FROM_HERE, 97 FROM_HERE,
95 base::Bind(&VideoCaptureController::ReturnBuffer, 98 base::Bind(&VideoCaptureController::ReturnBuffer,
96 base::Unretained(controller_), 99 base::Unretained(controller_),
97 id, 100 id,
98 this, 101 this,
99 buffer_id, 102 buffer_id,
100 mailbox_holder.sync_point)); 103 mailbox_holder.sync_point,
104 stress_level_));
101 } 105 }
102 void OnEnded(VideoCaptureControllerID id) override { 106 void OnEnded(VideoCaptureControllerID id) override {
103 DoEnded(id); 107 DoEnded(id);
104 // OnEnded() must respond by (eventually) unregistering the client. 108 // OnEnded() must respond by (eventually) unregistering the client.
105 base::MessageLoop::current()->PostTask(FROM_HERE, 109 base::MessageLoop::current()->PostTask(FROM_HERE,
106 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), 110 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient),
107 base::Unretained(controller_), id, this)); 111 base::Unretained(controller_), id, this));
108 } 112 }
109 113
110 VideoCaptureController* controller_; 114 VideoCaptureController* controller_;
115 double stress_level_;
111 }; 116 };
112 117
113 // Test class. 118 // Test class.
114 class VideoCaptureControllerTest : public testing::Test { 119 class VideoCaptureControllerTest : public testing::Test {
115 public: 120 public:
116 VideoCaptureControllerTest() {} 121 VideoCaptureControllerTest() {}
117 ~VideoCaptureControllerTest() override {} 122 ~VideoCaptureControllerTest() override {}
118 123
119 protected: 124 protected:
120 static const int kPoolSize = 3; 125 static const int kPoolSize = 3;
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); 342 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1);
338 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1,_)).Times(1); 343 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1,_)).Times(1);
339 } 344 }
340 { 345 {
341 InSequence s; 346 InSequence s;
342 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); 347 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1);
343 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2,_)).Times(1); 348 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2,_)).Times(1);
344 } 349 }
345 scoped_refptr<media::VideoFrame> video_frame = 350 scoped_refptr<media::VideoFrame> video_frame =
346 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer->data())); 351 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer->data()));
352 ASSERT_FALSE(video_frame->metadata()->HasKey(
353 media::VideoFrameMetadata::STRESS_LEVEL));
354 client_a_->stress_level_ = 0.5; // Simulate reporting of 0.5 stress level.
355 client_b_->stress_level_ = -1.0; // Simulate no reporting of a stress level.
347 device_->OnIncomingCapturedVideoFrame(buffer.Pass(), video_frame, 356 device_->OnIncomingCapturedVideoFrame(buffer.Pass(), video_frame,
348 base::TimeTicks()); 357 base::TimeTicks());
349 358
350 base::RunLoop().RunUntilIdle(); 359 base::RunLoop().RunUntilIdle();
351 Mock::VerifyAndClearExpectations(client_a_.get()); 360 Mock::VerifyAndClearExpectations(client_a_.get());
352 Mock::VerifyAndClearExpectations(client_b_.get()); 361 Mock::VerifyAndClearExpectations(client_b_.get());
362 // Expect VideoCaptureController set the metadata in |video_frame| to hold a
363 // stress level of 0.5 (the largest of all reported values).
364 double stress_level_in_metadata = -1.0;
365 ASSERT_TRUE(video_frame->metadata()->GetDouble(
366 media::VideoFrameMetadata::STRESS_LEVEL, &stress_level_in_metadata));
367 ASSERT_EQ(0.5, stress_level_in_metadata);
353 368
354 // Second buffer which ought to use the same shared memory buffer. In this 369 // Second buffer which ought to use the same shared memory buffer. In this
355 // case pretend that the Buffer pointer is held by the device for a long 370 // case pretend that the Buffer pointer is held by the device for a long
356 // delay. This shouldn't affect anything. 371 // delay. This shouldn't affect anything.
357 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 = 372 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 =
358 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, 373 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420,
359 capture_resolution); 374 capture_resolution);
360 ASSERT_TRUE(buffer2.get()); 375 ASSERT_TRUE(buffer2.get());
361 memset(buffer2->data(), buffer_no++, buffer2->size()); 376 memset(buffer2->data(), buffer_no++, buffer2->size());
362 video_frame = 377 video_frame =
363 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer2->data())); 378 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer2->data()));
379 ASSERT_FALSE(video_frame->metadata()->HasKey(
380 media::VideoFrameMetadata::STRESS_LEVEL));
381 client_a_->stress_level_ = 0.5; // Simulate reporting moderate stress level.
382 client_b_->stress_level_ = 3.14; // Simulate reporting high stress level.
364 device_->OnIncomingCapturedVideoFrame(buffer2.Pass(), video_frame, 383 device_->OnIncomingCapturedVideoFrame(buffer2.Pass(), video_frame,
365 base::TimeTicks()); 384 base::TimeTicks());
366 385
367 // The buffer should be delivered to the clients in any order. 386 // The buffer should be delivered to the clients in any order.
368 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1,_)).Times(1); 387 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1,_)).Times(1);
369 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1,_)).Times(1); 388 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1,_)).Times(1);
370 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2,_)).Times(1); 389 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2,_)).Times(1);
371 base::RunLoop().RunUntilIdle(); 390 base::RunLoop().RunUntilIdle();
372 Mock::VerifyAndClearExpectations(client_a_.get()); 391 Mock::VerifyAndClearExpectations(client_a_.get());
373 Mock::VerifyAndClearExpectations(client_b_.get()); 392 Mock::VerifyAndClearExpectations(client_b_.get());
393 // Expect VideoCaptureController set the metadata in |video_frame| to hold a
394 // stress level of 3.14 (the largest of all reported values).
395 stress_level_in_metadata = -1.0;
396 ASSERT_TRUE(video_frame->metadata()->GetDouble(
397 media::VideoFrameMetadata::STRESS_LEVEL, &stress_level_in_metadata));
398 ASSERT_EQ(3.14, stress_level_in_metadata);
374 399
375 // Add a fourth client now that some buffers have come through. 400 // Add a fourth client now that some buffers have come through.
376 controller_->AddClient(client_b_route_2, 401 controller_->AddClient(client_b_route_2,
377 client_b_.get(), 402 client_b_.get(),
378 base::kNullProcessHandle, 403 base::kNullProcessHandle,
379 1, 404 1,
380 session_1); 405 session_1);
381 Mock::VerifyAndClearExpectations(client_b_.get()); 406 Mock::VerifyAndClearExpectations(client_b_.get());
382 407
383 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. 408 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time.
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 EXPECT_EQ(coded_size.width(), size_and_rotation.output_resolution.width()); 725 EXPECT_EQ(coded_size.width(), size_and_rotation.output_resolution.width());
701 EXPECT_EQ(coded_size.height(), 726 EXPECT_EQ(coded_size.height(),
702 size_and_rotation.output_resolution.height()); 727 size_and_rotation.output_resolution.height());
703 728
704 EXPECT_EQ(kSessionId, controller_->RemoveClient(route_id, client_a_.get())); 729 EXPECT_EQ(kSessionId, controller_->RemoveClient(route_id, client_a_.get()));
705 Mock::VerifyAndClearExpectations(client_a_.get()); 730 Mock::VerifyAndClearExpectations(client_a_.get());
706 } 731 }
707 } 732 }
708 733
709 } // namespace content 734 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698