diff options
author | Dan Liang <dan.liang@intel.com> | 2013-06-18 13:21:37 +0800 |
---|---|---|
committer | Patrick Tjin <pattjin@google.com> | 2014-07-21 22:02:52 -0700 |
commit | 1d9a6eea6f268090d01bd36b88d912b265170ea5 (patch) | |
tree | 1e2205710ec7d970403ea97ee83ba058d3afd3c3 | |
parent | ed2fa14d0407f291a7fd97ef3440e57052e97a58 (diff) | |
download | android_hardware_intel_common_omx-components-1d9a6eea6f268090d01bd36b88d912b265170ea5.tar.gz android_hardware_intel_common_omx-components-1d9a6eea6f268090d01bd36b88d912b265170ea5.tar.bz2 android_hardware_intel_common_omx-components-1d9a6eea6f268090d01bd36b88d912b265170ea5.zip |
omx-component: add output port buffer reallocation via port settings change
BZ: 116761
Change-Id: Id65409de429d0dd0ae7827b23a3466c68e3a407d
Signed-off-by: Dan Liang <dan.liang@intel.com>
Reviewed-on: http://android.intel.com:8080/114225
Reviewed-by: Feng, Wei <wei.feng@intel.com>
Reviewed-by: Shi, PingX <pingx.shi@intel.com>
Tested-by: Shi, PingX <pingx.shi@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
-rw-r--r-- | videocodec/OMXVideoDecoderAVC.cpp | 64 | ||||
-rw-r--r-- | videocodec/OMXVideoDecoderAVC.h | 6 | ||||
-rw-r--r--[-rwxr-xr-x] | videocodec/OMXVideoDecoderBase.cpp | 37 | ||||
-rw-r--r--[-rwxr-xr-x] | videocodec/OMXVideoDecoderBase.h | 4 | ||||
-rw-r--r-- | videocodec/securevideo/ctp/OMXVideoDecoderAVCSecure.h | 3 | ||||
-rw-r--r-- | videocodec/securevideo/merrifield/OMXVideoDecoderAVCSecure.h | 3 |
6 files changed, 45 insertions, 72 deletions
diff --git a/videocodec/OMXVideoDecoderAVC.cpp b/videocodec/OMXVideoDecoderAVC.cpp index 1a1afd6..8dffab0 100644 --- a/videocodec/OMXVideoDecoderAVC.cpp +++ b/videocodec/OMXVideoDecoderAVC.cpp @@ -255,7 +255,6 @@ OMX_ERRORTYPE OMXVideoDecoderAVC::SetParamVideoAvc(OMX_PTR pStructure) { // TODO: see SetPortAvcParam implementation - Can we make simple copy???? memcpy(&mParamAvc, p, sizeof(mParamAvc)); - CalculateBufferCount(); return OMX_ErrorNone; } @@ -312,67 +311,4 @@ OMX_ERRORTYPE OMXVideoDecoderAVC::SetParamVideoAVCProfileLevel(OMX_PTR pStructur return OMX_ErrorUnsupportedSetting; } -void OMXVideoDecoderAVC::CalculateBufferCount() { - - OMX_U32 dpbSize = 0; - OMX_U32 width = this->ports[OUTPORT_INDEX]->GetPortDefinition()->format.video.nFrameWidth; - OMX_U32 height = this->ports[OUTPORT_INDEX]->GetPortDefinition()->format.video.nFrameHeight; - - dpbSize = GetDPBSize(mParamAvc.eLevel, width, height); - mNativeBufferCount = ((dpbSize > 8) ? dpbSize : 8) + 1 + 8; -} - -OMX_U32 OMXVideoDecoderAVC::GetDPBSize(OMX_U32 level, OMX_U32 picWidth, OMX_U32 picHeight) { - - OMX_U32 widthInMbs = (picWidth + 15) / 16; - OMX_U32 heightInMbs = (picHeight + 15) / 16; - - // 1024 * MaxDPB / ( PicWidthInMbs * FrameHeightInMbs * 384 ), 16 - struct DPBTable { - OMX_U32 level; - float maxDPB; - } dpbTable[] = { - {9, 148.5}, - {10, 148.5}, - {11, 337.5}, - {12, 891.0}, - {13, 891.0}, - {20, 891.0}, - {21, 1782.0}, - {22, 3037.5}, - {30, 3037.5}, - {31, 6750.0}, - {32, 7680.0}, - {40, 12288.0}, - {41, 12288.0}, - {42, 13056.0}, - {50, 41400.0}, - {51, 69120.0} - }; - - OMX_U32 count = sizeof(dpbTable)/sizeof(DPBTable); - float maxDPB = 0; - for (OMX_U32 i = 0; i < count; i++) - { - if (dpbTable[i].level == level) { - maxDPB = dpbTable[i].maxDPB; - break; - } - } - - // HW only supports up to L4.2, set limit here - // will move this part to OMX IL later - if (level > 42) maxDPB = 13056.0; - - OMX_U32 maxDPBSize = maxDPB * 1024 / ( - widthInMbs * heightInMbs * 384); - - if (maxDPBSize > 16) { - maxDPBSize = 16; - } else if (maxDPBSize == 0) { - maxDPBSize = 3; - } - return maxDPBSize; -} - DECLARE_OMX_COMPONENT("OMX.Intel.VideoDecoder.AVC", "video_decoder.avc", OMXVideoDecoderAVC); diff --git a/videocodec/OMXVideoDecoderAVC.h b/videocodec/OMXVideoDecoderAVC.h index a2dde19..77b1a47 100644 --- a/videocodec/OMXVideoDecoderAVC.h +++ b/videocodec/OMXVideoDecoderAVC.h @@ -46,8 +46,6 @@ protected: private: inline OMX_ERRORTYPE AccumulateBuffer(OMX_BUFFERHEADERTYPE *buffer); inline OMX_ERRORTYPE FillDecodeBuffer(VideoDecodeBuffer *p); - OMX_U32 GetDPBSize(OMX_U32 level, OMX_U32 picWidth, OMX_U32 picHeight); - void CalculateBufferCount(); private: enum { @@ -64,8 +62,8 @@ private: // total number of reference frame allocated by default in video conferencing use case is 10. EXTRA_REFERENCE_FRAME = 6, - // max DBP + EXTRA_REFERENCE_FRAME + 1 - OUTPORT_NATIVE_BUFFER_COUNT = 23, + // a typical value for 1080p clips + OUTPORT_NATIVE_BUFFER_COUNT = 17, }; OMX_VIDEO_PARAM_AVCTYPE mParamAvc; diff --git a/videocodec/OMXVideoDecoderBase.cpp b/videocodec/OMXVideoDecoderBase.cpp index 1a83e29..92cf39a 100755..100644 --- a/videocodec/OMXVideoDecoderBase.cpp +++ b/videocodec/OMXVideoDecoderBase.cpp @@ -31,10 +31,17 @@ OMXVideoDecoderBase::OMXVideoDecoderBase() mRotationDegrees(0), mWorkingMode(RAWDATA_MODE) { memset(&mGraphicBufferParam, 0, sizeof(mGraphicBufferParam)); + pthread_mutex_init(&mOMXBufferArray_lock, NULL); + pthread_cond_init(&mOMXBufferArray_cond, NULL); + mSetNativeBuffer_completion = false; } OMXVideoDecoderBase::~OMXVideoDecoderBase() { releaseVideoDecoder(mVideoDecoder); + + pthread_mutex_destroy(&mOMXBufferArray_lock); + pthread_cond_destroy(&mOMXBufferArray_cond); + if (this->ports) { if (this->ports[INPORT_INDEX]) { delete this->ports[INPORT_INDEX]; @@ -196,10 +203,14 @@ OMX_ERRORTYPE OMXVideoDecoderBase::ProcessorInit(void) { OMX_ERRORTYPE OMXVideoDecoderBase::ProcessorReset(void) { OMX_ERRORTYPE ret; VideoConfigBuffer configBuffer; + pthread_mutex_lock(&mOMXBufferArray_lock); + if (!mSetNativeBuffer_completion) + pthread_cond_wait(&mOMXBufferArray_cond, &mOMXBufferArray_lock); // reset the configbuffer and set it to mix ret = PrepareConfigBuffer(&configBuffer); CHECK_RETURN_VALUE("PrepareConfigBuffer"); mVideoDecoder->reset(&configBuffer); + pthread_mutex_unlock(&mOMXBufferArray_lock); return OMX_ErrorNone; } @@ -570,13 +581,26 @@ OMX_ERRORTYPE OMXVideoDecoderBase::HandleFormatChange(void) { int heightCropped = formatInfo->height - formatInfo->cropTop - formatInfo->cropBottom; int strideCropped = widthCropped; int sliceHeightCropped = heightCropped; + int force_realloc = 0; + + if (paramPortDefinitionOutput.nBufferCountActual < formatInfo->actualBufferNeeded) { + if (mWorkingMode == GRAPHICBUFFER_MODE) { + LOGV("output port buffer number is not enough: %d to %d", + paramPortDefinitionOutput.nBufferCountActual, + formatInfo->actualBufferNeeded); + paramPortDefinitionOutput.nBufferCountActual = mNativeBufferCount = formatInfo->actualBufferNeeded; + force_realloc = 1; + mSetNativeBuffer_completion = false; + } + } LOGV("Original size = %lu x %lu, new size = %d x %d, cropped size = %d x %d", paramPortDefinitionInput.format.video.nFrameWidth, paramPortDefinitionInput.format.video.nFrameHeight, width, height, widthCropped, heightCropped); - if (widthCropped == paramPortDefinitionOutput.format.video.nFrameWidth && + if (!force_realloc && + widthCropped == paramPortDefinitionOutput.format.video.nFrameWidth && heightCropped == paramPortDefinitionOutput.format.video.nFrameHeight) { if (mWorkingMode == GRAPHICBUFFER_MODE) { if (width <= formatInfo->surfaceWidth && @@ -603,7 +627,7 @@ OMX_ERRORTYPE OMXVideoDecoderBase::HandleFormatChange(void) { } else if (mWorkingMode == GRAPHICBUFFER_MODE) { // when the width and height ES parse are not larger than allocated graphic buffer in outport, // there is no need to reallocate graphic buffer,just report the crop info to omx client - if (width <= formatInfo->surfaceWidth && height <= formatInfo->surfaceHeight) { + if (!force_realloc && width <= formatInfo->surfaceWidth && height <= formatInfo->surfaceHeight) { this->ports[INPORT_INDEX]->SetPortDefinition(¶mPortDefinitionInput, true); this->ports[OUTPORT_INDEX]->ReportOutputCrop(); return OMX_ErrorNone; @@ -741,6 +765,7 @@ OMX_ERRORTYPE OMXVideoDecoderBase::SetNativeBuffer(OMX_PTR pStructure) { if (param->nPortIndex != OUTPORT_INDEX) return OMX_ErrorBadParameter; OMX_BUFFERHEADERTYPE *buf_hdr = NULL; + ret = this->ports[OUTPORT_INDEX]->UseBuffer(&buf_hdr, OUTPORT_INDEX, param->pAppPrivate, sizeof(OMX_U8*), const_cast<OMX_U8*>(reinterpret_cast<const OMX_U8*>(param->nativeBuffer->handle))); if (ret != OMX_ErrorNone) @@ -753,8 +778,16 @@ OMX_ERRORTYPE OMXVideoDecoderBase::SetNativeBuffer(OMX_PTR pStructure) { mGraphicBufferParam.graphicBufferWidth = param->nativeBuffer->width; mGraphicBufferParam.graphicBufferHeight = param->nativeBuffer->height; } + + pthread_mutex_lock(&mOMXBufferArray_lock); mOMXBufferHeaderTypePtrArray[mOMXBufferHeaderTypePtrNum++] = buf_hdr; *(param->bufferHeader) = buf_hdr; + if (mNativeBufferCount == mOMXBufferHeaderTypePtrNum) { + mSetNativeBuffer_completion = true; + pthread_cond_signal(&mOMXBufferArray_cond); + } + + pthread_mutex_unlock(&mOMXBufferArray_lock); return OMX_ErrorNone; } diff --git a/videocodec/OMXVideoDecoderBase.h b/videocodec/OMXVideoDecoderBase.h index 51828f6..55021da 100755..100644 --- a/videocodec/OMXVideoDecoderBase.h +++ b/videocodec/OMXVideoDecoderBase.h @@ -85,6 +85,10 @@ private: }; uint32_t mOMXBufferHeaderTypePtrNum; OMX_BUFFERHEADERTYPE *mOMXBufferHeaderTypePtrArray[MAX_GRAPHIC_BUFFER_NUM]; + bool mSetNativeBuffer_completion; + pthread_mutex_t mOMXBufferArray_lock; + pthread_cond_t mOMXBufferArray_cond; + struct GraphicBufferParam { uint32_t graphicBufferStride; uint32_t graphicBufferWidth; diff --git a/videocodec/securevideo/ctp/OMXVideoDecoderAVCSecure.h b/videocodec/securevideo/ctp/OMXVideoDecoderAVCSecure.h index 310e9ba..733f959 100644 --- a/videocodec/securevideo/ctp/OMXVideoDecoderAVCSecure.h +++ b/videocodec/securevideo/ctp/OMXVideoDecoderAVCSecure.h @@ -66,7 +66,8 @@ private: // default number of reference frame NUM_REFERENCE_FRAME = 4, - OUTPORT_NATIVE_BUFFER_COUNT = 15, + // a typical value for 1080p clips + OUTPORT_NATIVE_BUFFER_COUNT = 17, }; OMX_VIDEO_PARAM_AVCTYPE mParamAvc; diff --git a/videocodec/securevideo/merrifield/OMXVideoDecoderAVCSecure.h b/videocodec/securevideo/merrifield/OMXVideoDecoderAVCSecure.h index 310e9ba..733f959 100644 --- a/videocodec/securevideo/merrifield/OMXVideoDecoderAVCSecure.h +++ b/videocodec/securevideo/merrifield/OMXVideoDecoderAVCSecure.h @@ -66,7 +66,8 @@ private: // default number of reference frame NUM_REFERENCE_FRAME = 4, - OUTPORT_NATIVE_BUFFER_COUNT = 15, + // a typical value for 1080p clips + OUTPORT_NATIVE_BUFFER_COUNT = 17, }; OMX_VIDEO_PARAM_AVCTYPE mParamAvc; |