Skip to content

Commit

Permalink
squash: windows: dxva adaptions
Browse files Browse the repository at this point in the history
  • Loading branch information
afedchin authored and popcornmix committed May 3, 2017
1 parent dc4d92d commit a49c239
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 38 deletions.
4 changes: 2 additions & 2 deletions xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,7 @@ CDVDVideoCodec::VCReturn CDecoder::Decode(AVCodecContext* avctx, AVFrame* frame)
SAFE_RELEASE(m_presentPicture);
m_presentPicture = new CRenderPicture(m_surface_context);
m_presentPicture->view = reinterpret_cast<ID3D11View*>(frame->data[3]);
m_presentPicture->format = m_format.OutputFormat;
m_surface_context->MarkRender(m_presentPicture->view);
return CDVDVideoCodec::VC_PICTURE;
}
Expand All @@ -975,10 +976,9 @@ CDVDVideoCodec::VCReturn CDecoder::Decode(AVCodecContext* avctx, AVFrame* frame)

bool CDecoder::GetPicture(AVCodecContext* avctx, VideoPicture* picture)
{
((ICallbackHWAccel*)avctx->opaque)->GetPictureCommon(picture);
static_cast<ICallbackHWAccel*>(avctx->opaque)->GetPictureCommon(picture);
CSingleLock lock(m_section);

m_presentPicture->extFormat = (unsigned int)m_format.OutputFormat;
picture->hwPic = m_presentPicture;
picture->format = RENDER_FMT_DXVA;

Expand Down
2 changes: 1 addition & 1 deletion xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class CRenderPicture
CRenderPicture(CSurfaceContext *context);
~CRenderPicture();
ID3D11View* view;
unsigned int extFormat;
DXGI_FORMAT format;

protected:
CSurfaceContext *surface_context;
Expand Down
29 changes: 11 additions & 18 deletions xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/DXVAHD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "DXVAHD.h"
#include "cores/VideoPlayer/VideoRenderers/RenderManager.h"
#include "cores/VideoPlayer/VideoRenderers/RenderFlags.h"
#include "settings/AdvancedSettings.h"
#include "settings/MediaSettings.h"
#include "utils/Log.h"
#include "utils/win32/memcpy_sse2.h"
Expand Down Expand Up @@ -86,11 +85,6 @@ void CProcessorHD::Close()
m_eViewType = PROCESSOR_VIEW_TYPE_UNKNOWN;
}

bool CProcessorHD::UpdateSize(const DXVA2_VideoDesc& dsc)
{
return true;
}

bool CProcessorHD::PreInit()
{
SAFE_RELEASE(m_pVideoDevice);
Expand Down Expand Up @@ -240,7 +234,7 @@ bool CProcessorHD::InitProcessor()
return true;
}

bool DXVA::CProcessorHD::IsFormatSupported(DXGI_FORMAT format, D3D11_VIDEO_PROCESSOR_FORMAT_SUPPORT support)
bool DXVA::CProcessorHD::IsFormatSupported(DXGI_FORMAT format, D3D11_VIDEO_PROCESSOR_FORMAT_SUPPORT support) const
{
UINT uiFlags;
if (S_OK == m_pEnumerator->CheckVideoProcessorFormat(format, &uiFlags))
Expand All @@ -253,15 +247,15 @@ bool DXVA::CProcessorHD::IsFormatSupported(DXGI_FORMAT format, D3D11_VIDEO_PROCE
return false;
}

bool CProcessorHD::ConfigureProcessor(unsigned int format, unsigned int extended_format)
bool CProcessorHD::ConfigureProcessor(unsigned int format, DXGI_FORMAT dxva_format)
{
// check default output format DXGI_FORMAT_B8G8R8A8_UNORM (as render target)
if (!IsFormatSupported(DXGI_FORMAT_B8G8R8A8_UNORM, D3D11_VIDEO_PROCESSOR_FORMAT_SUPPORT_OUTPUT))
return false;

if (format == RENDER_FMT_DXVA)
{
m_textureFormat = (DXGI_FORMAT)extended_format;
m_textureFormat = dxva_format;
m_eViewType = PROCESSOR_VIEW_TYPE_DECODER;
}
else
Expand All @@ -286,7 +280,7 @@ bool CProcessorHD::ConfigureProcessor(unsigned int format, unsigned int extended
return true;
}

bool CProcessorHD::Open(UINT width, UINT height, unsigned int flags, unsigned int format, unsigned int extended_format)
bool CProcessorHD::Open(UINT width, UINT height, unsigned int flags, unsigned int format, DXGI_FORMAT dxva_format)
{
Close();

Expand All @@ -300,7 +294,7 @@ bool CProcessorHD::Open(UINT width, UINT height, unsigned int flags, unsigned in
if (!InitProcessor())
return false;

if (!ConfigureProcessor(m_renderFormat, extended_format))
if (!ConfigureProcessor(m_renderFormat, dxva_format))
return false;

return OpenProcessor();
Expand Down Expand Up @@ -335,7 +329,6 @@ bool CProcessorHD::OpenProcessor()
CLog::Log(LOGDEBUG, "%s: Creating processor with input format: (%d).", __FUNCTION__, m_textureFormat);

// create processor
// There is a MSFT bug when creating processor it might throw first-chance exception
HRESULT hr = m_pVideoDevice->CreateVideoProcessor(m_pEnumerator, m_procIndex, &m_pVideoProcessor);
if (FAILED(hr))
{
Expand All @@ -356,7 +349,7 @@ bool CProcessorHD::OpenProcessor()
m_pVideoContext->VideoProcessorSetStreamColorSpace(m_pVideoProcessor, DEFAULT_STREAM_INDEX, &cs);

// Output background color (black)
D3D11_VIDEO_COLOR color = {};
D3D11_VIDEO_COLOR color;
color.YCbCr = { 0.0625f, 0.5f, 0.5f, 1.0f }; // black color
m_pVideoContext->VideoProcessorSetOutputBackgroundColor(m_pVideoProcessor, TRUE, &color);

Expand All @@ -375,7 +368,7 @@ bool CProcessorHD::CreateSurfaces()
pivd.Texture2D.ArraySlice = 0;
pivd.Texture2D.MipSlice = 0;

ID3D11VideoProcessorInputView* views[32] = { 0 };
ID3D11VideoProcessorInputView* views[32] = { nullptr };
CLog::Log(LOGDEBUG, "%s - Creating %d processor surfaces with format %d.", __FUNCTION__, m_size, m_textureFormat);

for (idx = 0; idx < m_size; idx++)
Expand All @@ -395,7 +388,7 @@ bool CProcessorHD::CreateSurfaces()
{
// something goes wrong
CLog::Log(LOGERROR, "%s: Failed to create processor surfaces.", __FUNCTION__);
for (unsigned idx = 0; idx < m_size; idx++)
for (idx = 0; idx < m_size; idx++)
{
SAFE_RELEASE(views[idx]);
}
Expand Down Expand Up @@ -474,7 +467,7 @@ CRenderPicture *CProcessorHD::Convert(VideoPicture &picture)
return pic;
}

bool CProcessorHD::ApplyFilter(D3D11_VIDEO_PROCESSOR_FILTER filter, int value, int min, int max, int def)
bool CProcessorHD::ApplyFilter(D3D11_VIDEO_PROCESSOR_FILTER filter, int value, int min, int max, int def) const
{
if (filter >= NUM_FILTERS)
return false;
Expand All @@ -497,7 +490,7 @@ bool CProcessorHD::ApplyFilter(D3D11_VIDEO_PROCESSOR_FILTER filter, int value, i
return true;
}

ID3D11VideoProcessorInputView* CProcessorHD::GetInputView(ID3D11View* view)
ID3D11VideoProcessorInputView* CProcessorHD::GetInputView(ID3D11View* view) const
{
ID3D11VideoProcessorInputView* inputView = nullptr;
if (m_eViewType == PROCESSOR_VIEW_TYPE_PROCESSOR)
Expand All @@ -520,7 +513,7 @@ ID3D11VideoProcessorInputView* CProcessorHD::GetInputView(ID3D11View* view)
decoderView->GetDesc(&vdovd);
decoderView->GetResource(&resource);

D3D11_VIDEO_PROCESSOR_INPUT_VIEW_DESC vpivd = { { 0 } };
D3D11_VIDEO_PROCESSOR_INPUT_VIEW_DESC vpivd;
vpivd.FourCC = 0;
vpivd.ViewDimension = D3D11_VPIV_DIMENSION_TEXTURE2D;
vpivd.Texture2D.ArraySlice = vdovd.Texture2D.ArraySlice;
Expand Down
17 changes: 7 additions & 10 deletions xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/DXVAHD.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
#pragma once

#include <dxva2api.h>
#include <vector>
#include "DVDCodecs/Video/DVDVideoCodecFFmpeg.h"
#include "DVDCodecs/Video/DXVA.h"
Expand Down Expand Up @@ -54,12 +53,12 @@ class CProcessorHD : public ID3DResource

bool PreInit();
void UnInit();
bool Open(UINT width, UINT height, unsigned int flags, unsigned int format, unsigned int extended_format);
bool Open(UINT width, UINT height, unsigned int flags, unsigned int format, DXGI_FORMAT dxva_format);
void Close();
CRenderPicture *Convert(VideoPicture &picture);
bool Render(CRect src, CRect dst, ID3D11Resource* target, ID3D11View **views, DWORD flags, UINT frameIdx, UINT rotation);
uint8_t Size() { if (m_pVideoProcessor) return m_size; return 0; }
uint8_t PastRefs() { return m_max_back_refs; }
uint8_t Size() const { if (m_pVideoProcessor) return m_size; return 0; }
uint8_t PastRefs() const { return m_max_back_refs; }
void ApplySupportedFormats(std::vector<ERenderFormat> * formats);

// ID3DResource overrides
Expand All @@ -69,15 +68,14 @@ class CProcessorHD : public ID3DResource
void OnResetDevice() override { CSingleLock lock(m_section); Close(); }

protected:
bool UpdateSize(const DXVA2_VideoDesc& dsc);
bool ReInit();
bool InitProcessor();
bool ConfigureProcessor(unsigned int format, unsigned int extended_format);
bool ConfigureProcessor(unsigned int format, DXGI_FORMAT dxva_format);
bool OpenProcessor();
bool CreateSurfaces();
bool ApplyFilter(D3D11_VIDEO_PROCESSOR_FILTER filter, int value, int min, int max, int def);
ID3D11VideoProcessorInputView* GetInputView(ID3D11View* view);
bool IsFormatSupported(DXGI_FORMAT format, D3D11_VIDEO_PROCESSOR_FORMAT_SUPPORT support);
bool ApplyFilter(D3D11_VIDEO_PROCESSOR_FILTER filter, int value, int min, int max, int def) const;
ID3D11VideoProcessorInputView* GetInputView(ID3D11View* view) const;
bool IsFormatSupported(DXGI_FORMAT format, D3D11_VIDEO_PROCESSOR_FORMAT_SUPPORT support) const;

uint32_t m_width;
uint32_t m_height;
Expand All @@ -94,7 +92,6 @@ class CProcessorHD : public ID3DResource
};
ProcAmpInfo m_Filters[NUM_FILTERS];

// dx 11
DXGI_FORMAT m_textureFormat;
ID3D11VideoDevice *m_pVideoDevice;
ID3D11VideoContext *m_pVideoContext;
Expand Down
12 changes: 6 additions & 6 deletions xbmc/cores/VideoPlayer/VideoRenderers/WinRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ CWinRenderer::CWinRenderer()

m_colorShader = nullptr;
m_scalerShader = nullptr;
m_extended_format = 0;
m_dxva_format = DXGI_FORMAT_UNKNOWN;

m_iRequestedMethod = RENDER_METHOD_AUTO;

Expand Down Expand Up @@ -127,7 +127,7 @@ bool CWinRenderer::ConfigChanged(void *hwPic)
if (m_format == RENDER_FMT_DXVA)
{
DXVA::CRenderPicture *dxvaPic = static_cast<DXVA::CRenderPicture*>(hwPic);
if (dxvaPic->extFormat != m_extended_format)
if (dxvaPic->format != m_dxva_format)
return true;
}

Expand Down Expand Up @@ -162,7 +162,7 @@ void CWinRenderer::SelectRenderMethod()
{
CLog::Log(LOGNOTICE, "D3D: rendering method forced to DXVA processor");
m_renderMethod = RENDER_DXVA;
if (!m_processor || !m_processor->Open(m_sourceWidth, m_sourceHeight, m_iFlags, m_format, m_extended_format))
if (!m_processor || !m_processor->Open(m_sourceWidth, m_sourceHeight, m_iFlags, m_format, m_dxva_format))
{
CLog::Log(LOGNOTICE, "D3D: unable to open DXVA processor");
if (m_processor)
Expand All @@ -177,7 +177,7 @@ void CWinRenderer::SelectRenderMethod()
switch(m_iRequestedMethod)
{
case RENDER_METHOD_DXVA:
if (!m_processor || !m_processor->Open(m_sourceWidth, m_sourceHeight, m_iFlags, m_format, m_extended_format))
if (!m_processor || !m_processor->Open(m_sourceWidth, m_sourceHeight, m_iFlags, m_format, m_dxva_format))
{
CLog::Log(LOGNOTICE, "D3D: unable to open DXVA processor");
if (m_processor)
Expand Down Expand Up @@ -238,7 +238,7 @@ bool CWinRenderer::Configure(unsigned int width, unsigned int height, unsigned i
m_iFlags = flags;
m_format = format;
if (format == RENDER_FMT_DXVA)
m_extended_format = dxvaPic->extFormat;
m_dxva_format = dxvaPic->format;

// calculate the input frame aspect ratio
CalculateFrameAspectRatio(d_width, d_height);
Expand Down Expand Up @@ -1113,7 +1113,7 @@ CRenderInfo CWinRenderer::GetRenderInfo()
if (m_renderMethod == RENDER_DXVA && m_processor)
{
info.optimal_buffer_size = m_processor->Size();
if (m_extended_format != RENDER_FMT_DXVA)
if (m_format != RENDER_FMT_DXVA)
info.m_deintMethods.push_back(VS_INTERLACEMETHOD_DXVA_AUTO);
}
else
Expand Down
2 changes: 1 addition & 1 deletion xbmc/cores/VideoPlayer/VideoRenderers/WinRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class CWinRenderer : public CBaseRenderer

bool m_bFilterInitialized;
int m_iRequestedMethod;
unsigned int m_extended_format;
DXGI_FORMAT m_dxva_format;

// Width and height of the render target
// the separable HQ scalers need this info, but could the m_destRect be used instead?
Expand Down

0 comments on commit a49c239

Please sign in to comment.