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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,117 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef peerconnectionctx_h___h__
     1.9 +#define peerconnectionctx_h___h__
    1.10 +
    1.11 +#include <string>
    1.12 +
    1.13 +#include "mozilla/Attributes.h"
    1.14 +#include "CallControlManager.h"
    1.15 +#include "CC_Device.h"
    1.16 +#include "CC_DeviceInfo.h"
    1.17 +#include "CC_Call.h"
    1.18 +#include "CC_CallInfo.h"
    1.19 +#include "CC_Line.h"
    1.20 +#include "CC_LineInfo.h"
    1.21 +#include "CC_Observer.h"
    1.22 +#include "CC_FeatureInfo.h"
    1.23 +#include "cpr_stdlib.h"
    1.24 +
    1.25 +#include "StaticPtr.h"
    1.26 +#include "PeerConnectionImpl.h"
    1.27 +
    1.28 +namespace mozilla {
    1.29 +class PeerConnectionCtxShutdown;
    1.30 +
    1.31 +namespace dom {
    1.32 +class WebrtcGlobalInformation;
    1.33 +}
    1.34 +
    1.35 +// Unit-test helper, because cc_media_constraints_t is hard to forward-declare
    1.36 +
    1.37 +class MediaConstraintsExternal {
    1.38 +public:
    1.39 +  MediaConstraintsExternal();
    1.40 +  MediaConstraintsExternal(const dom::MediaConstraintsInternal &aOther);
    1.41 +  cc_media_constraints_t* build() const;
    1.42 +protected:
    1.43 +  cc_media_constraints_t mConstraints;
    1.44 +};
    1.45 +}
    1.46 +
    1.47 +namespace sipcc {
    1.48 +
    1.49 +class OnCallEventArgs {
    1.50 +public:
    1.51 +  OnCallEventArgs(ccapi_call_event_e aCallEvent, CSF::CC_CallInfoPtr aInfo)
    1.52 +  : mCallEvent(aCallEvent), mInfo(aInfo) {}
    1.53 +
    1.54 +  ccapi_call_event_e mCallEvent;
    1.55 +  CSF::CC_CallInfoPtr mInfo;
    1.56 +};
    1.57 +
    1.58 +// A class to hold some of the singleton objects we need:
    1.59 +// * The global PeerConnectionImpl table and its associated lock.
    1.60 +// * Currently SIPCC only allows a single stack instance to exist in a process
    1.61 +//   at once. This class implements a singleton object that wraps that.
    1.62 +// * The observer class that demuxes events onto individual PCs.
    1.63 +class PeerConnectionCtx : public CSF::CC_Observer {
    1.64 + public:
    1.65 +  static nsresult InitializeGlobal(nsIThread *mainThread, nsIEventTarget *stsThread);
    1.66 +  static PeerConnectionCtx* GetInstance();
    1.67 +  static bool isActive();
    1.68 +  static void Destroy();
    1.69 +
    1.70 +  // Implementations of CC_Observer methods
    1.71 +  virtual void onDeviceEvent(ccapi_device_event_e deviceEvent, CSF::CC_DevicePtr device, CSF::CC_DeviceInfoPtr info);
    1.72 +  virtual void onFeatureEvent(ccapi_device_event_e deviceEvent, CSF::CC_DevicePtr device, CSF::CC_FeatureInfoPtr feature_info) {}
    1.73 +  virtual void onLineEvent(ccapi_line_event_e lineEvent, CSF::CC_LinePtr line, CSF::CC_LineInfoPtr info) {}
    1.74 +  virtual void onCallEvent(ccapi_call_event_e callEvent, CSF::CC_CallPtr call, CSF::CC_CallInfoPtr info);
    1.75 +
    1.76 +  // Create a SIPCC Call
    1.77 +  CSF::CC_CallPtr createCall();
    1.78 +
    1.79 +  mozilla::dom::PCImplSipccState sipcc_state() { return mSipccState; }
    1.80 +
    1.81 +  // Make these classes friend so that they can access mPeerconnections.
    1.82 +  friend class PeerConnectionImpl;
    1.83 +  friend class PeerConnectionWrapper;
    1.84 +  friend class mozilla::dom::WebrtcGlobalInformation;
    1.85 +
    1.86 + private:
    1.87 +  // We could make these available only via accessors but it's too much trouble.
    1.88 +  std::map<const std::string, PeerConnectionImpl *> mPeerConnections;
    1.89 +
    1.90 +  PeerConnectionCtx() :  mSipccState(mozilla::dom::PCImplSipccState::Idle),
    1.91 +                         mCCM(nullptr), mDevice(nullptr) {}
    1.92 +  // This is a singleton, so don't copy construct it, etc.
    1.93 +  PeerConnectionCtx(const PeerConnectionCtx& other) MOZ_DELETE;
    1.94 +  void operator=(const PeerConnectionCtx& other) MOZ_DELETE;
    1.95 +  virtual ~PeerConnectionCtx() {};
    1.96 +
    1.97 +  nsresult Initialize();
    1.98 +  nsresult Cleanup();
    1.99 +
   1.100 +  void ChangeSipccState(mozilla::dom::PCImplSipccState aState) {
   1.101 +    mSipccState = aState;
   1.102 +  }
   1.103 +
   1.104 +  // Telemetry Peer conection counter
   1.105 +  int mConnectionCounter;
   1.106 +
   1.107 +  // SIPCC objects
   1.108 +  mozilla::dom::PCImplSipccState mSipccState;  // TODO(ekr@rtfm.com): refactor this out? What does it do?
   1.109 +  CSF::CallControlManagerPtr mCCM;
   1.110 +  CSF::CC_DevicePtr mDevice;
   1.111 +
   1.112 +  static PeerConnectionCtx *gInstance;
   1.113 +public:
   1.114 +  static nsIThread *gMainThread;
   1.115 +  static mozilla::StaticRefPtr<mozilla::PeerConnectionCtxShutdown> gPeerConnectionCtxShutdown;
   1.116 +};
   1.117 +
   1.118 +}  // namespace sipcc
   1.119 +
   1.120 +#endif

mercurial