Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: webrtc/modules/video_coding/utility/simulcast_rate_allocator.cc

Issue 2288223002: Extract simulcast rate allocation outside of video encoder. (Closed)
Patch Set: Rebase, handle pause case in simulcast wrapper Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 size_t layer = 0;
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 allocate remaining bitrate, up to max bitrate, in top layer.
53 // TODO(sprang): Allocate up to max bitrate for all layers once we have a
54 // better idea of possible performance implications.
55 if (left_to_allocate > 0) {
56 size_t active_layer = layer - 1;
57 const SimulcastStream& stream = codec_.simulcastStream[active_layer];
58 uint32_t allocation =
59 std::min(left_to_allocate,
60 stream.maxBitrate - allocated_bitrates_bps[active_layer]);
61 left_to_allocate -= allocation;
62 allocated_bitrates_bps[active_layer] += allocation;
63 }
64
65 return allocated_bitrates_bps;
66 }
67
68 const VideoCodec& webrtc::SimulcastRateAllocator::GetCodec() const {
69 return codec_;
70 }
71
72 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698