| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "modules/audio_coding/audio_network_adaptor/frame_length_controller.h" | 14 #include "modules/audio_coding/audio_network_adaptor/frame_length_controller.h" |
| 15 #include "test/gtest.h" | 15 #include "test/gtest.h" |
| 16 | 16 |
| 17 namespace webrtc { | 17 namespace webrtc { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 constexpr float kFlIncreasingPacketLossFraction = 0.04f; | 21 constexpr float kFlIncreasingPacketLossFraction = 0.04f; |
| 22 constexpr float kFlDecreasingPacketLossFraction = 0.05f; | 22 constexpr float kFlDecreasingPacketLossFraction = 0.05f; |
| 23 constexpr int kFlIncreaseOverheadOffset = 0; |
| 24 constexpr int kFlDecreaseOverheadOffset = 0; |
| 23 constexpr int kMinEncoderBitrateBps = 6000; | 25 constexpr int kMinEncoderBitrateBps = 6000; |
| 24 constexpr int kPreventOveruseMarginBps = 5000; | 26 constexpr int kPreventOveruseMarginBps = 5000; |
| 25 constexpr size_t kOverheadBytesPerPacket = 20; | 27 constexpr size_t kOverheadBytesPerPacket = 20; |
| 26 constexpr int kFl20msTo60msBandwidthBps = 40000; | 28 constexpr int kFl20msTo60msBandwidthBps = 40000; |
| 27 constexpr int kFl60msTo20msBandwidthBps = 50000; | 29 constexpr int kFl60msTo20msBandwidthBps = 50000; |
| 28 constexpr int kFl60msTo120msBandwidthBps = 30000; | 30 constexpr int kFl60msTo120msBandwidthBps = 30000; |
| 29 constexpr int kFl120msTo60msBandwidthBps = 40000; | 31 constexpr int kFl120msTo60msBandwidthBps = 40000; |
| 30 constexpr int kMediumBandwidthBps = | 32 constexpr int kMediumBandwidthBps = |
| 31 (kFl60msTo20msBandwidthBps + kFl20msTo60msBandwidthBps) / 2; | 33 (kFl60msTo20msBandwidthBps + kFl20msTo60msBandwidthBps) / 2; |
| 32 constexpr float kMediumPacketLossFraction = | 34 constexpr float kMediumPacketLossFraction = |
| 33 (kFlDecreasingPacketLossFraction + kFlIncreasingPacketLossFraction) / 2; | 35 (kFlDecreasingPacketLossFraction + kFlIncreasingPacketLossFraction) / 2; |
| 34 | 36 |
| 35 int VeryLowBitrate(int frame_length_ms) { | 37 int VeryLowBitrate(int frame_length_ms) { |
| 36 return kMinEncoderBitrateBps + kPreventOveruseMarginBps + | 38 return kMinEncoderBitrateBps + kPreventOveruseMarginBps + |
| 37 (kOverheadBytesPerPacket * 8 * 1000 / frame_length_ms); | 39 (kOverheadBytesPerPacket * 8 * 1000 / frame_length_ms); |
| 38 } | 40 } |
| 39 | 41 |
| 40 std::unique_ptr<FrameLengthController> CreateController( | 42 std::unique_ptr<FrameLengthController> CreateController( |
| 41 const std::map<FrameLengthController::Config::FrameLengthChange, int>& | 43 const std::map<FrameLengthController::Config::FrameLengthChange, int>& |
| 42 frame_length_change_criteria, | 44 frame_length_change_criteria, |
| 43 const std::vector<int>& encoder_frame_lengths_ms, | 45 const std::vector<int>& encoder_frame_lengths_ms, |
| 44 int initial_frame_length_ms) { | 46 int initial_frame_length_ms) { |
| 45 std::unique_ptr<FrameLengthController> controller( | 47 std::unique_ptr<FrameLengthController> controller( |
| 46 new FrameLengthController(FrameLengthController::Config( | 48 new FrameLengthController(FrameLengthController::Config( |
| 47 encoder_frame_lengths_ms, initial_frame_length_ms, | 49 encoder_frame_lengths_ms, initial_frame_length_ms, |
| 48 kMinEncoderBitrateBps, kFlIncreasingPacketLossFraction, | 50 kMinEncoderBitrateBps, kFlIncreasingPacketLossFraction, |
| 49 kFlDecreasingPacketLossFraction, frame_length_change_criteria))); | 51 kFlDecreasingPacketLossFraction, kFlIncreaseOverheadOffset, |
| 52 kFlDecreaseOverheadOffset, frame_length_change_criteria))); |
| 50 | 53 |
| 51 return controller; | 54 return controller; |
| 52 } | 55 } |
| 53 | 56 |
| 54 std::map<FrameLengthController::Config::FrameLengthChange, int> | 57 std::map<FrameLengthController::Config::FrameLengthChange, int> |
| 55 CreateChangeCriteriaFor20msAnd60ms() { | 58 CreateChangeCriteriaFor20msAnd60ms() { |
| 56 return std::map<FrameLengthController::Config::FrameLengthChange, int>{ | 59 return std::map<FrameLengthController::Config::FrameLengthChange, int>{ |
| 57 {FrameLengthController::Config::FrameLengthChange(20, 60), | 60 {FrameLengthController::Config::FrameLengthChange(20, 60), |
| 58 kFl20msTo60msBandwidthBps}, | 61 kFl20msTo60msBandwidthBps}, |
| 59 {FrameLengthController::Config::FrameLengthChange(60, 20), | 62 {FrameLengthController::Config::FrameLengthChange(60, 20), |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 CheckDecision(controller.get(), 60); | 377 CheckDecision(controller.get(), 60); |
| 375 | 378 |
| 376 UpdateNetworkMetrics(controller.get(), | 379 UpdateNetworkMetrics(controller.get(), |
| 377 rtc::Optional<int>(kMediumBandwidthBps), | 380 rtc::Optional<int>(kMediumBandwidthBps), |
| 378 rtc::Optional<float>(kFlDecreasingPacketLossFraction), | 381 rtc::Optional<float>(kFlDecreasingPacketLossFraction), |
| 379 rtc::Optional<size_t>(kOverheadBytesPerPacket)); | 382 rtc::Optional<size_t>(kOverheadBytesPerPacket)); |
| 380 CheckDecision(controller.get(), 20); | 383 CheckDecision(controller.get(), 20); |
| 381 } | 384 } |
| 382 | 385 |
| 383 } // namespace webrtc | 386 } // namespace webrtc |
| OLD | NEW |