Bug 1141749 - Prevent collisions in local SSRCs. r=mt, a=abillings
authorByron Campen [:bwc] <docfaraday@gmail.com>
Tue, 10 Mar 2015 13:54:34 -0700
changeset 250446 d76c709556bb
parent 250445 e92558fa59eb
child 250447 45897d27ef82
push id4589
push userryanvm@gmail.com
push date2015-03-19 02:20 +0000
treeherdermozilla-beta@d76c709556bb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmt, abillings
bugs1141749
milestone37.0
Bug 1141749 - Prevent collisions in local SSRCs. r=mt, a=abillings
media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
media/webrtc/signaling/src/jsep/JsepSessionImpl.h
--- a/media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
+++ b/media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
@@ -83,22 +83,26 @@ JsepSessionImpl::AddTrack(const RefPtr<J
   mLastError.clear();
   MOZ_ASSERT(track->GetDirection() == JsepTrack::kJsepTrackSending);
 
   if (track->GetMediaType() != SdpMediaSection::kApplication) {
     track->SetCNAME(mCNAME);
 
     if (track->GetSsrcs().empty()) {
       uint32_t ssrc;
-      SECStatus rv = PK11_GenerateRandom(
-          reinterpret_cast<unsigned char*>(&ssrc), sizeof(ssrc));
-      if (rv != SECSuccess) {
-        JSEP_SET_ERROR("Failed to generate SSRC, error=" << rv);
-        return NS_ERROR_FAILURE;
-      }
+      do {
+        SECStatus rv = PK11_GenerateRandom(
+            reinterpret_cast<unsigned char*>(&ssrc), sizeof(ssrc));
+        if (rv != SECSuccess) {
+          JSEP_SET_ERROR("Failed to generate SSRC, error=" << rv);
+          return NS_ERROR_FAILURE;
+        }
+      } while (mSsrcs.count(ssrc));
+
+      mSsrcs.insert(ssrc);
       track->AddSsrc(ssrc);
     }
   }
 
   JsepSendingTrack strack;
   strack.mTrack = track;
 
   mLocalTracks.push_back(strack);
--- a/media/webrtc/signaling/src/jsep/JsepSessionImpl.h
+++ b/media/webrtc/signaling/src/jsep/JsepSessionImpl.h
@@ -1,15 +1,16 @@
 /* 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 _JSEPSESSIONIMPL_H_
 #define _JSEPSESSIONIMPL_H_
 
+#include <set>
 #include <string>
 #include <vector>
 
 #include "signaling/src/jsep/JsepCodecDescription.h"
 #include "signaling/src/jsep/JsepTrack.h"
 #include "signaling/src/jsep/JsepSession.h"
 #include "signaling/src/jsep/JsepTrack.h"
 #include "signaling/src/jsep/JsepTrackImpl.h"
@@ -298,16 +299,19 @@ private:
   std::vector<JsepDtlsFingerprint> mDtlsFingerprints;
   uint64_t mSessionId;
   uint64_t mSessionVersion;
   std::vector<SdpExtmapAttributeList::Extmap> mAudioRtpExtensions;
   std::vector<SdpExtmapAttributeList::Extmap> mVideoRtpExtensions;
   UniquePtr<JsepUuidGenerator> mUuidGen;
   std::string mDefaultRemoteStreamId;
   std::string mCNAME;
+  // Used to prevent duplicate local SSRCs. Not used to prevent local/remote or
+  // remote-only duplication, which will be important for EKT but not now.
+  std::set<uint32_t> mSsrcs;
   UniquePtr<Sdp> mGeneratedLocalDescription; // Created but not set.
   UniquePtr<Sdp> mCurrentLocalDescription;
   UniquePtr<Sdp> mCurrentRemoteDescription;
   UniquePtr<Sdp> mPendingLocalDescription;
   UniquePtr<Sdp> mPendingRemoteDescription;
   std::vector<JsepCodecDescription*> mCodecs;
   std::string mLastError;
   SipccSdpParser mParser;