blob: 5867c9e18168f237f607df3ef7a87cfa4f005e2b [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
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef MEDIA_BASE_MEDIA_ENGINE_H_
12#define MEDIA_BASE_MEDIA_ENGINE_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
Sebastian Janssonfa0aa392018-11-16 09:54:32 +010018#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000019#include <string>
20#include <vector>
21
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "api/audio_codecs/audio_decoder_factory.h"
23#include "api/audio_codecs/audio_encoder_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "api/crypto/crypto_options.h"
25#include "api/rtp_parameters.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "call/audio_state.h"
27#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080028#include "media/base/media_channel.h"
29#include "media/base/video_common.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
Fredrik Solenberg709ed672015-09-15 12:26:33 +020032namespace webrtc {
solenbergff976312016-03-30 23:28:51 -070033class AudioDeviceModule;
gyzhou95aa9642016-12-13 14:06:26 -080034class AudioMixer;
peaha9cc40b2017-06-29 08:32:09 -070035class AudioProcessing;
Fredrik Solenberg709ed672015-09-15 12:26:33 +020036class Call;
Yves Gerey665174f2018-06-19 15:03:05 +020037} // namespace webrtc
Fredrik Solenberg709ed672015-09-15 12:26:33 +020038
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039namespace cricket {
40
Florent Castellic1a0bcb2019-01-29 14:26:48 +010041webrtc::RTCError CheckRtpParametersValues(
42 const webrtc::RtpParameters& new_parameters);
43
44webrtc::RTCError CheckRtpParametersInvalidModificationAndValues(
Florent Castelli892acf02018-10-01 22:47:20 +020045 const webrtc::RtpParameters& old_parameters,
46 const webrtc::RtpParameters& new_parameters);
47
Stefan Holmer9d69c3f2015-12-07 10:45:43 +010048struct RtpCapabilities {
Paulina Hensman11b34f42018-04-09 14:24:52 +020049 RtpCapabilities();
50 ~RtpCapabilities();
isheriff6f8d6862016-05-26 11:24:55 -070051 std::vector<webrtc::RtpExtension> header_extensions;
Stefan Holmer9d69c3f2015-12-07 10:45:43 +010052};
53
Sebastian Jansson84848f22018-11-16 10:40:36 +010054class VoiceEngineInterface {
55 public:
56 VoiceEngineInterface() = default;
57 virtual ~VoiceEngineInterface() = default;
58 RTC_DISALLOW_COPY_AND_ASSIGN(VoiceEngineInterface);
59
60 // Initialization
61 // Starts the engine.
62 virtual void Init() = 0;
63
64 // TODO(solenberg): Remove once VoE API refactoring is done.
65 virtual rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const = 0;
66
67 // MediaChannel creation
68 // Creates a voice media channel. Returns NULL on failure.
69 virtual VoiceMediaChannel* CreateMediaChannel(
70 webrtc::Call* call,
71 const MediaConfig& config,
72 const AudioOptions& options,
73 const webrtc::CryptoOptions& crypto_options) = 0;
74
75 virtual const std::vector<AudioCodec>& send_codecs() const = 0;
76 virtual const std::vector<AudioCodec>& recv_codecs() const = 0;
77 virtual RtpCapabilities GetCapabilities() const = 0;
78
79 // Starts AEC dump using existing file, a maximum file size in bytes can be
80 // specified. Logging is stopped just before the size limit is exceeded.
81 // If max_size_bytes is set to a value <= 0, no limit will be used.
82 virtual bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) = 0;
83
84 // Stops recording AEC dump.
85 virtual void StopAecDump() = 0;
86};
87
88class VideoEngineInterface {
89 public:
90 VideoEngineInterface() = default;
91 virtual ~VideoEngineInterface() = default;
92 RTC_DISALLOW_COPY_AND_ASSIGN(VideoEngineInterface);
93
94 // Creates a video media channel, paired with the specified voice channel.
95 // Returns NULL on failure.
96 virtual VideoMediaChannel* CreateMediaChannel(
97 webrtc::Call* call,
98 const MediaConfig& config,
99 const VideoOptions& options,
100 const webrtc::CryptoOptions& crypto_options) = 0;
101
102 virtual std::vector<VideoCodec> codecs() const = 0;
103 virtual RtpCapabilities GetCapabilities() const = 0;
104};
105
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106// MediaEngineInterface is an abstraction of a media engine which can be
107// subclassed to support different media componentry backends.
108// It supports voice and video operations in the same class to facilitate
109// proper synchronization between both media types.
110class MediaEngineInterface {
111 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112 virtual ~MediaEngineInterface() {}
113
114 // Initialization
115 // Starts the engine.
solenbergff976312016-03-30 23:28:51 -0700116 virtual bool Init() = 0;
Sebastian Jansson6eb8a162018-11-16 11:29:55 +0100117 virtual VoiceEngineInterface& voice() = 0;
118 virtual VideoEngineInterface& video() = 0;
119 virtual const VoiceEngineInterface& voice() const = 0;
120 virtual const VideoEngineInterface& video() const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121};
122
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123// CompositeMediaEngine constructs a MediaEngine from separate
124// voice and video engine classes.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125class CompositeMediaEngine : public MediaEngineInterface {
126 public:
Sebastian Janssonfa0aa392018-11-16 09:54:32 +0100127 CompositeMediaEngine(std::unique_ptr<VoiceEngineInterface> audio_engine,
128 std::unique_ptr<VideoEngineInterface> video_engine);
129 ~CompositeMediaEngine() override;
130 bool Init() override;
magjed2475ae22017-09-12 04:42:15 -0700131
Sebastian Jansson6eb8a162018-11-16 11:29:55 +0100132 VoiceEngineInterface& voice() override;
133 VideoEngineInterface& video() override;
134 const VoiceEngineInterface& voice() const override;
135 const VideoEngineInterface& video() const override;
magjed2475ae22017-09-12 04:42:15 -0700136
137 private:
Sebastian Janssonfa0aa392018-11-16 09:54:32 +0100138 std::unique_ptr<VoiceEngineInterface> voice_engine_;
139 std::unique_ptr<VideoEngineInterface> video_engine_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000140};
141
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800142enum DataChannelType {
143 DCT_NONE = 0,
144 DCT_RTP = 1,
145 DCT_SCTP = 2,
146 DCT_MEDIA_TRANSPORT = 3
147};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000148
149class DataEngineInterface {
150 public:
151 virtual ~DataEngineInterface() {}
deadbeef953c2ce2017-01-09 14:53:41 -0800152 virtual DataMediaChannel* CreateChannel(const MediaConfig& config) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153 virtual const std::vector<DataCodec>& data_codecs() = 0;
154};
155
skvladdc1c62c2016-03-16 19:07:43 -0700156webrtc::RtpParameters CreateRtpParametersWithOneEncoding();
Zach Stein3ca452b2018-01-18 10:01:24 -0800157webrtc::RtpParameters CreateRtpParametersWithEncodings(StreamParams sp);
skvladdc1c62c2016-03-16 19:07:43 -0700158
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159} // namespace cricket
160
Steve Anton10542f22019-01-11 09:11:00 -0800161#endif // MEDIA_BASE_MEDIA_ENGINE_H_