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 #if !defined(LIBPEERCONNECTION_LIB) && \
44 !defined(LIBPEERCONNECTION_IMPLEMENTATION)
45
46 WRME_EXPORT
47 cricket::MediaEngineInterface* CreateWebRtcMediaEngine(
48 webrtc::AudioDeviceModule* adm, webrtc::AudioDeviceModule* adm_sc,
49 cricket::WebRtcVideoEncoderFactory* encoder_factory,
50 cricket::WebRtcVideoDecoderFactory* decoder_factory);
51
52 WRME_EXPORT
53 void DestroyWebRtcMediaEngine(cricket::MediaEngineInterface* media_engine);
54
55 #endif // !defined(LIBPEERCONNECTION_LIB) &&
56 // !defined(LIBPEERCONNECTION_IMPLEMENTATION)
57
58 namespace cricket {
59
60 class WebRtcMediaEngineFactory {
61 public:
62 #if !defined(LIBPEERCONNECTION_LIB) && \
63 !defined(LIBPEERCONNECTION_IMPLEMENTATION)
64 // A bare Create() isn't supported when using the delegating media
65 // engine.
66 #else
67 static MediaEngineInterface* Create();
68 #endif // !defined(LIBPEERCONNECTION_LIB) &&
69 // !defined(LIBPEERCONNECTION_IMPLEMENTATION)
70 static MediaEngineInterface* Create(
71 webrtc::AudioDeviceModule* adm,
72 webrtc::AudioDeviceModule* adm_sc,
73 WebRtcVideoEncoderFactory* encoder_factory,
74 WebRtcVideoDecoderFactory* decoder_factory);
75 };
76
77 } // namespace cricket
78
79
80 #if !defined(LIBPEERCONNECTION_LIB) && \
81 !defined(LIBPEERCONNECTION_IMPLEMENTATION)
82
83 namespace cricket {
84
85 // TODO(pthacther): Move this code into webrtcmediaengine.cc once
86 // Chrome compiles it. Right now it relies on only the .h file.
87 class DelegatingWebRtcMediaEngine : public cricket::MediaEngineInterface {
88 public:
DelegatingWebRtcMediaEngine(webrtc::AudioDeviceModule * adm,webrtc::AudioDeviceModule * adm_sc,WebRtcVideoEncoderFactory * encoder_factory,WebRtcVideoDecoderFactory * decoder_factory)89 DelegatingWebRtcMediaEngine(
90 webrtc::AudioDeviceModule* adm,
91 webrtc::AudioDeviceModule* adm_sc,
92 WebRtcVideoEncoderFactory* encoder_factory,
93 WebRtcVideoDecoderFactory* decoder_factory)
94 : delegate_(CreateWebRtcMediaEngine(
95 adm, adm_sc, encoder_factory, decoder_factory)) {
96 }
~DelegatingWebRtcMediaEngine()97 virtual ~DelegatingWebRtcMediaEngine() {
98 DestroyWebRtcMediaEngine(delegate_);
99 }
Init(rtc::Thread * worker_thread)100 virtual bool Init(rtc::Thread* worker_thread) OVERRIDE {
101 return delegate_->Init(worker_thread);
102 }
Terminate()103 virtual void Terminate() OVERRIDE {
104 delegate_->Terminate();
105 }
GetCapabilities()106 virtual int GetCapabilities() OVERRIDE {
107 return delegate_->GetCapabilities();
108 }
CreateChannel()109 virtual VoiceMediaChannel* CreateChannel() OVERRIDE {
110 return delegate_->CreateChannel();
111 }
CreateVideoChannel(VoiceMediaChannel * voice_media_channel)112 virtual VideoMediaChannel* CreateVideoChannel(
113 VoiceMediaChannel* voice_media_channel) OVERRIDE {
114 return delegate_->CreateVideoChannel(voice_media_channel);
115 }
CreateSoundclip()116 virtual SoundclipMedia* CreateSoundclip() OVERRIDE {
117 return delegate_->CreateSoundclip();
118 }
GetAudioOptions()119 virtual AudioOptions GetAudioOptions() const OVERRIDE {
120 return delegate_->GetAudioOptions();
121 }
SetAudioOptions(const AudioOptions & options)122 virtual bool SetAudioOptions(const AudioOptions& options) OVERRIDE {
123 return delegate_->SetAudioOptions(options);
124 }
SetAudioDelayOffset(int offset)125 virtual bool SetAudioDelayOffset(int offset) OVERRIDE {
126 return delegate_->SetAudioDelayOffset(offset);
127 }
SetDefaultVideoEncoderConfig(const VideoEncoderConfig & config)128 virtual bool SetDefaultVideoEncoderConfig(
129 const VideoEncoderConfig& config) OVERRIDE {
130 return delegate_->SetDefaultVideoEncoderConfig(config);
131 }
GetDefaultVideoEncoderConfig()132 virtual VideoEncoderConfig GetDefaultVideoEncoderConfig() const OVERRIDE {
133 return delegate_->GetDefaultVideoEncoderConfig();
134 }
SetSoundDevices(const Device * in_device,const Device * out_device)135 virtual bool SetSoundDevices(
136 const Device* in_device, const Device* out_device) OVERRIDE {
137 return delegate_->SetSoundDevices(in_device, out_device);
138 }
GetOutputVolume(int * level)139 virtual bool GetOutputVolume(int* level) OVERRIDE {
140 return delegate_->GetOutputVolume(level);
141 }
SetOutputVolume(int level)142 virtual bool SetOutputVolume(int level) OVERRIDE {
143 return delegate_->SetOutputVolume(level);
144 }
GetInputLevel()145 virtual int GetInputLevel() OVERRIDE {
146 return delegate_->GetInputLevel();
147 }
SetLocalMonitor(bool enable)148 virtual bool SetLocalMonitor(bool enable) OVERRIDE {
149 return delegate_->SetLocalMonitor(enable);
150 }
audio_codecs()151 virtual const std::vector<AudioCodec>& audio_codecs() OVERRIDE {
152 return delegate_->audio_codecs();
153 }
154 virtual const std::vector<RtpHeaderExtension>&
audio_rtp_header_extensions()155 audio_rtp_header_extensions() OVERRIDE {
156 return delegate_->audio_rtp_header_extensions();
157 }
video_codecs()158 virtual const std::vector<VideoCodec>& video_codecs() OVERRIDE {
159 return delegate_->video_codecs();
160 }
161 virtual const std::vector<RtpHeaderExtension>&
video_rtp_header_extensions()162 video_rtp_header_extensions() OVERRIDE {
163 return delegate_->video_rtp_header_extensions();
164 }
SetVoiceLogging(int min_sev,const char * filter)165 virtual void SetVoiceLogging(int min_sev, const char* filter) OVERRIDE {
166 delegate_->SetVoiceLogging(min_sev, filter);
167 }
SetVideoLogging(int min_sev,const char * filter)168 virtual void SetVideoLogging(int min_sev, const char* filter) OVERRIDE {
169 delegate_->SetVideoLogging(min_sev, filter);
170 }
StartAecDump(rtc::PlatformFile file)171 virtual bool StartAecDump(rtc::PlatformFile file) OVERRIDE {
172 return delegate_->StartAecDump(file);
173 }
RegisterVoiceProcessor(uint32 ssrc,VoiceProcessor * video_processor,MediaProcessorDirection direction)174 virtual bool RegisterVoiceProcessor(
175 uint32 ssrc, VoiceProcessor* video_processor,
176 MediaProcessorDirection direction) OVERRIDE {
177 return delegate_->RegisterVoiceProcessor(ssrc, video_processor, direction);
178 }
UnregisterVoiceProcessor(uint32 ssrc,VoiceProcessor * video_processor,MediaProcessorDirection direction)179 virtual bool UnregisterVoiceProcessor(
180 uint32 ssrc, VoiceProcessor* video_processor,
181 MediaProcessorDirection direction) OVERRIDE {
182 return delegate_->UnregisterVoiceProcessor(ssrc, video_processor,
183 direction);
184 }
GetStartCaptureFormat()185 virtual VideoFormat GetStartCaptureFormat() const OVERRIDE {
186 return delegate_->GetStartCaptureFormat();
187 }
188 virtual sigslot::repeater2<VideoCapturer*, CaptureState>&
SignalVideoCaptureStateChange()189 SignalVideoCaptureStateChange() {
190 return delegate_->SignalVideoCaptureStateChange();
191 }
192
193 private:
194 cricket::MediaEngineInterface* delegate_;
195 };
196
197 // Used by PeerConnectionFactory to create a media engine passed into
198 // ChannelManager.
Create(webrtc::AudioDeviceModule * adm,webrtc::AudioDeviceModule * adm_sc,WebRtcVideoEncoderFactory * encoder_factory,WebRtcVideoDecoderFactory * decoder_factory)199 MediaEngineInterface* WebRtcMediaEngineFactory::Create(
200 webrtc::AudioDeviceModule* adm,
201 webrtc::AudioDeviceModule* adm_sc,
202 WebRtcVideoEncoderFactory* encoder_factory,
203 WebRtcVideoDecoderFactory* decoder_factory) {
204 return new cricket::DelegatingWebRtcMediaEngine(
205 adm, adm_sc, encoder_factory, decoder_factory);
206 }
207
208 } // namespace cricket
209
210 #endif // !defined(LIBPEERCONNECTION_LIB) &&
211 // !defined(LIBPEERCONNECTION_IMPLEMENTATION)
212
213 #endif // TALK_MEDIA_WEBRTCMEDIAENGINE_H_
214