2 * Copyright (c) 2021, Alliance for Open Media. All rights reserved
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
12 #ifndef AOM_AV1_RATECTRL_RTC_H_
13 #define AOM_AV1_RATECTRL_RTC_H_
22 // These constants come from AV1 spec.
23 static constexpr size_t kAV1MaxLayers
= 32;
24 static constexpr size_t kAV1MaxTemporalLayers
= 8;
25 static constexpr size_t kAV1MaxSpatialLayers
= 4;
27 typedef uint8_t FRAME_TYPE
;
29 struct AV1RateControlRtcConfig
{
31 AV1RateControlRtcConfig();
38 int64_t target_bandwidth
;
39 int64_t buf_initial_sz
;
40 int64_t buf_optimal_sz
;
44 int max_intra_bitrate_pct
;
45 int max_inter_bitrate_pct
;
47 int layer_target_bitrate
[kAV1MaxLayers
];
48 int ts_rate_decimator
[kAV1MaxTemporalLayers
];
50 // Number of spatial layers
52 // Number of temporal layers
54 int max_quantizers
[kAV1MaxLayers
];
55 int min_quantizers
[kAV1MaxLayers
];
56 int scaling_factor_num
[kAV1MaxSpatialLayers
];
57 int scaling_factor_den
[kAV1MaxSpatialLayers
];
60 struct AV1FrameParamsRTC
{
61 FRAME_TYPE frame_type
;
63 int temporal_layer_id
;
66 class AV1RateControlRTC
{
68 static std::unique_ptr
<AV1RateControlRTC
> Create(
69 const AV1RateControlRtcConfig
&cfg
);
72 void UpdateRateControl(const AV1RateControlRtcConfig
&rc_cfg
);
73 // GetQP() needs to be called after ComputeQP() to get the latest QP
75 signed char *GetCyclicRefreshMap() const;
76 int *GetDeltaQ() const;
77 void ComputeQP(const AV1FrameParamsRTC
&frame_params
);
78 // Feedback to rate control with the size of current encoded frame
79 void PostEncodeUpdate(uint64_t encoded_frame_size
);
82 AV1RateControlRTC() = default;
83 void InitRateControl(const AV1RateControlRtcConfig
&cfg
);
91 #endif // AOM_AV1_RATECTRL_RTC_H_