Fix scaling logic in the Linux renderers using the new helper function

This commit is contained in:
Cameron Gutman 2018-08-04 22:31:14 -07:00
parent 5cbb38091b
commit b04bc5117d
2 changed files with 27 additions and 41 deletions

View File

@ -1,4 +1,5 @@
#include "vaapi.h"
#include <streaming/streamutils.h>
#include <dlfcn.h>
@ -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);

View File

@ -1,4 +1,5 @@
#include "vdpau.h"
#include <streaming/streamutils.h>
#include <SDL_syswm.h>
@ -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,