[h264e]: remove redundant code

git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@1166 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
ChenHengming
2016-08-07 05:39:41 +00:00
parent b15604090a
commit 20717fb0e9
12 changed files with 103 additions and 661 deletions

View File

@@ -46,6 +46,6 @@ typedef enum {
/*------------------------------------------------------------------------------
4. Function prototypes
------------------------------------------------------------------------------*/
void H264CodeFrame(h264Instance_s * inst, h264e_syntax *syntax_data);
void H264CodeFrame(H264ECtx * inst, h264e_syntax *syntax_data);
#endif

View File

@@ -22,7 +22,7 @@
i32 H264GetAllowedWidth(i32 width, MppFrameFormat inputType);
H264EncRet H264Init(h264Instance_s * pinst);
H264EncRet H264Cfg(const H264EncConfig * pEncCfg, h264Instance_s * pinst);
H264EncRet H264Init(H264ECtx * pinst);
H264EncRet H264Cfg(const H264EncConfig * pEncCfg, H264ECtx * pinst);
#endif

View File

@@ -22,7 +22,7 @@
#include "ewl.h"
#include "mpp_mem.h"
#include "mpp_buffer.h"
#include "h264e_syntax.h" // add by lance 2016.05.07
#include "h264e_syntax.h"
/* HW status register bits */
#define ASIC_STATUS_BUFF_FULL 0x020
@@ -75,21 +75,10 @@ typedef enum {
} asicFrameCodingType_e;
typedef struct {
u32 irqDisable;
u32 irqInterval;
u32 mbsInCol;
u32 mbsInRow;
u32 qp;
u32 qpMin;
u32 qpMax;
u32 constrainedIntraPrediction;
u32 roundingCtrl;
u32 frameCodingType;
u32 codingType;
u32 pixelsOnRow;
u32 xFill;
u32 yFill;
u32 ppsId;
u32 idrPicId;
u32 frameNum;
u32 picInitQp;
@@ -105,12 +94,6 @@ typedef struct {
u32 inputImageRotation;
u32 outputStrmBase;
u32 outputStrmSize;
u32 firstFreeBit;
u32 strmStartMSB;
u32 strmStartLSB;
u32 rlcBase;
u32 rlcLimitSpace;
u32 socket; // vpu socket // now it will be inited by hal part, so mask it by lance 2016.05.09
u32 inputLumBase;
u32 inputCbBase;
@@ -123,31 +106,12 @@ typedef struct {
u32 rlcCount;
u32 qpSum;
u32 h264StrmMode; /* 0 - byte stream, 1 - NAL units */
u32 gobHeaderMask;
u32 gobFrameId;
u8 quantTable[8 * 8 * 2];
u32 jpegMode;
u32 jpegSliceEnable;
u32 jpegRestartInterval;
u32 jpegRestartMarker;
u32 inputLumaBaseOffset;
u32 inputChromaBaseOffset;
u32 h264Inter4x4Disabled;
u32 disableQuarterPixelMv;
u32 vsNextLumaBase;
u32 vsMode;
u32 vpSize;
u32 vpMbBits;
u32 hec;
u32 moduloTimeBase;
u32 intraDcVlcThr;
u32 vopFcode;
u32 timeInc;
u32 timeIncBits;
u32 asicCfgReg;
u32 intra16Favor;
u32 interFavor;
u32 skipPenalty;
i32 madQpDelta;
u32 madThreshold;
u32 madCount;
@@ -159,24 +123,6 @@ typedef struct {
u32 rMaskMsb;
u32 gMaskMsb;
u32 bMaskMsb;
u32 splitMvMode;
u32 diffMvPenalty[3];
u32 splitPenalty[4];
u32 zeroMvFavorDiv2;
u32 intraAreaTop;
u32 intraAreaLeft;
u32 intraAreaBottom;
u32 intraAreaRight;
u32 roi1Top;
u32 roi1Left;
u32 roi1Bottom;
u32 roi1Right;
u32 roi2Top;
u32 roi2Left;
u32 roi2Bottom;
u32 roi2Right;
u32 hw_status;
} regValues_s;
@@ -190,5 +136,5 @@ typedef struct {
i32 EncAsicControllerInit(asicData_s * asic);
/* Functions for controlling ASIC */
void EncAsicFrameStart(void * inst,/* const void *ewl,*/ regValues_s * val, h264e_syntax *syntax_data); // mask by lance 2016.05.12
void EncAsicFrameStart(void * inst, regValues_s * val, h264e_syntax *syntax_data);
#endif

View File

@@ -16,4 +16,4 @@
#include "H264Instance.h"
RK_U32 getOutputStreamSize(h264Instance_s *pEncInst);
RK_U32 getOutputStreamSize(H264ECtx *pEncInst);

View File

@@ -301,7 +301,7 @@ typedef struct {
h264e_control_extra_info_cfg info;
H264EncConfig enc_cfg;
H264EncRateCtrl enc_rc_cfg;
} h264Instance_s;
} H264ECtx;
#define H264E_DBG_FUNCTION (0x00000001)
@@ -317,30 +317,24 @@ extern RK_U32 h264e_debug;
------------------------------------------------------------------------------*/
/* Initialization & release */
H264EncRet H264EncInit(h264Instance_s *inst);
H264EncRet H264EncRelease(h264Instance_s *inst);
H264EncRet H264EncInit(H264ECtx *inst);
H264EncRet H264EncRelease(H264ECtx *inst);
/* Encoder configuration before stream generation */
H264EncRet H264EncCfg(h264Instance_s *inst, const H264EncConfig * pEncConfig);
H264EncRet H264EncSetCodingCtrl(h264Instance_s *inst, const H264EncCodingCtrl *
H264EncRet H264EncCfg(H264ECtx *inst, const H264EncConfig * pEncConfig);
H264EncRet H264EncSetCodingCtrl(H264ECtx *inst, const H264EncCodingCtrl *
pCodingParams);
H264EncRet H264EncGetCodingCtrl(h264Instance_s *inst, H264EncCodingCtrl *
H264EncRet H264EncGetCodingCtrl(H264ECtx *inst, H264EncCodingCtrl *
pCodingParams);
/* Encoder configuration before and during stream generation */
H264EncRet H264EncSetRateCtrl(h264Instance_s *inst,
H264EncRet H264EncSetRateCtrl(H264ECtx *inst,
const H264EncRateCtrl * pRateCtrl);
H264EncRet H264EncGetRateCtrl(h264Instance_s *inst,
H264EncRet H264EncGetRateCtrl(H264ECtx *inst,
H264EncRateCtrl * pRateCtrl);
H264EncRet H264EncSetPreProcessing(h264Instance_s *inst,
const H264EncPreProcessingCfg *
pPreProcCfg);
H264EncRet H264EncGetPreProcessing(h264Instance_s *inst,
H264EncPreProcessingCfg * pPreProcCfg);
/* Encoder user data insertion during stream generation */
H264EncRet H264EncSetSeiUserData(h264Instance_s *inst, const u8 * pUserData,
H264EncRet H264EncSetSeiUserData(H264ECtx *inst, const u8 * pUserData,
u32 userDataSize);
/* Stream generation */
@@ -348,20 +342,20 @@ H264EncRet H264EncSetSeiUserData(h264Instance_s *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(h264Instance_s *inst, const H264EncIn * pEncIn,
H264EncRet H264EncStrmStart(H264ECtx *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(h264Instance_s *inst, const H264EncIn * pEncIn,
H264EncRet H264EncStrmEncode(H264ECtx *inst, const H264EncIn * pEncIn,
H264EncOut * pEncOut, h264e_syntax *syntax_data);
H264EncRet H264EncStrmEncodeAfter(h264Instance_s *inst,
H264EncRet H264EncStrmEncodeAfter(H264ECtx *inst,
H264EncOut * pEncOut, MPP_RET vpuWaitResult);
/* H264EncStrmEnd ends a stream with an EOS code. */
H264EncRet H264EncStrmEnd(h264Instance_s *inst, const H264EncIn * pEncIn,
H264EncRet H264EncStrmEnd(H264ECtx *inst, const H264EncIn * pEncIn,
H264EncOut * pEncOut);
#ifdef __cplusplus

View File

@@ -14,63 +14,17 @@
* limitations under the License.
*/
/*------------------------------------------------------------------------------
1. Include headers
------------------------------------------------------------------------------*/
#include "mpp_log.h"
#include "enccommon.h"
#include "ewl.h"
#include "h264encapi.h"
#include "H264CodeFrame.h"
/*------------------------------------------------------------------------------
2. External compiler flags
------------------------------------------------------------------------------*/
static void H264SetNewFrame(H264ECtx * inst);
/*------------------------------------------------------------------------------
3. Module defines
------------------------------------------------------------------------------*/
static const u32 h264Intra16Favor[52] = {
24, 24, 24, 26, 27, 30, 32, 35, 39, 43, 48, 53, 58, 64, 71, 78,
85, 93, 102, 111, 121, 131, 142, 154, 167, 180, 195, 211, 229,
248, 271, 296, 326, 361, 404, 457, 523, 607, 714, 852, 1034,
1272, 1588, 2008, 2568, 3318, 4323, 5672, 7486, 9928, 13216,
17648
};
static const u32 h264InterFavor[52] = {
40, 40, 41, 42, 43, 44, 45, 48, 51, 53, 55, 60, 62, 67, 69, 72,
78, 84, 90, 96, 110, 120, 135, 152, 170, 189, 210, 235, 265,
297, 335, 376, 420, 470, 522, 572, 620, 670, 724, 770, 820,
867, 915, 970, 1020, 1076, 1132, 1180, 1230, 1275, 1320, 1370
};
static const u32 h264SkipSadPenalty[52] = { //rk29
255, 255, 255, 255, 255, 255, 255, 255, 255, 224,
208, 192, 176, 160, 144, 128, 112, 96, 80, 64,
56, 48, 44, 40, 36, 32, 28, 24, 22, 20,
18, 16, 12, 11, 10, 9, 8, 7, 5, 5,
4, 4, 3, 3, 2, 2, 1, 1, 1, 1,
0, 0
};
/*------------------------------------------------------------------------------
4. Local function prototypes
------------------------------------------------------------------------------*/
static void H264SetNewFrame(h264Instance_s * inst);
//static struct timeval tv1, tv2; // mask by lance 2016.05.05
//static int64_t total = 0; // mask by lance 2016.05.05
static RK_S64 encNum = 0;
/*------------------------------------------------------------------------------
H264CodeFrame
------------------------------------------------------------------------------*/
void H264CodeFrame(h264Instance_s * inst, h264e_syntax *syntax_data)
void H264CodeFrame(H264ECtx * inst, h264e_syntax *syntax_data)
{
H264SetNewFrame(inst);
if (!inst->time_debug_init) {
@@ -78,21 +32,10 @@ void H264CodeFrame(h264Instance_s * inst, h264e_syntax *syntax_data)
encNum = 0;
}
EncAsicFrameStart((void*)inst,/* inst->asic.ewl,*/ &inst->asic.regs, syntax_data); // mask by lance 2016.05.12
/* Reset the favor values for next frame */
inst->asic.regs.intra16Favor = 0;
inst->asic.regs.interFavor = 0;
inst->asic.regs.skipPenalty = 1;
return;
EncAsicFrameStart((void*)inst, &inst->asic.regs, syntax_data);
}
/*------------------------------------------------------------------------------
Set encoding parameters at the beginning of a new frame.
------------------------------------------------------------------------------*/
void H264SetNewFrame(h264Instance_s * inst)
void H264SetNewFrame(H264ECtx * inst)
{
regValues_s *regs = &inst->asic.regs;
@@ -100,39 +43,6 @@ void H264SetNewFrame(h264Instance_s * inst)
/* 64-bit aligned stream base address */
regs->outputStrmBase += (inst->stream.byteCnt & (~0x07));
/* bit offset in the last 64-bit word */
regs->firstFreeBit = (inst->stream.byteCnt & 0x07) * 8;
/* header remainder is byte aligned, max 7 bytes = 56 bits */
if (regs->firstFreeBit != 0) {
/* 64-bit aligned stream pointer */
u8 *pTmp = (u8 *) ((size_t) (inst->stream.stream) & (u32) (~0x07));
u32 val;
/* Clear remaining bits */
for (val = 6; val >= regs->firstFreeBit / 8; val--)
pTmp[val] = 0;
val = pTmp[0] << 24;
val |= pTmp[1] << 16;
val |= pTmp[2] << 8;
val |= pTmp[3];
regs->strmStartMSB = val; /* 32 bits to MSB */
if (regs->firstFreeBit > 32) {
val = pTmp[4] << 24;
val |= pTmp[5] << 16;
val |= pTmp[6] << 8;
regs->strmStartLSB = val;
} else
regs->strmStartLSB = 0;
} else {
regs->strmStartMSB = regs->strmStartLSB = 0;
}
regs->frameNum = inst->slice.frameNum;
regs->idrPicId = inst->slice.idrPicId;
@@ -171,23 +81,11 @@ void H264SetNewFrame(h264Instance_s * inst)
if (inst->picParameterSet.entropyCodingMode) {
regs->cabacInitIdc = inst->slice.cabacInitIdc;
}
regs->constrainedIntraPrediction =
(inst->picParameterSet.constIntraPred == ENCHW_YES) ? 1 : 0;
regs->frameCodingType =
(inst->slice.sliceType == ISLICE) ? ASIC_INTRA : ASIC_INTER;
/* If favor has not been set earlier by testId use default */
if (regs->intra16Favor == 0)
regs->intra16Favor = h264Intra16Favor[regs->qp];
if (regs->interFavor == 0)
regs->interFavor = h264InterFavor[regs->qp];
if (regs->skipPenalty == 1)
regs->skipPenalty = h264SkipSadPenalty[regs->qp];
/* MAD threshold range [0, 63*256] register 6-bits range [0,63] */
regs->madThreshold = inst->mad.threshold / 256;
regs->madQpDelta = inst->rateControl.mbQpAdjustment;
}

View File

@@ -46,9 +46,6 @@
/*((bus_address & 0x07) == 0)*/)
RK_U32 h264e_debug = 0;
static i32 VSCheckSize(u32 inputWidth, u32 inputHeight, u32 stabilizedWidth,
u32 stabilizedHeight);
/*------------------------------------------------------------------------------
Function name : H264EncInit
Description : Initialize an encoder instance and returns it to application
@@ -57,10 +54,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 *pEncInst)
H264EncRet H264EncInit(H264ECtx *pEncInst)
{
H264EncRet ret;
h264e_dbg_func("enter\n");
ret = H264Init(pEncInst);
if (ret != H264ENC_OK) {
@@ -69,12 +65,8 @@ H264EncRet H264EncInit(h264Instance_s *pEncInst)
}
/* Status == INIT Initialization succesful */
pEncInst->encStatus = H264ENCSTAT_INIT;
pEncInst->inst = pEncInst; /* used as checksum */
mpp_env_get_u32("h264e_debug", &h264e_debug, 0);
h264e_dbg_func("leave\n");
return H264ENC_OK;
}
@@ -86,7 +78,7 @@ H264EncRet H264EncInit(h264Instance_s *pEncInst)
Return type : H264EncRet
Argument : inst - the instance to be released
------------------------------------------------------------------------------*/
H264EncRet H264EncRelease(h264Instance_s *pEncInst)
H264EncRet H264EncRelease(H264ECtx *pEncInst)
{
h264e_dbg_func("enter\n");
@@ -106,7 +98,7 @@ H264EncRet H264EncRelease(h264Instance_s *pEncInst)
return H264ENC_OK;
}
H264EncRet H264EncCfg(h264Instance_s *pEncInst, const H264EncConfig * pEncConfig)
H264EncRet H264EncCfg(H264ECtx *pEncInst, const H264EncConfig * pEncConfig)
{
H264EncRet ret;
h264e_dbg_func("enter\n");
@@ -130,7 +122,7 @@ H264EncRet H264EncCfg(h264Instance_s *pEncInst, const H264EncConfig * pEncConfig
Argument : inst - the instance in use
pCodeParams - user provided parameters
------------------------------------------------------------------------------*/
H264EncRet H264EncSetCodingCtrl(h264Instance_s *pEncInst, const H264EncCodingCtrl * pCodeParams)
H264EncRet H264EncSetCodingCtrl(H264ECtx *pEncInst, const H264EncCodingCtrl * pCodeParams)
{
h264e_dbg_func("enter\n");
@@ -232,7 +224,7 @@ set_slice_size:
Argument : inst - the instance in use
pCodeParams - palce where parameters are returned
------------------------------------------------------------------------------*/
H264EncRet H264EncGetCodingCtrl(h264Instance_s *pEncInst,
H264EncRet H264EncGetCodingCtrl(H264ECtx *pEncInst,
H264EncCodingCtrl * pCodeParams)
{
h264e_dbg_func("enter\n");
@@ -282,7 +274,7 @@ H264EncRet H264EncGetCodingCtrl(h264Instance_s *pEncInst,
Argument : inst - the instance in use
pRateCtrl - user provided parameters
------------------------------------------------------------------------------*/
H264EncRet H264EncSetRateCtrl(h264Instance_s *pEncInst,
H264EncRet H264EncSetRateCtrl(H264ECtx *pEncInst,
const H264EncRateCtrl * pRateCtrl)
{
h264RateControl_s *rc;
@@ -448,7 +440,7 @@ H264EncRet H264EncSetRateCtrl(h264Instance_s *pEncInst,
Argument : inst - the instance in use
pRateCtrl - place where parameters are returned
------------------------------------------------------------------------------*/
H264EncRet H264EncGetRateCtrl(h264Instance_s *pEncInst, H264EncRateCtrl * pRateCtrl)
H264EncRet H264EncGetRateCtrl(H264ECtx *pEncInst, H264EncRateCtrl * pRateCtrl)
{
h264RateControl_s *rc;
@@ -487,234 +479,7 @@ H264EncRet H264EncGetRateCtrl(h264Instance_s *pEncInst, H264EncRateCtrl * pRateC
return H264ENC_OK;
}
/*------------------------------------------------------------------------------
Function name : VSCheckSize
Description :
Return type : i32
Argument : u32 inputWidth
Argument : u32 inputHeight
Argument : u32 stabilizedWidth
Argument : u32 stabilizedHeight
------------------------------------------------------------------------------*/
i32 VSCheckSize(u32 inputWidth, u32 inputHeight, u32 stabilizedWidth,
u32 stabilizedHeight)
{
/* Input picture minimum dimensions */
if ((inputWidth < 104) || (inputHeight < 104))
return 1;
/* Stabilized picture minimum values */
if ((stabilizedWidth < 96) || (stabilizedHeight < 96))
return 1;
/* Stabilized dimensions multiple of 4 */
if (((stabilizedWidth & 3) != 0) || ((stabilizedHeight & 3) != 0))
return 1;
/* Edge >= 4 pixels, not checked because stabilization can be
* used without cropping for scene detection
if((inputWidth < (stabilizedWidth + 8)) ||
(inputHeight < (stabilizedHeight + 8)))
return 1; */
return 0;
}
/*------------------------------------------------------------------------------
Function name : H264EncSetPreProcessing
Description : Sets the preprocessing parameters
Return type : H264EncRet
Argument : inst - encoder instance in use
Argument : pPreProcCfg - user provided parameters
------------------------------------------------------------------------------*/
H264EncRet H264EncSetPreProcessing(h264Instance_s *pEncInst,
const H264EncPreProcessingCfg * pPreProcCfg)
{
preProcess_s pp_tmp;
h264e_dbg_func("enter\n");
/* Check for illegal inputs */
if ((pEncInst == NULL) || (pPreProcCfg == NULL)) {
mpp_err_f("ERROR Null argument\n");
return H264ENC_NULL_ARGUMENT;
}
/* Check for existing instance */
if (pEncInst->inst != pEncInst) {
mpp_err_f("ERROR Invalid instance\n");
return H264ENC_INSTANCE_ERROR;
}
if (pPreProcCfg->origWidth > H264ENC_MAX_PP_INPUT_WIDTH ||
pPreProcCfg->origHeight > H264ENC_MAX_PP_INPUT_HEIGHT) {
mpp_err_f("ERROR Too big input image\n");
return H264ENC_INVALID_ARGUMENT;
}
if (pPreProcCfg->inputType > MPP_FMT_ABGR8888) {
mpp_err_f("ERROR Invalid YUV type\n");
return H264ENC_INVALID_ARGUMENT;
}
if (pPreProcCfg->rotation > H264ENC_ROTATE_90L) {
mpp_err_f("ERROR Invalid rotation\n");
return H264ENC_INVALID_ARGUMENT;
}
pp_tmp.lumHeightSrc = pPreProcCfg->origHeight;
pp_tmp.lumWidthSrc = pPreProcCfg->origWidth;
if (pPreProcCfg->videoStabilization == 0) {
pp_tmp.horOffsetSrc = pPreProcCfg->xOffset;
pp_tmp.verOffsetSrc = pPreProcCfg->yOffset;
} else {
pp_tmp.horOffsetSrc = pp_tmp.verOffsetSrc = 0;
}
pp_tmp.lumWidth = pEncInst->preProcess.lumWidth;
pp_tmp.lumHeight = pEncInst->preProcess.lumHeight;
pp_tmp.rotation = pPreProcCfg->rotation;
pp_tmp.inputFormat = pPreProcCfg->inputType;
pp_tmp.videoStab = (pPreProcCfg->videoStabilization != 0) ? 1 : 0;
/* Check for invalid values */
if (EncPreProcessCheck(&pp_tmp) != ENCHW_OK) {
mpp_err_f("ERROR Invalid cropping values\n");
return H264ENC_INVALID_ARGUMENT;
}
/* Set cropping parameters if required */
if ( pEncInst->preProcess.lumWidth % 16 || pEncInst->preProcess.lumHeight % 16 ) {
u32 fillRight = (pEncInst->preProcess.lumWidth + 15) / 16 * 16 -
pEncInst->preProcess.lumWidth;
u32 fillBottom = (pEncInst->preProcess.lumHeight + 15) / 16 * 16 -
pEncInst->preProcess.lumHeight;
pEncInst->seqParameterSet.frameCropping = ENCHW_YES;
pEncInst->seqParameterSet.frameCropLeftOffset = 0;
pEncInst->seqParameterSet.frameCropRightOffset = 0;
pEncInst->seqParameterSet.frameCropTopOffset = 0;
pEncInst->seqParameterSet.frameCropBottomOffset = 0;
if (pPreProcCfg->rotation == 0) { /* No rotation */
pEncInst->seqParameterSet.frameCropRightOffset = fillRight / 2;
pEncInst->seqParameterSet.frameCropBottomOffset = fillBottom / 2;
} else if (pPreProcCfg->rotation == 1) { /* Rotate right */
pEncInst->seqParameterSet.frameCropLeftOffset = fillRight / 2;
pEncInst->seqParameterSet.frameCropBottomOffset = fillBottom / 2;
} else { /* Rotate left */
pEncInst->seqParameterSet.frameCropRightOffset = fillRight / 2;
pEncInst->seqParameterSet.frameCropTopOffset = fillBottom / 2;
}
}
if (pp_tmp.videoStab != 0) {
u32 width = pp_tmp.lumWidth;
u32 height = pp_tmp.lumHeight;
if (pp_tmp.rotation) {
u32 tmp;
tmp = width;
width = height;
height = tmp;
}
if (VSCheckSize(pp_tmp.lumWidthSrc, pp_tmp.lumHeightSrc, width, height)
!= 0) {
mpp_err_f("ERROR Invalid size for stabilization\n");
return H264ENC_INVALID_ARGUMENT;
}
}
pp_tmp.colorConversionType = pPreProcCfg->colorConversion.type;
pp_tmp.colorConversionCoeffA = pPreProcCfg->colorConversion.coeffA;
pp_tmp.colorConversionCoeffB = pPreProcCfg->colorConversion.coeffB;
pp_tmp.colorConversionCoeffC = pPreProcCfg->colorConversion.coeffC;
pp_tmp.colorConversionCoeffE = pPreProcCfg->colorConversion.coeffE;
pp_tmp.colorConversionCoeffF = pPreProcCfg->colorConversion.coeffF;
EncSetColorConversion(&pp_tmp, &pEncInst->asic);
{
preProcess_s *pp = &pEncInst->preProcess;
if (memcpy(pp, &pp_tmp, sizeof(preProcess_s)) != pp) {
mpp_err_f("memcpy failed\n");
return H264ENC_SYSTEM_ERROR;
}
}
h264e_dbg_func("leave\n");
return H264ENC_OK;
}
/*------------------------------------------------------------------------------
Function name : H264EncGetPreProcessing
Description : Returns current preprocessing parameters
Return type : H264EncRet
Argument : inst - encoder instance
Argument : pPreProcCfg - place where the parameters are returned
------------------------------------------------------------------------------*/
H264EncRet H264EncGetPreProcessing(h264Instance_s *pEncInst,
H264EncPreProcessingCfg * pPreProcCfg)
{
preProcess_s *pPP;
h264e_dbg_func("enter\n");
/* Check for illegal inputs */
if ((pEncInst == NULL) || (pPreProcCfg == NULL)) {
mpp_err_f("ERROR Null argument\n");
return H264ENC_NULL_ARGUMENT;
}
/* Check for existing instance */
if (pEncInst->inst != pEncInst) {
mpp_err_f("ERROR Invalid instance\n");
return H264ENC_INSTANCE_ERROR;
}
pPP = &pEncInst->preProcess;
pPreProcCfg->origHeight = pPP->lumHeightSrc;
pPreProcCfg->origWidth = pPP->lumWidthSrc;
pPreProcCfg->xOffset = pPP->horOffsetSrc;
pPreProcCfg->yOffset = pPP->verOffsetSrc;
pPreProcCfg->rotation = (H264EncPictureRotation) pPP->rotation;
pPreProcCfg->inputType = (MppFrameFormat) pPP->inputFormat;
pPreProcCfg->videoStabilization = pPP->videoStab;
pPreProcCfg->colorConversion.type =
(H264EncColorConversionType) pPP->colorConversionType;
pPreProcCfg->colorConversion.coeffA = pPP->colorConversionCoeffA;
pPreProcCfg->colorConversion.coeffB = pPP->colorConversionCoeffB;
pPreProcCfg->colorConversion.coeffC = pPP->colorConversionCoeffC;
pPreProcCfg->colorConversion.coeffE = pPP->colorConversionCoeffE;
pPreProcCfg->colorConversion.coeffF = pPP->colorConversionCoeffF;
h264e_dbg_func("leave\n");
return H264ENC_OK;
}
/*------------------------------------------------------------------------------
Function name : H264EncSetSeiUserData
Description : Sets user data SEI messages
Return type : H264EncRet
Argument : inst - the instance in use
pUserData - pointer to userData, this is used by the
encoder so it must not be released before
disabling user data
userDataSize - size of userData, minimum size 16,
maximum size H264ENC_MAX_USER_DATA_SIZE
not valid size disables userData sei messages
------------------------------------------------------------------------------*/
H264EncRet H264EncSetSeiUserData(h264Instance_s *pEncInst, const u8 * pUserData,
H264EncRet H264EncSetSeiUserData(H264ECtx *pEncInst, const u8 * pUserData,
u32 userDataSize)
{
/* Check for illegal inputs */
@@ -752,7 +517,7 @@ H264EncRet H264EncSetSeiUserData(h264Instance_s *pEncInst, const u8 * pUserData,
Argument : pEncIn - user provided input parameters
pEncOut - place where output info is returned
------------------------------------------------------------------------------*/
H264EncRet H264EncStrmStart(h264Instance_s *pEncInst, const H264EncIn * pEncIn,
H264EncRet H264EncStrmStart(H264ECtx *pEncInst, const H264EncIn * pEncIn,
H264EncOut * pEncOut)
{
h264RateControl_s *rc;
@@ -870,12 +635,11 @@ H264EncRet H264EncStrmStart(h264Instance_s *pEncInst, const H264EncIn * pEncIn,
Argument : pEncIn - user provided input parameters
pEncOut - place where output info is returned
------------------------------------------------------------------------------*/
H264EncRet H264EncStrmEncode(h264Instance_s *pEncInst, const H264EncIn * pEncIn,
H264EncRet H264EncStrmEncode(H264ECtx *pEncInst, const H264EncIn * pEncIn,
H264EncOut * pEncOut, h264e_syntax *syntax_data)
{
slice_s *pSlice;
regValues_s *regs;
/*h264EncodeFrame_e ret;*/ // mask by lance 2016.05.12
h264e_dbg_func("enter\n");
@@ -964,7 +728,7 @@ H264EncRet H264EncStrmEncode(h264Instance_s *pEncInst, const H264EncIn * pEncIn,
}
break;
default:
mpp_err_f("ERROR Invalid input format\n");
mpp_err_f("ERROR Invalid input format %d\n", pEncInst->preProcess.inputFormat);
return H264ENC_INVALID_ARGUMENT;
}
@@ -1072,7 +836,7 @@ H264EncRet H264EncStrmEncode(h264Instance_s *pEncInst, const H264EncIn * pEncIn,
}
/* Code one frame */
H264CodeFrame(pEncInst, syntax_data); // mask by lance 2016.05.12
H264CodeFrame(pEncInst, syntax_data);
// need to think about it also modify by lance 2016.05.07
return H264ENC_FRAME_READY;
@@ -1097,7 +861,7 @@ RK_S32 EncAsicCheckHwStatus(asicData_s *asic)
return ret;
}
H264EncRet H264EncStrmEncodeAfter(h264Instance_s *pEncInst,
H264EncRet H264EncStrmEncodeAfter(H264ECtx *pEncInst,
H264EncOut * pEncOut, MPP_RET vpuWaitResult)
{
slice_s *pSlice;
@@ -1240,7 +1004,7 @@ H264EncRet H264EncStrmEncodeAfter(h264Instance_s *pEncInst,
Argument : pEncIn - user provided input parameters
pEncOut - place where output info is returned
------------------------------------------------------------------------------*/
H264EncRet H264EncStrmEnd(h264Instance_s *pEncInst, const H264EncIn * pEncIn,
H264EncRet H264EncStrmEnd(H264ECtx *pEncInst, const H264EncIn * pEncIn,
H264EncOut * pEncOut)
{
h264e_dbg_func("enter\n");

View File

@@ -43,9 +43,9 @@
/*------------------------------------------------------------------------------
4. Local function prototypes
------------------------------------------------------------------------------*/
static bool_e SetParameter(h264Instance_s * inst,
static bool_e SetParameter(H264ECtx * inst,
const H264EncConfig * pEncCfg);
static bool_e CheckParameter(const h264Instance_s * inst);
static bool_e CheckParameter(const H264ECtx * inst);
/*------------------------------------------------------------------------------
@@ -63,9 +63,9 @@ static bool_e CheckParameter(const h264Instance_s * inst);
H264ENC_INVALID_ARGUMENT
------------------------------------------------------------------------------*/
H264EncRet H264Init(h264Instance_s * pinst)
H264EncRet H264Init(H264ECtx * pinst)
{
h264Instance_s *inst = pinst;
H264ECtx *inst = pinst;
H264EncRet ret = H264ENC_OK;
@@ -77,9 +77,6 @@ H264EncRet H264Init(h264Instance_s * pinst)
/* Initialize ASIC */
EncAsicControllerInit(&inst->asic);
inst->asic.regs.codingType = ASIC_H264;
inst->asic.regs.skipPenalty = 1;
return ret;
}
@@ -90,7 +87,7 @@ H264EncRet H264Init(h264Instance_s * pinst)
Set all parameters in instance to valid values depending on user config.
------------------------------------------------------------------------------*/
bool_e SetParameter(h264Instance_s * inst, const H264EncConfig * pEncCfg)
bool_e SetParameter(H264ECtx * inst, const H264EncConfig * pEncCfg)
{
i32 width, height, tmp, bps;
ASSERT(inst);
@@ -126,14 +123,6 @@ bool_e SetParameter(h264Instance_s * inst, const H264EncConfig * pEncCfg)
inst->mbPerRow = width / 16;
inst->mbPerCol = height / 16;
/* Disable intra and ROI areas by default */
inst->asic.regs.intraAreaTop = inst->asic.regs.intraAreaBottom = inst->mbPerCol;
inst->asic.regs.intraAreaLeft = inst->asic.regs.intraAreaRight = inst->mbPerRow;
inst->asic.regs.roi1Top = inst->asic.regs.roi1Bottom = inst->mbPerCol;
inst->asic.regs.roi1Left = inst->asic.regs.roi1Right = inst->mbPerRow;
inst->asic.regs.roi2Top = inst->asic.regs.roi2Bottom = inst->mbPerCol;
inst->asic.regs.roi2Left = inst->asic.regs.roi2Right = inst->mbPerRow;
/* Sequence parameter set */
inst->seqParameterSet.levelIdc = pEncCfg->level;
inst->seqParameterSet.picWidthInMbsMinus1 = width / 16 - 1;
@@ -251,7 +240,7 @@ bool_e SetParameter(h264Instance_s * inst, const H264EncConfig * pEncCfg)
CheckParameter
------------------------------------------------------------------------------*/
bool_e CheckParameter(const h264Instance_s * inst)
bool_e CheckParameter(const H264ECtx * inst)
{
/* Check crop */
if (EncPreProcessCheck(&inst->preProcess) != ENCHW_OK) {
@@ -280,9 +269,9 @@ i32 H264GetAllowedWidth(i32 width, MppFrameFormat inputType)
}
}
H264EncRet H264Cfg(const H264EncConfig * pEncCfg, h264Instance_s * pinst)
H264EncRet H264Cfg(const H264EncConfig * pEncCfg, H264ECtx * pinst)
{
h264Instance_s *inst = pinst;
H264ECtx *inst = pinst;
H264EncRet ret = H264ENC_OK;

View File

@@ -47,26 +47,11 @@
#define HSWREG(n) ((n)*4)
//#define WRITE_VAL_INFO_FOR_COMPARE 1
#ifdef WRITE_VAL_INFO_FOR_COMPARE
FILE *valCompareFile = NULL;
int oneFrameFlagTest = 0;
#endif
i32 EncAsicControllerInit(asicData_s * asic)
{
ASSERT(asic != NULL);
/* Initialize default values from defined configuration */
asic->regs.irqDisable = ENC6820_IRQ_DISABLE;
asic->regs.asicCfgReg =
((ENC6820_OUTPUT_SWAP_32 & (1)) << 26) |
((ENC6820_OUTPUT_SWAP_16 & (1)) << 27) |
((ENC6820_OUTPUT_SWAP_8 & (1)) << 28);
/* Initialize default values */
asic->regs.roundingCtrl = 0;
asic->regs.cpDistanceMbs = 0;
/* User must set these */
@@ -76,114 +61,13 @@ i32 EncAsicControllerInit(asicData_s * asic)
/* we do NOT reset hardware at this point because */
/* of the multi-instance support */
#ifdef WRITE_VAL_INFO_FOR_COMPARE
oneFrameFlagTest = 0;
if (valCompareFile == NULL) {
if ((valCompareFile = fopen("/data/test/val_cmp.file", "w")) == NULL)
mpp_err("val original File open failed!");
}
#endif
return ENCHW_OK;
}
void EncAsicFrameStart(void * inst, regValues_s * val, h264e_syntax *syntax_data)
{
h264Instance_s *instH264Encoder = (h264Instance_s *)inst;
H264ECtx *instH264Encoder = (H264ECtx *)inst;
int iCount = 0;
#ifdef WRITE_VAL_INFO_FOR_COMPARE
int iTest = 0;
if (oneFrameFlagTest < 240 && valCompareFile != NULL) {
fprintf(valCompareFile, "val->intraAreaTop 0x%08X\n", val->intraAreaTop);
fprintf(valCompareFile, "val->intraAreaBottom 0x%08X\n", val->intraAreaBottom);
fprintf(valCompareFile, "val->intraAreaLeft 0x%08X\n", val->intraAreaLeft);
fprintf(valCompareFile, "val->intraAreaRight 0x%08X\n", val->intraAreaRight);
fprintf(valCompareFile, "val->inputLumBase 0x%08X\n", val->inputLumBase);
fprintf(valCompareFile, "val->inputCbBase 0x%08X\n", val->inputCbBase);
fprintf(valCompareFile, "val->inputCrBase 0x%08X\n", val->inputCrBase);
fprintf(valCompareFile, "val->strmStartMSB 0x%08X\n", val->strmStartMSB);
fprintf(valCompareFile, "val->strmStartLSB 0x%08X\n", val->strmStartLSB);
fprintf(valCompareFile, "val->outputStrmSize 0x%08X\n", val->outputStrmSize);
fprintf(valCompareFile, "val->madQpDelta 0x%08X\n", val->madQpDelta);
fprintf(valCompareFile, "val->internalImageChrBaseR 0x%08X\n", val->internalImageChrBaseR);
fprintf(valCompareFile, "val->mbsInRow 0x%08X\n", val->mbsInRow);
fprintf(valCompareFile, "val->mbsInCol 0x%08X\n", val->mbsInCol);
fprintf(valCompareFile, "val->qp 0x%08X\n", val->qp);
fprintf(valCompareFile, "val->disableQuarterPixelMv 0x%08X\n", val->disableQuarterPixelMv);
fprintf(valCompareFile, "val->cabacInitIdc 0x%08X\n", val->cabacInitIdc);
fprintf(valCompareFile, "val->enableCabac 0x%08X\n", val->enableCabac);
fprintf(valCompareFile, "val->transform8x8Mode 0x%08X\n", val->transform8x8Mode);
fprintf(valCompareFile, "val->h264Inter4x4Disabled 0x%08X\n", val->h264Inter4x4Disabled);
fprintf(valCompareFile, "val->h264StrmMode 0x%08X\n", val->h264StrmMode);
fprintf(valCompareFile, "val->sliceSizeMbRows 0x%08X\n", val->sliceSizeMbRows);
fprintf(valCompareFile, "val->firstFreeBit 0x%08X\n", val->firstFreeBit);
fprintf(valCompareFile, "val->xFill 0x%08X\n", val->xFill);
fprintf(valCompareFile, "val->yFill 0x%08X\n", val->yFill);
fprintf(valCompareFile, "val->inputChromaBaseOffset 0x%08X\n", val->inputChromaBaseOffset);
fprintf(valCompareFile, "val->inputLumaBaseOffset 0x%08X\n", val->inputLumaBaseOffset);
fprintf(valCompareFile, "val->pixelsOnRow 0x%08X\n", val->pixelsOnRow);
fprintf(valCompareFile, "val->internalImageLumBaseW 0x%08X\n", val->internalImageLumBaseW);
fprintf(valCompareFile, "val->internalImageChrBaseW 0x%08X\n", val->internalImageChrBaseW);
if (val->cpTarget != NULL) {
for (iTest = 0; iTest < 10; ++iTest) {
fprintf(valCompareFile, "val->cpTarget[%2d] 0x%08X\n", iTest, val->cpTarget[iTest]);
}
for (iTest = 0; iTest < 6; ++iTest) {
fprintf(valCompareFile, "val->targetError[%2d] 0x%08X\n", iTest, val->targetError[iTest]);
}
for (iTest = 0; iTest < 7; ++iTest) {
fprintf(valCompareFile, "val->deltaQp[%2d] 0x%08X\n", iTest, val->deltaQp[iTest]);
}
}
fprintf(valCompareFile, "val->outputStrmBase 0x%08X\n", val->outputStrmBase);
fprintf(valCompareFile, "val->madThreshold 0x%08X\n", val->madThreshold);
fprintf(valCompareFile, "val->inputImageFormat 0x%08X\n", val->inputImageFormat);
fprintf(valCompareFile, "val->inputImageRotation 0x%08X\n", val->inputImageRotation);
fprintf(valCompareFile, "val->intra16Favor 0x%08X\n", val->intra16Favor);
fprintf(valCompareFile, "val->interFavor 0x%08X\n", val->interFavor);
fprintf(valCompareFile, "val->picInitQp 0x%08X\n", val->picInitQp);
fprintf(valCompareFile, "val->sliceAlphaOffset 0x%08X\n", val->sliceAlphaOffset);
fprintf(valCompareFile, "val->sliceBetaOffset 0x%08X\n", val->sliceBetaOffset);
fprintf(valCompareFile, "val->chromaQpIndexOffset 0x%08X\n", val->chromaQpIndexOffset);
fprintf(valCompareFile, "val->filterDisable 0x%08X\n", val->filterDisable);
fprintf(valCompareFile, "val->idrPicId 0x%08X\n", val->idrPicId);
fprintf(valCompareFile, "val->constrainedIntraPrediction 0x%08X\n", val->constrainedIntraPrediction);
fprintf(valCompareFile, "val->vsNextLumaBase 0x%08X\n", val->vsNextLumaBase);
fprintf(valCompareFile, "val->roi1Top 0x%08X\n", val->roi1Top);
fprintf(valCompareFile, "val->roi1Bottom 0x%08X\n", val->roi1Bottom);
fprintf(valCompareFile, "val->roi1Left 0x%08X\n", val->roi1Left);
fprintf(valCompareFile, "val->roi1Right 0x%08X\n", val->roi1Right);
fprintf(valCompareFile, "val->roi2Top 0x%08X\n", val->roi2Top);
fprintf(valCompareFile, "val->roi2Bottom 0x%08X\n", val->roi2Bottom);
fprintf(valCompareFile, "val->roi2Left 0x%08X\n", val->roi2Left);
fprintf(valCompareFile, "val->roi2Right 0x%08X\n", val->roi2Right);
fprintf(valCompareFile, "val->vsMode 0x%08X\n", val->vsMode);
fprintf(valCompareFile, "val->colorConversionCoeffB 0x%08X\n", val->colorConversionCoeffB);
fprintf(valCompareFile, "val->colorConversionCoeffA 0x%08X\n", val->colorConversionCoeffA);
fprintf(valCompareFile, "val->colorConversionCoeffC 0x%08X\n", val->colorConversionCoeffC);
fprintf(valCompareFile, "val->colorConversionCoeffE 0x%08X\n", val->colorConversionCoeffE);
fprintf(valCompareFile, "val->colorConversionCoeffF 0x%08X\n", val->colorConversionCoeffF);
fprintf(valCompareFile, "val->bMaskMsb 0x%08X\n", val->bMaskMsb);
fprintf(valCompareFile, "val->gMaskMsb 0x%08X\n", val->gMaskMsb);
fprintf(valCompareFile, "val->rMaskMsb 0x%08X\n", val->rMaskMsb);
fprintf(valCompareFile, "val->splitMvMode 0x%08X\n", val->splitMvMode);
fprintf(valCompareFile, "val->qpMax 0x%08X\n", val->qpMax);
fprintf(valCompareFile, "val->qpMin 0x%08X\n", val->qpMin);
fprintf(valCompareFile, "val->cpDistanceMbs 0x%08X\n", val->cpDistanceMbs);
fprintf(valCompareFile, "val->zeroMvFavorDiv2 0x%08X\n", val->zeroMvFavorDiv2);
fprintf(valCompareFile, "val->frameCodingType 0x%08X\n", val->frameCodingType);
fprintf(valCompareFile, "val->codingType 0x%08X\n", val->codingType);
fprintf(valCompareFile, "val->asicCfgReg 0x%08X\n", val->asicCfgReg);
fprintf(valCompareFile, "val->ppsId 0x%08X\n", val->ppsId);
fprintf(valCompareFile, "val->frameNum 0x%08X\n", val->frameNum);
fprintf(valCompareFile, "val->irqDisable 0x%08X\n", val->irqDisable);
fflush(valCompareFile);
++oneFrameFlagTest;
if (valCompareFile != NULL && (oneFrameFlagTest == 239)) {
fclose(valCompareFile);
valCompareFile = NULL;
}
}
#endif
// TODO for rkv
syntax_data->pic_order_cnt_lsb = 2 * val->frameNum;
syntax_data->second_chroma_qp_index_offset = val->chromaQpIndexOffset;
@@ -196,7 +80,7 @@ void EncAsicFrameStart(void * inst, regValues_s * val, h264e_syntax *syntax_data
syntax_data->chroma_qp_index_offset = val->chromaQpIndexOffset;
syntax_data->filter_disable = val->filterDisable;
syntax_data->idr_pic_id = val->idrPicId;
syntax_data->pps_id = val->ppsId;
syntax_data->pps_id = 0;
syntax_data->frame_num = val->frameNum;
syntax_data->slice_size_mb_rows = val->sliceSizeMbRows;
syntax_data->h264_inter4x4_disabled = val->h264Inter4x4Disabled;

View File

@@ -109,7 +109,32 @@ void EncPreProcess(asicData_s * asic, const preProcess_s * preProcess)
stride = (preProcess->lumWidthSrc + 15) & (~15); /* 16 pixel multiple stride */
/* cropping */
if (preProcess->inputFormat <= MPP_FMT_YUV420SP_VU) { /* YUV 420 */
switch (preProcess->inputFormat) {
case MPP_FMT_YUV420SP : {
tmp = preProcess->verOffsetSrc;
tmp *= stride;
tmp += preProcess->horOffsetSrc;
regs->inputLumBase += (tmp & (~7));
regs->inputLumaBaseOffset = tmp & 7;
if (preProcess->videoStab)
regs->vsNextLumaBase += (tmp & (~7));
tmp = preProcess->verOffsetSrc / 2;
tmp *= stride / 2;
tmp += preProcess->horOffsetSrc / 2;
if (VPUClientGetIOMMUStatus() <= 0) {
regs->inputCbBase += (tmp & (~7));
regs->inputCrBase += (tmp & (~7));
} else {
regs->inputCbBase += (tmp & (~7)) << 10;
regs->inputCrBase += (tmp & (~7)) << 10;
}
regs->inputChromaBaseOffset = tmp & 7;
} break;
case MPP_FMT_YUV420P : {
/* Input image position after crop and stabilization */
tmp = preProcess->verOffsetSrc;
tmp *= stride;
@@ -120,33 +145,16 @@ void EncPreProcess(asicData_s * asic, const preProcess_s * preProcess)
if (preProcess->videoStab)
regs->vsNextLumaBase += (tmp & (~7));
/* Chroma */
if (preProcess->inputFormat == MPP_FMT_YUV420P) {
tmp = preProcess->verOffsetSrc / 2;
tmp *= stride / 2;
tmp += preProcess->horOffsetSrc / 2;
tmp = preProcess->verOffsetSrc / 2;
tmp *= stride / 2;
tmp += preProcess->horOffsetSrc / 2;
tmp *= 2;
if (VPUClientGetIOMMUStatus() <= 0/*!VPUMemJudgeIommu()*/) { // modify by lance 2016.05.06
regs->inputCbBase += (tmp & (~7));
} else {
regs->inputCbBase += (tmp & (~7)) << 10;
}
if (VPUClientGetIOMMUStatus() <= 0/*!VPUMemJudgeIommu()*/) { // modify by lance 2016.05.06
regs->inputCrBase += (tmp & (~7));
} else {
regs->inputCrBase += (tmp & (~7)) << 10;
}
regs->inputChromaBaseOffset = tmp & 7;
} else {
tmp = preProcess->verOffsetSrc / 2;
tmp *= stride / 2;
tmp += preProcess->horOffsetSrc / 2;
tmp *= 2;
regs->inputCbBase += (tmp & (~7));
regs->inputChromaBaseOffset = tmp & 7;
}
regs->inputCbBase += (tmp & (~7));
regs->inputChromaBaseOffset = tmp & 7;
} break;
}
if (preProcess->inputFormat < MPP_FMT_YUV_BUTT) { /* YUV 420 */
} else if (preProcess->inputFormat <= MPP_FMT_BGR444) { /* YUV 422 / RGB 16bpp */
/* Input image position after crop and stabilization */
tmp = preProcess->verOffsetSrc;
@@ -190,32 +198,12 @@ void EncPreProcess(asicData_s * asic, const preProcess_s * preProcess)
height = tmp_rotation; // modify by lance 2016.05.12
}
/* Set mandatory input parameters in asic structure */
regs->mbsInRow = (width + 15) / 16;
regs->mbsInCol = (height + 15) / 16;
regs->pixelsOnRow = preProcess->lumWidth;
/* Set the overfill values */
if (width & 0x0F)
regs->xFill = (16 - (width & 0x0F)) / 4;
else
regs->xFill = 0;
if (height & 0x0F)
regs->yFill = 16 - (height & 0x0F);
else
regs->yFill = 0;
/* video stabilization */
if (regs->codingType != ASIC_JPEG && preProcess->videoStab != 0)
if (preProcess->videoStab != 0)
regs->vsMode = 2;
else
regs->vsMode = 0;
#ifdef TRACE_PREPROCESS
EncTracePreProcess(preProcess);
#endif
return;
}

View File

@@ -14,8 +14,9 @@
* limitations under the License.
*/
#define MODULE_TAG "H264E_API"
#define MODULE_TAG "h264e_api"
#include "mpp_env.h"
#include "mpp_log.h"
#include "mpp_common.h"
@@ -32,21 +33,29 @@ RK_U32 h264e_ctrl_debug = 0;
MPP_RET h264e_init(void *ctx, ControllerCfg *ctrlCfg)
{
h264Instance_s * pEncInst = (h264Instance_s*)ctx;
h264e_dbg_func("enter\n");
H264ECtx * pEncInst = (H264ECtx*)ctx;
MPP_RET ret = (MPP_RET)H264EncInit(pEncInst);
pEncInst->encStatus = H264ENCSTAT_INIT;
pEncInst->inst = pEncInst;
mpp_env_get_u32("h264e_debug", &h264e_debug, 0);
if (ret) {
mpp_err_f("H264EncInit() failed ret %d", ret);
}
(void)ctrlCfg;
h264e_dbg_func("leave\n");
return ret;
}
MPP_RET h264e_deinit(void *ctx)
{
h264Instance_s * pEncInst = (h264Instance_s *)ctx;
H264ECtx * pEncInst = (H264ECtx *)ctx;
H264EncRet ret/* = MPP_OK*/;
H264EncIn *encIn = &(pEncInst->encIn);
H264EncOut *encOut = &(pEncInst->encOut);
@@ -68,7 +77,7 @@ MPP_RET h264e_deinit(void *ctx)
MPP_RET h264e_encode(void *ctx, /*HalEncTask **/void *task)
{
H264EncRet ret;
h264Instance_s *p = (h264Instance_s *)ctx;
H264ECtx *p = (H264ECtx *)ctx;
H264EncIn *encIn = &(p->encIn);
H264EncOut *encOut = &(p->encOut);
RK_U32 srcLumaWidth = p->lumWidthSrc;
@@ -94,18 +103,12 @@ MPP_RET h264e_encode(void *ctx, /*HalEncTask **/void *task)
/* Setup encoder input */
{
u32 w = (srcLumaWidth + 15) & (~0x0f); // TODO 352 need to be modify by lance 2016.05.31
// mask by lance 2016.07.04
//MppBufferInfo inInfo; // add by lance 2016.05.06
//mpp_buffer_info_get(((EncTask*)task)->ctrl_frm_buf_in, &inInfo);
u32 w = srcLumaWidth;
encIn->busLuma = mpp_buffer_get_fd(((EncTask*)task)->ctrl_frm_buf_in)/*pictureMem.phy_addr*/;
encIn->busChromaU = encIn->busLuma | ((w * srcLumaHeight) << 10); // TODO 288 need to be modify by lance 2016.05.31
encIn->busChromaV = encIn->busChromaU +
((((w + 1) >> 1) * ((srcLumaHeight + 1) >> 1)) << 10); // TODO 288 need to be modify by lance 2016.05.31
// mask by lance 2016.07.04
/*mpp_log("enc->busChromaU %15x V %15x w %d srcLumaHeight %d size %d",
encIn->busChromaU, encIn->busChromaV, w, srcLumaHeight, inInfo.size);*/
}
@@ -249,7 +252,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 *enc = (h264Instance_s *)ctx; // add by lance 2016.05.31
H264ECtx *enc = (H264ECtx *)ctx; // add by lance 2016.05.31
h264e_dbg_func("enter ctx %p cmd %x param %p\n", ctx, cmd, param);
@@ -262,7 +265,6 @@ MPP_RET h264e_config(void *ctx, RK_S32 cmd, void *param)
H264EncConfig *enc_cfg = &enc->enc_cfg;
H264EncCodingCtrl oriCodingCfg;
H264EncPreProcessingCfg oriPreProcCfg;
enc_cfg->streamType = H264ENC_BYTE_STREAM;
enc_cfg->frameRateDenom = 1;
@@ -297,13 +299,10 @@ MPP_RET h264e_config(void *ctx, RK_S32 cmd, void *param)
h264e_deinit((void*)enc);
break;
} else {
// will be replaced modify by lance 2016.05.20
// ------------
oriCodingCfg.sliceSize = 0;
oriCodingCfg.constrainedIntraPrediction = 0;
oriCodingCfg.disableDeblockingFilter = 0;
oriCodingCfg.cabacInitIdc = 0;
oriCodingCfg.transform8x8Mode = 0;
oriCodingCfg.videoFullRange = 0;
oriCodingCfg.seiMessages = 0;
ret = H264EncSetCodingCtrl(enc, &oriCodingCfg);
@@ -313,26 +312,6 @@ MPP_RET h264e_config(void *ctx, RK_S32 cmd, void *param)
break;
}
}
/* PreP setup */
ret = H264EncGetPreProcessing(enc, &oriPreProcCfg);
if (ret) {
mpp_err("H264EncGetPreProcessing() failed, ret %d.\n", ret);
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",
oriPreProcCfg.origWidth, oriPreProcCfg.origHeight, oriPreProcCfg.xOffset,
oriPreProcCfg.yOffset, oriPreProcCfg.inputType, oriPreProcCfg.rotation,
oriPreProcCfg.videoStabilization, oriPreProcCfg.colorConversion.type);
ret = H264EncSetPreProcessing(enc, &oriPreProcCfg);
if (ret) {
mpp_err("H264EncSetPreProcessing() failed.", ret);
h264e_deinit((void*)enc);
break;
}
}
} break;
case SET_ENC_RC_CFG : {
MppEncConfig *mpp_cfg = (MppEncConfig *)param;
@@ -375,7 +354,7 @@ MPP_RET h264e_config(void *ctx, RK_S32 cmd, void *param)
enc_rc_cfg->gopLen = mpp_cfg->gop;
enc_rc_cfg->fixedIntraQp = 0;
enc_rc_cfg->mbQpAdjustment = 3;
enc_rc_cfg->hrdCpbSize = mpp_cfg->bps / 8;
enc_rc_cfg->hrdCpbSize = mpp_cfg->bps;
enc->intraPicRate = enc_rc_cfg->intraPicRate;
enc->intraPeriodCnt = enc_rc_cfg->intraPicRate;
@@ -464,7 +443,7 @@ MPP_RET h264e_config(void *ctx, RK_S32 cmd, void *param)
MPP_RET h264e_callback(void *ctx, void *feedback)
{
h264Instance_s *enc = (h264Instance_s *)ctx;
H264ECtx *enc = (H264ECtx *)ctx;
regValues_s *val = &(enc->asic.regs);
h264e_feedback *fb = (h264e_feedback *)feedback;
H264EncOut *encOut = &(enc->encOut);
@@ -524,7 +503,7 @@ MPP_RET h264e_callback(void *ctx, void *feedback)
const ControlApi api_h264e_controller = {
"h264e_control",
MPP_VIDEO_CodingAVC,
sizeof(h264Instance_s),
sizeof(H264ECtx),
0,
h264e_init,
h264e_deinit,

View File

@@ -16,7 +16,7 @@
#include "h264e_utils.h"
RK_U32 getOutputStreamSize(h264Instance_s *pEncInst)
RK_U32 getOutputStreamSize(H264ECtx *pEncInst)
{
regValues_s *val = &(pEncInst->asic.regs);