shithub: openh264

Download patch

ref: 201ab42d7ea03bea96fe8c3a324694b6daef4ac5
parent: 8cc332dea1b196416d2175aae4564ed933f996fe
parent: 8a7a9195d9fe5711078cb2ba0dbda040ab4b14fc
author: Licai Guo <[email protected]>
date: Thu Mar 6 11:51:59 EST 2014

Merge pull request #431 from huili2/large_to_small_sps_bug

Large to small sps bug for issue #373

--- a/codec/decoder/core/inc/dec_frame.h
+++ b/codec/decoder/core/inc/dec_frame.h
@@ -61,8 +61,6 @@
 struct TagDqLayer {
   SLayerInfo			sLayerInfo;
 
-  uint8_t*				pCsData[3];	// pointer to reconstructed picture data
-  int32_t				iCsStride[3];	// Cs stride
   PBitStringAux		pBitStringAux;	// pointer to SBitStringAux
   PFmo				pFmo;		// Current fmo context pointer used
   int8_t*  pMbType;
--- a/codec/decoder/core/inc/decode_slice.h
+++ b/codec/decoder/core/inc/decode_slice.h
@@ -59,9 +59,6 @@
 int32_t WelsMbInterConstruction (PWelsDecoderContext pCtx, PDqLayer pCurLayer);
 void WelsLumaDcDequantIdct (int16_t* pBlock, int32_t iQp);
 int32_t WelsMbInterPrediction (PWelsDecoderContext pCtx, PDqLayer pCurLayer);
-void WelsMbCopy (uint8_t* pDst, int32_t iStrideDst, uint8_t* pSrc, int32_t iStrideSrc,
-                   int32_t iHeight, int32_t iWidth);
-
 void WelsChromaDcIdct (int16_t* pBlock);
 
 #ifdef __cplusplus
--- a/codec/decoder/core/inc/decoder_context.h
+++ b/codec/decoder/core/inc/decoder_context.h
@@ -246,11 +246,6 @@
   // Memory for pAccessUnitList is dynamically held till decoder destruction.
   PDqLayer			pCurDqLayer;		// current DQ layer representation, also carry reference base layer if applicable
   PDqLayer			pDqLayersList[LAYER_NUM_EXCHANGEABLE];	// DQ layers list with memory allocated
-  uint8_t*				pCsListXchg[LAYER_NUM_EXCHANGEABLE][3];	// Constructed picture buffer: 0- cur layer, 1- ref layer;
-  int16_t*				pRsListXchg[LAYER_NUM_EXCHANGEABLE][3];// Residual picture buffer: 0- cur layer, 1- ref layer;
-
-  int32_t				iCsStride[3];		// strides for Cs
-  int32_t				iRsStride[3];		// strides for Rs
 
   int32_t             iPicWidthReq;		// picture width have requested the memory
   int32_t             iPicHeightReq;		// picture height have requested the memory
--- a/codec/decoder/core/src/decode_slice.cpp
+++ b/codec/decoder/core/src/decode_slice.cpp
@@ -270,46 +270,10 @@
   return 0;
 }
 
-void WelsMbCopy (uint8_t* pDst, int32_t iStrideDst, uint8_t* pSrc, int32_t iStrideSrc,
-                 int32_t iHeight, int32_t iWidth) {
-  int32_t i;
-  int32_t iOffsetDst = 0, iOffsetSrc = 0;
-  for (i = 0; i < iHeight; i++) {
-    memcpy (pDst + iOffsetDst, pSrc + iOffsetSrc, iWidth);
-    iOffsetDst += iStrideDst;
-    iOffsetSrc += iStrideSrc;
-  }
-}
-
-
 int32_t WelsTargetMbConstruction (PWelsDecoderContext pCtx) {
   PDqLayer pCurLayer = pCtx->pCurDqLayer;
   if (MB_TYPE_INTRA_PCM == pCurLayer->pMbType[pCurLayer->iMbXyIndex]) {
-    //copy cs into fdec
-    int32_t iCsStrideL = pCurLayer->iCsStride[0];
-    int32_t iCsStrideC = pCurLayer->iCsStride[1];
-
-    int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0];
-    int32_t iDecStrideC = pCurLayer->pDec->iLinesize[1];
-
-    int32_t iCsOffsetL = (pCurLayer->iMbX + pCurLayer->iMbY * iCsStrideL) << 4;
-    int32_t iCsOffsetC = (pCurLayer->iMbX + pCurLayer->iMbY * iCsStrideC) << 3;
-
-    int32_t iDecOffsetL = (pCurLayer->iMbX + pCurLayer->iMbY * iDecStrideL) << 4;
-    int32_t iDecOffsetC = (pCurLayer->iMbX + pCurLayer->iMbY * iDecStrideC) << 3;
-
-    uint8_t* pSrcY = pCurLayer->pCsData[0] + iCsOffsetL;
-    uint8_t* pSrcU = pCurLayer->pCsData[1] + iCsOffsetC;
-    uint8_t* pSrcV = pCurLayer->pCsData[2] + iCsOffsetC;
-
-    uint8_t* pDecY = pCurLayer->pDec->pData[0] + iDecOffsetL;
-    uint8_t* pDecU = pCurLayer->pDec->pData[1] + iDecOffsetC;
-    uint8_t* pDecV = pCurLayer->pDec->pData[2] + iDecOffsetC;
-
-    WelsMbCopy (pDecY, iDecStrideL, pSrcY, iCsStrideL, 16, 16);
-    WelsMbCopy (pDecU, iDecStrideC, pSrcU, iCsStrideC, 8, 8);
-    WelsMbCopy (pDecV, iDecStrideC, pSrcV, iCsStrideC, 8, 8);
-
+    //already decoded and reconstructed when parsing
     return 0;
   } else if (IS_INTRA (pCurLayer->pMbType[pCurLayer->iMbXyIndex])) {
     WelsMbIntraPredictionConstruction (pCtx, pCurLayer, 1);
@@ -512,9 +476,9 @@
     int32_t iOffsetL = (iMbX + iMbY * iDecStrideL) << 4;
     int32_t iOffsetC = (iMbX + iMbY * iDecStrideC) << 3;
 
-    uint8_t* pDecY = pCurLayer->pCsData[0] + iOffsetL;
-    uint8_t* pDecU = pCurLayer->pCsData[1] + iOffsetC;
-    uint8_t* pDecV = pCurLayer->pCsData[2] + iOffsetC;
+    uint8_t* pDecY = pCurLayer->pDec->pData[0] + iOffsetL;
+    uint8_t* pDecU = pCurLayer->pDec->pData[1] + iOffsetC;
+    uint8_t* pDecV = pCurLayer->pDec->pData[2] + iOffsetC;
 
     uint8_t* pTmpBsBuf;
 
@@ -821,9 +785,9 @@
       int32_t iOffsetL = (iMbX + iMbY * iDecStrideL) << 4;
       int32_t iOffsetC = (iMbX + iMbY * iDecStrideC) << 3;
 
-      uint8_t* pDecY = pCurLayer->pCsData[0] + iOffsetL;
-      uint8_t* pDecU = pCurLayer->pCsData[1] + iOffsetC;
-      uint8_t* pDecV = pCurLayer->pCsData[2] + iOffsetC;
+      uint8_t* pDecY = pCurLayer->pDec->pData[0] + iOffsetL;
+      uint8_t* pDecU = pCurLayer->pDec->pData[1] + iOffsetC;
+      uint8_t* pDecV = pCurLayer->pDec->pData[2] + iOffsetC;
 
       uint8_t* pTmpBsBuf;
 
--- a/codec/decoder/core/src/decoder_core.cpp
+++ b/codec/decoder/core/src/decoder_core.cpp
@@ -903,9 +903,6 @@
 }
 
 int32_t InitialDqLayersContext (PWelsDecoderContext pCtx, const int32_t kiMaxWidth, const int32_t kiMaxHeight) {
-  const int32_t kiPicStride		= ((kiMaxWidth + 15) & 0xfffff0) + (PADDING_LENGTH << 1);
-  const int32_t kiPicLines		= ((kiMaxHeight + 15) & 0xfffff0);
-
   int32_t i = 0;
 
   WELS_VERIFY_RETURN_IF (ERR_INFO_INVALID_PARAM, (NULL == pCtx || kiMaxWidth <= 0 || kiMaxHeight <= 0))
@@ -922,35 +919,11 @@
   do {
     PDqLayer pDq = (PDqLayer)WelsMalloc (sizeof (SDqLayer), "PDqLayer");
 
-    int32_t iPlaneIdx = 0;
-
     if (pDq == NULL)
       return ERR_INFO_OUT_OF_MEMORY;
 
     memset (pDq, 0, sizeof (SDqLayer));
 
-    do {
-      const int32_t kiHshift	= iPlaneIdx ? 1 : 0;
-      const int32_t kiVshift	= kiHshift;
-      const int32_t kiStride	= WELS_ALIGN ((kiPicStride >> kiHshift), (16 << (1 - kiHshift)));
-      const int32_t kiLine	= (kiPicLines + (PADDING_LENGTH << 1)) >> kiVshift;
-      const int32_t kiSize	= kiStride * kiLine;
-
-      pCtx->pCsListXchg[i][iPlaneIdx]	= (uint8_t*)WelsMalloc (kiSize * sizeof (uint8_t), "pCtx->pCsListXchg[][]");
-
-      WELS_VERIFY_RETURN_IF (ERR_INFO_OUT_OF_MEMORY, (NULL == pCtx->pCsListXchg[i][iPlaneIdx]))
-      pCtx->iCsStride[iPlaneIdx]	= kiStride;
-
-
-      pCtx->pRsListXchg[i][iPlaneIdx]	= (int16_t*)WelsMalloc (kiSize * sizeof (int16_t), "pCtx->pRsListXchg[][]");
-
-      WELS_VERIFY_RETURN_IF (ERR_INFO_OUT_OF_MEMORY , (NULL == pCtx->pRsListXchg[i][iPlaneIdx]))
-      pCtx->iRsStride[iPlaneIdx]	= kiStride;
-
-      ++ iPlaneIdx;
-    } while (iPlaneIdx < 3);
-
-
     pCtx->sMb.pMbType[i] = (int8_t*)WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (int8_t),
                            "pCtx->sMb.pMbType[]");
     pCtx->sMb.pMv[i][0] = (int16_t (*)[16][2])WelsMalloc (pCtx->sMb.iMbWidth * pCtx->sMb.iMbHeight * sizeof (
@@ -1031,34 +1004,6 @@
       continue;
     }
 
-    if (pCtx->pCsListXchg[i]) {	// cs picture
-      j = 0;
-      do {
-        if (NULL != pCtx->pCsListXchg[i][j]) {
-          WelsFree (pCtx->pCsListXchg[i][j], "pCtx->pCsListXchg[][]");
-
-          pCtx->pCsListXchg[i][j] = NULL;
-        }
-        pCtx->iCsStride[j]	= 0;
-        ++ j;
-      } while (j < 3);
-
-      pDq->pCsData[i]		= NULL;	// for safe
-      pDq->iCsStride[i]	= 0;
-    }
-    if (pCtx->pRsListXchg[i]) {
-      j = 0;
-      do {
-        if (NULL != pCtx->pRsListXchg[i][j]) {
-          WelsFree (pCtx->pRsListXchg[i][j], "pCtx->pRsListXchg[][]");
-
-          pCtx->pRsListXchg[i][j]	= NULL;
-        }
-        pCtx->iRsStride[j]	= 0;
-        ++ j;
-      } while (j < 3);
-    }
-
     if (pCtx->sMb.pMbType[i]) {
       WelsFree (pCtx->sMb.pMbType[i], "pCtx->sMb.pMbType[]");
 
@@ -1652,13 +1597,6 @@
 
 void InitCurDqLayerData (PWelsDecoderContext pCtx, PDqLayer pCurDq) {
   if (NULL != pCtx && NULL != pCurDq) {
-    pCurDq->pCsData[0]		= pCtx->pCsListXchg[0][0];
-    pCurDq->pCsData[1]		= pCtx->pCsListXchg[0][1];
-    pCurDq->pCsData[2]		= pCtx->pCsListXchg[0][2];
-    pCurDq->iCsStride[0]	= pCtx->iCsStride[0];
-    pCurDq->iCsStride[1]	= pCtx->iCsStride[1];
-    pCurDq->iCsStride[2]	= pCtx->iCsStride[2];
-
     pCurDq->pMbType			= pCtx->sMb.pMbType[0];
     pCurDq->pSliceIdc		= pCtx->sMb.pSliceIdc[0];
     pCurDq->pMv[0]			= pCtx->sMb.pMv[0][0];
--- a/codec/decoder/core/src/rec_mb.cpp
+++ b/codec/decoder/core/src/rec_mb.cpp
@@ -104,7 +104,7 @@
 
 
 int32_t RecI4x4Chroma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) {
-  int32_t iChromaStride = pCtx->pCurDqLayer->iCsStride[1];
+  int32_t iChromaStride = pCtx->pCurDqLayer->pDec->iLinesize[1];
 
   int8_t iChromaPredMode = pDqLayer->pChromaPredMode[iMBXY];
 
@@ -128,7 +128,7 @@
   int8_t iChromaPredMode = pDqLayer->pChromaPredMode[iMBXY];
   PGetIntraPredFunc* pGetIChromaPredFunc = pCtx->pGetIChromaPredFunc;
   PGetIntraPredFunc* pGetI16x16LumaPredFunc = pCtx->pGetI16x16LumaPredFunc;
-  int32_t iUVStride = pCtx->pCurDqLayer->iCsStride[1];
+  int32_t iUVStride = pCtx->pCurDqLayer->pDec->iLinesize[1];
 
   /*common use by decoder&encoder*/
   int32_t iYStride = pDqLayer->iLumaStride;
@@ -435,7 +435,7 @@
 }
 
 int32_t RecChroma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) {
-  int32_t iChromaStride = pCtx->pCurDqLayer->iCsStride[1];
+  int32_t iChromaStride = pCtx->pCurDqLayer->pDec->iLinesize[1];
   PIdctResAddPredFunc pIdctResAddPredFunc = pCtx->pIdctResAddPredFunc;
 
   uint8_t i = 0, j = 0;