diff --git a/app/app.pro b/app/app.pro index f524de18..156de9ee 100644 --- a/app/app.pro +++ b/app/app.pro @@ -81,7 +81,8 @@ SOURCES += \ streaming/session.cpp \ streaming/audio.cpp \ gui/computermodel.cpp \ - gui/appmodel.cpp + gui/appmodel.cpp \ + streaming/streamutils.cpp HEADERS += \ utils.h \ @@ -95,7 +96,8 @@ HEADERS += \ streaming/session.hpp \ gui/computermodel.h \ gui/appmodel.h \ - streaming/video/decoder.h + streaming/video/decoder.h \ + streaming/streamutils.h # Platform-specific renderers and decoders ffmpeg { diff --git a/app/streaming/streamutils.cpp b/app/streaming/streamutils.cpp new file mode 100644 index 00000000..c0d46c18 --- /dev/null +++ b/app/streaming/streamutils.cpp @@ -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); + } +} diff --git a/app/streaming/streamutils.h b/app/streaming/streamutils.h new file mode 100644 index 00000000..ecf54add --- /dev/null +++ b/app/streaming/streamutils.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +class StreamUtils +{ +public: + static + void scaleSourceToDestinationSurface(SDL_Rect* src, SDL_Rect* dst); +}; diff --git a/app/streaming/video/ffmpeg-renderers/dxva2.cpp b/app/streaming/video/ffmpeg-renderers/dxva2.cpp index 2ed5a2e1..bff42b68 100644 --- a/app/streaming/video/ffmpeg-renderers/dxva2.cpp +++ b/app/streaming/video/ffmpeg-renderers/dxva2.cpp @@ -1,6 +1,7 @@ #include #include "dxva2.h" #include "../ffmpeg.h" +#include #include @@ -593,22 +594,20 @@ void DXVA2Renderer::renderFrame(AVFrame* frame) sample.PlanarAlpha = DXVA2_Fixed32OpaqueAlpha(); // Center in frame and preserve aspect ratio - double srcAspectRatio = (double)m_Desc.SampleWidth / (double)m_Desc.SampleHeight; - double dstAspectRatio = (double)m_DisplayWidth / (double)m_DisplayHeight; - if (dstAspectRatio < srcAspectRatio) { - // Greater height per width - int drawHeight = (int)(m_DisplayWidth / srcAspectRatio); - sample.DstRect.top = (m_DisplayHeight - drawHeight) / 2; - sample.DstRect.bottom = sample.DstRect.bottom + drawHeight; - sample.DstRect.right = m_DisplayWidth; - } - else { - // Greater width per height - int drawWidth = (int)(m_DisplayHeight * srcAspectRatio); - sample.DstRect.bottom = m_DisplayHeight; - sample.DstRect.left = (m_DisplayWidth - drawWidth) / 2; - sample.DstRect.right = sample.DstRect.left + drawWidth; - } + SDL_Rect src, dst; + src.x = src.y = 0; + src.w = m_Desc.SampleWidth; + src.h = m_Desc.SampleHeight; + dst.x = dst.y = 0; + dst.w = m_DisplayWidth; + dst.h = m_DisplayHeight; + + StreamUtils::scaleSourceToDestinationSurface(&src, &dst); + + sample.DstRect.left = dst.x; + sample.DstRect.right = dst.x + dst.w; + sample.DstRect.top = dst.y; + sample.DstRect.bottom = dst.y + dst.h; DXVA2_VideoProcessBltParams bltParams = {};