Bug 874306 - Add PC identifier to ICE logging r=ekr
authorAdam Roach [:abr] <adam@nostrum.com>
Tue, 21 May 2013 11:34:09 +0800
changeset 139602 7080277aa570a9e7bbef4cf4cfb2ce4b17e713df
parent 139601 7b4e9af7376413cd5a17503c2f811c986eb98525
child 139603 3322189ff1db90ca807fa38ac636edf68af59c08
push id3911
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 20:17:26 +0000
treeherdermozilla-aurora@7e26ca8db92b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersekr
bugs874306
milestone24.0a1
Bug 874306 - Add PC identifier to ICE logging r=ekr
media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp
media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp
media/webrtc/signaling/src/sipcc/core/gsm/fsmdef.c
--- a/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp
+++ b/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp
@@ -2663,17 +2663,17 @@ vcmCreateTransportFlow(sipcc::PeerConnec
 
     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("flow", pc->media()->ice_ctx(),
+        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].
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -51,16 +51,21 @@ using namespace mozilla;
 
 // Logging context
 MOZ_MTLOG_MODULE("mediapipeline")
 
 namespace mozilla {
 
 static char kDTLSExporterLabel[] = "EXTRACTOR-dtls_srtp";
 
+MediaPipeline::~MediaPipeline() {
+  MOZ_ASSERT(!stream_);  // Check that we have shut down already.
+  MOZ_MTLOG(PR_LOG_DEBUG, "Destroying MediaPipeline: " << description_);
+}
+
 nsresult MediaPipeline::Init() {
   ASSERT_ON_THREAD(main_thread_);
 
   RUN_ON_THREAD(sts_thread_,
                 WrapRunnable(
                     nsRefPtr<MediaPipeline>(this),
                     &MediaPipeline::Init_s),
                 NS_DISPATCH_NORMAL);
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
@@ -92,19 +92,17 @@ class MediaPipeline : public sigslot::ha
         rtcp_packets_sent_(0),
         rtp_packets_received_(0),
         rtcp_packets_received_(0),
         muxed_((rtcp_transport_ == NULL) || (rtp_transport_ == rtcp_transport_)),
         pc_(pc),
         description_() {
   }
 
-  virtual ~MediaPipeline() {
-    MOZ_ASSERT(!stream_);  // Check that we have shut down already.
-  }
+  virtual ~MediaPipeline();
 
   // Must be called on the STS thread.  Must be called after ShutdownMedia_m().
   void ShutdownTransport_s();
 
   // Must be called on the main thread.
   void ShutdownMedia_m() {
     ASSERT_ON_THREAD(main_thread_);
 
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -460,16 +460,37 @@ PeerConnectionImpl::Initialize(IPeerConn
                                nsIDOMWindow* aWindow,
                                const IceConfiguration* aConfiguration,
                                const JS::Value* aRTCConfiguration,
                                nsIThread* aThread,
                                JSContext* aCx)
 {
   nsresult res;
 
+  // Generate a random handle
+  unsigned char handle_bin[8];
+  SECStatus rv;
+  rv = PK11_GenerateRandom(handle_bin, sizeof(handle_bin));
+  if (rv != SECSuccess) {
+    return NS_ERROR_UNEXPECTED;
+  }
+
+  char hex[17];
+  PR_snprintf(hex,sizeof(hex),"%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x",
+    handle_bin[0],
+    handle_bin[1],
+    handle_bin[2],
+    handle_bin[3],
+    handle_bin[4],
+    handle_bin[5],
+    handle_bin[6],
+    handle_bin[7]);
+
+  mHandle = hex;
+
 #ifdef MOZILLA_INTERNAL_API
   MOZ_ASSERT(NS_IsMainThread());
 #endif
   MOZ_ASSERT(aObserver);
   MOZ_ASSERT(aThread);
   mThread = aThread;
 
   mPCObserver = do_GetWeakReference(aObserver);
@@ -519,33 +540,16 @@ PeerConnectionImpl::Initialize(IPeerConn
     res = mMedia->Init(aConfiguration->getStunServers(),
                        aConfiguration->getTurnServers());
   }
   if (NS_FAILED(res)) {
     CSFLogError(logTag, "%s: Couldn't initialize media object", __FUNCTION__);
     return res;
   }
 
-  // Generate a random handle
-  unsigned char handle_bin[8];
-  PK11_GenerateRandom(handle_bin, sizeof(handle_bin));
-
-  char hex[17];
-  PR_snprintf(hex,sizeof(hex),"%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x",
-    handle_bin[0],
-    handle_bin[1],
-    handle_bin[2],
-    handle_bin[3],
-    handle_bin[4],
-    handle_bin[5],
-    handle_bin[6],
-    handle_bin[7]);
-
-  mHandle += hex;
-
   // Store under mHandle
   mCall->setPeerConnection(mHandle);
   PeerConnectionCtx::GetInstance()->mPeerConnections[mHandle] = this;
 
   // Create the DTLS Identity
   mIdentity = DtlsIdentity::Generate();
 
   if (!mIdentity) {
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp
@@ -174,19 +174,22 @@ nsresult PeerConnectionMedia::Init(const
   mIceCtx->SignalCompleted.connect(this,
                                    &PeerConnectionMedia::IceCompleted);
   mIceCtx->SignalFailed.connect(this,
                                 &PeerConnectionMedia::IceFailed);
 
   // Create three streams to start with.
   // One each for audio, video and DataChannel
   // TODO: this will be re-visited
-  RefPtr<NrIceMediaStream> audioStream = mIceCtx->CreateStream("stream1", 2);
-  RefPtr<NrIceMediaStream> videoStream = mIceCtx->CreateStream("stream2", 2);
-  RefPtr<NrIceMediaStream> dcStream = mIceCtx->CreateStream("stream3", 2);
+  RefPtr<NrIceMediaStream> audioStream =
+    mIceCtx->CreateStream((mParent->GetHandle()+"/stream1/audio").c_str(), 2);
+  RefPtr<NrIceMediaStream> videoStream =
+    mIceCtx->CreateStream((mParent->GetHandle()+"/stream2/video").c_str(), 2);
+  RefPtr<NrIceMediaStream> dcStream =
+    mIceCtx->CreateStream((mParent->GetHandle()+"/stream3/data").c_str(), 2);
 
   if (!audioStream) {
     CSFLogError(logTag, "%s: audio stream is NULL", __FUNCTION__);
     return NS_ERROR_FAILURE;
   } else {
     mIceStreams.push_back(audioStream);
   }
 
--- a/media/webrtc/signaling/src/sipcc/core/gsm/fsmdef.c
+++ b/media/webrtc/signaling/src/sipcc/core/gsm/fsmdef.c
@@ -3511,16 +3511,20 @@ fsmdef_ev_setpeerconnection(sm_event_t *
 
       fsm_set_fcb_dcbs(dcb);
     }
 
     PR_ASSERT(strlen(msg->data.pc.pc_handle) < PC_HANDLE_SIZE);
     sstrncpy(dcb->peerconnection, msg->data.pc.pc_handle, sizeof(dcb->peerconnection));
     dcb->peerconnection_set = TRUE;
 
+    FSM_DEBUG_SM(DEB_F_PREFIX"Setting peerconnection handle for (%d/%d) to %s",
+                 DEB_F_PREFIX_ARGS(FSM, __FUNCTION__),
+                 line, call_id, dcb->peerconnection);
+
     return (SM_RC_END);
 }
 
 
 static sm_rcs_t
 fsmdef_ev_addstream(sm_event_t *event) {
     fsm_fcb_t           *fcb = (fsm_fcb_t *) event->data;
     fsmdef_dcb_t        *dcb = fcb->dcb;