media_engine.h 6.2 KB

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