Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
Fix hang caused by OUT_ALLOC and remove macro (#523)
Browse files Browse the repository at this point in the history
1. The reason of hang caused by OUT_ALLOC is lack of available output stream buffer.
   The fix is to seperate the outputBufferFifoInitCount from inputOutputBufferFifoInitCount.
   And increase its size.
2. Clean up the OUT_ALLOC macro.

Signed-off-by: Jun Tian <jun.tian@intel.com>
  • Loading branch information
tianjunwork authored Apr 17, 2020
1 parent b58df36 commit cb1d6a9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 34 deletions.
1 change: 0 additions & 1 deletion Source/Lib/Codec/EbDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ extern "C" {
#endif

#define PAREF_OUT 1 // Disconnect pa ref from input for both single/multi core
#define OUT_ALLOC 0 // Output bitsream allocation at run time for both single/multi core

//#define BENCHMARK 0
#define LATENCY_PROFILE 0
Expand Down
22 changes: 7 additions & 15 deletions Source/Lib/Codec/EbEncHandle.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@
#define EB_PacketizationProcessInitCount 1

// Buffer Transfer Parameters
#define EB_INPUTVIDEOBUFFERSIZE 0x10000// 832*480*3// // Input Slice Size , must me a multiple of 2 in case of 10 bit video.
#define EB_OUTPUTSTREAMBUFFERSIZE 0x2DC6C0 //0x7D00 // match MTU Size
#define EB_OUTPUTRECONBUFFERSIZE (MAX_PICTURE_WIDTH_SIZE*MAX_PICTURE_HEIGHT_SIZE*2) // Recon Slice Size
#define EB_OUTPUTSTREAMQUANT 27
#define EB_OUTPUTSTATISTICSBUFFERSIZE 0x30 // 6X8 (8 Bytes for Y, U, V, number of bits, picture number, QP)
#define EB_OUTPUTBUFFERCOUNT 5000
#define EB_OUTPUTSTREAMBUFFERSIZE_MACRO(ResolutionSize) ((ResolutionSize) < (INPUT_SIZE_1080i_TH) ? 0x1E8480 : (ResolutionSize) < (INPUT_SIZE_1080p_TH) ? 0x2DC6C0 : (ResolutionSize) < (INPUT_SIZE_4K_TH) ? 0x2DC6C0 : (ResolutionSize) < (INPUT_SIZE_8K_TH) ? 0x2DC6C0:0x5B8D80)

static EB_U64 maxLumaPictureSize[TOTAL_LEVEL_COUNT] = { 36864U, 122880U, 245760U, 552960U, 983040U, 2228224U, 2228224U, 8912896U, 8912896U, 8912896U, 35651584U, 35651584U, 35651584U };
Expand Down Expand Up @@ -952,7 +948,7 @@ EB_API EB_ERRORTYPE EbInitEncoder(EB_COMPONENTTYPE *h265EncComponent)
EB_NEW(
encHandlePtr->inputBufferResourcePtr,
EbSystemResourceCtor,
encHandlePtr->sequenceControlSetInstanceArray[0]->sequenceControlSetPtr->inputOutputBufferFifoInitCount,
encHandlePtr->sequenceControlSetInstanceArray[0]->sequenceControlSetPtr->inputBufferFifoInitCount,
1,
EB_ResourceCoordinationProcessInitCount,
&encHandlePtr->inputBufferProducerFifoPtrArray,
Expand All @@ -971,7 +967,7 @@ EB_API EB_ERRORTYPE EbInitEncoder(EB_COMPONENTTYPE *h265EncComponent)
EB_NEW(
encHandlePtr->outputStreamBufferResourcePtrArray[instanceIndex],
EbSystemResourceCtor,
encHandlePtr->sequenceControlSetInstanceArray[instanceIndex]->sequenceControlSetPtr->inputOutputBufferFifoInitCount + 4, // to accommodate output error + vps + eos
encHandlePtr->sequenceControlSetInstanceArray[instanceIndex]->sequenceControlSetPtr->outputBufferFifoInitCount,
encHandlePtr->sequenceControlSetInstanceArray[instanceIndex]->sequenceControlSetPtr->totalProcessInitCount,// EB_PacketizationProcessInitCount,
1,
&encHandlePtr->outputStreamBufferProducerFifoPtrDblArray[instanceIndex],
Expand Down Expand Up @@ -1733,7 +1729,8 @@ void LoadDefaultBufferConfigurationSettings(
}
threadUnit = totalThreadCount / EB_THREAD_COUNT_MIN_CORE;

sequenceControlSetPtr->inputOutputBufferFifoInitCount = inputPic + SCD_LAD;
sequenceControlSetPtr->inputBufferFifoInitCount = inputPic + SCD_LAD;
sequenceControlSetPtr->outputBufferFifoInitCount = EB_OUTPUTBUFFERCOUNT;

// ME segments
sequenceControlSetPtr->meSegmentRowCountArray[0] = meSegH;
Expand Down Expand Up @@ -1792,7 +1789,7 @@ void LoadDefaultBufferConfigurationSettings(
sequenceControlSetPtr->pictureControlSetPoolInitCount = inputPic;

sequenceControlSetPtr->pictureControlSetPoolInitCountChild = MAX(4, coreCount / 6);
sequenceControlSetPtr->referencePictureBufferInitCount = inputPic;//MAX((EB_U32)(sequenceControlSetPtr->inputOutputBufferFifoInitCount >> 1), (EB_U32)((1 << sequenceControlSetPtr->staticConfig.hierarchicalLevels) + 2));
sequenceControlSetPtr->referencePictureBufferInitCount = inputPic;//MAX((EB_U32)(sequenceControlSetPtr->inputBufferFifoInitCount >> 1), (EB_U32)((1 << sequenceControlSetPtr->staticConfig.hierarchicalLevels) + 2));

if (inputResolution <= INPUT_SIZE_1080p_RANGE)
sequenceControlSetPtr->paReferencePictureBufferInitCount = inputPic * lowResInputFactor;
Expand Down Expand Up @@ -3718,12 +3715,10 @@ __attribute__((visibility("default")))
EB_API void EbH265ReleaseOutBuffer(
EB_BUFFERHEADERTYPE **pBuffer)
{
#if OUT_ALLOC
if ((*pBuffer)->pBuffer) {
free((*pBuffer)->pBuffer);
(*pBuffer)->pBuffer = EB_NULL;
}
#endif

if ((*pBuffer)->wrapperPtr)
// Release out put buffer back into the pool
Expand Down Expand Up @@ -3958,10 +3953,8 @@ EB_ERRORTYPE EbOutputBufferHeaderCreator(
}

// Initialize Header
// pBuffer is allocated in PK
outBufPtr->nSize = sizeof(EB_BUFFERHEADERTYPE);
#if !OUT_ALLOC
EB_MALLOC(outBufPtr->pBuffer, nStride);
#endif
outBufPtr->nAllocLen = nStride;

return EB_ErrorNone;
Expand All @@ -3970,7 +3963,6 @@ EB_ERRORTYPE EbOutputBufferHeaderCreator(
void EbOutputBufferHeaderDestroyer(EB_PTR p)
{
EB_BUFFERHEADERTYPE* obj = (EB_BUFFERHEADERTYPE*)p;
EB_FREE(obj->pBuffer);
EB_FREE(obj);
}

Expand Down
11 changes: 0 additions & 11 deletions Source/Lib/Codec/EbInitialRateControlProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -866,9 +866,6 @@ void* InitialRateControlKernel(void *inputPtr)
EB_U8 temporalLayerIndex;
EbObjectWrapper_t *referencePictureWrapperPtr;

#if !OUT_ALLOC
EbObjectWrapper_t *outputStreamWrapperPtr;
#endif

for (;;) {

Expand Down Expand Up @@ -1071,14 +1068,6 @@ void* InitialRateControlKernel(void *inputPtr)
1);
//OPTION 1: get the buffer in resource coordination

#if !OUT_ALLOC
EbGetEmptyObject(
sequenceControlSetPtr->encodeContextPtr->streamOutputFifoPtr,
&outputStreamWrapperPtr);

pictureControlSetPtr->outputStreamWrapperPtr = outputStreamWrapperPtr;
#endif

// Get Empty Results Object
EbGetEmptyObject(
contextPtr->initialrateControlResultsOutputFifoPtr,
Expand Down
6 changes: 0 additions & 6 deletions Source/Lib/Codec/EbPacketizationProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,13 @@ void* PacketizationKernel(void *inputPtr)
queueEntryPtr->sliceType = pictureControlSetPtr->sliceType;
queueEntryPtr->pictureNumber = pictureControlSetPtr->pictureNumber;

#if OUT_ALLOC
EbGetEmptyObject(sequenceControlSetPtr->encodeContextPtr->streamOutputFifoPtr,
&pictureControlSetPtr->ParentPcsPtr->outputStreamWrapperPtr);
outputStreamWrapperPtr = pictureControlSetPtr->ParentPcsPtr->outputStreamWrapperPtr;
outputStreamPtr = (EB_BUFFERHEADERTYPE*) outputStreamWrapperPtr->objectPtr;
// Not use EB_MALLOC due to lacking of EB_FREE which needs to parse all the memoryMap entries.
outputStreamPtr->pBuffer = (EB_U8 *)malloc(outputStreamPtr->nAllocLen);
assert(outputStreamPtr->pBuffer != EB_NULL && "bit-stream memory allocation failure");
#else
// Get Output Bitstream buffer
outputStreamWrapperPtr = pictureControlSetPtr->ParentPcsPtr->outputStreamWrapperPtr;
outputStreamPtr = (EB_BUFFERHEADERTYPE*) outputStreamWrapperPtr->objectPtr;
#endif

outputStreamPtr->nFlags = 0;
EbBlockOnMutex(encodeContextPtr->terminatingConditionsMutex);
Expand Down
3 changes: 2 additions & 1 deletion Source/Lib/Codec/EbSequenceControlSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ typedef struct SequenceControlSet_s
EB_U32 paReferencePictureBufferInitCount;
EB_U32 referencePictureBufferInitCount;
EB_U32 reconBufferFifoInitCount;
EB_U32 inputOutputBufferFifoInitCount;
EB_U32 inputBufferFifoInitCount;
EB_U32 outputBufferFifoInitCount;
EB_U32 resourceCoordinationFifoInitCount;
EB_U32 pictureAnalysisFifoInitCount;
EB_U32 pictureDecisionFifoInitCount;
Expand Down

0 comments on commit cb1d6a9

Please sign in to comment.