Reland of Periodically update codec bit/frame rate settings.
Patch set 1 is a reland + trivial rebase.
Patch set >= 2 contains bug fixes.
> Original issue's description:
> > Fix bug in vie_encoder.cc which caused channel parameters not to be updated at regular intervals, as it was intended.
> >
> > That however exposes a bunch of failed test, so this CL also fixed a few other things:
> > * FakeEncoder should trust the configured FPS value rather than guesstimating itself based on the realtime clock, so as not to completely undershoot targets in offline mode. Also, compensate for key-frame overshoots when outputting delta frames.
> > * FrameDropper should not assuming incoming frame rate is 0 if no frames have been seen.
> > * Fix a bunch of test cases that started failing because they were relying on the fake encoder undershooting.
> > * Fix test
> >
> > BUG=7664
> >
> > Review-Url: https://codereview.webrtc.org/2883963002
> > Cr-Commit-Position: refs/heads/master@{#18473}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/6431e21da672a5f3bbf166d3d4d98b171d015706
BUG=webrtc:7664
Review-Url: https://codereview.webrtc.org/2953053002
Cr-Commit-Position: refs/heads/master@{#18782}
diff --git a/webrtc/media/engine/simulcast.cc b/webrtc/media/engine/simulcast.cc
index 4dd8c31..f1cd2ce 100644
--- a/webrtc/media/engine/simulcast.cc
+++ b/webrtc/media/engine/simulcast.cc
@@ -49,7 +49,7 @@
{0, 0, 1, 200, 150, 30}
};
-const int kMaxScreenshareSimulcastStreams = 2;
+const int kDefaultScreenshareSimulcastStreams = 2;
// Multiway: Number of temporal layers for each simulcast stream, for maximum
// possible number of simulcast streams |kMaxSimulcastStreams|. The array
@@ -176,12 +176,8 @@
bool is_screencast) {
size_t num_simulcast_layers;
if (is_screencast) {
- if (UseSimulcastScreenshare()) {
- num_simulcast_layers =
- std::min<int>(max_streams, kMaxScreenshareSimulcastStreams);
- } else {
- num_simulcast_layers = 1;
- }
+ num_simulcast_layers =
+ UseSimulcastScreenshare() ? kDefaultScreenshareSimulcastStreams : 1;
} else {
num_simulcast_layers = FindSimulcastMaxLayers(width, height);
}
@@ -198,60 +194,33 @@
std::vector<webrtc::VideoStream> streams;
streams.resize(num_simulcast_layers);
- if (is_screencast) {
- ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault();
- // For legacy screenshare in conference mode, tl0 and tl1 bitrates are
- // piggybacked on the VideoCodec struct as target and max bitrates,
- // respectively. See eg. webrtc::VP8EncoderImpl::SetRates().
- streams[0].width = width;
- streams[0].height = height;
- streams[0].max_qp = max_qp;
- streams[0].max_framerate = 5;
- streams[0].min_bitrate_bps = kMinVideoBitrateKbps * 1000;
- streams[0].target_bitrate_bps = config.tl0_bitrate_kbps * 1000;
- streams[0].max_bitrate_bps = config.tl1_bitrate_kbps * 1000;
- streams[0].temporal_layer_thresholds_bps.clear();
- streams[0].temporal_layer_thresholds_bps.push_back(config.tl0_bitrate_kbps *
- 1000);
-
- // With simulcast enabled, add another spatial layer. This one will have a
- // more normal layout, with the regular 3 temporal layer pattern and no fps
- // restrictions. The base simulcast stream will still use legacy setup.
- if (num_simulcast_layers == kMaxScreenshareSimulcastStreams) {
- // Add optional upper simulcast layer.
- // Lowest temporal layers of a 3 layer setup will have 40% of the total
- // bitrate allocation for that stream. Make sure the gap between the
- // target of the lower stream and first temporal layer of the higher one
- // is at most 2x the bitrate, so that upswitching is not hampered by
- // stalled bitrate estimates.
- int max_bitrate_bps = 2 * ((streams[0].target_bitrate_bps * 10) / 4);
- // Cap max bitrate so it isn't overly high for the given resolution.
- max_bitrate_bps = std::min<int>(
- max_bitrate_bps, FindSimulcastMaxBitrateBps(width, height));
-
- streams[1].width = width;
- streams[1].height = height;
- streams[1].max_qp = max_qp;
- streams[1].max_framerate = max_framerate;
- // Three temporal layers means two thresholds.
- streams[1].temporal_layer_thresholds_bps.resize(2);
- streams[1].min_bitrate_bps = streams[0].target_bitrate_bps * 2;
- streams[1].target_bitrate_bps = max_bitrate_bps;
- streams[1].max_bitrate_bps = max_bitrate_bps;
- }
- } else {
+ if (!is_screencast) {
// Format width and height has to be divisible by |2 ^ number_streams - 1|.
width = NormalizeSimulcastSize(width, num_simulcast_layers);
height = NormalizeSimulcastSize(height, num_simulcast_layers);
+ }
- // Add simulcast sub-streams from lower resolution to higher resolutions.
- // Add simulcast streams, from highest resolution (|s| = number_streams -1)
- // to lowest resolution at |s| = 0.
- for (size_t s = num_simulcast_layers - 1;; --s) {
- streams[s].width = width;
- streams[s].height = height;
- // TODO(pbos): Fill actual temporal-layer bitrate thresholds.
- streams[s].max_qp = max_qp;
+ // Add simulcast sub-streams from lower resolution to higher resolutions.
+ // Add simulcast streams, from highest resolution (|s| = number_streams -1)
+ // to lowest resolution at |s| = 0.
+ for (size_t s = num_simulcast_layers - 1;; --s) {
+ streams[s].width = width;
+ streams[s].height = height;
+ // TODO(pbos): Fill actual temporal-layer bitrate thresholds.
+ streams[s].max_qp = max_qp;
+ if (is_screencast && s == 0) {
+ ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault();
+ // For legacy screenshare in conference mode, tl0 and tl1 bitrates are
+ // piggybacked on the VideoCodec struct as target and max bitrates,
+ // respectively. See eg. webrtc::VP8EncoderImpl::SetRates().
+ streams[s].min_bitrate_bps = kMinVideoBitrateKbps * 1000;
+ streams[s].target_bitrate_bps = config.tl0_bitrate_kbps * 1000;
+ streams[s].max_bitrate_bps = config.tl1_bitrate_kbps * 1000;
+ streams[s].temporal_layer_thresholds_bps.clear();
+ streams[s].temporal_layer_thresholds_bps.push_back(
+ config.tl0_bitrate_kbps * 1000);
+ streams[s].max_framerate = 5;
+ } else {
streams[s].temporal_layer_thresholds_bps.resize(
kDefaultConferenceNumberOfTemporalLayers[s] - 1);
streams[s].max_bitrate_bps = FindSimulcastMaxBitrateBps(width, height);
@@ -259,19 +228,20 @@
FindSimulcastTargetBitrateBps(width, height);
streams[s].min_bitrate_bps = FindSimulcastMinBitrateBps(width, height);
streams[s].max_framerate = max_framerate;
+ }
+ if (!is_screencast) {
width /= 2;
height /= 2;
-
- if (s == 0)
- break;
}
+ if (s == 0)
+ break;
+ }
- // Spend additional bits to boost the max stream.
- int bitrate_left_bps = max_bitrate_bps - GetTotalMaxBitrateBps(streams);
- if (bitrate_left_bps > 0) {
- streams.back().max_bitrate_bps += bitrate_left_bps;
- }
+ // Spend additional bits to boost the max stream.
+ int bitrate_left_bps = max_bitrate_bps - GetTotalMaxBitrateBps(streams);
+ if (bitrate_left_bps > 0) {
+ streams.back().max_bitrate_bps += bitrate_left_bps;
}
return streams;