From 2dad3fbe492dceacbfc55b2e2e0648be37624b1e Mon Sep 17 00:00:00 2001 From: "marpan@webrtc.org" Date: Mon, 9 Jan 2012 18:18:36 +0000 Subject: [PATCH] Media-opt: Added a filter type mode for the filtering of the received packet loss. This makes the filter selection explicit and easier to modify/test. Removed the function UpdateLossPr(); the filter updates are done in the same function that returns the filtered loss. Review URL: http://webrtc-codereview.appspot.com/333018 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1361 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../main/source/media_opt_util.cc | 54 ++++++++++--------- .../video_coding/main/source/media_opt_util.h | 25 +++++---- .../main/source/media_optimization.cc | 12 ++--- 3 files changed, 49 insertions(+), 42 deletions(-) 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 45ba2b64fa..2c6f50bdf2 100644 --- a/src/modules/video_coding/main/source/media_opt_util.cc +++ b/src/modules/video_coding/main/source/media_opt_util.cc @@ -687,17 +687,6 @@ VCMLossProtectionLogic::UpdateResidualPacketLoss(float residualPacketLoss) _residualPacketLossFec = residualPacketLoss; } -void -VCMLossProtectionLogic::UpdateLossPr(WebRtc_UWord8 lossPr255, - int64_t nowMs) -{ - UpdateMaxLossHistory(lossPr255, nowMs); - _lossPr255.Apply(static_cast (nowMs - _lastPrUpdateT), - static_cast (lossPr255)); - _lastPrUpdateT = nowMs; - _lossPr = _lossPr255.Value() / 255.0f; -} - void VCMLossProtectionLogic::UpdateMaxLossHistory(WebRtc_UWord8 lossPr255, WebRtc_Word64 now) @@ -767,21 +756,34 @@ VCMLossProtectionLogic::MaxFilteredLossPr(WebRtc_Word64 nowMs) const return maxFound; } -WebRtc_UWord8 -VCMLossProtectionLogic::FilteredLoss(int64_t nowMs) const -{ - if (_selectedMethod != NULL && - (_selectedMethod->Type() == kFec || - _selectedMethod->Type() == kNackFec)) - { - // Take the windowed max of the received loss. - return MaxFilteredLossPr(nowMs); - } - else - { - // Take the average received loss. - return static_cast (_lossPr255.Value() + 0.5); - } +WebRtc_UWord8 VCMLossProtectionLogic::FilteredLoss( + int64_t nowMs, + FilterPacketLossMode filter_mode, + WebRtc_UWord8 lossPr255) { + + // Update the max window filter. + UpdateMaxLossHistory(lossPr255, nowMs); + + // Update the recursive average filter. + _lossPr255.Apply(static_cast (nowMs - _lastPrUpdateT), + static_cast (lossPr255)); + _lastPrUpdateT = nowMs; + + // Filtered loss: default is received loss (no filtering). + WebRtc_UWord8 filtered_loss = lossPr255; + + switch (filter_mode) { + case kNoFilter: + break; + case kAvgFilter: + filtered_loss = static_cast (_lossPr255.Value() + 0.5); + break; + case kMaxFilter: + filtered_loss = MaxFilteredLossPr(nowMs); + break; + } + + return filtered_loss; } void 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 3d87b0e516..047ac921c6 100644 --- a/src/modules/video_coding/main/source/media_opt_util.h +++ b/src/modules/video_coding/main/source/media_opt_util.h @@ -33,6 +33,14 @@ enum { kLossPrHistorySize = 10 }; // 1000 ms, total filter length is (kLossPrHistorySize * 1000) ms enum { kLossPrShortFilterWinMs = 1000 }; +// The type of filter used on the received packet loss reports. +enum FilterPacketLossMode { + kNoFilter, // No filtering on received loss. + kAvgFilter, // Recursive average filter. + kMaxFilter // Max-window filter, over the time interval of: + // (kLossPrHistorySize * kLossPrShortFilterWinMs) ms. +}; + // Thresholds for hybrid NACK/FEC // common to media optimization and the jitter buffer. enum HybridNackTH { @@ -249,13 +257,6 @@ public: // effective loss after FEC recovery void UpdateResidualPacketLoss(float _residualPacketLoss); - // Update the loss probability. - // - // Input: - // - lossPr255 : The packet loss probability [0, 255], - // reported by RTCP. - void UpdateLossPr(WebRtc_UWord8 lossPr255, int64_t nowMs); - // Update the filtered packet loss. // // Input: @@ -330,10 +331,14 @@ public: // Return the protection type of the currently selected method VCMProtectionMethodEnum SelectedType() const; - // Returns the filtered loss probability in the interval [0, 255]. - // + // Updates the filtered loss for the average and max window packet loss, + // and returns the filtered loss probability in the interval [0, 255]. + // The returned filtered loss value depends on the parameter |filter_mode|. + // The input parameter |lossPr255| is the received packet loss. + // Return value : The filtered loss probability - WebRtc_UWord8 FilteredLoss(int64_t nowMs) const; + WebRtc_UWord8 FilteredLoss(int64_t nowMs, FilterPacketLossMode filter_mode, + WebRtc_UWord8 lossPr255); void Reset(int64_t nowMs); diff --git a/src/modules/video_coding/main/source/media_optimization.cc b/src/modules/video_coding/main/source/media_optimization.cc index 0475293fb2..e2c4329803 100644 --- a/src/modules/video_coding/main/source/media_optimization.cc +++ b/src/modules/video_coding/main/source/media_optimization.cc @@ -98,7 +98,6 @@ VCMMediaOptimization::SetTargetRates(WebRtc_UWord32 bitRate, { VCMProtectionMethod *selectedMethod = _lossProtLogic->SelectedMethod(); _lossProtLogic->UpdateBitRate(static_cast(bitRate)); - _lossProtLogic->UpdateLossPr(fractionLost, _clock->MillisecondTimestamp()); _lossProtLogic->UpdateRtt(roundTripTimeMs); _lossProtLogic->UpdateResidualPacketLoss(static_cast(fractionLost)); @@ -117,12 +116,13 @@ VCMMediaOptimization::SetTargetRates(WebRtc_UWord32 bitRate, _fractionLost = fractionLost; - // The effective packet loss may be the received loss or filtered, i.e., - // average or max filter may be used. - // We should think about which filter is appropriate for low/high bit rates, - // low/high loss rates, etc. + // Returns the filtered packet loss, used for the protection setting. + // The filtered loss may be the received loss (no filter), or some + // filtered value (average or max window filter). + // Use max window filter for now. + FilterPacketLossMode filter_mode = kMaxFilter; WebRtc_UWord8 packetLossEnc = _lossProtLogic->FilteredLoss( - _clock->MillisecondTimestamp()); + _clock->MillisecondTimestamp(), filter_mode, fractionLost); // For now use the filtered loss for computing the robustness settings _lossProtLogic->UpdateFilteredLossPr(packetLossEnc);