Index: webrtc/modules/video_coding/codecs/vp9/test/vp9_impl_unittest.cc |
diff --git a/webrtc/modules/video_coding/codecs/vp9/test/vp9_impl_unittest.cc b/webrtc/modules/video_coding/codecs/vp9/test/vp9_impl_unittest.cc |
index bb453bd58252905869d3ee2f87382f2376d28f91..6a61d37965177c0da7ddd94f7aa09921322cb287 100644 |
--- a/webrtc/modules/video_coding/codecs/vp9/test/vp9_impl_unittest.cc |
+++ b/webrtc/modules/video_coding/codecs/vp9/test/vp9_impl_unittest.cc |
@@ -14,6 +14,10 @@ |
namespace webrtc { |
+namespace { |
+constexpr uint32_t kTimestampIncrementPerFrame = 3000; |
+} // namespace |
+ |
class TestVp9Impl : public VideoCodecTest { |
protected: |
VideoEncoder* CreateEncoder() override { return VP9Encoder::Create(); } |
@@ -27,6 +31,16 @@ class TestVp9Impl : public VideoCodecTest { |
codec_inst.VP9()->numberOfSpatialLayers = 1; |
return codec_inst; |
} |
+ |
+ void ExpectFrame(int16_t picture_id, int tl0_pic_idx, uint8_t temporal_idx) { |
stefan-webrtc
2017/05/02 07:21:50
ExpectFrameWith here too perhaps
brandtr
2017/05/02 07:48:50
Done.
|
+ EncodedImage encoded_frame; |
+ CodecSpecificInfo codec_specific_info; |
+ ASSERT_TRUE(WaitForEncodedFrame(&encoded_frame, &codec_specific_info)); |
+ EXPECT_EQ(picture_id, codec_specific_info.codecSpecific.VP9.picture_id); |
+ EXPECT_EQ(tl0_pic_idx, codec_specific_info.codecSpecific.VP9.tl0_pic_idx); |
+ EXPECT_EQ(temporal_idx, |
+ codec_specific_info.codecSpecific.VP9.temporal_idx); |
+ } |
}; |
// Disabled on ios as flake, see https://crbug.com/webrtc/7057 |
@@ -38,7 +52,8 @@ TEST_F(TestVp9Impl, EncodeDecode) { |
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
encoder_->Encode(*input_frame_, nullptr, nullptr)); |
EncodedImage encoded_frame; |
- ASSERT_TRUE(WaitForEncodedFrame(&encoded_frame)); |
+ CodecSpecificInfo codec_specific_info; |
+ ASSERT_TRUE(WaitForEncodedFrame(&encoded_frame, &codec_specific_info)); |
// First frame should be a key frame. |
encoded_frame._frameType = kVideoFrameKey; |
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
@@ -54,7 +69,8 @@ TEST_F(TestVp9Impl, DecodedQpEqualsEncodedQp) { |
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
encoder_->Encode(*input_frame_, nullptr, nullptr)); |
EncodedImage encoded_frame; |
- ASSERT_TRUE(WaitForEncodedFrame(&encoded_frame)); |
+ CodecSpecificInfo codec_specific_info; |
+ ASSERT_TRUE(WaitForEncodedFrame(&encoded_frame, &codec_specific_info)); |
// First frame should be a key frame. |
encoded_frame._frameType = kVideoFrameKey; |
EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
@@ -67,4 +83,79 @@ TEST_F(TestVp9Impl, DecodedQpEqualsEncodedQp) { |
EXPECT_EQ(encoded_frame.qp_, *decoded_qp); |
} |
+TEST_F(TestVp9Impl, EncoderRetainsRtpStateAfterRelease) { |
+ // Override default settings. |
+ codec_inst_.VP9()->numberOfTemporalLayers = 2; |
+ // Tl0PidIdx is only used in non-flexible mode. |
+ codec_inst_.VP9()->flexibleMode = false; |
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
+ encoder_->InitEncode(&codec_inst_, 1 /* number of cores */, |
+ 0 /* max payload size (unused) */)); |
+ |
+ // Temporal layer 0. |
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
+ encoder_->Encode(*input_frame_, nullptr, nullptr)); |
+ EncodedImage encoded_frame; |
+ CodecSpecificInfo codec_specific_info; |
+ ASSERT_TRUE(WaitForEncodedFrame(&encoded_frame, &codec_specific_info)); |
+ int16_t picture_id = codec_specific_info.codecSpecific.VP9.picture_id; |
+ int tl0_pic_idx = codec_specific_info.codecSpecific.VP9.tl0_pic_idx; |
+ EXPECT_EQ(0, codec_specific_info.codecSpecific.VP9.temporal_idx); |
+ |
+ // Temporal layer 1. |
+ input_frame_->set_timestamp(input_frame_->timestamp() + |
+ kTimestampIncrementPerFrame); |
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
+ encoder_->Encode(*input_frame_, nullptr, nullptr)); |
+ ExpectFrame((picture_id + 1) % (1 << 15), tl0_pic_idx, 1); |
+ |
+ // Temporal layer 0. |
+ input_frame_->set_timestamp(input_frame_->timestamp() + |
+ kTimestampIncrementPerFrame); |
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
+ encoder_->Encode(*input_frame_, nullptr, nullptr)); |
+ ExpectFrame((picture_id + 2) % (1 << 15), (tl0_pic_idx + 1) % (1 << 8), 0); |
+ |
+ // Temporal layer 1. |
+ input_frame_->set_timestamp(input_frame_->timestamp() + |
+ kTimestampIncrementPerFrame); |
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
+ encoder_->Encode(*input_frame_, nullptr, nullptr)); |
+ ExpectFrame((picture_id + 3) % (1 << 15), (tl0_pic_idx + 1) % (1 << 8), 1); |
+ |
+ // Reinit. |
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); |
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
+ encoder_->InitEncode(&codec_inst_, 1 /* number of cores */, |
+ 0 /* max payload size (unused) */)); |
+ |
+ // Temporal layer 0. |
+ input_frame_->set_timestamp(input_frame_->timestamp() + |
+ kTimestampIncrementPerFrame); |
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
+ encoder_->Encode(*input_frame_, nullptr, nullptr)); |
+ ExpectFrame((picture_id + 4) % (1 << 15), (tl0_pic_idx + 2) % (1 << 8), 0); |
+ |
+ // Temporal layer 1. |
+ input_frame_->set_timestamp(input_frame_->timestamp() + |
+ kTimestampIncrementPerFrame); |
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
+ encoder_->Encode(*input_frame_, nullptr, nullptr)); |
+ ExpectFrame((picture_id + 5) % (1 << 15), (tl0_pic_idx + 2) % (1 << 8), 1); |
+ |
+ // Temporal layer 0. |
+ input_frame_->set_timestamp(input_frame_->timestamp() + |
+ kTimestampIncrementPerFrame); |
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
+ encoder_->Encode(*input_frame_, nullptr, nullptr)); |
+ ExpectFrame((picture_id + 6) % (1 << 15), (tl0_pic_idx + 3) % (1 << 8), 0); |
+ |
+ // Temporal layer 1. |
+ input_frame_->set_timestamp(input_frame_->timestamp() + |
+ kTimestampIncrementPerFrame); |
+ EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
+ encoder_->Encode(*input_frame_, nullptr, nullptr)); |
+ ExpectFrame((picture_id + 7) % (1 << 15), (tl0_pic_idx + 3) % (1 << 8), 1); |
+} |
+ |
} // namespace webrtc |