diff options
| author | Lajos Molnar <lajos@google.com> | 2015-07-01 21:00:13 +0000 | 
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-07-01 21:01:00 +0000 | 
| commit | dfad5454e0caf46f8732f1415d3b9a76f2a1242e (patch) | |
| tree | ba10126cafdc2070d70ea39447cacb68a84201d7 /media | |
| parent | 49605e8ab171a2b1f474645d632d3982f5f7b8e6 (diff) | |
| parent | 264bac95912efe121d6a60026612617f04f42966 (diff) | |
| download | frameworks_av-dfad5454e0caf46f8732f1415d3b9a76f2a1242e.zip frameworks_av-dfad5454e0caf46f8732f1415d3b9a76f2a1242e.tar.gz frameworks_av-dfad5454e0caf46f8732f1415d3b9a76f2a1242e.tar.bz2  | |
Merge "stagefright: prevent allocating stale buffers for OMX decoders" into mnc-dev
Diffstat (limited to 'media')
| -rw-r--r-- | media/libstagefright/ACodec.cpp | 1 | ||||
| -rw-r--r-- | media/libstagefright/MediaCodec.cpp | 22 | ||||
| -rw-r--r-- | media/libstagefright/MediaSync.cpp | 14 | ||||
| -rw-r--r-- | media/libstagefright/omx/GraphicBufferSource.cpp | 8 | 
4 files changed, 33 insertions, 12 deletions
diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp index c6e45af..7452e4b 100644 --- a/media/libstagefright/ACodec.cpp +++ b/media/libstagefright/ACodec.cpp @@ -5242,6 +5242,7 @@ void ACodec::BaseState::onOutputBufferDrained(const sp<AMessage> &msg) {          if (err == OK) {              info->mStatus = BufferInfo::OWNED_BY_NATIVE_WINDOW;          } else { +            ALOGE("queueBuffer failed in onOutputBufferDrained: %d", err);              mCodec->signalError(OMX_ErrorUndefined, makeNoSideEffectStatus(err));              info->mStatus = BufferInfo::OWNED_BY_US;              // keeping read fence as write fence to avoid clobbering diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp index b576cd9..69f44ed 100644 --- a/media/libstagefright/MediaCodec.cpp +++ b/media/libstagefright/MediaCodec.cpp @@ -2528,7 +2528,25 @@ status_t MediaCodec::connectToSurface(const sp<Surface> &surface) {          err = native_window_api_connect(surface.get(), NATIVE_WINDOW_API_MEDIA);          if (err == BAD_VALUE) {              ALOGI("native window already connected. Assuming no change of surface"); -        } else if (err != OK) { +        } else if (err == OK) { +            // Require a fresh set of buffers after each connect by using a unique generation +            // number. Rely on the fact that max supported process id by Linux is 2^22. +            // PID is never 0 so we don't have to worry that we use the default generation of 0. +            // TODO: come up with a unique scheme if other producers also set the generation number. +            static uint32_t mSurfaceGeneration = 0; +            uint32_t generation = (getpid() << 10) | (++mSurfaceGeneration & ((1 << 10) - 1)); +            surface->setGenerationNumber(generation); +            ALOGI("[%s] setting surface generation to %u", mComponentName.c_str(), generation); + +            // HACK: clear any free buffers. Remove when connect will automatically do this. +            // This is needed as the consumer may be holding onto stale frames that it can reattach +            // to this surface after disconnect/connect, and those free frames would inherit the new +            // generation number. Disconnecting after setting a unique generation prevents this. +            native_window_api_disconnect(surface.get(), NATIVE_WINDOW_API_MEDIA); +            err = native_window_api_connect(surface.get(), NATIVE_WINDOW_API_MEDIA); +        } + +        if (err != OK) {              ALOGE("native_window_api_connect returned an error: %s (%d)", strerror(-err), err);          }      } @@ -2538,6 +2556,8 @@ status_t MediaCodec::connectToSurface(const sp<Surface> &surface) {  status_t MediaCodec::disconnectFromSurface() {      status_t err = OK;      if (mSurface != NULL) { +        // Resetting generation is not technically needed, but there is no need to keep it either +        mSurface->setGenerationNumber(0);          err = native_window_api_disconnect(mSurface.get(), NATIVE_WINDOW_API_MEDIA);          if (err != OK) {              ALOGW("native_window_api_disconnect returned an error: %s (%d)", strerror(-err), err); diff --git a/media/libstagefright/MediaSync.cpp b/media/libstagefright/MediaSync.cpp index b402e48..52077a7 100644 --- a/media/libstagefright/MediaSync.cpp +++ b/media/libstagefright/MediaSync.cpp @@ -558,7 +558,6 @@ void MediaSync::onFrameAvailableFromInput() {              return;          }      } -    ++mNumOutstandingBuffers;      // Acquire and detach the buffer from the input.      BufferItem bufferItem; @@ -567,6 +566,7 @@ void MediaSync::onFrameAvailableFromInput() {          ALOGE("acquiring buffer from input failed (%d)", status);          return;      } +    ++mNumOutstandingBuffers;      ALOGV("acquired buffer %#llx from input", (long long)bufferItem.mGraphicBuffer->getId()); @@ -608,6 +608,7 @@ void MediaSync::renderOneBufferItem_l( const BufferItem &bufferItem) {      // Attach and queue the buffer to the output.      int slot; +    mOutput->setGenerationNumber(bufferItem.mGraphicBuffer->getGenerationNumber());      status_t status = mOutput->attachBuffer(&slot, bufferItem.mGraphicBuffer);      ALOGE_IF(status != NO_ERROR, "attaching buffer to output failed (%d)", status);      if (status == NO_ERROR) { @@ -695,16 +696,13 @@ void MediaSync::returnBufferToInput_l(          ALOGE_IF(status != NO_ERROR, "releasing buffer to input failed (%d)", status);      } -    if (status != NO_ERROR) { -        // TODO: do we need to try to return this buffer later? -        return; -    } - -    ALOGV("released buffer %#llx to input", (long long)oldBuffer->getId()); -      // Notify any waiting onFrameAvailable calls.      --mNumOutstandingBuffers;      mReleaseCondition.signal(); + +    if (status == NO_ERROR) { +        ALOGV("released buffer %#llx to input", (long long)oldBuffer->getId()); +    }  }  void MediaSync::onAbandoned_l(bool isInput) { diff --git a/media/libstagefright/omx/GraphicBufferSource.cpp b/media/libstagefright/omx/GraphicBufferSource.cpp index a424819..1a7dc9d 100644 --- a/media/libstagefright/omx/GraphicBufferSource.cpp +++ b/media/libstagefright/omx/GraphicBufferSource.cpp @@ -843,13 +843,15 @@ void GraphicBufferSource::releaseBuffer(          mConsumer->detachBuffer(id);          mBufferSlot[id] = NULL; -        mConsumer->attachBuffer(&id, buffer); -        mConsumer->releaseBuffer( -                id, 0, EGL_NO_DISPLAY, EGL_NO_SYNC_KHR, fence); +        if (mConsumer->attachBuffer(&id, buffer) == OK) { +            mConsumer->releaseBuffer( +                    id, 0, EGL_NO_DISPLAY, EGL_NO_SYNC_KHR, fence); +        }      } else {          mConsumer->releaseBuffer(                  id, frameNum, EGL_NO_DISPLAY, EGL_NO_SYNC_KHR, fence);      } +    id = -1; // invalidate id      mNumBufferAcquired--;  }  | 
