File size: 6,890 Bytes
477da44 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
/*
* Copyright 2016 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPP_RC_API_H__
#define __MPP_RC_API_H__
#include "mpp_err.h"
#include "rk_venc_rc.h"
#include "mpp_rc_defs.h"
/*
* Mpp rate control has three parts:
*
* 1. MPI user config module
* MppEncRcCfg structure is provided to user for overall rate control config
* Mpp will receive MppEncRcCfg from user, check parameter and set it to
* encoder.
*
* 2. Encoder rate control module
* Encoder will implement the rate control strategy required by users
* including CBR, VBR, AVBR and so on.
* This module only implement the target bit calculation behavior and
* quality restriction. And the quality level will be controlled by hal.
*
* 3. Hal rate control module
* Hal will implement the rate control on hardware. Hal will calculate the
* QP parameter for hardware according to the frame level target bit
* specified by the encoder. And the report the real bitrate and quality to
* encoder.
*
* The header defines the communication interfaces and structures used between
* MPI, encoder and hal.
*/
typedef enum RcMode_e {
RC_VBR,
RC_CBR,
RC_FIXQP,
RC_AVBR,
RC_CVBR,
RC_QVBR,
RC_LEARNING,
RC_MODE_BUTT,
} RcMode;
typedef enum GopMode_e {
NORMAL_P,
SMART_P,
} GopMode;
/*
* frame rate parameters have great effect on rate control
*
* fps_in_flex
* 0 - fix input frame rate
* 1 - variable input frame rate
*
* fps_in_num
* input frame rate numerator, if 0 then default 30
*
* fps_in_denorm
* input frame rate denorminator, if 0 then default 1
*
* fps_out_flex
* 0 - fix output frame rate
* 1 - variable output frame rate
*
* fps_out_num
* output frame rate numerator, if 0 then default 30
*
* fps_out_denorm
* output frame rate denorminator, if 0 then default 1
*/
typedef struct RcFpsCfg_t {
RK_S32 fps_in_flex;
RK_S32 fps_in_num;
RK_S32 fps_in_denorm;
RK_S32 fps_out_flex;
RK_S32 fps_out_num;
RK_S32 fps_out_denorm;
} RcFpsCfg;
typedef struct RcSuperframeCfg_t {
MppEncRcSuperFrameMode super_mode;
RK_U32 super_i_thd;
RK_U32 super_p_thd;
MppEncRcPriority rc_priority;
} RcSuperframeCfg;
typedef struct RcDebreathCfg_t {
RK_U32 enable;
RK_U32 strength;
} RcDebreathCfg;
typedef struct RcHierQPCfg_t {
RK_S32 hier_qp_en;
RK_S32 hier_qp_delta[4];
RK_S32 hier_frame_num[4];
} RcHierQPCfg;
/*
* Control parameter from external config
*
* It will be updated on rc/prep/gopref config changed.
*/
typedef struct RcCfg_s {
/* encode image size */
RK_S32 width;
RK_S32 height;
/* Use rc_mode to find different api */
RcMode mode;
RcFpsCfg fps;
GopMode gop_mode;
/* I frame gop len */
RK_S32 igop;
/* visual gop len */
RK_S32 vgop;
/* bitrate parameter */
RK_S32 bps_min;
RK_S32 bps_target;
RK_S32 bps_max;
RK_S32 stats_time;
/* max I frame bit ratio to P frame bit */
RK_S32 max_i_bit_prop;
RK_S32 min_i_bit_prop;
RK_S32 init_ip_ratio;
/* layer bitrate proportion */
RK_S32 layer_bit_prop[4];
/* quality parameter */
RK_S32 init_quality;
RK_S32 max_quality;
RK_S32 min_quality;
RK_S32 max_i_quality;
RK_S32 min_i_quality;
RK_S32 i_quality_delta;
RK_S32 vi_quality_delta;
/* layer quality proportion */
RK_S32 layer_quality_delta[4];
/* reencode parameter */
RK_S32 max_reencode_times;
/* still / motion desision parameter */
RK_S32 min_still_prop;
RK_S32 max_still_quality;
/*
* vbr parameter
*
* vbr_hi_prop - high proportion bitrate for reduce quality
* vbr_lo_prop - low proportion bitrate for increase quality
*/
RK_S32 vbr_hi_prop;
RK_S32 vbr_lo_prop;
MppEncRcDropFrmMode drop_mode;
RK_U32 drop_thd;
RK_U32 drop_gap;
RcSuperframeCfg super_cfg;
RcDebreathCfg debreath_cfg;
RcHierQPCfg hier_qp_cfg;
RK_U32 refresh_len;
} RcCfg;
/*
* Different rate control strategy will be implemented by different API config
*/
typedef struct RcImplApi_t {
char *name;
MppCodingType type;
RK_U32 ctx_size;
MPP_RET (*init)(void *ctx, RcCfg *cfg);
MPP_RET (*deinit)(void *ctx);
MPP_RET (*check_drop)(void *ctx, EncRcTask *task);
MPP_RET (*check_reenc)(void *ctx, EncRcTask *task);
/*
* frm_start - frame level rate control frm_start.
* The EncRcTaskInfo will be output to hal for hardware to implement.
* frm_end - frame level rate control frm_end.
* The EncRcTaskInfo is returned for real quality and bitrate.
*/
MPP_RET (*frm_start)(void *ctx, EncRcTask *task);
MPP_RET (*frm_end)(void *ctx, EncRcTask *task);
/*
* hal_start - hardware level rate control start.
* The EncRcTaskInfo will be output to hal for hardware to implement.
* hal_end - hardware level rate control end.
* The EncRcTaskInfo is returned for real quality and bitrate.
*/
MPP_RET (*hal_start)(void *ctx, EncRcTask *task);
MPP_RET (*hal_end)(void *ctx, EncRcTask *task);
} RcImplApi;
/*
* structures for RC API register and query
*/
typedef struct RcApiBrief_t {
const char *name;
MppCodingType type;
} RcApiBrief;
typedef struct RcApiQueryAll_t {
/* input param for query */
RcApiBrief *brief;
RK_S32 max_count;
/* output query count */
RK_S32 count;
} RcApiQueryAll;
typedef struct RcApiQueryType_t {
/* input param for query */
RcApiBrief *brief;
RK_S32 max_count;
MppCodingType type;
/* output query count */
RK_S32 count;
} RcApiQueryType;
#ifdef __cplusplus
extern "C" {
#endif
MPP_RET rc_api_add(const RcImplApi *api);
MPP_RET rc_brief_get_all(RcApiQueryAll *query);
MPP_RET rc_brief_get_by_type(RcApiQueryType *query);
#ifdef __cplusplus
}
#endif
#endif /* __MPP_RC_API_H__ */
|