1 /* 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. 3 * 4 * 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. 9 */ 10 11 #ifndef MEDIA_BASE_MEDIA_ENGINE_H_ 12 #define MEDIA_BASE_MEDIA_ENGINE_H_ 13 14 #include <memory> 15 #include <string> 16 #include <vector> 17 18 #include "api/audio_codecs/audio_decoder_factory.h" 19 #include "api/audio_codecs/audio_encoder_factory.h" 20 #include "api/crypto/crypto_options.h" 21 #include "api/rtp_parameters.h" 22 #include "api/video/video_bitrate_allocator_factory.h" 23 #include "call/audio_state.h" 24 #include "media/base/codec.h" 25 #include "media/base/media_channel.h" 26 #include "media/base/video_common.h" 27 #include "rtc_base/system/file_wrapper.h" 28 29 namespace webrtc { 30 class AudioDeviceModule; 31 class AudioMixer; 32 class AudioProcessing; 33 class Call; 34 } // namespace webrtc 35 36 namespace cricket { 37 38 webrtc::RTCError CheckRtpParametersValues( 39 const webrtc::RtpParameters& new_parameters); 40 41 webrtc::RTCError CheckRtpParametersInvalidModificationAndValues( 42 const webrtc::RtpParameters& old_parameters, 43 const webrtc::RtpParameters& new_parameters); 44 45 struct RtpCapabilities { 46 RtpCapabilities(); 47 ~RtpCapabilities(); 48 std::vector<webrtc::RtpExtension> header_extensions; 49 }; 50 51 class RtpHeaderExtensionQueryInterface { 52 public: 53 virtual ~RtpHeaderExtensionQueryInterface() = default; 54 55 // Returns a vector of RtpHeaderExtensionCapability, whose direction is 56 // kStopped if the extension is stopped (not used) by default. 57 virtual std::vector<webrtc::RtpHeaderExtensionCapability> 58 GetRtpHeaderExtensions() const = 0; 59 }; 60 61 class VoiceEngineInterface : public RtpHeaderExtensionQueryInterface { 62 public: 63 VoiceEngineInterface() = default; 64 virtual ~VoiceEngineInterface() = default; 65 RTC_DISALLOW_COPY_AND_ASSIGN(VoiceEngineInterface); 66 67 // Initialization 68 // Starts the engine. 69 virtual void Init() = 0; 70 71 // TODO(solenberg): Remove once VoE API refactoring is done. 72 virtual rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const = 0; 73 74 // MediaChannel creation 75 // Creates a voice media channel. Returns NULL on failure. 76 virtual VoiceMediaChannel* CreateMediaChannel( 77 webrtc::Call* call, 78 const MediaConfig& config, 79 const AudioOptions& options, 80 const webrtc::CryptoOptions& crypto_options) = 0; 81 82 virtual const std::vector<AudioCodec>& send_codecs() const = 0; 83 virtual const std::vector<AudioCodec>& recv_codecs() const = 0; 84 85 // Starts AEC dump using existing file, a maximum file size in bytes can be 86 // specified. Logging is stopped just before the size limit is exceeded. 87 // If max_size_bytes is set to a value <= 0, no limit will be used. 88 virtual bool StartAecDump(webrtc::FileWrapper file, 89 int64_t max_size_bytes) = 0; 90 91 // Stops recording AEC dump. 92 virtual void StopAecDump() = 0; 93 }; 94 95 class VideoEngineInterface : public RtpHeaderExtensionQueryInterface { 96 public: 97 VideoEngineInterface() = default; 98 virtual ~VideoEngineInterface() = default; 99 RTC_DISALLOW_COPY_AND_ASSIGN(VideoEngineInterface); 100 101 // Creates a video media channel, paired with the specified voice channel. 102 // Returns NULL on failure. 103 virtual VideoMediaChannel* CreateMediaChannel( 104 webrtc::Call* call, 105 const MediaConfig& config, 106 const VideoOptions& options, 107 const webrtc::CryptoOptions& crypto_options, 108 webrtc::VideoBitrateAllocatorFactory* 109 video_bitrate_allocator_factory) = 0; 110 111 virtual std::vector<VideoCodec> send_codecs() const = 0; 112 virtual std::vector<VideoCodec> recv_codecs() const = 0; 113 }; 114 115 // MediaEngineInterface is an abstraction of a media engine which can be 116 // subclassed to support different media componentry backends. 117 // It supports voice and video operations in the same class to facilitate 118 // proper synchronization between both media types. 119 class MediaEngineInterface { 120 public: ~MediaEngineInterface()121 virtual ~MediaEngineInterface() {} 122 123 // Initialization 124 // Starts the engine. 125 virtual bool Init() = 0; 126 virtual VoiceEngineInterface& voice() = 0; 127 virtual VideoEngineInterface& video() = 0; 128 virtual const VoiceEngineInterface& voice() const = 0; 129 virtual const VideoEngineInterface& video() const = 0; 130 }; 131 132 // CompositeMediaEngine constructs a MediaEngine from separate 133 // voice and video engine classes. 134 class CompositeMediaEngine : public MediaEngineInterface { 135 public: 136 CompositeMediaEngine(std::unique_ptr<VoiceEngineInterface> audio_engine, 137 std::unique_ptr<VideoEngineInterface> video_engine); 138 ~CompositeMediaEngine() override; 139 bool Init() override; 140 141 VoiceEngineInterface& voice() override; 142 VideoEngineInterface& video() override; 143 const VoiceEngineInterface& voice() const override; 144 const VideoEngineInterface& video() const override; 145 146 private: 147 std::unique_ptr<VoiceEngineInterface> voice_engine_; 148 std::unique_ptr<VideoEngineInterface> video_engine_; 149 }; 150 151 enum DataChannelType { 152 DCT_NONE = 0, 153 DCT_RTP = 1, 154 DCT_SCTP = 2, 155 }; 156 157 class DataEngineInterface { 158 public: ~DataEngineInterface()159 virtual ~DataEngineInterface() {} 160 virtual DataMediaChannel* CreateChannel(const MediaConfig& config) = 0; 161 virtual const std::vector<DataCodec>& data_codecs() = 0; 162 }; 163 164 webrtc::RtpParameters CreateRtpParametersWithOneEncoding(); 165 webrtc::RtpParameters CreateRtpParametersWithEncodings(StreamParams sp); 166 167 // Returns a vector of RTP extensions as visible from RtpSender/Receiver 168 // GetCapabilities(). The returned vector only shows what will definitely be 169 // offered by default, i.e. the list of extensions returned from 170 // GetRtpHeaderExtensions() that are not kStopped. 171 std::vector<webrtc::RtpExtension> GetDefaultEnabledRtpHeaderExtensions( 172 const RtpHeaderExtensionQueryInterface& query_interface); 173 174 } // namespace cricket 175 176 #endif // MEDIA_BASE_MEDIA_ENGINE_H_ 177