You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
6.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 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 PC_CHANNEL_MANAGER_H_
  11. #define PC_CHANNEL_MANAGER_H_
  12. #include <stdint.h>
  13. #include <memory>
  14. #include <string>
  15. #include <vector>
  16. #include "api/audio_options.h"
  17. #include "api/crypto/crypto_options.h"
  18. #include "api/transport/media/media_transport_config.h"
  19. #include "call/call.h"
  20. #include "media/base/codec.h"
  21. #include "media/base/media_channel.h"
  22. #include "media/base/media_config.h"
  23. #include "media/base/media_engine.h"
  24. #include "pc/channel.h"
  25. #include "pc/rtp_transport_internal.h"
  26. #include "pc/session_description.h"
  27. #include "rtc_base/system/file_wrapper.h"
  28. #include "rtc_base/thread.h"
  29. namespace cricket {
  30. // ChannelManager allows the MediaEngine to run on a separate thread, and takes
  31. // care of marshalling calls between threads. It also creates and keeps track of
  32. // voice and video channels; by doing so, it can temporarily pause all the
  33. // channels when a new audio or video device is chosen. The voice and video
  34. // channels are stored in separate vectors, to easily allow operations on just
  35. // voice or just video channels.
  36. // ChannelManager also allows the application to discover what devices it has
  37. // using device manager.
  38. class ChannelManager final {
  39. public:
  40. // Construct a ChannelManager with the specified media engine and data engine.
  41. ChannelManager(std::unique_ptr<MediaEngineInterface> media_engine,
  42. std::unique_ptr<DataEngineInterface> data_engine,
  43. rtc::Thread* worker_thread,
  44. rtc::Thread* network_thread);
  45. ~ChannelManager();
  46. // Accessors for the worker thread, allowing it to be set after construction,
  47. // but before Init. set_worker_thread will return false if called after Init.
  48. rtc::Thread* worker_thread() const { return worker_thread_; }
  49. bool set_worker_thread(rtc::Thread* thread) {
  50. if (initialized_) {
  51. return false;
  52. }
  53. worker_thread_ = thread;
  54. return true;
  55. }
  56. rtc::Thread* network_thread() const { return network_thread_; }
  57. bool set_network_thread(rtc::Thread* thread) {
  58. if (initialized_) {
  59. return false;
  60. }
  61. network_thread_ = thread;
  62. return true;
  63. }
  64. MediaEngineInterface* media_engine() { return media_engine_.get(); }
  65. // Retrieves the list of supported audio & video codec types.
  66. // Can be called before starting the media engine.
  67. void GetSupportedAudioSendCodecs(std::vector<AudioCodec>* codecs) const;
  68. void GetSupportedAudioReceiveCodecs(std::vector<AudioCodec>* codecs) const;
  69. void GetSupportedAudioRtpHeaderExtensions(RtpHeaderExtensions* ext) const;
  70. void GetSupportedVideoCodecs(std::vector<VideoCodec>* codecs) const;
  71. void GetSupportedVideoRtpHeaderExtensions(RtpHeaderExtensions* ext) const;
  72. void GetSupportedDataCodecs(std::vector<DataCodec>* codecs) const;
  73. // Indicates whether the media engine is started.
  74. bool initialized() const { return initialized_; }
  75. // Starts up the media engine.
  76. bool Init();
  77. // Shuts down the media engine.
  78. void Terminate();
  79. // The operations below all occur on the worker thread.
  80. // ChannelManager retains ownership of the created channels, so clients should
  81. // call the appropriate Destroy*Channel method when done.
  82. // Creates a voice channel, to be associated with the specified session.
  83. VoiceChannel* CreateVoiceChannel(
  84. webrtc::Call* call,
  85. const cricket::MediaConfig& media_config,
  86. webrtc::RtpTransportInternal* rtp_transport,
  87. const webrtc::MediaTransportConfig& media_transport_config,
  88. rtc::Thread* signaling_thread,
  89. const std::string& content_name,
  90. bool srtp_required,
  91. const webrtc::CryptoOptions& crypto_options,
  92. rtc::UniqueRandomIdGenerator* ssrc_generator,
  93. const AudioOptions& options);
  94. // Destroys a voice channel created by CreateVoiceChannel.
  95. void DestroyVoiceChannel(VoiceChannel* voice_channel);
  96. // Creates a video channel, synced with the specified voice channel, and
  97. // associated with the specified session.
  98. // Version of the above that takes PacketTransportInternal.
  99. VideoChannel* CreateVideoChannel(
  100. webrtc::Call* call,
  101. const cricket::MediaConfig& media_config,
  102. webrtc::RtpTransportInternal* rtp_transport,
  103. const webrtc::MediaTransportConfig& media_transport_config,
  104. rtc::Thread* signaling_thread,
  105. const std::string& content_name,
  106. bool srtp_required,
  107. const webrtc::CryptoOptions& crypto_options,
  108. rtc::UniqueRandomIdGenerator* ssrc_generator,
  109. const VideoOptions& options,
  110. webrtc::VideoBitrateAllocatorFactory* video_bitrate_allocator_factory);
  111. // Destroys a video channel created by CreateVideoChannel.
  112. void DestroyVideoChannel(VideoChannel* video_channel);
  113. RtpDataChannel* CreateRtpDataChannel(
  114. const cricket::MediaConfig& media_config,
  115. webrtc::RtpTransportInternal* rtp_transport,
  116. rtc::Thread* signaling_thread,
  117. const std::string& content_name,
  118. bool srtp_required,
  119. const webrtc::CryptoOptions& crypto_options,
  120. rtc::UniqueRandomIdGenerator* ssrc_generator);
  121. // Destroys a data channel created by CreateRtpDataChannel.
  122. void DestroyRtpDataChannel(RtpDataChannel* data_channel);
  123. // Indicates whether any channels exist.
  124. bool has_channels() const {
  125. return (!voice_channels_.empty() || !video_channels_.empty() ||
  126. !data_channels_.empty());
  127. }
  128. // RTX will be enabled/disabled in engines that support it. The supporting
  129. // engines will start offering an RTX codec. Must be called before Init().
  130. bool SetVideoRtxEnabled(bool enable);
  131. // Starts/stops the local microphone and enables polling of the input level.
  132. bool capturing() const { return capturing_; }
  133. // The operations below occur on the main thread.
  134. // Starts AEC dump using existing file, with a specified maximum file size in
  135. // bytes. When the limit is reached, logging will stop and the file will be
  136. // closed. If max_size_bytes is set to <= 0, no limit will be used.
  137. bool StartAecDump(webrtc::FileWrapper file, int64_t max_size_bytes);
  138. // Stops recording AEC dump.
  139. void StopAecDump();
  140. private:
  141. std::unique_ptr<MediaEngineInterface> media_engine_; // Nullable.
  142. std::unique_ptr<DataEngineInterface> data_engine_; // Non-null.
  143. bool initialized_ = false;
  144. rtc::Thread* main_thread_;
  145. rtc::Thread* worker_thread_;
  146. rtc::Thread* network_thread_;
  147. // Vector contents are non-null.
  148. std::vector<std::unique_ptr<VoiceChannel>> voice_channels_;
  149. std::vector<std::unique_ptr<VideoChannel>> video_channels_;
  150. std::vector<std::unique_ptr<RtpDataChannel>> data_channels_;
  151. bool enable_rtx_ = false;
  152. bool capturing_ = false;
  153. };
  154. } // namespace cricket
  155. #endif // PC_CHANNEL_MANAGER_H_