Skip to content

Commit

Permalink
Bug 1912989 - Vendor libwebrtc from f237dc146d
Browse files Browse the repository at this point in the history
Upstream commit: https://webrtc.googlesource.com/src/+/f237dc146debcfde3d70038c2b66f71bfea8d24b
    [M128] Ensure calls to QP convergence controller are on the same sequence

    The original CL overlooked the possibility that the encoder may be
    reconfigured in the middle of a stream.

    Restructure the code so that all calls to QP convergence controller
    happen on the encoder queue.

    A side effect of this CL is that `EncodedImage::SetAtTargetQuality()`
    is never called. The information is supplied to the frame cadence
    adapter directly without this intermediate step.

    `EncodedImage::SetAtTargetQuality()` and
    `EncodedImage::IsAtTargetQuality()` are being marked as deprecated
    in https://webrtc-review.googlesource.com/c/src/+/359660.

    (cherry picked from commit b47cd6fbe315690756f2f03e7658d4e26fe27b1e)

    Bug: chromium:359410061
    Change-Id: I941b5f60b1a9fd7694dbedf2f3e4ff5253ccf357
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/359640
    Commit-Queue: Johannes Kron <[email protected]>
    Reviewed-by: Ilya Nikolaevskiy <[email protected]>
    Reviewed-by: Markus Handell <[email protected]>
    Cr-Original-Commit-Position: refs/heads/main@{#42788}
    No-Try: true
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/360240
    Cr-Commit-Position: refs/branch-heads/6613@{mykmelez#3}
    Cr-Branched-From: 1ac162ee20a214bf97f6594a7effcbbc21f1effb-refs/heads/main@{#42664}
  • Loading branch information
Drekabi committed Aug 28, 2024
1 parent bc81116 commit 147cca9
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 17 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 @@ -31776,3 +31776,6 @@ bef5d63112
# MOZ_LIBWEBRTC_SRC=/Users/danielbaker/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
e7686023a1
# MOZ_LIBWEBRTC_SRC=/Users/danielbaker/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
f237dc146d
2 changes: 2 additions & 0 deletions third_party/libwebrtc/README.mozilla
Original file line number Diff line number Diff line change
Expand Up @@ -21208,3 +21208,5 @@ libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc co
libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2024-08-28T17:21:13.694405.
# ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc
libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2024-08-28T17:23:39.728003.
# ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc
libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2024-08-28T17:27:24.493750.
2 changes: 1 addition & 1 deletion third_party/libwebrtc/moz-patch-stack/0079.patch
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Mercurial Revision: https://hg.mozilla.org/mozilla-central/rev/a7179d8d75313b6c9
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc
index af26db8719..7ef6ea5f77 100644
index a9391e0cea..ef3d85f8b4 100644
--- a/video/video_stream_encoder.cc
+++ b/video/video_stream_encoder.cc
@@ -1368,7 +1368,7 @@ void VideoStreamEncoder::ReconfigureEncoder() {
Expand Down
10 changes: 10 additions & 0 deletions third_party/libwebrtc/video/quality_convergence_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void QualityConvergenceController::Initialize(
absl::optional<int> static_qp_threshold,
VideoCodecType codec,
const FieldTrialsView& trials) {
RTC_DCHECK(sequence_checker_.IsCurrent());
RTC_CHECK(number_of_layers > 0);
number_of_layers_ = number_of_layers;
convergence_monitors_.clear();
Expand All @@ -61,11 +62,20 @@ bool QualityConvergenceController::AddSampleAndCheckTargetQuality(
int layer_index,
int qp,
bool is_refresh_frame) {
RTC_DCHECK(sequence_checker_.IsCurrent());
RTC_CHECK(initialized_);
if (layer_index < 0 || layer_index >= number_of_layers_) {
return false;
}

// TODO(kron): Remove temporary check that verifies that the initialization is
// working as expected. See https://crbug.com/359410061.
RTC_DCHECK(number_of_layers_ ==
static_cast<int>(convergence_monitors_.size()));
if (number_of_layers_ != static_cast<int>(convergence_monitors_.size())) {
return false;
}

convergence_monitors_[layer_index]->AddSample(qp, is_refresh_frame);
return convergence_monitors_[layer_index]->AtTargetQuality();
}
Expand Down
2 changes: 2 additions & 0 deletions third_party/libwebrtc/video/quality_convergence_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "absl/types/optional.h"
#include "api/field_trials_view.h"
#include "api/sequence_checker.h"
#include "api/video/video_codec_type.h"
#include "video/quality_convergence_monitor.h"

Expand All @@ -41,6 +42,7 @@ class QualityConvergenceController {
bool initialized_ = false;
int number_of_layers_ = 0;
std::vector<std::unique_ptr<QualityConvergenceMonitor>> convergence_monitors_;
SequenceChecker sequence_checker_{SequenceChecker::kDetached};
};

} // namespace webrtc
Expand Down
24 changes: 9 additions & 15 deletions third_party/libwebrtc/video/video_stream_encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2090,22 +2090,11 @@ EncodedImage VideoStreamEncoder::AugmentEncodedImage(
.value_or(-1);
}

// Check if the encoded image has reached target quality.
const size_t simulcast_index = encoded_image.SimulcastIndex().value_or(0);
bool at_target_quality =
quality_convergence_controller_.AddSampleAndCheckTargetQuality(
simulcast_index, image_copy.qp_,
image_copy.IsSteadyStateRefreshFrame());
image_copy.SetAtTargetQuality(at_target_quality);
TRACE_EVENT2("webrtc", "VideoStreamEncoder::AugmentEncodedImage",
"stream_idx", stream_idx, "qp", image_copy.qp_);
TRACE_EVENT_INSTANT2("webrtc", "VideoStreamEncoder::AugmentEncodedImage",
TRACE_EVENT_SCOPE_GLOBAL, "simulcast_idx",
simulcast_index, "at_target_quality", at_target_quality);
RTC_LOG(LS_VERBOSE) << __func__ << " ntp time " << encoded_image.NtpTimeMs()
<< " stream_idx " << stream_idx << " qp "
<< image_copy.qp_ << " at target quality "
<< at_target_quality;
<< image_copy.qp_;
return image_copy;
}

Expand All @@ -2128,11 +2117,16 @@ EncodedImageCallback::Result VideoStreamEncoder::OnEncodedImage(
unsigned int image_width = image_copy._encodedWidth;
unsigned int image_height = image_copy._encodedHeight;
encoder_queue_->PostTask([this, codec_type, image_width, image_height,
simulcast_index,
at_target_quality =
image_copy.IsAtTargetQuality()] {
simulcast_index, qp = image_copy.qp_,
is_steady_state_refresh_frame =
image_copy.IsSteadyStateRefreshFrame()] {
RTC_DCHECK_RUN_ON(encoder_queue_.get());

// Check if the encoded image has reached target quality.
bool at_target_quality =
quality_convergence_controller_.AddSampleAndCheckTargetQuality(
simulcast_index, qp, is_steady_state_refresh_frame);

// Let the frame cadence adapter know about quality convergence.
if (frame_cadence_adapter_)
frame_cadence_adapter_->UpdateLayerQualityConvergence(simulcast_index,
Expand Down
3 changes: 2 additions & 1 deletion third_party/libwebrtc/video/video_stream_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ class VideoStreamEncoder : public VideoStreamEncoderInterface,
// The quality convergence controller is used to determine if a codec has
// reached its target quality. This is used for screenshare to determine when
// there's no need to continue encoding the same repeated frame.
QualityConvergenceController quality_convergence_controller_;
QualityConvergenceController quality_convergence_controller_
RTC_GUARDED_BY(encoder_queue_);

// Enables encoder switching on initialization failures.
bool switch_encoder_on_init_failures_;
Expand Down

0 comments on commit 147cca9

Please sign in to comment.