Bug 792188: Fixes to signaling MediaPipeline and Srtpflow r=jesup,derf
authorRandell Jesup <rjesup@jesup.org>
Sun, 07 Oct 2012 01:34:29 -0400
changeset 109554 8de22a14e8c8a1cf9e67ba7490f4198c81af2580
parent 109553 7c84f16616074286430165034bcf0e990c04e655
child 109555 cbce2911566ddcdaa25dff9b03e3ef51e89861db
push id23632
push userphilringnalda@gmail.com
push dateSun, 07 Oct 2012 19:14:37 +0000
treeherdermozilla-central@83d38854c21e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup, derf
bugs792188
milestone18.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 792188: Fixes to signaling MediaPipeline and Srtpflow r=jesup,derf
media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
media/webrtc/signaling/src/mediapipeline/SrtpFlow.cpp
media/webrtc/signaling/src/mediapipeline/SrtpFlow.h
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -25,208 +25,228 @@
 #include "MediaSegment.h"
 #include "transportflow.h"
 #include "transportlayer.h"
 #include "transportlayerdtls.h"
 #include "transportlayerice.h"
 
 #include "runnable_utils.h"
 
-#ifdef ERROR
-#undef ERROR
-#endif
-
 using namespace mozilla;
 
 // Logging context
 MOZ_MTLOG_MODULE("mediapipeline");
 
 namespace mozilla {
 
 static char kDTLSExporterLabel[] = "EXTRACTOR-dtls_srtp";
 
 nsresult MediaPipeline::Init() {
   conduit_->AttachTransport(transport_);
 
-  PR_ASSERT(rtp_transport_);
+  MOZ_ASSERT(rtp_transport_);
 
   nsresult res;
+  
+  // Look to see if the transport is ready
+  rtp_transport_->SignalStateChange.connect(this,
+                                            &MediaPipeline::StateChange);
 
-  // TODO(ekr@rtfm.com): Danger....
-  // Look to see if the transport is ready
   if (rtp_transport_->state() == TransportLayer::TS_OPEN) {
     res = TransportReady(rtp_transport_);
-    if (!NS_SUCCEEDED(res))
-      return res;
+    NS_ENSURE_SUCCESS(res, res);
   } else {
-    rtp_transport_->SignalStateChange.connect(this,
-                                              &MediaPipeline::StateChange);
+    if (!muxed_) {
+      rtcp_transport_->SignalStateChange.connect(this,
+                                                 &MediaPipeline::StateChange);
 
-    if (!muxed_) {
       if (rtcp_transport_->state() == TransportLayer::TS_OPEN) {
         res = TransportReady(rtcp_transport_);
-        if (!NS_SUCCEEDED(res))
-          return res;
-      } else {
-        rtcp_transport_->SignalStateChange.connect(this,
-                                                   &MediaPipeline::StateChange);
+        NS_ENSURE_SUCCESS(res, res);
       }
     }
   }
-
   return NS_OK;
 }
 
+
+// Disconnect us from the transport so that we can cleanly destruct
+// the pipeline on the main thread.
 void MediaPipeline::DetachTransportInt() {
   transport_->Detach();
 }
 
 void MediaPipeline::DetachTransport() {
   RUN_ON_THREAD(sts_thread_,
                 WrapRunnable(this, &MediaPipeline::DetachTransportInt),
                 NS_DISPATCH_SYNC);
 }
 
 void MediaPipeline::StateChange(TransportFlow *flow, TransportLayer::State state) {
-  // TODO(ekr@rtfm.com): check for double changes. This shouldn't happen,
-  // but...
   if (state == TransportLayer::TS_OPEN) {
     MOZ_MTLOG(PR_LOG_DEBUG, "Flow is ready");
     TransportReady(flow);
   } else if (state == TransportLayer::TS_CLOSED ||
              state == TransportLayer::TS_ERROR) {
     TransportFailed(flow);
   }
 }
 
 nsresult MediaPipeline::TransportReady(TransportFlow *flow) {
-  bool rtcp =  flow == rtp_transport_.get() ? false : true;
+  bool rtcp = !(flow == rtp_transport_);
+  State *state = rtcp ? &rtcp_state_ : &rtp_state_;
+
+  if (*state != MP_CONNECTING) {
+    MOZ_MTLOG(PR_LOG_ERROR, "Transport ready for flow in wrong state:" <<
+              (rtcp ? "rtcp" : "rtp"));
+    return NS_ERROR_FAILURE;
+  }
+
   nsresult res;
 
   MOZ_MTLOG(PR_LOG_DEBUG, "Transport ready for flow " << (rtcp ? "rtcp" : "rtp"));
 
   // Now instantiate the SRTP objects
   TransportLayerDtls *dtls = static_cast<TransportLayerDtls *>(
       flow->GetLayer(TransportLayerDtls::ID()));
-  PR_ASSERT(dtls);  // DTLS is mandatory
+  MOZ_ASSERT(dtls);  // DTLS is mandatory
 
   PRUint16 cipher_suite;
   res = dtls->GetSrtpCipher(&cipher_suite);
   if (NS_FAILED(res)) {
     MOZ_MTLOG(PR_LOG_ERROR, "Failed to negotiate DTLS-SRTP. This is an error");
     return res;
   }
 
   // SRTP Key Exporter as per RFC 5764 S 4.2
   unsigned char srtp_block[SRTP_TOTAL_KEY_LENGTH * 2];
   res = dtls->ExportKeyingMaterial(kDTLSExporterLabel, false, "",
                                    srtp_block, sizeof(srtp_block));
+  if (NS_FAILED(res)) {
+    MOZ_MTLOG(PR_LOG_ERROR, "Failed to compute DTLS-SRTP keys. This is an error");
+    *state = MP_CLOSED;
+    MOZ_CRASH();  // TODO: Remove once we have enough field experience to
+                  // know it doesn't happen. bug 798797. Note that the
+                  // code after this never executes.
+    return res;
+  }
 
   // Slice and dice as per RFC 5764 S 4.2
   unsigned char client_write_key[SRTP_TOTAL_KEY_LENGTH];
   unsigned char server_write_key[SRTP_TOTAL_KEY_LENGTH];
   int offset = 0;
   memcpy(client_write_key, srtp_block + offset, SRTP_MASTER_KEY_LENGTH);
   offset += SRTP_MASTER_KEY_LENGTH;
   memcpy(server_write_key, srtp_block + offset, SRTP_MASTER_KEY_LENGTH);
   offset += SRTP_MASTER_KEY_LENGTH;
   memcpy(client_write_key + SRTP_MASTER_KEY_LENGTH,
          srtp_block + offset, SRTP_MASTER_SALT_LENGTH);
   offset += SRTP_MASTER_SALT_LENGTH;
   memcpy(server_write_key + SRTP_MASTER_KEY_LENGTH,
          srtp_block + offset, SRTP_MASTER_SALT_LENGTH);
   offset += SRTP_MASTER_SALT_LENGTH;
-  PR_ASSERT(offset == sizeof(srtp_block));
+  MOZ_ASSERT(offset == sizeof(srtp_block));
 
   unsigned char *write_key;
   unsigned char *read_key;
 
   if (dtls->role() == TransportLayerDtls::CLIENT) {
     write_key = client_write_key;
     read_key = server_write_key;
   } else {
     write_key = server_write_key;
     read_key = client_write_key;
   }
 
   if (!rtcp) {
     // RTP side
-    PR_ASSERT(!rtp_send_srtp_ && !rtp_recv_srtp_);
+    MOZ_ASSERT(!rtp_send_srtp_ && !rtp_recv_srtp_);
     rtp_send_srtp_ = SrtpFlow::Create(cipher_suite, false,
                                       write_key, SRTP_TOTAL_KEY_LENGTH);
     rtp_recv_srtp_ = SrtpFlow::Create(cipher_suite, true,
                                       read_key, SRTP_TOTAL_KEY_LENGTH);
     if (!rtp_send_srtp_ || !rtp_recv_srtp_) {
       MOZ_MTLOG(PR_LOG_ERROR, "Couldn't create SRTP flow for RTCP");
+      *state = MP_CLOSED;
       return NS_ERROR_FAILURE;
     }
 
     // Start listening
     if (muxed_) {
-      PR_ASSERT(!rtcp_send_srtp_ && !rtcp_recv_srtp_);
+      MOZ_ASSERT(!rtcp_send_srtp_ && !rtcp_recv_srtp_);
       rtcp_send_srtp_ = rtp_send_srtp_;
       rtcp_recv_srtp_ = rtp_recv_srtp_;
 
       MOZ_MTLOG(PR_LOG_DEBUG, "Listening for packets received on " <<
-        static_cast<void *>(dtls->downward()));
+                static_cast<void *>(dtls->downward()));
 
       dtls->downward()->SignalPacketReceived.connect(this,
                                                      &MediaPipeline::
                                                      PacketReceived);
     } else {
       MOZ_MTLOG(PR_LOG_DEBUG, "Listening for RTP packets received on " <<
-        static_cast<void *>(dtls->downward()));
+                static_cast<void *>(dtls->downward()));
 
       dtls->downward()->SignalPacketReceived.connect(this,
                                                      &MediaPipeline::
                                                      RtpPacketReceived);
     }
   }
   else {
-    PR_ASSERT(!rtcp_send_srtp_ && !rtcp_recv_srtp_);
+    MOZ_ASSERT(!rtcp_send_srtp_ && !rtcp_recv_srtp_);
     rtcp_send_srtp_ = SrtpFlow::Create(cipher_suite, false,
                                        write_key, SRTP_TOTAL_KEY_LENGTH);
     rtcp_recv_srtp_ = SrtpFlow::Create(cipher_suite, true,
                                        read_key, SRTP_TOTAL_KEY_LENGTH);
     if (!rtcp_send_srtp_ || !rtcp_recv_srtp_) {
       MOZ_MTLOG(PR_LOG_ERROR, "Couldn't create SRTCP flow for RTCP");
+      *state = MP_CLOSED;
       return NS_ERROR_FAILURE;
     }
 
     MOZ_MTLOG(PR_LOG_DEBUG, "Listening for RTCP packets received on " <<
       static_cast<void *>(dtls->downward()));
 
     // Start listening
     dtls->downward()->SignalPacketReceived.connect(this,
                                                   &MediaPipeline::
                                                   RtcpPacketReceived);
   }
 
+  *state = MP_OPEN;
   return NS_OK;
 }
 
 nsresult MediaPipeline::TransportFailed(TransportFlow *flow) {
-  bool rtcp =  flow == rtp_transport_.get() ? false : true;
+  bool rtcp = !(flow == rtp_transport_);
+
+  State *state = rtcp ? &rtcp_state_ : &rtp_state_;
+
+  *state = MP_CLOSED;
 
-  MOZ_MTLOG(PR_LOG_DEBUG, "Transport ready for flow " << (rtcp ? "rtcp" : "rtp"));
+  MOZ_MTLOG(PR_LOG_DEBUG, "Transport closed for flow " << (rtcp ? "rtcp" : "rtp"));
+
+  NS_WARNING(
+      "MediaPipeline Transport failed. This is not properly cleaned up yet");
+
 
   // TODO(ekr@rtfm.com): SECURITY: Figure out how to clean up if the
   // connection was good and now it is bad.
   // TODO(ekr@rtfm.com): Report up so that the PC knows we
   // have experienced an error.
 
   return NS_OK;
 }
 
 nsresult MediaPipeline::SendPacket(TransportFlow *flow, const void *data,
                                    int len) {
   // Note that we bypass the DTLS layer here
   TransportLayerDtls *dtls = static_cast<TransportLayerDtls *>(
       flow->GetLayer(TransportLayerDtls::ID()));
-  PR_ASSERT(dtls);
+  MOZ_ASSERT(dtls);
 
   TransportResult res = dtls->downward()->
       SendPacket(static_cast<const unsigned char *>(data), len);
 
   if (res != len) {
     // Ignore blocking indications
     if (res == TE_WOULDBLOCK)
       return NS_OK;
@@ -237,87 +257,89 @@ nsresult MediaPipeline::SendPacket(Trans
 
   return NS_OK;
 }
 
 void MediaPipeline::increment_rtp_packets_sent() {
   ++rtp_packets_sent_;
   if (!(rtp_packets_sent_ % 1000)) {
     MOZ_MTLOG(PR_LOG_DEBUG, "RTP packet count " << static_cast<void *>(this)
-         << ": " << rtp_packets_sent_);
+              << ": " << rtp_packets_sent_);
   }
 }
 
 void MediaPipeline::increment_rtcp_packets_sent() {
+  ++rtcp_packets_sent_;
   if (!(rtcp_packets_sent_ % 1000)) {
     MOZ_MTLOG(PR_LOG_DEBUG, "RTCP packet count " << static_cast<void *>(this)
-         << ": " << rtcp_packets_sent_);
+              << ": " << rtcp_packets_sent_);
   }
 }
 
 void MediaPipeline::increment_rtp_packets_received() {
   ++rtp_packets_received_;
   if (!(rtp_packets_received_ % 1000)) {
     MOZ_MTLOG(PR_LOG_DEBUG, "RTP packet count " << static_cast<void *>(this)
-         << ": " << rtp_packets_received_);
+              << ": " << rtp_packets_received_);
   }
 }
 
 void MediaPipeline::increment_rtcp_packets_received() {
+  ++rtcp_packets_received_;
   if (!(rtcp_packets_received_ % 1000)) {
     MOZ_MTLOG(PR_LOG_DEBUG, "RTCP packet count " << static_cast<void *>(this)
-         << ": " << rtcp_packets_received_);
+              << ": " << rtcp_packets_received_);
   }
 }
 
 
 void MediaPipeline::RtpPacketReceived(TransportLayer *layer,
                                       const unsigned char *data,
                                       size_t len) {
   if (!transport_->pipeline()) {
     MOZ_MTLOG(PR_LOG_DEBUG, "Discarding incoming packet; transport disconnected");
     return;
   }
 
   // TODO(ekr@rtfm.com): filter for DTLS here and in RtcpPacketReceived
   // TODO(ekr@rtfm.com): filter on SSRC for bundle
   increment_rtp_packets_received();
 
-  PR_ASSERT(rtp_recv_srtp_);  // This should never happen
+  MOZ_ASSERT(rtp_recv_srtp_);  // This should never happen
 
   if (direction_ == TRANSMIT) {
     // Discard any media that is being transmitted to us
     // This will be unnecessary when we have SSRC filtering.
     return;
   }
 
   // Make a copy rather than cast away constness
   ScopedDeletePtr<unsigned char> inner_data(
       new unsigned char[len]);
   memcpy(inner_data, data, len);
   int out_len;
   nsresult res = rtp_recv_srtp_->UnprotectRtp(inner_data,
-                                         len, len, &out_len);
+                                              len, len, &out_len);
   if (!NS_SUCCEEDED(res))
     return;
 
   (void)conduit_->ReceivedRTPPacket(inner_data, out_len);  // Ignore error codes
 }
 
 void MediaPipeline::RtcpPacketReceived(TransportLayer *layer,
-                                              const unsigned char *data,
-                                              size_t len) {
+                                       const unsigned char *data,
+                                       size_t len) {
   if (!transport_->pipeline()) {
     MOZ_MTLOG(PR_LOG_DEBUG, "Discarding incoming packet; transport disconnected");
     return;
   }
 
   increment_rtcp_packets_received();
 
-  PR_ASSERT(rtcp_recv_srtp_);  // This should never happen
+  MOZ_ASSERT(rtcp_recv_srtp_);  // This should never happen
 
   // Make a copy rather than cast away constness
   ScopedDeletePtr<unsigned char> inner_data(
       new unsigned char[len]);
   memcpy(inner_data, data, len);
   int out_len;
 
   nsresult res = rtcp_recv_srtp_->UnprotectRtcp(inner_data, len, len, &out_len);
@@ -327,22 +349,43 @@ void MediaPipeline::RtcpPacketReceived(T
 
   (void)conduit_->ReceivedRTCPPacket(inner_data, out_len);  // Ignore error codes
 }
 
 bool MediaPipeline::IsRtp(const unsigned char *data, size_t len) {
   if (len < 2)
     return false;
 
-  // TODO(ekr@rtfm.com): this needs updating in light of RFC5761
-  if ((data[1] >= 200) && (data[1] <= 204))
+  // Check if this is a RTCP packet. Logic based on the types listed in
+  // media/webrtc/trunk/src/modules/rtp_rtcp/source/rtp_utility.cc
+
+  // Anything outside this range is RTP.
+  if ((data[1] < 192) || (data[1] > 207))
+    return true;
+  
+  if (data[1] == 192)  // FIR
     return false;
+  
+  if (data[1] == 193)  // NACK, but could also be RTP. This makes us sad
+    return true;       // but it's how webrtc.org behaves.
 
+  if (data[1] == 194)
+    return true;
+
+  if (data[1] == 195)  // IJ.
+    return false;   
+
+  if ((data[1] > 195) && (data[1] < 200))  // the > 195 is redundant
+    return true;
+
+  if ((data[1] >= 200) && (data[1] <= 207))  // SR, RR, SDES, BYE,
+    return false;                            // APP, RTPFB, PSFB, XR
+
+  MOZ_ASSERT(false);  // Not reached, belt and suspenders.
   return true;
-
 }
 
 void MediaPipeline::PacketReceived(TransportLayer *layer,
                                    const unsigned char *data,
                                    size_t len) {
   if (!transport_->pipeline()) {
     MOZ_MTLOG(PR_LOG_DEBUG, "Discarding incoming packet; transport disconnected");
     return;
@@ -352,25 +395,27 @@ void MediaPipeline::PacketReceived(Trans
     RtpPacketReceived(layer, data, len);
   } else {
     RtcpPacketReceived(layer, data, len);
   }
 }
 
 nsresult MediaPipelineTransmit::Init() {
   // TODO(ekr@rtfm.com): Check for errors
-  MOZ_MTLOG(PR_LOG_DEBUG, "Attaching pipeline to stream " << static_cast<void *>(stream_) <<
-                    " conduit type=" << (conduit_->type() == MediaSessionConduit::AUDIO ?
-                                         "audio" : "video") <<
-                    " hints=" << stream_->GetHintContents());
+  MOZ_MTLOG(PR_LOG_DEBUG, "Attaching pipeline to stream " 
+            << static_cast<void *>(stream_) <<
+            " conduit type=" << 
+            (conduit_->type() == MediaSessionConduit::AUDIO ?
+             "audio" : "video") <<
+            " hints=" << stream_->GetHintContents());
 
   if (main_thread_) {
     main_thread_->Dispatch(WrapRunnable(
-      stream_->GetStream(), &MediaStream::AddListener, listener_),
-      NS_DISPATCH_SYNC);
+        stream_->GetStream(), &MediaStream::AddListener, listener_),
+                           NS_DISPATCH_SYNC);
   }
   else {
     stream_->GetStream()->AddListener(listener_);
   }
 
   return NS_OK;
 }
 
@@ -379,24 +424,22 @@ nsresult MediaPipeline::PipelineTranspor
   if (!pipeline_)
     return NS_OK;  // Detached
 
   if (!pipeline_->rtp_send_srtp_) {
     MOZ_MTLOG(PR_LOG_DEBUG, "Couldn't write RTP packet; SRTP not set up yet");
     return NS_OK;
   }
 
-  PR_ASSERT(pipeline_->rtp_transport_);
-  if (!pipeline_->rtp_transport_) {
-    MOZ_MTLOG(PR_LOG_DEBUG, "Couldn't write RTP packet (null flow)");
-    return NS_ERROR_NULL_POINTER;
-  }
+  MOZ_ASSERT(pipeline_->rtp_transport_);
+  NS_ENSURE_TRUE(pipeline_->rtp_transport_, NS_ERROR_NULL_POINTER);
 
   // libsrtp enciphers in place, so we need a new, big enough
   // buffer.
+  // XXX. allocates and deletes one buffer per packet sent.
   int max_len = len + SRTP_MAX_EXPANSION;
   ScopedDeletePtr<unsigned char> inner_data(
       new unsigned char[max_len]);
   memcpy(inner_data, data, len);
 
   int out_len;
   nsresult res = pipeline_->rtp_send_srtp_->ProtectRtp(inner_data,
                                                        len,
@@ -415,23 +458,22 @@ nsresult MediaPipeline::PipelineTranspor
   if (!pipeline_)
     return NS_OK;  // Detached
 
   if (!pipeline_->rtcp_send_srtp_) {
     MOZ_MTLOG(PR_LOG_DEBUG, "Couldn't write RTCP packet; SRTCP not set up yet");
     return NS_OK;
   }
 
-  if (!pipeline_->rtcp_transport_) {
-    MOZ_MTLOG(PR_LOG_DEBUG, "Couldn't write RTCP packet (null flow)");
-    return NS_ERROR_NULL_POINTER;
-  }
+  MOZ_ASSERT(pipeline_->rtcp_transport_);
+  NS_ENSURE_TRUE(pipeline_->rtcp_transport_, NS_ERROR_NULL_POINTER);
 
   // libsrtp enciphers in place, so we need a new, big enough
   // buffer.
+  // XXX. allocates and deletes one buffer per packet sent.
   int max_len = len + SRTP_MAX_EXPANSION;
   ScopedDeletePtr<unsigned char> inner_data(
       new unsigned char[max_len]);
   memcpy(inner_data, data, len);
 
   int out_len;
   nsresult res = pipeline_->rtcp_send_srtp_->ProtectRtcp(inner_data,
                                                          len,
@@ -476,49 +518,49 @@ NotifyQueuedTrackChanges(MediaStreamGrap
     AudioSegment::ChunkIterator iter(*audio);
     while(!iter.IsEnded()) {
       pipeline_->ProcessAudioChunk(static_cast<AudioSessionConduit *>
                                    (pipeline_->conduit_.get()),
                                    rate, *iter);
       iter.Next();
     }
   } else if (queued_media.GetType() == MediaSegment::VIDEO) {
-    #ifdef MOZILLA_INTERNAL_API
+#ifdef MOZILLA_INTERNAL_API
     if (pipeline_->conduit_->type() != MediaSessionConduit::VIDEO) {
       // Ignore data in case we have a muxed stream
       return;
     }
     VideoSegment* video = const_cast<VideoSegment *>(
         static_cast<const VideoSegment *>(&queued_media));
 
     VideoSegment::ChunkIterator iter(*video);
     while(!iter.IsEnded()) {
       pipeline_->ProcessVideoChunk(static_cast<VideoSessionConduit *>
                                    (pipeline_->conduit_.get()),
                                    rate, *iter);
       iter.Next();
     }
-    #endif
+#endif
   } else {
     // Ignore
   }
 }
 
 void MediaPipelineTransmit::ProcessAudioChunk(AudioSessionConduit *conduit,
                                               TrackRate rate,
                                               AudioChunk& chunk) {
   // TODO(ekr@rtfm.com): Do more than one channel
   nsAutoArrayPtr<int16_t> samples(new int16_t[chunk.mDuration]);
 
   if (chunk.mBuffer) {
     switch(chunk.mBufferFormat) {
       case nsAudioStream::FORMAT_U8:
       case nsAudioStream::FORMAT_FLOAT32:
-        MOZ_MTLOG(PR_LOG_ERROR, "Can't process audio exceptin 16-bit PCM yet");
-        PR_ASSERT(PR_FALSE);
+        MOZ_MTLOG(PR_LOG_ERROR, "Can't process audio except in 16-bit PCM yet");
+        MOZ_ASSERT(PR_FALSE);
         return;
         break;
       case nsAudioStream::FORMAT_S16:
         {
           // Code based on nsAudioStream
           const short* buf = static_cast<const short *>(chunk.mBuffer->Data());
 
           PRInt32 volume = PRInt32((1 << 16) * chunk.mVolume);
@@ -527,21 +569,22 @@ void MediaPipelineTransmit::ProcessAudio
 #if defined(IS_BIG_ENDIAN)
             s = ((s & 0x00ff) << 8) | ((s & 0xff00) >> 8);
 #endif
             samples[i] = short((PRInt32(s) * volume) >> 16);
           }
         }
         break;
       default:
-        PR_ASSERT(PR_FALSE);
+        MOZ_ASSERT(PR_FALSE);
         return;
         break;
     }
   } else {
+    // This means silence.
     for (PRUint32 i = 0; i < chunk.mDuration; ++i) {
       samples[i] = 0;
     }
   }
 
   MOZ_MTLOG(PR_LOG_DEBUG, "Sending an audio frame");
   conduit->SendAudioFrame(samples.get(), chunk.mDuration, rate, 0);
 }
@@ -552,17 +595,17 @@ void MediaPipelineTransmit::ProcessVideo
                                               VideoChunk& chunk) {
   // We now need to send the video frame to the other side
   layers::Image *img = chunk.mFrame.GetImage();
 
   ImageFormat format = img->GetFormat();
 
   if (format != PLANAR_YCBCR) {
     MOZ_MTLOG(PR_LOG_ERROR, "Can't process non-YCBCR video");
-    PR_ASSERT(PR_FALSE);
+    MOZ_ASSERT(PR_FALSE);
     return;
   }
 
   // Cast away constness b/c some of the accessors are non-const
   layers::PlanarYCbCrImage* yuv =
     const_cast<layers::PlanarYCbCrImage *>(
       static_cast<const layers::PlanarYCbCrImage *>(img));
 
@@ -596,35 +639,35 @@ void MediaPipelineTransmit::ProcessVideo
   conduit->SendVideoFrame(y, length, width, height, mozilla::kVideoI420, 0);
 }
 #endif
 
 nsresult MediaPipelineReceiveAudio::Init() {
   MOZ_MTLOG(PR_LOG_DEBUG, __FUNCTION__);
   if (main_thread_) {
     main_thread_->Dispatch(WrapRunnable(
-      stream_->GetStream(), &MediaStream::AddListener, listener_),
-      NS_DISPATCH_SYNC);
+        stream_->GetStream(), &MediaStream::AddListener, listener_),
+                           NS_DISPATCH_SYNC);
   }
   else {
     stream_->GetStream()->AddListener(listener_);
   }
 
   return NS_OK;
 }
 
 void MediaPipelineReceiveAudio::PipelineListener::
 NotifyPull(MediaStreamGraph* graph, StreamTime total) {
   if (!pipeline_)
     return;  // Detached
 
   SourceMediaStream *source =
     pipeline_->stream_->GetStream()->AsSourceStream();
 
-  PR_ASSERT(source);
+  MOZ_ASSERT(source);
   if (!source) {
     MOZ_MTLOG(PR_LOG_ERROR, "NotifyPull() called from a non-SourceMediaStream");
     return;
   }
 
   // "total" is absolute stream time.
   // StreamTime desired = total - played_;
   played_ = total;
@@ -643,37 +686,36 @@ NotifyPull(MediaStreamGraph* graph, Stre
   }
 
   while (num_samples--) {
     // TODO(ekr@rtfm.com): Is there a way to avoid mallocating here?
     nsRefPtr<SharedBuffer> samples = SharedBuffer::Create(1000);
     int samples_length;
 
     MediaConduitErrorCode err =
-      static_cast<AudioSessionConduit*>(pipeline_->conduit_.get())->GetAudioFrame(
-        static_cast<int16_t *>(samples->Data()),
-        16000,  // Sampling rate fixed at 16 kHz for now
-        0,  // TODO(ekr@rtfm.com): better estimate of capture delay
-        samples_length);
+        static_cast<AudioSessionConduit*>(pipeline_->conduit_.get())->GetAudioFrame(
+            static_cast<int16_t *>(samples->Data()),
+            16000,  // Sampling rate fixed at 16 kHz for now
+            0,  // TODO(ekr@rtfm.com): better estimate of capture delay
+            samples_length);
 
     if (err != kMediaConduitNoError)
       return;
 
     MOZ_MTLOG(PR_LOG_DEBUG, "Audio conduit returned buffer of length " << samples_length);
 
     AudioSegment segment;
     segment.Init(1);
     segment.AppendFrames(samples.forget(), samples_length,
-      0, samples_length, nsAudioStream::FORMAT_S16);
+                         0, samples_length, nsAudioStream::FORMAT_S16);
 
     char buf[32];
     PR_snprintf(buf, 32, "%p", source);
-    MOZ_MTLOG(PR_LOG_DEBUG, "Appended audio segments to stream " << buf);
     source->AppendToTrack(1,  // TODO(ekr@rtfm.com): Track ID
-      &segment);
+                          &segment);
   }
 }
 
 nsresult MediaPipelineReceiveVideo::Init() {
   MOZ_MTLOG(PR_LOG_DEBUG, __FUNCTION__);
 
   static_cast<VideoSessionConduit *>(conduit_.get())->
       AttachRenderer(renderer_);
@@ -684,30 +726,30 @@ nsresult MediaPipelineReceiveVideo::Init
 MediaPipelineReceiveVideo::PipelineRenderer::PipelineRenderer(
     MediaPipelineReceiveVideo *pipeline) :
     pipeline_(pipeline),
     width_(640), height_(480) {
 
 #ifdef MOZILLA_INTERNAL_API
   image_container_ = layers::LayerManager::CreateImageContainer();
   SourceMediaStream *source =
-    pipeline_->stream_->GetStream()->AsSourceStream();
-  source->AddTrack(1, 30, 0, new VideoSegment());
+      pipeline_->stream_->GetStream()->AsSourceStream();
+  source->AddTrack(1 /* Track ID */, 30, 0, new VideoSegment());
   source->AdvanceKnownTracksTime(STREAM_TIME_MAX);
 #endif
 }
 
 void MediaPipelineReceiveVideo::PipelineRenderer::RenderVideoFrame(
     const unsigned char* buffer,
     unsigned int buffer_size,
     uint32_t time_stamp,
     int64_t render_time) {
 #ifdef MOZILLA_INTERNAL_API
   SourceMediaStream *source =
-    pipeline_->stream_->GetStream()->AsSourceStream();
+      pipeline_->stream_->GetStream()->AsSourceStream();
 
   // Create a video frame and append it to the track.
   ImageFormat format = PLANAR_YCBCR;
   nsRefPtr<layers::Image> image = image_container_->CreateImage(&format, 1);
 
   layers::PlanarYCbCrImage* videoImage = static_cast<layers::PlanarYCbCrImage*>(image.get());
   PRUint8* frame = const_cast<PRUint8*>(static_cast<const PRUint8*> (buffer));
   const PRUint8 lumaBpp = 8;
@@ -726,17 +768,16 @@ void MediaPipelineReceiveVideo::Pipeline
   data.mPicSize = gfxIntSize(width_, height_);
   data.mStereoMode = STEREO_MODE_MONO;
 
   videoImage->SetData(data);
 
   VideoSegment segment;
   char buf[32];
   PR_snprintf(buf, 32, "%p", source);
-  MOZ_MTLOG(PR_LOG_DEBUG, "Appended video segments to stream " << buf);
 
   segment.AppendFrame(image.forget(), 1, gfxIntSize(width_, height_));
   source->AppendToTrack(1, &(segment));
 #endif
 }
 
 
 }  // end namespace
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
@@ -33,41 +33,43 @@ namespace mozilla {
 //
 // RECEIVE
 // network -> transport -> [us] -> conduit -> [us] -> stream -> Playout 
 //
 // The boxes labeled [us] are just bridge logic implemented in this class
 class MediaPipeline : public sigslot::has_slots<> {
  public:
   enum Direction { TRANSMIT, RECEIVE };
-
+  enum State { MP_CONNECTING, MP_OPEN, MP_CLOSED };
   MediaPipeline(Direction direction,
                 nsCOMPtr<nsIEventTarget> main_thread,
                 nsCOMPtr<nsIEventTarget> sts_thread,
                 nsDOMMediaStream* stream,
                 RefPtr<MediaSessionConduit> conduit,
-                mozilla::RefPtr<TransportFlow> rtp_transport,
-                mozilla::RefPtr<TransportFlow> rtcp_transport) :
-      direction_(direction),
-      stream_(stream),
-      conduit_(conduit),
-      rtp_transport_(rtp_transport),
-      rtcp_transport_(rtcp_transport),
-      main_thread_(main_thread),
-      sts_thread_(sts_thread),
-      transport_(new PipelineTransport(this)),
-      rtp_send_srtp_(),
-      rtcp_send_srtp_(),
-      rtp_recv_srtp_(),
-      rtcp_recv_srtp_(),
-      rtp_packets_sent_(0),
-      rtcp_packets_sent_(0),
-      rtp_packets_received_(0),
-      rtcp_packets_received_(0),
-      muxed_((rtcp_transport_ == NULL) || (rtp_transport_ == rtcp_transport_)) {
+                RefPtr<TransportFlow> rtp_transport,
+                RefPtr<TransportFlow> rtcp_transport)
+      : direction_(direction),
+        stream_(stream),
+        conduit_(conduit),
+        rtp_transport_(rtp_transport),
+        rtp_state_(MP_CONNECTING),
+        rtcp_transport_(rtcp_transport),
+        rtcp_state_(MP_CONNECTING),
+        main_thread_(main_thread),
+        sts_thread_(sts_thread),
+        transport_(new PipelineTransport(this)),
+        rtp_send_srtp_(),
+        rtcp_send_srtp_(),
+        rtp_recv_srtp_(),
+        rtcp_recv_srtp_(),
+        rtp_packets_sent_(0),
+        rtcp_packets_sent_(0),
+        rtp_packets_received_(0),
+        rtcp_packets_received_(0),
+        muxed_((rtcp_transport_ == NULL) || (rtp_transport_ == rtcp_transport_)) {
     Init();
   }
 
   virtual ~MediaPipeline() {
     DetachTransport();
   }
 
   virtual nsresult Init();
@@ -80,23 +82,23 @@ class MediaPipeline : public sigslot::ha
   int rtp_packets_sent() const { return rtp_packets_sent_; }
   int rtcp_packets_sent() const { return rtp_packets_sent_; }
   int rtp_packets_received() const { return rtp_packets_received_; }
   int rtcp_packets_received() const { return rtp_packets_received_; }
 
   // Thread counting
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaPipeline)
 
- protected:
+  protected:
   // Separate class to allow ref counting
   class PipelineTransport : public TransportInterface {
    public:
     // Implement the TransportInterface functions
-    PipelineTransport(MediaPipeline *pipeline) :
-        pipeline_(pipeline) {}
+    PipelineTransport(MediaPipeline *pipeline)
+        : pipeline_(pipeline) {}
     void Detach() { pipeline_ = NULL; }
     MediaPipeline *pipeline() const { return pipeline_; }
 
     virtual nsresult SendRtpPacket(const void* data, int len);
     virtual nsresult SendRtcpPacket(const void* data, int len);
 
    private:
     MediaPipeline *pipeline_;  // Raw pointer to avoid cycles
@@ -122,25 +124,27 @@ class MediaPipeline : public sigslot::ha
   void PacketReceived(TransportLayer *layer, const unsigned char *data,
                       size_t len);
 
 
   Direction direction_;
   nsDOMMediaStream* stream_;
   RefPtr<MediaSessionConduit> conduit_;
   RefPtr<TransportFlow> rtp_transport_;
+  State rtp_state_;
   RefPtr<TransportFlow> rtcp_transport_;
+  State rtcp_state_;
   nsCOMPtr<nsIEventTarget> main_thread_;
   nsCOMPtr<nsIEventTarget> sts_thread_;
-  mozilla::RefPtr<PipelineTransport> transport_;
+  RefPtr<PipelineTransport> transport_;
   bool transport_connected_;
-  mozilla::RefPtr<SrtpFlow> rtp_send_srtp_;
-  mozilla::RefPtr<SrtpFlow> rtcp_send_srtp_;
-  mozilla::RefPtr<SrtpFlow> rtp_recv_srtp_;
-  mozilla::RefPtr<SrtpFlow> rtcp_recv_srtp_;
+  RefPtr<SrtpFlow> rtp_send_srtp_;
+  RefPtr<SrtpFlow> rtcp_send_srtp_;
+  RefPtr<SrtpFlow> rtp_recv_srtp_;
+  RefPtr<SrtpFlow> rtcp_recv_srtp_;
   int rtp_packets_sent_;
   int rtcp_packets_sent_;
   int rtp_packets_received_;
   int rtcp_packets_received_;
   bool muxed_;
 
  private:
   virtual void DetachTransportInt();
@@ -152,18 +156,18 @@ class MediaPipeline : public sigslot::ha
 // A specialization of pipeline for reading from an input device
 // and transmitting to the network.
 class MediaPipelineTransmit : public MediaPipeline {
  public:
   MediaPipelineTransmit(nsCOMPtr<nsIEventTarget> main_thread,
                         nsCOMPtr<nsIEventTarget> sts_thread,
                         nsDOMMediaStream* stream,
                         RefPtr<MediaSessionConduit> conduit,
-                        mozilla::RefPtr<TransportFlow> rtp_transport,
-                        mozilla::RefPtr<TransportFlow> rtcp_transport) :
+                        RefPtr<TransportFlow> rtp_transport,
+                        RefPtr<TransportFlow> rtcp_transport) :
       MediaPipeline(TRANSMIT, main_thread, sts_thread,
                     stream, conduit, rtp_transport,
                     rtcp_transport),
       listener_(new PipelineListener(this)) {
     Init();  // TODO(ekr@rtfm.com): ignoring error
   }
 
   // Initialize (stuff here may fail)
@@ -186,17 +190,17 @@ class MediaPipelineTransmit : public Med
     stream_ = NULL;
     listener_->Detach();
   }
 
   // Separate class to allow ref counting
   class PipelineListener : public MediaStreamListener {
    public:
     PipelineListener(MediaPipelineTransmit *pipeline) :
-        pipeline_(pipeline) {}
+    pipeline_(pipeline) {}
     void Detach() { pipeline_ = NULL; }
 
 
     // Implement MediaStreamListener
     virtual void NotifyQueuedTrackChanges(MediaStreamGraph* graph, TrackID tid,
                                           TrackRate rate,
                                           TrackTicks offset,
                                           PRUint32 events,
@@ -205,35 +209,35 @@ class MediaPipelineTransmit : public Med
 
    private:
     MediaPipelineTransmit *pipeline_;  // Raw pointer to avoid cycles
   };
   friend class PipelineListener;
 
  private:
   virtual void ProcessAudioChunk(AudioSessionConduit *conduit,
-                                 TrackRate rate, mozilla::AudioChunk& chunk);
+                                 TrackRate rate, AudioChunk& chunk);
 #ifdef MOZILLA_INTERNAL_API
   virtual void ProcessVideoChunk(VideoSessionConduit *conduit,
-                                 TrackRate rate, mozilla::VideoChunk& chunk);
+                                 TrackRate rate, VideoChunk& chunk);
 #endif
-  mozilla::RefPtr<PipelineListener> listener_;
+  RefPtr<PipelineListener> listener_;
 };
 
 
 // A specialization of pipeline for reading from the network and
 // rendering video.
 class MediaPipelineReceive : public MediaPipeline {
  public:
   MediaPipelineReceive(nsCOMPtr<nsIEventTarget> main_thread,
                        nsCOMPtr<nsIEventTarget> sts_thread,
                        nsDOMMediaStream* stream,
                        RefPtr<MediaSessionConduit> conduit,
-                       mozilla::RefPtr<TransportFlow> rtp_transport,
-                       mozilla::RefPtr<TransportFlow> rtcp_transport) :
+                       RefPtr<TransportFlow> rtp_transport,
+                       RefPtr<TransportFlow> rtcp_transport) :
       MediaPipeline(RECEIVE, main_thread, sts_thread,
                     stream, conduit, rtp_transport,
                     rtcp_transport),
       segments_added_(0) {
   }
 
   int segments_added() const { return segments_added_; }
 
@@ -247,18 +251,18 @@ class MediaPipelineReceive : public Medi
 // A specialization of pipeline for reading from the network and
 // rendering audio.
 class MediaPipelineReceiveAudio : public MediaPipelineReceive {
  public:
   MediaPipelineReceiveAudio(nsCOMPtr<nsIEventTarget> main_thread,
                             nsCOMPtr<nsIEventTarget> sts_thread,
                             nsDOMMediaStream* stream,
                             RefPtr<AudioSessionConduit> conduit,
-                            mozilla::RefPtr<TransportFlow> rtp_transport,
-                            mozilla::RefPtr<TransportFlow> rtcp_transport) :
+                            RefPtr<TransportFlow> rtp_transport,
+                            RefPtr<TransportFlow> rtcp_transport) :
       MediaPipelineReceive(main_thread, sts_thread,
                            stream, conduit, rtp_transport,
                            rtcp_transport),
       listener_(new PipelineListener(this)) {
     Init();
   }
 
   ~MediaPipelineReceiveAudio() {
@@ -275,18 +279,18 @@ class MediaPipelineReceiveAudio : public
     listener_->Detach();
   }
 
  private:
   // Separate class to allow ref counting
   class PipelineListener : public MediaStreamListener {
    public:
     PipelineListener(MediaPipelineReceiveAudio *pipeline)
-      : pipeline_(pipeline)
-      , played_(0) {}
+        : pipeline_(pipeline),
+        played_(0) {}
     void Detach() { pipeline_ = NULL; }
 
     // Implement MediaStreamListener
     virtual void NotifyQueuedTrackChanges(MediaStreamGraph* graph, TrackID tid,
                                           TrackRate rate,
                                           TrackTicks offset,
                                           PRUint32 events,
                                           const MediaSegment& queued_media) {}
@@ -295,42 +299,42 @@ class MediaPipelineReceiveAudio : public
    private:
     MediaPipelineReceiveAudio *pipeline_;  // Raw pointer to avoid cycles
     StreamTime played_;
   };
   friend class PipelineListener;
 
   nsresult Init();
 
-  mozilla::RefPtr<PipelineListener> listener_;
+  RefPtr<PipelineListener> listener_;
 };
 
 
 // A specialization of pipeline for reading from the network and
 // rendering video.
 class MediaPipelineReceiveVideo : public MediaPipelineReceive {
  public:
   MediaPipelineReceiveVideo(nsCOMPtr<nsIEventTarget> main_thread,
                             nsCOMPtr<nsIEventTarget> sts_thread,
                             nsDOMMediaStream* stream,
                             RefPtr<VideoSessionConduit> conduit,
-                            mozilla::RefPtr<TransportFlow> rtp_transport,
-                            mozilla::RefPtr<TransportFlow> rtcp_transport) :
+                            RefPtr<TransportFlow> rtp_transport,
+                            RefPtr<TransportFlow> rtcp_transport) :
       MediaPipelineReceive(main_thread, sts_thread,
                            stream, conduit, rtp_transport,
                            rtcp_transport),
       renderer_(new PipelineRenderer(this)) {
     Init();
   }
 
   ~MediaPipelineReceiveVideo() {
   }
 
  private:
-  class PipelineRenderer : public mozilla::VideoRenderer {
+  class PipelineRenderer : public VideoRenderer {
    public:
     PipelineRenderer(MediaPipelineReceiveVideo *);
     void Detach() { pipeline_ = NULL; }
 
     // Implement VideoRenderer
     virtual void FrameSizeChange(unsigned int width,
                                  unsigned int height,
                                  unsigned int number_of_streams) {
@@ -350,14 +354,14 @@ class MediaPipelineReceiveVideo : public
     nsRefPtr<layers::ImageContainer> image_container_;
 #endif
     int width_;
     int height_;
   };
   friend class PipelineRenderer;
 
   nsresult Init();
-  mozilla::RefPtr<PipelineRenderer> renderer_;
+  RefPtr<PipelineRenderer> renderer_;
 };
 
 
 }  // end namespace
 #endif
--- a/media/webrtc/signaling/src/mediapipeline/SrtpFlow.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/SrtpFlow.cpp
@@ -18,19 +18,16 @@
 using namespace mozilla;
 MOZ_MTLOG_MODULE("mediapipeline");
 
 namespace mozilla {
 
 bool SrtpFlow::initialized;  // Static
 
 SrtpFlow::~SrtpFlow() {
-  if (policy_) {
-    delete policy_;
-  }
   if (session_) {
     srtp_dealloc(session_);
   }
 }
 
 RefPtr<SrtpFlow> SrtpFlow::Create(int cipher_suite,
                                            bool inbound,
                                            const void *key,
@@ -46,60 +43,61 @@ RefPtr<SrtpFlow> SrtpFlow::Create(int ci
     return NULL;
   }
 
   if (key_len != SRTP_TOTAL_KEY_LENGTH) {
     MOZ_MTLOG(PR_LOG_ERROR, "Invalid SRTP key length");
     return NULL;
   }
 
-  // First create the policy
-  flow->policy_ = new srtp_policy_t();
-  memset(flow->policy_, 0, sizeof(srtp_policy_t));
+  srtp_policy_t policy;
+  memset(&policy, 0, sizeof(srtp_policy_t));
 
   // Note that we set the same cipher suite for RTP and RTCP
   // since any flow can only have one cipher suite with DTLS-SRTP
   switch (cipher_suite) {
     case SRTP_AES128_CM_HMAC_SHA1_80:
       MOZ_MTLOG(PR_LOG_DEBUG, "Setting SRTP cipher suite SRTP_AES128_CM_HMAC_SHA1_80");
-      crypto_policy_set_aes_cm_128_hmac_sha1_80(&flow->policy_->rtp);
-      crypto_policy_set_aes_cm_128_hmac_sha1_80(&flow->policy_->rtcp);
+      crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtp);
+      crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp);
       break;
     case SRTP_AES128_CM_HMAC_SHA1_32:
       MOZ_MTLOG(PR_LOG_DEBUG, "Setting SRTP cipher suite SRTP_AES128_CM_HMAC_SHA1_32");
-      crypto_policy_set_aes_cm_128_hmac_sha1_32(&flow->policy_->rtp);
-      crypto_policy_set_aes_cm_128_hmac_sha1_32(&flow->policy_->rtcp);
+      crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtp);
+      crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtcp);
       break;
     default:
       MOZ_MTLOG(PR_LOG_ERROR, "Request to set unknown SRTP cipher suite");
       return NULL;
   }
-  flow->policy_->key = const_cast<unsigned char *>(
+  // This key is copied into the srtp_t object, so we don't
+  // need to keep it.
+  policy.key = const_cast<unsigned char *>(
       static_cast<const unsigned char *>(key));
-  flow->policy_->ssrc.type = inbound ? ssrc_any_inbound : ssrc_any_outbound;
-  flow->policy_->ssrc.value = 0;
-  flow->policy_->ekt = NULL;
-  flow->policy_->window_size = 1024;  // TODO(ekr@rtfm.com): how to set?
-  flow->policy_->allow_repeat_tx = 0;  // TODO(ekr@rtfm.com): revisit?
-  flow->policy_->next = NULL;
+  policy.ssrc.type = inbound ? ssrc_any_inbound : ssrc_any_outbound;
+  policy.ssrc.value = 0;
+  policy.ekt = NULL;
+  policy.window_size = 0;      // Use the default value.
+  policy.allow_repeat_tx = 0;  // TODO(ekr@rtfm.com): revisit?
+  policy.next = NULL;
 
   // Now make the session
-  err_status_t r = srtp_create(&flow->session_, flow->policy_);
+  err_status_t r = srtp_create(&flow->session_, &policy);
   if (r != err_status_ok) {
     MOZ_MTLOG(PR_LOG_ERROR, "Error creating srtp session");
     return NULL;
   }
 
   return flow;
 }
 
 
 nsresult SrtpFlow::CheckInputs(bool protect, void *in, int in_len,
                                int max_len, int *out_len) {
-  PR_ASSERT(in);
+  MOZ_ASSERT(in);
   if (!in) {
     MOZ_MTLOG(PR_LOG_ERROR, "NULL input value");
     return NS_ERROR_NULL_POINTER;
   }
 
   if (in_len < 0) {
     MOZ_MTLOG(PR_LOG_ERROR, "Input length is negative");
     return NS_ERROR_ILLEGAL_VALUE;
@@ -136,17 +134,17 @@ nsresult SrtpFlow::ProtectRtp(void *in, 
   int len = in_len;
   err_status_t r = srtp_protect(session_, in, &len);
 
   if (r != err_status_ok) {
     MOZ_MTLOG(PR_LOG_ERROR, "Error protecting SRTP packet");
     return NS_ERROR_FAILURE;
   }
 
-  PR_ASSERT(len < max_len);
+  MOZ_ASSERT(len <= max_len);
   *out_len = len;
 
 
   MOZ_MTLOG(PR_LOG_DEBUG, "Successfully protected an SRTP packet of len " << *out_len);
 
   return NS_OK;
 }
 
@@ -159,17 +157,17 @@ nsresult SrtpFlow::UnprotectRtp(void *in
   int len = in_len;
   err_status_t r = srtp_unprotect(session_, in, &len);
 
   if (r != err_status_ok) {
     MOZ_MTLOG(PR_LOG_ERROR, "Error unprotecting SRTP packet");
     return NS_ERROR_FAILURE;
   }
 
-  PR_ASSERT(len < max_len);
+  MOZ_ASSERT(len <= max_len);
   *out_len = len;
 
   MOZ_MTLOG(PR_LOG_DEBUG, "Successfully unprotected an SRTP packet of len " << *out_len);
 
   return NS_OK;
 }
 
 nsresult SrtpFlow::ProtectRtcp(void *in, int in_len,
@@ -181,17 +179,17 @@ nsresult SrtpFlow::ProtectRtcp(void *in,
   int len = in_len;
   err_status_t r = srtp_protect_rtcp(session_, in, &len);
 
   if (r != err_status_ok) {
     MOZ_MTLOG(PR_LOG_ERROR, "Error protecting SRTCP packet");
     return NS_ERROR_FAILURE;
   }
 
-  PR_ASSERT(len <= max_len);
+  MOZ_ASSERT(len <= max_len);
   *out_len = len;
 
   MOZ_MTLOG(PR_LOG_DEBUG, "Successfully protected an SRTCP packet of len " << *out_len);
 
   return NS_OK;
 }
 
 nsresult SrtpFlow::UnprotectRtcp(void *in, int in_len,
@@ -203,43 +201,43 @@ nsresult SrtpFlow::UnprotectRtcp(void *i
   int len = in_len;
   err_status_t r = srtp_unprotect_rtcp(session_, in, &len);
 
   if (r != err_status_ok) {
     MOZ_MTLOG(PR_LOG_ERROR, "Error unprotecting SRTCP packet");
     return NS_ERROR_FAILURE;
   }
 
-  PR_ASSERT(len <= max_len);
+  MOZ_ASSERT(len <= max_len);
   *out_len = len;
 
   MOZ_MTLOG(PR_LOG_DEBUG, "Successfully unprotected an SRTCP packet of len " << *out_len);
 
   return NS_OK;
 }
 
 // Statics
 void SrtpFlow::srtp_event_handler(srtp_event_data_t *data) {
   // TODO(ekr@rtfm.com): Implement this
-  abort();
+  MOZ_CRASH();
 }
 
 nsresult SrtpFlow::Init() {
   if (!initialized) {
     err_status_t r = srtp_init();
     if (r != err_status_ok) {
       MOZ_MTLOG(PR_LOG_ERROR, "Could not initialize SRTP");
-      PR_ASSERT(PR_FALSE);
+      MOZ_ASSERT(PR_FALSE);
       return NS_ERROR_FAILURE;
     }
 
     r = srtp_install_event_handler(&SrtpFlow::srtp_event_handler);
     if (r != err_status_ok) {
       MOZ_MTLOG(PR_LOG_ERROR, "Could not install SRTP event handler");
-      PR_ASSERT(PR_FALSE);
+      MOZ_ASSERT(PR_FALSE);
       return NS_ERROR_FAILURE;
     }
 
     initialized = true;
   }
 
   return NS_OK;
 }
--- a/media/webrtc/signaling/src/mediapipeline/SrtpFlow.h
+++ b/media/webrtc/signaling/src/mediapipeline/SrtpFlow.h
@@ -47,23 +47,22 @@ class SrtpFlow {
                          int max_len, int *out_len);
 
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SrtpFlow)
 
   static void srtp_event_handler(srtp_event_data_t *data);
 
 
  private:
-  SrtpFlow() : policy_(NULL), session_(NULL) {}
+  SrtpFlow() : session_(NULL) {}
 
   nsresult CheckInputs(bool protect, void *in, int in_len,
                        int max_len, int *out_len);
 
   static nsresult Init();
-  static bool initialized;  // Was SRTP initialized?
+  static bool initialized;  // Was libsrtp initialized? Only happens once.
 
-  srtp_policy_t *policy_;
   srtp_t session_;
 };
 
 }  // End of namespace
 #endif