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

Side by Side Diff: media/cast/video_sender/external_video_encoder_unittest.cc

Issue 116623002: Cast: Adding support for GPU accelerated encode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed merge nits Created 6 years, 11 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
(Empty)
1 // Copyright 2013 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.
4
5 #include <vector>
6
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"
19
20 namespace media {
21 namespace cast {
22
23 using testing::_;
24
25 namespace {
26 class TestVideoEncoderCallback :
27 public base::RefCountedThreadSafe<TestVideoEncoderCallback> {
28 public:
29 TestVideoEncoderCallback() {}
30
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;
39 }
40
41 void DeliverEncodedVideoFrame(scoped_ptr<EncodedVideoFrame> encoded_frame,
42 const base::TimeTicks& capture_time) {
43 EXPECT_EQ(expected_key_frame_, encoded_frame->key_frame);
44 EXPECT_EQ(expected_frame_id_, encoded_frame->frame_id);
45 EXPECT_EQ(expected_last_referenced_frame_id_,
46 encoded_frame->last_referenced_frame_id);
47 EXPECT_EQ(expected_capture_time_, capture_time);
48 }
49
50 protected:
51 virtual ~TestVideoEncoderCallback() {}
52
53 private:
54 friend class base::RefCountedThreadSafe<TestVideoEncoderCallback>;
55
56 bool expected_key_frame_;
57 uint8 expected_frame_id_;
58 uint8 expected_last_referenced_frame_id_;
59 base::TimeTicks expected_capture_time_;
60 };
61 } // namespace
62
63
64 class ExternalVideoEncoderTest : public ::testing::Test {
65 protected:
66 ExternalVideoEncoderTest()
67 : test_video_encoder_callback_(new TestVideoEncoderCallback()) {
68 video_config_.sender_ssrc = 1;
69 video_config_.incoming_feedback_ssrc = 2;
70 video_config_.rtp_payload_type = 127;
71 video_config_.use_external_encoder = true;
72 video_config_.width = 320;
73 video_config_.height = 240;
74 video_config_.max_bitrate = 5000000;
75 video_config_.min_bitrate = 1000000;
76 video_config_.start_bitrate = 2000000;
77 video_config_.max_qp = 56;
78 video_config_.min_qp = 0;
79 video_config_.max_frame_rate = 30;
80 video_config_.max_number_of_video_buffers_used = 3;
81 video_config_.codec = kVp8;
82 gfx::Size size(video_config_.width, video_config_.height);
83 video_frame_ = media::VideoFrame::CreateFrame(VideoFrame::I420,
84 size, gfx::Rect(size), size, base::TimeDelta());
85 PopulateVideoFrame(video_frame_, 123);
86 }
87
88 virtual ~ExternalVideoEncoderTest() {}
89
90 virtual void SetUp() {
91 task_runner_ = new test::FakeTaskRunner(&testing_clock_);
92 cast_environment_ = new CastEnvironment(&testing_clock_, task_runner_,
93 task_runner_, task_runner_, task_runner_, task_runner_,
94 GetDefaultCastLoggingConfig());
95 video_encoder_.reset(new ExternalVideoEncoder(
96 cast_environment_,
97 video_config_,
98 new test::FakeGpuVideoAcceleratorFactories(task_runner_)));
99 }
100
101 base::SimpleTestTickClock testing_clock_;
102 scoped_refptr<TestVideoEncoderCallback> test_video_encoder_callback_;
103 VideoSenderConfig video_config_;
104 scoped_refptr<test::FakeTaskRunner> task_runner_;
105 scoped_ptr<VideoEncoder> video_encoder_;
106 scoped_refptr<media::VideoFrame> video_frame_;
107 scoped_refptr<CastEnvironment> cast_environment_;
108 };
109
110 TEST_F(ExternalVideoEncoderTest, EncodePattern30fpsRunningOutOfAck) {
111 task_runner_->RunTasks(); // Run the initializer on the correct thread.
112
113 VideoEncoder::FrameEncodedCallback frame_encoded_callback =
114 base::Bind(&TestVideoEncoderCallback::DeliverEncodedVideoFrame,
115 test_video_encoder_callback_.get());
116
117 base::TimeTicks capture_time;
118 capture_time += base::TimeDelta::FromMilliseconds(33);
119 test_video_encoder_callback_->SetExpectedResult(true, 0, 0, capture_time);
120 EXPECT_TRUE(video_encoder_->EncodeVideoFrame(video_frame_, capture_time,
121 frame_encoded_callback));
122 task_runner_->RunTasks();
123
124 for (int i = 0; i < 6; ++i) {
125 capture_time += base::TimeDelta::FromMilliseconds(33);
126 test_video_encoder_callback_->SetExpectedResult(false, i + 1, i,
127 capture_time);
128 EXPECT_TRUE(video_encoder_->EncodeVideoFrame(video_frame_, capture_time,
129 frame_encoded_callback));
130 task_runner_->RunTasks();
131 }
132 }
133
134 } // namespace cast
135 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/video_sender/external_video_encoder.cc ('k') | media/cast/video_sender/mock_video_encoder_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698