Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / libjingle / source / talk / media / webrtc / webrtcmediaengine.h
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(rtc::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 StartAecDump(rtc::PlatformFile file) OVERRIDE {
149     return delegate_->StartAecDump(file);
150   }
151   virtual bool RegisterVoiceProcessor(
152       uint32 ssrc, VoiceProcessor* video_processor,
153       MediaProcessorDirection direction) OVERRIDE {
154     return delegate_->RegisterVoiceProcessor(ssrc, video_processor, direction);
155   }
156   virtual bool UnregisterVoiceProcessor(
157       uint32 ssrc, VoiceProcessor* video_processor,
158       MediaProcessorDirection direction) OVERRIDE {
159     return delegate_->UnregisterVoiceProcessor(ssrc, video_processor,
160         direction);
161   }
162   virtual VideoFormat GetStartCaptureFormat() const OVERRIDE {
163     return delegate_->GetStartCaptureFormat();
164   }
165   virtual sigslot::repeater2<VideoCapturer*, CaptureState>&
166       SignalVideoCaptureStateChange() {
167     return delegate_->SignalVideoCaptureStateChange();
168   }
169
170  private:
171   cricket::MediaEngineInterface* delegate_;
172 };
173
174 }  // namespace cricket
175 #else
176
177 #include "talk/media/webrtc/webrtcvideoengine.h"
178 #ifdef WEBRTC_CHROMIUM_BUILD
179 #include "talk/media/webrtc/webrtcvideoengine2.h"
180 #endif
181 #include "talk/media/webrtc/webrtcvoiceengine.h"
182
183 namespace cricket {
184 typedef CompositeMediaEngine<WebRtcVoiceEngine, WebRtcVideoEngine>
185         WebRtcCompositeMediaEngine;
186
187 class WebRtcMediaEngine : public WebRtcCompositeMediaEngine {
188  public:
189   WebRtcMediaEngine(webrtc::AudioDeviceModule* adm,
190       webrtc::AudioDeviceModule* adm_sc,
191       WebRtcVideoEncoderFactory* encoder_factory,
192       WebRtcVideoDecoderFactory* decoder_factory) {
193     voice_.SetAudioDeviceModule(adm, adm_sc);
194     video_.SetVoiceEngine(&voice_);
195     video_.EnableTimedRender();
196     video_.SetExternalEncoderFactory(encoder_factory);
197     video_.SetExternalDecoderFactory(decoder_factory);
198   }
199 };
200
201 #ifdef WEBRTC_CHROMIUM_BUILD
202 typedef CompositeMediaEngine<WebRtcVoiceEngine, WebRtcVideoEngine2>
203         WebRtcCompositeMediaEngine2;
204
205 class WebRtcMediaEngine2 : public WebRtcCompositeMediaEngine2 {
206  public:
207   WebRtcMediaEngine2(webrtc::AudioDeviceModule* adm,
208                      webrtc::AudioDeviceModule* adm_sc,
209                      WebRtcVideoEncoderFactory* encoder_factory,
210                      WebRtcVideoDecoderFactory* decoder_factory) {
211     voice_.SetAudioDeviceModule(adm, adm_sc);
212     video_.SetVoiceEngine(&voice_);
213     video_.EnableTimedRender();
214   }
215 };
216 #endif
217
218 }  // namespace cricket
219
220 #endif  // !defined(LIBPEERCONNECTION_LIB) &&
221         // !defined(LIBPEERCONNECTION_IMPLEMENTATION)
222
223 #endif  // TALK_MEDIA_WEBRTCMEDIAENGINE_H_