mpp/inc/mpp_rc_api.h
Herman Chen 6d52e80b27 [encoder]: Change rate control work flow
1. Add mpp_rc_api and mpp_rc_defs for open rc module to external users.
2. Add RcImplApi registration and setup function.
3. Separate RC module from the encoder implement.
4. Use EncFrmStatus and EncRcTaskInfo to control work flow.
5. proc_rc and update_rc function in enc_impl are removed.
6. Use rc_frm_start and rc_hal_start to process rate control.
7. Add more RcCfg setup in mpp_enc_v2.cpp.
8. Use rc_task to replace all the frame status and rc config transmit.
   EncFrmStatus is for encoder flow control.
   EncRcTaskInfo is for communication between rc / hal / hardware

Change-Id: Ia72b0e0804bfca13963c2b2a5887983fd9b5bcbf
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
Signed-off-by: sayon.chen <sayon.chen@rock-chips.com>
2020-03-19 14:43:02 +08:00

221 lines
5.8 KiB
C

/*
* 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 "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_CBR,
RC_VBR,
RC_AVBR,
RC_CVBR,
RC_QVBR,
RC_FIXQP,
RC_LEARNING,
RC_MODE_BUTT,
} RcMode;
/*
* 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;
/*
* 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;
/* 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 stat_times;
/* max I frame bit ratio to P frame bit */
RK_S32 max_i_bit_prop;
RK_S32 min_i_bit_prop;
/* 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;
/* 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;
} 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);
/*
* 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__ */