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 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 // of packets (total rate: source+fec) FEC in RTP module assumes protection | 512 // of packets (total rate: source+fec) FEC in RTP module assumes protection |
513 // factor is defined relative to source number of packets so we should | 513 // factor is defined relative to source number of packets so we should |
514 // convert the factor to reduce mismatch between mediaOpt suggested rate and | 514 // convert the factor to reduce mismatch between mediaOpt suggested rate and |
515 // the actual rate | 515 // the actual rate |
516 _protectionFactorK = ConvertFECRate(_protectionFactorK); | 516 _protectionFactorK = ConvertFECRate(_protectionFactorK); |
517 _protectionFactorD = ConvertFECRate(_protectionFactorD); | 517 _protectionFactorD = ConvertFECRate(_protectionFactorD); |
518 | 518 |
519 return true; | 519 return true; |
520 } | 520 } |
521 VCMLossProtectionLogic::VCMLossProtectionLogic(int64_t nowMs): | 521 VCMLossProtectionLogic::VCMLossProtectionLogic(int64_t nowMs): |
522 _selectedMethod(NULL), | |
523 _currentParameters(), | 522 _currentParameters(), |
524 _rtt(0), | 523 _rtt(0), |
525 _lossPr(0.0f), | 524 _lossPr(0.0f), |
526 _bitRate(0.0f), | 525 _bitRate(0.0f), |
527 _frameRate(0.0f), | 526 _frameRate(0.0f), |
528 _keyFrameSize(0.0f), | 527 _keyFrameSize(0.0f), |
529 _fecRateKey(0), | 528 _fecRateKey(0), |
530 _fecRateDelta(0), | 529 _fecRateDelta(0), |
531 _lastPrUpdateT(0), | 530 _lastPrUpdateT(0), |
532 _lossPr255(0.9999f), | 531 _lossPr255(0.9999f), |
533 _lossPrHistory(), | 532 _lossPrHistory(), |
534 _shortMaxLossPr255(0), | 533 _shortMaxLossPr255(0), |
535 _packetsPerFrame(0.9999f), | 534 _packetsPerFrame(0.9999f), |
536 _packetsPerFrameKey(0.9999f), | 535 _packetsPerFrameKey(0.9999f), |
537 _codecWidth(0), | 536 _codecWidth(0), |
538 _codecHeight(0), | 537 _codecHeight(0), |
539 _numLayers(1) | 538 _numLayers(1) |
540 { | 539 { |
541 Reset(nowMs); | 540 Reset(nowMs); |
542 } | 541 } |
543 | 542 |
544 VCMLossProtectionLogic::~VCMLossProtectionLogic() | 543 VCMLossProtectionLogic::~VCMLossProtectionLogic() |
545 { | 544 { |
546 Release(); | 545 Release(); |
547 } | 546 } |
548 | 547 |
549 void VCMLossProtectionLogic::SetMethod( | 548 void VCMLossProtectionLogic::SetMethod( |
550 enum VCMProtectionMethodEnum newMethodType) { | 549 enum VCMProtectionMethodEnum newMethodType) { |
551 if (_selectedMethod != nullptr) { | 550 if (_selectedMethod && _selectedMethod->Type() == newMethodType) |
552 if (_selectedMethod->Type() == newMethodType) | 551 return; |
553 return; | |
554 // Remove old method. | |
555 delete _selectedMethod; | |
556 } | |
557 | 552 |
558 switch(newMethodType) { | 553 switch(newMethodType) { |
559 case kNack: | 554 case kNack: |
560 _selectedMethod = new VCMNackMethod(); | 555 _selectedMethod.reset(new VCMNackMethod()); |
561 break; | 556 break; |
562 case kFec: | 557 case kFec: |
563 _selectedMethod = new VCMFecMethod(); | 558 _selectedMethod.reset(new VCMFecMethod()); |
564 break; | 559 break; |
565 case kNackFec: | 560 case kNackFec: |
566 _selectedMethod = new VCMNackFecMethod(kLowRttNackMs, -1); | 561 _selectedMethod.reset(new VCMNackFecMethod(kLowRttNackMs, -1)); |
567 break; | 562 break; |
568 case kNone: | 563 case kNone: |
569 _selectedMethod = nullptr; | 564 _selectedMethod.reset(); |
570 break; | 565 break; |
571 } | 566 } |
572 UpdateMethod(); | 567 UpdateMethod(); |
573 } | 568 } |
574 | 569 |
575 void | 570 void |
576 VCMLossProtectionLogic::UpdateRtt(int64_t rtt) | 571 VCMLossProtectionLogic::UpdateRtt(int64_t rtt) |
577 { | 572 { |
578 _rtt = rtt; | 573 _rtt = rtt; |
579 } | 574 } |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 _codecHeight = height; | 714 _codecHeight = height; |
720 } | 715 } |
721 | 716 |
722 void VCMLossProtectionLogic::UpdateNumLayers(int numLayers) { | 717 void VCMLossProtectionLogic::UpdateNumLayers(int numLayers) { |
723 _numLayers = (numLayers == 0) ? 1 : numLayers; | 718 _numLayers = (numLayers == 0) ? 1 : numLayers; |
724 } | 719 } |
725 | 720 |
726 bool | 721 bool |
727 VCMLossProtectionLogic::UpdateMethod() | 722 VCMLossProtectionLogic::UpdateMethod() |
728 { | 723 { |
729 if (_selectedMethod == NULL) | 724 if (!_selectedMethod) |
730 { | 725 return false; |
731 return false; | |
732 } | |
733 _currentParameters.rtt = _rtt; | 726 _currentParameters.rtt = _rtt; |
734 _currentParameters.lossPr = _lossPr; | 727 _currentParameters.lossPr = _lossPr; |
735 _currentParameters.bitRate = _bitRate; | 728 _currentParameters.bitRate = _bitRate; |
736 _currentParameters.frameRate = _frameRate; // rename actual frame rate? | 729 _currentParameters.frameRate = _frameRate; // rename actual frame rate? |
737 _currentParameters.keyFrameSize = _keyFrameSize; | 730 _currentParameters.keyFrameSize = _keyFrameSize; |
738 _currentParameters.fecRateDelta = _fecRateDelta; | 731 _currentParameters.fecRateDelta = _fecRateDelta; |
739 _currentParameters.fecRateKey = _fecRateKey; | 732 _currentParameters.fecRateKey = _fecRateKey; |
740 _currentParameters.packetsPerFrame = _packetsPerFrame.filtered(); | 733 _currentParameters.packetsPerFrame = _packetsPerFrame.filtered(); |
741 _currentParameters.packetsPerFrameKey = _packetsPerFrameKey.filtered(); | 734 _currentParameters.packetsPerFrameKey = _packetsPerFrameKey.filtered(); |
742 _currentParameters.codecWidth = _codecWidth; | 735 _currentParameters.codecWidth = _codecWidth; |
743 _currentParameters.codecHeight = _codecHeight; | 736 _currentParameters.codecHeight = _codecHeight; |
744 _currentParameters.numLayers = _numLayers; | 737 _currentParameters.numLayers = _numLayers; |
745 return _selectedMethod->UpdateParameters(&_currentParameters); | 738 return _selectedMethod->UpdateParameters(&_currentParameters); |
746 } | 739 } |
747 | 740 |
748 VCMProtectionMethod* | 741 VCMProtectionMethod* |
749 VCMLossProtectionLogic::SelectedMethod() const | 742 VCMLossProtectionLogic::SelectedMethod() const |
750 { | 743 { |
751 return _selectedMethod; | 744 return _selectedMethod.get(); |
752 } | 745 } |
753 | 746 |
754 VCMProtectionMethodEnum VCMLossProtectionLogic::SelectedType() const { | 747 VCMProtectionMethodEnum VCMLossProtectionLogic::SelectedType() const { |
755 return _selectedMethod == nullptr ? kNone : _selectedMethod->Type(); | 748 return _selectedMethod ? _selectedMethod->Type() : kNone; |
756 } | 749 } |
757 | 750 |
758 void | 751 void |
759 VCMLossProtectionLogic::Reset(int64_t nowMs) | 752 VCMLossProtectionLogic::Reset(int64_t nowMs) |
760 { | 753 { |
761 _lastPrUpdateT = nowMs; | 754 _lastPrUpdateT = nowMs; |
762 _lastPacketPerFrameUpdateT = nowMs; | 755 _lastPacketPerFrameUpdateT = nowMs; |
763 _lastPacketPerFrameUpdateTKey = nowMs; | 756 _lastPacketPerFrameUpdateTKey = nowMs; |
764 _lossPr255.Reset(0.9999f); | 757 _lossPr255.Reset(0.9999f); |
765 _packetsPerFrame.Reset(0.9999f); | 758 _packetsPerFrame.Reset(0.9999f); |
766 _fecRateDelta = _fecRateKey = 0; | 759 _fecRateDelta = _fecRateKey = 0; |
767 for (int32_t i = 0; i < kLossPrHistorySize; i++) | 760 for (int32_t i = 0; i < kLossPrHistorySize; i++) |
768 { | 761 { |
769 _lossPrHistory[i].lossPr255 = 0; | 762 _lossPrHistory[i].lossPr255 = 0; |
770 _lossPrHistory[i].timeMs = -1; | 763 _lossPrHistory[i].timeMs = -1; |
771 } | 764 } |
772 _shortMaxLossPr255 = 0; | 765 _shortMaxLossPr255 = 0; |
773 Release(); | 766 Release(); |
774 } | 767 } |
775 | 768 |
776 void | 769 void VCMLossProtectionLogic::Release() { |
777 VCMLossProtectionLogic::Release() | 770 _selectedMethod.reset(); |
778 { | |
779 delete _selectedMethod; | |
780 _selectedMethod = NULL; | |
781 } | 771 } |
782 | 772 |
783 } // namespace media_optimization | 773 } // namespace media_optimization |
784 } // namespace webrtc | 774 } // namespace webrtc |
OLD | NEW |