kodi
DXVAHD.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
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"
17 
18 #include <mutex>
19 
20 #include <wrl/client.h>
21 
22 class CRenderBuffer;
23 
24 namespace DXVA {
25 
26 using namespace Microsoft::WRL;
27 
28 struct ProcColorSpaces;
29 
30 class CProcessorHD : public ID3DResource
31 {
32 public:
33  explicit CProcessorHD();
34  ~CProcessorHD();
35 
36  void UnInit();
37  bool Open(const VideoPicture& picture, std::shared_ptr<DXVA::CEnumeratorHD> enumerator);
38  void Close();
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); }
41 
47  bool SetConversion(const ProcessorConversion& conversion);
48 
49  // ID3DResource overrides
50  void OnCreateDevice() override {}
51  void OnDestroyDevice(bool) override
52  {
53  std::unique_lock<CCriticalSection> lock(m_section);
54  UnInit();
55  }
56 
57  static bool IsSuperResolutionSuitable(const VideoPicture& picture);
58  void TryEnableVideoSuperResolution();
59  bool IsVideoSuperResolutionEnabled() const { return m_superResolutionEnabled; }
60  bool Supports(ERENDERFEATURE feature) const;
61 
62 protected:
63  bool ReInit();
64  bool InitProcessor();
65  bool CheckFormats() const;
66  bool OpenProcessor();
67  void ApplyFilter(D3D11_VIDEO_PROCESSOR_FILTER filter, int value, int min, int max, int def) const;
68  ComPtr<ID3D11VideoProcessorInputView> GetInputView(CRenderBuffer* view) const;
72  bool CheckVideoParameters(const CRect& src,
73  const CRect& dst,
74  const UINT& rotation,
75  const float& contrast,
76  const float& brightness,
77  const CRenderBuffer& rb);
78 
79  void EnableIntelVideoSuperResolution();
80  void EnableNvidiaRTXVideoSuperResolution();
81 
82  CCriticalSection m_section;
83 
84  ComPtr<ID3D11VideoDevice> m_pVideoDevice;
85  ComPtr<ID3D11VideoContext> m_pVideoContext;
86  ComPtr<ID3D11VideoProcessor> m_pVideoProcessor;
87  std::shared_ptr<CEnumeratorHD> m_enumerator;
88 
89  AVColorPrimaries m_color_primaries{AVCOL_PRI_UNSPECIFIED};
90  AVColorTransferCharacteristic m_color_transfer{AVCOL_TRC_UNSPECIFIED};
91  ProcessorCapabilities m_procCaps;
92 
93  bool m_superResolutionEnabled{false};
94  ProcessorConversion m_conversion;
95  bool m_isValidConversion{false};
96 
100  bool m_configured{false};
101 
102  // Members to compare the current frame with the previous frame
103  UINT m_lastInputFrameOrField{0};
104  UINT m_lastOutputIndex{0};
105  CRect m_lastSrc{};
106  CRect m_lastDst{};
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};
113 };
114 };
Definition: RendererBase.h:57
Definition: DXVA.h:27
Definition: DXVAEnumeratorHD.h:85
Definition: DXVAHD.h:30
Definition: D3DResource.h:36
Definition: DVDVideoCodec.h:36
Definition: DXVAEnumeratorHD.h:60