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
34namespace webrtc {
35class AudioDeviceModule;
36class VideoCaptureModule;
37}
38namespace cricket {
39class WebRtcVideoDecoderFactory;
40class WebRtcVideoEncoderFactory;
41}
42
43#if !defined(LIBPEERCONNECTION_LIB) && \
44    !defined(LIBPEERCONNECTION_IMPLEMENTATION)
45
46WRME_EXPORT
47cricket::MediaEngineInterface* CreateWebRtcMediaEngine(
48    webrtc::AudioDeviceModule* adm, webrtc::AudioDeviceModule* adm_sc,
49    cricket::WebRtcVideoEncoderFactory* encoder_factory,
50    cricket::WebRtcVideoDecoderFactory* decoder_factory);
51
52WRME_EXPORT
53void DestroyWebRtcMediaEngine(cricket::MediaEngineInterface* media_engine);
54
55#endif  // !defined(LIBPEERCONNECTION_LIB) &&
56        // !defined(LIBPEERCONNECTION_IMPLEMENTATION)
57
58namespace cricket {
59
60class 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
83namespace 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.
87class DelegatingWebRtcMediaEngine : public cricket::MediaEngineInterface {
88 public:
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  }
97  virtual ~DelegatingWebRtcMediaEngine() {
98    DestroyWebRtcMediaEngine(delegate_);
99  }
100  virtual bool Init(rtc::Thread* worker_thread) OVERRIDE {
101    return delegate_->Init(worker_thread);
102  }
103  virtual void Terminate() OVERRIDE {
104    delegate_->Terminate();
105  }
106  virtual int GetCapabilities() OVERRIDE {
107    return delegate_->GetCapabilities();
108  }
109  virtual VoiceMediaChannel* CreateChannel() OVERRIDE {
110    return delegate_->CreateChannel();
111  }
112  virtual VideoMediaChannel* CreateVideoChannel(
113      VoiceMediaChannel* voice_media_channel) OVERRIDE {
114    return delegate_->CreateVideoChannel(voice_media_channel);
115  }
116  virtual SoundclipMedia* CreateSoundclip() OVERRIDE {
117    return delegate_->CreateSoundclip();
118  }
119  virtual AudioOptions GetAudioOptions() const OVERRIDE {
120    return delegate_->GetAudioOptions();
121  }
122  virtual bool SetAudioOptions(const AudioOptions& options) OVERRIDE {
123    return delegate_->SetAudioOptions(options);
124  }
125  virtual bool SetAudioDelayOffset(int offset) OVERRIDE {
126    return delegate_->SetAudioDelayOffset(offset);
127  }
128  virtual bool SetDefaultVideoEncoderConfig(
129      const VideoEncoderConfig& config) OVERRIDE {
130    return delegate_->SetDefaultVideoEncoderConfig(config);
131  }
132  virtual VideoEncoderConfig GetDefaultVideoEncoderConfig() const OVERRIDE {
133    return delegate_->GetDefaultVideoEncoderConfig();
134  }
135  virtual bool SetSoundDevices(
136      const Device* in_device, const Device* out_device) OVERRIDE {
137    return delegate_->SetSoundDevices(in_device, out_device);
138  }
139  virtual bool GetOutputVolume(int* level) OVERRIDE {
140    return delegate_->GetOutputVolume(level);
141  }
142  virtual bool SetOutputVolume(int level) OVERRIDE {
143    return delegate_->SetOutputVolume(level);
144  }
145  virtual int GetInputLevel() OVERRIDE {
146    return delegate_->GetInputLevel();
147  }
148  virtual bool SetLocalMonitor(bool enable) OVERRIDE {
149    return delegate_->SetLocalMonitor(enable);
150  }
151  virtual const std::vector<AudioCodec>& audio_codecs() OVERRIDE {
152    return delegate_->audio_codecs();
153  }
154  virtual const std::vector<RtpHeaderExtension>&
155      audio_rtp_header_extensions() OVERRIDE {
156    return delegate_->audio_rtp_header_extensions();
157  }
158  virtual const std::vector<VideoCodec>& video_codecs() OVERRIDE {
159    return delegate_->video_codecs();
160  }
161  virtual const std::vector<RtpHeaderExtension>&
162      video_rtp_header_extensions() OVERRIDE {
163    return delegate_->video_rtp_header_extensions();
164  }
165  virtual void SetVoiceLogging(int min_sev, const char* filter) OVERRIDE {
166    delegate_->SetVoiceLogging(min_sev, filter);
167  }
168  virtual void SetVideoLogging(int min_sev, const char* filter) OVERRIDE {
169    delegate_->SetVideoLogging(min_sev, filter);
170  }
171  virtual bool StartAecDump(rtc::PlatformFile file) OVERRIDE {
172    return delegate_->StartAecDump(file);
173  }
174  virtual bool RegisterVoiceProcessor(
175      uint32 ssrc, VoiceProcessor* video_processor,
176      MediaProcessorDirection direction) OVERRIDE {
177    return delegate_->RegisterVoiceProcessor(ssrc, video_processor, direction);
178  }
179  virtual bool UnregisterVoiceProcessor(
180      uint32 ssrc, VoiceProcessor* video_processor,
181      MediaProcessorDirection direction) OVERRIDE {
182    return delegate_->UnregisterVoiceProcessor(ssrc, video_processor,
183        direction);
184  }
185  virtual VideoFormat GetStartCaptureFormat() const OVERRIDE {
186    return delegate_->GetStartCaptureFormat();
187  }
188  virtual sigslot::repeater2<VideoCapturer*, CaptureState>&
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.
199MediaEngineInterface* 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