Move quality scaling frame drop logic to adaptation module
Bug: webrtc:11222
Change-Id: I43db57fa128924ccaa3e44cd58098e7938e5ff5e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168050
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Evan Shrubsole <eshr@google.com>
Cr-Commit-Position: refs/heads/master@{#30445}
diff --git a/call/adaptation/resource_adaptation_module_interface.h b/call/adaptation/resource_adaptation_module_interface.h
index 52b0760..074857d 100644
--- a/call/adaptation/resource_adaptation_module_interface.h
+++ b/call/adaptation/resource_adaptation_module_interface.h
@@ -119,12 +119,15 @@
// currently no signal for encode failure.
virtual void OnEncodeStarted(const VideoFrame& cropped_frame,
int64_t time_when_first_seen_us) = 0;
- // 3. The frame has successfully completed encoding. Next up: The encoded
+ // 3.i) The frame has successfully completed encoding. Next up: The encoded
// frame is dropped or packetized and sent over the network. There is
// currently no signal what happens beyond this point.
virtual void OnEncodeCompleted(const EncodedImage& encoded_image,
int64_t time_sent_in_us,
absl::optional<int> encode_duration_us) = 0;
+ // A frame was dropped at any point in the pipeline. This may come from
+ // the encoder, or elsewhere, like a frame dropper or frame size check.
+ virtual void OnFrameDropped(EncodedImageCallback::DropReason reason) = 0;
};
} // namespace webrtc
diff --git a/video/overuse_frame_detector_resource_adaptation_module.cc b/video/overuse_frame_detector_resource_adaptation_module.cc
index 3fd2204..4403857 100644
--- a/video/overuse_frame_detector_resource_adaptation_module.cc
+++ b/video/overuse_frame_detector_resource_adaptation_module.cc
@@ -484,6 +484,21 @@
quality_scaler_->ReportQp(encoded_image.qp_, time_sent_in_us);
}
+void OveruseFrameDetectorResourceAdaptationModule::OnFrameDropped(
+ EncodedImageCallback::DropReason reason) {
+ if (!quality_scaler_) {
+ return;
+ }
+ switch (reason) {
+ case EncodedImageCallback::DropReason::kDroppedByMediaOptimizations:
+ quality_scaler_->ReportDroppedFrameByMediaOpt();
+ break;
+ case EncodedImageCallback::DropReason::kDroppedByEncoder:
+ quality_scaler_->ReportDroppedFrameByEncoder();
+ break;
+ }
+}
+
void OveruseFrameDetectorResourceAdaptationModule::UpdateQualityScalerSettings(
absl::optional<VideoEncoder::QpThresholds> qp_thresholds) {
if (qp_thresholds.has_value()) {
@@ -874,7 +889,6 @@
return balanced_settings_.GetQpThresholds(GetVideoCodecTypeOrGeneric(),
LastInputFrameSizeOrDefault());
}
-
bool OveruseFrameDetectorResourceAdaptationModule::CanAdaptUpResolution(
int pixels,
uint32_t bitrate_bps) const {
diff --git a/video/overuse_frame_detector_resource_adaptation_module.h b/video/overuse_frame_detector_resource_adaptation_module.h
index 8cc8242..21c055b 100644
--- a/video/overuse_frame_detector_resource_adaptation_module.h
+++ b/video/overuse_frame_detector_resource_adaptation_module.h
@@ -84,6 +84,7 @@
void OnEncodeCompleted(const EncodedImage& encoded_image,
int64_t time_sent_in_us,
absl::optional<int> encode_duration_us) override;
+ void OnFrameDropped(EncodedImageCallback::DropReason reason) override;
// Use nullopt to disable quality scaling.
void UpdateQualityScalerSettings(
diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc
index 335532c..cf71271 100644
--- a/video/video_stream_encoder.cc
+++ b/video/video_stream_encoder.cc
@@ -1547,27 +1547,17 @@
case DropReason::kDroppedByMediaOptimizations:
encoder_stats_observer_->OnFrameDropped(
VideoStreamEncoderObserver::DropReason::kMediaOptimization);
- encoder_queue_.PostTask([this] {
- RTC_DCHECK_RUN_ON(&encoder_queue_);
- QualityScaler* quality_scaler =
- resource_adaptation_module_->quality_scaler();
- if (quality_scaler)
- quality_scaler->ReportDroppedFrameByMediaOpt();
- });
break;
case DropReason::kDroppedByEncoder:
encoder_stats_observer_->OnFrameDropped(
VideoStreamEncoderObserver::DropReason::kEncoder);
- encoder_queue_.PostTask([this] {
- RTC_DCHECK_RUN_ON(&encoder_queue_);
- QualityScaler* quality_scaler =
- resource_adaptation_module_->quality_scaler();
- if (quality_scaler)
- quality_scaler->ReportDroppedFrameByEncoder();
- });
break;
}
sink_->OnDroppedFrame(reason);
+ encoder_queue_.PostTask([this, reason] {
+ RTC_DCHECK_RUN_ON(&encoder_queue_);
+ resource_adaptation_module_->OnFrameDropped(reason);
+ });
}
void VideoStreamEncoder::OnBitrateUpdated(DataRate target_bitrate,