Bug 929534 r=jesup
authorJan-Ivar Bruaroey <jib@mozilla.com>
Fri, 25 Oct 2013 10:52:17 -0400
changeset 166112 dd7618acdabd7949586dc5e3b3fbb156ed817059
parent 166111 86cf81278443ce7c482266123e10f1e20bcd2066
child 166113 9861229c1b150b154dcea5da69dee7dd2e397393
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs929534
milestone27.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 929534 r=jesup
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/test/signaling_unittests.cpp
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp
@@ -19,16 +19,20 @@
 #include "PeerConnectionCtx.h"
 #include "runnable_utils.h"
 #include "cpr_socket.h"
 #include "debug-psipcc-types.h"
 #include "prcvar.h"
 
 #include "mozilla/Telemetry.h"
 
+#ifdef MOZILLA_INTERNAL_API
+#include "mozilla/dom/RTCPeerConnectionBinding.h"
+#endif
+
 #include "nsIObserverService.h"
 #include "nsIObserver.h"
 #include "mozilla/Services.h"
 #include "StaticPtr.h"
 extern "C" {
 #include "../sipcc/core/common/thread_monitor.h"
 }
 
@@ -36,16 +40,67 @@ static const char* logTag = "PeerConnect
 
 extern "C" {
 extern PRCondVar *ccAppReadyToStartCond;
 extern PRLock *ccAppReadyToStartLock;
 extern char ccAppReadyToStart;
 }
 
 namespace mozilla {
+
+using namespace dom;
+
+// Convert constraints to C structures
+
+#ifdef MOZILLA_INTERNAL_API
+static void
+Apply(const Optional<bool> &aSrc, cc_boolean_constraint_t *aDst,
+      bool mandatory = false) {
+  if (aSrc.WasPassed() && (mandatory || !aDst->was_passed)) {
+    aDst->was_passed = true;
+    aDst->value = aSrc.Value();
+    aDst->mandatory = mandatory;
+  }
+}
+#endif
+
+MediaConstraintsExternal::MediaConstraintsExternal() {
+  memset(&mConstraints, 0, sizeof(mConstraints));
+}
+
+MediaConstraintsExternal::MediaConstraintsExternal(
+    const MediaConstraintsInternal &aSrc) {
+  cc_media_constraints_t* c = &mConstraints;
+  memset(c, 0, sizeof(*c));
+#ifdef MOZILLA_INTERNAL_API
+  Apply(aSrc.mMandatory.mOfferToReceiveAudio, &c->offer_to_receive_audio, true);
+  Apply(aSrc.mMandatory.mOfferToReceiveVideo, &c->offer_to_receive_video, true);
+  Apply(aSrc.mMandatory.mMozDontOfferDataChannel, &c->moz_dont_offer_datachannel,
+        true);
+  if (aSrc.mOptional.WasPassed()) {
+    const Sequence<MediaConstraintSet> &array = aSrc.mOptional.Value();
+    for (uint32_t i = 0; i < array.Length(); i++) {
+      Apply(array[i].mOfferToReceiveAudio, &c->offer_to_receive_audio);
+      Apply(array[i].mOfferToReceiveVideo, &c->offer_to_receive_video);
+      Apply(array[i].mMozDontOfferDataChannel, &c->moz_dont_offer_datachannel);
+    }
+  }
+#endif
+}
+
+cc_media_constraints_t*
+MediaConstraintsExternal::build() const {
+  cc_media_constraints_t* cc  = (cc_media_constraints_t*)
+    cpr_malloc(sizeof(cc_media_constraints_t));
+  if (cc) {
+    *cc = mConstraints;
+  }
+  return cc;
+}
+
 class PeerConnectionCtxShutdown : public nsIObserver
 {
 public:
   NS_DECL_ISUPPORTS
 
   PeerConnectionCtxShutdown() {}
 
   void Init()
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.h
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.h
@@ -12,37 +12,40 @@
 #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"
 
 namespace mozilla {
 class PeerConnectionCtxShutdown;
+
+// Unit-test helper, because cc_media_constraints_t is hard to forward-declare
+
+class MediaConstraintsExternal {
+public:
+  MediaConstraintsExternal();
+  MediaConstraintsExternal(const dom::MediaConstraintsInternal &aOther);
+  cc_media_constraints_t* build() const;
+protected:
+  cc_media_constraints_t mConstraints;
+};
 }
 
 namespace sipcc {
 
 using namespace mozilla;
 
-// Unit-test helper, because cc_media_constraints_t is hard to forward-declare
-
-class MediaConstraintsExternal {
-public:
-  MediaConstraintsExternal(cc_media_constraints_t *aConstraints)
-  : mConstraints(aConstraints) {}
-  cc_media_constraints_t *mConstraints;
-};
-
 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/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -94,53 +94,16 @@ PRLogModuleInfo *signalingLogInfo() {
     logModuleInfo = PR_NewLogModule("signaling");
   }
   return logModuleInfo;
 }
 
 
 namespace sipcc {
 
-// Convert constraints to C structures
-
-#ifdef MOZILLA_INTERNAL_API
-static void
-Apply(const Optional<bool> &aSrc, cc_boolean_constraint_t *aDst,
-      bool mandatory = false) {
-  if (aSrc.WasPassed() && (mandatory || !aDst->was_passed)) {
-    aDst->was_passed = true;
-    aDst->value = aSrc.Value();
-    aDst->mandatory = mandatory;
-  }
-}
-#endif
-
-static cc_media_constraints_t*
-ConvertConstraints(const MediaConstraintsInternal& aSrc) {
-  cc_media_constraints_t* c = (cc_media_constraints_t*)
-      cpr_malloc(sizeof(cc_media_constraints_t));
-  NS_ENSURE_TRUE(c,c);
-  memset(c, 0, sizeof(cc_media_constraints_t));
-#ifdef MOZILLA_INTERNAL_API
-  Apply(aSrc.mMandatory.mOfferToReceiveAudio, &c->offer_to_receive_audio, true);
-  Apply(aSrc.mMandatory.mOfferToReceiveVideo, &c->offer_to_receive_video, true);
-  Apply(aSrc.mMandatory.mMozDontOfferDataChannel, &c->moz_dont_offer_datachannel,
-        true);
-  if (aSrc.mOptional.WasPassed()) {
-    const Sequence<MediaConstraintSet> &array = aSrc.mOptional.Value();
-    for (uint32_t i = 0; i < array.Length(); i++) {
-      Apply(array[i].mOfferToReceiveAudio, &c->offer_to_receive_audio);
-      Apply(array[i].mOfferToReceiveVideo, &c->offer_to_receive_video);
-      Apply(array[i].mMozDontOfferDataChannel, &c->moz_dont_offer_datachannel);
-    }
-  }
-#endif
-  return c;
-}
-
 // Getting exceptions back down from PCObserver is generally not harmful.
 namespace {
 class JSErrorResult : public ErrorResult
 {
 public:
   ~JSErrorResult()
   {
 #ifdef MOZILLA_INTERNAL_API
@@ -1049,51 +1012,53 @@ PeerConnectionImpl::NotifyDataChannel(al
                                pco),
                 NS_DISPATCH_NORMAL);
 #endif
 }
 
 NS_IMETHODIMP
 PeerConnectionImpl::CreateOffer(const MediaConstraintsInternal& aConstraints)
 {
-  return CreateOffer(MediaConstraintsExternal(ConvertConstraints(aConstraints)));
+  return CreateOffer(MediaConstraintsExternal (aConstraints));
 }
 
 // Used by unit tests and the IDL CreateOffer.
 NS_IMETHODIMP
 PeerConnectionImpl::CreateOffer(const MediaConstraintsExternal& aConstraints)
 {
   PC_AUTO_ENTER_API_CALL(true);
 
   Timecard *tc = mTimeCard;
   mTimeCard = nullptr;
   STAMP_TIMECARD(tc, "Create Offer");
 
-  NS_ENSURE_TRUE(aConstraints.mConstraints, NS_ERROR_UNEXPECTED);
-  mInternal->mCall->createOffer(aConstraints.mConstraints, tc);
+  cc_media_constraints_t* cc_constraints = aConstraints.build();
+  NS_ENSURE_TRUE(cc_constraints, NS_ERROR_UNEXPECTED);
+  mInternal->mCall->createOffer(cc_constraints, tc);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PeerConnectionImpl::CreateAnswer(const MediaConstraintsInternal& aConstraints)
 {
-  return CreateAnswer(MediaConstraintsExternal(ConvertConstraints(aConstraints)));
+  return CreateAnswer(MediaConstraintsExternal (aConstraints));
 }
 
 NS_IMETHODIMP
 PeerConnectionImpl::CreateAnswer(const MediaConstraintsExternal& aConstraints)
 {
   PC_AUTO_ENTER_API_CALL(true);
 
   Timecard *tc = mTimeCard;
   mTimeCard = nullptr;
   STAMP_TIMECARD(tc, "Create Answer");
 
-  NS_ENSURE_TRUE(aConstraints.mConstraints, NS_ERROR_UNEXPECTED);
-  mInternal->mCall->createAnswer(aConstraints.mConstraints, tc);
+  cc_media_constraints_t* cc_constraints = aConstraints.build();
+  NS_ENSURE_TRUE(cc_constraints, NS_ERROR_UNEXPECTED);
+  mInternal->mCall->createAnswer(cc_constraints, tc);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PeerConnectionImpl::SetLocalDescription(int32_t aAction, const char* aSDP)
 {
   PC_AUTO_ENTER_API_CALL(true);
 
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
@@ -69,16 +69,17 @@ class RTCStatsReportInternal;
 #ifdef USE_FAKE_PCOBSERVER
 typedef test::AFakePCObserver PeerConnectionObserver;
 typedef const char *PCObserverString;
 #else
 class PeerConnectionObserver;
 typedef NS_ConvertUTF8toUTF16 PCObserverString;
 #endif
 }
+class MediaConstraintsExternal;
 }
 
 #if defined(__cplusplus) && __cplusplus >= 201103L
 typedef struct Timecard Timecard;
 #else
 #include "timecard.h"
 #endif
 
@@ -93,28 +94,28 @@ void func (__VA_ARGS__, rv)
 NS_IMETHODIMP func(__VA_ARGS__, resulttype **result);                  \
 already_AddRefed<resulttype> func (__VA_ARGS__, rv)
 
 namespace sipcc {
 
 using mozilla::dom::PeerConnectionObserver;
 using mozilla::dom::RTCConfiguration;
 using mozilla::dom::MediaConstraintsInternal;
+using mozilla::MediaConstraintsExternal;
 using mozilla::DOMMediaStream;
 using mozilla::NrIceCtx;
 using mozilla::NrIceMediaStream;
 using mozilla::DtlsIdentity;
 using mozilla::ErrorResult;
 using mozilla::NrIceStunServer;
 using mozilla::NrIceTurnServer;
 
 class PeerConnectionWrapper;
 class PeerConnectionMedia;
 class RemoteSourceStreamInfo;
-class MediaConstraintsExternal;
 class OnCallEventArgs;
 
 class IceConfiguration
 {
 public:
   bool addStunServer(const std::string& addr, uint16_t port)
   {
     NrIceStunServer* server(NrIceStunServer::Create(addr, port));
--- a/media/webrtc/signaling/test/signaling_unittests.cpp
+++ b/media/webrtc/signaling/test/signaling_unittests.cpp
@@ -73,40 +73,32 @@ uint16_t kBogusSrflxPort(1001);
 
 namespace sipcc {
 
 // We can't use mozilla/dom/MediaConstraintsBinding.h here because it uses
 // nsString, so we pass constraints in using MediaConstraintsExternal instead
 
 class MediaConstraints : public MediaConstraintsExternal {
 public:
-  MediaConstraints()
-  : MediaConstraintsExternal((cc_media_constraints_t*)
-                             cpr_malloc(sizeof(*mConstraints))) {
-    MOZ_ASSERT(mConstraints);
-    memset(mConstraints, 0, sizeof(*mConstraints));
-  }
-
   void setBooleanConstraint(const char *namePtr, bool value, bool mandatory) {
     cc_boolean_constraint_t &member (getMember(namePtr));
     member.was_passed = true;
     member.value = value;
     member.mandatory = mandatory;
   }
 private:
   cc_boolean_constraint_t &getMember(const char *namePtr) {
-    MOZ_ASSERT(mConstraints);
     if (strcmp(namePtr, "OfferToReceiveAudio") == 0) {
-        return mConstraints->offer_to_receive_audio;
+        return mConstraints.offer_to_receive_audio;
     }
     if (strcmp(namePtr, "OfferToReceiveVideo") == 0) {
-        return mConstraints->offer_to_receive_video;
+        return mConstraints.offer_to_receive_video;
     }
     MOZ_ASSERT(false);
-    return mConstraints->moz_dont_offer_datachannel;
+    return mConstraints.moz_dont_offer_datachannel;
   }
 };
 }
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 namespace test {