blob: 5fa05c6dd927b648c93b5730c4711d353813bcd2 [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>
19#include <vector>
20
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#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öllerd8970db2017-09-29 13:40:39 +020028#include "rtc_base/platform_file.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029
30#if defined(GOOGLE_CHROME_BUILD) || defined(CHROMIUM_BUILD)
31#define DISABLE_MEDIA_ENGINE_FACTORY
32#endif
33
Fredrik Solenberg709ed672015-09-15 12:26:33 +020034namespace webrtc {
solenbergff976312016-03-30 23:28:51 -070035class AudioDeviceModule;
gyzhou95aa9642016-12-13 14:06:26 -080036class AudioMixer;
peaha9cc40b2017-06-29 08:32:09 -070037class AudioProcessing;
Fredrik Solenberg709ed672015-09-15 12:26:33 +020038class Call;
Fredrik Solenberg709ed672015-09-15 12:26:33 +020039}
40
henrike@webrtc.org28e20752013-07-10 00:45:36 +000041namespace cricket {
42
Stefan Holmer9d69c3f2015-12-07 10:45:43 +010043struct RtpCapabilities {
isheriff6f8d6862016-05-26 11:24:55 -070044 std::vector<webrtc::RtpExtension> header_extensions;
Stefan Holmer9d69c3f2015-12-07 10:45:43 +010045};
46
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047// 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.
51class MediaEngineInterface {
52 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053 virtual ~MediaEngineInterface() {}
54
55 // Initialization
56 // Starts the engine.
solenbergff976312016-03-30 23:28:51 -070057 virtual bool Init() = 0;
Fredrik Solenberg709ed672015-09-15 12:26:33 +020058 // TODO(solenberg): Remove once VoE API refactoring is done.
solenberg566ef242015-11-06 15:34:49 -080059 virtual rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060
61 // MediaChannel creation
62 // Creates a voice media channel. Returns NULL on failure.
nisse51542be2016-02-12 02:27:06 -080063 virtual VoiceMediaChannel* CreateChannel(webrtc::Call* call,
64 const MediaConfig& config,
65 const AudioOptions& options) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066 // Creates a video media channel, paired with the specified voice channel.
67 // Returns NULL on failure.
buildbot@webrtc.org1ecbe452014-10-14 20:29:28 +000068 virtual VideoMediaChannel* CreateVideoChannel(
Fredrik Solenberg709ed672015-09-15 12:26:33 +020069 webrtc::Call* call,
nisse51542be2016-02-12 02:27:06 -080070 const MediaConfig& config,
Fredrik Solenberg709ed672015-09-15 12:26:33 +020071 const VideoOptions& options) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073 // Gets the current microphone level, as a value between 0 and 10.
74 virtual int GetInputLevel() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075
ossudedfd282016-06-14 07:12:39 -070076 virtual const std::vector<AudioCodec>& audio_send_codecs() = 0;
77 virtual const std::vector<AudioCodec>& audio_recv_codecs() = 0;
Stefan Holmer9d69c3f2015-12-07 10:45:43 +010078 virtual RtpCapabilities GetAudioCapabilities() = 0;
brandtrffc61182016-11-28 06:02:22 -080079 virtual std::vector<VideoCodec> video_codecs() = 0;
Stefan Holmer9d69c3f2015-12-07 10:45:43 +010080 virtual RtpCapabilities GetVideoCapabilities() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081
ivocd66b44d2016-01-15 03:06:36 -080082 // 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;
ivoc112a3d82015-10-16 02:22:18 -070086
ivoc797ef122015-10-22 03:25:41 -070087 // Stops recording AEC dump.
88 virtual void StopAecDump() = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089};
90
91
92#if !defined(DISABLE_MEDIA_ENGINE_FACTORY)
93class MediaEngineFactory {
94 public:
henrike@webrtc.org40b3b682014-03-03 18:30:11 +000095 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.org28e20752013-07-10 00:45:36 +000098 static MediaEngineInterface* Create();
henrike@webrtc.org40b3b682014-03-03 18:30:11 +000099 // 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.org28e20752013-07-10 00:45:36 +0000107};
108#endif
109
110// CompositeMediaEngine constructs a MediaEngine from separate
111// voice and video engine classes.
magjed2475ae22017-09-12 04:42:15 -0700112template <class VOICE, class VIDEO>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113class CompositeMediaEngine : public MediaEngineInterface {
114 public:
magjed2475ae22017-09-12 04:42:15 -0700115 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.org28e20752013-07-10 00:45:36 +0000122 virtual ~CompositeMediaEngine() {}
solenbergff976312016-03-30 23:28:51 -0700123 virtual bool Init() {
magjed2475ae22017-09-12 04:42:15 -0700124 voice().Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125 return true;
126 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127
solenberg566ef242015-11-06 15:34:49 -0800128 virtual rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const {
magjed2475ae22017-09-12 04:42:15 -0700129 return voice().GetAudioState();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130 }
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200131 virtual VoiceMediaChannel* CreateChannel(webrtc::Call* call,
nisse51542be2016-02-12 02:27:06 -0800132 const MediaConfig& config,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200133 const AudioOptions& options) {
magjed2475ae22017-09-12 04:42:15 -0700134 return voice().CreateChannel(call, config, options);
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200135 }
136 virtual VideoMediaChannel* CreateVideoChannel(webrtc::Call* call,
nisse51542be2016-02-12 02:27:06 -0800137 const MediaConfig& config,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200138 const VideoOptions& options) {
magjed2475ae22017-09-12 04:42:15 -0700139 return video().CreateChannel(call, config, options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000140 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000141
magjed2475ae22017-09-12 04:42:15 -0700142 virtual int GetInputLevel() { return voice().GetInputLevel(); }
ossudedfd282016-06-14 07:12:39 -0700143 virtual const std::vector<AudioCodec>& audio_send_codecs() {
magjed2475ae22017-09-12 04:42:15 -0700144 return voice().send_codecs();
ossudedfd282016-06-14 07:12:39 -0700145 }
146 virtual const std::vector<AudioCodec>& audio_recv_codecs() {
magjed2475ae22017-09-12 04:42:15 -0700147 return voice().recv_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000148 }
Stefan Holmer9d69c3f2015-12-07 10:45:43 +0100149 virtual RtpCapabilities GetAudioCapabilities() {
magjed2475ae22017-09-12 04:42:15 -0700150 return voice().GetCapabilities();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151 }
magjed2475ae22017-09-12 04:42:15 -0700152 virtual std::vector<VideoCodec> video_codecs() { return video().codecs(); }
Stefan Holmer9d69c3f2015-12-07 10:45:43 +0100153 virtual RtpCapabilities GetVideoCapabilities() {
magjed2475ae22017-09-12 04:42:15 -0700154 return video().GetCapabilities();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 }
156
ivocd66b44d2016-01-15 03:06:36 -0800157 virtual bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) {
magjed2475ae22017-09-12 04:42:15 -0700158 return voice().StartAecDump(file, max_size_bytes);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000159 }
160
magjed2475ae22017-09-12 04:42:15 -0700161 virtual void StopAecDump() { voice().StopAecDump(); }
ivoc797ef122015-10-22 03:25:41 -0700162
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163 protected:
magjed2475ae22017-09-12 04:42:15 -0700164 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.org28e20752013-07-10 00:45:36 +0000171};
172
Steve Antonc4faa9c2017-10-23 14:44:03 -0700173enum DataChannelType { DCT_NONE = 0, DCT_RTP = 1, DCT_SCTP = 2 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174
175class DataEngineInterface {
176 public:
177 virtual ~DataEngineInterface() {}
deadbeef953c2ce2017-01-09 14:53:41 -0800178 virtual DataMediaChannel* CreateChannel(const MediaConfig& config) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179 virtual const std::vector<DataCodec>& data_codecs() = 0;
180};
181
skvladdc1c62c2016-03-16 19:07:43 -0700182webrtc::RtpParameters CreateRtpParametersWithOneEncoding();
183
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184} // namespace cricket
185
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200186#endif // MEDIA_BASE_MEDIAENGINE_H_