OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 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 "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 11 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
12 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" | 12 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" |
13 #include "webrtc/modules/video_coding/codecs/test/video_codec_test.h" | 13 #include "webrtc/modules/video_coding/codecs/test/video_codec_test.h" |
14 | 14 |
15 namespace webrtc { | 15 namespace webrtc { |
16 | 16 |
17 namespace { | |
18 constexpr uint32_t kTimestampIncrementPerFrame = 3000; | |
19 } // namespace | |
20 | |
17 class TestVp9Impl : public VideoCodecTest { | 21 class TestVp9Impl : public VideoCodecTest { |
18 protected: | 22 protected: |
19 VideoEncoder* CreateEncoder() override { return VP9Encoder::Create(); } | 23 VideoEncoder* CreateEncoder() override { return VP9Encoder::Create(); } |
20 | 24 |
21 VideoDecoder* CreateDecoder() override { return VP9Decoder::Create(); } | 25 VideoDecoder* CreateDecoder() override { return VP9Decoder::Create(); } |
22 | 26 |
23 VideoCodec codec_settings() override { | 27 VideoCodec codec_settings() override { |
24 VideoCodec codec_inst; | 28 VideoCodec codec_inst; |
25 codec_inst.codecType = webrtc::kVideoCodecVP9; | 29 codec_inst.codecType = webrtc::kVideoCodecVP9; |
26 codec_inst.VP9()->numberOfTemporalLayers = 1; | 30 codec_inst.VP9()->numberOfTemporalLayers = 1; |
27 codec_inst.VP9()->numberOfSpatialLayers = 1; | 31 codec_inst.VP9()->numberOfSpatialLayers = 1; |
28 return codec_inst; | 32 return codec_inst; |
29 } | 33 } |
34 | |
35 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.
| |
36 EncodedImage encoded_frame; | |
37 CodecSpecificInfo codec_specific_info; | |
38 ASSERT_TRUE(WaitForEncodedFrame(&encoded_frame, &codec_specific_info)); | |
39 EXPECT_EQ(picture_id, codec_specific_info.codecSpecific.VP9.picture_id); | |
40 EXPECT_EQ(tl0_pic_idx, codec_specific_info.codecSpecific.VP9.tl0_pic_idx); | |
41 EXPECT_EQ(temporal_idx, | |
42 codec_specific_info.codecSpecific.VP9.temporal_idx); | |
43 } | |
30 }; | 44 }; |
31 | 45 |
32 // Disabled on ios as flake, see https://crbug.com/webrtc/7057 | 46 // Disabled on ios as flake, see https://crbug.com/webrtc/7057 |
33 #if defined(WEBRTC_IOS) | 47 #if defined(WEBRTC_IOS) |
34 TEST_F(TestVp9Impl, DISABLED_EncodeDecode) { | 48 TEST_F(TestVp9Impl, DISABLED_EncodeDecode) { |
35 #else | 49 #else |
36 TEST_F(TestVp9Impl, EncodeDecode) { | 50 TEST_F(TestVp9Impl, EncodeDecode) { |
37 #endif | 51 #endif |
38 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 52 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
39 encoder_->Encode(*input_frame_, nullptr, nullptr)); | 53 encoder_->Encode(*input_frame_, nullptr, nullptr)); |
40 EncodedImage encoded_frame; | 54 EncodedImage encoded_frame; |
41 ASSERT_TRUE(WaitForEncodedFrame(&encoded_frame)); | 55 CodecSpecificInfo codec_specific_info; |
56 ASSERT_TRUE(WaitForEncodedFrame(&encoded_frame, &codec_specific_info)); | |
42 // First frame should be a key frame. | 57 // First frame should be a key frame. |
43 encoded_frame._frameType = kVideoFrameKey; | 58 encoded_frame._frameType = kVideoFrameKey; |
44 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 59 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
45 decoder_->Decode(encoded_frame, false, nullptr)); | 60 decoder_->Decode(encoded_frame, false, nullptr)); |
46 std::unique_ptr<VideoFrame> decoded_frame; | 61 std::unique_ptr<VideoFrame> decoded_frame; |
47 rtc::Optional<uint8_t> decoded_qp; | 62 rtc::Optional<uint8_t> decoded_qp; |
48 ASSERT_TRUE(WaitForDecodedFrame(&decoded_frame, &decoded_qp)); | 63 ASSERT_TRUE(WaitForDecodedFrame(&decoded_frame, &decoded_qp)); |
49 ASSERT_TRUE(decoded_frame); | 64 ASSERT_TRUE(decoded_frame); |
50 EXPECT_GT(I420PSNR(input_frame_.get(), decoded_frame.get()), 36); | 65 EXPECT_GT(I420PSNR(input_frame_.get(), decoded_frame.get()), 36); |
51 } | 66 } |
52 | 67 |
53 TEST_F(TestVp9Impl, DecodedQpEqualsEncodedQp) { | 68 TEST_F(TestVp9Impl, DecodedQpEqualsEncodedQp) { |
54 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 69 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
55 encoder_->Encode(*input_frame_, nullptr, nullptr)); | 70 encoder_->Encode(*input_frame_, nullptr, nullptr)); |
56 EncodedImage encoded_frame; | 71 EncodedImage encoded_frame; |
57 ASSERT_TRUE(WaitForEncodedFrame(&encoded_frame)); | 72 CodecSpecificInfo codec_specific_info; |
73 ASSERT_TRUE(WaitForEncodedFrame(&encoded_frame, &codec_specific_info)); | |
58 // First frame should be a key frame. | 74 // First frame should be a key frame. |
59 encoded_frame._frameType = kVideoFrameKey; | 75 encoded_frame._frameType = kVideoFrameKey; |
60 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | 76 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, |
61 decoder_->Decode(encoded_frame, false, nullptr)); | 77 decoder_->Decode(encoded_frame, false, nullptr)); |
62 std::unique_ptr<VideoFrame> decoded_frame; | 78 std::unique_ptr<VideoFrame> decoded_frame; |
63 rtc::Optional<uint8_t> decoded_qp; | 79 rtc::Optional<uint8_t> decoded_qp; |
64 ASSERT_TRUE(WaitForDecodedFrame(&decoded_frame, &decoded_qp)); | 80 ASSERT_TRUE(WaitForDecodedFrame(&decoded_frame, &decoded_qp)); |
65 ASSERT_TRUE(decoded_frame); | 81 ASSERT_TRUE(decoded_frame); |
66 ASSERT_TRUE(decoded_qp); | 82 ASSERT_TRUE(decoded_qp); |
67 EXPECT_EQ(encoded_frame.qp_, *decoded_qp); | 83 EXPECT_EQ(encoded_frame.qp_, *decoded_qp); |
68 } | 84 } |
69 | 85 |
86 TEST_F(TestVp9Impl, EncoderRetainsRtpStateAfterRelease) { | |
87 // Override default settings. | |
88 codec_inst_.VP9()->numberOfTemporalLayers = 2; | |
89 // Tl0PidIdx is only used in non-flexible mode. | |
90 codec_inst_.VP9()->flexibleMode = false; | |
91 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | |
92 encoder_->InitEncode(&codec_inst_, 1 /* number of cores */, | |
93 0 /* max payload size (unused) */)); | |
94 | |
95 // Temporal layer 0. | |
96 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | |
97 encoder_->Encode(*input_frame_, nullptr, nullptr)); | |
98 EncodedImage encoded_frame; | |
99 CodecSpecificInfo codec_specific_info; | |
100 ASSERT_TRUE(WaitForEncodedFrame(&encoded_frame, &codec_specific_info)); | |
101 int16_t picture_id = codec_specific_info.codecSpecific.VP9.picture_id; | |
102 int tl0_pic_idx = codec_specific_info.codecSpecific.VP9.tl0_pic_idx; | |
103 EXPECT_EQ(0, codec_specific_info.codecSpecific.VP9.temporal_idx); | |
104 | |
105 // Temporal layer 1. | |
106 input_frame_->set_timestamp(input_frame_->timestamp() + | |
107 kTimestampIncrementPerFrame); | |
108 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | |
109 encoder_->Encode(*input_frame_, nullptr, nullptr)); | |
110 ExpectFrame((picture_id + 1) % (1 << 15), tl0_pic_idx, 1); | |
111 | |
112 // Temporal layer 0. | |
113 input_frame_->set_timestamp(input_frame_->timestamp() + | |
114 kTimestampIncrementPerFrame); | |
115 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | |
116 encoder_->Encode(*input_frame_, nullptr, nullptr)); | |
117 ExpectFrame((picture_id + 2) % (1 << 15), (tl0_pic_idx + 1) % (1 << 8), 0); | |
118 | |
119 // Temporal layer 1. | |
120 input_frame_->set_timestamp(input_frame_->timestamp() + | |
121 kTimestampIncrementPerFrame); | |
122 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | |
123 encoder_->Encode(*input_frame_, nullptr, nullptr)); | |
124 ExpectFrame((picture_id + 3) % (1 << 15), (tl0_pic_idx + 1) % (1 << 8), 1); | |
125 | |
126 // Reinit. | |
127 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, encoder_->Release()); | |
128 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | |
129 encoder_->InitEncode(&codec_inst_, 1 /* number of cores */, | |
130 0 /* max payload size (unused) */)); | |
131 | |
132 // Temporal layer 0. | |
133 input_frame_->set_timestamp(input_frame_->timestamp() + | |
134 kTimestampIncrementPerFrame); | |
135 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | |
136 encoder_->Encode(*input_frame_, nullptr, nullptr)); | |
137 ExpectFrame((picture_id + 4) % (1 << 15), (tl0_pic_idx + 2) % (1 << 8), 0); | |
138 | |
139 // Temporal layer 1. | |
140 input_frame_->set_timestamp(input_frame_->timestamp() + | |
141 kTimestampIncrementPerFrame); | |
142 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | |
143 encoder_->Encode(*input_frame_, nullptr, nullptr)); | |
144 ExpectFrame((picture_id + 5) % (1 << 15), (tl0_pic_idx + 2) % (1 << 8), 1); | |
145 | |
146 // Temporal layer 0. | |
147 input_frame_->set_timestamp(input_frame_->timestamp() + | |
148 kTimestampIncrementPerFrame); | |
149 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | |
150 encoder_->Encode(*input_frame_, nullptr, nullptr)); | |
151 ExpectFrame((picture_id + 6) % (1 << 15), (tl0_pic_idx + 3) % (1 << 8), 0); | |
152 | |
153 // Temporal layer 1. | |
154 input_frame_->set_timestamp(input_frame_->timestamp() + | |
155 kTimestampIncrementPerFrame); | |
156 EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, | |
157 encoder_->Encode(*input_frame_, nullptr, nullptr)); | |
158 ExpectFrame((picture_id + 7) % (1 << 15), (tl0_pic_idx + 3) % (1 << 8), 1); | |
159 } | |
160 | |
70 } // namespace webrtc | 161 } // namespace webrtc |
OLD | NEW |