#pragma once #include "renderer.h" #include #include extern "C" { #include } #include class D3D11VARenderer : public IFFmpegRenderer { public: D3D11VARenderer(int decoderSelectionPass); virtual ~D3D11VARenderer() override; virtual bool initialize(PDECODER_PARAMETERS params) override; virtual bool prepareDecoderContext(AVCodecContext* context, AVDictionary**) override; virtual bool prepareDecoderContextInGetFormat(AVCodecContext* context, AVPixelFormat pixelFormat) override; virtual void renderFrame(AVFrame* frame) override; virtual void notifyOverlayUpdated(Overlay::OverlayType) override; virtual int getRendererAttributes() override; virtual int getDecoderCapabilities() override; virtual bool needsTestFrame() override; virtual InitFailureReason getInitFailureReason() override; enum PixelShaders { GENERIC_YUV_420, BT_601_LIMITED_YUV_420, BT_2020_LIMITED_YUV_420, GENERIC_AYUV, GENERIC_Y410, _COUNT }; private: static void lockContext(void* lock_ctx); static void unlockContext(void* lock_ctx); bool setupRenderingResources(); std::vector getVideoTextureSRVFormats(); bool setupVideoTexture(); // for !m_BindDecoderOutputTextures bool setupTexturePoolViews(AVD3D11VAFramesContext* frameContext); // for m_BindDecoderOutputTextures void renderOverlay(Overlay::OverlayType type); void bindColorConversion(AVFrame* frame); void renderVideo(AVFrame* frame); bool checkDecoderSupport(IDXGIAdapter* adapter); bool createDeviceByAdapterIndex(int adapterIndex, bool* adapterNotFound = nullptr); int m_DecoderSelectionPass; int m_DevicesWithFL11Support; int m_DevicesWithCodecSupport; Microsoft::WRL::ComPtr m_Factory; Microsoft::WRL::ComPtr m_Device; Microsoft::WRL::ComPtr m_SwapChain; Microsoft::WRL::ComPtr m_DeviceContext; Microsoft::WRL::ComPtr m_RenderTargetView; SDL_mutex* m_ContextLock; bool m_BindDecoderOutputTextures; DECODER_PARAMETERS m_DecoderParams; int m_TextureAlignment; DXGI_FORMAT m_TextureFormat; int m_DisplayWidth; int m_DisplayHeight; int m_LastColorSpace; bool m_LastFullRange; AVColorTransferCharacteristic m_LastColorTrc; bool m_AllowTearing; std::array, PixelShaders::_COUNT> m_VideoPixelShaders; Microsoft::WRL::ComPtr m_VideoVertexBuffer; // Only valid if !m_BindDecoderOutputTextures Microsoft::WRL::ComPtr m_VideoTexture; // Only index 0 is valid if !m_BindDecoderOutputTextures #define DECODER_BUFFER_POOL_SIZE 17 std::array, 2>, DECODER_BUFFER_POOL_SIZE> m_VideoTextureResourceViews; SDL_SpinLock m_OverlayLock; std::array, Overlay::OverlayMax> m_OverlayVertexBuffers; std::array, Overlay::OverlayMax> m_OverlayTextures; std::array, Overlay::OverlayMax> m_OverlayTextureResourceViews; Microsoft::WRL::ComPtr m_OverlayPixelShader; AVBufferRef* m_HwDeviceContext; AVBufferRef* m_HwFramesContext; };