Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit b878179

Browse files
perkjCommit Bot
authored andcommitted
Revert "Refactor reporting of VideoBitrateAllocation"
This reverts commit 39a31af. Reason for revert: Will cause RTCP Target bitrate messages to not be sent unless BWE changes. Original change's description: > Refactor reporting of VideoBitrateAllocation > > Move reporting of target bitrate to just after the encoder has been > updated. > > Bug: webrtc:12000 > Change-Id: I3e7c5bd44c2f64e5f7e32d6451861b80e0b779ca > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/186041 > Commit-Queue: Per Kjellander <[email protected]> > Reviewed-by: Erik Språng <[email protected]> > Cr-Commit-Position: refs/heads/master@{#32275} [email protected],[email protected] # Not skipping CQ checks because original CL landed > 1 day ago. Bug: webrtc:12000 Change-Id: Icf21e6ae28dc17c61b9243c037ffef9b623894ee Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/186945 Reviewed-by: Per Kjellander <[email protected]> Reviewed-by: Erik Språng <[email protected]> Commit-Queue: Per Kjellander <[email protected]> Cr-Commit-Position: refs/heads/master@{#32337}
1 parent 08b6253 commit b878179

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

api/video_codecs/video_encoder.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,6 @@ class RTC_EXPORT VideoEncoder {
267267

268268
// Target bitrate, per spatial/temporal layer.
269269
// A target bitrate of 0bps indicates a layer should not be encoded at all.
270-
VideoBitrateAllocation target_bitrate;
271-
// Adjusted target bitrate, per spatial/temporal layer. May be lower or
272-
// higher than the target depending on encoder behaviour.
273270
VideoBitrateAllocation bitrate;
274271
// Target framerate, in fps. A value <= 0.0 is invalid and should be
275272
// interpreted as framerate target not available. In this case the encoder

video/video_stream_encoder.cc

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ void VideoStreamEncoder::ReconfigureEncoder() {
874874
last_encoder_rate_settings_.reset();
875875
rate_settings.rate_control.framerate_fps = GetInputFramerateFps();
876876

877-
SetEncoderRates(UpdateBitrateAllocation(rate_settings));
877+
SetEncoderRates(UpdateBitrateAllocationAndNotifyObserver(rate_settings));
878878
}
879879

880880
encoder_stats_observer_->OnEncoderReconfigured(encoder_config_, streams);
@@ -1053,7 +1053,7 @@ void VideoStreamEncoder::TraceFrameDropEnd() {
10531053
}
10541054

10551055
VideoStreamEncoder::EncoderRateSettings
1056-
VideoStreamEncoder::UpdateBitrateAllocation(
1056+
VideoStreamEncoder::UpdateBitrateAllocationAndNotifyObserver(
10571057
const EncoderRateSettings& rate_settings) {
10581058
VideoBitrateAllocation new_allocation;
10591059
// Only call allocators if bitrate > 0 (ie, not suspended), otherwise they
@@ -1064,8 +1064,24 @@ VideoStreamEncoder::UpdateBitrateAllocation(
10641064
rate_settings.rate_control.framerate_fps));
10651065
}
10661066

1067+
if (bitrate_observer_ && new_allocation.get_sum_bps() > 0) {
1068+
if (encoder_ && encoder_initialized_) {
1069+
// Avoid too old encoder_info_.
1070+
const int64_t kMaxDiffMs = 100;
1071+
const bool updated_recently =
1072+
(last_encode_info_ms_ && ((clock_->TimeInMilliseconds() -
1073+
*last_encode_info_ms_) < kMaxDiffMs));
1074+
// Update allocation according to info from encoder.
1075+
bitrate_observer_->OnBitrateAllocationUpdated(
1076+
UpdateAllocationFromEncoderInfo(
1077+
new_allocation,
1078+
updated_recently ? encoder_info_ : encoder_->GetEncoderInfo()));
1079+
} else {
1080+
bitrate_observer_->OnBitrateAllocationUpdated(new_allocation);
1081+
}
1082+
}
1083+
10671084
EncoderRateSettings new_rate_settings = rate_settings;
1068-
new_rate_settings.rate_control.target_bitrate = new_allocation;
10691085
new_rate_settings.rate_control.bitrate = new_allocation;
10701086
// VideoBitrateAllocator subclasses may allocate a bitrate higher than the
10711087
// target in order to sustain the min bitrate of the video codec. In this
@@ -1086,6 +1102,9 @@ VideoStreamEncoder::UpdateBitrateAllocation(
10861102
new_rate_settings.rate_control.bitrate = adjusted_allocation;
10871103
}
10881104

1105+
encoder_stats_observer_->OnBitrateAllocationUpdated(
1106+
send_codec_, new_rate_settings.rate_control.bitrate);
1107+
10891108
return new_rate_settings;
10901109
}
10911110

@@ -1109,7 +1128,7 @@ void VideoStreamEncoder::SetEncoderRates(
11091128
last_encoder_rate_settings_ = rate_settings;
11101129
}
11111130

1112-
if (!encoder_ || !rate_control_changed) {
1131+
if (!encoder_) {
11131132
return;
11141133
}
11151134

@@ -1126,22 +1145,13 @@ void VideoStreamEncoder::SetEncoderRates(
11261145
return;
11271146
}
11281147

1148+
if (rate_control_changed) {
11291149
encoder_->SetRates(rate_settings.rate_control);
1130-
1131-
encoder_stats_observer_->OnBitrateAllocationUpdated(
1132-
send_codec_, rate_settings.rate_control.bitrate);
11331150
frame_encode_metadata_writer_.OnSetRates(
11341151
rate_settings.rate_control.bitrate,
11351152
static_cast<uint32_t>(rate_settings.rate_control.framerate_fps + 0.5));
11361153
stream_resource_manager_.SetEncoderRates(rate_settings.rate_control);
1137-
if (bitrate_observer_) {
1138-
bitrate_observer_->OnBitrateAllocationUpdated(
1139-
// Update allocation according to info from encoder. An encoder may
1140-
// choose to not use all layers due to for example HW.
1141-
UpdateAllocationFromEncoderInfo(
1142-
rate_settings.rate_control.target_bitrate,
1143-
encoder_->GetEncoderInfo()));
1144-
}
1154+
}
11451155
}
11461156

11471157
void VideoStreamEncoder::MaybeEncodeVideoFrame(const VideoFrame& video_frame,
@@ -1192,7 +1202,8 @@ void VideoStreamEncoder::MaybeEncodeVideoFrame(const VideoFrame& video_frame,
11921202
EncoderRateSettings new_rate_settings = *last_encoder_rate_settings_;
11931203
new_rate_settings.rate_control.framerate_fps =
11941204
static_cast<double>(framerate_fps);
1195-
SetEncoderRates(UpdateBitrateAllocation(new_rate_settings));
1205+
SetEncoderRates(
1206+
UpdateBitrateAllocationAndNotifyObserver(new_rate_settings));
11961207
}
11971208
last_parameters_update_ms_.emplace(now_ms);
11981209
}
@@ -1727,7 +1738,7 @@ void VideoStreamEncoder::OnBitrateUpdated(DataRate target_bitrate,
17271738
EncoderRateSettings new_rate_settings{
17281739
VideoBitrateAllocation(), static_cast<double>(framerate_fps),
17291740
link_allocation, target_bitrate, stable_target_bitrate};
1730-
SetEncoderRates(UpdateBitrateAllocation(new_rate_settings));
1741+
SetEncoderRates(UpdateBitrateAllocationAndNotifyObserver(new_rate_settings));
17311742

17321743
if (target_bitrate.bps() != 0)
17331744
encoder_target_bitrate_bps_ = target_bitrate.bps();

video/video_stream_encoder.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,9 @@ class VideoStreamEncoder : public VideoStreamEncoderInterface,
192192
void TraceFrameDropEnd();
193193

194194
// Returns a copy of |rate_settings| with the |bitrate| field updated using
195-
// the current VideoBitrateAllocator.
196-
EncoderRateSettings UpdateBitrateAllocation(
195+
// the current VideoBitrateAllocator, and notifies any listeners of the new
196+
// allocation.
197+
EncoderRateSettings UpdateBitrateAllocationAndNotifyObserver(
197198
const EncoderRateSettings& rate_settings) RTC_RUN_ON(&encoder_queue_);
198199

199200
uint32_t GetInputFramerateFps() RTC_RUN_ON(&encoder_queue_);

0 commit comments

Comments
 (0)