From decae3d85870d5f25e261663ad4b7fcc676a6247 Mon Sep 17 00:00:00 2001 From: Randell Jesup Date: Thu, 15 Nov 2012 17:58:40 -0500 Subject: [PATCH] Bug 811695: disable internal socket transports for getUserMedia Audio capture r=derf --- content/media/webrtc/Makefile.in | 1 + content/media/webrtc/MediaEngineWebRTC.h | 7 ++- .../media/webrtc/MediaEngineWebRTCAudio.cpp | 30 ++++++++++--- dom/media/Makefile.in | 1 + media/webrtc/signaling/signaling.gyp | 1 + .../signaling/src/common/NullTransport.h | 44 +++++++++++++++++++ .../src/voice_engine/voice_engine_core.gypi | 3 ++ 7 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 media/webrtc/signaling/src/common/NullTransport.h diff --git a/content/media/webrtc/Makefile.in b/content/media/webrtc/Makefile.in index 3deb47bb261b..937b6f317068 100644 --- a/content/media/webrtc/Makefile.in +++ b/content/media/webrtc/Makefile.in @@ -41,5 +41,6 @@ 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 diff --git a/content/media/webrtc/MediaEngineWebRTC.h b/content/media/webrtc/MediaEngineWebRTC.h index 4f9e75b18dc0..999373f8d43c 100644 --- a/content/media/webrtc/MediaEngineWebRTC.h +++ b/content/media/webrtc/MediaEngineWebRTC.h @@ -32,6 +32,7 @@ #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" @@ -43,6 +44,7 @@ #include "video_engine/include/vie_capture.h" #include "video_engine/include/vie_file.h" +#include "NullTransport.h" namespace mozilla { @@ -166,7 +168,8 @@ public: , 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)); @@ -201,6 +204,7 @@ private: webrtc::VoiceEngine* mVoiceEngine; webrtc::VoEBase* mVoEBase; webrtc::VoEExternalMedia* mVoERender; + webrtc::VoENetwork* mVoENetwork; mozilla::ReentrantMonitor mMonitor; @@ -213,6 +217,7 @@ private: nsString mDeviceUUID; SourceMediaStream* mSource; + NullTransport *mNullTransport; }; class MediaEngineWebRTC : public MediaEngine diff --git a/content/media/webrtc/MediaEngineWebRTCAudio.cpp b/content/media/webrtc/MediaEngineWebRTCAudio.cpp index 95b50e0adaed..c19f4db22fba 100644 --- a/content/media/webrtc/MediaEngineWebRTCAudio.cpp +++ b/content/media/webrtc/MediaEngineWebRTCAudio.cpp @@ -53,11 +53,6 @@ MediaEngineWebRTCAudioSource::Allocate() 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; } @@ -165,11 +160,19 @@ MediaEngineWebRTCAudioSource::Init() 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); @@ -209,6 +212,15 @@ 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; } @@ -221,6 +233,14 @@ MediaEngineWebRTCAudioSource::Shutdown() } mVoEBase->Terminate(); + if (mChannel != -1) { + mVoENetwork->DeRegisterExternalTransport(mChannel); + } + + if (mNullTransport) { + delete mNullTransport; + } + mVoERender->Release(); mVoEBase->Release(); diff --git a/dom/media/Makefile.in b/dom/media/Makefile.in index b0944228d9f4..9accd09faf04 100644 --- a/dom/media/Makefile.in +++ b/dom/media/Makefile.in @@ -43,6 +43,7 @@ CPPSRCS = \ ifdef MOZ_WEBRTC LOCAL_INCLUDES += \ -I$(topsrcdir)/media/webrtc/trunk/src \ + -I$(topsrcdir)/media/webrtc/signaling/src/common \ $(NULL) DIRS += bridge endif diff --git a/media/webrtc/signaling/signaling.gyp b/media/webrtc/signaling/signaling.gyp index f0cbf8705f8c..125f4ddef50f 100644 --- a/media/webrtc/signaling/signaling.gyp +++ b/media/webrtc/signaling/signaling.gyp @@ -79,6 +79,7 @@ './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', diff --git a/media/webrtc/signaling/src/common/NullTransport.h b/media/webrtc/signaling/src/common/NullTransport.h new file mode 100644 index 000000000000..455b5593da9a --- /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 diff --git a/media/webrtc/trunk/src/voice_engine/voice_engine_core.gypi b/media/webrtc/trunk/src/voice_engine/voice_engine_core.gypi index 354993a3d3ac..802e2f280ae4 100644 --- a/media/webrtc/trunk/src/voice_engine/voice_engine_core.gypi +++ b/media/webrtc/trunk/src/voice_engine/voice_engine_core.gypi @@ -38,6 +38,9 @@ 'include', ], }, + 'defines': [ + 'WEBRTC_EXTERNAL_TRANSPORT', + ], 'sources': [ '../common_types.h', '../engine_configurations.h',