blob: 483a96b7e8971d3790ca2b1a5324b6799cfc3fad [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellander1afca732016-02-07 20:46:45 -08002 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellander1afca732016-02-07 20:46:45 -08004 * 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.org28e20752013-07-10 00:45:36 +00009 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MEDIA_BASE_MEDIAENGINE_H_
12#define MEDIA_BASE_MEDIAENGINE_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
kjellanderfcfc8042016-01-14 11:01:09 -080014#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015#include <CoreAudio/CoreAudio.h>
16#endif
17
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018#include <string>
Steve Antone78bcb92017-10-31 09:53:08 -070019#include <tuple>
20#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000021#include <vector>
22
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#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öllerd8970db2017-09-29 13:40:39 +020030#include "rtc_base/platform_file.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000031
32#if defined(GOOGLE_CHROME_BUILD) || defined(CHROMIUM_BUILD)
33#define DISABLE_MEDIA_ENGINE_FACTORY
34#endif
35
Fredrik Solenberg709ed672015-09-15 12:26:33 +020036namespace webrtc {
solenbergff976312016-03-30 23:28:51 -070037class AudioDeviceModule;
gyzhou95aa9642016-12-13 14:06:26 -080038class AudioMixer;
peaha9cc40b2017-06-29 08:32:09 -070039class AudioProcessing;
Fredrik Solenberg709ed672015-09-15 12:26:33 +020040class Call;
Fredrik Solenberg709ed672015-09-15 12:26:33 +020041}
42
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043namespace cricket {
44
Stefan Holmer9d69c3f2015-12-07 10:45:43 +010045struct RtpCapabilities {
isheriff6f8d6862016-05-26 11:24:55 -070046 std::vector<webrtc::RtpExtension> header_extensions;
Stefan Holmer9d69c3f2015-12-07 10:45:43 +010047};
48
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049// 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.
53class MediaEngineInterface {
54 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055 virtual ~MediaEngineInterface() {}
56
57 // Initialization
58 // Starts the engine.
solenbergff976312016-03-30 23:28:51 -070059 virtual bool Init() = 0;
Fredrik Solenberg709ed672015-09-15 12:26:33 +020060 // TODO(solenberg): Remove once VoE API refactoring is done.
solenberg566ef242015-11-06 15:34:49 -080061 virtual rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062
63 // MediaChannel creation
64 // Creates a voice media channel. Returns NULL on failure.
nisse51542be2016-02-12 02:27:06 -080065 virtual VoiceMediaChannel* CreateChannel(webrtc::Call* call,
66 const MediaConfig& config,
67 const AudioOptions& options) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068 // Creates a video media channel, paired with the specified voice channel.
69 // Returns NULL on failure.
buildbot@webrtc.org1ecbe452014-10-14 20:29:28 +000070 virtual VideoMediaChannel* CreateVideoChannel(
Fredrik Solenberg709ed672015-09-15 12:26:33 +020071 webrtc::Call* call,
nisse51542be2016-02-12 02:27:06 -080072 const MediaConfig& config,
Fredrik Solenberg709ed672015-09-15 12:26:33 +020073 const VideoOptions& options) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075 // Gets the current microphone level, as a value between 0 and 10.
76 virtual int GetInputLevel() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077
ossudedfd282016-06-14 07:12:39 -070078 virtual const std::vector<AudioCodec>& audio_send_codecs() = 0;
79 virtual const std::vector<AudioCodec>& audio_recv_codecs() = 0;
Stefan Holmer9d69c3f2015-12-07 10:45:43 +010080 virtual RtpCapabilities GetAudioCapabilities() = 0;
brandtrffc61182016-11-28 06:02:22 -080081 virtual std::vector<VideoCodec> video_codecs() = 0;
Stefan Holmer9d69c3f2015-12-07 10:45:43 +010082 virtual RtpCapabilities GetVideoCapabilities() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083
ivocd66b44d2016-01-15 03:06:36 -080084 // 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;
ivoc112a3d82015-10-16 02:22:18 -070088
ivoc797ef122015-10-22 03:25:41 -070089 // Stops recording AEC dump.
90 virtual void StopAecDump() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091};
92
93
94#if !defined(DISABLE_MEDIA_ENGINE_FACTORY)
95class MediaEngineFactory {
96 public:
henrike@webrtc.org40b3b682014-03-03 18:30:11 +000097 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.org28e20752013-07-10 00:45:36 +0000100 static MediaEngineInterface* Create();
henrike@webrtc.org40b3b682014-03-03 18:30:11 +0000101 // 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.org28e20752013-07-10 00:45:36 +0000109};
110#endif
111
112// CompositeMediaEngine constructs a MediaEngine from separate
113// voice and video engine classes.
magjed2475ae22017-09-12 04:42:15 -0700114template <class VOICE, class VIDEO>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115class CompositeMediaEngine : public MediaEngineInterface {
116 public:
magjed2475ae22017-09-12 04:42:15 -0700117 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.org28e20752013-07-10 00:45:36 +0000124 virtual ~CompositeMediaEngine() {}
solenbergff976312016-03-30 23:28:51 -0700125 virtual bool Init() {
magjed2475ae22017-09-12 04:42:15 -0700126 voice().Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127 return true;
128 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000129
solenberg566ef242015-11-06 15:34:49 -0800130 virtual rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const {
magjed2475ae22017-09-12 04:42:15 -0700131 return voice().GetAudioState();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000132 }
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200133 virtual VoiceMediaChannel* CreateChannel(webrtc::Call* call,
nisse51542be2016-02-12 02:27:06 -0800134 const MediaConfig& config,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200135 const AudioOptions& options) {
magjed2475ae22017-09-12 04:42:15 -0700136 return voice().CreateChannel(call, config, options);
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200137 }
138 virtual VideoMediaChannel* CreateVideoChannel(webrtc::Call* call,
nisse51542be2016-02-12 02:27:06 -0800139 const MediaConfig& config,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200140 const VideoOptions& options) {
magjed2475ae22017-09-12 04:42:15 -0700141 return video().CreateChannel(call, config, options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143
magjed2475ae22017-09-12 04:42:15 -0700144 virtual int GetInputLevel() { return voice().GetInputLevel(); }
ossudedfd282016-06-14 07:12:39 -0700145 virtual const std::vector<AudioCodec>& audio_send_codecs() {
magjed2475ae22017-09-12 04:42:15 -0700146 return voice().send_codecs();
ossudedfd282016-06-14 07:12:39 -0700147 }
148 virtual const std::vector<AudioCodec>& audio_recv_codecs() {
magjed2475ae22017-09-12 04:42:15 -0700149 return voice().recv_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150 }
Stefan Holmer9d69c3f2015-12-07 10:45:43 +0100151 virtual RtpCapabilities GetAudioCapabilities() {
magjed2475ae22017-09-12 04:42:15 -0700152 return voice().GetCapabilities();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153 }
magjed2475ae22017-09-12 04:42:15 -0700154 virtual std::vector<VideoCodec> video_codecs() { return video().codecs(); }
Stefan Holmer9d69c3f2015-12-07 10:45:43 +0100155 virtual RtpCapabilities GetVideoCapabilities() {
magjed2475ae22017-09-12 04:42:15 -0700156 return video().GetCapabilities();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157 }
158
ivocd66b44d2016-01-15 03:06:36 -0800159 virtual bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) {
magjed2475ae22017-09-12 04:42:15 -0700160 return voice().StartAecDump(file, max_size_bytes);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000161 }
162
magjed2475ae22017-09-12 04:42:15 -0700163 virtual void StopAecDump() { voice().StopAecDump(); }
ivoc797ef122015-10-22 03:25:41 -0700164
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 protected:
magjed2475ae22017-09-12 04:42:15 -0700166 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.org28e20752013-07-10 00:45:36 +0000173};
174
Steve Antonc4faa9c2017-10-23 14:44:03 -0700175enum DataChannelType { DCT_NONE = 0, DCT_RTP = 1, DCT_SCTP = 2 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000176
177class DataEngineInterface {
178 public:
179 virtual ~DataEngineInterface() {}
deadbeef953c2ce2017-01-09 14:53:41 -0800180 virtual DataMediaChannel* CreateChannel(const MediaConfig& config) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 virtual const std::vector<DataCodec>& data_codecs() = 0;
182};
183
skvladdc1c62c2016-03-16 19:07:43 -0700184webrtc::RtpParameters CreateRtpParametersWithOneEncoding();
185
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186} // namespace cricket
187
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200188#endif // MEDIA_BASE_MEDIAENGINE_H_