VALibWrapper.h (2642B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef DOM_MEDIA_PLATFORMS_FFMPEG_VALIBWRAPPER_H_ 6 #define DOM_MEDIA_PLATFORMS_FFMPEG_VALIBWRAPPER_H_ 7 8 #include "mozilla/Attributes.h" 9 #include "mozilla/UniquePtrExtensions.h" 10 #include "nsISupportsImpl.h" 11 12 struct PRLibrary; 13 14 #ifdef MOZ_WIDGET_GTK 15 16 // Forward declare from va.h 17 typedef void* VADisplay; 18 typedef int VAStatus; 19 # define VA_EXPORT_SURFACE_READ_ONLY 0x0001 20 # define VA_EXPORT_SURFACE_SEPARATE_LAYERS 0x0004 21 # define VA_STATUS_SUCCESS 0x00000000 22 23 namespace mozilla { 24 25 class MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS VALibWrapper { 26 public: 27 // The class is used only in static storage and so is zero initialized. 28 VALibWrapper() = default; 29 // The libraries are not unloaded in the destructor, because doing so would 30 // require a static constructor to register the static destructor. As the 31 // class is in static storage, the destructor would only run on shutdown 32 // anyway. 33 ~VALibWrapper() = default; 34 35 // Check if sVALib and sVALibDrm are available with necessary symbols and 36 // initialize sFuncs; 37 static bool IsVAAPIAvailable(); 38 static VALibWrapper sFuncs; 39 40 private: 41 void Link(); 42 bool AreVAAPIFuncsAvailable(); 43 // Attempt to load libva-drm and libva and resolve necessary symbols. 44 // Upon failure, the entire object will be reset and any attached libraries 45 // will be unlinked. Do not invoke more than once. 46 bool LinkVAAPILibs(); 47 48 public: 49 int (*vaExportSurfaceHandle)(void*, unsigned int, uint32_t, uint32_t, void*); 50 int (*vaSyncSurface)(void*, unsigned int); 51 52 private: 53 PRLibrary* mVALib; 54 PRLibrary* mVALibDrm; 55 }; 56 57 class VADisplayHolder { 58 public: 59 NS_INLINE_DECL_THREADSAFE_REFCOUNTING_WITH_DESTROY(VADisplayHolder, 60 MaybeDestroy()) 61 62 static RefPtr<VADisplayHolder> GetSingleton(); 63 64 VADisplay Display() const { return mDisplay.get(); } 65 66 private: 67 struct VADisplayDeleter { 68 using pointer = VADisplay; 69 void operator()(VADisplay aDisplay); 70 }; 71 using UniqueVADisplay = std::unique_ptr<VADisplay, VADisplayDeleter>; 72 73 VADisplayHolder(UniqueVADisplay aDisplay, UniqueFileHandle aDRMFd); 74 ~VADisplayHolder(); 75 76 void MaybeDestroy(); 77 78 // mDRMFd is declared before mDisplay, so that mDRMFd is closed after 79 // mDisplay is terminated. 80 const UniqueFileHandle mDRMFd; 81 const UniqueVADisplay mDisplay; 82 }; 83 84 } // namespace mozilla 85 #endif // MOZ_WIDGET_GTK 86 87 #endif // DOM_MEDIA_PLATFORMS_FFMPEG_VALIBWRAPPER_H_