Skip to content

Commit

Permalink
Bug 1847074 - Vendor libwebrtc from 6603550a42
Browse files Browse the repository at this point in the history
Upstream commit: https://webrtc.googlesource.com/src/+/6603550a4279b4b68b8b763523370dc8e010500c
    [Merge-M115] Support conversion of VP9 non-flexible mode to generic descriptor for non-layered streams only.

    When VP9 HW encoders don't provide any metadata a minimal non-flexible mode structure is generated for the stream: (https://source.chromium.org/chromium/chromium/src/+/refs/heads/main:third_party/blink/renderer/platform/peerconnection/rtc_video_encoder.cc;l=1275-1298;drc=f80633b34538615fcb73515ad8c4bc56a748abfe).

    (cherry picked from commit 4e0bf2e5a1946b8f94f4b23b57b3e89a25fce65d)

    Bug: chromium:1455428, b/286993839, b/287458300
    Change-Id: I72628f20927d685e9c8ba1744126d763896bd804
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/309380
    Commit-Queue: Philip Eliasson <philipel@webrtc.org>
    Reviewed-by: Erik Språng <sprang@webrtc.org>
    Reviewed-by: Henrik Boström <hbos@webrtc.org>
    Cr-Original-Commit-Position: refs/heads/main@{#40316}
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/309921
    Commit-Queue: Henrik Boström <hbos@webrtc.org>
    Cr-Commit-Position: refs/branch-heads/5790@{#5}
    Cr-Branched-From: 2eacbbc03a4a41ea658661225eb1c8fc07884c33-refs/heads/main@{#40122}
  • Loading branch information
mfromanmoz committed Aug 14, 2023
1 parent 9e4f656 commit 6b8f918
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 14 deletions.
3 changes: 3 additions & 0 deletions third_party/libwebrtc/README.moz-ff-commit
Original file line number Diff line number Diff line change
Expand Up @@ -24036,3 +24036,6 @@ f0d954f659
# MOZ_LIBWEBRTC_SRC=/home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc MOZ_LIBWEBRTC_BRANCH=mozpatches bash dom/media/webrtc/third_party_build/fast-forward-libwebrtc.sh
# base of lastest vendoring
f5ffd45855
# MOZ_LIBWEBRTC_SRC=/home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc MOZ_LIBWEBRTC_BRANCH=mozpatches bash dom/media/webrtc/third_party_build/fast-forward-libwebrtc.sh
# base of lastest vendoring
6603550a42
2 changes: 2 additions & 0 deletions third_party/libwebrtc/README.mozilla
Original file line number Diff line number Diff line change
Expand Up @@ -16046,3 +16046,5 @@ libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc
libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2023-08-14T19:56:07.476855.
# ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc
libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2023-08-14T19:57:58.881726.
# ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc
libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2023-08-14T19:58:55.023984.
47 changes: 33 additions & 14 deletions third_party/libwebrtc/call/rtp_payload_params.cc
Original file line number Diff line number Diff line change
Expand Up @@ -604,23 +604,42 @@ void RtpPayloadParams::Vp9ToGeneric(const CodecSpecificInfoVP9& vp9_info,
// Create the array only if it is ever used.
last_vp9_frame_id_.resize(kPictureDiffLimit);
}
if (vp9_header.inter_layer_predicted && spatial_index > 0) {
result.dependencies.push_back(
last_vp9_frame_id_[vp9_header.picture_id % kPictureDiffLimit]
[spatial_index - 1]);
}
if (vp9_header.inter_pic_predicted) {
for (size_t i = 0; i < vp9_header.num_ref_pics; ++i) {
// picture_id is 15 bit number that wraps around. Though undeflow may
// produce picture that exceeds 2^15, it is ok because in this
// code block only last 7 bits of the picture_id are used.
uint16_t depend_on = vp9_header.picture_id - vp9_header.pid_diff[i];

if (vp9_header.flexible_mode) {
if (vp9_header.inter_layer_predicted && spatial_index > 0) {
result.dependencies.push_back(
last_vp9_frame_id_[depend_on % kPictureDiffLimit][spatial_index]);
last_vp9_frame_id_[vp9_header.picture_id % kPictureDiffLimit]
[spatial_index - 1]);
}
if (vp9_header.inter_pic_predicted) {
for (size_t i = 0; i < vp9_header.num_ref_pics; ++i) {
// picture_id is 15 bit number that wraps around. Though undeflow may
// produce picture that exceeds 2^15, it is ok because in this
// code block only last 7 bits of the picture_id are used.
uint16_t depend_on = vp9_header.picture_id - vp9_header.pid_diff[i];
result.dependencies.push_back(
last_vp9_frame_id_[depend_on % kPictureDiffLimit][spatial_index]);
}
}
last_vp9_frame_id_[vp9_header.picture_id % kPictureDiffLimit]
[spatial_index] = shared_frame_id;
} else {
// Implementing general conversion logic for non-flexible mode requires some
// work and we will almost certainly never need it, so for now support only
// non-layerd streams.
if (spatial_index > 0 || temporal_index > 0) {
// Prefer to generate no generic layering than an inconsistent one.
rtp_video_header.generic.reset();
return;
}

if (vp9_header.inter_pic_predicted) {
// Since we only support non-scalable streams we only need to save the
// last frame id.
result.dependencies.push_back(last_vp9_frame_id_[0][0]);
}
last_vp9_frame_id_[0][0] = shared_frame_id;
}
last_vp9_frame_id_[vp9_header.picture_id % kPictureDiffLimit][spatial_index] =
shared_frame_id;

result.active_decode_targets =
((uint32_t{1} << num_temporal_layers * num_active_spatial_layers) - 1);
Expand Down
54 changes: 54 additions & 0 deletions third_party/libwebrtc/call/rtp_payload_params_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ TEST(RtpPayloadParamsVp9ToGenericTest, NoScalability) {
EncodedImage encoded_image;
CodecSpecificInfo codec_info;
codec_info.codecType = kVideoCodecVP9;
codec_info.codecSpecific.VP9.flexible_mode = true;
codec_info.codecSpecific.VP9.num_spatial_layers = 1;
codec_info.codecSpecific.VP9.temporal_idx = kNoTemporalIdx;
codec_info.codecSpecific.VP9.first_frame_in_picture = true;
Expand Down Expand Up @@ -611,6 +612,55 @@ TEST(RtpPayloadParamsVp9ToGenericTest, NoScalability) {
EXPECT_EQ(header.generic->chain_diffs[0], 3 - 1);
}

TEST(RtpPayloadParamsVp9ToGenericTest, NoScalabilityNonFlexibleMode) {
RtpPayloadState state;
RtpPayloadParams params(/*ssrc=*/123, &state, FieldTrialBasedConfig());

EncodedImage encoded_image;
CodecSpecificInfo codec_info;
codec_info.codecType = kVideoCodecVP9;
codec_info.codecSpecific.VP9.flexible_mode = false;
codec_info.codecSpecific.VP9.num_spatial_layers = 1;
codec_info.codecSpecific.VP9.temporal_idx = kNoTemporalIdx;
codec_info.codecSpecific.VP9.first_frame_in_picture = true;
codec_info.end_of_picture = true;

// Key frame.
encoded_image._frameType = VideoFrameType::kVideoFrameKey;
codec_info.codecSpecific.VP9.inter_pic_predicted = false;
RTPVideoHeader key_header =
params.GetRtpVideoHeader(encoded_image, &codec_info,
/*shared_frame_id=*/1);

ASSERT_TRUE(key_header.generic);
EXPECT_EQ(key_header.generic->spatial_index, 0);
EXPECT_EQ(key_header.generic->temporal_index, 0);
EXPECT_EQ(key_header.generic->frame_id, 1);
ASSERT_THAT(key_header.generic->decode_target_indications, Not(IsEmpty()));
EXPECT_EQ(key_header.generic->decode_target_indications[0],
DecodeTargetIndication::kSwitch);
EXPECT_THAT(key_header.generic->dependencies, IsEmpty());
ASSERT_THAT(key_header.generic->chain_diffs, Not(IsEmpty()));
EXPECT_EQ(key_header.generic->chain_diffs[0], 0);

encoded_image._frameType = VideoFrameType::kVideoFrameDelta;
codec_info.codecSpecific.VP9.inter_pic_predicted = true;
RTPVideoHeader delta_header =
params.GetRtpVideoHeader(encoded_image, &codec_info,
/*shared_frame_id=*/3);

ASSERT_TRUE(delta_header.generic);
EXPECT_EQ(delta_header.generic->spatial_index, 0);
EXPECT_EQ(delta_header.generic->temporal_index, 0);
EXPECT_EQ(delta_header.generic->frame_id, 3);
ASSERT_THAT(delta_header.generic->decode_target_indications, Not(IsEmpty()));
EXPECT_EQ(delta_header.generic->decode_target_indications[0],
DecodeTargetIndication::kSwitch);
EXPECT_THAT(delta_header.generic->dependencies, ElementsAre(1));
ASSERT_THAT(delta_header.generic->chain_diffs, Not(IsEmpty()));
EXPECT_EQ(delta_header.generic->chain_diffs[0], 3 - 1);
}

TEST(RtpPayloadParamsVp9ToGenericTest, TemporalScalabilityWith2Layers) {
// Test with 2 temporal layers structure that is not used by webrtc:
// 1---3 5
Expand All @@ -622,6 +672,7 @@ TEST(RtpPayloadParamsVp9ToGenericTest, TemporalScalabilityWith2Layers) {
EncodedImage image;
CodecSpecificInfo info;
info.codecType = kVideoCodecVP9;
info.codecSpecific.VP9.flexible_mode = true;
info.codecSpecific.VP9.num_spatial_layers = 1;
info.codecSpecific.VP9.first_frame_in_picture = true;
info.end_of_picture = true;
Expand Down Expand Up @@ -732,6 +783,7 @@ TEST(RtpPayloadParamsVp9ToGenericTest, TemporalScalabilityWith3Layers) {
EncodedImage image;
CodecSpecificInfo info;
info.codecType = kVideoCodecVP9;
info.codecSpecific.VP9.flexible_mode = true;
info.codecSpecific.VP9.num_spatial_layers = 1;
info.codecSpecific.VP9.first_frame_in_picture = true;
info.end_of_picture = true;
Expand Down Expand Up @@ -885,6 +937,7 @@ TEST(RtpPayloadParamsVp9ToGenericTest, SpatialScalabilityKSvc) {
EncodedImage image;
CodecSpecificInfo info;
info.codecType = kVideoCodecVP9;
info.codecSpecific.VP9.flexible_mode = true;
info.codecSpecific.VP9.num_spatial_layers = 2;
info.codecSpecific.VP9.first_frame_in_picture = true;

Expand Down Expand Up @@ -993,6 +1046,7 @@ TEST(RtpPayloadParamsVp9ToGenericTest,
EncodedImage image;
CodecSpecificInfo info;
info.codecType = kVideoCodecVP9;
info.codecSpecific.VP9.flexible_mode = true;
info.codecSpecific.VP9.num_spatial_layers = 1;
info.codecSpecific.VP9.first_frame_in_picture = true;

Expand Down

0 comments on commit 6b8f918

Please sign in to comment.