blob: 467614bb3eaa4cea214d1a044558222cc3d5bed0 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2004 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_BASE_MEDIAENGINE_H_
29#define TALK_MEDIA_BASE_MEDIAENGINE_H_
30
kjellanderfcfc8042016-01-14 11:01:09 -080031#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032#include <CoreAudio/CoreAudio.h>
33#endif
34
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035#include <string>
36#include <vector>
37
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038#include "talk/media/base/codec.h"
39#include "talk/media/base/mediachannel.h"
40#include "talk/media/base/mediacommon.h"
41#include "talk/media/base/videocapturer.h"
42#include "talk/media/base/videocommon.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043#include "talk/media/devices/devicemanager.h"
solenberg566ef242015-11-06 15:34:49 -080044#include "webrtc/audio_state.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000045#include "webrtc/base/fileutils.h"
46#include "webrtc/base/sigslotrepeater.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047
48#if defined(GOOGLE_CHROME_BUILD) || defined(CHROMIUM_BUILD)
49#define DISABLE_MEDIA_ENGINE_FACTORY
50#endif
51
Fredrik Solenberg709ed672015-09-15 12:26:33 +020052namespace webrtc {
53class Call;
Fredrik Solenberg709ed672015-09-15 12:26:33 +020054}
55
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056namespace cricket {
57
58class VideoCapturer;
59
Stefan Holmer9d69c3f2015-12-07 10:45:43 +010060struct RtpCapabilities {
61 std::vector<RtpHeaderExtension> header_extensions;
62};
63
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064// MediaEngineInterface is an abstraction of a media engine which can be
65// subclassed to support different media componentry backends.
66// It supports voice and video operations in the same class to facilitate
67// proper synchronization between both media types.
68class MediaEngineInterface {
69 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070 virtual ~MediaEngineInterface() {}
71
72 // Initialization
73 // Starts the engine.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000074 virtual bool Init(rtc::Thread* worker_thread) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075 // Shuts down the engine.
76 virtual void Terminate() = 0;
Fredrik Solenberg709ed672015-09-15 12:26:33 +020077 // TODO(solenberg): Remove once VoE API refactoring is done.
solenberg566ef242015-11-06 15:34:49 -080078 virtual rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079
80 // MediaChannel creation
81 // Creates a voice media channel. Returns NULL on failure.
Fredrik Solenberg709ed672015-09-15 12:26:33 +020082 virtual VoiceMediaChannel* CreateChannel(
83 webrtc::Call* call,
84 const AudioOptions& options) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085 // Creates a video media channel, paired with the specified voice channel.
86 // Returns NULL on failure.
buildbot@webrtc.org1ecbe452014-10-14 20:29:28 +000087 virtual VideoMediaChannel* CreateVideoChannel(
Fredrik Solenberg709ed672015-09-15 12:26:33 +020088 webrtc::Call* call,
89 const VideoOptions& options) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091 // Device configuration
92 // Gets the current speaker volume, as a value between 0 and 255.
93 virtual bool GetOutputVolume(int* level) = 0;
94 // Sets the current speaker volume, as a value between 0 and 255.
95 virtual bool SetOutputVolume(int level) = 0;
96
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097 // Gets the current microphone level, as a value between 0 and 10.
98 virtual int GetInputLevel() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099
100 virtual const std::vector<AudioCodec>& audio_codecs() = 0;
Stefan Holmer9d69c3f2015-12-07 10:45:43 +0100101 virtual RtpCapabilities GetAudioCapabilities() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102 virtual const std::vector<VideoCodec>& video_codecs() = 0;
Stefan Holmer9d69c3f2015-12-07 10:45:43 +0100103 virtual RtpCapabilities GetVideoCapabilities() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104
ivoca4df27b2015-12-19 10:14:10 -0800105 // Starts AEC dump using existing file.
106 virtual bool StartAecDump(rtc::PlatformFile file) = 0;
ivoc112a3d82015-10-16 02:22:18 -0700107
ivoc797ef122015-10-22 03:25:41 -0700108 // Stops recording AEC dump.
109 virtual void StopAecDump() = 0;
110
ivoc112a3d82015-10-16 02:22:18 -0700111 // Starts RtcEventLog using existing file.
112 virtual bool StartRtcEventLog(rtc::PlatformFile file) = 0;
113
114 // Stops recording an RtcEventLog.
115 virtual void StopRtcEventLog() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116};
117
118
119#if !defined(DISABLE_MEDIA_ENGINE_FACTORY)
120class MediaEngineFactory {
121 public:
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000122 typedef cricket::MediaEngineInterface* (*MediaEngineCreateFunction)();
123 // Creates a media engine, using either the compiled system default or the
124 // creation function specified in SetCreateFunction, if specified.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125 static MediaEngineInterface* Create();
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000126 // Sets the function used when calling Create. If unset, the compiled system
127 // default will be used. Returns the old create function, or NULL if one
128 // wasn't set. Likewise, NULL can be used as the |function| parameter to
129 // reset to the default behavior.
130 static MediaEngineCreateFunction SetCreateFunction(
131 MediaEngineCreateFunction function);
132 private:
133 static MediaEngineCreateFunction create_function_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000134};
135#endif
136
137// CompositeMediaEngine constructs a MediaEngine from separate
138// voice and video engine classes.
139template<class VOICE, class VIDEO>
140class CompositeMediaEngine : public MediaEngineInterface {
141 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142 virtual ~CompositeMediaEngine() {}
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000143 virtual bool Init(rtc::Thread* worker_thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144 if (!voice_.Init(worker_thread))
145 return false;
Fredrik Solenberg9a416bd2015-05-22 09:04:09 +0200146 video_.Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000147 return true;
148 }
149 virtual void Terminate() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150 voice_.Terminate();
151 }
152
solenberg566ef242015-11-06 15:34:49 -0800153 virtual rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const {
154 return voice_.GetAudioState();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 }
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200156 virtual VoiceMediaChannel* CreateChannel(webrtc::Call* call,
157 const AudioOptions& options) {
158 return voice_.CreateChannel(call, options);
159 }
160 virtual VideoMediaChannel* CreateVideoChannel(webrtc::Call* call,
161 const VideoOptions& options) {
162 return video_.CreateChannel(call, options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 virtual bool GetOutputVolume(int* level) {
166 return voice_.GetOutputVolume(level);
167 }
168 virtual bool SetOutputVolume(int level) {
169 return voice_.SetOutputVolume(level);
170 }
171
172 virtual int GetInputLevel() {
173 return voice_.GetInputLevel();
174 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175 virtual const std::vector<AudioCodec>& audio_codecs() {
176 return voice_.codecs();
177 }
Stefan Holmer9d69c3f2015-12-07 10:45:43 +0100178 virtual RtpCapabilities GetAudioCapabilities() {
179 return voice_.GetCapabilities();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000180 }
181 virtual const std::vector<VideoCodec>& video_codecs() {
182 return video_.codecs();
183 }
Stefan Holmer9d69c3f2015-12-07 10:45:43 +0100184 virtual RtpCapabilities GetVideoCapabilities() {
185 return video_.GetCapabilities();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 }
187
ivoca4df27b2015-12-19 10:14:10 -0800188 virtual bool StartAecDump(rtc::PlatformFile file) {
189 return voice_.StartAecDump(file);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000190 }
191
ivoc797ef122015-10-22 03:25:41 -0700192 virtual void StopAecDump() {
193 voice_.StopAecDump();
194 }
195
ivoc112a3d82015-10-16 02:22:18 -0700196 virtual bool StartRtcEventLog(rtc::PlatformFile file) {
197 return voice_.StartRtcEventLog(file);
198 }
199
200 virtual void StopRtcEventLog() { voice_.StopRtcEventLog(); }
201
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000202 protected:
203 VOICE voice_;
204 VIDEO video_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205};
206
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207enum DataChannelType {
208 DCT_NONE = 0,
209 DCT_RTP = 1,
210 DCT_SCTP = 2
211};
212
213class DataEngineInterface {
214 public:
215 virtual ~DataEngineInterface() {}
216 virtual DataMediaChannel* CreateChannel(DataChannelType type) = 0;
217 virtual const std::vector<DataCodec>& data_codecs() = 0;
218};
219
220} // namespace cricket
221
222#endif // TALK_MEDIA_BASE_MEDIAENGINE_H_