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