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

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

Issue 388663003: Cast: Reshuffle files under media/cast (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: missing includes Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
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.
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_single_thread_task_runner.h"
14 #include "media/cast/test/fake_video_encode_accelerator.h"
15 #include "media/cast/test/utility/video_utility.h"
16 #include "media/cast/video_sender/external_video_encoder.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18
19 namespace media {
20 namespace cast {
21
22 using testing::_;
23
24 namespace {
25
26 void CreateVideoEncodeAccelerator(
27 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
28 scoped_ptr<VideoEncodeAccelerator> fake_vea,
29 const ReceiveVideoEncodeAcceleratorCallback& callback) {
30 callback.Run(task_runner, fake_vea.Pass());
31 }
32
33 void CreateSharedMemory(
34 size_t size, const ReceiveVideoEncodeMemoryCallback& callback) {
35 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory());
36 if (!shm->CreateAndMapAnonymous(size)) {
37 NOTREACHED();
38 return;
39 }
40 callback.Run(shm.Pass());
41 }
42
43 class TestVideoEncoderCallback
44 : public base::RefCountedThreadSafe<TestVideoEncoderCallback> {
45 public:
46 TestVideoEncoderCallback() {}
47
48 void SetExpectedResult(uint32 expected_frame_id,
49 uint32 expected_last_referenced_frame_id,
50 const base::TimeTicks& expected_capture_time) {
51 expected_frame_id_ = expected_frame_id;
52 expected_last_referenced_frame_id_ = expected_last_referenced_frame_id;
53 expected_capture_time_ = expected_capture_time;
54 }
55
56 void DeliverEncodedVideoFrame(
57 scoped_ptr<transport::EncodedFrame> encoded_frame) {
58 if (expected_frame_id_ == expected_last_referenced_frame_id_) {
59 EXPECT_EQ(transport::EncodedFrame::KEY, encoded_frame->dependency);
60 } else {
61 EXPECT_EQ(transport::EncodedFrame::DEPENDENT,
62 encoded_frame->dependency);
63 }
64 EXPECT_EQ(expected_frame_id_, encoded_frame->frame_id);
65 EXPECT_EQ(expected_last_referenced_frame_id_,
66 encoded_frame->referenced_frame_id);
67 EXPECT_EQ(expected_capture_time_, encoded_frame->reference_time);
68 }
69
70 protected:
71 virtual ~TestVideoEncoderCallback() {}
72
73 private:
74 friend class base::RefCountedThreadSafe<TestVideoEncoderCallback>;
75
76 bool expected_key_frame_;
77 uint32 expected_frame_id_;
78 uint32 expected_last_referenced_frame_id_;
79 base::TimeTicks expected_capture_time_;
80
81 DISALLOW_COPY_AND_ASSIGN(TestVideoEncoderCallback);
82 };
83 } // namespace
84
85 class ExternalVideoEncoderTest : public ::testing::Test {
86 protected:
87 ExternalVideoEncoderTest()
88 : test_video_encoder_callback_(new TestVideoEncoderCallback()) {
89 video_config_.ssrc = 1;
90 video_config_.incoming_feedback_ssrc = 2;
91 video_config_.rtp_payload_type = 127;
92 video_config_.use_external_encoder = true;
93 video_config_.width = 320;
94 video_config_.height = 240;
95 video_config_.max_bitrate = 5000000;
96 video_config_.min_bitrate = 1000000;
97 video_config_.start_bitrate = 2000000;
98 video_config_.max_qp = 56;
99 video_config_.min_qp = 0;
100 video_config_.max_frame_rate = 30;
101 video_config_.max_number_of_video_buffers_used = 3;
102 video_config_.codec = transport::CODEC_VIDEO_VP8;
103 gfx::Size size(video_config_.width, video_config_.height);
104 video_frame_ = media::VideoFrame::CreateFrame(
105 VideoFrame::I420, size, gfx::Rect(size), size, base::TimeDelta());
106 PopulateVideoFrame(video_frame_, 123);
107
108 testing_clock_ = new base::SimpleTestTickClock();
109 task_runner_ = new test::FakeSingleThreadTaskRunner(testing_clock_);
110 cast_environment_ =
111 new CastEnvironment(scoped_ptr<base::TickClock>(testing_clock_).Pass(),
112 task_runner_,
113 task_runner_,
114 task_runner_);
115
116 fake_vea_ = new test::FakeVideoEncodeAccelerator(task_runner_);
117 scoped_ptr<VideoEncodeAccelerator> fake_vea(fake_vea_);
118 video_encoder_.reset(
119 new ExternalVideoEncoder(cast_environment_,
120 video_config_,
121 base::Bind(&CreateVideoEncodeAccelerator,
122 task_runner_,
123 base::Passed(&fake_vea)),
124 base::Bind(&CreateSharedMemory)));
125 }
126
127 virtual ~ExternalVideoEncoderTest() {}
128
129 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment.
130 test::FakeVideoEncodeAccelerator* fake_vea_; // Owned by video_encoder_.
131 scoped_refptr<TestVideoEncoderCallback> test_video_encoder_callback_;
132 VideoSenderConfig video_config_;
133 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_;
134 scoped_ptr<VideoEncoder> video_encoder_;
135 scoped_refptr<media::VideoFrame> video_frame_;
136 scoped_refptr<CastEnvironment> cast_environment_;
137
138 DISALLOW_COPY_AND_ASSIGN(ExternalVideoEncoderTest);
139 };
140
141 TEST_F(ExternalVideoEncoderTest, EncodePattern30fpsRunningOutOfAck) {
142 task_runner_->RunTasks(); // Run the initializer on the correct thread.
143
144 VideoEncoder::FrameEncodedCallback frame_encoded_callback =
145 base::Bind(&TestVideoEncoderCallback::DeliverEncodedVideoFrame,
146 test_video_encoder_callback_.get());
147
148 base::TimeTicks capture_time;
149 capture_time += base::TimeDelta::FromMilliseconds(33);
150 test_video_encoder_callback_->SetExpectedResult(0, 0, capture_time);
151 EXPECT_TRUE(video_encoder_->EncodeVideoFrame(
152 video_frame_, capture_time, frame_encoded_callback));
153 task_runner_->RunTasks();
154
155 for (int i = 0; i < 6; ++i) {
156 capture_time += base::TimeDelta::FromMilliseconds(33);
157 test_video_encoder_callback_->SetExpectedResult(i + 1, i, capture_time);
158 EXPECT_TRUE(video_encoder_->EncodeVideoFrame(
159 video_frame_, capture_time, frame_encoded_callback));
160 task_runner_->RunTasks();
161 }
162 // We need to run the task to cleanup the GPU instance.
163 video_encoder_.reset(NULL);
164 task_runner_->RunTasks();
165 }
166
167 TEST_F(ExternalVideoEncoderTest, StreamHeader) {
168 task_runner_->RunTasks(); // Run the initializer on the correct thread.
169
170 VideoEncoder::FrameEncodedCallback frame_encoded_callback =
171 base::Bind(&TestVideoEncoderCallback::DeliverEncodedVideoFrame,
172 test_video_encoder_callback_.get());
173
174 // Force the FakeVideoEncodeAccelerator to return a dummy non-key frame first.
175 fake_vea_->SendDummyFrameForTesting(false);
176
177 // Verify the first returned bitstream buffer is still a key frame.
178 base::TimeTicks capture_time;
179 capture_time += base::TimeDelta::FromMilliseconds(33);
180 test_video_encoder_callback_->SetExpectedResult(0, 0, capture_time);
181 EXPECT_TRUE(video_encoder_->EncodeVideoFrame(
182 video_frame_, capture_time, frame_encoded_callback));
183 task_runner_->RunTasks();
184
185 // We need to run the task to cleanup the GPU instance.
186 video_encoder_.reset(NULL);
187 task_runner_->RunTasks();
188 }
189
190 } // namespace cast
191 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/video_sender/external_video_encoder.cc ('k') | media/cast/video_sender/fake_software_video_encoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698