From 84cd8e39cf2a998248daa16cae7b7713f79da0d8 Mon Sep 17 00:00:00 2001 From: "stefan@webrtc.org" Date: Thu, 7 Mar 2013 13:12:32 +0000 Subject: [PATCH] Disable frame dropper for screenshare mode. BUG=1466 Review URL: https://webrtc-codereview.appspot.com/1170004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3629 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../codecs/vp8/default_temporal_layers.cc | 1 + .../codecs/vp8/default_temporal_layers.h | 1 + .../vp8/default_temporal_layers_unittest.cc | 8 ++--- .../video_coding/codecs/vp8/temporal_layers.h | 1 + .../video_coding/codecs/vp8/vp8_impl.cc | 7 ++-- .../main/source/video_coding_impl.cc | 4 +++ .../video_coding/utility/frame_dropper.cc | 34 ++++++++++++++----- .../utility/include/frame_dropper.h | 2 +- 8 files changed, 42 insertions(+), 16 deletions(-) diff --git a/webrtc/modules/video_coding/codecs/vp8/default_temporal_layers.cc b/webrtc/modules/video_coding/codecs/vp8/default_temporal_layers.cc index 43020f737c..11523d7125 100644 --- a/webrtc/modules/video_coding/codecs/vp8/default_temporal_layers.cc +++ b/webrtc/modules/video_coding/codecs/vp8/default_temporal_layers.cc @@ -37,6 +37,7 @@ DefaultTemporalLayers::DefaultTemporalLayers(int numberOfTemporalLayers, } bool DefaultTemporalLayers::ConfigureBitrates(int bitrateKbit, + int max_bitrate_kbit, int framerate, vpx_codec_enc_cfg_t* cfg) { switch (number_of_temporal_layers_) { diff --git a/webrtc/modules/video_coding/codecs/vp8/default_temporal_layers.h b/webrtc/modules/video_coding/codecs/vp8/default_temporal_layers.h index 6918e45273..99b0e95696 100644 --- a/webrtc/modules/video_coding/codecs/vp8/default_temporal_layers.h +++ b/webrtc/modules/video_coding/codecs/vp8/default_temporal_layers.h @@ -27,6 +27,7 @@ class DefaultTemporalLayers : public TemporalLayers { virtual int EncodeFlags(uint32_t timestamp); virtual bool ConfigureBitrates(int bitrate_kbit, + int max_bitrate_kbit, int framerate, vpx_codec_enc_cfg_t* cfg); diff --git a/webrtc/modules/video_coding/codecs/vp8/default_temporal_layers_unittest.cc b/webrtc/modules/video_coding/codecs/vp8/default_temporal_layers_unittest.cc index fe8588ad67..be89d6da67 100644 --- a/webrtc/modules/video_coding/codecs/vp8/default_temporal_layers_unittest.cc +++ b/webrtc/modules/video_coding/codecs/vp8/default_temporal_layers_unittest.cc @@ -66,7 +66,7 @@ TEST(TemporalLayersTest, 2Layers) { DefaultTemporalLayers tl(2, 0); vpx_codec_enc_cfg_t cfg; CodecSpecificInfoVP8 vp8_info; - tl.ConfigureBitrates(500, 30, &cfg); + tl.ConfigureBitrates(500, 500, 30, &cfg); int expected_flags[16] = { kTemporalUpdateLastAndGoldenRefAltRef, kTemporalUpdateGoldenWithoutDependencyRefAltRef, @@ -106,7 +106,7 @@ TEST(TemporalLayersTest, 3Layers) { DefaultTemporalLayers tl(3, 0); vpx_codec_enc_cfg_t cfg; CodecSpecificInfoVP8 vp8_info; - tl.ConfigureBitrates(500, 30, &cfg); + tl.ConfigureBitrates(500, 500, 30, &cfg); int expected_flags[16] = { kTemporalUpdateLastAndGoldenRefAltRef, kTemporalUpdateNoneNoRefGolden, @@ -146,7 +146,7 @@ TEST(TemporalLayersTest, 4Layers) { DefaultTemporalLayers tl(4, 0); vpx_codec_enc_cfg_t cfg; CodecSpecificInfoVP8 vp8_info; - tl.ConfigureBitrates(500, 30, &cfg); + tl.ConfigureBitrates(500, 500, 30, &cfg); int expected_flags[16] = { kTemporalUpdateLast, kTemporalUpdateNone, @@ -186,7 +186,7 @@ TEST(TemporalLayersTest, KeyFrame) { DefaultTemporalLayers tl(3, 0); vpx_codec_enc_cfg_t cfg; CodecSpecificInfoVP8 vp8_info; - tl.ConfigureBitrates(500, 30, &cfg); + tl.ConfigureBitrates(500, 500, 30, &cfg); int expected_flags[8] = { kTemporalUpdateLastAndGoldenRefAltRef, diff --git a/webrtc/modules/video_coding/codecs/vp8/temporal_layers.h b/webrtc/modules/video_coding/codecs/vp8/temporal_layers.h index 71b1cd47ed..f08d8da4b2 100644 --- a/webrtc/modules/video_coding/codecs/vp8/temporal_layers.h +++ b/webrtc/modules/video_coding/codecs/vp8/temporal_layers.h @@ -31,6 +31,7 @@ class TemporalLayers { virtual int EncodeFlags(uint32_t timestamp) = 0; virtual bool ConfigureBitrates(int bitrate_kbit, + int max_bitrate_kbit, int framerate, vpx_codec_enc_cfg_t* cfg) = 0; diff --git a/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc b/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc index c1e7e4a37e..9a57e4c5a7 100644 --- a/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc +++ b/webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc @@ -113,7 +113,8 @@ int VP8EncoderImpl::SetRates(uint32_t new_bitrate_kbit, config_->rc_target_bitrate = new_bitrate_kbit; // in kbit/s #if WEBRTC_LIBVPX_VERSION >= 971 - temporal_layers_->ConfigureBitrates(new_bitrate_kbit, new_framerate, config_); + temporal_layers_->ConfigureBitrates(new_bitrate_kbit, codec_.maxBitrate, + new_framerate, config_); #endif codec_.maxFramerate = new_framerate; @@ -190,8 +191,8 @@ int VP8EncoderImpl::InitEncode(const VideoCodec* inst, config_->rc_target_bitrate = inst->startBitrate; // in kbit/s #if WEBRTC_LIBVPX_VERSION >= 971 - temporal_layers_->ConfigureBitrates(inst->startBitrate, inst->maxFramerate, - config_); + temporal_layers_->ConfigureBitrates(inst->startBitrate, inst->maxBitrate, + inst->maxFramerate, config_); #endif // setting the time base of the codec config_->g_timebase.num = 1; diff --git a/webrtc/modules/video_coding/main/source/video_coding_impl.cc b/webrtc/modules/video_coding/main/source/video_coding_impl.cc index 2f8a373a59..70e84ff2a1 100644 --- a/webrtc/modules/video_coding/main/source/video_coding_impl.cc +++ b/webrtc/modules/video_coding/main/source/video_coding_impl.cc @@ -330,6 +330,10 @@ VideoCodingModuleImpl::RegisterSendCodec(const VideoCodec* sendCodec, _sendCodecType = sendCodec->codecType; int numLayers = (_sendCodecType != kVideoCodecVP8) ? 1 : sendCodec->codecSpecific.VP8.numberOfTemporalLayers; + // Disable frame dropper if screensharing if we have layers. + bool disable_frame_dropper = + numLayers > 1 && sendCodec->mode == kScreensharing; + _mediaOpt.EnableFrameDropper(!disable_frame_dropper); _nextFrameTypes.clear(); _nextFrameTypes.resize(VCM_MAX(sendCodec->numberOfSimulcastStreams, 1), kVideoFrameDelta); diff --git a/webrtc/modules/video_coding/utility/frame_dropper.cc b/webrtc/modules/video_coding/utility/frame_dropper.cc index b871022d3b..afa043923c 100644 --- a/webrtc/modules/video_coding/utility/frame_dropper.cc +++ b/webrtc/modules/video_coding/utility/frame_dropper.cc @@ -15,12 +15,30 @@ namespace webrtc { +const float kDefaultKeyFrameSizeAvgKBits = 0.9f; +const float kDefaultKeyFrameRatio = 0.99f; +const float kDefaultDropRatioAlpha = 0.9f; +const float kDefaultDropRatioMax = 0.96f; +const float kDefaultMaxTimeToDropFrames = 4.0f; // In seconds. + FrameDropper::FrameDropper() : -_keyFrameSizeAvgKbits(0.9f), -_keyFrameRatio(0.99f), -_dropRatio(0.9f, 0.96f), -_enabled(true) +_keyFrameSizeAvgKbits(kDefaultKeyFrameSizeAvgKBits), +_keyFrameRatio(kDefaultKeyFrameRatio), +_dropRatio(kDefaultDropRatioAlpha, kDefaultDropRatioMax), +_enabled(true), +_max_time_drops(kDefaultMaxTimeToDropFrames) +{ + Reset(); +} + +FrameDropper::FrameDropper(float max_time_drops) +: +_keyFrameSizeAvgKbits(kDefaultKeyFrameSizeAvgKBits), +_keyFrameRatio(kDefaultKeyFrameRatio), +_dropRatio(kDefaultDropRatioAlpha, kDefaultDropRatioMax), +_enabled(true), +_max_time_drops(max_time_drops) { Reset(); } @@ -138,6 +156,10 @@ FrameDropper::Leak(WebRtc_UWord32 inputFrameRate) _keyFrameCount--; } _accumulator -= T; + if (_accumulator < 0.0f) + { + _accumulator = 0.0f; + } UpdateRatio(); } @@ -192,10 +214,6 @@ FrameDropper::UpdateRatio() { _dropRatio.Apply(1.0f, 0.0f); } - if (_accumulator < 0.0f) - { - _accumulator = 0.0f; - } _wasBelowMax = _accumulator < _accumulatorMax; } diff --git a/webrtc/modules/video_coding/utility/include/frame_dropper.h b/webrtc/modules/video_coding/utility/include/frame_dropper.h index fd15dd0872..68a74045e6 100644 --- a/webrtc/modules/video_coding/utility/include/frame_dropper.h +++ b/webrtc/modules/video_coding/utility/include/frame_dropper.h @@ -24,6 +24,7 @@ class FrameDropper { public: FrameDropper(); + explicit FrameDropper(float max_time_drops); virtual ~FrameDropper() {} // Resets the FrameDropper to its initial state. @@ -66,7 +67,6 @@ public: // instruction of when to drop frames. virtual float ActualFrameRate(WebRtc_UWord32 inputFrameRate) const; - private: void FillBucket(float inKbits, float outKbits); void UpdateRatio();