Skip to content

Commit

Permalink
Merge pull request cisco#1002 from ganyangbbl/slicectx_bugfix
Browse files Browse the repository at this point in the history
fix overflow issue caused by pCountMbNumInSlice
  • Loading branch information
huili2 committed Jun 24, 2014
2 parents 82a4bee + 43b56d9 commit bcdb911
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
35 changes: 20 additions & 15 deletions codec/encoder/core/src/encoder_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3803,6 +3803,26 @@ int32_t DynSliceRealloc (sWelsEncCtx* pCtx,
pMA->WelsFree (pCurLayer->sLayerInfo.pSliceInLayer, "Slice");
pCurLayer->sLayerInfo.pSliceInLayer = pSlice;

int16_t* pFirstMbInSlice = (int16_t*)pMA->WelsMalloc (iMaxSliceNum * sizeof (int16_t), "pSliceSeg->pFirstMbInSlice");
if (NULL == pFirstMbInSlice)
return ENC_RETURN_MEMALLOCERR;
memset(pFirstMbInSlice, 0, sizeof(int16_t) * iMaxSliceNum);
memcpy (pFirstMbInSlice, pCurLayer->pSliceEncCtx->pFirstMbInSlice, sizeof (int16_t) * iMaxSliceNumOld);
pMA->WelsFree (pCurLayer->pSliceEncCtx->pFirstMbInSlice, "pSliceSeg->pFirstMbInSlice");
pCurLayer->pSliceEncCtx->pFirstMbInSlice = pFirstMbInSlice;

int32_t* pCountMbNumInSlice = (int32_t*)pMA->WelsMalloc (iMaxSliceNum * sizeof (int32_t),"pSliceSeg->pCountMbNumInSlice");
if (NULL == pCountMbNumInSlice)
return ENC_RETURN_MEMALLOCERR;
memcpy (pCountMbNumInSlice, pCurLayer->pSliceEncCtx->pCountMbNumInSlice, sizeof (int32_t) * iMaxSliceNumOld);
uiSliceIdx = iMaxSliceNumOld;
while (uiSliceIdx < iMaxSliceNum) {
pCountMbNumInSlice[uiSliceIdx] = pCurLayer->pSliceEncCtx->iMbNumInFrame;
uiSliceIdx++;
}
pMA->WelsFree (pCurLayer->pSliceEncCtx->pCountMbNumInSlice, "pSliceSeg->pCountMbNumInSlice");
pCurLayer->pSliceEncCtx->pCountMbNumInSlice = pCountMbNumInSlice;

SRCSlicing* pSlcingOverRc = (SRCSlicing*)pMA->WelsMalloc (iMaxSliceNum * sizeof (SRCSlicing), "SlicingOverRC");
if (NULL == pSlcingOverRc)
return ENC_RETURN_MEMALLOCERR;
Expand All @@ -3824,21 +3844,6 @@ int32_t DynSliceRealloc (sWelsEncCtx* pCtx,
pMA->WelsFree (pCtx->pWelsSvcRc->pSlicingOverRc, "SlicingOverRC");
pCtx->pWelsSvcRc->pSlicingOverRc = pSlcingOverRc;

int16_t* pFirstMbInSlice = (int16_t*)pMA->WelsMalloc (iMaxSliceNum * sizeof (int16_t), "pSliceSeg->pFirstMbInSlice");
if (NULL == pFirstMbInSlice)
return ENC_RETURN_MEMALLOCERR;
memcpy (pFirstMbInSlice, pCurLayer->pSliceEncCtx->pFirstMbInSlice, sizeof (int16_t) * iMaxSliceNumOld);
pMA->WelsFree (pCurLayer->pSliceEncCtx->pFirstMbInSlice, "pSliceSeg->pFirstMbInSlice");
pCurLayer->pSliceEncCtx->pFirstMbInSlice = pFirstMbInSlice;

int32_t* pCountMbNumInSlice = (int32_t*)pMA->WelsMalloc (iMaxSliceNum * sizeof (int32_t),
"pSliceSeg->pCountMbNumInSlice");
if (NULL == pCountMbNumInSlice)
return ENC_RETURN_MEMALLOCERR;
memcpy (pCountMbNumInSlice, pCurLayer->pSliceEncCtx->pCountMbNumInSlice, sizeof (int32_t) * iMaxSliceNumOld);
pMA->WelsFree (pCurLayer->pSliceEncCtx->pCountMbNumInSlice, "pSliceSeg->pCountMbNumInSlice");
pCurLayer->pSliceEncCtx->pCountMbNumInSlice = pCountMbNumInSlice;

if (pCtx->iMaxSliceCount < iMaxSliceNum)
pCtx->iMaxSliceCount = iMaxSliceNum;
pCurLayer->pSliceEncCtx->iMaxSliceNumConstraint = iMaxSliceNum;
Expand Down
8 changes: 8 additions & 0 deletions codec/encoder/core/src/svc_enc_slice_segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ int32_t AssignMbMapMultipleSlices (SSliceCtx* pSliceSeg, const SSliceConfig* kpM
++ iSliceIdx;
} while (iSliceIdx < kiCountSliceNumInFrame && iMbIdx < kiCountNumMbInFrame);
} else if (SM_DYN_SLICE == pSliceSeg->uiSliceMode) {
int32_t iSliceIdx = 0;
const int32_t kiMaxSliceNum = pSliceSeg->iMaxSliceNumConstraint;
const int32_t kiCountNumMbInFrame = pSliceSeg->iMbNumInFrame;
do {
pSliceSeg->pFirstMbInSlice[iSliceIdx] = 0;
pSliceSeg->pCountMbNumInSlice[iSliceIdx] = kiCountNumMbInFrame;
iSliceIdx++;
} while (iSliceIdx < kiMaxSliceNum);
} else { // any else uiSliceMode?
assert (0);
}
Expand Down

0 comments on commit bcdb911

Please sign in to comment.