media_engine.h 6.3 KB

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