pbos@webrtc.org | 289a35c | 2014-06-03 14:51:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2014 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 | |
pbos@webrtc.org | 9e65a3b | 2014-06-11 13:42:37 +0000 | [diff] [blame] | 28 | #include "talk/media/webrtc/webrtcmediaengine.h" |
henrike@webrtc.org | 0481f15 | 2014-08-19 14:56:59 +0000 | [diff] [blame] | 29 | #include "talk/media/webrtc/webrtcvideoengine.h" |
| 30 | #ifdef WEBRTC_CHROMIUM_BUILD |
| 31 | #include "talk/media/webrtc/webrtcvideoengine2.h" |
| 32 | #endif |
| 33 | #include "talk/media/webrtc/webrtcvoiceengine.h" |
| 34 | #ifdef WEBRTC_CHROMIUM_BUILD |
pbos@webrtc.org | 9e65a3b | 2014-06-11 13:42:37 +0000 | [diff] [blame] | 35 | #include "webrtc/system_wrappers/interface/field_trial.h" |
henrike@webrtc.org | 0481f15 | 2014-08-19 14:56:59 +0000 | [diff] [blame] | 36 | #endif |
| 37 | |
| 38 | namespace cricket { |
| 39 | |
| 40 | class WebRtcMediaEngine : |
| 41 | public CompositeMediaEngine<WebRtcVoiceEngine, WebRtcVideoEngine> { |
| 42 | public: |
| 43 | WebRtcMediaEngine() {} |
| 44 | WebRtcMediaEngine(webrtc::AudioDeviceModule* adm, |
| 45 | webrtc::AudioDeviceModule* adm_sc, |
| 46 | WebRtcVideoEncoderFactory* encoder_factory, |
| 47 | WebRtcVideoDecoderFactory* decoder_factory) { |
| 48 | voice_.SetAudioDeviceModule(adm, adm_sc); |
| 49 | video_.SetVoiceEngine(&voice_); |
| 50 | video_.EnableTimedRender(); |
| 51 | video_.SetExternalEncoderFactory(encoder_factory); |
| 52 | video_.SetExternalDecoderFactory(decoder_factory); |
| 53 | } |
| 54 | }; |
| 55 | |
| 56 | #ifdef WEBRTC_CHROMIUM_BUILD |
| 57 | class WebRtcMediaEngine2 : |
| 58 | public CompositeMediaEngine<WebRtcVoiceEngine, WebRtcVideoEngine2> { |
| 59 | public: |
| 60 | WebRtcMediaEngine2(webrtc::AudioDeviceModule* adm, |
| 61 | webrtc::AudioDeviceModule* adm_sc, |
| 62 | WebRtcVideoEncoderFactory* encoder_factory, |
| 63 | WebRtcVideoDecoderFactory* decoder_factory) { |
| 64 | voice_.SetAudioDeviceModule(adm, adm_sc); |
| 65 | video_.SetVoiceEngine(&voice_); |
| 66 | video_.EnableTimedRender(); |
| 67 | } |
| 68 | }; |
| 69 | #endif // WEBRTC_CHROMIUM_BUILD |
| 70 | |
| 71 | } // namespace cricket |
pbos@webrtc.org | 9e65a3b | 2014-06-11 13:42:37 +0000 | [diff] [blame] | 72 | |
| 73 | WRME_EXPORT |
| 74 | cricket::MediaEngineInterface* CreateWebRtcMediaEngine( |
| 75 | webrtc::AudioDeviceModule* adm, |
| 76 | webrtc::AudioDeviceModule* adm_sc, |
| 77 | cricket::WebRtcVideoEncoderFactory* encoder_factory, |
| 78 | cricket::WebRtcVideoDecoderFactory* decoder_factory) { |
| 79 | #ifdef WEBRTC_CHROMIUM_BUILD |
| 80 | if (webrtc::field_trial::FindFullName("WebRTC-NewVideoAPI") == "Enabled") { |
| 81 | return new cricket::WebRtcMediaEngine2( |
| 82 | adm, adm_sc, encoder_factory, decoder_factory); |
| 83 | } |
| 84 | #endif // WEBRTC_CHROMIUM_BUILD |
henrike@webrtc.org | 0481f15 | 2014-08-19 14:56:59 +0000 | [diff] [blame] | 85 | // This is just to get a diff to run pulse. |
pbos@webrtc.org | 9e65a3b | 2014-06-11 13:42:37 +0000 | [diff] [blame] | 86 | return new cricket::WebRtcMediaEngine( |
| 87 | adm, adm_sc, encoder_factory, decoder_factory); |
| 88 | } |
| 89 | |
| 90 | WRME_EXPORT |
| 91 | void DestroyWebRtcMediaEngine(cricket::MediaEngineInterface* media_engine) { |
henrike@webrtc.org | 0481f15 | 2014-08-19 14:56:59 +0000 | [diff] [blame] | 92 | delete media_engine; |
pbos@webrtc.org | 9e65a3b | 2014-06-11 13:42:37 +0000 | [diff] [blame] | 93 | } |
henrike@webrtc.org | 0481f15 | 2014-08-19 14:56:59 +0000 | [diff] [blame] | 94 | |
| 95 | namespace cricket { |
| 96 | |
| 97 | class DelegatingWebRtcMediaEngine : public cricket::MediaEngineInterface { |
| 98 | public: |
| 99 | DelegatingWebRtcMediaEngine( |
| 100 | webrtc::AudioDeviceModule* adm, |
| 101 | webrtc::AudioDeviceModule* adm_sc, |
| 102 | WebRtcVideoEncoderFactory* encoder_factory, |
| 103 | WebRtcVideoDecoderFactory* decoder_factory) |
| 104 | : delegate_(CreateWebRtcMediaEngine( |
| 105 | adm, adm_sc, encoder_factory, decoder_factory)) { |
| 106 | } |
| 107 | virtual ~DelegatingWebRtcMediaEngine() { |
| 108 | DestroyWebRtcMediaEngine(delegate_); |
| 109 | } |
| 110 | virtual bool Init(rtc::Thread* worker_thread) OVERRIDE { |
| 111 | return delegate_->Init(worker_thread); |
| 112 | } |
| 113 | virtual void Terminate() OVERRIDE { |
| 114 | delegate_->Terminate(); |
| 115 | } |
| 116 | virtual int GetCapabilities() OVERRIDE { |
| 117 | return delegate_->GetCapabilities(); |
| 118 | } |
| 119 | virtual VoiceMediaChannel* CreateChannel() OVERRIDE { |
| 120 | return delegate_->CreateChannel(); |
| 121 | } |
| 122 | virtual VideoMediaChannel* CreateVideoChannel( |
| 123 | VoiceMediaChannel* voice_media_channel) OVERRIDE { |
| 124 | return delegate_->CreateVideoChannel(voice_media_channel); |
| 125 | } |
| 126 | virtual SoundclipMedia* CreateSoundclip() OVERRIDE { |
| 127 | return delegate_->CreateSoundclip(); |
| 128 | } |
| 129 | virtual AudioOptions GetAudioOptions() const OVERRIDE { |
| 130 | return delegate_->GetAudioOptions(); |
| 131 | } |
| 132 | virtual bool SetAudioOptions(const AudioOptions& options) OVERRIDE { |
| 133 | return delegate_->SetAudioOptions(options); |
| 134 | } |
| 135 | virtual bool SetVideoOptions(const VideoOptions& options) OVERRIDE { |
| 136 | return delegate_->SetVideoOptions(options); |
| 137 | } |
| 138 | virtual bool SetAudioDelayOffset(int offset) OVERRIDE { |
| 139 | return delegate_->SetAudioDelayOffset(offset); |
| 140 | } |
| 141 | virtual bool SetDefaultVideoEncoderConfig( |
| 142 | const VideoEncoderConfig& config) OVERRIDE { |
| 143 | return delegate_->SetDefaultVideoEncoderConfig(config); |
| 144 | } |
| 145 | virtual VideoEncoderConfig GetDefaultVideoEncoderConfig() const OVERRIDE { |
| 146 | return delegate_->GetDefaultVideoEncoderConfig(); |
| 147 | } |
| 148 | virtual bool SetSoundDevices( |
| 149 | const Device* in_device, const Device* out_device) OVERRIDE { |
| 150 | return delegate_->SetSoundDevices(in_device, out_device); |
| 151 | } |
| 152 | virtual bool GetOutputVolume(int* level) OVERRIDE { |
| 153 | return delegate_->GetOutputVolume(level); |
| 154 | } |
| 155 | virtual bool SetOutputVolume(int level) OVERRIDE { |
| 156 | return delegate_->SetOutputVolume(level); |
| 157 | } |
| 158 | virtual int GetInputLevel() OVERRIDE { |
| 159 | return delegate_->GetInputLevel(); |
| 160 | } |
| 161 | virtual bool SetLocalMonitor(bool enable) OVERRIDE { |
| 162 | return delegate_->SetLocalMonitor(enable); |
| 163 | } |
| 164 | virtual bool SetLocalRenderer(VideoRenderer* renderer) OVERRIDE { |
| 165 | return delegate_->SetLocalRenderer(renderer); |
| 166 | } |
| 167 | virtual const std::vector<AudioCodec>& audio_codecs() OVERRIDE { |
| 168 | return delegate_->audio_codecs(); |
| 169 | } |
| 170 | virtual const std::vector<RtpHeaderExtension>& |
| 171 | audio_rtp_header_extensions() OVERRIDE { |
| 172 | return delegate_->audio_rtp_header_extensions(); |
| 173 | } |
| 174 | virtual const std::vector<VideoCodec>& video_codecs() OVERRIDE { |
| 175 | return delegate_->video_codecs(); |
| 176 | } |
| 177 | virtual const std::vector<RtpHeaderExtension>& |
| 178 | video_rtp_header_extensions() OVERRIDE { |
| 179 | return delegate_->video_rtp_header_extensions(); |
| 180 | } |
| 181 | virtual void SetVoiceLogging(int min_sev, const char* filter) OVERRIDE { |
| 182 | delegate_->SetVoiceLogging(min_sev, filter); |
| 183 | } |
| 184 | virtual void SetVideoLogging(int min_sev, const char* filter) OVERRIDE { |
| 185 | delegate_->SetVideoLogging(min_sev, filter); |
| 186 | } |
| 187 | virtual bool StartAecDump(rtc::PlatformFile file) OVERRIDE { |
| 188 | return delegate_->StartAecDump(file); |
| 189 | } |
| 190 | virtual bool RegisterVoiceProcessor( |
| 191 | uint32 ssrc, VoiceProcessor* video_processor, |
| 192 | MediaProcessorDirection direction) OVERRIDE { |
| 193 | return delegate_->RegisterVoiceProcessor(ssrc, video_processor, direction); |
| 194 | } |
| 195 | virtual bool UnregisterVoiceProcessor( |
| 196 | uint32 ssrc, VoiceProcessor* video_processor, |
| 197 | MediaProcessorDirection direction) OVERRIDE { |
| 198 | return delegate_->UnregisterVoiceProcessor(ssrc, video_processor, |
| 199 | direction); |
| 200 | } |
| 201 | virtual VideoFormat GetStartCaptureFormat() const OVERRIDE { |
| 202 | return delegate_->GetStartCaptureFormat(); |
| 203 | } |
| 204 | virtual sigslot::repeater2<VideoCapturer*, CaptureState>& |
| 205 | SignalVideoCaptureStateChange() { |
| 206 | return delegate_->SignalVideoCaptureStateChange(); |
| 207 | } |
| 208 | |
| 209 | private: |
| 210 | cricket::MediaEngineInterface* delegate_; |
| 211 | }; |
| 212 | |
| 213 | // Used by ChannelManager when no media engine is passed in to it |
| 214 | // explicitly (acts as a default). |
| 215 | MediaEngineInterface* WebRtcMediaEngineFactory::Create() { |
| 216 | return new cricket::WebRtcMediaEngine(); |
| 217 | } |
| 218 | |
| 219 | // Used by PeerConnectionFactory and to create a media engine passed |
| 220 | // into ChannelManager. |
| 221 | MediaEngineInterface* WebRtcMediaEngineFactory::Create( |
| 222 | webrtc::AudioDeviceModule* adm, |
| 223 | webrtc::AudioDeviceModule* adm_sc, |
| 224 | WebRtcVideoEncoderFactory* encoder_factory, |
| 225 | WebRtcVideoDecoderFactory* decoder_factory) { |
| 226 | #if !defined(LIBPEERCONNECTION_LIB) && \ |
| 227 | !defined(LIBPEERCONNECTION_IMPLEMENTATION) |
| 228 | return new cricket::DelegatingWebRtcMediaEngine(); |
| 229 | #else |
| 230 | return CreateWebRtcMediaEngine(adm, adm_sc, encoder_factory, decoder_factory); |
| 231 | #endif // !defined(LIBPEERCONNECTION_LIB) && |
| 232 | // !defined(LIBPEERCONNECTION_IMPLEMENTATION) |
| 233 | } |
| 234 | |
| 235 | } // namespace cricket |