Line data Source code
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 GMPContentParent_h_
7 : #define GMPContentParent_h_
8 :
9 : #include "mozilla/gmp/PGMPContentParent.h"
10 : #include "GMPSharedMemManager.h"
11 : #include "nsISupportsImpl.h"
12 :
13 : namespace mozilla {
14 : namespace gmp {
15 :
16 : class GMPDecryptorParent;
17 : class GMPParent;
18 : class GMPVideoDecoderParent;
19 : class GMPVideoEncoderParent;
20 : class ChromiumCDMParent;
21 :
22 : class GMPContentParent final : public PGMPContentParent,
23 : public GMPSharedMem
24 : {
25 : public:
26 0 : NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GMPContentParent)
27 :
28 : explicit GMPContentParent(GMPParent* aParent = nullptr);
29 :
30 : nsresult GetGMPVideoDecoder(GMPVideoDecoderParent** aGMPVD,
31 : uint32_t aDecryptorId);
32 : void VideoDecoderDestroyed(GMPVideoDecoderParent* aDecoder);
33 :
34 : nsresult GetGMPVideoEncoder(GMPVideoEncoderParent** aGMPVE);
35 : void VideoEncoderDestroyed(GMPVideoEncoderParent* aEncoder);
36 :
37 : nsresult GetGMPDecryptor(GMPDecryptorParent** aGMPKS);
38 : void DecryptorDestroyed(GMPDecryptorParent* aSession);
39 :
40 : already_AddRefed<ChromiumCDMParent> GetChromiumCDM();
41 : void ChromiumCDMDestroyed(ChromiumCDMParent* aCDM);
42 :
43 : nsCOMPtr<nsISerialEventTarget> GMPEventTarget();
44 :
45 : // GMPSharedMem
46 : void CheckThread() override;
47 :
48 0 : void SetDisplayName(const nsCString& aDisplayName)
49 : {
50 0 : mDisplayName = aDisplayName;
51 0 : }
52 0 : const nsCString& GetDisplayName()
53 : {
54 0 : return mDisplayName;
55 : }
56 0 : void SetPluginId(const uint32_t aPluginId)
57 : {
58 0 : mPluginId = aPluginId;
59 0 : }
60 0 : uint32_t GetPluginId() const
61 : {
62 0 : return mPluginId;
63 : }
64 :
65 : class CloseBlocker {
66 : public:
67 0 : NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CloseBlocker)
68 :
69 0 : explicit CloseBlocker(GMPContentParent* aParent)
70 0 : : mParent(aParent)
71 : {
72 0 : mParent->AddCloseBlocker();
73 0 : }
74 : RefPtr<GMPContentParent> mParent;
75 : private:
76 0 : ~CloseBlocker() {
77 0 : mParent->RemoveCloseBlocker();
78 0 : }
79 : };
80 :
81 : private:
82 :
83 : void AddCloseBlocker();
84 : void RemoveCloseBlocker();
85 :
86 : ~GMPContentParent();
87 :
88 : void ActorDestroy(ActorDestroyReason aWhy) override;
89 :
90 : PGMPVideoDecoderParent* AllocPGMPVideoDecoderParent(const uint32_t& aDecryptorId) override;
91 : bool DeallocPGMPVideoDecoderParent(PGMPVideoDecoderParent* aActor) override;
92 :
93 : PGMPVideoEncoderParent* AllocPGMPVideoEncoderParent() override;
94 : bool DeallocPGMPVideoEncoderParent(PGMPVideoEncoderParent* aActor) override;
95 :
96 : PGMPDecryptorParent* AllocPGMPDecryptorParent() override;
97 : bool DeallocPGMPDecryptorParent(PGMPDecryptorParent* aActor) override;
98 :
99 : PChromiumCDMParent* AllocPChromiumCDMParent() override;
100 : bool DeallocPChromiumCDMParent(PChromiumCDMParent* aActor) override;
101 :
102 : void CloseIfUnused();
103 : // Needed because NewRunnableMethod tried to use the class that the method
104 : // lives on to store the receiver, but PGMPContentParent isn't refcounted.
105 0 : void Close()
106 : {
107 0 : PGMPContentParent::Close();
108 0 : }
109 :
110 : nsTArray<RefPtr<GMPVideoDecoderParent>> mVideoDecoders;
111 : nsTArray<RefPtr<GMPVideoEncoderParent>> mVideoEncoders;
112 : nsTArray<RefPtr<GMPDecryptorParent>> mDecryptors;
113 : nsTArray<RefPtr<ChromiumCDMParent>> mChromiumCDMs;
114 : nsCOMPtr<nsISerialEventTarget> mGMPEventTarget;
115 : RefPtr<GMPParent> mParent;
116 : nsCString mDisplayName;
117 : uint32_t mPluginId;
118 : uint32_t mCloseBlockerCount = 0;
119 : };
120 :
121 : } // namespace gmp
122 : } // namespace mozilla
123 :
124 : #endif // GMPParent_h_
|