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" |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 29 | #include "test/field_trial.h" |
philipel | 8aba8fe | 2019-06-13 15:13:16 +0200 | [diff] [blame] | 30 | #include "test/gmock.h" |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 31 | #include "test/gtest.h" |
| 32 | |
Danil Chapovalov | dc7fe40 | 2019-12-13 12:23:58 +0100 | [diff] [blame] | 33 | using ::testing::ElementsAre; |
| 34 | using ::testing::IsEmpty; |
Danil Chapovalov | dc7fe40 | 2019-12-13 12:23:58 +0100 | [diff] [blame] | 35 | |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 36 | namespace webrtc { |
| 37 | namespace { |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 38 | const uint32_t kSsrc1 = 12345; |
| 39 | const uint32_t kSsrc2 = 23456; |
| 40 | const int16_t kPictureId = 123; |
| 41 | const int16_t kTl0PicIdx = 20; |
| 42 | const uint8_t kTemporalIdx = 1; |
| 43 | const int16_t kInitialPictureId1 = 222; |
| 44 | const int16_t kInitialTl0PicIdx1 = 99; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 45 | const int64_t kDontCare = 0; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 46 | } // namespace |
| 47 | |
| 48 | TEST(RtpPayloadParamsTest, InfoMappedToRtpVideoHeader_Vp8) { |
| 49 | RtpPayloadState state2; |
| 50 | state2.picture_id = kPictureId; |
| 51 | state2.tl0_pic_idx = kTl0PicIdx; |
| 52 | std::map<uint32_t, RtpPayloadState> states = {{kSsrc2, state2}}; |
| 53 | |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 54 | RtpPayloadParams params(kSsrc2, &state2, FieldTrialBasedConfig()); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 55 | EncodedImage encoded_image; |
| 56 | encoded_image.rotation_ = kVideoRotation_90; |
| 57 | encoded_image.content_type_ = VideoContentType::SCREENSHARE; |
Niels Möller | d3b8c63 | 2018-08-27 15:33:42 +0200 | [diff] [blame] | 58 | encoded_image.SetSpatialIndex(1); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 59 | |
| 60 | CodecSpecificInfo codec_info; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 61 | codec_info.codecType = kVideoCodecVP8; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 62 | codec_info.codecSpecific.VP8.temporalIdx = 0; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 63 | codec_info.codecSpecific.VP8.keyIdx = kNoKeyIdx; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 64 | codec_info.codecSpecific.VP8.layerSync = false; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 65 | codec_info.codecSpecific.VP8.nonReference = true; |
| 66 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 67 | RTPVideoHeader header = |
| 68 | params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
| 69 | |
| 70 | codec_info.codecType = kVideoCodecVP8; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 71 | codec_info.codecSpecific.VP8.temporalIdx = 1; |
| 72 | codec_info.codecSpecific.VP8.layerSync = true; |
| 73 | |
| 74 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, 1); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 75 | |
| 76 | EXPECT_EQ(kVideoRotation_90, header.rotation); |
| 77 | EXPECT_EQ(VideoContentType::SCREENSHARE, header.content_type); |
| 78 | EXPECT_EQ(1, header.simulcastIdx); |
| 79 | EXPECT_EQ(kVideoCodecVP8, header.codec); |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 80 | const auto& vp8_header = |
| 81 | absl::get<RTPVideoHeaderVP8>(header.video_type_header); |
| 82 | EXPECT_EQ(kPictureId + 2, vp8_header.pictureId); |
| 83 | EXPECT_EQ(kTemporalIdx, vp8_header.temporalIdx); |
| 84 | EXPECT_EQ(kTl0PicIdx + 1, vp8_header.tl0PicIdx); |
| 85 | EXPECT_EQ(kNoKeyIdx, vp8_header.keyIdx); |
| 86 | EXPECT_TRUE(vp8_header.layerSync); |
| 87 | EXPECT_TRUE(vp8_header.nonReference); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | TEST(RtpPayloadParamsTest, InfoMappedToRtpVideoHeader_Vp9) { |
| 91 | RtpPayloadState state; |
| 92 | state.picture_id = kPictureId; |
| 93 | state.tl0_pic_idx = kTl0PicIdx; |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 94 | RtpPayloadParams params(kSsrc1, &state, FieldTrialBasedConfig()); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 95 | |
| 96 | EncodedImage encoded_image; |
| 97 | encoded_image.rotation_ = kVideoRotation_90; |
| 98 | encoded_image.content_type_ = VideoContentType::SCREENSHARE; |
Niels Möller | d3b8c63 | 2018-08-27 15:33:42 +0200 | [diff] [blame] | 99 | encoded_image.SetSpatialIndex(0); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 100 | CodecSpecificInfo codec_info; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 101 | codec_info.codecType = kVideoCodecVP9; |
| 102 | codec_info.codecSpecific.VP9.num_spatial_layers = 3; |
| 103 | codec_info.codecSpecific.VP9.first_frame_in_picture = true; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 104 | codec_info.codecSpecific.VP9.temporal_idx = 2; |
| 105 | codec_info.codecSpecific.VP9.end_of_picture = false; |
| 106 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 107 | RTPVideoHeader header = |
| 108 | params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 109 | |
| 110 | EXPECT_EQ(kVideoRotation_90, header.rotation); |
| 111 | EXPECT_EQ(VideoContentType::SCREENSHARE, header.content_type); |
| 112 | EXPECT_EQ(kVideoCodecVP9, header.codec); |
Johannes Kron | d0b69a8 | 2018-12-03 14:18:53 +0100 | [diff] [blame] | 113 | EXPECT_FALSE(header.color_space); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 114 | const auto& vp9_header = |
| 115 | absl::get<RTPVideoHeaderVP9>(header.video_type_header); |
| 116 | EXPECT_EQ(kPictureId + 1, vp9_header.picture_id); |
| 117 | EXPECT_EQ(kTl0PicIdx, vp9_header.tl0_pic_idx); |
| 118 | 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] | 119 | EXPECT_EQ(vp9_header.spatial_idx, encoded_image.SpatialIndex()); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 120 | EXPECT_EQ(vp9_header.num_spatial_layers, |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 121 | codec_info.codecSpecific.VP9.num_spatial_layers); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 122 | EXPECT_EQ(vp9_header.end_of_picture, |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 123 | codec_info.codecSpecific.VP9.end_of_picture); |
| 124 | |
| 125 | // Next spatial layer. |
| 126 | codec_info.codecSpecific.VP9.first_frame_in_picture = false; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 127 | codec_info.codecSpecific.VP9.end_of_picture = true; |
| 128 | |
Niels Möller | d3b8c63 | 2018-08-27 15:33:42 +0200 | [diff] [blame] | 129 | encoded_image.SetSpatialIndex(1); |
Johannes Kron | d0b69a8 | 2018-12-03 14:18:53 +0100 | [diff] [blame] | 130 | ColorSpace color_space( |
| 131 | ColorSpace::PrimaryID::kSMPTE170M, ColorSpace::TransferID::kSMPTE170M, |
| 132 | ColorSpace::MatrixID::kSMPTE170M, ColorSpace::RangeID::kFull); |
Danil Chapovalov | b769894 | 2019-02-05 11:32:19 +0100 | [diff] [blame] | 133 | encoded_image.SetColorSpace(color_space); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 134 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 135 | |
| 136 | EXPECT_EQ(kVideoRotation_90, header.rotation); |
| 137 | EXPECT_EQ(VideoContentType::SCREENSHARE, header.content_type); |
| 138 | EXPECT_EQ(kVideoCodecVP9, header.codec); |
Johannes Kron | d0b69a8 | 2018-12-03 14:18:53 +0100 | [diff] [blame] | 139 | EXPECT_EQ(absl::make_optional(color_space), header.color_space); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 140 | EXPECT_EQ(kPictureId + 1, vp9_header.picture_id); |
| 141 | EXPECT_EQ(kTl0PicIdx, vp9_header.tl0_pic_idx); |
| 142 | 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] | 143 | EXPECT_EQ(vp9_header.spatial_idx, encoded_image.SpatialIndex()); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 144 | EXPECT_EQ(vp9_header.num_spatial_layers, |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 145 | codec_info.codecSpecific.VP9.num_spatial_layers); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 146 | EXPECT_EQ(vp9_header.end_of_picture, |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 147 | codec_info.codecSpecific.VP9.end_of_picture); |
| 148 | } |
| 149 | |
| 150 | TEST(RtpPayloadParamsTest, InfoMappedToRtpVideoHeader_H264) { |
Johnny Lee | 1a1c52b | 2019-02-08 14:25:40 -0500 | [diff] [blame] | 151 | RtpPayloadState state; |
| 152 | state.picture_id = kPictureId; |
| 153 | state.tl0_pic_idx = kInitialTl0PicIdx1; |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 154 | RtpPayloadParams params(kSsrc1, &state, FieldTrialBasedConfig()); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 155 | |
| 156 | EncodedImage encoded_image; |
| 157 | CodecSpecificInfo codec_info; |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 158 | CodecSpecificInfoH264* h264info = &codec_info.codecSpecific.H264; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 159 | codec_info.codecType = kVideoCodecH264; |
Johnny Lee | 1a1c52b | 2019-02-08 14:25:40 -0500 | [diff] [blame] | 160 | h264info->packetization_mode = H264PacketizationMode::SingleNalUnit; |
| 161 | h264info->temporal_idx = kNoTemporalIdx; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 162 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 163 | RTPVideoHeader header = |
Markus Handell | c1cbf6b | 2020-02-17 20:03:57 +0100 | [diff] [blame] | 164 | params.GetRtpVideoHeader(encoded_image, &codec_info, 10); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 165 | |
| 166 | EXPECT_EQ(0, header.simulcastIdx); |
| 167 | EXPECT_EQ(kVideoCodecH264, header.codec); |
| 168 | const auto& h264 = absl::get<RTPVideoHeaderH264>(header.video_type_header); |
| 169 | EXPECT_EQ(H264PacketizationMode::SingleNalUnit, h264.packetization_mode); |
Johnny Lee | 1a1c52b | 2019-02-08 14:25:40 -0500 | [diff] [blame] | 170 | |
| 171 | // test temporal param 1 |
| 172 | h264info->temporal_idx = 1; |
| 173 | h264info->base_layer_sync = true; |
| 174 | h264info->idr_frame = false; |
| 175 | |
Markus Handell | c1cbf6b | 2020-02-17 20:03:57 +0100 | [diff] [blame] | 176 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, 20); |
Johnny Lee | 1a1c52b | 2019-02-08 14:25:40 -0500 | [diff] [blame] | 177 | |
| 178 | EXPECT_EQ(kVideoCodecH264, header.codec); |
| 179 | EXPECT_EQ(header.frame_marking.tl0_pic_idx, kInitialTl0PicIdx1); |
| 180 | EXPECT_EQ(header.frame_marking.temporal_id, h264info->temporal_idx); |
| 181 | EXPECT_EQ(header.frame_marking.base_layer_sync, h264info->base_layer_sync); |
| 182 | EXPECT_EQ(header.frame_marking.independent_frame, h264info->idr_frame); |
| 183 | |
| 184 | // test temporal param 2 |
| 185 | h264info->temporal_idx = 0; |
| 186 | h264info->base_layer_sync = false; |
| 187 | h264info->idr_frame = true; |
| 188 | |
Markus Handell | c1cbf6b | 2020-02-17 20:03:57 +0100 | [diff] [blame] | 189 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, 30); |
Johnny Lee | 1a1c52b | 2019-02-08 14:25:40 -0500 | [diff] [blame] | 190 | |
| 191 | EXPECT_EQ(kVideoCodecH264, header.codec); |
| 192 | EXPECT_EQ(header.frame_marking.tl0_pic_idx, kInitialTl0PicIdx1 + 1); |
| 193 | EXPECT_EQ(header.frame_marking.temporal_id, h264info->temporal_idx); |
| 194 | EXPECT_EQ(header.frame_marking.base_layer_sync, h264info->base_layer_sync); |
| 195 | EXPECT_EQ(header.frame_marking.independent_frame, h264info->idr_frame); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | TEST(RtpPayloadParamsTest, PictureIdIsSetForVp8) { |
| 199 | RtpPayloadState state; |
| 200 | state.picture_id = kInitialPictureId1; |
| 201 | state.tl0_pic_idx = kInitialTl0PicIdx1; |
| 202 | |
| 203 | EncodedImage encoded_image; |
| 204 | CodecSpecificInfo codec_info; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 205 | codec_info.codecType = kVideoCodecVP8; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 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 | EXPECT_EQ(kVideoCodecVP8, header.codec); |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 211 | EXPECT_EQ(kInitialPictureId1 + 1, |
| 212 | absl::get<RTPVideoHeaderVP8>(header.video_type_header).pictureId); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 213 | |
| 214 | // State should hold latest used picture id and tl0_pic_idx. |
| 215 | state = params.state(); |
| 216 | EXPECT_EQ(kInitialPictureId1 + 1, state.picture_id); |
| 217 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, state.tl0_pic_idx); |
| 218 | } |
| 219 | |
| 220 | TEST(RtpPayloadParamsTest, PictureIdWraps) { |
| 221 | RtpPayloadState state; |
| 222 | state.picture_id = kMaxTwoBytePictureId; |
| 223 | state.tl0_pic_idx = kInitialTl0PicIdx1; |
| 224 | |
| 225 | EncodedImage encoded_image; |
| 226 | CodecSpecificInfo codec_info; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 227 | codec_info.codecType = kVideoCodecVP8; |
| 228 | codec_info.codecSpecific.VP8.temporalIdx = kNoTemporalIdx; |
| 229 | |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 230 | RtpPayloadParams params(kSsrc1, &state, FieldTrialBasedConfig()); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 231 | RTPVideoHeader header = |
| 232 | params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 233 | EXPECT_EQ(kVideoCodecVP8, header.codec); |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 234 | EXPECT_EQ(0, |
| 235 | absl::get<RTPVideoHeaderVP8>(header.video_type_header).pictureId); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 236 | |
| 237 | // State should hold latest used picture id and tl0_pic_idx. |
| 238 | EXPECT_EQ(0, params.state().picture_id); // Wrapped. |
| 239 | EXPECT_EQ(kInitialTl0PicIdx1, params.state().tl0_pic_idx); |
| 240 | } |
| 241 | |
| 242 | TEST(RtpPayloadParamsTest, Tl0PicIdxUpdatedForVp8) { |
| 243 | RtpPayloadState state; |
| 244 | state.picture_id = kInitialPictureId1; |
| 245 | state.tl0_pic_idx = kInitialTl0PicIdx1; |
| 246 | |
| 247 | EncodedImage encoded_image; |
| 248 | // Modules are sending for this test. |
| 249 | // OnEncodedImage, temporalIdx: 1. |
| 250 | CodecSpecificInfo codec_info; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 251 | codec_info.codecType = kVideoCodecVP8; |
| 252 | codec_info.codecSpecific.VP8.temporalIdx = 1; |
| 253 | |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 254 | RtpPayloadParams params(kSsrc1, &state, FieldTrialBasedConfig()); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 255 | RTPVideoHeader header = |
| 256 | params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 257 | |
| 258 | EXPECT_EQ(kVideoCodecVP8, header.codec); |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 259 | const auto& vp8_header = |
| 260 | absl::get<RTPVideoHeaderVP8>(header.video_type_header); |
| 261 | EXPECT_EQ(kInitialPictureId1 + 1, vp8_header.pictureId); |
| 262 | EXPECT_EQ(kInitialTl0PicIdx1, vp8_header.tl0PicIdx); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 263 | |
| 264 | // OnEncodedImage, temporalIdx: 0. |
| 265 | codec_info.codecSpecific.VP8.temporalIdx = 0; |
| 266 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 267 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 268 | EXPECT_EQ(kVideoCodecVP8, header.codec); |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 269 | EXPECT_EQ(kInitialPictureId1 + 2, vp8_header.pictureId); |
| 270 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, vp8_header.tl0PicIdx); |
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 | } |
| 276 | |
| 277 | TEST(RtpPayloadParamsTest, Tl0PicIdxUpdatedForVp9) { |
| 278 | RtpPayloadState state; |
| 279 | state.picture_id = kInitialPictureId1; |
| 280 | state.tl0_pic_idx = kInitialTl0PicIdx1; |
| 281 | |
| 282 | EncodedImage encoded_image; |
| 283 | // Modules are sending for this test. |
| 284 | // OnEncodedImage, temporalIdx: 1. |
| 285 | CodecSpecificInfo codec_info; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 286 | codec_info.codecType = kVideoCodecVP9; |
| 287 | codec_info.codecSpecific.VP9.temporal_idx = 1; |
| 288 | codec_info.codecSpecific.VP9.first_frame_in_picture = true; |
| 289 | |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 290 | RtpPayloadParams params(kSsrc1, &state, FieldTrialBasedConfig()); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 291 | RTPVideoHeader header = |
| 292 | params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 293 | |
| 294 | EXPECT_EQ(kVideoCodecVP9, header.codec); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 295 | const auto& vp9_header = |
| 296 | absl::get<RTPVideoHeaderVP9>(header.video_type_header); |
| 297 | EXPECT_EQ(kInitialPictureId1 + 1, vp9_header.picture_id); |
| 298 | EXPECT_EQ(kInitialTl0PicIdx1, vp9_header.tl0_pic_idx); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 299 | |
| 300 | // OnEncodedImage, temporalIdx: 0. |
| 301 | codec_info.codecSpecific.VP9.temporal_idx = 0; |
| 302 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 303 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 304 | |
| 305 | EXPECT_EQ(kVideoCodecVP9, header.codec); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 306 | EXPECT_EQ(kInitialPictureId1 + 2, vp9_header.picture_id); |
| 307 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, vp9_header.tl0_pic_idx); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 308 | |
| 309 | // OnEncodedImage, first_frame_in_picture = false |
| 310 | codec_info.codecSpecific.VP9.first_frame_in_picture = false; |
| 311 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 312 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 313 | |
| 314 | EXPECT_EQ(kVideoCodecVP9, header.codec); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 315 | EXPECT_EQ(kInitialPictureId1 + 2, vp9_header.picture_id); |
| 316 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, vp9_header.tl0_pic_idx); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 317 | |
| 318 | // State should hold latest used picture id and tl0_pic_idx. |
| 319 | EXPECT_EQ(kInitialPictureId1 + 2, params.state().picture_id); |
| 320 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, params.state().tl0_pic_idx); |
| 321 | } |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 322 | |
| 323 | TEST(RtpPayloadParamsTest, PictureIdForOldGenericFormat) { |
| 324 | test::ScopedFieldTrials generic_picture_id( |
| 325 | "WebRTC-GenericPictureId/Enabled/"); |
| 326 | RtpPayloadState state{}; |
| 327 | |
| 328 | EncodedImage encoded_image; |
philipel | d1d0359 | 2019-03-01 13:53:55 +0100 | [diff] [blame] | 329 | CodecSpecificInfo codec_info; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 330 | codec_info.codecType = kVideoCodecGeneric; |
Markus Handell | c1cbf6b | 2020-02-17 20:03:57 +0100 | [diff] [blame] | 331 | encoded_image._frameType = VideoFrameType::kVideoFrameKey; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 332 | |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 333 | RtpPayloadParams params(kSsrc1, &state, FieldTrialBasedConfig()); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 334 | RTPVideoHeader header = |
Markus Handell | c1cbf6b | 2020-02-17 20:03:57 +0100 | [diff] [blame] | 335 | params.GetRtpVideoHeader(encoded_image, &codec_info, 10); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 336 | |
| 337 | EXPECT_EQ(kVideoCodecGeneric, header.codec); |
Danil Chapovalov | b6bf0b2 | 2020-01-28 18:36:57 +0100 | [diff] [blame] | 338 | const auto* generic = |
| 339 | absl::get_if<RTPVideoHeaderLegacyGeneric>(&header.video_type_header); |
| 340 | ASSERT_TRUE(generic); |
| 341 | EXPECT_EQ(0, generic->picture_id); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 342 | |
Markus Handell | c1cbf6b | 2020-02-17 20:03:57 +0100 | [diff] [blame] | 343 | encoded_image._frameType = VideoFrameType::kVideoFrameDelta; |
| 344 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, 20); |
Danil Chapovalov | b6bf0b2 | 2020-01-28 18:36:57 +0100 | [diff] [blame] | 345 | generic = |
| 346 | absl::get_if<RTPVideoHeaderLegacyGeneric>(&header.video_type_header); |
| 347 | ASSERT_TRUE(generic); |
| 348 | EXPECT_EQ(1, generic->picture_id); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 349 | } |
| 350 | |
philipel | 8aba8fe | 2019-06-13 15:13:16 +0200 | [diff] [blame] | 351 | TEST(RtpPayloadParamsTest, GenericDescriptorForGenericCodec) { |
| 352 | test::ScopedFieldTrials generic_picture_id( |
| 353 | "WebRTC-GenericDescriptor/Enabled/"); |
| 354 | RtpPayloadState state{}; |
| 355 | |
| 356 | EncodedImage encoded_image; |
| 357 | encoded_image._frameType = VideoFrameType::kVideoFrameKey; |
| 358 | CodecSpecificInfo codec_info; |
| 359 | codec_info.codecType = kVideoCodecGeneric; |
| 360 | |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 361 | RtpPayloadParams params(kSsrc1, &state, FieldTrialBasedConfig()); |
philipel | 8aba8fe | 2019-06-13 15:13:16 +0200 | [diff] [blame] | 362 | RTPVideoHeader header = |
| 363 | params.GetRtpVideoHeader(encoded_image, &codec_info, 0); |
| 364 | |
| 365 | EXPECT_EQ(kVideoCodecGeneric, header.codec); |
| 366 | ASSERT_TRUE(header.generic); |
| 367 | EXPECT_EQ(0, header.generic->frame_id); |
| 368 | EXPECT_THAT(header.generic->dependencies, IsEmpty()); |
| 369 | |
| 370 | encoded_image._frameType = VideoFrameType::kVideoFrameDelta; |
| 371 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, 1); |
| 372 | ASSERT_TRUE(header.generic); |
| 373 | EXPECT_EQ(1, header.generic->frame_id); |
| 374 | EXPECT_THAT(header.generic->dependencies, ElementsAre(0)); |
| 375 | } |
| 376 | |
Danil Chapovalov | 02d71fb | 2020-02-10 16:22:57 +0100 | [diff] [blame] | 377 | TEST(RtpPayloadParamsTest, SetsGenericFromGenericFrameInfo) { |
| 378 | test::ScopedFieldTrials generic_picture_id( |
| 379 | "WebRTC-GenericDescriptor/Enabled/"); |
| 380 | RtpPayloadState state; |
| 381 | EncodedImage encoded_image; |
| 382 | CodecSpecificInfo codec_info; |
| 383 | |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 384 | RtpPayloadParams params(kSsrc1, &state, FieldTrialBasedConfig()); |
Danil Chapovalov | 02d71fb | 2020-02-10 16:22:57 +0100 | [diff] [blame] | 385 | |
| 386 | encoded_image._frameType = VideoFrameType::kVideoFrameKey; |
| 387 | codec_info.generic_frame_info = |
| 388 | GenericFrameInfo::Builder().S(1).T(0).Dtis("S").Build(); |
| 389 | codec_info.generic_frame_info->encoder_buffers = { |
| 390 | {/*id=*/0, /*referenced=*/false, /*updated=*/true}}; |
| 391 | RTPVideoHeader key_header = |
| 392 | params.GetRtpVideoHeader(encoded_image, &codec_info, /*frame_id=*/1); |
| 393 | |
| 394 | ASSERT_TRUE(key_header.generic); |
| 395 | EXPECT_EQ(key_header.generic->spatial_index, 1); |
| 396 | EXPECT_EQ(key_header.generic->temporal_index, 0); |
| 397 | EXPECT_EQ(key_header.generic->frame_id, 1); |
| 398 | EXPECT_THAT(key_header.generic->dependencies, IsEmpty()); |
| 399 | EXPECT_THAT(key_header.generic->decode_target_indications, |
| 400 | ElementsAre(DecodeTargetIndication::kSwitch)); |
Danil Chapovalov | 02d71fb | 2020-02-10 16:22:57 +0100 | [diff] [blame] | 401 | |
| 402 | encoded_image._frameType = VideoFrameType::kVideoFrameDelta; |
| 403 | codec_info.generic_frame_info = |
| 404 | GenericFrameInfo::Builder().S(2).T(3).Dtis("D").Build(); |
| 405 | codec_info.generic_frame_info->encoder_buffers = { |
| 406 | {/*id=*/0, /*referenced=*/true, /*updated=*/false}}; |
| 407 | RTPVideoHeader delta_header = |
| 408 | params.GetRtpVideoHeader(encoded_image, &codec_info, /*frame_id=*/3); |
| 409 | |
| 410 | ASSERT_TRUE(delta_header.generic); |
| 411 | EXPECT_EQ(delta_header.generic->spatial_index, 2); |
| 412 | EXPECT_EQ(delta_header.generic->temporal_index, 3); |
| 413 | EXPECT_EQ(delta_header.generic->frame_id, 3); |
| 414 | EXPECT_THAT(delta_header.generic->dependencies, ElementsAre(1)); |
| 415 | EXPECT_THAT(delta_header.generic->decode_target_indications, |
| 416 | ElementsAre(DecodeTargetIndication::kDiscardable)); |
Danil Chapovalov | 02d71fb | 2020-02-10 16:22:57 +0100 | [diff] [blame] | 417 | } |
| 418 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 419 | class RtpPayloadParamsVp8ToGenericTest : public ::testing::Test { |
| 420 | public: |
| 421 | enum LayerSync { kNoSync, kSync }; |
| 422 | |
philipel | 569397f | 2018-09-26 12:25:31 +0200 | [diff] [blame] | 423 | RtpPayloadParamsVp8ToGenericTest() |
| 424 | : generic_descriptor_field_trial_("WebRTC-GenericDescriptor/Enabled/"), |
| 425 | state_(), |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 426 | params_(123, &state_, trials_config_) {} |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 427 | |
| 428 | void ConvertAndCheck(int temporal_index, |
| 429 | int64_t shared_frame_id, |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 430 | VideoFrameType frame_type, |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 431 | LayerSync layer_sync, |
philipel | fab9129 | 2018-10-17 14:36:08 +0200 | [diff] [blame] | 432 | const std::set<int64_t>& expected_deps, |
| 433 | uint16_t width = 0, |
| 434 | uint16_t height = 0) { |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 435 | EncodedImage encoded_image; |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 436 | encoded_image._frameType = frame_type; |
philipel | fab9129 | 2018-10-17 14:36:08 +0200 | [diff] [blame] | 437 | encoded_image._encodedWidth = width; |
| 438 | encoded_image._encodedHeight = height; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 439 | |
philipel | d1d0359 | 2019-03-01 13:53:55 +0100 | [diff] [blame] | 440 | CodecSpecificInfo codec_info; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 441 | codec_info.codecType = kVideoCodecVP8; |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 442 | codec_info.codecSpecific.VP8.temporalIdx = temporal_index; |
| 443 | codec_info.codecSpecific.VP8.layerSync = layer_sync == kSync; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 444 | |
| 445 | RTPVideoHeader header = |
| 446 | params_.GetRtpVideoHeader(encoded_image, &codec_info, shared_frame_id); |
| 447 | |
| 448 | ASSERT_TRUE(header.generic); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 449 | EXPECT_EQ(header.generic->spatial_index, 0); |
| 450 | |
| 451 | EXPECT_EQ(header.generic->frame_id, shared_frame_id); |
| 452 | EXPECT_EQ(header.generic->temporal_index, temporal_index); |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 453 | std::set<int64_t> actual_deps(header.generic->dependencies.begin(), |
| 454 | header.generic->dependencies.end()); |
| 455 | EXPECT_EQ(expected_deps, actual_deps); |
philipel | fab9129 | 2018-10-17 14:36:08 +0200 | [diff] [blame] | 456 | |
| 457 | EXPECT_EQ(header.width, width); |
| 458 | EXPECT_EQ(header.height, height); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | protected: |
philipel | 569397f | 2018-09-26 12:25:31 +0200 | [diff] [blame] | 462 | test::ScopedFieldTrials generic_descriptor_field_trial_; |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 463 | FieldTrialBasedConfig trials_config_; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 464 | RtpPayloadState state_; |
| 465 | RtpPayloadParams params_; |
| 466 | }; |
| 467 | |
| 468 | TEST_F(RtpPayloadParamsVp8ToGenericTest, Keyframe) { |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 469 | ConvertAndCheck(0, 0, VideoFrameType::kVideoFrameKey, kNoSync, {}, 480, 360); |
| 470 | ConvertAndCheck(0, 1, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 471 | ConvertAndCheck(0, 2, VideoFrameType::kVideoFrameKey, kNoSync, {}, 480, 360); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | TEST_F(RtpPayloadParamsVp8ToGenericTest, TooHighTemporalIndex) { |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 475 | ConvertAndCheck(0, 0, VideoFrameType::kVideoFrameKey, kNoSync, {}, 480, 360); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 476 | |
| 477 | EncodedImage encoded_image; |
Niels Möller | 8f7ce22 | 2019-03-21 15:43:58 +0100 | [diff] [blame] | 478 | encoded_image._frameType = VideoFrameType::kVideoFrameDelta; |
philipel | d1d0359 | 2019-03-01 13:53:55 +0100 | [diff] [blame] | 479 | CodecSpecificInfo codec_info; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 480 | codec_info.codecType = kVideoCodecVP8; |
| 481 | codec_info.codecSpecific.VP8.temporalIdx = |
| 482 | RtpGenericFrameDescriptor::kMaxTemporalLayers; |
| 483 | codec_info.codecSpecific.VP8.layerSync = false; |
| 484 | |
| 485 | RTPVideoHeader header = |
| 486 | params_.GetRtpVideoHeader(encoded_image, &codec_info, 1); |
| 487 | EXPECT_FALSE(header.generic); |
| 488 | } |
| 489 | |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 490 | TEST_F(RtpPayloadParamsVp8ToGenericTest, LayerSync) { |
| 491 | // 02120212 pattern |
| 492 | ConvertAndCheck(0, 0, VideoFrameType::kVideoFrameKey, kNoSync, {}, 480, 360); |
| 493 | ConvertAndCheck(2, 1, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 494 | ConvertAndCheck(1, 2, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 495 | ConvertAndCheck(2, 3, VideoFrameType::kVideoFrameDelta, kNoSync, {0, 1, 2}); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 496 | |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 497 | ConvertAndCheck(0, 4, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 498 | ConvertAndCheck(2, 5, VideoFrameType::kVideoFrameDelta, kNoSync, {2, 3, 4}); |
| 499 | ConvertAndCheck(1, 6, VideoFrameType::kVideoFrameDelta, kSync, |
| 500 | {4}); // layer sync |
| 501 | ConvertAndCheck(2, 7, VideoFrameType::kVideoFrameDelta, kNoSync, {4, 5, 6}); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | TEST_F(RtpPayloadParamsVp8ToGenericTest, FrameIdGaps) { |
| 505 | // 0101 pattern |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 506 | ConvertAndCheck(0, 0, VideoFrameType::kVideoFrameKey, kNoSync, {}, 480, 360); |
| 507 | ConvertAndCheck(1, 1, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 508 | |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 509 | ConvertAndCheck(0, 5, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 510 | ConvertAndCheck(1, 10, VideoFrameType::kVideoFrameDelta, kNoSync, {1, 5}); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 511 | |
Qingsi Wang | 1c1b99e | 2020-01-07 19:16:33 +0000 | [diff] [blame] | 512 | ConvertAndCheck(0, 15, VideoFrameType::kVideoFrameDelta, kNoSync, {5}); |
| 513 | ConvertAndCheck(1, 20, VideoFrameType::kVideoFrameDelta, kNoSync, {10, 15}); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 514 | } |
| 515 | |
philipel | 8aba8fe | 2019-06-13 15:13:16 +0200 | [diff] [blame] | 516 | class RtpPayloadParamsH264ToGenericTest : public ::testing::Test { |
| 517 | public: |
| 518 | enum LayerSync { kNoSync, kSync }; |
| 519 | |
| 520 | RtpPayloadParamsH264ToGenericTest() |
| 521 | : generic_descriptor_field_trial_("WebRTC-GenericDescriptor/Enabled/"), |
| 522 | state_(), |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 523 | params_(123, &state_, trials_config_) {} |
philipel | 8aba8fe | 2019-06-13 15:13:16 +0200 | [diff] [blame] | 524 | |
| 525 | void ConvertAndCheck(int temporal_index, |
| 526 | int64_t shared_frame_id, |
| 527 | VideoFrameType frame_type, |
| 528 | LayerSync layer_sync, |
| 529 | const std::set<int64_t>& expected_deps, |
| 530 | uint16_t width = 0, |
| 531 | uint16_t height = 0) { |
| 532 | EncodedImage encoded_image; |
| 533 | encoded_image._frameType = frame_type; |
| 534 | encoded_image._encodedWidth = width; |
| 535 | encoded_image._encodedHeight = height; |
| 536 | |
| 537 | CodecSpecificInfo codec_info; |
| 538 | codec_info.codecType = kVideoCodecH264; |
| 539 | codec_info.codecSpecific.H264.temporal_idx = temporal_index; |
| 540 | codec_info.codecSpecific.H264.base_layer_sync = layer_sync == kSync; |
| 541 | |
| 542 | RTPVideoHeader header = |
| 543 | params_.GetRtpVideoHeader(encoded_image, &codec_info, shared_frame_id); |
| 544 | |
| 545 | ASSERT_TRUE(header.generic); |
philipel | 8aba8fe | 2019-06-13 15:13:16 +0200 | [diff] [blame] | 546 | EXPECT_EQ(header.generic->spatial_index, 0); |
| 547 | |
| 548 | EXPECT_EQ(header.generic->frame_id, shared_frame_id); |
| 549 | EXPECT_EQ(header.generic->temporal_index, temporal_index); |
| 550 | std::set<int64_t> actual_deps(header.generic->dependencies.begin(), |
| 551 | header.generic->dependencies.end()); |
| 552 | EXPECT_EQ(expected_deps, actual_deps); |
| 553 | |
| 554 | EXPECT_EQ(header.width, width); |
| 555 | EXPECT_EQ(header.height, height); |
| 556 | } |
| 557 | |
| 558 | protected: |
| 559 | test::ScopedFieldTrials generic_descriptor_field_trial_; |
Erik Språng | cbc0cba | 2020-04-18 14:36:59 +0200 | [diff] [blame] | 560 | FieldTrialBasedConfig trials_config_; |
philipel | 8aba8fe | 2019-06-13 15:13:16 +0200 | [diff] [blame] | 561 | RtpPayloadState state_; |
| 562 | RtpPayloadParams params_; |
| 563 | }; |
| 564 | |
| 565 | TEST_F(RtpPayloadParamsH264ToGenericTest, Keyframe) { |
| 566 | ConvertAndCheck(0, 0, VideoFrameType::kVideoFrameKey, kNoSync, {}, 480, 360); |
| 567 | ConvertAndCheck(0, 1, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 568 | ConvertAndCheck(0, 2, VideoFrameType::kVideoFrameKey, kNoSync, {}, 480, 360); |
| 569 | } |
| 570 | |
| 571 | TEST_F(RtpPayloadParamsH264ToGenericTest, TooHighTemporalIndex) { |
| 572 | ConvertAndCheck(0, 0, VideoFrameType::kVideoFrameKey, kNoSync, {}, 480, 360); |
| 573 | |
| 574 | EncodedImage encoded_image; |
| 575 | encoded_image._frameType = VideoFrameType::kVideoFrameDelta; |
| 576 | CodecSpecificInfo codec_info; |
| 577 | codec_info.codecType = kVideoCodecH264; |
| 578 | codec_info.codecSpecific.H264.temporal_idx = |
| 579 | RtpGenericFrameDescriptor::kMaxTemporalLayers; |
| 580 | codec_info.codecSpecific.H264.base_layer_sync = false; |
| 581 | |
| 582 | RTPVideoHeader header = |
| 583 | params_.GetRtpVideoHeader(encoded_image, &codec_info, 1); |
| 584 | EXPECT_FALSE(header.generic); |
| 585 | } |
| 586 | |
| 587 | TEST_F(RtpPayloadParamsH264ToGenericTest, LayerSync) { |
| 588 | // 02120212 pattern |
| 589 | ConvertAndCheck(0, 0, VideoFrameType::kVideoFrameKey, kNoSync, {}, 480, 360); |
| 590 | ConvertAndCheck(2, 1, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 591 | ConvertAndCheck(1, 2, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 592 | ConvertAndCheck(2, 3, VideoFrameType::kVideoFrameDelta, kNoSync, {0, 1, 2}); |
| 593 | |
| 594 | ConvertAndCheck(0, 4, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 595 | ConvertAndCheck(2, 5, VideoFrameType::kVideoFrameDelta, kNoSync, {2, 3, 4}); |
| 596 | ConvertAndCheck(1, 6, VideoFrameType::kVideoFrameDelta, kSync, |
| 597 | {4}); // layer sync |
| 598 | ConvertAndCheck(2, 7, VideoFrameType::kVideoFrameDelta, kNoSync, {4, 5, 6}); |
| 599 | } |
| 600 | |
| 601 | TEST_F(RtpPayloadParamsH264ToGenericTest, FrameIdGaps) { |
| 602 | // 0101 pattern |
| 603 | ConvertAndCheck(0, 0, VideoFrameType::kVideoFrameKey, kNoSync, {}, 480, 360); |
| 604 | ConvertAndCheck(1, 1, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 605 | |
| 606 | ConvertAndCheck(0, 5, VideoFrameType::kVideoFrameDelta, kNoSync, {0}); |
| 607 | ConvertAndCheck(1, 10, VideoFrameType::kVideoFrameDelta, kNoSync, {1, 5}); |
| 608 | |
| 609 | ConvertAndCheck(0, 15, VideoFrameType::kVideoFrameDelta, kNoSync, {5}); |
| 610 | ConvertAndCheck(1, 20, VideoFrameType::kVideoFrameDelta, kNoSync, {10, 15}); |
| 611 | } |
| 612 | |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 613 | } // namespace webrtc |