diff options
author | Andreas Huber <andih@google.com> | 2010-11-16 15:26:30 -0800 |
---|---|---|
committer | Andreas Huber <andih@google.com> | 2010-11-16 15:26:30 -0800 |
commit | ba529e486dde15fe75ea1b48570f9d60a4cf3c48 (patch) | |
tree | 081f61aca5f4967c1ee3a741414b58ca4a39ffd3 /media/libstagefright/AwesomePlayer.cpp | |
parent | 0a5ca668c6f7d45706e9aec4a1dfec0aacc6d233 (diff) | |
download | frameworks_av-ba529e486dde15fe75ea1b48570f9d60a4cf3c48.zip frameworks_av-ba529e486dde15fe75ea1b48570f9d60a4cf3c48.tar.gz frameworks_av-ba529e486dde15fe75ea1b48570f9d60a4cf3c48.tar.bz2 |
Support post-decode video rotation.
Change-Id: I9ac90871269c5e132e98a9bf3ad8cae00f329f17
Diffstat (limited to 'media/libstagefright/AwesomePlayer.cpp')
-rw-r--r-- | media/libstagefright/AwesomePlayer.cpp | 64 |
1 files changed, 54 insertions, 10 deletions
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp index ff9f255..538e7bf 100644 --- a/media/libstagefright/AwesomePlayer.cpp +++ b/media/libstagefright/AwesomePlayer.cpp @@ -84,11 +84,13 @@ struct AwesomeLocalRenderer : public AwesomeRenderer { OMX_COLOR_FORMATTYPE colorFormat, const sp<Surface> &surface, size_t displayWidth, size_t displayHeight, - size_t decodedWidth, size_t decodedHeight) + size_t decodedWidth, size_t decodedHeight, + int32_t rotationDegrees) : mTarget(NULL) { init(colorFormat, surface, displayWidth, displayHeight, - decodedWidth, decodedHeight); + decodedWidth, decodedHeight, + rotationDegrees); } virtual void render(MediaBuffer *buffer) { @@ -113,7 +115,8 @@ private: OMX_COLOR_FORMATTYPE colorFormat, const sp<Surface> &surface, size_t displayWidth, size_t displayHeight, - size_t decodedWidth, size_t decodedHeight); + size_t decodedWidth, size_t decodedHeight, + int32_t rotationDegrees); AwesomeLocalRenderer(const AwesomeLocalRenderer &); AwesomeLocalRenderer &operator=(const AwesomeLocalRenderer &);; @@ -123,15 +126,19 @@ void AwesomeLocalRenderer::init( OMX_COLOR_FORMATTYPE colorFormat, const sp<Surface> &surface, size_t displayWidth, size_t displayHeight, - size_t decodedWidth, size_t decodedHeight) { + size_t decodedWidth, size_t decodedHeight, + int32_t rotationDegrees) { mTarget = new SoftwareRenderer( colorFormat, surface, displayWidth, displayHeight, - decodedWidth, decodedHeight); + decodedWidth, decodedHeight, rotationDegrees); } struct AwesomeNativeWindowRenderer : public AwesomeRenderer { - AwesomeNativeWindowRenderer(const sp<ANativeWindow> &nativeWindow) + AwesomeNativeWindowRenderer( + const sp<ANativeWindow> &nativeWindow, + int32_t rotationDegrees) : mNativeWindow(nativeWindow) { + applyRotation(rotationDegrees); } virtual void render(MediaBuffer *buffer) { @@ -153,6 +160,22 @@ protected: private: sp<ANativeWindow> mNativeWindow; + void applyRotation(int32_t rotationDegrees) { + uint32_t transform; + switch (rotationDegrees) { + case 0: transform = 0; break; + case 90: transform = HAL_TRANSFORM_ROT_90; break; + case 180: transform = HAL_TRANSFORM_ROT_180; break; + case 270: transform = HAL_TRANSFORM_ROT_270; break; + default: transform = 0; break; + } + + if (transform) { + CHECK_EQ(0, native_window_set_buffers_transform( + mNativeWindow.get(), transform)); + } + } + AwesomeNativeWindowRenderer(const AwesomeNativeWindowRenderer &); AwesomeNativeWindowRenderer &operator=( const AwesomeNativeWindowRenderer &); @@ -796,7 +819,19 @@ void AwesomePlayer::notifyVideoSize_l() { CHECK(meta->findInt32(kKeyWidth, &decodedWidth)); CHECK(meta->findInt32(kKeyHeight, &decodedHeight)); - notifyListener_l(MEDIA_SET_VIDEO_SIZE, decodedWidth, decodedHeight); + int32_t rotationDegrees; + if (!mVideoTrack->getFormat()->findInt32( + kKeyRotation, &rotationDegrees)) { + rotationDegrees = 0; + } + + if (rotationDegrees == 90 || rotationDegrees == 270) { + notifyListener_l( + MEDIA_SET_VIDEO_SIZE, decodedHeight, decodedWidth); + } else { + notifyListener_l( + MEDIA_SET_VIDEO_SIZE, decodedWidth, decodedHeight); + } } void AwesomePlayer::initRenderer_l() { @@ -814,6 +849,12 @@ void AwesomePlayer::initRenderer_l() { CHECK(meta->findInt32(kKeyWidth, &decodedWidth)); CHECK(meta->findInt32(kKeyHeight, &decodedHeight)); + int32_t rotationDegrees; + if (!mVideoTrack->getFormat()->findInt32( + kKeyRotation, &rotationDegrees)) { + rotationDegrees = 0; + } + mVideoRenderer.clear(); // Must ensure that mVideoRenderer's destructor is actually executed @@ -824,7 +865,8 @@ void AwesomePlayer::initRenderer_l() { // 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); + mVideoRenderer = + new AwesomeNativeWindowRenderer(mSurface, rotationDegrees); } else { // Other decoders are instantiated locally and as a consequence // allocate their buffers in local address space. This renderer @@ -834,7 +876,8 @@ void AwesomePlayer::initRenderer_l() { (OMX_COLOR_FORMATTYPE)format, mSurface, mVideoWidth, mVideoHeight, - decodedWidth, decodedHeight); + decodedWidth, decodedHeight, + rotationDegrees); } } @@ -1819,7 +1862,8 @@ status_t AwesomePlayer::resume() { state->mVideoWidth, state->mVideoHeight, state->mDecodedWidth, - state->mDecodedHeight); + state->mDecodedHeight, + 0); mVideoRendererIsPreview = true; |