/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef GMPService_h_ #define GMPService_h_ #include "GMPContentParent.h" #include "GMPCrashHelper.h" #include "mozIGeckoMediaPluginService.h" #include "mozilla/Atomics.h" #include "mozilla/gmp/GMPTypes.h" #include "mozilla/MozPromise.h" #include "nsCOMPtr.h" #include "nsClassHashtable.h" #include "nsIObserver.h" #include "nsString.h" #include "nsTArray.h" class nsIAsyncShutdownClient; class nsIRunnable; class nsISerialEventTarget; class nsIThread; template struct already_AddRefed; namespace mozilla { class GMPCrashHelper; class MediaResult; extern LogModule* GetGMPLog(); namespace gmp { typedef MozPromise, MediaResult, /* IsExclusive = */ true> GetGMPContentParentPromise; typedef MozPromise, MediaResult, /* IsExclusive = */ true> GetCDMParentPromise; class GeckoMediaPluginService : public mozIGeckoMediaPluginService, public nsIObserver { public: static already_AddRefed GetGeckoMediaPluginService(); virtual nsresult Init(); NS_DECL_THREADSAFE_ISUPPORTS RefPtr GetCDM(const NodeIdParts& aNodeIdParts, nsTArray aTags, GMPCrashHelper* aHelper); // mozIGeckoMediaPluginService NS_IMETHOD GetThread(nsIThread** aThread) override; NS_IMETHOD GetDecryptingGMPVideoDecoder( GMPCrashHelper* aHelper, nsTArray* aTags, const nsACString& aNodeId, UniquePtr&& aCallback, uint32_t aDecryptorId) override; NS_IMETHOD GetGMPVideoEncoder( GMPCrashHelper* aHelper, nsTArray* aTags, const nsACString& aNodeId, UniquePtr&& aCallback) override; // Helper for backwards compatibility with WebRTC/tests. NS_IMETHOD GetGMPVideoDecoder( GMPCrashHelper* aHelper, nsTArray* aTags, const nsACString& aNodeId, UniquePtr&& aCallback) override { return GetDecryptingGMPVideoDecoder(aHelper, aTags, aNodeId, std::move(aCallback), 0); } NS_IMETHOD RunPluginCrashCallbacks(uint32_t aPluginId, const nsACString& aPluginName) override; already_AddRefed GetGMPThread(); void ConnectCrashHelper(uint32_t aPluginId, GMPCrashHelper* aHelper); void DisconnectCrashHelper(GMPCrashHelper* aHelper); bool XPCOMWillShutdownReceived() const { return mXPCOMWillShutdown; } protected: GeckoMediaPluginService(); virtual ~GeckoMediaPluginService(); virtual void InitializePlugins(nsISerialEventTarget* aGMPThread) = 0; virtual RefPtr GetContentParent( GMPCrashHelper* aHelper, const NodeIdVariant& aNodeIdVariant, const nsCString& aAPI, const nsTArray& aTags) = 0; nsresult GMPDispatch(nsIRunnable* event, uint32_t flags = NS_DISPATCH_NORMAL); nsresult GMPDispatch(already_AddRefed event, uint32_t flags = NS_DISPATCH_NORMAL); void ShutdownGMPThread(); static nsCOMPtr GetShutdownBarrier(); Mutex mMutex; // Protects mGMPThread, mPluginCrashHelpers, // mGMPThreadShutdown and some members in derived classes. const nsCOMPtr mMainThread; nsCOMPtr mGMPThread; bool mGMPThreadShutdown; bool mShuttingDownOnGMPThread; Atomic mXPCOMWillShutdown; nsClassHashtable>> mPluginCrashHelpers; }; } // namespace gmp } // namespace mozilla #endif // GMPService_h_