| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 static const int kPacketLossMax = 129; | 27 static const int kPacketLossMax = 129; |
| 28 | 28 |
| 29 namespace media_optimization { | 29 namespace media_optimization { |
| 30 | 30 |
| 31 VCMProtectionMethod::VCMProtectionMethod() | 31 VCMProtectionMethod::VCMProtectionMethod() |
| 32 : _effectivePacketLoss(0), | 32 : _effectivePacketLoss(0), |
| 33 _protectionFactorK(0), | 33 _protectionFactorK(0), |
| 34 _protectionFactorD(0), | 34 _protectionFactorD(0), |
| 35 _scaleProtKey(2.0f), | 35 _scaleProtKey(2.0f), |
| 36 _maxPayloadSize(1460), | 36 _maxPayloadSize(1460), |
| 37 _qmRobustness(new VCMQmRobustness()), | |
| 38 _useUepProtectionK(false), | |
| 39 _useUepProtectionD(true), | |
| 40 _corrFecCost(1.0), | 37 _corrFecCost(1.0), |
| 41 _type(kNone) {} | 38 _type(kNone) {} |
| 42 | 39 |
| 43 VCMProtectionMethod::~VCMProtectionMethod() { | 40 VCMProtectionMethod::~VCMProtectionMethod() {} |
| 44 delete _qmRobustness; | |
| 45 } | |
| 46 void VCMProtectionMethod::UpdateContentMetrics( | |
| 47 const VideoContentMetrics* contentMetrics) { | |
| 48 _qmRobustness->UpdateContent(contentMetrics); | |
| 49 } | |
| 50 | 41 |
| 51 VCMNackFecMethod::VCMNackFecMethod(int64_t lowRttNackThresholdMs, | 42 VCMNackFecMethod::VCMNackFecMethod(int64_t lowRttNackThresholdMs, |
| 52 int64_t highRttNackThresholdMs) | 43 int64_t highRttNackThresholdMs) |
| 53 : VCMFecMethod(), | 44 : VCMFecMethod(), |
| 54 _lowRttNackMs(lowRttNackThresholdMs), | 45 _lowRttNackMs(lowRttNackThresholdMs), |
| 55 _highRttNackMs(highRttNackThresholdMs), | 46 _highRttNackMs(highRttNackThresholdMs), |
| 56 _maxFramesFec(1) { | 47 _maxFramesFec(1) { |
| 57 assert(lowRttNackThresholdMs >= -1 && highRttNackThresholdMs >= -1); | 48 assert(lowRttNackThresholdMs >= -1 && highRttNackThresholdMs >= -1); |
| 58 assert(highRttNackThresholdMs == -1 || | 49 assert(highRttNackThresholdMs == -1 || |
| 59 lowRttNackThresholdMs <= highRttNackThresholdMs); | 50 lowRttNackThresholdMs <= highRttNackThresholdMs); |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 if (codeRateDelta < firstPartitionProt) { | 317 if (codeRateDelta < firstPartitionProt) { |
| 327 codeRateDelta = firstPartitionProt; | 318 codeRateDelta = firstPartitionProt; |
| 328 } | 319 } |
| 329 } | 320 } |
| 330 | 321 |
| 331 // Check limit on amount of protection for P frame; 50% is max. | 322 // Check limit on amount of protection for P frame; 50% is max. |
| 332 if (codeRateDelta >= kPacketLossMax) { | 323 if (codeRateDelta >= kPacketLossMax) { |
| 333 codeRateDelta = kPacketLossMax - 1; | 324 codeRateDelta = kPacketLossMax - 1; |
| 334 } | 325 } |
| 335 | 326 |
| 336 float adjustFec = 1.0f; | |
| 337 // Avoid additional adjustments when layers are active. | |
| 338 // TODO(mikhal/marco): Update adjusmtent based on layer info. | |
| 339 if (parameters->numLayers == 1) { | |
| 340 adjustFec = _qmRobustness->AdjustFecFactor( | |
| 341 codeRateDelta, parameters->bitRate, parameters->frameRate, | |
| 342 parameters->rtt, packetLoss); | |
| 343 } | |
| 344 | |
| 345 codeRateDelta = static_cast<uint8_t>(codeRateDelta * adjustFec); | |
| 346 | |
| 347 // For Key frame: | 327 // For Key frame: |
| 348 // Effectively at a higher rate, so we scale/boost the rate | 328 // Effectively at a higher rate, so we scale/boost the rate |
| 349 // The boost factor may depend on several factors: ratio of packet | 329 // The boost factor may depend on several factors: ratio of packet |
| 350 // number of I to P frames, how much protection placed on P frames, etc. | 330 // number of I to P frames, how much protection placed on P frames, etc. |
| 351 const uint8_t packetFrameDelta = (uint8_t)(0.5 + parameters->packetsPerFrame); | 331 const uint8_t packetFrameDelta = (uint8_t)(0.5 + parameters->packetsPerFrame); |
| 352 const uint8_t packetFrameKey = | 332 const uint8_t packetFrameKey = |
| 353 (uint8_t)(0.5 + parameters->packetsPerFrameKey); | 333 (uint8_t)(0.5 + parameters->packetsPerFrameKey); |
| 354 const uint8_t boostKey = BoostCodeRateKey(packetFrameDelta, packetFrameKey); | 334 const uint8_t boostKey = BoostCodeRateKey(packetFrameDelta, packetFrameKey); |
| 355 | 335 |
| 356 rateIndexTable = (uint8_t)VCM_MAX( | 336 rateIndexTable = (uint8_t)VCM_MAX( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 // We reduce cost factor (which will reduce overhead for FEC and | 384 // We reduce cost factor (which will reduce overhead for FEC and |
| 405 // hybrid method) and not the protectionFactor. | 385 // hybrid method) and not the protectionFactor. |
| 406 _corrFecCost = 1.0f; | 386 _corrFecCost = 1.0f; |
| 407 if (estNumFecGen < 1.1f && _protectionFactorD < minProtLevelFec) { | 387 if (estNumFecGen < 1.1f && _protectionFactorD < minProtLevelFec) { |
| 408 _corrFecCost = 0.5f; | 388 _corrFecCost = 0.5f; |
| 409 } | 389 } |
| 410 if (estNumFecGen < 0.9f && _protectionFactorD < minProtLevelFec) { | 390 if (estNumFecGen < 0.9f && _protectionFactorD < minProtLevelFec) { |
| 411 _corrFecCost = 0.0f; | 391 _corrFecCost = 0.0f; |
| 412 } | 392 } |
| 413 | 393 |
| 414 // TODO(marpan): Set the UEP protection on/off for Key and Delta frames | |
| 415 _useUepProtectionK = _qmRobustness->SetUepProtection( | |
| 416 codeRateKey, parameters->bitRate, packetLoss, 0); | |
| 417 | |
| 418 _useUepProtectionD = _qmRobustness->SetUepProtection( | |
| 419 codeRateDelta, parameters->bitRate, packetLoss, 1); | |
| 420 | |
| 421 // DONE WITH FEC PROTECTION SETTINGS | 394 // DONE WITH FEC PROTECTION SETTINGS |
| 422 return true; | 395 return true; |
| 423 } | 396 } |
| 424 | 397 |
| 425 int VCMFecMethod::BitsPerFrame(const VCMProtectionParameters* parameters) { | 398 int VCMFecMethod::BitsPerFrame(const VCMProtectionParameters* parameters) { |
| 426 // When temporal layers are available FEC will only be applied on the base | 399 // When temporal layers are available FEC will only be applied on the base |
| 427 // layer. | 400 // layer. |
| 428 const float bitRateRatio = | 401 const float bitRateRatio = |
| 429 kVp8LayerRateAlloction[parameters->numLayers - 1][0]; | 402 kVp8LayerRateAlloction[parameters->numLayers - 1][0]; |
| 430 float frameRateRatio = powf(1 / 2.0, parameters->numLayers - 1); | 403 float frameRateRatio = powf(1 / 2.0, parameters->numLayers - 1); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 _shortMaxLossPr255 = 0; | 648 _shortMaxLossPr255 = 0; |
| 676 Release(); | 649 Release(); |
| 677 } | 650 } |
| 678 | 651 |
| 679 void VCMLossProtectionLogic::Release() { | 652 void VCMLossProtectionLogic::Release() { |
| 680 _selectedMethod.reset(); | 653 _selectedMethod.reset(); |
| 681 } | 654 } |
| 682 | 655 |
| 683 } // namespace media_optimization | 656 } // namespace media_optimization |
| 684 } // namespace webrtc | 657 } // namespace webrtc |
| OLD | NEW |