You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

564 lines
21 KiB

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