Line data Source code
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 peerconnectionctx_h___h__
6 : #define peerconnectionctx_h___h__
7 :
8 : #include <string>
9 :
10 : #include "WebrtcGlobalChild.h"
11 :
12 : #include "mozilla/Attributes.h"
13 : #include "mozilla/StaticPtr.h"
14 : #include "PeerConnectionImpl.h"
15 : #include "mozIGeckoMediaPluginService.h"
16 : #include "nsIRunnable.h"
17 :
18 : namespace mozilla {
19 : class PeerConnectionCtxObserver;
20 :
21 : namespace dom {
22 : class WebrtcGlobalInformation;
23 : }
24 :
25 : // A class to hold some of the singleton objects we need:
26 : // * The global PeerConnectionImpl table and its associated lock.
27 : // * Stats report objects for PCs that are gone
28 : // * GMP related state
29 : class PeerConnectionCtx {
30 : public:
31 : static nsresult InitializeGlobal(nsIThread *mainThread, nsIEventTarget *stsThread);
32 : static PeerConnectionCtx* GetInstance();
33 : static bool isActive();
34 : static void Destroy();
35 :
36 0 : bool isReady() {
37 : // If mGMPService is not set, we aren't using GMP.
38 0 : if (mGMPService) {
39 0 : return mGMPReady;
40 : }
41 0 : return true;
42 : }
43 :
44 : void queueJSEPOperation(nsIRunnable* aJSEPOperation);
45 : void onGMPReady();
46 :
47 : bool gmpHasH264();
48 :
49 : static void UpdateNetworkState(bool online);
50 :
51 : // Make these classes friend so that they can access mPeerconnections.
52 : friend class PeerConnectionImpl;
53 : friend class PeerConnectionWrapper;
54 : friend class mozilla::dom::WebrtcGlobalInformation;
55 :
56 : // WebrtcGlobalInformation uses this; we put it here so we don't need to
57 : // create another shutdown observer class.
58 : mozilla::dom::Sequence<mozilla::dom::RTCStatsReportInternal>
59 : mStatsForClosedPeerConnections;
60 :
61 : const std::map<const std::string, PeerConnectionImpl *>& mGetPeerConnections();
62 : private:
63 : // We could make these available only via accessors but it's too much trouble.
64 : std::map<const std::string, PeerConnectionImpl *> mPeerConnections;
65 :
66 0 : PeerConnectionCtx() : mGMPReady(false) {}
67 : // This is a singleton, so don't copy construct it, etc.
68 : PeerConnectionCtx(const PeerConnectionCtx& other) = delete;
69 : void operator=(const PeerConnectionCtx& other) = delete;
70 : virtual ~PeerConnectionCtx();
71 :
72 : nsresult Initialize();
73 : nsresult Cleanup();
74 :
75 : void initGMP();
76 :
77 : static void
78 : EverySecondTelemetryCallback_m(nsITimer* timer, void *);
79 :
80 : nsCOMPtr<nsITimer> mTelemetryTimer;
81 :
82 : public:
83 : // TODO(jib): If we ever enable move semantics on std::map...
84 : //std::map<nsString,nsAutoPtr<mozilla::dom::RTCStatsReportInternal>> mLastReports;
85 : nsTArray<nsAutoPtr<mozilla::dom::RTCStatsReportInternal>> mLastReports;
86 : private:
87 :
88 : // We cannot form offers/answers properly until the Gecko Media Plugin stuff
89 : // has been initted, which is a complicated mess of thread dispatches,
90 : // including sync dispatches to main. So, we need to be able to queue up
91 : // offer creation (or SetRemote, when we're the answerer) until all of this is
92 : // ready to go, since blocking on this init is just begging for deadlock.
93 : nsCOMPtr<mozIGeckoMediaPluginService> mGMPService;
94 : bool mGMPReady;
95 : nsTArray<nsCOMPtr<nsIRunnable>> mQueuedJSEPOperations;
96 :
97 : static PeerConnectionCtx *gInstance;
98 : public:
99 : static nsIThread *gMainThread;
100 : static mozilla::StaticRefPtr<mozilla::PeerConnectionCtxObserver> gPeerConnectionCtxObserver;
101 : };
102 :
103 : } // namespace mozilla
104 :
105 : #endif
|