From b04bc5117dd4e159fe5c3fac738e400c82b3cb58 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 4 Aug 2018 22:31:14 -0700 Subject: [PATCH] Fix scaling logic in the Linux renderers using the new helper function --- .../video/ffmpeg-renderers/vaapi.cpp | 34 +++++++------------ .../video/ffmpeg-renderers/vdpau.cpp | 34 ++++++++----------- 2 files changed, 27 insertions(+), 41 deletions(-) diff --git a/app/streaming/video/ffmpeg-renderers/vaapi.cpp b/app/streaming/video/ffmpeg-renderers/vaapi.cpp index c985fe65..2bfdbe78 100644 --- a/app/streaming/video/ffmpeg-renderers/vaapi.cpp +++ b/app/streaming/video/ffmpeg-renderers/vaapi.cpp @@ -1,4 +1,5 @@ #include "vaapi.h" +#include #include @@ -109,34 +110,23 @@ VAAPIRenderer::renderFrame(AVFrame* frame) AVHWDeviceContext* deviceContext = (AVHWDeviceContext*)m_HwContext->data; AVVAAPIDeviceContext* vaDeviceContext = (AVVAAPIDeviceContext*)deviceContext->hwctx; - // Center in frame and preserve aspect ratio - int x, y, width, height; - double srcAspectRatio = (double)m_VideoWidth / (double)m_VideoHeight; - double dstAspectRatio = (double)m_DisplayWidth / (double)m_DisplayHeight; - if (dstAspectRatio < srcAspectRatio) { - // Greater height per width - int drawHeight = (int)(m_DisplayWidth / srcAspectRatio); - y = (m_DisplayHeight - drawHeight) / 2; - height = drawHeight; - x = 0; - width = m_DisplayWidth; - } - else { - // Greater width per height - int drawWidth = (int)(m_DisplayHeight * srcAspectRatio); - y = 0; - height = m_DisplayHeight; - x = (m_DisplayWidth - drawWidth) / 2; - width = drawWidth; - } + SDL_Rect src, dst; + src.x = src.y = 0; + src.w = m_VideoWidth; + src.h = m_VideoHeight; + dst.x = dst.y = 0; + dst.w = m_DisplayWidth; + dst.h = m_DisplayHeight; + + StreamUtils::scaleSourceToDestinationSurface(&src, &dst); m_vaPutSurface(vaDeviceContext->display, surface, m_XWindow, 0, 0, m_VideoWidth, m_VideoHeight, - x, y, - width, height, + dst.x, dst.y, + dst.w, dst.h, NULL, 0, 0); av_frame_free(&frame); diff --git a/app/streaming/video/ffmpeg-renderers/vdpau.cpp b/app/streaming/video/ffmpeg-renderers/vdpau.cpp index 4eea69e1..ca597198 100644 --- a/app/streaming/video/ffmpeg-renderers/vdpau.cpp +++ b/app/streaming/video/ffmpeg-renderers/vdpau.cpp @@ -1,4 +1,5 @@ #include "vdpau.h" +#include #include @@ -256,25 +257,20 @@ void VDPAURenderer::renderFrame(AVFrame* frame) VdpRect outputRect; - // Center in frame and preserve aspect ratio - double srcAspectRatio = (double)m_VideoWidth / (double)m_VideoHeight; - double dstAspectRatio = (double)m_DisplayWidth / (double)m_DisplayHeight; - if (dstAspectRatio < srcAspectRatio) { - // Greater height per width - uint32_t drawHeight = (uint32_t)(m_DisplayWidth / srcAspectRatio); - outputRect.y0 = (m_DisplayHeight - drawHeight) / 2; - outputRect.y1 = outputRect.y0 + drawHeight; - outputRect.x0 = 0; - outputRect.x1 = outputRect.x0 + m_DisplayWidth; - } - else { - // Greater width per height - uint32_t drawWidth = (uint32_t)(m_DisplayHeight * srcAspectRatio); - outputRect.y0 = 0; - outputRect.y1 = outputRect.y0 + m_DisplayHeight; - outputRect.x0 = (m_DisplayWidth - drawWidth) / 2; - outputRect.x1 = outputRect.x0 + drawWidth; - } + SDL_Rect src, dst; + src.x = src.y = 0; + src.w = m_VideoWidth; + src.h = m_VideoHeight; + dst.x = dst.y = 0; + dst.w = m_DisplayWidth; + dst.h = m_DisplayHeight; + + StreamUtils::scaleSourceToDestinationSurface(&src, &dst); + + outputRect.x0 = dst.x; + outputRect.x1 = dst.x + dst.w; + outputRect.y0 = dst.y; + outputRect.y1 = dst.y + dst.h; // Render the next frame into the output surface status = m_VdpVideoMixerRender(m_VideoMixer,