Skip to content

Commit

Permalink
Fix a thread buffering bug: a few yuv frames at output can be dropped…
Browse files Browse the repository at this point in the history
… due to unexpected pDst reset. This is resolved by moving pDst into SBufferInfo data structure.
  • Loading branch information
xiaotiansf committed Nov 20, 2019
1 parent 861596a commit bbcc2cb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
1 change: 1 addition & 0 deletions codec/api/svc/codec_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ typedef struct TagBufferInfo {
union {
SSysMEMBuffer sSystemBuffer; ///< memory info for one picture
} UsrData; ///< output buffer info
unsigned char* pDst[3]; //point to picture YUV data
} SBufferInfo;


Expand Down
18 changes: 9 additions & 9 deletions codec/console/dec/src/h264dec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ void FlushFrames (ISVCDecoder* pDecoder, int64_t& iTotal, FILE* pYuvFile, FILE*
sDstBufInfo.iBufferStatus = 1;
pDecoder->FlushFrame (pData, &sDstBufInfo);
if (sDstBufInfo.iBufferStatus == 1) {
pDst[0] = pData[0];
pDst[1] = pData[1];
pDst[2] = pData[2];
pDst[0] = sDstBufInfo.pDst[0];
pDst[1] = sDstBufInfo.pDst[1];
pDst[2] = sDstBufInfo.pDst[2];
}
int64_t iEnd = WelsTime();
iTotal += iEnd - iStart;
Expand Down Expand Up @@ -346,9 +346,9 @@ void H264DecodeInstance (ISVCDecoder* pDecoder, const char* kpH264FileName, cons
}

if (sDstBufInfo.iBufferStatus == 1) {
pDst[0] = pData[0];
pDst[1] = pData[1];
pDst[2] = pData[2];
pDst[0] = sDstBufInfo.pDst[0];
pDst[1] = sDstBufInfo.pDst[1];
pDst[2] = sDstBufInfo.pDst[2];
}
iEnd = WelsTime();
iTotal += iEnd - iStart;
Expand Down Expand Up @@ -378,9 +378,9 @@ void H264DecodeInstance (ISVCDecoder* pDecoder, const char* kpH264FileName, cons
sDstBufInfo.uiInBsTimeStamp = uiTimeStamp;
pDecoder->DecodeFrame2 (NULL, 0, pData, &sDstBufInfo);
if (sDstBufInfo.iBufferStatus == 1) {
pDst[0] = pData[0];
pDst[1] = pData[1];
pDst[2] = pData[2];
pDst[0] = sDstBufInfo.pDst[0];
pDst[1] = sDstBufInfo.pDst[1];
pDst[2] = sDstBufInfo.pDst[2];
}
iEnd = WelsTime();
iTotal += iEnd - iStart;
Expand Down
1 change: 0 additions & 1 deletion codec/decoder/core/inc/decoder_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ typedef struct tagPictInfo {
int32_t iPicBuffIdx;
uint32_t uiDecodingTimeStamp;
bool bLastGOP;
unsigned char* pData[3];
} SPictInfo, *PPictInfo;

typedef struct tagPictReoderingStatus {
Expand Down
3 changes: 3 additions & 0 deletions codec/decoder/core/src/decoder_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ static inline int32_t DecodeFrameConstruction (PWelsDecoderContext pCtx, uint8_t
ppDst[0] = ppDst[0] + pCtx->sFrameCrop.iTopOffset * 2 * pPic->iLinesize[0] + pCtx->sFrameCrop.iLeftOffset * 2;
ppDst[1] = ppDst[1] + pCtx->sFrameCrop.iTopOffset * pPic->iLinesize[1] + pCtx->sFrameCrop.iLeftOffset;
ppDst[2] = ppDst[2] + pCtx->sFrameCrop.iTopOffset * pPic->iLinesize[1] + pCtx->sFrameCrop.iLeftOffset;
for (int i = 0; i < 3; ++i) {
pDstInfo->pDst[i] = ppDst[i];
}
pDstInfo->iBufferStatus = 1;
if (GetThreadCount (pCtx) > 1 && pPic->bIsComplete == false) {
pPic->bIsComplete = true;
Expand Down
27 changes: 12 additions & 15 deletions codec/decoder/plus/src/welsDecoderExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,9 +944,9 @@ DECODING_STATE CWelsDecoder::FlushFrame (unsigned char** ppDst,
#endif
#endif
memcpy (pDstInfo, &m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].sBufferInfo, sizeof (SBufferInfo));
ppDst[0] = m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].pData[0];
ppDst[1] = m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].pData[1];
ppDst[2] = m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].pData[2];
ppDst[0] = pDstInfo->pDst[0];
ppDst[1] = pDstInfo->pDst[1];
ppDst[2] = pDstInfo->pDst[2];
m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].iPOC = IMinInt32;
PPicBuff pPicBuff = m_iThreadCount <= 1 ? m_pDecThrCtx[0].pCtx->pPicBuff : m_pPicBuff;
if (m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].iPicBuffIdx < pPicBuff->iCapacity) {
Expand Down Expand Up @@ -1046,9 +1046,6 @@ void CWelsDecoder::BufferingReadyPicture (PWelsDecoderContext pCtx, unsigned cha
for (int32_t i = 0; i < 16; ++i) {
if (m_sPictInfoList[i].iPOC == IMinInt32) {
memcpy (&m_sPictInfoList[i].sBufferInfo, pDstInfo, sizeof (SBufferInfo));
m_sPictInfoList[i].pData[0] = ppDst[0];
m_sPictInfoList[i].pData[1] = ppDst[1];
m_sPictInfoList[i].pData[2] = ppDst[2];
m_sPictInfoList[i].iPOC = pCtx->pSliceHeader->iPicOrderCntLsb;
m_sPictInfoList[i].uiDecodingTimeStamp = pCtx->uiDecodingTimeStamp;
m_sPictInfoList[i].iPicBuffIdx = pCtx->pLastDecPicInfo->pPreviousDecodedPictureInDpb->iPicBuffIdx;
Expand Down Expand Up @@ -1090,9 +1087,9 @@ void CWelsDecoder::ReleaseBufferedReadyPicture (PWelsDecoderContext pCtx, unsign
#endif
#endif
memcpy (pDstInfo, &m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].sBufferInfo, sizeof (SBufferInfo));
ppDst[0] = m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].pData[0];
ppDst[1] = m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].pData[1];
ppDst[2] = m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].pData[2];
ppDst[0] = pDstInfo->pDst[0];
ppDst[1] = pDstInfo->pDst[1];
ppDst[2] = pDstInfo->pDst[2];
m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].iPOC = IMinInt32;
PPicture pPic = pPicBuff->ppPic[m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].iPicBuffIdx];
--pPic->iRefCount;
Expand Down Expand Up @@ -1123,9 +1120,9 @@ void CWelsDecoder::ReleaseBufferedReadyPicture (PWelsDecoderContext pCtx, unsign
}
if (uiDecodingTimeStamp > 0) {
memcpy (pDstInfo, &m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].sBufferInfo, sizeof (SBufferInfo));
ppDst[0] = m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].pData[0];
ppDst[1] = m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].pData[1];
ppDst[2] = m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].pData[2];
ppDst[0] = pDstInfo->pDst[0];
ppDst[1] = pDstInfo->pDst[1];
ppDst[2] = pDstInfo->pDst[2];
m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].iPOC = IMinInt32;
PPicture pPic = pPicBuff->ppPic[m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].iPicBuffIdx];
--pPic->iRefCount;
Expand Down Expand Up @@ -1164,9 +1161,9 @@ void CWelsDecoder::ReleaseBufferedReadyPicture (PWelsDecoderContext pCtx, unsign
#endif
#endif
memcpy (pDstInfo, &m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].sBufferInfo, sizeof (SBufferInfo));
ppDst[0] = m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].pData[0];
ppDst[1] = m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].pData[1];
ppDst[2] = m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].pData[2];
ppDst[0] = pDstInfo->pDst[0];
ppDst[1] = pDstInfo->pDst[1];
ppDst[2] = pDstInfo->pDst[2];
m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].iPOC = IMinInt32;
PPicture pPic = pPicBuff->ppPic[m_sPictInfoList[m_sReoderingStatus.iPictInfoIndex].iPicBuffIdx];
--pPic->iRefCount;
Expand Down

0 comments on commit bbcc2cb

Please sign in to comment.