blob: 173df50e343cc1afa063467fd233bcdfa0b8b379 [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
Sebastian Janssonfa0aa392018-11-16 09:54:32 +010014#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015#include <string>
16#include <vector>
17
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "api/audio_codecs/audio_decoder_factory.h"
19#include "api/audio_codecs/audio_encoder_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "api/crypto/crypto_options.h"
21#include "api/rtp_parameters.h"
Jonas Orelanda3aa9bd2019-04-17 07:38:40 +020022#include "api/video/video_bitrate_allocator_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "call/audio_state.h"
24#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080025#include "media/base/media_channel.h"
26#include "media/base/video_common.h"
Niels Möllere8e4dc42019-06-11 14:04:16 +020027#include "rtc_base/system/file_wrapper.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028
Fredrik Solenberg709ed672015-09-15 12:26:33 +020029namespace webrtc {
solenbergff976312016-03-30 23:28:51 -070030class AudioDeviceModule;
gyzhou95aa9642016-12-13 14:06:26 -080031class AudioMixer;
peaha9cc40b2017-06-29 08:32:09 -070032class AudioProcessing;
Fredrik Solenberg709ed672015-09-15 12:26:33 +020033class Call;
Yves Gerey665174f2018-06-19 15:03:05 +020034} // namespace webrtc
Fredrik Solenberg709ed672015-09-15 12:26:33 +020035
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036namespace cricket {
37
Florent Castellic1a0bcb2019-01-29 14:26:48 +010038webrtc::RTCError CheckRtpParametersValues(
39 const webrtc::RtpParameters& new_parameters);
40
41webrtc::RTCError CheckRtpParametersInvalidModificationAndValues(
Florent Castelli892acf02018-10-01 22:47:20 +020042 const webrtc::RtpParameters& old_parameters,
43 const webrtc::RtpParameters& new_parameters);
44
Stefan Holmer9d69c3f2015-12-07 10:45:43 +010045struct RtpCapabilities {
Paulina Hensman11b34f42018-04-09 14:24:52 +020046 RtpCapabilities();
47 ~RtpCapabilities();
isheriff6f8d6862016-05-26 11:24:55 -070048 std::vector<webrtc::RtpExtension> header_extensions;
Stefan Holmer9d69c3f2015-12-07 10:45:43 +010049};
50
Sebastian Jansson84848f22018-11-16 10:40:36 +010051class VoiceEngineInterface {
52 public:
53 VoiceEngineInterface() = default;
54 virtual ~VoiceEngineInterface() = default;
55 RTC_DISALLOW_COPY_AND_ASSIGN(VoiceEngineInterface);
56
57 // Initialization
58 // Starts the engine.
59 virtual void Init() = 0;
60
61 // TODO(solenberg): Remove once VoE API refactoring is done.
62 virtual rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const = 0;
63
64 // MediaChannel creation
65 // Creates a voice media channel. Returns NULL on failure.
66 virtual VoiceMediaChannel* CreateMediaChannel(
67 webrtc::Call* call,
68 const MediaConfig& config,
69 const AudioOptions& options,
70 const webrtc::CryptoOptions& crypto_options) = 0;
71
72 virtual const std::vector<AudioCodec>& send_codecs() const = 0;
73 virtual const std::vector<AudioCodec>& recv_codecs() const = 0;
74 virtual RtpCapabilities GetCapabilities() const = 0;
75
76 // Starts AEC dump using existing file, a maximum file size in bytes can be
77 // specified. Logging is stopped just before the size limit is exceeded.
78 // If max_size_bytes is set to a value <= 0, no limit will be used.
Niels Möllere8e4dc42019-06-11 14:04:16 +020079 virtual bool StartAecDump(webrtc::FileWrapper file,
80 int64_t max_size_bytes) = 0;
Sebastian Jansson84848f22018-11-16 10:40:36 +010081
82 // Stops recording AEC dump.
83 virtual void StopAecDump() = 0;
84};
85
86class VideoEngineInterface {
87 public:
88 VideoEngineInterface() = default;
89 virtual ~VideoEngineInterface() = default;
90 RTC_DISALLOW_COPY_AND_ASSIGN(VideoEngineInterface);
91
92 // Creates a video media channel, paired with the specified voice channel.
93 // Returns NULL on failure.
94 virtual VideoMediaChannel* CreateMediaChannel(
95 webrtc::Call* call,
96 const MediaConfig& config,
97 const VideoOptions& options,
Jonas Orelanda3aa9bd2019-04-17 07:38:40 +020098 const webrtc::CryptoOptions& crypto_options,
99 webrtc::VideoBitrateAllocatorFactory*
100 video_bitrate_allocator_factory) = 0;
Sebastian Jansson84848f22018-11-16 10:40:36 +0100101
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,
Bjorn A Mellemb689af42019-08-21 10:44:59 -0700146
147 // Data channel transport over media transport.
148 DCT_MEDIA_TRANSPORT = 3,
149
150 // Data channel transport over datagram transport (with no fallback). This is
151 // the same behavior as data channel transport over media transport, and is
152 // usable without DTLS.
153 DCT_DATA_CHANNEL_TRANSPORT = 4,
154
155 // Data channel transport over datagram transport (with SCTP negotiation
156 // semantics and a fallback to SCTP). Only usable with DTLS.
157 DCT_DATA_CHANNEL_TRANSPORT_SCTP = 5,
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800158};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159
160class DataEngineInterface {
161 public:
162 virtual ~DataEngineInterface() {}
deadbeef953c2ce2017-01-09 14:53:41 -0800163 virtual DataMediaChannel* CreateChannel(const MediaConfig& config) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164 virtual const std::vector<DataCodec>& data_codecs() = 0;
165};
166
skvladdc1c62c2016-03-16 19:07:43 -0700167webrtc::RtpParameters CreateRtpParametersWithOneEncoding();
Zach Stein3ca452b2018-01-18 10:01:24 -0800168webrtc::RtpParameters CreateRtpParametersWithEncodings(StreamParams sp);
skvladdc1c62c2016-03-16 19:07:43 -0700169
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170} // namespace cricket
171
Steve Anton10542f22019-01-11 09:11:00 -0800172#endif // MEDIA_BASE_MEDIA_ENGINE_H_