1 /* 2 * libjingle 3 * Copyright 2011 Google Inc. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 3. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #ifndef TALK_MEDIA_WEBRTCMEDIAENGINE_H_ 29 #define TALK_MEDIA_WEBRTCMEDIAENGINE_H_ 30 31 #include "talk/media/base/mediaengine.h" 32 #include "talk/media/webrtc/webrtcexport.h" 33 34 namespace webrtc { 35 class AudioDeviceModule; 36 class VideoCaptureModule; 37 } 38 namespace cricket { 39 class WebRtcVideoDecoderFactory; 40 class WebRtcVideoEncoderFactory; 41 } 42 43 44 #if !defined(LIBPEERCONNECTION_LIB) && \ 45 !defined(LIBPEERCONNECTION_IMPLEMENTATION) 46 47 WRME_EXPORT 48 cricket::MediaEngineInterface* CreateWebRtcMediaEngine( 49 webrtc::AudioDeviceModule* adm, webrtc::AudioDeviceModule* adm_sc, 50 cricket::WebRtcVideoEncoderFactory* encoder_factory, 51 cricket::WebRtcVideoDecoderFactory* decoder_factory); 52 53 WRME_EXPORT 54 void DestroyWebRtcMediaEngine(cricket::MediaEngineInterface* media_engine); 55 56 namespace cricket { 57 58 class WebRtcMediaEngine : public cricket::MediaEngineInterface { 59 public: 60 WebRtcMediaEngine( 61 webrtc::AudioDeviceModule* adm, 62 webrtc::AudioDeviceModule* adm_sc, 63 cricket::WebRtcVideoEncoderFactory* encoder_factory, 64 cricket::WebRtcVideoDecoderFactory* decoder_factory) 65 : delegate_(CreateWebRtcMediaEngine( 66 adm, adm_sc, encoder_factory, decoder_factory)) { 67 } 68 virtual ~WebRtcMediaEngine() { 69 DestroyWebRtcMediaEngine(delegate_); 70 } 71 virtual bool Init(talk_base::Thread* worker_thread) OVERRIDE { 72 return delegate_->Init(worker_thread); 73 } 74 virtual void Terminate() OVERRIDE { 75 delegate_->Terminate(); 76 } 77 virtual int GetCapabilities() OVERRIDE { 78 return delegate_->GetCapabilities(); 79 } 80 virtual VoiceMediaChannel* CreateChannel() OVERRIDE { 81 return delegate_->CreateChannel(); 82 } 83 virtual VideoMediaChannel* CreateVideoChannel( 84 VoiceMediaChannel* voice_media_channel) OVERRIDE { 85 return delegate_->CreateVideoChannel(voice_media_channel); 86 } 87 virtual SoundclipMedia* CreateSoundclip() OVERRIDE { 88 return delegate_->CreateSoundclip(); 89 } 90 virtual AudioOptions GetAudioOptions() const OVERRIDE { 91 return delegate_->GetAudioOptions(); 92 } 93 virtual bool SetAudioOptions(const AudioOptions& options) OVERRIDE { 94 return delegate_->SetAudioOptions(options); 95 } 96 virtual bool SetVideoOptions(const VideoOptions& options) OVERRIDE { 97 return delegate_->SetVideoOptions(options); 98 } 99 virtual bool SetAudioDelayOffset(int offset) OVERRIDE { 100 return delegate_->SetAudioDelayOffset(offset); 101 } 102 virtual bool SetDefaultVideoEncoderConfig( 103 const VideoEncoderConfig& config) OVERRIDE { 104 return delegate_->SetDefaultVideoEncoderConfig(config); 105 } 106 virtual VideoEncoderConfig GetDefaultVideoEncoderConfig() const OVERRIDE { 107 return delegate_->GetDefaultVideoEncoderConfig(); 108 } 109 virtual bool SetSoundDevices( 110 const Device* in_device, const Device* out_device) OVERRIDE { 111 return delegate_->SetSoundDevices(in_device, out_device); 112 } 113 virtual bool GetOutputVolume(int* level) OVERRIDE { 114 return delegate_->GetOutputVolume(level); 115 } 116 virtual bool SetOutputVolume(int level) OVERRIDE { 117 return delegate_->SetOutputVolume(level); 118 } 119 virtual int GetInputLevel() OVERRIDE { 120 return delegate_->GetInputLevel(); 121 } 122 virtual bool SetLocalMonitor(bool enable) OVERRIDE { 123 return delegate_->SetLocalMonitor(enable); 124 } 125 virtual bool SetLocalRenderer(VideoRenderer* renderer) OVERRIDE { 126 return delegate_->SetLocalRenderer(renderer); 127 } 128 virtual const std::vector<AudioCodec>& audio_codecs() OVERRIDE { 129 return delegate_->audio_codecs(); 130 } 131 virtual const std::vector<RtpHeaderExtension>& 132 audio_rtp_header_extensions() OVERRIDE { 133 return delegate_->audio_rtp_header_extensions(); 134 } 135 virtual const std::vector<VideoCodec>& video_codecs() OVERRIDE { 136 return delegate_->video_codecs(); 137 } 138 virtual const std::vector<RtpHeaderExtension>& 139 video_rtp_header_extensions() OVERRIDE { 140 return delegate_->video_rtp_header_extensions(); 141 } 142 virtual void SetVoiceLogging(int min_sev, const char* filter) OVERRIDE { 143 delegate_->SetVoiceLogging(min_sev, filter); 144 } 145 virtual void SetVideoLogging(int min_sev, const char* filter) OVERRIDE { 146 delegate_->SetVideoLogging(min_sev, filter); 147 } 148 virtual bool RegisterVoiceProcessor( 149 uint32 ssrc, VoiceProcessor* video_processor, 150 MediaProcessorDirection direction) OVERRIDE { 151 return delegate_->RegisterVoiceProcessor(ssrc, video_processor, direction); 152 } 153 virtual bool UnregisterVoiceProcessor( 154 uint32 ssrc, VoiceProcessor* video_processor, 155 MediaProcessorDirection direction) OVERRIDE { 156 return delegate_->UnregisterVoiceProcessor(ssrc, video_processor, 157 direction); 158 } 159 virtual VideoFormat GetStartCaptureFormat() const OVERRIDE { 160 return delegate_->GetStartCaptureFormat(); 161 } 162 virtual sigslot::repeater2<VideoCapturer*, CaptureState>& 163 SignalVideoCaptureStateChange() { 164 return delegate_->SignalVideoCaptureStateChange(); 165 } 166 167 private: 168 cricket::MediaEngineInterface* delegate_; 169 }; 170 171 } // namespace cricket 172 #else 173 174 #include "talk/media/webrtc/webrtcvideoengine.h" 175 #include "talk/media/webrtc/webrtcvoiceengine.h" 176 177 namespace cricket { 178 typedef CompositeMediaEngine<WebRtcVoiceEngine, WebRtcVideoEngine> 179 WebRtcCompositeMediaEngine; 180 181 class WebRtcMediaEngine : public WebRtcCompositeMediaEngine { 182 public: 183 WebRtcMediaEngine(webrtc::AudioDeviceModule* adm, 184 webrtc::AudioDeviceModule* adm_sc, 185 WebRtcVideoEncoderFactory* encoder_factory, 186 WebRtcVideoDecoderFactory* decoder_factory) { 187 voice_.SetAudioDeviceModule(adm, adm_sc); 188 video_.SetVoiceEngine(&voice_); 189 video_.EnableTimedRender(); 190 video_.SetExternalEncoderFactory(encoder_factory); 191 video_.SetExternalDecoderFactory(decoder_factory); 192 } 193 }; 194 195 } // namespace cricket 196 197 #endif // !defined(LIBPEERCONNECTION_LIB) && 198 // !defined(LIBPEERCONNECTION_IMPLEMENTATION) 199 200 #endif // TALK_MEDIA_WEBRTCMEDIAENGINE_H_ 201