Revert "Remove ResourceAdaptationModule::OnMaybeEncodeFrame"

This reverts commit 93d9ae8a17f2e7b90641cbac28e740afc67d383a.

Reason for revert: Perf regression.

Original change's description:
> Remove ResourceAdaptationModule::OnMaybeEncodeFrame
>
> We can react just as well at OnEncodeVideoFrame, which is the same
> behaviour except after checking if the Encoder is paused and the frame
> dropper.
>
> For the initial frame drop, the frame dropper is irrelevant as the frame
> can not be dropped until we are accepting frames. If we didn't drop the
> frame, the encoder can't be paused as the data rate
> is over 0.
>
> For the quality rampup experiment, similar for encoder paused - we can't
> rampup if we are paused anyways since the data rate needs to be non-zero.
> If we are dropping frames we likely don't want to do quality rampup
> anyways.
>
> Bug: webrtc:11222
> Change-Id: Ie3e09d9d8d509dc17ba7a1443cf4747f61c04f6a
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168601
> Reviewed-by: Henrik Boström <hbos@webrtc.org>
> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
> Commit-Queue: Evan Shrubsole <eshr@google.com>
> Cr-Commit-Position: refs/heads/master@{#30539}

TBR=ilnik@webrtc.org,hbos@webrtc.org,eshr@google.com

# Not skipping CQ checks because original CL landed > 1 day ago.

No-Try: True
Bug: webrtc:11222
Change-Id: Ifb2fc74eb7572568fb0ee1b53a09e4180f87b30c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168880
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30568}
This commit is contained in:
Mirko Bonadei 2020-02-20 08:45:01 +00:00 committed by Commit Bot
parent b5ffd47156
commit 2e161c4dd6
4 changed files with 17 additions and 4 deletions

View File

@ -119,7 +119,15 @@ class ResourceAdaptationModuleInterface {
// TODO(hbos): If we take frame rate into account perhaps it would be valid to
// adapt down in frame rate as well.
virtual void OnFrameDroppedDueToSize() = 0;
// 2.ii) An input frame is about to be encoded. It may have been cropped and
// 2.ii) If the frame will not be dropped due to size then signal that it may
// get encoded. However the frame is not guaranteed to be encoded right away
// or ever (for example if encoding is paused).
// TODO(eshr): Try replace OnMaybeEncodeFrame and merge behaviour into
// EncodeStarted.
// TODO(eshr): Try to merge OnFrame, OnFrameDroppedDueToSize, and
// OnMaybeEncode frame into one method.
virtual void OnMaybeEncodeFrame() = 0;
// 2.iii) An input frame is about to be encoded. It may have been cropped and
// have different dimensions than what was observed at OnFrame(). Next
// up: encoding completes or fails, see OnEncodeCompleted(). There is
// currently no signal for encode failure.

View File

@ -367,7 +367,7 @@ class OveruseFrameDetectorResourceAdaptationModule::InitialFrameDropper {
void OnFrameDroppedDueToSize() { ++initial_framedrop_; }
void OnEncodeStarted() { initial_framedrop_ = kMaxInitialFramedrop; }
void OnMaybeEncodeFrame() { initial_framedrop_ = kMaxInitialFramedrop; }
void OnQualityScalerSettingsUpdated() {
if (quality_scaler_resource_->is_started()) {
@ -536,8 +536,6 @@ void OveruseFrameDetectorResourceAdaptationModule::OnFrameDroppedDueToSize() {
void OveruseFrameDetectorResourceAdaptationModule::OnEncodeStarted(
const VideoFrame& cropped_frame,
int64_t time_when_first_seen_us) {
initial_frame_dropper_->OnEncodeStarted();
MaybePerformQualityRampupExperiment();
encode_usage_resource_->OnEncodeStarted(cropped_frame,
time_when_first_seen_us);
}
@ -565,6 +563,11 @@ bool OveruseFrameDetectorResourceAdaptationModule::DropInitialFrames() const {
return initial_frame_dropper_->DropInitialFrames();
}
void OveruseFrameDetectorResourceAdaptationModule::OnMaybeEncodeFrame() {
initial_frame_dropper_->OnMaybeEncodeFrame();
MaybePerformQualityRampupExperiment();
}
void OveruseFrameDetectorResourceAdaptationModule::UpdateQualityScalerSettings(
absl::optional<VideoEncoder::QpThresholds> qp_thresholds) {
if (qp_thresholds.has_value()) {

View File

@ -86,6 +86,7 @@ class OveruseFrameDetectorResourceAdaptationModule
void OnFrame(const VideoFrame& frame) override;
void OnFrameDroppedDueToSize() override;
void OnMaybeEncodeFrame() override;
void OnEncodeStarted(const VideoFrame& cropped_frame,
int64_t time_when_first_seen_us) override;
void OnEncodeCompleted(const EncodedImage& encoded_image,

View File

@ -1080,6 +1080,7 @@ void VideoStreamEncoder::MaybeEncodeVideoFrame(const VideoFrame& video_frame,
}
return;
}
resource_adaptation_module_->OnMaybeEncodeFrame();
if (EncoderPaused()) {
// Storing references to a native buffer risks blocking frame capture.