Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 13 matching lines...) Expand all Loading... | |
| 24 #include "webrtc/test/frame_utils.h" | 24 #include "webrtc/test/frame_utils.h" |
| 25 #include "webrtc/test/gtest.h" | 25 #include "webrtc/test/gtest.h" |
| 26 #include "webrtc/test/testsupport/fileutils.h" | 26 #include "webrtc/test/testsupport/fileutils.h" |
| 27 #include "webrtc/test/video_codec_settings.h" | 27 #include "webrtc/test/video_codec_settings.h" |
| 28 | 28 |
| 29 namespace webrtc { | 29 namespace webrtc { |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 constexpr int64_t kMaxWaitEncTimeMs = 100; | 32 constexpr int64_t kMaxWaitEncTimeMs = 100; |
| 33 constexpr int64_t kMaxWaitDecTimeMs = 25; | 33 constexpr int64_t kMaxWaitDecTimeMs = 25; |
| 34 constexpr uint32_t kTestTimestamp = 123; | 34 constexpr uint32_t kTestTimestamp = 123; |
|
brandtr
2017/08/30 09:08:17
kInitialRtpTimestamp?
åsapersson
2017/08/30 10:53:49
Done.
| |
| 35 constexpr int64_t kTestNtpTimeMs = 456; | 35 constexpr int64_t kTestNtpTimeMs = 456; |
| 36 constexpr uint32_t kTimestampIncrementPerFrame = 3000; | 36 constexpr int64_t kTimestampMs = 789; |
|
brandtr
2017/08/30 09:08:17
kInitialTimestampMs?
åsapersson
2017/08/30 10:53:49
Done.
| |
| 37 constexpr uint32_t kTimestampIncrement = 3000; | |
| 37 constexpr int kNumCores = 1; | 38 constexpr int kNumCores = 1; |
| 38 constexpr size_t kMaxPayloadSize = 1440; | 39 constexpr size_t kMaxPayloadSize = 1440; |
| 39 constexpr int kMinPixelsPerFrame = 12345; | 40 constexpr int kMinPixelsPerFrame = 12345; |
| 40 constexpr int kDefaultMinPixelsPerFrame = 320 * 180; | 41 constexpr int kDefaultMinPixelsPerFrame = 320 * 180; |
| 41 constexpr int kWidth = 172; | 42 constexpr int kWidth = 172; |
| 42 constexpr int kHeight = 144; | 43 constexpr int kHeight = 144; |
| 43 | 44 |
| 44 void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv) { | 45 void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv) { |
| 45 *stride_y = 16 * ((width + 15) / 16); | 46 *stride_y = 16 * ((width + 15) / 16); |
| 46 *stride_uv = 16 * ((width + 31) / 32); | 47 *stride_uv = 16 * ((width + 31) / 32); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 60 frame_buffer_.reset(new uint8_t[encoded_frame._size]); | 61 frame_buffer_.reset(new uint8_t[encoded_frame._size]); |
| 61 } | 62 } |
| 62 RTC_DCHECK(frame_buffer_); | 63 RTC_DCHECK(frame_buffer_); |
| 63 memcpy(frame_buffer_.get(), encoded_frame._buffer, encoded_frame._length); | 64 memcpy(frame_buffer_.get(), encoded_frame._buffer, encoded_frame._length); |
| 64 encoded_frame_ = encoded_frame; | 65 encoded_frame_ = encoded_frame; |
| 65 encoded_frame_._buffer = frame_buffer_.get(); | 66 encoded_frame_._buffer = frame_buffer_.get(); |
| 66 | 67 |
| 67 // Skip |codec_name|, to avoid allocating. | 68 // Skip |codec_name|, to avoid allocating. |
| 68 EXPECT_STREQ("libvpx", codec_specific_info->codec_name); | 69 EXPECT_STREQ("libvpx", codec_specific_info->codec_name); |
| 69 EXPECT_EQ(kVideoCodecVP8, codec_specific_info->codecType); | 70 EXPECT_EQ(kVideoCodecVP8, codec_specific_info->codecType); |
| 71 EXPECT_EQ(0u, codec_specific_info->codecSpecific.VP8.simulcastIdx); | |
| 70 codec_specific_info_.codecType = codec_specific_info->codecType; | 72 codec_specific_info_.codecType = codec_specific_info->codecType; |
| 71 codec_specific_info_.codecSpecific = codec_specific_info->codecSpecific; | 73 codec_specific_info_.codecSpecific = codec_specific_info->codecSpecific; |
| 72 complete_ = true; | 74 complete_ = true; |
| 73 return Result(Result::OK, 0); | 75 return Result(Result::OK, 0); |
| 74 } | 76 } |
| 75 | 77 |
| 76 void VerifyQpParser(const EncodedImage& encoded_frame) const { | 78 void VerifyQpParser(const EncodedImage& encoded_frame) const { |
| 77 int qp; | 79 int qp; |
| 78 ASSERT_TRUE(vp8::GetQp(encoded_frame._buffer, encoded_frame._length, &qp)); | 80 ASSERT_TRUE(vp8::GetQp(encoded_frame._buffer, encoded_frame._length, &qp)); |
| 79 EXPECT_EQ(encoded_frame.qp_, qp) << "Encoder QP != parsed bitstream QP."; | 81 EXPECT_EQ(encoded_frame.qp_, qp) << "Encoder QP != parsed bitstream QP."; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 int stride_y; | 160 int stride_y; |
| 159 Calc16ByteAlignedStride(kWidth, &stride_y, &stride_uv); | 161 Calc16ByteAlignedStride(kWidth, &stride_y, &stride_uv); |
| 160 EXPECT_EQ(stride_y, 176); | 162 EXPECT_EQ(stride_y, 176); |
| 161 EXPECT_EQ(stride_uv, 96); | 163 EXPECT_EQ(stride_uv, 96); |
| 162 rtc::scoped_refptr<I420Buffer> stride_buffer( | 164 rtc::scoped_refptr<I420Buffer> stride_buffer( |
| 163 I420Buffer::Create(kWidth, kHeight, stride_y, stride_uv, stride_uv)); | 165 I420Buffer::Create(kWidth, kHeight, stride_y, stride_uv, stride_uv)); |
| 164 | 166 |
| 165 // No scaling in our case, just a copy, to add stride to the image. | 167 // No scaling in our case, just a copy, to add stride to the image. |
| 166 stride_buffer->ScaleFrom(*compact_buffer); | 168 stride_buffer->ScaleFrom(*compact_buffer); |
| 167 | 169 |
| 168 input_frame_.reset(new VideoFrame(stride_buffer, kVideoRotation_0, 0)); | 170 input_frame_.reset( |
| 171 new VideoFrame(stride_buffer, kVideoRotation_0, | |
|
brandtr
2017/08/30 09:08:17
Change to "preferred" ctor? Then you don't need to
åsapersson
2017/08/30 10:53:49
Done.
| |
| 172 kTimestampMs * rtc::kNumMicrosecsPerMillisec)); | |
| 169 input_frame_->set_timestamp(kTestTimestamp); | 173 input_frame_->set_timestamp(kTestTimestamp); |
| 170 fclose(file); | 174 fclose(file); |
| 171 } | 175 } |
| 172 | 176 |
| 173 void SetupCodecSettings() { | 177 void SetupCodecSettings() { |
| 174 webrtc::test::CodecSettings(kVideoCodecVP8, &codec_settings_); | 178 webrtc::test::CodecSettings(kVideoCodecVP8, &codec_settings_); |
| 175 codec_settings_.maxBitrate = 4000; | 179 codec_settings_.maxBitrate = 4000; |
| 176 codec_settings_.width = kWidth; | 180 codec_settings_.width = kWidth; |
| 177 codec_settings_.height = kHeight; | 181 codec_settings_.height = kHeight; |
| 178 codec_settings_.VP8()->denoisingOn = true; | 182 codec_settings_.VP8()->denoisingOn = true; |
| 179 codec_settings_.VP8()->frameDroppingOn = false; | 183 codec_settings_.VP8()->frameDroppingOn = false; |
| 180 codec_settings_.VP8()->automaticResizeOn = false; | 184 codec_settings_.VP8()->automaticResizeOn = false; |
| 181 codec_settings_.VP8()->complexity = kComplexityNormal; | 185 codec_settings_.VP8()->complexity = kComplexityNormal; |
| 182 codec_settings_.VP8()->tl_factory = &tl_factory_; | 186 codec_settings_.VP8()->tl_factory = &tl_factory_; |
| 183 } | 187 } |
| 184 | 188 |
| 185 void InitEncodeDecode() { | 189 void InitEncodeDecode() { |
| 186 EXPECT_EQ( | 190 EXPECT_EQ( |
| 187 WEBRTC_VIDEO_CODEC_OK, | 191 WEBRTC_VIDEO_CODEC_OK, |
| 188 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); | 192 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); |
| 189 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 193 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
| 190 decoder_->InitDecode(&codec_settings_, kNumCores)); | 194 decoder_->InitDecode(&codec_settings_, kNumCores)); |
| 191 } | 195 } |
| 192 | 196 |
| 197 void EncodeFrame() { | |
| 198 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | |
| 199 encoder_->Encode(*input_frame_, nullptr, nullptr)); | |
| 200 } | |
| 201 | |
| 193 void WaitForEncodedFrame() { | 202 void WaitForEncodedFrame() { |
| 194 int64_t start_ms = rtc::TimeMillis(); | 203 int64_t start_ms = rtc::TimeMillis(); |
| 195 while (rtc::TimeMillis() - start_ms < kMaxWaitEncTimeMs) { | 204 while (rtc::TimeMillis() - start_ms < kMaxWaitEncTimeMs) { |
| 196 if (encoded_cb_.EncodeComplete()) | 205 if (encoded_cb_.EncodeComplete()) |
| 197 return; | 206 return; |
| 198 } | 207 } |
| 199 ASSERT_TRUE(false); | 208 ASSERT_TRUE(false); |
|
brandtr
2017/08/30 09:08:17
RTC_NOTREACHED
åsapersson
2017/08/30 10:53:49
Done.
| |
| 200 } | 209 } |
| 201 | 210 |
| 202 void WaitForDecodedFrame() { | 211 void WaitForDecodedFrame() { |
|
brandtr
2017/08/30 11:07:17
Then I guess this could be removed too?
åsapersson
2017/08/30 11:22:20
Done.
| |
| 203 int64_t start_ms = rtc::TimeMillis(); | 212 int64_t start_ms = rtc::TimeMillis(); |
| 204 while (rtc::TimeMillis() - start_ms < kMaxWaitDecTimeMs) { | 213 while (rtc::TimeMillis() - start_ms < kMaxWaitDecTimeMs) { |
| 205 if (decoded_cb_.DecodeComplete()) | 214 if (decoded_cb_.DecodeComplete()) |
| 206 return; | 215 return; |
| 207 } | 216 } |
| 208 ASSERT_TRUE(false); | 217 ASSERT_TRUE(false); |
|
brandtr
2017/08/30 09:08:17
RTC_NOTREACHED
åsapersson
2017/08/30 10:53:49
Done.
| |
| 209 } | 218 } |
| 210 | 219 |
| 211 void ExpectFrameWith(int16_t picture_id, | 220 void ExpectFrameWith(int16_t picture_id, |
| 212 int tl0_pic_idx, | 221 int tl0_pic_idx, |
| 213 uint8_t temporal_idx) { | 222 uint8_t temporal_idx) { |
| 214 WaitForEncodedFrame(); | 223 WaitForEncodedFrame(); |
| 215 EXPECT_EQ(picture_id, | 224 EXPECT_EQ(picture_id % (1 << 15), |
| 216 encoded_cb_.codec_specific_info_.codecSpecific.VP8.pictureId); | 225 encoded_cb_.codec_specific_info_.codecSpecific.VP8.pictureId); |
| 217 EXPECT_EQ(tl0_pic_idx, | 226 EXPECT_EQ(tl0_pic_idx % (1 << 8), |
| 218 encoded_cb_.codec_specific_info_.codecSpecific.VP8.tl0PicIdx); | 227 encoded_cb_.codec_specific_info_.codecSpecific.VP8.tl0PicIdx); |
| 219 EXPECT_EQ(temporal_idx, | 228 EXPECT_EQ(temporal_idx, |
| 220 encoded_cb_.codec_specific_info_.codecSpecific.VP8.temporalIdx); | 229 encoded_cb_.codec_specific_info_.codecSpecific.VP8.temporalIdx); |
| 221 } | 230 } |
| 222 | 231 |
| 223 test::ScopedFieldTrials override_field_trials_; | 232 test::ScopedFieldTrials override_field_trials_; |
| 224 EncodedImageCallbackTestImpl encoded_cb_; | 233 EncodedImageCallbackTestImpl encoded_cb_; |
| 225 DecodedImageCallbackTestImpl decoded_cb_; | 234 DecodedImageCallbackTestImpl decoded_cb_; |
| 226 std::unique_ptr<VideoFrame> input_frame_; | 235 std::unique_ptr<VideoFrame> input_frame_; |
| 227 const std::unique_ptr<VideoEncoder> encoder_; | 236 const std::unique_ptr<VideoEncoder> encoder_; |
| 228 const std::unique_ptr<VideoDecoder> decoder_; | 237 const std::unique_ptr<VideoDecoder> decoder_; |
| 229 VideoCodec codec_settings_; | 238 VideoCodec codec_settings_; |
| 230 TemporalLayersFactory tl_factory_; | 239 TemporalLayersFactory tl_factory_; |
| 231 }; | 240 }; |
| 232 | 241 |
| 233 TEST_F(TestVp8Impl, EncodeFrame) { | 242 TEST_F(TestVp8Impl, SetRateAllocation) { |
| 234 InitEncodeDecode(); | |
| 235 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | |
| 236 encoder_->Encode(*input_frame_, nullptr, nullptr)); | |
| 237 WaitForEncodedFrame(); | |
| 238 } | |
| 239 | |
| 240 TEST_F(TestVp8Impl, EncoderParameterTest) { | |
| 241 codec_settings_.maxBitrate = 0; | |
| 242 codec_settings_.width = 1440; | |
| 243 codec_settings_.height = 1080; | |
| 244 | |
| 245 // Calls before InitEncode(). | |
| 246 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); | |
| 247 const int kBitrateBps = 300000; | 243 const int kBitrateBps = 300000; |
| 248 BitrateAllocation bitrate_allocation; | 244 BitrateAllocation bitrate_allocation; |
| 249 bitrate_allocation.SetBitrate(0, 0, kBitrateBps); | 245 bitrate_allocation.SetBitrate(0, 0, kBitrateBps); |
| 250 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, | 246 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, |
| 251 encoder_->SetRateAllocation(bitrate_allocation, | 247 encoder_->SetRateAllocation(bitrate_allocation, |
| 252 codec_settings_.maxFramerate)); | 248 codec_settings_.maxFramerate)); |
| 249 InitEncodeDecode(); | |
| 250 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | |
| 251 encoder_->SetRateAllocation(bitrate_allocation, | |
| 252 codec_settings_.maxFramerate)); | |
| 253 } | |
| 254 | |
| 255 TEST_F(TestVp8Impl, EncodeFrameAndRelease) { | |
| 256 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); | |
| 253 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 257 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
| 254 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); | 258 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); |
| 259 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | |
| 260 encoder_->Encode(*input_frame_, nullptr, nullptr)); | |
| 261 WaitForEncodedFrame(); | |
| 262 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); | |
| 263 EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED, | |
| 264 encoder_->Encode(*input_frame_, nullptr, nullptr)); | |
| 255 } | 265 } |
| 256 | 266 |
| 257 TEST_F(TestVp8Impl, DecoderParameterTest) { | 267 TEST_F(TestVp8Impl, InitDecode) { |
| 258 // Calls before InitDecode(). | |
| 259 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); | 268 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, decoder_->Release()); |
| 260 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 269 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
| 261 decoder_->InitDecode(&codec_settings_, kNumCores)); | 270 decoder_->InitDecode(&codec_settings_, kNumCores)); |
| 262 } | 271 } |
| 263 | 272 |
| 273 TEST_F(TestVp8Impl, OnEncodedImageReportsInfo) { | |
| 274 InitEncodeDecode(); | |
| 275 EncodeFrame(); | |
| 276 EXPECT_EQ(kTestTimestamp, encoded_cb_.encoded_frame_._timeStamp); | |
| 277 EXPECT_EQ(kTimestampMs, encoded_cb_.encoded_frame_.capture_time_ms_); | |
| 278 EXPECT_EQ(kWidth, static_cast<int>(encoded_cb_.encoded_frame_._encodedWidth)); | |
| 279 EXPECT_EQ(kHeight, | |
| 280 static_cast<int>(encoded_cb_.encoded_frame_._encodedHeight)); | |
| 281 EXPECT_EQ(-1, | |
| 282 encoded_cb_.encoded_frame_.adapt_reason_.bw_resolutions_disabled); | |
|
brandtr
2017/08/30 09:08:17
Is this field set/related to VP8Impl?
åsapersson
2017/08/30 10:53:49
Should be disabled for a single stream.
| |
| 283 } | |
| 284 | |
| 264 // We only test the encoder here, since the decoded frame rotation is set based | 285 // We only test the encoder here, since the decoded frame rotation is set based |
| 265 // on the CVO RTP header extension in VCMDecodedFrameCallback::Decoded. | 286 // on the CVO RTP header extension in VCMDecodedFrameCallback::Decoded. |
| 266 // TODO(brandtr): Consider passing through the rotation flag through the decoder | 287 // TODO(brandtr): Consider passing through the rotation flag through the decoder |
| 267 // in the same way as done in the encoder. | 288 // in the same way as done in the encoder. |
| 268 TEST_F(TestVp8Impl, EncodedRotationEqualsInputRotation) { | 289 TEST_F(TestVp8Impl, EncodedRotationEqualsInputRotation) { |
| 269 InitEncodeDecode(); | 290 InitEncodeDecode(); |
| 270 | |
| 271 input_frame_->set_rotation(kVideoRotation_0); | 291 input_frame_->set_rotation(kVideoRotation_0); |
| 272 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 292 EncodeFrame(); |
|
brandtr
2017/08/30 09:08:18
is WaitForEncodedFrame() not needed here?
Is it e
åsapersson
2017/08/30 10:53:49
Do not think it is ever needed, removed WaitForEnc
| |
| 273 encoder_->Encode(*input_frame_, nullptr, nullptr)); | |
| 274 WaitForEncodedFrame(); | |
| 275 EXPECT_EQ(kVideoRotation_0, encoded_cb_.encoded_frame_.rotation_); | 293 EXPECT_EQ(kVideoRotation_0, encoded_cb_.encoded_frame_.rotation_); |
| 276 | 294 |
| 277 input_frame_->set_rotation(kVideoRotation_90); | 295 input_frame_->set_rotation(kVideoRotation_90); |
| 278 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 296 EncodeFrame(); |
|
brandtr
2017/08/30 09:08:18
and here.
| |
| 279 encoder_->Encode(*input_frame_, nullptr, nullptr)); | |
| 280 WaitForEncodedFrame(); | |
| 281 EXPECT_EQ(kVideoRotation_90, encoded_cb_.encoded_frame_.rotation_); | 297 EXPECT_EQ(kVideoRotation_90, encoded_cb_.encoded_frame_.rotation_); |
| 282 } | 298 } |
| 283 | 299 |
| 284 TEST_F(TestVp8Impl, DecodedQpEqualsEncodedQp) { | 300 TEST_F(TestVp8Impl, DecodedQpEqualsEncodedQp) { |
| 285 InitEncodeDecode(); | 301 InitEncodeDecode(); |
| 286 encoder_->Encode(*input_frame_, nullptr, nullptr); | 302 encoder_->Encode(*input_frame_, nullptr, nullptr); |
| 287 WaitForEncodedFrame(); | 303 WaitForEncodedFrame(); |
| 288 // First frame should be a key frame. | 304 // First frame should be a key frame. |
| 289 encoded_cb_.encoded_frame_._frameType = kVideoFrameKey; | 305 encoded_cb_.encoded_frame_._frameType = kVideoFrameKey; |
| 290 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 306 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 decoder_->Decode(encoded_cb_.encoded_frame_, false, nullptr)); | 351 decoder_->Decode(encoded_cb_.encoded_frame_, false, nullptr)); |
| 336 // Now setting a key frame. | 352 // Now setting a key frame. |
| 337 encoded_cb_.encoded_frame_._frameType = kVideoFrameKey; | 353 encoded_cb_.encoded_frame_._frameType = kVideoFrameKey; |
| 338 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 354 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
| 339 decoder_->Decode(encoded_cb_.encoded_frame_, false, nullptr)); | 355 decoder_->Decode(encoded_cb_.encoded_frame_, false, nullptr)); |
| 340 ASSERT_TRUE(decoded_cb_.frame_); | 356 ASSERT_TRUE(decoded_cb_.frame_); |
| 341 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_cb_.frame_), 36); | 357 EXPECT_GT(I420PSNR(input_frame_.get(), &*decoded_cb_.frame_), 36); |
| 342 } | 358 } |
| 343 | 359 |
| 344 TEST_F(TestVp8Impl, EncoderRetainsRtpStateAfterRelease) { | 360 TEST_F(TestVp8Impl, EncoderRetainsRtpStateAfterRelease) { |
| 361 codec_settings_.VP8()->numberOfTemporalLayers = 2; | |
| 345 InitEncodeDecode(); | 362 InitEncodeDecode(); |
| 346 // Override default settings. | |
| 347 codec_settings_.VP8()->numberOfTemporalLayers = 2; | |
| 348 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | |
| 349 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); | |
| 350 | 363 |
| 351 // Temporal layer 0. | 364 // Temporal layer 0. |
| 352 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 365 EncodeFrame(); |
|
brandtr
2017/08/30 09:08:17
and here
| |
| 353 encoder_->Encode(*input_frame_, nullptr, nullptr)); | |
| 354 WaitForEncodedFrame(); | |
| 355 EXPECT_EQ(0, encoded_cb_.codec_specific_info_.codecSpecific.VP8.temporalIdx); | 366 EXPECT_EQ(0, encoded_cb_.codec_specific_info_.codecSpecific.VP8.temporalIdx); |
| 356 int16_t picture_id = | 367 int16_t picture_id = |
| 357 encoded_cb_.codec_specific_info_.codecSpecific.VP8.pictureId; | 368 encoded_cb_.codec_specific_info_.codecSpecific.VP8.pictureId; |
| 358 int tl0_pic_idx = | 369 int tl0_pic_idx = |
| 359 encoded_cb_.codec_specific_info_.codecSpecific.VP8.tl0PicIdx; | 370 encoded_cb_.codec_specific_info_.codecSpecific.VP8.tl0PicIdx; |
| 360 | |
| 361 // Temporal layer 1. | 371 // Temporal layer 1. |
| 362 input_frame_->set_timestamp(input_frame_->timestamp() + | 372 input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
| 363 kTimestampIncrementPerFrame); | 373 EncodeFrame(); |
| 364 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 374 ExpectFrameWith(picture_id + 1, tl0_pic_idx + 0, 1); |
| 365 encoder_->Encode(*input_frame_, nullptr, nullptr)); | |
| 366 ExpectFrameWith((picture_id + 1) % (1 << 15), tl0_pic_idx, 1); | |
| 367 | |
| 368 // Temporal layer 0. | 375 // Temporal layer 0. |
| 369 input_frame_->set_timestamp(input_frame_->timestamp() + | 376 input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
| 370 kTimestampIncrementPerFrame); | 377 EncodeFrame(); |
| 371 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 378 ExpectFrameWith(picture_id + 2, tl0_pic_idx + 1, 0); |
| 372 encoder_->Encode(*input_frame_, nullptr, nullptr)); | |
| 373 ExpectFrameWith((picture_id + 2) % (1 << 15), (tl0_pic_idx + 1) % (1 << 8), | |
| 374 0); | |
| 375 | |
| 376 // Temporal layer 1. | 379 // Temporal layer 1. |
| 377 input_frame_->set_timestamp(input_frame_->timestamp() + | 380 input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
| 378 kTimestampIncrementPerFrame); | 381 EncodeFrame(); |
| 379 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 382 ExpectFrameWith(picture_id + 3, tl0_pic_idx + 1, 1); |
| 380 encoder_->Encode(*input_frame_, nullptr, nullptr)); | |
| 381 ExpectFrameWith((picture_id + 3) % (1 << 15), (tl0_pic_idx + 1) % (1 << 8), | |
| 382 1); | |
| 383 | 383 |
| 384 // Reinit. | 384 // Reinit. |
| 385 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); | 385 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); |
| 386 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 386 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
| 387 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); | 387 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); |
| 388 | 388 |
| 389 // Temporal layer 0. | 389 // Temporal layer 0. |
| 390 input_frame_->set_timestamp(input_frame_->timestamp() + | 390 input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
| 391 kTimestampIncrementPerFrame); | 391 EncodeFrame(); |
| 392 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 392 ExpectFrameWith(picture_id + 4, tl0_pic_idx + 2, 0); |
| 393 encoder_->Encode(*input_frame_, nullptr, nullptr)); | 393 // Temporal layer 1. |
| 394 ExpectFrameWith((picture_id + 4) % (1 << 15), (tl0_pic_idx + 2) % (1 << 8), | 394 input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
| 395 0); | 395 EncodeFrame(); |
| 396 ExpectFrameWith(picture_id + 5, tl0_pic_idx + 2, 1); | |
| 397 // Temporal layer 0. | |
| 398 input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); | |
| 399 EncodeFrame(); | |
| 400 ExpectFrameWith(picture_id + 6, tl0_pic_idx + 3, 0); | |
| 401 // Temporal layer 1. | |
| 402 input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); | |
| 403 EncodeFrame(); | |
| 404 ExpectFrameWith(picture_id + 7, tl0_pic_idx + 3, 1); | |
| 405 } | |
| 396 | 406 |
| 397 // Temporal layer 1. | 407 TEST_F(TestVp8Impl, EncodeWithThreeTemporalLayers) { |
| 398 input_frame_->set_timestamp(input_frame_->timestamp() + | 408 codec_settings_.VP8()->numberOfTemporalLayers = 3; |
| 399 kTimestampIncrementPerFrame); | 409 InitEncodeDecode(); |
| 400 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | |
| 401 encoder_->Encode(*input_frame_, nullptr, nullptr)); | |
| 402 ExpectFrameWith((picture_id + 5) % (1 << 15), (tl0_pic_idx + 2) % (1 << 8), | |
| 403 1); | |
| 404 | 410 |
| 405 // Temporal layer 0. | 411 // Temporal layer 0. |
| 406 input_frame_->set_timestamp(input_frame_->timestamp() + | 412 EncodeFrame(); |
| 407 kTimestampIncrementPerFrame); | 413 EXPECT_EQ(0, encoded_cb_.codec_specific_info_.codecSpecific.VP8.temporalIdx); |
| 408 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 414 int16_t picture_id = |
| 409 encoder_->Encode(*input_frame_, nullptr, nullptr)); | 415 encoded_cb_.codec_specific_info_.codecSpecific.VP8.pictureId; |
| 410 ExpectFrameWith((picture_id + 6) % (1 << 15), (tl0_pic_idx + 3) % (1 << 8), | 416 int tl0_pic_idx = |
| 411 0); | 417 encoded_cb_.codec_specific_info_.codecSpecific.VP8.tl0PicIdx; |
| 412 | 418 // Temporal layer 2. |
| 419 input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); | |
| 420 EncodeFrame(); | |
| 421 ExpectFrameWith(picture_id + 1, tl0_pic_idx + 0, 2); | |
| 413 // Temporal layer 1. | 422 // Temporal layer 1. |
| 414 input_frame_->set_timestamp(input_frame_->timestamp() + | 423 input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
| 415 kTimestampIncrementPerFrame); | 424 EncodeFrame(); |
| 416 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 425 ExpectFrameWith(picture_id + 2, tl0_pic_idx + 0, 1); |
| 417 encoder_->Encode(*input_frame_, nullptr, nullptr)); | 426 // Temporal layer 2. |
| 418 ExpectFrameWith((picture_id + 7) % (1 << 15), (tl0_pic_idx + 3) % (1 << 8), | 427 input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); |
| 419 1); | 428 EncodeFrame(); |
| 429 ExpectFrameWith(picture_id + 3, tl0_pic_idx + 0, 2); | |
| 430 // Temporal layer 0. | |
| 431 input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); | |
| 432 EncodeFrame(); | |
| 433 ExpectFrameWith(picture_id + 4, tl0_pic_idx + 1, 0); | |
| 434 // Temporal layer 2. | |
| 435 input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); | |
| 436 EncodeFrame(); | |
| 437 ExpectFrameWith(picture_id + 5, tl0_pic_idx + 1, 2); | |
| 438 // Temporal layer 1. | |
| 439 input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); | |
| 440 EncodeFrame(); | |
| 441 ExpectFrameWith(picture_id + 6, tl0_pic_idx + 1, 1); | |
| 442 // Temporal layer 2. | |
| 443 input_frame_->set_timestamp(input_frame_->timestamp() + kTimestampIncrement); | |
| 444 EncodeFrame(); | |
| 445 ExpectFrameWith(picture_id + 7, tl0_pic_idx + 1, 2); | |
| 420 } | 446 } |
|
brandtr
2017/08/30 09:08:17
Might as well add a reinit here, and make this tes
åsapersson
2017/08/30 10:53:49
Done.
| |
| 421 | 447 |
| 422 TEST_F(TestVp8Impl, ScalingDisabledIfAutomaticResizeOff) { | 448 TEST_F(TestVp8Impl, ScalingDisabledIfAutomaticResizeOff) { |
| 423 codec_settings_.VP8()->frameDroppingOn = true; | 449 codec_settings_.VP8()->frameDroppingOn = true; |
| 424 codec_settings_.VP8()->automaticResizeOn = false; | 450 codec_settings_.VP8()->automaticResizeOn = false; |
| 425 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 451 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
| 426 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); | 452 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); |
| 427 | 453 |
| 428 VideoEncoder::ScalingSettings settings = encoder_->GetScalingSettings(); | 454 VideoEncoder::ScalingSettings settings = encoder_->GetScalingSettings(); |
| 429 EXPECT_FALSE(settings.enabled); | 455 EXPECT_FALSE(settings.enabled); |
| 430 } | 456 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 452 codec_settings_.VP8()->automaticResizeOn = true; | 478 codec_settings_.VP8()->automaticResizeOn = true; |
| 453 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 479 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
| 454 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); | 480 encoder_->InitEncode(&codec_settings_, kNumCores, kMaxPayloadSize)); |
| 455 | 481 |
| 456 VideoEncoder::ScalingSettings settings = encoder_->GetScalingSettings(); | 482 VideoEncoder::ScalingSettings settings = encoder_->GetScalingSettings(); |
| 457 EXPECT_TRUE(settings.enabled); | 483 EXPECT_TRUE(settings.enabled); |
| 458 EXPECT_EQ(kMinPixelsPerFrame, settings.min_pixels_per_frame); | 484 EXPECT_EQ(kMinPixelsPerFrame, settings.min_pixels_per_frame); |
| 459 } | 485 } |
| 460 | 486 |
| 461 } // namespace webrtc | 487 } // namespace webrtc |
| OLD | NEW |