| 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // Always allocate enough bitrate for the minimum bitrate of the first layer. | 22 // Always allocate enough bitrate for the minimum bitrate of the first layer. |
| 23 // Suspending below min bitrate is controlled outside the codec implementation | 23 // Suspending below min bitrate is controlled outside the codec implementation |
| 24 // and is not overridden by this. | 24 // and is not overridden by this. |
| 25 const uint32_t min_bitrate_bps = codec_.numberOfSimulcastStreams == 0 | 25 const uint32_t min_bitrate_bps = codec_.numberOfSimulcastStreams == 0 |
| 26 ? codec_.minBitrate | 26 ? codec_.minBitrate |
| 27 : codec_.simulcastStream[0].minBitrate; | 27 : codec_.simulcastStream[0].minBitrate; |
| 28 uint32_t left_to_allocate = std::max(min_bitrate_bps, bitrate_kbps); | 28 uint32_t left_to_allocate = std::max(min_bitrate_bps, bitrate_kbps); |
| 29 if (codec_.maxBitrate) | 29 if (codec_.maxBitrate) |
| 30 left_to_allocate = std::min(left_to_allocate, codec_.maxBitrate); | 30 left_to_allocate = std::min(left_to_allocate, codec_.maxBitrate); |
| 31 | 31 |
| 32 if (codec_.numberOfSimulcastStreams == 0) { | 32 if (codec_.numberOfSimulcastStreams < 2) { |
| 33 // No simulcast, just set the target as this has been capped already. | 33 // No simulcast, just set the target as this has been capped already. |
| 34 return std::vector<uint32_t>(1, left_to_allocate); | 34 return std::vector<uint32_t>(1, left_to_allocate); |
| 35 } | 35 } |
| 36 | 36 |
| 37 // Initialize bitrates with zeroes. | 37 // Initialize bitrates with zeroes. |
| 38 std::vector<uint32_t> allocated_bitrates_bps(codec_.numberOfSimulcastStreams, | 38 std::vector<uint32_t> allocated_bitrates_bps(codec_.numberOfSimulcastStreams, |
| 39 0); | 39 0); |
| 40 | 40 |
| 41 // First try to allocate up to the target bitrate for each substream. | 41 // First try to allocate up to the target bitrate for each substream. |
| 42 size_t layer = 0; | 42 size_t layer = 0; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 58 uint32_t allocation = | 58 uint32_t allocation = |
| 59 std::min(left_to_allocate, | 59 std::min(left_to_allocate, |
| 60 stream.maxBitrate - allocated_bitrates_bps[active_layer]); | 60 stream.maxBitrate - allocated_bitrates_bps[active_layer]); |
| 61 left_to_allocate -= allocation; | 61 left_to_allocate -= allocation; |
| 62 allocated_bitrates_bps[active_layer] += allocation; | 62 allocated_bitrates_bps[active_layer] += allocation; |
| 63 } | 63 } |
| 64 | 64 |
| 65 return allocated_bitrates_bps; | 65 return allocated_bitrates_bps; |
| 66 } | 66 } |
| 67 | 67 |
| 68 uint32_t SimulcastRateAllocator::GetPreferedBitrate() const { |
| 69 std::vector<uint32_t> rates = GetAllocation(codec_.maxBitrate); |
| 70 uint32_t preferred_bitrate = 0; |
| 71 for (const uint32_t& rate : rates) { |
| 72 preferred_bitrate += rate; |
| 73 } |
| 74 return preferred_bitrate; |
| 75 } |
| 76 |
| 68 const VideoCodec& webrtc::SimulcastRateAllocator::GetCodec() const { | 77 const VideoCodec& webrtc::SimulcastRateAllocator::GetCodec() const { |
| 69 return codec_; | 78 return codec_; |
| 70 } | 79 } |
| 71 | 80 |
| 72 } // namespace webrtc | 81 } // namespace webrtc |
| OLD | NEW |