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