From 88ad06b99900eec841e05b501dca742677af317d Mon Sep 17 00:00:00 2001 From: "marpan@webrtc.org" Date: Fri, 20 Apr 2012 16:05:24 +0000 Subject: [PATCH] VCM: Added condition(s) for setting FEC protection factor to zero at low bitrates. Review URL: https://webrtc-codereview.appspot.com/494001 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2084 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../main/source/media_opt_util.cc | 29 +++++++++++++++++++ .../video_coding/main/source/media_opt_util.h | 13 ++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/modules/video_coding/main/source/media_opt_util.cc b/src/modules/video_coding/main/source/media_opt_util.cc index 20b90c8b1..063a84d2c 100644 --- a/src/modules/video_coding/main/source/media_opt_util.cc +++ b/src/modules/video_coding/main/source/media_opt_util.cc @@ -141,6 +141,31 @@ int VCMNackFecMethod::MaxFramesFec() const { return _maxFramesFec; } +bool VCMNackFecMethod::BitRateTooLowForFec( + const VCMProtectionParameters* parameters) { + // Bitrate below which we turn off FEC, regardless of reported packet loss. + // The condition should depend on resolution and content. For now, use + // threshold on bytes per frame, with some effect for the frame size. + // The condition for turning off FEC is also based on other factors, + // such as |_numLayers|, |_maxFramesFec|, and |_rtt|. + int estimate_bytes_per_frame = 1000 * BitsPerFrame(parameters) / 8; + int max_bytes_per_frame = kMaxBytesPerFrameForFec; + int num_pixels = parameters->codecWidth * parameters->codecHeight; + if (num_pixels <= 352 * 288) { + max_bytes_per_frame = kMaxBytesPerFrameForFecLow; + } else if (num_pixels > 640 * 480) { + max_bytes_per_frame = kMaxBytesPerFrameForFecHigh; + } + // TODO (marpan): add condition based on maximum frames used for FEC, + // and expand condition based on frame size. + if (estimate_bytes_per_frame < max_bytes_per_frame && + parameters->numLayers < 3 && + parameters->rtt < kMaxRttTurnOffFec) { + return true; + } + return false; +} + bool VCMNackFecMethod::EffectivePacketLoss(const VCMProtectionParameters* parameters) { @@ -156,6 +181,10 @@ VCMNackFecMethod::UpdateParameters(const VCMProtectionParameters* parameters) ProtectionFactor(parameters); EffectivePacketLoss(parameters); _maxFramesFec = ComputeMaxFramesFec(parameters); + if (BitRateTooLowForFec(parameters)) { + _protectionFactorK = 0; + _protectionFactorD = 0; + } // Efficiency computation is based on FEC and NACK diff --git a/src/modules/video_coding/main/source/media_opt_util.h b/src/modules/video_coding/main/source/media_opt_util.h index 079b06492..c8d88a829 100644 --- a/src/modules/video_coding/main/source/media_opt_util.h +++ b/src/modules/video_coding/main/source/media_opt_util.h @@ -203,6 +203,16 @@ public: protected: enum { kUpperLimitFramesFec = 6 }; + // Thresholds values for the bytes/frame and round trip time, below which we + // may turn off FEC, depending on |_numLayers| and |_maxFramesFec|. + // Max bytes/frame for VGA, corresponds to ~140k at 25fps. + enum { kMaxBytesPerFrameForFec = 700 }; + // Max bytes/frame for CIF and lower: corresponds to ~80k at 25fps. + enum { kMaxBytesPerFrameForFecLow = 400 }; + // Max bytes/frame for frame size larger than VGA, ~200k at 25fps. + enum { kMaxBytesPerFrameForFecHigh = 1000 }; + // Max round trip time threshold in ms. + enum { kMaxRttTurnOffFec = 200 }; }; @@ -219,7 +229,8 @@ public: bool ProtectionFactor(const VCMProtectionParameters* parameters); // Get the max number of frames the FEC is allowed to be based on. int MaxFramesFec() const; - + // Turn off the FEC based on low bitrate and other factors. + bool BitRateTooLowForFec(const VCMProtectionParameters* parameters); private: int ComputeMaxFramesFec(const VCMProtectionParameters* parameters);