henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 2 | * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MEDIA_BASE_MEDIAENGINE_H_ |
| 12 | #define MEDIA_BASE_MEDIAENGINE_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
kjellander | fcfc804 | 2016-01-14 11:01:09 -0800 | [diff] [blame] | 14 | #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 15 | #include <CoreAudio/CoreAudio.h> |
| 16 | #endif |
| 17 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 18 | #include <string> |
Steve Anton | e78bcb9 | 2017-10-31 09:53:08 -0700 | [diff] [blame] | 19 | #include <tuple> |
| 20 | #include <utility> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "api/audio_codecs/audio_decoder_factory.h" |
| 24 | #include "api/audio_codecs/audio_encoder_factory.h" |
| 25 | #include "api/rtpparameters.h" |
| 26 | #include "call/audio_state.h" |
| 27 | #include "media/base/codec.h" |
| 28 | #include "media/base/mediachannel.h" |
| 29 | #include "media/base/videocommon.h" |
Niels Möller | d8970db | 2017-09-29 13:40:39 +0200 | [diff] [blame] | 30 | #include "rtc_base/platform_file.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 31 | |
| 32 | #if defined(GOOGLE_CHROME_BUILD) || defined(CHROMIUM_BUILD) |
| 33 | #define DISABLE_MEDIA_ENGINE_FACTORY |
| 34 | #endif |
| 35 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 36 | namespace webrtc { |
solenberg | ff97631 | 2016-03-30 23:28:51 -0700 | [diff] [blame] | 37 | class AudioDeviceModule; |
gyzhou | 95aa964 | 2016-12-13 14:06:26 -0800 | [diff] [blame] | 38 | class AudioMixer; |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 39 | class AudioProcessing; |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 40 | class Call; |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 41 | } |
| 42 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 43 | namespace cricket { |
| 44 | |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 45 | struct RtpCapabilities { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 46 | std::vector<webrtc::RtpExtension> header_extensions; |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 47 | }; |
| 48 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 49 | // MediaEngineInterface is an abstraction of a media engine which can be |
| 50 | // subclassed to support different media componentry backends. |
| 51 | // It supports voice and video operations in the same class to facilitate |
| 52 | // proper synchronization between both media types. |
| 53 | class MediaEngineInterface { |
| 54 | public: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 55 | virtual ~MediaEngineInterface() {} |
| 56 | |
| 57 | // Initialization |
| 58 | // Starts the engine. |
solenberg | ff97631 | 2016-03-30 23:28:51 -0700 | [diff] [blame] | 59 | virtual bool Init() = 0; |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 60 | // TODO(solenberg): Remove once VoE API refactoring is done. |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 61 | virtual rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 62 | |
| 63 | // MediaChannel creation |
| 64 | // Creates a voice media channel. Returns NULL on failure. |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 65 | virtual VoiceMediaChannel* CreateChannel(webrtc::Call* call, |
| 66 | const MediaConfig& config, |
| 67 | const AudioOptions& options) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 68 | // Creates a video media channel, paired with the specified voice channel. |
| 69 | // Returns NULL on failure. |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 70 | virtual VideoMediaChannel* CreateVideoChannel( |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 71 | webrtc::Call* call, |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 72 | const MediaConfig& config, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 73 | const VideoOptions& options) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 75 | // Gets the current microphone level, as a value between 0 and 10. |
| 76 | virtual int GetInputLevel() = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 77 | |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 78 | virtual const std::vector<AudioCodec>& audio_send_codecs() = 0; |
| 79 | virtual const std::vector<AudioCodec>& audio_recv_codecs() = 0; |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 80 | virtual RtpCapabilities GetAudioCapabilities() = 0; |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 81 | virtual std::vector<VideoCodec> video_codecs() = 0; |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 82 | virtual RtpCapabilities GetVideoCapabilities() = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 84 | // Starts AEC dump using existing file, a maximum file size in bytes can be |
| 85 | // specified. Logging is stopped just before the size limit is exceeded. |
| 86 | // If max_size_bytes is set to a value <= 0, no limit will be used. |
| 87 | virtual bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) = 0; |
ivoc | 112a3d8 | 2015-10-16 02:22:18 -0700 | [diff] [blame] | 88 | |
ivoc | 797ef12 | 2015-10-22 03:25:41 -0700 | [diff] [blame] | 89 | // Stops recording AEC dump. |
| 90 | virtual void StopAecDump() = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | |
| 94 | #if !defined(DISABLE_MEDIA_ENGINE_FACTORY) |
| 95 | class MediaEngineFactory { |
| 96 | public: |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 97 | typedef cricket::MediaEngineInterface* (*MediaEngineCreateFunction)(); |
| 98 | // Creates a media engine, using either the compiled system default or the |
| 99 | // creation function specified in SetCreateFunction, if specified. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 100 | static MediaEngineInterface* Create(); |
henrike@webrtc.org | 40b3b68 | 2014-03-03 18:30:11 +0000 | [diff] [blame] | 101 | // Sets the function used when calling Create. If unset, the compiled system |
| 102 | // default will be used. Returns the old create function, or NULL if one |
| 103 | // wasn't set. Likewise, NULL can be used as the |function| parameter to |
| 104 | // reset to the default behavior. |
| 105 | static MediaEngineCreateFunction SetCreateFunction( |
| 106 | MediaEngineCreateFunction function); |
| 107 | private: |
| 108 | static MediaEngineCreateFunction create_function_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 109 | }; |
| 110 | #endif |
| 111 | |
| 112 | // CompositeMediaEngine constructs a MediaEngine from separate |
| 113 | // voice and video engine classes. |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 114 | template <class VOICE, class VIDEO> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 115 | class CompositeMediaEngine : public MediaEngineInterface { |
| 116 | public: |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 117 | template <class... Args1, class... Args2> |
| 118 | CompositeMediaEngine(std::tuple<Args1...> first_args, |
| 119 | std::tuple<Args2...> second_args) |
| 120 | : engines_(std::piecewise_construct, |
| 121 | std::move(first_args), |
| 122 | std::move(second_args)) {} |
| 123 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 124 | virtual ~CompositeMediaEngine() {} |
solenberg | ff97631 | 2016-03-30 23:28:51 -0700 | [diff] [blame] | 125 | virtual bool Init() { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 126 | voice().Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 127 | return true; |
| 128 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 129 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 130 | virtual rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 131 | return voice().GetAudioState(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 132 | } |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 133 | virtual VoiceMediaChannel* CreateChannel(webrtc::Call* call, |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 134 | const MediaConfig& config, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 135 | const AudioOptions& options) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 136 | return voice().CreateChannel(call, config, options); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 137 | } |
| 138 | virtual VideoMediaChannel* CreateVideoChannel(webrtc::Call* call, |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 139 | const MediaConfig& config, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 140 | const VideoOptions& options) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 141 | return video().CreateChannel(call, config, options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 142 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 143 | |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 144 | virtual int GetInputLevel() { return voice().GetInputLevel(); } |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 145 | virtual const std::vector<AudioCodec>& audio_send_codecs() { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 146 | return voice().send_codecs(); |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 147 | } |
| 148 | virtual const std::vector<AudioCodec>& audio_recv_codecs() { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 149 | return voice().recv_codecs(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 150 | } |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 151 | virtual RtpCapabilities GetAudioCapabilities() { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 152 | return voice().GetCapabilities(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 153 | } |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 154 | virtual std::vector<VideoCodec> video_codecs() { return video().codecs(); } |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 155 | virtual RtpCapabilities GetVideoCapabilities() { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 156 | return video().GetCapabilities(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 157 | } |
| 158 | |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 159 | virtual bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) { |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 160 | return voice().StartAecDump(file, max_size_bytes); |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 161 | } |
| 162 | |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 163 | virtual void StopAecDump() { voice().StopAecDump(); } |
ivoc | 797ef12 | 2015-10-22 03:25:41 -0700 | [diff] [blame] | 164 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 165 | protected: |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 166 | VOICE& voice() { return engines_.first; } |
| 167 | VIDEO& video() { return engines_.second; } |
| 168 | const VOICE& voice() const { return engines_.first; } |
| 169 | const VIDEO& video() const { return engines_.second; } |
| 170 | |
| 171 | private: |
| 172 | std::pair<VOICE, VIDEO> engines_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 173 | }; |
| 174 | |
Steve Anton | c4faa9c | 2017-10-23 14:44:03 -0700 | [diff] [blame] | 175 | enum DataChannelType { DCT_NONE = 0, DCT_RTP = 1, DCT_SCTP = 2 }; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 176 | |
| 177 | class DataEngineInterface { |
| 178 | public: |
| 179 | virtual ~DataEngineInterface() {} |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 180 | virtual DataMediaChannel* CreateChannel(const MediaConfig& config) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 181 | virtual const std::vector<DataCodec>& data_codecs() = 0; |
| 182 | }; |
| 183 | |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 184 | webrtc::RtpParameters CreateRtpParametersWithOneEncoding(); |
| 185 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 186 | } // namespace cricket |
| 187 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 188 | #endif // MEDIA_BASE_MEDIAENGINE_H_ |