Line data Source code
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/default_video_bitrate_allocator.h"
12 :
13 : #include <stdint.h>
14 :
15 : namespace webrtc {
16 :
17 0 : DefaultVideoBitrateAllocator::DefaultVideoBitrateAllocator(
18 0 : const VideoCodec& codec)
19 0 : : codec_(codec) {}
20 :
21 0 : DefaultVideoBitrateAllocator::~DefaultVideoBitrateAllocator() {}
22 :
23 0 : BitrateAllocation DefaultVideoBitrateAllocator::GetAllocation(
24 : uint32_t total_bitrate_bps,
25 : uint32_t framerate) {
26 0 : BitrateAllocation allocation;
27 0 : if (total_bitrate_bps == 0)
28 0 : return allocation;
29 :
30 0 : if (total_bitrate_bps < codec_.minBitrate * 1000) {
31 0 : allocation.SetBitrate(0, 0, codec_.minBitrate * 1000);
32 0 : } else if (codec_.maxBitrate > 0 &&
33 0 : total_bitrate_bps > codec_.maxBitrate * 1000) {
34 0 : allocation.SetBitrate(0, 0, codec_.maxBitrate * 1000);
35 : } else {
36 0 : allocation.SetBitrate(0, 0, total_bitrate_bps);
37 : }
38 :
39 0 : return allocation;
40 : }
41 :
42 0 : uint32_t DefaultVideoBitrateAllocator::GetPreferredBitrateBps(
43 : uint32_t framerate) {
44 0 : return GetAllocation(codec_.maxBitrate * 1000, framerate).get_sum_bps();
45 : }
46 :
47 : } // namespace webrtc
|