DXVA2Manager.h (4225B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 #if !defined(DXVA2Manager_h_) 7 # define DXVA2Manager_h_ 8 9 # include "D3D11TextureWrapper.h" 10 # include "MediaInfo.h" 11 # include "WMF.h" 12 # include "d3d11.h" 13 # include "mozilla/Mutex.h" 14 # include "mozilla/gfx/Rect.h" 15 16 namespace mozilla { 17 18 namespace layers { 19 class Image; 20 class ImageContainer; 21 class KnowsCompositor; 22 } // namespace layers 23 24 enum class DXVA2Usage { Playback, ColorConversionOnly }; 25 26 class DXVA2Manager { 27 public: 28 // Creates and initializes a DXVA2Manager. We can use DXVA2 via D3D11. 29 static DXVA2Manager* CreateD3D11DXVA( 30 layers::KnowsCompositor* aKnowsCompositor, nsACString& aFailureReason, 31 ID3D11Device* aDevice = nullptr, 32 DXVA2Usage aUsage = DXVA2Usage::Playback); 33 34 // Returns a pointer to the D3D device manager responsible for managing the 35 // device we're using for hardware accelerated video decoding. For D3D11 this 36 // is an IMFDXGIDeviceManager. It is safe to call this on any thread. 37 virtual IUnknown* GetDXVADeviceManager() = 0; 38 39 // Copy the video frame into a share handle image. 40 virtual HRESULT CopyToImage(IMFSample* aVideoSample, 41 const gfx::IntRect& aRegion, 42 layers::Image** aOutImage) = 0; 43 virtual HRESULT CopyToImage(ID3D11Texture2D* aInputTexture, 44 UINT aSurfaceIndex, const gfx::IntRect& aRegion, 45 layers::Image** aOutImage) = 0; 46 47 virtual HRESULT WrapTextureWithImage(IMFSample* aVideoSample, 48 const gfx::IntRect& aRegion, 49 layers::Image** aOutImage) { 50 // Not implemented! 51 MOZ_CRASH("WrapTextureWithImage not implemented on this manager."); 52 return E_FAIL; 53 } 54 55 virtual HRESULT WrapTextureWithImage(D3D11TextureWrapper* aTextureWrapper, 56 const gfx::IntRect& aRegion, 57 layers::Image** aOutImage) { 58 // Not implemented! 59 MOZ_CRASH("WrapTextureWithImage not implemented on this manager."); 60 return E_FAIL; 61 } 62 63 virtual HRESULT ConfigureForSize(IMFMediaType* aInputType, 64 gfx::YUVColorSpace aColorSpace, 65 gfx::ColorRange aColorRange, 66 gfx::ColorDepth aColorDepth, 67 gfx::TransferFunction aTransferFunction, 68 uint32_t aWidth, uint32_t aHeight) { 69 return S_OK; 70 } 71 virtual HRESULT ConfigureForSize(gfx::SurfaceFormat aSurfaceFormat, 72 gfx::YUVColorSpace aColorSpace, 73 gfx::ColorRange aColorRange, 74 gfx::ColorDepth aColorDepth, 75 gfx::TransferFunction aTransferFunction, 76 uint32_t aWidth, uint32_t aHeight) { 77 // Not implemented! 78 MOZ_CRASH("ConfigureForSize not implemented on this manager."); 79 return E_FAIL; 80 } 81 82 virtual bool IsD3D11() { return false; } 83 84 virtual ~DXVA2Manager(); 85 86 virtual bool SupportsConfig(const VideoInfo& aInfo, IMFMediaType* aInputType, 87 IMFMediaType* aOutputType) = 0; 88 89 // Called before shutdown video MFTDecoder. 90 virtual void BeforeShutdownVideoMFTDecoder() {} 91 92 virtual bool SupportsZeroCopyNV12Texture() { return false; } 93 94 static bool IsNV12Supported(uint32_t aVendorID, uint32_t aDeviceID, 95 const nsAString& aDriverVersionString); 96 97 virtual ID3D11Device* GetD3D11Device() { return nullptr; } 98 99 protected: 100 Mutex mLock MOZ_UNANNOTATED; 101 DXVA2Manager(); 102 103 bool IsUnsupportedResolution(const uint32_t& aWidth, const uint32_t& aHeight, 104 const float& aFramerate) const; 105 106 bool mIsAMDPreUVD4 = false; 107 }; 108 109 } // namespace mozilla 110 111 #endif // DXVA2Manager_h_