From 5a15ab9e363f5c959dbf69a47c732d1a7c3d459f Mon Sep 17 00:00:00 2001 From: "wu@webrtc.org" Date: Thu, 1 Sep 2011 23:04:52 +0000 Subject: [PATCH] Move the WebRtcDeviceManager and WebRtcMediaEngine to libjingle. Review URL: http://webrtc-codereview.appspot.com/139009 git-svn-id: http://webrtc.googlecode.com/svn/trunk@515 4adac7df-926f-26a2-2b94-8c16560cd09d --- third_party_mods/libjingle/libjingle.gyp | 4 + .../talk/app/webrtc/webrtcdevicemanager.cc | 81 ++++++++++ .../talk/app/webrtc/webrtcdevicemanager.h | 53 +++++++ .../talk/app/webrtc/webrtcmediaengine.cc | 143 ++++++++++++++++++ .../talk/app/webrtc/webrtcmediaengine.h | 89 +++++++++++ 5 files changed, 370 insertions(+) create mode 100644 third_party_mods/libjingle/source/talk/app/webrtc/webrtcdevicemanager.cc create mode 100644 third_party_mods/libjingle/source/talk/app/webrtc/webrtcdevicemanager.h create mode 100644 third_party_mods/libjingle/source/talk/app/webrtc/webrtcmediaengine.cc create mode 100644 third_party_mods/libjingle/source/talk/app/webrtc/webrtcmediaengine.h diff --git a/third_party_mods/libjingle/libjingle.gyp b/third_party_mods/libjingle/libjingle.gyp index 921d47044..43e7b32ab 100644 --- a/third_party_mods/libjingle/libjingle.gyp +++ b/third_party_mods/libjingle/libjingle.gyp @@ -563,6 +563,10 @@ '<(libjingle_mods)/source/talk/app/webrtc/peerconnection_impl.h', '<(libjingle_mods)/source/talk/app/webrtc/peerconnection_proxy.cc', '<(libjingle_mods)/source/talk/app/webrtc/peerconnection_proxy.h', + '<(libjingle_mods)/source/talk/app/webrtc/webrtcdevicemanager.cc', + '<(libjingle_mods)/source/talk/app/webrtc/webrtcdevicemanager.h', + '<(libjingle_mods)/source/talk/app/webrtc/webrtcmediaengine.cc', + '<(libjingle_mods)/source/talk/app/webrtc/webrtcmediaengine.h', '<(libjingle_mods)/source/talk/app/webrtc/webrtcsession.cc', '<(libjingle_mods)/source/talk/app/webrtc/webrtcsession.h', '<(libjingle_mods)/source/talk/app/webrtc/webrtc_json.cc', diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/webrtcdevicemanager.cc b/third_party_mods/libjingle/source/talk/app/webrtc/webrtcdevicemanager.cc new file mode 100644 index 000000000..bb6a79c33 --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc/webrtcdevicemanager.cc @@ -0,0 +1,81 @@ +/* + * libjingle + * Copyright 2011, Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "talk/app/webrtc/webrtcdevicemanager.h" + +#include + +using cricket::Device; +using cricket::DeviceManager; + +const int WebRtcDeviceManager::kDefaultDeviceId = -1; + +WebRtcDeviceManager::WebRtcDeviceManager() + : DeviceManager(), + default_device_(DeviceManager::kDefaultDeviceName, kDefaultDeviceId) { +} + +WebRtcDeviceManager::~WebRtcDeviceManager() { + Terminate(); +} + +bool WebRtcDeviceManager::Init() { + return true; +} + +void WebRtcDeviceManager::Terminate() { +} + +bool WebRtcDeviceManager::GetAudioInputDevices( + std::vector* devs) { + return GetDefaultDevices(devs); +} + +bool WebRtcDeviceManager::GetAudioOutputDevices( + std::vector* devs) { + return GetDefaultDevices(devs); +} + +bool WebRtcDeviceManager::GetVideoCaptureDevices( + std::vector* devs) { + return GetDefaultDevices(devs); +} + +bool WebRtcDeviceManager::GetDefaultVideoCaptureDevice( + Device* device) { + *device = default_device_; + return true; +} + +bool WebRtcDeviceManager::GetDefaultDevices( + std::vector* devs) { + if (!devs) + return false; + devs->clear(); + devs->push_back(default_device_); + return true; +} diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/webrtcdevicemanager.h b/third_party_mods/libjingle/source/talk/app/webrtc/webrtcdevicemanager.h new file mode 100644 index 000000000..30c2b71fb --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc/webrtcdevicemanager.h @@ -0,0 +1,53 @@ +/* + * libjingle + * Copyright 2011, Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef TALK_APP_WEBRTC_WEBRTCDEVICEMANAGER_H_ +#define TALK_APP_WEBRTC_WEBRTCDEVICEMANAGER_H_ + +#include + +#include "talk/session/phone/devicemanager.h" + +class WebRtcDeviceManager : public cricket::DeviceManager { + public: + WebRtcDeviceManager(); + ~WebRtcDeviceManager(); + virtual bool Init(); + virtual void Terminate(); + virtual bool GetAudioInputDevices(std::vector* devs); + virtual bool GetAudioOutputDevices(std::vector* devs); + virtual bool GetVideoCaptureDevices(std::vector* devs); + virtual bool GetDefaultVideoCaptureDevice(cricket::Device* device); + + private: + static const int kDefaultDeviceId; + bool GetDefaultDevices(std::vector* devs); + + cricket::Device default_device_; +}; + +#endif // TALK_APP_WEBRTC_WEBRTCDEVICEMANAGER_H_ diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/webrtcmediaengine.cc b/third_party_mods/libjingle/source/talk/app/webrtc/webrtcmediaengine.cc new file mode 100644 index 000000000..c25c57cff --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc/webrtcmediaengine.cc @@ -0,0 +1,143 @@ +/* + * libjingle + * Copyright 2011, Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "talk/app/webrtc/webrtcmediaengine.h" + +#include + +#include "talk/session/phone/webrtcvoiceengine.h" +#include "talk/session/phone/webrtcvideoengine.h" + +WebRtcMediaEngine::WebRtcMediaEngine(webrtc::AudioDeviceModule* adm, + webrtc::AudioDeviceModule* adm_sc, webrtc::VideoCaptureModule* vcm) + : voice_(new cricket::WebRtcVoiceEngine(adm, adm_sc)), + video_(new cricket::WebRtcVideoEngine(voice_.get(), vcm)) { +} + +WebRtcMediaEngine::~WebRtcMediaEngine() { +} + +bool WebRtcMediaEngine::Init() { + if (!voice_->Init()) + return false; + if (!video_->Init()) { + voice_->Terminate(); + return false; + } + SignalVideoCaptureResult.repeat(video_->SignalCaptureResult); + return true; +} + +void WebRtcMediaEngine::Terminate() { + video_->Terminate(); + voice_->Terminate(); +} + +int WebRtcMediaEngine::GetCapabilities() { + return (voice_->GetCapabilities() | video_->GetCapabilities()); +} + +cricket::VoiceMediaChannel* WebRtcMediaEngine::CreateChannel() { + return voice_->CreateChannel(); +} + +cricket::VideoMediaChannel* WebRtcMediaEngine::CreateVideoChannel( + cricket::VoiceMediaChannel* channel) { + return video_->CreateChannel(channel); +} + +cricket::SoundclipMedia* WebRtcMediaEngine::CreateSoundclip() { + return voice_->CreateSoundclip(); +} + +bool WebRtcMediaEngine::SetAudioOptions(int o) { + return voice_->SetOptions(o); +} + +bool WebRtcMediaEngine::SetVideoOptions(int o) { + return video_->SetOptions(o); +} + +bool WebRtcMediaEngine::SetDefaultVideoEncoderConfig( + const cricket::VideoEncoderConfig& config) { + return video_->SetDefaultEncoderConfig(config); +} + +bool WebRtcMediaEngine::SetSoundDevices(const cricket::Device* in_device, + const cricket::Device* out_device) { + return voice_->SetDevices(in_device, out_device); +} + +bool WebRtcMediaEngine::SetVideoCaptureDevice( + const cricket::Device* cam_device) { + return video_->SetCaptureDevice(cam_device); +} + +bool WebRtcMediaEngine::GetOutputVolume(int* level) { + return voice_->GetOutputVolume(level); +} + +bool WebRtcMediaEngine::SetOutputVolume(int level) { + return voice_->SetOutputVolume(level); +} + +int WebRtcMediaEngine::GetInputLevel() { + return voice_->GetInputLevel(); +} + +bool WebRtcMediaEngine::SetLocalMonitor(bool enable) { + return voice_->SetLocalMonitor(enable); +} + +bool WebRtcMediaEngine::SetLocalRenderer(cricket::VideoRenderer* renderer) { + return video_->SetLocalRenderer(renderer); +} + +cricket::CaptureResult WebRtcMediaEngine::SetVideoCapture(bool capture) { + return video_->SetCapture(capture); +} + +const std::vector& WebRtcMediaEngine::audio_codecs() { + return voice_->codecs(); +} + +const std::vector& WebRtcMediaEngine::video_codecs() { + return video_->codecs(); +} + +void WebRtcMediaEngine::SetVoiceLogging(int min_sev, const char* filter) { + return voice_->SetLogging(min_sev, filter); +} + +void WebRtcMediaEngine::SetVideoLogging(int min_sev, const char* filter) { + return video_->SetLogging(min_sev, filter); +} + +bool WebRtcMediaEngine::SetVideoCaptureModule( + webrtc::VideoCaptureModule* vcm) { + return video_->SetCaptureModule(vcm); +} diff --git a/third_party_mods/libjingle/source/talk/app/webrtc/webrtcmediaengine.h b/third_party_mods/libjingle/source/talk/app/webrtc/webrtcmediaengine.h new file mode 100644 index 000000000..457623327 --- /dev/null +++ b/third_party_mods/libjingle/source/talk/app/webrtc/webrtcmediaengine.h @@ -0,0 +1,89 @@ +/* + * libjingle + * Copyright 2011, Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef TALK_APP_WEBRTC_WEBRTCMEDIAENGINE_H_ +#define TALK_APP_WEBRTC_WEBRTCMEDIAENGINE_H_ + +#include + +#include "talk/base/scoped_ptr.h" +#include "talk/session/phone/mediaengine.h" + +namespace cricket { + +class WebRtcVideoEngine; +class WebRtcVoiceEngine; +} + +namespace webrtc { +class AudioDeviceModule; +class VideoCaptureModule; +} + +// TODO(ronghuawu): chromium doesn't need to know the +// detail about the cricket::MediaEngine interface. +class WebRtcMediaEngine : public cricket::MediaEngine { + public: + WebRtcMediaEngine(webrtc::AudioDeviceModule* adm, + webrtc::AudioDeviceModule* adm_sc, webrtc::VideoCaptureModule* vcm); + virtual ~WebRtcMediaEngine(); + virtual bool Init(); + virtual void Terminate(); + virtual int GetCapabilities(); + virtual cricket::VoiceMediaChannel *CreateChannel(); + virtual cricket::VideoMediaChannel *CreateVideoChannel( + cricket::VoiceMediaChannel* channel); + virtual cricket::SoundclipMedia *CreateSoundclip(); + virtual bool SetAudioOptions(int o); + virtual bool SetVideoOptions(int o); + virtual bool SetDefaultVideoEncoderConfig( + const cricket::VideoEncoderConfig& config); + virtual bool SetSoundDevices(const cricket::Device* in_device, + const cricket::Device* out_device); + virtual bool SetVideoCaptureDevice(const cricket::Device* cam_device); + virtual bool GetOutputVolume(int* level); + virtual bool SetOutputVolume(int level); + virtual int GetInputLevel(); + virtual bool SetLocalMonitor(bool enable); + virtual bool SetLocalRenderer(cricket::VideoRenderer* renderer); + virtual cricket::CaptureResult SetVideoCapture(bool capture); + virtual const std::vector& audio_codecs(); + virtual const std::vector& video_codecs(); + virtual void SetVoiceLogging(int min_sev, const char* filter); + virtual void SetVideoLogging(int min_sev, const char* filter); + + // Allow the VCM be set later if not ready during the construction time + bool SetVideoCaptureModule(webrtc::VideoCaptureModule* vcm); + + protected: + WebRtcMediaEngine(); + + talk_base::scoped_ptr voice_; + talk_base::scoped_ptr video_; +}; + +#endif // TALK_APP_WEBRTC_WEBRTCMEDIAENGINE_H_