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

Side by Side Diff: webrtc/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc

Issue 2995213002: TestVp8Impl: Remove unused arguments and member variable. (Closed)
Patch Set: Created 3 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 17 matching lines...) Expand all
28 28
29 namespace webrtc { 29 namespace webrtc {
30 30
31 namespace { 31 namespace {
32 32
33 void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv) { 33 void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv) {
34 *stride_y = 16 * ((width + 15) / 16); 34 *stride_y = 16 * ((width + 15) / 16);
35 *stride_uv = 16 * ((width + 31) / 32); 35 *stride_uv = 16 * ((width + 31) / 32);
36 } 36 }
37 37
38 enum { kMaxWaitEncTimeMs = 100 }; 38 constexpr int64_t kMaxWaitEncTimeMs = 100;
39 enum { kMaxWaitDecTimeMs = 25 }; 39 constexpr int64_t kMaxWaitDecTimeMs = 25;
40
41 constexpr uint32_t kTestTimestamp = 123; 40 constexpr uint32_t kTestTimestamp = 123;
42 constexpr int64_t kTestNtpTimeMs = 456; 41 constexpr int64_t kTestNtpTimeMs = 456;
43 constexpr uint32_t kTimestampIncrementPerFrame = 3000; 42 constexpr uint32_t kTimestampIncrementPerFrame = 3000;
44 constexpr int kNumCores = 1; 43 constexpr int kNumCores = 1;
45 constexpr size_t kMaxPayloadSize = 1440; 44 constexpr size_t kMaxPayloadSize = 1440;
46 constexpr int kMinPixelsPerFrame = 12345; 45 constexpr int kMinPixelsPerFrame = 12345;
47 constexpr int kDefaultMinPixelsPerFrame = 320 * 180; 46 constexpr int kDefaultMinPixelsPerFrame = 320 * 180;
48 47 constexpr int kWidth = 172;
48 constexpr int kHeight = 144;
49 } // namespace 49 } // namespace
50 50
51 // TODO(mikhal): Replace these with mocks.
52 class Vp8UnitTestEncodeCompleteCallback : public webrtc::EncodedImageCallback { 51 class Vp8UnitTestEncodeCompleteCallback : public webrtc::EncodedImageCallback {
53 public: 52 public:
54 Vp8UnitTestEncodeCompleteCallback(EncodedImage* frame, 53 Vp8UnitTestEncodeCompleteCallback(EncodedImage* frame,
55 CodecSpecificInfo* codec_specific_info, 54 CodecSpecificInfo* codec_specific_info)
56 unsigned int decoderSpecificSize,
57 void* decoderSpecificInfo)
58 : encoded_frame_(frame), 55 : encoded_frame_(frame),
59 codec_specific_info_(codec_specific_info), 56 codec_specific_info_(codec_specific_info),
60 encode_complete_(false) {} 57 encode_complete_(false) {}
61 58
62 Result OnEncodedImage(const EncodedImage& encoded_frame_, 59 Result OnEncodedImage(const EncodedImage& encoded_frame,
63 const CodecSpecificInfo* codec_specific_info, 60 const CodecSpecificInfo* codec_specific_info,
64 const RTPFragmentationHeader* fragmentation) override; 61 const RTPFragmentationHeader* fragmentation) override;
65 bool EncodeComplete(); 62 bool EncodeComplete();
66 63
64 void VerifyQp(const EncodedImage& encoded_frame) const {
brandtr 2017/08/21 11:27:33 Maybe add a comment what this function does?
åsapersson 2017/08/21 11:53:11 Renamed function.
65 int qp;
66 ASSERT_TRUE(vp8::GetQp(encoded_frame._buffer, encoded_frame._length, &qp));
67 EXPECT_EQ(encoded_frame.qp_, qp) << "Encoder QP != bitstream QP.";
68 }
69
67 private: 70 private:
68 EncodedImage* const encoded_frame_; 71 EncodedImage* const encoded_frame_;
69 CodecSpecificInfo* const codec_specific_info_; 72 CodecSpecificInfo* const codec_specific_info_;
70 std::unique_ptr<uint8_t[]> frame_buffer_; 73 std::unique_ptr<uint8_t[]> frame_buffer_;
71 bool encode_complete_; 74 bool encode_complete_;
72 }; 75 };
73 76
74 webrtc::EncodedImageCallback::Result 77 webrtc::EncodedImageCallback::Result
75 Vp8UnitTestEncodeCompleteCallback::OnEncodedImage( 78 Vp8UnitTestEncodeCompleteCallback::OnEncodedImage(
76 const EncodedImage& encoded_frame, 79 const EncodedImage& encoded_frame,
77 const CodecSpecificInfo* codec_specific_info, 80 const CodecSpecificInfo* codec_specific_info,
78 const RTPFragmentationHeader* fragmentation) { 81 const RTPFragmentationHeader* fragmentation) {
79 if (encoded_frame_->_size < encoded_frame._length) { 82 EXPECT_GT(encoded_frame._length, 0u);
83 VerifyQp(encoded_frame);
84
85 if (encoded_frame_->_size != encoded_frame._size) {
80 delete[] encoded_frame_->_buffer; 86 delete[] encoded_frame_->_buffer;
81 frame_buffer_.reset(new uint8_t[encoded_frame._length]); 87 frame_buffer_.reset(new uint8_t[encoded_frame._size]);
82 encoded_frame_->_buffer = frame_buffer_.get();
83 encoded_frame_->_size = encoded_frame._length;
84 } 88 }
85 memcpy(encoded_frame_->_buffer, encoded_frame._buffer, encoded_frame._length); 89 memcpy(frame_buffer_.get(), encoded_frame._buffer, encoded_frame._length);
86 encoded_frame_->_length = encoded_frame._length; 90 *encoded_frame_ = encoded_frame;
87 encoded_frame_->_encodedWidth = encoded_frame._encodedWidth; 91 encoded_frame_->_buffer = frame_buffer_.get();
88 encoded_frame_->_encodedHeight = encoded_frame._encodedHeight; 92
89 encoded_frame_->_timeStamp = encoded_frame._timeStamp; 93 // Skip |codec_name|, to avoid allocating.
90 encoded_frame_->_frameType = encoded_frame._frameType;
91 encoded_frame_->_completeFrame = encoded_frame._completeFrame;
92 encoded_frame_->rotation_ = encoded_frame.rotation_;
93 encoded_frame_->qp_ = encoded_frame.qp_;
94 codec_specific_info_->codecType = codec_specific_info->codecType; 94 codec_specific_info_->codecType = codec_specific_info->codecType;
95 // Skip |codec_name|, to avoid allocating.
96 codec_specific_info_->codecSpecific = codec_specific_info->codecSpecific; 95 codec_specific_info_->codecSpecific = codec_specific_info->codecSpecific;
97 encode_complete_ = true; 96 encode_complete_ = true;
98 return Result(Result::OK, 0); 97 return Result(Result::OK, 0);
99 } 98 }
100 99
101 bool Vp8UnitTestEncodeCompleteCallback::EncodeComplete() { 100 bool Vp8UnitTestEncodeCompleteCallback::EncodeComplete() {
102 if (encode_complete_) { 101 if (encode_complete_) {
103 encode_complete_ = false; 102 encode_complete_ = false;
104 return true; 103 return true;
105 } 104 }
106 return false; 105 return false;
107 } 106 }
108 107
109 class Vp8UnitTestDecodeCompleteCallback : public webrtc::DecodedImageCallback { 108 class Vp8UnitTestDecodeCompleteCallback : public webrtc::DecodedImageCallback {
110 public: 109 public:
111 explicit Vp8UnitTestDecodeCompleteCallback(rtc::Optional<VideoFrame>* frame, 110 explicit Vp8UnitTestDecodeCompleteCallback(rtc::Optional<VideoFrame>* frame,
112 rtc::Optional<uint8_t>* qp) 111 rtc::Optional<uint8_t>* qp)
113 : decoded_frame_(frame), decoded_qp_(qp), decode_complete(false) {} 112 : decoded_frame_(frame), decoded_qp_(qp), decode_complete_(false) {}
114 int32_t Decoded(VideoFrame& frame) override { 113 int32_t Decoded(VideoFrame& frame) override {
115 RTC_NOTREACHED(); 114 RTC_NOTREACHED();
116 return -1; 115 return -1;
117 } 116 }
118 int32_t Decoded(VideoFrame& frame, int64_t decode_time_ms) override { 117 int32_t Decoded(VideoFrame& frame, int64_t decode_time_ms) override {
119 RTC_NOTREACHED(); 118 RTC_NOTREACHED();
120 return -1; 119 return -1;
121 } 120 }
122 void Decoded(VideoFrame& frame, 121 void Decoded(VideoFrame& frame,
123 rtc::Optional<int32_t> decode_time_ms, 122 rtc::Optional<int32_t> decode_time_ms,
124 rtc::Optional<uint8_t> qp) override; 123 rtc::Optional<uint8_t> qp) override;
125 bool DecodeComplete(); 124 bool DecodeComplete();
126 125
127 private: 126 private:
128 rtc::Optional<VideoFrame>* decoded_frame_; 127 rtc::Optional<VideoFrame>* decoded_frame_;
129 rtc::Optional<uint8_t>* decoded_qp_; 128 rtc::Optional<uint8_t>* decoded_qp_;
130 bool decode_complete; 129 bool decode_complete_;
131 }; 130 };
132 131
133 bool Vp8UnitTestDecodeCompleteCallback::DecodeComplete() { 132 bool Vp8UnitTestDecodeCompleteCallback::DecodeComplete() {
134 if (decode_complete) { 133 if (decode_complete_) {
135 decode_complete = false; 134 decode_complete_ = false;
136 return true; 135 return true;
137 } 136 }
138 return false; 137 return false;
139 } 138 }
140 139
141 void Vp8UnitTestDecodeCompleteCallback::Decoded( 140 void Vp8UnitTestDecodeCompleteCallback::Decoded(
142 VideoFrame& frame, 141 VideoFrame& frame,
143 rtc::Optional<int32_t> decode_time_ms, 142 rtc::Optional<int32_t> decode_time_ms,
144 rtc::Optional<uint8_t> qp) { 143 rtc::Optional<uint8_t> qp) {
144 EXPECT_GT(frame.width(), 0);
145 EXPECT_GT(frame.height(), 0);
145 *decoded_frame_ = rtc::Optional<VideoFrame>(frame); 146 *decoded_frame_ = rtc::Optional<VideoFrame>(frame);
146 *decoded_qp_ = qp; 147 *decoded_qp_ = qp;
147 decode_complete = true; 148 decode_complete_ = true;
148 } 149 }
149 150
150 class TestVp8Impl : public ::testing::Test { 151 class TestVp8Impl : public ::testing::Test {
151 protected: 152 protected:
152 TestVp8Impl() : TestVp8Impl("") {} 153 TestVp8Impl() : TestVp8Impl("") {}
153 explicit TestVp8Impl(const std::string& field_trials) 154 explicit TestVp8Impl(const std::string& field_trials)
154 : override_field_trials_(field_trials) {} 155 : override_field_trials_(field_trials) {}
155 156
156 virtual void SetUp() { 157 virtual void SetUp() {
157 encoder_.reset(VP8Encoder::Create()); 158 encoder_.reset(VP8Encoder::Create());
158 decoder_.reset(VP8Decoder::Create()); 159 decoder_.reset(VP8Decoder::Create());
159 memset(&codec_settings_, 0, sizeof(codec_settings_));
160 encode_complete_callback_.reset(new Vp8UnitTestEncodeCompleteCallback( 160 encode_complete_callback_.reset(new Vp8UnitTestEncodeCompleteCallback(
161 &encoded_frame_, &codec_specific_info_, 0, nullptr)); 161 &encoded_frame_, &codec_specific_info_));
162 decode_complete_callback_.reset( 162 decode_complete_callback_.reset(
163 new Vp8UnitTestDecodeCompleteCallback(&decoded_frame_, &decoded_qp_)); 163 new Vp8UnitTestDecodeCompleteCallback(&decoded_frame_, &decoded_qp_));
164 encoder_->RegisterEncodeCompleteCallback(encode_complete_callback_.get()); 164 encoder_->RegisterEncodeCompleteCallback(encode_complete_callback_.get());
165 decoder_->RegisterDecodeCompleteCallback(decode_complete_callback_.get()); 165 decoder_->RegisterDecodeCompleteCallback(decode_complete_callback_.get());
166
167 SetupCodecSettings();
168
166 // Using a QCIF image (aligned stride (u,v planes) > width). 169 // Using a QCIF image (aligned stride (u,v planes) > width).
167 // Processing only one frame. 170 // Processing only one frame.
168 source_file_ = fopen(test::ResourcePath("paris_qcif", "yuv").c_str(), "rb"); 171 FILE* file = fopen(test::ResourcePath("paris_qcif", "yuv").c_str(), "rb");
169 ASSERT_TRUE(source_file_ != nullptr); 172 ASSERT_TRUE(file != nullptr);
170 rtc::scoped_refptr<I420BufferInterface> compact_buffer( 173 rtc::scoped_refptr<I420BufferInterface> compact_buffer(
171 test::ReadI420Buffer(kWidth, kHeight, source_file_)); 174 test::ReadI420Buffer(kWidth, kHeight, file));
172 ASSERT_TRUE(compact_buffer); 175 ASSERT_TRUE(compact_buffer);
173 codec_settings_.width = kWidth;
174 codec_settings_.height = kHeight;
175 const int kFramerate = 30;
176 codec_settings_.maxFramerate = kFramerate;
177 // Setting aligned stride values. 176 // Setting aligned stride values.
178 int stride_uv; 177 int stride_uv;
179 int stride_y; 178 int stride_y;
180 Calc16ByteAlignedStride(codec_settings_.width, &stride_y, &stride_uv); 179 Calc16ByteAlignedStride(kWidth, &stride_y, &stride_uv);
181 EXPECT_EQ(stride_y, 176); 180 EXPECT_EQ(stride_y, 176);
182 EXPECT_EQ(stride_uv, 96); 181 EXPECT_EQ(stride_uv, 96);
183 182
184 rtc::scoped_refptr<I420Buffer> stride_buffer( 183 rtc::scoped_refptr<I420Buffer> stride_buffer(
185 I420Buffer::Create(kWidth, kHeight, stride_y, stride_uv, stride_uv)); 184 I420Buffer::Create(kWidth, kHeight, stride_y, stride_uv, stride_uv));
186 185
187 // No scaling in our case, just a copy, to add stride to the image. 186 // No scaling in our case, just a copy, to add stride to the image.
188 stride_buffer->ScaleFrom(*compact_buffer); 187 stride_buffer->ScaleFrom(*compact_buffer);
189 188
190 input_frame_.reset( 189 input_frame_.reset(new VideoFrame(stride_buffer, kVideoRotation_0, 0));
191 new VideoFrame(stride_buffer, kVideoRotation_0, 0));
192 input_frame_->set_timestamp(kTestTimestamp); 190 input_frame_->set_timestamp(kTestTimestamp);
191 fclose(file);
192 }
193
194 void SetupCodecSettings() {
195 webrtc::test::CodecSettings(kVideoCodecVP8, &codec_settings_);
196 codec_settings_.maxBitrate = 4000;
197 codec_settings_.width = kWidth;
198 codec_settings_.height = kHeight;
199 codec_settings_.VP8()->denoisingOn = true;
200 codec_settings_.VP8()->frameDroppingOn = false;
201 codec_settings_.VP8()->automaticResizeOn = false;
202 codec_settings_.VP8()->complexity = kComplexityNormal;
203 codec_settings_.VP8()->tl_factory = &tl_factory_;
193 } 204 }
194 205
195 void SetUpEncodeDecode() { 206 void SetUpEncodeDecode() {
196 codec_settings_.startBitrate = 300;
197 codec_settings_.maxBitrate = 4000;
198 codec_settings_.qpMax = 56;
199 codec_settings_.VP8()->denoisingOn = true;
200 codec_settings_.VP8()->tl_factory = &tl_factory_;
201 codec_settings_.VP8()->numberOfTemporalLayers = 1;
202
203 EXPECT_EQ( 207 EXPECT_EQ(
204 WEBRTC_VIDEO_CODEC_OK, 208 WEBRTC_VIDEO_CODEC_OK,
205 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); 209 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize));
206 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 210 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
207 decoder_->InitDecode(&codec_settings_, kNumCores)); 211 decoder_->InitDecode(&codec_settings_, kNumCores));
208 } 212 }
209 213
210 size_t WaitForEncodedFrame() const { 214 void WaitForEncodedFrame() const {
211 int64_t startTime = rtc::TimeMillis(); 215 int64_t start_ms = rtc::TimeMillis();
212 while (rtc::TimeMillis() - startTime < kMaxWaitEncTimeMs) { 216 while (rtc::TimeMillis() - start_ms < kMaxWaitEncTimeMs) {
213 if (encode_complete_callback_->EncodeComplete()) { 217 if (encode_complete_callback_->EncodeComplete()) {
214 return encoded_frame_._length; 218 return;
215 } 219 }
216 } 220 }
217 return 0; 221 ASSERT_TRUE(false);
218 } 222 }
219 223
220 size_t WaitForDecodedFrame() const { 224 void WaitForDecodedFrame() const {
221 int64_t startTime = rtc::TimeMillis(); 225 int64_t start_ms = rtc::TimeMillis();
222 while (rtc::TimeMillis() - startTime < kMaxWaitDecTimeMs) { 226 while (rtc::TimeMillis() - start_ms < kMaxWaitDecTimeMs) {
223 if (decode_complete_callback_->DecodeComplete()) { 227 if (decode_complete_callback_->DecodeComplete()) {
224 return CalcBufferSize(VideoType::kI420, decoded_frame_->width(), 228 return;
225 decoded_frame_->height());
226 } 229 }
227 } 230 }
228 return 0; 231 ASSERT_TRUE(false);
229 } 232 }
230 233
231 void ExpectFrameWith(int16_t picture_id, 234 void ExpectFrameWith(int16_t picture_id,
232 int tl0_pic_idx, 235 int tl0_pic_idx,
233 uint8_t temporal_idx) { 236 uint8_t temporal_idx) {
234 ASSERT_TRUE(WaitForEncodedFrame()); 237 WaitForEncodedFrame();
235 EXPECT_EQ(picture_id, codec_specific_info_.codecSpecific.VP8.pictureId); 238 EXPECT_EQ(picture_id, codec_specific_info_.codecSpecific.VP8.pictureId);
236 EXPECT_EQ(tl0_pic_idx, codec_specific_info_.codecSpecific.VP8.tl0PicIdx); 239 EXPECT_EQ(tl0_pic_idx, codec_specific_info_.codecSpecific.VP8.tl0PicIdx);
237 EXPECT_EQ(temporal_idx, codec_specific_info_.codecSpecific.VP8.temporalIdx); 240 EXPECT_EQ(temporal_idx, codec_specific_info_.codecSpecific.VP8.temporalIdx);
238 } 241 }
239 242
240 const int kWidth = 172;
241 const int kHeight = 144;
242
243 test::ScopedFieldTrials override_field_trials_; 243 test::ScopedFieldTrials override_field_trials_;
244 std::unique_ptr<Vp8UnitTestEncodeCompleteCallback> encode_complete_callback_; 244 std::unique_ptr<Vp8UnitTestEncodeCompleteCallback> encode_complete_callback_;
245 std::unique_ptr<Vp8UnitTestDecodeCompleteCallback> decode_complete_callback_; 245 std::unique_ptr<Vp8UnitTestDecodeCompleteCallback> decode_complete_callback_;
246 std::unique_ptr<uint8_t[]> source_buffer_;
247 FILE* source_file_;
248 std::unique_ptr<VideoFrame> input_frame_; 246 std::unique_ptr<VideoFrame> input_frame_;
249 std::unique_ptr<VideoEncoder> encoder_; 247 std::unique_ptr<VideoEncoder> encoder_;
250 std::unique_ptr<VideoDecoder> decoder_; 248 std::unique_ptr<VideoDecoder> decoder_;
251 EncodedImage encoded_frame_; 249 EncodedImage encoded_frame_;
252 CodecSpecificInfo codec_specific_info_; 250 CodecSpecificInfo codec_specific_info_;
253 rtc::Optional<VideoFrame> decoded_frame_; 251 rtc::Optional<VideoFrame> decoded_frame_;
254 rtc::Optional<uint8_t> decoded_qp_; 252 rtc::Optional<uint8_t> decoded_qp_;
255 VideoCodec codec_settings_; 253 VideoCodec codec_settings_;
256 TemporalLayersFactory tl_factory_; 254 TemporalLayersFactory tl_factory_;
257 }; 255 };
258 256
257 TEST_F(TestVp8Impl, EncodeFrame) {
258 SetUpEncodeDecode();
259 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
260 encoder_->Encode(*input_frame_, nullptr, nullptr));
261 WaitForEncodedFrame();
262 }
263
259 TEST_F(TestVp8Impl, EncoderParameterTest) { 264 TEST_F(TestVp8Impl, EncoderParameterTest) {
260 strncpy(codec_settings_.plName, "VP8", 31);
261 codec_settings_.plType = 126;
262 codec_settings_.maxBitrate = 0; 265 codec_settings_.maxBitrate = 0;
263 codec_settings_.minBitrate = 0;
264 codec_settings_.width = 1440; 266 codec_settings_.width = 1440;
265 codec_settings_.height = 1080; 267 codec_settings_.height = 1080;
266 codec_settings_.maxFramerate = 30; 268
267 codec_settings_.startBitrate = 300;
268 codec_settings_.qpMax = 56;
269 codec_settings_.VP8()->complexity = kComplexityNormal;
270 codec_settings_.VP8()->numberOfTemporalLayers = 1;
271 codec_settings_.VP8()->tl_factory = &tl_factory_;
272 // Calls before InitEncode(). 269 // Calls before InitEncode().
273 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); 270 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release());
274 int bit_rate = 300; 271 const int kBitrate = 300;
brandtr 2017/08/21 11:27:33 kBitrateKbps
åsapersson 2017/08/21 11:53:11 Done.
275 BitrateAllocation bitrate_allocation; 272 BitrateAllocation bitrate_allocation;
276 bitrate_allocation.SetBitrate(0, 0, bit_rate * 1000); 273 bitrate_allocation.SetBitrate(0, 0, kBitrate * 1000);
277 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, 274 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED,
278 encoder_->SetRateAllocation(bitrate_allocation, 275 encoder_->SetRateAllocation(bitrate_allocation,
279 codec_settings_.maxFramerate)); 276 codec_settings_.maxFramerate));
280 277
281 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 278 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
282 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); 279 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize));
283 280
284 // Decoder parameter tests. 281 // Decoder parameter tests.
285 // Calls before InitDecode(). 282 // Calls before InitDecode().
286 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); 283 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release());
(...skipping 17 matching lines...) Expand all
304 input_frame_->set_rotation(kVideoRotation_90); 301 input_frame_->set_rotation(kVideoRotation_90);
305 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 302 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
306 encoder_->Encode(*input_frame_, nullptr, nullptr)); 303 encoder_->Encode(*input_frame_, nullptr, nullptr));
307 WaitForEncodedFrame(); 304 WaitForEncodedFrame();
308 EXPECT_EQ(kVideoRotation_90, encoded_frame_.rotation_); 305 EXPECT_EQ(kVideoRotation_90, encoded_frame_.rotation_);
309 } 306 }
310 307
311 TEST_F(TestVp8Impl, DecodedQpEqualsEncodedQp) { 308 TEST_F(TestVp8Impl, DecodedQpEqualsEncodedQp) {
312 SetUpEncodeDecode(); 309 SetUpEncodeDecode();
313 encoder_->Encode(*input_frame_, nullptr, nullptr); 310 encoder_->Encode(*input_frame_, nullptr, nullptr);
314 EXPECT_GT(WaitForEncodedFrame(), 0u); 311 WaitForEncodedFrame();
315 // First frame should be a key frame. 312 // First frame should be a key frame.
316 encoded_frame_._frameType = kVideoFrameKey; 313 encoded_frame_._frameType = kVideoFrameKey;
317 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 314 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
318 decoder_->Decode(encoded_frame_, false, nullptr)); 315 decoder_->Decode(encoded_frame_, false, nullptr));
319 EXPECT_GT(WaitForDecodedFrame(), 0u); 316 WaitForDecodedFrame();
320 ASSERT_TRUE(decoded_frame_); 317 ASSERT_TRUE(decoded_frame_);
321 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_frame_), 36); 318 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_frame_), 36);
322 ASSERT_TRUE(decoded_qp_); 319 ASSERT_TRUE(decoded_qp_);
323 EXPECT_EQ(encoded_frame_.qp_, *decoded_qp_); 320 EXPECT_EQ(encoded_frame_.qp_, *decoded_qp_);
324 } 321 }
325 322
326 TEST_F(TestVp8Impl, ParserQpEqualsEncodedQp) {
327 SetUpEncodeDecode();
328 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
329 encoder_->Encode(*input_frame_, nullptr, nullptr));
330 EXPECT_GT(WaitForEncodedFrame(), 0u);
331
332 int qp = 0;
333 ASSERT_TRUE(vp8::GetQp(encoded_frame_._buffer, encoded_frame_._length, &qp));
334
335 EXPECT_EQ(encoded_frame_.qp_, qp);
336 }
337
338 #if defined(WEBRTC_ANDROID) 323 #if defined(WEBRTC_ANDROID)
339 #define MAYBE_AlignedStrideEncodeDecode DISABLED_AlignedStrideEncodeDecode 324 #define MAYBE_AlignedStrideEncodeDecode DISABLED_AlignedStrideEncodeDecode
340 #else 325 #else
341 #define MAYBE_AlignedStrideEncodeDecode AlignedStrideEncodeDecode 326 #define MAYBE_AlignedStrideEncodeDecode AlignedStrideEncodeDecode
342 #endif 327 #endif
343 TEST_F(TestVp8Impl, MAYBE_AlignedStrideEncodeDecode) { 328 TEST_F(TestVp8Impl, MAYBE_AlignedStrideEncodeDecode) {
344 SetUpEncodeDecode(); 329 SetUpEncodeDecode();
345 encoder_->Encode(*input_frame_, nullptr, nullptr); 330 encoder_->Encode(*input_frame_, nullptr, nullptr);
346 EXPECT_GT(WaitForEncodedFrame(), 0u); 331 WaitForEncodedFrame();
347 // First frame should be a key frame. 332 // First frame should be a key frame.
348 encoded_frame_._frameType = kVideoFrameKey; 333 encoded_frame_._frameType = kVideoFrameKey;
349 encoded_frame_.ntp_time_ms_ = kTestNtpTimeMs; 334 encoded_frame_.ntp_time_ms_ = kTestNtpTimeMs;
350 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 335 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
351 decoder_->Decode(encoded_frame_, false, nullptr)); 336 decoder_->Decode(encoded_frame_, false, nullptr));
352 EXPECT_GT(WaitForDecodedFrame(), 0u); 337 WaitForDecodedFrame();
353 ASSERT_TRUE(decoded_frame_); 338 ASSERT_TRUE(decoded_frame_);
354 // Compute PSNR on all planes (faster than SSIM). 339 // Compute PSNR on all planes (faster than SSIM).
355 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_frame_), 36); 340 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_frame_), 36);
356 EXPECT_EQ(kTestTimestamp, decoded_frame_->timestamp()); 341 EXPECT_EQ(kTestTimestamp, decoded_frame_->timestamp());
357 EXPECT_EQ(kTestNtpTimeMs, decoded_frame_->ntp_time_ms()); 342 EXPECT_EQ(kTestNtpTimeMs, decoded_frame_->ntp_time_ms());
358 } 343 }
359 344
360 #if defined(WEBRTC_ANDROID) 345 #if defined(WEBRTC_ANDROID)
361 #define MAYBE_DecodeWithACompleteKeyFrame DISABLED_DecodeWithACompleteKeyFrame 346 #define MAYBE_DecodeWithACompleteKeyFrame DISABLED_DecodeWithACompleteKeyFrame
362 #else 347 #else
363 #define MAYBE_DecodeWithACompleteKeyFrame DecodeWithACompleteKeyFrame 348 #define MAYBE_DecodeWithACompleteKeyFrame DecodeWithACompleteKeyFrame
364 #endif 349 #endif
365 TEST_F(TestVp8Impl, MAYBE_DecodeWithACompleteKeyFrame) { 350 TEST_F(TestVp8Impl, MAYBE_DecodeWithACompleteKeyFrame) {
366 SetUpEncodeDecode(); 351 SetUpEncodeDecode();
367 encoder_->Encode(*input_frame_, nullptr, nullptr); 352 encoder_->Encode(*input_frame_, nullptr, nullptr);
368 EXPECT_GT(WaitForEncodedFrame(), 0u); 353 WaitForEncodedFrame();
369 // Setting complete to false -> should return an error. 354 // Setting complete to false -> should return an error.
370 encoded_frame_._completeFrame = false; 355 encoded_frame_._completeFrame = false;
371 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, 356 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR,
372 decoder_->Decode(encoded_frame_, false, nullptr)); 357 decoder_->Decode(encoded_frame_, false, nullptr));
373 // Setting complete back to true. Forcing a delta frame. 358 // Setting complete back to true. Forcing a delta frame.
374 encoded_frame_._frameType = kVideoFrameDelta; 359 encoded_frame_._frameType = kVideoFrameDelta;
375 encoded_frame_._completeFrame = true; 360 encoded_frame_._completeFrame = true;
376 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, 361 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR,
377 decoder_->Decode(encoded_frame_, false, nullptr)); 362 decoder_->Decode(encoded_frame_, false, nullptr));
378 // Now setting a key frame. 363 // Now setting a key frame.
379 encoded_frame_._frameType = kVideoFrameKey; 364 encoded_frame_._frameType = kVideoFrameKey;
380 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 365 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
381 decoder_->Decode(encoded_frame_, false, nullptr)); 366 decoder_->Decode(encoded_frame_, false, nullptr));
382 ASSERT_TRUE(decoded_frame_); 367 ASSERT_TRUE(decoded_frame_);
383 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_frame_), 36); 368 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_frame_), 36);
384 } 369 }
385 370
386 TEST_F(TestVp8Impl, EncoderRetainsRtpStateAfterRelease) { 371 TEST_F(TestVp8Impl, EncoderRetainsRtpStateAfterRelease) {
387 SetUpEncodeDecode(); 372 SetUpEncodeDecode();
388 // Override default settings. 373 // Override default settings.
389 codec_settings_.VP8()->numberOfTemporalLayers = 2; 374 codec_settings_.VP8()->numberOfTemporalLayers = 2;
390 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 375 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
391 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); 376 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize));
392 377
393 // Temporal layer 0. 378 // Temporal layer 0.
394 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 379 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
395 encoder_->Encode(*input_frame_, nullptr, nullptr)); 380 encoder_->Encode(*input_frame_, nullptr, nullptr));
396 ASSERT_TRUE(WaitForEncodedFrame()); 381 WaitForEncodedFrame();
397 EXPECT_EQ(0, codec_specific_info_.codecSpecific.VP8.temporalIdx); 382 EXPECT_EQ(0, codec_specific_info_.codecSpecific.VP8.temporalIdx);
398 int16_t picture_id = codec_specific_info_.codecSpecific.VP8.pictureId; 383 int16_t picture_id = codec_specific_info_.codecSpecific.VP8.pictureId;
399 int tl0_pic_idx = codec_specific_info_.codecSpecific.VP8.tl0PicIdx; 384 int tl0_pic_idx = codec_specific_info_.codecSpecific.VP8.tl0PicIdx;
400 385
401 // Temporal layer 1. 386 // Temporal layer 1.
402 input_frame_->set_timestamp(input_frame_->timestamp() + 387 input_frame_->set_timestamp(input_frame_->timestamp() +
403 kTimestampIncrementPerFrame); 388 kTimestampIncrementPerFrame);
404 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 389 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
405 encoder_->Encode(*input_frame_, nullptr, nullptr)); 390 encoder_->Encode(*input_frame_, nullptr, nullptr));
406 ExpectFrameWith((picture_id + 1) % (1 << 15), tl0_pic_idx, 1); 391 ExpectFrameWith((picture_id + 1) % (1 << 15), tl0_pic_idx, 1);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 // Temporal layer 1. 438 // Temporal layer 1.
454 input_frame_->set_timestamp(input_frame_->timestamp() + 439 input_frame_->set_timestamp(input_frame_->timestamp() +
455 kTimestampIncrementPerFrame); 440 kTimestampIncrementPerFrame);
456 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 441 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
457 encoder_->Encode(*input_frame_, nullptr, nullptr)); 442 encoder_->Encode(*input_frame_, nullptr, nullptr));
458 ExpectFrameWith((picture_id + 7) % (1 << 15), (tl0_pic_idx + 3) % (1 << 8), 443 ExpectFrameWith((picture_id + 7) % (1 << 15), (tl0_pic_idx + 3) % (1 << 8),
459 1); 444 1);
460 } 445 }
461 446
462 TEST_F(TestVp8Impl, ScalingDisabledIfAutomaticResizeOff) { 447 TEST_F(TestVp8Impl, ScalingDisabledIfAutomaticResizeOff) {
463 webrtc::test::CodecSettings(kVideoCodecVP8, &codec_settings_); 448 codec_settings_.VP8()->frameDroppingOn = true;
464 codec_settings_.VP8()->tl_factory = &tl_factory_;
465 codec_settings_.VP8()->automaticResizeOn = false; 449 codec_settings_.VP8()->automaticResizeOn = false;
466
467 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 450 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
468 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); 451 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize));
452
469 VideoEncoder::ScalingSettings settings = encoder_->GetScalingSettings(); 453 VideoEncoder::ScalingSettings settings = encoder_->GetScalingSettings();
470 EXPECT_FALSE(settings.enabled); 454 EXPECT_FALSE(settings.enabled);
471 } 455 }
472 456
473 TEST_F(TestVp8Impl, ScalingEnabledIfAutomaticResizeOn) { 457 TEST_F(TestVp8Impl, ScalingEnabledIfAutomaticResizeOn) {
474 webrtc::test::CodecSettings(kVideoCodecVP8, &codec_settings_); 458 codec_settings_.VP8()->frameDroppingOn = true;
475 codec_settings_.VP8()->tl_factory = &tl_factory_;
476 codec_settings_.VP8()->automaticResizeOn = true; 459 codec_settings_.VP8()->automaticResizeOn = true;
477
478 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 460 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
479 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); 461 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize));
462
480 VideoEncoder::ScalingSettings settings = encoder_->GetScalingSettings(); 463 VideoEncoder::ScalingSettings settings = encoder_->GetScalingSettings();
481 EXPECT_TRUE(settings.enabled); 464 EXPECT_TRUE(settings.enabled);
482 EXPECT_EQ(kDefaultMinPixelsPerFrame, settings.min_pixels_per_frame); 465 EXPECT_EQ(kDefaultMinPixelsPerFrame, settings.min_pixels_per_frame);
483 } 466 }
484 467
485 class TestVp8ImplWithForcedFallbackEnabled : public TestVp8Impl { 468 class TestVp8ImplWithForcedFallbackEnabled : public TestVp8Impl {
486 public: 469 public:
487 TestVp8ImplWithForcedFallbackEnabled() 470 TestVp8ImplWithForcedFallbackEnabled()
488 : TestVp8Impl("WebRTC-VP8-Forced-Fallback-Encoder/Enabled-1,2,3," + 471 : TestVp8Impl("WebRTC-VP8-Forced-Fallback-Encoder/Enabled-1,2,3," +
489 std::to_string(kMinPixelsPerFrame) + "/") {} 472 std::to_string(kMinPixelsPerFrame) + "/") {}
490 }; 473 };
491 474
492 TEST_F(TestVp8ImplWithForcedFallbackEnabled, MinPixelsPerFrameConfigured) { 475 TEST_F(TestVp8ImplWithForcedFallbackEnabled, MinPixelsPerFrameConfigured) {
493 webrtc::test::CodecSettings(kVideoCodecVP8, &codec_settings_); 476 codec_settings_.VP8()->frameDroppingOn = true;
494 codec_settings_.VP8()->tl_factory = &tl_factory_;
495 codec_settings_.VP8()->automaticResizeOn = true; 477 codec_settings_.VP8()->automaticResizeOn = true;
496
497 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 478 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
498 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); 479 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize));
480
499 VideoEncoder::ScalingSettings settings = encoder_->GetScalingSettings(); 481 VideoEncoder::ScalingSettings settings = encoder_->GetScalingSettings();
500 EXPECT_TRUE(settings.enabled); 482 EXPECT_TRUE(settings.enabled);
501 EXPECT_EQ(kMinPixelsPerFrame, settings.min_pixels_per_frame); 483 EXPECT_EQ(kMinPixelsPerFrame, settings.min_pixels_per_frame);
502 } 484 }
503 485
504 } // namespace webrtc 486 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698