Create new utility function for scaling with aspect ratio and use it for DXVA2

This commit is contained in:
Cameron Gutman 2018-08-04 22:22:15 -07:00
parent b076744f00
commit 5cbb38091b
4 changed files with 49 additions and 18 deletions

View file

@ -81,7 +81,8 @@ SOURCES += \
streaming/session.cpp \ streaming/session.cpp \
streaming/audio.cpp \ streaming/audio.cpp \
gui/computermodel.cpp \ gui/computermodel.cpp \
gui/appmodel.cpp gui/appmodel.cpp \
streaming/streamutils.cpp
HEADERS += \ HEADERS += \
utils.h \ utils.h \
@ -95,7 +96,8 @@ HEADERS += \
streaming/session.hpp \ streaming/session.hpp \
gui/computermodel.h \ gui/computermodel.h \
gui/appmodel.h \ gui/appmodel.h \
streaming/video/decoder.h streaming/video/decoder.h \
streaming/streamutils.h
# Platform-specific renderers and decoders # Platform-specific renderers and decoders
ffmpeg { ffmpeg {

View file

@ -0,0 +1,20 @@
#include "streamutils.h"
void StreamUtils::scaleSourceToDestinationSurface(SDL_Rect* src, SDL_Rect* dst)
{
int dstH = dst->w * src->h / src->w;
int dstW = dst->h * src->w / src->h;
if (dstH > dst->h) {
dst->y = 0;
dst->x = (dst->w - dstW) / 2;
dst->w = dstW;
SDL_assert(dst->w * src->h / src->w <= dst->h);
}
else {
dst->x = 0;
dst->y = (dst->h - dstH) / 2;
dst->h = dstH;
SDL_assert(dst->h * src->w / src->h <= dst->w);
}
}

View file

@ -0,0 +1,10 @@
#pragma once
#include <SDL.h>
class StreamUtils
{
public:
static
void scaleSourceToDestinationSurface(SDL_Rect* src, SDL_Rect* dst);
};

View file

@ -1,6 +1,7 @@
#include <initguid.h> #include <initguid.h>
#include "dxva2.h" #include "dxva2.h"
#include "../ffmpeg.h" #include "../ffmpeg.h"
#include <streaming/streamutils.h>
#include <Limelight.h> #include <Limelight.h>
@ -593,22 +594,20 @@ void DXVA2Renderer::renderFrame(AVFrame* frame)
sample.PlanarAlpha = DXVA2_Fixed32OpaqueAlpha(); sample.PlanarAlpha = DXVA2_Fixed32OpaqueAlpha();
// Center in frame and preserve aspect ratio // Center in frame and preserve aspect ratio
double srcAspectRatio = (double)m_Desc.SampleWidth / (double)m_Desc.SampleHeight; SDL_Rect src, dst;
double dstAspectRatio = (double)m_DisplayWidth / (double)m_DisplayHeight; src.x = src.y = 0;
if (dstAspectRatio < srcAspectRatio) { src.w = m_Desc.SampleWidth;
// Greater height per width src.h = m_Desc.SampleHeight;
int drawHeight = (int)(m_DisplayWidth / srcAspectRatio); dst.x = dst.y = 0;
sample.DstRect.top = (m_DisplayHeight - drawHeight) / 2; dst.w = m_DisplayWidth;
sample.DstRect.bottom = sample.DstRect.bottom + drawHeight; dst.h = m_DisplayHeight;
sample.DstRect.right = m_DisplayWidth;
} StreamUtils::scaleSourceToDestinationSurface(&src, &dst);
else {
// Greater width per height sample.DstRect.left = dst.x;
int drawWidth = (int)(m_DisplayHeight * srcAspectRatio); sample.DstRect.right = dst.x + dst.w;
sample.DstRect.bottom = m_DisplayHeight; sample.DstRect.top = dst.y;
sample.DstRect.left = (m_DisplayWidth - drawWidth) / 2; sample.DstRect.bottom = dst.y + dst.h;
sample.DstRect.right = sample.DstRect.left + drawWidth;
}
DXVA2_VideoProcessBltParams bltParams = {}; DXVA2_VideoProcessBltParams bltParams = {};