move DecoderConfigParam into InitDecoder
Unified · Split
| @@ -525,13 +525,6 @@ int32_t DecoderConfigParam (PWelsDecoderContext pCtx, const SDecodingParam* kpPa · 524 unmodified lines | ||
| 525 | 525 | if (NULL == pCtx || NULL == kpParam) |
| 526 | 526 | return 1; |
| 527 | 527 | |
| 528 | − CMemoryAlign* pMa = pCtx->pMemAlign; | |
| 529 | − | |
| 530 | − pCtx->pParam = (SDecodingParam*)pMa->WelsMallocz (sizeof (SDecodingParam), "SDecodingParam"); | |
| 531 | − | |
| 532 | − if (NULL == pCtx->pParam) | |
| 533 | − return 1; | |
| 534 | − | |
| 535 | 528 | memcpy (pCtx->pParam, kpParam, sizeof (SDecodingParam)); |
| 536 | 529 | pCtx->eOutputColorFormat = pCtx->pParam->eOutputColorFormat; |
| 537 | 530 | if (!pCtx->bParseOnly) { |
| @@ -539,6 +532,14 @@ int32_t DecoderConfigParam (PWelsDecoderContext pCtx, const SDecodingParam* kpPa · 1 unmodified line | ||
| 539 | 532 | if (iRet) |
| 540 | 533 | return iRet; |
| 541 | 534 | } |
| 535 | + if ((pCtx->pParam->eEcActiveIdc > ERROR_CON_SLICE_MV_COPY_CROSS_IDR_FREEZE_RES_CHANGE) | |
| 536 | + || (pCtx->pParam->eEcActiveIdc < ERROR_CON_DISABLE)) { | |
| 537 | + WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, | |
| 538 | + "eErrorConMethod (%d) not in range: (%d - %d). Set as default value: (%d).", pCtx->pParam->eEcActiveIdc, | |
| 539 | + ERROR_CON_DISABLE, ERROR_CON_SLICE_MV_COPY_CROSS_IDR_FREEZE_RES_CHANGE, | |
| 540 | + ERROR_CON_SLICE_MV_COPY_CROSS_IDR_FREEZE_RES_CHANGE); | |
| 541 | + pCtx->pParam->eEcActiveIdc = ERROR_CON_SLICE_MV_COPY_CROSS_IDR_FREEZE_RES_CHANGE; | |
| 542 | + } | |
| 542 | 543 | pCtx->eErrorConMethod = pCtx->pParam->eEcActiveIdc; |
| 543 | 544 | |
| 544 | 545 | if (pCtx->bParseOnly) //parse only, disable EC method |
| @@ -109,7 +109,7 @@ virtual long EXTAPI GetOption (DECODER_OPTION eOptID, void* pOption); · 108 unmodified lines | ||
| 109 | 109 | PWelsDecoderContext m_pDecContext; |
| 110 | 110 | welsCodecTrace* m_pWelsTrace; |
| 111 | 111 | |
| 112 | −int32_t InitDecoder (const bool); | |
| 112 | +int32_t InitDecoder (const SDecodingParam* pParam); | |
| 113 | 113 | void UninitDecoder (void); |
| 114 | 114 | int32_t ResetDecoder(); |
| 115 | 115 | |
| @@ -198,11 +198,7 @@ long CWelsDecoder::Initialize (const SDecodingParam* pParam) { · 197 unmodified lines | ||
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // H.264 decoder initialization,including memory allocation,then open it ready to decode |
| 201 | − iRet = InitDecoder (pParam->bParseOnly); | |
| 202 | − if (iRet) | |
| 203 | − return iRet; | |
| 204 | − | |
| 205 | − iRet = DecoderConfigParam (m_pDecContext, pParam); | |
| 201 | + iRet = InitDecoder (pParam); | |
| 206 | 202 | if (iRet) |
| 207 | 203 | return iRet; |
| 208 | 204 | |
| @@ -241,11 +237,11 @@ void CWelsDecoder::UninitDecoder (void) { · 32 unmodified lines | ||
| 241 | 237 | } |
| 242 | 238 | |
| 243 | 239 | // the return value of this function is not suitable, it need report failure info to upper layer. |
| 244 | −int32_t CWelsDecoder::InitDecoder (const bool bParseOnly) { | |
| 240 | +int32_t CWelsDecoder::InitDecoder (const SDecodingParam* pParam) { | |
| 245 | 241 | |
| 246 | 242 | WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, |
| 247 | 243 | "CWelsDecoder::init_decoder(), openh264 codec version = %s, ParseOnly = %d", |
| 248 | − VERSION_NUMBER, (int32_t)bParseOnly); | |
| 244 | + VERSION_NUMBER, (int32_t)pParam->bParseOnly); | |
| 249 | 245 | |
| 250 | 246 | if (m_pDecContext) //free |
| 251 | 247 | UninitDecoder(); |
| @@ -256,7 +252,17 @@ int32_t CWelsDecoder::InitDecoder (const bool bParseOnly) { · 4 unmodified lines | ||
| 256 | 252 | m_pDecContext->pMemAlign = new CMemoryAlign (iCacheLineSize); |
| 257 | 253 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == m_pDecContext->pMemAlign), UninitDecoder()) |
| 258 | 254 | |
| 259 | − return WelsInitDecoder (m_pDecContext, bParseOnly, &m_pWelsTrace->m_sLogCtx); | |
| 255 | + WELS_VERIFY_RETURN_PROC_IF (cmInitParaError, WelsInitDecoder (m_pDecContext, pParam->bParseOnly, | |
| 256 | + &m_pWelsTrace->m_sLogCtx), UninitDecoder()) | |
| 257 | + | |
| 258 | + //check param and update decoder context | |
| 259 | + m_pDecContext->pParam = (SDecodingParam*) m_pDecContext->pMemAlign->WelsMallocz (sizeof (SDecodingParam), | |
| 260 | + "SDecodingParam"); | |
| 261 | + WELS_VERIFY_RETURN_PROC_IF (cmMallocMemeError, (NULL == m_pDecContext->pParam), UninitDecoder()); | |
| 262 | + int32_t iRet = DecoderConfigParam (m_pDecContext, pParam); | |
| 263 | + WELS_VERIFY_RETURN_IFNEQ (iRet, cmResultSuccess); | |
| 264 | + | |
| 265 | + return cmResultSuccess; | |
| 260 | 266 | } |
| 261 | 267 | |
| 262 | 268 | int32_t CWelsDecoder::ResetDecoder() { |
| @@ -267,11 +273,7 @@ int32_t CWelsDecoder::ResetDecoder() { · 4 unmodified lines | ||
| 267 | 273 | SDecodingParam sPrevParam; |
| 268 | 274 | memcpy (&sPrevParam, m_pDecContext->pParam, sizeof (SDecodingParam)); |
| 269 | 275 | |
| 270 | − int32_t iRet = InitDecoder (m_pDecContext->bParseOnly); | |
| 271 | − if (iRet) | |
| 272 | − return iRet; | |
| 273 | − | |
| 274 | − return DecoderConfigParam (m_pDecContext, &sPrevParam); | |
| 276 | + WELS_VERIFY_RETURN_PROC_IF (cmInitParaError, InitDecoder (&sPrevParam), UninitDecoder()); | |
| 275 | 277 | } else if (m_pWelsTrace != NULL) { |
| 276 | 278 | WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "ResetDecoder() failed as decoder context null"); |
| 277 | 279 | } |
| @@ -58,8 +58,23 @@ DECODING_STATE DecodeFrame (const unsigned char* kpSrc, · 57 unmodified lines | ||
| 58 | 58 | return dsErrorFree; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | +void UninitDecoder (PWelsDecoderContext pCtx) { | |
| 62 | + if (NULL == pCtx) | |
| 63 | + return; | |
| 64 | + | |
| 65 | + WelsEndDecoder (pCtx); | |
| 66 | + if (NULL != pCtx->pMemAlign) { | |
| 67 | + delete pCtx->pMemAlign; | |
| 68 | + pCtx->pMemAlign = NULL; | |
| 69 | + } | |
| 70 | + if (NULL != pCtx) { | |
| 71 | + free (pCtx); | |
| 72 | + pCtx = NULL; | |
| 73 | + } | |
| 61 | 74 | |
| 62 | −int32_t InitDecoder (const bool bParseOnly, PWelsDecoderContext pCtx, SLogContext* pLogCtx) { | |
| 75 | +} | |
| 76 | + | |
| 77 | +int32_t InitDecoder (const SDecodingParam* pParam, PWelsDecoderContext pCtx, SLogContext* pLogCtx) { | |
| 63 | 78 | |
| 64 | 79 | |
| 65 | 80 | if (NULL == pCtx) |
| @@ -71,7 +86,14 @@ int32_t InitDecoder (const bool bParseOnly, PWelsDecoderContext pCtx, SLogContex · 5 unmodified lines | ||
| 71 | 86 | return cmMallocMemeError; |
| 72 | 87 | } |
| 73 | 88 | |
| 74 | − return WelsInitDecoder (pCtx, bParseOnly, pLogCtx); | |
| 89 | + WELS_VERIFY_RETURN_PROC_IF (cmInitParaError, WelsInitDecoder (pCtx, pParam->bParseOnly, pLogCtx), UninitDecoder (pCtx)); | |
| 90 | + //check param and update decoder context | |
| 91 | + pCtx->pParam = (SDecodingParam*) pCtx->pMemAlign->WelsMallocz (sizeof (SDecodingParam), "SDecodingParam"); | |
| 92 | + WELS_VERIFY_RETURN_PROC_IF (cmMallocMemeError, (NULL == pCtx->pParam), UninitDecoder (pCtx)); | |
| 93 | + int32_t iRet = DecoderConfigParam (pCtx, pCtx->pParam); | |
| 94 | + WELS_VERIFY_RETURN_IFNEQ (iRet, cmResultSuccess); | |
| 95 | + | |
| 96 | + return cmResultSuccess; | |
| 75 | 97 | } |
| 76 | 98 | |
| 77 | 99 | long Initialize (const SDecodingParam* pParam, PWelsDecoderContext pCtx, SLogContext* pLogCtx) { |
| @@ -81,32 +103,13 @@ long Initialize (const SDecodingParam* pParam, PWelsDecoderContext pCtx, SLogCon · 3 unmodified lines | ||
| 81 | 103 | } |
| 82 | 104 | |
| 83 | 105 | // H.264 decoder initialization,including memory allocation,then open it ready to decode |
| 84 | − iRet = InitDecoder (pParam->bParseOnly, pCtx, pLogCtx); | |
| 85 | − if (iRet) | |
| 86 | − return iRet; | |
| 87 | − | |
| 88 | − iRet = DecoderConfigParam (pCtx, pParam); | |
| 106 | + iRet = InitDecoder (pParam, pCtx, pLogCtx); | |
| 89 | 107 | if (iRet) |
| 90 | 108 | return iRet; |
| 91 | 109 | |
| 92 | 110 | return cmResultSuccess; |
| 93 | 111 | } |
| 94 | 112 | |
| 95 | −void UninitDecoder (PWelsDecoderContext pCtx) { | |
| 96 | − if (NULL == pCtx) | |
| 97 | − return; | |
| 98 | − | |
| 99 | − WelsEndDecoder (pCtx); | |
| 100 | − if (NULL != pCtx->pMemAlign) { | |
| 101 | − delete pCtx->pMemAlign; | |
| 102 | − pCtx->pMemAlign = NULL; | |
| 103 | − } | |
| 104 | − if (NULL != pCtx) { | |
| 105 | − free (pCtx); | |
| 106 | − pCtx = NULL; | |
| 107 | − } | |
| 108 | − | |
| 109 | −} | |
| 110 | 113 | class DecoderParseSyntaxTest : public ::testing::Test { |
| 111 | 114 | public: |
| 112 | 115 | virtual void SetUp() { |