henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 31 | #ifdef OSX |
| 32 | #include <CoreAudio/CoreAudio.h> |
| 33 | #endif |
| 34 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 35 | #include <string> |
| 36 | #include <vector> |
| 37 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 38 | #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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 43 | #include "talk/media/devices/devicemanager.h" |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 44 | #include "webrtc/audio_state.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 45 | #include "webrtc/base/fileutils.h" |
| 46 | #include "webrtc/base/sigslotrepeater.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 47 | |
| 48 | #if defined(GOOGLE_CHROME_BUILD) || defined(CHROMIUM_BUILD) |
| 49 | #define DISABLE_MEDIA_ENGINE_FACTORY |
| 50 | #endif |
| 51 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 52 | namespace webrtc { |
| 53 | class Call; |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 54 | } |
| 55 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 56 | namespace cricket { |
| 57 | |
| 58 | class VideoCapturer; |
| 59 | |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame^] | 60 | struct RtpCapabilities { |
| 61 | std::vector<RtpHeaderExtension> header_extensions; |
| 62 | }; |
| 63 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 64 | // 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. |
| 68 | class MediaEngineInterface { |
| 69 | public: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 70 | virtual ~MediaEngineInterface() {} |
| 71 | |
| 72 | // Initialization |
| 73 | // Starts the engine. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 74 | virtual bool Init(rtc::Thread* worker_thread) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 75 | // Shuts down the engine. |
| 76 | virtual void Terminate() = 0; |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 77 | // TODO(solenberg): Remove once VoE API refactoring is done. |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 78 | virtual rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 79 | |
| 80 | // MediaChannel creation |
| 81 | // Creates a voice media channel. Returns NULL on failure. |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 82 | virtual VoiceMediaChannel* CreateChannel( |
| 83 | webrtc::Call* call, |
| 84 | const AudioOptions& options) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 85 | // Creates a video media channel, paired with the specified voice channel. |
| 86 | // Returns NULL on failure. |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 87 | virtual VideoMediaChannel* CreateVideoChannel( |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 88 | webrtc::Call* call, |
| 89 | const VideoOptions& options) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 90 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 91 | // Configuration |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 92 | // Gets global audio options. |
| 93 | virtual AudioOptions GetAudioOptions() const = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 94 | // Sets global audio options. "options" are from AudioOptions, above. |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 95 | virtual bool SetAudioOptions(const AudioOptions& options) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 96 | // Sets the default (maximum) codec/resolution and encoder option to capture |
| 97 | // and encode video. |
| 98 | virtual bool SetDefaultVideoEncoderConfig(const VideoEncoderConfig& config) |
| 99 | = 0; |
| 100 | |
| 101 | // Device selection |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 102 | virtual bool SetSoundDevices(const Device* in_device, |
| 103 | const Device* out_device) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 104 | |
| 105 | // Device configuration |
| 106 | // Gets the current speaker volume, as a value between 0 and 255. |
| 107 | virtual bool GetOutputVolume(int* level) = 0; |
| 108 | // Sets the current speaker volume, as a value between 0 and 255. |
| 109 | virtual bool SetOutputVolume(int level) = 0; |
| 110 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 111 | // Gets the current microphone level, as a value between 0 and 10. |
| 112 | virtual int GetInputLevel() = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 113 | |
| 114 | virtual const std::vector<AudioCodec>& audio_codecs() = 0; |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame^] | 115 | virtual RtpCapabilities GetAudioCapabilities() = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 116 | virtual const std::vector<VideoCodec>& video_codecs() = 0; |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame^] | 117 | virtual RtpCapabilities GetVideoCapabilities() = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 118 | |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 119 | // Starts AEC dump using existing file. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 120 | virtual bool StartAecDump(rtc::PlatformFile file) = 0; |
ivoc | 112a3d8 | 2015-10-16 02:22:18 -0700 | [diff] [blame] | 121 | |
ivoc | 797ef12 | 2015-10-22 03:25:41 -0700 | [diff] [blame] | 122 | // Stops recording AEC dump. |
| 123 | virtual void StopAecDump() = 0; |
| 124 | |
ivoc | 112a3d8 | 2015-10-16 02:22:18 -0700 | [diff] [blame] | 125 | // Starts RtcEventLog using existing file. |
| 126 | virtual bool StartRtcEventLog(rtc::PlatformFile file) = 0; |
| 127 | |
| 128 | // Stops recording an RtcEventLog. |
| 129 | virtual void StopRtcEventLog() = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | |
| 133 | #if !defined(DISABLE_MEDIA_ENGINE_FACTORY) |
| 134 | class MediaEngineFactory { |
| 135 | public: |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 136 | typedef cricket::MediaEngineInterface* (*MediaEngineCreateFunction)(); |
| 137 | // Creates a media engine, using either the compiled system default or the |
| 138 | // creation function specified in SetCreateFunction, if specified. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 139 | static MediaEngineInterface* Create(); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 140 | // Sets the function used when calling Create. If unset, the compiled system |
| 141 | // default will be used. Returns the old create function, or NULL if one |
| 142 | // wasn't set. Likewise, NULL can be used as the |function| parameter to |
| 143 | // reset to the default behavior. |
| 144 | static MediaEngineCreateFunction SetCreateFunction( |
| 145 | MediaEngineCreateFunction function); |
| 146 | private: |
| 147 | static MediaEngineCreateFunction create_function_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 148 | }; |
| 149 | #endif |
| 150 | |
| 151 | // CompositeMediaEngine constructs a MediaEngine from separate |
| 152 | // voice and video engine classes. |
| 153 | template<class VOICE, class VIDEO> |
| 154 | class CompositeMediaEngine : public MediaEngineInterface { |
| 155 | public: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 156 | virtual ~CompositeMediaEngine() {} |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 157 | virtual bool Init(rtc::Thread* worker_thread) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 158 | if (!voice_.Init(worker_thread)) |
| 159 | return false; |
Fredrik Solenberg | 9a416bd | 2015-05-22 09:04:09 +0200 | [diff] [blame] | 160 | video_.Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 161 | return true; |
| 162 | } |
| 163 | virtual void Terminate() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 164 | voice_.Terminate(); |
| 165 | } |
| 166 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 167 | virtual rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const { |
| 168 | return voice_.GetAudioState(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 169 | } |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 170 | virtual VoiceMediaChannel* CreateChannel(webrtc::Call* call, |
| 171 | const AudioOptions& options) { |
| 172 | return voice_.CreateChannel(call, options); |
| 173 | } |
| 174 | virtual VideoMediaChannel* CreateVideoChannel(webrtc::Call* call, |
| 175 | const VideoOptions& options) { |
| 176 | return video_.CreateChannel(call, options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 177 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 178 | |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 179 | virtual AudioOptions GetAudioOptions() const { |
| 180 | return voice_.GetOptions(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 181 | } |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 182 | virtual bool SetAudioOptions(const AudioOptions& options) { |
| 183 | return voice_.SetOptions(options); |
| 184 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 185 | virtual bool SetDefaultVideoEncoderConfig(const VideoEncoderConfig& config) { |
| 186 | return video_.SetDefaultEncoderConfig(config); |
| 187 | } |
| 188 | |
| 189 | virtual bool SetSoundDevices(const Device* in_device, |
| 190 | const Device* out_device) { |
| 191 | return voice_.SetDevices(in_device, out_device); |
| 192 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 193 | |
| 194 | virtual bool GetOutputVolume(int* level) { |
| 195 | return voice_.GetOutputVolume(level); |
| 196 | } |
| 197 | virtual bool SetOutputVolume(int level) { |
| 198 | return voice_.SetOutputVolume(level); |
| 199 | } |
| 200 | |
| 201 | virtual int GetInputLevel() { |
| 202 | return voice_.GetInputLevel(); |
| 203 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 204 | virtual const std::vector<AudioCodec>& audio_codecs() { |
| 205 | return voice_.codecs(); |
| 206 | } |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame^] | 207 | virtual RtpCapabilities GetAudioCapabilities() { |
| 208 | return voice_.GetCapabilities(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 209 | } |
| 210 | virtual const std::vector<VideoCodec>& video_codecs() { |
| 211 | return video_.codecs(); |
| 212 | } |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame^] | 213 | virtual RtpCapabilities GetVideoCapabilities() { |
| 214 | return video_.GetCapabilities(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 215 | } |
| 216 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 217 | virtual bool StartAecDump(rtc::PlatformFile file) { |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 218 | return voice_.StartAecDump(file); |
| 219 | } |
| 220 | |
ivoc | 797ef12 | 2015-10-22 03:25:41 -0700 | [diff] [blame] | 221 | virtual void StopAecDump() { |
| 222 | voice_.StopAecDump(); |
| 223 | } |
| 224 | |
ivoc | 112a3d8 | 2015-10-16 02:22:18 -0700 | [diff] [blame] | 225 | virtual bool StartRtcEventLog(rtc::PlatformFile file) { |
| 226 | return voice_.StartRtcEventLog(file); |
| 227 | } |
| 228 | |
| 229 | virtual void StopRtcEventLog() { voice_.StopRtcEventLog(); } |
| 230 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 231 | protected: |
| 232 | VOICE voice_; |
| 233 | VIDEO video_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 234 | }; |
| 235 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 236 | enum DataChannelType { |
| 237 | DCT_NONE = 0, |
| 238 | DCT_RTP = 1, |
| 239 | DCT_SCTP = 2 |
| 240 | }; |
| 241 | |
| 242 | class DataEngineInterface { |
| 243 | public: |
| 244 | virtual ~DataEngineInterface() {} |
| 245 | virtual DataMediaChannel* CreateChannel(DataChannelType type) = 0; |
| 246 | virtual const std::vector<DataCodec>& data_codecs() = 0; |
| 247 | }; |
| 248 | |
| 249 | } // namespace cricket |
| 250 | |
| 251 | #endif // TALK_MEDIA_BASE_MEDIAENGINE_H_ |