Don't count frames passed to VP8 BWE disabled streams as being encoded

This excludes these frames from being counted as dropped by encoder.
Also fix bitrate projected distribution for vp9 svc for outliers
detection.

Bug: webrtc:8497
Change-Id: Id37487456170c61e2323a660668f0c319ea5831d
Reviewed-on: https://webrtc-review.googlesource.com/21223
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20632}
This commit is contained in:
Ilya Nikolaevskiy
2017-11-08 14:39:02 +01:00
committed by Commit Bot
parent fb65b10fa1
commit e0da9eab5f
3 changed files with 23 additions and 4 deletions

View File

@ -49,6 +49,7 @@ int32_t VCMGenericEncoder::InitEncode(const VideoCodec* settings,
RTC_DCHECK_RUNS_SERIALIZED(&race_checker_); RTC_DCHECK_RUNS_SERIALIZED(&race_checker_);
TRACE_EVENT0("webrtc", "VCMGenericEncoder::InitEncode"); TRACE_EVENT0("webrtc", "VCMGenericEncoder::InitEncode");
streams_or_svc_num_ = settings->numberOfSimulcastStreams; streams_or_svc_num_ = settings->numberOfSimulcastStreams;
codec_type_ = settings->codecType;
if (settings->codecType == kVideoCodecVP9) { if (settings->codecType == kVideoCodecVP9) {
streams_or_svc_num_ = settings->VP9().numberOfSpatialLayers; streams_or_svc_num_ = settings->VP9().numberOfSpatialLayers;
} }
@ -122,9 +123,16 @@ void VCMGenericEncoder::SetEncoderParameters(const EncoderParameters& params) {
size_t layer_bitrate_bytes_per_sec = size_t layer_bitrate_bytes_per_sec =
params.target_bitrate.GetSpatialLayerSum(i) / 8; params.target_bitrate.GetSpatialLayerSum(i) / 8;
// VP9 rate control is not yet moved out of VP9Impl. Due to that rates // VP9 rate control is not yet moved out of VP9Impl. Due to that rates
// are not split among spatial layers. // are not split among spatial layers. Use default 1:2:4 bitrate
if (layer_bitrate_bytes_per_sec == 0) // distribution.
layer_bitrate_bytes_per_sec = params.target_bitrate.get_sum_bps() / 8; // TODO(ilnik): move bitrate per spatial layer calculations out of
// vp9_impl.cc and drop the check below.
if (codec_type_ == kVideoCodecVP9) {
int scaling_factor_num = 1 << i; // 1, 2 or 4
int scaling_factor_den = (1 << streams_or_svc_num_) - 1; // 1 + 2 + 4
layer_bitrate_bytes_per_sec = params.target_bitrate.get_sum_bps() / 8 *
scaling_factor_num / scaling_factor_den;
}
vcm_encoded_frame_callback_->OnTargetBitrateChanged( vcm_encoded_frame_callback_->OnTargetBitrateChanged(
layer_bitrate_bytes_per_sec, i); layer_bitrate_bytes_per_sec, i);
} }
@ -223,6 +231,10 @@ void VCMEncodedFrameCallback::OnEncodeStarted(int64_t capture_time_ms,
rtc::TimeDiff(capture_time_ms, timing_frames_info_[simulcast_svc_idx] rtc::TimeDiff(capture_time_ms, timing_frames_info_[simulcast_svc_idx]
.encode_start_list.back() .encode_start_list.back()
.capture_time_ms) >= 0); .capture_time_ms) >= 0);
// If stream is disabled due to low bandwidth OnEncodeStarted still will be
// called and have to be ignored.
if (timing_frames_info_[simulcast_svc_idx].target_bitrate_bytes_per_sec == 0)
return;
if (timing_frames_info_[simulcast_svc_idx].encode_start_list.size() == if (timing_frames_info_[simulcast_svc_idx].encode_start_list.size() ==
kMaxEncodeStartTimeListSize) { kMaxEncodeStartTimeListSize) {
RTC_LOG(LS_WARNING) << "Too many frames in the encode_start_list." RTC_LOG(LS_WARNING) << "Too many frames in the encode_start_list."
@ -279,6 +291,9 @@ EncodedImageCallback::Result VCMEncodedFrameCallback::OnEncodedImage(
encode_start_ms.emplace( encode_start_ms.emplace(
encode_start_list->front().encode_start_time_ms); encode_start_list->front().encode_start_time_ms);
encode_start_list->pop_front(); encode_start_list->pop_front();
} else {
LOG(LS_WARNING) << "Frame with no encode started time recordings. "
"Encoder may be reordering frames.";
} }
size_t target_bitrate = size_t target_bitrate =

View File

@ -135,7 +135,8 @@ class VCMGenericEncoder {
const bool internal_source_; const bool internal_source_;
rtc::CriticalSection params_lock_; rtc::CriticalSection params_lock_;
EncoderParameters encoder_params_ RTC_GUARDED_BY(params_lock_); EncoderParameters encoder_params_ RTC_GUARDED_BY(params_lock_);
size_t streams_or_svc_num_; size_t streams_or_svc_num_ RTC_GUARDED_BY(race_checker_);
VideoCodecType codec_type_ RTC_GUARDED_BY(race_checker_);
}; };
} // namespace webrtc } // namespace webrtc

View File

@ -185,6 +185,7 @@ TEST(TestVCMEncodedFrameCallback, NoTimingFrameIfNoEncodeStartTime) {
VideoCodec::TimingFrameTriggerThresholds thresholds; VideoCodec::TimingFrameTriggerThresholds thresholds;
thresholds.delay_ms = 1; // Make all frames timing frames. thresholds.delay_ms = 1; // Make all frames timing frames.
callback.SetTimingFramesThresholds(thresholds); callback.SetTimingFramesThresholds(thresholds);
callback.OnTargetBitrateChanged(500, 0);
// Verify a single frame works with encode start time set. // Verify a single frame works with encode start time set.
callback.OnEncodeStarted(timestamp, 0); callback.OnEncodeStarted(timestamp, 0);
@ -208,6 +209,8 @@ TEST(TestVCMEncodedFrameCallback, NotifiesAboutDroppedFrames) {
codec_specific.codecSpecific.generic.simulcast_idx = 0; codec_specific.codecSpecific.generic.simulcast_idx = 0;
FakeEncodedImageCallback sink; FakeEncodedImageCallback sink;
VCMEncodedFrameCallback callback(&sink, nullptr); VCMEncodedFrameCallback callback(&sink, nullptr);
// Any non-zero bitrate needed to be set before the first frame.
callback.OnTargetBitrateChanged(500, 0);
callback.OnEncodeStarted(timestamp1, 0); callback.OnEncodeStarted(timestamp1, 0);
EXPECT_EQ(0u, sink.GetNumFramesDropped()); EXPECT_EQ(0u, sink.GetNumFramesDropped());
image.capture_time_ms_ = timestamp1; image.capture_time_ms_ = timestamp1;