add protection for decoder and data format
This commit is contained in:
parent
06e56ecdd8
commit
f8d2ae42ef
@ -273,9 +273,10 @@ void WelsFreeMem (PWelsDecoderContext pCtx) {
|
|||||||
/*!
|
/*!
|
||||||
* \brief Open decoder
|
* \brief Open decoder
|
||||||
*/
|
*/
|
||||||
void WelsOpenDecoder (PWelsDecoderContext pCtx) {
|
int32_t WelsOpenDecoder (PWelsDecoderContext pCtx) {
|
||||||
// function pointers
|
// function pointers
|
||||||
//initial MC function pointer--
|
//initial MC function pointer--
|
||||||
|
int iRet = ERR_NONE;
|
||||||
InitMcFunc (& (pCtx->sMcFunc), pCtx->uiCpuFlag);
|
InitMcFunc (& (pCtx->sMcFunc), pCtx->uiCpuFlag);
|
||||||
InitErrorCon (pCtx);
|
InitErrorCon (pCtx);
|
||||||
|
|
||||||
@ -286,8 +287,9 @@ void WelsOpenDecoder (PWelsDecoderContext pCtx) {
|
|||||||
InitVlcTable (&pCtx->sVlcTable);
|
InitVlcTable (&pCtx->sVlcTable);
|
||||||
|
|
||||||
// startup memory
|
// startup memory
|
||||||
if (ERR_NONE != WelsInitMemory (pCtx))
|
iRet = WelsInitMemory (pCtx);
|
||||||
return;
|
if (ERR_NONE != iRet)
|
||||||
|
return iRet;
|
||||||
|
|
||||||
#ifdef LONG_TERM_REF
|
#ifdef LONG_TERM_REF
|
||||||
pCtx->bParamSetsLostFlag = true;
|
pCtx->bParamSetsLostFlag = true;
|
||||||
@ -298,6 +300,7 @@ void WelsOpenDecoder (PWelsDecoderContext pCtx) {
|
|||||||
pCtx->bDecErrorConedFlag = false; //default: decoder normal status
|
pCtx->bDecErrorConedFlag = false; //default: decoder normal status
|
||||||
pCtx->bPrintFrameErrorTraceFlag = true;
|
pCtx->bPrintFrameErrorTraceFlag = true;
|
||||||
pCtx->iIgnoredErrorInfoPacketCount = 0;
|
pCtx->iIgnoredErrorInfoPacketCount = 0;
|
||||||
|
return iRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -333,6 +336,9 @@ int32_t DecoderConfigParam (PWelsDecoderContext pCtx, const SDecodingParam* kpPa
|
|||||||
|
|
||||||
memcpy (pCtx->pParam, kpParam, sizeof (SDecodingParam));
|
memcpy (pCtx->pParam, kpParam, sizeof (SDecodingParam));
|
||||||
pCtx->eOutputColorFormat = pCtx->pParam->eOutputColorFormat;
|
pCtx->eOutputColorFormat = pCtx->pParam->eOutputColorFormat;
|
||||||
|
int32_t iRet = DecoderSetCsp (pCtx, pCtx->pParam->eOutputColorFormat);
|
||||||
|
if (iRet)
|
||||||
|
return iRet;
|
||||||
pCtx->eErrorConMethod = pCtx->pParam->eEcActiveIdc;
|
pCtx->eErrorConMethod = pCtx->pParam->eEcActiveIdc;
|
||||||
|
|
||||||
if (VIDEO_BITSTREAM_SVC == pCtx->pParam->sVideoProperty.eVideoBsType ||
|
if (VIDEO_BITSTREAM_SVC == pCtx->pParam->sVideoProperty.eVideoBsType ||
|
||||||
@ -368,10 +374,7 @@ int32_t WelsInitDecoder (PWelsDecoderContext pCtx, SLogContext* pLogCtx) {
|
|||||||
WelsDecoderDefaults (pCtx, pLogCtx);
|
WelsDecoderDefaults (pCtx, pLogCtx);
|
||||||
|
|
||||||
// open decoder
|
// open decoder
|
||||||
WelsOpenDecoder (pCtx);
|
return WelsOpenDecoder (pCtx);
|
||||||
|
|
||||||
|
|
||||||
return ERR_NONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -596,9 +599,12 @@ int32_t DecoderSetCsp (PWelsDecoderContext pCtx, const int32_t kiColorFormat) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//For now, support only videoFormatI420!
|
//For now, support only videoFormatI420!
|
||||||
if (kiColorFormat != (int32_t) videoFormatI420) {
|
if (kiColorFormat == (int32_t) videoFormatInternal) {
|
||||||
|
pCtx->pParam->eOutputColorFormat = pCtx->eOutputColorFormat = videoFormatI420;
|
||||||
|
} else if (kiColorFormat != (int32_t) videoFormatI420) {
|
||||||
WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "Support I420 output only for now! Change to I420...");
|
WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "Support I420 output only for now! Change to I420...");
|
||||||
pCtx->pParam->eOutputColorFormat = pCtx->eOutputColorFormat = videoFormatI420;
|
pCtx->pParam->eOutputColorFormat = pCtx->eOutputColorFormat = videoFormatI420;
|
||||||
|
return cmUnsupportedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -101,7 +101,7 @@ virtual long EXTAPI GetOption (DECODER_OPTION eOptID, void* pOption);
|
|||||||
PWelsDecoderContext m_pDecContext;
|
PWelsDecoderContext m_pDecContext;
|
||||||
welsCodecTrace* m_pWelsTrace;
|
welsCodecTrace* m_pWelsTrace;
|
||||||
|
|
||||||
void InitDecoder (void);
|
int32_t InitDecoder (void);
|
||||||
void UninitDecoder (void);
|
void UninitDecoder (void);
|
||||||
|
|
||||||
#ifdef OUTPUT_BIT_STREAM
|
#ifdef OUTPUT_BIT_STREAM
|
||||||
|
@ -185,6 +185,7 @@ CWelsDecoder::~CWelsDecoder() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
long CWelsDecoder::Initialize (const SDecodingParam* pParam) {
|
long CWelsDecoder::Initialize (const SDecodingParam* pParam) {
|
||||||
|
int iRet = ERR_NONE;
|
||||||
if (m_pWelsTrace == NULL) {
|
if (m_pWelsTrace == NULL) {
|
||||||
return cmMallocMemeError;
|
return cmMallocMemeError;
|
||||||
}
|
}
|
||||||
@ -195,9 +196,13 @@ long CWelsDecoder::Initialize (const SDecodingParam* pParam) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// H.264 decoder initialization,including memory allocation,then open it ready to decode
|
// H.264 decoder initialization,including memory allocation,then open it ready to decode
|
||||||
InitDecoder();
|
iRet = InitDecoder();
|
||||||
|
if (iRet)
|
||||||
|
return iRet;
|
||||||
|
|
||||||
DecoderConfigParam (m_pDecContext, pParam);
|
iRet = DecoderConfigParam (m_pDecContext, pParam);
|
||||||
|
if (iRet)
|
||||||
|
return iRet;
|
||||||
|
|
||||||
return cmResultSuccess;
|
return cmResultSuccess;
|
||||||
}
|
}
|
||||||
@ -226,15 +231,16 @@ void CWelsDecoder::UninitDecoder (void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// the return value of this function is not suitable, it need report failure info to upper layer.
|
// the return value of this function is not suitable, it need report failure info to upper layer.
|
||||||
void CWelsDecoder::InitDecoder (void) {
|
int32_t CWelsDecoder::InitDecoder (void) {
|
||||||
|
|
||||||
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::init_decoder(), openh264 codec version = %s",
|
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::init_decoder(), openh264 codec version = %s",
|
||||||
VERSION_NUMBER);
|
VERSION_NUMBER);
|
||||||
|
|
||||||
m_pDecContext = (PWelsDecoderContext)WelsMalloc (sizeof (SWelsDecoderContext), "m_pDecContext");
|
m_pDecContext = (PWelsDecoderContext)WelsMalloc (sizeof (SWelsDecoderContext), "m_pDecContext");
|
||||||
|
if (NULL == m_pDecContext)
|
||||||
|
return cmMallocMemeError;
|
||||||
|
|
||||||
WelsInitDecoder (m_pDecContext, &m_pWelsTrace->m_sLogCtx);
|
return WelsInitDecoder (m_pDecContext, &m_pWelsTrace->m_sLogCtx);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -86,7 +86,11 @@ void DecoderInterfaceTest::Init() {
|
|||||||
m_szBuffer[3] = 1;
|
m_szBuffer[3] = 1;
|
||||||
m_iBufLength = 4;
|
m_iBufLength = 4;
|
||||||
CM_RETURN eRet = (CM_RETURN) m_pDec->Initialize (&m_sDecParam);
|
CM_RETURN eRet = (CM_RETURN) m_pDec->Initialize (&m_sDecParam);
|
||||||
ASSERT_EQ (eRet, cmResultSuccess);
|
if ((m_sDecParam.eOutputColorFormat != videoFormatI420) ||
|
||||||
|
(m_sDecParam.eOutputColorFormat != videoFormatInternal))
|
||||||
|
ASSERT_EQ (eRet, cmUnsupportedData);
|
||||||
|
else
|
||||||
|
ASSERT_EQ (eRet, cmResultSuccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DecoderInterfaceTest::Uninit() {
|
void DecoderInterfaceTest::Uninit() {
|
||||||
@ -154,7 +158,7 @@ void DecoderInterfaceTest::TestInitUninit() {
|
|||||||
m_pDec->Initialize (&m_sDecParam);
|
m_pDec->Initialize (&m_sDecParam);
|
||||||
eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_DATAFORMAT, &iOutput);
|
eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_DATAFORMAT, &iOutput);
|
||||||
EXPECT_EQ (eRet, cmResultSuccess);
|
EXPECT_EQ (eRet, cmResultSuccess);
|
||||||
EXPECT_EQ (20, iOutput);
|
EXPECT_EQ ((int32_t) videoFormatI420, iOutput);
|
||||||
|
|
||||||
//Uninitialize, no GetOption can be done
|
//Uninitialize, no GetOption can be done
|
||||||
m_pDec->Uninitialize();
|
m_pDec->Uninitialize();
|
||||||
@ -180,7 +184,10 @@ void DecoderInterfaceTest::TestDataFormat() {
|
|||||||
|
|
||||||
//valid input
|
//valid input
|
||||||
eRet = (CM_RETURN) m_pDec->SetOption (DECODER_OPTION_DATAFORMAT, &iTmp);
|
eRet = (CM_RETURN) m_pDec->SetOption (DECODER_OPTION_DATAFORMAT, &iTmp);
|
||||||
EXPECT_EQ (eRet, cmResultSuccess);
|
if ((iTmp != (int32_t) videoFormatI420) && (iTmp != (int32_t) videoFormatInternal))
|
||||||
|
EXPECT_EQ (eRet, cmUnsupportedData);
|
||||||
|
else
|
||||||
|
EXPECT_EQ (eRet, cmResultSuccess);
|
||||||
eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_DATAFORMAT, &iOut);
|
eRet = (CM_RETURN) m_pDec->GetOption (DECODER_OPTION_DATAFORMAT, &iOut);
|
||||||
EXPECT_EQ (eRet, cmResultSuccess);
|
EXPECT_EQ (eRet, cmResultSuccess);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user