GMPService.h (4376B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef GMPService_h_ 7 #define GMPService_h_ 8 9 #include "GMPContentParent.h" 10 #include "GMPCrashHelper.h" 11 #include "gmp-video-codec.h" 12 #include "mozIGeckoMediaPluginService.h" 13 #include "mozilla/Atomics.h" 14 #include "mozilla/MozPromise.h" 15 #include "mozilla/gmp/GMPTypes.h" 16 #include "nsCOMPtr.h" 17 #include "nsClassHashtable.h" 18 #include "nsIObserver.h" 19 #include "nsString.h" 20 #include "nsTArray.h" 21 22 class nsIAsyncShutdownClient; 23 class nsIRunnable; 24 class nsISerialEventTarget; 25 class nsIThread; 26 27 template <class> 28 struct already_AddRefed; 29 30 namespace mozilla { 31 32 class GMPCrashHelper; 33 class MediaResult; 34 35 extern LogModule* GetGMPLog(); 36 extern LogModule* GetGMPLibraryLog(); 37 extern GMPLogLevel GetGMPLibraryLogLevel(); 38 39 namespace gmp { 40 41 using GetGMPContentParentPromise = 42 MozPromise<RefPtr<GMPContentParentCloseBlocker>, MediaResult, 43 /* IsExclusive = */ true>; 44 using GetCDMParentPromise = MozPromise<RefPtr<ChromiumCDMParent>, MediaResult, 45 /* IsExclusive = */ true>; 46 47 class GeckoMediaPluginService : public mozIGeckoMediaPluginService, 48 public nsIObserver { 49 public: 50 static already_AddRefed<GeckoMediaPluginService> GetGeckoMediaPluginService(); 51 52 virtual nsresult Init(); 53 54 NS_DECL_THREADSAFE_ISUPPORTS 55 56 RefPtr<GetCDMParentPromise> GetCDM(const NodeIdParts& aNodeIdParts, 57 const nsACString& aKeySystem, 58 GMPCrashHelper* aHelper); 59 60 #if defined(MOZ_SANDBOX) && defined(MOZ_DEBUG) && defined(ENABLE_TESTS) 61 RefPtr<GetGMPContentParentPromise> GetContentParentForTest(); 62 #endif 63 64 // mozIGeckoMediaPluginService 65 NS_IMETHOD GetThread(nsIThread** aThread) override MOZ_EXCLUDES(mMutex); 66 nsresult GetThreadLocked(nsIThread** aThread) MOZ_REQUIRES(mMutex); 67 NS_IMETHOD GetGMPVideoDecoder( 68 GMPCrashHelper* aHelper, nsTArray<nsCString>* aTags, 69 const nsACString& aNodeId, 70 UniquePtr<GetGMPVideoDecoderCallback>&& aCallback) override; 71 NS_IMETHOD GetGMPVideoEncoder( 72 GMPCrashHelper* aHelper, nsTArray<nsCString>* aTags, 73 const nsACString& aNodeId, 74 UniquePtr<GetGMPVideoEncoderCallback>&& aCallback) override; 75 76 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230) 77 MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHOD RunPluginCrashCallbacks( 78 uint32_t aPluginId, const nsACString& aPluginName) override; 79 80 already_AddRefed<nsISerialEventTarget> GetGMPThread(); 81 82 void ConnectCrashHelper(uint32_t aPluginId, GMPCrashHelper* aHelper); 83 void DisconnectCrashHelper(GMPCrashHelper* aHelper); 84 85 bool XPCOMWillShutdownReceived() const { return mXPCOMWillShutdown; } 86 87 protected: 88 GeckoMediaPluginService(); 89 virtual ~GeckoMediaPluginService(); 90 91 void AssertOnGMPThread() { 92 #ifdef DEBUG 93 MutexAutoLock lock(mMutex); 94 MOZ_ASSERT(mGMPThread->IsOnCurrentThread()); 95 #endif 96 } 97 98 virtual void InitializePlugins(nsISerialEventTarget* aGMPThread) = 0; 99 100 virtual RefPtr<GetGMPContentParentPromise> GetContentParent( 101 GMPCrashHelper* aHelper, const NodeIdVariant& aNodeIdVariant, 102 const nsACString& aAPI, const nsTArray<nsCString>& aTags) = 0; 103 104 nsresult GMPDispatch(nsIRunnable* event, nsIEventTarget::DispatchFlags flags = 105 NS_DISPATCH_NORMAL); 106 nsresult GMPDispatch( 107 already_AddRefed<nsIRunnable> event, 108 nsIEventTarget::DispatchFlags flags = NS_DISPATCH_NORMAL); 109 void ShutdownGMPThread(); 110 111 static nsCOMPtr<nsIAsyncShutdownClient> GetShutdownBarrier(); 112 113 Mutex mMutex; // Protects mGMPThread, mPluginCrashHelpers, 114 // mGMPThreadShutdown and some members in 115 // derived classes. 116 117 const nsCOMPtr<nsISerialEventTarget> mMainThread; 118 119 nsCOMPtr<nsIThread> mGMPThread MOZ_GUARDED_BY(mMutex); 120 bool mGMPThreadShutdown MOZ_GUARDED_BY(mMutex); 121 bool mShuttingDownOnGMPThread; 122 Atomic<bool> mXPCOMWillShutdown; 123 124 nsClassHashtable<nsUint32HashKey, nsTArray<RefPtr<GMPCrashHelper>>> 125 mPluginCrashHelpers MOZ_GUARDED_BY(mMutex); 126 }; 127 128 } // namespace gmp 129 } // namespace mozilla 130 131 #endif // GMPService_h_