michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef peerconnectionctx_h___h__ michael@0: #define peerconnectionctx_h___h__ michael@0: michael@0: #include michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "CallControlManager.h" michael@0: #include "CC_Device.h" michael@0: #include "CC_DeviceInfo.h" michael@0: #include "CC_Call.h" michael@0: #include "CC_CallInfo.h" michael@0: #include "CC_Line.h" michael@0: #include "CC_LineInfo.h" michael@0: #include "CC_Observer.h" michael@0: #include "CC_FeatureInfo.h" michael@0: #include "cpr_stdlib.h" michael@0: michael@0: #include "StaticPtr.h" michael@0: #include "PeerConnectionImpl.h" michael@0: michael@0: namespace mozilla { michael@0: class PeerConnectionCtxShutdown; michael@0: michael@0: namespace dom { michael@0: class WebrtcGlobalInformation; michael@0: } michael@0: michael@0: // Unit-test helper, because cc_media_constraints_t is hard to forward-declare michael@0: michael@0: class MediaConstraintsExternal { michael@0: public: michael@0: MediaConstraintsExternal(); michael@0: MediaConstraintsExternal(const dom::MediaConstraintsInternal &aOther); michael@0: cc_media_constraints_t* build() const; michael@0: protected: michael@0: cc_media_constraints_t mConstraints; michael@0: }; michael@0: } michael@0: michael@0: namespace sipcc { michael@0: michael@0: class OnCallEventArgs { michael@0: public: michael@0: OnCallEventArgs(ccapi_call_event_e aCallEvent, CSF::CC_CallInfoPtr aInfo) michael@0: : mCallEvent(aCallEvent), mInfo(aInfo) {} michael@0: michael@0: ccapi_call_event_e mCallEvent; michael@0: CSF::CC_CallInfoPtr mInfo; michael@0: }; michael@0: michael@0: // A class to hold some of the singleton objects we need: michael@0: // * The global PeerConnectionImpl table and its associated lock. michael@0: // * Currently SIPCC only allows a single stack instance to exist in a process michael@0: // at once. This class implements a singleton object that wraps that. michael@0: // * The observer class that demuxes events onto individual PCs. michael@0: class PeerConnectionCtx : public CSF::CC_Observer { michael@0: public: michael@0: static nsresult InitializeGlobal(nsIThread *mainThread, nsIEventTarget *stsThread); michael@0: static PeerConnectionCtx* GetInstance(); michael@0: static bool isActive(); michael@0: static void Destroy(); michael@0: michael@0: // Implementations of CC_Observer methods michael@0: virtual void onDeviceEvent(ccapi_device_event_e deviceEvent, CSF::CC_DevicePtr device, CSF::CC_DeviceInfoPtr info); michael@0: virtual void onFeatureEvent(ccapi_device_event_e deviceEvent, CSF::CC_DevicePtr device, CSF::CC_FeatureInfoPtr feature_info) {} michael@0: virtual void onLineEvent(ccapi_line_event_e lineEvent, CSF::CC_LinePtr line, CSF::CC_LineInfoPtr info) {} michael@0: virtual void onCallEvent(ccapi_call_event_e callEvent, CSF::CC_CallPtr call, CSF::CC_CallInfoPtr info); michael@0: michael@0: // Create a SIPCC Call michael@0: CSF::CC_CallPtr createCall(); michael@0: michael@0: mozilla::dom::PCImplSipccState sipcc_state() { return mSipccState; } michael@0: michael@0: // Make these classes friend so that they can access mPeerconnections. michael@0: friend class PeerConnectionImpl; michael@0: friend class PeerConnectionWrapper; michael@0: friend class mozilla::dom::WebrtcGlobalInformation; michael@0: michael@0: private: michael@0: // We could make these available only via accessors but it's too much trouble. michael@0: std::map mPeerConnections; michael@0: michael@0: PeerConnectionCtx() : mSipccState(mozilla::dom::PCImplSipccState::Idle), michael@0: mCCM(nullptr), mDevice(nullptr) {} michael@0: // This is a singleton, so don't copy construct it, etc. michael@0: PeerConnectionCtx(const PeerConnectionCtx& other) MOZ_DELETE; michael@0: void operator=(const PeerConnectionCtx& other) MOZ_DELETE; michael@0: virtual ~PeerConnectionCtx() {}; michael@0: michael@0: nsresult Initialize(); michael@0: nsresult Cleanup(); michael@0: michael@0: void ChangeSipccState(mozilla::dom::PCImplSipccState aState) { michael@0: mSipccState = aState; michael@0: } michael@0: michael@0: // Telemetry Peer conection counter michael@0: int mConnectionCounter; michael@0: michael@0: // SIPCC objects michael@0: mozilla::dom::PCImplSipccState mSipccState; // TODO(ekr@rtfm.com): refactor this out? What does it do? michael@0: CSF::CallControlManagerPtr mCCM; michael@0: CSF::CC_DevicePtr mDevice; michael@0: michael@0: static PeerConnectionCtx *gInstance; michael@0: public: michael@0: static nsIThread *gMainThread; michael@0: static mozilla::StaticRefPtr gPeerConnectionCtxShutdown; michael@0: }; michael@0: michael@0: } // namespace sipcc michael@0: michael@0: #endif