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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,694 @@
     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 file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef _PEER_CONNECTION_IMPL_H_
     1.9 +#define _PEER_CONNECTION_IMPL_H_
    1.10 +
    1.11 +#include <deque>
    1.12 +#include <string>
    1.13 +#include <vector>
    1.14 +#include <map>
    1.15 +#include <cmath>
    1.16 +
    1.17 +#include "prlock.h"
    1.18 +#include "mozilla/RefPtr.h"
    1.19 +#include "nsWeakPtr.h"
    1.20 +#include "nsAutoPtr.h"
    1.21 +#include "nsIWeakReferenceUtils.h" // for the definition of nsWeakPtr
    1.22 +#include "IPeerConnection.h"
    1.23 +#include "sigslot.h"
    1.24 +#include "nricectx.h"
    1.25 +#include "nricemediastream.h"
    1.26 +#include "nsComponentManagerUtils.h"
    1.27 +#include "nsPIDOMWindow.h"
    1.28 +#include "nsIThread.h"
    1.29 +
    1.30 +#include "mozilla/ErrorResult.h"
    1.31 +#include "mozilla/dom/PeerConnectionImplEnumsBinding.h"
    1.32 +#include "StreamBuffer.h"
    1.33 +#include "LoadManagerFactory.h"
    1.34 +
    1.35 +#ifdef MOZILLA_INTERNAL_API
    1.36 +#include "mozilla/TimeStamp.h"
    1.37 +#include "mozilla/net/DataChannel.h"
    1.38 +#include "VideoUtils.h"
    1.39 +#include "VideoSegment.h"
    1.40 +#include "nsNSSShutDown.h"
    1.41 +#include "mozilla/dom/RTCStatsReportBinding.h"
    1.42 +#endif
    1.43 +
    1.44 +namespace test {
    1.45 +#ifdef USE_FAKE_PCOBSERVER
    1.46 +class AFakePCObserver;
    1.47 +#endif
    1.48 +}
    1.49 +
    1.50 +#ifdef USE_FAKE_MEDIA_STREAMS
    1.51 +class Fake_DOMMediaStream;
    1.52 +#endif
    1.53 +
    1.54 +class nsGlobalWindow;
    1.55 +class nsIDOMMediaStream;
    1.56 +class nsDOMDataChannel;
    1.57 +
    1.58 +namespace mozilla {
    1.59 +class DataChannel;
    1.60 +class DtlsIdentity;
    1.61 +class NrIceCtx;
    1.62 +class NrIceMediaStream;
    1.63 +class NrIceStunServer;
    1.64 +class NrIceTurnServer;
    1.65 +class MediaPipeline;
    1.66 +
    1.67 +#ifdef USE_FAKE_MEDIA_STREAMS
    1.68 +typedef Fake_DOMMediaStream DOMMediaStream;
    1.69 +#else
    1.70 +class DOMMediaStream;
    1.71 +#endif
    1.72 +
    1.73 +namespace dom {
    1.74 +class RTCConfiguration;
    1.75 +class MediaConstraintsInternal;
    1.76 +class MediaStreamTrack;
    1.77 +class RTCStatsReportInternal;
    1.78 +
    1.79 +#ifdef USE_FAKE_PCOBSERVER
    1.80 +typedef test::AFakePCObserver PeerConnectionObserver;
    1.81 +typedef const char *PCObserverString;
    1.82 +#else
    1.83 +class PeerConnectionObserver;
    1.84 +typedef NS_ConvertUTF8toUTF16 PCObserverString;
    1.85 +#endif
    1.86 +}
    1.87 +class MediaConstraintsExternal;
    1.88 +}
    1.89 +
    1.90 +#if defined(__cplusplus) && __cplusplus >= 201103L
    1.91 +typedef struct Timecard Timecard;
    1.92 +#else
    1.93 +#include "timecard.h"
    1.94 +#endif
    1.95 +
    1.96 +// To preserve blame, convert nsresult to ErrorResult with wrappers. These macros
    1.97 +// help declare wrappers w/function being wrapped when there are no differences.
    1.98 +
    1.99 +#define NS_IMETHODIMP_TO_ERRORRESULT(func, rv, ...) \
   1.100 +NS_IMETHODIMP func(__VA_ARGS__);                    \
   1.101 +void func (__VA_ARGS__, rv)
   1.102 +
   1.103 +#define NS_IMETHODIMP_TO_ERRORRESULT_RETREF(resulttype, func, rv, ...) \
   1.104 +NS_IMETHODIMP func(__VA_ARGS__, resulttype **result);                  \
   1.105 +already_AddRefed<resulttype> func (__VA_ARGS__, rv)
   1.106 +
   1.107 +namespace sipcc {
   1.108 +
   1.109 +using mozilla::dom::PeerConnectionObserver;
   1.110 +using mozilla::dom::RTCConfiguration;
   1.111 +using mozilla::dom::MediaConstraintsInternal;
   1.112 +using mozilla::MediaConstraintsExternal;
   1.113 +using mozilla::DOMMediaStream;
   1.114 +using mozilla::NrIceCtx;
   1.115 +using mozilla::NrIceMediaStream;
   1.116 +using mozilla::DtlsIdentity;
   1.117 +using mozilla::ErrorResult;
   1.118 +using mozilla::NrIceStunServer;
   1.119 +using mozilla::NrIceTurnServer;
   1.120 +
   1.121 +class PeerConnectionWrapper;
   1.122 +class PeerConnectionMedia;
   1.123 +class RemoteSourceStreamInfo;
   1.124 +class OnCallEventArgs;
   1.125 +
   1.126 +class IceConfiguration
   1.127 +{
   1.128 +public:
   1.129 +  bool addStunServer(const std::string& addr, uint16_t port)
   1.130 +  {
   1.131 +    NrIceStunServer* server(NrIceStunServer::Create(addr, port));
   1.132 +    if (!server) {
   1.133 +      return false;
   1.134 +    }
   1.135 +    addStunServer(*server);
   1.136 +    return true;
   1.137 +  }
   1.138 +  bool addTurnServer(const std::string& addr, uint16_t port,
   1.139 +                     const std::string& username,
   1.140 +                     const std::string& pwd,
   1.141 +                     const char* transport)
   1.142 +  {
   1.143 +    // TODO(ekr@rtfm.com): Need support for SASLprep for
   1.144 +    // username and password. Bug # ???
   1.145 +    std::vector<unsigned char> password(pwd.begin(), pwd.end());
   1.146 +
   1.147 +    NrIceTurnServer* server(NrIceTurnServer::Create(addr, port, username, password,
   1.148 +                                                    transport));
   1.149 +    if (!server) {
   1.150 +      return false;
   1.151 +    }
   1.152 +    addTurnServer(*server);
   1.153 +    return true;
   1.154 +  }
   1.155 +  void addStunServer(const NrIceStunServer& server) { mStunServers.push_back (server); }
   1.156 +  void addTurnServer(const NrIceTurnServer& server) { mTurnServers.push_back (server); }
   1.157 +  const std::vector<NrIceStunServer>& getStunServers() const { return mStunServers; }
   1.158 +  const std::vector<NrIceTurnServer>& getTurnServers() const { return mTurnServers; }
   1.159 +private:
   1.160 +  std::vector<NrIceStunServer> mStunServers;
   1.161 +  std::vector<NrIceTurnServer> mTurnServers;
   1.162 +};
   1.163 +
   1.164 +#ifdef MOZILLA_INTERNAL_API
   1.165 +// Not an inner class so we can forward declare.
   1.166 +class RTCStatsQuery {
   1.167 +  public:
   1.168 +    explicit RTCStatsQuery(bool internalStats);
   1.169 +    ~RTCStatsQuery();
   1.170 +
   1.171 +    mozilla::dom::RTCStatsReportInternal report;
   1.172 +    std::string error;
   1.173 +
   1.174 +  private:
   1.175 +    friend class PeerConnectionImpl;
   1.176 +    std::string pcName;
   1.177 +    bool internalStats;
   1.178 +    nsTArray<mozilla::RefPtr<mozilla::MediaPipeline>> pipelines;
   1.179 +    mozilla::RefPtr<NrIceCtx> iceCtx;
   1.180 +    nsTArray<mozilla::RefPtr<NrIceMediaStream>> streams;
   1.181 +    DOMHighResTimeStamp now;
   1.182 +};
   1.183 +#endif // MOZILLA_INTERNAL_API
   1.184 +
   1.185 +// Enter an API call and check that the state is OK,
   1.186 +// the PC isn't closed, etc.
   1.187 +#define PC_AUTO_ENTER_API_CALL(assert_ice_ready) \
   1.188 +    do { \
   1.189 +      /* do/while prevents res from conflicting with locals */    \
   1.190 +      nsresult res = CheckApiState(assert_ice_ready);             \
   1.191 +      if (NS_FAILED(res)) return res; \
   1.192 +    } while(0)
   1.193 +#define PC_AUTO_ENTER_API_CALL_VOID_RETURN(assert_ice_ready) \
   1.194 +    do { \
   1.195 +      /* do/while prevents res from conflicting with locals */    \
   1.196 +      nsresult res = CheckApiState(assert_ice_ready);             \
   1.197 +      if (NS_FAILED(res)) return; \
   1.198 +    } while(0)
   1.199 +#define PC_AUTO_ENTER_API_CALL_NO_CHECK() CheckThread()
   1.200 +
   1.201 +class PeerConnectionImpl MOZ_FINAL : public nsISupports,
   1.202 +#ifdef MOZILLA_INTERNAL_API
   1.203 +                                     public mozilla::DataChannelConnection::DataConnectionListener,
   1.204 +                                     public nsNSSShutDownObject,
   1.205 +#endif
   1.206 +                                     public sigslot::has_slots<>
   1.207 +{
   1.208 +  class Internal; // Avoid exposing c includes to bindings
   1.209 +
   1.210 +public:
   1.211 +  PeerConnectionImpl(const mozilla::dom::GlobalObject* aGlobal = nullptr);
   1.212 +  virtual ~PeerConnectionImpl();
   1.213 +
   1.214 +  enum Error {
   1.215 +    kNoError                          = 0,
   1.216 +    kInvalidConstraintsType           = 1,
   1.217 +    kInvalidCandidateType             = 2,
   1.218 +    kInvalidMediastreamTrack          = 3,
   1.219 +    kInvalidState                     = 4,
   1.220 +    kInvalidSessionDescription        = 5,
   1.221 +    kIncompatibleSessionDescription   = 6,
   1.222 +    kIncompatibleConstraints          = 7,
   1.223 +    kIncompatibleMediaStreamTrack     = 8,
   1.224 +    kInternalError                    = 9
   1.225 +  };
   1.226 +
   1.227 +  NS_DECL_THREADSAFE_ISUPPORTS
   1.228 +
   1.229 +#ifdef MOZILLA_INTERNAL_API
   1.230 +  virtual JSObject* WrapObject(JSContext* cx);
   1.231 +#endif
   1.232 +
   1.233 +  static already_AddRefed<PeerConnectionImpl>
   1.234 +      Constructor(const mozilla::dom::GlobalObject& aGlobal, ErrorResult& rv);
   1.235 +  static PeerConnectionImpl* CreatePeerConnection();
   1.236 +  static nsresult ConvertRTCConfiguration(const RTCConfiguration& aSrc,
   1.237 +                                          IceConfiguration *aDst);
   1.238 +  static already_AddRefed<DOMMediaStream> MakeMediaStream(nsPIDOMWindow* aWindow,
   1.239 +                                                          uint32_t aHint);
   1.240 +
   1.241 +  nsresult CreateRemoteSourceStreamInfo(nsRefPtr<RemoteSourceStreamInfo>* aInfo);
   1.242 +
   1.243 +  // Implementation of the only observer we need
   1.244 +  void onCallEvent(const OnCallEventArgs &args);
   1.245 +
   1.246 +  // DataConnection observers
   1.247 +  void NotifyConnection();
   1.248 +  void NotifyClosedConnection();
   1.249 +  void NotifyDataChannel(already_AddRefed<mozilla::DataChannel> aChannel);
   1.250 +
   1.251 +  // Get the media object
   1.252 +  const nsRefPtr<PeerConnectionMedia>& media() const {
   1.253 +    PC_AUTO_ENTER_API_CALL_NO_CHECK();
   1.254 +    return mMedia;
   1.255 +  }
   1.256 +
   1.257 +  mozilla::LoadManager* load_manager()  {
   1.258 +    return mLoadManager;
   1.259 +  }
   1.260 +
   1.261 +  // Handle system to allow weak references to be passed through C code
   1.262 +  virtual const std::string& GetHandle();
   1.263 +
   1.264 +  // Name suitable for exposing to content
   1.265 +  virtual const std::string& GetName();
   1.266 +
   1.267 +  // ICE events
   1.268 +  void IceConnectionStateChange(NrIceCtx* ctx,
   1.269 +                                NrIceCtx::ConnectionState state);
   1.270 +  void IceGatheringStateChange(NrIceCtx* ctx,
   1.271 +                               NrIceCtx::GatheringState state);
   1.272 +  void IceStreamReady(NrIceMediaStream *aStream);
   1.273 +
   1.274 +  static void ListenThread(void *aData);
   1.275 +  static void ConnectThread(void *aData);
   1.276 +
   1.277 +  // Get the main thread
   1.278 +  nsCOMPtr<nsIThread> GetMainThread() {
   1.279 +    PC_AUTO_ENTER_API_CALL_NO_CHECK();
   1.280 +    return mThread;
   1.281 +  }
   1.282 +
   1.283 +  // Get the STS thread
   1.284 +  nsCOMPtr<nsIEventTarget> GetSTSThread() {
   1.285 +    PC_AUTO_ENTER_API_CALL_NO_CHECK();
   1.286 +    return mSTSThread;
   1.287 +  }
   1.288 +
   1.289 +  // Get the DTLS identity
   1.290 +  mozilla::RefPtr<DtlsIdentity> const GetIdentity() const;
   1.291 +  std::string GetFingerprint() const;
   1.292 +  std::string GetFingerprintAlgorithm() const;
   1.293 +  std::string GetFingerprintHexValue() const;
   1.294 +
   1.295 +  // Create a fake media stream
   1.296 +  nsresult CreateFakeMediaStream(uint32_t hint, nsIDOMMediaStream** retval);
   1.297 +
   1.298 +  nsPIDOMWindow* GetWindow() const {
   1.299 +    PC_AUTO_ENTER_API_CALL_NO_CHECK();
   1.300 +    return mWindow;
   1.301 +  }
   1.302 +
   1.303 +  // Initialize PeerConnection from an IceConfiguration object (unit-tests)
   1.304 +  nsresult Initialize(PeerConnectionObserver& aObserver,
   1.305 +                      nsGlobalWindow* aWindow,
   1.306 +                      const IceConfiguration& aConfiguration,
   1.307 +                      nsIThread* aThread) {
   1.308 +    return Initialize(aObserver, aWindow, &aConfiguration, nullptr, aThread);
   1.309 +  }
   1.310 +
   1.311 +  // Initialize PeerConnection from an RTCConfiguration object (JS entrypoint)
   1.312 +  void Initialize(PeerConnectionObserver& aObserver,
   1.313 +                  nsGlobalWindow& aWindow,
   1.314 +                  const RTCConfiguration& aConfiguration,
   1.315 +                  nsISupports* aThread,
   1.316 +                  ErrorResult &rv)
   1.317 +  {
   1.318 +    nsresult r = Initialize(aObserver, &aWindow, nullptr, &aConfiguration, aThread);
   1.319 +    if (NS_FAILED(r)) {
   1.320 +      rv.Throw(r);
   1.321 +    }
   1.322 +  }
   1.323 +
   1.324 +  NS_IMETHODIMP_TO_ERRORRESULT(CreateOffer, ErrorResult &rv,
   1.325 +                               const MediaConstraintsInternal& aConstraints)
   1.326 +  {
   1.327 +    rv = CreateOffer(aConstraints);
   1.328 +  }
   1.329 +
   1.330 +  NS_IMETHODIMP_TO_ERRORRESULT(CreateAnswer, ErrorResult &rv,
   1.331 +                               const MediaConstraintsInternal& aConstraints)
   1.332 +  {
   1.333 +    rv = CreateAnswer(aConstraints);
   1.334 +  }
   1.335 +
   1.336 +  NS_IMETHODIMP CreateOffer(const MediaConstraintsExternal& aConstraints);
   1.337 +  NS_IMETHODIMP CreateAnswer(const MediaConstraintsExternal& aConstraints);
   1.338 +
   1.339 +  NS_IMETHODIMP SetLocalDescription (int32_t aAction, const char* aSDP);
   1.340 +
   1.341 +  void SetLocalDescription (int32_t aAction, const nsAString& aSDP, ErrorResult &rv)
   1.342 +  {
   1.343 +    rv = SetLocalDescription(aAction, NS_ConvertUTF16toUTF8(aSDP).get());
   1.344 +  }
   1.345 +
   1.346 +  NS_IMETHODIMP SetRemoteDescription (int32_t aAction, const char* aSDP);
   1.347 +
   1.348 +  void SetRemoteDescription (int32_t aAction, const nsAString& aSDP, ErrorResult &rv)
   1.349 +  {
   1.350 +    rv = SetRemoteDescription(aAction, NS_ConvertUTF16toUTF8(aSDP).get());
   1.351 +  }
   1.352 +
   1.353 +  NS_IMETHODIMP_TO_ERRORRESULT(GetStats, ErrorResult &rv,
   1.354 +                               mozilla::dom::MediaStreamTrack *aSelector)
   1.355 +  {
   1.356 +    rv = GetStats(aSelector);
   1.357 +  }
   1.358 +
   1.359 +  NS_IMETHODIMP AddIceCandidate(const char* aCandidate, const char* aMid,
   1.360 +                                unsigned short aLevel);
   1.361 +
   1.362 +  void AddIceCandidate(const nsAString& aCandidate, const nsAString& aMid,
   1.363 +                       unsigned short aLevel, ErrorResult &rv)
   1.364 +  {
   1.365 +    rv = AddIceCandidate(NS_ConvertUTF16toUTF8(aCandidate).get(),
   1.366 +                         NS_ConvertUTF16toUTF8(aMid).get(), aLevel);
   1.367 +  }
   1.368 +
   1.369 +  NS_IMETHODIMP CloseStreams();
   1.370 +
   1.371 +  void CloseStreams(ErrorResult &rv)
   1.372 +  {
   1.373 +    rv = CloseStreams();
   1.374 +  }
   1.375 +
   1.376 +  NS_IMETHODIMP_TO_ERRORRESULT(AddStream, ErrorResult &rv,
   1.377 +                               DOMMediaStream& aMediaStream,
   1.378 +                               const MediaConstraintsInternal& aConstraints)
   1.379 +  {
   1.380 +    rv = AddStream(aMediaStream, aConstraints);
   1.381 +  }
   1.382 +
   1.383 +  NS_IMETHODIMP AddStream(DOMMediaStream & aMediaStream,
   1.384 +                          const MediaConstraintsExternal& aConstraints);
   1.385 +
   1.386 +  NS_IMETHODIMP_TO_ERRORRESULT(RemoveStream, ErrorResult &rv,
   1.387 +                               DOMMediaStream& aMediaStream)
   1.388 +  {
   1.389 +    rv = RemoveStream(aMediaStream);
   1.390 +  }
   1.391 +
   1.392 +  NS_IMETHODIMP GetFingerprint(char** fingerprint);
   1.393 +  void GetFingerprint(nsAString& fingerprint)
   1.394 +  {
   1.395 +    char *tmp;
   1.396 +    GetFingerprint(&tmp);
   1.397 +    fingerprint.AssignASCII(tmp);
   1.398 +    delete[] tmp;
   1.399 +  }
   1.400 +
   1.401 +  NS_IMETHODIMP GetLocalDescription(char** aSDP);
   1.402 +
   1.403 +  void GetLocalDescription(nsAString& aSDP)
   1.404 +  {
   1.405 +    char *tmp;
   1.406 +    GetLocalDescription(&tmp);
   1.407 +    aSDP.AssignASCII(tmp);
   1.408 +    delete tmp;
   1.409 +  }
   1.410 +
   1.411 +  NS_IMETHODIMP GetRemoteDescription(char** aSDP);
   1.412 +
   1.413 +  void GetRemoteDescription(nsAString& aSDP)
   1.414 +  {
   1.415 +    char *tmp;
   1.416 +    GetRemoteDescription(&tmp);
   1.417 +    aSDP.AssignASCII(tmp);
   1.418 +    delete tmp;
   1.419 +  }
   1.420 +
   1.421 +  NS_IMETHODIMP ReadyState(mozilla::dom::PCImplReadyState* aState);
   1.422 +
   1.423 +  mozilla::dom::PCImplReadyState ReadyState()
   1.424 +  {
   1.425 +    mozilla::dom::PCImplReadyState state;
   1.426 +    ReadyState(&state);
   1.427 +    return state;
   1.428 +  }
   1.429 +
   1.430 +  NS_IMETHODIMP SignalingState(mozilla::dom::PCImplSignalingState* aState);
   1.431 +
   1.432 +  mozilla::dom::PCImplSignalingState SignalingState()
   1.433 +  {
   1.434 +    mozilla::dom::PCImplSignalingState state;
   1.435 +    SignalingState(&state);
   1.436 +    return state;
   1.437 +  }
   1.438 +
   1.439 +  NS_IMETHODIMP SipccState(mozilla::dom::PCImplSipccState* aState);
   1.440 +
   1.441 +  mozilla::dom::PCImplSipccState SipccState()
   1.442 +  {
   1.443 +    mozilla::dom::PCImplSipccState state;
   1.444 +    SipccState(&state);
   1.445 +    return state;
   1.446 +  }
   1.447 +
   1.448 +  NS_IMETHODIMP IceConnectionState(
   1.449 +      mozilla::dom::PCImplIceConnectionState* aState);
   1.450 +
   1.451 +  mozilla::dom::PCImplIceConnectionState IceConnectionState()
   1.452 +  {
   1.453 +    mozilla::dom::PCImplIceConnectionState state;
   1.454 +    IceConnectionState(&state);
   1.455 +    return state;
   1.456 +  }
   1.457 +
   1.458 +  NS_IMETHODIMP IceGatheringState(
   1.459 +      mozilla::dom::PCImplIceGatheringState* aState);
   1.460 +
   1.461 +  mozilla::dom::PCImplIceGatheringState IceGatheringState()
   1.462 +  {
   1.463 +    mozilla::dom::PCImplIceGatheringState state;
   1.464 +    IceGatheringState(&state);
   1.465 +    return state;
   1.466 +  }
   1.467 +
   1.468 +  NS_IMETHODIMP Close();
   1.469 +
   1.470 +  void Close(ErrorResult &rv)
   1.471 +  {
   1.472 +    rv = Close();
   1.473 +  }
   1.474 +
   1.475 +  nsresult InitializeDataChannel(int track_id, uint16_t aLocalport,
   1.476 +                                 uint16_t aRemoteport, uint16_t aNumstreams);
   1.477 +
   1.478 +  NS_IMETHODIMP_TO_ERRORRESULT(ConnectDataConnection, ErrorResult &rv,
   1.479 +                               uint16_t aLocalport,
   1.480 +                               uint16_t aRemoteport,
   1.481 +                               uint16_t aNumstreams)
   1.482 +  {
   1.483 +    rv = ConnectDataConnection(aLocalport, aRemoteport, aNumstreams);
   1.484 +  }
   1.485 +
   1.486 +  NS_IMETHODIMP_TO_ERRORRESULT_RETREF(nsDOMDataChannel,
   1.487 +                                      CreateDataChannel, ErrorResult &rv,
   1.488 +                                      const nsAString& aLabel,
   1.489 +                                      const nsAString& aProtocol,
   1.490 +                                      uint16_t aType,
   1.491 +                                      bool outOfOrderAllowed,
   1.492 +                                      uint16_t aMaxTime,
   1.493 +                                      uint16_t aMaxNum,
   1.494 +                                      bool aExternalNegotiated,
   1.495 +                                      uint16_t aStream);
   1.496 +
   1.497 +  NS_IMETHODIMP_TO_ERRORRESULT(GetLocalStreams, ErrorResult &rv,
   1.498 +                               nsTArray<nsRefPtr<DOMMediaStream > >& result)
   1.499 +  {
   1.500 +    rv = GetLocalStreams(result);
   1.501 +  }
   1.502 +
   1.503 +  NS_IMETHODIMP_TO_ERRORRESULT(GetRemoteStreams, ErrorResult &rv,
   1.504 +                               nsTArray<nsRefPtr<DOMMediaStream > >& result)
   1.505 +  {
   1.506 +    rv = GetRemoteStreams(result);
   1.507 +  }
   1.508 +
   1.509 +  // Called whenever something is unrecognized by the parser
   1.510 +  // May be called more than once and does not necessarily mean
   1.511 +  // that parsing was stopped, only that something was unrecognized.
   1.512 +  void OnSdpParseError(const char* errorMessage);
   1.513 +
   1.514 +  // Called when OnLocal/RemoteDescriptionSuccess/Error
   1.515 +  // is called to start the list over.
   1.516 +  void ClearSdpParseErrorMessages();
   1.517 +
   1.518 +  // Called to retreive the list of parsing errors.
   1.519 +  const std::vector<std::string> &GetSdpParseErrors();
   1.520 +
   1.521 +  // Sets the RTC Signaling State
   1.522 +  void SetSignalingState_m(mozilla::dom::PCImplSignalingState aSignalingState);
   1.523 +
   1.524 +  bool IsClosed() const;
   1.525 +
   1.526 +  bool HasMedia() const;
   1.527 +
   1.528 +#ifdef MOZILLA_INTERNAL_API
   1.529 +  // initialize telemetry for when calls start
   1.530 +  void startCallTelem();
   1.531 +
   1.532 +  nsresult BuildStatsQuery_m(
   1.533 +      mozilla::dom::MediaStreamTrack *aSelector,
   1.534 +      RTCStatsQuery *query);
   1.535 +
   1.536 +  static nsresult ExecuteStatsQuery_s(RTCStatsQuery *query);
   1.537 +#endif
   1.538 +
   1.539 +private:
   1.540 +  PeerConnectionImpl(const PeerConnectionImpl&rhs);
   1.541 +  PeerConnectionImpl& operator=(PeerConnectionImpl);
   1.542 +  NS_IMETHODIMP Initialize(PeerConnectionObserver& aObserver,
   1.543 +                           nsGlobalWindow* aWindow,
   1.544 +                           const IceConfiguration* aConfiguration,
   1.545 +                           const RTCConfiguration* aRTCConfiguration,
   1.546 +                           nsISupports* aThread);
   1.547 +
   1.548 +  NS_IMETHODIMP EnsureDataConnection(uint16_t aNumstreams);
   1.549 +
   1.550 +  nsresult CloseInt();
   1.551 +  void ChangeReadyState(mozilla::dom::PCImplReadyState aReadyState);
   1.552 +  nsresult CheckApiState(bool assert_ice_ready) const;
   1.553 +  void CheckThread() const {
   1.554 +    NS_ABORT_IF_FALSE(CheckThreadInt(), "Wrong thread");
   1.555 +  }
   1.556 +  bool CheckThreadInt() const {
   1.557 +#ifdef MOZILLA_INTERNAL_API
   1.558 +    // Thread assertions are disabled in the C++ unit tests because those
   1.559 +    // make API calls off the main thread.
   1.560 +    // TODO(ekr@rtfm.com): Fix the unit tests so they don't do that.
   1.561 +    bool on;
   1.562 +    NS_ENSURE_SUCCESS(mThread->IsOnCurrentThread(&on), false);
   1.563 +    NS_ENSURE_TRUE(on, false);
   1.564 +#endif
   1.565 +    return true;
   1.566 +  }
   1.567 +
   1.568 +#ifdef MOZILLA_INTERNAL_API
   1.569 +  void virtualDestroyNSSReference() MOZ_FINAL;
   1.570 +  void destructorSafeDestroyNSSReference();
   1.571 +  nsresult GetTimeSinceEpoch(DOMHighResTimeStamp *result);
   1.572 +#endif
   1.573 +
   1.574 +  // Shut down media - called on main thread only
   1.575 +  void ShutdownMedia();
   1.576 +
   1.577 +  NS_IMETHOD FingerprintSplitHelper(
   1.578 +      std::string& fingerprint, size_t& spaceIdx) const;
   1.579 +
   1.580 +
   1.581 +#ifdef MOZILLA_INTERNAL_API
   1.582 +  static void GetStatsForPCObserver_s(
   1.583 +      const std::string& pcHandle,
   1.584 +      nsAutoPtr<RTCStatsQuery> query);
   1.585 +
   1.586 +  // Sends an RTCStatsReport to JS. Must run on main thread.
   1.587 +  static void DeliverStatsReportToPCObserver_m(
   1.588 +      const std::string& pcHandle,
   1.589 +      nsresult result,
   1.590 +      nsAutoPtr<RTCStatsQuery> query);
   1.591 +#endif
   1.592 +
   1.593 +  // When ICE completes, we record a bunch of statistics that outlive the
   1.594 +  // PeerConnection. This is just telemetry right now, but this can also
   1.595 +  // include things like dumping the RLogRingbuffer somewhere, saving away
   1.596 +  // an RTCStatsReport somewhere so it can be inspected after the call is over,
   1.597 +  // or other things.
   1.598 +  void RecordLongtermICEStatistics();
   1.599 +
   1.600 +  // Timecard used to measure processing time. This should be the first class
   1.601 +  // attribute so that we accurately measure the time required to instantiate
   1.602 +  // any other attributes of this class.
   1.603 +  Timecard *mTimeCard;
   1.604 +
   1.605 +  // The call
   1.606 +  mozilla::ScopedDeletePtr<Internal> mInternal;
   1.607 +  mozilla::dom::PCImplReadyState mReadyState;
   1.608 +  mozilla::dom::PCImplSignalingState mSignalingState;
   1.609 +
   1.610 +  // ICE State
   1.611 +  mozilla::dom::PCImplIceConnectionState mIceConnectionState;
   1.612 +  mozilla::dom::PCImplIceGatheringState mIceGatheringState;
   1.613 +
   1.614 +  nsCOMPtr<nsIThread> mThread;
   1.615 +  // TODO: Remove if we ever properly wire PeerConnection for cycle-collection.
   1.616 +  nsWeakPtr mPCObserver;
   1.617 +
   1.618 +  nsCOMPtr<nsPIDOMWindow> mWindow;
   1.619 +
   1.620 +  // The SDP sent in from JS - here for debugging.
   1.621 +  std::string mLocalRequestedSDP;
   1.622 +  std::string mRemoteRequestedSDP;
   1.623 +  // The SDP we are using.
   1.624 +  std::string mLocalSDP;
   1.625 +  std::string mRemoteSDP;
   1.626 +
   1.627 +  // DTLS fingerprint
   1.628 +  std::string mFingerprint;
   1.629 +  std::string mRemoteFingerprint;
   1.630 +
   1.631 +  // The DTLS identity
   1.632 +  mozilla::RefPtr<DtlsIdentity> mIdentity;
   1.633 +
   1.634 +  // A handle to refer to this PC with
   1.635 +  std::string mHandle;
   1.636 +
   1.637 +  // A name for this PC that we are willing to expose to content.
   1.638 +  std::string mName;
   1.639 +
   1.640 +  // The target to run stuff on
   1.641 +  nsCOMPtr<nsIEventTarget> mSTSThread;
   1.642 +
   1.643 +  // CPU Load adaptation stuff
   1.644 +  mozilla::LoadManager* mLoadManager;
   1.645 +
   1.646 +#ifdef MOZILLA_INTERNAL_API
   1.647 +  // DataConnection that's used to get all the DataChannels
   1.648 +	nsRefPtr<mozilla::DataChannelConnection> mDataConnection;
   1.649 +#endif
   1.650 +
   1.651 +  nsRefPtr<PeerConnectionMedia> mMedia;
   1.652 +
   1.653 +#ifdef MOZILLA_INTERNAL_API
   1.654 +  // Start time of ICE, used for telemetry
   1.655 +  mozilla::TimeStamp mIceStartTime;
   1.656 +  // Start time of call used for Telemetry
   1.657 +  mozilla::TimeStamp mStartTime;
   1.658 +#endif
   1.659 +
   1.660 +  // Temporary: used to prevent multiple audio streams or multiple video streams
   1.661 +  // in a single PC. This is tied up in the IETF discussion around proper
   1.662 +  // representation of multiple streams in SDP, and strongly related to
   1.663 +  // Bug 840728.
   1.664 +  int mNumAudioStreams;
   1.665 +  int mNumVideoStreams;
   1.666 +
   1.667 +  bool mHaveDataStream;
   1.668 +
   1.669 +  // Holder for error messages from parsing SDP
   1.670 +  std::vector<std::string> mSDPParseErrorMessages;
   1.671 +
   1.672 +  bool mTrickle;
   1.673 +
   1.674 +public:
   1.675 +  //these are temporary until the DataChannel Listen/Connect API is removed
   1.676 +  unsigned short listenPort;
   1.677 +  unsigned short connectPort;
   1.678 +  char *connectStr; // XXX ownership/free
   1.679 +};
   1.680 +
   1.681 +// This is what is returned when you acquire on a handle
   1.682 +class PeerConnectionWrapper
   1.683 +{
   1.684 + public:
   1.685 +  PeerConnectionWrapper(const std::string& handle);
   1.686 +
   1.687 +  PeerConnectionImpl *impl() { return impl_; }
   1.688 +
   1.689 + private:
   1.690 +  nsRefPtr<PeerConnectionImpl> impl_;
   1.691 +};
   1.692 +
   1.693 +}  // end sipcc namespace
   1.694 +
   1.695 +#undef NS_IMETHODIMP_TO_ERRORRESULT
   1.696 +#undef NS_IMETHODIMP_TO_ERRORRESULT_RETREF
   1.697 +#endif  // _PEER_CONNECTION_IMPL_H_

mercurial