Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 11 | #include "call/rtp_payload_params.h" |
| 12 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include <string.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 14 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 15 | #include <map> |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 16 | #include <set> |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 17 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 18 | #include "absl/container/inlined_vector.h" |
| 19 | #include "absl/types/optional.h" |
| 20 | #include "absl/types/variant.h" |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 21 | #include "api/transport/field_trial_based_config.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 22 | #include "api/video/video_content_type.h" |
| 23 | #include "api/video/video_rotation.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 24 | #include "modules/video_coding/codecs/h264/include/h264_globals.h" |
| 25 | #include "modules/video_coding/codecs/interface/common_constants.h" |
| 26 | #include "modules/video_coding/codecs/vp8/include/vp8_globals.h" |
| 27 | #include "modules/video_coding/codecs/vp9/include/vp9_globals.h" |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 28 | #include "modules/video_coding/include/video_codec_interface.h" |
Danil Chapovalov | af36644 | 2021-04-22 15:20:28 +0200 | [diff] [blame^] | 29 | #include "test/explicit_key_value_config.h" |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 30 | #include "test/field_trial.h" |
philipel | 8aba8fe | 2019-06-13 15:13:16 +0200 | [diff] [blame] | 31 | #include "test/gmock.h" |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 32 | #include "test/gtest.h" |
| 33 | |
Danil Chapovalov | af36644 | 2021-04-22 15:20:28 +0200 | [diff] [blame^] | 34 | using ::testing::Each; |
Danil Chapovalov | dc7fe40 | 2019-12-13 12:23:58 +0100 | [diff] [blame] | 35 | using ::testing::ElementsAre; |
| 36 | using ::testing::IsEmpty; |
Danil Chapovalov | 4b860c1 | 2020-05-19 14:48:19 +0200 | [diff] [blame] | 37 | using ::testing::SizeIs; |
Danil Chapovalov | dc7fe40 | 2019-12-13 12:23:58 +0100 | [diff] [blame] | 38 | |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 39 | namespace webrtc { |
| 40 | namespace { |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 41 | const uint32_t kSsrc1 = 12345; |
| 42 | const uint32_t kSsrc2 = 23456; |
| 43 | const int16_t kPictureId = 123; |
| 44 | const int16_t kTl0PicIdx = 20; |
| 45 | const uint8_t kTemporalIdx = 1; |
| 46 | const int16_t kInitialPictureId1 = 222; |
| 47 | const int16_t kInitialTl0PicIdx1 = 99; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 48 | const int64_t kDontCare = 0; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 49 | } // namespace |
| 50 | |
| 51 | TEST(RtpPayloadParamsTest, InfoMappedToRtpVideoHeader_Vp8) { |
| 52 | RtpPayloadState state2; |
| 53 | state2.picture_id = kPictureId; |
| 54 | state2.tl0_pic_idx = kTl0PicIdx; |
| 55 | std::map<uint32_t, RtpPayloadState> states = {{kSsrc2, state2}}; |
| 56 | |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 57 | RtpPayloadParams params(kSsrc2, &state2, FieldTrialBasedConfig()); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 58 | EncodedImage encoded_image; |
| 59 | encoded_image.rotation_ = kVideoRotation_90; |
| 60 | encoded_image.content_type_ = VideoContentType::SCREENSHARE; |
Niels Möller | d3b8c63 | 2018-08-27 15:33:42 +0200 | [diff] [blame] | 61 | encoded_image.SetSpatialIndex(1); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 62 | |
| 63 | CodecSpecificInfo codec_info; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 64 | codec_info.codecType = kVideoCodecVP8; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 65 | codec_info.codecSpecific.VP8.temporalIdx = 0; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 66 | codec_info.codecSpecific.VP8.keyIdx = kNoKeyIdx; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 67 | codec_info.codecSpecific.VP8.layerSync = false; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 68 | codec_info.codecSpecific.VP8.nonReference = true; |
| 69 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 70 | RTPVideoHeader header = |
| 71 | params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
| 72 | |
| 73 | codec_info.codecType = kVideoCodecVP8; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 74 | codec_info.codecSpecific.VP8.temporalIdx = 1; |
| 75 | codec_info.codecSpecific.VP8.layerSync = true; |
| 76 | |
| 77 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, 1); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 78 | |
| 79 | EXPECT_EQ(kVideoRotation_90, header.rotation); |
| 80 | EXPECT_EQ(VideoContentType::SCREENSHARE, header.content_type); |
| 81 | EXPECT_EQ(1, header.simulcastIdx); |
| 82 | EXPECT_EQ(kVideoCodecVP8, header.codec); |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 83 | const auto& vp8_header = |
| 84 | absl::get<RTPVideoHeaderVP8>(header.video_type_header); |
| 85 | EXPECT_EQ(kPictureId + 2, vp8_header.pictureId); |
| 86 | EXPECT_EQ(kTemporalIdx, vp8_header.temporalIdx); |
| 87 | EXPECT_EQ(kTl0PicIdx + 1, vp8_header.tl0PicIdx); |
| 88 | EXPECT_EQ(kNoKeyIdx, vp8_header.keyIdx); |
| 89 | EXPECT_TRUE(vp8_header.layerSync); |
| 90 | EXPECT_TRUE(vp8_header.nonReference); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | TEST(RtpPayloadParamsTest, InfoMappedToRtpVideoHeader_Vp9) { |
| 94 | RtpPayloadState state; |
| 95 | state.picture_id = kPictureId; |
| 96 | state.tl0_pic_idx = kTl0PicIdx; |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 97 | RtpPayloadParams params(kSsrc1, &state, FieldTrialBasedConfig()); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 98 | |
| 99 | EncodedImage encoded_image; |
| 100 | encoded_image.rotation_ = kVideoRotation_90; |
| 101 | encoded_image.content_type_ = VideoContentType::SCREENSHARE; |
Niels Möller | d3b8c63 | 2018-08-27 15:33:42 +0200 | [diff] [blame] | 102 | encoded_image.SetSpatialIndex(0); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 103 | CodecSpecificInfo codec_info; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 104 | codec_info.codecType = kVideoCodecVP9; |
| 105 | codec_info.codecSpecific.VP9.num_spatial_layers = 3; |
| 106 | codec_info.codecSpecific.VP9.first_frame_in_picture = true; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 107 | codec_info.codecSpecific.VP9.temporal_idx = 2; |
Danil Chapovalov | 06bbeb3 | 2020-11-11 12:42:56 +0100 | [diff] [blame] | 108 | codec_info.end_of_picture = false; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 109 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 110 | RTPVideoHeader header = |
| 111 | params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 112 | |
| 113 | EXPECT_EQ(kVideoRotation_90, header.rotation); |
| 114 | EXPECT_EQ(VideoContentType::SCREENSHARE, header.content_type); |
| 115 | EXPECT_EQ(kVideoCodecVP9, header.codec); |
Johannes Kron | d0b69a8 | 2018-12-03 14:18:53 +0100 | [diff] [blame] | 116 | EXPECT_FALSE(header.color_space); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 117 | const auto& vp9_header = |
| 118 | absl::get<RTPVideoHeaderVP9>(header.video_type_header); |
| 119 | EXPECT_EQ(kPictureId + 1, vp9_header.picture_id); |
| 120 | EXPECT_EQ(kTl0PicIdx, vp9_header.tl0_pic_idx); |
| 121 | EXPECT_EQ(vp9_header.temporal_idx, codec_info.codecSpecific.VP9.temporal_idx); |
Niels Möller | d3b8c63 | 2018-08-27 15:33:42 +0200 | [diff] [blame] | 122 | EXPECT_EQ(vp9_header.spatial_idx, encoded_image.SpatialIndex()); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 123 | EXPECT_EQ(vp9_header.num_spatial_layers, |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 124 | codec_info.codecSpecific.VP9.num_spatial_layers); |
Danil Chapovalov | 06bbeb3 | 2020-11-11 12:42:56 +0100 | [diff] [blame] | 125 | EXPECT_EQ(vp9_header.end_of_picture, codec_info.end_of_picture); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 126 | |
| 127 | // Next spatial layer. |
| 128 | codec_info.codecSpecific.VP9.first_frame_in_picture = false; |
Danil Chapovalov | 06bbeb3 | 2020-11-11 12:42:56 +0100 | [diff] [blame] | 129 | codec_info.end_of_picture = true; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 130 | |
Niels Möller | d3b8c63 | 2018-08-27 15:33:42 +0200 | [diff] [blame] | 131 | encoded_image.SetSpatialIndex(1); |
Johannes Kron | d0b69a8 | 2018-12-03 14:18:53 +0100 | [diff] [blame] | 132 | ColorSpace color_space( |
| 133 | ColorSpace::PrimaryID::kSMPTE170M, ColorSpace::TransferID::kSMPTE170M, |
| 134 | ColorSpace::MatrixID::kSMPTE170M, ColorSpace::RangeID::kFull); |
Danil Chapovalov | b769894 | 2019-02-05 11:32:19 +0100 | [diff] [blame] | 135 | encoded_image.SetColorSpace(color_space); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 136 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 137 | |
| 138 | EXPECT_EQ(kVideoRotation_90, header.rotation); |
| 139 | EXPECT_EQ(VideoContentType::SCREENSHARE, header.content_type); |
| 140 | EXPECT_EQ(kVideoCodecVP9, header.codec); |
Johannes Kron | d0b69a8 | 2018-12-03 14:18:53 +0100 | [diff] [blame] | 141 | EXPECT_EQ(absl::make_optional(color_space), header.color_space); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 142 | EXPECT_EQ(kPictureId + 1, vp9_header.picture_id); |
| 143 | EXPECT_EQ(kTl0PicIdx, vp9_header.tl0_pic_idx); |
| 144 | EXPECT_EQ(vp9_header.temporal_idx, codec_info.codecSpecific.VP9.temporal_idx); |
Niels Möller | d3b8c63 | 2018-08-27 15:33:42 +0200 | [diff] [blame] | 145 | EXPECT_EQ(vp9_header.spatial_idx, encoded_image.SpatialIndex()); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 146 | EXPECT_EQ(vp9_header.num_spatial_layers, |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 147 | codec_info.codecSpecific.VP9.num_spatial_layers); |
Danil Chapovalov | 06bbeb3 | 2020-11-11 12:42:56 +0100 | [diff] [blame] | 148 | EXPECT_EQ(vp9_header.end_of_picture, codec_info.end_of_picture); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 149 | } |
| 150 | |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 151 | TEST(RtpPayloadParamsTest, PictureIdIsSetForVp8) { |
| 152 | RtpPayloadState state; |
| 153 | state.picture_id = kInitialPictureId1; |
| 154 | state.tl0_pic_idx = kInitialTl0PicIdx1; |
| 155 | |
| 156 | EncodedImage encoded_image; |
| 157 | CodecSpecificInfo codec_info; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 158 | codec_info.codecType = kVideoCodecVP8; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 159 | |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 160 | RtpPayloadParams params(kSsrc1, &state, FieldTrialBasedConfig()); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 161 | RTPVideoHeader header = |
| 162 | params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 163 | EXPECT_EQ(kVideoCodecVP8, header.codec); |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 164 | EXPECT_EQ(kInitialPictureId1 + 1, |
| 165 | absl::get<RTPVideoHeaderVP8>(header.video_type_header).pictureId); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 166 | |
| 167 | // State should hold latest used picture id and tl0_pic_idx. |
| 168 | state = params.state(); |
| 169 | EXPECT_EQ(kInitialPictureId1 + 1, state.picture_id); |
| 170 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, state.tl0_pic_idx); |
| 171 | } |
| 172 | |
| 173 | TEST(RtpPayloadParamsTest, PictureIdWraps) { |
| 174 | RtpPayloadState state; |
| 175 | state.picture_id = kMaxTwoBytePictureId; |
| 176 | state.tl0_pic_idx = kInitialTl0PicIdx1; |
| 177 | |
| 178 | EncodedImage encoded_image; |
| 179 | CodecSpecificInfo codec_info; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 180 | codec_info.codecType = kVideoCodecVP8; |
| 181 | codec_info.codecSpecific.VP8.temporalIdx = kNoTemporalIdx; |
| 182 | |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 183 | RtpPayloadParams params(kSsrc1, &state, FieldTrialBasedConfig()); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 184 | RTPVideoHeader header = |
| 185 | params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 186 | EXPECT_EQ(kVideoCodecVP8, header.codec); |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 187 | EXPECT_EQ(0, |
| 188 | absl::get<RTPVideoHeaderVP8>(header.video_type_header).pictureId); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 189 | |
| 190 | // State should hold latest used picture id and tl0_pic_idx. |
| 191 | EXPECT_EQ(0, params.state().picture_id); // Wrapped. |
| 192 | EXPECT_EQ(kInitialTl0PicIdx1, params.state().tl0_pic_idx); |
| 193 | } |
| 194 | |
| 195 | TEST(RtpPayloadParamsTest, Tl0PicIdxUpdatedForVp8) { |
| 196 | RtpPayloadState state; |
| 197 | state.picture_id = kInitialPictureId1; |
| 198 | state.tl0_pic_idx = kInitialTl0PicIdx1; |
| 199 | |
| 200 | EncodedImage encoded_image; |
| 201 | // Modules are sending for this test. |
| 202 | // OnEncodedImage, temporalIdx: 1. |
| 203 | CodecSpecificInfo codec_info; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 204 | codec_info.codecType = kVideoCodecVP8; |
| 205 | codec_info.codecSpecific.VP8.temporalIdx = 1; |
| 206 | |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 207 | RtpPayloadParams params(kSsrc1, &state, FieldTrialBasedConfig()); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 208 | RTPVideoHeader header = |
| 209 | params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 210 | |
| 211 | EXPECT_EQ(kVideoCodecVP8, header.codec); |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 212 | const auto& vp8_header = |
| 213 | absl::get<RTPVideoHeaderVP8>(header.video_type_header); |
| 214 | EXPECT_EQ(kInitialPictureId1 + 1, vp8_header.pictureId); |
| 215 | EXPECT_EQ(kInitialTl0PicIdx1, vp8_header.tl0PicIdx); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 216 | |
| 217 | // OnEncodedImage, temporalIdx: 0. |
| 218 | codec_info.codecSpecific.VP8.temporalIdx = 0; |
| 219 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 220 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 221 | EXPECT_EQ(kVideoCodecVP8, header.codec); |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 222 | EXPECT_EQ(kInitialPictureId1 + 2, vp8_header.pictureId); |
| 223 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, vp8_header.tl0PicIdx); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 224 | |
| 225 | // State should hold latest used picture id and tl0_pic_idx. |
| 226 | EXPECT_EQ(kInitialPictureId1 + 2, params.state().picture_id); |
| 227 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, params.state().tl0_pic_idx); |
| 228 | } |
| 229 | |
| 230 | TEST(RtpPayloadParamsTest, Tl0PicIdxUpdatedForVp9) { |
| 231 | RtpPayloadState state; |
| 232 | state.picture_id = kInitialPictureId1; |
| 233 | state.tl0_pic_idx = kInitialTl0PicIdx1; |
| 234 | |
| 235 | EncodedImage encoded_image; |
| 236 | // Modules are sending for this test. |
| 237 | // OnEncodedImage, temporalIdx: 1. |
| 238 | CodecSpecificInfo codec_info; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 239 | codec_info.codecType = kVideoCodecVP9; |
| 240 | codec_info.codecSpecific.VP9.temporal_idx = 1; |
| 241 | codec_info.codecSpecific.VP9.first_frame_in_picture = true; |
| 242 | |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 243 | RtpPayloadParams params(kSsrc1, &state, FieldTrialBasedConfig()); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 244 | RTPVideoHeader header = |
| 245 | params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 246 | |
| 247 | EXPECT_EQ(kVideoCodecVP9, header.codec); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 248 | const auto& vp9_header = |
| 249 | absl::get<RTPVideoHeaderVP9>(header.video_type_header); |
| 250 | EXPECT_EQ(kInitialPictureId1 + 1, vp9_header.picture_id); |
| 251 | EXPECT_EQ(kInitialTl0PicIdx1, vp9_header.tl0_pic_idx); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 252 | |
| 253 | // OnEncodedImage, temporalIdx: 0. |
| 254 | codec_info.codecSpecific.VP9.temporal_idx = 0; |
| 255 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 256 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 257 | |
| 258 | EXPECT_EQ(kVideoCodecVP9, header.codec); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 259 | EXPECT_EQ(kInitialPictureId1 + 2, vp9_header.picture_id); |
| 260 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, vp9_header.tl0_pic_idx); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 261 | |
| 262 | // OnEncodedImage, first_frame_in_picture = false |
| 263 | codec_info.codecSpecific.VP9.first_frame_in_picture = false; |
| 264 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 265 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 266 | |
| 267 | EXPECT_EQ(kVideoCodecVP9, header.codec); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 268 | EXPECT_EQ(kInitialPictureId1 + 2, vp9_header.picture_id); |
| 269 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, vp9_header.tl0_pic_idx); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 270 | |
| 271 | // State should hold latest used picture id and tl0_pic_idx. |
| 272 | EXPECT_EQ(kInitialPictureId1 + 2, params.state().picture_id); |
| 273 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, params.state().tl0_pic_idx); |
| 274 | } |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 275 | |
| 276 | TEST(RtpPayloadParamsTest, PictureIdForOldGenericFormat) { |
| 277 | test::ScopedFieldTrials generic_picture_id( |
| 278 | "WebRTC-GenericPictureId/Enabled/"); |
| 279 | RtpPayloadState state{}; |
| 280 | |
| 281 | EncodedImage encoded_image; |
philipel | d1d0359 | 2019-03-01 13:53:55 +0100 | [diff] [blame] | 282 | CodecSpecificInfo codec_info; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 283 | codec_info.codecType = kVideoCodecGeneric; |
Markus Handell | c1cbf6b | 2020-02-17 20:03:57 +0100 | [diff] [blame] | 284 | encoded_image._frameType = VideoFrameType::kVideoFrameKey; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 285 | |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 286 | RtpPayloadParams params(kSsrc1, &state, FieldTrialBasedConfig()); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 287 | RTPVideoHeader header = |
Markus Handell | c1cbf6b | 2020-02-17 20:03:57 +0100 | [diff] [blame] | 288 | params.GetRtpVideoHeader(encoded_image, &codec_info, 10); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 289 | |
| 290 | EXPECT_EQ(kVideoCodecGeneric, header.codec); |
Danil Chapovalov | b6bf0b2 | 2020-01-28 18:36:57 +0100 | [diff] [blame] | 291 | const auto* generic = |
| 292 | absl::get_if<RTPVideoHeaderLegacyGeneric>(&header.video_type_header); |
| 293 | ASSERT_TRUE(generic); |
| 294 | EXPECT_EQ(0, generic->picture_id); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 295 | |
Markus Handell | c1cbf6b | 2020-02-17 20:03:57 +0100 | [diff] [blame] | 296 | encoded_image._frameType = VideoFrameType::kVideoFrameDelta; |
| 297 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, 20); |
Danil Chapovalov | b6bf0b2 | 2020-01-28 18:36:57 +0100 | [diff] [blame] | 298 | generic = |
| 299 | absl::get_if<RTPVideoHeaderLegacyGeneric>(&header.video_type_header); |
| 300 | ASSERT_TRUE(generic); |
| 301 | EXPECT_EQ(1, generic->picture_id); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 302 | } |
| 303 | |
philipel | 8aba8fe | 2019-06-13 15:13:16 +0200 | [diff] [blame] | 304 | TEST(RtpPayloadParamsTest, GenericDescriptorForGenericCodec) { |
philipel | 8aba8fe | 2019-06-13 15:13:16 +0200 | [diff] [blame] | 305 | RtpPayloadState state{}; |
| 306 | |
| 307 | EncodedImage encoded_image; |
| 308 | encoded_image._frameType = VideoFrameType::kVideoFrameKey; |
| 309 | CodecSpecificInfo codec_info; |
| 310 | codec_info.codecType = kVideoCodecGeneric; |
| 311 | |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 312 | RtpPayloadParams params(kSsrc1, &state, FieldTrialBasedConfig()); |
philipel | 8aba8fe | 2019-06-13 15:13:16 +0200 | [diff] [blame] | 313 | RTPVideoHeader header = |
| 314 | params.GetRtpVideoHeader(encoded_image, &codec_info, 0); |
| 315 | |
| 316 | EXPECT_EQ(kVideoCodecGeneric, header.codec); |
| 317 | ASSERT_TRUE(header.generic); |
| 318 | EXPECT_EQ(0, header.generic->frame_id); |
| 319 | EXPECT_THAT(header.generic->dependencies, IsEmpty()); |
| 320 | |
| 321 | encoded_image._frameType = VideoFrameType::kVideoFrameDelta; |
| 322 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, 1); |
| 323 | ASSERT_TRUE(header.generic); |
| 324 | EXPECT_EQ(1, header.generic->frame_id); |
| 325 | EXPECT_THAT(header.generic->dependencies, ElementsAre(0)); |
| 326 | } |
| 327 | |
Danil Chapovalov | 02d71fb | 2020-02-10 16:22:57 +0100 | [diff] [blame] | 328 | TEST(RtpPayloadParamsTest, SetsGenericFromGenericFrameInfo) { |
Danil Chapovalov | 02d71fb | 2020-02-10 16:22:57 +0100 | [diff] [blame] | 329 | RtpPayloadState state; |
| 330 | EncodedImage encoded_image; |
| 331 | CodecSpecificInfo codec_info; |
| 332 | |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 333 | RtpPayloadParams params(kSsrc1, &state, FieldTrialBasedConfig()); |
Danil Chapovalov | 02d71fb | 2020-02-10 16:22:57 +0100 | [diff] [blame] | 334 | |
| 335 | encoded_image._frameType = VideoFrameType::kVideoFrameKey; |
| 336 | codec_info.generic_frame_info = |
| 337 | GenericFrameInfo::Builder().S(1).T(0).Dtis("S").Build(); |
| 338 | codec_info.generic_frame_info->encoder_buffers = { |
| 339 | {/*id=*/0, /*referenced=*/false, /*updated=*/true}}; |
Danil Chapovalov | 4b860c1 | 2020-05-19 14:48:19 +0200 | [diff] [blame] | 340 | codec_info.generic_frame_info->part_of_chain = {true, false}; |
Danil Chapovalov | 02d71fb | 2020-02-10 16:22:57 +0100 | [diff] [blame] | 341 | RTPVideoHeader key_header = |
| 342 | params.GetRtpVideoHeader(encoded_image, &codec_info, /*frame_id=*/1); |
| 343 | |
| 344 | ASSERT_TRUE(key_header.generic); |
| 345 | EXPECT_EQ(key_header.generic->spatial_index, 1); |
| 346 | EXPECT_EQ(key_header.generic->temporal_index, 0); |
| 347 | EXPECT_EQ(key_header.generic->frame_id, 1); |
| 348 | EXPECT_THAT(key_header.generic->dependencies, IsEmpty()); |
| 349 | EXPECT_THAT(key_header.generic->decode_target_indications, |
| 350 | ElementsAre(DecodeTargetIndication::kSwitch)); |
Danil Chapovalov | 4b860c1 | 2020-05-19 14:48:19 +0200 | [diff] [blame] | 351 | EXPECT_THAT(key_header.generic->chain_diffs, SizeIs(2)); |
Danil Chapovalov | 02d71fb | 2020-02-10 16:22:57 +0100 | [diff] [blame] | 352 | |
| 353 | encoded_image._frameType = VideoFrameType::kVideoFrameDelta; |
| 354 | codec_info.generic_frame_info = |
| 355 | GenericFrameInfo::Builder().S(2).T(3).Dtis("D").Build(); |
| 356 | codec_info.generic_frame_info->encoder_buffers = { |
| 357 | {/*id=*/0, /*referenced=*/true, /*updated=*/false}}; |
Danil Chapovalov | 4b860c1 | 2020-05-19 14:48:19 +0200 | [diff] [blame] | 358 | codec_info.generic_frame_info->part_of_chain = {false, false}; |
Danil Chapovalov | 02d71fb | 2020-02-10 16:22:57 +0100 | [diff] [blame] | 359 | RTPVideoHeader delta_header = |
| 360 | params.GetRtpVideoHeader(encoded_image, &codec_info, /*frame_id=*/3); |
| 361 | |
| 362 | ASSERT_TRUE(delta_header.generic); |
| 363 | EXPECT_EQ(delta_header.generic->spatial_index, 2); |
| 364 | EXPECT_EQ(delta_header.generic->temporal_index, 3); |
| 365 | EXPECT_EQ(delta_header.generic->frame_id, 3); |
| 366 | EXPECT_THAT(delta_header.generic->dependencies, ElementsAre(1)); |
| 367 | EXPECT_THAT(delta_header.generic->decode_target_indications, |
| 368 | ElementsAre(DecodeTargetIndication::kDiscardable)); |
Danil Chapovalov | 4b860c1 | 2020-05-19 14:48:19 +0200 | [diff] [blame] | 369 | EXPECT_THAT(delta_header.generic->chain_diffs, SizeIs(2)); |
Danil Chapovalov | 02d71fb | 2020-02-10 16:22:57 +0100 | [diff] [blame] | 370 | } |
| 371 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 372 | class RtpPayloadParamsVp8ToGenericTest : public ::testing::Test { |
| 373 | public: |
| 374 | enum LayerSync { kNoSync, kSync }; |
| 375 | |
philipel | 569397f | 2018-09-26 12:25:31 +0200 | [diff] [blame] | 376 | RtpPayloadParamsVp8ToGenericTest() |
Danil Chapovalov | 636865e | 2020-06-03 14:11:26 +0200 | [diff] [blame] | 377 | : state_(), params_(123, &state_, trials_config_) {} |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 378 | |
| 379 | void ConvertAndCheck(int temporal_index, |
| 380 | int64_t shared_frame_id, |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 381 | VideoFrameType frame_type, |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 382 | LayerSync layer_sync, |
philipel | fab9129 | 2018-10-17 14:36:08 +0200 | [diff] [blame] | 383 | const std::set<int64_t>& expected_deps, |
| 384 | uint16_t width = 0, |
| 385 | uint16_t height = 0) { |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 386 | EncodedImage encoded_image; |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 387 | encoded_image._frameType = frame_type; |
philipel | fab9129 | 2018-10-17 14:36:08 +0200 | [diff] [blame] | 388 | encoded_image._encodedWidth = width; |
| 389 | encoded_image._encodedHeight = height; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 390 | |
philipel | d1d0359 | 2019-03-01 13:53:55 +0100 | [diff] [blame] | 391 | CodecSpecificInfo codec_info; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 392 | codec_info.codecType = kVideoCodecVP8; |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 393 | codec_info.codecSpecific.VP8.temporalIdx = temporal_index; |
| 394 | codec_info.codecSpecific.VP8.layerSync = layer_sync == kSync; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 395 | |
| 396 | RTPVideoHeader header = |
| 397 | params_.GetRtpVideoHeader(encoded_image, &codec_info, shared_frame_id); |
| 398 | |
| 399 | ASSERT_TRUE(header.generic); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 400 | EXPECT_EQ(header.generic->spatial_index, 0); |
| 401 | |
| 402 | EXPECT_EQ(header.generic->frame_id, shared_frame_id); |
| 403 | EXPECT_EQ(header.generic->temporal_index, temporal_index); |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 404 | std::set<int64_t> actual_deps(header.generic->dependencies.begin(), |
| 405 | header.generic->dependencies.end()); |
| 406 | EXPECT_EQ(expected_deps, actual_deps); |
philipel | fab9129 | 2018-10-17 14:36:08 +0200 | [diff] [blame] | 407 | |
| 408 | EXPECT_EQ(header.width, width); |
| 409 | EXPECT_EQ(header.height, height); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | protected: |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 413 | FieldTrialBasedConfig trials_config_; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 414 | RtpPayloadState state_; |
| 415 | RtpPayloadParams params_; |
| 416 | }; |
| 417 | |
| 418 | TEST_F(RtpPayloadParamsVp8ToGenericTest, Keyframe) { |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 419 | ConvertAndCheck(0, 0, VideoFrameType::kVideoFrameKey, kNoSync, {}, 480, 360); |
| 420 | ConvertAndCheck(0, 1, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 421 | ConvertAndCheck(0, 2, VideoFrameType::kVideoFrameKey, kNoSync, {}, 480, 360); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | TEST_F(RtpPayloadParamsVp8ToGenericTest, TooHighTemporalIndex) { |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 425 | ConvertAndCheck(0, 0, VideoFrameType::kVideoFrameKey, kNoSync, {}, 480, 360); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 426 | |
| 427 | EncodedImage encoded_image; |
Niels Möller | 8f7ce22 | 2019-03-21 15:43:58 +0100 | [diff] [blame] | 428 | encoded_image._frameType = VideoFrameType::kVideoFrameDelta; |
philipel | d1d0359 | 2019-03-01 13:53:55 +0100 | [diff] [blame] | 429 | CodecSpecificInfo codec_info; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 430 | codec_info.codecType = kVideoCodecVP8; |
| 431 | codec_info.codecSpecific.VP8.temporalIdx = |
| 432 | RtpGenericFrameDescriptor::kMaxTemporalLayers; |
| 433 | codec_info.codecSpecific.VP8.layerSync = false; |
| 434 | |
| 435 | RTPVideoHeader header = |
| 436 | params_.GetRtpVideoHeader(encoded_image, &codec_info, 1); |
| 437 | EXPECT_FALSE(header.generic); |
| 438 | } |
| 439 | |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 440 | TEST_F(RtpPayloadParamsVp8ToGenericTest, LayerSync) { |
| 441 | // 02120212 pattern |
| 442 | ConvertAndCheck(0, 0, VideoFrameType::kVideoFrameKey, kNoSync, {}, 480, 360); |
| 443 | ConvertAndCheck(2, 1, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 444 | ConvertAndCheck(1, 2, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 445 | ConvertAndCheck(2, 3, VideoFrameType::kVideoFrameDelta, kNoSync, {0, 1, 2}); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 446 | |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 447 | ConvertAndCheck(0, 4, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 448 | ConvertAndCheck(2, 5, VideoFrameType::kVideoFrameDelta, kNoSync, {2, 3, 4}); |
| 449 | ConvertAndCheck(1, 6, VideoFrameType::kVideoFrameDelta, kSync, |
| 450 | {4}); // layer sync |
| 451 | ConvertAndCheck(2, 7, VideoFrameType::kVideoFrameDelta, kNoSync, {4, 5, 6}); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | TEST_F(RtpPayloadParamsVp8ToGenericTest, FrameIdGaps) { |
| 455 | // 0101 pattern |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 456 | ConvertAndCheck(0, 0, VideoFrameType::kVideoFrameKey, kNoSync, {}, 480, 360); |
| 457 | ConvertAndCheck(1, 1, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 458 | |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 459 | ConvertAndCheck(0, 5, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 460 | ConvertAndCheck(1, 10, VideoFrameType::kVideoFrameDelta, kNoSync, {1, 5}); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 461 | |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 462 | ConvertAndCheck(0, 15, VideoFrameType::kVideoFrameDelta, kNoSync, {5}); |
| 463 | ConvertAndCheck(1, 20, VideoFrameType::kVideoFrameDelta, kNoSync, {10, 15}); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 464 | } |
| 465 | |
Danil Chapovalov | af36644 | 2021-04-22 15:20:28 +0200 | [diff] [blame^] | 466 | class RtpPayloadParamsVp9ToGenericTest : public ::testing::Test { |
| 467 | protected: |
| 468 | RtpPayloadParamsVp9ToGenericTest() |
| 469 | : field_trials_("WebRTC-Vp9DependencyDescriptor/Enabled/") {} |
| 470 | |
| 471 | test::ExplicitKeyValueConfig field_trials_; |
| 472 | RtpPayloadState state_; |
| 473 | }; |
| 474 | |
| 475 | TEST_F(RtpPayloadParamsVp9ToGenericTest, NoScalability) { |
| 476 | RtpPayloadParams params(/*ssrc=*/123, &state_, field_trials_); |
| 477 | |
| 478 | EncodedImage encoded_image; |
| 479 | CodecSpecificInfo codec_info; |
| 480 | codec_info.codecType = kVideoCodecVP9; |
| 481 | codec_info.codecSpecific.VP9.num_spatial_layers = 1; |
| 482 | codec_info.codecSpecific.VP9.temporal_idx = kNoTemporalIdx; |
| 483 | codec_info.codecSpecific.VP9.first_frame_in_picture = true; |
| 484 | codec_info.end_of_picture = true; |
| 485 | |
| 486 | // Key frame. |
| 487 | encoded_image._frameType = VideoFrameType::kVideoFrameKey; |
| 488 | codec_info.codecSpecific.VP9.inter_pic_predicted = false; |
| 489 | codec_info.codecSpecific.VP9.num_ref_pics = 0; |
| 490 | RTPVideoHeader header = params.GetRtpVideoHeader(encoded_image, &codec_info, |
| 491 | /*shared_frame_id=*/1); |
| 492 | |
| 493 | ASSERT_TRUE(header.generic); |
| 494 | EXPECT_EQ(header.generic->spatial_index, 0); |
| 495 | EXPECT_EQ(header.generic->temporal_index, 0); |
| 496 | EXPECT_EQ(header.generic->frame_id, 1); |
| 497 | ASSERT_THAT(header.generic->decode_target_indications, Not(IsEmpty())); |
| 498 | EXPECT_EQ(header.generic->decode_target_indications[0], |
| 499 | DecodeTargetIndication::kSwitch); |
| 500 | EXPECT_THAT(header.generic->dependencies, IsEmpty()); |
| 501 | EXPECT_THAT(header.generic->chain_diffs, ElementsAre(0)); |
| 502 | |
| 503 | // Delta frame. |
| 504 | encoded_image._frameType = VideoFrameType::kVideoFrameDelta; |
| 505 | codec_info.codecSpecific.VP9.inter_pic_predicted = true; |
| 506 | codec_info.codecSpecific.VP9.num_ref_pics = 1; |
| 507 | codec_info.codecSpecific.VP9.p_diff[0] = 1; |
| 508 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, |
| 509 | /*shared_frame_id=*/3); |
| 510 | |
| 511 | ASSERT_TRUE(header.generic); |
| 512 | EXPECT_EQ(header.generic->spatial_index, 0); |
| 513 | EXPECT_EQ(header.generic->temporal_index, 0); |
| 514 | EXPECT_EQ(header.generic->frame_id, 3); |
| 515 | ASSERT_THAT(header.generic->decode_target_indications, Not(IsEmpty())); |
| 516 | EXPECT_EQ(header.generic->decode_target_indications[0], |
| 517 | DecodeTargetIndication::kSwitch); |
| 518 | EXPECT_THAT(header.generic->dependencies, ElementsAre(1)); |
| 519 | // previous frame in the chain was frame#1, |
| 520 | EXPECT_THAT(header.generic->chain_diffs, ElementsAre(3 - 1)); |
| 521 | } |
| 522 | |
| 523 | TEST_F(RtpPayloadParamsVp9ToGenericTest, TemporalScalabilityWith2Layers) { |
| 524 | // Test with 2 temporal layers structure that is not used by webrtc: |
| 525 | // 1---3 5 |
| 526 | // / / / ... |
| 527 | // 0---2---4--- |
| 528 | RtpPayloadParams params(/*ssrc=*/123, &state_, field_trials_); |
| 529 | |
| 530 | EncodedImage image; |
| 531 | CodecSpecificInfo info; |
| 532 | info.codecType = kVideoCodecVP9; |
| 533 | info.codecSpecific.VP9.num_spatial_layers = 1; |
| 534 | info.codecSpecific.VP9.first_frame_in_picture = true; |
| 535 | info.end_of_picture = true; |
| 536 | |
| 537 | RTPVideoHeader headers[6]; |
| 538 | // Key frame. |
| 539 | image._frameType = VideoFrameType::kVideoFrameKey; |
| 540 | info.codecSpecific.VP9.inter_pic_predicted = false; |
| 541 | info.codecSpecific.VP9.num_ref_pics = 0; |
| 542 | info.codecSpecific.VP9.temporal_up_switch = true; |
| 543 | info.codecSpecific.VP9.temporal_idx = 0; |
| 544 | headers[0] = params.GetRtpVideoHeader(image, &info, /*shared_frame_id=*/1); |
| 545 | |
| 546 | // Delta frames. |
| 547 | info.codecSpecific.VP9.inter_pic_predicted = true; |
| 548 | image._frameType = VideoFrameType::kVideoFrameDelta; |
| 549 | |
| 550 | info.codecSpecific.VP9.temporal_up_switch = true; |
| 551 | info.codecSpecific.VP9.temporal_idx = 1; |
| 552 | info.codecSpecific.VP9.num_ref_pics = 1; |
| 553 | info.codecSpecific.VP9.p_diff[0] = 1; |
| 554 | headers[1] = params.GetRtpVideoHeader(image, &info, /*shared_frame_id=*/3); |
| 555 | |
| 556 | info.codecSpecific.VP9.temporal_up_switch = false; |
| 557 | info.codecSpecific.VP9.temporal_idx = 0; |
| 558 | info.codecSpecific.VP9.num_ref_pics = 1; |
| 559 | info.codecSpecific.VP9.p_diff[0] = 2; |
| 560 | headers[2] = params.GetRtpVideoHeader(image, &info, /*shared_frame_id=*/5); |
| 561 | |
| 562 | info.codecSpecific.VP9.temporal_up_switch = false; |
| 563 | info.codecSpecific.VP9.temporal_idx = 1; |
| 564 | info.codecSpecific.VP9.num_ref_pics = 2; |
| 565 | info.codecSpecific.VP9.p_diff[0] = 1; |
| 566 | info.codecSpecific.VP9.p_diff[1] = 2; |
| 567 | headers[3] = params.GetRtpVideoHeader(image, &info, /*shared_frame_id=*/7); |
| 568 | |
| 569 | info.codecSpecific.VP9.temporal_up_switch = true; |
| 570 | info.codecSpecific.VP9.temporal_idx = 0; |
| 571 | info.codecSpecific.VP9.num_ref_pics = 1; |
| 572 | info.codecSpecific.VP9.p_diff[0] = 2; |
| 573 | headers[4] = params.GetRtpVideoHeader(image, &info, /*shared_frame_id=*/9); |
| 574 | |
| 575 | info.codecSpecific.VP9.temporal_up_switch = true; |
| 576 | info.codecSpecific.VP9.temporal_idx = 1; |
| 577 | info.codecSpecific.VP9.num_ref_pics = 1; |
| 578 | info.codecSpecific.VP9.p_diff[0] = 1; |
| 579 | headers[5] = params.GetRtpVideoHeader(image, &info, /*shared_frame_id=*/11); |
| 580 | |
| 581 | ASSERT_TRUE(headers[0].generic); |
| 582 | int num_decode_targets = headers[0].generic->decode_target_indications.size(); |
| 583 | ASSERT_GE(num_decode_targets, 2); |
| 584 | |
| 585 | for (int frame_idx = 0; frame_idx < 6; ++frame_idx) { |
| 586 | const RTPVideoHeader& header = headers[frame_idx]; |
| 587 | ASSERT_TRUE(header.generic); |
| 588 | EXPECT_EQ(header.generic->spatial_index, 0); |
| 589 | EXPECT_EQ(header.generic->temporal_index, frame_idx % 2); |
| 590 | EXPECT_EQ(header.generic->frame_id, 1 + 2 * frame_idx); |
| 591 | ASSERT_THAT(header.generic->decode_target_indications, |
| 592 | SizeIs(num_decode_targets)); |
| 593 | // Expect only T0 frames are needed for the 1st decode target. |
| 594 | if (header.generic->temporal_index == 0) { |
| 595 | EXPECT_NE(header.generic->decode_target_indications[0], |
| 596 | DecodeTargetIndication::kNotPresent); |
| 597 | } else { |
| 598 | EXPECT_EQ(header.generic->decode_target_indications[0], |
| 599 | DecodeTargetIndication::kNotPresent); |
| 600 | } |
| 601 | // Expect all frames are needed for the 2nd decode target. |
| 602 | EXPECT_NE(header.generic->decode_target_indications[1], |
| 603 | DecodeTargetIndication::kNotPresent); |
| 604 | } |
| 605 | |
| 606 | // Expect switch at every beginning of the pattern. |
| 607 | EXPECT_THAT(headers[0].generic->decode_target_indications, |
| 608 | Each(DecodeTargetIndication::kSwitch)); |
| 609 | EXPECT_THAT(headers[4].generic->decode_target_indications, |
| 610 | Each(DecodeTargetIndication::kSwitch)); |
| 611 | |
| 612 | EXPECT_THAT(headers[0].generic->dependencies, IsEmpty()); // T0, 1 |
| 613 | EXPECT_THAT(headers[1].generic->dependencies, ElementsAre(1)); // T1, 3 |
| 614 | EXPECT_THAT(headers[2].generic->dependencies, ElementsAre(1)); // T0, 5 |
| 615 | EXPECT_THAT(headers[3].generic->dependencies, ElementsAre(5, 3)); // T1, 7 |
| 616 | EXPECT_THAT(headers[4].generic->dependencies, ElementsAre(5)); // T0, 9 |
| 617 | EXPECT_THAT(headers[5].generic->dependencies, ElementsAre(9)); // T1, 11 |
| 618 | |
| 619 | EXPECT_THAT(headers[0].generic->chain_diffs, ElementsAre(0)); |
| 620 | EXPECT_THAT(headers[1].generic->chain_diffs, ElementsAre(2)); |
| 621 | EXPECT_THAT(headers[2].generic->chain_diffs, ElementsAre(4)); |
| 622 | EXPECT_THAT(headers[3].generic->chain_diffs, ElementsAre(2)); |
| 623 | EXPECT_THAT(headers[4].generic->chain_diffs, ElementsAre(4)); |
| 624 | EXPECT_THAT(headers[5].generic->chain_diffs, ElementsAre(2)); |
| 625 | } |
| 626 | |
| 627 | TEST_F(RtpPayloadParamsVp9ToGenericTest, TemporalScalabilityWith3Layers) { |
| 628 | // Test with 3 temporal layers structure that is not used by webrtc, but used |
| 629 | // by chromium: https://imgur.com/pURAGvp |
| 630 | RtpPayloadParams params(/*ssrc=*/123, &state_, field_trials_); |
| 631 | |
| 632 | EncodedImage image; |
| 633 | CodecSpecificInfo info; |
| 634 | info.codecType = kVideoCodecVP9; |
| 635 | info.codecSpecific.VP9.num_spatial_layers = 1; |
| 636 | info.codecSpecific.VP9.first_frame_in_picture = true; |
| 637 | info.end_of_picture = true; |
| 638 | |
| 639 | RTPVideoHeader headers[9]; |
| 640 | // Key frame. |
| 641 | image._frameType = VideoFrameType::kVideoFrameKey; |
| 642 | info.codecSpecific.VP9.inter_pic_predicted = false; |
| 643 | info.codecSpecific.VP9.num_ref_pics = 0; |
| 644 | info.codecSpecific.VP9.temporal_up_switch = true; |
| 645 | info.codecSpecific.VP9.temporal_idx = 0; |
| 646 | headers[0] = params.GetRtpVideoHeader(image, &info, /*shared_frame_id=*/1); |
| 647 | |
| 648 | // Delta frames. |
| 649 | info.codecSpecific.VP9.inter_pic_predicted = true; |
| 650 | image._frameType = VideoFrameType::kVideoFrameDelta; |
| 651 | |
| 652 | info.codecSpecific.VP9.temporal_up_switch = true; |
| 653 | info.codecSpecific.VP9.temporal_idx = 2; |
| 654 | info.codecSpecific.VP9.num_ref_pics = 1; |
| 655 | info.codecSpecific.VP9.p_diff[0] = 1; |
| 656 | headers[1] = params.GetRtpVideoHeader(image, &info, /*shared_frame_id=*/3); |
| 657 | |
| 658 | info.codecSpecific.VP9.temporal_up_switch = true; |
| 659 | info.codecSpecific.VP9.temporal_idx = 1; |
| 660 | info.codecSpecific.VP9.num_ref_pics = 1; |
| 661 | info.codecSpecific.VP9.p_diff[0] = 2; |
| 662 | headers[2] = params.GetRtpVideoHeader(image, &info, /*shared_frame_id=*/5); |
| 663 | |
| 664 | info.codecSpecific.VP9.temporal_up_switch = true; |
| 665 | info.codecSpecific.VP9.temporal_idx = 2; |
| 666 | info.codecSpecific.VP9.num_ref_pics = 1; |
| 667 | info.codecSpecific.VP9.p_diff[0] = 1; |
| 668 | headers[3] = params.GetRtpVideoHeader(image, &info, /*shared_frame_id=*/7); |
| 669 | |
| 670 | info.codecSpecific.VP9.temporal_up_switch = false; |
| 671 | info.codecSpecific.VP9.temporal_idx = 0; |
| 672 | info.codecSpecific.VP9.num_ref_pics = 1; |
| 673 | info.codecSpecific.VP9.p_diff[0] = 4; |
| 674 | headers[4] = params.GetRtpVideoHeader(image, &info, /*shared_frame_id=*/9); |
| 675 | |
| 676 | info.codecSpecific.VP9.temporal_up_switch = true; |
| 677 | info.codecSpecific.VP9.temporal_idx = 2; |
| 678 | info.codecSpecific.VP9.num_ref_pics = 2; |
| 679 | info.codecSpecific.VP9.p_diff[0] = 1; |
| 680 | info.codecSpecific.VP9.p_diff[1] = 3; |
| 681 | headers[5] = params.GetRtpVideoHeader(image, &info, /*shared_frame_id=*/11); |
| 682 | |
| 683 | info.codecSpecific.VP9.temporal_up_switch = false; |
| 684 | info.codecSpecific.VP9.temporal_idx = 1; |
| 685 | info.codecSpecific.VP9.num_ref_pics = 2; |
| 686 | info.codecSpecific.VP9.p_diff[0] = 2; |
| 687 | info.codecSpecific.VP9.p_diff[1] = 4; |
| 688 | headers[6] = params.GetRtpVideoHeader(image, &info, /*shared_frame_id=*/13); |
| 689 | |
| 690 | info.codecSpecific.VP9.temporal_up_switch = true; |
| 691 | info.codecSpecific.VP9.temporal_idx = 2; |
| 692 | info.codecSpecific.VP9.num_ref_pics = 1; |
| 693 | info.codecSpecific.VP9.p_diff[0] = 1; |
| 694 | headers[7] = params.GetRtpVideoHeader(image, &info, /*shared_frame_id=*/15); |
| 695 | |
| 696 | info.codecSpecific.VP9.temporal_up_switch = true; |
| 697 | info.codecSpecific.VP9.temporal_idx = 0; |
| 698 | info.codecSpecific.VP9.num_ref_pics = 1; |
| 699 | info.codecSpecific.VP9.p_diff[0] = 4; |
| 700 | headers[8] = params.GetRtpVideoHeader(image, &info, /*shared_frame_id=*/17); |
| 701 | |
| 702 | ASSERT_TRUE(headers[0].generic); |
| 703 | int num_decode_targets = headers[0].generic->decode_target_indications.size(); |
| 704 | ASSERT_GE(num_decode_targets, 3); |
| 705 | |
| 706 | for (int frame_idx = 0; frame_idx < 9; ++frame_idx) { |
| 707 | const RTPVideoHeader& header = headers[frame_idx]; |
| 708 | ASSERT_TRUE(header.generic); |
| 709 | EXPECT_EQ(header.generic->spatial_index, 0); |
| 710 | EXPECT_EQ(header.generic->frame_id, 1 + 2 * frame_idx); |
| 711 | ASSERT_THAT(header.generic->decode_target_indications, |
| 712 | SizeIs(num_decode_targets)); |
| 713 | // Expect only T0 frames are needed for the 1st decode target. |
| 714 | if (header.generic->temporal_index == 0) { |
| 715 | EXPECT_NE(header.generic->decode_target_indications[0], |
| 716 | DecodeTargetIndication::kNotPresent); |
| 717 | } else { |
| 718 | EXPECT_EQ(header.generic->decode_target_indications[0], |
| 719 | DecodeTargetIndication::kNotPresent); |
| 720 | } |
| 721 | // Expect only T0 and T1 frames are needed for the 2nd decode target. |
| 722 | if (header.generic->temporal_index <= 1) { |
| 723 | EXPECT_NE(header.generic->decode_target_indications[1], |
| 724 | DecodeTargetIndication::kNotPresent); |
| 725 | } else { |
| 726 | EXPECT_EQ(header.generic->decode_target_indications[1], |
| 727 | DecodeTargetIndication::kNotPresent); |
| 728 | } |
| 729 | // Expect all frames are needed for the 3rd decode target. |
| 730 | EXPECT_NE(header.generic->decode_target_indications[2], |
| 731 | DecodeTargetIndication::kNotPresent); |
| 732 | } |
| 733 | |
| 734 | EXPECT_EQ(headers[0].generic->temporal_index, 0); |
| 735 | EXPECT_EQ(headers[1].generic->temporal_index, 2); |
| 736 | EXPECT_EQ(headers[2].generic->temporal_index, 1); |
| 737 | EXPECT_EQ(headers[3].generic->temporal_index, 2); |
| 738 | EXPECT_EQ(headers[4].generic->temporal_index, 0); |
| 739 | EXPECT_EQ(headers[5].generic->temporal_index, 2); |
| 740 | EXPECT_EQ(headers[6].generic->temporal_index, 1); |
| 741 | EXPECT_EQ(headers[7].generic->temporal_index, 2); |
| 742 | EXPECT_EQ(headers[8].generic->temporal_index, 0); |
| 743 | |
| 744 | // Expect switch at every beginning of the pattern. |
| 745 | EXPECT_THAT(headers[0].generic->decode_target_indications, |
| 746 | Each(DecodeTargetIndication::kSwitch)); |
| 747 | EXPECT_THAT(headers[8].generic->decode_target_indications, |
| 748 | Each(DecodeTargetIndication::kSwitch)); |
| 749 | |
| 750 | EXPECT_THAT(headers[0].generic->dependencies, IsEmpty()); // T0, 1 |
| 751 | EXPECT_THAT(headers[1].generic->dependencies, ElementsAre(1)); // T2, 3 |
| 752 | EXPECT_THAT(headers[2].generic->dependencies, ElementsAre(1)); // T1, 5 |
| 753 | EXPECT_THAT(headers[3].generic->dependencies, ElementsAre(5)); // T2, 7 |
| 754 | EXPECT_THAT(headers[4].generic->dependencies, ElementsAre(1)); // T0, 9 |
| 755 | EXPECT_THAT(headers[5].generic->dependencies, ElementsAre(9, 5)); // T2, 11 |
| 756 | EXPECT_THAT(headers[6].generic->dependencies, ElementsAre(9, 5)); // T1, 13 |
| 757 | EXPECT_THAT(headers[7].generic->dependencies, ElementsAre(13)); // T2, 15 |
| 758 | EXPECT_THAT(headers[8].generic->dependencies, ElementsAre(9)); // T0, 17 |
| 759 | |
| 760 | EXPECT_THAT(headers[0].generic->chain_diffs, ElementsAre(0)); |
| 761 | EXPECT_THAT(headers[1].generic->chain_diffs, ElementsAre(2)); |
| 762 | EXPECT_THAT(headers[2].generic->chain_diffs, ElementsAre(4)); |
| 763 | EXPECT_THAT(headers[3].generic->chain_diffs, ElementsAre(6)); |
| 764 | EXPECT_THAT(headers[4].generic->chain_diffs, ElementsAre(8)); |
| 765 | EXPECT_THAT(headers[5].generic->chain_diffs, ElementsAre(2)); |
| 766 | EXPECT_THAT(headers[6].generic->chain_diffs, ElementsAre(4)); |
| 767 | EXPECT_THAT(headers[7].generic->chain_diffs, ElementsAre(6)); |
| 768 | EXPECT_THAT(headers[8].generic->chain_diffs, ElementsAre(8)); |
| 769 | } |
| 770 | |
| 771 | TEST_F(RtpPayloadParamsVp9ToGenericTest, SpatialScalabilityKSvc) { |
| 772 | // 1---3-- |
| 773 | // | ... |
| 774 | // 0---2-- |
| 775 | RtpPayloadParams params(/*ssrc=*/123, &state_, field_trials_); |
| 776 | |
| 777 | EncodedImage image; |
| 778 | CodecSpecificInfo info; |
| 779 | info.codecType = kVideoCodecVP9; |
| 780 | info.codecSpecific.VP9.num_spatial_layers = 2; |
| 781 | info.codecSpecific.VP9.first_frame_in_picture = true; |
| 782 | |
| 783 | RTPVideoHeader headers[4]; |
| 784 | // Key frame. |
| 785 | image._frameType = VideoFrameType::kVideoFrameKey; |
| 786 | image.SetSpatialIndex(0); |
| 787 | info.codecSpecific.VP9.inter_pic_predicted = false; |
| 788 | info.codecSpecific.VP9.inter_layer_predicted = false; |
| 789 | info.codecSpecific.VP9.non_ref_for_inter_layer_pred = false; |
| 790 | info.codecSpecific.VP9.num_ref_pics = 0; |
| 791 | info.codecSpecific.VP9.first_frame_in_picture = true; |
| 792 | info.end_of_picture = false; |
| 793 | headers[0] = params.GetRtpVideoHeader(image, &info, /*shared_frame_id=*/1); |
| 794 | |
| 795 | image.SetSpatialIndex(1); |
| 796 | info.codecSpecific.VP9.inter_layer_predicted = true; |
| 797 | info.codecSpecific.VP9.non_ref_for_inter_layer_pred = true; |
| 798 | info.codecSpecific.VP9.first_frame_in_picture = false; |
| 799 | info.end_of_picture = true; |
| 800 | headers[1] = params.GetRtpVideoHeader(image, &info, /*shared_frame_id=*/3); |
| 801 | |
| 802 | // Delta frames. |
| 803 | info.codecSpecific.VP9.inter_pic_predicted = true; |
| 804 | image._frameType = VideoFrameType::kVideoFrameDelta; |
| 805 | info.codecSpecific.VP9.num_ref_pics = 1; |
| 806 | info.codecSpecific.VP9.p_diff[0] = 1; |
| 807 | |
| 808 | image.SetSpatialIndex(0); |
| 809 | info.codecSpecific.VP9.inter_layer_predicted = false; |
| 810 | info.codecSpecific.VP9.non_ref_for_inter_layer_pred = true; |
| 811 | info.codecSpecific.VP9.first_frame_in_picture = true; |
| 812 | info.end_of_picture = false; |
| 813 | headers[2] = params.GetRtpVideoHeader(image, &info, /*shared_frame_id=*/5); |
| 814 | |
| 815 | image.SetSpatialIndex(1); |
| 816 | info.codecSpecific.VP9.inter_layer_predicted = false; |
| 817 | info.codecSpecific.VP9.non_ref_for_inter_layer_pred = true; |
| 818 | info.codecSpecific.VP9.first_frame_in_picture = false; |
| 819 | info.end_of_picture = true; |
| 820 | headers[3] = params.GetRtpVideoHeader(image, &info, /*shared_frame_id=*/7); |
| 821 | |
| 822 | ASSERT_TRUE(headers[0].generic); |
| 823 | int num_decode_targets = headers[0].generic->decode_target_indications.size(); |
| 824 | // Rely on implementation detail there are always kMaxTemporalStreams temporal |
| 825 | // layers assumed, in particular assume Decode Target#0 matches layer S0T0, |
| 826 | // and Decode Target#kMaxTemporalStreams matches layer S1T0. |
| 827 | ASSERT_EQ(num_decode_targets, kMaxTemporalStreams * 2); |
| 828 | |
| 829 | for (int frame_idx = 0; frame_idx < 4; ++frame_idx) { |
| 830 | const RTPVideoHeader& header = headers[frame_idx]; |
| 831 | ASSERT_TRUE(header.generic); |
| 832 | EXPECT_EQ(header.generic->spatial_index, frame_idx % 2); |
| 833 | EXPECT_EQ(header.generic->temporal_index, 0); |
| 834 | EXPECT_EQ(header.generic->frame_id, 1 + 2 * frame_idx); |
| 835 | ASSERT_THAT(header.generic->decode_target_indications, |
| 836 | SizeIs(num_decode_targets)); |
| 837 | } |
| 838 | |
| 839 | // Expect S0 key frame is switch for both Decode Targets. |
| 840 | EXPECT_EQ(headers[0].generic->decode_target_indications[0], |
| 841 | DecodeTargetIndication::kSwitch); |
| 842 | EXPECT_EQ(headers[0].generic->decode_target_indications[kMaxTemporalStreams], |
| 843 | DecodeTargetIndication::kSwitch); |
| 844 | // S1 key frame is only needed for the 2nd Decode Targets. |
| 845 | EXPECT_EQ(headers[1].generic->decode_target_indications[0], |
| 846 | DecodeTargetIndication::kNotPresent); |
| 847 | EXPECT_NE(headers[1].generic->decode_target_indications[kMaxTemporalStreams], |
| 848 | DecodeTargetIndication::kNotPresent); |
| 849 | // Delta frames are only needed for their own Decode Targets. |
| 850 | EXPECT_NE(headers[2].generic->decode_target_indications[0], |
| 851 | DecodeTargetIndication::kNotPresent); |
| 852 | EXPECT_EQ(headers[2].generic->decode_target_indications[kMaxTemporalStreams], |
| 853 | DecodeTargetIndication::kNotPresent); |
| 854 | EXPECT_EQ(headers[3].generic->decode_target_indications[0], |
| 855 | DecodeTargetIndication::kNotPresent); |
| 856 | EXPECT_NE(headers[3].generic->decode_target_indications[kMaxTemporalStreams], |
| 857 | DecodeTargetIndication::kNotPresent); |
| 858 | |
| 859 | EXPECT_THAT(headers[0].generic->dependencies, IsEmpty()); // S0, 1 |
| 860 | EXPECT_THAT(headers[1].generic->dependencies, ElementsAre(1)); // S1, 3 |
| 861 | EXPECT_THAT(headers[2].generic->dependencies, ElementsAre(1)); // S0, 5 |
| 862 | EXPECT_THAT(headers[3].generic->dependencies, ElementsAre(3)); // S1, 7 |
| 863 | |
| 864 | EXPECT_THAT(headers[0].generic->chain_diffs, ElementsAre(0, 0)); |
| 865 | EXPECT_THAT(headers[1].generic->chain_diffs, ElementsAre(2, 2)); |
| 866 | EXPECT_THAT(headers[2].generic->chain_diffs, ElementsAre(4, 2)); |
| 867 | EXPECT_THAT(headers[3].generic->chain_diffs, ElementsAre(2, 4)); |
| 868 | } |
| 869 | |
philipel | 8aba8fe | 2019-06-13 15:13:16 +0200 | [diff] [blame] | 870 | class RtpPayloadParamsH264ToGenericTest : public ::testing::Test { |
| 871 | public: |
| 872 | enum LayerSync { kNoSync, kSync }; |
| 873 | |
| 874 | RtpPayloadParamsH264ToGenericTest() |
Danil Chapovalov | 636865e | 2020-06-03 14:11:26 +0200 | [diff] [blame] | 875 | : state_(), params_(123, &state_, trials_config_) {} |
philipel | 8aba8fe | 2019-06-13 15:13:16 +0200 | [diff] [blame] | 876 | |
| 877 | void ConvertAndCheck(int temporal_index, |
| 878 | int64_t shared_frame_id, |
| 879 | VideoFrameType frame_type, |
| 880 | LayerSync layer_sync, |
| 881 | const std::set<int64_t>& expected_deps, |
| 882 | uint16_t width = 0, |
| 883 | uint16_t height = 0) { |
| 884 | EncodedImage encoded_image; |
| 885 | encoded_image._frameType = frame_type; |
| 886 | encoded_image._encodedWidth = width; |
| 887 | encoded_image._encodedHeight = height; |
| 888 | |
| 889 | CodecSpecificInfo codec_info; |
| 890 | codec_info.codecType = kVideoCodecH264; |
| 891 | codec_info.codecSpecific.H264.temporal_idx = temporal_index; |
| 892 | codec_info.codecSpecific.H264.base_layer_sync = layer_sync == kSync; |
| 893 | |
| 894 | RTPVideoHeader header = |
| 895 | params_.GetRtpVideoHeader(encoded_image, &codec_info, shared_frame_id); |
| 896 | |
| 897 | ASSERT_TRUE(header.generic); |
philipel | 8aba8fe | 2019-06-13 15:13:16 +0200 | [diff] [blame] | 898 | EXPECT_EQ(header.generic->spatial_index, 0); |
| 899 | |
| 900 | EXPECT_EQ(header.generic->frame_id, shared_frame_id); |
| 901 | EXPECT_EQ(header.generic->temporal_index, temporal_index); |
| 902 | std::set<int64_t> actual_deps(header.generic->dependencies.begin(), |
| 903 | header.generic->dependencies.end()); |
| 904 | EXPECT_EQ(expected_deps, actual_deps); |
| 905 | |
| 906 | EXPECT_EQ(header.width, width); |
| 907 | EXPECT_EQ(header.height, height); |
| 908 | } |
| 909 | |
| 910 | protected: |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 911 | FieldTrialBasedConfig trials_config_; |
philipel | 8aba8fe | 2019-06-13 15:13:16 +0200 | [diff] [blame] | 912 | RtpPayloadState state_; |
| 913 | RtpPayloadParams params_; |
| 914 | }; |
| 915 | |
| 916 | TEST_F(RtpPayloadParamsH264ToGenericTest, Keyframe) { |
| 917 | ConvertAndCheck(0, 0, VideoFrameType::kVideoFrameKey, kNoSync, {}, 480, 360); |
| 918 | ConvertAndCheck(0, 1, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 919 | ConvertAndCheck(0, 2, VideoFrameType::kVideoFrameKey, kNoSync, {}, 480, 360); |
| 920 | } |
| 921 | |
| 922 | TEST_F(RtpPayloadParamsH264ToGenericTest, TooHighTemporalIndex) { |
| 923 | ConvertAndCheck(0, 0, VideoFrameType::kVideoFrameKey, kNoSync, {}, 480, 360); |
| 924 | |
| 925 | EncodedImage encoded_image; |
| 926 | encoded_image._frameType = VideoFrameType::kVideoFrameDelta; |
| 927 | CodecSpecificInfo codec_info; |
| 928 | codec_info.codecType = kVideoCodecH264; |
| 929 | codec_info.codecSpecific.H264.temporal_idx = |
| 930 | RtpGenericFrameDescriptor::kMaxTemporalLayers; |
| 931 | codec_info.codecSpecific.H264.base_layer_sync = false; |
| 932 | |
| 933 | RTPVideoHeader header = |
| 934 | params_.GetRtpVideoHeader(encoded_image, &codec_info, 1); |
| 935 | EXPECT_FALSE(header.generic); |
| 936 | } |
| 937 | |
| 938 | TEST_F(RtpPayloadParamsH264ToGenericTest, LayerSync) { |
| 939 | // 02120212 pattern |
| 940 | ConvertAndCheck(0, 0, VideoFrameType::kVideoFrameKey, kNoSync, {}, 480, 360); |
| 941 | ConvertAndCheck(2, 1, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 942 | ConvertAndCheck(1, 2, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 943 | ConvertAndCheck(2, 3, VideoFrameType::kVideoFrameDelta, kNoSync, {0, 1, 2}); |
| 944 | |
| 945 | ConvertAndCheck(0, 4, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 946 | ConvertAndCheck(2, 5, VideoFrameType::kVideoFrameDelta, kNoSync, {2, 3, 4}); |
| 947 | ConvertAndCheck(1, 6, VideoFrameType::kVideoFrameDelta, kSync, |
| 948 | {4}); // layer sync |
| 949 | ConvertAndCheck(2, 7, VideoFrameType::kVideoFrameDelta, kNoSync, {4, 5, 6}); |
| 950 | } |
| 951 | |
| 952 | TEST_F(RtpPayloadParamsH264ToGenericTest, FrameIdGaps) { |
| 953 | // 0101 pattern |
| 954 | ConvertAndCheck(0, 0, VideoFrameType::kVideoFrameKey, kNoSync, {}, 480, 360); |
| 955 | ConvertAndCheck(1, 1, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 956 | |
| 957 | ConvertAndCheck(0, 5, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 958 | ConvertAndCheck(1, 10, VideoFrameType::kVideoFrameDelta, kNoSync, {1, 5}); |
| 959 | |
| 960 | ConvertAndCheck(0, 15, VideoFrameType::kVideoFrameDelta, kNoSync, {5}); |
| 961 | ConvertAndCheck(1, 20, VideoFrameType::kVideoFrameDelta, kNoSync, {10, 15}); |
| 962 | } |
| 963 | |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 964 | } // namespace webrtc |