shithub: openh264

Download patch

ref: de5e385f96c0589d30a3824500ce1e3115ce59af
parent: 01068cc9b967e4931d9a584930304d8ca317ebbd
author: huili2 <huili2@cisco.com>
date: Thu Dec 14 09:07:14 EST 2017

add dec option for is_ref_pic

--- a/codec/api/svc/codec_app_def.h
+++ b/codec/api/svc/codec_app_def.h
@@ -165,6 +165,7 @@
   DECODER_OPTION_PROFILE,               ///< get current AU profile info, only is used in GetOption
   DECODER_OPTION_LEVEL,                 ///< get current AU level info,only is used in GetOption
   DECODER_OPTION_STATISTICS_LOG_INTERVAL,///< set log output interval
+  DECODER_OPTION_IS_REF_PIC,             ///< feedback current frame is ref pic or not
 
 } DECODER_OPTION;
 
--- a/codec/decoder/core/inc/decoder_context.h
+++ b/codec/decoder/core/inc/decoder_context.h
@@ -415,6 +415,7 @@
 //feedback whether or not have VCL in current AU, and the temporal ID
   int32_t iFeedbackVclNalInAu;
   int32_t iFeedbackTidInAu;
+  int32_t iFeedbackNalRefIdc;
 
   bool bAuReadyFlag;   // true: one au is ready for decoding; false: default value
 
--- a/codec/decoder/core/src/decoder.cpp
+++ b/codec/decoder/core/src/decoder.cpp
@@ -323,6 +323,8 @@
   pCtx->iSPSLastInvalidId = -1;
   pCtx->iSubSPSInvalidNum = 0;
   pCtx->iSubSPSLastInvalidId = -1;
+  pCtx->iFeedbackNalRefIdc = -1; //initialize
+
 }
 
 /*
@@ -596,6 +598,7 @@
 
   pCtx->iFeedbackVclNalInAu = FEEDBACK_VCL_NAL;
   pCtx->iFeedbackTidInAu    = pAccessUnit->pNalUnitsList[idx]->sNalHeaderExt.uiTemporalId;
+  pCtx->iFeedbackNalRefIdc  = pAccessUnit->pNalUnitsList[idx]->sNalHeaderExt.sNalUnitHeader.uiNalRefIdc;
 }
 
 /*!
--- a/codec/decoder/plus/src/welsDecoderExt.cpp
+++ b/codec/decoder/plus/src/welsDecoderExt.cpp
@@ -403,6 +403,12 @@
     iVal = m_pDecContext->iFeedbackTidInAu;
     * ((int*)pOption) = iVal;
     return cmResultSuccess;
+  } else if (DECODER_OPTION_IS_REF_PIC == eOptID) {
+    iVal = m_pDecContext->iFeedbackNalRefIdc;
+    if (iVal > 0)
+      iVal = 1;
+    * ((int*)pOption) = iVal;
+    return cmResultSuccess;
   } else if (DECODER_OPTION_ERROR_CON_IDC == eOptID) {
     iVal = (int) m_pDecContext->pParam->eEcActiveIdc;
     * ((int*)pOption) = iVal;
@@ -537,6 +543,7 @@
 #endif
 
   m_pDecContext->iFeedbackTidInAu             = -1; //initialize
+  m_pDecContext->iFeedbackNalRefIdc           = -1; //initialize
   if (pDstInfo) {
     pDstInfo->uiOutYuvTimeStamp = 0;
     m_pDecContext->uiTimeStamp = pDstInfo->uiInBsTimeStamp;
@@ -716,6 +723,7 @@
 
   m_pDecContext->iErrorCode = dsErrorFree; //initialize at the starting of AU decoding.
   m_pDecContext->pParam->eEcActiveIdc = ERROR_CON_DISABLE; //add protection to disable EC here.
+  m_pDecContext->iFeedbackNalRefIdc = -1; //initialize
   if (!m_pDecContext->bFramePending) { //frame complete
     m_pDecContext->pParserBsInfo->iNalNum = 0;
     memset (m_pDecContext->pParserBsInfo->pNalLenInByte, 0, MAX_NAL_UNITS_IN_LAYER);
--- a/test/api/decode_api_test.cpp
+++ b/test/api/decode_api_test.cpp
@@ -186,6 +186,44 @@
   (void) iSkipedBytes;
 }
 
+TEST_P(EncodeDecodeTestAPI, GetOptionIsRefPic) {
+  EncodeDecodeFileParamBase p = GetParam();
+  prepareParamDefault(1, p.slicenum, p.width, p.height, p.frameRate, &param_);
+  encoder_->Uninitialize();
+  int rv = encoder_->InitializeExt(&param_);
+  ASSERT_TRUE(rv == cmResultSuccess);
+
+  ASSERT_TRUE(InitialEncDec(p.width, p.height));
+  int32_t iTraceLevel = WELS_LOG_QUIET;
+  encoder_->SetOption(ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
+  decoder_->SetOption(DECODER_OPTION_TRACE_LEVEL, &iTraceLevel);
+  int iIdx = 0;
+  int iSkipedBytes;
+  int iIsRefPic;
+  decoder_->GetOption(DECODER_OPTION_IS_REF_PIC, &iIsRefPic);
+  ASSERT_EQ(iIsRefPic, -1);
+
+  while (iIdx <= p.numframes) {
+    EncodeOneFrame(1);
+    //decoding after each encoding frame
+    int len = 0;
+    encToDecData(info, len);
+    unsigned char* pData[3] = { NULL };
+    memset(&dstBufInfo_, 0, sizeof(SBufferInfo));
+    rv = decoder_->DecodeFrame2(info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
+    memset(&dstBufInfo_, 0, sizeof(SBufferInfo));
+    decoder_->GetOption(DECODER_OPTION_IS_REF_PIC, &iIsRefPic);
+    ASSERT_EQ(iIsRefPic, -1);
+    rv = decoder_->DecodeFrame2(NULL, 0, pData, &dstBufInfo_); //reconstruction
+    if (dstBufInfo_.iBufferStatus == 1) {
+      decoder_->GetOption(DECODER_OPTION_IS_REF_PIC, &iIsRefPic);
+      ASSERT_TRUE(iIsRefPic >= 0);
+    }
+    iIdx++;
+  }
+  (void)iSkipedBytes;
+}
+
 TEST_P (EncodeDecodeTestAPI, GetOptionTid_AVC_NOPREFIX) {
   SLTRMarkingFeedback m_LTR_Marking_Feedback;
   SLTRRecoverRequest m_LTR_Recover_Request;