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 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 11 | #include <string.h> |
| 12 | #include <map> |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 13 | #include <set> |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 14 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 15 | #include "absl/container/inlined_vector.h" |
| 16 | #include "absl/types/optional.h" |
| 17 | #include "absl/types/variant.h" |
| 18 | #include "api/video/video_content_type.h" |
| 19 | #include "api/video/video_rotation.h" |
Stefan Holmer | 9416ef8 | 2018-07-19 10:34:38 +0200 | [diff] [blame] | 20 | #include "call/rtp_payload_params.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 21 | #include "common_types.h" // NOLINT(build/include) |
| 22 | #include "modules/video_coding/codecs/h264/include/h264_globals.h" |
| 23 | #include "modules/video_coding/codecs/interface/common_constants.h" |
| 24 | #include "modules/video_coding/codecs/vp8/include/vp8_globals.h" |
| 25 | #include "modules/video_coding/codecs/vp9/include/vp9_globals.h" |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 26 | #include "modules/video_coding/include/video_codec_interface.h" |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 27 | #include "test/field_trial.h" |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 28 | #include "test/gtest.h" |
| 29 | |
| 30 | namespace webrtc { |
| 31 | namespace { |
| 32 | const uint32_t kSsrc1 = 12345; |
| 33 | const uint32_t kSsrc2 = 23456; |
| 34 | const int16_t kPictureId = 123; |
| 35 | const int16_t kTl0PicIdx = 20; |
| 36 | const uint8_t kTemporalIdx = 1; |
| 37 | const int16_t kInitialPictureId1 = 222; |
| 38 | const int16_t kInitialTl0PicIdx1 = 99; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 39 | const int64_t kDontCare = 0; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 40 | } // namespace |
| 41 | |
| 42 | TEST(RtpPayloadParamsTest, InfoMappedToRtpVideoHeader_Vp8) { |
| 43 | RtpPayloadState state2; |
| 44 | state2.picture_id = kPictureId; |
| 45 | state2.tl0_pic_idx = kTl0PicIdx; |
| 46 | std::map<uint32_t, RtpPayloadState> states = {{kSsrc2, state2}}; |
| 47 | |
| 48 | RtpPayloadParams params(kSsrc2, &state2); |
| 49 | EncodedImage encoded_image; |
| 50 | encoded_image.rotation_ = kVideoRotation_90; |
| 51 | encoded_image.content_type_ = VideoContentType::SCREENSHARE; |
Niels Möller | d3b8c63 | 2018-08-27 15:33:42 +0200 | [diff] [blame] | 52 | encoded_image.SetSpatialIndex(1); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 53 | |
| 54 | CodecSpecificInfo codec_info; |
| 55 | memset(&codec_info, 0, sizeof(CodecSpecificInfo)); |
| 56 | codec_info.codecType = kVideoCodecVP8; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 57 | codec_info.codecSpecific.VP8.temporalIdx = 0; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 58 | codec_info.codecSpecific.VP8.keyIdx = kNoKeyIdx; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 59 | codec_info.codecSpecific.VP8.layerSync = false; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 60 | codec_info.codecSpecific.VP8.nonReference = true; |
| 61 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 62 | RTPVideoHeader header = |
| 63 | params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
| 64 | |
| 65 | codec_info.codecType = kVideoCodecVP8; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 66 | codec_info.codecSpecific.VP8.temporalIdx = 1; |
| 67 | codec_info.codecSpecific.VP8.layerSync = true; |
| 68 | |
| 69 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, 1); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 70 | |
| 71 | EXPECT_EQ(kVideoRotation_90, header.rotation); |
| 72 | EXPECT_EQ(VideoContentType::SCREENSHARE, header.content_type); |
| 73 | EXPECT_EQ(1, header.simulcastIdx); |
| 74 | EXPECT_EQ(kVideoCodecVP8, header.codec); |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 75 | const auto& vp8_header = |
| 76 | absl::get<RTPVideoHeaderVP8>(header.video_type_header); |
| 77 | EXPECT_EQ(kPictureId + 2, vp8_header.pictureId); |
| 78 | EXPECT_EQ(kTemporalIdx, vp8_header.temporalIdx); |
| 79 | EXPECT_EQ(kTl0PicIdx + 1, vp8_header.tl0PicIdx); |
| 80 | EXPECT_EQ(kNoKeyIdx, vp8_header.keyIdx); |
| 81 | EXPECT_TRUE(vp8_header.layerSync); |
| 82 | EXPECT_TRUE(vp8_header.nonReference); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | TEST(RtpPayloadParamsTest, InfoMappedToRtpVideoHeader_Vp9) { |
| 86 | RtpPayloadState state; |
| 87 | state.picture_id = kPictureId; |
| 88 | state.tl0_pic_idx = kTl0PicIdx; |
| 89 | RtpPayloadParams params(kSsrc1, &state); |
| 90 | |
| 91 | EncodedImage encoded_image; |
| 92 | encoded_image.rotation_ = kVideoRotation_90; |
| 93 | encoded_image.content_type_ = VideoContentType::SCREENSHARE; |
Niels Möller | d3b8c63 | 2018-08-27 15:33:42 +0200 | [diff] [blame] | 94 | encoded_image.SetSpatialIndex(0); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 95 | CodecSpecificInfo codec_info; |
| 96 | memset(&codec_info, 0, sizeof(CodecSpecificInfo)); |
| 97 | codec_info.codecType = kVideoCodecVP9; |
| 98 | codec_info.codecSpecific.VP9.num_spatial_layers = 3; |
| 99 | codec_info.codecSpecific.VP9.first_frame_in_picture = true; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 100 | codec_info.codecSpecific.VP9.temporal_idx = 2; |
| 101 | codec_info.codecSpecific.VP9.end_of_picture = false; |
| 102 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 103 | RTPVideoHeader header = |
| 104 | params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 105 | |
| 106 | EXPECT_EQ(kVideoRotation_90, header.rotation); |
| 107 | EXPECT_EQ(VideoContentType::SCREENSHARE, header.content_type); |
| 108 | EXPECT_EQ(kVideoCodecVP9, header.codec); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 109 | const auto& vp9_header = |
| 110 | absl::get<RTPVideoHeaderVP9>(header.video_type_header); |
| 111 | EXPECT_EQ(kPictureId + 1, vp9_header.picture_id); |
| 112 | EXPECT_EQ(kTl0PicIdx, vp9_header.tl0_pic_idx); |
| 113 | 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] | 114 | EXPECT_EQ(vp9_header.spatial_idx, encoded_image.SpatialIndex()); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 115 | EXPECT_EQ(vp9_header.num_spatial_layers, |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 116 | codec_info.codecSpecific.VP9.num_spatial_layers); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 117 | EXPECT_EQ(vp9_header.end_of_picture, |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 118 | codec_info.codecSpecific.VP9.end_of_picture); |
| 119 | |
| 120 | // Next spatial layer. |
| 121 | codec_info.codecSpecific.VP9.first_frame_in_picture = false; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 122 | codec_info.codecSpecific.VP9.end_of_picture = true; |
| 123 | |
Niels Möller | d3b8c63 | 2018-08-27 15:33:42 +0200 | [diff] [blame] | 124 | encoded_image.SetSpatialIndex(1); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 125 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 126 | |
| 127 | EXPECT_EQ(kVideoRotation_90, header.rotation); |
| 128 | EXPECT_EQ(VideoContentType::SCREENSHARE, header.content_type); |
| 129 | EXPECT_EQ(kVideoCodecVP9, header.codec); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 130 | EXPECT_EQ(kPictureId + 1, vp9_header.picture_id); |
| 131 | EXPECT_EQ(kTl0PicIdx, vp9_header.tl0_pic_idx); |
| 132 | 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] | 133 | EXPECT_EQ(vp9_header.spatial_idx, encoded_image.SpatialIndex()); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 134 | EXPECT_EQ(vp9_header.num_spatial_layers, |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 135 | codec_info.codecSpecific.VP9.num_spatial_layers); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 136 | EXPECT_EQ(vp9_header.end_of_picture, |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 137 | codec_info.codecSpecific.VP9.end_of_picture); |
| 138 | } |
| 139 | |
| 140 | TEST(RtpPayloadParamsTest, InfoMappedToRtpVideoHeader_H264) { |
| 141 | RtpPayloadParams params(kSsrc1, {}); |
| 142 | |
| 143 | EncodedImage encoded_image; |
| 144 | CodecSpecificInfo codec_info; |
| 145 | memset(&codec_info, 0, sizeof(CodecSpecificInfo)); |
| 146 | codec_info.codecType = kVideoCodecH264; |
| 147 | codec_info.codecSpecific.H264.packetization_mode = |
| 148 | H264PacketizationMode::SingleNalUnit; |
| 149 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 150 | RTPVideoHeader header = |
| 151 | params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 152 | |
| 153 | EXPECT_EQ(0, header.simulcastIdx); |
| 154 | EXPECT_EQ(kVideoCodecH264, header.codec); |
| 155 | const auto& h264 = absl::get<RTPVideoHeaderH264>(header.video_type_header); |
| 156 | EXPECT_EQ(H264PacketizationMode::SingleNalUnit, h264.packetization_mode); |
| 157 | } |
| 158 | |
| 159 | TEST(RtpPayloadParamsTest, PictureIdIsSetForVp8) { |
| 160 | RtpPayloadState state; |
| 161 | state.picture_id = kInitialPictureId1; |
| 162 | state.tl0_pic_idx = kInitialTl0PicIdx1; |
| 163 | |
| 164 | EncodedImage encoded_image; |
| 165 | CodecSpecificInfo codec_info; |
| 166 | memset(&codec_info, 0, sizeof(CodecSpecificInfo)); |
| 167 | codec_info.codecType = kVideoCodecVP8; |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 168 | |
| 169 | RtpPayloadParams params(kSsrc1, &state); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 170 | RTPVideoHeader header = |
| 171 | params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 172 | EXPECT_EQ(kVideoCodecVP8, header.codec); |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 173 | EXPECT_EQ(kInitialPictureId1 + 1, |
| 174 | absl::get<RTPVideoHeaderVP8>(header.video_type_header).pictureId); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 175 | |
| 176 | // State should hold latest used picture id and tl0_pic_idx. |
| 177 | state = params.state(); |
| 178 | EXPECT_EQ(kInitialPictureId1 + 1, state.picture_id); |
| 179 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, state.tl0_pic_idx); |
| 180 | } |
| 181 | |
| 182 | TEST(RtpPayloadParamsTest, PictureIdWraps) { |
| 183 | RtpPayloadState state; |
| 184 | state.picture_id = kMaxTwoBytePictureId; |
| 185 | state.tl0_pic_idx = kInitialTl0PicIdx1; |
| 186 | |
| 187 | EncodedImage encoded_image; |
| 188 | CodecSpecificInfo codec_info; |
| 189 | memset(&codec_info, 0, sizeof(CodecSpecificInfo)); |
| 190 | codec_info.codecType = kVideoCodecVP8; |
| 191 | codec_info.codecSpecific.VP8.temporalIdx = kNoTemporalIdx; |
| 192 | |
| 193 | RtpPayloadParams params(kSsrc1, &state); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 194 | RTPVideoHeader header = |
| 195 | params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 196 | EXPECT_EQ(kVideoCodecVP8, header.codec); |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 197 | EXPECT_EQ(0, |
| 198 | absl::get<RTPVideoHeaderVP8>(header.video_type_header).pictureId); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 199 | |
| 200 | // State should hold latest used picture id and tl0_pic_idx. |
| 201 | EXPECT_EQ(0, params.state().picture_id); // Wrapped. |
| 202 | EXPECT_EQ(kInitialTl0PicIdx1, params.state().tl0_pic_idx); |
| 203 | } |
| 204 | |
| 205 | TEST(RtpPayloadParamsTest, Tl0PicIdxUpdatedForVp8) { |
| 206 | RtpPayloadState state; |
| 207 | state.picture_id = kInitialPictureId1; |
| 208 | state.tl0_pic_idx = kInitialTl0PicIdx1; |
| 209 | |
| 210 | EncodedImage encoded_image; |
| 211 | // Modules are sending for this test. |
| 212 | // OnEncodedImage, temporalIdx: 1. |
| 213 | CodecSpecificInfo codec_info; |
| 214 | memset(&codec_info, 0, sizeof(CodecSpecificInfo)); |
| 215 | codec_info.codecType = kVideoCodecVP8; |
| 216 | codec_info.codecSpecific.VP8.temporalIdx = 1; |
| 217 | |
| 218 | RtpPayloadParams params(kSsrc1, &state); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 219 | RTPVideoHeader header = |
| 220 | params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 221 | |
| 222 | EXPECT_EQ(kVideoCodecVP8, header.codec); |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame] | 223 | const auto& vp8_header = |
| 224 | absl::get<RTPVideoHeaderVP8>(header.video_type_header); |
| 225 | EXPECT_EQ(kInitialPictureId1 + 1, vp8_header.pictureId); |
| 226 | EXPECT_EQ(kInitialTl0PicIdx1, vp8_header.tl0PicIdx); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 227 | |
| 228 | // OnEncodedImage, temporalIdx: 0. |
| 229 | codec_info.codecSpecific.VP8.temporalIdx = 0; |
| 230 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 231 | header = 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(kInitialPictureId1 + 2, vp8_header.pictureId); |
| 234 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, vp8_header.tl0PicIdx); |
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(kInitialPictureId1 + 2, params.state().picture_id); |
| 238 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, params.state().tl0_pic_idx); |
| 239 | } |
| 240 | |
| 241 | TEST(RtpPayloadParamsTest, Tl0PicIdxUpdatedForVp9) { |
| 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; |
| 250 | memset(&codec_info, 0, sizeof(CodecSpecificInfo)); |
| 251 | codec_info.codecType = kVideoCodecVP9; |
| 252 | codec_info.codecSpecific.VP9.temporal_idx = 1; |
| 253 | codec_info.codecSpecific.VP9.first_frame_in_picture = true; |
| 254 | |
| 255 | RtpPayloadParams params(kSsrc1, &state); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 256 | RTPVideoHeader header = |
| 257 | 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 | const auto& vp9_header = |
| 261 | absl::get<RTPVideoHeaderVP9>(header.video_type_header); |
| 262 | EXPECT_EQ(kInitialPictureId1 + 1, vp9_header.picture_id); |
| 263 | EXPECT_EQ(kInitialTl0PicIdx1, vp9_header.tl0_pic_idx); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 264 | |
| 265 | // OnEncodedImage, temporalIdx: 0. |
| 266 | codec_info.codecSpecific.VP9.temporal_idx = 0; |
| 267 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 268 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 269 | |
| 270 | EXPECT_EQ(kVideoCodecVP9, header.codec); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 271 | EXPECT_EQ(kInitialPictureId1 + 2, vp9_header.picture_id); |
| 272 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, vp9_header.tl0_pic_idx); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 273 | |
| 274 | // OnEncodedImage, first_frame_in_picture = false |
| 275 | codec_info.codecSpecific.VP9.first_frame_in_picture = false; |
| 276 | |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 277 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 278 | |
| 279 | EXPECT_EQ(kVideoCodecVP9, header.codec); |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 280 | EXPECT_EQ(kInitialPictureId1 + 2, vp9_header.picture_id); |
| 281 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, vp9_header.tl0_pic_idx); |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 282 | |
| 283 | // State should hold latest used picture id and tl0_pic_idx. |
| 284 | EXPECT_EQ(kInitialPictureId1 + 2, params.state().picture_id); |
| 285 | EXPECT_EQ(kInitialTl0PicIdx1 + 1, params.state().tl0_pic_idx); |
| 286 | } |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 287 | |
| 288 | TEST(RtpPayloadParamsTest, PictureIdForOldGenericFormat) { |
| 289 | test::ScopedFieldTrials generic_picture_id( |
| 290 | "WebRTC-GenericPictureId/Enabled/"); |
| 291 | RtpPayloadState state{}; |
| 292 | |
| 293 | EncodedImage encoded_image; |
| 294 | CodecSpecificInfo codec_info{}; |
| 295 | codec_info.codecType = kVideoCodecGeneric; |
| 296 | |
| 297 | RtpPayloadParams params(kSsrc1, &state); |
| 298 | RTPVideoHeader header = |
| 299 | params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
| 300 | |
| 301 | EXPECT_EQ(kVideoCodecGeneric, header.codec); |
| 302 | ASSERT_TRUE(header.generic); |
| 303 | EXPECT_EQ(0, header.generic->frame_id); |
| 304 | |
| 305 | header = params.GetRtpVideoHeader(encoded_image, &codec_info, kDontCare); |
| 306 | ASSERT_TRUE(header.generic); |
| 307 | EXPECT_EQ(1, header.generic->frame_id); |
| 308 | } |
| 309 | |
| 310 | class RtpPayloadParamsVp8ToGenericTest : public ::testing::Test { |
| 311 | public: |
| 312 | enum LayerSync { kNoSync, kSync }; |
| 313 | |
philipel | 569397f | 2018-09-26 12:25:31 +0200 | [diff] [blame] | 314 | RtpPayloadParamsVp8ToGenericTest() |
| 315 | : generic_descriptor_field_trial_("WebRTC-GenericDescriptor/Enabled/"), |
| 316 | state_(), |
| 317 | params_(123, &state_) {} |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 318 | |
| 319 | void ConvertAndCheck(int temporal_index, |
| 320 | int64_t shared_frame_id, |
| 321 | FrameType frame_type, |
| 322 | LayerSync layer_sync, |
philipel | fab9129 | 2018-10-17 14:36:08 +0200 | [diff] [blame] | 323 | const std::set<int64_t>& expected_deps, |
| 324 | uint16_t width = 0, |
| 325 | uint16_t height = 0) { |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 326 | EncodedImage encoded_image; |
| 327 | encoded_image._frameType = frame_type; |
philipel | fab9129 | 2018-10-17 14:36:08 +0200 | [diff] [blame] | 328 | encoded_image._encodedWidth = width; |
| 329 | encoded_image._encodedHeight = height; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 330 | |
| 331 | CodecSpecificInfo codec_info{}; |
| 332 | codec_info.codecType = kVideoCodecVP8; |
| 333 | codec_info.codecSpecific.VP8.temporalIdx = temporal_index; |
| 334 | codec_info.codecSpecific.VP8.layerSync = layer_sync == kSync; |
| 335 | |
| 336 | RTPVideoHeader header = |
| 337 | params_.GetRtpVideoHeader(encoded_image, &codec_info, shared_frame_id); |
| 338 | |
| 339 | ASSERT_TRUE(header.generic); |
| 340 | EXPECT_TRUE(header.generic->higher_spatial_layers.empty()); |
| 341 | EXPECT_EQ(header.generic->spatial_index, 0); |
| 342 | |
| 343 | EXPECT_EQ(header.generic->frame_id, shared_frame_id); |
| 344 | EXPECT_EQ(header.generic->temporal_index, temporal_index); |
| 345 | std::set<int64_t> actual_deps(header.generic->dependencies.begin(), |
| 346 | header.generic->dependencies.end()); |
| 347 | EXPECT_EQ(expected_deps, actual_deps); |
philipel | fab9129 | 2018-10-17 14:36:08 +0200 | [diff] [blame] | 348 | |
| 349 | EXPECT_EQ(header.width, width); |
| 350 | EXPECT_EQ(header.height, height); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | protected: |
philipel | 569397f | 2018-09-26 12:25:31 +0200 | [diff] [blame] | 354 | test::ScopedFieldTrials generic_descriptor_field_trial_; |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 355 | RtpPayloadState state_; |
| 356 | RtpPayloadParams params_; |
| 357 | }; |
| 358 | |
| 359 | TEST_F(RtpPayloadParamsVp8ToGenericTest, Keyframe) { |
philipel | fab9129 | 2018-10-17 14:36:08 +0200 | [diff] [blame] | 360 | ConvertAndCheck(0, 0, kVideoFrameKey, kNoSync, {}, 480, 360); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 361 | ConvertAndCheck(0, 1, kVideoFrameDelta, kNoSync, {0}); |
philipel | fab9129 | 2018-10-17 14:36:08 +0200 | [diff] [blame] | 362 | ConvertAndCheck(0, 2, kVideoFrameKey, kNoSync, {}, 480, 360); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | TEST_F(RtpPayloadParamsVp8ToGenericTest, TooHighTemporalIndex) { |
philipel | fab9129 | 2018-10-17 14:36:08 +0200 | [diff] [blame] | 366 | ConvertAndCheck(0, 0, kVideoFrameKey, kNoSync, {}, 480, 360); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 367 | |
| 368 | EncodedImage encoded_image; |
| 369 | encoded_image._frameType = kVideoFrameDelta; |
| 370 | CodecSpecificInfo codec_info{}; |
| 371 | codec_info.codecType = kVideoCodecVP8; |
| 372 | codec_info.codecSpecific.VP8.temporalIdx = |
| 373 | RtpGenericFrameDescriptor::kMaxTemporalLayers; |
| 374 | codec_info.codecSpecific.VP8.layerSync = false; |
| 375 | |
| 376 | RTPVideoHeader header = |
| 377 | params_.GetRtpVideoHeader(encoded_image, &codec_info, 1); |
| 378 | EXPECT_FALSE(header.generic); |
| 379 | } |
| 380 | |
| 381 | TEST_F(RtpPayloadParamsVp8ToGenericTest, LayerSync) { |
| 382 | // 02120212 pattern |
philipel | fab9129 | 2018-10-17 14:36:08 +0200 | [diff] [blame] | 383 | ConvertAndCheck(0, 0, kVideoFrameKey, kNoSync, {}, 480, 360); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 384 | ConvertAndCheck(2, 1, kVideoFrameDelta, kNoSync, {0}); |
| 385 | ConvertAndCheck(1, 2, kVideoFrameDelta, kNoSync, {0}); |
| 386 | ConvertAndCheck(2, 3, kVideoFrameDelta, kNoSync, {0, 1, 2}); |
| 387 | |
| 388 | ConvertAndCheck(0, 4, kVideoFrameDelta, kNoSync, {0}); |
| 389 | ConvertAndCheck(2, 5, kVideoFrameDelta, kNoSync, {2, 3, 4}); |
| 390 | ConvertAndCheck(1, 6, kVideoFrameDelta, kSync, {4}); // layer sync |
| 391 | ConvertAndCheck(2, 7, kVideoFrameDelta, kNoSync, {4, 5, 6}); |
| 392 | } |
| 393 | |
| 394 | TEST_F(RtpPayloadParamsVp8ToGenericTest, FrameIdGaps) { |
| 395 | // 0101 pattern |
philipel | fab9129 | 2018-10-17 14:36:08 +0200 | [diff] [blame] | 396 | ConvertAndCheck(0, 0, kVideoFrameKey, kNoSync, {}, 480, 360); |
philipel | bf2b620 | 2018-08-27 14:33:18 +0200 | [diff] [blame] | 397 | ConvertAndCheck(1, 1, kVideoFrameDelta, kNoSync, {0}); |
| 398 | |
| 399 | ConvertAndCheck(0, 5, kVideoFrameDelta, kNoSync, {0}); |
| 400 | ConvertAndCheck(1, 10, kVideoFrameDelta, kNoSync, {1, 5}); |
| 401 | |
| 402 | ConvertAndCheck(0, 15, kVideoFrameDelta, kNoSync, {5}); |
| 403 | ConvertAndCheck(1, 20, kVideoFrameDelta, kNoSync, {10, 15}); |
| 404 | } |
| 405 | |
Stefan Holmer | f704468 | 2018-07-17 10:16:41 +0200 | [diff] [blame] | 406 | } // namespace webrtc |