Index: media/cast/sender/video_sender_unittest.cc |
diff --git a/media/cast/sender/video_sender_unittest.cc b/media/cast/sender/video_sender_unittest.cc |
index 1dbccf0ddc0e210cd67249d2eabc629568579543..8100b22e556188f251a546d383678ef25b256591 100644 |
--- a/media/cast/sender/video_sender_unittest.cc |
+++ b/media/cast/sender/video_sender_unittest.cc |
@@ -563,5 +563,35 @@ TEST_F(VideoSenderTest, CheckVideoFrameFactoryIsNull) { |
EXPECT_EQ(nullptr, video_sender_->CreateVideoFrameFactory().get()); |
} |
+TEST_F(VideoSenderTest, PopulatesResourceUtilizationInFrameMetadata) { |
+ InitEncoder(false, true); |
+ ASSERT_EQ(STATUS_INITIALIZED, operational_status_); |
+ |
+ for (int i = 0; i < 3; ++i) { |
+ scoped_refptr<media::VideoFrame> video_frame = GetNewVideoFrame(); |
+ ASSERT_FALSE(video_frame->metadata()->HasKey( |
+ media::VideoFrameMetadata::RESOURCE_UTILIZATION)); |
+ |
+ const base::TimeTicks reference_time = testing_clock_->NowTicks(); |
+ video_sender_->InsertRawVideoFrame(video_frame, reference_time); |
+ |
+ // Run encode tasks. VideoSender::OnEncodedVideoFrame() will be called once |
+ // encoding of the frame is complete, and this is when the |
+ // RESOURCE_UTILIZATION metadata is populated. |
+ RunTasks(33); |
+ |
+ // Check that the RESOURCE_UTILIZATION value is set and non-negative. Don't |
+ // check for specific values because they are dependent on real-world CPU |
+ // encode time, which can vary across test runs. |
+ double utilization = -1.0; |
+ EXPECT_TRUE(video_frame->metadata()->GetDouble( |
+ media::VideoFrameMetadata::RESOURCE_UTILIZATION, &utilization)); |
+ EXPECT_LE(0.0, utilization); |
+ if (i == 0) |
+ EXPECT_GE(1.0, utilization); // Key frames never exceed 1.0. |
+ DVLOG(1) << "Utilization computed by VideoSender is: " << utilization; |
+ } |
+} |
+ |
} // namespace cast |
} // namespace media |