Bug 811695: disable internal socket transports for getUserMedia Audio capture r=derf
authorRandell Jesup <rjesup@jesup.org>
Thu, 15 Nov 2012 17:58:40 -0500
changeset 113427 045367d6644efb8e12759d96bdc6ae0608a513e4
parent 113426 dc61a415f3e907b85a562c47ce1bd985d6b44f23
child 113428 b1b0fbcbdf3b01f8015b6c3d70706e450c37c1fb
push id23872
push useremorley@mozilla.com
push dateFri, 16 Nov 2012 17:06:27 +0000
treeherderautoland@a7ed19f7d21a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersderf
bugs811695
milestone19.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 811695: disable internal socket transports for getUserMedia Audio capture r=derf
content/media/webrtc/Makefile.in
content/media/webrtc/MediaEngineWebRTC.h
content/media/webrtc/MediaEngineWebRTCAudio.cpp
dom/media/Makefile.in
media/webrtc/signaling/signaling.gyp
media/webrtc/signaling/src/common/NullTransport.h
media/webrtc/trunk/src/voice_engine/voice_engine_core.gypi
--- a/content/media/webrtc/Makefile.in
+++ b/content/media/webrtc/Makefile.in
@@ -36,10 +36,11 @@ endif
 
 FORCE_STATIC_LIB = 1
 
 include $(topsrcdir)/config/rules.mk
 
 ifdef MOZ_WEBRTC
 LOCAL_INCLUDES += \
   -I$(topsrcdir)/media/webrtc/trunk/src \
+  -I$(topsrcdir)/media/webrtc/signaling/src/common \
   $(NULL)
 endif
--- a/content/media/webrtc/MediaEngineWebRTC.h
+++ b/content/media/webrtc/MediaEngineWebRTC.h
@@ -27,27 +27,29 @@
 #include "MediaStreamGraph.h"
 
 // WebRTC library includes follow
 
 // Audio Engine
 #include "voice_engine/include/voe_base.h"
 #include "voice_engine/include/voe_codec.h"
 #include "voice_engine/include/voe_hardware.h"
+#include "voice_engine/include/voe_network.h"
 #include "voice_engine/include/voe_audio_processing.h"
 #include "voice_engine/include/voe_volume_control.h"
 #include "voice_engine/include/voe_external_media.h"
 
 // Video Engine
 #include "video_engine/include/vie_base.h"
 #include "video_engine/include/vie_codec.h"
 #include "video_engine/include/vie_render.h"
 #include "video_engine/include/vie_capture.h"
 #include "video_engine/include/vie_file.h"
 
+#include "NullTransport.h"
 
 namespace mozilla {
 
 /**
  * The WebRTC implementation of the MediaEngine interface.
  */
 class MediaEngineWebRTCVideoSource : public MediaEngineVideoSource,
                                      public webrtc::ExternalRenderer,
@@ -161,17 +163,18 @@ class MediaEngineWebRTCAudioSource : pub
 {
 public:
   MediaEngineWebRTCAudioSource(webrtc::VoiceEngine* voiceEngine, int aIndex,
     const char* name, const char* uuid)
     : mVoiceEngine(voiceEngine)
     , mMonitor("WebRTCMic.Monitor")
     , mCapIndex(aIndex)
     , mChannel(-1)
-    , mInitDone(false) {
+    , mInitDone(false)
+    , mNullTransport(nullptr) {
     mState = kReleased;
     mDeviceName.Assign(NS_ConvertUTF8toUTF16(name));
     mDeviceUUID.Assign(NS_ConvertUTF8toUTF16(uuid));
     Init();
   }
   ~MediaEngineWebRTCAudioSource() { Shutdown(); }
 
   virtual void GetName(nsAString&);
@@ -196,28 +199,30 @@ private:
   static const unsigned int KMaxUniqueIdLength = 256;
 
   void Init();
   void Shutdown();
 
   webrtc::VoiceEngine* mVoiceEngine;
   webrtc::VoEBase* mVoEBase;
   webrtc::VoEExternalMedia* mVoERender;
+  webrtc::VoENetwork*  mVoENetwork;
 
   mozilla::ReentrantMonitor mMonitor;
 
   int mCapIndex;
   int mChannel;
   TrackID mTrackID;
   bool mInitDone;
 
   nsString mDeviceName;
   nsString mDeviceUUID;
 
   SourceMediaStream* mSource;
+  NullTransport *mNullTransport;
 };
 
 class MediaEngineWebRTC : public MediaEngine
 {
 public:
   MediaEngineWebRTC()
   : mMutex("mozilla::MediaEngineWebRTC")
   , mVideoEngine(NULL)
--- a/content/media/webrtc/MediaEngineWebRTCAudio.cpp
+++ b/content/media/webrtc/MediaEngineWebRTCAudio.cpp
@@ -48,21 +48,16 @@ MediaEngineWebRTCAudioSource::GetUUID(ns
 
 nsresult
 MediaEngineWebRTCAudioSource::Allocate()
 {
   if (mState != kReleased) {
     return NS_ERROR_FAILURE;
   }
 
-  // Audio doesn't play through unless we set a receiver and destination, so
-  // we setup a dummy local destination, and do a loopback.
-  mVoEBase->SetLocalReceiver(mChannel, DEFAULT_PORT);
-  mVoEBase->SetSendDestination(mChannel, DEFAULT_PORT, "127.0.0.1");
-
   mState = kAllocated;
   return NS_OK;
 }
 
 nsresult
 MediaEngineWebRTCAudioSource::Deallocate()
 {
   if (mState != kStopped && mState != kAllocated) {
@@ -160,21 +155,29 @@ MediaEngineWebRTCAudioSource::Init()
   mVoEBase = webrtc::VoEBase::GetInterface(mVoiceEngine);
 
   mVoEBase->Init();
 
   mVoERender = webrtc::VoEExternalMedia::GetInterface(mVoiceEngine);
   if (!mVoERender) {
     return;
   }
+  mVoENetwork = webrtc::VoENetwork::GetInterface(mVoiceEngine);
+  if (!mVoENetwork) {
+    return;
+  }
 
   mChannel = mVoEBase->CreateChannel();
   if (mChannel < 0) {
     return;
   }
+  mNullTransport = new NullTransport();
+  if (mVoENetwork->RegisterExternalTransport(mChannel, *mNullTransport)) {
+    return;
+  }
 
   // Check for availability.
   webrtc::VoEHardware* ptrVoEHw = webrtc::VoEHardware::GetInterface(mVoiceEngine);
   if (ptrVoEHw->SetRecordingDevice(mCapIndex)) {
     return;
   }
 
   bool avail = false;
@@ -204,28 +207,45 @@ MediaEngineWebRTCAudioSource::Init()
 
   mInitDone = true;
 }
 
 void
 MediaEngineWebRTCAudioSource::Shutdown()
 {
   if (!mInitDone) {
+    // duplicate these here in case we failed during Init()
+    if (mChannel != -1) {
+      mVoENetwork->DeRegisterExternalTransport(mChannel);
+    }
+
+    if (mNullTransport) {
+      delete mNullTransport;
+    }
+
     return;
   }
 
   if (mState == kStarted) {
     Stop();
   }
 
   if (mState == kAllocated) {
     Deallocate();
   }
 
   mVoEBase->Terminate();
+  if (mChannel != -1) {
+    mVoENetwork->DeRegisterExternalTransport(mChannel);
+  }
+
+  if (mNullTransport) {
+    delete mNullTransport;
+  }
+
   mVoERender->Release();
   mVoEBase->Release();
 
   mState = kReleased;
   mInitDone = false;
 }
 
 typedef WebRtc_Word16 sample;
--- a/dom/media/Makefile.in
+++ b/dom/media/Makefile.in
@@ -38,16 +38,17 @@ EXPORTS_mozilla = \
 
 CPPSRCS = \
   MediaManager.cpp \
   $(NULL)
 
 ifdef MOZ_WEBRTC
 LOCAL_INCLUDES += \
   -I$(topsrcdir)/media/webrtc/trunk/src \
+  -I$(topsrcdir)/media/webrtc/signaling/src/common \
   $(NULL)
 DIRS += bridge
 endif
 
 TEST_DIRS += \
   tests/mochitest \
   $(NULL)
 
--- a/media/webrtc/signaling/signaling.gyp
+++ b/media/webrtc/signaling/signaling.gyp
@@ -74,16 +74,17 @@
         './src/media-conduit/AudioConduit.cpp',
         './src/media-conduit/VideoConduit.h',
         './src/media-conduit/VideoConduit.cpp',
         # Common
         './src/common/CommonTypes.h',
         './src/common/csf_common.h',
         './src/common/NullDeleter.h',
         './src/common/Wrapper.h',
+        './src/common/NullTransport.h',
         # Browser Logging
         './src/common/browser_logging/CSFLog.cpp',
         './src/common/browser_logging/CSFLog.h',
         # Call Control
         './src/callcontrol/CC_CallTypes.cpp',
         './src/callcontrol/CallControlManager.cpp',
         './src/callcontrol/CallControlManagerImpl.cpp',
         './src/callcontrol/ECC_Types.cpp',
new file mode 100644
--- /dev/null
+++ b/media/webrtc/signaling/src/common/NullTransport.h
@@ -0,0 +1,44 @@
+/* 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 NULL_TRANSPORT_H_
+#define NULL_TRANSPORT_H_
+
+#include "mozilla/Attributes.h"
+
+#include "common_types.h"
+
+namespace mozilla {
+
+/**
+ * NullTransport is registered as ExternalTransport to throw away data
+ */
+class NullTransport : public webrtc::Transport
+{
+public:
+  virtual int SendPacket(int channel, const void *data, int len)
+  {
+    (void) channel; (void) data;
+    return len;
+  }
+
+  virtual int SendRTCPPacket(int channel, const void *data, int len)
+  {
+    (void) channel; (void) data;
+    return len;
+  }
+
+  NullTransport() {}
+
+  virtual ~NullTransport() {};
+
+private:
+  NullTransport(const NullTransport& other) MOZ_DELETE;
+  void operator=(const NullTransport& other) MOZ_DELETE;
+};
+
+} // end namespace
+
+#endif
--- a/media/webrtc/trunk/src/voice_engine/voice_engine_core.gypi
+++ b/media/webrtc/trunk/src/voice_engine/voice_engine_core.gypi
@@ -33,16 +33,19 @@
         'include',
         '<(webrtc_root)/modules/audio_device/main/source',
       ],
       'direct_dependent_settings': {
         'include_dirs': [
           'include',
         ],
       },
+      'defines': [
+        'WEBRTC_EXTERNAL_TRANSPORT',
+      ],
       'sources': [
         '../common_types.h',
         '../engine_configurations.h',
         '../typedefs.h',
         'include/voe_audio_processing.h',
         'include/voe_base.h',
         'include/voe_call_report.h',
         'include/voe_codec.h',