
This reverts commit c2406e4eaf7703c6c64d21318186adda791e09fd. Reason for revert: Reland by removing the conflict with the broken CL. Original change's description: > Revert "Move allocation and rtp conversion logic out of payload router." > > This reverts commit 1da4d79ba3275b3fa48cad3b2c0949e0d3b7afe7. > > Reason for revert: Need to revert https://webrtc-review.googlesource.com/c/src/+/88220 > > This causes a merge conflict. So need to revert this first. > > Original change's description: > > Move allocation and rtp conversion logic out of payload router. > > > > Makes it easier to write tests, and allows for moving rtp module > > ownership into the payload router in the future. > > > > The RtpPayloadParams class is split into declaration and definition and > > moved into separate files. > > > > Bug: webrtc:9517 > > Change-Id: I8700628edff19abcacfe8d3a20e4ba7476f712ad > > Reviewed-on: https://webrtc-review.googlesource.com/88564 > > Commit-Queue: Stefan Holmer <stefan@webrtc.org> > > Reviewed-by: Sebastian Jansson <srte@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#23983} > > TBR=sprang@webrtc.org,stefan@webrtc.org,srte@webrtc.org > > Change-Id: I342c4bf483d975c87c706fe7f76f44e2dc60fe4c > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:9517 > Reviewed-on: https://webrtc-review.googlesource.com/88821 > Reviewed-by: JT Teh <jtteh@webrtc.org> > Commit-Queue: JT Teh <jtteh@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#23991} TBR=sprang@webrtc.org,stefan@webrtc.org,srte@webrtc.org,lliuu@webrtc.org,jtteh@webrtc.org,tkchin@webrtc.org Change-Id: I154145cdbc668feee86dbe78860147a6954fee6c No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: webrtc:9517 Reviewed-on: https://webrtc-review.googlesource.com/89020 Commit-Queue: Stefan Holmer <stefan@webrtc.org> Reviewed-by: Stefan Holmer <stefan@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23996}
255 lines
9.5 KiB
C++
255 lines
9.5 KiB
C++
/*
|
|
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include <memory>
|
|
|
|
#include "call/payload_router.h"
|
|
#include "modules/video_coding/include/video_codec_interface.h"
|
|
#include "test/gtest.h"
|
|
|
|
namespace webrtc {
|
|
namespace {
|
|
const uint32_t kSsrc1 = 12345;
|
|
const uint32_t kSsrc2 = 23456;
|
|
const int16_t kPictureId = 123;
|
|
const int16_t kTl0PicIdx = 20;
|
|
const uint8_t kTemporalIdx = 1;
|
|
const int16_t kInitialPictureId1 = 222;
|
|
const int16_t kInitialTl0PicIdx1 = 99;
|
|
} // namespace
|
|
|
|
TEST(RtpPayloadParamsTest, InfoMappedToRtpVideoHeader_Vp8) {
|
|
RtpPayloadState state2;
|
|
state2.picture_id = kPictureId;
|
|
state2.tl0_pic_idx = kTl0PicIdx;
|
|
std::map<uint32_t, RtpPayloadState> states = {{kSsrc2, state2}};
|
|
|
|
RtpPayloadParams params(kSsrc2, &state2);
|
|
EncodedImage encoded_image;
|
|
encoded_image.rotation_ = kVideoRotation_90;
|
|
encoded_image.content_type_ = VideoContentType::SCREENSHARE;
|
|
|
|
CodecSpecificInfo codec_info;
|
|
memset(&codec_info, 0, sizeof(CodecSpecificInfo));
|
|
codec_info.codecType = kVideoCodecVP8;
|
|
codec_info.codecSpecific.VP8.simulcastIdx = 1;
|
|
codec_info.codecSpecific.VP8.temporalIdx = kTemporalIdx;
|
|
codec_info.codecSpecific.VP8.keyIdx = kNoKeyIdx;
|
|
codec_info.codecSpecific.VP8.layerSync = true;
|
|
codec_info.codecSpecific.VP8.nonReference = true;
|
|
|
|
RTPVideoHeader header = params.GetRtpVideoHeader(encoded_image, &codec_info);
|
|
|
|
EXPECT_EQ(kVideoRotation_90, header.rotation);
|
|
EXPECT_EQ(VideoContentType::SCREENSHARE, header.content_type);
|
|
EXPECT_EQ(1, header.simulcastIdx);
|
|
EXPECT_EQ(kVideoCodecVP8, header.codec);
|
|
EXPECT_EQ(kPictureId + 1, header.vp8().pictureId);
|
|
EXPECT_EQ(kTemporalIdx, header.vp8().temporalIdx);
|
|
EXPECT_EQ(kTl0PicIdx, header.vp8().tl0PicIdx);
|
|
EXPECT_EQ(kNoKeyIdx, header.vp8().keyIdx);
|
|
EXPECT_TRUE(header.vp8().layerSync);
|
|
EXPECT_TRUE(header.vp8().nonReference);
|
|
}
|
|
|
|
TEST(RtpPayloadParamsTest, InfoMappedToRtpVideoHeader_Vp9) {
|
|
RtpPayloadState state;
|
|
state.picture_id = kPictureId;
|
|
state.tl0_pic_idx = kTl0PicIdx;
|
|
RtpPayloadParams params(kSsrc1, &state);
|
|
|
|
EncodedImage encoded_image;
|
|
encoded_image.rotation_ = kVideoRotation_90;
|
|
encoded_image.content_type_ = VideoContentType::SCREENSHARE;
|
|
|
|
CodecSpecificInfo codec_info;
|
|
memset(&codec_info, 0, sizeof(CodecSpecificInfo));
|
|
codec_info.codecType = kVideoCodecVP9;
|
|
codec_info.codecSpecific.VP9.num_spatial_layers = 3;
|
|
codec_info.codecSpecific.VP9.first_frame_in_picture = true;
|
|
codec_info.codecSpecific.VP9.spatial_idx = 0;
|
|
codec_info.codecSpecific.VP9.temporal_idx = 2;
|
|
codec_info.codecSpecific.VP9.end_of_picture = false;
|
|
|
|
RTPVideoHeader header = params.GetRtpVideoHeader(encoded_image, &codec_info);
|
|
|
|
EXPECT_EQ(kVideoRotation_90, header.rotation);
|
|
EXPECT_EQ(VideoContentType::SCREENSHARE, header.content_type);
|
|
EXPECT_EQ(kVideoCodecVP9, header.codec);
|
|
EXPECT_EQ(kPictureId + 1, header.vp9().picture_id);
|
|
EXPECT_EQ(kTl0PicIdx, header.vp9().tl0_pic_idx);
|
|
EXPECT_EQ(header.vp9().temporal_idx,
|
|
codec_info.codecSpecific.VP9.temporal_idx);
|
|
EXPECT_EQ(header.vp9().spatial_idx, codec_info.codecSpecific.VP9.spatial_idx);
|
|
EXPECT_EQ(header.vp9().num_spatial_layers,
|
|
codec_info.codecSpecific.VP9.num_spatial_layers);
|
|
EXPECT_EQ(header.vp9().end_of_picture,
|
|
codec_info.codecSpecific.VP9.end_of_picture);
|
|
|
|
// Next spatial layer.
|
|
codec_info.codecSpecific.VP9.first_frame_in_picture = false;
|
|
codec_info.codecSpecific.VP9.spatial_idx += 1;
|
|
codec_info.codecSpecific.VP9.end_of_picture = true;
|
|
|
|
header = params.GetRtpVideoHeader(encoded_image, &codec_info);
|
|
|
|
EXPECT_EQ(kVideoRotation_90, header.rotation);
|
|
EXPECT_EQ(VideoContentType::SCREENSHARE, header.content_type);
|
|
EXPECT_EQ(kVideoCodecVP9, header.codec);
|
|
EXPECT_EQ(kPictureId + 1, header.vp9().picture_id);
|
|
EXPECT_EQ(kTl0PicIdx, header.vp9().tl0_pic_idx);
|
|
EXPECT_EQ(header.vp9().temporal_idx,
|
|
codec_info.codecSpecific.VP9.temporal_idx);
|
|
EXPECT_EQ(header.vp9().spatial_idx, codec_info.codecSpecific.VP9.spatial_idx);
|
|
EXPECT_EQ(header.vp9().num_spatial_layers,
|
|
codec_info.codecSpecific.VP9.num_spatial_layers);
|
|
EXPECT_EQ(header.vp9().end_of_picture,
|
|
codec_info.codecSpecific.VP9.end_of_picture);
|
|
}
|
|
|
|
TEST(RtpPayloadParamsTest, InfoMappedToRtpVideoHeader_H264) {
|
|
RtpPayloadParams params(kSsrc1, {});
|
|
|
|
EncodedImage encoded_image;
|
|
CodecSpecificInfo codec_info;
|
|
memset(&codec_info, 0, sizeof(CodecSpecificInfo));
|
|
codec_info.codecType = kVideoCodecH264;
|
|
codec_info.codecSpecific.H264.packetization_mode =
|
|
H264PacketizationMode::SingleNalUnit;
|
|
|
|
RTPVideoHeader header = params.GetRtpVideoHeader(encoded_image, &codec_info);
|
|
|
|
EXPECT_EQ(0, header.simulcastIdx);
|
|
EXPECT_EQ(kVideoCodecH264, header.codec);
|
|
const auto& h264 = absl::get<RTPVideoHeaderH264>(header.video_type_header);
|
|
EXPECT_EQ(H264PacketizationMode::SingleNalUnit, h264.packetization_mode);
|
|
}
|
|
|
|
TEST(RtpPayloadParamsTest, PictureIdIsSetForVp8) {
|
|
RtpPayloadState state;
|
|
state.picture_id = kInitialPictureId1;
|
|
state.tl0_pic_idx = kInitialTl0PicIdx1;
|
|
|
|
EncodedImage encoded_image;
|
|
CodecSpecificInfo codec_info;
|
|
memset(&codec_info, 0, sizeof(CodecSpecificInfo));
|
|
codec_info.codecType = kVideoCodecVP8;
|
|
codec_info.codecSpecific.VP8.simulcastIdx = 0;
|
|
|
|
RtpPayloadParams params(kSsrc1, &state);
|
|
RTPVideoHeader header = params.GetRtpVideoHeader(encoded_image, &codec_info);
|
|
EXPECT_EQ(kVideoCodecVP8, header.codec);
|
|
EXPECT_EQ(kInitialPictureId1 + 1, header.vp8().pictureId);
|
|
|
|
// State should hold latest used picture id and tl0_pic_idx.
|
|
state = params.state();
|
|
EXPECT_EQ(kInitialPictureId1 + 1, state.picture_id);
|
|
EXPECT_EQ(kInitialTl0PicIdx1 + 1, state.tl0_pic_idx);
|
|
}
|
|
|
|
TEST(RtpPayloadParamsTest, PictureIdWraps) {
|
|
RtpPayloadState state;
|
|
state.picture_id = kMaxTwoBytePictureId;
|
|
state.tl0_pic_idx = kInitialTl0PicIdx1;
|
|
|
|
EncodedImage encoded_image;
|
|
CodecSpecificInfo codec_info;
|
|
memset(&codec_info, 0, sizeof(CodecSpecificInfo));
|
|
codec_info.codecType = kVideoCodecVP8;
|
|
codec_info.codecSpecific.VP8.temporalIdx = kNoTemporalIdx;
|
|
|
|
RtpPayloadParams params(kSsrc1, &state);
|
|
RTPVideoHeader header = params.GetRtpVideoHeader(encoded_image, &codec_info);
|
|
EXPECT_EQ(kVideoCodecVP8, header.codec);
|
|
EXPECT_EQ(0, header.vp8().pictureId);
|
|
|
|
// State should hold latest used picture id and tl0_pic_idx.
|
|
EXPECT_EQ(0, params.state().picture_id); // Wrapped.
|
|
EXPECT_EQ(kInitialTl0PicIdx1, params.state().tl0_pic_idx);
|
|
}
|
|
|
|
TEST(RtpPayloadParamsTest, Tl0PicIdxUpdatedForVp8) {
|
|
RtpPayloadState state;
|
|
state.picture_id = kInitialPictureId1;
|
|
state.tl0_pic_idx = kInitialTl0PicIdx1;
|
|
|
|
EncodedImage encoded_image;
|
|
// Modules are sending for this test.
|
|
// OnEncodedImage, temporalIdx: 1.
|
|
CodecSpecificInfo codec_info;
|
|
memset(&codec_info, 0, sizeof(CodecSpecificInfo));
|
|
codec_info.codecType = kVideoCodecVP8;
|
|
codec_info.codecSpecific.VP8.temporalIdx = 1;
|
|
|
|
RtpPayloadParams params(kSsrc1, &state);
|
|
RTPVideoHeader header = params.GetRtpVideoHeader(encoded_image, &codec_info);
|
|
|
|
EXPECT_EQ(kVideoCodecVP8, header.codec);
|
|
EXPECT_EQ(kInitialPictureId1 + 1, header.vp8().pictureId);
|
|
EXPECT_EQ(kInitialTl0PicIdx1, header.vp8().tl0PicIdx);
|
|
|
|
// OnEncodedImage, temporalIdx: 0.
|
|
codec_info.codecSpecific.VP8.temporalIdx = 0;
|
|
|
|
header = params.GetRtpVideoHeader(encoded_image, &codec_info);
|
|
EXPECT_EQ(kVideoCodecVP8, header.codec);
|
|
EXPECT_EQ(kInitialPictureId1 + 2, header.vp8().pictureId);
|
|
EXPECT_EQ(kInitialTl0PicIdx1 + 1, header.vp8().tl0PicIdx);
|
|
|
|
// State should hold latest used picture id and tl0_pic_idx.
|
|
EXPECT_EQ(kInitialPictureId1 + 2, params.state().picture_id);
|
|
EXPECT_EQ(kInitialTl0PicIdx1 + 1, params.state().tl0_pic_idx);
|
|
}
|
|
|
|
TEST(RtpPayloadParamsTest, Tl0PicIdxUpdatedForVp9) {
|
|
RtpPayloadState state;
|
|
state.picture_id = kInitialPictureId1;
|
|
state.tl0_pic_idx = kInitialTl0PicIdx1;
|
|
|
|
EncodedImage encoded_image;
|
|
// Modules are sending for this test.
|
|
// OnEncodedImage, temporalIdx: 1.
|
|
CodecSpecificInfo codec_info;
|
|
memset(&codec_info, 0, sizeof(CodecSpecificInfo));
|
|
codec_info.codecType = kVideoCodecVP9;
|
|
codec_info.codecSpecific.VP9.temporal_idx = 1;
|
|
codec_info.codecSpecific.VP9.first_frame_in_picture = true;
|
|
|
|
RtpPayloadParams params(kSsrc1, &state);
|
|
RTPVideoHeader header = params.GetRtpVideoHeader(encoded_image, &codec_info);
|
|
|
|
EXPECT_EQ(kVideoCodecVP9, header.codec);
|
|
EXPECT_EQ(kInitialPictureId1 + 1, header.vp9().picture_id);
|
|
EXPECT_EQ(kInitialTl0PicIdx1, header.vp9().tl0_pic_idx);
|
|
|
|
// OnEncodedImage, temporalIdx: 0.
|
|
codec_info.codecSpecific.VP9.temporal_idx = 0;
|
|
|
|
header = params.GetRtpVideoHeader(encoded_image, &codec_info);
|
|
|
|
EXPECT_EQ(kVideoCodecVP9, header.codec);
|
|
EXPECT_EQ(kInitialPictureId1 + 2, header.vp9().picture_id);
|
|
EXPECT_EQ(kInitialTl0PicIdx1 + 1, header.vp9().tl0_pic_idx);
|
|
|
|
// OnEncodedImage, first_frame_in_picture = false
|
|
codec_info.codecSpecific.VP9.first_frame_in_picture = false;
|
|
|
|
header = params.GetRtpVideoHeader(encoded_image, &codec_info);
|
|
|
|
EXPECT_EQ(kVideoCodecVP9, header.codec);
|
|
EXPECT_EQ(kInitialPictureId1 + 2, header.vp9().picture_id);
|
|
EXPECT_EQ(kInitialTl0PicIdx1 + 1, header.vp9().tl0_pic_idx);
|
|
|
|
// State should hold latest used picture id and tl0_pic_idx.
|
|
EXPECT_EQ(kInitialPictureId1 + 2, params.state().picture_id);
|
|
EXPECT_EQ(kInitialTl0PicIdx1 + 1, params.state().tl0_pic_idx);
|
|
}
|
|
} // namespace webrtc
|