blob: 01300d48ac370b7a95a6daa788a6f492c46c7a3c [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
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"
Benjamin Wrightbfb444c2018-10-15 10:20:24 -070024#include "api/crypto/cryptooptions.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#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
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 Castelli892acf02018-10-01 22:47:20 +020041webrtc::RTCError ValidateRtpParameters(
42 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.
79 virtual bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) = 0;
80
81 // Stops recording AEC dump.
82 virtual void StopAecDump() = 0;
83};
84
85class VideoEngineInterface {
86 public:
87 VideoEngineInterface() = default;
88 virtual ~VideoEngineInterface() = default;
89 RTC_DISALLOW_COPY_AND_ASSIGN(VideoEngineInterface);
90
91 // Creates a video media channel, paired with the specified voice channel.
92 // Returns NULL on failure.
93 virtual VideoMediaChannel* CreateMediaChannel(
94 webrtc::Call* call,
95 const MediaConfig& config,
96 const VideoOptions& options,
97 const webrtc::CryptoOptions& crypto_options) = 0;
98
99 virtual std::vector<VideoCodec> codecs() const = 0;
100 virtual RtpCapabilities GetCapabilities() const = 0;
101};
102
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103// MediaEngineInterface is an abstraction of a media engine which can be
104// subclassed to support different media componentry backends.
105// It supports voice and video operations in the same class to facilitate
106// proper synchronization between both media types.
107class MediaEngineInterface {
108 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109 virtual ~MediaEngineInterface() {}
110
111 // Initialization
112 // Starts the engine.
solenbergff976312016-03-30 23:28:51 -0700113 virtual bool Init() = 0;
Sebastian Jansson6eb8a162018-11-16 11:29:55 +0100114 virtual VoiceEngineInterface& voice() = 0;
115 virtual VideoEngineInterface& video() = 0;
116 virtual const VoiceEngineInterface& voice() const = 0;
117 virtual const VideoEngineInterface& video() const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118};
119
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120// CompositeMediaEngine constructs a MediaEngine from separate
121// voice and video engine classes.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000122class CompositeMediaEngine : public MediaEngineInterface {
123 public:
Sebastian Janssonfa0aa392018-11-16 09:54:32 +0100124 CompositeMediaEngine(std::unique_ptr<VoiceEngineInterface> audio_engine,
125 std::unique_ptr<VideoEngineInterface> video_engine);
126 ~CompositeMediaEngine() override;
127 bool Init() override;
magjed2475ae22017-09-12 04:42:15 -0700128
Sebastian Jansson6eb8a162018-11-16 11:29:55 +0100129 VoiceEngineInterface& voice() override;
130 VideoEngineInterface& video() override;
131 const VoiceEngineInterface& voice() const override;
132 const VideoEngineInterface& video() const override;
magjed2475ae22017-09-12 04:42:15 -0700133
134 private:
Sebastian Janssonfa0aa392018-11-16 09:54:32 +0100135 std::unique_ptr<VoiceEngineInterface> voice_engine_;
136 std::unique_ptr<VideoEngineInterface> video_engine_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000137};
138
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800139enum DataChannelType {
140 DCT_NONE = 0,
141 DCT_RTP = 1,
142 DCT_SCTP = 2,
143 DCT_MEDIA_TRANSPORT = 3
144};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000145
146class DataEngineInterface {
147 public:
148 virtual ~DataEngineInterface() {}
deadbeef953c2ce2017-01-09 14:53:41 -0800149 virtual DataMediaChannel* CreateChannel(const MediaConfig& config) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150 virtual const std::vector<DataCodec>& data_codecs() = 0;
151};
152
skvladdc1c62c2016-03-16 19:07:43 -0700153webrtc::RtpParameters CreateRtpParametersWithOneEncoding();
Zach Stein3ca452b2018-01-18 10:01:24 -0800154webrtc::RtpParameters CreateRtpParametersWithEncodings(StreamParams sp);
skvladdc1c62c2016-03-16 19:07:43 -0700155
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000156} // namespace cricket
157
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200158#endif // MEDIA_BASE_MEDIAENGINE_H_