diff options
author | Jamie Gennis <jgennis@google.com> | 2010-10-07 14:08:38 -0700 |
---|---|---|
committer | Jamie Gennis <jgennis@google.com> | 2010-10-20 11:03:30 -0700 |
commit | 6a9da9fc558263548ebfbae2cbf177eb7454a41b (patch) | |
tree | 267bd7076e4e9a6b6db1235d73e6a306a30b9496 /media/libstagefright/AwesomePlayer.cpp | |
parent | 4d63523ece864ea783cf9ceeb036400af5804397 (diff) | |
download | frameworks_av-6a9da9fc558263548ebfbae2cbf177eb7454a41b.zip frameworks_av-6a9da9fc558263548ebfbae2cbf177eb7454a41b.tar.gz frameworks_av-6a9da9fc558263548ebfbae2cbf177eb7454a41b.tar.bz2 |
Add decode-to-ANativeWindow support to Stagefright.
This change adds support to Stagefright for doing OMX video decoding directly
into buffers dequeued from an ANativeWindow. It does this by registering the
dequeued buffers with the OMX component using an Android-specific OMX
extension, and then exchanging buffers between the OMX component and the
ANativeWindow.
Change-Id: Ida66f836503255a68d378c6903d96dfe9747ce87
Diffstat (limited to 'media/libstagefright/AwesomePlayer.cpp')
-rw-r--r-- | media/libstagefright/AwesomePlayer.cpp | 61 |
1 files changed, 49 insertions, 12 deletions
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp index ad6cb5b..d172eef 100644 --- a/media/libstagefright/AwesomePlayer.cpp +++ b/media/libstagefright/AwesomePlayer.cpp @@ -194,6 +194,35 @@ void AwesomeLocalRenderer::init( } } +struct AwesomeNativeWindowRenderer : public AwesomeRenderer { + AwesomeNativeWindowRenderer(const sp<ANativeWindow> &nativeWindow) + : mNativeWindow(nativeWindow) { + } + + virtual void render(MediaBuffer *buffer) { + status_t err = mNativeWindow->queueBuffer( + mNativeWindow.get(), buffer->graphicBuffer().get()); + if (err != 0) { + LOGE("queueBuffer failed with error %s (%d)", strerror(-err), + -err); + return; + } + + sp<MetaData> metaData = buffer->meta_data(); + metaData->setInt32(kKeyRendered, 1); + } + +protected: + virtual ~AwesomeNativeWindowRenderer() {} + +private: + sp<ANativeWindow> mNativeWindow; + + AwesomeNativeWindowRenderer(const AwesomeNativeWindowRenderer &); + AwesomeNativeWindowRenderer &operator=( + const AwesomeNativeWindowRenderer &); +}; + AwesomePlayer::AwesomePlayer() : mQueueStarted(false), mTimeSource(NULL), @@ -805,16 +834,25 @@ void AwesomePlayer::initRenderer_l() { IPCThreadState::self()->flushCommands(); if (mSurface != NULL) { - // 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, - mSurface, - mVideoWidth, mVideoHeight, - decodedWidth, decodedHeight); + if (strncmp(component, "OMX.", 4) == 0) { + // Hardware decoders avoid the CPU color conversion by decoding + // directly to ANativeBuffers, so we must use a renderer that + // just pushes those buffers to the ANativeWindow. + mVideoRenderer = new AwesomeNativeWindowRenderer(mSurface); + } else { + // Other decoders are instantiated locally and as a consequence + // allocate their buffers in local address space. This renderer + // then performs a color conversion and copy to get the data + // into the ANativeBuffer. + mVideoRenderer = new AwesomeLocalRenderer( + false, // previewOnly + component, + (OMX_COLOR_FORMATTYPE)format, + mISurface, + mSurface, + mVideoWidth, mVideoHeight, + decodedWidth, decodedHeight); + } } else { // Our OMX codecs allocate buffers on the media_server side // therefore they require a remote IOMXRenderer that knows how @@ -1054,7 +1092,7 @@ status_t AwesomePlayer::initVideoDecoder(uint32_t flags) { mClient.interface(), mVideoTrack->getFormat(), false, // createEncoder mVideoTrack, - NULL, flags); + NULL, flags, mSurface); if (mVideoSource != NULL) { int64_t durationUs; @@ -1811,4 +1849,3 @@ void AwesomePlayer::postAudioSeekComplete() { } } // namespace android - |