History

Merge pull request #916 from huili2/dynamic_dec_au_size

enable dynamic AU size in decoder

HaiboZhu committed 12 years ago

Commit 08377f32 parents a46b1aa bed18c25 files · +81 −14Browse files

Showing the changes to codec/decoder/core/src/decoder_core.cpp (1 of 5 files). Show all

Unified · Split

codec/decoder/core/src/decoder_core.cpp+52−6
@@ -297,6 +297,57 @@ bool FillDefaultSliceHeaderExt (PSliceHeaderExt pShExt, PNalUnitHeaderExt pNalEx · 296 unmodified lines
297297 return true;
298298 }
299299
300+int32_t InitBsBuffer (PWelsDecoderContext pCtx) {
301+ if (pCtx == NULL)
302+ return ERR_INFO_INVALID_PTR;
303+
304+ pCtx->iMaxBsBufferSizeInByte = MIN_ACCESS_UNIT_CAPACITY * MAX_BUFFERED_NUM;
305+ if ((pCtx->sRawData.pHead = static_cast<uint8_t*> (WelsMalloc (pCtx->iMaxBsBufferSizeInByte,
306+ "pCtx->sRawData.pHead"))) == NULL) {
307+ return ERR_INFO_OUT_OF_MEMORY;
308+ }
309+ pCtx->sRawData.pStartPos = pCtx->sRawData.pCurPos = pCtx->sRawData.pHead;
310+ pCtx->sRawData.pEnd = pCtx->sRawData.pHead + pCtx->iMaxBsBufferSizeInByte;
311+ return ERR_NONE;
312+}
313+
314+int32_t ExpandBsBuffer (PWelsDecoderContext pCtx, const int kiSrcLen) {
315+ if (pCtx == NULL)
316+ return ERR_INFO_INVALID_PTR;
317+ int32_t iExpandStepShift = 1;
318+ int32_t iNewBuffLen = WELS_MAX ((kiSrcLen * MAX_BUFFERED_NUM), (pCtx->iMaxBsBufferSizeInByte << iExpandStepShift));
319+ //allocate new bs buffer
320+ uint8_t* pNewBsBuff = static_cast<uint8_t*> (WelsMalloc (iNewBuffLen, "pCtx->sRawData.pHead"));
321+ if (pNewBsBuff == NULL)
322+ return ERR_INFO_OUT_OF_MEMORY;
323+
324+ //Copy current buffer status to new buffer
325+ memcpy (pNewBsBuff, pCtx->sRawData.pHead, pCtx->iMaxBsBufferSizeInByte);
326+ pCtx->iMaxBsBufferSizeInByte = iNewBuffLen;
327+ pCtx->sRawData.pStartPos = pNewBsBuff + (pCtx->sRawData.pStartPos - pCtx->sRawData.pHead);
328+ pCtx->sRawData.pCurPos = pNewBsBuff + (pCtx->sRawData.pCurPos - pCtx->sRawData.pHead);
329+ pCtx->sRawData.pEnd = pNewBsBuff + iNewBuffLen;
330+ WelsFree (pCtx->sRawData.pHead, "pCtx->sRawData.pHead");
331+ pCtx->sRawData.pHead = pNewBsBuff;
332+ return ERR_NONE;
333+}
334+
335+int32_t CheckBsBuffer (PWelsDecoderContext pCtx, const int32_t kiSrcLen) {
336+ if (kiSrcLen > MAX_ACCESS_UNIT_CAPACITY) { //exceeds max allowed data
337+ WelsLog (pCtx, WELS_LOG_WARNING, "Max AU size exceeded. Allowed size = %d, current size = %d", MAX_ACCESS_UNIT_CAPACITY,
338+ kiSrcLen);
339+ pCtx->iErrorCode |= dsBitstreamError;
340+ return ERR_INFO_INVALID_ACCESS;
341+ } else if (kiSrcLen > pCtx->iMaxBsBufferSizeInByte /
342+ MAX_BUFFERED_NUM) { //may lead to buffer overwrite, prevent it by expanding buffer
343+ if (ExpandBsBuffer (pCtx, kiSrcLen)) {
344+ return ERR_INFO_OUT_OF_MEMORY;
345+ }
346+ }
347+
348+ return ERR_NONE;
349+}
350+
300351 /*
301352 * WelsInitMemory
302353 * Memory request for new introduced data
@@ -313,13 +364,8 @@ int32_t WelsInitMemory (PWelsDecoderContext pCtx) { · 10 unmodified lines
313364 if (MemInitNalList (&pCtx->pAccessUnitList, MAX_NAL_UNIT_NUM_IN_AU) != 0)
314365 return ERR_INFO_OUT_OF_MEMORY;
315366
316− if ((pCtx->sRawData.pHead = static_cast<uint8_t*> (WelsMalloc (BS_BUFFER_SIZE,
317− "pCtx->sRawData->pHead"))) == NULL) {
367+ if (InitBsBuffer (pCtx) != 0)
318368 return ERR_INFO_OUT_OF_MEMORY;
319− }
320− pCtx->sRawData.pStartPos =
321− pCtx->sRawData.pCurPos = pCtx->sRawData.pHead;
322− pCtx->sRawData.pEnd = pCtx->sRawData.pHead + BS_BUFFER_SIZE;
323369
324370 pCtx->uiTargetDqId = (uint8_t) - 1;
325371 pCtx->bEndOfStreamFlag = false;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t