diff options
author | Jamie Gennis <jgennis@google.com> | 2011-02-22 18:33:06 -0800 |
---|---|---|
committer | Jamie Gennis <jgennis@google.com> | 2011-02-28 12:23:23 -0800 |
commit | 74006804065941841883c4b46ee785070164023f (patch) | |
tree | 7ad683fcf66330919b9015c5ff7d44bb8fb7d220 /media/libstagefright | |
parent | 633b4c8cc1f41370576aa43e6c5a70e4865a36df (diff) | |
download | frameworks_av-74006804065941841883c4b46ee785070164023f.zip frameworks_av-74006804065941841883c4b46ee785070164023f.tar.gz frameworks_av-74006804065941841883c4b46ee785070164023f.tar.bz2 |
Fix error recovery in Stagefright init.
This change fixes the error path of
OMXCodec::allocateOutputBuffersFromNativeWindow so that it cancels the
correct number of buffers if a dequeueBuffer operation fails.
Change-Id: Ib7cdcdf24f1718bc070ad218a5980949c0e942eb
Diffstat (limited to 'media/libstagefright')
-rw-r--r-- | media/libstagefright/ACodec.cpp | 26 | ||||
-rw-r--r-- | media/libstagefright/OMXCodec.cpp | 33 |
2 files changed, 27 insertions, 32 deletions
diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp index b0ae3d8..2bbb320 100644 --- a/media/libstagefright/ACodec.cpp +++ b/media/libstagefright/ACodec.cpp @@ -459,16 +459,12 @@ status_t ACodec::allocateOutputBuffersFromNativeWindow() { return err; } - // XXX TODO: Do something so the ANativeWindow knows that we'll need to get - // the same set of buffers. - LOGV("[%s] Allocating %lu buffers from a native window of size %lu on " "output port", mComponentName.c_str(), def.nBufferCountActual, def.nBufferSize); // Dequeue buffers and send them to OMX - OMX_U32 i; - for (i = 0; i < def.nBufferCountActual; i++) { + for (OMX_U32 i = 0; i < def.nBufferCountActual; i++) { android_native_buffer_t *buf; err = mNativeWindow->dequeueBuffer(mNativeWindow.get(), &buf); if (err != 0) { @@ -477,23 +473,26 @@ status_t ACodec::allocateOutputBuffersFromNativeWindow() { } sp<GraphicBuffer> graphicBuffer(new GraphicBuffer(buf, false)); + BufferInfo info; + info.mStatus = BufferInfo::OWNED_BY_US; + info.mData = new ABuffer(0); + info.mGraphicBuffer = graphicBuffer; + mBuffers[kPortIndexOutput].push(info); + IOMX::buffer_id bufferId; err = mOMX->useGraphicBuffer(mNode, kPortIndexOutput, graphicBuffer, &bufferId); if (err != 0) { + LOGE("registering GraphicBuffer %lu with OMX IL component failed: " + "%d", i, err); break; } + mBuffers[kPortIndexOutput].editItemAt(i).mBufferID = bufferId; + LOGV("[%s] Registered graphic buffer with ID %p (pointer = %p)", mComponentName.c_str(), bufferId, graphicBuffer.get()); - - BufferInfo info; - info.mBufferID = bufferId; - info.mStatus = BufferInfo::OWNED_BY_US; - info.mData = new ABuffer(0); - info.mGraphicBuffer = graphicBuffer; - mBuffers[kPortIndexOutput].push(info); } OMX_U32 cancelStart; @@ -503,7 +502,7 @@ status_t ACodec::allocateOutputBuffersFromNativeWindow() { // If an error occurred while dequeuing we need to cancel any buffers // that were dequeued. cancelStart = 0; - cancelEnd = i; + cancelEnd = mBuffers[kPortIndexOutput].size(); } else { // Return the last two buffers to the native window. // XXX TODO: The number of buffers the native window owns should @@ -2286,4 +2285,3 @@ void ACodec::FlushingState::changeStateIfWeOwnAllBuffers() { } } // namespace android - diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp index 5d502e7..00b1310 100644 --- a/media/libstagefright/OMXCodec.cpp +++ b/media/libstagefright/OMXCodec.cpp @@ -1769,15 +1769,11 @@ status_t OMXCodec::allocateOutputBuffersFromNativeWindow() { return err; } - // XXX TODO: Do something so the ANativeWindow knows that we'll need to get - // the same set of buffers. - CODEC_LOGI("allocating %lu buffers from a native window of size %lu on " "output port", def.nBufferCountActual, def.nBufferSize); // Dequeue buffers and send them to OMX - OMX_U32 i; - for (i = 0; i < def.nBufferCountActual; i++) { + for (OMX_U32 i = 0; i < def.nBufferCountActual; i++) { android_native_buffer_t* buf; err = mNativeWindow->dequeueBuffer(mNativeWindow.get(), &buf); if (err != 0) { @@ -1786,36 +1782,37 @@ status_t OMXCodec::allocateOutputBuffersFromNativeWindow() { } sp<GraphicBuffer> graphicBuffer(new GraphicBuffer(buf, false)); + BufferInfo info; + info.mData = NULL; + info.mSize = def.nBufferSize; + info.mStatus = OWNED_BY_US; + info.mMem = NULL; + info.mMediaBuffer = new MediaBuffer(graphicBuffer); + info.mMediaBuffer->setObserver(this); + mPortBuffers[kPortIndexOutput].push(info); + IOMX::buffer_id bufferId; err = mOMX->useGraphicBuffer(mNode, kPortIndexOutput, graphicBuffer, &bufferId); if (err != 0) { + CODEC_LOGE("registering GraphicBuffer with OMX IL component " + "failed: %d", err); break; } + mPortBuffers[kPortIndexOutput].editItemAt(i).mBuffer = bufferId; + CODEC_LOGV("registered graphic buffer with ID %p (pointer = %p)", bufferId, graphicBuffer.get()); - - BufferInfo info; - info.mData = NULL; - info.mSize = def.nBufferSize; - info.mBuffer = bufferId; - info.mStatus = OWNED_BY_US; - info.mMem = NULL; - info.mMediaBuffer = new MediaBuffer(graphicBuffer); - info.mMediaBuffer->setObserver(this); - - mPortBuffers[kPortIndexOutput].push(info); } OMX_U32 cancelStart; OMX_U32 cancelEnd; - if (err != 0) { // If an error occurred while dequeuing we need to cancel any buffers // that were dequeued. cancelStart = 0; - cancelEnd = i; + cancelEnd = mPortBuffers[kPortIndexOutput].size(); } else { // Return the last two buffers to the native window. // XXX TODO: The number of buffers the native window owns should probably be |