2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "DVDCodecs/Video/DVDVideoCodecFFmpeg.h"
12 #include "DVDCodecs/Video/DXVA.h"
13 #include "VideoRenderers/HwDecRender/DXVAEnumeratorHD.h"
14 #include "VideoRenderers/Windows/RendererBase.h"
15 #include "guilib/D3DResource.h"
16 #include "utils/Geometry.h"
20 #include <wrl/client.h>
26 using namespace Microsoft::WRL
;
28 struct ProcColorSpaces
;
30 class CProcessorHD
: public ID3DResource
33 explicit CProcessorHD();
37 bool Open(const VideoPicture
& picture
, std::shared_ptr
<DXVA::CEnumeratorHD
> enumerator
);
39 bool Render(CRect src
, CRect dst
, ID3D11Resource
* target
, CRenderBuffer
**views
, DWORD flags
, UINT frameIdx
, UINT rotation
, float contrast
, float brightness
);
40 uint8_t PastRefs() const { return std::min(m_procCaps
.m_rateCaps
.PastFrames
, 4u); }
43 * \brief Configure the processor for the provided conversion.
44 * \param conversion the conversion
45 * \return success status, true = success, false = error
47 bool SetConversion(const ProcessorConversion
& conversion
);
49 // ID3DResource overrides
50 void OnCreateDevice() override
{}
51 void OnDestroyDevice(bool) override
53 std::unique_lock
<CCriticalSection
> lock(m_section
);
57 static bool IsSuperResolutionSuitable(const VideoPicture
& picture
);
58 void TryEnableVideoSuperResolution();
59 bool IsVideoSuperResolutionEnabled() const { return m_superResolutionEnabled
; }
60 bool Supports(ERENDERFEATURE feature
) const;
65 bool CheckFormats() const;
67 void ApplyFilter(D3D11_VIDEO_PROCESSOR_FILTER filter
, int value
, int min
, int max
, int def
) const;
68 ComPtr
<ID3D11VideoProcessorInputView
> GetInputView(CRenderBuffer
* view
) const;
70 * \brief Apply new video settings if there was a change. Returns true if a parameter changed, false otherwise.
72 bool CheckVideoParameters(const CRect
& src
,
75 const float& contrast
,
76 const float& brightness
,
77 const CRenderBuffer
& rb
);
79 void EnableIntelVideoSuperResolution();
80 void EnableNvidiaRTXVideoSuperResolution();
82 CCriticalSection m_section
;
84 ComPtr
<ID3D11VideoDevice
> m_pVideoDevice
;
85 ComPtr
<ID3D11VideoContext
> m_pVideoContext
;
86 ComPtr
<ID3D11VideoProcessor
> m_pVideoProcessor
;
87 std::shared_ptr
<CEnumeratorHD
> m_enumerator
;
89 AVColorPrimaries m_color_primaries
{AVCOL_PRI_UNSPECIFIED
};
90 AVColorTransferCharacteristic m_color_transfer
{AVCOL_TRC_UNSPECIFIED
};
91 ProcessorCapabilities m_procCaps
;
93 bool m_superResolutionEnabled
{false};
94 ProcessorConversion m_conversion
;
95 bool m_isValidConversion
{false};
98 * \brief true when at least one frame has been processed successfully since init
100 bool m_configured
{false};
102 // Members to compare the current frame with the previous frame
103 UINT m_lastInputFrameOrField
{0};
104 UINT m_lastOutputIndex
{0};
107 UINT m_lastRotation
{0};
108 float m_lastContrast
{.0f
};
109 float m_lastBrightness
{.0f
};
110 ProcessorConversion m_lastConversion
{};
111 AVColorSpace m_lastColorSpace
{AVCOL_SPC_UNSPECIFIED
};
112 bool m_lastFullRange
{false};