11 #include "cores/VideoPlayer/Buffers/VideoBuffer.h" 12 #include "cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodec.h" 13 #include "guilib/D3DResource.h" 14 #include "threads/Event.h" 20 #include <wrl/client.h> 23 #include <libavcodec/avcodec.h> 24 #include <libavcodec/d3d11va.h> 33 template<
typename TBuffer>
39 void SetRef(AVFrame* frame);
42 virtual void Initialize(
CDecoder* decoder);
43 virtual HRESULT GetResource(ID3D11Resource** ppResource);
44 virtual unsigned GetIdx();
46 ID3D11View* view =
nullptr;
47 DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN;
55 AVFrame* m_pFrame{
nullptr};
60 template<
typename TBuffer>
64 HRESULT GetResource(ID3D11Resource** ppResource)
override;
65 void Initialize(
CDecoder* decoder)
override;
71 void InitializeFence(
CDecoder* decoder);
74 HANDLE handle = INVALID_HANDLE_VALUE;
75 Microsoft::WRL::ComPtr<ID3D11Resource> m_sharedRes;
78 Microsoft::WRL::ComPtr<ID3D11Fence>
m_fence;
82 HANDLE m_handleFence{INVALID_HANDLE_VALUE};
83 UINT64 m_fenceValue{0};
92 template<
typename TBuffer>
96 void Initialize(
CDecoder* decoder)
override;
97 unsigned GetIdx()
override {
return 0; }
103 Microsoft::WRL::ComPtr<ID3D11Resource> m_copyRes;
104 Microsoft::WRL::ComPtr<ID3D11Resource> m_pResource;
105 Microsoft::WRL::ComPtr<ID3D11DeviceContext> m_pDeviceContext;
111 typedef std::shared_ptr<CContext> shared_ptr;
112 typedef std::weak_ptr<CContext> weak_ptr;
116 static shared_ptr EnsureContext(
CDecoder* decoder);
117 bool GetFormatAndConfig(AVCodecContext* avctx, D3D11_VIDEO_DECODER_DESC& format, D3D11_VIDEO_DECODER_CONFIG&
config)
const;
118 bool CreateSurfaces(
const D3D11_VIDEO_DECODER_DESC& format, uint32_t count, uint32_t alignment,
119 ID3D11VideoDecoderOutputView** surfaces,
HANDLE* pHandle,
bool trueShared)
const;
120 bool CreateDecoder(
const D3D11_VIDEO_DECODER_DESC& format,
const D3D11_VIDEO_DECODER_CONFIG& config,
121 ID3D11VideoDecoder** decoder, ID3D11VideoContext** context);
126 bool IsContextShared()
const 128 return m_sharingAllowed;
130 bool HasAMDWorkaround()
const 132 return m_atiWorkaround;
139 bool CreateContext();
140 void DestroyContext();
142 bool IsValidDecoder(
CDecoder* decoder);
143 bool GetConfig(
const D3D11_VIDEO_DECODER_DESC& format, D3D11_VIDEO_DECODER_CONFIG& config)
const;
145 static weak_ptr m_context;
146 static CCriticalSection m_section;
148 UINT m_input_count = 0;
149 GUID* m_input_list =
nullptr;
150 bool m_atiWorkaround =
false;
151 bool m_sharingAllowed =
false;
152 Microsoft::WRL::ComPtr<ID3D11VideoContext> m_pD3D11Context;
153 Microsoft::WRL::ComPtr<ID3D11VideoDevice> m_pD3D11Device;
155 Microsoft::WRL::ComPtr<ID3D11Debug> m_d3d11Debug;
158 std::vector<CDecoder*> m_decoders;
164 typedef std::shared_ptr<CVideoBufferPool> shared_ptr;
171 void Return(
int id)
override;
174 void AddView(ID3D11View* view);
175 bool ReturnView(ID3D11View* view);
176 ID3D11View* GetView();
177 bool IsValid(ID3D11View* view);
185 CCriticalSection m_section;
187 std::vector<ID3D11View*> m_views;
188 std::deque<size_t> m_freeViews;
189 std::vector<CVideoBuffer*> m_out;
190 std::deque<size_t> m_freeOut;
193 template<
typename TBuffer>
199 return new TBuffer(idx);
209 static bool Register();
212 bool Open(AVCodecContext* avctx, AVCodecContext* mainctx,
const enum AVPixelFormat)
override;
213 CDVDVideoCodec::VCReturn Decode(AVCodecContext* avctx, AVFrame* frame)
override;
214 bool GetPicture(AVCodecContext* avctx,
VideoPicture* picture)
override;
215 CDVDVideoCodec::VCReturn Check(AVCodecContext* avctx)
override;
216 const std::string Name()
override {
return "d3d11va"; }
217 unsigned GetAllowedReferences()
override;
218 void Reset()
override;
221 int GetBuffer(AVCodecContext* avctx, AVFrame* pic);
222 void ReleaseBuffer(uint8_t* data);
224 void CloseDXVADecoder();
227 static bool Supports(
enum AVPixelFormat fmt);
228 static int FFGetBuffer(AVCodecContext* avctx, AVFrame* pic,
int flags);
229 static void FFReleaseBuffer(
void* opaque, uint8_t* data);
243 } m_state = DXVA_OPEN;
247 void OnCreateDevice()
override 249 std::unique_lock<CCriticalSection> lock(m_section);
250 m_state = DXVA_RESET;
253 void OnDestroyDevice(
bool fatal)
override 255 std::unique_lock<CCriticalSection> lock(m_section);
261 CCriticalSection m_section;
263 Microsoft::WRL::ComPtr<ID3D11VideoDecoder> m_pD3D11Decoder;
264 Microsoft::WRL::ComPtr<ID3D11VideoContext> m_pD3D11Context;
265 CVideoBufferPool::shared_ptr m_bufferPool;
266 CContext::shared_ptr m_dxvaContext;
268 struct AVD3D11VAContext* m_avD3D11Context =
nullptr;
270 unsigned int m_shared = 0;
271 unsigned int m_surface_alignment = 0;
272 HANDLE m_sharedHandle = INVALID_HANDLE_VALUE;
273 D3D11_VIDEO_DECODER_DESC m_format = {};
274 bool m_DVDWorkaround =
false;
This is an Event class built from a ConditionVariable.
Definition: Event.h:35
Definition: DVDStreamInfo.h:25
Definition: deflate.c:123
Microsoft::WRL::ComPtr< ID3D11Fence > m_appFence
app-side fence object
Definition: DXVA.h:85
Definition: DVDVideoCodec.h:248
Definition: VideoBuffer.h:51
Microsoft::WRL::ComPtr< ID3D11DeviceContext4 > m_deviceContext4
decoder-side context
Definition: DXVA.h:80
Microsoft::WRL::ComPtr< ID3D11DeviceContext4 > m_appContext4
app-side context
Definition: DXVA.h:87
Definition: ProcessInfo.h:26
Definition: D3DResource.h:36
Microsoft::WRL::ComPtr< ID3D11Fence > m_fence
decoder-side fence object
Definition: DXVA.h:78
Definition: DVDVideoCodec.h:36