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

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

Issue 2833493003: Don't re-randomize picture_id/tl0_pic_idx when re-initializing internal encoders. (Closed)
Patch Set: Change back TimeMills() -> TimeMicros(). Created 3 years, 7 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
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
11 #include <stdio.h> 11 #include <stdio.h>
12 12
13 #include <memory> 13 #include <memory>
14 14
15 #include "webrtc/api/video/i420_buffer.h" 15 #include "webrtc/api/video/i420_buffer.h"
16 #include "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
17 #include "webrtc/base/optional.h" 17 #include "webrtc/base/optional.h"
18 #include "webrtc/base/timeutils.h" 18 #include "webrtc/base/timeutils.h"
19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" 19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
20 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" 20 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
21 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" 21 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h"
22 #include "webrtc/modules/video_coding/include/video_codec_interface.h"
22 #include "webrtc/test/frame_utils.h" 23 #include "webrtc/test/frame_utils.h"
23 #include "webrtc/test/gtest.h" 24 #include "webrtc/test/gtest.h"
24 #include "webrtc/test/testsupport/fileutils.h" 25 #include "webrtc/test/testsupport/fileutils.h"
25 26
26 namespace webrtc { 27 namespace webrtc {
27 28
28 namespace { 29 namespace {
30
29 void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv) { 31 void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv) {
30 *stride_y = 16 * ((width + 15) / 16); 32 *stride_y = 16 * ((width + 15) / 16);
31 *stride_uv = 16 * ((width + 31) / 32); 33 *stride_uv = 16 * ((width + 31) / 32);
32 } 34 }
33 35
34 } // Anonymous namespace
35
36 enum { kMaxWaitEncTimeMs = 100 }; 36 enum { kMaxWaitEncTimeMs = 100 };
37 enum { kMaxWaitDecTimeMs = 25 }; 37 enum { kMaxWaitDecTimeMs = 25 };
38 38
39 static const uint32_t kTestTimestamp = 123; 39 constexpr uint32_t kTestTimestamp = 123;
40 static const int64_t kTestNtpTimeMs = 456; 40 constexpr int64_t kTestNtpTimeMs = 456;
41 constexpr uint32_t kTimestampIncrementPerFrame = 3000;
42
43 } // namespace
41 44
42 // TODO(mikhal): Replace these with mocks. 45 // TODO(mikhal): Replace these with mocks.
43 class Vp8UnitTestEncodeCompleteCallback : public webrtc::EncodedImageCallback { 46 class Vp8UnitTestEncodeCompleteCallback : public webrtc::EncodedImageCallback {
44 public: 47 public:
45 Vp8UnitTestEncodeCompleteCallback(EncodedImage* frame, 48 Vp8UnitTestEncodeCompleteCallback(EncodedImage* frame,
49 CodecSpecificInfo* codec_specific_info,
46 unsigned int decoderSpecificSize, 50 unsigned int decoderSpecificSize,
47 void* decoderSpecificInfo) 51 void* decoderSpecificInfo)
48 : encoded_frame_(frame), encode_complete_(false) {} 52 : encoded_frame_(frame),
53 codec_specific_info_(codec_specific_info),
54 encode_complete_(false) {}
49 55
50 Result OnEncodedImage(const EncodedImage& encoded_frame_, 56 Result OnEncodedImage(const EncodedImage& encoded_frame_,
51 const CodecSpecificInfo* codec_specific_info, 57 const CodecSpecificInfo* codec_specific_info,
52 const RTPFragmentationHeader* fragmentation) override; 58 const RTPFragmentationHeader* fragmentation) override;
53 bool EncodeComplete(); 59 bool EncodeComplete();
54 60
55 private: 61 private:
56 EncodedImage* const encoded_frame_; 62 EncodedImage* const encoded_frame_;
63 CodecSpecificInfo* const codec_specific_info_;
57 std::unique_ptr<uint8_t[]> frame_buffer_; 64 std::unique_ptr<uint8_t[]> frame_buffer_;
58 bool encode_complete_; 65 bool encode_complete_;
59 }; 66 };
60 67
61 webrtc::EncodedImageCallback::Result 68 webrtc::EncodedImageCallback::Result
62 Vp8UnitTestEncodeCompleteCallback::OnEncodedImage( 69 Vp8UnitTestEncodeCompleteCallback::OnEncodedImage(
63 const EncodedImage& encoded_frame, 70 const EncodedImage& encoded_frame,
64 const CodecSpecificInfo* codec_specific_info, 71 const CodecSpecificInfo* codec_specific_info,
65 const RTPFragmentationHeader* fragmentation) { 72 const RTPFragmentationHeader* fragmentation) {
66 if (encoded_frame_->_size < encoded_frame._length) { 73 if (encoded_frame_->_size < encoded_frame._length) {
67 delete[] encoded_frame_->_buffer; 74 delete[] encoded_frame_->_buffer;
68 frame_buffer_.reset(new uint8_t[encoded_frame._length]); 75 frame_buffer_.reset(new uint8_t[encoded_frame._length]);
69 encoded_frame_->_buffer = frame_buffer_.get(); 76 encoded_frame_->_buffer = frame_buffer_.get();
70 encoded_frame_->_size = encoded_frame._length; 77 encoded_frame_->_size = encoded_frame._length;
71 } 78 }
72 memcpy(encoded_frame_->_buffer, encoded_frame._buffer, encoded_frame._length); 79 memcpy(encoded_frame_->_buffer, encoded_frame._buffer, encoded_frame._length);
73 encoded_frame_->_length = encoded_frame._length; 80 encoded_frame_->_length = encoded_frame._length;
74 encoded_frame_->_encodedWidth = encoded_frame._encodedWidth; 81 encoded_frame_->_encodedWidth = encoded_frame._encodedWidth;
75 encoded_frame_->_encodedHeight = encoded_frame._encodedHeight; 82 encoded_frame_->_encodedHeight = encoded_frame._encodedHeight;
76 encoded_frame_->_timeStamp = encoded_frame._timeStamp; 83 encoded_frame_->_timeStamp = encoded_frame._timeStamp;
77 encoded_frame_->_frameType = encoded_frame._frameType; 84 encoded_frame_->_frameType = encoded_frame._frameType;
78 encoded_frame_->_completeFrame = encoded_frame._completeFrame; 85 encoded_frame_->_completeFrame = encoded_frame._completeFrame;
79 encoded_frame_->qp_ = encoded_frame.qp_; 86 encoded_frame_->qp_ = encoded_frame.qp_;
87 codec_specific_info_->codecType = codec_specific_info->codecType;
88 // Skip |codec_name|, to avoid allocating.
89 codec_specific_info_->codecSpecific = codec_specific_info->codecSpecific;
80 encode_complete_ = true; 90 encode_complete_ = true;
81 return Result(Result::OK, 0); 91 return Result(Result::OK, 0);
82 } 92 }
83 93
84 bool Vp8UnitTestEncodeCompleteCallback::EncodeComplete() { 94 bool Vp8UnitTestEncodeCompleteCallback::EncodeComplete() {
85 if (encode_complete_) { 95 if (encode_complete_) {
86 encode_complete_ = false; 96 encode_complete_ = false;
87 return true; 97 return true;
88 } 98 }
89 return false; 99 return false;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 *decoded_frame_ = rtc::Optional<VideoFrame>(frame); 138 *decoded_frame_ = rtc::Optional<VideoFrame>(frame);
129 *decoded_qp_ = qp; 139 *decoded_qp_ = qp;
130 decode_complete = true; 140 decode_complete = true;
131 } 141 }
132 142
133 class TestVp8Impl : public ::testing::Test { 143 class TestVp8Impl : public ::testing::Test {
134 protected: 144 protected:
135 virtual void SetUp() { 145 virtual void SetUp() {
136 encoder_.reset(VP8Encoder::Create()); 146 encoder_.reset(VP8Encoder::Create());
137 decoder_.reset(VP8Decoder::Create()); 147 decoder_.reset(VP8Decoder::Create());
138 memset(&codec_inst_, 0, sizeof(codec_inst_)); 148 memset(&codec_settings_, 0, sizeof(codec_settings_));
139 encode_complete_callback_.reset( 149 encode_complete_callback_.reset(new Vp8UnitTestEncodeCompleteCallback(
140 new Vp8UnitTestEncodeCompleteCallback(&encoded_frame_, 0, NULL)); 150 &encoded_frame_, &codec_specific_info_, 0, nullptr));
141 decode_complete_callback_.reset( 151 decode_complete_callback_.reset(
142 new Vp8UnitTestDecodeCompleteCallback(&decoded_frame_, &decoded_qp_)); 152 new Vp8UnitTestDecodeCompleteCallback(&decoded_frame_, &decoded_qp_));
143 encoder_->RegisterEncodeCompleteCallback(encode_complete_callback_.get()); 153 encoder_->RegisterEncodeCompleteCallback(encode_complete_callback_.get());
144 decoder_->RegisterDecodeCompleteCallback(decode_complete_callback_.get()); 154 decoder_->RegisterDecodeCompleteCallback(decode_complete_callback_.get());
145 // Using a QCIF image (aligned stride (u,v planes) > width). 155 // Using a QCIF image (aligned stride (u,v planes) > width).
146 // Processing only one frame. 156 // Processing only one frame.
147 source_file_ = fopen(test::ResourcePath("paris_qcif", "yuv").c_str(), "rb"); 157 source_file_ = fopen(test::ResourcePath("paris_qcif", "yuv").c_str(), "rb");
148 ASSERT_TRUE(source_file_ != NULL); 158 ASSERT_TRUE(source_file_ != nullptr);
149 rtc::scoped_refptr<VideoFrameBuffer> compact_buffer( 159 rtc::scoped_refptr<VideoFrameBuffer> compact_buffer(
150 test::ReadI420Buffer(kWidth, kHeight, source_file_)); 160 test::ReadI420Buffer(kWidth, kHeight, source_file_));
151 ASSERT_TRUE(compact_buffer); 161 ASSERT_TRUE(compact_buffer);
152 codec_inst_.width = kWidth; 162 codec_settings_.width = kWidth;
153 codec_inst_.height = kHeight; 163 codec_settings_.height = kHeight;
154 const int kFramerate = 30; 164 const int kFramerate = 30;
155 codec_inst_.maxFramerate = kFramerate; 165 codec_settings_.maxFramerate = kFramerate;
156 // Setting aligned stride values. 166 // Setting aligned stride values.
157 int stride_uv; 167 int stride_uv;
158 int stride_y; 168 int stride_y;
159 Calc16ByteAlignedStride(codec_inst_.width, &stride_y, &stride_uv); 169 Calc16ByteAlignedStride(codec_settings_.width, &stride_y, &stride_uv);
160 EXPECT_EQ(stride_y, 176); 170 EXPECT_EQ(stride_y, 176);
161 EXPECT_EQ(stride_uv, 96); 171 EXPECT_EQ(stride_uv, 96);
162 172
163 rtc::scoped_refptr<I420Buffer> stride_buffer( 173 rtc::scoped_refptr<I420Buffer> stride_buffer(
164 I420Buffer::Create(kWidth, kHeight, stride_y, stride_uv, stride_uv)); 174 I420Buffer::Create(kWidth, kHeight, stride_y, stride_uv, stride_uv));
165 175
166 // No scaling in our case, just a copy, to add stride to the image. 176 // No scaling in our case, just a copy, to add stride to the image.
167 stride_buffer->ScaleFrom(*compact_buffer); 177 stride_buffer->ScaleFrom(*compact_buffer);
168 178
169 input_frame_.reset( 179 input_frame_.reset(
170 new VideoFrame(stride_buffer, kVideoRotation_0, 0)); 180 new VideoFrame(stride_buffer, kVideoRotation_0, 0));
171 input_frame_->set_timestamp(kTestTimestamp); 181 input_frame_->set_timestamp(kTestTimestamp);
172 } 182 }
173 183
174 void SetUpEncodeDecode() { 184 void SetUpEncodeDecode() {
175 codec_inst_.startBitrate = 300; 185 codec_settings_.startBitrate = 300;
176 codec_inst_.maxBitrate = 4000; 186 codec_settings_.maxBitrate = 4000;
177 codec_inst_.qpMax = 56; 187 codec_settings_.qpMax = 56;
178 codec_inst_.VP8()->denoisingOn = true; 188 codec_settings_.VP8()->denoisingOn = true;
179 codec_inst_.VP8()->tl_factory = &tl_factory_; 189 codec_settings_.VP8()->tl_factory = &tl_factory_;
180 codec_inst_.VP8()->numberOfTemporalLayers = 1; 190 codec_settings_.VP8()->numberOfTemporalLayers = 1;
181 191
182 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 192 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
183 encoder_->InitEncode(&codec_inst_, 1, 1440)); 193 encoder_->InitEncode(&codec_settings_, 1, 1440));
184 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_inst_, 1)); 194 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_settings_, 1));
185 } 195 }
186 196
187 size_t WaitForEncodedFrame() const { 197 size_t WaitForEncodedFrame() const {
188 int64_t startTime = rtc::TimeMillis(); 198 int64_t startTime = rtc::TimeMillis();
189 while (rtc::TimeMillis() - startTime < kMaxWaitEncTimeMs) { 199 while (rtc::TimeMillis() - startTime < kMaxWaitEncTimeMs) {
190 if (encode_complete_callback_->EncodeComplete()) { 200 if (encode_complete_callback_->EncodeComplete()) {
191 return encoded_frame_._length; 201 return encoded_frame_._length;
192 } 202 }
193 } 203 }
194 return 0; 204 return 0;
195 } 205 }
196 206
197 size_t WaitForDecodedFrame() const { 207 size_t WaitForDecodedFrame() const {
198 int64_t startTime = rtc::TimeMillis(); 208 int64_t startTime = rtc::TimeMillis();
199 while (rtc::TimeMillis() - startTime < kMaxWaitDecTimeMs) { 209 while (rtc::TimeMillis() - startTime < kMaxWaitDecTimeMs) {
200 if (decode_complete_callback_->DecodeComplete()) { 210 if (decode_complete_callback_->DecodeComplete()) {
201 return CalcBufferSize(VideoType::kI420, decoded_frame_->width(), 211 return CalcBufferSize(VideoType::kI420, decoded_frame_->width(),
202 decoded_frame_->height()); 212 decoded_frame_->height());
203 } 213 }
204 } 214 }
205 return 0; 215 return 0;
206 } 216 }
207 217
218 void ExpectFrameWith(int16_t picture_id,
219 int tl0_pic_idx,
220 uint8_t temporal_idx) {
221 ASSERT_TRUE(WaitForEncodedFrame());
222 EXPECT_EQ(picture_id, codec_specific_info_.codecSpecific.VP8.pictureId);
223 EXPECT_EQ(tl0_pic_idx, codec_specific_info_.codecSpecific.VP8.tl0PicIdx);
224 EXPECT_EQ(temporal_idx, codec_specific_info_.codecSpecific.VP8.temporalIdx);
225 }
226
208 const int kWidth = 172; 227 const int kWidth = 172;
209 const int kHeight = 144; 228 const int kHeight = 144;
210 229
211 std::unique_ptr<Vp8UnitTestEncodeCompleteCallback> encode_complete_callback_; 230 std::unique_ptr<Vp8UnitTestEncodeCompleteCallback> encode_complete_callback_;
212 std::unique_ptr<Vp8UnitTestDecodeCompleteCallback> decode_complete_callback_; 231 std::unique_ptr<Vp8UnitTestDecodeCompleteCallback> decode_complete_callback_;
213 std::unique_ptr<uint8_t[]> source_buffer_; 232 std::unique_ptr<uint8_t[]> source_buffer_;
214 FILE* source_file_; 233 FILE* source_file_;
215 std::unique_ptr<VideoFrame> input_frame_; 234 std::unique_ptr<VideoFrame> input_frame_;
216 std::unique_ptr<VideoEncoder> encoder_; 235 std::unique_ptr<VideoEncoder> encoder_;
217 std::unique_ptr<VideoDecoder> decoder_; 236 std::unique_ptr<VideoDecoder> decoder_;
218 EncodedImage encoded_frame_; 237 EncodedImage encoded_frame_;
238 CodecSpecificInfo codec_specific_info_;
219 rtc::Optional<VideoFrame> decoded_frame_; 239 rtc::Optional<VideoFrame> decoded_frame_;
220 rtc::Optional<uint8_t> decoded_qp_; 240 rtc::Optional<uint8_t> decoded_qp_;
221 VideoCodec codec_inst_; 241 VideoCodec codec_settings_;
222 TemporalLayersFactory tl_factory_; 242 TemporalLayersFactory tl_factory_;
223 }; 243 };
224 244
225 TEST_F(TestVp8Impl, EncoderParameterTest) { 245 TEST_F(TestVp8Impl, EncoderParameterTest) {
226 strncpy(codec_inst_.plName, "VP8", 31); 246 strncpy(codec_settings_.plName, "VP8", 31);
227 codec_inst_.plType = 126; 247 codec_settings_.plType = 126;
228 codec_inst_.maxBitrate = 0; 248 codec_settings_.maxBitrate = 0;
229 codec_inst_.minBitrate = 0; 249 codec_settings_.minBitrate = 0;
230 codec_inst_.width = 1440; 250 codec_settings_.width = 1440;
231 codec_inst_.height = 1080; 251 codec_settings_.height = 1080;
232 codec_inst_.maxFramerate = 30; 252 codec_settings_.maxFramerate = 30;
233 codec_inst_.startBitrate = 300; 253 codec_settings_.startBitrate = 300;
234 codec_inst_.qpMax = 56; 254 codec_settings_.qpMax = 56;
235 codec_inst_.VP8()->complexity = kComplexityNormal; 255 codec_settings_.VP8()->complexity = kComplexityNormal;
236 codec_inst_.VP8()->numberOfTemporalLayers = 1; 256 codec_settings_.VP8()->numberOfTemporalLayers = 1;
237 codec_inst_.VP8()->tl_factory = &tl_factory_; 257 codec_settings_.VP8()->tl_factory = &tl_factory_;
238 // Calls before InitEncode(). 258 // Calls before InitEncode().
239 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); 259 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release());
240 int bit_rate = 300; 260 int bit_rate = 300;
241 BitrateAllocation bitrate_allocation; 261 BitrateAllocation bitrate_allocation;
242 bitrate_allocation.SetBitrate(0, 0, bit_rate * 1000); 262 bitrate_allocation.SetBitrate(0, 0, bit_rate * 1000);
243 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, 263 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED,
244 encoder_->SetRateAllocation(bitrate_allocation, 264 encoder_->SetRateAllocation(bitrate_allocation,
245 codec_inst_.maxFramerate)); 265 codec_settings_.maxFramerate));
246 266
247 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->InitEncode(&codec_inst_, 1, 1440)); 267 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
268 encoder_->InitEncode(&codec_settings_, 1, 1440));
248 269
249 // Decoder parameter tests. 270 // Decoder parameter tests.
250 // Calls before InitDecode(). 271 // Calls before InitDecode().
251 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); 272 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release());
252 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_inst_, 1)); 273 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->InitDecode(&codec_settings_, 1));
253 } 274 }
254 275
255 TEST_F(TestVp8Impl, DecodedQpEqualsEncodedQp) { 276 TEST_F(TestVp8Impl, DecodedQpEqualsEncodedQp) {
256 SetUpEncodeDecode(); 277 SetUpEncodeDecode();
257 encoder_->Encode(*input_frame_, nullptr, nullptr); 278 encoder_->Encode(*input_frame_, nullptr, nullptr);
258 EXPECT_GT(WaitForEncodedFrame(), 0u); 279 EXPECT_GT(WaitForEncodedFrame(), 0u);
259 // First frame should be a key frame. 280 // First frame should be a key frame.
260 encoded_frame_._frameType = kVideoFrameKey; 281 encoded_frame_._frameType = kVideoFrameKey;
261 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 282 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
262 decoder_->Decode(encoded_frame_, false, nullptr)); 283 decoder_->Decode(encoded_frame_, false, nullptr));
263 EXPECT_GT(WaitForDecodedFrame(), 0u); 284 EXPECT_GT(WaitForDecodedFrame(), 0u);
264 ASSERT_TRUE(decoded_frame_); 285 ASSERT_TRUE(decoded_frame_);
265 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_frame_), 36); 286 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_frame_), 36);
266 ASSERT_TRUE(decoded_qp_); 287 ASSERT_TRUE(decoded_qp_);
267 EXPECT_EQ(encoded_frame_.qp_, *decoded_qp_); 288 EXPECT_EQ(encoded_frame_.qp_, *decoded_qp_);
268 } 289 }
269 290
270 #if defined(WEBRTC_ANDROID) 291 #if defined(WEBRTC_ANDROID)
271 #define MAYBE_AlignedStrideEncodeDecode DISABLED_AlignedStrideEncodeDecode 292 #define MAYBE_AlignedStrideEncodeDecode DISABLED_AlignedStrideEncodeDecode
272 #else 293 #else
273 #define MAYBE_AlignedStrideEncodeDecode AlignedStrideEncodeDecode 294 #define MAYBE_AlignedStrideEncodeDecode AlignedStrideEncodeDecode
274 #endif 295 #endif
275 TEST_F(TestVp8Impl, MAYBE_AlignedStrideEncodeDecode) { 296 TEST_F(TestVp8Impl, MAYBE_AlignedStrideEncodeDecode) {
276 SetUpEncodeDecode(); 297 SetUpEncodeDecode();
277 encoder_->Encode(*input_frame_, NULL, NULL); 298 encoder_->Encode(*input_frame_, nullptr, nullptr);
278 EXPECT_GT(WaitForEncodedFrame(), 0u); 299 EXPECT_GT(WaitForEncodedFrame(), 0u);
279 // First frame should be a key frame. 300 // First frame should be a key frame.
280 encoded_frame_._frameType = kVideoFrameKey; 301 encoded_frame_._frameType = kVideoFrameKey;
281 encoded_frame_.ntp_time_ms_ = kTestNtpTimeMs; 302 encoded_frame_.ntp_time_ms_ = kTestNtpTimeMs;
282 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 303 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
283 decoder_->Decode(encoded_frame_, false, NULL)); 304 decoder_->Decode(encoded_frame_, false, nullptr));
284 EXPECT_GT(WaitForDecodedFrame(), 0u); 305 EXPECT_GT(WaitForDecodedFrame(), 0u);
285 ASSERT_TRUE(decoded_frame_); 306 ASSERT_TRUE(decoded_frame_);
286 // Compute PSNR on all planes (faster than SSIM). 307 // Compute PSNR on all planes (faster than SSIM).
287 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_frame_), 36); 308 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_frame_), 36);
288 EXPECT_EQ(kTestTimestamp, decoded_frame_->timestamp()); 309 EXPECT_EQ(kTestTimestamp, decoded_frame_->timestamp());
289 EXPECT_EQ(kTestNtpTimeMs, decoded_frame_->ntp_time_ms()); 310 EXPECT_EQ(kTestNtpTimeMs, decoded_frame_->ntp_time_ms());
290 } 311 }
291 312
292 #if defined(WEBRTC_ANDROID) 313 #if defined(WEBRTC_ANDROID)
293 #define MAYBE_DecodeWithACompleteKeyFrame DISABLED_DecodeWithACompleteKeyFrame 314 #define MAYBE_DecodeWithACompleteKeyFrame DISABLED_DecodeWithACompleteKeyFrame
294 #else 315 #else
295 #define MAYBE_DecodeWithACompleteKeyFrame DecodeWithACompleteKeyFrame 316 #define MAYBE_DecodeWithACompleteKeyFrame DecodeWithACompleteKeyFrame
296 #endif 317 #endif
297 TEST_F(TestVp8Impl, MAYBE_DecodeWithACompleteKeyFrame) { 318 TEST_F(TestVp8Impl, MAYBE_DecodeWithACompleteKeyFrame) {
298 SetUpEncodeDecode(); 319 SetUpEncodeDecode();
299 encoder_->Encode(*input_frame_, NULL, NULL); 320 encoder_->Encode(*input_frame_, nullptr, nullptr);
300 EXPECT_GT(WaitForEncodedFrame(), 0u); 321 EXPECT_GT(WaitForEncodedFrame(), 0u);
301 // Setting complete to false -> should return an error. 322 // Setting complete to false -> should return an error.
302 encoded_frame_._completeFrame = false; 323 encoded_frame_._completeFrame = false;
303 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, 324 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR,
304 decoder_->Decode(encoded_frame_, false, NULL)); 325 decoder_->Decode(encoded_frame_, false, nullptr));
305 // Setting complete back to true. Forcing a delta frame. 326 // Setting complete back to true. Forcing a delta frame.
306 encoded_frame_._frameType = kVideoFrameDelta; 327 encoded_frame_._frameType = kVideoFrameDelta;
307 encoded_frame_._completeFrame = true; 328 encoded_frame_._completeFrame = true;
308 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, 329 EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR,
309 decoder_->Decode(encoded_frame_, false, NULL)); 330 decoder_->Decode(encoded_frame_, false, nullptr));
310 // Now setting a key frame. 331 // Now setting a key frame.
311 encoded_frame_._frameType = kVideoFrameKey; 332 encoded_frame_._frameType = kVideoFrameKey;
312 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, 333 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
313 decoder_->Decode(encoded_frame_, false, NULL)); 334 decoder_->Decode(encoded_frame_, false, nullptr));
314 ASSERT_TRUE(decoded_frame_); 335 ASSERT_TRUE(decoded_frame_);
315 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_frame_), 36); 336 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_frame_), 36);
316 } 337 }
317 338
339 TEST_F(TestVp8Impl, EncoderRetainsRtpStateAfterRelease) {
340 SetUpEncodeDecode();
341 // Override default settings.
342 codec_settings_.VP8()->numberOfTemporalLayers = 2;
343 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
344 encoder_->InitEncode(&codec_settings_, 1, 1440));
345
346 // Temporal layer 0.
347 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
348 encoder_->Encode(*input_frame_, nullptr, nullptr));
349 ASSERT_TRUE(WaitForEncodedFrame());
350 EXPECT_EQ(0, codec_specific_info_.codecSpecific.VP8.temporalIdx);
351 int16_t picture_id = codec_specific_info_.codecSpecific.VP8.pictureId;
352 int tl0_pic_idx = codec_specific_info_.codecSpecific.VP8.tl0PicIdx;
353
354 // Temporal layer 1.
355 input_frame_->set_timestamp(input_frame_->timestamp() +
356 kTimestampIncrementPerFrame);
357 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
358 encoder_->Encode(*input_frame_, nullptr, nullptr));
359 ExpectFrameWith((picture_id + 1) % (1 << 15), tl0_pic_idx, 1);
360
361 // Temporal layer 0.
362 input_frame_->set_timestamp(input_frame_->timestamp() +
363 kTimestampIncrementPerFrame);
364 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
365 encoder_->Encode(*input_frame_, nullptr, nullptr));
366 ExpectFrameWith((picture_id + 2) % (1 << 15), (tl0_pic_idx + 1) % (1 << 8),
367 0);
368
369 // Temporal layer 1.
370 input_frame_->set_timestamp(input_frame_->timestamp() +
371 kTimestampIncrementPerFrame);
372 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
373 encoder_->Encode(*input_frame_, nullptr, nullptr));
374 ExpectFrameWith((picture_id + 3) % (1 << 15), (tl0_pic_idx + 1) % (1 << 8),
375 1);
376
377 // Reinit.
378 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release());
379 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
380 encoder_->InitEncode(&codec_settings_, 1, 1440));
381
382 // Temporal layer 0.
383 input_frame_->set_timestamp(input_frame_->timestamp() +
384 kTimestampIncrementPerFrame);
385 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
386 encoder_->Encode(*input_frame_, nullptr, nullptr));
387 ExpectFrameWith((picture_id + 4) % (1 << 15), (tl0_pic_idx + 2) % (1 << 8),
388 0);
389
390 // Temporal layer 1.
391 input_frame_->set_timestamp(input_frame_->timestamp() +
392 kTimestampIncrementPerFrame);
393 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
394 encoder_->Encode(*input_frame_, nullptr, nullptr));
395 ExpectFrameWith((picture_id + 5) % (1 << 15), (tl0_pic_idx + 2) % (1 << 8),
396 1);
397
398 // Temporal layer 0.
399 input_frame_->set_timestamp(input_frame_->timestamp() +
400 kTimestampIncrementPerFrame);
401 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
402 encoder_->Encode(*input_frame_, nullptr, nullptr));
403 ExpectFrameWith((picture_id + 6) % (1 << 15), (tl0_pic_idx + 3) % (1 << 8),
404 0);
405
406 // Temporal layer 1.
407 input_frame_->set_timestamp(input_frame_->timestamp() +
408 kTimestampIncrementPerFrame);
409 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
410 encoder_->Encode(*input_frame_, nullptr, nullptr));
411 ExpectFrameWith((picture_id + 7) % (1 << 15), (tl0_pic_idx + 3) % (1 << 8),
412 1);
413 }
414
318 } // namespace webrtc 415 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/codecs/vp8/temporal_layers.h ('k') | webrtc/modules/video_coding/codecs/vp8/vp8_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698