Skip to content

Commit 317005a

Browse files
sprangCommit Bot
sprang
authored and
Commit Bot
committed
Revert of Periodically update codec bit/frame rate settings. (patchset #2 id:160001 of https://codereview.webrtc.org/2924023002/ )
Reason for revert: Looks like there's still one failing perf test: RampUpTest.UpDownUpTransportSequenceNumberPacketLoss Original issue's description: > Reland of Periodically update codec bit/frame rate settings. (patchset #1 id:1 of https://codereview.webrtc.org/2923993002/ ) > > Reason for revert: > Create reland cl that we can patch with fix. > > Original issue's description: > > Revert of Periodically update codec bit/frame rate settings. (patchset #8 id:140001 of https://codereview.webrtc.org/2883963002/ ) > > > > Reason for revert: > > Breaks some Call perf tests that are not run by the try bots.... > > > > 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 > > > > [email protected],[email protected] > > # Skipping CQ checks because original CL landed less than 1 days ago. > > NOPRESUBMIT=true > > NOTREECHECKS=true > > NOTRY=true > > BUG=7664 > > > > Review-Url: https://codereview.webrtc.org/2923993002 > > Cr-Commit-Position: refs/heads/master@{#18475} > > Committed: https://chromium.googlesource.com/external/webrtc/+/5390c4814d7880ea79edcd55596ea25e0d9b97ad > > [email protected],[email protected] > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=7664 > > Review-Url: https://codereview.webrtc.org/2924023002 > Cr-Commit-Position: refs/heads/master@{#18497} > Committed: https://chromium.googlesource.com/external/webrtc/+/cdafeda1cb95ac49104b2cc5112bab8def863818 [email protected] # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=7664 Review-Url: https://codereview.webrtc.org/2926283002 Cr-Commit-Position: refs/heads/master@{#18500}
1 parent d3a8119 commit 317005a

File tree

8 files changed

+257
-373
lines changed

8 files changed

+257
-373
lines changed

webrtc/media/engine/simulcast.cc

+65-35
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const SimulcastFormat kSimulcastFormats[] = {
4949
{0, 0, 1, 200, 150, 30}
5050
};
5151

52-
const int kDefaultScreenshareSimulcastStreams = 2;
52+
const int kMaxScreenshareSimulcastStreams = 2;
5353

5454
// Multiway: Number of temporal layers for each simulcast stream, for maximum
5555
// possible number of simulcast streams |kMaxSimulcastStreams|. The array
@@ -176,8 +176,12 @@ std::vector<webrtc::VideoStream> GetSimulcastConfig(size_t max_streams,
176176
bool is_screencast) {
177177
size_t num_simulcast_layers;
178178
if (is_screencast) {
179-
num_simulcast_layers =
180-
UseSimulcastScreenshare() ? kDefaultScreenshareSimulcastStreams : 1;
179+
if (UseSimulcastScreenshare()) {
180+
num_simulcast_layers =
181+
std::min<int>(max_streams, kMaxScreenshareSimulcastStreams);
182+
} else {
183+
num_simulcast_layers = 1;
184+
}
181185
} else {
182186
num_simulcast_layers = FindSimulcastMaxLayers(width, height);
183187
}
@@ -194,54 +198,80 @@ std::vector<webrtc::VideoStream> GetSimulcastConfig(size_t max_streams,
194198
std::vector<webrtc::VideoStream> streams;
195199
streams.resize(num_simulcast_layers);
196200

197-
if (!is_screencast) {
201+
if (is_screencast) {
202+
ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault();
203+
// For legacy screenshare in conference mode, tl0 and tl1 bitrates are
204+
// piggybacked on the VideoCodec struct as target and max bitrates,
205+
// respectively. See eg. webrtc::VP8EncoderImpl::SetRates().
206+
streams[0].width = width;
207+
streams[0].height = height;
208+
streams[0].max_qp = max_qp;
209+
streams[0].max_framerate = 5;
210+
streams[0].min_bitrate_bps = kMinVideoBitrateKbps * 1000;
211+
streams[0].target_bitrate_bps = config.tl0_bitrate_kbps * 1000;
212+
streams[0].max_bitrate_bps = config.tl1_bitrate_kbps * 1000;
213+
streams[0].temporal_layer_thresholds_bps.clear();
214+
streams[0].temporal_layer_thresholds_bps.push_back(config.tl0_bitrate_kbps *
215+
1000);
216+
217+
// With simulcast enabled, add another spatial layer. This one will have a
218+
// more normal layout, with the regular 3 temporal layer pattern and no fps
219+
// restrictions. The base simulcast stream will still use legacy setup.
220+
if (num_simulcast_layers == kMaxScreenshareSimulcastStreams) {
221+
// Add optional upper simulcast layer.
222+
// Lowest temporal layers of a 3 layer setup will have 40% of the total
223+
// bitrate allocation for that stream. Make sure the gap between the
224+
// target of the lower stream and first temporal layer of the higher one
225+
// is at most 2x the bitrate, so that upswitching is not hampered by
226+
// stalled bitrate estimates.
227+
int max_bitrate_bps = 2 * ((streams[0].target_bitrate_bps * 10) / 4);
228+
// Cap max bitrate so it isn't overly high for the given resolution.
229+
max_bitrate_bps = std::min<int>(
230+
max_bitrate_bps, FindSimulcastMaxBitrateBps(width, height));
231+
232+
streams[1].width = width;
233+
streams[1].height = height;
234+
streams[1].max_qp = max_qp;
235+
streams[1].max_framerate = max_framerate;
236+
// Three temporal layers means two thresholds.
237+
streams[1].temporal_layer_thresholds_bps.resize(2);
238+
streams[1].min_bitrate_bps = streams[0].target_bitrate_bps * 2;
239+
streams[1].target_bitrate_bps = max_bitrate_bps;
240+
streams[1].max_bitrate_bps = max_bitrate_bps;
241+
}
242+
} else {
198243
// Format width and height has to be divisible by |2 ^ number_streams - 1|.
199244
width = NormalizeSimulcastSize(width, num_simulcast_layers);
200245
height = NormalizeSimulcastSize(height, num_simulcast_layers);
201-
}
202246

203-
// Add simulcast sub-streams from lower resolution to higher resolutions.
204-
// Add simulcast streams, from highest resolution (|s| = number_streams -1)
205-
// to lowest resolution at |s| = 0.
206-
for (size_t s = num_simulcast_layers - 1;; --s) {
207-
streams[s].width = width;
208-
streams[s].height = height;
209-
// TODO(pbos): Fill actual temporal-layer bitrate thresholds.
210-
streams[s].max_qp = max_qp;
211-
if (is_screencast && s == 0) {
212-
ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault();
213-
// For legacy screenshare in conference mode, tl0 and tl1 bitrates are
214-
// piggybacked on the VideoCodec struct as target and max bitrates,
215-
// respectively. See eg. webrtc::VP8EncoderImpl::SetRates().
216-
streams[s].min_bitrate_bps = kMinVideoBitrateKbps * 1000;
217-
streams[s].target_bitrate_bps = config.tl0_bitrate_kbps * 1000;
218-
streams[s].max_bitrate_bps = config.tl1_bitrate_kbps * 1000;
219-
streams[s].temporal_layer_thresholds_bps.clear();
220-
streams[s].temporal_layer_thresholds_bps.push_back(
221-
config.tl0_bitrate_kbps * 1000);
222-
streams[s].max_framerate = 5;
223-
} else {
247+
// Add simulcast sub-streams from lower resolution to higher resolutions.
248+
// Add simulcast streams, from highest resolution (|s| = number_streams -1)
249+
// to lowest resolution at |s| = 0.
250+
for (size_t s = num_simulcast_layers - 1;; --s) {
251+
streams[s].width = width;
252+
streams[s].height = height;
253+
// TODO(pbos): Fill actual temporal-layer bitrate thresholds.
254+
streams[s].max_qp = max_qp;
224255
streams[s].temporal_layer_thresholds_bps.resize(
225256
kDefaultConferenceNumberOfTemporalLayers[s] - 1);
226257
streams[s].max_bitrate_bps = FindSimulcastMaxBitrateBps(width, height);
227258
streams[s].target_bitrate_bps =
228259
FindSimulcastTargetBitrateBps(width, height);
229260
streams[s].min_bitrate_bps = FindSimulcastMinBitrateBps(width, height);
230261
streams[s].max_framerate = max_framerate;
231-
}
232262

233-
if (!is_screencast) {
234263
width /= 2;
235264
height /= 2;
265+
266+
if (s == 0)
267+
break;
236268
}
237-
if (s == 0)
238-
break;
239-
}
240269

241-
// Spend additional bits to boost the max stream.
242-
int bitrate_left_bps = max_bitrate_bps - GetTotalMaxBitrateBps(streams);
243-
if (bitrate_left_bps > 0) {
244-
streams.back().max_bitrate_bps += bitrate_left_bps;
270+
// Spend additional bits to boost the max stream.
271+
int bitrate_left_bps = max_bitrate_bps - GetTotalMaxBitrateBps(streams);
272+
if (bitrate_left_bps > 0) {
273+
streams.back().max_bitrate_bps += bitrate_left_bps;
274+
}
245275
}
246276

247277
return streams;

webrtc/modules/video_coding/media_optimization.cc

+1-7
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,7 @@ uint32_t MediaOptimization::SetTargetRates(uint32_t target_bitrate) {
118118
// Update encoding rates following protection settings.
119119
float target_video_bitrate_kbps =
120120
static_cast<float>(video_target_bitrate_) / 1000.0f;
121-
float framerate = incoming_frame_rate_;
122-
if (framerate == 0.0) {
123-
// No framerate estimate available, use configured max framerate instead.
124-
framerate = user_frame_rate_;
125-
}
126-
127-
frame_dropper_->SetRates(target_video_bitrate_kbps, framerate);
121+
frame_dropper_->SetRates(target_video_bitrate_kbps, incoming_frame_rate_);
128122

129123
return video_target_bitrate_;
130124
}

webrtc/modules/video_coding/video_sender.cc

-5
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,6 @@ int32_t VideoSender::RegisterSendCodec(const VideoCodec* sendCodec,
103103
numLayers = sendCodec->VP8().numberOfTemporalLayers;
104104
} else if (sendCodec->codecType == kVideoCodecVP9) {
105105
numLayers = sendCodec->VP9().numberOfTemporalLayers;
106-
} else if (sendCodec->codecType == kVideoCodecGeneric &&
107-
sendCodec->numberOfSimulcastStreams > 0) {
108-
// This is mainly for unit testing, disabling frame dropping.
109-
// TODO(sprang): Add a better way to disable frame dropping.
110-
numLayers = sendCodec->simulcastStream[0].numberOfTemporalLayers;
111106
} else {
112107
numLayers = 1;
113108
}

webrtc/test/fake_encoder.cc

+36-48
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,11 @@
2424
namespace webrtc {
2525
namespace test {
2626

27-
const int kKeyframeSizeFactor = 10;
28-
2927
FakeEncoder::FakeEncoder(Clock* clock)
3028
: clock_(clock),
3129
callback_(nullptr),
32-
configured_input_framerate_(-1),
3330
max_target_bitrate_kbps_(-1),
34-
pending_keyframe_(true),
35-
debt_bytes_(0) {
31+
last_encode_time_ms_(0) {
3632
// Generate some arbitrary not-all-zero data
3733
for (size_t i = 0; i < sizeof(encoded_buffer_); ++i) {
3834
encoded_buffer_[i] = static_cast<uint8_t>(i);
@@ -51,8 +47,6 @@ int32_t FakeEncoder::InitEncode(const VideoCodec* config,
5147
rtc::CritScope cs(&crit_sect_);
5248
config_ = *config;
5349
target_bitrate_.SetBitrate(0, 0, config_.startBitrate * 1000);
54-
configured_input_framerate_ = config_.maxFramerate;
55-
pending_keyframe_ = true;
5650
return 0;
5751
}
5852

@@ -65,10 +59,9 @@ int32_t FakeEncoder::Encode(const VideoFrame& input_image,
6559
EncodedImageCallback* callback;
6660
uint32_t target_bitrate_sum_kbps;
6761
int max_target_bitrate_kbps;
62+
int64_t last_encode_time_ms;
6863
size_t num_encoded_bytes;
69-
int framerate;
7064
VideoCodecMode mode;
71-
bool keyframe;
7265
{
7366
rtc::CritScope cs(&crit_sect_);
7467
max_framerate = config_.maxFramerate;
@@ -79,32 +72,42 @@ int32_t FakeEncoder::Encode(const VideoFrame& input_image,
7972
callback = callback_;
8073
target_bitrate_sum_kbps = target_bitrate_.get_sum_kbps();
8174
max_target_bitrate_kbps = max_target_bitrate_kbps_;
75+
last_encode_time_ms = last_encode_time_ms_;
8276
num_encoded_bytes = sizeof(encoded_buffer_);
8377
mode = config_.mode;
84-
if (configured_input_framerate_ > 0) {
85-
framerate = configured_input_framerate_;
86-
} else {
87-
framerate = max_framerate;
88-
}
89-
keyframe = pending_keyframe_;
90-
pending_keyframe_ = false;
9178
}
9279

93-
for (FrameType frame_type : *frame_types) {
94-
if (frame_type == kVideoFrameKey) {
95-
keyframe = true;
96-
break;
97-
}
80+
int64_t time_now_ms = clock_->TimeInMilliseconds();
81+
const bool first_encode = (last_encode_time_ms == 0);
82+
RTC_DCHECK_GT(max_framerate, 0);
83+
int64_t time_since_last_encode_ms = 1000 / max_framerate;
84+
if (!first_encode) {
85+
// For all frames but the first we can estimate the display time by looking
86+
// at the display time of the previous frame.
87+
time_since_last_encode_ms = time_now_ms - last_encode_time_ms;
88+
}
89+
if (time_since_last_encode_ms > 3 * 1000 / max_framerate) {
90+
// Rudimentary check to make sure we don't widely overshoot bitrate target
91+
// when resuming encoding after a suspension.
92+
time_since_last_encode_ms = 3 * 1000 / max_framerate;
9893
}
9994

100-
RTC_DCHECK_GT(max_framerate, 0);
95+
size_t bits_available =
96+
static_cast<size_t>(target_bitrate_sum_kbps * time_since_last_encode_ms);
97+
size_t min_bits = static_cast<size_t>(simulcast_streams[0].minBitrate *
98+
time_since_last_encode_ms);
10199

102-
size_t bitrate =
103-
std::max(target_bitrate_sum_kbps, simulcast_streams[0].minBitrate);
104-
if (max_target_bitrate_kbps > 0)
105-
bitrate = std::min(bitrate, static_cast<size_t>(max_target_bitrate_kbps));
100+
if (bits_available < min_bits)
101+
bits_available = min_bits;
102+
size_t max_bits =
103+
static_cast<size_t>(max_target_bitrate_kbps * time_since_last_encode_ms);
104+
if (max_bits > 0 && max_bits < bits_available)
105+
bits_available = max_bits;
106106

107-
size_t bits_available = bitrate * 1000 / framerate;
107+
{
108+
rtc::CritScope cs(&crit_sect_);
109+
last_encode_time_ms_ = time_now_ms;
110+
}
108111

109112
RTC_DCHECK_GT(num_simulcast_streams, 0);
110113
for (unsigned char i = 0; i < num_simulcast_streams; ++i) {
@@ -113,27 +116,18 @@ int32_t FakeEncoder::Encode(const VideoFrame& input_image,
113116
specifics.codecType = kVideoCodecGeneric;
114117
specifics.codecSpecific.generic.simulcast_idx = i;
115118
size_t min_stream_bits = static_cast<size_t>(
116-
(simulcast_streams[i].minBitrate * 1000) / framerate);
119+
simulcast_streams[i].minBitrate * time_since_last_encode_ms);
117120
size_t max_stream_bits = static_cast<size_t>(
118-
(simulcast_streams[i].maxBitrate * 1000) / framerate);
121+
simulcast_streams[i].maxBitrate * time_since_last_encode_ms);
119122
size_t stream_bits = (bits_available > max_stream_bits) ? max_stream_bits :
120123
bits_available;
121124
size_t stream_bytes = (stream_bits + 7) / 8;
122-
if (keyframe) {
125+
if (first_encode) {
123126
// The first frame is a key frame and should be larger.
124-
// Store the overshoot bytes and distribute them over the coming frames,
125-
// so that we on average meet the bitrate target.
126-
debt_bytes_ += (kKeyframeSizeFactor - 1) * stream_bytes;
127-
stream_bytes *= kKeyframeSizeFactor;
128-
} else {
129-
if (debt_bytes_ > 0) {
130-
// Pay at most half of the frame size for old debts.
131-
size_t payment_size = std::min(stream_bytes / 2, debt_bytes_);
132-
debt_bytes_ -= payment_size;
133-
stream_bytes -= payment_size;
134-
}
127+
// TODO(holmer): The FakeEncoder should store the bits_available between
128+
// encodes so that it can compensate for oversized frames.
129+
stream_bytes *= 10;
135130
}
136-
137131
if (stream_bytes > num_encoded_bytes)
138132
stream_bytes = num_encoded_bytes;
139133

@@ -181,7 +175,6 @@ int32_t FakeEncoder::SetRateAllocation(const BitrateAllocation& rate_allocation,
181175
uint32_t framerate) {
182176
rtc::CritScope cs(&crit_sect_);
183177
target_bitrate_ = rate_allocation;
184-
configured_input_framerate_ = framerate;
185178
return 0;
186179
}
187180

@@ -190,11 +183,6 @@ const char* FakeEncoder::ImplementationName() const {
190183
return kImplementationName;
191184
}
192185

193-
int FakeEncoder::GetConfiguredInputFramerate() const {
194-
rtc::CritScope cs(&crit_sect_);
195-
return configured_input_framerate_;
196-
}
197-
198186
FakeH264Encoder::FakeH264Encoder(Clock* clock)
199187
: FakeEncoder(clock), callback_(nullptr), idr_counter_(0) {
200188
FakeEncoder::RegisterEncodeCompleteCallback(this);

webrtc/test/fake_encoder.h

+1-7
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class FakeEncoder : public VideoEncoder {
4545
int32_t SetRateAllocation(const BitrateAllocation& rate_allocation,
4646
uint32_t framerate) override;
4747
const char* ImplementationName() const override;
48-
int GetConfiguredInputFramerate() const;
4948

5049
static const char* kImplementationName;
5150

@@ -54,16 +53,11 @@ class FakeEncoder : public VideoEncoder {
5453
VideoCodec config_ GUARDED_BY(crit_sect_);
5554
EncodedImageCallback* callback_ GUARDED_BY(crit_sect_);
5655
BitrateAllocation target_bitrate_ GUARDED_BY(crit_sect_);
57-
int configured_input_framerate_ GUARDED_BY(crit_sect_);
5856
int max_target_bitrate_kbps_ GUARDED_BY(crit_sect_);
59-
bool pending_keyframe_ GUARDED_BY(crit_sect_);
57+
int64_t last_encode_time_ms_ GUARDED_BY(crit_sect_);
6058
rtc::CriticalSection crit_sect_;
6159

6260
uint8_t encoded_buffer_[100000];
63-
64-
// Current byte debt to be payed over a number of frames.
65-
// The debt is acquired by keyframes overshooting the bitrate target.
66-
size_t debt_bytes_;
6761
};
6862

6963
class FakeH264Encoder : public FakeEncoder, public EncodedImageCallback {

webrtc/video/video_send_stream_tests.cc

+3-34
Original file line numberDiff line numberDiff line change
@@ -939,12 +939,10 @@ void VideoSendStreamTest::TestPacketFragmentationSize(VideoFormat format,
939939

940940
void TriggerLossReport(const RTPHeader& header) {
941941
// Send lossy receive reports to trigger FEC enabling.
942-
const int kLossPercent = 5;
943-
if (packet_count_++ % (100 / kLossPercent) != 0) {
942+
if (packet_count_++ % 2 != 0) {
943+
// Receive statistics reporting having lost 50% of the packets.
944944
FakeReceiveStatistics lossy_receive_stats(
945-
kVideoSendSsrcs[0], header.sequenceNumber,
946-
(packet_count_ * (100 - kLossPercent)) / 100, // Cumulative lost.
947-
static_cast<uint8_t>((255 * kLossPercent) / 100)); // Loss percent.
945+
kVideoSendSsrcs[0], header.sequenceNumber, packet_count_ / 2, 127);
948946
RTCPSender rtcp_sender(false, Clock::GetRealTimeClock(),
949947
&lossy_receive_stats, nullptr, nullptr,
950948
transport_adapter_.get());
@@ -997,35 +995,6 @@ void VideoSendStreamTest::TestPacketFragmentationSize(VideoFormat format,
997995
// Make sure there is at least one extension header, to make the RTP
998996
// header larger than the base length of 12 bytes.
999997
EXPECT_FALSE(send_config->rtp.extensions.empty());
1000-
1001-
// Setup screen content disables frame dropping which makes this easier.
1002-
class VideoStreamFactory
1003-
: public VideoEncoderConfig::VideoStreamFactoryInterface {
1004-
public:
1005-
explicit VideoStreamFactory(size_t num_temporal_layers)
1006-
: num_temporal_layers_(num_temporal_layers) {
1007-
EXPECT_GT(num_temporal_layers, 0u);
1008-
}
1009-
1010-
private:
1011-
std::vector<VideoStream> CreateEncoderStreams(
1012-
int width,
1013-
int height,
1014-
const VideoEncoderConfig& encoder_config) override {
1015-
std::vector<VideoStream> streams =
1016-
test::CreateVideoStreams(width, height, encoder_config);
1017-
for (VideoStream& stream : streams) {
1018-
stream.temporal_layer_thresholds_bps.resize(num_temporal_layers_ -
1019-
1);
1020-
}
1021-
return streams;
1022-
}
1023-
const size_t num_temporal_layers_;
1024-
};
1025-
1026-
encoder_config->video_stream_factory =
1027-
new rtc::RefCountedObject<VideoStreamFactory>(2);
1028-
encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen;
1029998
}
1030999

10311000
void PerformTest() override {

0 commit comments

Comments
 (0)