From ffc2fcc19129c50b10323b1b0b5796969165fbae Mon Sep 17 00:00:00 2001 From: "Chris \"Koying\" Browet" Date: Sun, 1 Jan 2017 17:45:45 +0100 Subject: reADD: [amcs] Handle Rotation --- .../Video/DVDVideoCodecAndroidMediaCodec.cpp | 12 +++++ .../HwDecRender/RendererMediaCodecSurface.cpp | 57 ++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAndroidMediaCodec.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAndroidMediaCodec.cpp index 4029095698..7216817549 100644 --- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAndroidMediaCodec.cpp +++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAndroidMediaCodec.cpp @@ -370,6 +370,11 @@ bool CDVDVideoCodecAndroidMediaCodec::Open(CDVDStreamInfo &hints, CDVDCodecOptio // Won't work reliably return false; } + else if (hints.orientation && m_render_surface && CJNIMediaFormat::GetSDKVersion() < 23) + { + CLog::Log(LOGERROR, "CDVDVideoCodecAndroidMediaCodec::Open - %s\n", "Surface does not support orientation before API 23"); + return false; + } else if (!CSettings::GetInstance().GetBool(CSettings::SETTING_VIDEOPLAYER_USEMEDIACODEC) && !CSettings::GetInstance().GetBool(CSettings::SETTING_VIDEOPLAYER_USEMEDIACODECSURFACE)) return false; @@ -964,6 +969,13 @@ bool CDVDVideoCodecAndroidMediaCodec::ConfigureMediaCodec(void) // some android devices forget to default the demux input max size mediaformat.setInteger(CJNIMediaFormat::KEY_MAX_INPUT_SIZE, 0); + if (CJNIBase::GetSDKVersion() >= 23 && m_render_surface) + { + // Handle rotation + mediaformat.setInteger(CJNIMediaFormat::KEY_ROTATION, m_hints.orientation); + } + + // handle codec extradata if (m_hints.extrasize) { diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/RendererMediaCodecSurface.cpp b/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/RendererMediaCodecSurface.cpp index 1d759b5b45..a7287c6b72 100644 --- a/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/RendererMediaCodecSurface.cpp +++ b/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/RendererMediaCodecSurface.cpp @@ -147,6 +147,63 @@ bool CRendererMediaCodecSurface::RenderHook(int index) break; } + + // Handle orientation + switch (m_renderOrientation) + { + case 90: + case 270: + { + int diffX = 0; + int diffY = 0; + int centerX = 0; + int centerY = 0; + + int newWidth = dstRect.Height(); // new width is old height + int newHeight = dstRect.Width(); // new height is old width + int diffWidth = newWidth - dstRect.Width(); // difference between old and new width + int diffHeight = newHeight - dstRect.Height(); // difference between old and new height + + // if the new width is bigger then the old or + // the new height is bigger then the old - we need to scale down + if (diffWidth > 0 || diffHeight > 0 ) + { + float aspectRatio = GetAspectRatio(); + // scale to fit screen width because + // the difference in width is bigger then the + // difference in height + if (diffWidth > diffHeight) + { + newWidth = dstRect.Width(); // clamp to the width of the old dest rect + newHeight *= aspectRatio; + } + else // scale to fit screen height + { + newHeight = dstRect.Height(); // clamp to the height of the old dest rect + newWidth /= aspectRatio; + } + } + + // calculate the center point of the view + centerX = m_viewRect.x1 + m_viewRect.Width() / 2; + centerY = m_viewRect.y1 + m_viewRect.Height() / 2; + + // calculate the number of pixels we need to go in each + // x direction from the center point + diffX = newWidth / 2; + // calculate the number of pixels we need to go in each + // y direction from the center point + diffY = newHeight / 2; + + dstRect = CRect(centerX - diffX, centerY - diffY, centerX + diffX, centerY + diffY); + + break; + } + + default: + break; + } + mci->RenderUpdate(srcRect, dstRect); } return true; -- cgit v1.2.3