@@ -874,7 +874,7 @@ void VideoStreamEncoder::ReconfigureEncoder() {
874
874
last_encoder_rate_settings_.reset ();
875
875
rate_settings.rate_control .framerate_fps = GetInputFramerateFps ();
876
876
877
- SetEncoderRates (UpdateBitrateAllocationAndNotifyObserver (rate_settings));
877
+ SetEncoderRates (UpdateBitrateAllocation (rate_settings));
878
878
}
879
879
880
880
encoder_stats_observer_->OnEncoderReconfigured (encoder_config_, streams);
@@ -1053,7 +1053,7 @@ void VideoStreamEncoder::TraceFrameDropEnd() {
1053
1053
}
1054
1054
1055
1055
VideoStreamEncoder::EncoderRateSettings
1056
- VideoStreamEncoder::UpdateBitrateAllocationAndNotifyObserver (
1056
+ VideoStreamEncoder::UpdateBitrateAllocation (
1057
1057
const EncoderRateSettings& rate_settings) {
1058
1058
VideoBitrateAllocation new_allocation;
1059
1059
// Only call allocators if bitrate > 0 (ie, not suspended), otherwise they
@@ -1064,24 +1064,8 @@ VideoStreamEncoder::UpdateBitrateAllocationAndNotifyObserver(
1064
1064
rate_settings.rate_control .framerate_fps ));
1065
1065
}
1066
1066
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
-
1084
1067
EncoderRateSettings new_rate_settings = rate_settings;
1068
+ new_rate_settings.rate_control .target_bitrate = new_allocation;
1085
1069
new_rate_settings.rate_control .bitrate = new_allocation;
1086
1070
// VideoBitrateAllocator subclasses may allocate a bitrate higher than the
1087
1071
// target in order to sustain the min bitrate of the video codec. In this
@@ -1102,9 +1086,6 @@ VideoStreamEncoder::UpdateBitrateAllocationAndNotifyObserver(
1102
1086
new_rate_settings.rate_control .bitrate = adjusted_allocation;
1103
1087
}
1104
1088
1105
- encoder_stats_observer_->OnBitrateAllocationUpdated (
1106
- send_codec_, new_rate_settings.rate_control .bitrate );
1107
-
1108
1089
return new_rate_settings;
1109
1090
}
1110
1091
@@ -1147,11 +1128,22 @@ void VideoStreamEncoder::SetEncoderRates(
1147
1128
1148
1129
if (rate_control_changed) {
1149
1130
encoder_->SetRates (rate_settings.rate_control );
1131
+
1132
+ encoder_stats_observer_->OnBitrateAllocationUpdated (
1133
+ send_codec_, rate_settings.rate_control .bitrate );
1150
1134
frame_encode_metadata_writer_.OnSetRates (
1151
1135
rate_settings.rate_control .bitrate ,
1152
1136
static_cast <uint32_t >(rate_settings.rate_control .framerate_fps + 0.5 ));
1153
1137
stream_resource_manager_.SetEncoderRates (rate_settings.rate_control );
1154
1138
}
1139
+ if (bitrate_observer_) {
1140
+ bitrate_observer_->OnBitrateAllocationUpdated (
1141
+ // Update allocation according to info from encoder. An encoder may
1142
+ // choose to not use all layers due to for example HW.
1143
+ UpdateAllocationFromEncoderInfo (
1144
+ rate_settings.rate_control .target_bitrate ,
1145
+ encoder_->GetEncoderInfo ()));
1146
+ }
1155
1147
}
1156
1148
1157
1149
void VideoStreamEncoder::MaybeEncodeVideoFrame (const VideoFrame& video_frame,
@@ -1202,8 +1194,7 @@ void VideoStreamEncoder::MaybeEncodeVideoFrame(const VideoFrame& video_frame,
1202
1194
EncoderRateSettings new_rate_settings = *last_encoder_rate_settings_;
1203
1195
new_rate_settings.rate_control .framerate_fps =
1204
1196
static_cast <double >(framerate_fps);
1205
- SetEncoderRates (
1206
- UpdateBitrateAllocationAndNotifyObserver (new_rate_settings));
1197
+ SetEncoderRates (UpdateBitrateAllocation (new_rate_settings));
1207
1198
}
1208
1199
last_parameters_update_ms_.emplace (now_ms);
1209
1200
}
@@ -1738,7 +1729,7 @@ void VideoStreamEncoder::OnBitrateUpdated(DataRate target_bitrate,
1738
1729
EncoderRateSettings new_rate_settings{
1739
1730
VideoBitrateAllocation (), static_cast <double >(framerate_fps),
1740
1731
link_allocation, target_bitrate, stable_target_bitrate};
1741
- SetEncoderRates (UpdateBitrateAllocationAndNotifyObserver (new_rate_settings));
1732
+ SetEncoderRates (UpdateBitrateAllocation (new_rate_settings));
1742
1733
1743
1734
if (target_bitrate.bps () != 0 )
1744
1735
encoder_target_bitrate_bps_ = target_bitrate.bps ();
0 commit comments