media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.h

branch
TOR_BUG_9701
changeset 10
ac0c01689b40
equal deleted inserted replaced
-1:000000000000 0:d31927a97bfa
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 "mozilla/Attributes.h"
11 #include "CallControlManager.h"
12 #include "CC_Device.h"
13 #include "CC_DeviceInfo.h"
14 #include "CC_Call.h"
15 #include "CC_CallInfo.h"
16 #include "CC_Line.h"
17 #include "CC_LineInfo.h"
18 #include "CC_Observer.h"
19 #include "CC_FeatureInfo.h"
20 #include "cpr_stdlib.h"
21
22 #include "StaticPtr.h"
23 #include "PeerConnectionImpl.h"
24
25 namespace mozilla {
26 class PeerConnectionCtxShutdown;
27
28 namespace dom {
29 class WebrtcGlobalInformation;
30 }
31
32 // Unit-test helper, because cc_media_constraints_t is hard to forward-declare
33
34 class MediaConstraintsExternal {
35 public:
36 MediaConstraintsExternal();
37 MediaConstraintsExternal(const dom::MediaConstraintsInternal &aOther);
38 cc_media_constraints_t* build() const;
39 protected:
40 cc_media_constraints_t mConstraints;
41 };
42 }
43
44 namespace sipcc {
45
46 class OnCallEventArgs {
47 public:
48 OnCallEventArgs(ccapi_call_event_e aCallEvent, CSF::CC_CallInfoPtr aInfo)
49 : mCallEvent(aCallEvent), mInfo(aInfo) {}
50
51 ccapi_call_event_e mCallEvent;
52 CSF::CC_CallInfoPtr mInfo;
53 };
54
55 // A class to hold some of the singleton objects we need:
56 // * The global PeerConnectionImpl table and its associated lock.
57 // * Currently SIPCC only allows a single stack instance to exist in a process
58 // at once. This class implements a singleton object that wraps that.
59 // * The observer class that demuxes events onto individual PCs.
60 class PeerConnectionCtx : public CSF::CC_Observer {
61 public:
62 static nsresult InitializeGlobal(nsIThread *mainThread, nsIEventTarget *stsThread);
63 static PeerConnectionCtx* GetInstance();
64 static bool isActive();
65 static void Destroy();
66
67 // Implementations of CC_Observer methods
68 virtual void onDeviceEvent(ccapi_device_event_e deviceEvent, CSF::CC_DevicePtr device, CSF::CC_DeviceInfoPtr info);
69 virtual void onFeatureEvent(ccapi_device_event_e deviceEvent, CSF::CC_DevicePtr device, CSF::CC_FeatureInfoPtr feature_info) {}
70 virtual void onLineEvent(ccapi_line_event_e lineEvent, CSF::CC_LinePtr line, CSF::CC_LineInfoPtr info) {}
71 virtual void onCallEvent(ccapi_call_event_e callEvent, CSF::CC_CallPtr call, CSF::CC_CallInfoPtr info);
72
73 // Create a SIPCC Call
74 CSF::CC_CallPtr createCall();
75
76 mozilla::dom::PCImplSipccState sipcc_state() { return mSipccState; }
77
78 // Make these classes friend so that they can access mPeerconnections.
79 friend class PeerConnectionImpl;
80 friend class PeerConnectionWrapper;
81 friend class mozilla::dom::WebrtcGlobalInformation;
82
83 private:
84 // We could make these available only via accessors but it's too much trouble.
85 std::map<const std::string, PeerConnectionImpl *> mPeerConnections;
86
87 PeerConnectionCtx() : mSipccState(mozilla::dom::PCImplSipccState::Idle),
88 mCCM(nullptr), mDevice(nullptr) {}
89 // This is a singleton, so don't copy construct it, etc.
90 PeerConnectionCtx(const PeerConnectionCtx& other) MOZ_DELETE;
91 void operator=(const PeerConnectionCtx& other) MOZ_DELETE;
92 virtual ~PeerConnectionCtx() {};
93
94 nsresult Initialize();
95 nsresult Cleanup();
96
97 void ChangeSipccState(mozilla::dom::PCImplSipccState aState) {
98 mSipccState = aState;
99 }
100
101 // Telemetry Peer conection counter
102 int mConnectionCounter;
103
104 // SIPCC objects
105 mozilla::dom::PCImplSipccState mSipccState; // TODO(ekr@rtfm.com): refactor this out? What does it do?
106 CSF::CallControlManagerPtr mCCM;
107 CSF::CC_DevicePtr mDevice;
108
109 static PeerConnectionCtx *gInstance;
110 public:
111 static nsIThread *gMainThread;
112 static mozilla::StaticRefPtr<mozilla::PeerConnectionCtxShutdown> gPeerConnectionCtxShutdown;
113 };
114
115 } // namespace sipcc
116
117 #endif

mercurial