From 643319f60e72a86c180ee839b25c086554e5bd47 Mon Sep 17 00:00:00 2001 From: Lajos Molnar Date: Mon, 24 Nov 2014 21:55:35 -0800 Subject: stagefright: add graceful handling when setting port definition - don't crash when count of buffers is incorrect, or when the buffer size decreases. This allows configuring SW video encoders for smaller than QCIF size. Bug: 18513091 Change-Id: Ibfcd6b883a892156e408e94fbc329103b9ac09ac --- .../libstagefright/omx/SimpleSoftOMXComponent.cpp | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'media/libstagefright') diff --git a/media/libstagefright/omx/SimpleSoftOMXComponent.cpp b/media/libstagefright/omx/SimpleSoftOMXComponent.cpp index 4999663..7f99dcd 100644 --- a/media/libstagefright/omx/SimpleSoftOMXComponent.cpp +++ b/media/libstagefright/omx/SimpleSoftOMXComponent.cpp @@ -152,28 +152,28 @@ OMX_ERRORTYPE SimpleSoftOMXComponent::internalSetParameter( OMX_PARAM_PORTDEFINITIONTYPE *defParams = (OMX_PARAM_PORTDEFINITIONTYPE *)params; - if (defParams->nPortIndex >= mPorts.size() - || defParams->nSize - != sizeof(OMX_PARAM_PORTDEFINITIONTYPE)) { - return OMX_ErrorUndefined; + if (defParams->nPortIndex >= mPorts.size()) { + return OMX_ErrorBadPortIndex; + } + if (defParams->nSize != sizeof(OMX_PARAM_PORTDEFINITIONTYPE)) { + return OMX_ErrorUnsupportedSetting; } PortInfo *port = &mPorts.editItemAt(defParams->nPortIndex); - if (defParams->nBufferSize != port->mDef.nBufferSize) { - CHECK_GE(defParams->nBufferSize, port->mDef.nBufferSize); + // default behavior is that we only allow buffer size to increase + if (defParams->nBufferSize > port->mDef.nBufferSize) { port->mDef.nBufferSize = defParams->nBufferSize; } - if (defParams->nBufferCountActual - != port->mDef.nBufferCountActual) { - CHECK_GE(defParams->nBufferCountActual, - port->mDef.nBufferCountMin); - - port->mDef.nBufferCountActual = defParams->nBufferCountActual; + if (defParams->nBufferCountActual < port->mDef.nBufferCountMin) { + ALOGW("component requires at least %u buffers (%u requested)", + port->mDef.nBufferCountMin, defParams->nBufferCountActual); + return OMX_ErrorUnsupportedSetting; } + port->mDef.nBufferCountActual = defParams->nBufferCountActual; return OMX_ErrorNone; } -- cgit v1.1