Bug 1091242 - Part 6: Wiring the new JSEP handler code in. See https://github.com/unicorn-wg/gecko-dev/tree/multistream_rebase for more history. r=jesup, r=smaug
☠☠ backed out by 960303b07c90 ☠ ☠
authorByron Campen [:bwc] <docfaraday@gmail.com>
Wed, 19 Nov 2014 16:16:29 -0800
changeset 246288 7fde5994aee5d053baee4bc9142a8ea79a567fcc
parent 246287 59b415714087055d5c8800236a6ca31184dd8556
child 246289 f1501aa243975fb8298ababc09ef6004c78f87d6
push id698
push userjlund@mozilla.com
push dateMon, 23 Mar 2015 22:08:11 +0000
treeherdermozilla-release@b0c0ae7b02a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup, smaug
bugs1091242
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1091242 - Part 6: Wiring the new JSEP handler code in. See https://github.com/unicorn-wg/gecko-dev/tree/multistream_rebase for more history. r=jesup, r=smaug
build/automation.py.in
build/automationutils.py
dom/bindings/Bindings.conf
dom/media/PeerConnection.js
dom/media/PeerConnection.manifest
dom/media/bridge/IPeerConnection.idl
dom/media/bridge/MediaModule.cpp
dom/webidl/PeerConnectionImpl.webidl
media/mtransport/dtlsidentity.cpp
media/mtransport/dtlsidentity.h
media/mtransport/logging.h
media/mtransport/nricectx.cpp
media/mtransport/nricectx.h
media/mtransport/nricemediastream.cpp
media/mtransport/nricemediastream.h
media/mtransport/test/ice_unittest.cpp
media/mtransport/test/transport_unittests.cpp
media/mtransport/third_party/nICEr/src/ice/ice_candidate.c
media/mtransport/third_party/nICEr/src/ice/ice_component.c
media/mtransport/third_party/nICEr/src/ice/ice_ctx.c
media/mtransport/third_party/nICEr/src/ice/ice_parser.c
media/mtransport/third_party/nICEr/src/ice/ice_peer_ctx.c
media/mtransport/transportlayerice.cpp
media/mtransport/transportlayerice.h
media/webrtc/signaling/include/CC_Call.h
media/webrtc/signaling/include/CC_CallInfo.h
media/webrtc/signaling/include/CC_CallServerInfo.h
media/webrtc/signaling/include/CC_CallTypes.h
media/webrtc/signaling/include/CC_Common.h
media/webrtc/signaling/include/CC_Device.h
media/webrtc/signaling/include/CC_DeviceInfo.h
media/webrtc/signaling/include/CC_FeatureInfo.h
media/webrtc/signaling/include/CC_Line.h
media/webrtc/signaling/include/CC_LineInfo.h
media/webrtc/signaling/include/CC_Observer.h
media/webrtc/signaling/include/CC_Service.h
media/webrtc/signaling/include/CSFAudioControl.h
media/webrtc/signaling/include/CSFVideoControl.h
media/webrtc/signaling/include/CallControlManager.h
media/webrtc/signaling/include/ECC_Observer.h
media/webrtc/signaling/include/ECC_Types.h
media/webrtc/signaling/include/PhoneDetails.h
media/webrtc/signaling/include/SharedPtr.h
media/webrtc/signaling/include/debug-psipcc-types.h
media/webrtc/signaling/src/common/browser_logging/CSFLog.cpp
media/webrtc/signaling/src/common/time_profiling/timecard.c
media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
media/webrtc/signaling/src/media-conduit/CodecConfig.h
media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
media/webrtc/signaling/src/media/CSFVideoControlWrapper.cpp
media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp
media/webrtc/signaling/src/media/VcmSIPCCBinding.h
media/webrtc/signaling/src/media/cip_Sipcc_CodecMask.h
media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp
media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.h
media/webrtc/signaling/src/peerconnection/MediaStreamList.cpp
media/webrtc/signaling/src/peerconnection/MediaStreamList.h
media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.h
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.h
media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp
media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.h
media/webrtc/signaling/test/FakePCObserver.h
media/webrtc/signaling/test/mediaconduit_unittests.cpp
media/webrtc/signaling/test/mediapipeline_unittest.cpp
media/webrtc/signaling/test/sdp_unittests.cpp
media/webrtc/signaling/test/signaling_unittests.cpp
modules/libpref/init/all.js
testing/mozbase/mozrunner/mozrunner/base/device.py
--- a/build/automation.py.in
+++ b/build/automation.py.in
@@ -502,17 +502,17 @@ class Automation(object):
     # override the user's choice here.  See bug 1049688.
     env.setdefault('MOZ_DISABLE_NONLOCAL_CONNECTIONS', '1')
 
     env['GNOME_DISABLE_CRASH_DIALOG'] = '1'
     env['XRE_NO_WINDOWS_CRASH_DIALOG'] = '1'
     env['NS_TRACE_MALLOC_DISABLE_STACKS'] = '1'
 
     # Set WebRTC logging in case it is not set yet
-    env.setdefault('NSPR_LOG_MODULES', 'signaling:5,mtransport:5,datachannel:5')
+    env.setdefault('NSPR_LOG_MODULES', 'signaling:5,mtransport:5,datachannel:5,jsep:5,MediaPipelineFactory:5')
     env.setdefault('R_LOG_LEVEL', '6')
     env.setdefault('R_LOG_DESTINATION', 'stderr')
     env.setdefault('R_LOG_VERBOSE', '1')
 
     # ASan specific environment stuff
     if self.IS_ASAN and (self.IS_LINUX or self.IS_MAC):
       # Symbolizer support
       llvmsym = os.path.join(xrePath, "llvm-symbolizer")
--- a/build/automationutils.py
+++ b/build/automationutils.py
@@ -405,17 +405,17 @@ def environment(xrePath, env=None, crash
 
   # Crash on non-local network connections by default.
   # MOZ_DISABLE_NONLOCAL_CONNECTIONS can be set to "0" to temporarily
   # enable non-local connections for the purposes of local testing.  Don't
   # override the user's choice here.  See bug 1049688.
   env.setdefault('MOZ_DISABLE_NONLOCAL_CONNECTIONS', '1')
 
   # Set WebRTC logging in case it is not set yet
-  env.setdefault('NSPR_LOG_MODULES', 'signaling:5,mtransport:5,datachannel:5')
+  env.setdefault('NSPR_LOG_MODULES', 'signaling:5,mtransport:5,datachannel:5,jsep:5,MediaPipelineFactory:5')
   env.setdefault('R_LOG_LEVEL', '6')
   env.setdefault('R_LOG_DESTINATION', 'stderr')
   env.setdefault('R_LOG_VERBOSE', '1')
 
   # ASan specific environment stuff
   asan = bool(mozinfo.info.get("asan"))
   if asan and (mozinfo.isLinux or mozinfo.isMac):
     try:
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -857,17 +857,17 @@ DOMInterfaces = {
 },
 
 'Path2D': {
     'nativeType': 'mozilla::dom::CanvasPath',
     'headerFile': 'CanvasRenderingContext2D.h'
 },
 
 'PeerConnectionImpl': {
-    'nativeType': 'sipcc::PeerConnectionImpl',
+    'nativeType': 'mozilla::PeerConnectionImpl',
     'headerFile': 'PeerConnectionImpl.h',
     'wrapperCache': False
 },
 
 'Performance': [{
     'nativeType': 'nsPerformance',
 },
 {
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -20,17 +20,17 @@ const PC_ICE_CONTRACT = "@mozilla.org/do
 const PC_SESSION_CONTRACT = "@mozilla.org/dom/rtcsessiondescription;1";
 const PC_MANAGER_CONTRACT = "@mozilla.org/dom/peerconnectionmanager;1";
 const PC_STATS_CONTRACT = "@mozilla.org/dom/rtcstatsreport;1";
 const PC_IDENTITY_CONTRACT = "@mozilla.org/dom/rtcidentityassertion;1";
 const PC_STATIC_CONTRACT = "@mozilla.org/dom/peerconnectionstatic;1";
 const PC_SENDER_CONTRACT = "@mozilla.org/dom/rtpsender;1";
 const PC_RECEIVER_CONTRACT = "@mozilla.org/dom/rtpreceiver;1";
 
-const PC_CID = Components.ID("{00e0e20d-1494-4776-8e0e-0f0acbea3c79}");
+const PC_CID = Components.ID("{bdc2e533-b308-4708-ac8e-a8bfade6d851}");
 const PC_OBS_CID = Components.ID("{d1748d4c-7f6a-4dc5-add6-d55b7678537e}");
 const PC_ICE_CID = Components.ID("{02b9970c-433d-4cc2-923d-f7028ac66073}");
 const PC_SESSION_CID = Components.ID("{1775081b-b62d-4954-8ffe-a067bbf508a7}");
 const PC_MANAGER_CID = Components.ID("{7293e901-2be3-4c02-b4bd-cbef6fc24f78}");
 const PC_STATS_CID = Components.ID("{7fe6e18b-0da3-4056-bf3b-440ef3809e06}");
 const PC_IDENTITY_CID = Components.ID("{1abc7499-3c54-43e0-bd60-686e2703f072}");
 const PC_STATIC_CID = Components.ID("{0fb47c47-a205-4583-a9fc-cbadf8c95880}");
 const PC_SENDER_CID = Components.ID("{4fff5d46-d827-4cd4-a970-8fd53977440e}");
@@ -844,17 +844,17 @@ RTCPeerConnection.prototype = {
   },
 
   _addIceCandidate: function(cand, onSuccess, onError) {
     this._onAddIceCandidateSuccess = onSuccess || null;
     this._onAddIceCandidateError = onError || null;
 
     this._impl.addIceCandidate(cand.candidate, cand.sdpMid || "",
                                (cand.sdpMLineIndex === null) ? 0 :
-                                 cand.sdpMLineIndex + 1);
+                                 cand.sdpMLineIndex);
   },
 
   addStream: function(stream) {
     stream.getTracks().forEach(track => this.addTrack(track, stream));
   },
 
   removeStream: function(stream) {
      // Bug 844295: Not implementing this functionality.
@@ -1117,17 +1117,17 @@ PeerConnectionObserver.prototype = {
     this._dompc = dompc._innerObject;
   },
 
   newError: function(code, message) {
     // These strings must match those defined in the WebRTC spec.
     const reasonName = [
       "",
       "InternalError",
-      "InternalError",
+      "InvalidCandidateError",
       "InvalidParameter",
       "InvalidStateError",
       "InvalidSessionDescriptionError",
       "IncompatibleSessionDescriptionError",
       "InternalError",
       "IncompatibleMediaStreamTrackError",
       "InternalError"
     ];
@@ -1216,17 +1216,17 @@ PeerConnectionObserver.prototype = {
   onIceCandidate: function(level, mid, candidate) {
     if (candidate == "") {
       this.foundIceCandidate(null);
     } else {
       this.foundIceCandidate(new this._dompc._win.mozRTCIceCandidate(
           {
               candidate: candidate,
               sdpMid: mid,
-              sdpMLineIndex: level - 1
+              sdpMLineIndex: level
           }
       ));
     }
   },
 
 
   // This method is primarily responsible for updating iceConnectionState.
   // This state is defined in the WebRTC specification as follows:
--- a/dom/media/PeerConnection.manifest
+++ b/dom/media/PeerConnection.manifest
@@ -1,20 +1,20 @@
-component {00e0e20d-1494-4776-8e0e-0f0acbea3c79} PeerConnection.js
+component {bdc2e533-b308-4708-ac8e-a8bfade6d851} PeerConnection.js
 component {d1748d4c-7f6a-4dc5-add6-d55b7678537e} PeerConnection.js
 component {02b9970c-433d-4cc2-923d-f7028ac66073} PeerConnection.js
 component {1775081b-b62d-4954-8ffe-a067bbf508a7} PeerConnection.js
 component {7293e901-2be3-4c02-b4bd-cbef6fc24f78} PeerConnection.js
 component {7fe6e18b-0da3-4056-bf3b-440ef3809e06} PeerConnection.js
 component {1abc7499-3c54-43e0-bd60-686e2703f072} PeerConnection.js
 component {0fb47c47-a205-4583-a9fc-cbadf8c95880} PeerConnection.js
 component {4fff5d46-d827-4cd4-a970-8fd53977440e} PeerConnection.js
 component {d974b814-8fde-411c-8c45-b86791b81030} PeerConnection.js
 
-contract @mozilla.org/dom/peerconnection;1 {00e0e20d-1494-4776-8e0e-0f0acbea3c79}
+contract @mozilla.org/dom/peerconnection;1 {bdc2e533-b308-4708-ac8e-a8bfade6d851}
 contract @mozilla.org/dom/peerconnectionobserver;1 {d1748d4c-7f6a-4dc5-add6-d55b7678537e}
 contract @mozilla.org/dom/rtcicecandidate;1 {02b9970c-433d-4cc2-923d-f7028ac66073}
 contract @mozilla.org/dom/rtcsessiondescription;1 {1775081b-b62d-4954-8ffe-a067bbf508a7}
 contract @mozilla.org/dom/peerconnectionmanager;1 {7293e901-2be3-4c02-b4bd-cbef6fc24f78}
 contract @mozilla.org/dom/rtcstatsreport;1 {7fe6e18b-0da3-4056-bf3b-440ef3809e06}
 contract @mozilla.org/dom/rtcidentityassertion;1 {1abc7499-3c54-43e0-bd60-686e2703f072}
 contract @mozilla.org/dom/peerconnectionstatic;1 {0fb47c47-a205-4583-a9fc-cbadf8c95880}
 contract @mozilla.org/dom/rtpsender;1 {4fff5d46-d827-4cd4-a970-8fd53977440e}
--- a/dom/media/bridge/IPeerConnection.idl
+++ b/dom/media/bridge/IPeerConnection.idl
@@ -54,16 +54,17 @@ interface IPeerConnection : nsISupports
 
   /* for 'type' in DataChannelInit dictionary */
   const unsigned short kDataChannelReliable = 0;
   const unsigned short kDataChannelPartialReliableRexmit = 1;
   const unsigned short kDataChannelPartialReliableTimed = 2;
 
   /* Constants for 'name' in error callbacks */
   const unsigned long kNoError                          = 0; // Test driver only
+  const unsigned long kInvalidCandidate                 = 2;
   const unsigned long kInvalidMediastreamTrack          = 3;
   const unsigned long kInvalidState                     = 4;
   const unsigned long kInvalidSessionDescription        = 5;
   const unsigned long kIncompatibleSessionDescription   = 6;
   const unsigned long kIncompatibleMediaStreamTrack     = 8;
   const unsigned long kInternalError                    = 9;
   const unsigned long kMaxErrorType                     = 9; // Same as final error
 };
--- a/dom/media/bridge/MediaModule.cpp
+++ b/dom/media/bridge/MediaModule.cpp
@@ -16,27 +16,27 @@
 
 #include "stun_udp_socket_filter.h"
 
 NS_DEFINE_NAMED_CID(NS_STUN_UDP_SOCKET_FILTER_HANDLER_CID)
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsStunUDPSocketFilterHandler)
 
 
-namespace sipcc
+namespace mozilla
 {
-// Factory defined in sipcc::, defines sipcc::PeerConnectionImplConstructor
+// Factory defined in mozilla::, defines mozilla::PeerConnectionImplConstructor
 NS_GENERIC_FACTORY_CONSTRUCTOR(PeerConnectionImpl)
 }
 
 // Defines kPEERCONNECTION_CID
 NS_DEFINE_NAMED_CID(PEERCONNECTION_CID);
 
 static const mozilla::Module::CIDEntry kCIDs[] = {
-  { &kPEERCONNECTION_CID, false, nullptr, sipcc::PeerConnectionImplConstructor },
+  { &kPEERCONNECTION_CID, false, nullptr, mozilla::PeerConnectionImplConstructor },
   { &kNS_STUN_UDP_SOCKET_FILTER_HANDLER_CID, false, nullptr, nsStunUDPSocketFilterHandlerConstructor },
   { nullptr }
 };
 
 static const mozilla::Module::ContractIDEntry kContracts[] = {
   { PEERCONNECTION_CONTRACTID, &kPEERCONNECTION_CID },
   { NS_STUN_UDP_SOCKET_FILTER_HANDLER_CONTRACTID, &kNS_STUN_UDP_SOCKET_FILTER_HANDLER_CID },
   { nullptr }
--- a/dom/webidl/PeerConnectionImpl.webidl
+++ b/dom/webidl/PeerConnectionImpl.webidl
@@ -62,24 +62,24 @@ interface PeerConnectionImpl  {
 
   /* Puts the SIPCC engine back to 'kIdle', shuts down threads, deletes state */
   void close();
 
   /* Notify DOM window if this plugin crash is ours. */
   boolean pluginCrash(unsigned long long pluginId, DOMString name, DOMString pluginDumpID);
 
   /* Attributes */
+  [Constant]
   readonly attribute DOMString fingerprint;
   readonly attribute DOMString localDescription;
   readonly attribute DOMString remoteDescription;
 
   readonly attribute PCImplIceConnectionState iceConnectionState;
   readonly attribute PCImplIceGatheringState iceGatheringState;
   readonly attribute PCImplSignalingState signalingState;
-  readonly attribute PCImplSipccState sipccState;
   attribute DOMString id;
 
   attribute DOMString peerIdentity;
   readonly attribute boolean privacyRequested;
 
   /* Data channels */
   [Throws]
   DataChannel createDataChannel(DOMString label, DOMString protocol,
--- a/media/mtransport/dtlsidentity.cpp
+++ b/media/mtransport/dtlsidentity.cpp
@@ -12,27 +12,24 @@
 #include "keyhi.h"
 #include "pk11pub.h"
 #include "sechash.h"
 #include "nsError.h"
 #include "dtlsidentity.h"
 
 namespace mozilla {
 
-MOZ_MTLOG_MODULE("mtransport")
-
 DtlsIdentity::~DtlsIdentity() {
   // XXX: make cert_ a smart pointer to avoid this, after we figure
   // out the linking problem.
   if (cert_)
     CERT_DestroyCertificate(cert_);
 }
 
 const std::string DtlsIdentity::DEFAULT_HASH_ALGORITHM = "sha-256";
-const size_t DtlsIdentity::HASH_ALGORITHM_MAX_LENGTH = 64;
 
 TemporaryRef<DtlsIdentity> DtlsIdentity::Generate() {
 
   ScopedPK11SlotInfo slot(PK11_GetInternalSlot());
   if (!slot) {
     return nullptr;
   }
 
@@ -205,94 +202,9 @@ nsresult DtlsIdentity::ComputeFingerprin
   if (rv != SECSuccess)
     return NS_ERROR_FAILURE;
 
   *digest_length = ho->length;
 
   return NS_OK;
 }
 
-// Format the fingerprint in RFC 4572 Section 5 attribute format, including both
-// the hash name and the fingerprint, colons and all.
-// returns an empty string if there is a problem
-std::string DtlsIdentity::GetFormattedFingerprint(const std::string &algorithm) {
-  unsigned char digest[HASH_ALGORITHM_MAX_LENGTH];
-  size_t digest_length;
-
-  nsresult res = this->ComputeFingerprint(algorithm,
-                                          digest,
-                                          sizeof(digest),
-                                          &digest_length);
-  if (NS_FAILED(res)) {
-    MOZ_MTLOG(ML_ERROR, "Unable to compute " << algorithm
-              << " hash for identity: nsresult = 0x"
-              << std::hex << std::uppercase
-              << static_cast<uint32_t>(res)
-              << std::nouppercase << std::dec);
-    return "";
-  }
-
-  return algorithm + " " + this->FormatFingerprint(digest, digest_length);
-}
-
-std::string DtlsIdentity::FormatFingerprint(const unsigned char *digest,
-                                            std::size_t size) {
-  std::string str("");
-  char group[3];
-
-  for (std::size_t i=0; i < size; i++) {
-    PR_snprintf(group, sizeof(group), "%.2X", digest[i]);
-    if (i != 0) {
-      str += ":";
-    }
-    str += group;
-  }
-
-  MOZ_ASSERT(str.size() == (size * 3 - 1));  // Check result length
-  return str;
-}
-
-// Parse a fingerprint in RFC 4572 format.
-// Note that this tolerates some badly formatted data, in particular:
-// (a) arbitrary runs of colons
-// (b) colons at the beginning or end.
-nsresult DtlsIdentity::ParseFingerprint(const std::string fp,
-                                        unsigned char *digest,
-                                        size_t size,
-                                        size_t *length) {
-  size_t offset = 0;
-  bool top_half = true;
-  uint8_t val = 0;
-
-  for (size_t i=0; i<fp.length(); i++) {
-    if (offset >= size) {
-      // Note: no known way for offset to get > size
-      MOZ_MTLOG(ML_ERROR, "Fingerprint too long for buffer");
-      return NS_ERROR_INVALID_ARG;
-    }
-
-    if (top_half && (fp[i] == ':')) {
-      continue;
-    } else if ((fp[i] >= '0') && (fp[i] <= '9')) {
-      val |= fp[i] - '0';
-    } else if ((fp[i] >= 'A') && (fp[i] <= 'F')) {
-      val |= fp[i] - 'A' + 10;
-    } else {
-      MOZ_MTLOG(ML_ERROR, "Invalid fingerprint value " << fp[i]);
-      return NS_ERROR_ILLEGAL_VALUE;
-    }
-
-    if (top_half) {
-      val <<= 4;
-      top_half = false;
-    } else {
-      digest[offset++] = val;
-      top_half = true;
-      val = 0;
-    }
-  }
-
-  *length = offset;
-
-  return NS_OK;
-}
-
 }  // close namespace
--- a/media/mtransport/dtlsidentity.h
+++ b/media/mtransport/dtlsidentity.h
@@ -28,44 +28,36 @@ class DtlsIdentity {
 
   // Note: the following two functions just provide access. They
   // do not transfer ownership. If you want a pointer that lasts
   // past the lifetime of the DtlsIdentity, you must make
   // a copy yourself.
   CERTCertificate *cert() { return cert_; }
   SECKEYPrivateKey *privkey() { return privkey_; }
 
-  std::string GetFormattedFingerprint(const std::string &algorithm = DEFAULT_HASH_ALGORITHM);
-
   nsresult ComputeFingerprint(const std::string algorithm,
                               unsigned char *digest,
                               std::size_t size,
                               std::size_t *digest_length);
 
   static nsresult ComputeFingerprint(const CERTCertificate *cert,
                                      const std::string algorithm,
                                      unsigned char *digest,
                                      std::size_t size,
                                      std::size_t *digest_length);
-
-  static nsresult ParseFingerprint(const std::string fp,
-                                   unsigned char *digest,
-                                   size_t size, size_t *length);
+  static const std::string DEFAULT_HASH_ALGORITHM;
+  enum {
+    HASH_ALGORITHM_MAX_LENGTH = 64
+  };
 
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DtlsIdentity)
 
- private:
+private:
   DtlsIdentity(SECKEYPrivateKey *privkey, CERTCertificate *cert)
       : privkey_(privkey), cert_(cert) {}
   DISALLOW_COPY_ASSIGN(DtlsIdentity);
 
-  static const std::string DEFAULT_HASH_ALGORITHM;
-  static const size_t HASH_ALGORITHM_MAX_LENGTH;
-
-  std::string FormatFingerprint(const unsigned char *digest,
-                                std::size_t size);
-
   ScopedSECKEYPrivateKey privkey_;
   CERTCertificate *cert_;  // TODO: Using a smart pointer here causes link
                            // errors.
 };
 }  // close namespace
 #endif
--- a/media/mtransport/logging.h
+++ b/media/mtransport/logging.h
@@ -35,12 +35,11 @@
     std::stringstream str;                                              \
     str << b;                                                           \
     PR_LOG(getLogModule(), level, ("%s", str.str().c_str())); } while(0)
 
 #else
 // PR_LOGGING is off --> make no-op MTLOG macros
 #define MOZ_MTLOG_MODULE(n)
 #define MOZ_MTLOG(level, b)
-
 #endif // defined(PR_LOGGING)
 
 #endif // logging_h__
--- a/media/mtransport/nricectx.cpp
+++ b/media/mtransport/nricectx.cpp
@@ -528,21 +528,31 @@ NrIceCtx::~NrIceCtx() {
   delete ice_handler_;
 }
 
 RefPtr<NrIceMediaStream>
 NrIceCtx::CreateStream(const std::string& name, int components) {
   RefPtr<NrIceMediaStream> stream =
     NrIceMediaStream::Create(this, name, components);
 
-  streams_.push_back(stream);
+  if (stream) {
+    streams_.push_back(stream);
+  }
 
   return stream;
 }
 
+std::string NrIceCtx::ufrag() const {
+  return ctx_->ufrag;
+}
+
+std::string NrIceCtx::pwd() const {
+  return ctx_->pwd;
+}
+
 void NrIceCtx::destroy_peer_ctx() {
   nr_ice_peer_ctx_destroy(&peer_);
 }
 
 nsresult NrIceCtx::SetControlling(Controlling controlling) {
   peer_->controlling = (controlling == ICE_CONTROLLING)? 1 : 0;
 
   MOZ_MTLOG(ML_DEBUG, "ICE ctx " << name_ << " setting controlling to" <<
--- a/media/mtransport/nricectx.h
+++ b/media/mtransport/nricectx.h
@@ -202,19 +202,30 @@ class NrIceCtx {
 
   // Testing only.
   void destroy_peer_ctx();
 
   // Create a media stream
   RefPtr<NrIceMediaStream> CreateStream(const std::string& name,
                                                  int components);
 
+  RefPtr<NrIceMediaStream> GetStream(size_t index) {
+    if (index < streams_.size()) {
+      return streams_[index];
+    }
+    return nullptr;
+  }
+
   // The name of the ctx
   const std::string& name() const { return name_; }
 
+  // Get ufrag and password.
+  std::string ufrag() const;
+  std::string pwd() const;
+
   // Current state
   ConnectionState connection_state() const {
     return connection_state_;
   }
 
   // Current state
   GatheringState gathering_state() const {
     return gathering_state_;
--- a/media/mtransport/nricemediastream.cpp
+++ b/media/mtransport/nricemediastream.cpp
@@ -333,16 +333,37 @@ nsresult NrIceMediaStream::GetCandidateP
     }
 
     out_pairs->push_back(pair);
   }
 
   return NS_OK;
 }
 
+nsresult NrIceMediaStream::GetDefaultCandidate(
+    NrIceCandidate* candidate) const {
+
+  nr_ice_candidate *cand;
+
+  int r = nr_ice_media_stream_get_default_candidate(stream_, 1, &cand);
+  if (r) {
+    MOZ_MTLOG(ML_ERROR, "Couldn't get default ICE candidate for '"
+              << name_ << "'");
+    return NS_ERROR_FAILURE;
+  }
+
+  if (!ToNrIceCandidate(*cand, candidate)) {
+    MOZ_MTLOG(ML_ERROR, "Failed to convert default ICE candidate for '"
+              << name_ << "'");
+    return NS_ERROR_FAILURE;
+  }
+
+  return NS_OK;
+}
+
 std::vector<std::string> NrIceMediaStream::GetCandidates() const {
   char **attrs = 0;
   int attrct;
   int r;
   std::vector<std::string> ret;
 
   r = nr_ice_media_stream_get_attributes(stream_,
                                          &attrs, &attrct);
--- a/media/mtransport/nricemediastream.h
+++ b/media/mtransport/nricemediastream.h
@@ -131,32 +131,36 @@ class NrIceMediaStream {
 
   nsresult GetLocalCandidates(std::vector<NrIceCandidate>* candidates) const;
   nsresult GetRemoteCandidates(std::vector<NrIceCandidate>* candidates) const;
 
   // Get all candidate pairs, whether in the check list or triggered check
   // queue, in priority order. |out_pairs| is cleared before being filled.
   nsresult GetCandidatePairs(std::vector<NrIceCandidatePair>* out_pairs) const;
 
+  // TODO(bug 1096795): This needs to take a component number, so we can get
+  // default candidates for rtcp.
+  nsresult GetDefaultCandidate(NrIceCandidate* candidate) const;
+
   // Parse remote attributes
   nsresult ParseAttributes(std::vector<std::string>& candidates);
 
   // Parse trickle ICE candidate
   nsresult ParseTrickleCandidate(const std::string& candidate);
 
   // Disable a component
   nsresult DisableComponent(int component);
 
   // Get the candidate pair currently active. It's the
   // caller's responsibility to free these.
   nsresult GetActivePair(int component,
                          NrIceCandidate** local, NrIceCandidate** remote);
 
   // The number of components
-  int components() const { return components_; }
+  size_t components() const { return components_; }
 
   // The underlying nICEr stream
   nr_ice_media_stream *stream() { return stream_; }
   // Signals to indicate events. API users can (and should)
   // register for these.
 
   // Send a packet
   nsresult SendPacket(int component_id, const unsigned char *data, size_t len);
@@ -183,31 +187,31 @@ class NrIceMediaStream {
   sigslot::signal1<NrIceMediaStream *> SignalFailed;  // Candidate pair failed.
   sigslot::signal4<NrIceMediaStream *, int, const unsigned char *, int>
   SignalPacketReceived;  // Incoming packet
 
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(NrIceMediaStream)
 
  private:
   NrIceMediaStream(NrIceCtx *ctx,  const std::string& name,
-                   int components) :
+                   size_t components) :
       state_(ICE_CONNECTING),
       ctx_(ctx),
       name_(name),
       components_(components),
       stream_(nullptr),
       level_(0) {}
 
   ~NrIceMediaStream();
 
   DISALLOW_COPY_ASSIGN(NrIceMediaStream);
 
   State state_;
   NrIceCtx *ctx_;
   const std::string name_;
-  const int components_;
+  const size_t components_;
   nr_ice_media_stream *stream_;
   uint16_t level_;
 };
 
 
 }  // close namespace
 #endif
--- a/media/mtransport/test/ice_unittest.cpp
+++ b/media/mtransport/test/ice_unittest.cpp
@@ -540,17 +540,17 @@ class IceTestPeer : public sigslot::has_
               << " codeword="
               << cand.codeword
               << std::endl;
   }
 
   void DumpAndCheckActiveCandidates_s() {
     std::cerr << "Active candidates:" << std::endl;
     for (size_t i=0; i < streams_.size(); ++i) {
-      for (int j=0; j < streams_[i]->components(); ++j) {
+      for (size_t j=0; j < streams_[i]->components(); ++j) {
         std::cerr << "Stream " << i << " component " << j+1 << std::endl;
 
         NrIceCandidate *local;
         NrIceCandidate *remote;
 
         nsresult res = streams_[i]->GetActivePair(j+1, &local, &remote);
         if (res == NS_ERROR_NOT_AVAILABLE) {
           std::cerr << "Component unpaired or disabled." << std::endl;
--- a/media/mtransport/test/transport_unittests.cpp
+++ b/media/mtransport/test/transport_unittests.cpp
@@ -602,17 +602,18 @@ class TransportTestPeer : public sigslot
     ASSERT_TRUE(stream != nullptr);
     streams_.push_back(stream);
 
     // Listen for candidates
     stream->SignalCandidate.
         connect(this, &TransportTestPeer::GotCandidate);
 
     // Create the transport layer
-    ice_ = new TransportLayerIce(name, ice_ctx_, stream, 1);
+    ice_ = new TransportLayerIce(name);
+    ice_->SetParameters(ice_ctx_, stream, 1);
 
     // Assemble the stack
     nsAutoPtr<std::queue<mozilla::TransportLayer *> > layers(
       new std::queue<mozilla::TransportLayer *>);
     layers->push(ice_);
     layers->push(dtls_);
 
     test_utils->sts_target()->Dispatch(
--- a/media/mtransport/third_party/nICEr/src/ice/ice_candidate.c
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_candidate.c
@@ -458,17 +458,19 @@ int nr_ice_candidate_initialize(nr_ice_c
     cand->done_cb=ready_cb;
     cand->cb_arg=cb_arg;
 
     switch(cand->type){
       case HOST:
         if(r=nr_socket_getaddr(cand->isock->sock,&cand->addr))
           ABORT(r);
         cand->osock=cand->isock->sock;
-        cand->state=NR_ICE_CAND_STATE_INITIALIZED;
+        // This is actually ready, but we set this anyway to prevent it from
+        // being paired twice.
+        cand->state=NR_ICE_CAND_STATE_INITIALIZING;
         // Post this so that it doesn't happen in-line
         cand->ready_cb = ready_cb;
         cand->ready_cb_arg = cb_arg;
         NR_ASYNC_TIMER_SET(0, nr_ice_candidate_fire_ready_cb, (void *)cand, &cand->ready_cb_timer);
         break;
 #ifdef USE_TURN
       case RELAYED:
         protocol=NR_RESOLVE_PROTOCOL_TURN;
--- a/media/mtransport/third_party/nICEr/src/ice/ice_component.c
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_component.c
@@ -788,20 +788,21 @@ int nr_ice_component_pair_candidate(nr_i
 
         1. Pair remote candidates which have not been paired
            (used in initial pairing or in processing the other side's
            trickle candidates).
         2. Pair any remote candidate (used when processing our own
            trickle candidates).
       */
       if (pair_all_remote || (pcand->state == NR_ICE_CAND_PEER_CANDIDATE_UNPAIRED)) {
-        /* If we are pairing our own trickle candidates, the remote candidate should
-           all be paired */
-        if (pair_all_remote)
-          assert (pcand->state == NR_ICE_CAND_PEER_CANDIDATE_PAIRED);
+        if (pair_all_remote) {
+          /* When a remote candidate arrives after the start of checking, but
+           * before the gathering of local candidates, it can be in UNPAIRED */
+          pcand->state = NR_ICE_CAND_PEER_CANDIDATE_PAIRED;
+        }
 
         nr_ice_compute_codeword(pcand->label,strlen(pcand->label),codeword);
         r_log(LOG_ICE,LOG_DEBUG,"ICE-PEER(%s)/CAND(%s): Pairing with peer candidate %s", pctx->label, codeword, pcand->label);
 
         if(r=nr_ice_candidate_pair_create(pctx,lcand,pcand,&pair))
           ABORT(r);
 
         if(r=nr_ice_component_insert_pair(pcomp, pair))
@@ -1096,20 +1097,22 @@ int nr_ice_component_insert_pair(nr_ice_
       assert(0);
       ABORT(R_BAD_ARGS);
     }
 
     if(r=nr_ice_candidate_pair_insert(&pair->remote->stream->check_list,pair))
       ABORT(r);
 
     /* Make sure the check timer is running, if the stream was previously
-     * started. We will not start streams just because a pair was created. */
+     * started. We will not start streams just because a pair was created,
+     * unless it is the first pair to be created across all streams. */
     r_log(LOG_ICE,LOG_DEBUG,"ICE-PEER(%s)/CAND-PAIR(%s): Ensure that check timer is running for new pair %s.",pair->remote->stream->pctx->label, pair->codeword, pair->as_string);
 
-    if(pair->remote->stream->ice_state == NR_ICE_MEDIA_STREAM_CHECKS_ACTIVE){
+    if(pair->remote->stream->ice_state == NR_ICE_MEDIA_STREAM_CHECKS_ACTIVE ||
+       !pair->remote->stream->pctx->checks_started){
       if(nr_ice_media_stream_start_checks(pair->remote->stream->pctx, pair->remote->stream)) {
         r_log(LOG_ICE,LOG_WARNING,"ICE-PEER(%s)/CAND-PAIR(%s): Could not restart checks for new pair %s.",pair->remote->stream->pctx->label, pair->codeword, pair->as_string);
         ABORT(R_INTERNAL);
       }
     }
 
     _status=0;
   abort:
--- a/media/mtransport/third_party/nICEr/src/ice/ice_ctx.c
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_ctx.c
@@ -450,30 +450,34 @@ void nr_ice_initialize_finished_cb(NR_SO
 
     assert(cb_arg);
     if (!cb_arg)
       return;
     ctx = cand->ctx;
 
     ctx->uninitialized_candidates--;
 
+    // Avoid the need for yet another initialization function
+    if (cand->state == NR_ICE_CAND_STATE_INITIALIZING && cand->type == HOST)
+      cand->state = NR_ICE_CAND_STATE_INITIALIZED;
+
     if (cand->state == NR_ICE_CAND_STATE_INITIALIZED) {
       int was_pruned = 0;
 
       if (r=nr_ice_component_maybe_prune_candidate(ctx, cand->component,
                                                    cand, &was_pruned)) {
           r_log(LOG_ICE, LOG_NOTICE, "ICE(%s): Problem pruning candidates",ctx->label);
       }
 
       /* If we are initialized, the candidate wasn't pruned,
          and we have a trickle ICE callback fire the callback */
       if (ctx->trickle_cb && !was_pruned) {
         ctx->trickle_cb(ctx->trickle_cb_arg, ctx, cand->stream, cand->component_id, cand);
 
-        if (r=nr_ice_ctx_pair_new_trickle_candidates(ctx, cand)) {
+        if (nr_ice_ctx_pair_new_trickle_candidates(ctx, cand)) {
           r_log(LOG_ICE,LOG_ERR, "ICE(%s): All could not pair new trickle candidate",ctx->label);
           /* But continue */
         }
       }
     }
 
     if(ctx->uninitialized_candidates==0){
       r_log(LOG_ICE,LOG_DEBUG,"ICE(%s): All candidates initialized",ctx->label);
--- a/media/mtransport/third_party/nICEr/src/ice/ice_parser.c
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_parser.c
@@ -132,16 +132,20 @@ nr_ice_peer_candidate_from_attribute(nr_
         ABORT(R_NO_MEMORY);
 
     cand->ctx=ctx;
     cand->isock=0;
     cand->state=NR_ICE_CAND_PEER_CANDIDATE_UNPAIRED;
     cand->stream=stream;
     skip_whitespace(&str);
 
+    /* Skip a= if present */
+    if (!strncmp(str, "a=", 2))
+        str += 2;
+
     /* Candidate attr */
     if (strncasecmp(str, "candidate:", 10))
         ABORT(R_BAD_DATA);
 
     fast_forward(&str, 10);
     if (*str == '\0')
         ABORT(R_BAD_DATA);
 
--- a/media/mtransport/third_party/nICEr/src/ice/ice_peer_ctx.c
+++ b/media/mtransport/third_party/nICEr/src/ice/ice_peer_ctx.c
@@ -166,17 +166,17 @@ static int nr_ice_peer_ctx_parse_stream_
       }
       else if (!strncmp(attrs[i],"candidate",9)){
         if(r=nr_ice_ctx_parse_candidate(pctx,pstream,attrs[i])) {
           r_log(LOG_ICE,LOG_WARNING,"ICE(%s): peer (%s) specified bogus candidate",pctx->ctx->label,pctx->label);
           continue;
         }
       }
       else {
-        r_log(LOG_ICE,LOG_WARNING,"ICE(%s): peer (%s) specified bogus attribute",pctx->ctx->label,pctx->label);
+        r_log(LOG_ICE,LOG_WARNING,"ICE(%s): peer (%s) specified bogus attribute: %s",pctx->ctx->label,pctx->label,attrs[i]);
       }
     }
 
     /* Doesn't fail because we just skip errors */
     return(0);
   }
 
 static int nr_ice_ctx_parse_candidate(nr_ice_peer_ctx *pctx, nr_ice_media_stream *pstream, char *candidate)
@@ -215,16 +215,19 @@ static int nr_ice_ctx_parse_candidate(nr
       r_log(LOG_ICE,LOG_WARNING,"Peer offered candidates for disabled local component");
       ABORT(R_BAD_DATA);
     }
 
     cand->component=comp;
 
     TAILQ_INSERT_TAIL(&comp->candidates,cand,entry_comp);
 
+    r_log(LOG_ICE,LOG_DEBUG,"ICE-PEER(%s)/CAND(%s): creating peer candidate",
+      pctx->label,cand->label);
+
     _status=0;
  abort:
     if (_status) {
       nr_ice_candidate_destroy(&cand);
     }
     return(_status);
   }
 
@@ -286,35 +289,35 @@ int nr_ice_peer_ctx_parse_trickle_candid
        then we need to pair this new candidate. For now we
        just re-pair the stream which is inefficient but still
        fine because we suppress duplicate pairing */
     if (needs_pairing) {
       if(r=nr_ice_media_stream_pair_candidates(pctx, stream, pstream)) {
         r_log(LOG_ICE,LOG_ERR,"ICE(%s): peer (%s), stream(%s) failed to pair trickle ICE candidates",pctx->ctx->label,pctx->label,stream->label);
         ABORT(r);
       }
-    }
 
-    /* Start checks if this stream is not checking yet or if it has checked
-       all the available candidates but not had a completed check for all
-       components.
+      /* Start checks if this stream is not checking yet or if it has checked
+         all the available candidates but not had a completed check for all
+         components.
 
-       Note that this is not compliant with RFC 5245, but consistent with
-       the libjingle trickle ICE behavior. Note that we will not restart
-       checks if either (a) the stream has failed or (b) all components
-       have a successful pair because the switch statement above jumps
-       will in both states.
+         Note that this is not compliant with RFC 5245, but consistent with
+         the libjingle trickle ICE behavior. Note that we will not restart
+         checks if either (a) the stream has failed or (b) all components
+         have a successful pair because the switch statement above jumps
+         will in both states.
 
-       TODO(ekr@rtfm.com): restart checks.
-       TODO(ekr@rtfm.com): update when the trickle ICE RFC is published
-    */
-    if (!pstream->timer) {
-      if(r=nr_ice_media_stream_start_checks(pctx, pstream)) {
-        r_log(LOG_ICE,LOG_ERR,"ICE(%s): peer (%s), stream(%s) failed to start checks",pctx->ctx->label,pctx->label,stream->label);
-        ABORT(r);
+         TODO(ekr@rtfm.com): restart checks.
+         TODO(ekr@rtfm.com): update when the trickle ICE RFC is published
+      */
+      if (!pstream->timer) {
+        if(r=nr_ice_media_stream_start_checks(pctx, pstream)) {
+          r_log(LOG_ICE,LOG_ERR,"ICE(%s): peer (%s), stream(%s) failed to start checks",pctx->ctx->label,pctx->label,stream->label);
+          ABORT(r);
+        }
       }
     }
 
     _status=0;
  abort:
     return(_status);
 
   }
--- a/media/mtransport/transportlayerice.cpp
+++ b/media/mtransport/transportlayerice.cpp
@@ -79,35 +79,45 @@ extern "C" {
 namespace mozilla {
 
 #ifdef ERROR
 #undef ERROR
 #endif
 
 MOZ_MTLOG_MODULE("mtransport")
 
-TransportLayerIce::TransportLayerIce(const std::string& name,
-    RefPtr<NrIceCtx> ctx, RefPtr<NrIceMediaStream> stream,
-                                     int component)
-    : name_(name), ctx_(ctx), stream_(stream), component_(component) {
-  target_ = ctx->thread();
+TransportLayerIce::TransportLayerIce(const std::string& name)
+    : name_(name), ctx_(nullptr), stream_(nullptr), component_(0) {}
+
+TransportLayerIce::~TransportLayerIce() {
+  // No need to do anything here, since we use smart pointers
+}
+
+void TransportLayerIce::SetParameters(RefPtr<NrIceCtx> ctx,
+                                      RefPtr<NrIceMediaStream> stream,
+                                      int component) {
+  ctx_ = ctx;
+  stream_ = stream;
+  component_ = component;
+
+  PostSetup();
+}
+
+void TransportLayerIce::PostSetup() {
+  target_ = ctx_->thread();
 
   stream_->SignalReady.connect(this, &TransportLayerIce::IceReady);
   stream_->SignalFailed.connect(this, &TransportLayerIce::IceFailed);
   stream_->SignalPacketReceived.connect(this,
                                         &TransportLayerIce::IcePacketReceived);
   if (stream_->state() == NrIceMediaStream::ICE_OPEN) {
     TL_SET_STATE(TS_OPEN);
   }
 }
 
-TransportLayerIce::~TransportLayerIce() {
-  // No need to do anything here, since we use smart pointers
-}
-
 TransportResult TransportLayerIce::SendPacket(const unsigned char *data,
                                               size_t len) {
   CheckThread();
   nsresult res = stream_->SendPacket(component_, data, len);
 
   if (!NS_SUCCEEDED(res)) {
     return (res == NS_BASE_STREAM_WOULD_BLOCK) ?
         TE_WOULDBLOCK : TE_ERROR;
--- a/media/mtransport/transportlayerice.h
+++ b/media/mtransport/transportlayerice.h
@@ -26,36 +26,39 @@
 #include "transportflow.h"
 #include "transportlayer.h"
 
 // An ICE transport layer -- corresponds to a single ICE
 namespace mozilla {
 
 class TransportLayerIce : public TransportLayer {
  public:
-  TransportLayerIce(const std::string& name,
-                    RefPtr<NrIceCtx> ctx,
-                    RefPtr<NrIceMediaStream> stream,
-                    int component);
+  explicit TransportLayerIce(const std::string& name);
+
   virtual ~TransportLayerIce();
 
+  void SetParameters(RefPtr<NrIceCtx> ctx,
+                     RefPtr<NrIceMediaStream> stream,
+                     int component);
+
   // Transport layer overrides.
   virtual TransportResult SendPacket(const unsigned char *data, size_t len);
 
   // Slots for ICE
   void IceCandidate(NrIceMediaStream *stream, const std::string&);
   void IceReady(NrIceMediaStream *stream);
   void IceFailed(NrIceMediaStream *stream);
   void IcePacketReceived(NrIceMediaStream *stream, int component,
                          const unsigned char *data, int len);
 
   TRANSPORT_LAYER_ID("ice")
 
  private:
   DISALLOW_COPY_ASSIGN(TransportLayerIce);
+  void PostSetup();
 
   const std::string name_;
   RefPtr<NrIceCtx> ctx_;
   RefPtr<NrIceMediaStream> stream_;
   int component_;
 };
 
 }  // close namespace
deleted file mode 100644
--- a/media/webrtc/signaling/include/CC_Call.h
+++ /dev/null
@@ -1,314 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#pragma once
-
-#include "CC_Common.h"
-#include "ECC_Types.h"
-#include "mozilla/RefPtr.h"
-
-extern "C"
-{
-#include "ccapi_types.h"
-#include "fsmdef_states.h"
-}
-
-#if defined(__cplusplus) && __cplusplus >= 201103L
-typedef struct Timecard Timecard;
-#else
-#include "timecard.h"
-#endif
-
-namespace CSF
-{
-    class ECC_API CC_Call
-    {
-    public:
-        NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CC_Call)
-
-    protected:
-        CC_Call () { }
-
-        virtual ~CC_Call () {}
-
-    public:
-		virtual void setRemoteWindow (VideoWindowHandle window) = 0;
-
-		virtual int setExternalRenderer(VideoFormat videoFormat, ExternalRendererHandle renderer) = 0;
-
-		virtual void sendIFrame	() = 0;
-
-        virtual void getLocalSdp(std::string *sdp) const = 0;
-        virtual void getRemoteSdp(std::string *sdp) const = 0;
-        virtual fsmdef_states_t getFsmState () const = 0;
-        virtual std::string fsmStateToString (fsmdef_states_t state) const = 0;
-
-        virtual void getErrorString(std::string *error) const = 0;
-        virtual pc_error getError() const = 0;
-
-        virtual CC_CallInfoPtr getCallInfo () = 0;
-
-        virtual std::string toString() = 0;
-
-        /**
-           Originate call - API to go offhook and dial specified digits on a given call
-
-           @param [in] video_pref - video direction desired on call
-           @param [in] digits - digits to be dialed. can be empty then this API simply goes offhook
-
-           @return true or false.
-         */
-        virtual bool originateCall (cc_sdp_direction_t video_pref, const std::string & digits) = 0;
-
-        /**
-           Use this function to answer an incoming call.
-
-           @param[in] video_pref - video direction desired on call
-
-           @return true or false.
-         */
-        virtual bool answerCall (cc_sdp_direction_t video_pref) = 0;
-
-        /**
-           Use this function to put an active call on hold.
-
-           @param[in] reason - If the user chooses to put the call on hold then
-                               CC_HOLD_REASON_NONE should be the value passed in here.
-
-           @return true or false. If it's not appropriate to put this call on
-                   hold at the moment then this function will return false.
-         */
-        virtual bool hold (cc_hold_reason_t reason) = 0;
-
-        /**
-           Use this function to resume a call that is currently on hold.
-
-           @param [in] video_pref - video direction desired on call
-
-           @return true or false
-         */
-        virtual bool resume (cc_sdp_direction_t video_pref) = 0;
-
-        /**
-           Use this function to end an active call.
-
-           @return true or false
-         */
-        virtual bool endCall() = 0;
-
-        /**
-           Send digits on the call - can be invoked either to dial additional digits or send DTMF
-
-           @param [in] digit - digit to be dialed
-
-           @return true or false
-         */
-        virtual bool sendDigit (cc_digit_t digit) = 0;
-
-        /**
-           Send Backspace - Delete last digit dialed.
-
-           @return true or false
-         */
-        virtual bool backspace() = 0;
-
-        /**
-           Redial
-
-           @param [in] video_pref - video direction desired on call
-           @return true or false
-         */
-        virtual bool redial (cc_sdp_direction_t video_pref) = 0;
-
-        /**
-           Initiate Call Forward All
-
-           @return true or false
-         */
-        virtual bool initiateCallForwardAll() = 0;
-
-        /**
-           end Consult leg - used to end consult leg when the user picks active calls list for xfer/conf
-
-           @return true or false
-         */
-        virtual bool endConsultativeCall() = 0;
-
-        /**
-           Initiate a conference
-
-           @param [in] video_pref - video direction desired on consult call
-
-           @return true or false
-         */
-        virtual bool conferenceStart (cc_sdp_direction_t video_pref) = 0;
-
-        /**
-           complete conference
-
-           @param [in] otherCall - CC_CallPtr of the other leg
-           @param [in] video_pref - video direction desired on consult call
-
-           @return true or false
-         */
-        virtual bool conferenceComplete (CC_CallPtr otherLog, cc_sdp_direction_t video_pref) = 0;
-
-        /**
-           start transfer
-
-           @param [in] video_pref - video direction desired on consult call
-
-           @return true or false
-         */
-        virtual bool transferStart (cc_sdp_direction_t video_pref) = 0;
-
-        /**
-           complete transfer
-
-           @param [in] otherLeg - CC_CallPtr of the other leg
-           @param [in] video_pref - video direction desired on consult call
-
-           @return true or false
-         */
-        virtual bool transferComplete (CC_CallPtr otherLeg,
-                                       cc_sdp_direction_t video_pref) = 0;
-
-        /**
-           cancel conference or transfer
-
-           @return true or false
-         */
-        virtual bool cancelTransferOrConferenceFeature() = 0;
-
-        /**
-           direct Transfer
-
-           @param [in] target - call handle for transfer target call
-           @return true or false
-         */
-        virtual bool directTransfer (CC_CallPtr target) = 0;
-
-        /**
-           Join Across line
-
-           @param [in] target - join target
-           @return true or false
-         */
-        virtual bool joinAcrossLine (CC_CallPtr target) = 0;
-
-        /**
-           BLF Call Pickup
-
-           @param [in] video_pref - video direction preference
-           @param [in] speed - speedDial Number
-           @return true or false
-         */
-        virtual bool blfCallPickup (cc_sdp_direction_t video_pref, const std::string & speed) = 0;
-
-        /**
-           Select a call
-
-           @return true or false
-         */
-        virtual bool select() = 0;
-
-        /**
-           Update Video Media Cap for the call
-
-           @param [in] video_pref - video direction desired on call
-           @return true or false
-         */
-        virtual bool updateVideoMediaCap (cc_sdp_direction_t video_pref) = 0;
-
-        /**
-           send INFO method for the call
-           @param [in] handle - call handle
-           @param [in] infopackage - Info-Package header value
-           @param [in] infotype - Content-Type header val
-           @param [in] infobody - Body of the INFO message
-           @return true or false
-         */
-        virtual bool sendInfo (const std::string & infopackage, const std::string & infotype, const std::string & infobody) = 0;
-
-        /**
-           API to mute audio
-
-           @return true if the operation succeeded
-
-           NOTE: The mute state is persisted within the stack and shall be remembered across hold/resume.
-         */
-        virtual bool muteAudio(void) = 0;
-
-
-        /**
-           API to unmute audio
-
-           @return true if the operation succeeded
-
-           NOTE: The mute state is persisted within the stack and shall be remembered across hold/resume.
-         */
-        virtual bool unmuteAudio(void) = 0;
-        /**
-           API to mute video
-
-           @return true if the operation succeeded
-
-           NOTE: The mute state is persisted within the stack and shall be remembered across hold/resume.
-         */
-        virtual bool muteVideo(void) = 0;
-
-
-        /**
-           API to unmute video
-
-           @return true if the operation succeeded
-
-           NOTE: The mute state is persisted within the stack and shall be remembered across hold/resume.
-         */
-        virtual bool unmuteVideo(void) = 0;
-
-
-        /**
-        API to set the call volume, acceptable values are 0 - 100
-        @return true if volume set successfully, false if value out of range or change failed
-        */
-        virtual bool setVolume(int volume) = 0;
-
-
-        /**
-           Originate P2P call - API to go offhook and dial specified digits\user on a given call
-
-           @param [in] video_pref - video direction desired on call
-           @param [in] digits - digits to be dialed. can be empty then this API simply goes offhook
-           @param [in] ip address - the ip address of the peer to call
-
-           @return void
-          */
-        virtual void originateP2PCall (cc_sdp_direction_t video_pref, const std::string & digits, const std::string & ip) = 0;
-
-        virtual pc_error createOffer (cc_media_options_t* options, Timecard *) = 0;
-
-        virtual pc_error createAnswer(Timecard *) = 0;
-
-        virtual pc_error setLocalDescription(cc_jsep_action_t action, const std::string & sdp, Timecard *) = 0;
-
-        virtual pc_error setRemoteDescription(cc_jsep_action_t action, const std::string & sdp, Timecard *) = 0;
-
-        virtual pc_error setPeerConnection(const std::string& handle) = 0;
-
-        virtual pc_error addStream(cc_media_stream_id_t stream_id,
-                               cc_media_track_id_t track_id,
-                               cc_media_type_t media_type) = 0;
-
-        virtual pc_error removeStream(cc_media_stream_id_t stream_id, cc_media_track_id_t track_id, cc_media_type_t media_type) = 0;
-
-        virtual const std::string& getPeerConnection() const = 0;
-
-        virtual pc_error addICECandidate(const std::string & candidate, const std::string & mid, unsigned short level, Timecard *) = 0;
-
-        virtual pc_error foundICECandidate(const std::string & candidate, const std::string & mid, unsigned short level, Timecard *) = 0;
-
-    };
-}
-
deleted file mode 100644
--- a/media/webrtc/signaling/include/CC_CallInfo.h
+++ /dev/null
@@ -1,339 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#pragma once
-
-#include <set>
-
-extern "C"
-{
-#include "ccapi_types.h"
-#include "fsmdef_states.h"
-}
-
-
-#include "CC_Common.h"
-#include "CC_CallTypes.h"
-#include "peer_connection_types.h"
-
-#if defined(__cplusplus) && __cplusplus >= 201103L
-typedef struct Timecard Timecard;
-#else
-#include "timecard.h"
-#endif
-
-namespace CSF
-{
-
-	class ECC_API CC_CallInfo
-    {
-    public:
-        NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CC_CallInfo)
-    protected:
-        CC_CallInfo() { }
-
-        //Base class needs dtor to be declared as virtual
-        virtual ~CC_CallInfo() {};
-
-    public:
-        /**
-           Get the line object associated with this call.
-
-           @return CC_LinePtr - line ID
-         */
-        virtual CC_LinePtr getline () = 0;
-
-        /**
-           get Call state
-           @param [in] handle - call info handle
-           @return call state
-         */
-        virtual cc_call_state_t getCallState () = 0;
-
-        /**
-           get FSM state
-           @param [in] handle - call info handle
-           @return FSM state
-         */
-        virtual fsmdef_states_t getFsmState () const = 0;
-
-        /**
-           print Call state
-           @param [in] handle - call info handle
-           @return call state as string
-         */
-        virtual std::string callStateToString (cc_call_state_t state) = 0;
-
-        /**
-           print FSM state
-           @param [in] handle - call info handle
-           @return call state as string
-         */
-        virtual std::string fsmStateToString (fsmdef_states_t state) const = 0;
-
-        /**
-           print Call event
-           @param [in] call event
-           @return call event as string
-         */
-        virtual std::string callEventToString (ccapi_call_event_e callEvent) = 0;
-
-        /**
-           Get ringer state.
-
-           @return bool ringer state.
-         */
-        virtual bool getRingerState() = 0;
-
-        /**
-           Get call attributes
-
-           @return cc_call_attr_t.
-         */
-        virtual cc_call_attr_t getCallAttr() = 0;
-
-        /**
-           Get the call type
-
-           @return cc_call_type_t for this call. Supported values inlude:
-                   CC_CALL_TYPE_INCOMING, CC_CALL_TYPE_OUTGOING and CC_CALL_TYPE_FORWARDED.
-         */
-        virtual cc_call_type_t getCallType() = 0;
-
-        /**
-           Get called party name
-
-           @return called party name
-         */
-        virtual std::string getCalledPartyName() = 0;
-
-        /**
-           Get called party number
-
-           @return called party number as a string.
-         */
-        virtual std::string getCalledPartyNumber() = 0;
-
-        /**
-           Get calling party name
-
-           @return calling party name
-         */
-        virtual std::string getCallingPartyName() = 0;
-
-        /**
-           Get calling party number
-           @return calling party number as a string
-                   Note: this is a const reference to a string that's owned by the
-          */
-        virtual std::string getCallingPartyNumber() = 0;
-
-        /**
-           Get alternate number
-
-           @return calling party number as a string.
-         */
-        virtual std::string getAlternateNumber() = 0;
-
-        /**
-           This function is used to check if a given capability is supported
-           based on the information in this CC_CallInfo object.
-
-           @param [in] capability - the capability that is to be checked for availability.
-           @return boolean - returns true if the given capability is available, false otherwise.
-         */
-        virtual bool hasCapability (CC_CallCapabilityEnum::CC_CallCapability capability) = 0;
-
-        /**
-           If you need the complete set of capabilities
-
-           @return cc_return_t - set of Call Capabilities.
-         */
-        virtual std::set<CC_CallCapabilityEnum::CC_CallCapability> getCapabilitySet() = 0;
-
-        /**
-           get Original Called party name
-           @param [in] handle - call info handle
-           @return original called party name
-         */
-        virtual std::string getOriginalCalledPartyName() = 0;
-
-        /**
-           get Original Called party number
-           @param [in] handle - call info handle
-           @return original called party number
-         */
-        virtual std::string getOriginalCalledPartyNumber() = 0;
-
-        /**
-           get last redirecting party name
-           @param [in] handle - call info handle
-           @return last redirecting party name
-         */
-        virtual std::string getLastRedirectingPartyName() = 0;
-
-        /**
-           get past redirecting party number
-           @param [in] handle - call info handle
-           @return last redirecting party number
-         */
-        virtual std::string getLastRedirectingPartyNumber() = 0;
-
-        /**
-           get placed call party name
-           @param [in] handle - call info handle
-           @return placed party name
-         */
-        virtual std::string getPlacedCallPartyName() = 0;
-
-        /**
-           get placed call party number
-           @param [in] handle - call info handle
-           @return placed party number
-         */
-        virtual std::string getPlacedCallPartyNumber() = 0;
-
-        /**
-           get call instance number
-           @param [in] handle - call info handle
-           @return
-         */
-        virtual cc_int32_t getCallInstance() = 0;
-
-        /**
-           get call status prompt
-           @param [in] handle - call info handle
-           @return call status
-         */
-        virtual std::string getStatus() = 0;
-
-        /**
-           get call security   // TODO XLS has callagent security and endtoend security on call?
-           @param [in] handle - call info handle
-           @return call security status
-         */
-        virtual cc_call_security_t getSecurity() = 0;
-
-        /**
-           get Call Selection Status
-           @param [in] handle - call info handle
-           @return bool - TRUE => selected
-         */
-        virtual cc_int32_t getSelectionStatus() = 0;
-
-        /**
-           get GCID
-           @param [in] handle - call info handle
-           @return GCID
-         */
-        virtual std::string getGCID() = 0;
-
-        /**
-           get ringer loop count
-           @param handle - call handle
-           @return once Vs continuous
-         */
-        virtual bool getIsRingOnce() = 0;
-
-        /**
-           get ringer mode
-           @param handle - call handle
-           @return ringer mode
-         */
-        virtual int getRingerMode() = 0;
-
-        /**
-           get onhook reason
-           @param [in] handle - call info handle
-           @return onhook reason
-         */
-        virtual cc_int32_t getOnhookReason() = 0;
-
-        /**
-           is Conference Call?
-           @param [in] handle - call info handle
-           @return boolean - is Conference
-         */
-        virtual bool getIsConference() = 0;
-
-        /**
-           getStream Statistics
-           @param [in] handle - call info handle
-           @param [in,out] stats - Array to get the stats
-           @param [in,out] count - in len of stats arraysize of stats / out stats copied
-           @return cc_return_t - CC_SUCCESS or CC_FAILURE
-         */
-        virtual std::set<cc_int32_t> getStreamStatistics() = 0;
-
-        /**
-           Call selection status
-           @param [in] handle - call info handle
-           @return bool - selection status
-         */
-        virtual bool isCallSelected() = 0;
-
-        /**
-           INFO Package for RECEIVED_INFO event
-           @param [in] handle - call info handle
-           @return string - Info package header
-         */
-        virtual std::string getINFOPack() = 0;
-
-        /**
-           INFO type for RECEIVED_INFO event
-
-           @return string - content-type  header
-         */
-        virtual std::string getINFOType() = 0;
-
-        /**
-           INFO body for RECEIVED_INFO event
-
-           @return string - INFO body
-         */
-        virtual std::string getINFOBody() = 0;
-
-        /**
-           Get the call log reference
-
-           //TODO NEED TO DO SOMETHING WRAP CALL LOG REF.
-           @return string - INFO body
-           NOTE: Memory associated with the call log is tied to the
-           this would be freed when the callinfo ref is freed.
-         */
-        virtual cc_calllog_ref_t  getCallLogRef() = 0;
-
-        /**
-           returns the negotiated video direction for this call
-
-           @return cc_sdp_direction_t - video direction
-         */
-        virtual cc_sdp_direction_t getVideoDirection() = 0;
-
-         /**
-           Find out if this call is capable of querying the media state, which includes mute state and video direction
-           @return  bool
-          */
-        virtual bool isMediaStateAvailable() = 0;
-
-        /**
-           Get the audio mute state if available (check availability with isMediaStateAvailable())
-           @return  bool  - the current audio state of the call
-          */
-        virtual bool isAudioMuted(void) = 0;
-
-         /**
-           Get the video mute state if available (check availability with isMediaStateAvailable())
-           @return  bool  - the current video state of the call
-          */
-        virtual bool isVideoMuted(void) = 0;
-
-        /**
-          Get the current call volume level
-          @return int - the current call volume level, or -1 if it cannot be determined
-        */
-        virtual int getVolume() = 0;
-
-    };
-};
deleted file mode 100644
--- a/media/webrtc/signaling/include/CC_CallServerInfo.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#pragma once
-
-#include "CC_Common.h"
-
-#include <vector>
-
-extern "C"
-{
-#include "ccapi_types.h"
-}
-
-namespace CSF
-{
-    class ECC_API CC_CallServerInfo
-    {
-    public:
-        NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CC_CallServerInfo)
-
-    protected:
-        //Base class needs dtor to be declared as virtual
-        virtual ~CC_CallServerInfo() { }
-        CC_CallServerInfo() { }
-
-    public:
-        /**
-           gets call server name
-
-           @returns name of the call server
-         */
-        virtual std::string getCallServerName() = 0;
-
-        /**
-           gets call server mode
-
-           @returns - mode of the call server
-         */
-        virtual cc_cucm_mode_t getCallServerMode() = 0;
-
-        /**
-           gets calls erver name
-
-           @returns status of the call server
-         */
-        virtual cc_ccm_status_t getCallServerStatus() = 0;
-    };
-};
deleted file mode 100644
--- a/media/webrtc/signaling/include/CC_CallTypes.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#pragma once
-
-#include "CC_Common.h"
-#include <string>
-#include <set>
-
-namespace CSF
-{
-	namespace CC_CallCapabilityEnum
-	{
-		typedef enum
-		{
-			canSetRemoteWindow,
-			canSetLocalWindow,
-			canSendIFrame,
-			canOriginateCall,
-			canAnswerCall,
-			canHold,
-			canResume,
-			canEndCall,
-			canSendDigit,
-			canBackspace,
-			canRedial,
-			canInitiateCallForwardAll,
-			canEndConsultativeCall,
-			canConferenceStart,
-			canConferenceComplete,
-			canTransferStart,
-			canTransferComplete,
-			canCancelTransferOrConferenceFeature,
-			canDirectTransfer,
-			canJoinAcrossLine,
-			canBlfCallPickup,
-			canSelect,
-			canUpdateVideoMediaCap,
-			canSendInfo,
-			canMuteAudio,
-			canUnmuteAudio,
-			canMuteVideo,
-			canUnmuteVideo,
-			canSetVolume
-		} CC_CallCapability;
-		std::string ECC_API toString(CC_CallCapability cap);
-		std::string ECC_API toString(std::set<CC_CallCapability>& caps);
-	};
-};
deleted file mode 100644
--- a/media/webrtc/signaling/include/CC_Common.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#pragma once
-
-#include "SharedPtr.h"
-
-#ifndef ECC_API
-#ifdef ECC_EXPORT
-#define ECC_API _declspec(dllexport)
-#elif ECC_IMPORT
-#define ECC_API _declspec(dllimport)
-#else
-#define ECC_API
-#endif
-#endif
-
-namespace CSF
-{
-    DECLARE_NS_PTR(CallControlManager)
-    DECLARE_NS_PTR_VECTOR(PhoneDetails)
-    DECLARE_NS_PTR(CC_Service)
-    DECLARE_NS_PTR(VideoControl)
-    DECLARE_NS_PTR(AudioControl)
-    DECLARE_NS_PTR_VECTOR(CC_Device)
-    DECLARE_NS_PTR(CC_DeviceInfo)
-    DECLARE_NS_PTR(CC_CallServerInfo)
-    DECLARE_NS_PTR(CC_FeatureInfo)
-    DECLARE_NS_PTR_VECTOR(CC_Line)
-    DECLARE_NS_PTR(CC_LineInfo)
-    DECLARE_NS_PTR_VECTOR(CC_Call)
-    DECLARE_NS_PTR(CC_CallInfo)
-}
deleted file mode 100644
--- a/media/webrtc/signaling/include/CC_Device.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#pragma once
-
-#include "CC_Common.h"
-
-extern "C"
-{
-#include "ccapi_types.h"
-}
-
-namespace CSF
-{
-
-    class ECC_API CC_Device
-    {
-    public:
-        NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CC_Device)
-    protected:
-        CC_Device() {}
-
-        virtual ~CC_Device() {}
-
-    public:
-        virtual std::string toString() = 0;
-
-        virtual CC_DeviceInfoPtr getDeviceInfo () = 0;
-
-        /**
-           Create a call on the device. Line selection is on the first available line.
-           Lines that have their MNC reached will be skipped. If you have a specific line
-           you want to make a call on (assuming the device has more than available) then
-           you should use CC_Line::createCall() to do that.
-
-           @return CC_CallPtr - the created call object wrapped in a smart_ptr.
-         */
-        virtual CC_CallPtr createCall() = 0;
-
-        virtual void enableVideo(bool enable) = 0;
-        virtual void enableCamera(bool enable) = 0;
-		virtual void setDigestNamePasswd (char *name, char *pw) = 0;
-
-    private:
-		// Cannot copy - clients should be passing the pointer not the object.
-		CC_Device& operator=(const CC_Device& rhs);
-		CC_Device(const CC_Device&);
-    };
-}
deleted file mode 100644
--- a/media/webrtc/signaling/include/CC_DeviceInfo.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#pragma once
-
-#include "CC_Common.h"
-
-#include <vector>
-
-extern "C"
-{
-#include "ccapi_types.h"
-}
-
-namespace CSF
-{
-    class ECC_API CC_DeviceInfo
-    {
-    public:
-        NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CC_DeviceInfo)
-    protected:
-        CC_DeviceInfo() { }
-
-        //Base class needs dtor to be declared as virtual
-        virtual ~CC_DeviceInfo() {};
-
-    public:
-        /**
-           gets the device name
-           @returns - the device name as an std::string
-         */
-        virtual std::string getDeviceName() = 0;
-
-        /**
-           gets the service state
-           @param [in] handle - reference to device info
-           @returns cc_service_state_t - INS/OOS
-         */
-        virtual cc_service_state_t getServiceState() = 0;
-
-        /**
-           gets the service cause
-           @param [in] handle - reference to device info
-           @returns cc_service_cause_t - reason for service state
-         */
-        virtual cc_service_cause_t getServiceCause() = 0;
-
-        /**
-           gets vector of CC_CallPtr from this CC_DeviceInfo
-
-           @returns vector<CC_CallPtr> containing the CC_CallPtrs
-         */
-        virtual std::vector<CC_CallPtr> getCalls () = 0;
-
-        /**
-           gets list of handles to calls on the device by state
-           @param [in] handle - reference to device info
-           @param [in] state - call state for which the calls are requested
-           @param [out] handles - array of call handle to be returned
-           @param [in,out] count number allocated in array/elements returned
-           @returns
-         */
-//        void getCallsByState (cc_call_state_t state,
-//                              cc_call_handle_t handles[], cc_uint16_t *count);
-
-        /**
-           gets vector of CC_LinePtr from this CC_DeviceInfo
-
-           @returns vector<CC_LinePtr> containing the CC_LinePtrs
-         */
-        virtual std::vector<CC_LinePtr> getLines () = 0;
-
-        /**
-           gets vector of features on the device
-
-           @returns
-         */
-        virtual std::vector<CC_FeatureInfoPtr> getFeatures () = 0;
-
-        /**
-           gets handles of call agent servers
-
-           @returns
-         */
-        virtual std::vector<CC_CallServerInfoPtr> getCallServers () = 0;
-
-        /**
-           gets call server name
-           @param [in] handle - handle of call server
-           @returns name of the call server
-           NOTE: The memory for return string doesn't need to be freed it will be freed when the info reference is freed
-         */
-//        cc_string_t getCallServerName (cc_callserver_ref_t handle);
-
-        /**
-           gets call server mode
-           @param [in] handle - handle of call server
-           @returns - mode of the call server
-         */
-//        cc_cucm_mode_t getCallServerMode (cc_callserver_ref_t handle);
-
-        /**
-           gets calls erver name
-           @param [in] handle - handle of call server
-           @returns status of the call server
-         */
-//        cc_ccm_status_t getCallServerStatus (cc_callserver_ref_t handle);
-
-        /**
-           get the NOTIFICATION PROMPT
-           @param [in] handle - reference to device info
-           @returns
-         */
-//        cc_string_t getNotifyPrompt ();
-
-        /**
-           get the NOTIFICATION PROMPT PRIORITY
-           @param [in] handle - reference to device info
-           @returns
-         */
-//        cc_uint32_t getNotifyPromptPriority ();
-
-        /**
-           get the NOTIFICATION PROMPT Progress
-           @param [in] handle - reference to device info
-           @returns
-         */
-//        cc_uint32_t getNotifyPromptProgress ();
-
-    private:
-		// Cannot copy - clients should be passing the pointer not the object.
-		CC_DeviceInfo& operator=(const CC_DeviceInfo& rhs);
-		CC_DeviceInfo(const CC_DeviceInfo&);
-    };
-};
deleted file mode 100644
--- a/media/webrtc/signaling/include/CC_FeatureInfo.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#pragma once
-
-#include "CC_Common.h"
-
-extern "C"
-{
-#include "ccapi_types.h"
-}
-
-namespace CSF
-{
-    class ECC_API CC_FeatureInfo
-    {
-    public:
-        NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CC_FeatureInfo)
-    protected:
-        CC_FeatureInfo() { }
-
-        //Base class needs dtor to be declared as virtual
-        virtual ~CC_FeatureInfo() {};
-
-    public:
-        /**
-           Get the physical button number on which this feature is configured
-
-           @return cc_int32_t - button assgn to the feature
-         */
-        virtual cc_int32_t getButton() = 0;
-
-        /**
-           Get the featureID
-
-           @return cc_int32_t - button assgn to the feature
-         */
-        virtual cc_int32_t getFeatureID() = 0;
-
-        /**
-           Get the feature Name
-
-           @return string - handle of the feature created
-         */
-        virtual std::string getDisplayName() = 0;
-
-        /**
-           Get the speeddial Number
-
-           @return string - handle of the feature created
-         */
-        virtual std::string getSpeedDialNumber() = 0;
-
-        /**
-           Get the contact
-
-           @return string - handle of the feature created
-         */
-        virtual std::string getContact() = 0;
-
-        /**
-           Get the retrieval prefix
-
-           @return string - handle of the feature created
-         */
-        virtual std::string getRetrievalPrefix() = 0;
-
-        /**
-           Get the feature option mask
-
-           @return cc_int32_t - button assgn to the feature
-         */
-        virtual cc_int32_t getFeatureOptionMask() = 0;
-    };
-};
deleted file mode 100644
--- a/media/webrtc/signaling/include/CC_Line.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#pragma once
-
-#include "CC_Common.h"
-
-extern "C"
-{
-#include "ccapi_types.h"
-}
-
-namespace CSF
-{
-    class ECC_API CC_Line
-    {
-    public:
-        NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CC_Line)
-    protected:
-        CC_Line () { }
-
-        virtual ~CC_Line () {};
-
-    public:
-        virtual std::string toString() = 0;
-
-        virtual cc_lineid_t getID() = 0;
-        virtual CC_LineInfoPtr getLineInfo () = 0;
-        virtual CC_CallPtr createCall () = 0;
-    };
-};
deleted file mode 100644
--- a/media/webrtc/signaling/include/CC_LineInfo.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#pragma once
-
-#include "CC_Common.h"
-#include <bitset>
-#include <set>
-#include <vector>
-
-extern "C"
-{
-#include "ccapi_types.h"
-}
-
-namespace CSF
-{
-    class ECC_API CC_LineInfo
-    {
-    public:
-        NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CC_LineInfo)
-    protected:
-        CC_LineInfo() { }
-
-        //Base class needs dtor to be declared as virtual
-        virtual ~CC_LineInfo() {};
-
-    public:
-        /**
-           Get the line Name
-
-           @return string - line Name
-         */
-        virtual std::string getName() = 0;
-
-        /**
-           Get the line DN Number
-           @return string - line DN
-         */
-        virtual std::string getNumber() = 0;
-
-        /**
-           Get the physical button number on which this line is configured
-
-           @return cc_uint32_t - button number
-         */
-        virtual cc_uint32_t getButton() = 0;
-
-        /**
-           Get the Line Type
-
-           @return cc_line_feature_t - line featureID ( Line )
-         */
-        virtual cc_line_feature_t getLineType() = 0;
-
-        /**
-
-           @return bool - true if phone is currently registered with CM.
-         */
-        virtual bool getRegState() = 0;
-
-        /**
-           Get the CFWDAll status for the line
-
-           @return bool - isForwarded
-         */
-        virtual bool isCFWDActive() = 0;
-
-        /**
-           Get the CFWDAll destination
-
-           @return string - cfwd target
-         */
-        virtual std::string getCFWDName() = 0;
-
-        /**
-           Get calls on line
-
-           @param [in] line - line
-           @return vector<CC_CallPtr>
-         */
-        virtual std::vector<CC_CallPtr> getCalls (CC_LinePtr linePtr) = 0;
-
-        /**
-           Get calls on line by state
-
-           @param [in] line - line
-           @param [in] state - state
-
-           @return vector<CC_CallPtr>
-         */
-        virtual std::vector<CC_CallPtr> getCallsByState (CC_LinePtr linePtr, cc_call_state_t state) = 0;
-
-        /**
-           Get the MWI Status
-
-           @return cc_uint32_t - MWI status (boolean 0 => no MWI)
-         */
-        virtual bool getMWIStatus() = 0;
-
-        /**
-           Get the MWI Type
-
-           @return cc_uint32_t - MWI Type
-         */
-        virtual cc_uint32_t getMWIType() = 0;
-
-        /**
-           Get the MWI new msg count
-
-           @return cc_uint32_t - MWI new msg count
-         */
-        virtual cc_uint32_t getMWINewMsgCount() = 0;
-
-        /**
-           Get the MWI old msg count
-
-           @return cc_uint32_t - MWI old msg count
-         */
-        virtual cc_uint32_t getMWIOldMsgCount() = 0;
-
-        /**
-           Get the MWI high priority new msg count
-
-           @return cc_uint32_t - MWI new msg count
-         */
-        virtual cc_uint32_t getMWIPrioNewMsgCount() = 0;
-
-        /**
-           Get the MWI high priority old msg count
-
-           @return cc_uint32_t - MWI old msg count
-         */
-        virtual cc_uint32_t getMWIPrioOldMsgCount() = 0;
-
-        /**
-           has capability - is the feature allowed
-
-           @param [in] capability - capability being queried to see if it's available
-           @return bool - is Allowed
-         */
-        virtual bool hasCapability(ccapi_call_capability_e capability) = 0;
-
-        /**
-           get Allowed Feature set
-
-           @return cc_return_t - bitset of Line Capabilities.
-         */
-        virtual std::bitset<CCAPI_CALL_CAP_MAX> getCapabilitySet() = 0;
-    };
-};
deleted file mode 100644
--- a/media/webrtc/signaling/include/CC_Observer.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#pragma once
-
-#include "CC_Common.h"
-
-extern "C"
-{
-#include "ccapi_types.h"
-}
-
-namespace CSF
-{
-	/**
-	 * These callbacks relate to the "core" Call Control API objects CC_Device, CC_Line and CC_Call.
-	 */
-    class ECC_API CC_Observer
-    {
-    public:
-        virtual void onDeviceEvent  ( ccapi_device_event_e deviceEvent, CC_DevicePtr device, CC_DeviceInfoPtr info ) = 0;
-        virtual void onFeatureEvent ( ccapi_device_event_e deviceEvent, CC_DevicePtr device, CC_FeatureInfoPtr feature_info) = 0;
-        virtual void onLineEvent    ( ccapi_line_event_e lineEvent,     CC_LinePtr line,     CC_LineInfoPtr info ) = 0;
-        virtual void onCallEvent    ( ccapi_call_event_e callEvent,     CC_CallPtr call,     CC_CallInfoPtr infog ) = 0;
-    };
-
-}
deleted file mode 100644
--- a/media/webrtc/signaling/include/CC_Service.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#pragma once
-
-#include "CC_Common.h"
-#include "CC_Observer.h"
-
-#include <vector>
-
-extern "C"
-{
-#include "ccapi_types.h"
-#include "ccapi_service.h"
-}
-
-namespace CSF
-{
-    class ECC_API CC_Service
-    {
-    public:
-        NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CC_Service)
-    protected:
-    	CC_Service() {}
-        virtual ~CC_Service() {};
-
-    public:
-        /**
-         * Clients use CC_Observer to receive CCAPI events (Device, Line, Call) from the service.
-         */
-        virtual void addCCObserver ( CC_Observer * observer ) = 0;
-        virtual void removeCCObserver ( CC_Observer * observer ) = 0;
-
-        /**
-         * Use init() immediately on creating the service, and destroy() when finished with it.
-         * password is required for Asterisk not CUCM.
-         * deviceName is required for CUCM not Asterisk.
-         */
-        virtual bool init(const std::string& user, const std::string& password, const std::string& domain, const std::string& deviceName) = 0;
-        virtual void destroy() = 0;
-
-        /**
-         * TODO: Set config parameters prior to starting the service.
-         *		 Need to design a nice abstraction for this accommodating SIPCC and CTI.
-         */
-
-        /**
-         * Use start() to attempt to register for a device and stop() to cancel a current
-         * registration (or registration attempt).
-         */
-        virtual bool startService() = 0;
-        virtual void stop() = 0;
-
-
-        /**
-         * Check on the current status/health of the service.
-         */
-        virtual bool isStarted() = 0;
-
-        /**
-         * Obtain the currently selected Device.
-         * If multiple devices are discoverable (i.e. in CTI), all known devices will appear
-         *   in getDevices(), but only the ActiveDevice will be controllable at any given time.
-         */
-        virtual CC_DevicePtr getActiveDevice() = 0;
-        virtual std::vector<CC_DevicePtr> getDevices() = 0;
-
-        /**
-         * Global settings for audio and video control.  Return nullptr if Media control is not
-         * available in this implementation.  Return nullptr in any case if media is not yet
-         * initialized.
-         * TODO: Assuming for now that media init aligns with init/destroy.
-         */
-        virtual AudioControlPtr getAudioControl() = 0;
-        virtual VideoControlPtr getVideoControl() = 0;
-
-        virtual bool setLocalVoipPort(int port) = 0;
-        virtual bool setRemoteVoipPort(int port) = 0;
-        virtual bool setP2PMode(bool mode) = 0;
-        virtual bool setSDPMode(bool mode) = 0;
-
-    private:
-        CC_Service(const CC_Service& rhs);
-        CC_Service& operator=(const CC_Service& rhs);
-    };
-}
deleted file mode 100644
--- a/media/webrtc/signaling/include/CSFAudioControl.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#pragma once
-
-#include "CC_Common.h"
-
-namespace CSF
-{
-        DECLARE_NS_PTR(AudioControl)
-	class ECC_API AudioControl
-	{
-	public:
-                NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AudioControl)
-		// device names are in UTF-8 encoding
-
-		virtual std::vector<std::string> getRecordingDevices() = 0;
-		virtual std::vector<std::string> getPlayoutDevices() = 0;
-
-		virtual std::string getRecordingDevice() = 0;
-		virtual std::string getPlayoutDevice() = 0;
-
-		virtual bool setRecordingDevice( const std::string& name ) = 0;
-		virtual bool setPlayoutDevice( const std::string& name ) = 0;
-
-        virtual bool setDefaultVolume( int ) = 0;
-        virtual int getDefaultVolume() = 0;
-
-        virtual bool setRingerVolume( int ) = 0;
-        virtual int getRingerVolume() = 0;
-
-        protected:
-                virtual ~AudioControl(){};
-	};
-};
deleted file mode 100644
--- a/media/webrtc/signaling/include/CSFVideoControl.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#pragma once
-
-#include "CC_Common.h"
-#include "ECC_Types.h"
-
-#include <string>
-#include <vector>
-
-namespace CSF
-{
-	DECLARE_NS_PTR(VideoControl)
-	class ECC_API VideoControl
-	{
-	public:
-                NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VideoControl)
-
-		virtual void setVideoMode( bool enable ) = 0;
-
-		// window type is platform-specific
-		virtual void setPreviewWindow( VideoWindowHandle window, int top, int left, int bottom, int right, RenderScaling style ) = 0;
-		virtual void showPreviewWindow( bool show ) = 0;
-
-		// device names are in UTF-8 encoding
-		virtual std::vector<std::string> getCaptureDevices() = 0;
-
-		virtual std::string getCaptureDevice() = 0;
-		virtual bool setCaptureDevice( const std::string& name ) = 0;
-	protected:
-		virtual ~VideoControl() {};
-	};
-
-}; // namespace
deleted file mode 100755
--- a/media/webrtc/signaling/include/CallControlManager.h
+++ /dev/null
@@ -1,130 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#pragma once
-
-#include "CC_Common.h"
-
-#include "CC_Observer.h"
-#include "ECC_Observer.h"
-#include "ECC_Types.h"
-
-#include <string>
-#include <vector>
-
-/**
- *  @mainpage Enhanced Call Control
- *
- *  @section intro_sec Introduction
- *  This wraps and aggregates the SIPCC and CTI call control stacks, media stacks, and various additional
- *  components and glue necessary to start, configure and run them, and presents a high-level C++ API
- *  for connection, device selection and status, and call control.
- *
- *  @section main_outline Outline
- *  @li The main entry point is CSF::CallControlManager, which is used to configure and start a
- *  	call control stack.
- *  @li Configuration and events are raised to the CSF::ECC_Observer interface.
- *  @li Call Control is performed via CSF::CC_Device, CSF::CC_Line and CSF::CC_Call.
- *  @li Call Control events are raised to the CSF::CC_Observer interface.
- *  @li Audio/Video device selection and global media configuration is performed via CSF::AudioControl
- *      and CSF::VideoControl.  Per-call media operations (mute, volume, etc) are integrated onto
- *      the CSF::CC_Call and CSF::CC_CallInfo interfaces.
- */
-
-namespace CSF
-{
-	DECLARE_NS_PTR(CallControlManager)
-	/**
-	 * CallControlManager
-	 *
-	 * The class is partitioned into several blocks of functionality:
-	 * - Create/Destroy - Initialisation and clean shutdown.
-	 * 					  Destroy is optional if the destructor is used properly.
-	 * - Observer - Register for events when any state changes.  Optional but strongly advised.
-	 *
-	 * Methods are generally synchronous (at present).
-	 */
-    class ECC_API CallControlManager
-    {
-    protected:
-        virtual ~CallControlManager();
-
-    public:
-        NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CallControlManager)
-		/**
-		 *  Use create() to create a CallControlManager instance.
-		 *
-		 *  CallControlManager cleans up its resources in its destructor, implicitly disconnect()in if required.
-		 *  Use the destroy() method if you need to force a cleanup earlier.  It is a bad idea to continue using
-		 *  CallControlManager or any of its related objects after destroy().
-		 */
-        static CallControlManagerPtr create();
-        virtual bool destroy() = 0;
-
-        /**
-           CC_Observer is for core call control events (on CC_Device, CC_Line and CC_Call).
-           ECC_Observer is for "value add" features of CallControlManager.
-
-           Client can add multiple observers if they have different Observer objects that handle
-           different event scenarios, but generally it's probably sufficient to only register one observer.
-
-           @param[in] observer - This is a pointer to a CC_Observer-derived class that the client
-                                 must instantiate to receive notifications on this client object.
-         */
-        virtual void addCCObserver ( CC_Observer * observer ) = 0;
-        virtual void removeCCObserver ( CC_Observer * observer ) = 0;
-
-        virtual void addECCObserver ( ECC_Observer * observer ) = 0;
-        virtual void removeECCObserver ( ECC_Observer * observer ) = 0;
-
-        virtual void setMultiClusterMode(bool allowMultipleClusters) = 0;
-        virtual void setSIPCCLoggingMask(const cc_int32_t mask) = 0;
-        virtual void setAuthenticationString(const std::string &authString) = 0;
-        virtual void setSecureCachePath(const std::string &secureCachePath) = 0;
-
-        // Add local codecs
-        virtual void setAudioCodecs(int codecMask) = 0;
-        virtual void setVideoCodecs(int codecMask) = 0;
-
-        virtual bool registerUser(const std::string& deviceName, const std::string& user, const std::string& password, const std::string& domain) = 0;
-        virtual bool disconnect() = 0;
-        virtual std::string getPreferredDeviceName() = 0;
-        virtual std::string getPreferredLineDN() = 0;
-        virtual ConnectionStatusEnum::ConnectionStatus getConnectionStatus() = 0;
-        virtual std::string getCurrentServer() = 0;
-
-        /* P2P MODE */
-        virtual bool startP2PMode(const std::string& user) = 0;
-
-        /* SDP MODE */
-        virtual bool startSDPMode() = 0;
-
-        /**
-         * Obtain the device object, from which call control can be done.
-         * getAvailablePhoneDetails lists all known devices which the user is likely to be able to control.
-         */
-        virtual CC_DevicePtr getActiveDevice() = 0;
-        virtual PhoneDetailsVtrPtr getAvailablePhoneDetails() = 0;
-        virtual PhoneDetailsPtr getAvailablePhoneDetails(const std::string& deviceName) = 0;
-
-        /**
-         * Obtain the audio/video object, from which video setup can be done.
-         * This relates to global tuning, device selection, preview window positioning, etc, not to
-         * per-call settings or control.
-         *
-         * These objects are unavailable except while in softphone mode.
-         */
-        virtual VideoControlPtr getVideoControl() = 0;
-        virtual AudioControlPtr getAudioControl() = 0;
-
-        virtual bool setProperty(ConfigPropertyKeysEnum::ConfigPropertyKeys key, std::string& value) = 0;
-        virtual std::string getProperty(ConfigPropertyKeysEnum::ConfigPropertyKeys key) = 0;
-
-    protected:
-        CallControlManager() {}
-    private:
-        CallControlManager(const CallControlManager&);
-        CallControlManager& operator=(const CallControlManager&);
-    };
-} //end namespace CSF
deleted file mode 100644
--- a/media/webrtc/signaling/include/ECC_Observer.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#pragma once
-
-#include "CC_Common.h"
-#include "ECC_Types.h"
-
-namespace CSF
-{
-	/**
-	 * These callbacks relate to CallControlManager's "value add" features relating to authentication,
-	 * configuration, setup, service health and management of SIP.
-	 *
-	 * They do not relate to call control - see also CC_Observer.
-	 */
-	class ECC_API ECC_Observer
-	{
-	public:
-		virtual void onAvailablePhoneEvent (AvailablePhoneEventType::AvailablePhoneEvent event,
-											const PhoneDetailsPtr availablePhoneDetails) = 0;
-
-		virtual void onAuthenticationStatusChange (AuthenticationStatusEnum::AuthenticationStatus) = 0;
-		virtual void onConnectionStatusChange(ConnectionStatusEnum::ConnectionStatus status) = 0;
-	};
-}
deleted file mode 100755
--- a/media/webrtc/signaling/include/ECC_Types.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#pragma once
-
-#include "CC_Common.h"
-
-/*
-  These #defines are for use with CallControlManager::createSoftphone(..., const cc_int32_t mask) parameter as follows:
-
-  CallControlManager::createSoftphone(..., GSM_DEBUG_BIT | FIM_DEBUG_BIT | LSM_DEBUG_BIT );
-
-  This turns on debugging for the three areas (and disables logging in all other areas) of pSIPCC logging specified.
-
-*/
-
-#define SIP_DEBUG_MSG_BIT         (1 <<  0) // Bit 0
-#define SIP_DEBUG_STATE_BIT       (1 <<  1) // Bit 1
-#define SIP_DEBUG_TASK_BIT        (1 <<  2) // Bit 2
-#define SIP_DEBUG_REG_STATE_BIT   (1 <<  3) // Bit 3
-#define GSM_DEBUG_BIT             (1 <<  4) // Bit 4
-#define FIM_DEBUG_BIT             (1 <<  5) // Bit 5
-#define LSM_DEBUG_BIT             (1 <<  6) // Bit 6
-#define FSM_DEBUG_SM_BIT          (1 <<  7) // Bit 7
-#define CSM_DEBUG_SM_BIT          (1 <<  8) // Bit 8
-#define CC_DEBUG_BIT              (1 <<  9) // Bit 9
-#define CC_DEBUG_MSG_BIT          (1 << 10) // Bit 10
-#define AUTH_DEBUG_BIT            (1 << 11) // Bit 11
-#define CONFIG_DEBUG_BIT          (1 << 12) // Bit 12
-#define DPINT_DEBUG_BIT           (1 << 13) // Bit 13
-#define KPML_DEBUG_BIT            (1 << 15) // Bit 15
-#define VCM_DEBUG_BIT             (1 << 17) // Bit 17
-#define CC_APP_DEBUG_BIT          (1 << 18) // Bit 18
-#define CC_LOG_DEBUG_BIT          (1 << 19) // Bit 19
-#define TNP_DEBUG_BIT             (1 << 20) // Bit 20
-
-namespace CSFUnified
-{
-    DECLARE_PTR(DeviceInfo)
-}
-
-namespace CSF
-{
-	namespace AuthenticationFailureCodeType
-	{
-		typedef enum {
-			eNoError,
-			eNoServersConfigured,
-			eNoCredentialsConfigured,
-			eCouldNotConnect,
-			eServerCertificateRejected,
-			eCredentialsRejected,
-			eResponseEmpty,
-			eResponseInvalid
-		} AuthenticationFailureCode;
-		std::string ECC_API toString(AuthenticationFailureCode value);
-	}
-
-	namespace AuthenticationStatusEnum
-	{
-		typedef enum {
-			eNotAuthenticated,
-			eInProgress,
-			eAuthenticated,
-			eFailed
-		} AuthenticationStatus;
-		std::string ECC_API toString(AuthenticationStatus value);
-	}
-
-	namespace DeviceRetrievalFailureCodeType
-	{
-		typedef enum {
-			eNoError,
-			eNoServersConfigured,
-			eNoDeviceNameConfigured,
-			eCouldNotConnect,
-			eFileNotFound,
-			eFileEmpty,
-			eFileInvalid
-		} DeviceRetrievalFailureCode;
-		std::string ECC_API toString(DeviceRetrievalFailureCode value);
-	}
-
-    namespace ConnectionStatusEnum
-    {
-    	typedef enum {
-    		eIdle,
-    		eNone,
-    		eFetchingDeviceConfig,
-    		eRegistering,
-    		eReady,
-    		eConnectedButNoDeviceReady,
-    		eRetrying,
-    		eFailed
-    	} ConnectionStatus;
-		std::string ECC_API toString(ConnectionStatus value);
-    }
-
-	namespace ServiceStateType {
-		typedef enum
-		{
-			eUnknown,
-			eInService,
-			eOutOfService
-		} ServiceState;
-		std::string ECC_API toString(ServiceState value);
-	}
-
-	namespace AvailablePhoneEventType
-	{
-		typedef enum {
-			eFound,		// New Phone device discovered and added to the Available list.
-			eUpdated,	// Change to an existing Phone details record in the Available list.
-			eLost		// Phone device removed from the Available list.
-		} AvailablePhoneEvent;
-		std::string ECC_API toString(AvailablePhoneEvent value);
-	}
-
-	namespace ConfigPropertyKeysEnum
-	{
-		typedef enum {
-			eLocalVoipPort,
-			eRemoteVoipPort,
-			eVersion,
-			eTransport
-		} ConfigPropertyKeys;
-	}
-
-	typedef enum
-	{
-		VideoEnableMode_DISABLED,
-		VideoEnableMode_SENDONLY,
-		VideoEnableMode_RECVONLY,
-		VideoEnableMode_SENDRECV
-
-	} VideoEnableMode;
-
-	typedef enum				// scaling from codec size to render window size
-	{
-		RenderScaling_NONE,		// 1:1 actual pixels, crop and/or fill
-		RenderScaling_TO_FIT,	// scale to fit, without preserving aspect ratio
-		RenderScaling_BORDER,	// scale to fit, fill without cropping
-		RenderScaling_CROP		// scale to fit, crop without filling
-
-	} RenderScaling;
-
-    typedef void *VideoWindowHandle;
-	typedef void* ExternalRendererHandle;
-	typedef unsigned int VideoFormat;
-}
-
deleted file mode 100644
--- a/media/webrtc/signaling/include/PhoneDetails.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#pragma once
-
-#include <string>
-
-#include "CC_Common.h"
-#include "ECC_Types.h"
-
-namespace CSF
-{
-	DECLARE_NS_PTR_VECTOR(PhoneDetails);
-	class ECC_API PhoneDetails
-	{
-        protected:
-                virtual ~PhoneDetails() {}
-	public:
-                NS_INLINE_DECL_THREADSAFE_REFCOUNTING(PhoneDetails)
-		/**
-		 * Get the device name (the CUCM device name) and the free text description.
-		 */
-		virtual std::string getName() const = 0;
-		virtual std::string getDescription() const = 0;
-
-		/**
-		 * Get the model number (the internal CUCM number, not the number printed on the phone)
-		 * and the corresponding description (which normally does include the number printed on the phone).
-		 * Returns -1, "" if unknown
-		 */
-		virtual int getModel() const = 0;
-		virtual std::string getModelDescription() const = 0;
-
-		virtual bool isSoftPhone() = 0;
-
-		/**
-		 * List the known directory numbers of lines associated with the device.
-		 * Empty list if unknown.
-		 */
-		virtual std::vector<std::string> getLineDNs() const = 0;
-
-		/**
-		 * Current status of the device, if known.
-		 */
-		virtual ServiceStateType::ServiceState getServiceState() const = 0;
-
-		/**
-		 * TFTP config of device, and freshness of the config.
-		 */
-		virtual std::string getConfig() const = 0;
-
-	protected:
-		PhoneDetails() {}
-
-	private:
-		PhoneDetails(const PhoneDetails&);
-		PhoneDetails& operator=(const PhoneDetails&);
-	};
-};
deleted file mode 100644
--- a/media/webrtc/signaling/include/SharedPtr.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#pragma once
-
-#include <vector>
-#include "base/linked_ptr.h"
-#include "nsAutoPtr.h"
-
-#ifndef DECLARE_PTR
-#define DECLARE_PTR(className)\
-    class className;\
-    typedef linked_ptr<className> className##Ptr;
-#endif
-
-
-#ifndef DECLARE_PTR_VECTOR
-#define DECLARE_PTR_VECTOR(className)\
-    DECLARE_PTR(className)\
-    typedef std::vector<className##Ptr> className##Vtr;\
-    typedef linked_ptr<className##Vtr> className##Vtr##Ptr;
-#endif
-
-
-#ifndef NULL_PTR
-#define NULL_PTR(className) linked_ptr<className>()
-#endif
-
-// NSPR Variations of the above, to help with migration
-// from linked_ptr to nsRefPtr
-#ifndef DECLARE_NS_PTR
-#define DECLARE_NS_PTR(className)\
-    class className;\
-    typedef nsRefPtr<className> className##Ptr;
-#endif
-
-
-#ifndef DECLARE_NS_PTR_VECTOR
-#define DECLARE_NS_PTR_VECTOR(className)\
-    DECLARE_NS_PTR(className)\
-    typedef std::vector<className##Ptr> className##Vtr;\
-    typedef linked_ptr<className##Vtr> className##Vtr##Ptr;
-#endif
deleted file mode 100644
--- a/media/webrtc/signaling/include/debug-psipcc-types.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef T1_DEBUG_H
-#define T1_DEBUG_H
-
-#include "CC_Common.h"
-
-extern "C"
-{
-#include <ccapi_service.h>
-#include "ccapi_types.h"
-
-ECC_API cc_string_t device_event_getname(ccapi_device_event_e);
-ECC_API cc_string_t call_event_getname(ccapi_call_event_e);
-ECC_API cc_string_t line_event_getname(ccapi_line_event_e);
-
-ECC_API cc_string_t digit_getname(cc_digit_t);
-ECC_API cc_string_t cucm_mode_getname(cc_cucm_mode_t);
-ECC_API cc_string_t line_feature_getname(cc_line_feature_t);
-ECC_API cc_string_t feature_option_mask_getname(cc_feature_option_mask_t);
-ECC_API cc_string_t service_cause_getname(cc_service_cause_t);
-ECC_API cc_string_t service_state_getname(cc_service_state_t);
-ECC_API cc_string_t ccm_status_getname(cc_ccm_status_t);
-ECC_API cc_string_t line_reg_state_getname(cc_line_reg_state_t);
-ECC_API cc_string_t shutdown_reason_getname(cc_shutdown_reason_t);
-ECC_API cc_string_t kpml_config_getname(cc_kpml_config_t);
-ECC_API cc_string_t upgrade_getname(cc_upgrade_t);
-ECC_API cc_string_t sdp_direction_getname(cc_sdp_direction_t);
-ECC_API cc_string_t blf_state_getname(cc_blf_state_t);
-ECC_API cc_string_t blf_feature_mask_getname(cc_blf_feature_mask_t);
-ECC_API cc_string_t call_state_getname(cc_call_state_t);
-ECC_API cc_string_t call_attr_getname(cc_call_attr_t);
-ECC_API cc_string_t hold_reason_getname(cc_hold_reason_t);
-ECC_API cc_string_t call_type_getname(cc_call_type_t);
-ECC_API cc_string_t call_security_getname(cc_call_security_t);
-ECC_API cc_string_t call_policy_getname(cc_call_policy_t);
-ECC_API cc_string_t log_disposition_getname(cc_log_disposition_t);
-ECC_API cc_string_t call_priority_getname(cc_call_priority_t);
-ECC_API cc_string_t call_selection_getname(cc_call_selection_t);
-ECC_API cc_string_t call_capability_getname(ccapi_call_capability_e);
-ECC_API cc_string_t srv_ctrl_req_getname(cc_srv_ctrl_req_t);
-ECC_API cc_string_t srv_ctrl_cmd_getname(cc_srv_ctrl_cmd_t);
-ECC_API cc_string_t message_type_getname(cc_message_type_t);
-ECC_API cc_string_t lamp_state_getname(cc_lamp_state_t);
-ECC_API cc_string_t cause_getname(cc_cause_t);
-ECC_API cc_string_t subscriptions_ext_getname(cc_subscriptions_ext_t);
-ECC_API cc_string_t apply_config_result_getname(cc_apply_config_result_t);
-
-}
-
-#endif /* T1_DEBUG_H */
--- a/media/webrtc/signaling/src/common/browser_logging/CSFLog.cpp
+++ b/media/webrtc/signaling/src/common/browser_logging/CSFLog.cpp
@@ -5,29 +5,19 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdarg.h>
 
 #include "CSFLog.h"
 #include "base/basictypes.h"
 
 #include <map>
-#include "cpr_threads.h"
 #include "prrwlock.h"
 #include "prthread.h"
 #include "nsThreadUtils.h"
-#ifndef WIN32
-#include <pthread.h>
-#endif
-#ifdef OS_MACOSX
-#include <dlfcn.h>
-#endif
-#ifdef OS_LINUX
-#include <sys/prctl.h>
-#endif
 
 static PRLogModuleInfo *gLogModuleInfo = nullptr;
 
 PRLogModuleInfo *GetSignalingLogInfo()
 {
   if (gLogModuleInfo == nullptr)
     gLogModuleInfo = PR_NewLogModule("signaling");
 
@@ -39,91 +29,16 @@ static PRLogModuleInfo *gWebRTCLogModule
 PRLogModuleInfo *GetWebRTCLogInfo()
 {
   if (gWebRTCLogModuleInfo == nullptr)
     gWebRTCLogModuleInfo = PR_NewLogModule("webrtc_trace");
 
   return gWebRTCLogModuleInfo;
 }
 
-extern "C" {
-  void CSFLogRegisterThread(const cprThread_t thread);
-  void CSFLogUnregisterThread(const cprThread_t thread);
-#ifndef WIN32
-  pthread_t cprGetThreadId(cprThread_t thread);
-#endif
-}
-
-#ifdef WIN32
-typedef unsigned int thread_key_t;
-#else
-typedef pthread_t thread_key_t;
-#endif
-static PRRWLock *maplock = PR_NewRWLock(0,"thread map");
-typedef std::map<thread_key_t,const cpr_thread_t*> threadMap_t;
-static threadMap_t threadMap;
-
-void CSFLogRegisterThread(const cprThread_t thread) {
-  const cpr_thread_t *t = reinterpret_cast<cpr_thread_t *>(thread);
-  thread_key_t key;
-#ifdef WIN32
-  key = t->threadId;
-#else
-  key = cprGetThreadId(thread);
-#endif
-
-  CSFLog(CSF_LOG_DEBUG, __FILE__, __LINE__, "log",
-         "Registering new thread with logging system: %s", t->name);
-  PR_RWLock_Wlock(maplock);
-  threadMap[key] = t;
-  PR_RWLock_Unlock(maplock);
-}
-
-void CSFLogUnregisterThread(const cprThread_t thread) {
-  const cpr_thread_t *t = reinterpret_cast<cpr_thread_t *>(thread);
-  thread_key_t key;
-#ifdef WIN32
-  key = t->threadId;
-#else
-  key = cprGetThreadId(thread);
-#endif
-  CSFLog(CSF_LOG_DEBUG, __FILE__, __LINE__, "log",
-         "Unregistering thread from logging system: %s", t->name);
-  PR_RWLock_Wlock(maplock);
-  threadMap.erase(key);
-  PR_RWLock_Unlock(maplock);
-}
-
-const char *CSFCurrentThreadName() {
-  const char *name = nullptr;
-#ifdef WIN32
-  thread_key_t key = GetCurrentThreadId();
-#else
-  thread_key_t key = pthread_self();
-#endif
-  PR_RWLock_Rlock(maplock);
-  threadMap_t::iterator i = threadMap.find(key);
-  if (i != threadMap.end()) {
-    name = i->second->name;
-  }
-  PR_RWLock_Unlock(maplock);
-  return name;
-}
-
-#ifdef OS_MACOSX
-// pthread_getname_np isn't available on all versions of OS X, so
-// we need to load it in dynamically and check for its presence
-static int (*dynamic_pthread_getname_np)(pthread_t,char*,size_t);
-bool init_pthread_getname() {
-  *reinterpret_cast<void**>(&dynamic_pthread_getname_np) =
-      dlsym(RTLD_DEFAULT, "pthread_getname_np");
-  return dynamic_pthread_getname_np;
-}
-static bool have_pthread_getname_np = init_pthread_getname();
-#endif
 
 void CSFLogV(CSFLogLevel priority, const char* sourceFile, int sourceLine, const char* tag , const char* format, va_list args)
 {
 #ifdef STDOUT_LOGGING
   printf("%s\n:",tag);
   vprintf(format, args);
 #else
 
@@ -146,50 +61,26 @@ void CSFLogV(CSFLogLevel priority, const
   }
   sourceFile = lastSlash;
   if (*sourceFile == '/' || *sourceFile == '\\') {
     sourceFile++;
   }
 
 #define MAX_MESSAGE_LENGTH 1024
   char message[MAX_MESSAGE_LENGTH];
-  char buffer[64] = "";
 
-  const char *threadName = CSFCurrentThreadName();
+  const char *threadName = NULL;
 
   // Check if we're the main thread...
-  if (!threadName && NS_IsMainThread()) {
+  if (NS_IsMainThread()) {
     threadName = "main";
-  }
-
-  // If null, the name wasn't set up by CPR -- try NSPR
-  if (!threadName) {
+  } else {
     threadName = PR_GetThreadName(PR_GetCurrentThread());
   }
 
-  // If not NSPR, it might be from some other imported library that uses
-  // one of the variety of non-portable means of naming threads.
-#ifdef OS_LINUX
-  if (!threadName &&
-    !prctl(PR_GET_NAME,reinterpret_cast<uintptr_t>(buffer),0,0,0)) {
-    buffer[16]='\0';
-    if (buffer[0] != '\0') {
-      threadName = buffer;
-    }
-  }
-#endif
-#ifdef OS_MACOSX
-  if (!threadName && have_pthread_getname_np) {
-    dynamic_pthread_getname_np(pthread_self(), buffer, sizeof(buffer));
-    if (buffer[0] != '\0') {
-      threadName = buffer;
-    }
-  }
-#endif
-
   // If we can't find it anywhere, use a blank string
   if (!threadName) {
     threadName = "";
   }
 
   vsnprintf(message, MAX_MESSAGE_LENGTH, format, args);
   PR_LOG(gLogModuleInfo, level, ("[%s|%s] %s:%d: %s",
                                   threadName, tag, sourceFile, sourceLine,
--- a/media/webrtc/signaling/src/common/time_profiling/timecard.c
+++ b/media/webrtc/signaling/src/common/time_profiling/timecard.c
@@ -83,18 +83,19 @@ print_timecard(Timecard *tc)
     if (strlen(entry->file) > file_width) {
       file_width = strlen(entry->file);
     }
     if (strlen(entry->function) > function_width) {
       function_width = strlen(entry->function);
     }
   }
 
-  printf("\nTimecard created %4lld.%6.6lld\n\n",
-          tc->start_time / PR_USEC_PER_SEC, tc->start_time % PR_USEC_PER_SEC);
+  printf("\nTimecard created %4ld.%6.6ld\n\n",
+          (long)(tc->start_time / PR_USEC_PER_SEC),
+          (long)(tc->start_time % PR_USEC_PER_SEC));
 
   line_width = 1 + 11 + 11 + event_width + file_width + 6 +
                    function_width + (4 * 3);
 
   printf(" %-11s | %-11s | %-*s | %-*s | %-*s\n",
           "Timestamp", "Delta",
           (int)event_width, "Event",
           (int)file_width + 6, "File",
@@ -108,17 +109,17 @@ print_timecard(Timecard *tc)
   for (i = 0; i < tc->curr_entry; i++) {
     entry = &tc->entries[i];
     offset = entry->timestamp - tc->start_time;
     if (i > 0) {
       delta = entry->timestamp - tc->entries[i-1].timestamp;
     } else {
       delta = entry->timestamp - tc->start_time;
     }
-    printf(" %4lld.%6.6lld | %4lld.%6.6lld | %-*s | %*s:%-5d | %-*s\n",
-           offset / PR_USEC_PER_SEC, offset % PR_USEC_PER_SEC,
-           delta / PR_USEC_PER_SEC, delta % PR_USEC_PER_SEC,
+    printf(" %4ld.%6.6ld | %4ld.%6.6ld | %-*s | %*s:%-5d | %-*s\n",
+           (long)(offset / PR_USEC_PER_SEC), (long)(offset % PR_USEC_PER_SEC),
+           (long)(delta / PR_USEC_PER_SEC), (long)(delta % PR_USEC_PER_SEC),
            (int)event_width, entry->event,
            (int)file_width, entry->file, entry->line,
            (int)function_width, entry->function);
   }
   printf("\n");
 }
--- a/media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
+++ b/media/webrtc/signaling/src/media-conduit/AudioConduit.cpp
@@ -856,16 +856,20 @@ WebrtcAudioConduit::CodecConfigToWebRTCC
     return false;
   }
   memcpy(cinst.plname, codecInfo->mName.c_str(), plNameLength);
   cinst.plname[plNameLength]='\0';
   cinst.pltype   =  codecInfo->mType;
   cinst.rate     =  codecInfo->mRate;
   cinst.pacsize  =  codecInfo->mPacSize;
   cinst.plfreq   =  codecInfo->mFreq;
+  if (codecInfo->mName == "G722") {
+    // Compensate for G.722 spec error in RFC 1890
+    cinst.plfreq = 16000;
+  }
   cinst.channels =  codecInfo->mChannels;
   return true;
  }
 
 /**
   *  Supported Sampling Frequncies.
   */
 bool
--- a/media/webrtc/signaling/src/media-conduit/CodecConfig.h
+++ b/media/webrtc/signaling/src/media-conduit/CodecConfig.h
@@ -2,17 +2,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef CODEC_CONFIG_H_
 #define CODEC_CONFIG_H_
 
 #include <string>
-#include "ccsdp_rtcp_fb.h"
+#include <vector>
 
 namespace mozilla {
 
 /**
  * Minimalistic Audio Codec Config Params
  */
 struct AudioCodecConfig
 {
@@ -71,38 +71,40 @@ class VideoCodecConfig
 {
 public:
   /*
    * The data-types for these properties mimic the
    * corresponding webrtc::VideoCodec data-types.
    */
   int mType; // payload type
   std::string mName;
-  uint32_t mRtcpFbTypes;
+
+  std::vector<std::string> mAckFbTypes;
+  std::vector<std::string> mNackFbTypes;
+  std::vector<std::string> mCcmFbTypes;
+
   unsigned int mMaxFrameSize;
   unsigned int mMaxFrameRate;
   unsigned int mMaxMBPS;    // in macroblocks-per-second
   unsigned int mMaxBitrate;
   // max_cpb & max_dpb would be streaming/mode-2 only
   std::string mSpropParameterSets;
   uint8_t mProfile;
   uint8_t mConstraints;
   uint8_t mLevel;
   uint8_t mPacketizationMode;
   // TODO: add external negotiated SPS/PPS
 
   VideoCodecConfig(int type,
                    std::string name,
-                   int rtcpFbTypes,
                    unsigned int max_fs = 0,
                    unsigned int max_fr = 0,
                    const struct VideoCodecConfigH264 *h264 = nullptr) :
     mType(type),
     mName(name),
-    mRtcpFbTypes(rtcpFbTypes),
     mMaxFrameSize(max_fs), // may be overridden
     mMaxFrameRate(max_fr),
     mMaxMBPS(0),
     mMaxBitrate(0),
     mProfile(0x42),
     mConstraints(0xE0),
     mLevel(0x0C),
     mPacketizationMode(1)
@@ -116,25 +118,42 @@ public:
       mProfile = (h264->profile_level_id & 0x00FF0000) >> 16;
       mConstraints = (h264->profile_level_id & 0x0000FF00) >> 8;
       mLevel = (h264->profile_level_id & 0x000000FF);
       mPacketizationMode = h264->packetization_mode;
       mSpropParameterSets = h264->sprop_parameter_sets;
     }
   }
 
-  bool RtcpFbIsSet(sdp_rtcp_fb_nack_type_e type) const
+  // Nothing seems to use this right now. Do we intend to support this
+  // someday?
+  bool RtcpFbAckIsSet(const std::string& type) const
   {
-    return mRtcpFbTypes & sdp_rtcp_fb_nack_to_bitmap(type);
+    for (auto i = mAckFbTypes.begin(); i != mAckFbTypes.end(); ++i) {
+      if (*i == type) {
+        return true;
+      }
+    }
+    return false;
   }
 
-  bool RtcpFbIsSet(sdp_rtcp_fb_ack_type_e type) const
+  bool RtcpFbNackIsSet(const std::string& type) const
   {
-    return mRtcpFbTypes & sdp_rtcp_fb_ack_to_bitmap(type);
+    for (auto i = mNackFbTypes.begin(); i != mNackFbTypes.end(); ++i) {
+      if (*i == type) {
+        return true;
+      }
+    }
+    return false;
   }
 
-  bool RtcpFbIsSet(sdp_rtcp_fb_ccm_type_e type) const
+  bool RtcpFbCcmIsSet(const std::string& type) const
   {
-    return mRtcpFbTypes & sdp_rtcp_fb_ccm_to_bitmap(type);
+    for (auto i = mCcmFbTypes.begin(); i != mCcmFbTypes.end(); ++i) {
+      if (*i == type) {
+        return true;
+      }
+    }
+    return false;
   }
 };
 }
 #endif
--- a/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
+++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp
@@ -283,31 +283,31 @@ MediaConduitErrorCode WebrtcVideoConduit
   nsCOMPtr<nsIPrefService> prefs = do_GetService("@mozilla.org/preferences-service;1", &rv);
   if (!NS_WARN_IF(NS_FAILED(rv)))
   {
     nsCOMPtr<nsIPrefBranch> branch = do_QueryInterface(prefs);
 
     if (branch)
     {
       int32_t temp;
-      NS_WARN_IF(NS_FAILED(branch->GetBoolPref("media.video.test_latency", &mVideoLatencyTestEnable)));
-      NS_WARN_IF(NS_FAILED(branch->GetIntPref("media.peerconnection.video.min_bitrate", &temp)));
+      (void) NS_WARN_IF(NS_FAILED(branch->GetBoolPref("media.video.test_latency", &mVideoLatencyTestEnable)));
+      (void) NS_WARN_IF(NS_FAILED(branch->GetIntPref("media.peerconnection.video.min_bitrate", &temp)));
       if (temp >= 0) {
         mMinBitrate = temp;
       }
-      NS_WARN_IF(NS_FAILED(branch->GetIntPref("media.peerconnection.video.start_bitrate", &temp)));
+      (void) NS_WARN_IF(NS_FAILED(branch->GetIntPref("media.peerconnection.video.start_bitrate", &temp)));
       if (temp >= 0) {
         mStartBitrate = temp;
       }
-      NS_WARN_IF(NS_FAILED(branch->GetIntPref("media.peerconnection.video.max_bitrate", &temp)));
+      (void) NS_WARN_IF(NS_FAILED(branch->GetIntPref("media.peerconnection.video.max_bitrate", &temp)));
       if (temp >= 0) {
         mMaxBitrate = temp;
       }
       bool use_loadmanager = false;
-      NS_WARN_IF(NS_FAILED(branch->GetBoolPref("media.navigator.load_adapt", &use_loadmanager)));
+      (void) NS_WARN_IF(NS_FAILED(branch->GetBoolPref("media.navigator.load_adapt", &use_loadmanager)));
       if (use_loadmanager) {
         mLoadManager = LoadManagerBuild();
       }
     }
   }
 #endif
 
   if (other) {
@@ -652,17 +652,17 @@ WebrtcVideoConduit::ConfigureSendMediaCo
 
   if (!mVideoCodecStat) {
     mVideoCodecStat = new VideoCodecStatistics(mChannel, mPtrViECodec, true);
   }
 
   mSendingWidth = 0;
   mSendingHeight = 0;
 
-  if(codecConfig->RtcpFbIsSet(SDP_RTCP_FB_NACK_BASIC)) {
+  if(codecConfig->RtcpFbNackIsSet("")) {
     CSFLogDebug(logTag, "Enabling NACK (send) for video stream\n");
     if (mPtrRTP->SetNACKStatus(mChannel, true) != 0)
     {
       CSFLogError(logTag,  "%s NACKStatus Failed %d ", __FUNCTION__,
                   mPtrViEBase->LastError());
       return kMediaConduitNACKStatusError;
     }
   }
@@ -735,27 +735,27 @@ WebrtcVideoConduit::ConfigureRecvMediaCo
     //if the codec param is invalid or diplicate, return error
     if((condError = ValidateCodecConfig(codecConfigList[i],false)) != kMediaConduitNoError)
     {
       return condError;
     }
 
     // Check for the keyframe request type: PLI is preferred
     // over FIR, and FIR is preferred over none.
-    if (codecConfigList[i]->RtcpFbIsSet(SDP_RTCP_FB_NACK_PLI))
+    if (codecConfigList[i]->RtcpFbNackIsSet("pli"))
     {
       kf_request = webrtc::kViEKeyFrameRequestPliRtcp;
     } else if(kf_request == webrtc::kViEKeyFrameRequestNone &&
-              codecConfigList[i]->RtcpFbIsSet(SDP_RTCP_FB_CCM_FIR))
+              codecConfigList[i]->RtcpFbCcmIsSet("fir"))
     {
       kf_request = webrtc::kViEKeyFrameRequestFirRtcp;
     }
 
     // Check whether NACK is requested
-    if(codecConfigList[i]->RtcpFbIsSet(SDP_RTCP_FB_NACK_BASIC))
+    if(codecConfigList[i]->RtcpFbNackIsSet(""))
     {
       use_nack_basic = true;
     }
 
     webrtc::VideoCodec  video_codec;
 
     mEngineReceiving = false;
     memset(&video_codec, 0, sizeof(webrtc::VideoCodec));
@@ -1273,17 +1273,17 @@ WebrtcVideoConduit::DeliverFrame(unsigne
 void
 WebrtcVideoConduit::CodecConfigToWebRTCCodec(const VideoCodecConfig* codecInfo,
                                               webrtc::VideoCodec& cinst)
 {
   // Note: this assumes cinst is initialized to a base state either by
   // hand or from a config fetched with GetConfig(); this modifies the config
   // to match parameters from VideoCodecConfig
   cinst.plType  = codecInfo->mType;
-  if (codecInfo->mName == "H264_P0" || codecInfo->mName == "H264_P1") {
+  if (codecInfo->mName == "H264") {
     cinst.codecType = webrtc::kVideoCodecH264;
     PL_strncpyz(cinst.plName, "H264", sizeof(cinst.plName));
   } else if (codecInfo->mName == "VP8") {
     cinst.codecType = webrtc::kVideoCodecVP8;
     PL_strncpyz(cinst.plName, "VP8", sizeof(cinst.plName));
   } else if (codecInfo->mName == "I420") {
     cinst.codecType = webrtc::kVideoCodecI420;
     PL_strncpyz(cinst.plName, "I420", sizeof(cinst.plName));
deleted file mode 100644
--- a/media/webrtc/signaling/src/media/CSFVideoControlWrapper.cpp
+++ /dev/null
@@ -1,94 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "CSFLog.h"
-#include "CSFVideoControlWrapper.h"
-
-static const char* logTag = "VcmSipccBinding";
-
-namespace CSF {
-
-void VideoControlWrapper::setVideoMode( bool enable )
-{
-	if (_realVideoControl != nullptr)
-	{
-		_realVideoControl->setVideoMode(enable);
-	}
-	else
-	{
-		CSFLogWarn( logTag, "Attempt to setVideoMode to %s for expired video control",
-			enable ? "TRUE" : "FALSE");
-	}
-}
-
-void VideoControlWrapper::setPreviewWindow( VideoWindowHandle window, int top, int left, int bottom, int right, RenderScaling style )
-{
-	if (_realVideoControl != nullptr)
-	{
-		_realVideoControl->setPreviewWindow(window, top, left, bottom, right, style);
-	}
-	else
-	{
-		CSFLogWarn( logTag, "Attempt to setPreviewWindow for expired video control");
-	}
-}
-
-
-void VideoControlWrapper::showPreviewWindow( bool show )
-{
-	if (_realVideoControl != nullptr)
-	{
-		_realVideoControl->showPreviewWindow(show);
-	}
-	else
-	{
-		CSFLogWarn( logTag, "Attempt to showPreviewWindow( %s ) for expired video control",
-			show ? "TRUE" : "FALSE");
-	}
-}
-
-
-std::vector<std::string> VideoControlWrapper::getCaptureDevices()
-{
-	if (_realVideoControl != nullptr)
-	{
-		return _realVideoControl->getCaptureDevices();
-	}
-	else
-	{
-		CSFLogWarn( logTag, "Attempt to getCaptureDevices for expired video control");
-		std::vector<std::string> vec;
-		return vec;
-	}
-}
-
-
-std::string VideoControlWrapper::getCaptureDevice()
-{
-	if (_realVideoControl != nullptr)
-	{
-		return _realVideoControl->getCaptureDevice();
-	}
-	else
-	{
-		CSFLogWarn( logTag, "Attempt to getCaptureDevice for expired video control");
-		return "";
-	}
-}
-
-bool VideoControlWrapper::setCaptureDevice( const std::string& name )
-{
-	if (_realVideoControl != nullptr)
-	{
-		return _realVideoControl->setCaptureDevice(name);
-	}
-	else
-	{
-		CSFLogWarn( logTag, "Attempt to setCaptureDevice to %s for expired video control",
-			name.c_str());
-		return false;
-	}
-}
-
-}
deleted file mode 100644
--- a/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp
+++ /dev/null
@@ -1,2853 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "CSFLog.h"
-
-#include "CSFMediaProvider.h"
-#include "CSFAudioTermination.h"
-#include "CSFVideoTermination.h"
-#include "MediaConduitErrors.h"
-#include "MediaConduitInterface.h"
-#include "GmpVideoCodec.h"
-#include "MediaPipeline.h"
-#include "MediaPipelineFilter.h"
-#include "VcmSIPCCBinding.h"
-#include "csf_common.h"
-#include "PeerConnectionImpl.h"
-#include "PeerConnectionMedia.h"
-#include "nsThreadUtils.h"
-#include "transportflow.h"
-#include "transportlayer.h"
-#include "transportlayerdtls.h"
-#include "transportlayerice.h"
-#include "runnable_utils.h"
-#include "cpr_stdlib.h"
-#include "cpr_string.h"
-#include "mozilla/SyncRunnable.h"
-#include "mozilla/Services.h"
-#include "nsServiceManagerUtils.h"
-#include "nsIPrefService.h"
-#include "nsIPrefBranch.h"
-#ifdef MOZILLA_INTERNAL_API
-#include "nsIPrincipal.h"
-#include "nsIDocument.h"
-#include "mozilla/Preferences.h"
-#endif
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <ssl.h>
-#include <sslproto.h>
-#include <algorithm>
-
-#ifdef MOZ_WEBRTC_OMX
-#include "OMXVideoCodec.h"
-#include "OMXCodecWrapper.h"
-#endif
-
-extern "C" {
-#include "ccsdp.h"
-#include "ccapi.h"
-#include "cip_mmgr_mediadefinitions.h"
-#include "cip_Sipcc_CodecMask.h"
-#include "peer_connection_types.h"
-
-extern void lsm_start_multipart_tone_timer (vcm_tones_t tone,
-                                            uint32_t delay,
-                                            cc_call_handle_t callId);
-extern void lsm_start_continuous_tone_timer (vcm_tones_t tone,
-                                             uint32_t delay,
-                                             cc_call_handle_t callId);
-extern void lsm_update_active_tone(vcm_tones_t tone, cc_call_handle_t call_handle);
-extern void lsm_stop_multipart_tone_timer(void);
-extern void lsm_stop_continuous_tone_timer(void);
-
-static int vcmEnsureExternalCodec(
-    const mozilla::RefPtr<mozilla::VideoSessionConduit>& conduit,
-    mozilla::VideoCodecConfig* config,
-    bool send);
-
-}//end extern "C"
-
-static const char* logTag = "VcmSipccBinding";
-
-#define SIPSDP_ILBC_MODE20 20
-
-/* static */
-
-using namespace mozilla;
-using namespace CSF;
-
-VcmSIPCCBinding * VcmSIPCCBinding::gSelf = nullptr;
-bool VcmSIPCCBinding::gInitGmpCodecs = false;
-int VcmSIPCCBinding::gAudioCodecMask = 0;
-int VcmSIPCCBinding::gVideoCodecMask = 0;
-int VcmSIPCCBinding::gVideoCodecGmpMask = 0;
-nsIThread *VcmSIPCCBinding::gMainThread = nullptr;
-nsCOMPtr<nsIPrefBranch> VcmSIPCCBinding::gBranch = nullptr;
-
-static mozilla::RefPtr<TransportFlow> vcmCreateTransportFlow(
-    sipcc::PeerConnectionImpl *pc,
-    int level,
-    bool rtcp,
-    sdp_setup_type_e setup_type,
-    const char *fingerprint_alg,
-    const char *fingerprint);
-
-// Convenience macro to acquire PC
-
-#define ENSURE_PC(pc, errval) \
-  do { \
-    if (!pc.impl()) {                                                 \
-      CSFLogDebug(logTag, "%s: couldn't acquire peerconnection %s", __FUNCTION__, peerconnection); \
-      return errval; \
-    }         \
-  } while(0)
-
-#define ENSURE_PC_NO_RET(pc, peerconnection) \
-  do { \
-    if (!pc.impl()) {                                                 \
-      CSFLogDebug(logTag, "%s: couldn't acquire peerconnection %s", __FUNCTION__, peerconnection); \
-      return; \
-    }         \
-  } while(0)
-
-VcmSIPCCBinding::VcmSIPCCBinding ()
-  : streamObserver(nullptr)
-{
-    delete gSelf;
-    gSelf = this;
-  nsresult rv;
-
-  nsCOMPtr<nsIPrefService> prefs = do_GetService("@mozilla.org/preferences-service;1", &rv);
-  if (NS_SUCCEEDED(rv)) {
-    gBranch = do_QueryInterface(prefs);
-  }
-}
-
-VcmSIPCCBinding::~VcmSIPCCBinding ()
-{
-  assert(gSelf);
-  gSelf = nullptr;
-  gBranch = nullptr;
-}
-
-void VcmSIPCCBinding::setStreamObserver(StreamObserver* obs)
-{
-        streamObserver = obs;
-}
-
-/* static */
-StreamObserver * VcmSIPCCBinding::getStreamObserver()
-{
-    if (gSelf != nullptr)
-        return gSelf->streamObserver;
-
-    return nullptr;
-}
-
-void VcmSIPCCBinding::setMediaProviderObserver(MediaProviderObserver* obs)
-{
-        mediaProviderObserver = obs;
-}
-
-
-MediaProviderObserver * VcmSIPCCBinding::getMediaProviderObserver()
-{
-    if (gSelf != nullptr)
-        return gSelf->mediaProviderObserver;
-
-    return nullptr;
-}
-
-void VcmSIPCCBinding::setAudioCodecs(int codecMask)
-{
-  CSFLogDebug(logTag, "SETTING AUDIO: %d", codecMask);
-  VcmSIPCCBinding::gAudioCodecMask = codecMask;
-}
-
-void VcmSIPCCBinding::setVideoCodecs(int codecMask)
-{
-  CSFLogDebug(logTag, "SETTING VIDEO: %d", codecMask);
-  VcmSIPCCBinding::gVideoCodecMask = codecMask;
-}
-
-int VcmSIPCCBinding::getAudioCodecs()
-{
-  return VcmSIPCCBinding::gAudioCodecMask;
-}
-
-int VcmSIPCCBinding::getVideoCodecs()
-{
-  return VcmSIPCCBinding::gVideoCodecMask;
-}
-
-int VcmSIPCCBinding::getVideoCodecsGmp()
-{
-  // This code assumes that GMP has been initted, specifically
-  // by PeerConnectionCtx::initGMP()
-  if (!gSelf->mGMPService) {
-    gSelf->mGMPService = do_GetService("@mozilla.org/gecko-media-plugin-service;1");
-  }
-
-  if (!gSelf->mGMPService) {
-    return 0;
-  }
-
-  // XXX I'd prefer if this was all known ahead of time...
-
-  nsTArray<nsCString> tags;
-  tags.AppendElement(NS_LITERAL_CSTRING("h264"));
-
-  // H.264 only for now
-  bool has_gmp;
-  nsresult rv;
-  rv = gSelf->mGMPService->HasPluginForAPI(NS_LITERAL_CSTRING("encode-video"),
-                                           &tags,
-                                           &has_gmp);
-  if (NS_FAILED(rv) || !has_gmp) {
-    return 0;
-  }
-
-  rv = gSelf->mGMPService->HasPluginForAPI(NS_LITERAL_CSTRING("decode-video"),
-                                           &tags,
-                                           &has_gmp);
-  if (NS_FAILED(rv) || !has_gmp) {
-    return 0;
-  }
-
-  return VCM_CODEC_RESOURCE_H264;
-}
-
-int VcmSIPCCBinding::getVideoCodecsHw()
-{
-  // Check to see if what HW codecs are available (not in use) at this moment.
-  // Note that streaming video decode can reserve a decoder
-
-  // XXX See bug 1018791 Implement W3 codec reservation policy
-  // Note that currently, OMXCodecReservation needs to be held by an sp<> because it puts
-  // 'this' into an sp<EventListener> to talk to the resource reservation code
-#ifdef MOZ_WEBRTC_OMX
-#ifdef MOZILLA_INTERNAL_API
-  if (Preferences::GetBool("media.peerconnection.video.h264_enabled")) {
-#endif
-    android::sp<android::OMXCodecReservation> encode = new android::OMXCodecReservation(true);
-    android::sp<android::OMXCodecReservation> decode = new android::OMXCodecReservation(false);
-
-    // Currently we just check if they're available right now, which will fail if we're
-    // trying to call ourself, for example.  It will work for most real-world cases, like
-    // if we try to add a person to a 2-way call to make a 3-way mesh call
-    if (encode->ReserveOMXCodec() && decode->ReserveOMXCodec()) {
-      CSFLogDebug( logTag, "%s: H264 hardware codec available", __FUNCTION__);
-      return VCM_CODEC_RESOURCE_H264;
-    }
-#if defined( MOZILLA_INTERNAL_API)
-   }
-#endif
-#endif
-
-  return 0;
-}
-
-void VcmSIPCCBinding::setMainThread(nsIThread *thread)
-{
-  gMainThread = thread;
-}
-
-nsIThread* VcmSIPCCBinding::getMainThread()
-{
-  return gMainThread;
-}
-
-nsCOMPtr<nsIPrefBranch> VcmSIPCCBinding::getPrefBranch()
-{
-  return gBranch;
-}
-
-/* static */
-AudioTermination * VcmSIPCCBinding::getAudioTermination()
-{
-    // commenting as part of media provider removal
-    return nullptr;
-}
-
-/* static */
-VideoTermination * VcmSIPCCBinding::getVideoTermination()
-{
-    // commenting as part of media provider removal
-    return nullptr;
-}
-
-/* static */
-AudioControl * VcmSIPCCBinding::getAudioControl()
-{
-    // commenting as part of media provider removal
-    return nullptr;
-}
-
-/* static */
-VideoControl * VcmSIPCCBinding::getVideoControl()
-{
-    // commenting as part of media provider removal
-    return nullptr;
-}
-
-/*
- * Used to play busy verfication tone
- */
-#define BUSY_VERIFICATION_DELAY       (10000)
-
-/*
- * Temp until added to config
- */
-
-#define TOH_DELAY                (10000)/*
- * Used to play msg waiting and stutter dialtones.
- * Both tones are 100ms on/off repeating 10 and
- * 3 times respectively, followed by steady dialtone.
- * Due to DSP limitations we first tell the DSP to
- * play the 100ms on/off pairs the correct number of
- * times, set a timer, and then tell it to play dialtone.
- */
-#define MSG_WAITING_DELAY   (2050)
-#define STUTTER_DELAY       (650)
-
-/*
- * Used to play the busy verfication tone which
- * is two seconds of dialtone followed by the
- * callwaiting tone every ten seconds.
- */
-#define BUSY_VERIFY_DELAY   (12000)
-
-
-#define VCM_MIN_VOLUME_BYTE       0
-#define VCM_MAX_VOLUME_BYTE       255
-#define VCM_MIN_VOLUME_LEVEL      0
-#define VCM_MAX_VOLUME_LEVEL      240
-#define VCM_RNG_MAX_VOLUME_LEVEL  248
-#define VCM_DEFAULT_AUDIO_VOLUME  144
-#define VCM_DEFAULT_RINGER_VOLUME 80
-#define VCM_VOLUME_ADJUST_LEVEL   8
-
-
-extern "C" {
-
-
-/* MediaTermination APIs expect dynmic payload type in upper 16 bits and
-   codec type in lower 16 bits. */
-#define CREATE_MT_MAP(a,b)        ((a << 16) | b)
-#define DYNAMIC_PAYLOAD_TYPE(x)    ((x >> 16) & 0xFFFF)
-
-#define VCM_ERROR -1
-
-/**
- *  start/stop ringing
- *
- *  @param[in] ringMode   - VCM ring mode (ON/OFF)
- *  @param[in] once       - type of ring - continuous or one shot.
- *  @param[in] alert_info - header specified ring mode.
- *  @param[in] line       - the line on which to start/stop ringing
- *
- *  @return    void
- */
-
-void vcmControlRinger (vcm_ring_mode_t ringMode,
-                       short once,
-                       cc_boolean alert_info,
-                       int line,
-                       cc_callid_t call_id)
-{
-    ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-    const char fname[] = "vcmControlRinger";
-
-    CSFLogDebug( logTag, "%s: ringMode=%d once=%d", fname, ringMode, once);
-
-    /* we need to pass the line parameter for this */
-
-#if 0
-     // <emannion> part of media provider removal
-    if ( ringMode == VCM_RING_OFF )
-    {
-        //call media_ring_stop
-        if ( VcmSIPCCBinding::getAudioTermination()->ringStop( line ) != 0 )
-        {
-            CSFLogDebug( logTag, "%s: mediaRingStop failed", fname);
-        }
-    }
-    else if ( VcmSIPCCBinding::getAudioTermination()->ringStart( line, map_ring_mode(ringMode), (once != 0) ) != 0 )
-    {
-        CSFLogDebug( logTag, "%s: mediaRingStart failed", fname);
-    }
-#endif
-}
-
-/**
- *  To be Deprecated
- *  This may be needed to be implemented if the DSP doesn't automatically enable the side tone
- *  The stack will make a call to this method based on the call state. Provide a stub if this is not needed.
- *
- *  @param[in] side_tone - cc_boolean to enable/disable side tone
- *
- *  @return void
- *
- */
-
-void vcmEnableSidetone(cc_uint16_t side_tone)
-{
-    ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-    /* NOT REQD for TNP */
-    CSFLogDebug( logTag, "vcmEnableSidetone: vcmEnableSidetone(): called");
-}
-
-/*
- *  Function:map_algorithmID
- *
- *  Parameters:algorithmID
- *
- *  Description: Converts VCM algorithmID type to media layer defs.
- *
- *  Returns:algorithmID value corresponding to VCM algorithmID
- *
- */
-static EncryptionAlgorithm
-map_algorithmID( vcm_crypto_algorithmID algorithmID )
-{
-    switch ( algorithmID )
-    {
-    case VCM_AES_128_COUNTER:
-        return EncryptionAlgorithm_AES_128_COUNTER;
-
-    default:
-        return EncryptionAlgorithm_NONE;
-    }
-}
-
-/*
- *  Function:vcm_init
- *
- *  Parameters:none
- *
- *  Description: Nothing to do for TNP.
- *
- *  Returns:none
- *
- */
-void vcmInit (void)
-{
-    // We do not do a thread assert here, since there are unit-tests that set
-    // gMainThread to something other than main, but still call the init code
-    // on main.
-    CSFLogDebug( logTag, "vcmInit() called.");
-}
-
-/**
- * The unloading of the VCM module
- */
-void vcmUnload (void)
-{
-    ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-    CSFLogDebug( logTag, "vcmUnload() called.");
-}
-
-/**
- *  Allocate(Reserve) a receive port.
- *
- *  @param[in]  mcap_id - Media Capability ID
- *  @param[in]  group_id - group identifier to which stream belongs.
- *  @param[in]  stream_id - stream identifier
- *  @param[in]  call_handle  - call identifier
- *  @param[in]  port_requested - port requested (if zero -> give any)
- *  @param[out]  port_allocated - port that was actually allocated.
- *
- *  @return    void
- *
- */
-
-void vcmRxAllocPort(cc_mcapid_t mcap_id,
-                    cc_groupid_t group_id,
-                    cc_streamid_t stream_id,
-                    cc_call_handle_t  call_handle,
-                    cc_uint16_t port_requested,
-                    int *port_allocated)
-{
-    ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-    *port_allocated = -1;
-    CSFLogDebug( logTag, "vcmRxAllocPort(): group_id=%d stream_id=%d call_handle=%d port_requested = %d",
-        group_id, stream_id, call_handle, port_requested);
-
-    // Not in SDP/PeerConnection mode
-    int port = -1;
-    bool isVideo = false;
-    if(CC_IS_AUDIO(mcap_id))
-    {
-      isVideo = false;
-      if ( VcmSIPCCBinding::getAudioTermination() != nullptr )
-        port = VcmSIPCCBinding::getAudioTermination()->rxAlloc( group_id, stream_id, port_requested );
-    }
-    else if(CC_IS_VIDEO(mcap_id))
-    {
-      isVideo = true;
-      if ( VcmSIPCCBinding::getVideoTermination() != nullptr )
-        port = VcmSIPCCBinding::getVideoTermination()->rxAlloc( group_id, stream_id, port_requested );
-    }
-
-    StreamObserver* obs = VcmSIPCCBinding::getStreamObserver();
-    if(obs != nullptr)
-      obs->registerStream(call_handle, stream_id, isVideo);
-
-    CSFLogDebug( logTag, "vcmRxAllocPort(): allocated port %d", port);
-    *port_allocated = port;
-}
-
-/**
- *  Gets the ICE parameters for a stream. Called "alloc" for style consistency
- *
- *  @param[in]  mcap_id - Media Capability ID
- *  @param[in]  group_id - group identifier to which stream belongs.
- *  @param[in]  stream_id - stream identifier
- *  @param[in]  call_handle  - call identifier
- *  @param[in]  peerconnection - the peerconnection in use
- *  @param[in]  level - the m-line index (1-based)
- *  @param[out] default_addrp - the ICE default addr
- *  @param[out] port_allocatedp - the ICE default port
- *  @param[out] candidatesp - the ICE candidate array
- *  @param[out] candidate_ctp length of the array
- *
- *  @return 0 for success; VCM_ERROR for failure
- *
- */
-short vcmRxAllocICE(cc_mcapid_t mcap_id,
-                   cc_groupid_t group_id,
-                   cc_streamid_t stream_id,
-                   cc_call_handle_t  call_handle,
-                   const char *peerconnection,
-                   uint16_t level,
-                   char **default_addrp, /* Out */
-                   int *default_portp, /* Out */
-                   char ***candidatesp, /* Out */
-                   int *candidate_ctp /* Out */
-                   )
-{
-  *default_addrp = nullptr;
-  *default_portp = -1;
-  *candidatesp = nullptr;
-  *candidate_ctp = 0;
-
-  // draft-ivov-mmusic-trickle-ice-01.txt says to use port 9
-  // but "::" instead of "0.0.0.0". Since we don't do any
-  // IPv6 we are ignoring that for now.
-  std::string default_addr("0.0.0.0");
-  int default_port = 9;
-
-  // Copy the default address
-  *default_addrp = (char *) cpr_malloc(default_addr.size() + 1);
-  if (!*default_addrp)
-    return VCM_ERROR;
-  sstrncpy(*default_addrp, default_addr.c_str(), default_addr.size() + 1);
-  *default_portp = default_port; /* This is the signal that things are cool */
-
-  // Now, we let the PeerConnectionImpl know that another m-line has been added
-  // This is necessary to avoid trickling extra candidates that aren't needed.
-  sipcc::PeerConnectionWrapper pc(peerconnection);
-  ENSURE_PC(pc, VCM_ERROR);
-
-  pc.impl()->OnNewMline(level);
-
-  return 0;
-}
-
-/* Get ICE global parameters (ufrag and pwd)
- *  @param[in]  peerconnection - the peerconnection in use
- *  @param[out] ufragp - where to put the ufrag
- *  @param[out] pwdp - where to put the pwd
- *
- *  @return 0 for success; VCM_ERROR for failure
- */
-short vcmGetIceParams(const char *peerconnection,
-                      char **ufragp,
-                      char **pwdp)
-{
-  ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-  CSFLogDebug( logTag, "%s: PC = %s", __FUNCTION__, peerconnection);
-
-  *ufragp = *pwdp = nullptr;
-
- // Note: we don't acquire any media resources here, and we assume that the
-  // ICE streams already exist, so we're just acquiring them. Any logic
-  // to make them on demand is elsewhere.
-  sipcc::PeerConnectionWrapper pc(peerconnection);
-  ENSURE_PC(pc, VCM_ERROR);
-
-  std::vector<std::string> attrs = pc.impl()->media()->
-    ice_ctx()->GetGlobalAttributes();
-
-  // Now fish through these looking for a ufrag and passwd
-  char *ufrag = nullptr;
-  char *pwd = nullptr;
-
-  for (size_t i=0; i<attrs.size(); i++) {
-    if (attrs[i].compare(0, strlen("ice-ufrag:"), "ice-ufrag:") == 0) {
-      if (!ufrag) {
-        ufrag = (char *) cpr_malloc(attrs[i].size() + 1);
-        if (!ufrag)
-          return VCM_ERROR;
-        sstrncpy(ufrag, attrs[i].c_str(), attrs[i].size() + 1);
-        ufrag[attrs[i].size()] = 0;
-      }
-    }
-
-    if (attrs[i].compare(0, strlen("ice-pwd:"), "ice-pwd:") == 0) {
-      pwd = (char *) cpr_malloc(attrs[i].size() + 1);
-      if (!pwd)
-        return VCM_ERROR;
-      sstrncpy(pwd, attrs[i].c_str(), attrs[i].size() + 1);
-      pwd[attrs[i].size()] = 0;
-    }
-
-  }
-  if (!ufrag || !pwd) {
-    MOZ_ASSERT(PR_FALSE);
-    cpr_free(ufrag);
-    cpr_free(pwd);
-    CSFLogDebug( logTag, "%s: no ufrag or password", __FUNCTION__);
-    return VCM_ERROR;
-  }
-
-  *ufragp = ufrag;
-  *pwdp = pwd;
-
-  return 0;
-}
-
-/* Set remote ICE global parameters.
- *
- *  @param[in]  peerconnection - the peerconnection in use
- *  @param[in]  ufrag - the ufrag
- *  @param[in]  pwd - the pwd
- *  @param[in]  icelite - is peer ice lite
- *
- *  @return 0 for success; VCM_ERROR for failure
- */
-short vcmSetIceSessionParams(const char *peerconnection,
-                             char *ufrag,
-                             char *pwd,
-                             cc_boolean icelite)
-{
-  ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-  CSFLogDebug( logTag, "%s: PC = %s", __FUNCTION__, peerconnection);
-
-  sipcc::PeerConnectionWrapper pc(peerconnection);
-  ENSURE_PC(pc, VCM_ERROR);
-
-  std::vector<std::string> attributes;
-
-  if (ufrag)
-    attributes.push_back(ufrag);
-  if (pwd)
-    attributes.push_back(pwd);
-  if (icelite) {
-    attributes.push_back("ice-lite");
-  }
-  nsresult res = pc.impl()->media()->ice_ctx()->
-    ParseGlobalAttributes(attributes);
-
-  if (!NS_SUCCEEDED(res)) {
-    CSFLogError( logTag, "%s: couldn't parse global parameters", __FUNCTION__ );
-    return VCM_ERROR;
-  }
-
-  return 0;
-}
-
-/* Set ice candidate for trickle ICE.
- *
- *  @param[in]  peerconnection - the peerconnection in use
- *  @param[in]  icecandidate - the icecandidate
- *  @param[in]  level - the m line level
- *
- *  @return 0 success, error failure
- */
-short vcmSetIceCandidate(const char *peerconnection,
-                         const char *icecandidate,
-                         uint16_t level)
-{
-  ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-  CSFLogDebug( logTag, "%s: PC = %s", __FUNCTION__, peerconnection);
-
-  sipcc::PeerConnectionWrapper pc(peerconnection);
-  ENSURE_PC(pc, VCM_ERROR);
-
-  CSFLogDebug( logTag, "%s(): Getting stream %d", __FUNCTION__, level);
-  mozilla::RefPtr<NrIceMediaStream> stream = pc.impl()->media()->
-    ice_media_stream(level-1);
-  if (!stream)
-    return VCM_ERROR;
-
-  nsresult rv = RUN_ON_THREAD(pc.impl()->media()->ice_ctx()->thread(),
-                              WrapRunnable(stream,
-                                           &NrIceMediaStream::ParseTrickleCandidate,
-                                           std::string(icecandidate)),
-                              NS_DISPATCH_NORMAL);
-
-  if (!NS_SUCCEEDED(rv)) {
-    CSFLogError( logTag, "%s(): Could not dispatch to ICE thread, level %u",
-      __FUNCTION__, level);
-    return VCM_ERROR;
-  }
-
-  // TODO(ekr@rtfm.com): generate an error if the parse
-  // fails. Bug 847449.
-
-  return 0;
-}
-
-
-/* Start ICE checks
- *  @param[in]  peerconnection - the peerconnection in use
- *  @return 0 success, error failure
- */
-short vcmStartIceChecks(const char *peerconnection, cc_boolean isControlling)
-{
-  ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-  CSFLogDebug( logTag, "%s: PC = %s", __FUNCTION__, peerconnection);
-
-  sipcc::PeerConnectionWrapper pc(peerconnection);
-  ENSURE_PC(pc, VCM_ERROR);
-
-  nsresult res;
-  res = pc.impl()->media()->ice_ctx()->SetControlling(
-      isControlling ? NrIceCtx::ICE_CONTROLLING : NrIceCtx::ICE_CONTROLLED);
-  if (!NS_SUCCEEDED(res)) {
-    CSFLogError( logTag, "%s: couldn't set controlling", __FUNCTION__ );
-    return VCM_ERROR;
-  }
-  // TODO(ekr@rtfm.com): Figure out how to report errors here.
-  // Bug 854516.
-  nsresult rv = pc.impl()->media()->ice_ctx()->thread()->Dispatch(
-    WrapRunnable(pc.impl()->media()->ice_ctx(), &NrIceCtx::StartChecks),
-      NS_DISPATCH_NORMAL);
-
-  if (!NS_SUCCEEDED(rv)) {
-    CSFLogError( logTag, "%s(): Could not dispatch to ICE thread", __FUNCTION__);
-    return VCM_ERROR;
-  }
-
-  return 0;
-}
-
-/* Set remote ICE media-level parameters.
- *
- *  @param[in]  peerconnection - the peerconnection in use
- *  @param[in]  level - the m-line
- *  @param[in]  ufrag - the ufrag
- *  @param[in]  pwd - the pwd
- *  @param[in]  candidates - the candidates
- *  @param[in]  candidate_ct - the number of candidates
- *  @return 0 success, error failure
- */
-short vcmSetIceMediaParams(const char *peerconnection,
-                           int level,
-                           char *ufrag,
-                           char *pwd,
-                           char **candidates,
-                           int candidate_ct)
-{
-  ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-  CSFLogDebug( logTag, "%s: PC = %s", __FUNCTION__, peerconnection);
-
-  sipcc::PeerConnectionWrapper pc(peerconnection);
-  ENSURE_PC(pc, VCM_ERROR);
-
-  CSFLogDebug( logTag, "%s(): Getting stream %d", __FUNCTION__, level);
-  mozilla::RefPtr<NrIceMediaStream> stream = pc.impl()->media()->
-    ice_media_stream(level-1);
-  if (!stream)
-    return VCM_ERROR;
-
-  std::vector<std::string> attributes;
-
-  if (ufrag)
-    attributes.push_back(ufrag);
-  if (pwd)
-    attributes.push_back(pwd);
-
-  for (int i = 0; i<candidate_ct; i++) {
-    attributes.push_back(candidates[i]);
-  }
-
-  nsresult res = stream->ParseAttributes(attributes);
-
-  if (!NS_SUCCEEDED(res)) {
-    CSFLogError( logTag, "%s: couldn't parse global parameters", __FUNCTION__ );
-    return VCM_ERROR;
-  }
-
-  return 0;
-}
-
-/*
- * Create a remote stream
- *
- *  @param[in] mcap_id - group identifier to which stream belongs.
- *  @param[in]  peerconnection - the peerconnection in use
- *  @param[out] pc_stream_id - the id of the allocated stream
- *
- *  TODO(ekr@rtfm.com): Revise along with everything else for the
- *  new stream model.
- *
- *  Returns: zero(0) for success; otherwise, ERROR for failure
- */
-short vcmCreateRemoteStream(
-  cc_mcapid_t mcap_id,
-  const char *peerconnection,
-  int *pc_stream_id) {
-  ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-  nsresult res;
-
-  *pc_stream_id = -1;
-
-  CSFLogDebug( logTag, "%s", __FUNCTION__);
-  sipcc::PeerConnectionWrapper pc(peerconnection);
-  ENSURE_PC(pc, VCM_ERROR);
-
-  nsRefPtr<sipcc::RemoteSourceStreamInfo> info;
-  res = pc.impl()->CreateRemoteSourceStreamInfo(&info);
-  if (NS_FAILED(res)) {
-    return VCM_ERROR;
-  }
-
-  res = pc.impl()->media()->AddRemoteStream(info, pc_stream_id);
-  if (NS_FAILED(res)) {
-    return VCM_ERROR;
-  }
-
-  CSFLogDebug( logTag, "%s: created remote stream with index %d",
-    __FUNCTION__, *pc_stream_id);
-
-  return 0;
-}
-
-/*
- * Add remote stream hint
- *
- * We are sending track information up to PeerConnection before
- * the tracks exist so it knows when the stream is fully constructed.
- *
- * @param[in] peerconnection
- * @param[in] pc_stream_id
- * @param[in] is_video
- *
- * Returns: zero(0) for success; otherwise, ERROR for failure
- */
-short vcmAddRemoteStreamHint(
-  const char *peerconnection,
-  int pc_stream_id,
-  cc_boolean is_video) {
-  ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-  nsresult res;
-
-  sipcc::PeerConnectionWrapper pc(peerconnection);
-  ENSURE_PC(pc, VCM_ERROR);
-
-  res = pc.impl()->media()->AddRemoteStreamHint(pc_stream_id,
-    is_video ? TRUE : FALSE);
-  if (NS_FAILED(res)) {
-    return VCM_ERROR;
-  }
-
-  CSFLogDebug( logTag, "%s: added remote stream hint %u with index %d",
-    __FUNCTION__, is_video, pc_stream_id);
-
-  return 0;
-}
-
-/*
- * Get DTLS key data
- *
- *  @param[in]  peerconnection - the peerconnection in use
- *  @param[out] digest_algp    - the digest algorithm e.g. 'sha-256'
- *  @param[in] max_digest_alg_len - available length of string
- *  @param[out] digestp        - the digest string
- *  @param[in] max_digest_len - available length of string
- *
- *  Returns: zero(0) for success; otherwise, ERROR for failure
- */
-short vcmGetDtlsIdentity(const char *peerconnection,
-                         char *digest_algp,
-                         size_t max_digest_alg_len,
-                         char *digestp,
-                         size_t max_digest_len) {
-
-  ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-  digest_algp[0]='\0';
-  digestp[0]='\0';
-
-  sipcc::PeerConnectionWrapper pc(peerconnection);
-  ENSURE_PC(pc, VCM_ERROR);
-
-  std::string algorithm = pc.impl()->GetFingerprintAlgorithm();
-  sstrncpy(digest_algp, algorithm.c_str(), max_digest_alg_len);
-  std::string value = pc.impl()->GetFingerprintHexValue();
-  sstrncpy(digestp, value.c_str(), max_digest_len);
-
-  return 0;
-}
-
-/* Set negotiated DataChannel parameters.
- *
- *  @param[in]  peerconnection - the peerconnection in use
- *  @param[in]  streams - the number of streams for this data channel
- *  @param[in]  local_datachannel_port - the negotiated sctp port
- *  @param[in]  remote_datachannel_port - the negotiated sctp port
- *  @param[in]  protocol - the protocol as a string
- *
- *  @return 0 success, error failure
- */
-short vcmInitializeDataChannel(const char *peerconnection,
-  int track_id, cc_uint16_t streams,
-  int local_datachannel_port, int remote_datachannel_port, const char* protocol)
-{
-  ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-  nsresult res;
-
-  CSFLogDebug( logTag, "%s: PC = %s", __FUNCTION__, peerconnection);
-
-  sipcc::PeerConnectionWrapper pc(peerconnection);
-  ENSURE_PC(pc, VCM_ERROR);
-
-  res = pc.impl()->InitializeDataChannel(track_id, local_datachannel_port,
-                                         remote_datachannel_port, streams);
-  if (NS_FAILED(res)) {
-    return VCM_ERROR;
-  }
-
-  return 0;
-}
-
-/**
- *   Should we remove this from external API
- *
- *  @param[in] mcap_id - group identifier to which stream belongs.
- *  @param[in]     group_id         - group identifier
- *  @param[in]     stream_id        - stream identifier
- *  @param[in]     call_handle      - call identifier
- *  @param[in]     port_requested   - requested port.
- *  @param[in]     listen_ip        - local IP for listening
- *  @param[in]     is_multicast     - multicast stream?
- *  @param[out]    port_allocated   - allocated(reserved) port
- *
- *  tbd need to see if we can deprecate this API
- *
- *  @return       0 success, ERROR failure.
- *
- */
-
-short vcmRxOpen(cc_mcapid_t mcap_id,
-                cc_groupid_t group_id,
-                cc_streamid_t stream_id,
-                cc_call_handle_t call_handle,
-                cc_uint16_t port_requested,
-                cpr_ip_addr_t *listen_ip,
-                cc_boolean is_multicast,
-                int *port_allocated)
-{
-    ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-    char fname[] = "vcmRxOpen";
-
-    char dottedIP[20] = "";
-    *port_allocated = -1;
-    if(listen_ip)
-    {
-        csf_sprintf(dottedIP, sizeof(dottedIP), "%u.%u.%u.%u",
-                (listen_ip->u.ip4 >> 24) & 0xff, (listen_ip->u.ip4 >> 16) & 0xff,
-                (listen_ip->u.ip4 >> 8) & 0xff, listen_ip->u.ip4 & 0xff );
-    }
-
-    CSFLogDebug( logTag, "%s: group_id=%d call_handle=%d listen=%s:%d is_mcast=%d",
-                      fname, group_id, call_handle, dottedIP, port_requested, is_multicast);
-
-    switch ( mcap_id )
-    {
-    case CC_AUDIO_1:
-        CSFLogDebug( logTag, "%s: audio stream", fname);
-        if ( VcmSIPCCBinding::getAudioTermination() != nullptr )
-            *port_allocated = VcmSIPCCBinding::getAudioTermination()->rxOpen( group_id, stream_id,
-                                                    port_requested, listen_ip ? listen_ip->u.ip4 : 0,
-                                                    (is_multicast != 0) );
-        break;
-    case CC_VIDEO_1:
-        CSFLogDebug( logTag, "%s: video stream", fname);
-        if ( VcmSIPCCBinding::getVideoTermination() != nullptr )
-            *port_allocated = VcmSIPCCBinding::getVideoTermination()->rxOpen( group_id, stream_id,
-                                                    port_requested, listen_ip ? listen_ip->u.ip4 : 0,
-                                                    (is_multicast != 0) );
-        break;
-
-    default:
-        break;
-    }
-    return 0;
-}
-
-/**
- *  Start receive stream
- *  Note: For video calls, for a given call_handle there will be
- *        two media lines and the corresponding group_id/stream_id pair.
- *        One RTP session is requested from media server for each
- *        media line(group/stream) i.e. a video call would result in
- *        two rtp_sessions in our session info list created by two
- *        calls to vcm_rx/tx with mcap_id of AUDIO and VIDEO respectively.
- *
- *  @param[in]    mcap_id     - media type id
- *  @param[in]    group_id    - group identifier associated with the stream
- *  @param[in]    stream_id   - id of the stream one per each media line
- *  @param[in]    call_handle - call identifier
- *  @param[in]    payload     - payload information
- *  @param[in]    local_addr  - local ip address to use.
- *  @param[in]    port        - local port (receive)
- *  @param[in]    algorithmID - crypto alogrithm ID
- *  @param[in]    rx_key      - rx key used when algorithm ID is encrypting
- *  @param[in]    attrs       - media attributes
- *
- *  @return   zero(0) for success; otherwise, -1 for failure
- *
- */
-int vcmRxStart(cc_mcapid_t mcap_id,
-               cc_groupid_t group_id,
-               cc_streamid_t stream_id,
-               cc_call_handle_t  call_handle,
-               const vcm_payload_info_t *payload,
-               cpr_ip_addr_t *local_addr,
-               cc_uint16_t port,
-               vcm_crypto_algorithmID algorithmID,
-               vcm_crypto_key_t *rx_key,
-               vcm_mediaAttrs_t *attrs)
-{
-    ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-    uint8_t    *key;
-    uint8_t    *salt;
-    cc_uint16_t    key_len;
-    cc_uint16_t    salt_len;
-    char        fname[] = "vcmRxStart";
-
-    CSFLogDebug( logTag, "%s: group_id=%d call_handle=%d payload=%d port=%d"
-        " algID=%d", fname, group_id, call_handle, payload->remote_rtp_pt,
-        port, algorithmID);
-
-    if (call_handle == CC_NO_CALL_ID) {
-        /* no operation when no call ID */
-        return VCM_ERROR;
-    }
-
-    /* Set up crypto parameters */
-    switch ( algorithmID )
-    {
-    case VCM_AES_128_COUNTER:
-        if ( rx_key == nullptr )
-        {
-            /* No key provided */
-            CSFLogDebug( logTag, "vcmRxStart(): No key for algorithm ID %d",
-                      algorithmID);
-            return VCM_ERROR;
-        }
-        /* Set up key and Salt parameters */
-        key_len = rx_key->key_len;
-        key = &rx_key->key[0];
-        salt_len = rx_key->salt_len;
-        salt = &rx_key->salt[0];
-        break;
-
-    default:
-        /* Give dummy data to avoid passing nullptr for key/salt */
-        key_len = 0;
-        key = (uint8_t *)"";
-        salt_len = 0;
-        salt = (uint8_t *)"";
-        break;
-    }
-
-    switch ( mcap_id )
-    {
-    case CC_AUDIO_1:
-        if ( VcmSIPCCBinding::getAudioTermination() != nullptr )
-            return VcmSIPCCBinding::getAudioTermination()->rxStart(
-                group_id, stream_id, payload->local_rtp_pt,
-                attrs->audio.packetization_period, port,
-                attrs->audio.avt_payload_type, map_algorithmID(algorithmID),
-                key, key_len, salt, salt_len, attrs->audio.mixing_mode,
-                attrs->audio.mixing_party );
-        break;
-
-    case CC_VIDEO_1:
-        if ( VcmSIPCCBinding::getVideoTermination() != nullptr )
-            return VcmSIPCCBinding::getVideoTermination()->rxStart(
-                group_id, stream_id, payload->local_rtp_pt,
-                0, port, 0, map_algorithmID(algorithmID), key, key_len,
-                salt, salt_len, 0, 0);
-        break;
-
-    default:
-        break;
-    }
-    return VCM_ERROR;
-}
-
-
-void vcmOnRemoteStreamAdded(cc_call_handle_t call_handle,
-                            const char* peer_connection_handle,
-                            vcm_media_remote_track_table_t *sipcc_stream_table) {
-  sipcc::PeerConnectionWrapper wrapper(peer_connection_handle);
-
-  if (wrapper.impl()) {
-    // TODO: We are copying between structs that are almost identical here.
-    // Seems kinda wasteful.
-    MediaStreamTable pc_stream_table;
-    memset(&pc_stream_table, 0, sizeof(pc_stream_table));
-    pc_stream_table.media_stream_id = sipcc_stream_table->media_stream_id;
-
-    // TODO: This was hard-coded to 1 before, is this safe?
-    pc_stream_table.num_tracks = sipcc_stream_table->num_tracks;
-    for (size_t i = 0; i < pc_stream_table.num_tracks; ++i) {
-      pc_stream_table.track[i].media_stream_track_id =
-        sipcc_stream_table->track[i].media_stream_track_id;
-      // TODO: This was hard-coded to false before, do we even need this member?
-      pc_stream_table.track[i].video = sipcc_stream_table->track[i].video;
-    }
-
-    wrapper.impl()->OnRemoteStreamAdded(pc_stream_table);
-  }
-}
-
-/**
- *  start rx stream
- *  Same concept as vcmRxStart but for ICE/PeerConnection-based flows
- *
- *  @param[in]   mcap_id      - media cap id
- *  @param[in]   group_id     - group identifier to which the stream belongs
- *  @param[in]   stream_id    - stream id of the given media type.
- *  @param[in]   level        - the m-line index
- *  @param[in]   pc_stream_id - the media stream index (from PC.addStream())
- *  @param[in]   pc_track_id  - the track within the media stream
- *  @param[in]   call_handle  - call handle
- *  @param[in]   peerconnection - the peerconnection in use
- *  @param[in]   num_payloads   - number of negotiated payloads
- *  @param[in]   payloads       - negotiated codec details list
- *  @param[in]   setup          - whether playing client or server role
- *  @param[in]   fingerprint_alg - the DTLS fingerprint algorithm
- *  @param[in]   fingerprint  - the DTLS fingerprint
- *  @param[in]   attrs        - media attributes
- *
- *  Returns: zero(0) for success; otherwise, ERROR for failure
- */
-
-int vcmRxStartICE(cc_mcapid_t mcap_id,
-                  cc_groupid_t group_id,
-                  cc_streamid_t stream_id,
-                  int level,
-                  int pc_stream_id,
-                  int pc_track_id,
-                  cc_call_handle_t  call_handle,
-                  const char *peerconnection,
-                  int num_payloads,
-                  const vcm_payload_info_t* payloads,
-                  sdp_setup_type_e setup_type,
-                  const char *fingerprint_alg,
-                  const char *fingerprint,
-                  vcm_mediaAttrs_t *attrs)
-{
-  ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-  CSFLogDebug( logTag, "%s(%s) track = %d, stream = %d, level = %d",
-              __FUNCTION__,
-              peerconnection,
-              pc_track_id,
-              pc_stream_id,
-              level);
-
-  // Find the PC.
-  sipcc::PeerConnectionWrapper pc(peerconnection);
-  ENSURE_PC(pc, VCM_ERROR);
-
-  // Datachannel will use this though not for RTP
-  mozilla::RefPtr<TransportFlow> rtp_flow =
-    vcmCreateTransportFlow(pc.impl(), level, false, setup_type,
-                           fingerprint_alg, fingerprint);
-  if (!rtp_flow) {
-    CSFLogError( logTag, "Could not create RTP flow");
-    return VCM_ERROR;
-  }
-
-  if (CC_IS_DATACHANNEL(mcap_id)) {
-    // That's all we need for DataChannels - a flow registered
-    CSFLogDebug( logTag, "%s success", __FUNCTION__);
-    return 0;
-  }
-
-  if (!payloads) {
-    CSFLogError( logTag, "Unitialized payload list");
-    return VCM_ERROR;
-  }
-
-  // Find the stream we need
-  nsRefPtr<sipcc::RemoteSourceStreamInfo> stream =
-    pc.impl()->media()->GetRemoteStream(pc_stream_id);
-  if (!stream) {
-    // This should never happen
-    PR_ASSERT(PR_FALSE);
-    return VCM_ERROR;
-  }
-
-  mozilla::RefPtr<TransportFlow> rtcp_flow = nullptr;
-  if (!attrs->rtcp_mux) {
-    rtcp_flow = vcmCreateTransportFlow(pc.impl(), level, true, setup_type,
-                                       fingerprint_alg, fingerprint);
-    if (!rtcp_flow) {
-      CSFLogError( logTag, "Could not create RTCP flow");
-      return VCM_ERROR;
-    }
-  }
-
-  // If we're offering bundle, a given MediaPipeline could receive traffic on
-  // two different network flows depending on whether the answerer accepts,
-  // before any answer comes in. We need to be prepared for both cases.
-  nsAutoPtr<mozilla::MediaPipelineFilter> filter;
-  RefPtr<TransportFlow> bundle_rtp_flow;
-  RefPtr<TransportFlow> bundle_rtcp_flow;
-  if (attrs->bundle_level) {
-    filter = new MediaPipelineFilter;
-    // Record our correlator, if present in our offer.
-    filter->SetCorrelator(attrs->bundle_stream_correlator);
-
-    // Record our own ssrcs (these are _not_ those of the remote end; that
-    // is handled in vcmTxStart)
-    for (int s = 0; s < attrs->num_ssrcs; ++s) {
-      filter->AddLocalSSRC(attrs->ssrcs[s]);
-    }
-
-    // Record the unique payload types
-    for (int p = 0; p < attrs->num_unique_payload_types; ++p) {
-      filter->AddUniquePT(attrs->unique_payload_types[p]);
-    }
-
-    // Do not pass additional TransportFlows if the pipeline will use the same
-    // flow regardless of whether bundle happens or not.
-    if (attrs->bundle_level != (unsigned int)level) {
-      // This might end up creating it, or might reuse it.
-      mozilla::RefPtr<TransportFlow> bundle_rtp_flow =
-        vcmCreateTransportFlow(pc.impl(),
-                               attrs->bundle_level,
-                               false,
-                               setup_type,
-                               fingerprint_alg,
-                               fingerprint);
-
-      if (!bundle_rtp_flow) {
-        CSFLogError( logTag, "Could not create bundle RTP flow");
-        return VCM_ERROR;
-      }
-
-      if (!attrs->rtcp_mux) {
-        bundle_rtcp_flow = vcmCreateTransportFlow(pc.impl(),
-                                                  attrs->bundle_level,
-                                                  true,
-                                                  setup_type,
-                                                  fingerprint_alg,
-                                                  fingerprint);
-        if (!bundle_rtcp_flow) {
-          CSFLogError( logTag, "Could not create bundle RTCP flow");
-          return VCM_ERROR;
-        }
-      }
-    }
-  }
-
-  if (CC_IS_AUDIO(mcap_id)) {
-    std::vector<mozilla::AudioCodecConfig *> configs;
-
-    // Instantiate an appropriate conduit
-    mozilla::RefPtr<mozilla::MediaSessionConduit> tx_conduit =
-      pc.impl()->media()->GetConduit(level, false);
-    MOZ_ASSERT_IF(tx_conduit, tx_conduit->type() == MediaSessionConduit::AUDIO);
-
-    // The two sides of a send/receive pair of conduits each keep a raw pointer to the other,
-    // and are responsible for cleanly shutting down.
-    mozilla::RefPtr<mozilla::AudioSessionConduit> conduit =
-      mozilla::AudioSessionConduit::Create(static_cast<AudioSessionConduit *>(tx_conduit.get()));
-    if(!conduit)
-      return VCM_ERROR;
-
-    pc.impl()->media()->AddConduit(level, true, conduit);
-
-    mozilla::AudioCodecConfig *config_raw;
-
-    for(int i=0; i <num_payloads ; i++)
-    {
-      config_raw = new mozilla::AudioCodecConfig(
-        payloads[i].local_rtp_pt,
-        ccsdpCodecName(payloads[i].codec_type),
-        payloads[i].audio.frequency,
-        payloads[i].audio.packet_size,
-        payloads[i].audio.channels,
-        payloads[i].audio.bitrate);
-      configs.push_back(config_raw);
-    }
-
-    auto error = conduit->ConfigureRecvMediaCodecs(configs);
-
-    // Would be nice to use a smart container, but we'd need to change
-    // a lot of code.
-    for (auto it = configs.begin(); it != configs.end(); ++it) {
-      delete *it;
-    }
-
-    if (error) {
-      return VCM_ERROR;
-    }
-
-    // Now we have all the pieces, create the pipeline
-    mozilla::RefPtr<mozilla::MediaPipelineReceiveAudio> pipeline =
-      new mozilla::MediaPipelineReceiveAudio(
-        pc.impl()->GetHandle(),
-        pc.impl()->GetMainThread().get(),
-        pc.impl()->GetSTSThread(),
-        stream->GetMediaStream()->GetStream(),
-        pc_track_id,
-        level,
-        conduit,
-        rtp_flow,
-        rtcp_flow,
-        bundle_rtp_flow,
-        bundle_rtcp_flow,
-        filter);
-
-    nsresult res = pipeline->Init();
-    if (NS_FAILED(res)) {
-      CSFLogError(logTag, "Failure initializing audio pipeline");
-      return VCM_ERROR;
-    }
-
-    CSFLogDebug(logTag, "Created audio pipeline %p, conduit=%p, pc_stream=%d pc_track=%d",
-                pipeline.get(), conduit.get(), pc_stream_id, pc_track_id);
-
-    stream->StorePipeline(pc_track_id, false, pipeline);
-  } else if (CC_IS_VIDEO(mcap_id)) {
-
-    std::vector<mozilla::VideoCodecConfig *> configs;
-    // Instantiate an appropriate conduit
-    mozilla::RefPtr<mozilla::MediaSessionConduit> tx_conduit =
-      pc.impl()->media()->GetConduit(level, false);
-    MOZ_ASSERT_IF(tx_conduit, tx_conduit->type() == MediaSessionConduit::VIDEO);
-
-    // The two sides of a send/receive pair of conduits each keep a raw pointer to the other,
-    // and are responsible for cleanly shutting down.
-    mozilla::RefPtr<mozilla::VideoSessionConduit> conduit =
-      mozilla::VideoSessionConduit::Create(static_cast<VideoSessionConduit *>(tx_conduit.get()));
-    if(!conduit)
-      return VCM_ERROR;
-
-    pc.impl()->media()->AddConduit(level, true, conduit);
-
-    mozilla::VideoCodecConfig *config_raw;
-
-    for(int i=0; i <num_payloads; i++)
-    {
-      config_raw = new mozilla::VideoCodecConfig(
-        payloads[i].local_rtp_pt,
-        ccsdpCodecName(payloads[i].codec_type),
-        payloads[i].video.rtcp_fb_types);
-      if (vcmEnsureExternalCodec(conduit, config_raw, false)) {
-        delete config_raw;
-        continue;
-      }
-      configs.push_back(config_raw);
-    }
-
-    auto error = conduit->ConfigureRecvMediaCodecs(configs);
-
-    // Would be nice to use a smart container, but we'd need to change
-    // a lot of code.
-    for (auto it = configs.begin(); it != configs.end(); ++it) {
-      delete *it;
-    }
-
-    if (error) {
-      return VCM_ERROR;
-    }
-
-    // Now we have all the pieces, create the pipeline
-    mozilla::RefPtr<mozilla::MediaPipelineReceiveVideo> pipeline =
-        new mozilla::MediaPipelineReceiveVideo(
-            pc.impl()->GetHandle(),
-            pc.impl()->GetMainThread().get(),
-            pc.impl()->GetSTSThread(),
-            stream->GetMediaStream()->GetStream(),
-            pc_track_id,
-            level,
-            conduit,
-            rtp_flow,
-            rtcp_flow,
-            bundle_rtp_flow,
-            bundle_rtcp_flow,
-            filter);
-
-    nsresult res = pipeline->Init();
-    if (NS_FAILED(res)) {
-      CSFLogError(logTag, "Failure initializing video pipeline");
-      return VCM_ERROR;
-    }
-
-    CSFLogDebug(logTag, "Created video pipeline %p, conduit=%p, pc_stream=%d pc_track=%d",
-                pipeline.get(), conduit.get(), pc_stream_id, pc_track_id);
-
-    stream->StorePipeline(pc_track_id, true, pipeline);
-  } else {
-    CSFLogError(logTag, "%s: mcap_id unrecognized", __FUNCTION__);
-    return VCM_ERROR;
-  }
-
-  CSFLogDebug( logTag, "%s success", __FUNCTION__);
-  return 0;
-}
-
-/**
- *  Close the receive stream.
- *
- *  @param[in]    mcap_id - Media Capability ID
- *  @param[in]    group_id - group identifier that belongs to the stream.
- *  @param[in]    stream_id - stream id of the given media type.
- *  @param[in]    call_handle  - call identifier
- *
- *  @return 0 for success; VCM_ERROR for failure
- *
- */
-
-short vcmRxClose(cc_mcapid_t mcap_id,
-                 cc_groupid_t group_id,
-                 cc_streamid_t stream_id,
-                 cc_call_handle_t  call_handle)
-{
-    ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-    char fname[] = "vcmRxClose";
-
-    CSFLogDebug( logTag, "%s: group_id=%d call_handle=%d", fname, group_id, call_handle);
-
-    if (call_handle == CC_NO_CALL_ID) {
-        CSFLogDebug( logTag, "No CALL ID");
-        /* no operation when no call ID */
-        return VCM_ERROR;
-    }
-    switch ( mcap_id )
-    {
-    case CC_AUDIO_1:
-        if ( VcmSIPCCBinding::getAudioTermination() != nullptr )
-            VcmSIPCCBinding::getAudioTermination()->rxClose( group_id, stream_id );
-        break;
-
-    case CC_VIDEO_1:
-        if ( VcmSIPCCBinding::getVideoTermination() != nullptr )
-            VcmSIPCCBinding::getVideoTermination()->rxClose( group_id, stream_id );
-        break;
-
-    default:
-        break;
-    }
-    return 0;
-}
-
-/**
- *  Release the allocated port
- * @param[in] mcap_id   - media capability id (0 is audio)
- * @param[in] group_id  - group identifier
- * @param[in] stream_id - stream identifier
- * @param[in] call_handle   - call id
- * @param[in] port     - port to be released
- *
- * @return void
- */
-
-void vcmRxReleasePort  (cc_mcapid_t mcap_id,
-                        cc_groupid_t group_id,
-                        cc_streamid_t stream_id,
-                        cc_call_handle_t  call_handle,
-                        int port)
-{
-    ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-    CSFLogDebug( logTag, "vcmRxReleasePort(): group_id=%d stream_id=%d call_handle=%d port=%d",
-                      group_id, stream_id, call_handle, port);
-
-    if(CC_IS_AUDIO(mcap_id))
-    {
-        if ( VcmSIPCCBinding::getAudioTermination() != nullptr )
-            VcmSIPCCBinding::getAudioTermination()->rxRelease( group_id, stream_id, port );
-    }
-    else if(CC_IS_VIDEO(mcap_id))
-    {
-        if ( VcmSIPCCBinding::getVideoTermination() != nullptr )
-           VcmSIPCCBinding::getVideoTermination()->rxRelease( group_id, stream_id, port );
-    }
-
-    StreamObserver* obs = VcmSIPCCBinding::getStreamObserver();
-    if(obs != nullptr)
-        obs->deregisterStream(call_handle, stream_id);
-}
-
-/*
- *  Function:map_tone_type
- *
- *  Description: Convert to corresponding JPhone tone.
- *
- *  Parameters:  tone - vcm tone
- *
- *  Returns:     Mapped tone type
- *
- */
-static ToneType
-map_tone_type( vcm_tones_t tone )
-{
-    switch ( tone )
-    {
-    case VCM_INSIDE_DIAL_TONE:
-        return ToneType_INSIDE_DIAL_TONE;
-    case VCM_OUTSIDE_DIAL_TONE:
-        return ToneType_OUTSIDE_DIAL_TONE;
-    case VCM_LINE_BUSY_TONE:
-        return ToneType_LINE_BUSY_TONE;
-    case VCM_ALERTING_TONE:
-        return ToneType_ALERTING_TONE;
-    case VCM_BUSY_VERIFY_TONE:
-        return ToneType_BUSY_VERIFY_TONE;
-    case VCM_STUTTER_TONE:
-        return ToneType_STUTTER_TONE;
-    case VCM_MSG_WAITING_TONE:
-        return ToneType_MSG_WAITING_TONE;
-    case VCM_REORDER_TONE:
-        return ToneType_REORDER_TONE;
-    case VCM_CALL_WAITING_TONE:
-        return ToneType_CALL_WAITING_TONE;
-    case VCM_CALL_WAITING_2_TONE:
-        return ToneType_CALL_WAITING_2_TONE;
-    case VCM_CALL_WAITING_3_TONE:
-        return ToneType_CALL_WAITING_3_TONE;
-    case VCM_CALL_WAITING_4_TONE:
-        return ToneType_CALL_WAITING_4_TONE;
-    case VCM_HOLD_TONE:
-        return ToneType_HOLD_TONE;
-    case VCM_CONFIRMATION_TONE:
-        return ToneType_CONFIRMATION_TONE;
-    case VCM_PERMANENT_SIGNAL_TONE:
-        return ToneType_PERMANENT_SIGNAL_TONE;
-    case VCM_REMINDER_RING_TONE:
-        return ToneType_REMINDER_RING_TONE;
-    case VCM_NO_TONE:
-        return ToneType_NO_TONE;
-    case VCM_ZIP_ZIP:
-        return ToneType_ZIP_ZIP;
-    case VCM_ZIP:
-        return ToneType_ZIP;
-    case VCM_BEEP_BONK:
-        return ToneType_BEEP_BONK;
-    case VCM_RECORDERWARNING_TONE:
-        return ToneType_RECORDERWARNING_TONE;
-    case VCM_RECORDERDETECTED_TONE:
-        return ToneType_RECORDERDETECTED_TONE;
-    case VCM_MONITORWARNING_TONE:
-        return ToneType_MONITORWARNING_TONE;
-    case VCM_SECUREWARNING_TONE:
-        return ToneType_SECUREWARNING_TONE;
-    default:
-        CSFLogDebug( logTag, "map_tone_type(): WARNING..tone type not mapped.");
-        return ToneType_NO_TONE;
-    }
-}
-
-/**
- *  Start a tone (continuous)
- *
- *  Parameters:
- *  @param[in] tone       - tone type
- *  @param[in] alert_info - alertinfo header
- *  @param[in] call_handle    - call identifier
- *  @param[in] group_id - identifier of the group to which stream belongs
- *  @param[in] stream_id   - stream identifier.
- *  @param[in] direction  - network, speaker, both
- *
- *  @return void
- *
- */
-
-void vcmToneStart(vcm_tones_t tone,
-                  short alert_info,
-                  cc_call_handle_t  call_handle,
-                  cc_groupid_t group_id,
-                  cc_streamid_t stream_id,
-                  cc_uint16_t direction)
-{
-    ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-    const char fname[] = "vcmToneStart";
-
-    CSFLogDebug( logTag, "%s:tone=%d call_handle=%d dir=%d", fname, tone, call_handle, direction);
-
-    VcmSIPCCBinding::getAudioTermination()->toneStart( map_tone_type(tone), (ToneDirection)direction,
-                                alert_info, group_id, stream_id, FALSE );
-    /*
-     * Set delay value for multi-part tones and repeated tones.
-     * Currently the only multi-part tones are stutter and message
-     * waiting tones. The only repeated tones are call waiting and
-     * tone on hold tones.  If the DSP ever supports stutter and
-     * message waiting tones, these tones can be removed from this
-     * switch statement.
-     */
-
-    /*
-    switch ( tone )
-    {
-    case VCM_MSG_WAITING_TONE:
-        lsm_start_multipart_tone_timer(tone, MSG_WAITING_DELAY, call_handle);
-        break;
-
-    case VCM_HOLD_TONE:
-        lsm_start_continuous_tone_timer(tone, TOH_DELAY, call_handle);
-        break;
-
-    default:
-        break;
-    }
-    */
-
-    /*
-     * Update dcb->active_tone if start request
-     * is for an infinite duration tone.
-     */
-    //lsm_update_active_tone(tone, call_handle);
-}
-
-/**
- * Plays a short tone. uses the open audio path.
- * If no audio path is open, plays on speaker.
- *
- * @param[in] tone       - tone type
- * @param[in] alert_info - alertinfo header
- * @param[in] call_handle    - call identifier
- * @param[in] group_id - identifier of the group to which stream belongs
- * @param[in] stream_id   - stream identifier.
- * @param[in] direction  - network, speaker, both
- *
- * @return void
- */
-
-void vcmToneStartWithSpeakerAsBackup(vcm_tones_t tone,
-                                     short alert_info,
-                                     cc_call_handle_t  call_handle,
-                                     cc_groupid_t group_id,
-                                     cc_streamid_t stream_id,
-                                     cc_uint16_t direction)
-{
-    ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-    const char fname[] = "vcmToneStartWithSpeakerAsBackup";
-
-    CSFLogDebug( logTag, "%s:tone=%d call_handle=%d dir=%d", fname, tone, call_handle, direction);
-
-    VcmSIPCCBinding::getAudioTermination()->toneStart( map_tone_type(tone), (ToneDirection)direction,
-                                alert_info, group_id, stream_id, TRUE );
-    /*
-     * Update dcb->active_tone if start request
-     * is for an infinite duration tone.
-     */
-    //lsm_update_active_tone(tone, call_handle);
-}
-
-/**
- *  Stop the tone being played.
- *
- *  Description: Stop the tone being played currently
- *
- *
- * @param[in] tone - tone to be stopeed
- * @param[in] group_id - associated stream's group
- * @param[in] stream_id - associated stream id
- * @param[in] call_handle - the context (call) for this tone.
- *
- * @return void
- *
- */
-
-void vcmToneStop(vcm_tones_t tone,
-                 cc_groupid_t group_id,
-                 cc_streamid_t stream_id,
-                 cc_call_handle_t call_handle)
-{
-    ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-    const char fname[] = "vcmToneStop";
-
-    CSFLogDebug( logTag, "%s:tone=%d stream_id=%d", fname, tone, stream_id);
-/*
-    lsm_stop_multipart_tone_timer();
-    lsm_stop_continuous_tone_timer();
-    */
-
-    VcmSIPCCBinding::getAudioTermination()->toneStop( map_tone_type(tone), group_id, stream_id );
-}
-
-/**
- *  should we remove from external API
- *
- *  @param[in]  mcap_id - Media Capability ID
- *  @param[in]  group_id - group to which stream belongs
- *  @param[in]  stream_id - stream identifier
- *  @param[in]  call_handle - call identifier
- *
- *  @return  zero(0) for success; otherwise, ERROR for failure
- *
- */
-
-short vcmTxOpen(cc_mcapid_t mcap_id,
-                cc_groupid_t group_id,
-                cc_streamid_t stream_id,
-                cc_call_handle_t call_handle)
-{
-    ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-    char        fname[] = "vcmTxOpen";
-
-    CSFLogDebug( logTag, "%s: group_id=%d call_handle=%d", fname, group_id, call_handle);
-
-    if (call_handle == CC_NO_CALL_ID) {
-        /* no operation when no call ID */
-        return VCM_ERROR;
-    }
-    return 0;
-}
-
-/*
- * Add external H.264 video codec.
- */
-static int vcmEnsureExternalCodec(
-    const mozilla::RefPtr<mozilla::VideoSessionConduit>& conduit,
-    mozilla::VideoCodecConfig* config,
-    bool send)
-{
-  if (config->mName == "VP8") {
-    // whitelist internal codecs; I420 will be here once we resolve bug 995884
-    return 0;
-  } else if (config->mName == "H264_P0" || config->mName == "H264_P1") {
-    // Here we use "I420" to register H.264 because WebRTC.org code has a
-    // whitelist of supported video codec in |webrtc::ViECodecImpl::CodecValid()|
-    // and will reject registration of those not in it.
-    // TODO: bug 995884 to support H.264 in WebRTC.org code.
-
-    // Register H.264 codec.
-    if (send) {
-      VideoEncoder* encoder = nullptr;
-#ifdef MOZ_WEBRTC_OMX
-      encoder = OMXVideoCodec::CreateEncoder(OMXVideoCodec::CodecType::CODEC_H264);
-#else
-      encoder = mozilla::GmpVideoCodec::CreateEncoder();
-#endif
-      if (encoder) {
-        return conduit->SetExternalSendCodec(config, encoder);
-      } else {
-        return kMediaConduitInvalidSendCodec;
-      }
-    } else {
-      VideoDecoder* decoder;
-#ifdef MOZ_WEBRTC_OMX
-      decoder = OMXVideoCodec::CreateDecoder(OMXVideoCodec::CodecType::CODEC_H264);
-#else
-      decoder = mozilla::GmpVideoCodec::CreateDecoder();
-#endif
-      if (decoder) {
-        return conduit->SetExternalRecvCodec(config, decoder);
-      } else {
-        return kMediaConduitInvalidReceiveCodec;
-      }
-    }
-    NS_NOTREACHED("Shouldn't get here!");
-  } else {
-    CSFLogError( logTag, "%s: Invalid video codec configured: %s", __FUNCTION__, config->mName.c_str());
-    return send ? kMediaConduitInvalidSendCodec : kMediaConduitInvalidReceiveCodec;
-  }
-
-  return 0;
-}
-
-/**
- *  start tx stream
- *  Note: For video calls, for a given call_handle there will be
- *        two media lines and the corresponding group_id/stream_id pair.
- *        One RTP session is requested from media server for each
- *        media line(group/stream) i.e. a video call would result in
- *        two rtp_sessions in our session info list created by two
- *        calls to vcm_rx/tx with mcap_id of AUDIO and VIDEO respectively.
- *
- *  @param[in]   mcap_id      - media cap id
- *  @param[in]   group_id     - group identifier to which the stream belongs
- *  @param[in]   stream_id    - stream id of the given media type.
- *  @param[in]   call_handle      - call identifier
- *  @param[in]   payload      - payload information
- *  @param[in]   tos          - bit marking
- *  @param[in]   local_addr   - local address
- *  @param[in]   local_port   - local port
- *  @param[in]   remote_ip_addr - remote ip address
- *  @param[in]   remote_port  - remote port
- *  @param[in]   algorithmID  - crypto alogrithm ID
- *  @param[in]   tx_key       - tx key used when algorithm ID is encrypting.
- *  @param[in]   attrs        - media attributes
- *
- *  Returns: zero(0) for success; otherwise, ERROR for failure
- *
- */
-int vcmTxStart(cc_mcapid_t mcap_id,
-               cc_groupid_t group_id,
-               cc_streamid_t stream_id,
-               cc_call_handle_t  call_handle,
-               const vcm_payload_info_t *payload,
-               short tos,
-               cpr_ip_addr_t *local_addr,
-               cc_uint16_t local_port,
-               cpr_ip_addr_t *remote_ip_addr,
-               cc_uint16_t remote_port,
-               vcm_crypto_algorithmID algorithmID,
-               vcm_crypto_key_t *tx_key,
-               vcm_mediaAttrs_t *attrs)
-{
-    ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-    const char fname[] = "vcmTxStart";
-    uint8_t    *key;
-    uint8_t    *salt;
-    cc_uint16_t    key_len;
-    cc_uint16_t    salt_len;
-
-    char dottedIP[20];
-    csf_sprintf(dottedIP, sizeof(dottedIP), "%u.%u.%u.%u",
-                (remote_ip_addr->u.ip4 >> 24) & 0xff, (remote_ip_addr->u.ip4 >> 16) & 0xff,
-                (remote_ip_addr->u.ip4 >> 8) & 0xff, remote_ip_addr->u.ip4 & 0xff );
-
-    CSFLogDebug( logTag, "%s: group_id=%d call_handle=%d payload=%d tos=%d local_port=%d remote=%s:%d algID=%d",
-        fname, group_id, call_handle, payload->remote_rtp_pt, tos, local_port,
-        dottedIP, remote_port, algorithmID);
-
-    if (call_handle == CC_NO_CALL_ID) {
-        /* no operation when no call ID */
-        return VCM_ERROR;
-    }
-
-    /* Set up crypto parameters */
-    switch ( algorithmID )
-    {
-    case VCM_AES_128_COUNTER:
-        if ( tx_key == nullptr )
-        {
-            /* No key provided */
-            CSFLogDebug( logTag, "%s: No key for algorithm ID %d", fname, algorithmID);
-            return VCM_ERROR;
-        }
-        /* Set up key and Salt parameters */
-        key_len  = tx_key->key_len;
-        key      = &tx_key->key[0];
-        salt_len = tx_key->salt_len;
-        salt     = &tx_key->salt[0];
-        break;
-
-    default:
-        /* Give dummy data to avoid passing nullptr for key/salt */
-        key_len  = 0;
-        key      = (uint8_t *)"";
-        salt_len = 0;
-        salt     = (uint8_t *)"";
-        break;
-    }
-
-    switch ( mcap_id )
-    {
-    case CC_AUDIO_1:
-        if ( VcmSIPCCBinding::getAudioTermination() != nullptr )
-            return VcmSIPCCBinding::getAudioTermination()->txStart(
-                group_id, stream_id, payload->remote_rtp_pt,
-                attrs->audio.packetization_period, (attrs->audio.vad != 0),
-                tos, dottedIP, remote_port, attrs->audio.avt_payload_type,
-                map_algorithmID(algorithmID), key, key_len, salt, salt_len,
-                attrs->audio.mixing_mode, attrs->audio.mixing_party );
-
-        break;
-
-    case CC_VIDEO_1:
-        if ( VcmSIPCCBinding::getVideoTermination() != nullptr )
-           return VcmSIPCCBinding::getVideoTermination()->txStart(
-              group_id, stream_id, payload->remote_rtp_pt,
-              0, 0, tos, dottedIP, remote_port, 0,
-              map_algorithmID(algorithmID), key, key_len, salt, salt_len, 0, 0);
-        break;
-
-    default:
-        break;
-    }
-    return VCM_ERROR;
-}
-
-/**
- * Create a conduit for audio transmission.
- *
- *  @param[in]   level        - the m-line index
- *  @param[in]   payload      - codec info
- *  @param[in]   pc           - the peer connection
- *  @param [in]  attrs        - additional audio attributes
- *  @param[out]  conduit      - the conduit to create
- */
-static int vcmTxCreateAudioConduit(int level,
-                                   const vcm_payload_info_t *payload,
-                                   sipcc::PeerConnectionWrapper &pc,
-                                   const vcm_mediaAttrs_t *attrs,
-                                   mozilla::RefPtr<mozilla::MediaSessionConduit> &conduit)
-{
-  mozilla::AudioCodecConfig *config_raw =
-    new mozilla::AudioCodecConfig(
-      payload->remote_rtp_pt,
-      ccsdpCodecName(payload->codec_type),
-      payload->audio.frequency,
-      payload->audio.packet_size,
-      payload->audio.channels,
-      payload->audio.bitrate);
-
-  // Take possession of this pointer
-  mozilla::ScopedDeletePtr<mozilla::AudioCodecConfig> config(config_raw);
-
-  // Instantiate an appropriate conduit
-  mozilla::RefPtr<mozilla::MediaSessionConduit> rx_conduit =
-    pc.impl()->media()->GetConduit(level, true);
-  MOZ_ASSERT_IF(rx_conduit, rx_conduit->type() == MediaSessionConduit::AUDIO);
-
-  // The two sides of a send/receive pair of conduits each keep a raw pointer to the other,
-  // and are responsible for cleanly shutting down.
-  mozilla::RefPtr<mozilla::AudioSessionConduit> tx_conduit =
-    mozilla::AudioSessionConduit::Create(
-      static_cast<AudioSessionConduit *>(rx_conduit.get()));
-
-  if (!tx_conduit || tx_conduit->ConfigureSendMediaCodec(config) ||
-      tx_conduit->EnableAudioLevelExtension(attrs->audio_level,
-                                            attrs->audio_level_id)) {
-    return VCM_ERROR;
-  }
-  CSFLogError(logTag, "Created audio pipeline audio level %d %d",
-              attrs->audio_level, attrs->audio_level_id);
-
-  conduit = tx_conduit;
-  return 0;
-}
-
-/**
- * Create a conduit for video transmission.
- *
- *  @param[in]   level        - the m-line index
- *  @param[in]   payload      - codec info
- *  @param[in]   pc           - the peer connection
- *  @param[out]  conduit      - the conduit to create
- */
-static int vcmTxCreateVideoConduit(int level,
-                                   const vcm_payload_info_t *payload,
-                                   sipcc::PeerConnectionWrapper &pc,
-                                   const vcm_mediaAttrs_t *attrs,
-                                   mozilla::RefPtr<mozilla::MediaSessionConduit> &conduit)
-{
-  mozilla::VideoCodecConfig *config_raw;
-  struct VideoCodecConfigH264 *negotiated = nullptr;
-
-  if (attrs->video.opaque &&
-      (payload->codec_type == RTP_H264_P0 || payload->codec_type == RTP_H264_P1)) {
-    negotiated = static_cast<struct VideoCodecConfigH264 *>(attrs->video.opaque);
-  }
-
-  config_raw = new mozilla::VideoCodecConfig(
-    payload->remote_rtp_pt,
-    ccsdpCodecName(payload->codec_type),
-    payload->video.rtcp_fb_types,
-    payload->video.max_fs,
-    payload->video.max_fr,
-    negotiated);
-
-  // Take possession of this pointer
-  mozilla::ScopedDeletePtr<mozilla::VideoCodecConfig> config(config_raw);
-
-  // Instantiate an appropriate conduit
-  mozilla::RefPtr<mozilla::MediaSessionConduit> rx_conduit =
-    pc.impl()->media()->GetConduit(level, true);
-  MOZ_ASSERT_IF(rx_conduit, rx_conduit->type() == MediaSessionConduit::VIDEO);
-
-  // The two sides of a send/receive pair of conduits each keep a raw pointer to the other,
-  // and are responsible for cleanly shutting down.
-  mozilla::RefPtr<mozilla::VideoSessionConduit> tx_conduit =
-    mozilla::VideoSessionConduit::Create(static_cast<VideoSessionConduit *>(rx_conduit.get()));
-  if (!tx_conduit) {
-    return VCM_ERROR;
-  }
-  if (vcmEnsureExternalCodec(tx_conduit, config, true)) {
-    return VCM_ERROR;
-  }
-  if (tx_conduit->ConfigureSendMediaCodec(config)) {
-    return VCM_ERROR;
-  }
-  conduit = tx_conduit;
-  return 0;
-}
-
-/**
- *  start tx stream
- *  Same concept as vcmTxStart but for ICE/PeerConnection-based flows
- *
- *  @param[in]   mcap_id      - media cap id
- *  @param[in]   group_id     - group identifier to which the stream belongs
- *  @param[in]   stream_id    - stream id of the given media type.
- *  @param[in]   level        - the m-line index
- *  @param[in]   pc_stream_id - the media stream index (from PC.addStream())
- *  @param[in]   pc_track_id  - the track within the media stream
- *  @param[in]   call_handle  - call handle
- *  @param[in]   peerconnection - the peerconnection in use
- *  @param[in]   payload      - payload information
- *  @param[in]   tos          - bit marking
- *  @param[in]   setup_type   - whether playing the client or server role
- *  @param[in]   fingerprint_alg - the DTLS fingerprint algorithm
- *  @param[in]   fingerprint  - the DTLS fingerprint
- *  @param[in]   attrs        - media attributes
- *
- *  Returns: zero(0) for success; otherwise, ERROR for failure
- *
- */
-#define EXTRACT_DYNAMIC_PAYLOAD_TYPE(PTYPE) ((PTYPE)>>16)
-
-int vcmTxStartICE(cc_mcapid_t mcap_id,
-                  cc_groupid_t group_id,
-                  cc_streamid_t stream_id,
-                  int level,
-                  int pc_stream_id,
-                  int pc_track_id,
-                  cc_call_handle_t  call_handle,
-                  const char *peerconnection,
-                  const vcm_payload_info_t *payload,
-                  short tos,
-                  sdp_setup_type_e setup_type,
-                  const char *fingerprint_alg,
-                  const char *fingerprint,
-                  vcm_mediaAttrs_t *attrs)
-{
-  ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-  CSFLogDebug(logTag, "%s(%s) track = %d, stream = %d, level = %d",
-              __FUNCTION__,
-              peerconnection,
-              pc_track_id,
-              pc_stream_id,
-              level);
-
-  // Find the PC and get the stream
-  sipcc::PeerConnectionWrapper pc(peerconnection);
-  ENSURE_PC(pc, VCM_ERROR);
-  nsRefPtr<sipcc::LocalSourceStreamInfo> stream =
-    pc.impl()->media()->GetLocalStream(pc_stream_id);
-  if (!stream) {
-    CSFLogError(logTag, "Stream not found");
-    return VCM_ERROR;
-  }
-
-  // Create the transport flows
-  mozilla::RefPtr<TransportFlow> rtp_flow =
-    vcmCreateTransportFlow(pc.impl(), level, false, setup_type,
-                           fingerprint_alg, fingerprint);
-  if (!rtp_flow) {
-    CSFLogError(logTag, "Could not create RTP flow");
-    return VCM_ERROR;
-  }
-
-  mozilla::RefPtr<TransportFlow> rtcp_flow = nullptr;
-  if (!attrs->rtcp_mux) {
-    rtcp_flow = vcmCreateTransportFlow(pc.impl(), level, true, setup_type,
-                                       fingerprint_alg, fingerprint);
-    if (!rtcp_flow) {
-      CSFLogError( logTag, "Could not create RTCP flow");
-      return VCM_ERROR;
-    }
-  }
-
-  const char *mediaType;
-  mozilla::RefPtr<mozilla::MediaSessionConduit> conduit;
-  int err = VCM_ERROR;
-  bool is_video;
-  if (CC_IS_AUDIO(mcap_id)) {
-    mediaType = "audio";
-    err = vcmTxCreateAudioConduit(level, payload, pc, attrs, conduit);
-    is_video = false;
-  } else if (CC_IS_VIDEO(mcap_id)) {
-    mediaType = "video";
-    err = vcmTxCreateVideoConduit(level, payload, pc, attrs, conduit);
-    is_video = true;
-  } else {
-    mediaType = "unrecognized";
-    CSFLogError(logTag, "%s: mcap_id unrecognized", __FUNCTION__);
-  }
-  if (err) {
-    CSFLogError(logTag, "%s: failed to create %s conduit", __FUNCTION__, mediaType);
-    return err;
-  }
-
-  pc.impl()->media()->AddConduit(level, false, conduit);
-
-  // Now we have all the pieces, create the pipeline
-  mozilla::RefPtr<mozilla::MediaPipelineTransmit> pipeline =
-    new mozilla::MediaPipelineTransmit(
-      pc.impl()->GetHandle(),
-      pc.impl()->GetMainThread().get(),
-      pc.impl()->GetSTSThread(),
-      stream->GetMediaStream(),
-      pc_track_id,
-      level,
-      is_video,
-      conduit, rtp_flow, rtcp_flow);
-
-  nsresult res = pipeline->Init();
-  if (NS_FAILED(res)) {
-    CSFLogError(logTag, "Failure initializing %s pipeline", mediaType);
-    return VCM_ERROR;
-  }
-#ifdef MOZILLA_INTERNAL_API
-  // implement checking for peerIdentity (where failure == black/silence)
-  nsIDocument* doc = pc.impl()->GetWindow()->GetExtantDoc();
-  if (doc) {
-    pipeline->UpdateSinkIdentity_m(doc->NodePrincipal(), pc.impl()->GetPeerIdentity());
-  } else {
-    CSFLogError(logTag, "Initializing pipeline without attached doc");
-  }
-#endif
-
-  CSFLogDebug(logTag,
-              "Created %s pipeline %p, conduit=%p, pc_stream=%d pc_track=%d",
-              mediaType, pipeline.get(), conduit.get(),
-              pc_stream_id, pc_track_id);
-  stream->StorePipeline(pc_track_id, pipeline);
-
-  // This tells the receive MediaPipeline (if there is one) whether we are
-  // doing bundle, and if so, updates the filter. Once the filter is finalized,
-  // it is then copied to the transmit pipeline so it can filter RTCP.
-  if (attrs->bundle_level) {
-    nsAutoPtr<mozilla::MediaPipelineFilter> filter (new MediaPipelineFilter);
-    for (int s = 0; s < attrs->num_ssrcs; ++s) {
-      filter->AddRemoteSSRC(attrs->ssrcs[s]);
-    }
-    pc.impl()->media()->SetUsingBundle_m(level, true);
-    pc.impl()->media()->UpdateFilterFromRemoteDescription_m(level, filter);
-  } else {
-    // This will also clear the filter.
-    pc.impl()->media()->SetUsingBundle_m(level, false);
-  }
-
-  CSFLogDebug( logTag, "%s success", __FUNCTION__);
-  return 0;
-}
-
-#define EXTRACT_DYNAMIC_PAYLOAD_TYPE(PTYPE) ((PTYPE)>>16)
-
-/**
- *  Close the transmit stream
- *
- *  @param[in] mcap_id - Media Capability ID
- *  @param[in] group_id - identifier of the group to which stream belongs
- *  @param[in] stream_id - stream id of the given media type.
- *  @param[in] call_handle  - call identifier
- *
- *  @return 0 for success; VCM_ERROR for failure
- */
-
-short vcmTxClose(cc_mcapid_t mcap_id,
-                 cc_groupid_t group_id,
-                 cc_streamid_t stream_id,
-                 cc_call_handle_t  call_handle)
-{
-    ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-    const char fname[] = "vcmTxClose";
-
-    CSFLogDebug( logTag, "%s: group_id=%d call_handle=%d", fname, group_id, call_handle);
-
-    if (call_handle == CC_NO_CALL_ID) {
-        /* no operation when no call ID */
-        return VCM_ERROR;
-    }
-
-    switch ( mcap_id )
-    {
-    case CC_AUDIO_1:
-        if ( VcmSIPCCBinding::getAudioTermination() != nullptr )
-            VcmSIPCCBinding::getAudioTermination()->txClose( group_id, stream_id);
-        break;
-
-    case CC_VIDEO_1:
-        if ( VcmSIPCCBinding::getVideoTermination() != nullptr )
-           VcmSIPCCBinding::getVideoTermination()->txClose( group_id, stream_id);
-        break;
-
-    default:
-        break;
-    }
-    return 0;
-}
-
-#if 0
-static CodecRequestType
-map_codec_request_type( int request_type )
-{
-    switch ( request_type )
-    {
-    default:
-    case cip_sipcc_CodecMask_DSP_IGNORE:     return CodecRequestType_IGNORE;
-    case cip_sipcc_CodecMask_DSP_DECODEONLY: return CodecRequestType_DECODEONLY;
-    case cip_sipcc_CodecMask_DSP_ENCODEONLY: return CodecRequestType_ENCODEONLY;
-    case cip_sipcc_CodecMask_DSP_FULLDUPLEX: return CodecRequestType_FULLDUPLEX;
-    }
-}
-#endif
-
-/**
- * Get current list of audio codec that could be used
- * @param request_type -
- * The request_type should be VCM_DECODEONLY/ENCODEONLY/FULLDUPLEX/IGNORE
- *
- * @return A bit mask should be returned that specifies the list of the audio
- * codecs. The bit mask should conform to the defines in this file.
- * #define VCM_RESOURCE_G711     0x00000001
- * #define VCM_RESOURCE_G729A    0x00000002
- * ....
- */
-
-int vcmGetAudioCodecList(int request_type)
-{
-// Direct access to media layer replaced by locally stored codecMask
-// set in PeerConnectionImpl
-#if 0
-    const char fname[] = "vcmGetAudioCodecList";
-    int retVal;
-    int codecMask = 0;
-
-    CSFLogDebug( logTag, "%s(request_type = %d)", fname, request_type);
-
-    retVal = VcmSIPCCBinding::getAudioTermination() ? VcmSIPCCBinding::getAudioTermination()->getCodecList( map_codec_request_type(request_type) ) : 0;
-
-    if ( retVal & AudioCodecMask_G711 ) {    codecMask |= cip_sipcc_CodecMask_DSP_RESOURCE_G711; CSFLogDebug( logTag, "%s", " G711"); }
-    if ( retVal & AudioCodecMask_LINEAR ) {  codecMask |= cip_sipcc_CodecMask_DSP_RESOURCE_LINEAR; CSFLogDebug( logTag, "%s", " LINEAR" ); }
-    if ( retVal & AudioCodecMask_G722 ) {    codecMask |= cip_sipcc_CodecMask_DSP_RESOURCE_G722; CSFLogDebug( logTag, "%s", " G722"); }
-    if ( retVal & AudioCodecMask_iLBC )  {   codecMask |= cip_sipcc_CodecMask_DSP_RESOURCE_iLBC; CSFLogDebug( logTag, "%s", " iLBC"); }
-    if ( retVal & AudioCodecMask_iSAC )   {  codecMask |= cip_sipcc_CodecMask_DSP_RESOURCE_iSAC; CSFLogDebug( logTag, "%s", " iSAC "); }
-
-    CSFLogDebug( logTag, "%s(codec_mask = %X)", fname, codecMask);
-    return codecMask;
-#else
-  ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-  int codecMask = VcmSIPCCBinding::getAudioCodecs();
-  CSFLogDebug(logTag, "GetAudioCodecList returning %X", codecMask);
-
-  return codecMask;
-#endif
-}
-
-/**
- * Get current list of video codec that could be used
- * @param request_type -
- * The request_type should be VCM_DECODEONLY/ENCODEONLY/FULLDUPLEX/IGNORE
- *
- * @return A bit mask should be returned that specifies the list of the audio
- * codecs. The bit mask should conform to the defines in this file.
- * #define VCM_RESOURCE_G711     0x00000001
- * #define VCM_RESOURCE_G729A    0x00000002
- * ....
- */
-
-#ifndef DSP_H264
-#define DSP_H264        0x00000001
-#endif
-
-#ifndef DSP_H263
-#define DSP_H263        0x00000002
-#endif
-
-int vcmGetVideoCodecList(int request_type)
-{
-// Direct access to media layer replaced by locally stored codecMask
-// set in PeerConnectionImpl
-#if 0
-    const char fname[] = "vcmGetVideoCodecList";
-    int retVal = 0;
-    int codecMask = 0;
-
-    CSFLogDebug( logTag, "%s(request_type = %d)", fname, request_type);
-
-    retVal = VcmSIPCCBinding::getVideoTermination() ? VcmSIPCCBinding::getVideoTermination()->getCodecList( map_codec_request_type(request_type) ) : 0;
-
-    if ( retVal & VideoCodecMask_H264 )    codecMask |= DSP_H264;
-    if ( retVal & VideoCodecMask_H263 )    codecMask |= DSP_H263;
-
-    CSFLogDebug( logTag, "%s(codec_mask = %X)", fname, codecMask);
-
-    //return codecMask;
-    return VCM_CODEC_RESOURCE_H264;
-#else
-  // Control if H264 is available and priority:
-  // If hardware codecs are available (VP8 or H264), use those as a preferred codec
-  // (question: on all platforms?)
-  // If OpenH264 is available, use that at lower priority to VP8
-  // (question: platform software or OS-unknown-impl codecs?  (Win8.x, etc)
-  // Else just use VP8 software
-
-    int codecMask;
-    switch (request_type) {
-      case VCM_DSP_FULLDUPLEX_HW:
-        codecMask = VcmSIPCCBinding::getVideoCodecsHw();
-        break;
-      case VCM_DSP_FULLDUPLEX_GMP:
-        codecMask = VcmSIPCCBinding::getVideoCodecsGmp();
-        break;
-      default: // VCM_DSP_FULLDUPLEX
-        codecMask = VcmSIPCCBinding::getVideoCodecs();
-        break;
-    }
-    CSFLogDebug(logTag, "GetVideoCodecList returning %X", codecMask);
-    return codecMask;
-#endif
-}
-
-/**
- * Get supported H.264 video packetization modes
- * @return mask of supported video packetization modes for H.264. Value returned
- * must be 1 to 3 (bit 0 is mode 0, bit 1 is mode 1.
- * Bit 2 (Mode 2) is not supported yet.
- */
-int vcmGetH264SupportedPacketizationModes()
-{
-#ifdef MOZ_WEBRTC_OMX
-  return VCM_H264_MODE_1;
-#else
-  return VCM_H264_MODE_0|VCM_H264_MODE_1;
-#endif
-}
-
-/**
- * Get supported H.264 profile-level-id
- * @return supported profile-level-id value
- */
-uint32_t vcmGetVideoH264ProfileLevelID()
-{
-  // For OMX, constrained baseline level 1.2 (via a pref)
-  // Max resolution CIF; we should include max-mbps
-  int32_t level = 13; // minimum suggested for WebRTC spec
-
-  vcmGetVideoLevel(0, &level);
-  level &= 0xFF;
-  level |= 0x42E000;
-
-  return (uint32_t) level;
-}
-
-/**
- *  MEDIA control received from far end on signaling path
- *
- *  @param call_handle - call_handle of the call
- *  @param to_encoder - the control request received
- *        Only FAST_PICTURE_UPDATE is supported
- *
- *  @return  void
- *
- */
-
-void vcmMediaControl(cc_call_handle_t  call_handle, vcm_media_control_to_encoder_t to_encoder)
-{
-    ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-    if ( to_encoder == VCM_MEDIA_CONTROL_PICTURE_FAST_UPDATE )
-    {
-        StreamObserver* obs = VcmSIPCCBinding::getStreamObserver();
-        if (obs != nullptr)
-        {
-                obs->sendIFrame(call_handle);
-        }
-    }
-}
-
-/**
- * Get the rx/tx stream statistics associated with the call.
- *
- * @param[in]  mcap_id  - media type (audio/video)
- * @param[in]  group_id - group id of the stream
- * @param[in]  stream_id - stram id of the stream
- * @param[in]  call_handle - call identifier
- * @param[out] rx_stats - ptr to the rx field in the stats struct
- * @param[out] tx_stats - ptr to the tx field in the stats struct
- *
- */
-
-int vcmGetRtpStats(cc_mcapid_t mcap_id,
-                   cc_groupid_t group_id,
-                   cc_streamid_t stream_id,
-                   cc_call_handle_t  call_handle,
-                   char *rx_stats,
-                   char *tx_stats)
-{
-    ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-    rx_stats[0] = '\0';
-    tx_stats[0] = '\0';
-    return 0;
-}
-
-/**
- *  specifies DSCP marking for RTCP streams
- *
- *  @param group_id - call_handle of the call
- *  @param dscp - the DSCP value to be used
- *
- *  @return  void
- */
-
-void vcmSetRtcpDscp(cc_groupid_t group_id, int dscp)
-{
-    // do nothing
-}
-
-/**
- *
- * The wlan interface puts into unique situation where call control
- * has to allocate the worst case bandwith before creating a
- * inbound or outbound call. The function call will interface through
- * media API into wlan to get the call bandwidth. The function
- * return is asynchronous and will block till the return media
- * callback signals to continue the execution.
- *
- * @note If not using WLAN interface simply return true
- *
- * @return true if the bandwidth can be allocated else false.
- */
-
-cc_boolean vcmAllocateBandwidth(cc_call_handle_t  call_handle, int sessions)
-{
-    return(TRUE);
-}
-
-/**
- *
- * Free the bandwidth allocated for this call
- * using the vcmAllocateBandwidth API
- *
- * @note  If not using WLAN provide a stub
- */
-
-void vcmRemoveBandwidth(cc_call_handle_t  call_handle)
-{
-    //do nothing
-}
-
-/**
- * @brief vcmActivateWlan
- *
- * Free the bandwidth allocated for this call
- * using the vcmAllocateBandwidth API
- *
- * @note If not using WLAN provide a stub
- */
-
-void vcmActivateWlan(cc_boolean is_active)
-{
-    // do nothing
-}
-
-/**
- *  free the media pointer allocated in vcm_negotiate_attrs method
- *
- *  @param ptr - pointer to be freed
- *
- *  @return  void
- */
-void vcmFreeMediaPtr(void *ptr)
-{
-  free(ptr);
-}
-
-/**
- * Verify if the SDP attributes for the requested video codec are acceptable
- *
- * This method is called for video codecs only. This method should parse the
- * Video SDP attributes using the SDP helper API and verify if received
- * attributes are acceptable. If the attributes are acceptable any attribute
- * values if needed by vcmTxStart method should be bundled in the desired
- * structure and its pointer should be returned in rccappptr. This opaque
- * pointer shall be provided again when vcmTxStart is invoked.
- *
- * @param [in] media_type - codec for which we are negotiating
- * @param [in] sdp_p - opaque SDP pointer to be used via SDP helper APIs
- * @param [in] level - Parameter to be used with SDP helper APIs
- * @param [out] rcapptr - variable to return the allocated attrib structure
- *
- * @return cc_boolean - true if attributes are accepted false otherwise
- */
-
-cc_boolean vcmCheckAttribs(cc_uint32_t media_type, void *sdp_p, int level,
-                           int remote_pt, void **rcapptr)
-{
-    ASSERT_ON_THREAD(VcmSIPCCBinding::getMainThread());
-    CSFLogDebug( logTag, "vcmCheckAttribs(): media=%d", media_type);
-
-    cc_uint16_t     temp;
-    const char      *ptr;
-    uint32_t        t_uint;
-    struct VideoCodecConfigH264 *rcap;
-
-    *rcapptr = nullptr;
-
-    int fmtp_inst = ccsdpAttrGetFmtpInst(sdp_p, level, remote_pt);
-    if (fmtp_inst < 0) {
-      return TRUE;
-    }
-
-    switch (media_type)
-    {
-    case RTP_VP8:
-        return TRUE;
-
-    case RTP_H264_P0:
-    case RTP_H264_P1:
-
-        rcap = (struct VideoCodecConfigH264 *) cpr_malloc( sizeof(struct VideoCodecConfigH264) );
-        if ( rcap == nullptr )
-        {
-            CSFLogDebug( logTag, "vcmCheckAttribs(): Malloc Failed for rcap");
-            return FALSE;
-        }
-        memset( rcap, 0, sizeof(struct VideoCodecConfigH264) );
-
-        if ( (ptr = ccsdpAttrGetFmtpParamSets(sdp_p, level, 0, fmtp_inst)) != nullptr )
-        {
-            memset(rcap->sprop_parameter_sets, 0, csf_countof(rcap->sprop_parameter_sets));
-            sstrncpy(rcap->sprop_parameter_sets, ptr, csf_countof(rcap->sprop_parameter_sets));
-        }
-
-        if ( ccsdpAttrGetFmtpPackMode(sdp_p, level, 0, fmtp_inst, &temp) == SDP_SUCCESS )
-        {
-            rcap->packetization_mode = temp;
-        }
-
-        if ( (ptr = ccsdpAttrGetFmtpProfileLevelId(sdp_p, level, 0, fmtp_inst)) != nullptr )
-        {
-#ifdef _WIN32
-            sscanf_s(ptr, "%x", &rcap->profile_level_id, sizeof(int*));
-#else
-            sscanf(ptr, "%x", &rcap->profile_level_id);
-#endif
-        }
-
-        if ( ccsdpAttrGetFmtpMaxMbps(sdp_p, level, 0, fmtp_inst, &t_uint) == SDP_SUCCESS )
-        {
-            rcap->max_mbps = t_uint;
-        }
-
-        if ( ccsdpAttrGetFmtpMaxFs(sdp_p, level, 0, fmtp_inst, &t_uint) == SDP_SUCCESS )
-        {
-            rcap->max_fs = t_uint;
-        }
-
-        if ( ccsdpAttrGetFmtpMaxCpb(sdp_p, level, 0, fmtp_inst, &t_uint) == SDP_SUCCESS )
-        {
-            rcap->max_cpb = t_uint;
-        }
-
-        if ( ccsdpAttrGetFmtpMaxDpb(sdp_p, level, 0, fmtp_inst, &t_uint) == SDP_SUCCESS )
-        {
-            rcap->max_dpb = t_uint;
-        }
-
-        if ( ccsdpAttrGetFmtpMaxBr(sdp_p, level, 0, fmtp_inst, &t_uint) == SDP_SUCCESS )
-        {
-            rcap->max_br = t_uint;
-        }
-
-        rcap->tias_bw = ccsdpGetBandwidthValue(sdp_p, level, fmtp_inst);
-        if ( rcap->tias_bw == 0 )
-        {
-            // received bandwidth of 0 reject this
-            free(rcap);
-            return FALSE;
-        }
-        else if ( rcap->tias_bw == SDP_INVALID_VALUE )
-        {
-            // bandwidth not received pass 0 to ms
-            rcap->tias_bw = 0;
-        }
-
-        CSFLogDebug( logTag, "vcmCheckAttribs(): Negotiated media attrs\nsprop=%s\npack_mode=%d\nprofile_level_id=%X\nmbps=%d\nmax_fs=%d\nmax_cpb=%d\nmax_dpb=%d\nbr=%d bw=%d\n",
-            rcap->sprop_parameter_sets,
-            rcap->packetization_mode,
-            rcap->profile_level_id,
-            rcap->max_mbps,
-            rcap->max_fs,
-            rcap->max_cpb,
-            rcap->max_dpb,
-            rcap->max_br,
-            rcap->tias_bw);
-
-        *rcapptr = rcap;
-        return TRUE;
-
-    default:
-        return FALSE;
-    }
-}
-
-/**
- * Send a DTMF digit
- *
- * This method is called for sending a DTMF tone for the specified duration
- *
- * @param [in] digit - the DTMF digit that needs to be played out.
- * @param [in] duration - duration of the tone
- * @param [in] direction - direction in which the tone needs to be played.
- *
- * @return void
- */
-int vcmDtmfBurst(int digit, int duration, int direction)
-{
-    CSFLogDebug( logTag, "vcmDtmfBurst(): digit=%d duration=%d, direction=%d", digit, duration, direction);
-    StreamObserver* obs = VcmSIPCCBinding::getStreamObserver();
-    if(obs != nullptr)
-        obs->dtmfBurst(digit, duration, direction);
-    return 0;
-}
-
-/**
- * vcmGetILBCMode
- *
- * This method should return the mode that needs to be used in
- * SDP
- * @return int
- */
-int vcmGetILBCMode()
-{
-    return 0;
-}
-
-} // extern "C"
-
-static mozilla::RefPtr<TransportFlow>
-vcmCreateTransportFlow(sipcc::PeerConnectionImpl *pc, int level, bool rtcp,
-  sdp_setup_type_e setup_type, const char *fingerprint_alg,
-  const char *fingerprint) {
-
-  // TODO(ekr@rtfm.com): Check that if the flow already exists the digest
-  // is the same. The only way that can happen is if
-  //
-  // (a) We have an error or
-  // (b) The other side bundled but had mismatched digests for each line
-  //
-  // Not clear that either of these cases matters.
-  mozilla::RefPtr<TransportFlow> flow;
-  flow = pc->media()->GetTransportFlow(level, rtcp);
-
-  if (!flow) {
-    CSFLogDebug(logTag, "Making new transport flow for level=%d rtcp=%s", level, rtcp ? "true" : "false");
-
-    char id[32];
-    PR_snprintf(id, sizeof(id), "%s:%d,%s",
-                pc->GetHandle().c_str(), level, rtcp ? "rtcp" : "rtp");
-    flow = new TransportFlow(id);
-
-
-    ScopedDeletePtr<TransportLayerIce> ice(
-        new TransportLayerIce(pc->GetHandle(), pc->media()->ice_ctx(),
-                              pc->media()->ice_media_stream(level-1),
-                              rtcp ? 2 : 1));
-
-    ScopedDeletePtr<TransportLayerDtls> dtls(new TransportLayerDtls());
-
-    // RFC 5763 says:
-    //
-    //   The endpoint MUST use the setup attribute defined in [RFC4145].
-    //   The endpoint that is the offerer MUST use the setup attribute
-    //   value of setup:actpass and be prepared to receive a client_hello
-    //   before it receives the answer.  The answerer MUST use either a
-    //   setup attribute value of setup:active or setup:passive.  Note that
-    //   if the answerer uses setup:passive, then the DTLS handshake will
-    //   not begin until the answerer is received, which adds additional
-    //   latency. setup:active allows the answer and the DTLS handshake to
-    //   occur in parallel.  Thus, setup:active is RECOMMENDED.  Whichever
-    //   party is active MUST initiate a DTLS handshake by sending a
-    //   ClientHello over each flow (host/port quartet).
-    //
-
-    // setup_type should at this point be either PASSIVE or ACTIVE
-    // other a=setup values should have been negotiated out.
-    MOZ_ASSERT(setup_type == SDP_SETUP_PASSIVE ||
-               setup_type == SDP_SETUP_ACTIVE);
-    dtls->SetRole(
-      setup_type == SDP_SETUP_PASSIVE ?
-      TransportLayerDtls::SERVER : TransportLayerDtls::CLIENT);
-    mozilla::RefPtr<DtlsIdentity> pcid = pc->GetIdentity();
-    if (!pcid) {
-      return nullptr;
-    }
-    dtls->SetIdentity(pcid);
-
-    unsigned char remote_digest[TransportLayerDtls::kMaxDigestLength];
-    size_t digest_len;
-
-    nsresult res = DtlsIdentity::ParseFingerprint(fingerprint,
-                                                  remote_digest,
-                                                  sizeof(remote_digest),
-                                                  &digest_len);
-    if (!NS_SUCCEEDED(res)) {
-      CSFLogError(logTag, "Could not convert fingerprint");
-      return nullptr;
-    }
-
-    std::string fingerprint_str(fingerprint_alg);
-    // Downcase because SDP is case-insensitive.
-    std::transform(fingerprint_str.begin(), fingerprint_str.end(),
-                   fingerprint_str.begin(), ::tolower);
-    res = dtls->SetVerificationDigest(fingerprint_str, remote_digest, digest_len);
-    if (!NS_SUCCEEDED(res)) {
-      CSFLogError(logTag, "Could not set remote DTLS digest");
-      return nullptr;
-    }
-
-    std::vector<uint16_t> srtp_ciphers;
-    srtp_ciphers.push_back(SRTP_AES128_CM_HMAC_SHA1_80);
-    srtp_ciphers.push_back(SRTP_AES128_CM_HMAC_SHA1_32);
-
-    res = dtls->SetSrtpCiphers(srtp_ciphers);
-    if (!NS_SUCCEEDED(res)) {
-      CSFLogError(logTag, "Couldn't set SRTP ciphers");
-      return nullptr;
-    }
-
-    nsAutoPtr<std::queue<TransportLayer *> > layers(new std::queue<TransportLayer *>);
-    layers->push(ice.forget());
-    layers->push(dtls.forget());
-
-
-    // Layers are now owned by the flow.
-    // TODO(ekr@rtfm.com): Propagate errors for when this fails.
-    // Bug 854518.
-    nsresult rv = pc->media()->ice_ctx()->thread()->Dispatch(
-        WrapRunnable(flow, &TransportFlow::PushLayers, layers),
-        NS_DISPATCH_NORMAL);
-
-    if (NS_FAILED(rv)) {
-      return nullptr;
-    }
-
-    // Note, this flow may actually turn out to be invalid
-    // because PushLayers is async and can fail.
-    pc->media()->AddTransportFlow(level, rtcp, flow);
-  }
-  return flow;
-}
-
-
-/**
- * vcmOnSdpParseError_m
- *
- * This method is called for each parsing error of SDP.  It does not necessarily
- * mean the SDP read was fatal and can be called many times for the same SDP.
- *
- * This function should only be called on the main thread.
- *
- */
-int vcmOnSdpParseError(const char *peerconnection, const char *message) {
-  MOZ_ASSERT(peerconnection);
-  MOZ_ASSERT(message);
-
-  sipcc::PeerConnectionWrapper pc(peerconnection);
-  ENSURE_PC(pc, VCM_ERROR);
-
-  pc.impl()->OnSdpParseError(message);
-  return 0;
-}
-
-
-/**
- * vcmDisableRtcpComponent_m
- *
- * If we are doing rtcp-mux we need to disable component number 2 in the ICE
- * layer.  Otherwise we will wait for it to connect when it is unused
- */
-int vcmDisableRtcpComponent(const char *peerconnection, int level) {
-#ifdef MOZILLA_INTERNAL_API
-  MOZ_ASSERT(NS_IsMainThread());
-#endif
-  MOZ_ASSERT(level > 0);
-
-  sipcc::PeerConnectionWrapper pc(peerconnection);
-  ENSURE_PC(pc, VCM_ERROR);
-
-  CSFLogDebug( logTag, "%s: disabling rtcp component %d", __FUNCTION__, level);
-  mozilla::RefPtr<NrIceMediaStream> stream = pc.impl()->media()->
-    ice_media_stream(level-1);
-  MOZ_ASSERT(stream);
-  if (!stream) {
-    return VCM_ERROR;
-  }
-
-  // The second component is for RTCP
-  nsresult res = stream->DisableComponent(2);
-  MOZ_ASSERT(NS_SUCCEEDED(res));
-  if (!NS_SUCCEEDED(res)) {
-    return VCM_ERROR;
-  }
-
-  return 0;
-}
-
-static short vcmGetVideoPref(uint16_t codec,
-                             const char *pref,
-                             int32_t *ret) {
-  nsCOMPtr<nsIPrefBranch> branch = VcmSIPCCBinding::getPrefBranch();
-  if (branch && NS_SUCCEEDED(branch->GetIntPref(pref, ret))) {
-    return 0;
-  }
-  return VCM_ERROR;
-}
-
-short vcmGetVideoLevel(uint16_t codec,
-                       int32_t *level) {
-  return vcmGetVideoPref(codec,
-                         "media.navigator.video.h264.level",
-                         level);
-}
-
-short vcmGetVideoMaxFs(uint16_t codec,
-                       int32_t *max_fs) {
-  return vcmGetVideoPref(codec,
-                         "media.navigator.video.max_fs",
-                         max_fs);
-}
-
-short vcmGetVideoMaxFr(uint16_t codec,
-                       int32_t *max_fr) {
-  return vcmGetVideoPref(codec,
-                         "media.navigator.video.max_fr",
-                         max_fr);
-}
-
-short vcmGetVideoMaxBr(uint16_t codec,
-                       int32_t *max_br) {
-  return vcmGetVideoPref(codec,
-                         "media.navigator.video.h264.max_br",
-                         max_br);
-}
-
-short vcmGetVideoMaxMbps(uint16_t codec,
-                         int32_t *max_mbps) {
-  short ret = vcmGetVideoPref(codec,
-                              "media.navigator.video.h264.max_mbps",
-                              max_mbps);
-
-  if (ret == VCM_ERROR) {
-#ifdef MOZ_WEBRTC_OMX
-    // Level 1.2; but let's allow CIF@30 or QVGA@30+ by default
-    *max_mbps = 11880;
-    ret = 0;
-#endif
-  }
-  return ret;
-}
-
-short vcmGetVideoPreferredCodec(int32_t *preferred_codec) {
-  return vcmGetVideoPref((uint16_t)0,
-                         "media.navigator.video.preferred_codec",
-                         preferred_codec);
-}
deleted file mode 100644
--- a/media/webrtc/signaling/src/media/VcmSIPCCBinding.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef _CSF_VCM_SIPCC_BINDING_H_
-#define _CSF_VCM_SIPCC_BINDING_H_
-
-extern "C"
-{
-#include "ccapi_types.h"
-}
-
-#include "mozIGeckoMediaPluginService.h"
-
-class nsIThread;
-class nsIEventTarget;
-class nsIPrefBranch;
-
-namespace mozilla {
-    class NrIceMediaStream;
-};
-
-namespace CSF
-{
-    class AudioTermination;
-    class VideoTermination;
-    class AudioControl;
-    class VideoControl;
-    class MediaProvider;
-    class MediaProviderObserver;
-
-    class StreamObserver
-    {
-    public:
-    	  virtual void registerStream(cc_call_handle_t call, int streamId, bool isVideo) = 0;
-    	  virtual void deregisterStream(cc_call_handle_t call, int streamId) = 0;
-    	  virtual void dtmfBurst(int digit, int direction, int duration) = 0;
-    	  virtual void sendIFrame(cc_call_handle_t call) = 0;
-    };
-
-    class VcmSIPCCBinding
-    {
-    public:
-        VcmSIPCCBinding ();
-        virtual ~VcmSIPCCBinding();
-
-        // The getter is only for use by the vcm_* impl functions.
-        void setStreamObserver(StreamObserver*);
-        static StreamObserver* getStreamObserver();
-
-        static AudioTermination * getAudioTermination();
-        static VideoTermination * getVideoTermination();
-
-        static AudioControl * getAudioControl();
-        static VideoControl * getVideoControl();
-
-        void setMediaProviderObserver(MediaProviderObserver* obs);
-        static MediaProviderObserver * getMediaProviderObserver();
-
-        static void setAudioCodecs(int codecMask);
-        static void setVideoCodecs(int codecMask);
-
-        static int getAudioCodecs();
-        static int getVideoCodecs();
-        static int getVideoCodecsGmp();
-        static int getVideoCodecsHw();
-
-        static void setMainThread(nsIThread *thread);
-        static nsIThread *getMainThread();
-
-        static nsCOMPtr<nsIPrefBranch> getPrefBranch();
-
-        static int gVideoCodecGmpMask;
-    private:
-        nsCOMPtr<mozIGeckoMediaPluginService> mGMPService;
-        static VcmSIPCCBinding * gSelf;
-        StreamObserver* streamObserver;
-        MediaProviderObserver *mediaProviderObserver;
-        static bool gInitGmpCodecs;
-        static int gAudioCodecMask;
-        static int gVideoCodecMask;
-        static nsIThread *gMainThread;
-        static nsIEventTarget *gSTSThread;
-        static nsCOMPtr<nsIPrefBranch> gBranch;
-    };
-}
-
-#endif
-
-
deleted file mode 100644
--- a/media/webrtc/signaling/src/media/cip_Sipcc_CodecMask.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef _Included_cip_sipcc_CodecMask
-#define _Included_cip_sipcc_CodecMask
-#ifdef __cplusplus
-extern "C" {
-#endif
-#undef cip_sipcc_CodecMask_DSP_RESOURCE_G711
-#define cip_sipcc_CodecMask_DSP_RESOURCE_G711 1L
-#undef cip_sipcc_CodecMask_DSP_RESOURCE_G729A
-#define cip_sipcc_CodecMask_DSP_RESOURCE_G729A 2L
-#undef cip_sipcc_CodecMask_DSP_RESOURCE_G729B
-#define cip_sipcc_CodecMask_DSP_RESOURCE_G729B 4L
-#undef cip_sipcc_CodecMask_DSP_RESOURCE_LINEAR
-#define cip_sipcc_CodecMask_DSP_RESOURCE_LINEAR 8L
-#undef cip_sipcc_CodecMask_DSP_RESOURCE_G722
-#define cip_sipcc_CodecMask_DSP_RESOURCE_G722 16L
-#undef cip_sipcc_CodecMask_DSP_RESOURCE_iLBC
-#define cip_sipcc_CodecMask_DSP_RESOURCE_iLBC 32L
-#undef cip_sipcc_CodecMask_DSP_RESOURCE_iSAC
-#define cip_sipcc_CodecMask_DSP_RESOURCE_iSAC 64L
-#undef cip_sipcc_CodecMask_DSP_DECODEONLY
-#define cip_sipcc_CodecMask_DSP_DECODEONLY 0L
-#undef cip_sipcc_CodecMask_DSP_ENCODEONLY
-#define cip_sipcc_CodecMask_DSP_ENCODEONLY 1L
-#undef cip_sipcc_CodecMask_DSP_FULLDUPLEX
-#define cip_sipcc_CodecMask_DSP_FULLDUPLEX 2L
-#undef cip_sipcc_CodecMask_DSP_IGNORE
-#define cip_sipcc_CodecMask_DSP_IGNORE 3L
-#ifdef __cplusplus
-}
-#endif
-#endif
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
@@ -361,38 +361,35 @@ private:
 // and transmitting to the network.
 class MediaPipelineTransmit : public MediaPipeline {
 public:
   // Set rtcp_transport to nullptr to use rtcp-mux
   MediaPipelineTransmit(const std::string& pc,
                         nsCOMPtr<nsIEventTarget> main_thread,
                         nsCOMPtr<nsIEventTarget> sts_thread,
                         DOMMediaStream *domstream,
-                        int pipeline_index, // For PeerConnectionMedia/mPipelines
                         int level,
                         bool is_video,
                         RefPtr<MediaSessionConduit> conduit,
                         RefPtr<TransportFlow> rtp_transport,
                         RefPtr<TransportFlow> rtcp_transport) :
       MediaPipeline(pc, TRANSMIT, main_thread, sts_thread,
                     domstream->GetStream(), TRACK_INVALID, level,
                     conduit, rtp_transport, rtcp_transport),
       listener_(new PipelineListener(conduit)),
       domstream_(domstream),
-      pipeline_index_(pipeline_index),
       is_video_(is_video)
   {}
 
   // Initialize (stuff here may fail)
   virtual nsresult Init() MOZ_OVERRIDE;
 
   virtual void AttachToTrack(TrackID track_id);
 
   // Index used to refer to this before we know the TrackID
-  virtual TrackID pipeline_index() const { return pipeline_index_; }
   // Note: unlike MediaPipeline::trackid(), this is threadsafe
   // Not set until first media is received
   virtual TrackID const trackid_locked() { return listener_->trackid(); }
   // written and used from MainThread
   virtual bool IsVideo() const MOZ_OVERRIDE { return is_video_; }
 
 #ifdef MOZILLA_INTERNAL_API
   // when the principal of the PeerConnection changes, it calls through to here
@@ -516,17 +513,16 @@ public:
 #ifdef MOZILLA_INTERNAL_API
     int32_t last_img_; // serial number of last Image
 #endif // MOZILLA_INTERNAL_API
   };
 
  private:
   RefPtr<PipelineListener> listener_;
   DOMMediaStream *domstream_;
-  int pipeline_index_; // for lookups in LocalSourceStreamInfo::mPipelines;
   bool is_video_;
 };
 
 
 // A specialization of pipeline for reading from the network and
 // rendering video.
 class MediaPipelineReceive : public MediaPipeline {
  public:
new file mode 100644
--- /dev/null
+++ b/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp
@@ -0,0 +1,703 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "logging.h"
+
+#include "PeerConnectionImpl.h"
+#include "PeerConnectionMedia.h"
+#include "MediaPipelineFactory.h"
+#include "transportflow.h"
+#include "transportlayer.h"
+#include "transportlayerdtls.h"
+#include "transportlayerice.h"
+
+#include "signaling/src/jsep/JsepTrack.h"
+#include "signaling/src/jsep/JsepTransport.h"
+
+#ifdef MOZILLA_INTERNAL_API
+#include "nsIPrincipal.h"
+#include "nsIDocument.h"
+#include "mozilla/Preferences.h"
+#endif
+
+#include "GmpVideoCodec.h"
+#ifdef MOZ_WEBRTC_OMX
+#include "OMXVideoCodec.h"
+#include "OMXCodecWrapper.h"
+#endif
+
+#include <stdlib.h>
+
+namespace mozilla {
+
+MOZ_MTLOG_MODULE("MediaPipelineFactory")
+
+// Trivial wrapper class around a vector of ptrs.
+template <class T> class PtrVector
+{
+public:
+  ~PtrVector()
+  {
+    for (auto it = values.begin(); it != values.end(); ++it) {
+      delete *it;
+    }
+  }
+
+  std::vector<T*> values;
+};
+
+static nsresult
+JsepCodecDescToCodecConfig(const JsepCodecDescription& aCodec,
+                           AudioCodecConfig** aConfig)
+{
+  MOZ_ASSERT(aCodec.mType == SdpMediaSection::kAudio);
+  if (aCodec.mType != SdpMediaSection::kAudio)
+    return NS_ERROR_INVALID_ARG;
+
+  const JsepAudioCodecDescription& desc =
+      static_cast<const JsepAudioCodecDescription&>(aCodec);
+
+  uint16_t pt;
+
+  if (!desc.GetPtAsInt(&pt)) {
+    MOZ_MTLOG(ML_ERROR, "Invalid payload type: " << desc.mDefaultPt);
+    return NS_ERROR_INVALID_ARG;
+  }
+
+  *aConfig = new AudioCodecConfig(pt,
+                                  desc.mName,
+                                  desc.mClock,
+                                  desc.mPacketSize,
+                                  desc.mChannels,
+                                  desc.mBitrate);
+
+  return NS_OK;
+}
+
+static nsresult
+JsepCodecDescToCodecConfig(const JsepCodecDescription& aCodec,
+                           VideoCodecConfig** aConfig)
+{
+  MOZ_ASSERT(aCodec.mType == SdpMediaSection::kVideo);
+  if (aCodec.mType != SdpMediaSection::kVideo) {
+    MOZ_ASSERT(false, "JsepCodecDescription has wrong type");
+    return NS_ERROR_INVALID_ARG;
+  }
+
+  const JsepVideoCodecDescription& desc =
+      static_cast<const JsepVideoCodecDescription&>(aCodec);
+
+  uint16_t pt;
+
+  if (!desc.GetPtAsInt(&pt)) {
+    MOZ_MTLOG(ML_ERROR, "Invalid payload type: " << desc.mDefaultPt);
+    return NS_ERROR_INVALID_ARG;
+  }
+
+  ScopedDeletePtr<VideoCodecConfigH264> h264Config;
+
+  if (desc.mName == "H264") {
+    h264Config = new VideoCodecConfigH264;
+    size_t spropSize = sizeof(h264Config->sprop_parameter_sets);
+    strncpy(h264Config->sprop_parameter_sets,
+            desc.mSpropParameterSets.c_str(),
+            spropSize);
+    h264Config->sprop_parameter_sets[spropSize - 1] = '\0';
+    h264Config->packetization_mode = desc.mPacketizationMode;
+    h264Config->profile_level_id = desc.mProfileLevelId;
+    h264Config->max_mbps = desc.mMaxMbps;
+    h264Config->max_fs = desc.mMaxFs;
+    h264Config->max_cpb = desc.mMaxCpb;
+    h264Config->max_dpb = desc.mMaxDpb;
+    h264Config->max_br = desc.mMaxBr;
+    h264Config->tias_bw = 0; // TODO. Issue 165.
+  }
+
+  VideoCodecConfig* configRaw;
+  configRaw = new VideoCodecConfig(
+      pt, desc.mName, desc.mMaxFs, desc.mMaxFr, h264Config);
+
+  configRaw->mAckFbTypes = desc.mAckFbTypes;
+  configRaw->mNackFbTypes = desc.mNackFbTypes;
+  configRaw->mCcmFbTypes = desc.mCcmFbTypes;
+
+  *aConfig = configRaw;
+  return NS_OK;
+}
+
+// Accessing the PCMedia should be safe here because we shouldn't
+// have enqueued this function unless it was still active and
+// the ICE data is destroyed on the STS.
+static void
+FinalizeTransportFlow_s(RefPtr<PeerConnectionMedia> aPCMedia,
+                        RefPtr<TransportFlow> aFlow, size_t aLevel,
+                        bool aIsRtcp,
+                        nsAutoPtr<PtrVector<TransportLayer> > aLayerList)
+{
+  TransportLayerIce* ice =
+      static_cast<TransportLayerIce*>(aLayerList->values.front());
+  ice->SetParameters(
+      aPCMedia->ice_ctx(), aPCMedia->ice_media_stream(aLevel), aIsRtcp ? 2 : 1);
+  nsAutoPtr<std::queue<TransportLayer*> > layerQueue(
+      new std::queue<TransportLayer*>);
+  for (auto i = aLayerList->values.begin(); i != aLayerList->values.end();
+       ++i) {
+    layerQueue->push(*i);
+  }
+  aLayerList->values.clear();
+  (void)aFlow->PushLayers(layerQueue); // TODO(bug 854518): Process errors.
+}
+
+nsresult
+MediaPipelineFactory::CreateOrGetTransportFlow(
+    size_t aLevel,
+    bool aIsRtcp,
+    const JsepTransport& aTransport,
+    RefPtr<TransportFlow>* aFlowOutparam)
+{
+  nsresult rv;
+  RefPtr<TransportFlow> flow;
+
+  flow = mPCMedia->GetTransportFlow(aLevel, aIsRtcp);
+  if (flow) {
+    *aFlowOutparam = flow;
+    return NS_OK;
+  }
+
+  std::ostringstream osId;
+  osId << mPC->GetHandle() << ":" << aLevel << ","
+       << (aIsRtcp ? "rtcp" : "rtp");
+  flow = new TransportFlow(osId.str());
+
+  // The media streams are made on STS so we need to defer setup.
+  auto ice = MakeUnique<TransportLayerIce>(mPC->GetHandle());
+  auto dtls = MakeUnique<TransportLayerDtls>();
+  dtls->SetRole(aTransport.mDtls->GetRole() ==
+                        JsepDtlsTransport::kJsepDtlsClient
+                    ? TransportLayerDtls::CLIENT
+                    : TransportLayerDtls::SERVER);
+
+  RefPtr<DtlsIdentity> pcid = mPC->GetIdentity();
+  if (!pcid) {
+    MOZ_MTLOG(ML_ERROR, "Failed to get DTLS identity.");
+    return NS_ERROR_FAILURE;
+  }
+  dtls->SetIdentity(pcid);
+
+  const SdpFingerprintAttributeList& fingerprints =
+      aTransport.mDtls->GetFingerprints();
+  for (auto fp = fingerprints.mFingerprints.begin();
+       fp != fingerprints.mFingerprints.end();
+       ++fp) {
+    std::ostringstream ss;
+    ss << fp->hashFunc;
+    rv = dtls->SetVerificationDigest(ss.str(), &fp->fingerprint[0],
+                                     fp->fingerprint.size());
+    if (NS_FAILED(rv)) {
+      MOZ_MTLOG(ML_ERROR, "Could not set fingerprint");
+      return rv;
+    }
+  }
+
+  std::vector<uint16_t> srtpCiphers;
+  srtpCiphers.push_back(SRTP_AES128_CM_HMAC_SHA1_80);
+  srtpCiphers.push_back(SRTP_AES128_CM_HMAC_SHA1_32);
+
+  rv = dtls->SetSrtpCiphers(srtpCiphers);
+  if (NS_FAILED(rv)) {
+    MOZ_MTLOG(ML_ERROR, "Couldn't set SRTP ciphers");
+    return rv;
+  }
+
+  nsAutoPtr<PtrVector<TransportLayer> > layers(new PtrVector<TransportLayer>);
+  layers->values.push_back(ice.release());
+  layers->values.push_back(dtls.release());
+
+  rv = mPCMedia->GetSTSThread()->Dispatch(
+      WrapRunnableNM(FinalizeTransportFlow_s, mPCMedia, flow, aLevel, aIsRtcp,
+                     layers),
+      NS_DISPATCH_NORMAL);
+  if (NS_FAILED(rv)) {
+    MOZ_MTLOG(ML_ERROR, "Failed to dispatch FinalizeTransportFlow_s");
+    return rv;
+  }
+
+  mPCMedia->AddTransportFlow(aLevel, aIsRtcp, flow);
+
+  *aFlowOutparam = flow;
+
+  return NS_OK;
+}
+
+nsresult
+MediaPipelineFactory::CreateMediaPipeline(const JsepTrackPair& aTrackPair,
+                                          const JsepTrack& aTrack)
+{
+  MOZ_MTLOG(ML_DEBUG,
+            "Creating media pipeline"
+                << " m-line index=" << aTrackPair.mLevel
+                << " type=" << aTrack.GetMediaType()
+                << " direction=" << aTrack.GetDirection());
+
+  MOZ_ASSERT(aTrackPair.mRtpTransport);
+
+  // First make sure the transport flow exists.
+  RefPtr<TransportFlow> rtpFlow;
+  nsresult rv = CreateOrGetTransportFlow(
+      aTrackPair.mLevel, false, *aTrackPair.mRtpTransport, &rtpFlow);
+  if (NS_FAILED(rv))
+    return rv;
+  MOZ_ASSERT(rtpFlow);
+
+  RefPtr<TransportFlow> rtcpFlow;
+  if (aTrackPair.mRtcpTransport) {
+    rv = CreateOrGetTransportFlow(
+        aTrackPair.mLevel, true, *aTrackPair.mRtcpTransport, &rtcpFlow);
+    if (NS_FAILED(rv))
+      return rv;
+    MOZ_ASSERT(rtcpFlow);
+  }
+
+  // TODO(bug 1016476): If bundle is in play, grab the TransportFlows for the
+  // bundle level too.
+
+  bool receiving =
+      aTrack.GetDirection() == JsepTrack::Direction::kJsepTrackReceiving;
+
+  RefPtr<MediaSessionConduit> conduit;
+  if (aTrack.GetMediaType() == SdpMediaSection::kAudio) {
+    rv = CreateAudioConduit(aTrackPair, aTrack, &conduit);
+    if (NS_FAILED(rv))
+      return rv;
+  } else if (aTrack.GetMediaType() == SdpMediaSection::kVideo) {
+    rv = CreateVideoConduit(aTrackPair, aTrack, &conduit);
+    if (NS_FAILED(rv))
+      return rv;
+  } else {
+    // We've created the TransportFlow, nothing else to do here.
+    return NS_OK;
+  }
+
+  if (receiving) {
+    rv = CreateMediaPipelineReceiving(rtpFlow, rtcpFlow, nullptr, nullptr,
+                                      aTrackPair, aTrack, conduit);
+    if (NS_FAILED(rv))
+      return rv;
+  } else {
+    rv = CreateMediaPipelineSending(rtpFlow, rtcpFlow, nullptr, nullptr,
+                                    aTrackPair, aTrack, conduit);
+    if (NS_FAILED(rv))
+      return rv;
+  }
+
+  return NS_OK;
+}
+
+nsresult
+MediaPipelineFactory::CreateMediaPipelineReceiving(
+    RefPtr<TransportFlow> aRtpFlow,
+    RefPtr<TransportFlow> aRtcpFlow,
+    RefPtr<TransportFlow> aBundleRtpFlow,
+    RefPtr<TransportFlow> aBundleRtcpFlow,
+    const JsepTrackPair& aTrackPair,
+    const JsepTrack& aTrack,
+    const RefPtr<MediaSessionConduit>& aConduit)
+{
+
+  // Find the stream we need
+  nsRefPtr<RemoteSourceStreamInfo> stream =
+      mPCMedia->GetRemoteStreamById(aTrack.GetStreamId());
+  MOZ_ASSERT(stream);
+  if (!stream) {
+    // This should never happen
+    MOZ_ASSERT(false);
+    MOZ_MTLOG(ML_ERROR, "Stream not found: " << aTrack.GetStreamId());
+    return NS_ERROR_FAILURE;
+  }
+
+  RefPtr<MediaPipelineReceive> pipeline;
+
+  // TODO(bug 1016476): Need bundle filter.
+  nsAutoPtr<MediaPipelineFilter> filter(nullptr);
+
+  if (aTrack.GetMediaType() == SdpMediaSection::kAudio) {
+    pipeline = new MediaPipelineReceiveAudio(
+        mPC->GetHandle(),
+        mPC->GetMainThread().get(),
+        mPC->GetSTSThread(),
+        stream->GetMediaStream()->GetStream(),
+        // Use the level + 1 as the track id. 0 is forbidden
+        aTrackPair.mLevel + 1,
+        aTrackPair.mLevel,
+        static_cast<AudioSessionConduit*>(aConduit.get()), // Ugly downcast.
+        aRtpFlow,
+        aRtcpFlow,
+        aBundleRtpFlow,
+        aBundleRtcpFlow,
+        filter);
+
+  } else if (aTrack.GetMediaType() == SdpMediaSection::kVideo) {
+    pipeline = new MediaPipelineReceiveVideo(
+        mPC->GetHandle(),
+        mPC->GetMainThread().get(),
+        mPC->GetSTSThread(),
+        stream->GetMediaStream()->GetStream(),
+        // Use the level + 1 as the track id. 0 is forbidden
+        aTrackPair.mLevel + 1,
+        aTrackPair.mLevel,
+        static_cast<VideoSessionConduit*>(aConduit.get()), // Ugly downcast.
+        aRtpFlow,
+        aRtcpFlow,
+        aBundleRtpFlow,
+        aBundleRtcpFlow,
+        filter);
+  } else {
+    MOZ_ASSERT(false);
+    MOZ_MTLOG(ML_ERROR, "Invalid media type in CreateMediaPipelineReceiving");
+    return NS_ERROR_FAILURE;
+  }
+
+  nsresult rv = pipeline->Init();
+  if (NS_FAILED(rv)) {
+    MOZ_MTLOG(ML_ERROR, "Couldn't initialize receiving pipeline");
+    return rv;
+  }
+
+  stream->StorePipeline(aTrackPair.mLevel, SdpMediaSection::kVideo, pipeline);
+  return NS_OK;
+}
+
+nsresult
+MediaPipelineFactory::CreateMediaPipelineSending(
+    RefPtr<TransportFlow> aRtpFlow,
+    RefPtr<TransportFlow> aRtcpFlow,
+    RefPtr<TransportFlow> aBundleRtpFlow,
+    RefPtr<TransportFlow> aBundleRtcpFlow,
+    const JsepTrackPair& aTrackPair,
+    const JsepTrack& aTrack,
+    const RefPtr<MediaSessionConduit>& aConduit)
+{
+  nsresult rv;
+
+  nsRefPtr<LocalSourceStreamInfo> stream =
+      mPCMedia->GetLocalStreamById(aTrack.GetStreamId());
+  MOZ_ASSERT(stream);
+  if (!stream) {
+    // This should never happen
+    MOZ_MTLOG(ML_ERROR, "Stream not found: " << aTrack.GetStreamId());
+    return NS_ERROR_FAILURE;
+  }
+
+  // Now we have all the pieces, create the pipeline
+  RefPtr<MediaPipelineTransmit> pipeline = new MediaPipelineTransmit(
+      mPC->GetHandle(), mPC->GetMainThread().get(), mPC->GetSTSThread(),
+      stream->GetMediaStream(), aTrackPair.mLevel,
+      aTrack.GetMediaType() == SdpMediaSection::kVideo, aConduit, aRtpFlow,
+      aRtcpFlow);
+
+#ifdef MOZILLA_INTERNAL_API
+  // implement checking for peerIdentity (where failure == black/silence)
+  nsIDocument* doc = mPC->GetWindow()->GetExtantDoc();
+  if (doc) {
+    pipeline->UpdateSinkIdentity_m(doc->NodePrincipal(),
+                                   mPC->GetPeerIdentity());
+  } else {
+    MOZ_MTLOG(ML_ERROR, "Cannot initialize pipeline without attached doc");
+    return NS_ERROR_FAILURE; // Don't remove this till we know it's safe.
+  }
+#endif
+
+  rv = pipeline->Init();
+  if (NS_FAILED(rv)) {
+    MOZ_MTLOG(ML_ERROR, "Couldn't initialize sending pipeline");
+    return rv;
+  }
+
+// TODO(bug 1016476): Copied from vcmSIPCCBinding. Need to unifdef and port in.
+#if 0
+  // This tells the receive MediaPipeline (if there is one) whether we are
+  // doing bundle, and if so, updates the filter. Once the filter is finalized,
+  // it is then copied to the transmit pipeline so it can filter RTCP.
+  if (attrs->bundle_level) {
+    nsAutoPtr<MediaPipelineFilter> filter (new MediaPipelineFilter);
+    for (int s = 0; s < attrs->num_ssrcs; ++s) {
+      filter->AddRemoteSSRC(attrs->ssrcs[s]);
+    }
+    pc.impl()->media()->SetUsingBundle_m(level, true);
+    pc.impl()->media()->UpdateFilterFromRemoteDescription_m(level, filter);
+  } else {
+    // This will also clear the filter.
+    pc.impl()->media()->SetUsingBundle_m(level, false);
+  }
+#endif
+
+  stream->StorePipeline(aTrackPair.mLevel, pipeline);
+
+  return NS_OK;
+}
+
+nsresult
+MediaPipelineFactory::CreateAudioConduit(const JsepTrackPair& aTrackPair,
+                                         const JsepTrack& aTrack,
+                                         RefPtr<MediaSessionConduit>* aConduitp)
+{
+
+  if (!aTrack.GetNegotiatedDetails()) {
+    MOZ_ASSERT(false, "Track is missing negotiated details");
+    return NS_ERROR_INVALID_ARG;
+  }
+
+  bool receiving =
+      aTrack.GetDirection() == JsepTrack::Direction::kJsepTrackReceiving;
+
+  RefPtr<MediaSessionConduit> otherConduit =
+      mPCMedia->GetConduit(aTrackPair.mLevel, !receiving);
+  MOZ_ASSERT_IF(otherConduit,
+                otherConduit->type() == MediaSessionConduit::AUDIO);
+  // The two sides of a send/receive pair of conduits each keep a raw pointer
+  // to the other, and are responsible for cleanly shutting down.
+  RefPtr<AudioSessionConduit> conduit = AudioSessionConduit::Create(
+      static_cast<AudioSessionConduit*>(otherConduit.get()));
+
+  if (!conduit) {
+    MOZ_MTLOG(ML_ERROR, "Could not create audio conduit");
+    return NS_ERROR_FAILURE;
+  }
+
+  mPCMedia->AddConduit(aTrackPair.mLevel, receiving, conduit);
+
+  size_t numCodecs = aTrack.GetNegotiatedDetails()->GetCodecCount();
+  if (numCodecs == 0) {
+    MOZ_MTLOG(ML_ERROR, "Can't set up a conduit with 0 codecs");
+    return NS_ERROR_FAILURE;
+  }
+
+  if (receiving) {
+    PtrVector<AudioCodecConfig> configs;
+
+    for (size_t i = 0; i < numCodecs; i++) {
+      const JsepCodecDescription* cdesc;
+      nsresult rv = aTrack.GetNegotiatedDetails()->GetCodec(i, &cdesc);
+      MOZ_ASSERT(NS_SUCCEEDED(rv));
+      if (NS_FAILED(rv)) {
+        MOZ_MTLOG(ML_ERROR, "Failed to get codec from jsep track, rv="
+                                << static_cast<uint32_t>(rv));
+        return rv;
+      }
+
+      AudioCodecConfig* configRaw;
+      rv = JsepCodecDescToCodecConfig(*cdesc, &configRaw);
+      if (NS_FAILED(rv))
+        return rv;
+
+      configs.values.push_back(configRaw);
+    }
+
+    auto error = conduit->ConfigureRecvMediaCodecs(configs.values);
+
+    if (error) {
+      MOZ_MTLOG(ML_ERROR, "ConfigureRecvMediaCodecs failed: " << error);
+      return NS_ERROR_FAILURE;
+    }
+  } else {
+    const JsepCodecDescription* cdesc;
+    // Best codec.
+    nsresult rv = aTrack.GetNegotiatedDetails()->GetCodec(0, &cdesc);
+    MOZ_ASSERT(NS_SUCCEEDED(rv));
+    if (NS_FAILED(rv)) {
+      MOZ_MTLOG(ML_ERROR, "Failed to get codec from jsep track, rv="
+                              << static_cast<uint32_t>(rv));
+      return rv;
+    }
+
+    AudioCodecConfig* configRaw;
+    rv = JsepCodecDescToCodecConfig(*cdesc, &configRaw);
+    if (NS_FAILED(rv))
+      return rv;
+
+    ScopedDeletePtr<AudioCodecConfig> config(configRaw);
+    auto error = conduit->ConfigureSendMediaCodec(config.get());
+    if (error) {
+      MOZ_MTLOG(ML_ERROR, "ConfigureSendMediaCodec failed: " << error);
+      return NS_ERROR_FAILURE;
+    }
+
+    const SdpExtmapAttributeList::Extmap* audioLevelExt =
+        aTrack.GetNegotiatedDetails()->GetExt(
+            "urn:ietf:params:rtp-hdrext:ssrc-audio-level");
+
+    if (audioLevelExt) {
+      MOZ_MTLOG(ML_DEBUG, "Calling EnableAudioLevelExtension");
+      error = conduit->EnableAudioLevelExtension(true, audioLevelExt->entry);
+
+      if (error) {
+        MOZ_MTLOG(ML_ERROR, "EnableAudioLevelExtension failed: " << error);
+        return NS_ERROR_FAILURE;
+      }
+    }
+  }
+
+  *aConduitp = conduit;
+
+  return NS_OK;
+}
+
+nsresult
+MediaPipelineFactory::CreateVideoConduit(const JsepTrackPair& aTrackPair,
+                                         const JsepTrack& aTrack,
+                                         RefPtr<MediaSessionConduit>* aConduitp)
+{
+
+  if (!aTrack.GetNegotiatedDetails()) {
+    MOZ_ASSERT(false, "Track is missing negotiated details");
+    return NS_ERROR_INVALID_ARG;
+  }
+
+  bool receiving =
+      aTrack.GetDirection() == JsepTrack::Direction::kJsepTrackReceiving;
+
+  // Instantiate an appropriate conduit
+  RefPtr<MediaSessionConduit> peerConduit =
+      mPCMedia->GetConduit(aTrackPair.mLevel, !receiving);
+  MOZ_ASSERT_IF(peerConduit, peerConduit->type() == MediaSessionConduit::VIDEO);
+
+  // The two sides of a send/receive pair of conduits each keep a raw
+  // pointer to the other, and are responsible for cleanly shutting down.
+  RefPtr<VideoSessionConduit> conduit = VideoSessionConduit::Create(
+      static_cast<VideoSessionConduit*>(peerConduit.get()));
+
+  if (!conduit) {
+    MOZ_MTLOG(ML_ERROR, "Could not create video conduit");
+    return NS_ERROR_FAILURE;
+  }
+
+  mPCMedia->AddConduit(aTrackPair.mLevel, receiving, conduit);
+
+  size_t numCodecs = aTrack.GetNegotiatedDetails()->GetCodecCount();
+  if (numCodecs == 0) {
+    MOZ_MTLOG(ML_ERROR, "Can't set up a conduit with 0 codecs");
+    return NS_ERROR_FAILURE;
+  }
+
+  if (receiving) {
+    PtrVector<VideoCodecConfig> configs;
+
+    for (size_t i = 0; i < numCodecs; i++) {
+      const JsepCodecDescription* cdesc;
+
+      nsresult rv = aTrack.GetNegotiatedDetails()->GetCodec(i, &cdesc);
+      MOZ_ASSERT(NS_SUCCEEDED(rv));
+      if (NS_FAILED(rv)) {
+        MOZ_MTLOG(ML_ERROR, "Failed to get codec from jsep track, rv="
+                                << static_cast<uint32_t>(rv));
+        return rv;
+      }
+
+      VideoCodecConfig* configRaw;
+      rv = JsepCodecDescToCodecConfig(*cdesc, &configRaw);
+      if (NS_FAILED(rv))
+        return rv;
+
+      UniquePtr<VideoCodecConfig> config(configRaw);
+      if (EnsureExternalCodec(*conduit, config.get(), false)) {
+        continue;
+      }
+
+      configs.values.push_back(config.release());
+    }
+
+    auto error = conduit->ConfigureRecvMediaCodecs(configs.values);
+
+    if (error) {
+      MOZ_MTLOG(ML_ERROR, "ConfigureRecvMediaCodecs failed: " << error);
+      return NS_ERROR_FAILURE;
+    }
+  } else {
+    const JsepCodecDescription* cdesc;
+    // Best codec.
+    nsresult rv = aTrack.GetNegotiatedDetails()->GetCodec(0, &cdesc);
+    MOZ_ASSERT(NS_SUCCEEDED(rv));
+    if (NS_FAILED(rv)) {
+      MOZ_MTLOG(ML_ERROR, "Failed to get codec from jsep track, rv="
+                              << static_cast<uint32_t>(rv));
+      return rv;
+    }
+
+    VideoCodecConfig* configRaw;
+    rv = JsepCodecDescToCodecConfig(*cdesc, &configRaw);
+    if (NS_FAILED(rv))
+      return rv;
+
+    // Take possession of this pointer
+    ScopedDeletePtr<VideoCodecConfig> config(configRaw);
+
+    if (EnsureExternalCodec(*conduit, config, true)) {
+      MOZ_MTLOG(ML_ERROR, "External codec not available");
+      return NS_ERROR_FAILURE;
+    }
+
+    auto error = conduit->ConfigureSendMediaCodec(config);
+
+    if (error) {
+      MOZ_MTLOG(ML_ERROR, "ConfigureSendMediaCodec failed: " << error);
+      return NS_ERROR_FAILURE;
+    }
+  }
+
+  *aConduitp = conduit;
+
+  return NS_OK;
+}
+
+/*
+ * Add external H.264 video codec.
+ */
+MediaConduitErrorCode
+MediaPipelineFactory::EnsureExternalCodec(VideoSessionConduit& aConduit,
+                                          VideoCodecConfig* aConfig,
+                                          bool aIsSend)
+{
+  if (aConfig->mName == "VP8") {
+    return kMediaConduitNoError;
+  } else if (aConfig->mName == "H264") {
+    // Register H.264 codec.
+    if (aIsSend) {
+      VideoEncoder* encoder = nullptr;
+#ifdef MOZ_WEBRTC_OMX
+      encoder =
+          OMXVideoCodec::CreateEncoder(OMXVideoCodec::CodecType::CODEC_H264);
+#else
+      encoder = GmpVideoCodec::CreateEncoder();
+#endif
+      if (encoder) {
+        return aConduit.SetExternalSendCodec(aConfig, encoder);
+      } else {
+        return kMediaConduitInvalidSendCodec;
+      }
+    } else {
+      VideoDecoder* decoder;
+#ifdef MOZ_WEBRTC_OMX
+      decoder =
+          OMXVideoCodec::CreateDecoder(OMXVideoCodec::CodecType::CODEC_H264);
+#else
+      decoder = GmpVideoCodec::CreateDecoder();
+#endif
+      if (decoder) {
+        return aConduit.SetExternalRecvCodec(aConfig, decoder);
+      } else {
+        return kMediaConduitInvalidReceiveCodec;
+      }
+    }
+    NS_NOTREACHED("Shouldn't get here!");
+  } else {
+    MOZ_MTLOG(ML_ERROR,
+              "Invalid video codec configured: " << aConfig->mName.c_str());
+    return aIsSend ? kMediaConduitInvalidSendCodec
+                   : kMediaConduitInvalidReceiveCodec;
+  }
+
+  NS_NOTREACHED("Shouldn't get here!");
+}
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.h
@@ -0,0 +1,72 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+#ifndef _MEDIAPIPELINEFACTORY_H_
+#define _MEDIAPIPELINEFACTORY_H_
+
+#include "MediaConduitInterface.h"
+#include "PeerConnectionMedia.h"
+#include "transportflow.h"
+
+#include "signaling/src/jsep/JsepTrack.h"
+#include "mozilla/RefPtr.h"
+#include "mozilla/UniquePtr.h"
+
+namespace mozilla {
+
+class MediaPipelineFactory
+{
+public:
+  explicit MediaPipelineFactory(PeerConnectionMedia* aPCMedia)
+      : mPCMedia(aPCMedia), mPC(aPCMedia->GetPC())
+  {
+  }
+
+  nsresult CreateMediaPipeline(const JsepTrackPair& aTrackPair,
+                               const JsepTrack& aTrack);
+
+private:
+  nsresult CreateMediaPipelineReceiving(
+      RefPtr<TransportFlow> aRtpFlow,
+      RefPtr<TransportFlow> aRtcpFlow,
+      RefPtr<TransportFlow> aBundleRtpFlow,
+      RefPtr<TransportFlow> aBundleRtcpFlow,
+      const JsepTrackPair& aTrackPair,
+      const JsepTrack& aTrack,
+      const RefPtr<MediaSessionConduit>& aConduit);
+
+  nsresult CreateMediaPipelineSending(
+      RefPtr<TransportFlow> aRtpFlow,
+      RefPtr<TransportFlow> aRtcpFlow,
+      RefPtr<TransportFlow> aBundleRtpFlow,
+      RefPtr<TransportFlow> aBundleRtcpFlow,
+      const JsepTrackPair& aTrackPair,
+      const JsepTrack& aTrack,
+      const RefPtr<MediaSessionConduit>& aConduit);
+
+  nsresult CreateAudioConduit(const JsepTrackPair& aTrackPair,
+                              const JsepTrack& aTrack,
+                              RefPtr<MediaSessionConduit>* aConduitp);
+
+  nsresult CreateVideoConduit(const JsepTrackPair& aTrackPair,
+                              const JsepTrack& aTrack,
+                              RefPtr<MediaSessionConduit>* aConduitp);
+
+  MediaConduitErrorCode EnsureExternalCodec(VideoSessionConduit& aConduit,
+                                            VideoCodecConfig* aConfig,
+                                            bool aIsSend);
+
+  nsresult CreateOrGetTransportFlow(size_t aLevel, bool aIsRtcp,
+                                    const JsepTransport& transport,
+                                    RefPtr<TransportFlow>* out);
+
+private:
+  // Not owned, and assumed to exist as long as the factory.
+  // The factory is a transient object, so this is fairly easy.
+  PeerConnectionMedia* mPCMedia;
+  PeerConnectionImpl* mPC;
+};
+
+} // namespace mozilla
+
+#endif
--- a/media/webrtc/signaling/src/peerconnection/MediaStreamList.cpp
+++ b/media/webrtc/signaling/src/peerconnection/MediaStreamList.cpp
@@ -10,17 +10,17 @@
 #endif
 #include "nsIScriptGlobalObject.h"
 #include "PeerConnectionImpl.h"
 #include "PeerConnectionMedia.h"
 
 namespace mozilla {
 namespace dom {
 
-MediaStreamList::MediaStreamList(sipcc::PeerConnectionImpl* peerConnection,
+MediaStreamList::MediaStreamList(PeerConnectionImpl* peerConnection,
                                  StreamType type)
   : mPeerConnection(peerConnection),
     mType(type)
 {
 }
 
 MediaStreamList::~MediaStreamList()
 {
@@ -78,21 +78,21 @@ DOMMediaStream*
 MediaStreamList::IndexedGetter(uint32_t index, bool& found)
 {
   if (!mPeerConnection->media()) { // PeerConnection closed
     found = false;
     return nullptr;
   }
   if (mType == Local) {
     return GetStreamFromInfo(mPeerConnection->media()->
-      GetLocalStream(index), found);
+      GetLocalStreamByIndex(index), found);
   }
 
   return GetStreamFromInfo(mPeerConnection->media()->
-    GetRemoteStream(index), found);
+    GetRemoteStreamByIndex(index), found);
 }
 
 uint32_t
 MediaStreamList::Length()
 {
   if (!mPeerConnection->media()) { // PeerConnection closed
     return 0;
   }
--- a/media/webrtc/signaling/src/peerconnection/MediaStreamList.h
+++ b/media/webrtc/signaling/src/peerconnection/MediaStreamList.h
@@ -11,47 +11,44 @@
 #include "nsWrapperCache.h"
 
 #ifdef USE_FAKE_MEDIA_STREAMS
 #include "FakeMediaStreams.h"
 #else
 #include "DOMMediaStream.h"
 #endif
 
-namespace sipcc {
+namespace mozilla {
 class PeerConnectionImpl;
-} // namespace sipcc
-
-namespace mozilla {
 namespace dom {
 
 class MediaStreamList : public nsISupports,
                         public nsWrapperCache
 {
 public:
   enum StreamType {
     Local,
     Remote
   };
 
-  MediaStreamList(sipcc::PeerConnectionImpl* peerConnection, StreamType type);
+  MediaStreamList(PeerConnectionImpl* peerConnection, StreamType type);
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaStreamList)
 
   virtual JSObject* WrapObject(JSContext *cx)
     MOZ_OVERRIDE;
   nsISupports* GetParentObject();
 
   DOMMediaStream* IndexedGetter(uint32_t index, bool& found);
   uint32_t Length();
 
 private:
   virtual ~MediaStreamList();
 
-  nsRefPtr<sipcc::PeerConnectionImpl> mPeerConnection;
+  nsRefPtr<PeerConnectionImpl> mPeerConnection;
   StreamType mType;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // MediaStreamList_h__
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp
@@ -1,29 +1,18 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "CSFLog.h"
 
 #include "base/histogram.h"
-#include "CallControlManager.h"
-#include "CC_Device.h"
-#include "CC_Call.h"
-#include "CC_Observer.h"
-#include "ccapi_call_info.h"
-#include "CC_SIPCCCallInfo.h"
-#include "ccapi_device_info.h"
-#include "CC_SIPCCDeviceInfo.h"
-#include "vcm.h"
-#include "VcmSIPCCBinding.h"
 #include "PeerConnectionImpl.h"
 #include "PeerConnectionCtx.h"
 #include "runnable_utils.h"
-#include "debug-psipcc-types.h"
 #include "prcvar.h"
 
 #include "mozilla/Telemetry.h"
 
 #ifdef MOZILLA_INTERNAL_API
 #include "mozilla/dom/RTCPeerConnectionBinding.h"
 #include "mozilla/Preferences.h"
 #include <mozilla/Types.h>
@@ -37,66 +26,16 @@
 #include "StaticPtr.h"
 
 static const char* logTag = "PeerConnectionCtx";
 
 namespace mozilla {
 
 using namespace dom;
 
-// Convert constraints to C structures
-
-#ifdef MOZILLA_INTERNAL_API
-static void
-Apply(const Optional<bool> &aSrc, cc_boolean_option_t *aDst) {
-  if (aSrc.WasPassed()) {
-    aDst->was_passed = true;
-    aDst->value = aSrc.Value();
-  }
-}
-
-static void
-Apply(const Optional<int32_t> &aSrc, cc_int32_option_t *aDst) {
-  if (aSrc.WasPassed()) {
-    aDst->was_passed = true;
-    aDst->value = aSrc.Value();
-  }
-}
-#endif
-
-SipccOfferOptions::SipccOfferOptions() {
-  memset(&mOptions, 0, sizeof(mOptions));
-}
-
-SipccOfferOptions::SipccOfferOptions(
-    const RTCOfferOptions &aSrc) {
-  cc_media_options_t* c = &mOptions;
-  memset(c, 0, sizeof(*c));
-#ifdef MOZILLA_INTERNAL_API
-  Apply(aSrc.mOfferToReceiveAudio, &c->offer_to_receive_audio);
-  Apply(aSrc.mOfferToReceiveVideo, &c->offer_to_receive_video);
-  if (!Preferences::GetBool("media.peerconnection.video.enabled", true)) {
-    c->offer_to_receive_video.was_passed = true;
-    c->offer_to_receive_video.value = false;
-  }
-  Apply(aSrc.mMozDontOfferDataChannel, &c->moz_dont_offer_datachannel);
-  Apply(aSrc.mMozBundleOnly, &c->moz_bundle_only);
-#endif
-}
-
-cc_media_options_t*
-SipccOfferOptions::build() const {
-  cc_media_options_t* cc  = (cc_media_options_t*)
-    cpr_malloc(sizeof(cc_media_options_t));
-  if (cc) {
-    *cc = mOptions;
-  }
-  return cc;
-}
-
 class PeerConnectionCtxShutdown : public nsIObserver
 {
 public:
   NS_DECL_ISUPPORTS
 
   PeerConnectionCtxShutdown() {}
 
   void Init()
@@ -116,30 +55,30 @@ public:
 #endif
       (void) rv;
     }
 
   NS_IMETHODIMP Observe(nsISupports* aSubject, const char* aTopic,
                         const char16_t* aData) {
     if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
       CSFLogDebug(logTag, "Shutting down PeerConnectionCtx");
-      sipcc::PeerConnectionCtx::Destroy();
+      PeerConnectionCtx::Destroy();
 
       nsCOMPtr<nsIObserverService> observerService =
         services::GetObserverService();
       if (!observerService)
         return NS_ERROR_FAILURE;
 
       nsresult rv = observerService->RemoveObserver(this,
                                                     NS_XPCOM_SHUTDOWN_OBSERVER_ID);
       MOZ_ALWAYS_TRUE(NS_SUCCEEDED(rv));
 
       // Make sure we're not deleted while still inside ::Observe()
       nsRefPtr<PeerConnectionCtxShutdown> kungFuDeathGrip(this);
-      sipcc::PeerConnectionCtx::gPeerConnectionCtxShutdown = nullptr;
+      PeerConnectionCtx::gPeerConnectionCtxShutdown = nullptr;
     }
     return NS_OK;
   }
 
 private:
   virtual ~PeerConnectionCtxShutdown()
     {
       nsCOMPtr<nsIObserverService> observerService =
@@ -147,28 +86,26 @@ private:
       if (observerService)
         observerService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
     }
 };
 
 NS_IMPL_ISUPPORTS(PeerConnectionCtxShutdown, nsIObserver);
 }
 
-using namespace mozilla;
-namespace sipcc {
+namespace mozilla {
 
 PeerConnectionCtx* PeerConnectionCtx::gInstance;
 nsIThread* PeerConnectionCtx::gMainThread;
 StaticRefPtr<PeerConnectionCtxShutdown> PeerConnectionCtx::gPeerConnectionCtxShutdown;
 
 nsresult PeerConnectionCtx::InitializeGlobal(nsIThread *mainThread,
   nsIEventTarget* stsThread) {
   if (!gMainThread) {
     gMainThread = mainThread;
-    CSF::VcmSIPCCBinding::setMainThread(gMainThread);
   } else {
     MOZ_ASSERT(gMainThread == mainThread);
   }
 
   nsresult res;
 
   MOZ_ASSERT(NS_IsMainThread());
 
@@ -178,19 +115,19 @@ nsresult PeerConnectionCtx::InitializeGl
 
     res = ctx->Initialize();
     PR_ASSERT(NS_SUCCEEDED(res));
     if (!NS_SUCCEEDED(res))
       return res;
 
     gInstance = ctx;
 
-    if (!sipcc::PeerConnectionCtx::gPeerConnectionCtxShutdown) {
-      sipcc::PeerConnectionCtx::gPeerConnectionCtxShutdown = new PeerConnectionCtxShutdown();
-      sipcc::PeerConnectionCtx::gPeerConnectionCtxShutdown->Init();
+    if (!PeerConnectionCtx::gPeerConnectionCtxShutdown) {
+      PeerConnectionCtx::gPeerConnectionCtxShutdown = new PeerConnectionCtxShutdown();
+      PeerConnectionCtx::gPeerConnectionCtxShutdown->Init();
     }
   }
 
   return NS_OK;
 }
 
 PeerConnectionCtx* PeerConnectionCtx::GetInstance() {
   MOZ_ASSERT(gInstance);
@@ -358,72 +295,28 @@ PeerConnectionCtx::EverySecondTelemetryC
                      NS_DISPATCH_NORMAL);
   NS_ENSURE_SUCCESS_VOID(rv);
 }
 #endif
 
 nsresult PeerConnectionCtx::Initialize() {
   initGMP();
 
-  mCCM = CSF::CallControlManager::create();
-
-  NS_ENSURE_TRUE(mCCM.get(), NS_ERROR_FAILURE);
-
-  // Add the local audio codecs
-  // FIX - Get this list from MediaEngine instead
-  int codecMask = 0;
-  codecMask |= VCM_CODEC_RESOURCE_G711;
-  codecMask |= VCM_CODEC_RESOURCE_OPUS;
-  //codecMask |= VCM_CODEC_RESOURCE_LINEAR;
-  codecMask |= VCM_CODEC_RESOURCE_G722;
-  //codecMask |= VCM_CODEC_RESOURCE_iLBC;
-  //codecMask |= VCM_CODEC_RESOURCE_iSAC;
-  mCCM->setAudioCodecs(codecMask);
-
-  //Add the local video codecs
-  // FIX - Get this list from MediaEngine instead
-  // Turning them all on for now
-  codecMask = 0;
-  // Only adding codecs supported
-  //codecMask |= VCM_CODEC_RESOURCE_H263;
-
-#ifdef MOZILLA_INTERNAL_API
-#ifdef MOZ_WEBRTC_OMX
-  if (Preferences::GetBool("media.peerconnection.video.h264_enabled")) {
-    codecMask |= VCM_CODEC_RESOURCE_H264;
-  }
-#endif
-#else
-  // Outside MOZILLA_INTERNAL_API ensures H.264 available in unit tests
-  codecMask |= VCM_CODEC_RESOURCE_H264;
-#endif
-
-  codecMask |= VCM_CODEC_RESOURCE_VP8;
-  //codecMask |= VCM_CODEC_RESOURCE_I420;
-  mCCM->setVideoCodecs(codecMask);
-  mCCM->addCCObserver(this);
-  ChangeSipccState(dom::PCImplSipccState::Starting);
-
-  if (!mCCM->startSDPMode())
-    return NS_ERROR_FAILURE;
-
-  mDevice = mCCM->getActiveDevice();
-  NS_ENSURE_TRUE(mDevice.get(), NS_ERROR_FAILURE);
-
 #ifdef MOZILLA_INTERNAL_API
   mConnectionCounter = 0;
   Telemetry::GetHistogramById(Telemetry::WEBRTC_CALL_COUNT)->Add(0);
 
   mTelemetryTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
   MOZ_ASSERT(mTelemetryTimer);
   nsresult rv = mTelemetryTimer->SetTarget(gMainThread);
   NS_ENSURE_SUCCESS(rv, rv);
   mTelemetryTimer->InitWithFuncCallback(EverySecondTelemetryCallback_m, this, 1000,
                                         nsITimer::TYPE_REPEATING_PRECISE_CAN_SKIP);
-#endif
+#endif // MOZILLA_INTERNAL_API
+
   return NS_OK;
 }
 
 static void GMPReady_m() {
   if (PeerConnectionCtx::isActive()) {
     PeerConnectionCtx::GetInstance()->onGMPReady();
   }
 };
@@ -459,72 +352,63 @@ void PeerConnectionCtx::initGMP()
   thread->Dispatch(WrapRunnableNM(&GMPReady), NS_DISPATCH_NORMAL);
 }
 
 nsresult PeerConnectionCtx::Cleanup() {
   CSFLogDebug(logTag, "%s", __FUNCTION__);
 
   mQueuedJSEPOperations.Clear();
   mGMPService = nullptr;
-
-  mCCM->destroy();
-  mCCM->removeCCObserver(this);
   return NS_OK;
 }
 
 PeerConnectionCtx::~PeerConnectionCtx() {
     // ensure mTelemetryTimer ends on main thread
   MOZ_ASSERT(NS_IsMainThread());
 #ifdef MOZILLA_INTERNAL_API
   if (mTelemetryTimer) {
     mTelemetryTimer->Cancel();
   }
 #endif
 };
 
-CSF::CC_CallPtr PeerConnectionCtx::createCall() {
-  return mDevice->createCall();
-}
-
 void PeerConnectionCtx::queueJSEPOperation(nsRefPtr<nsIRunnable> aOperation) {
   mQueuedJSEPOperations.AppendElement(aOperation);
 }
 
 void PeerConnectionCtx::onGMPReady() {
   mGMPReady = true;
   for (size_t i = 0; i < mQueuedJSEPOperations.Length(); ++i) {
     mQueuedJSEPOperations[i]->Run();
   }
   mQueuedJSEPOperations.Clear();
 }
 
-void PeerConnectionCtx::onDeviceEvent(ccapi_device_event_e aDeviceEvent,
-                                      CSF::CC_DevicePtr aDevice,
-                                      CSF::CC_DeviceInfoPtr aInfo ) {
-  cc_service_state_t state = aInfo->getServiceState();
-  // We are keeping this in a local var to avoid a data race
-  // with ChangeSipccState in the debug message and compound if below
-  dom::PCImplSipccState currentSipccState = mSipccState;
+bool PeerConnectionCtx::gmpHasH264() {
+  if (!mGMPService) {
+    return false;
+  }
 
-  switch (aDeviceEvent) {
-    case CCAPI_DEVICE_EV_STATE:
-      CSFLogDebug(logTag, "%s - %d : %d", __FUNCTION__, state,
-                  static_cast<uint32_t>(currentSipccState));
+  // XXX I'd prefer if this was all known ahead of time...
+
+  nsTArray<nsCString> tags;
+  tags.AppendElement(NS_LITERAL_CSTRING("h264"));
 
-      if (CC_STATE_INS == state) {
-        // SIPCC is up
-        if (dom::PCImplSipccState::Starting == currentSipccState ||
-            dom::PCImplSipccState::Idle == currentSipccState) {
-          ChangeSipccState(dom::PCImplSipccState::Started);
-        } else {
-          CSFLogError(logTag, "%s PeerConnection already started", __FUNCTION__);
-        }
-      } else {
-        NS_NOTREACHED("Unsupported Signaling State Transition");
-      }
-      break;
-    default:
-      CSFLogDebug(logTag, "%s: Ignoring event: %s\n",__FUNCTION__,
-                  device_event_getname(aDeviceEvent));
+  bool has_gmp;
+  nsresult rv;
+  rv = mGMPService->HasPluginForAPI(NS_LITERAL_CSTRING("encode-video"),
+                                    &tags,
+                                    &has_gmp);
+  if (NS_FAILED(rv) || !has_gmp) {
+    return false;
   }
+
+  rv = mGMPService->HasPluginForAPI(NS_LITERAL_CSTRING("decode-video"),
+                                    &tags,
+                                    &has_gmp);
+  if (NS_FAILED(rv) || !has_gmp) {
+    return false;
+  }
+
+  return true;
 }
 
-}  // namespace sipcc
+}  // namespace mozilla
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.h
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.h
@@ -3,126 +3,77 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef peerconnectionctx_h___h__
 #define peerconnectionctx_h___h__
 
 #include <string>
 
 #include "mozilla/Attributes.h"
-#include "CallControlManager.h"
-#include "CC_Device.h"
-#include "CC_DeviceInfo.h"
-#include "CC_Call.h"
-#include "CC_CallInfo.h"
-#include "CC_Line.h"
-#include "CC_LineInfo.h"
-#include "CC_Observer.h"
-#include "CC_FeatureInfo.h"
-#include "cpr_stdlib.h"
-
 #include "StaticPtr.h"
 #include "PeerConnectionImpl.h"
 #include "mozIGeckoMediaPluginService.h"
 #include "nsIRunnable.h"
 
 namespace mozilla {
 class PeerConnectionCtxShutdown;
 
 namespace dom {
 class WebrtcGlobalInformation;
 }
 
-// Unit-test helper, because cc_media_options_t is hard to forward-declare
-
-class SipccOfferOptions {
-public:
-  SipccOfferOptions();
-  explicit SipccOfferOptions(const dom::RTCOfferOptions &aOther);
-  cc_media_options_t* build() const;
-protected:
-  cc_media_options_t mOptions;
-};
-}
-
-namespace sipcc {
-
-class OnCallEventArgs {
-public:
-  OnCallEventArgs(ccapi_call_event_e aCallEvent, CSF::CC_CallInfoPtr aInfo)
-  : mCallEvent(aCallEvent), mInfo(aInfo) {}
-
-  ccapi_call_event_e mCallEvent;
-  CSF::CC_CallInfoPtr mInfo;
-};
-
 // A class to hold some of the singleton objects we need:
 // * The global PeerConnectionImpl table and its associated lock.
-// * Currently SIPCC only allows a single stack instance to exist in a process
-//   at once. This class implements a singleton object that wraps that.
-// * The observer class that demuxes events onto individual PCs.
-class PeerConnectionCtx : public CSF::CC_Observer {
+// * Stats report objects for PCs that are gone
+// * GMP related state
+class PeerConnectionCtx {
  public:
   static nsresult InitializeGlobal(nsIThread *mainThread, nsIEventTarget *stsThread);
   static PeerConnectionCtx* GetInstance();
   static bool isActive();
   static void Destroy();
 
-  // Implementations of CC_Observer methods
-  virtual void onDeviceEvent(ccapi_device_event_e deviceEvent, CSF::CC_DevicePtr device, CSF::CC_DeviceInfoPtr info);
-  virtual void onFeatureEvent(ccapi_device_event_e deviceEvent, CSF::CC_DevicePtr device, CSF::CC_FeatureInfoPtr feature_info) {}
-  virtual void onLineEvent(ccapi_line_event_e lineEvent, CSF::CC_LinePtr line, CSF::CC_LineInfoPtr info) {}
-  virtual void onCallEvent(ccapi_call_event_e callEvent, CSF::CC_CallPtr call, CSF::CC_CallInfoPtr info) {}
-
-  // Create a SIPCC Call
-  CSF::CC_CallPtr createCall();
-
-  mozilla::dom::PCImplSipccState sipcc_state() { return mSipccState; }
-
   bool isReady() {
     // If mGMPService is not set, we aren't using GMP.
     if (mGMPService) {
       return mGMPReady;
     }
     return true;
   }
 
   void queueJSEPOperation(nsRefPtr<nsIRunnable> aJSEPOperation);
   void onGMPReady();
 
+  bool gmpHasH264();
+
   // Make these classes friend so that they can access mPeerconnections.
   friend class PeerConnectionImpl;
   friend class PeerConnectionWrapper;
   friend class mozilla::dom::WebrtcGlobalInformation;
 
 #ifdef MOZILLA_INTERNAL_API
   // WebrtcGlobalInformation uses this; we put it here so we don't need to
   // create another shutdown observer class.
   mozilla::dom::Sequence<mozilla::dom::RTCStatsReportInternal>
     mStatsForClosedPeerConnections;
 #endif
 
  private:
   // We could make these available only via accessors but it's too much trouble.
   std::map<const std::string, PeerConnectionImpl *> mPeerConnections;
 
-  PeerConnectionCtx() :  mSipccState(mozilla::dom::PCImplSipccState::Idle),
-                         mCCM(nullptr), mDevice(nullptr), mGMPReady(false) {}
+  PeerConnectionCtx() :  mGMPReady(false) {}
   // This is a singleton, so don't copy construct it, etc.
   PeerConnectionCtx(const PeerConnectionCtx& other) MOZ_DELETE;
   void operator=(const PeerConnectionCtx& other) MOZ_DELETE;
   virtual ~PeerConnectionCtx();
 
   nsresult Initialize();
   nsresult Cleanup();
 
-  void ChangeSipccState(mozilla::dom::PCImplSipccState aState) {
-    mSipccState = aState;
-  }
-
   void initGMP();
 
   static void
   EverySecondTelemetryCallback_m(nsITimer* timer, void *);
 
 #ifdef MOZILLA_INTERNAL_API
   // Telemetry Peer conection counter
   int mConnectionCounter;
@@ -131,31 +82,26 @@ class PeerConnectionCtx : public CSF::CC
 
 public:
   // TODO(jib): If we ever enable move semantics on std::map...
   //std::map<nsString,nsAutoPtr<mozilla::dom::RTCStatsReportInternal>> mLastReports;
   nsTArray<nsAutoPtr<mozilla::dom::RTCStatsReportInternal>> mLastReports;
 private:
 #endif
 
-  // SIPCC objects
-  mozilla::dom::PCImplSipccState mSipccState;  // TODO(ekr@rtfm.com): refactor this out? What does it do?
-  CSF::CallControlManagerPtr mCCM;
-  CSF::CC_DevicePtr mDevice;
-
   // We cannot form offers/answers properly until the Gecko Media Plugin stuff
   // has been initted, which is a complicated mess of thread dispatches,
   // including sync dispatches to main. So, we need to be able to queue up
   // offer creation (or SetRemote, when we're the answerer) until all of this is
   // ready to go, since blocking on this init is just begging for deadlock.
   nsCOMPtr<mozIGeckoMediaPluginService> mGMPService;
   bool mGMPReady;
   nsTArray<nsRefPtr<nsIRunnable>> mQueuedJSEPOperations;
 
   static PeerConnectionCtx *gInstance;
 public:
   static nsIThread *gMainThread;
   static mozilla::StaticRefPtr<mozilla::PeerConnectionCtxShutdown> gPeerConnectionCtxShutdown;
 };
 
-}  // namespace sipcc
+}  // namespace mozilla
 
 #endif
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -1,53 +1,55 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <cstdlib>
 #include <cerrno>
 #include <deque>
+#include <set>
 #include <sstream>
+#include <vector>
 
 #include "base/histogram.h"
-#include "vcm.h"
 #include "CSFLog.h"
 #include "timecard.h"
-#include "ccapi_call_info.h"
-#include "CC_SIPCCCallInfo.h"
-#include "ccapi_device_info.h"
-#include "CC_SIPCCDeviceInfo.h"
-#include "cpr_string.h"
-#include "cpr_stdlib.h"
 
 #include "jsapi.h"
 #include "nspr.h"
 #include "nss.h"
 #include "pk11pub.h"
 
 #include "nsNetCID.h"
 #include "nsIProperty.h"
 #include "nsIPropertyBag2.h"
 #include "nsIServiceManager.h"
 #include "nsISimpleEnumerator.h"
 #include "nsServiceManagerUtils.h"
 #include "nsISocketTransportService.h"
 #include "nsIConsoleService.h"
 #include "nsThreadUtils.h"
+#include "nsIPrefService.h"
+#include "nsIPrefBranch.h"
 #include "nsProxyRelease.h"
 #include "prtime.h"
 
 #include "AudioConduit.h"
 #include "VideoConduit.h"
 #include "runnable_utils.h"
 #include "PeerConnectionCtx.h"
 #include "PeerConnectionImpl.h"
 #include "PeerConnectionMedia.h"
 #include "nsDOMDataChannelDeclarations.h"
 #include "dtlsidentity.h"
+#include "signaling/src/sdp/SdpAttribute.h"
+
+#include "signaling/src/jsep/JsepTrack.h"
+#include "signaling/src/jsep/JsepSession.h"
+#include "signaling/src/jsep/JsepSessionImpl.h"
 
 #ifdef MOZILLA_INTERNAL_API
 #ifdef XP_WIN
 // We need to undef the MS macro for nsIDocument::CreateEvent
 #ifdef CreateEvent
 #undef CreateEvent
 #endif
 #endif // XP_WIN
@@ -85,16 +87,17 @@
 #include "VideoStreamTrack.h"
 #include "nsIScriptGlobalObject.h"
 #include "DOMMediaStream.h"
 #include "rlogringbuffer.h"
 #include "WebrtcGlobalInformation.h"
 #include "mozilla/dom/Event.h"
 #include "nsIDOMCustomEvent.h"
 #include "mozilla/EventDispatcher.h"
+#include "mozilla/net/DataChannelProtocol.h"
 #endif
 
 #ifdef XP_WIN
 // We need to undef the MS macro again in case the windows include file
 // got imported after we included nsIDocument.h
 #ifdef CreateEvent
 #undef CreateEvent
 #endif
@@ -106,25 +109,118 @@
 
 #ifdef USE_FAKE_PCOBSERVER
 #include "FakePCObserver.h"
 #else
 #include "mozilla/dom/PeerConnectionObserverBinding.h"
 #endif
 #include "mozilla/dom/PeerConnectionObserverEnumsBinding.h"
 
+#ifdef MOZ_WEBRTC_OMX
+#include "OMXVideoCodec.h"
+#include "OMXCodecWrapper.h"
+#endif
+
 #define ICE_PARSING "In RTCConfiguration passed to RTCPeerConnection constructor"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 typedef PCObserverString ObString;
 
 static const char* logTag = "PeerConnectionImpl";
 
+
+// Getting exceptions back down from PCObserver is generally not harmful.
+namespace {
+class JSErrorResult : public ErrorResult
+{
+public:
+  ~JSErrorResult()
+  {
+#ifdef MOZILLA_INTERNAL_API
+    WouldReportJSException();
+    if (IsJSException()) {
+      MOZ_ASSERT(NS_IsMainThread());
+      AutoJSContext cx;
+      Optional<JS::Handle<JS::Value> > value(cx);
+      StealJSException(cx, &value.Value());
+    }
+#endif
+  }
+};
+
+// The WrapRunnable() macros copy passed-in args and passes them to the function
+// later on the other thread. ErrorResult cannot be passed like this because it
+// disallows copy-semantics.
+//
+// This WrappableJSErrorResult hack solves this by not actually copying the
+// ErrorResult, but creating a new one instead, which works because we don't
+// care about the result.
+//
+// Since this is for JS-calls, these can only be dispatched to the main thread.
+
+class WrappableJSErrorResult {
+public:
+  WrappableJSErrorResult() : isCopy(false) {}
+  WrappableJSErrorResult(WrappableJSErrorResult &other) : mRv(), isCopy(true) {}
+  ~WrappableJSErrorResult() {
+    if (isCopy) {
+      MOZ_ASSERT(NS_IsMainThread());
+    }
+  }
+  operator JSErrorResult &() { return mRv; }
+private:
+  JSErrorResult mRv;
+  bool isCopy;
+};
+}
+
+#ifdef MOZILLA_INTERNAL_API
+class TracksAvailableCallback : public DOMMediaStream::OnTracksAvailableCallback
+{
+public:
+  TracksAvailableCallback(DOMMediaStream::TrackTypeHints aTrackTypeHints,
+                          nsRefPtr<PeerConnectionObserver> aObserver)
+  : DOMMediaStream::OnTracksAvailableCallback(aTrackTypeHints)
+  , mObserver(aObserver) {}
+
+  virtual void NotifyTracksAvailable(DOMMediaStream* aStream) MOZ_OVERRIDE
+  {
+    MOZ_ASSERT(NS_IsMainThread());
+
+    // Start currentTime from the point where this stream was successfully
+    // returned.
+    aStream->SetLogicalStreamStartTime(aStream->GetStream()->GetCurrentTime());
+
+    CSFLogInfo(logTag, "Returning success for OnAddStream()");
+    // We are running on main thread here so we shouldn't have a race
+    // on this callback
+
+    nsTArray<nsRefPtr<MediaStreamTrack>> tracks;
+    aStream->GetTracks(tracks);
+    for (uint32_t i = 0; i < tracks.Length(); i++) {
+      JSErrorResult rv;
+      mObserver->OnAddTrack(*tracks[i], rv);
+      if (rv.Failed()) {
+        CSFLogError(logTag, ": OnAddTrack(%d) failed! Error: %d", i,
+                    rv.ErrorCode());
+      }
+    }
+    JSErrorResult rv;
+    mObserver->OnAddStream(*aStream, rv);
+    if (rv.Failed()) {
+      CSFLogError(logTag, ": OnAddStream() failed! Error: %d", rv.ErrorCode());
+    }
+  }
+private:
+  nsRefPtr<PeerConnectionObserver> mObserver;
+};
+#endif
+
 #ifdef MOZILLA_INTERNAL_API
 static nsresult InitNSSInContent()
 {
   NS_ENSURE_TRUE(NS_IsMainThread(), NS_ERROR_NOT_SAME_THREAD);
 
   if (XRE_GetProcessType() != GeckoProcessType_Content) {
     MOZ_ASSERT_UNREACHABLE("Must be called in content process");
     return NS_ERROR_FAILURE;
@@ -171,120 +267,99 @@ PRLogModuleInfo *signalingLogInfo() {
 
 // XXX Workaround for bug 998092 to maintain the existing broken semantics
 template<>
 struct nsISupportsWeakReference::COMTypeInfo<nsSupportsWeakReference, void> {
   static const nsIID kIID;
 };
 const nsIID nsISupportsWeakReference::COMTypeInfo<nsSupportsWeakReference, void>::kIID = NS_ISUPPORTSWEAKREFERENCE_IID;
 
-namespace sipcc {
+namespace mozilla {
 
 #ifdef MOZILLA_INTERNAL_API
 RTCStatsQuery::RTCStatsQuery(bool internal) :
   failed(false),
   internalStats(internal) {
 }
 
 RTCStatsQuery::~RTCStatsQuery() {
   MOZ_ASSERT(NS_IsMainThread());
 }
 
 #endif
 
-// Getting exceptions back down from PCObserver is generally not harmful.
-namespace {
-class JSErrorResult : public ErrorResult
-{
-public:
-  ~JSErrorResult()
-  {
-#ifdef MOZILLA_INTERNAL_API
-    WouldReportJSException();
-    if (IsJSException()) {
-      MOZ_ASSERT(NS_IsMainThread());
-      AutoJSContext cx;
-      Optional<JS::Handle<JS::Value> > value(cx);
-      StealJSException(cx, &value.Value());
-    }
-#endif
-  }
-};
-
-// The WrapRunnable() macros copy passed-in args and passes them to the function
-// later on the other thread. ErrorResult cannot be passed like this because it
-// disallows copy-semantics.
-//
-// This WrappableJSErrorResult hack solves this by not actually copying the
-// ErrorResult, but creating a new one instead, which works because we don't
-// care about the result.
-//
-// Since this is for JS-calls, these can only be dispatched to the main thread.
-
-class WrappableJSErrorResult {
-public:
-  WrappableJSErrorResult() : isCopy(false) {}
-  WrappableJSErrorResult(WrappableJSErrorResult &other) : mRv(), isCopy(true) {}
-  ~WrappableJSErrorResult() {
-    if (isCopy) {
-      MOZ_ASSERT(NS_IsMainThread());
-    }
-  }
-  operator JSErrorResult &() { return mRv; }
-private:
-  JSErrorResult mRv;
-  bool isCopy;
-};
-}
-
 NS_IMPL_ISUPPORTS0(PeerConnectionImpl)
 
 #ifdef MOZILLA_INTERNAL_API
 JSObject*
 PeerConnectionImpl::WrapObject(JSContext* aCx)
 {
   return PeerConnectionImplBinding::Wrap(aCx, this);
 }
 #endif
 
-struct PeerConnectionImpl::Internal {
-  CSF::CC_CallPtr mCall;
-};
+bool PCUuidGenerator::Generate(std::string* idp) {
+  nsresult rv;
+
+  if(!mGenerator) {
+    mGenerator = do_GetService("@mozilla.org/uuid-generator;1", &rv);
+    if (NS_FAILED(rv)) {
+      return false;
+    }
+    if (!mGenerator) {
+      return false;
+    }
+  }
+
+  nsID id;
+  rv = mGenerator->GenerateUUIDInPlace(&id);
+  if (NS_FAILED(rv)) {
+    return false;
+  }
+  char buffer[NSID_LENGTH];
+  id.ToProvidedString(buffer);
+  idp->assign(buffer);
+
+  return true;
+}
+
 
 PeerConnectionImpl::PeerConnectionImpl(const GlobalObject* aGlobal)
 : mTimeCard(PR_LOG_TEST(signalingLogInfo(),PR_LOG_ERROR) ?
             create_timecard() : nullptr)
-  , mInternal(new Internal())
   , mSignalingState(PCImplSignalingState::SignalingStable)
   , mIceConnectionState(PCImplIceConnectionState::New)
   , mIceGatheringState(PCImplIceGatheringState::New)
   , mDtlsConnected(false)
   , mWindow(nullptr)
   , mIdentity(nullptr)
   , mPrivacyRequested(false)
   , mSTSThread(nullptr)
   , mAllowIceLoopback(false)
   , mMedia(nullptr)
+  , mUuidGen(MakeUnique<PCUuidGenerator>())
   , mNumAudioStreams(0)
   , mNumVideoStreams(0)
   , mHaveDataStream(false)
-  , mNumMlines(0)
   , mAddCandidateErrorCount(0)
   , mTrickle(true) // TODO(ekr@rtfm.com): Use pref
 {
 #ifdef MOZILLA_INTERNAL_API
   MOZ_ASSERT(NS_IsMainThread());
   if (aGlobal) {
     mWindow = do_QueryInterface(aGlobal->GetAsSupports());
   }
 #endif
-  MOZ_ASSERT(mInternal);
   CSFLogInfo(logTag, "%s: PeerConnectionImpl constructor for %s",
              __FUNCTION__, mHandle.c_str());
   STAMP_TIMECARD(mTimeCard, "Constructor Completed");
+#ifdef MOZILLA_INTERNAL_API
+  mAllowIceLoopback = Preferences::GetBool(
+    "media.peerconnection.ice.loopback", false);
+#endif
 }
 
 PeerConnectionImpl::~PeerConnectionImpl()
 {
   if (mTimeCard) {
     STAMP_TIMECARD(mTimeCard, "Destructor Invoked");
     print_timecard(mTimeCard);
     destroy_timecard(mTimeCard);
@@ -295,17 +370,18 @@ PeerConnectionImpl::~PeerConnectionImpl(
   if (PeerConnectionCtx::isActive()) {
     PeerConnectionCtx::GetInstance()->mPeerConnections.erase(mHandle);
   } else {
     CSFLogError(logTag, "PeerConnectionCtx is already gone. Ignoring...");
   }
 
   CSFLogInfo(logTag, "%s: PeerConnectionImpl destructor invoked for %s",
              __FUNCTION__, mHandle.c_str());
-  CloseInt();
+
+  Close();
 
 #ifdef MOZILLA_INTERNAL_API
   {
     // Deregister as an NSS Shutdown Object
     nsNSSShutDownPreventionLock locker;
     if (!isAlreadyShutDown()) {
       destructorSafeDestroyNSSReference();
       shutdown(calledFromObject);
@@ -348,34 +424,35 @@ PeerConnectionImpl::MakeMediaStream(uint
 
   CSFLogDebug(logTag, "Created media stream %p, inner: %p", stream.get(), stream->GetStream());
 
   return stream.forget();
 }
 
 nsresult
 PeerConnectionImpl::CreateRemoteSourceStreamInfo(nsRefPtr<RemoteSourceStreamInfo>*
-                                                 aInfo)
+                                                 aInfo,
+                                                 const std::string& aStreamID)
 {
   MOZ_ASSERT(aInfo);
   PC_AUTO_ENTER_API_CALL_NO_CHECK();
 
   // We need to pass a dummy hint here because FakeMediaStream currently
   // needs to actually propagate a hint for local streams.
   // TODO(ekr@rtfm.com): Clean up when we have explicit track lists.
   // See bug 834835.
   nsRefPtr<DOMMediaStream> stream = MakeMediaStream(0);
   if (!stream) {
     return NS_ERROR_FAILURE;
   }
 
   static_cast<SourceMediaStream*>(stream->GetStream())->SetPullEnabled(true);
 
   nsRefPtr<RemoteSourceStreamInfo> remote;
-  remote = new RemoteSourceStreamInfo(stream.forget(), mMedia);
+  remote = new RemoteSourceStreamInfo(stream.forget(), mMedia, aStreamID);
   *aInfo = remote;
 
   return NS_OK;
 }
 
 /**
  * In JS, an RTCConfiguration looks like this:
  *
@@ -585,25 +662,16 @@ PeerConnectionImpl::Initialize(PeerConne
     handle_bin[7]);
 
   mHandle = hex;
 
   STAMP_TIMECARD(mTimeCard, "Initializing PC Ctx");
   res = PeerConnectionCtx::InitializeGlobal(mThread, mSTSThread);
   NS_ENSURE_SUCCESS(res, res);
 
-  PeerConnectionCtx *pcctx = PeerConnectionCtx::GetInstance();
-  MOZ_ASSERT(pcctx);
-  STAMP_TIMECARD(mTimeCard, "Done Initializing PC Ctx");
-
-  mInternal->mCall = pcctx->createCall();
-  if (!mInternal->mCall.get()) {
-    CSFLogError(logTag, "%s: Couldn't Create Call Object", __FUNCTION__);
-    return NS_ERROR_FAILURE;
-  }
 
   IceConfiguration converted;
   if (aRTCConfiguration) {
     res = ConvertRTCConfiguration(*aRTCConfiguration, &converted);
     if (NS_FAILED(res)) {
       CSFLogError(logTag, "%s: Invalid RTCConfiguration", __FUNCTION__);
       return res;
     }
@@ -612,104 +680,249 @@ PeerConnectionImpl::Initialize(PeerConne
 
   mMedia = new PeerConnectionMedia(this);
   mMedia->SetAllowIceLoopback(mAllowIceLoopback);
 
   // Connect ICE slots.
   mMedia->SignalIceGatheringStateChange.connect(
       this,
       &PeerConnectionImpl::IceGatheringStateChange);
+  mMedia->SignalEndOfLocalCandidates.connect(
+      this,
+      &PeerConnectionImpl::EndOfLocalCandidates);
   mMedia->SignalIceConnectionStateChange.connect(
       this,
       &PeerConnectionImpl::IceConnectionStateChange);
 
   mMedia->SignalCandidate.connect(this, &PeerConnectionImpl::CandidateReady);
 
   // Initialize the media object.
   res = mMedia->Init(aConfiguration->getStunServers(),
                      aConfiguration->getTurnServers());
   if (NS_FAILED(res)) {
     CSFLogError(logTag, "%s: Couldn't initialize media object", __FUNCTION__);
     return res;
   }
 
-  // Store under mHandle
-  mInternal->mCall->setPeerConnection(mHandle);
   PeerConnectionCtx::GetInstance()->mPeerConnections[mHandle] = this;
 
   STAMP_TIMECARD(mTimeCard, "Generating DTLS Identity");
   // Create the DTLS Identity
   mIdentity = DtlsIdentity::Generate();
   STAMP_TIMECARD(mTimeCard, "Done Generating DTLS Identity");
 
   if (!mIdentity) {
     CSFLogError(logTag, "%s: Generate returned NULL", __FUNCTION__);
     return NS_ERROR_FAILURE;
   }
 
-  mFingerprint = mIdentity->GetFormattedFingerprint();
-  if (mFingerprint.empty()) {
-    CSFLogError(logTag, "%s: unable to get fingerprint", __FUNCTION__);
+  mJsepSession = MakeUnique<JsepSessionImpl>(mName,
+                                             MakeUnique<PCUuidGenerator>());
+
+  res = mJsepSession->Init();
+  if (NS_FAILED(res)) {
+    CSFLogError(logTag, "%s: Couldn't init JSEP Session, res=%u",
+                        __FUNCTION__,
+                        static_cast<unsigned>(res));
+    return res;
+  }
+
+  res = mJsepSession->SetIceCredentials(mMedia->ice_ctx()->ufrag(),
+                                        mMedia->ice_ctx()->pwd());
+  if (NS_FAILED(res)) {
+    CSFLogError(logTag, "%s: Couldn't set ICE credentials, res=%u",
+                         __FUNCTION__,
+                         static_cast<unsigned>(res));
+    return res;
+  }
+
+  const std::string& fpAlg = DtlsIdentity::DEFAULT_HASH_ALGORITHM;
+  std::vector<uint8_t> fingerprint;
+  res = CalculateFingerprint(fpAlg, fingerprint);
+  NS_ENSURE_SUCCESS(res, res);
+  res = mJsepSession->AddDtlsFingerprint(fpAlg, fingerprint);
+  if (NS_FAILED(res)) {
+    CSFLogError(logTag, "%s: Couldn't set DTLS credentials, res=%u",
+                        __FUNCTION__,
+                        static_cast<unsigned>(res));
+    return res;
+  }
+
+  return NS_OK;
+}
+
+class CompareCodecPriority {
+  public:
+    explicit CompareCodecPriority(int32_t preferredCodec) {
+      // This pref really ought to be a string, preferably something like
+      // "H264" or "VP8" instead of a payload type.
+      // Bug 1101259.
+      std::ostringstream os;
+      os << preferredCodec;
+      mPreferredCodec = os.str();
+    }
+
+    bool operator()(JsepCodecDescription* lhs,
+                    JsepCodecDescription* rhs) const {
+      return !mPreferredCodec.empty() &&
+             lhs->mDefaultPt == mPreferredCodec &&
+             rhs->mDefaultPt != mPreferredCodec;
+    }
+
+  private:
+    std::string mPreferredCodec;
+};
+
+nsresult
+PeerConnectionImpl::ConfigureJsepSessionCodecs() {
+  nsresult res;
+  nsCOMPtr<nsIPrefService> prefs =
+    do_GetService("@mozilla.org/preferences-service;1", &res);
+
+  if (NS_FAILED(res)) {
+    CSFLogError(logTag, "%s: Couldn't get prefs service, res=%u",
+                        __FUNCTION__,
+                        static_cast<unsigned>(res));
     return res;
   }
 
+  nsCOMPtr<nsIPrefBranch> branch = do_QueryInterface(prefs);
+  if (!branch) {
+    CSFLogError(logTag, "%s: Couldn't get prefs branch", __FUNCTION__);
+    return NS_ERROR_FAILURE;
+  }
+
+
+  bool hardwareH264Supported = false;
+
+#ifdef MOZ_WEBRTC_OMX
+  bool hardwareH264Enabled = false;
+
+  // Check to see if what HW codecs are available (not in use) at this moment.
+  // Note that streaming video decode can reserve a decoder
+
+  // XXX See bug 1018791 Implement W3 codec reservation policy
+  // Note that currently, OMXCodecReservation needs to be held by an sp<> because it puts
+  // 'this' into an sp<EventListener> to talk to the resource reservation code
+
+  // This pref is a misnomer; it is solely for h264 _hardware_ support.
+  branch->GetBoolPref("media.peerconnection.video.h264_enabled",
+                      &hardwareH264Enabled);
+
+  if (hardwareH264Enabled) {
+    // Ok, it is preffed on. Can we actually do it?
+    android::sp<android::OMXCodecReservation> encode = new android::OMXCodecReservation(true);
+    android::sp<android::OMXCodecReservation> decode = new android::OMXCodecReservation(false);
+
+    // Currently we just check if they're available right now, which will fail if we're
+    // trying to call ourself, for example.  It will work for most real-world cases, like
+    // if we try to add a person to a 2-way call to make a 3-way mesh call
+    if (encode->ReserveOMXCodec() && decode->ReserveOMXCodec()) {
+      CSFLogDebug( logTag, "%s: H264 hardware codec available", __FUNCTION__);
+      hardwareH264Supported = true;
+    }
+  }
+
+#endif // MOZ_WEBRTC_OMX
+
+#ifdef MOZILLA_INTERNAL_API
+  bool softwareH264Enabled = PeerConnectionCtx::GetInstance()->gmpHasH264();
+#else
+  // For unit-tests
+  bool softwareH264Enabled = true;
+#endif
+
+  bool h264Enabled = hardwareH264Supported || softwareH264Enabled;
+
+  auto codecs = mJsepSession->Codecs();
+
+  // Set parameters
+  for (auto i = codecs.begin(); i != codecs.end(); ++i) {
+    auto &codec = **i;
+    switch (codec.mType) {
+      case SdpMediaSection::kAudio:
+        // Nothing to configure here, for now.
+        break;
+      case SdpMediaSection::kVideo:
+        {
+          JsepVideoCodecDescription& videoCodec =
+            static_cast<JsepVideoCodecDescription&>(codec);
+
+          if (videoCodec.mName == "H264") {
+            int32_t level = 13; // minimum suggested for WebRTC spec
+            branch->GetIntPref("media.navigator.video.h264.level", &level);
+            level &= 0xFF;
+            // Override level
+            videoCodec.mProfileLevelId &= 0xFFFF00;
+            videoCodec.mProfileLevelId |= level;
+
+            int32_t maxBr = 0; // Unlimited
+            branch->GetIntPref("media.navigator.video.h264.max_br", &maxBr);
+            videoCodec.mMaxBr = maxBr;
+
+            int32_t maxMbps = 0; // Unlimited
+#ifdef MOZ_WEBRTC_OMX
+            maxMbps = 11880;
+#endif
+            branch->GetIntPref("media.navigator.video.h264.max_mbps",
+                               &maxMbps);
+            videoCodec.mMaxBr = maxMbps;
+
+            // Might disable it, but we set up other params anyway
+            videoCodec.mEnabled = h264Enabled;
+
+            if (videoCodec.mPacketizationMode == 0 && !softwareH264Enabled) {
+              // We're assuming packetization mode 0 is unsupported by
+              // hardware.
+              videoCodec.mEnabled = false;
+            }
+          } else if (codec.mName == "VP8") {
+            int32_t maxFs = 0;
+            branch->GetIntPref("media.navigator.video.max_fs", &maxFs);
+            if (maxFs <= 0) {
+              maxFs = 12288; // We must specify something other than 0
+            }
+            videoCodec.mMaxFs = maxFs;
+
+            int32_t maxFr = 0;
+            branch->GetIntPref("media.navigator.video.max_fr", &maxFr);
+            if (maxFr <= 0) {
+              maxFr = 60; // We must specify something other than 0
+            }
+            videoCodec.mMaxFr = maxFr;
+          }
+        }
+        break;
+      case SdpMediaSection::kText:
+      case SdpMediaSection::kApplication:
+      case SdpMediaSection::kMessage:
+        {} // Nothing to configure for these.
+    }
+  }
+
+  // Sort by priority
+  int32_t preferredCodec;
+  branch->GetIntPref("media.navigator.video.preferred_codec",
+                     &preferredCodec);
+
+  if (preferredCodec) {
+    CompareCodecPriority comparator(preferredCodec);
+    std::stable_sort(codecs.begin(), codecs.end(), comparator);
+  }
+
   return NS_OK;
 }
 
 RefPtr<DtlsIdentity> const
 PeerConnectionImpl::GetIdentity() const
 {
   PC_AUTO_ENTER_API_CALL_NO_CHECK();
   return mIdentity;
 }
 
-std::string
-PeerConnectionImpl::GetFingerprint() const
-{
-  PC_AUTO_ENTER_API_CALL_NO_CHECK();
-  return mFingerprint;
-}
-
-NS_IMETHODIMP
-PeerConnectionImpl::FingerprintSplitHelper(std::string& fingerprint,
-    size_t& spaceIdx) const
-{
-  fingerprint = GetFingerprint();
-  spaceIdx = fingerprint.find_first_of(' ');
-  if (spaceIdx == std::string::npos) {
-    CSFLogError(logTag, "%s: fingerprint is messed up: %s",
-        __FUNCTION__, fingerprint.c_str());
-    return NS_ERROR_FAILURE;
-  }
-  return NS_OK;
-}
-
-std::string
-PeerConnectionImpl::GetFingerprintAlgorithm() const
-{
-  std::string fp;
-  size_t spc;
-  if (NS_SUCCEEDED(FingerprintSplitHelper(fp, spc))) {
-    return fp.substr(0, spc);
-  }
-  return "";
-}
-
-std::string
-PeerConnectionImpl::GetFingerprintHexValue() const
-{
-  std::string fp;
-  size_t spc;
-  if (NS_SUCCEEDED(FingerprintSplitHelper(fp, spc))) {
-    return fp.substr(spc + 1);
-  }
-  return "";
-}
-
-
 nsresult
 PeerConnectionImpl::CreateFakeMediaStream(uint32_t aHint, DOMMediaStream** aRetval)
 {
   MOZ_ASSERT(aRetval);
   PC_AUTO_ENTER_API_CALL(false);
 
   bool mute = false;
 
@@ -772,31 +985,118 @@ PeerConnectionImpl::EnsureDataConnection
   }
   CSFLogDebug(logTag,"%s DataChannelConnection %p attached to %s",
               __FUNCTION__, (void*) mDataConnection.get(), mHandle.c_str());
 #endif
   return NS_OK;
 }
 
 nsresult
-PeerConnectionImpl::InitializeDataChannel(int track_id,
-                                          uint16_t aLocalport,
-                                          uint16_t aRemoteport,
-                                          uint16_t aNumstreams)
+PeerConnectionImpl::GetDatachannelParameters(
+    const mozilla::JsepApplicationCodecDescription** datachannelCodec,
+    uint16_t* level) const {
+
+  for (size_t j = 0; j < mJsepSession->GetNegotiatedTrackPairCount(); ++j) {
+    const JsepTrackPair* trackPair;
+    nsresult res = mJsepSession->GetNegotiatedTrackPair(j, &trackPair);
+
+    if (NS_SUCCEEDED(res) &&
+        trackPair->mSending && // Assumes we don't do recvonly datachannel
+        trackPair->mSending->GetMediaType() == SdpMediaSection::kApplication) {
+
+      if (!trackPair->mSending->GetNegotiatedDetails()->GetCodecCount()) {
+        CSFLogError(logTag, "%s: Negotiated m=application with no codec. "
+                            "This is likely to be broken.",
+                            __FUNCTION__);
+        return NS_ERROR_FAILURE;
+      }
+
+      for (size_t i = 0;
+           i < trackPair->mSending->GetNegotiatedDetails()->GetCodecCount();
+           ++i) {
+        const JsepCodecDescription* codec;
+        res = trackPair->mSending->GetNegotiatedDetails()->GetCodec(i, &codec);
+
+        if (NS_FAILED(res)) {
+          CSFLogError(logTag, "%s: Failed getting codec for m=application.",
+                              __FUNCTION__);
+          continue;
+        }
+
+        if (codec->mType != SdpMediaSection::kApplication) {
+          CSFLogError(logTag, "%s: Codec type for m=application was %u, this "
+                              "is a bug.",
+                              __FUNCTION__,
+                              static_cast<unsigned>(codec->mType));
+          MOZ_ASSERT(false, "Codec for m=application was not \"application\"");
+          return NS_ERROR_FAILURE;
+        }
+
+        if (codec->mName != "webrtc-datachannel") {
+          CSFLogWarn(logTag, "%s: Codec for m=application was not "
+                             "webrtc-datachannel (was instead %s). ",
+                             __FUNCTION__,
+                             codec->mName.c_str());
+          continue;
+        }
+
+        *datachannelCodec =
+          static_cast<const JsepApplicationCodecDescription*>(codec);
+        *level = static_cast<uint16_t>(trackPair->mLevel);
+        return NS_OK;
+      }
+    }
+  }
+
+  *datachannelCodec = nullptr;
+  *level = 0;
+  return NS_OK;
+}
+
+nsresult
+PeerConnectionImpl::InitializeDataChannel()
 {
   PC_AUTO_ENTER_API_CALL_NO_CHECK();
+  CSFLogDebug(logTag, "%s", __FUNCTION__);
+
+  const JsepApplicationCodecDescription* codec;
+  uint16_t level;
+  nsresult rv = GetDatachannelParameters(&codec, &level);
+
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  if (!codec) {
+    CSFLogDebug(logTag, "%s: We did not negotiate datachannel", __FUNCTION__);
+    return NS_OK;
+  }
 
 #ifdef MOZILLA_INTERNAL_API
-  nsresult rv = EnsureDataConnection(aNumstreams);
+  uint32_t channels = codec->mChannels;
+  if (channels > MAX_NUM_STREAMS) {
+    channels = MAX_NUM_STREAMS;
+  }
+
+  rv = EnsureDataConnection(codec->mChannels);
   if (NS_SUCCEEDED(rv)) {
+    uint16_t localport = 5000;
+    uint16_t remoteport = 0;
+    // The logic that reflects the remote payload type is what sets the remote
+    // port here.
+    if (!codec->GetPtAsInt(&remoteport)) {
+      return NS_ERROR_FAILURE;
+    }
+
     // use the specified TransportFlow
-    nsRefPtr<TransportFlow> flow = mMedia->GetTransportFlow(track_id, false).get();
-    CSFLogDebug(logTag, "Transportflow[%d] = %p", track_id, flow.get());
+    nsRefPtr<TransportFlow> flow = mMedia->GetTransportFlow(level, false).get();
+    CSFLogDebug(logTag, "Transportflow[%u] = %p",
+                        static_cast<unsigned>(level), flow.get());
     if (flow) {
-      if (mDataConnection->ConnectViaTransportFlow(flow, aLocalport, aRemoteport)) {
+      if (mDataConnection->ConnectViaTransportFlow(flow,
+                                                   localport,
+                                                   remoteport)) {
         return NS_OK;
       }
     }
     // If we inited the DataConnection, call Destroy() before releasing it
     mDataConnection->Destroy();
   }
   mDataConnection = nullptr;
 #endif
@@ -855,20 +1155,40 @@ PeerConnectionImpl::CreateDataChannel(co
     (aType == DataChannelConnection::PARTIAL_RELIABLE_TIMED ? aMaxTime : 0),
     nullptr, nullptr, aExternalNegotiated, aStream
   );
   NS_ENSURE_TRUE(dataChannel,NS_ERROR_FAILURE);
 
   CSFLogDebug(logTag, "%s: making DOMDataChannel", __FUNCTION__);
 
   if (!mHaveDataStream) {
-    // XXX stream_id of 0 might confuse things...
-    if (mInternal->mCall->addStream(0, 2, DATA)) {
+
+    std::string streamId;
+    std::string trackId;
+
+    // Generate random ids because these aren't linked to any local streams.
+    if (!mUuidGen->Generate(&streamId)) {
+      return NS_ERROR_FAILURE;
+    }
+    if (!mUuidGen->Generate(&trackId)) {
       return NS_ERROR_FAILURE;
     }
+
+    RefPtr<JsepTrack> track(new JsepTrack(
+          mozilla::SdpMediaSection::kApplication,
+          streamId,
+          trackId,
+          JsepTrack::kJsepTrackSending));
+
+    rv = mJsepSession->AddTrack(track);
+    if (NS_FAILED(rv)) {
+      CSFLogError(logTag, "%s: Failed to add application track.",
+                          __FUNCTION__);
+      return rv;
+    }
     mHaveDataStream = true;
   }
   nsIDOMDataChannel *retval;
   rv = NS_NewDOMDataChannel(dataChannel.forget(), mWindow, &retval);
   if (NS_FAILED(rv)) {
     return rv;
   }
   *aRetval = static_cast<nsDOMDataChannel*>(retval);
@@ -947,117 +1267,146 @@ PeerConnectionImpl::NotifyDataChannel(al
                                pco),
                 NS_DISPATCH_NORMAL);
 #endif
 }
 
 NS_IMETHODIMP
 PeerConnectionImpl::CreateOffer(const RTCOfferOptions& aOptions)
 {
-  return CreateOffer(SipccOfferOptions(aOptions));
+  JsepOfferOptions options;
+#ifdef MOZILLA_INTERNAL_API
+  if (aOptions.mOfferToReceiveAudio.WasPassed()) {
+    options.mOfferToReceiveAudio =
+      mozilla::Some(size_t(aOptions.mOfferToReceiveAudio.Value()));
+  }
+
+  if (aOptions.mOfferToReceiveVideo.WasPassed()) {
+    options.mOfferToReceiveVideo =
+        mozilla::Some(size_t(aOptions.mOfferToReceiveVideo.Value()));
+  }
+
+  if (aOptions.mMozDontOfferDataChannel.WasPassed()) {
+    options.mDontOfferDataChannel =
+      mozilla::Some(aOptions.mMozDontOfferDataChannel.Value());
+  }
+#endif
+  return CreateOffer(options);
 }
 
 static void DeferredCreateOffer(const std::string& aPcHandle,
-                                const SipccOfferOptions& aOptions) {
+                                const JsepOfferOptions& aOptions) {
   PeerConnectionWrapper wrapper(aPcHandle);
 
   if (wrapper.impl()) {
     if (!PeerConnectionCtx::GetInstance()->isReady()) {
       MOZ_CRASH("Why is DeferredCreateOffer being executed when the "
                 "PeerConnectionCtx isn't ready?");
     }
     wrapper.impl()->CreateOffer(aOptions);
   }
 }
 
 // Used by unit tests and the IDL CreateOffer.
 NS_IMETHODIMP
-PeerConnectionImpl::CreateOffer(const SipccOfferOptions& aOptions)
+PeerConnectionImpl::CreateOffer(const JsepOfferOptions& aOptions)
 {
   PC_AUTO_ENTER_API_CALL(true);
 
-  JSErrorResult rv;
   nsRefPtr<PeerConnectionObserver> pco = do_QueryObjectReferent(mPCObserver);
   if (!pco) {
     return NS_OK;
   }
 
   if (!PeerConnectionCtx::GetInstance()->isReady()) {
     // Uh oh. We're not ready yet. Enqueue this operation.
     PeerConnectionCtx::GetInstance()->queueJSEPOperation(
         WrapRunnableNM(DeferredCreateOffer, mHandle, aOptions));
     STAMP_TIMECARD(mTimeCard, "Deferring CreateOffer (not ready)");
     return NS_OK;
   }
 
+  CSFLogDebug(logTag, "CreateOffer()");
+
+  nsresult nrv = ConfigureJsepSessionCodecs();
+  if (NS_FAILED(nrv)) {
+    CSFLogError(logTag, "Failed to configure codecs");
+    return nrv;
+  }
+
   STAMP_TIMECARD(mTimeCard, "Create Offer");
 
-  cc_media_options_t* cc_options = aOptions.build();
-  NS_ENSURE_TRUE(cc_options, NS_ERROR_UNEXPECTED);
-
-  cc_int32_t error = mInternal->mCall->createOffer(cc_options, mTimeCard);
-
-  if (error) {
-    std::string error_string;
-    mInternal->mCall->getErrorString(&error_string);
+  std::string offer;
+
+  nrv = mJsepSession->CreateOffer(aOptions, &offer);
+  JSErrorResult rv;
+  if (NS_FAILED(nrv)) {
+    Error error;
+    switch (nrv) {
+      case NS_ERROR_UNEXPECTED:
+        error = kInvalidState;
+        break;
+      default:
+        error = kInternalError;
+    }
+    std::string errorString = mJsepSession->GetLastError();
+
     CSFLogError(logTag, "%s: pc = %s, error = %s",
-                __FUNCTION__, mHandle.c_str(), error_string.c_str());
-    pco->OnCreateOfferError(error, ObString(error_string.c_str()), rv);
+                __FUNCTION__, mHandle.c_str(), errorString.c_str());
+    pco->OnCreateOfferError(error, ObString(errorString.c_str()), rv);
   } else {
-    std::string sdp;
-    mInternal->mCall->getLocalSdp(&sdp);
-    pco->OnCreateOfferSuccess(ObString(sdp.c_str()), rv);
+    pco->OnCreateOfferSuccess(ObString(offer.c_str()), rv);
   }
 
   UpdateSignalingState();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PeerConnectionImpl::CreateAnswer()
 {
   PC_AUTO_ENTER_API_CALL(true);
 
-  JSErrorResult rv;
   nsRefPtr<PeerConnectionObserver> pco = do_QueryObjectReferent(mPCObserver);
   if (!pco) {
     return NS_OK;
   }
 
+  CSFLogDebug(logTag, "CreateAnswer()");
   STAMP_TIMECARD(mTimeCard, "Create Answer");
-
-  cc_int32_t error = mInternal->mCall->createAnswer(mTimeCard);
-
-  if (error) {
-    std::string error_string;
-    mInternal->mCall->getErrorString(&error_string);
+  // TODO(bug 1098015): Once RTCAnswerOptions is standardized, we'll need to
+  // add it as a param to CreateAnswer, and convert it here.
+  JsepAnswerOptions options;
+  std::string answer;
+
+  nsresult nrv = mJsepSession->CreateAnswer(options, &answer);
+  JSErrorResult rv;
+  if (NS_FAILED(nrv)) {
+    Error error;
+    switch (nrv) {
+      case NS_ERROR_UNEXPECTED:
+        error = kInvalidState;
+        break;
+      default:
+        error = kInternalError;
+    }
+    std::string errorString = mJsepSession->GetLastError();
+
     CSFLogError(logTag, "%s: pc = %s, error = %s",
-                __FUNCTION__, mHandle.c_str(), error_string.c_str());
-    pco->OnCreateAnswerError(error, ObString(error_string.c_str()), rv);
+                __FUNCTION__, mHandle.c_str(), errorString.c_str());
+    pco->OnCreateAnswerError(error, ObString(errorString.c_str()), rv);
   } else {
-    std::string sdp;
-    mInternal->mCall->getLocalSdp(&sdp);
-    pco->OnCreateAnswerSuccess(ObString(sdp.c_str()), rv);
+    pco->OnCreateAnswerSuccess(ObString(answer.c_str()), rv);
   }
 
   UpdateSignalingState();
+
   return NS_OK;
 }
 
-static void appendSdpParseErrors(const std::vector<std::string>& aErrors,
-                                 std::string* aErrorString,
-                                 cc_int32_t* aErrorCode) {
-   for (auto i = aErrors.begin(); i != aErrors.end(); ++i) {
-     *aErrorString += " | SDP Parsing Error: " + *i;
-   }
-   if (aErrors.size()) {
-     *aErrorCode = PeerConnectionImpl::kInvalidSessionDescription;
-   }
-}
-
 NS_IMETHODIMP
 PeerConnectionImpl::SetLocalDescription(int32_t aAction, const char* aSDP)
 {
   PC_AUTO_ENTER_API_CALL(true);
 
   if (!aSDP) {
     CSFLogError(logTag, "%s - aSDP is NULL", __FUNCTION__);
     return NS_ERROR_FAILURE;
@@ -1072,35 +1421,56 @@ PeerConnectionImpl::SetLocalDescription(
   STAMP_TIMECARD(mTimeCard, "Set Local Description");
 
 #ifdef MOZILLA_INTERNAL_API
   bool isolated = mMedia->AnyLocalStreamHasPeerIdentity();
   mPrivacyRequested = mPrivacyRequested || isolated;
 #endif
 
   mLocalRequestedSDP = aSDP;
-  cc_int32_t error  = mInternal->mCall->setLocalDescription(
-      (cc_jsep_action_t)aAction,
-      mLocalRequestedSDP, mTimeCard);
-
-  if (error) {
-    std::string error_string;
-    mInternal->mCall->getErrorString(&error_string);
-    appendSdpParseErrors(mSDPParseErrorMessages, &error_string, &error);
+
+  JsepSdpType sdpType;
+  switch (aAction) {
+    case IPeerConnection::kActionOffer:
+      sdpType = mozilla::kJsepSdpOffer;
+      break;
+    case IPeerConnection::kActionAnswer:
+      sdpType = mozilla::kJsepSdpAnswer;
+      break;
+    case IPeerConnection::kActionPRAnswer:
+      sdpType = mozilla::kJsepSdpPranswer;
+      break;
+    default:
+      MOZ_ASSERT(false);
+      return NS_ERROR_FAILURE;
+
+  }
+  nsresult nrv = mJsepSession->SetLocalDescription(sdpType,
+                                                   mLocalRequestedSDP);
+  if (NS_FAILED(nrv)) {
+    Error error;
+    switch (nrv) {
+      case NS_ERROR_INVALID_ARG:
+        error = kInvalidSessionDescription;
+        break;
+      case NS_ERROR_UNEXPECTED:
+        error = kInvalidState;
+        break;
+      default:
+        error = kInternalError;
+    }
+
+    std::string errorString = mJsepSession->GetLastError();
     CSFLogError(logTag, "%s: pc = %s, error = %s",
-                __FUNCTION__, mHandle.c_str(), error_string.c_str());
-    pco->OnSetLocalDescriptionError(error, ObString(error_string.c_str()), rv);
+                __FUNCTION__, mHandle.c_str(), errorString.c_str());
+    pco->OnSetLocalDescriptionError(error, ObString(errorString.c_str()), rv);
   } else {
-    mInternal->mCall->getLocalSdp(&mLocalSDP);
     pco->OnSetLocalDescriptionSuccess(rv);
-    StartTrickle();
   }
 
-  ClearSdpParseErrorMessages();
-
   UpdateSignalingState();
   return NS_OK;
 }
 
 static void DeferredSetRemote(const std::string& aPcHandle,
                               int32_t aAction,
                               const std::string& aSdp) {
   PeerConnectionWrapper wrapper(aPcHandle);
@@ -1119,59 +1489,166 @@ PeerConnectionImpl::SetRemoteDescription
 {
   PC_AUTO_ENTER_API_CALL(true);
 
   if (!aSDP) {
     CSFLogError(logTag, "%s - aSDP is NULL", __FUNCTION__);
     return NS_ERROR_FAILURE;
   }
 
-  JSErrorResult rv;
+  JSErrorResult jrv;
   nsRefPtr<PeerConnectionObserver> pco = do_QueryObjectReferent(mPCObserver);
   if (!pco) {
     return NS_OK;
   }
 
-  if (!PeerConnectionCtx::GetInstance()->isReady()) {
-    // Uh oh. We're not ready yet. Enqueue this operation. (This must be a
-    // remote offer, or else we would not have gotten this far)
-    PeerConnectionCtx::GetInstance()->queueJSEPOperation(
-        WrapRunnableNM(DeferredSetRemote,
-                       mHandle,
-                       action,
-                       std::string(aSDP)));
-    STAMP_TIMECARD(mTimeCard, "Deferring SetRemote (not ready)");
-    return NS_OK;
+  if (action == IPeerConnection::kActionOffer) {
+    if (!PeerConnectionCtx::GetInstance()->isReady()) {
+      // Uh oh. We're not ready yet. Enqueue this operation. (This must be a
+      // remote offer, or else we would not have gotten this far)
+      PeerConnectionCtx::GetInstance()->queueJSEPOperation(
+          WrapRunnableNM(DeferredSetRemote,
+            mHandle,
+            action,
+            std::string(aSDP)));
+      STAMP_TIMECARD(mTimeCard, "Deferring SetRemote (not ready)");
+      return NS_OK;
+    }
+
+    nsresult nrv = ConfigureJsepSessionCodecs();
+    if (NS_FAILED(nrv)) {
+      CSFLogError(logTag, "Failed to configure codecs");
+      return nrv;
+    }
   }
 
   STAMP_TIMECARD(mTimeCard, "Set Remote Description");
 
   mRemoteRequestedSDP = aSDP;
-
-  cc_int32_t error = mInternal->mCall->setRemoteDescription(
-                                         (cc_jsep_action_t)action,
-                                         mRemoteRequestedSDP, mTimeCard);
-
-  if (error) {
-    std::string error_string;
-    mInternal->mCall->getErrorString(&error_string);
-    appendSdpParseErrors(mSDPParseErrorMessages, &error_string, &error);
+  JsepSdpType sdpType;
+  switch (action) {
+    case IPeerConnection::kActionOffer:
+      sdpType = mozilla::kJsepSdpOffer;
+      break;
+    case IPeerConnection::kActionAnswer:
+      sdpType = mozilla::kJsepSdpAnswer;
+      break;
+    case IPeerConnection::kActionPRAnswer:
+      sdpType = mozilla::kJsepSdpPranswer;
+      break;
+    default:
+      MOZ_ASSERT(false);
+      return NS_ERROR_FAILURE;
+
+  }
+  nsresult nrv = mJsepSession->SetRemoteDescription(sdpType,
+                                                    mRemoteRequestedSDP);
+  if (NS_FAILED(nrv)) {
+    Error error;
+    switch (nrv) {
+      case NS_ERROR_INVALID_ARG:
+        error = kInvalidSessionDescription;
+        break;
+      case NS_ERROR_UNEXPECTED:
+        error = kInvalidState;
+        break;
+      default:
+        error = kInternalError;
+    }
+
+    std::string errorString = mJsepSession->GetLastError();
     CSFLogError(logTag, "%s: pc = %s, error = %s",
-                __FUNCTION__, mHandle.c_str(), error_string.c_str());
-    pco->OnSetRemoteDescriptionError(error, ObString(error_string.c_str()), rv);
+                __FUNCTION__, mHandle.c_str(), errorString.c_str());
+    pco->OnSetRemoteDescriptionError(error, ObString(errorString.c_str()), jrv);
   } else {
-    mInternal->mCall->getRemoteSdp(&mRemoteSDP);
-    pco->OnSetRemoteDescriptionSuccess(rv);
+    // Add the tracks. This code is pretty complicated because the tracks
+    // come in arbitrary orders and we want to group them by streamId.
+    // We go through all the tracks and then for each track that represents
+    // a new stream id, go through the rest of the tracks and deal with
+    // them at once.
+    size_t numTracks = mJsepSession->GetRemoteTrackCount();
+    MOZ_ASSERT(numTracks <= 3);
+    bool hasAudio = false;
+    bool hasVideo = false;
+
+    std::set<std::string> streamsToNotify;
+    for (size_t i = 0; i < numTracks; ++i) {
+      RefPtr<JsepTrack> track;
+      nrv = mJsepSession->GetRemoteTrack(i, &track);
+      if (NS_FAILED(nrv)) {
+        pco->OnSetRemoteDescriptionError(kInternalError,
+                                         ObString("GetRemoteTrack failed"),
+                                         jrv);
+        return NS_OK;
+      }
+
+      if (track->GetMediaType() == mozilla::SdpMediaSection::kApplication) {
+        // Ignore datachannel
+        continue;
+      }
+
+      nsRefPtr<RemoteSourceStreamInfo> info =
+        mMedia->GetRemoteStreamById(track->GetStreamId());
+      if (!info) {
+        nsresult nrv = CreateRemoteSourceStreamInfo(&info, track->GetStreamId());
+        if (NS_FAILED(nrv)) {
+          pco->OnSetRemoteDescriptionError(
+              kInternalError,
+              ObString("CreateRemoteSourceStreamInfo failed"),
+              jrv);
+          return NS_OK;
+        }
+
+        nrv = mMedia->AddRemoteStream(info);
+        if (NS_FAILED(nrv)) {
+          pco->OnSetRemoteDescriptionError(
+              kInternalError,
+              ObString("AddRemoteStream failed"),
+              jrv);
+          return NS_OK;
+        }
+      }
+
+      streamsToNotify.insert(track->GetStreamId());
+
+      if (track->GetMediaType() == mozilla::SdpMediaSection::kAudio) {
+        MOZ_ASSERT(!hasAudio);
+        (void)hasAudio;
+        hasAudio = true;
+        info->mTrackTypeHints |= DOMMediaStream::HINT_CONTENTS_AUDIO;
+      } else if (track->GetMediaType() == mozilla::SdpMediaSection::kVideo) {
+        MOZ_ASSERT(!hasVideo);
+        (void)hasVideo;
+        hasVideo = true;
+        info->mTrackTypeHints |= DOMMediaStream::HINT_CONTENTS_VIDEO;
+      }
+    }
+
+    for (auto i = streamsToNotify.begin(); i != streamsToNotify.end(); ++i) {
+      // Now that the streams are all set up, notify about track availability.
+      // TODO(bug 1017888): Suppress on renegotiation when no change.
+      nsRefPtr<RemoteSourceStreamInfo> info =
+        mMedia->GetRemoteStreamById(*i);
+      MOZ_ASSERT(info);
+
+#ifdef MOZILLA_INTERNAL_API
+      TracksAvailableCallback* tracksAvailableCallback =
+        new TracksAvailableCallback(info->mTrackTypeHints, pco);
+      info->GetMediaStream()->OnTracksAvailable(tracksAvailableCallback);
+#else
+      pco->OnAddStream(info->GetMediaStream(), jrv);
+#endif
+    }
+
+    pco->OnSetRemoteDescriptionSuccess(jrv);
 #ifdef MOZILLA_INTERNAL_API
     startCallTelem();
 #endif
   }
 
-  ClearSdpParseErrorMessages();
-
   UpdateSignalingState();
   return NS_OK;
 }
 
 // WebRTC uses highres time relative to the UNIX epoch (Jan 1, 1970, UTC).
 
 #ifdef MOZILLA_INTERNAL_API
 nsresult
@@ -1233,136 +1710,78 @@ PeerConnectionImpl::AddIceCandidate(cons
   JSErrorResult rv;
   nsRefPtr<PeerConnectionObserver> pco = do_QueryObjectReferent(mPCObserver);
   if (!pco) {
     return NS_OK;
   }
 
   STAMP_TIMECARD(mTimeCard, "Add Ice Candidate");
 
+  CSFLogDebug(logTag, "AddIceCandidate: %s", aCandidate);
+
 #ifdef MOZILLA_INTERNAL_API
   // When remote candidates are added before our ICE ctx is up and running
   // (the transition to New is async through STS, so this is not impossible),
   // we won't record them as trickle candidates. Is this what we want?
   if(!mIceStartTime.IsNull()) {
     TimeDuration timeDelta = TimeStamp::Now() - mIceStartTime;
     if (mIceConnectionState == PCImplIceConnectionState::Failed) {
       Telemetry::Accumulate(Telemetry::WEBRTC_ICE_LATE_TRICKLE_ARRIVAL_TIME,
                             timeDelta.ToMilliseconds());
     } else {
       Telemetry::Accumulate(Telemetry::WEBRTC_ICE_ON_TIME_TRICKLE_ARRIVAL_TIME,
                             timeDelta.ToMilliseconds());
     }
   }
 #endif
 
-  cc_int32_t error = mInternal->mCall->addICECandidate(aCandidate, aMid, aLevel, mTimeCard);
-
-  if (error) {
-    OnAddIceCandidateError();
-    std::string error_string;
-    mInternal->mCall->getErrorString(&error_string);
-    CSFLogError(logTag, "%s: pc = %s, error = %s (note, this should not be "
-                        "a show-stopper, since whether we incorporate "
-                        "candidates into the SDP doesn't really matter since "
-                        "we're full trickle)",
-                __FUNCTION__, mHandle.c_str(), error_string.c_str());
-    pco->OnAddIceCandidateError(error, ObString(error_string.c_str()), rv);
+  nsresult res = mJsepSession->AddRemoteIceCandidate(aCandidate, aMid, aLevel);
+
+  if (NS_SUCCEEDED(res)) {
+    // We do not bother PCMedia about this before offer/answer concludes.
+    // Once offer/answer concludes, PCMedia will extract these candidates from
+    // the remote SDP.
+    if (mSignalingState == PCImplSignalingState::SignalingStable) {
+      mMedia->AddIceCandidate(aCandidate, aMid, aLevel);
+    }
+    pco->OnAddIceCandidateSuccess(rv);
   } else {
-    pco->OnAddIceCandidateSuccess(rv);
-    mInternal->mCall->getRemoteSdp(&mRemoteSDP);
+    ++mAddCandidateErrorCount;
+    Error error;
+    switch (res) {
+      case NS_ERROR_UNEXPECTED:
+        error = kInvalidState;
+        break;
+      case NS_ERROR_INVALID_ARG:
+        error = kInvalidCandidate;
+        break;
+      default:
+        error = kInternalError;
+    }
+
+    std::string errorString = mJsepSession->GetLastError();
+
+    CSFLogError(logTag, "Failed to incorporate remote candidate into SDP:"
+                        " res = %u, candidate = %s, level = %u, error = %s",
+                        static_cast<unsigned>(res),
+                        aCandidate,
+                        static_cast<unsigned>(aLevel),
+                        errorString.c_str());
+
+    pco->OnAddIceCandidateError(error, ObString(errorString.c_str()), rv);
   }
 
   UpdateSignalingState();
   return NS_OK;
 }
 
-#ifdef MOZILLA_INTERNAL_API
-class TracksAvailableCallback : public DOMMediaStream::OnTracksAvailableCallback
-{
-public:
-  TracksAvailableCallback(DOMMediaStream::TrackTypeHints aTrackTypeHints,
-                          nsRefPtr<PeerConnectionObserver> aObserver)
-  : DOMMediaStream::OnTracksAvailableCallback(aTrackTypeHints)
-  , mObserver(aObserver) {}
-
-  virtual void NotifyTracksAvailable(DOMMediaStream* aStream) MOZ_OVERRIDE
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    // Start currentTime from the point where this stream was successfully
-    // returned.
-    aStream->SetLogicalStreamStartTime(aStream->GetStream()->GetCurrentTime());
-
-    CSFLogInfo(logTag, "Returning success for OnAddStream()");
-    // We are running on main thread here so we shouldn't have a race
-    // on this callback
-
-    nsTArray<nsRefPtr<MediaStreamTrack>> tracks;
-    aStream->GetTracks(tracks);
-    for (uint32_t i = 0; i < tracks.Length(); i++) {
-      JSErrorResult rv;
-      mObserver->OnAddTrack(*tracks[i], rv);
-      if (rv.Failed()) {
-        CSFLogError(logTag, ": OnAddTrack(%d) failed! Error: %d", i,
-                    rv.ErrorCode());
-      }
-    }
-    JSErrorResult rv;
-    mObserver->OnAddStream(*aStream, rv);
-    if (rv.Failed()) {
-      CSFLogError(logTag, ": OnAddStream() failed! Error: %d", rv.ErrorCode());
-    }
-  }
-private:
-  nsRefPtr<PeerConnectionObserver> mObserver;
-};
-#endif
-
-void PeerConnectionImpl::OnRemoteStreamAdded(const MediaStreamTable& aStream) {
-  DOMMediaStream* stream = nullptr;
-
-  nsRefPtr<RemoteSourceStreamInfo> mRemoteStreamInfo =
-    media()->GetRemoteStream(aStream.media_stream_id);
-  MOZ_ASSERT(mRemoteStreamInfo);
-
-  if (!mRemoteStreamInfo) {
-    CSFLogError(logTag, "%s: GetRemoteStream returned NULL", __FUNCTION__);
-  } else {
-    stream = mRemoteStreamInfo->GetMediaStream();
-  }
-
-  if (!stream) {
-    CSFLogError(logTag, "%s: GetMediaStream returned NULL", __FUNCTION__);
-  } else {
-    nsRefPtr<PeerConnectionObserver> pco =
-      do_QueryObjectReferent(mPCObserver);
-    if (!pco) {
-      return;
-    }
-
-#ifdef MOZILLA_INTERNAL_API
-    TracksAvailableCallback* tracksAvailableCallback =
-      new TracksAvailableCallback(mRemoteStreamInfo->mTrackTypeHints, pco);
-
-    stream->OnTracksAvailable(tracksAvailableCallback);
-#else
-    JSErrorResult rv;
-    pco->OnAddStream(stream, rv);
-#endif
-  }
-}
-
 NS_IMETHODIMP
 PeerConnectionImpl::CloseStreams() {
   PC_AUTO_ENTER_API_CALL(false);
 
-  CSFLogInfo(logTag, "%s: Ending associated call", __FUNCTION__);
-
-  mInternal->mCall->endCall();
   return NS_OK;
 }
 
 #ifdef MOZILLA_INTERNAL_API
 nsresult
 PeerConnectionImpl::SetPeerIdentity(const nsAString& aPeerIdentity)
 {
   PC_AUTO_ENTER_API_CALL(true);
@@ -1465,110 +1884,62 @@ PeerConnectionImpl::AddTrack(MediaStream
       mNumVideoStreams > 0) {
     CSFLogError(logTag, "%s: Only one local video stream is supported for now",
                 __FUNCTION__);
     return NS_ERROR_FAILURE;
   }
 
   uint32_t num = mMedia->LocalStreamsLength();
 
-  uint32_t stream_id;
-  nsresult res = mMedia->AddStream(&aMediaStream, hints, &stream_id);
+  std::string streamId;
+  // TODO(bug 1089798): These ids should really come from the MS.
+  nsresult res = mMedia->AddStream(&aMediaStream, hints, &streamId);
   if (NS_FAILED(res)) {
     return res;
   }
 
   if (num != mMedia->LocalStreamsLength()) {
     aMediaStream.AddPrincipalChangeObserver(this);
   }
 
-  // TODO(ekr@rtfm.com): these integers should be the track IDs
   if (hints & DOMMediaStream::HINT_CONTENTS_AUDIO) {
-    if (mInternal->mCall->addStream(stream_id, 0, AUDIO)) {
-      std::string error_string;
-      mInternal->mCall->getErrorString(&error_string);
+    res = mJsepSession->AddTrack(new JsepTrack(
+        mozilla::SdpMediaSection::kAudio,
+        streamId,
+        "audio_track_id",
+        JsepTrack::kJsepTrackSending));
+    if (NS_FAILED(res)) {
+      std::string errorString = mJsepSession->GetLastError();
       CSFLogError(logTag, "%s (audio) : pc = %s, error = %s",
-                  __FUNCTION__, mHandle.c_str(), error_string.c_str());
+                  __FUNCTION__, mHandle.c_str(), errorString.c_str());
       return NS_ERROR_FAILURE;
     }
     mNumAudioStreams++;
   }
 
   if (hints & DOMMediaStream::HINT_CONTENTS_VIDEO) {
-    if (mInternal->mCall->addStream(stream_id, 1, VIDEO)) {
-      std::string error_string;
-      mInternal->mCall->getErrorString(&error_string);
-      CSFLogError(logTag, "%s: (video) pc = %s, error = %s",
-                  __FUNCTION__, mHandle.c_str(), error_string.c_str());
+    res = mJsepSession->AddTrack(new JsepTrack(
+        mozilla::SdpMediaSection::kVideo,
+        streamId,
+        "video_track_id",
+        JsepTrack::kJsepTrackSending));
+    if (NS_FAILED(res)) {
+      std::string errorString = mJsepSession->GetLastError();
+      CSFLogError(logTag, "%s (video) : pc = %s, error = %s",
+                  __FUNCTION__, mHandle.c_str(), errorString.c_str());
       return NS_ERROR_FAILURE;
     }
     mNumVideoStreams++;
   }
-
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PeerConnectionImpl::RemoveTrack(MediaStreamTrack& aTrack) {
-  PC_AUTO_ENTER_API_CALL(true);
-
-  DOMMediaStream *stream = nullptr;
-  for (uint32_t i = 0; i < mMedia->LocalStreamsLength(); ++i) {
-    auto* candidate = mMedia->GetLocalStream(i)->GetMediaStream();
-    if (candidate->HasTrack(aTrack)) {
-      stream = candidate;
-      break;
-    }
-  }
-  if (!stream) {
-    CSFLogError(logTag, "%s: Track not found", __FUNCTION__);
-    return NS_OK;
-  }
-  auto& aMediaStream = *stream;
-
-  uint32_t hints = aMediaStream.GetHintContents() &
-      ((aTrack.AsAudioStreamTrack()? DOMMediaStream::HINT_CONTENTS_AUDIO : 0) |
-       (aTrack.AsVideoStreamTrack()? DOMMediaStream::HINT_CONTENTS_VIDEO : 0));
-  uint32_t num = mMedia->LocalStreamsLength();
-
-  uint32_t stream_id;
-  nsresult res = mMedia->RemoveStream(&aMediaStream, hints, &stream_id);
-
-  if (NS_FAILED(res)) {
-    return res;
-  }
-
-  if (num != mMedia->LocalStreamsLength()) {
-    aMediaStream.RemovePrincipalChangeObserver(this);
-  }
-
-  if (hints & DOMMediaStream::HINT_CONTENTS_AUDIO) {
-    if (mInternal->mCall->removeStream(stream_id, 0, AUDIO)) {
-      std::string error_string;
-      mInternal->mCall->getErrorString(&error_string);
-      CSFLogError(logTag, "%s (audio) : pc = %s, error = %s",
-                  __FUNCTION__, mHandle.c_str(), error_string.c_str());
-      return NS_ERROR_FAILURE;
-    }
-    MOZ_ASSERT(mNumAudioStreams > 0);
-    mNumAudioStreams--;
-  }
-
-  if (hints & DOMMediaStream::HINT_CONTENTS_VIDEO) {
-    if (mInternal->mCall->removeStream(stream_id, 1, VIDEO)) {
-      std::string error_string;
-      mInternal->mCall->getErrorString(&error_string);
-      CSFLogError(logTag, "%s (video) : pc = %s, error = %s",
-                  __FUNCTION__, mHandle.c_str(), error_string.c_str());
-      return NS_ERROR_FAILURE;
-    }
-    MOZ_ASSERT(mNumVideoStreams > 0);
-    mNumVideoStreams--;
-  }
-
+  MOZ_CRASH(); // TODO(bug 1021647): Implement and expose RemoveTrack
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PeerConnectionImpl::ReplaceTrack(MediaStreamTrack& aThisTrack,
                                  MediaStreamTrack& aWithTrack,
                                  DOMMediaStream& aStream) {
   PC_AUTO_ENTER_API_CALL(true);
@@ -1582,27 +1953,27 @@ PeerConnectionImpl::ReplaceTrack(MediaSt
   // timestamps are tied to capture.
   //
   // Since a track may be replaced more than once, the track being replaced
   // may not be in the stream either, so we check neither arg right now.
 
   // XXX This MUST be addressed when we add multiple tracks of a type!!
   // This is needed because the track IDs used by MSG are from TrackUnion
   // (for getUserMedia streams) and aren't the same as the values the source tracks
-  // have.  Solution is to have SIPCC/VcmSIPCCBinding read track ids and use those.
+  // have.  Solution is to have JsepSession read track ids and use those.
 
   // Because DirectListeners see the SourceMediaStream's TrackID's, and not the
   // TrackUnionStream's TrackID's, this value won't currently match what is used in
   // MediaPipelineTransmit.  Bug 1056652
   //  TrackID thisID = aThisTrack.GetTrackID();
   TrackID withID = aWithTrack.GetTrackID();
 
   bool success = false;
   for(uint32_t i = 0; i < media()->LocalStreamsLength(); ++i) {
-    LocalSourceStreamInfo *info = media()->GetLocalStream(i);
+    LocalSourceStreamInfo *info = media()->GetLocalStreamByIndex(i);
     // XXX use type instead of TrackID - bug 1056650
     int pipeline = info->HasTrackType(&aStream, !!(aThisTrack.AsVideoStreamTrack()));
     if (pipeline >= 0) {
       // XXX GetStream() will likely be invalid once a track can be in more than one