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