From 4d0565de200e61f457e4d97fcfbc4c9ccd81bdad Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Fri, 12 Nov 2010 08:57:12 -0800 Subject: DO NOT MERGE - Instead of asserting that ISurface successfully registered buffers, report an error and propagate it up to the java client. Change-Id: Ibb14e5aff20920da4917d85de38ba3a8ee71d0bd related-to-bug: 3188835 --- media/libstagefright/AwesomePlayer.cpp | 146 +++++++++++++-------- .../colorconversion/SoftwareRenderer.cpp | 18 ++- media/libstagefright/include/AwesomePlayer.h | 3 +- media/libstagefright/include/SoftwareRenderer.h | 3 + media/libstagefright/omx/OMX.cpp | 7 + 5 files changed, 120 insertions(+), 57 deletions(-) (limited to 'media/libstagefright') diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp index 66eb7ee..5c423c0 100644 --- a/media/libstagefright/AwesomePlayer.cpp +++ b/media/libstagefright/AwesomePlayer.cpp @@ -82,6 +82,10 @@ struct AwesomeRemoteRenderer : public AwesomeRenderer { : mTarget(target) { } + virtual status_t initCheck() const { + return OK; + } + virtual void render(MediaBuffer *buffer) { void *id; if (buffer->meta_data()->findPointer(kKeyBufferID, &id)) { @@ -105,14 +109,19 @@ struct AwesomeLocalRenderer : public AwesomeRenderer { size_t displayWidth, size_t displayHeight, size_t decodedWidth, size_t decodedHeight, int32_t rotationDegrees) - : mTarget(NULL), + : mInitCheck(NO_INIT), + mTarget(NULL), mLibHandle(NULL) { - init(previewOnly, componentName, + mInitCheck = init(previewOnly, componentName, colorFormat, surface, displayWidth, displayHeight, decodedWidth, decodedHeight, rotationDegrees); } + virtual status_t initCheck() const { + return mInitCheck; + } + virtual void render(MediaBuffer *buffer) { render((const uint8_t *)buffer->data() + buffer->range_offset(), buffer->range_length()); @@ -134,10 +143,11 @@ protected: } private: + status_t mInitCheck; VideoRenderer *mTarget; void *mLibHandle; - void init( + status_t init( bool previewOnly, const char *componentName, OMX_COLOR_FORMATTYPE colorFormat, @@ -150,7 +160,7 @@ private: AwesomeLocalRenderer &operator=(const AwesomeLocalRenderer &);; }; -void AwesomeLocalRenderer::init( +status_t AwesomeLocalRenderer::init( bool previewOnly, const char *componentName, OMX_COLOR_FORMATTYPE colorFormat, @@ -215,11 +225,15 @@ void AwesomeLocalRenderer::init( } } - if (mTarget == NULL) { - mTarget = new SoftwareRenderer( - colorFormat, surface, displayWidth, displayHeight, - decodedWidth, decodedHeight, rotationDegrees); + if (mTarget != NULL) { + return OK; } + + mTarget = new SoftwareRenderer( + colorFormat, surface, displayWidth, displayHeight, + decodedWidth, decodedHeight, rotationDegrees); + + return ((SoftwareRenderer *)mTarget)->initCheck(); } AwesomePlayer::AwesomePlayer() @@ -804,53 +818,64 @@ status_t AwesomePlayer::play_l() { return OK; } -void AwesomePlayer::initRenderer_l() { - if (mISurface != NULL) { - sp meta = mVideoSource->getFormat(); - - int32_t format; - const char *component; - int32_t decodedWidth, decodedHeight; - CHECK(meta->findInt32(kKeyColorFormat, &format)); - CHECK(meta->findCString(kKeyDecoderComponent, &component)); - CHECK(meta->findInt32(kKeyWidth, &decodedWidth)); - CHECK(meta->findInt32(kKeyHeight, &decodedHeight)); - - int32_t rotationDegrees; - if (!mVideoTrack->getFormat()->findInt32( - kKeyRotation, &rotationDegrees)) { - rotationDegrees = 0; - } +status_t AwesomePlayer::initRenderer_l() { + if (mISurface == NULL) { + return OK; + } - mVideoRenderer.clear(); + sp meta = mVideoSource->getFormat(); - // Must ensure that mVideoRenderer's destructor is actually executed - // before creating a new one. - IPCThreadState::self()->flushCommands(); + int32_t format; + const char *component; + int32_t decodedWidth, decodedHeight; + CHECK(meta->findInt32(kKeyColorFormat, &format)); + CHECK(meta->findCString(kKeyDecoderComponent, &component)); + CHECK(meta->findInt32(kKeyWidth, &decodedWidth)); + CHECK(meta->findInt32(kKeyHeight, &decodedHeight)); - if (!strncmp("OMX.", component, 4)) { - // Our OMX codecs allocate buffers on the media_server side - // therefore they require a remote IOMXRenderer that knows how - // to display them. - mVideoRenderer = new AwesomeRemoteRenderer( - mClient.interface()->createRenderer( - mISurface, component, - (OMX_COLOR_FORMATTYPE)format, - decodedWidth, decodedHeight, - mVideoWidth, mVideoHeight, - rotationDegrees)); - } else { - // Other decoders are instantiated locally and as a consequence - // allocate their buffers in local address space. - mVideoRenderer = new AwesomeLocalRenderer( - false, // previewOnly - component, - (OMX_COLOR_FORMATTYPE)format, - mISurface, - mVideoWidth, mVideoHeight, - decodedWidth, decodedHeight, rotationDegrees); - } + int32_t rotationDegrees; + if (!mVideoTrack->getFormat()->findInt32( + kKeyRotation, &rotationDegrees)) { + rotationDegrees = 0; } + + mVideoRenderer.clear(); + + // Must ensure that mVideoRenderer's destructor is actually executed + // before creating a new one. + IPCThreadState::self()->flushCommands(); + + if (!strncmp("OMX.", component, 4)) { + // Our OMX codecs allocate buffers on the media_server side + // therefore they require a remote IOMXRenderer that knows how + // to display them. + + sp native = + mClient.interface()->createRenderer( + mISurface, component, + (OMX_COLOR_FORMATTYPE)format, + decodedWidth, decodedHeight, + mVideoWidth, mVideoHeight, + rotationDegrees); + + if (native == NULL) { + return NO_INIT; + } + + mVideoRenderer = new AwesomeRemoteRenderer(native); + } else { + // Other decoders are instantiated locally and as a consequence + // allocate their buffers in local address space. + mVideoRenderer = new AwesomeLocalRenderer( + false, // previewOnly + component, + (OMX_COLOR_FORMATTYPE)format, + mISurface, + mVideoWidth, mVideoHeight, + decodedWidth, decodedHeight, rotationDegrees); + } + + return mVideoRenderer->initCheck(); } status_t AwesomePlayer::pause() { @@ -1179,9 +1204,14 @@ void AwesomePlayer::onVideoEvent() { if (mVideoRenderer != NULL) { mVideoRendererIsPreview = false; - initRenderer_l(); + err = initRenderer_l(); + + if (err == OK) { + continue; + } + + // fall through } - continue; } // So video playback is complete, but we may still have @@ -1265,7 +1295,15 @@ void AwesomePlayer::onVideoEvent() { if (mVideoRendererIsPreview || mVideoRenderer == NULL) { mVideoRendererIsPreview = false; - initRenderer_l(); + status_t err = initRenderer_l(); + + if (err != OK) { + finishSeekIfNecessary(-1); + + mFlags |= VIDEO_AT_EOS; + postStreamDoneEvent_l(err); + return; + } } if (mVideoRenderer != NULL) { diff --git a/media/libstagefright/colorconversion/SoftwareRenderer.cpp b/media/libstagefright/colorconversion/SoftwareRenderer.cpp index 86ad85b..93ec79d 100644 --- a/media/libstagefright/colorconversion/SoftwareRenderer.cpp +++ b/media/libstagefright/colorconversion/SoftwareRenderer.cpp @@ -32,7 +32,8 @@ SoftwareRenderer::SoftwareRenderer( size_t displayWidth, size_t displayHeight, size_t decodedWidth, size_t decodedHeight, int32_t rotationDegrees) - : mColorFormat(colorFormat), + : mInitCheck(NO_INIT), + mColorFormat(colorFormat), mConverter(colorFormat, OMX_COLOR_Format16bitRGB565), mISurface(surface), mDisplayWidth(displayWidth), @@ -74,15 +75,28 @@ SoftwareRenderer::SoftwareRenderer( mMemoryHeap); status_t err = mISurface->registerBuffers(bufferHeap); - CHECK_EQ(err, OK); + + if (err != OK) { + LOGW("ISurface failed to register buffers (0x%08x)", err); + } + + mInitCheck = err; } SoftwareRenderer::~SoftwareRenderer() { mISurface->unregisterBuffers(); } +status_t SoftwareRenderer::initCheck() const { + return mInitCheck; +} + void SoftwareRenderer::render( const void *data, size_t size, void *platformPrivate) { + if (mInitCheck != OK) { + return; + } + size_t offset = mIndex * mFrameSize; void *dst = (uint8_t *)mMemoryHeap->getBase() + offset; diff --git a/media/libstagefright/include/AwesomePlayer.h b/media/libstagefright/include/AwesomePlayer.h index 3020a09..c059e60 100644 --- a/media/libstagefright/include/AwesomePlayer.h +++ b/media/libstagefright/include/AwesomePlayer.h @@ -44,6 +44,7 @@ struct UDPPusher; struct AwesomeRenderer : public RefBase { AwesomeRenderer() {} + virtual status_t initCheck() const = 0; virtual void render(MediaBuffer *buffer) = 0; private: @@ -225,7 +226,7 @@ private: void partial_reset_l(); status_t seekTo_l(int64_t timeUs); status_t pause_l(bool at_eos = false); - void initRenderer_l(); + status_t initRenderer_l(); void seekAudioIfNecessary_l(); void cancelPlayerEvents(bool keepBufferingGoing = false); diff --git a/media/libstagefright/include/SoftwareRenderer.h b/media/libstagefright/include/SoftwareRenderer.h index 25c9df7..89d7cc4 100644 --- a/media/libstagefright/include/SoftwareRenderer.h +++ b/media/libstagefright/include/SoftwareRenderer.h @@ -38,10 +38,13 @@ public: virtual ~SoftwareRenderer(); + status_t initCheck() const; + virtual void render( const void *data, size_t size, void *platformPrivate); private: + status_t mInitCheck; OMX_COLOR_FORMATTYPE mColorFormat; ColorConverter mConverter; sp mISurface; diff --git a/media/libstagefright/omx/OMX.cpp b/media/libstagefright/omx/OMX.cpp index 63af26a..f19c16a 100644 --- a/media/libstagefright/omx/OMX.cpp +++ b/media/libstagefright/omx/OMX.cpp @@ -525,6 +525,13 @@ sp OMX::createRenderer( surface, displayWidth, displayHeight, encodedWidth, encodedHeight); + + if (((SoftwareRenderer *)impl)->initCheck() != OK) { + delete impl; + impl = NULL; + + return NULL; + } } return new OMXRenderer(impl); -- cgit v1.1