From 560213eef9ac786093a0740d94ca20b55962617c Mon Sep 17 00:00:00 2001 From: ChenHengming Date: Wed, 3 Aug 2016 06:20:01 +0000 Subject: [PATCH] [h264]: encoder and decoder share common definition [h264e]: separate init and config into two functions and add mpp encoder config check function git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@1145 6e48237b-75ef-9749-8fc9-41990f28c85a --- inc/rk_mpi.h | 4 + mpp/codec/dec/h264/h264d_dpb.c | 2 +- mpp/codec/dec/h264/h264d_global.h | 50 +---- mpp/codec/dec/h264/h264d_init.c | 2 +- mpp/codec/dec/h264/h264d_scalist.c | 2 +- mpp/codec/dec/h264/h264d_sps.c | 20 +- mpp/codec/enc/h264/include/H264Init.h | 19 +- mpp/codec/enc/h264/include/H264Instance.h | 8 +- .../enc/h264/include/encasiccontroller.h | 4 - mpp/codec/enc/h264/include/h264encapi.h | 34 +--- mpp/codec/enc/h264/src/H264EncApi.c | 21 +- mpp/codec/enc/h264/src/H264Init.c | 91 +++------ mpp/codec/enc/h264/src/encasiccontroller_v2.c | 90 --------- mpp/codec/enc/h264/src/h264e_api.c | 188 ++++++++++++++---- mpp/codec/inc/encoder_codec_api.h | 1 + mpp/codec/mpp_enc.cpp | 54 ++--- mpp/common/h264_syntax.h | 94 +++++++++ mpp/common/h264d_syntax.h | 1 + mpp/common/h264e_syntax.h | 10 +- mpp/hal/rkenc/h264e/hal_h264e_rkv.c | 40 ++-- mpp/legacy/vpu_api_legacy.cpp | 45 ++++- 21 files changed, 421 insertions(+), 359 deletions(-) delete mode 100644 mpp/codec/enc/h264/src/encasiccontroller_v2.c create mode 100644 mpp/common/h264_syntax.h diff --git a/inc/rk_mpi.h b/inc/rk_mpi.h index 34f2251b..07e7d483 100644 --- a/inc/rk_mpi.h +++ b/inc/rk_mpi.h @@ -129,6 +129,10 @@ typedef void* MppParam; * and decoder will try to decode the */ typedef struct MppEncConfig_t { + /* encoder config also need to know size of itself */ + RK_U32 size; + RK_U32 version; + /* * input source data format */ diff --git a/mpp/codec/dec/h264/h264d_dpb.c b/mpp/codec/dec/h264/h264d_dpb.c index 158a3aab..6eaa1e4f 100644 --- a/mpp/codec/dec/h264/h264d_dpb.c +++ b/mpp/codec/dec/h264/h264d_dpb.c @@ -117,7 +117,7 @@ static RK_S32 getDpbSize(H264dVideoCtx_t *p_Vid, H264_SPS_t *active_sps) } size /= pic_size; if (p_Vid->active_mvc_sps_flag && - (p_Vid->profile_idc == MVC_HIGH || p_Vid->profile_idc == STEREO_HIGH)) { + (p_Vid->profile_idc == H264_PROFILE_MVC_HIGH || p_Vid->profile_idc == H264_PROFILE_STEREO_HIGH)) { num_views = p_Vid->active_subsps->num_views_minus1 + 1; size = MPP_MIN(2 * size, MPP_MAX(1, RoundLog2(num_views)) * 16) / num_views; } else { diff --git a/mpp/codec/dec/h264/h264d_global.h b/mpp/codec/dec/h264/h264d_global.h index b22b55c6..32054cc1 100644 --- a/mpp/codec/dec/h264/h264d_global.h +++ b/mpp/codec/dec/h264/h264d_global.h @@ -26,9 +26,6 @@ #include "h264d_log.h" #include "h264d_syntax.h" -//!< define -#define MAXSPS 32 -#define MAXPPS 256 #define START_PREFIX_3BYTE 3 #define MAX_NUM_DPB_LAYERS 2 #define MAX_LIST_SIZE 33 //!< for init list reorder @@ -44,51 +41,6 @@ #define NALU_BUF_MAX_SIZE (10*1024*1024) #define SODB_BUF_MAX_SIZE (10*1024*1024) -//!< AVC Profile IDC definitions -typedef enum { - FREXT_CAVLC444 = 44, //!< YUV 4:4:4/14 "CAVLC 4:4:4" - BASELINE = 66, //!< YUV 4:2:0/8 "Baseline" - H264_MAIN = 77, //!< YUV 4:2:0/8 "Main" - EXTENDED = 88, //!< YUV 4:2:0/8 "Extended" - FREXT_HP = 100, //!< YUV 4:2:0/8 "High" - FREXT_Hi10P = 110, //!< YUV 4:2:0/10 "High 10" - FREXT_Hi422 = 122, //!< YUV 4:2:2/10 "High 4:2:2" - FREXT_Hi444 = 244, //!< YUV 4:4:4/14 "High 4:4:4" - MVC_HIGH = 118, //!< YUV 4:2:0/8 "Multiview High" - STEREO_HIGH = 128 //!< YUV 4:2:0/8 "Stereo High" -} ProfileIDC; - -//!< values for nalu_type -typedef enum { - NALU_TYPE_NULL = 0, - NALU_TYPE_SLICE = 1, - NALU_TYPE_DPA = 2, - NALU_TYPE_DPB = 3, - NALU_TYPE_DPC = 4, - NALU_TYPE_IDR = 5, - NALU_TYPE_SEI = 6, - NALU_TYPE_SPS = 7, - NALU_TYPE_PPS = 8, - NALU_TYPE_AUD = 9, // Access Unit Delimiter - NALU_TYPE_EOSEQ = 10, // end of sequence - NALU_TYPE_EOSTREAM = 11, // end of stream - NALU_TYPE_FILL = 12, - NALU_TYPE_SPSEXT = 13, - NALU_TYPE_PREFIX = 14, // prefix - NALU_TYPE_SUB_SPS = 15, - NALU_TYPE_SLICE_AUX = 19, - NALU_TYPE_SLC_EXT = 20, // slice extensive - NALU_TYPE_VDRD = 24 // View and Dependency Representation Delimiter NAL Unit -} Nalu_type; - -//!< values for nal_ref_idc -typedef enum { - NALU_PRIORITY_HIGHEST = 3, - NALU_PRIORITY_HIGH = 2, - NALU_PRIORITY_LOW = 1, - NALU_PRIORITY_DISPOSABLE = 0 -} NalRefIdc_type; - //!< PPS parameters #define MAXnum_slice_groups_minus1 8 enum { @@ -110,6 +62,7 @@ typedef enum { FRAME = 0x3, STRUCT_MAX, } PictureStructure; //!< New enum for field processing + typedef enum { PIC_ERR_NULL = 0, PIC_ERR_TOP = 0x1, @@ -126,6 +79,7 @@ typedef enum { FIELD_ORDER_SAME, FIELD_ORDER_MAX } FieldOrder; + //!< Field Coding Types typedef enum { FRAME_CODING = 0, diff --git a/mpp/codec/dec/h264/h264d_init.c b/mpp/codec/dec/h264/h264d_init.c index dcc67bac..b19fd8bf 100644 --- a/mpp/codec/dec/h264/h264d_init.c +++ b/mpp/codec/dec/h264/h264d_init.c @@ -548,7 +548,7 @@ static MPP_RET alloc_decpic(H264_SLICE_t *currSlice) dec_pic->inter_view_flag = currSlice->inter_view_flag; dec_pic->anchor_pic_flag = currSlice->anchor_pic_flag; if (dec_pic->layer_id == 1) { - if ((p_Vid->profile_idc == MVC_HIGH) || (p_Vid->profile_idc == STEREO_HIGH)) { + if ((p_Vid->profile_idc == H264_PROFILE_MVC_HIGH) || (p_Vid->profile_idc == H264_PROFILE_STEREO_HIGH)) { FUN_CHECK(ret = init_mvc_picture(currSlice)); } } diff --git a/mpp/codec/dec/h264/h264d_scalist.c b/mpp/codec/dec/h264/h264d_scalist.c index e3c04ad3..c9412798 100644 --- a/mpp/codec/dec/h264/h264d_scalist.c +++ b/mpp/codec/dec/h264/h264d_scalist.c @@ -161,7 +161,7 @@ static void set_pps_scanlist_matrix(H264_SPS_t *sps, H264_PPS_t *pps, H264dVideo //extern "C" RK_U32 is_prext_profile(RK_U32 profile_idc) { - return (profile_idc >= FREXT_HP || profile_idc == FREXT_CAVLC444) ? 1 : 0; + return (profile_idc >= H264_PROFILE_HIGH || profile_idc == H264_PROFILE_FREXT_CAVLC444) ? 1 : 0; } /*! diff --git a/mpp/codec/dec/h264/h264d_sps.c b/mpp/codec/dec/h264/h264d_sps.c index 34e35b54..d0c4afd2 100644 --- a/mpp/codec/dec/h264/h264d_sps.c +++ b/mpp/codec/dec/h264/h264d_sps.c @@ -23,6 +23,7 @@ #include "vpu_api.h" +#include "h264_syntax.h" #include "h264d_log.h" #include "h264d_sps.h" #include "h264d_scalist.h" @@ -154,11 +155,16 @@ static MPP_RET parser_sps(BitReadCtx_t *p_bitctx, H264_SPS_t *cur_sps, H264_DecC cur_sps->delta_pic_order_always_zero_flag = 0; LogInfo(p_bitctx->ctx, "----------------------------- SPS begin --------------------------------"); READ_BITS(p_bitctx, 8, &cur_sps->profile_idc, "profile_idc"); - VAL_CHECK (ret, (cur_sps->profile_idc == BASELINE) || (cur_sps->profile_idc == H264_MAIN) - || (cur_sps->profile_idc == EXTENDED) || (cur_sps->profile_idc == FREXT_HP) - || (cur_sps->profile_idc == FREXT_Hi10P) || (cur_sps->profile_idc == FREXT_Hi422) - || (cur_sps->profile_idc == FREXT_Hi444) || (cur_sps->profile_idc == FREXT_CAVLC444) - || (cur_sps->profile_idc == MVC_HIGH) || (cur_sps->profile_idc == STEREO_HIGH) + VAL_CHECK (ret, (cur_sps->profile_idc == H264_PROFILE_BASELINE) + || (cur_sps->profile_idc == H264_PROFILE_MAIN) + || (cur_sps->profile_idc == H264_PROFILE_EXTENDED) + || (cur_sps->profile_idc == H264_PROFILE_HIGH) + || (cur_sps->profile_idc == H264_PROFILE_HIGH10) + || (cur_sps->profile_idc == H264_PROFILE_HIGH422) + || (cur_sps->profile_idc == H264_PROFILE_HIGH444) + || (cur_sps->profile_idc == H264_PROFILE_FREXT_CAVLC444) + || (cur_sps->profile_idc == H264_PROFILE_MVC_HIGH) + || (cur_sps->profile_idc == H264_PROFILE_STEREO_HIGH) ); READ_ONEBIT(p_bitctx, &cur_sps->constrained_set0_flag, "constrained_set0_flag"); READ_ONEBIT(p_bitctx, &cur_sps->constrained_set1_flag, "constrained_set1_flag"); @@ -326,8 +332,8 @@ static MPP_RET parser_subsps_ext(BitReadCtx_t *p_bitctx, H264_subSPS_t *cur_subs { MPP_RET ret = MPP_ERR_UNKNOW; - if ((cur_subsps->sps.profile_idc == MVC_HIGH) - || (cur_subsps->sps.profile_idc == STEREO_HIGH)) { + if ((cur_subsps->sps.profile_idc == H264_PROFILE_MVC_HIGH) + || (cur_subsps->sps.profile_idc == H264_PROFILE_STEREO_HIGH)) { READ_ONEBIT(p_bitctx, &cur_subsps->bit_equal_to_one, "bit_equal_to_one"); ASSERT(cur_subsps->bit_equal_to_one == 1); FUN_CHECK(ret = sps_mvc_extension(p_bitctx, cur_subsps)); diff --git a/mpp/codec/enc/h264/include/H264Init.h b/mpp/codec/enc/h264/include/H264Init.h index af64fbac..139a5d30 100644 --- a/mpp/codec/enc/h264/include/H264Init.h +++ b/mpp/codec/enc/h264/include/H264Init.h @@ -17,27 +17,12 @@ #ifndef __H264_INIT_H__ #define __H264_INIT_H__ -/*------------------------------------------------------------------------------ - 1. Include headers -------------------------------------------------------------------------------*/ #include "h264encapi.h" #include "H264Instance.h" -/*------------------------------------------------------------------------------ - 2. External compiler flags --------------------------------------------------------------------------------- - --------------------------------------------------------------------------------- - 3. Module defines -------------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------------ - 4. Function prototypes -------------------------------------------------------------------------------*/ - -bool_e H264CheckCfg(const H264EncConfig * pEncCfg); i32 H264GetAllowedWidth(i32 width, H264EncPictureFormat inputType); -H264EncRet H264Init(const H264EncConfig * pEncCfg, h264Instance_s * pinst); +H264EncRet H264Init(h264Instance_s * pinst); +H264EncRet H264Cfg(const H264EncConfig * pEncCfg, h264Instance_s * pinst); #endif diff --git a/mpp/codec/enc/h264/include/H264Instance.h b/mpp/codec/enc/h264/include/H264Instance.h index 4d71d3b1..c107ed4e 100644 --- a/mpp/codec/enc/h264/include/H264Instance.h +++ b/mpp/codec/enc/h264/include/H264Instance.h @@ -82,12 +82,6 @@ typedef struct { u32 streamSize; /* Size of output stream in bytes */ } H264EncOut; -/* Encoder configure parameter */ -typedef struct { - RK_U32 intraPicRate; // set I frame interval, and is 30 default -} H264EncCfg; - - typedef struct { u32 encStatus; RK_U32 lumWidthSrc; // TODO need to think again modify by lance 2016.06.15 @@ -112,7 +106,7 @@ typedef struct { // then determine next frame to which type to be encoded H264EncIn encIn; // put input struct into instance, todo modify by lance 2016.05.31 H264EncOut encOut; // put input struct into instance, todo modify by lance 2016.05.31 - H264EncCfg h264EncCfg; + RK_U32 intraPicRate; // set I frame interval, and is 30 default } h264Instance_s; #define H264E_DBG_FUNCTION (0x00000001) diff --git a/mpp/codec/enc/h264/include/encasiccontroller.h b/mpp/codec/enc/h264/include/encasiccontroller.h index 9ddf86de..6f06c16d 100644 --- a/mpp/codec/enc/h264/include/encasiccontroller.h +++ b/mpp/codec/enc/h264/include/encasiccontroller.h @@ -181,7 +181,6 @@ typedef struct { } regValues_s; typedef struct { - const void *ewl; regValues_s regs; } asicData_s; @@ -190,9 +189,6 @@ typedef struct { ------------------------------------------------------------------------------*/ i32 EncAsicControllerInit(asicData_s * asic); -i32 EncAsicMemAlloc_V2(asicData_s * asic, u32 width, u32 height, - u32 encodingType); - /* Functions for controlling ASIC */ void EncAsicFrameStart(void * inst,/* const void *ewl,*/ regValues_s * val, h264e_syntax *syntax_data); // mask by lance 2016.05.12 #endif diff --git a/mpp/codec/enc/h264/include/h264encapi.h b/mpp/codec/enc/h264/include/h264encapi.h index 047870e7..ee678aee 100644 --- a/mpp/codec/enc/h264/include/h264encapi.h +++ b/mpp/codec/enc/h264/include/h264encapi.h @@ -17,6 +17,7 @@ #ifndef __H264ENCAPI_H__ #define __H264ENCAPI_H__ +#include "h264_syntax.h" #include "basetype.h" #include "h264e_syntax.h" @@ -27,16 +28,8 @@ extern "C" #include "H264Instance.h" -/*------------------------------------------------------------------------------ - 1. Type definition for encoder instance -------------------------------------------------------------------------------*/ - typedef const void *H264EncInst; -/*------------------------------------------------------------------------------ - 2. Enumerations for API parameters -------------------------------------------------------------------------------*/ - /* Function return values */ typedef enum { H264ENC_OK = 0, @@ -67,23 +60,6 @@ typedef enum { H264ENC_NAL_UNIT_STREAM = 1 /* Plain NAL units without startcode */ } H264EncStreamType; -/* Level for initialization */ -typedef enum { - H264ENC_LEVEL_1 = 10, - H264ENC_LEVEL_1_b = 99, - H264ENC_LEVEL_1_1 = 11, - H264ENC_LEVEL_1_2 = 12, - H264ENC_LEVEL_1_3 = 13, - H264ENC_LEVEL_2 = 20, - H264ENC_LEVEL_2_1 = 21, - H264ENC_LEVEL_2_2 = 22, - H264ENC_LEVEL_3 = 30, - H264ENC_LEVEL_3_1 = 31, - H264ENC_LEVEL_3_2 = 32, - H264ENC_LEVEL_4_0 = 40, - H264ENC_LEVEL_4_1 = 41 -} H264EncLevel; - /* Picture YUV type for initialization */ typedef enum { H264ENC_YUV420_PLANAR = 0, /* YYYY... UUUU... VVVV */ @@ -133,8 +109,8 @@ typedef struct { H264EncStreamType streamType; /* Byte stream / Plain NAL units */ /* Stream Profile will be automatically decided, * CABAC -> main/high, 8x8-transform -> high */ - h264e_profile profile; - H264EncLevel level; + H264Profile profile; + H264Level level; u32 width; /* Encoded picture width in pixels, multiple of 4 */ u32 height; /* Encoded picture height in pixels, multiple of 2 */ u32 frameRateNum; /* The stream time scale, [1..65535] */ @@ -271,11 +247,11 @@ typedef struct { ------------------------------------------------------------------------------*/ /* Initialization & release */ -H264EncRet H264EncInit(const H264EncConfig * pEncConfig, - h264Instance_s * instAddr); +H264EncRet H264EncInit(h264Instance_s *instAddr); H264EncRet H264EncRelease(H264EncInst inst); /* Encoder configuration before stream generation */ +H264EncRet H264EncCfg(H264EncInst inst, const H264EncConfig * pEncConfig); H264EncRet H264EncSetCodingCtrl(H264EncInst inst, const H264EncCodingCtrl * pCodingParams); H264EncRet H264EncGetCodingCtrl(H264EncInst inst, H264EncCodingCtrl * diff --git a/mpp/codec/enc/h264/src/H264EncApi.c b/mpp/codec/enc/h264/src/H264EncApi.c index 2a914022..a5e18800 100644 --- a/mpp/codec/enc/h264/src/H264EncApi.c +++ b/mpp/codec/enc/h264/src/H264EncApi.c @@ -58,14 +58,14 @@ static i32 VSCheckSize(u32 inputWidth, u32 inputHeight, u32 stabilizedWidth, Argument : pEncCfg - initialization parameters instAddr - where to save the created instance ------------------------------------------------------------------------------*/ -H264EncRet H264EncInit(const H264EncConfig * pEncCfg, h264Instance_s * instAddr) +H264EncRet H264EncInit(h264Instance_s *instAddr) { H264EncRet ret; h264Instance_s *pEncInst = instAddr; h264e_dbg_func("enter\n"); - ret = H264Init(pEncCfg, pEncInst); + ret = H264Init(pEncInst); if (ret != H264ENC_OK) { mpp_err("H264EncInit: ERROR Initialization failed"); return ret; @@ -109,6 +109,23 @@ H264EncRet H264EncRelease(H264EncInst inst) return H264ENC_OK; } +H264EncRet H264EncCfg(H264EncInst inst, const H264EncConfig * pEncConfig) +{ + H264EncRet ret; + h264Instance_s *pEncInst = (h264Instance_s *) inst; + + h264e_dbg_func("enter\n"); + + ret = H264Cfg(pEncConfig, pEncInst); + if (ret != H264ENC_OK) { + mpp_err("H264EncCfg: ERROR Config failed"); + return ret; + } + + h264e_dbg_func("leave\n"); + return H264ENC_OK; +} + /*------------------------------------------------------------------------------ Function name : H264EncSetCodingCtrl diff --git a/mpp/codec/enc/h264/src/H264Init.c b/mpp/codec/enc/h264/src/H264Init.c index 491316be..10bb3a03 100644 --- a/mpp/codec/enc/h264/src/H264Init.c +++ b/mpp/codec/enc/h264/src/H264Init.c @@ -63,7 +63,7 @@ static bool_e CheckParameter(const h264Instance_s * inst); H264ENC_INVALID_ARGUMENT ------------------------------------------------------------------------------*/ -H264EncRet H264Init(const H264EncConfig * pEncCfg, h264Instance_s * pinst) +H264EncRet H264Init(h264Instance_s * pinst) { h264Instance_s *inst = pinst; @@ -74,68 +74,13 @@ H264EncRet H264Init(const H264EncConfig * pEncCfg, h264Instance_s * pinst) H264PicParameterSetInit(&inst->picParameterSet); H264SliceInit(&inst->slice); - /* Set parameters depending on user config */ - if (SetParameter(inst, pEncCfg) != ENCHW_OK) { - mpp_err("SetParameter error\n"); - ret = H264ENC_INVALID_ARGUMENT; - goto err; - } - /* Check and init the rest of parameters */ - if (CheckParameter(inst) != ENCHW_OK) { - mpp_err("CheckParameter error\n"); - ret = H264ENC_INVALID_ARGUMENT; - goto err; - } - - if (H264InitRc(&inst->rateControl) != ENCHW_OK) { - mpp_err("H264InitRc error\n"); - return H264ENC_INVALID_ARGUMENT; - } /* Initialize ASIC */ - inst->asic.ewl = NULL;//ewl; - (void) EncAsicControllerInit(&inst->asic); - - /* Allocate internal SW/HW shared memories */ - if (EncAsicMemAlloc_V2(&inst->asic, - (u32) inst->preProcess.lumWidth, - (u32) inst->preProcess.lumHeight, - ASIC_H264) != ENCHW_OK) { - - ret = H264ENC_EWL_MEMORY_ERROR; - goto err; - } - - /* init VUI */ - { - const h264VirtualBuffer_s *vb = &inst->rateControl.virtualBuffer; - - H264SpsSetVuiTimigInfo(&inst->seqParameterSet, - vb->timeScale, vb->unitsInTic); - } - - if (inst->seqParameterSet.levelIdc >= 31) - inst->asic.regs.h264Inter4x4Disabled = 1; - else - inst->asic.regs.h264Inter4x4Disabled = 0; - - /* When resolution larger than 720p = 3600 macroblocks - * there is not enough time to do 1/4 pixel ME */ - if (inst->mbPerFrame > 3600) - inst->asic.regs.disableQuarterPixelMv = 1; - else - inst->asic.regs.disableQuarterPixelMv = 0; + EncAsicControllerInit(&inst->asic); + inst->asic.regs.codingType = ASIC_H264; inst->asic.regs.skipPenalty = 1; return ret; - -err: - /*if(inst != NULL) - free(inst);*/ - /*if(ewl != NULL) - (void) EWLRelease(ewl);*/ - - return ret; } /*------------------------------------------------------------------------------ @@ -202,15 +147,17 @@ bool_e SetParameter(h264Instance_s * inst, const H264EncConfig * pEncCfg) } /* Level 1b is indicated with levelIdc == 11 and constraintSet3 */ - if (pEncCfg->level == H264ENC_LEVEL_1_b) { + if (pEncCfg->level == H264_LEVEL_1_b) { inst->seqParameterSet.levelIdc = 11; inst->seqParameterSet.constraintSet3 = ENCHW_YES; } /* Get the index for the table of level maximum values */ tmp = H264GetLevelIndex(inst->seqParameterSet.levelIdc); - if (tmp == INVALID_LEVEL) + if (tmp == INVALID_LEVEL) { + mpp_err("H264GetLevelIndex failed\n"); return ENCHW_NOK; + } inst->seqParameterSet.levelIdx = tmp; @@ -342,18 +289,42 @@ H264EncRet H264Cfg(const H264EncConfig * pEncCfg, h264Instance_s * pinst) /* Set parameters depending on user config */ if (SetParameter(inst, pEncCfg) != ENCHW_OK) { ret = H264ENC_INVALID_ARGUMENT; + mpp_err_f("SetParameter failed\n"); + return ret; } /* Check and init the rest of parameters */ if (CheckParameter(inst) != ENCHW_OK) { ret = H264ENC_INVALID_ARGUMENT; + mpp_err_f("CheckParameter failed\n"); return ret; } if (H264InitRc(&inst->rateControl) != ENCHW_OK) { + mpp_err_f("H264InitRc failed\n"); return H264ENC_INVALID_ARGUMENT; } + /* init VUI */ + { + const h264VirtualBuffer_s *vb = &inst->rateControl.virtualBuffer; + + H264SpsSetVuiTimigInfo(&inst->seqParameterSet, + vb->timeScale, vb->unitsInTic); + } + + if (inst->seqParameterSet.levelIdc >= 31) + inst->asic.regs.h264Inter4x4Disabled = 1; + else + inst->asic.regs.h264Inter4x4Disabled = 0; + + /* When resolution larger than 720p = 3600 macroblocks + * there is not enough time to do 1/4 pixel ME */ + if (inst->mbPerFrame > 3600) + inst->asic.regs.disableQuarterPixelMv = 1; + else + inst->asic.regs.disableQuarterPixelMv = 0; + return ret; } diff --git a/mpp/codec/enc/h264/src/encasiccontroller_v2.c b/mpp/codec/enc/h264/src/encasiccontroller_v2.c deleted file mode 100644 index 457e95e2..00000000 --- a/mpp/codec/enc/h264/src/encasiccontroller_v2.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2015 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. - */ - -/*------------------------------------------------------------------------------ - Include headers -------------------------------------------------------------------------------*/ -#include "encpreprocess.h" -#include "encasiccontroller.h" -#include "enccommon.h" -#include "ewl.h" -#include "mpp_log.h" -/*------------------------------------------------------------------------------ - External compiler flags -------------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------------ - Module defines -------------------------------------------------------------------------------*/ - -/* Mask fields */ -#define mask_2b (u32)0x00000003 -#define mask_3b (u32)0x00000007 -#define mask_4b (u32)0x0000000F -#define mask_5b (u32)0x0000001F -#define mask_6b (u32)0x0000003F -#define mask_11b (u32)0x000007FF -#define mask_14b (u32)0x00003FFF -#define mask_16b (u32)0x0000FFFF - -#define HSWREG(n) ((n)*4) - -/*------------------------------------------------------------------------------ - Local function prototypes -------------------------------------------------------------------------------*/ - -/*------------------------------------------------------------------------------ - - EncAsicMemAlloc_V2 - - Allocate HW/SW shared memory - - Input: - asic asicData structure - width width of encoded image, multiple of four - height height of encoded image - type ASIC_MPEG4 / ASIC_H263 / ASIC_JPEG - - Output: - asic base addresses point to allocated memory areas - - Return: - ENCHW_OK Success. - ENCHW_NOK Error: memory allocation failed, no memories allocated - and EWL instance released - -------------------------------------------------------------------------------*/ -i32 EncAsicMemAlloc_V2(asicData_s * asic, u32 width, u32 height, - u32 encodingType) -{ - regValues_s *regs; - - ASSERT(asic != NULL); - ASSERT(width != 0); - ASSERT(height != 0); - ASSERT((height % 2) == 0); - ASSERT((width % 4) == 0); - - regs = &asic->regs; - - regs->codingType = encodingType; - - width = (width + 15) / 16; - height = (height + 15) / 16; - - return ENCHW_OK; -} - diff --git a/mpp/codec/enc/h264/src/h264e_api.c b/mpp/codec/enc/h264/src/h264e_api.c index 88a878cd..5b005811 100644 --- a/mpp/codec/enc/h264/src/h264e_api.c +++ b/mpp/codec/enc/h264/src/h264e_api.c @@ -17,6 +17,7 @@ #define MODULE_TAG "H264E_API" #include "mpp_log.h" +#include "mpp_common.h" #include "H264Instance.h" #include "h264e_api.h" @@ -34,9 +35,16 @@ FILE *fp_syntax_in = NULL; MPP_RET h264e_init(void *ctx, ControllerCfg *ctrlCfg) { - (void)ctx; + h264Instance_s * pEncInst = (h264Instance_s*)ctx; + MPP_RET ret = (MPP_RET)H264EncInit(pEncInst); + + if (ret) { + mpp_err_f("H264EncInit() failed ret %d", ret); + } + (void)ctrlCfg; - return MPP_OK; + + return ret; } MPP_RET h264e_deinit(void *ctx) @@ -75,7 +83,6 @@ MPP_RET h264e_encode(void *ctx, /*HalEncTask **/void *task) h264Instance_s *pEncInst = (h264Instance_s *)ctx; // add by lance 2016.05.31 H264EncIn *encIn = &(pEncInst->encIn); // TODO modify by lance 2016.05.19 H264EncOut *encOut = &(pEncInst->encOut); // TODO modify by lance 2016.05.19 - const H264EncCfg *encCfgParam = &(pEncInst->h264EncCfg); RK_U32 srcLumaWidth = pEncInst->lumWidthSrc; RK_U32 srcLumaHeight = pEncInst->lumHeightSrc; @@ -118,8 +125,8 @@ MPP_RET h264e_encode(void *ctx, /*HalEncTask **/void *task) //encIn.busLumaStab = mpp_buffer_get_fd(pictureStabMem)/*pictureStabMem.phy_addr*/; /* Select frame type */ - if (encCfgParam->intraPicRate != 0 && - (pEncInst->intraPeriodCnt >= encCfgParam->intraPicRate)) { + if (pEncInst->intraPicRate != 0 && + (pEncInst->intraPeriodCnt >= pEncInst->intraPicRate)) { encIn->codingType = H264ENC_INTRA_FRAME; } else { encIn->codingType = H264ENC_PREDICTED_FRAME; @@ -150,31 +157,135 @@ MPP_RET h264e_flush(void *ctx) return MPP_OK; } + +static const H264Profile h264e_supported_profile[] = +{ + H264_PROFILE_BASELINE, + H264_PROFILE_MAIN, + H264_PROFILE_HIGH, +}; + +static const H264Level h264e_supported_level[] = +{ + H264_LEVEL_1, + H264_LEVEL_1_b, + H264_LEVEL_1_1, + H264_LEVEL_1_2, + H264_LEVEL_1_3, + H264_LEVEL_2, + H264_LEVEL_2_1, + H264_LEVEL_2_2, + H264_LEVEL_3, + H264_LEVEL_3_1, + H264_LEVEL_3_2, + H264_LEVEL_4_0, + H264_LEVEL_4_1, + H264_LEVEL_4_2, +}; + +static MPP_RET h264e_check_mpp_cfg(MppEncConfig *mpp_cfg) +{ + MPP_RET ret = MPP_NOK; + RK_U32 i, count; + + count = MPP_ARRAY_ELEMS(h264e_supported_profile); + for (i = 0; i < count; i++) { + if (h264e_supported_profile[i] == (H264Profile)mpp_cfg->profile) { + break; + } + } + + if (i >= count) { + mpp_log_f("invalid profile %d set to default baseline\n", mpp_cfg->profile); + mpp_cfg->profile = H264_PROFILE_BASELINE; + } + + count = MPP_ARRAY_ELEMS(h264e_supported_level); + for (i = 0; i < count; i++) { + if (h264e_supported_level[i] == (H264Level)mpp_cfg->level) { + break; + } + } + + if (i >= count) { + mpp_log_f("invalid level %d set to default 4.0\n", mpp_cfg->level); + mpp_cfg->level = H264_LEVEL_3; + } + + if (mpp_cfg->fps_in <= 0) { + mpp_log_f("invalid input fps %d will be set to default 30\n", mpp_cfg->fps_in); + mpp_cfg->fps_in = 30; + } + + if (mpp_cfg->fps_out <= 0) { + mpp_log_f("invalid output fps %d will be set to fps_in 30\n", mpp_cfg->fps_out, mpp_cfg->fps_in); + mpp_cfg->fps_out = mpp_cfg->fps_in; + } + + if (mpp_cfg->gop <= 0) { + mpp_log_f("invalid gop %d will be set to fps_out 30\n", mpp_cfg->gop, mpp_cfg->fps_out); + mpp_cfg->gop = mpp_cfg->fps_out; + } + + if (mpp_cfg->rc_mode < 0 || mpp_cfg->rc_mode > 2) { + mpp_err_f("invalid rc_mode %d\n", mpp_cfg->rc_mode); + return ret; + } + + if (mpp_cfg->qp <= 0 || mpp_cfg->qp > 51) { + mpp_log_f("invalid qp %d set to default 26\n", mpp_cfg->qp); + mpp_cfg->qp = 26; + } + + if (mpp_cfg->bps <= 0) { + mpp_err_f("invalid bit rate %d\n", mpp_cfg->bps); + return ret; + } + + if (mpp_cfg->width <= 0 || mpp_cfg->height <= 0) { + mpp_err_f("invalid width %d height %d\n", mpp_cfg->width, mpp_cfg->height); + return ret; + } + + if (mpp_cfg->hor_stride <= 0) { + mpp_err_f("invalid hor_stride %d will be set to %d\n", mpp_cfg->hor_stride, MPP_ALIGN(mpp_cfg->width, 16)); + mpp_cfg->hor_stride = MPP_ALIGN(mpp_cfg->width, 16); + } + + if (mpp_cfg->ver_stride <= 0) { + mpp_err_f("invalid ver_stride %d will be set to %d\n", mpp_cfg->ver_stride, MPP_ALIGN(mpp_cfg->height, 16)); + mpp_cfg->ver_stride = MPP_ALIGN(mpp_cfg->height, 16); + } + + return MPP_OK; +} + MPP_RET h264e_config(void *ctx, RK_S32 cmd, void *param) { + MPP_RET ret = MPP_NOK; h264Instance_s *pEncInst = (h264Instance_s *)ctx; // add by lance 2016.05.31 + h264e_control_debug_enter(); + switch (cmd) { + case CHK_ENC_CFG : { + ret = h264e_check_mpp_cfg((MppEncConfig *)param); + } break; case SET_ENC_CFG : { const H264EncConfig *encCfg = (const H264EncConfig *)param; - H264EncInst encoderOpen = (H264EncInst)ctx; + H264EncInst encoder = (H264EncInst)ctx; H264EncCodingCtrl oriCodingCfg; H264EncPreProcessingCfg oriPreProcCfg; - H264EncRet ret = MPP_OK; - h264e_control_debug_enter(); - - if ((ret = H264EncInit(encCfg, pEncInst)) != H264ENC_OK) { - mpp_err("H264EncInit() failed, ret %d.", ret); - return -1; - } + ret = H264EncCfg(encoder, encCfg); /* Encoder setup: coding control */ - if ((ret = H264EncGetCodingCtrl(encoderOpen, &oriCodingCfg)) != H264ENC_OK) { + ret = H264EncGetCodingCtrl(encoder, &oriCodingCfg); + if (ret) { mpp_err("H264EncGetCodingCtrl() failed, ret %d.", ret); - h264e_deinit((void*)encoderOpen); - return -1; + h264e_deinit((void*)encoder); + break; } else { // will be replaced modify by lance 2016.05.20 // ------------ @@ -186,18 +297,20 @@ MPP_RET h264e_config(void *ctx, RK_S32 cmd, void *param) oriCodingCfg.transform8x8Mode = 0; oriCodingCfg.videoFullRange = 0; oriCodingCfg.seiMessages = 0; - if ((ret = H264EncSetCodingCtrl(encoderOpen, &oriCodingCfg)) != H264ENC_OK) { + ret = H264EncSetCodingCtrl(encoder, &oriCodingCfg); + if (ret) { mpp_err("H264EncSetCodingCtrl() failed, ret %d.", ret); - h264e_deinit((void*)encoderOpen); - return -1; + h264e_deinit((void*)encoder); + break; } } /* PreP setup */ - if ((ret = H264EncGetPreProcessing(encoderOpen, &oriPreProcCfg)) != H264ENC_OK) { + ret = H264EncGetPreProcessing(encoder, &oriPreProcCfg); + if (ret) { mpp_err("H264EncGetPreProcessing() failed, ret %d.\n", ret); - h264e_deinit((void*)encoderOpen); - return -1; + h264e_deinit((void*)encoder); + break; } else { h264e_control_log("Get PreP: input %4dx%d : offset %4dx%d : format %d : rotation %d " ": stab %d : cc %d\n", @@ -208,8 +321,8 @@ MPP_RET h264e_config(void *ctx, RK_S32 cmd, void *param) // will be replaced modify by lance 2016.05.20 oriPreProcCfg.inputType = H264ENC_YUV420_SEMIPLANAR;//H264ENC_YUV420_PLANAR; oriPreProcCfg.rotation = H264ENC_ROTATE_0; - oriPreProcCfg.origWidth = encCfg->width/*352*/; - oriPreProcCfg.origHeight = encCfg->height/*288*/; + oriPreProcCfg.origWidth = encCfg->width; + oriPreProcCfg.origHeight = encCfg->height; oriPreProcCfg.xOffset = 0; oriPreProcCfg.yOffset = 0; oriPreProcCfg.videoStabilization = 0; @@ -222,10 +335,11 @@ MPP_RET h264e_config(void *ctx, RK_S32 cmd, void *param) oriPreProcCfg.colorConversion.coeffF = 38000; } - if ((ret = H264EncSetPreProcessing(encoderOpen, &oriPreProcCfg)) != H264ENC_OK) { + ret = H264EncSetPreProcessing(encoder, &oriPreProcCfg); + if (ret) { mpp_err("H264EncSetPreProcessing() failed.", ret); - h264e_deinit((void*)encoderOpen); - return -1; + h264e_deinit((void*)encoder); + break; } } @@ -237,24 +351,20 @@ MPP_RET h264e_config(void *ctx, RK_S32 cmd, void *param) mpp_err("open fp_syntax_in failed!"); } #endif - h264e_control_debug_leave(); - - } break; case SET_ENC_RC_CFG : { const H264EncRateCtrl *encCfg = (const H264EncRateCtrl *)param; H264EncInst encoder = (H264EncInst)ctx; H264EncRateCtrl oriRcCfg; - H264EncRet ret = MPP_OK; mpp_assert(pEncInst); - pEncInst->h264EncCfg.intraPicRate = encCfg->intraPicRate; + pEncInst->intraPicRate = encCfg->intraPicRate; pEncInst->intraPeriodCnt = encCfg->intraPicRate; /* Encoder setup: rate control */ - if ((ret = H264EncGetRateCtrl(encoder, &oriRcCfg)) != H264ENC_OK) { + ret = H264EncGetRateCtrl(encoder, &oriRcCfg); + if (ret) { mpp_err("H264EncGetRateCtrl() failed, ret %d.", ret); - return -1; } else { h264e_control_log("Get rate control: qp %2d [%2d, %2d] bps %8d\n", oriRcCfg.qpHdr, oriRcCfg.qpMin, oriRcCfg.qpMax, oriRcCfg.bitPerSecond); @@ -292,9 +402,9 @@ MPP_RET h264e_config(void *ctx, RK_S32 cmd, void *param) oriRcCfg.pictureRc, oriRcCfg.mbRc, oriRcCfg.pictureSkip, oriRcCfg.hrd, oriRcCfg.hrdCpbSize, oriRcCfg.gopLen); - if ((ret = H264EncSetRateCtrl(encoder, &oriRcCfg)) != H264ENC_OK) { + ret = H264EncSetRateCtrl(encoder, &oriRcCfg); + if (ret) { mpp_err("H264EncSetRateCtrl() failed, ret %d.", ret); - return -1; } } } break; @@ -305,7 +415,9 @@ MPP_RET h264e_config(void *ctx, RK_S32 cmd, void *param) mpp_err("No correspond cmd found, and can not config!"); break; } - return MPP_OK; + h264e_control_debug_leave(); + + return ret; } MPP_RET h264e_callback(void *ctx, void *feedback) @@ -430,7 +542,7 @@ MPP_RET h264e_callback(void *ctx, void *feedback) const ControlApi api_h264e_controller = { "h264e_control", MPP_VIDEO_CodingAVC, - sizeof(h264Instance_s),//sizeof(H264eContext), // TODO modify by lance 2016.05.20 + sizeof(h264Instance_s), 0, h264e_init, h264e_deinit, diff --git a/mpp/codec/inc/encoder_codec_api.h b/mpp/codec/inc/encoder_codec_api.h index cbd6e29c..d0398821 100644 --- a/mpp/codec/inc/encoder_codec_api.h +++ b/mpp/codec/inc/encoder_codec_api.h @@ -26,6 +26,7 @@ // config cmd typedef enum EncCfgCmd_t { + CHK_ENC_CFG, SET_ENC_CFG, SET_ENC_RC_CFG, GET_OUTPUT_STREAM_SIZE, diff --git a/mpp/codec/mpp_enc.cpp b/mpp/codec/mpp_enc.cpp index f7ac161a..9d46decf 100644 --- a/mpp/codec/mpp_enc.cpp +++ b/mpp/codec/mpp_enc.cpp @@ -337,12 +337,13 @@ MPP_RET mpp_enc_init(MppEnc **enc, MppCodingType coding) break; } - p->coding = coding; - p->controller = controller; - p->hal = hal; - p->tasks = hal_cfg.tasks; + p->coding = coding; + p->controller = controller; + p->hal = hal; + p->tasks = hal_cfg.tasks; p->frame_slots = frame_slots; p->packet_slots = packet_slots; + p->mpp_cfg.size = sizeof(p->mpp_cfg); *enc = p; return MPP_OK; } while (0); @@ -404,35 +405,33 @@ MPP_RET mpp_enc_control(MppEnc *enc, MpiCmd cmd, void *param) return MPP_ERR_NULL_PTR; } - // TODO - MppEncConfig *mpp_cfg = (MppEncConfig*)param; - H264EncConfig *enc_cfg = &(enc->enc_cfg); + MPP_RET ret = MPP_NOK; H264EncRateCtrl *enc_rc_cfg = &(enc->enc_rc_cfg); switch (cmd) { case MPP_ENC_SET_CFG : { + MppEncConfig *mpp_cfg = &enc->mpp_cfg; + H264EncConfig *enc_cfg = &enc->enc_cfg; //H264ENC_NAL_UNIT_STREAM; // decide whether stream start with start code,e.g."00 00 00 01" - enc->mpp_cfg = *mpp_cfg; + enc->mpp_cfg = *((MppEncConfig *)param); + + /* before set config to controller check it first */ + ret = controller_config(enc->controller, CHK_ENC_CFG, (void *)&enc->mpp_cfg); + if (ret) + break; enc_cfg->streamType = H264ENC_BYTE_STREAM; enc_cfg->frameRateDenom = 1; - if (mpp_cfg->profile) - enc_cfg->profile = (h264e_profile)mpp_cfg->profile; - else - enc_cfg->profile = H264_PROFILE_BASELINE; - if (mpp_cfg->level) - enc_cfg->level = (H264EncLevel)mpp_cfg->level; - else - enc_cfg->level = H264ENC_LEVEL_4_0; + enc_cfg->profile = (H264Profile)mpp_cfg->profile; + enc_cfg->level = (H264Level)mpp_cfg->level; + if (mpp_cfg->width && mpp_cfg->height) { - enc_cfg->width = mpp_cfg->width; + enc_cfg->width = mpp_cfg->width; enc_cfg->height = mpp_cfg->height; } else mpp_err("width %d height %d is not available\n", mpp_cfg->width, mpp_cfg->height); - if (mpp_cfg->fps_in) - enc_cfg->frameRateNum = mpp_cfg->fps_in; - else - enc_cfg->frameRateNum = 30; + + enc_cfg->frameRateNum = mpp_cfg->fps_in; if (mpp_cfg->cabac_en) enc_cfg->enable_cabac = mpp_cfg->cabac_en; else @@ -443,7 +442,7 @@ MPP_RET mpp_enc_control(MppEnc *enc, MpiCmd cmd, void *param) enc_cfg->pic_init_qp = mpp_cfg->qp; enc_cfg->second_chroma_qp_index_offset = 2; enc_cfg->pps_id = 0; - enc_cfg->input_image_format = H264ENC_YUV420_SEMIPLANAR; + enc_cfg->input_image_format = (H264EncPictureFormat)mpp_cfg->format; controller_config(enc->controller, SET_ENC_CFG, (void *)enc_cfg); @@ -487,19 +486,24 @@ MPP_RET mpp_enc_control(MppEnc *enc, MpiCmd cmd, void *param) mpp_extra_info_generate(enc); - mpp_hal_control(enc->hal, MPP_ENC_SET_EXTRA_INFO, (void*)(&(enc->extra_info_cfg))); + ret = mpp_hal_control(enc->hal, MPP_ENC_SET_EXTRA_INFO, (void*)(&(enc->extra_info_cfg))); } break; case MPP_ENC_GET_CFG : { + MppEncConfig *mpp_cfg = (MppEncConfig *)param; + + mpp_assert(mpp_cfg->size == sizeof(enc->mpp_cfg)); + *mpp_cfg = enc->mpp_cfg; + ret = MPP_OK; } break; case MPP_ENC_GET_EXTRA_INFO : { - mpp_hal_control(enc->hal, cmd, param); + ret = mpp_hal_control(enc->hal, cmd, param); } break; default : { } break; } - return MPP_OK; + return ret; } diff --git a/mpp/common/h264_syntax.h b/mpp/common/h264_syntax.h new file mode 100644 index 00000000..9c97adc6 --- /dev/null +++ b/mpp/common/h264_syntax.h @@ -0,0 +1,94 @@ +/* +* +* Copyright 2015 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 __H264_SYNTAX_H__ +#define __H264_SYNTAX_H__ + +/* H.264/AVC-specific definition */ + +//!< define +#define MAXSPS 32 +#define MAXPPS 256 + +//!< AVC Profile IDC definitions +typedef enum h264e_profile_t { + H264_PROFILE_FREXT_CAVLC444 = 44, //!< YUV 4:4:4/14 "CAVLC 4:4:4" + H264_PROFILE_BASELINE = 66, //!< YUV 4:2:0/8 "Baseline" + H264_PROFILE_MAIN = 77, //!< YUV 4:2:0/8 "Main" + H264_PROFILE_EXTENDED = 88, //!< YUV 4:2:0/8 "Extended" + H264_PROFILE_HIGH = 100, //!< YUV 4:2:0/8 "High" + H264_PROFILE_HIGH10 = 110, //!< YUV 4:2:0/10 "High 10" + H264_PROFILE_HIGH422 = 122, //!< YUV 4:2:2/10 "High 4:2:2" + H264_PROFILE_HIGH444 = 244, //!< YUV 4:4:4/14 "High 4:4:4" + H264_PROFILE_MVC_HIGH = 118, //!< YUV 4:2:0/8 "Multiview High" + H264_PROFILE_STEREO_HIGH = 128 //!< YUV 4:2:0/8 "Stereo High" +} H264Profile; + +//!< AVC Level IDC definitions +typedef enum { + H264_LEVEL_1 = 10, + H264_LEVEL_1_b = 99, + H264_LEVEL_1_1 = 11, + H264_LEVEL_1_2 = 12, + H264_LEVEL_1_3 = 13, + H264_LEVEL_2 = 20, + H264_LEVEL_2_1 = 21, + H264_LEVEL_2_2 = 22, + H264_LEVEL_3 = 30, + H264_LEVEL_3_1 = 31, + H264_LEVEL_3_2 = 32, + H264_LEVEL_4_0 = 40, + H264_LEVEL_4_1 = 41, + H264_LEVEL_4_2 = 42, + H264_LEVEL_5_0 = 50, + H264_LEVEL_5_1 = 51, +} H264Level; + +//!< values for nalu_type +typedef enum { + NALU_TYPE_NULL = 0, + NALU_TYPE_SLICE = 1, + NALU_TYPE_DPA = 2, + NALU_TYPE_DPB = 3, + NALU_TYPE_DPC = 4, + NALU_TYPE_IDR = 5, + NALU_TYPE_SEI = 6, + NALU_TYPE_SPS = 7, + NALU_TYPE_PPS = 8, + NALU_TYPE_AUD = 9, // Access Unit Delimiter + NALU_TYPE_EOSEQ = 10, // end of sequence + NALU_TYPE_EOSTREAM = 11, // end of stream + NALU_TYPE_FILL = 12, + NALU_TYPE_SPSEXT = 13, + NALU_TYPE_PREFIX = 14, // prefix + NALU_TYPE_SUB_SPS = 15, + NALU_TYPE_SLICE_AUX = 19, + NALU_TYPE_SLC_EXT = 20, // slice extensive + NALU_TYPE_VDRD = 24 // View and Dependency Representation Delimiter NAL Unit +} Nalu_type; + +//!< values for nal_ref_idc +typedef enum { + NALU_PRIORITY_HIGHEST = 3, + NALU_PRIORITY_HIGH = 2, + NALU_PRIORITY_LOW = 1, + NALU_PRIORITY_DISPOSABLE = 0 +} NalRefIdc_type; + +#endif /*__H264_SYNTAX_H__*/ + diff --git a/mpp/common/h264d_syntax.h b/mpp/common/h264d_syntax.h index f1013a57..4f0e1162 100644 --- a/mpp/common/h264d_syntax.h +++ b/mpp/common/h264d_syntax.h @@ -19,6 +19,7 @@ #ifndef __H264D_SYNTAX_H__ #define __H264D_SYNTAX_H__ +#include "h264_syntax.h" #include "dxva_syntax.h" /* H.264/AVC-specific structures */ diff --git a/mpp/common/h264e_syntax.h b/mpp/common/h264e_syntax.h index 55415fc7..577f1533 100644 --- a/mpp/common/h264e_syntax.h +++ b/mpp/common/h264e_syntax.h @@ -1,19 +1,11 @@ #ifndef __H264E_SYNTAX_H__ #define __H264E_SYNTAX_H__ + #include "rk_type.h" #define H264_BIT_DEPTH 8 #define H264_QP_BD_OFFSET (6*(H264_BIT_DEPTH-8)) -typedef enum h264e_profile_t { - H264_PROFILE_BASELINE = 66, - H264_PROFILE_MAIN = 77, - H264_PROFILE_HIGH = 100, - H264_PROFILE_HIGH10 = 110, - H264_PROFILE_HIGH422 = 122, - H264_PROFILE_HIGH444_PREDICTIVE = 244, -} h264e_profile; - typedef struct h264e_osd_pos_t { RK_U32 lt_pos_x : 8; RK_U32 lt_pos_y : 8; diff --git a/mpp/hal/rkenc/h264e/hal_h264e_rkv.c b/mpp/hal/rkenc/h264e/hal_h264e_rkv.c index 19b8e99e..14dc7c16 100644 --- a/mpp/hal/rkenc/h264e/hal_h264e_rkv.c +++ b/mpp/hal/rkenc/h264e/hal_h264e_rkv.c @@ -15,11 +15,15 @@ */ #define MODULE_TAG "hal_h264e_rk" + #include #include + #include "vpu.h" #include "mpp_common.h" #include "mpp_mem.h" + +#include "h264_syntax.h" #include "hal_h264e.h" #include "hal_h264e_rkv.h" @@ -344,7 +348,7 @@ static MPP_RET hal_h264e_rkv_open_dump_files(void *dump_files) if (!files->fp_mpp_extra_ino_cfg) { mpp_err("%s open error", full_path); return MPP_ERR_OPEN_FILE; - } + } } return MPP_OK; } @@ -551,7 +555,7 @@ static void hal_h264e_rkv_dump_mpp_extra_info_cfg(h264e_hal_context *ctx, h264e_ FILE *fp = dump_files->fp_mpp_extra_ino_cfg; if(fp) { - + /* common cfg */ fprintf(fp, "%-16d %s\n", cfg->pic_luma_width, "pic_luma_width"); fprintf(fp, "%-16d %s\n", cfg->pic_luma_height, "pic_luma_height"); @@ -563,14 +567,14 @@ static void hal_h264e_rkv_dump_mpp_extra_info_cfg(h264e_hal_context *ctx, h264e_ /* additional cfg only for rkv */ fprintf(fp, "%-16d %s\n", cfg->input_image_format, "input_image_format"); - fprintf(fp, "%-16d %s\n", cfg->profile_idc, "profile_idc"); + fprintf(fp, "%-16d %s\n", cfg->profile_idc, "profile_idc"); fprintf(fp, "%-16d %s\n", cfg->level_idc, "level_idc"); //TODO: may be removed later, get from sps/pps instead fprintf(fp, "%-16d %s\n", cfg->keyframe_max_interval, "keyframe_max_interval"); fprintf(fp, "%-16d %s\n", cfg->second_chroma_qp_index_offset, "second_chroma_qp_index_offset"); fprintf(fp, "%-16d %s\n", cfg->pps_id, "pps_id"); //TODO: may be removed later, get from sps/pps instead - + fprintf(fp, "\n"); - fflush(fp); + fflush(fp); } } @@ -578,12 +582,12 @@ static void hal_h264e_rkv_dump_mpp_reg_out(h264e_hal_context *ctx) { RK_U32 k = 0; h264e_hal_rkv_dump_files *dump_files = (h264e_hal_rkv_dump_files *)ctx->dump_files; - FILE *fp = dump_files->fp_mpp_reg_out; - h264e_rkv_ioctl_output *reg_out = (h264e_rkv_ioctl_output *)ctx->ioctl_output; + FILE *fp = dump_files->fp_mpp_reg_out; + h264e_rkv_ioctl_output *reg_out = (h264e_rkv_ioctl_output *)ctx->ioctl_output; RK_U32 *p_reg = (RK_U32 *)reg_out + sizeof(reg_out->frame_num)/4; - if (fp) { + if (fp) { fprintf(fp, "%d frames out\n", reg_out->frame_num); - for(k= 0; knum_frames_to_send; k++) { + for(k= 0; knum_frames_to_send; k++) { fprintf(fp, "#FRAME %d:\n", (ctx->frame_cnt-1) - (ctx->num_frames_to_send-1-k)); for (k=0; k<12; k++) { fprintf(fp, "reg[%03d/%03x]: %08x\n", k, k * 4, p_reg[k]); @@ -600,7 +604,7 @@ static void hal_h264e_rkv_dump_mpp_reg_out(h264e_hal_context *ctx) static void hal_h264e_rkv_dump_mpp_feedback(h264e_hal_context *ctx) { h264e_hal_rkv_dump_files *dump_files = (h264e_hal_rkv_dump_files *)ctx->dump_files; - FILE *fp = dump_files->fp_mpp_feedback; + FILE *fp = dump_files->fp_mpp_feedback; if (fp) { h264e_feedback *fb = &ctx->feedback; (void)fb; @@ -628,7 +632,7 @@ static void hal_h264e_rkv_dump_mpp_strm_out_header(h264e_hal_context *ctx, MppPa void hal_h264e_rkv_dump_mpp_strm_out(h264e_hal_context *ctx, MppBuffer *hw_buf) { h264e_hal_rkv_dump_files *dump_files = (h264e_hal_rkv_dump_files *)ctx->dump_files; - FILE *fp = dump_files->fp_mpp_strm_out; + FILE *fp = dump_files->fp_mpp_strm_out; if (fp) { RK_U32 k = 0; RK_U32 strm_size = 0; @@ -1561,7 +1565,7 @@ MPP_RET hal_h264e_rkv_set_sps(h264e_hal_sps *sps, h264e_hal_param *par, h264e_co /* only for backup, excluded in read SPS */ sps->keyframe_max_interval = cfg->keyframe_max_interval; - + return MPP_OK; } @@ -2384,7 +2388,7 @@ MPP_RET hal_h264e_rkv_deinit(void *hal) hal_h264e_rkv_reference_deinit(ctx->dpb_ctx); MPP_FREE(ctx->dpb_ctx); } - + if(ctx->dump_files) { hal_h264e_rkv_close_dump_files(ctx->dump_files); MPP_FREE(ctx->dump_files); @@ -2432,7 +2436,7 @@ MPP_RET hal_h264e_rkv_set_ioctl_extra_info(h264e_rkv_ioctl_extra_info *extra_inf static MPP_RET hal_h264e_rkv_validate_syntax(h264e_syntax *syn) { h264e_hal_debug_enter(); - + /* validate */ H264E_HAL_VALIDATE_GT(syn->output_strm_limit_size, "output_strm_limit_size", 0); @@ -2441,7 +2445,7 @@ static MPP_RET hal_h264e_rkv_validate_syntax(h264e_syntax *syn) syn->input_cb_addr = syn->input_luma_addr; syn->input_cr_addr = syn->input_luma_addr; } - + h264e_hal_debug_leave(); return MPP_OK; } @@ -2508,7 +2512,7 @@ MPP_RET hal_h264e_rkv_gen_regs(void *hal, HalTaskInfo *task) h264e_hal_log_detail("generate regs when frame_cnt_gen_ready/(num_frames_to_send-1): %d/%d", ctx->frame_cnt_gen_ready, ctx->num_frames_to_send - 1); - + memset(regs, 0, sizeof(h264e_rkv_reg_set)); regs->swreg01.rkvenc_ver = 0x1; @@ -3164,7 +3168,7 @@ MPP_RET hal_h264e_rkv_control(void *hal, RK_S32 cmd_type, void *param) break; } case MPP_ENC_GET_EXTRA_INFO: { - RK_S32 k = 0; + RK_S32 k = 0; size_t offset = 0; MppPacket pkt = ctx->packeted_param; MppPacket *pkt_out = (MppPacket *)param; @@ -3177,7 +3181,7 @@ MPP_RET hal_h264e_rkv_control(void *hal, RK_S32 cmd_type, void *param) } mpp_packet_set_length(pkt, offset); *pkt_out = pkt; - + hal_h264e_rkv_dump_mpp_strm_out_header(ctx, pkt); break; } diff --git a/mpp/legacy/vpu_api_legacy.cpp b/mpp/legacy/vpu_api_legacy.cpp index dd133caf..b54fb5d0 100644 --- a/mpp/legacy/vpu_api_legacy.cpp +++ b/mpp/legacy/vpu_api_legacy.cpp @@ -803,10 +803,51 @@ RK_S32 VpuApiLegacy::control(VpuCodecContext *ctx, VPU_API_CMD cmd, void *param) MpiCmd mpicmd = MPI_CMD_BUTT; switch (cmd) { case VPU_API_ENC_SETCFG : { - mpicmd = MPP_ENC_SET_CFG; + /* input EncParameter_t need to be transform to MppEncConfig */ + EncParameter_t *cfg = (EncParameter_t *)param; + MppEncConfig mpp_cfg; + + mpp_cfg.size = sizeof(mpp_cfg); + mpp_cfg.version = 0; + mpp_cfg.width = cfg->width; + mpp_cfg.height = cfg->height; + mpp_cfg.hor_stride = MPP_ALIGN(cfg->width, 16); + mpp_cfg.ver_stride = MPP_ALIGN(cfg->height, 16); + mpp_cfg.format = (RK_S32)enc_in_fmt; + mpp_cfg.rc_mode = cfg->rc_mode; + mpp_cfg.skip_cnt = 0; + mpp_cfg.bps = cfg->bitRate; + mpp_cfg.fps_in = cfg->framerate; + mpp_cfg.fps_out = cfg->framerateout; + mpp_cfg.qp = cfg->qp; + mpp_cfg.gop = cfg->intraPicRate; + mpp_cfg.profile = cfg->profileIdc; + mpp_cfg.level = cfg->levelIdc; + mpp_cfg.cabac_en = cfg->enableCabac; + + return mpi->control(mpp_ctx, MPP_ENC_SET_CFG, (MppParam)&mpp_cfg); } break; case VPU_API_ENC_GETCFG : { - mpicmd = MPP_ENC_GET_CFG; + /* input EncParameter_t need to be transform to MppEncConfig */ + EncParameter_t *cfg = (EncParameter_t *)param; + MppEncConfig mpp_cfg; + + MPP_RET ret = mpi->control(mpp_ctx, MPP_ENC_GET_CFG, (MppParam)&mpp_cfg); + + cfg->width = mpp_cfg.width; + cfg->height = mpp_cfg.height; + cfg->rc_mode = mpp_cfg.rc_mode; + cfg->bitRate = mpp_cfg.bps; + cfg->framerate = mpp_cfg.fps_in; + cfg->framerateout = mpp_cfg.fps_out; + cfg->qp = mpp_cfg.qp; + cfg->intraPicRate = mpp_cfg.gop; + cfg->profileIdc = mpp_cfg.profile; + cfg->levelIdc = mpp_cfg.level; + cfg->enableCabac = mpp_cfg.cabac_en; + cfg->cabacInitIdc = 0; + + return ret; } break; case VPU_API_ENC_SETFORMAT : { enc_in_fmt = *((EncInputPictureType *)param);