[h264e]: fix extra info config error

git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@1151 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
ChenHengming 2016-08-03 09:37:55 +00:00
parent b61412dd02
commit b85f0a746e
8 changed files with 277 additions and 303 deletions

View file

@ -19,6 +19,9 @@
#include "mpp_log.h"
#include "h264_syntax.h"
#include "enccommon.h"
#include "encpreprocess.h"
#include "encasiccontroller.h"
@ -29,93 +32,7 @@
#include "H264RateControl.h"
#include "H264Mad.h"
enum H264EncStatus {
H264ENCSTAT_INIT = 0xA1,
H264ENCSTAT_START_STREAM,
H264ENCSTAT_START_FRAME,
H264ENCSTAT_ERROR
};
#include "h264encapi.h"
/* Picture type for encoding */
typedef enum {
H264ENC_INTRA_FRAME = 0,
H264ENC_PREDICTED_FRAME = 1,
H264ENC_NOTCODED_FRAME /* Used just as a return value */
} H264EncPictureCodingType;
/* Encoder input structure */
typedef struct {
u32 busLuma; /* Bus address for input picture
* planar format: luminance component
* semiplanar format: luminance component
* interleaved format: whole picture
*/
u32 busChromaU; /* Bus address for input chrominance
* planar format: cb component
* semiplanar format: both chrominance
* interleaved format: not used
*/
u32 busChromaV; /* Bus address for input chrominance
* planar format: cr component
* semiplanar format: not used
* interleaved format: not used
*/
u32 timeIncrement; /* The previous picture duration in units
* of frameRateDenom/frameRateNum.
* 0 for the very first picture.
*/
u32 *pOutBuf; /* Pointer to output stream buffer */
u32 busOutBuf; /* Bus address of output stream buffer */
u32 outBufSize; /* Size of output stream buffer in bytes */
H264EncPictureCodingType codingType; /* Proposed picture coding type,
* INTRA/PREDICTED
*/
u32 busLumaStab; /* bus address of next picture to stabilize (luminance) */
} H264EncIn;
/* Encoder output structure */
typedef struct {
H264EncPictureCodingType codingType; /* Realized picture coding type,
* INTRA/PREDICTED/NOTCODED
*/
u32 streamSize; /* Size of output stream in bytes */
} H264EncOut;
typedef struct {
u32 encStatus;
RK_U32 lumWidthSrc; // TODO need to think again modify by lance 2016.06.15
RK_U32 lumHeightSrc; // TODO need to think again modify by lance 2016.06.15
u32 mbPerFrame;
u32 mbPerRow;
u32 mbPerCol;
u32 frameCnt;
u32 fillerNalSize;
u32 testId;
stream_s stream;
preProcess_s preProcess;
sps_s seqParameterSet;
pps_s picParameterSet;
slice_s slice;
h264RateControl_s rateControl;
madTable_s mad;
asicData_s asic;
const void *inst;
u32 time_debug_init;
RK_U32 intraPeriodCnt; // count the frame amount from last intra frame,
// 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
RK_U32 intraPicRate; // set I frame interval, and is 30 default
} h264Instance_s;
#define H264E_DBG_FUNCTION (0x00000001)
extern RK_U32 h264e_debug;
#define h264e_dbg(flag, fmt, ...) _mpp_dbg(h264e_debug, flag, fmt, ## __VA_ARGS__)
#define h264e_dbg_f(flag, fmt, ...) _mpp_dbg_f(h264e_debug, flag, fmt, ## __VA_ARGS__)
#define h264e_dbg_func(fmt, ...) h264e_dbg_f(H264E_DBG_FUNCTION, fmt, ## __VA_ARGS__)
#endif

View file

@ -28,8 +28,6 @@ extern "C"
#include "H264Instance.h"
typedef const void *H264EncInst;
/* Function return values */
typedef enum {
H264ENC_OK = 0,
@ -53,6 +51,27 @@ typedef enum {
H264ENC_HW_RESET = -16
} H264EncRet;
/* Picture rotation for pre-processing */
typedef enum {
H264ENC_ROTATE_0 = 0,
H264ENC_ROTATE_90R = 1, /* Rotate 90 degrees clockwise */
H264ENC_ROTATE_90L = 2 /* Rotate 90 degrees counter-clockwise */
} H264EncPictureRotation;
/* Picture color space conversion (RGB input) for pre-processing */
typedef enum {
H264ENC_RGBTOYUV_BT601 = 0, /* Color conversion according to BT.601 */
H264ENC_RGBTOYUV_BT709 = 1, /* Color conversion according to BT.709 */
H264ENC_RGBTOYUV_USER_DEFINED = 2 /* User defined color conversion */
} H264EncColorConversionType;
enum H264EncStatus {
H264ENCSTAT_INIT = 0xA1,
H264ENCSTAT_START_STREAM,
H264ENCSTAT_START_FRAME,
H264ENCSTAT_ERROR
};
/* Stream type for initialization */
typedef enum {
H264ENC_BYTE_STREAM = 0, /* H.264 annex B: NAL unit starts with
@ -60,6 +79,13 @@ typedef enum {
H264ENC_NAL_UNIT_STREAM = 1 /* Plain NAL units without startcode */
} H264EncStreamType;
/* Picture type for encoding */
typedef enum {
H264ENC_INTRA_FRAME = 0,
H264ENC_PREDICTED_FRAME = 1,
H264ENC_NOTCODED_FRAME /* Used just as a return value */
} H264EncPictureCodingType;
/* Picture YUV type for initialization */
typedef enum {
H264ENC_YUV420_PLANAR = 0, /* YYYY... UUUU... VVVV */
@ -78,58 +104,11 @@ typedef enum {
H264ENC_BGR101010 = 13 /* 30-bit RGB */
} H264EncPictureFormat;
/* Picture rotation for pre-processing */
typedef enum {
H264ENC_ROTATE_0 = 0,
H264ENC_ROTATE_90R = 1, /* Rotate 90 degrees clockwise */
H264ENC_ROTATE_90L = 2 /* Rotate 90 degrees counter-clockwise */
} H264EncPictureRotation;
/* Picture color space conversion (RGB input) for pre-processing */
typedef enum {
H264ENC_RGBTOYUV_BT601 = 0, /* Color conversion according to BT.601 */
H264ENC_RGBTOYUV_BT709 = 1, /* Color conversion according to BT.709 */
H264ENC_RGBTOYUV_USER_DEFINED = 2 /* User defined color conversion */
} H264EncColorConversionType;
/* Complexity level */
typedef enum {
H264ENC_COMPLEXITY_1 = 1
} H264EncComplexityLevel;
/*------------------------------------------------------------------------------
3. Structures for API function parameters
------------------------------------------------------------------------------*/
/* Configuration info for initialization
* Width and height are picture dimensions after rotation
* Width and height are restricted by level limitations
*/
typedef struct {
H264EncStreamType streamType; /* Byte stream / Plain NAL units */
/* Stream Profile will be automatically decided,
* CABAC -> main/high, 8x8-transform -> high */
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] */
u32 frameRateDenom; /* Maximum frame rate is frameRateNum/frameRateDenom
* in frames/second. The actual frame rate will be
* defined by timeIncrement of encoded pictures,
* [1..frameRateNum] */
H264EncComplexityLevel complexityLevel; /* For compatibility */
RK_U32 enable_cabac;
RK_U32 transform8x8_mode;
RK_U32 pic_init_qp;
RK_U32 chroma_qp_index_offset;
RK_U32 pic_luma_height;
RK_U32 pic_luma_width;
H264EncPictureFormat input_image_format;
RK_U32 second_chroma_qp_index_offset;
RK_U32 pps_id;
} H264EncConfig;
/* Coding control parameters */
typedef struct {
u32 sliceSize; /* Slice size in macroblock rows,
@ -165,6 +144,106 @@ typedef struct {
* 0=disabled, 1=adaptive 8x8, 2=always 8x8 */
} H264EncCodingCtrl;
/* Input pre-processing */
typedef struct {
H264EncColorConversionType type;
u16 coeffA; /* User defined color conversion coefficient */
u16 coeffB; /* User defined color conversion coefficient */
u16 coeffC; /* User defined color conversion coefficient */
u16 coeffE; /* User defined color conversion coefficient */
u16 coeffF; /* User defined color conversion coefficient */
} H264EncColorConversion;
typedef struct {
u32 origWidth;
u32 origHeight;
u32 xOffset;
u32 yOffset;
H264EncPictureFormat inputType;
H264EncPictureRotation rotation;
u32 videoStabilization;
H264EncColorConversion colorConversion;
} H264EncPreProcessingCfg;
/* Version information */
typedef struct {
u32 major; /* Encoder API major version */
u32 minor; /* Encoder API minor version */
} H264EncApiVersion;
typedef struct {
u32 swBuild; /* Software build ID */
u32 hwBuild; /* Hardware build ID */
} H264EncBuild;
/* Encoder input structure */
typedef struct {
u32 busLuma; /* Bus address for input picture
* planar format: luminance component
* semiplanar format: luminance component
* interleaved format: whole picture
*/
u32 busChromaU; /* Bus address for input chrominance
* planar format: cb component
* semiplanar format: both chrominance
* interleaved format: not used
*/
u32 busChromaV; /* Bus address for input chrominance
* planar format: cr component
* semiplanar format: not used
* interleaved format: not used
*/
u32 timeIncrement; /* The previous picture duration in units
* of frameRateDenom/frameRateNum.
* 0 for the very first picture.
*/
u32 *pOutBuf; /* Pointer to output stream buffer */
u32 busOutBuf; /* Bus address of output stream buffer */
u32 outBufSize; /* Size of output stream buffer in bytes */
H264EncPictureCodingType codingType; /* Proposed picture coding type,
* INTRA/PREDICTED
*/
u32 busLumaStab; /* bus address of next picture to stabilize (luminance) */
} H264EncIn;
/* Encoder output structure */
typedef struct {
H264EncPictureCodingType codingType; /* Realized picture coding type,
* INTRA/PREDICTED/NOTCODED
*/
u32 streamSize; /* Size of output stream in bytes */
} H264EncOut;
/* Configuration info for initialization
* Width and height are picture dimensions after rotation
* Width and height are restricted by level limitations
*/
typedef struct {
H264EncStreamType streamType; /* Byte stream / Plain NAL units */
/* Stream Profile will be automatically decided,
* CABAC -> main/high, 8x8-transform -> high */
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] */
u32 frameRateDenom; /* Maximum frame rate is frameRateNum/frameRateDenom
* in frames/second. The actual frame rate will be
* defined by timeIncrement of encoded pictures,
* [1..frameRateNum] */
RK_U32 enable_cabac;
RK_U32 transform8x8_mode;
RK_U32 pic_init_qp;
RK_U32 chroma_qp_index_offset;
RK_U32 pic_luma_height;
RK_U32 pic_luma_width;
H264EncPictureFormat input_image_format;
RK_U32 second_chroma_qp_index_offset;
RK_U32 pps_id;
} H264EncConfig;
/* Rate control parameters */
typedef struct {
u32 pictureRc; /* Adjust QP between pictures, [0,1] */
@ -210,67 +289,75 @@ typedef struct {
*/
} H264EncRateCtrl;
/* Input pre-processing */
typedef struct {
H264EncColorConversionType type;
u16 coeffA; /* User defined color conversion coefficient */
u16 coeffB; /* User defined color conversion coefficient */
u16 coeffC; /* User defined color conversion coefficient */
u16 coeffE; /* User defined color conversion coefficient */
u16 coeffF; /* User defined color conversion coefficient */
} H264EncColorConversion;
u32 encStatus;
RK_U32 lumWidthSrc; // TODO need to think again modify by lance 2016.06.15
RK_U32 lumHeightSrc; // TODO need to think again modify by lance 2016.06.15
u32 mbPerFrame;
u32 mbPerRow;
u32 mbPerCol;
u32 frameCnt;
u32 fillerNalSize;
u32 testId;
stream_s stream;
preProcess_s preProcess;
sps_s seqParameterSet;
pps_s picParameterSet;
slice_s slice;
h264RateControl_s rateControl;
madTable_s mad;
asicData_s asic;
const void *inst;
u32 time_debug_init;
RK_U32 intraPeriodCnt; // count the frame amount from last intra frame,
// 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
RK_U32 intraPicRate; // set I frame interval, and is 30 default
typedef struct {
u32 origWidth;
u32 origHeight;
u32 xOffset;
u32 yOffset;
H264EncPictureFormat inputType;
H264EncPictureRotation rotation;
u32 videoStabilization;
H264EncColorConversion colorConversion;
} H264EncPreProcessingCfg;
h264e_control_extra_info_cfg info;
H264EncConfig enc_cfg;
H264EncRateCtrl enc_rc_cfg;
} h264Instance_s;
/* Version information */
typedef struct {
u32 major; /* Encoder API major version */
u32 minor; /* Encoder API minor version */
} H264EncApiVersion;
#define H264E_DBG_FUNCTION (0x00000001)
typedef struct {
u32 swBuild; /* Software build ID */
u32 hwBuild; /* Hardware build ID */
} H264EncBuild;
extern RK_U32 h264e_debug;
#define h264e_dbg(flag, fmt, ...) _mpp_dbg(h264e_debug, flag, fmt, ## __VA_ARGS__)
#define h264e_dbg_f(flag, fmt, ...) _mpp_dbg_f(h264e_debug, flag, fmt, ## __VA_ARGS__)
#define h264e_dbg_func(fmt, ...) h264e_dbg_f(H264E_DBG_FUNCTION, fmt, ## __VA_ARGS__)
/*------------------------------------------------------------------------------
4. Encoder API function prototypes
------------------------------------------------------------------------------*/
/* Initialization & release */
H264EncRet H264EncInit(h264Instance_s *instAddr);
H264EncRet H264EncRelease(H264EncInst inst);
H264EncRet H264EncInit(h264Instance_s *inst);
H264EncRet H264EncRelease(h264Instance_s *inst);
/* Encoder configuration before stream generation */
H264EncRet H264EncCfg(H264EncInst inst, const H264EncConfig * pEncConfig);
H264EncRet H264EncSetCodingCtrl(H264EncInst inst, const H264EncCodingCtrl *
H264EncRet H264EncCfg(h264Instance_s *inst, const H264EncConfig * pEncConfig);
H264EncRet H264EncSetCodingCtrl(h264Instance_s *inst, const H264EncCodingCtrl *
pCodingParams);
H264EncRet H264EncGetCodingCtrl(H264EncInst inst, H264EncCodingCtrl *
H264EncRet H264EncGetCodingCtrl(h264Instance_s *inst, H264EncCodingCtrl *
pCodingParams);
/* Encoder configuration before and during stream generation */
H264EncRet H264EncSetRateCtrl(H264EncInst inst,
H264EncRet H264EncSetRateCtrl(h264Instance_s *inst,
const H264EncRateCtrl * pRateCtrl);
H264EncRet H264EncGetRateCtrl(H264EncInst inst,
H264EncRet H264EncGetRateCtrl(h264Instance_s *inst,
H264EncRateCtrl * pRateCtrl);
H264EncRet H264EncSetPreProcessing(H264EncInst inst,
H264EncRet H264EncSetPreProcessing(h264Instance_s *inst,
const H264EncPreProcessingCfg *
pPreProcCfg);
H264EncRet H264EncGetPreProcessing(H264EncInst inst,
H264EncRet H264EncGetPreProcessing(h264Instance_s *inst,
H264EncPreProcessingCfg * pPreProcCfg);
/* Encoder user data insertion during stream generation */
H264EncRet H264EncSetSeiUserData(H264EncInst inst, const u8 * pUserData,
H264EncRet H264EncSetSeiUserData(h264Instance_s *inst, const u8 * pUserData,
u32 userDataSize);
/* Stream generation */
@ -278,20 +365,20 @@ H264EncRet H264EncSetSeiUserData(H264EncInst inst, const u8 * pUserData,
/* H264EncStrmStart generates the SPS and PPS. SPS is the first NAL unit and PPS
* is the second NAL unit. NaluSizeBuf indicates the size of NAL units.
*/
H264EncRet H264EncStrmStart(H264EncInst inst, const H264EncIn * pEncIn,
H264EncRet H264EncStrmStart(h264Instance_s *inst, const H264EncIn * pEncIn,
H264EncOut * pEncOut);
/* H264EncStrmEncode encodes one video frame. If SEI messages are enabled the
* first NAL unit is a SEI message.
*/
H264EncRet H264EncStrmEncode(H264EncInst inst, const H264EncIn * pEncIn,
H264EncRet H264EncStrmEncode(h264Instance_s *inst, const H264EncIn * pEncIn,
H264EncOut * pEncOut, h264e_syntax *syntax_data);
H264EncRet H264EncStrmEncodeAfter(H264EncInst inst,
H264EncOut * pEncOut, MPP_RET vpuWaitResult); // add by lance 2016.05.07
H264EncRet H264EncStrmEncodeAfter(h264Instance_s *inst,
H264EncOut * pEncOut, MPP_RET vpuWaitResult);
/* H264EncStrmEnd ends a stream with an EOS code. */
H264EncRet H264EncStrmEnd(H264EncInst inst, const H264EncIn * pEncIn,
H264EncRet H264EncStrmEnd(h264Instance_s *inst, const H264EncIn * pEncIn,
H264EncOut * pEncOut);
#ifdef __cplusplus

View file

@ -20,6 +20,7 @@
#include "mpp_log.h"
#include "enccommon.h"
#include "ewl.h"
#include "h264encapi.h"
#include "H264CodeFrame.h"
/*------------------------------------------------------------------------------

View file

@ -57,11 +57,9 @@ static i32 VSCheckSize(u32 inputWidth, u32 inputHeight, u32 stabilizedWidth,
Argument : pEncCfg - initialization parameters
instAddr - where to save the created instance
------------------------------------------------------------------------------*/
H264EncRet H264EncInit(h264Instance_s *instAddr)
H264EncRet H264EncInit(h264Instance_s *pEncInst)
{
H264EncRet ret;
h264Instance_s *pEncInst = instAddr;
h264e_dbg_func("enter\n");
ret = H264Init(pEncInst);
@ -88,10 +86,8 @@ H264EncRet H264EncInit(h264Instance_s *instAddr)
Return type : H264EncRet
Argument : inst - the instance to be released
------------------------------------------------------------------------------*/
H264EncRet H264EncRelease(H264EncInst inst)
H264EncRet H264EncRelease(h264Instance_s *pEncInst)
{
h264Instance_s *pEncInst = (h264Instance_s *) inst;
h264e_dbg_func("enter\n");
/* Check for illegal inputs */
@ -110,11 +106,9 @@ H264EncRet H264EncRelease(H264EncInst inst)
return H264ENC_OK;
}
H264EncRet H264EncCfg(H264EncInst inst, const H264EncConfig * pEncConfig)
H264EncRet H264EncCfg(h264Instance_s *pEncInst, const H264EncConfig * pEncConfig)
{
H264EncRet ret;
h264Instance_s *pEncInst = (h264Instance_s *) inst;
h264e_dbg_func("enter\n");
ret = H264Cfg(pEncConfig, pEncInst);
@ -136,11 +130,8 @@ H264EncRet H264EncCfg(H264EncInst inst, const H264EncConfig * pEncConfig)
Argument : inst - the instance in use
pCodeParams - user provided parameters
------------------------------------------------------------------------------*/
H264EncRet H264EncSetCodingCtrl(H264EncInst inst,
const H264EncCodingCtrl * pCodeParams)
H264EncRet H264EncSetCodingCtrl(h264Instance_s *pEncInst, const H264EncCodingCtrl * pCodeParams)
{
h264Instance_s *pEncInst = (h264Instance_s *) inst;
h264e_dbg_func("enter\n");
/* Check for illegal inputs */
@ -241,11 +232,9 @@ set_slice_size:
Argument : inst - the instance in use
pCodeParams - palce where parameters are returned
------------------------------------------------------------------------------*/
H264EncRet H264EncGetCodingCtrl(H264EncInst inst,
H264EncRet H264EncGetCodingCtrl(h264Instance_s *pEncInst,
H264EncCodingCtrl * pCodeParams)
{
h264Instance_s *pEncInst = (h264Instance_s *) inst;
h264e_dbg_func("enter\n");
/* Check for illegal inputs */
@ -293,10 +282,9 @@ H264EncRet H264EncGetCodingCtrl(H264EncInst inst,
Argument : inst - the instance in use
pRateCtrl - user provided parameters
------------------------------------------------------------------------------*/
H264EncRet H264EncSetRateCtrl(H264EncInst inst,
H264EncRet H264EncSetRateCtrl(h264Instance_s *pEncInst,
const H264EncRateCtrl * pRateCtrl)
{
h264Instance_s *pEncInst = (h264Instance_s *) inst;
h264RateControl_s *rc;
u32 i, tmp;
@ -460,9 +448,8 @@ H264EncRet H264EncSetRateCtrl(H264EncInst inst,
Argument : inst - the instance in use
pRateCtrl - place where parameters are returned
------------------------------------------------------------------------------*/
H264EncRet H264EncGetRateCtrl(H264EncInst inst, H264EncRateCtrl * pRateCtrl)
H264EncRet H264EncGetRateCtrl(h264Instance_s *pEncInst, H264EncRateCtrl * pRateCtrl)
{
h264Instance_s *pEncInst = (h264Instance_s *) inst;
h264RateControl_s *rc;
h264e_dbg_func("enter\n");
@ -540,16 +527,15 @@ i32 VSCheckSize(u32 inputWidth, u32 inputHeight, u32 stabilizedWidth,
Argument : inst - encoder instance in use
Argument : pPreProcCfg - user provided parameters
------------------------------------------------------------------------------*/
H264EncRet H264EncSetPreProcessing(H264EncInst inst,
H264EncRet H264EncSetPreProcessing(h264Instance_s *pEncInst,
const H264EncPreProcessingCfg * pPreProcCfg)
{
h264Instance_s *pEncInst = (h264Instance_s *) inst;
preProcess_s pp_tmp;
h264e_dbg_func("enter\n");
/* Check for illegal inputs */
if ((inst == NULL) || (pPreProcCfg == NULL)) {
if ((pEncInst == NULL) || (pPreProcCfg == NULL)) {
mpp_err_f("ERROR Null argument\n");
return H264ENC_NULL_ARGUMENT;
}
@ -673,16 +659,15 @@ H264EncRet H264EncSetPreProcessing(H264EncInst inst,
Argument : inst - encoder instance
Argument : pPreProcCfg - place where the parameters are returned
------------------------------------------------------------------------------*/
H264EncRet H264EncGetPreProcessing(H264EncInst inst,
H264EncRet H264EncGetPreProcessing(h264Instance_s *pEncInst,
H264EncPreProcessingCfg * pPreProcCfg)
{
h264Instance_s *pEncInst = (h264Instance_s *) inst;
preProcess_s *pPP;
h264e_dbg_func("enter\n");
/* Check for illegal inputs */
if ((inst == NULL) || (pPreProcCfg == NULL)) {
if ((pEncInst == NULL) || (pPreProcCfg == NULL)) {
mpp_err_f("ERROR Null argument\n");
return H264ENC_NULL_ARGUMENT;
}
@ -729,11 +714,9 @@ H264EncRet H264EncGetPreProcessing(H264EncInst inst,
maximum size H264ENC_MAX_USER_DATA_SIZE
not valid size disables userData sei messages
------------------------------------------------------------------------------*/
H264EncRet H264EncSetSeiUserData(H264EncInst inst, const u8 * pUserData,
H264EncRet H264EncSetSeiUserData(h264Instance_s *pEncInst, const u8 * pUserData,
u32 userDataSize)
{
h264Instance_s *pEncInst = (h264Instance_s *) inst;
/* Check for illegal inputs */
if ((pEncInst == NULL) || (userDataSize != 0 && pUserData == NULL)) {
mpp_err_f("ERROR Null argument\n");
@ -769,10 +752,9 @@ H264EncRet H264EncSetSeiUserData(H264EncInst inst, const u8 * pUserData,
Argument : pEncIn - user provided input parameters
pEncOut - place where output info is returned
------------------------------------------------------------------------------*/
H264EncRet H264EncStrmStart(H264EncInst inst, const H264EncIn * pEncIn,
H264EncRet H264EncStrmStart(h264Instance_s *pEncInst, const H264EncIn * pEncIn,
H264EncOut * pEncOut)
{
h264Instance_s *pEncInst = (h264Instance_s *)inst;
h264RateControl_s *rc;
h264e_dbg_func("enter\n");
@ -888,10 +870,9 @@ H264EncRet H264EncStrmStart(H264EncInst inst, const H264EncIn * pEncIn,
Argument : pEncIn - user provided input parameters
pEncOut - place where output info is returned
------------------------------------------------------------------------------*/
H264EncRet H264EncStrmEncode(H264EncInst inst, const H264EncIn * pEncIn,
H264EncRet H264EncStrmEncode(h264Instance_s *pEncInst, const H264EncIn * pEncIn,
H264EncOut * pEncOut, h264e_syntax *syntax_data)
{
h264Instance_s *pEncInst = (h264Instance_s *) inst;
slice_s *pSlice;
regValues_s *regs;
/*h264EncodeFrame_e ret;*/ // mask by lance 2016.05.12
@ -1110,16 +1091,14 @@ RK_S32 EncAsicCheckHwStatus(asicData_s *asic)
return ret;
}
H264EncRet H264EncStrmEncodeAfter(H264EncInst inst,
H264EncRet H264EncStrmEncodeAfter(h264Instance_s *pEncInst,
H264EncOut * pEncOut, MPP_RET vpuWaitResult)
{
h264Instance_s *pEncInst = (h264Instance_s *) inst; // add by lance 2016.05.07
slice_s *pSlice; // add by lance 2016.05.07
regValues_s *regs; // add by lance 2016.05.07
h264EncodeFrame_e ret = H264ENCODE_OK; // add by lance 2016.05.07
slice_s *pSlice;
regValues_s *regs;
h264EncodeFrame_e ret = H264ENCODE_OK;
asicData_s *asic = &pEncInst->asic;
// add by lance 2016.05.07
/* some shortcuts */
pSlice = &pEncInst->slice;
regs = &pEncInst->asic.regs;
if (vpuWaitResult != MPP_OK) {
@ -1255,11 +1234,9 @@ H264EncRet H264EncStrmEncodeAfter(H264EncInst inst,
Argument : pEncIn - user provided input parameters
pEncOut - place where output info is returned
------------------------------------------------------------------------------*/
H264EncRet H264EncStrmEnd(H264EncInst inst, const H264EncIn * pEncIn,
H264EncRet H264EncStrmEnd(h264Instance_s *pEncInst, const H264EncIn * pEncIn,
H264EncOut * pEncOut)
{
h264Instance_s *pEncInst = (h264Instance_s *)inst;
h264e_dbg_func("enter\n");
/* Check for illegal inputs */
if ((pEncInst == NULL) || (pEncIn == NULL) || (pEncOut == NULL)) {

View file

@ -46,19 +46,18 @@ MPP_RET h264e_init(void *ctx, ControllerCfg *ctrlCfg)
MPP_RET h264e_deinit(void *ctx)
{
H264EncInst encInst = (H264EncInst)ctx;
h264Instance_s * pEncInst = (h264Instance_s*)ctx;
h264Instance_s * pEncInst = (h264Instance_s *)ctx;
H264EncRet ret/* = MPP_OK*/;
H264EncIn *encIn = &(pEncInst->encIn);
H264EncOut *encOut = &(pEncInst->encOut);
/* End stream */
ret = H264EncStrmEnd(encInst, encIn, encOut);
ret = H264EncStrmEnd(pEncInst, encIn, encOut);
if (ret != H264ENC_OK) {
mpp_err("H264EncStrmEnd() failed, ret %d.", ret);
}
if ((ret = H264EncRelease(encInst)) != H264ENC_OK) {
if ((ret = H264EncRelease(pEncInst)) != H264ENC_OK) {
mpp_err("H264EncRelease() failed, ret %d.", ret);
return MPP_NOK;
}
@ -69,21 +68,19 @@ MPP_RET h264e_deinit(void *ctx)
MPP_RET h264e_encode(void *ctx, /*HalEncTask **/void *task)
{
H264EncRet ret;
H264EncInst encInst = (H264EncInst)ctx;
H264EncInst encoderOpen = (H264EncInst)ctx;
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
RK_U32 srcLumaWidth = pEncInst->lumWidthSrc;
RK_U32 srcLumaHeight = pEncInst->lumHeightSrc;
h264Instance_s *p = (h264Instance_s *)ctx;
H264EncIn *encIn = &(p->encIn);
H264EncOut *encOut = &(p->encOut);
RK_U32 srcLumaWidth = p->lumWidthSrc;
RK_U32 srcLumaHeight = p->lumHeightSrc;
encIn->pOutBuf = (u32*)mpp_buffer_get_ptr(((EncTask*)task)->ctrl_pkt_buf_out);
encIn->busOutBuf = mpp_buffer_get_fd(((EncTask*)task)->ctrl_pkt_buf_out);
encIn->outBufSize = mpp_buffer_get_size(((EncTask*)task)->ctrl_pkt_buf_out);
/* Start stream */
if (pEncInst->encStatus == H264ENCSTAT_INIT) {
ret = H264EncStrmStart(encoderOpen, encIn, encOut);
if (p->encStatus == H264ENCSTAT_INIT) {
ret = H264EncStrmStart(p, encIn, encOut);
if (ret != H264ENC_OK) {
mpp_err("H264EncStrmStart() failed, ret %d.", ret);
return -1;
@ -116,18 +113,18 @@ MPP_RET h264e_encode(void *ctx, /*HalEncTask **/void *task)
//encIn.busLumaStab = mpp_buffer_get_fd(pictureStabMem)/*pictureStabMem.phy_addr*/;
/* Select frame type */
if (pEncInst->intraPicRate != 0 &&
(pEncInst->intraPeriodCnt >= pEncInst->intraPicRate)) {
if (p->intraPicRate != 0 &&
(p->intraPeriodCnt >= p->intraPicRate)) {
encIn->codingType = H264ENC_INTRA_FRAME;
} else {
encIn->codingType = H264ENC_PREDICTED_FRAME;
}
if (encIn->codingType == H264ENC_INTRA_FRAME)
pEncInst->intraPeriodCnt = 0;
p->intraPeriodCnt = 0;
// TODO syntax_data need to be assigned modify by lance 2016.05.19
ret = H264EncStrmEncode(encInst, encIn, encOut, &(((EncTask*)task)->syntax_data));
ret = H264EncStrmEncode(p, encIn, encOut, &(((EncTask*)task)->syntax_data));
if (ret != H264ENC_FRAME_READY) {
mpp_err("H264EncStrmEncode() failed, ret %d.", ret); // TODO need to be modified by lance 2016.05.31
return MPP_NOK;
@ -254,7 +251,7 @@ static MPP_RET h264e_check_mpp_cfg(MppEncConfig *mpp_cfg)
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
h264Instance_s *enc = (h264Instance_s *)ctx; // add by lance 2016.05.31
h264e_dbg_func("enter ctx %p cmd %x param %p\n", ctx, cmd, param);
@ -263,11 +260,9 @@ MPP_RET h264e_config(void *ctx, RK_S32 cmd, void *param)
ret = h264e_check_mpp_cfg((MppEncConfig *)param);
} break;
case SET_ENC_CFG : {
const MppEncConfig *mpp_cfg = (const MppEncConfig *)param;
H264EncConfig cfg;
H264EncConfig *enc_cfg = &cfg;
MppEncConfig *mpp_cfg = (MppEncConfig *)param;
H264EncConfig *enc_cfg = &enc->enc_cfg;
H264EncInst encoder = (H264EncInst)ctx;
H264EncCodingCtrl oriCodingCfg;
H264EncPreProcessingCfg oriPreProcCfg;
@ -295,13 +290,13 @@ MPP_RET h264e_config(void *ctx, RK_S32 cmd, void *param)
enc_cfg->pps_id = 0;
enc_cfg->input_image_format = (H264EncPictureFormat)mpp_cfg->format;
ret = H264EncCfg(encoder, enc_cfg);
ret = H264EncCfg(enc, enc_cfg);
/* Encoder setup: coding control */
ret = H264EncGetCodingCtrl(encoder, &oriCodingCfg);
ret = H264EncGetCodingCtrl(enc, &oriCodingCfg);
if (ret) {
mpp_err("H264EncGetCodingCtrl() failed, ret %d.", ret);
h264e_deinit((void*)encoder);
h264e_deinit((void*)enc);
break;
} else {
// will be replaced modify by lance 2016.05.20
@ -314,19 +309,19 @@ MPP_RET h264e_config(void *ctx, RK_S32 cmd, void *param)
oriCodingCfg.transform8x8Mode = 0;
oriCodingCfg.videoFullRange = 0;
oriCodingCfg.seiMessages = 0;
ret = H264EncSetCodingCtrl(encoder, &oriCodingCfg);
ret = H264EncSetCodingCtrl(enc, &oriCodingCfg);
if (ret) {
mpp_err("H264EncSetCodingCtrl() failed, ret %d.", ret);
h264e_deinit((void*)encoder);
h264e_deinit((void*)enc);
break;
}
}
/* PreP setup */
ret = H264EncGetPreProcessing(encoder, &oriPreProcCfg);
ret = H264EncGetPreProcessing(enc, &oriPreProcCfg);
if (ret) {
mpp_err("H264EncGetPreProcessing() failed, ret %d.\n", ret);
h264e_deinit((void*)encoder);
h264e_deinit((void*)enc);
break;
} else {
mpp_log_f("Get PreP: input %dx%d : offset %dx%d : format %d : rotation %d : stab %d : cc %d\n",
@ -351,22 +346,20 @@ MPP_RET h264e_config(void *ctx, RK_S32 cmd, void *param)
oriPreProcCfg.colorConversion.coeffF = 38000;
}
ret = H264EncSetPreProcessing(encoder, &oriPreProcCfg);
ret = H264EncSetPreProcessing(enc, &oriPreProcCfg);
if (ret) {
mpp_err("H264EncSetPreProcessing() failed.", ret);
h264e_deinit((void*)encoder);
h264e_deinit((void*)enc);
break;
}
}
} break;
case SET_ENC_RC_CFG : {
const MppEncConfig *mpp_cfg = (const MppEncConfig *)param;
H264EncRateCtrl cfg;
H264EncRateCtrl *enc_rc_cfg = &cfg;
H264EncInst encoder = (H264EncInst)ctx;
MppEncConfig *mpp_cfg = (MppEncConfig *)param;
H264EncRateCtrl *enc_rc_cfg = &enc->enc_rc_cfg;
H264EncRateCtrl oriRcCfg;
mpp_assert(pEncInst);
mpp_assert(enc);
if (mpp_cfg->rc_mode) {
/* VBR / CBR mode */
@ -404,11 +397,11 @@ MPP_RET h264e_config(void *ctx, RK_S32 cmd, void *param)
enc_rc_cfg->mbQpAdjustment = 3;
enc_rc_cfg->hrdCpbSize = mpp_cfg->bps / 8;
pEncInst->intraPicRate = enc_rc_cfg->intraPicRate;
pEncInst->intraPeriodCnt = enc_rc_cfg->intraPicRate;
enc->intraPicRate = enc_rc_cfg->intraPicRate;
enc->intraPeriodCnt = enc_rc_cfg->intraPicRate;
/* Encoder setup: rate control */
ret = H264EncGetRateCtrl(encoder, &oriRcCfg);
ret = H264EncGetRateCtrl(enc, &oriRcCfg);
if (ret) {
mpp_err("H264EncGetRateCtrl() failed, ret %d.", ret);
} else {
@ -448,15 +441,37 @@ MPP_RET h264e_config(void *ctx, RK_S32 cmd, void *param)
oriRcCfg.pictureRc, oriRcCfg.mbRc, oriRcCfg.pictureSkip, oriRcCfg.hrd,
oriRcCfg.hrdCpbSize, oriRcCfg.gopLen);
ret = H264EncSetRateCtrl(encoder, &oriRcCfg);
ret = H264EncSetRateCtrl(enc, &oriRcCfg);
if (ret) {
mpp_err("H264EncSetRateCtrl() failed, ret %d.", ret);
}
}
} break;
case GET_OUTPUT_STREAM_SIZE:
*((RK_U32*)param) = getOutputStreamSize(pEncInst);
break;
case GET_ENC_EXTRA_INFO : {
h264e_control_extra_info_cfg **dst = (h264e_control_extra_info_cfg **)param;
h264e_control_extra_info_cfg *info = &enc->info;
H264EncConfig *enc_cfg = &enc->enc_cfg;
H264EncRateCtrl *enc_rc_cfg = &enc->enc_rc_cfg;
info->chroma_qp_index_offset = enc_cfg->chroma_qp_index_offset;
info->enable_cabac = enc_cfg->enable_cabac;
info->pic_init_qp = enc_cfg->pic_init_qp;
info->pic_luma_height = enc_cfg->height;
info->pic_luma_width = enc_cfg->width;
info->transform8x8_mode = enc_cfg->transform8x8_mode;
info->input_image_format = enc_cfg->input_image_format;
info->profile_idc = enc_cfg->profile;
info->level_idc = enc_cfg->level;
info->keyframe_max_interval = enc_rc_cfg->keyframe_max_interval;
info->second_chroma_qp_index_offset = enc_cfg->second_chroma_qp_index_offset;
info->pps_id = enc_cfg->pps_id;
*dst = info;
} break;
case GET_OUTPUT_STREAM_SIZE : {
*((RK_U32*)param) = getOutputStreamSize(enc);
} break;
default:
mpp_err("No correspond cmd found, and can not config!");
break;
@ -469,14 +484,12 @@ MPP_RET h264e_config(void *ctx, RK_S32 cmd, void *param)
MPP_RET h264e_callback(void *ctx, void *feedback)
{
h264Instance_s *pEncInst = (h264Instance_s *)ctx;
regValues_s *val = &(pEncInst->asic.regs);
h264e_feedback *fb = (h264e_feedback *)feedback;
int i = 0;
h264Instance_s *enc = (h264Instance_s *)ctx;
regValues_s *val = &(enc->asic.regs);
h264e_feedback *fb = (h264e_feedback *)feedback;
H264EncOut *encOut = &(enc->encOut);
RK_S32 i = 0;
H264EncRet ret;
H264EncInst encInst = (H264EncInst)ctx;
H264EncOut *encOut = &(pEncInst->encOut); // TODO modify by lance 2016.05.19
MPP_RET vpuWaitResult = MPP_OK;
/* HW output stream size, bits to bytes */
@ -502,11 +515,11 @@ MPP_RET h264e_callback(void *ctx, void *feedback)
val->hw_status = fb->hw_status;
// vpuWaitResult should be given from hal part, and here assume it is OK // TODO modify by lance 2016.06.01
ret = H264EncStrmEncodeAfter(encInst, encOut, vpuWaitResult); // add by lance 2016.05.07
ret = H264EncStrmEncodeAfter(enc, encOut, vpuWaitResult); // add by lance 2016.05.07
switch (ret) {
case H264ENC_FRAME_READY:
if (encOut->codingType != H264ENC_NOTCODED_FRAME) {
pEncInst->intraPeriodCnt++;
enc->intraPeriodCnt++;
}
break;

View file

@ -29,6 +29,7 @@ typedef enum EncCfgCmd_t {
CHK_ENC_CFG,
SET_ENC_CFG,
SET_ENC_RC_CFG,
GET_ENC_EXTRA_INFO,
GET_OUTPUT_STREAM_SIZE,
} EncCfgCmd;

View file

@ -40,9 +40,6 @@ struct MppEnc_t {
* configuration parameter to controller and hal
*/
MppEncConfig mpp_cfg;
H264EncConfig enc_cfg;
H264EncRateCtrl enc_rc_cfg;
h264e_control_extra_info_cfg extra_info_cfg;
};
#ifdef __cplusplus

View file

@ -103,8 +103,8 @@ void *mpp_enc_control_thread(void *data)
* if there is available buffer in the input frame do encoding
*/
if (NULL == packet) {
RK_U32 width = enc->enc_cfg.width;
RK_U32 height = enc->enc_cfg.height;
RK_U32 width = enc->mpp_cfg.width;
RK_U32 height = enc->mpp_cfg.height;
RK_U32 size = width * height;
MppBuffer buffer = NULL;
@ -241,28 +241,6 @@ void *mpp_enc_hal_thread(void *data)
return NULL;
}
static MPP_RET mpp_extra_info_generate(MppEnc *enc)
{
h264e_control_extra_info_cfg *info = &enc->extra_info_cfg;
H264EncConfig *enc_cfg = &enc->enc_cfg;
H264EncRateCtrl *enc_rc_cfg = &enc->enc_rc_cfg;
info->chroma_qp_index_offset = enc_cfg->chroma_qp_index_offset;
info->enable_cabac = enc_cfg->enable_cabac;
info->pic_init_qp = enc_cfg->pic_init_qp;
info->pic_luma_height = enc_cfg->height;
info->pic_luma_width = enc_cfg->width;
info->transform8x8_mode = enc_cfg->transform8x8_mode;
info->input_image_format = enc_cfg->input_image_format;
info->profile_idc = enc_cfg->profile;
info->level_idc = enc_cfg->level;
info->keyframe_max_interval = enc_rc_cfg->keyframe_max_interval;
info->second_chroma_qp_index_offset = enc_cfg->second_chroma_qp_index_offset;
info->pps_id = enc_cfg->pps_id;
return MPP_OK;
}
MPP_RET mpp_enc_init(MppEnc **enc, MppCodingType coding)
{
MPP_RET ret;
@ -410,18 +388,21 @@ MPP_RET mpp_enc_control(MppEnc *enc, MpiCmd cmd, void *param)
switch (cmd) {
case MPP_ENC_SET_CFG : {
MppEncConfig *mpp_cfg = &enc->mpp_cfg;
void *extra_info_cfg = NULL;
*mpp_cfg = *((MppEncConfig *)param);
/* before set config to controller check it first */
ret = controller_config(enc->controller, CHK_ENC_CFG, (void *)mpp_cfg);
if (ret)
if (ret) {
mpp_err("config check failed ret %d\n", ret);
break;
}
controller_config(enc->controller, SET_ENC_CFG, (void *)mpp_cfg);
controller_config(enc->controller, SET_ENC_RC_CFG, (void *)mpp_cfg);
mpp_extra_info_generate(enc);
controller_config(enc->controller, GET_ENC_EXTRA_INFO, (void *)&extra_info_cfg);
ret = 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, extra_info_cfg);
} break;
case MPP_ENC_GET_CFG : {