Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1397)

Unified Diff: webrtc/modules/video_coding/media_opt_util.cc

Issue 2501083003: Replace c-style cast and constrain value in VCMFecMethod::ProtectionFactor. (Closed)
Patch Set: Feedback response 1. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/video_coding/media_opt_util.cc
diff --git a/webrtc/modules/video_coding/media_opt_util.cc b/webrtc/modules/video_coding/media_opt_util.cc
index 24acfe9f669b18187cd8283fafd47cf67ce663b7..ed926e953b23c91941ea54e15fe8c173a9f5dcca 100644
--- a/webrtc/modules/video_coding/media_opt_util.cc
+++ b/webrtc/modules/video_coding/media_opt_util.cc
@@ -15,6 +15,7 @@
#include <math.h>
#include <algorithm>
+#include <limits>
#include "webrtc/modules/include/module_common_types.h"
#include "webrtc/modules/video_coding/codecs/vp8/include/vp8_common_types.h"
@@ -244,7 +245,7 @@ bool VCMFecMethod::ProtectionFactor(const VCMProtectionParameters* parameters) {
// FEC PROTECTION SETTINGS: varies with packet loss and bitrate
// No protection if (filtered) packetLoss is 0
- uint8_t packetLoss = (uint8_t)(255 * parameters->lossPr);
+ uint8_t packetLoss = static_cast<uint8_t>(255 * parameters->lossPr);
if (packetLoss == 0) {
_protectionFactorK = 0;
_protectionFactorD = 0;
@@ -255,7 +256,7 @@ bool VCMFecMethod::ProtectionFactor(const VCMProtectionParameters* parameters) {
// first partition size, thresholds, table pars, spatial resoln fac.
// First partition protection: ~ 20%
- uint8_t firstPartitionProt = (uint8_t)(255 * 0.20);
+ uint8_t firstPartitionProt = static_cast<uint8_t>(255 * 0.20);
// Minimum protection level needed to generate one FEC packet for one
// source packet/frame (in RTP sender)
@@ -282,10 +283,11 @@ bool VCMFecMethod::ProtectionFactor(const VCMProtectionParameters* parameters) {
const int bitRatePerFrame = BitsPerFrame(parameters);
// Average number of packets per frame (source and fec):
- const uint8_t avgTotPackets =
- 1 + (uint8_t)(static_cast<float>(bitRatePerFrame) * 1000.0 /
- static_cast<float>(8.0 * _maxPayloadSize) +
- 0.5);
+ const uint8_t avgTotPackets = static_cast<uint8_t>(
+ std::min(static_cast<float>(std::numeric_limits<uint8_t>::max()),
+ 1.5f +
+ static_cast<float>(bitRatePerFrame) * 1000.0f /
+ static_cast<float>(8.0 * _maxPayloadSize)));
// FEC rate parameters: for P and I frame
uint8_t codeRateDelta = 0;
@@ -296,8 +298,8 @@ bool VCMFecMethod::ProtectionFactor(const VCMProtectionParameters* parameters) {
// from ~200k to ~8000k, for 30fps
const uint16_t effRateFecTable =
static_cast<uint16_t>(resolnFac * bitRatePerFrame);
- uint8_t rateIndexTable = (uint8_t)VCM_MAX(
- VCM_MIN((effRateFecTable - ratePar1) / ratePar1, ratePar2), 0);
+ uint8_t rateIndexTable = static_cast<uint8_t>(
+ VCM_MAX(VCM_MIN((effRateFecTable - ratePar1) / ratePar1, ratePar2), 0));
// Restrict packet loss range to 50:
// current tables defined only up to 50%
@@ -328,14 +330,15 @@ bool VCMFecMethod::ProtectionFactor(const VCMProtectionParameters* parameters) {
// Effectively at a higher rate, so we scale/boost the rate
// The boost factor may depend on several factors: ratio of packet
// number of I to P frames, how much protection placed on P frames, etc.
- const uint8_t packetFrameDelta = (uint8_t)(0.5 + parameters->packetsPerFrame);
+ const uint8_t packetFrameDelta =
+ static_cast<uint8_t>(0.5 + parameters->packetsPerFrame);
const uint8_t packetFrameKey =
- (uint8_t)(0.5 + parameters->packetsPerFrameKey);
+ static_cast<uint8_t>(0.5 + parameters->packetsPerFrameKey);
const uint8_t boostKey = BoostCodeRateKey(packetFrameDelta, packetFrameKey);
- rateIndexTable = (uint8_t)VCM_MAX(
+ rateIndexTable = static_cast<uint8_t>(VCM_MAX(
VCM_MIN(1 + (boostKey * effRateFecTable - ratePar1) / ratePar1, ratePar2),
- 0);
+ 0));
uint16_t indexTableKey = rateIndexTable * kPacketLossMax + packetLoss;
indexTableKey = VCM_MIN(indexTableKey, kSizeCodeRateXORTable);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698