hadamard: Add 4x4 test.
[aom.git] / av1 / ratectrl_rtc.h
blob353e7c7474abcaf00e33e57fb4e841c520bd4176
1 /*
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_
15 #include <cstdint>
16 #include <memory>
18 struct AV1_COMP;
20 namespace aom {
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 {
30 public:
31 AV1RateControlRtcConfig();
33 int width;
34 int height;
35 // 0-63
36 int max_quantizer;
37 int min_quantizer;
38 int64_t target_bandwidth;
39 int64_t buf_initial_sz;
40 int64_t buf_optimal_sz;
41 int64_t buf_sz;
42 int undershoot_pct;
43 int overshoot_pct;
44 int max_intra_bitrate_pct;
45 int max_inter_bitrate_pct;
46 double framerate;
47 int layer_target_bitrate[kAV1MaxLayers];
48 int ts_rate_decimator[kAV1MaxTemporalLayers];
49 int aq_mode;
50 // Number of spatial layers
51 int ss_number_layers;
52 // Number of temporal layers
53 int ts_number_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;
62 int spatial_layer_id;
63 int temporal_layer_id;
66 class AV1RateControlRTC {
67 public:
68 static std::unique_ptr<AV1RateControlRTC> Create(
69 const AV1RateControlRtcConfig &cfg);
70 ~AV1RateControlRTC();
72 void UpdateRateControl(const AV1RateControlRtcConfig &rc_cfg);
73 // GetQP() needs to be called after ComputeQP() to get the latest QP
74 int GetQP() const;
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);
81 private:
82 AV1RateControlRTC() = default;
83 void InitRateControl(const AV1RateControlRtcConfig &cfg);
84 AV1_COMP *cpi_;
85 int initial_width_;
86 int initial_height_;
89 } // namespace aom
91 #endif // AOM_AV1_RATECTRL_RTC_H_