Add explicit |forceOnlineSignin| to user pod status
[chromium-blink-merge.git] / media / cast / video_sender / external_video_encoder_unittest.cc
blobf44d17799b44e7e451d85be2c2c781e2f9618994
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <vector>
7 #include "base/bind.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "media/base/video_frame.h"
11 #include "media/cast/cast_defines.h"
12 #include "media/cast/cast_environment.h"
13 #include "media/cast/test/fake_gpu_video_accelerator_factories.h"
14 #include "media/cast/test/fake_task_runner.h"
15 #include "media/cast/test/fake_video_encode_accelerator.h"
16 #include "media/cast/test/video_utility.h"
17 #include "media/cast/video_sender/external_video_encoder.h"
18 #include "testing/gmock/include/gmock/gmock.h"
20 namespace media {
21 namespace cast {
23 using testing::_;
25 namespace {
26 class TestVideoEncoderCallback :
27 public base::RefCountedThreadSafe<TestVideoEncoderCallback> {
28 public:
29 TestVideoEncoderCallback() {}
31 void SetExpectedResult(bool expected_key_frame,
32 uint8 expected_frame_id,
33 uint8 expected_last_referenced_frame_id,
34 const base::TimeTicks& expected_capture_time) {
35 expected_key_frame_ = expected_key_frame;
36 expected_frame_id_ = expected_frame_id;
37 expected_last_referenced_frame_id_ = expected_last_referenced_frame_id;
38 expected_capture_time_ = expected_capture_time;
41 void DeliverEncodedVideoFrame(
42 scoped_ptr<transport::EncodedVideoFrame> encoded_frame,
43 const base::TimeTicks& capture_time) {
44 EXPECT_EQ(expected_key_frame_, encoded_frame->key_frame);
45 EXPECT_EQ(expected_frame_id_, encoded_frame->frame_id);
46 EXPECT_EQ(expected_last_referenced_frame_id_,
47 encoded_frame->last_referenced_frame_id);
48 EXPECT_EQ(expected_capture_time_, capture_time);
51 protected:
52 virtual ~TestVideoEncoderCallback() {}
54 private:
55 friend class base::RefCountedThreadSafe<TestVideoEncoderCallback>;
57 bool expected_key_frame_;
58 uint8 expected_frame_id_;
59 uint8 expected_last_referenced_frame_id_;
60 base::TimeTicks expected_capture_time_;
62 } // namespace
65 class ExternalVideoEncoderTest : public ::testing::Test {
66 protected:
67 ExternalVideoEncoderTest()
68 : test_video_encoder_callback_(new TestVideoEncoderCallback()) {
69 video_config_.sender_ssrc = 1;
70 video_config_.incoming_feedback_ssrc = 2;
71 video_config_.rtp_payload_type = 127;
72 video_config_.use_external_encoder = true;
73 video_config_.width = 320;
74 video_config_.height = 240;
75 video_config_.max_bitrate = 5000000;
76 video_config_.min_bitrate = 1000000;
77 video_config_.start_bitrate = 2000000;
78 video_config_.max_qp = 56;
79 video_config_.min_qp = 0;
80 video_config_.max_frame_rate = 30;
81 video_config_.max_number_of_video_buffers_used = 3;
82 video_config_.codec = transport::kVp8;
83 gfx::Size size(video_config_.width, video_config_.height);
84 video_frame_ = media::VideoFrame::CreateFrame(VideoFrame::I420,
85 size, gfx::Rect(size), size, base::TimeDelta());
86 PopulateVideoFrame(video_frame_, 123);
89 virtual ~ExternalVideoEncoderTest() {}
91 virtual void SetUp() {
92 task_runner_ = new test::FakeTaskRunner(&testing_clock_);
93 cast_environment_ = new CastEnvironment(&testing_clock_, task_runner_,
94 task_runner_, task_runner_, task_runner_, task_runner_, task_runner_,
95 GetDefaultCastLoggingConfig());
96 video_encoder_.reset(new ExternalVideoEncoder(
97 cast_environment_,
98 video_config_,
99 new test::FakeGpuVideoAcceleratorFactories(task_runner_)));
102 base::SimpleTestTickClock testing_clock_;
103 scoped_refptr<TestVideoEncoderCallback> test_video_encoder_callback_;
104 VideoSenderConfig video_config_;
105 scoped_refptr<test::FakeTaskRunner> task_runner_;
106 scoped_ptr<VideoEncoder> video_encoder_;
107 scoped_refptr<media::VideoFrame> video_frame_;
108 scoped_refptr<CastEnvironment> cast_environment_;
111 TEST_F(ExternalVideoEncoderTest, EncodePattern30fpsRunningOutOfAck) {
112 task_runner_->RunTasks(); // Run the initializer on the correct thread.
114 VideoEncoder::FrameEncodedCallback frame_encoded_callback =
115 base::Bind(&TestVideoEncoderCallback::DeliverEncodedVideoFrame,
116 test_video_encoder_callback_.get());
118 base::TimeTicks capture_time;
119 capture_time += base::TimeDelta::FromMilliseconds(33);
120 test_video_encoder_callback_->SetExpectedResult(true, 0, 0, capture_time);
121 EXPECT_TRUE(video_encoder_->EncodeVideoFrame(video_frame_, capture_time,
122 frame_encoded_callback));
123 task_runner_->RunTasks();
125 for (int i = 0; i < 6; ++i) {
126 capture_time += base::TimeDelta::FromMilliseconds(33);
127 test_video_encoder_callback_->SetExpectedResult(false, i + 1, i,
128 capture_time);
129 EXPECT_TRUE(video_encoder_->EncodeVideoFrame(video_frame_, capture_time,
130 frame_encoded_callback));
131 task_runner_->RunTasks();
133 // We need to run the task to cleanup the GPU instance.
134 video_encoder_.reset(NULL);
135 task_runner_->RunTasks();
138 } // namespace cast
139 } // namespace media