OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
3 * | |
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 | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" | |
12 | |
13 #include <algorithm> | |
14 | |
15 namespace webrtc { | |
16 | |
17 webrtc::SimulcastRateAllocator::SimulcastRateAllocator(const VideoCodec& codec) | |
18 : codec_(codec) {} | |
19 | |
20 std::vector<uint32_t> webrtc::SimulcastRateAllocator::GetAllocation( | |
21 uint32_t bitrate_kbps) const { | |
22 // Always allocate enough bitrate for the minimum bitrate of the first layer. | |
23 // Suspending below min bitrate is controlled outside the codec implementation | |
24 // and is not overridden by this. | |
25 const uint32_t min_bitrate_bps = codec_.numberOfSimulcastStreams == 0 | |
26 ? codec_.minBitrate | |
27 : codec_.simulcastStream[0].minBitrate; | |
28 uint32_t left_to_allocate = std::max(min_bitrate_bps, bitrate_kbps); | |
29 if (codec_.maxBitrate) | |
30 left_to_allocate = std::min(left_to_allocate, codec_.maxBitrate); | |
31 | |
32 if (codec_.numberOfSimulcastStreams == 0) { | |
33 // No simulcast, just set the target as this has been capped already. | |
34 return std::vector<uint32_t>(1, left_to_allocate); | |
35 } | |
36 | |
37 // Initialize bitrates with zeroes. | |
38 std::vector<uint32_t> allocated_bitrates_bps(codec_.numberOfSimulcastStreams, | |
39 0); | |
40 | |
41 // First try to allocate up to the target bitrate for each substream. | |
42 uint32_t layer = 0; | |
noahric
2016/08/29 21:32:09
size_t for an array index?
sprang_webrtc
2016/08/30 13:27:24
Done.
| |
43 for (; layer < codec_.numberOfSimulcastStreams; ++layer) { | |
44 const SimulcastStream& stream = codec_.simulcastStream[layer]; | |
45 if (left_to_allocate < stream.minBitrate) | |
46 break; | |
47 uint32_t allocation = std::min(left_to_allocate, stream.targetBitrate); | |
48 allocated_bitrates_bps[layer] = allocation; | |
49 left_to_allocate -= allocation; | |
50 } | |
51 | |
52 // Next, try to distribute remaining bitrate, up to max bitrate, across the | |
53 // enabled layers, starting with the highest. | |
54 for (; layer --> 0;) { | |
noahric
2016/08/29 21:32:09
Can you rewrite this? As written, the code looks w
sprang_webrtc
2016/08/30 13:27:24
Aww. I was was aware this was going to be shot dow
noahric
2016/08/30 18:14:33
Ah, yeah :( You can also just make active_layer an
| |
55 if (left_to_allocate == 0) | |
56 break; | |
57 const SimulcastStream& stream = codec_.simulcastStream[layer]; | |
58 uint32_t allocation = std::min( | |
59 left_to_allocate, stream.maxBitrate - allocated_bitrates_bps[layer]); | |
60 left_to_allocate -= allocation; | |
61 allocated_bitrates_bps[layer] += allocation; | |
62 } | |
63 return allocated_bitrates_bps; | |
64 } | |
65 | |
66 const VideoCodec& webrtc::SimulcastRateAllocator::GetCodec() const { | |
67 return codec_; | |
68 } | |
69 | |
70 } // namespace webrtc | |
OLD | NEW |