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