cisco/openh264

Frame decode error.

tyan0 opened this issue · 1 comments

tyan0 commented

Frame decode error occurs if playing the following video file.
https://tyan0.yr32.net/openh264/decode_frame_error.mp4

I am not sure this is the right thing, but the following patch solves the issue.

diff --git a/codec/decoder/core/src/manage_dec_ref.cpp b/codec/decoder/core/src/manage_dec_ref.cpp
index c3c98312..8281b087 100644
--- a/codec/decoder/core/src/manage_dec_ref.cpp
+++ b/codec/decoder/core/src/manage_dec_ref.cpp
@@ -460,7 +460,8 @@ int32_t WelsReorderRefList (PWelsDecoderContext pCtx) {
           }
         }
         if (i < 0) {
-          return ERR_INFO_REFERENCE_PIC_LOST;
+          iReorderingIndex++;
+          continue;
         }
         pPic = ppRefList[i];
         if (i > iReorderingIndex) {

Could maintainer please have a look?


Edit: patch revised. (11 Dec 2023)

tyan0 commented

Sorry, I noticed above patch causes test failure. I'd like to propose alternative fix below.
New patch enables the function WelsReorderRefList2() which was introduced by the commit 1b8caef, and fixes trivial issue of that function. The two patches are completely different, but, both solve the issue.

diff --git a/codec/decoder/core/src/decoder_core.cpp b/codec/decoder/core/src/decoder_core.cpp
index 106d0d41..48e03a0d 100644
--- a/codec/decoder/core/src/decoder_core.cpp
+++ b/codec/decoder/core/src/decoder_core.cpp
@@ -2432,7 +2432,7 @@ int32_t InitRefPicList (PWelsDecoderContext pCtx, const uint8_t kuiNRi, int32_t
   } else
     iRet = WelsInitRefList (pCtx, iPoc);
   if ((pCtx->eSliceType != I_SLICE && pCtx->eSliceType != SI_SLICE)) {
-#if 0
+#if 1
     if (pCtx->pSps->uiProfileIdc != 66 && pCtx->pPps->bEntropyCodingModeFlag)
       iRet = WelsReorderRefList2 (pCtx);
     else
diff --git a/codec/decoder/core/src/manage_dec_ref.cpp b/codec/decoder/core/src/manage_dec_ref.cpp
index 410b9c47..fe3e033a 100644
--- a/codec/decoder/core/src/manage_dec_ref.cpp
+++ b/codec/decoder/core/src/manage_dec_ref.cpp
@@ -495,7 +495,10 @@ int32_t WelsReorderRefList2 (PWelsDecoderContext pCtx) {
   int32_t i = 0;
   int32_t j = 0;
   int32_t k = 0;
-  int32_t iMaxRefIdx = pCtx->pSps->iNumRefFrames;
+  int32_t iMaxRefIdx = pCtx->iPicQueueNumber;
+  if (iMaxRefIdx > MAX_REF_PIC_COUNT) {
+    iMaxRefIdx = MAX_REF_PIC_COUNT;
+  }
   const int32_t iCurFrameNum = pSliceHeader->iFrameNum;
   const int32_t iMaxPicNum = 1 << pSliceHeader->pSps->uiLog2MaxFrameNum;
   int32_t iListCount = 1;