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