henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 08:05:01 | [diff] [blame] | 2 | * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 08:05:01 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #ifndef PC_CHANNEL_MANAGER_H_ |
| 12 | #define PC_CHANNEL_MANAGER_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 13 | |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 14 | #include <stdint.h> |
Anton Sukhanov | 4f08faa | 2019-05-21 18:12:57 | [diff] [blame] | 15 | |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 16 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 17 | #include <string> |
| 18 | #include <vector> |
| 19 | |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 20 | #include "api/audio_options.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 21 | #include "api/crypto/crypto_options.h" |
Anton Sukhanov | 4f08faa | 2019-05-21 18:12:57 | [diff] [blame] | 22 | #include "api/media_transport_config.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 23 | #include "call/call.h" |
| 24 | #include "media/base/codec.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 25 | #include "media/base/media_channel.h" |
| 26 | #include "media/base/media_config.h" |
| 27 | #include "media/base/media_engine.h" |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 28 | #include "pc/channel.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 29 | #include "pc/rtp_transport_internal.h" |
| 30 | #include "pc/session_description.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 31 | #include "rtc_base/platform_file.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 32 | #include "rtc_base/thread.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 33 | |
| 34 | namespace cricket { |
| 35 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 36 | // ChannelManager allows the MediaEngine to run on a separate thread, and takes |
| 37 | // care of marshalling calls between threads. It also creates and keeps track of |
| 38 | // voice and video channels; by doing so, it can temporarily pause all the |
| 39 | // channels when a new audio or video device is chosen. The voice and video |
| 40 | // channels are stored in separate vectors, to easily allow operations on just |
| 41 | // voice or just video channels. |
| 42 | // ChannelManager also allows the application to discover what devices it has |
| 43 | // using device manager. |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 44 | class ChannelManager final { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 45 | public: |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 46 | // Construct a ChannelManager with the specified media engine and data engine. |
| 47 | ChannelManager(std::unique_ptr<MediaEngineInterface> media_engine, |
| 48 | std::unique_ptr<DataEngineInterface> data_engine, |
| 49 | rtc::Thread* worker_thread, |
| 50 | rtc::Thread* network_thread); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 51 | ~ChannelManager(); |
| 52 | |
| 53 | // Accessors for the worker thread, allowing it to be set after construction, |
| 54 | // but before Init. set_worker_thread will return false if called after Init. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 55 | rtc::Thread* worker_thread() const { return worker_thread_; } |
| 56 | bool set_worker_thread(rtc::Thread* thread) { |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 57 | if (initialized_) { |
| 58 | return false; |
| 59 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 60 | worker_thread_ = thread; |
| 61 | return true; |
| 62 | } |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 63 | rtc::Thread* network_thread() const { return network_thread_; } |
| 64 | bool set_network_thread(rtc::Thread* thread) { |
| 65 | if (initialized_) { |
| 66 | return false; |
| 67 | } |
| 68 | network_thread_ = thread; |
| 69 | return true; |
| 70 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 71 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 10:26:33 | [diff] [blame] | 72 | MediaEngineInterface* media_engine() { return media_engine_.get(); } |
| 73 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 74 | // Retrieves the list of supported audio & video codec types. |
| 75 | // Can be called before starting the media engine. |
ossu | dedfd28 | 2016-06-14 14:12:39 | [diff] [blame] | 76 | void GetSupportedAudioSendCodecs(std::vector<AudioCodec>* codecs) const; |
| 77 | void GetSupportedAudioReceiveCodecs(std::vector<AudioCodec>* codecs) const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 78 | void GetSupportedAudioRtpHeaderExtensions(RtpHeaderExtensions* ext) const; |
magjed | 3cf8ece | 2016-11-10 11:36:53 | [diff] [blame] | 79 | void GetSupportedVideoCodecs(std::vector<VideoCodec>* codecs) const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 80 | void GetSupportedVideoRtpHeaderExtensions(RtpHeaderExtensions* ext) const; |
| 81 | void GetSupportedDataCodecs(std::vector<DataCodec>* codecs) const; |
| 82 | |
| 83 | // Indicates whether the media engine is started. |
| 84 | bool initialized() const { return initialized_; } |
| 85 | // Starts up the media engine. |
| 86 | bool Init(); |
| 87 | // Shuts down the media engine. |
| 88 | void Terminate(); |
| 89 | |
| 90 | // The operations below all occur on the worker thread. |
Steve Anton | 774115c | 2017-08-30 17:48:46 | [diff] [blame] | 91 | // ChannelManager retains ownership of the created channels, so clients should |
| 92 | // call the appropriate Destroy*Channel method when done. |
| 93 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 94 | // Creates a voice channel, to be associated with the specified session. |
Anton Sukhanov | 98a462c | 2018-10-17 20:15:42 | [diff] [blame] | 95 | VoiceChannel* CreateVoiceChannel( |
| 96 | webrtc::Call* call, |
| 97 | const cricket::MediaConfig& media_config, |
| 98 | webrtc::RtpTransportInternal* rtp_transport, |
Anton Sukhanov | 4f08faa | 2019-05-21 18:12:57 | [diff] [blame] | 99 | const webrtc::MediaTransportConfig& media_transport_config, |
Anton Sukhanov | 98a462c | 2018-10-17 20:15:42 | [diff] [blame] | 100 | rtc::Thread* signaling_thread, |
| 101 | const std::string& content_name, |
| 102 | bool srtp_required, |
| 103 | const webrtc::CryptoOptions& crypto_options, |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 104 | rtc::UniqueRandomIdGenerator* ssrc_generator, |
Anton Sukhanov | 98a462c | 2018-10-17 20:15:42 | [diff] [blame] | 105 | const AudioOptions& options); |
Steve Anton | 774115c | 2017-08-30 17:48:46 | [diff] [blame] | 106 | // Destroys a voice channel created by CreateVoiceChannel. |
Fredrik Solenberg | 709ed67 | 2015-09-15 10:26:33 | [diff] [blame] | 107 | void DestroyVoiceChannel(VoiceChannel* voice_channel); |
Steve Anton | 774115c | 2017-08-30 17:48:46 | [diff] [blame] | 108 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 109 | // Creates a video channel, synced with the specified voice channel, and |
| 110 | // associated with the specified session. |
deadbeef | e814a0d | 2017-02-26 02:15:09 | [diff] [blame] | 111 | // Version of the above that takes PacketTransportInternal. |
Niels Möller | 4687915 | 2019-01-07 14:54:47 | [diff] [blame] | 112 | VideoChannel* CreateVideoChannel( |
| 113 | webrtc::Call* call, |
| 114 | const cricket::MediaConfig& media_config, |
| 115 | webrtc::RtpTransportInternal* rtp_transport, |
Anton Sukhanov | 4f08faa | 2019-05-21 18:12:57 | [diff] [blame] | 116 | const webrtc::MediaTransportConfig& media_transport_config, |
Niels Möller | 4687915 | 2019-01-07 14:54:47 | [diff] [blame] | 117 | rtc::Thread* signaling_thread, |
| 118 | const std::string& content_name, |
| 119 | bool srtp_required, |
| 120 | const webrtc::CryptoOptions& crypto_options, |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 121 | rtc::UniqueRandomIdGenerator* ssrc_generator, |
Jonas Oreland | a3aa9bd | 2019-04-17 05:38:40 | [diff] [blame] | 122 | const VideoOptions& options, |
| 123 | webrtc::VideoBitrateAllocatorFactory* video_bitrate_allocator_factory); |
Steve Anton | 774115c | 2017-08-30 17:48:46 | [diff] [blame] | 124 | // Destroys a video channel created by CreateVideoChannel. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 125 | void DestroyVideoChannel(VideoChannel* video_channel); |
Steve Anton | 774115c | 2017-08-30 17:48:46 | [diff] [blame] | 126 | |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 127 | RtpDataChannel* CreateRtpDataChannel( |
| 128 | const cricket::MediaConfig& media_config, |
| 129 | webrtc::RtpTransportInternal* rtp_transport, |
| 130 | rtc::Thread* signaling_thread, |
| 131 | const std::string& content_name, |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 132 | bool srtp_required, |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 133 | const webrtc::CryptoOptions& crypto_options, |
| 134 | rtc::UniqueRandomIdGenerator* ssrc_generator); |
Steve Anton | 774115c | 2017-08-30 17:48:46 | [diff] [blame] | 135 | // Destroys a data channel created by CreateRtpDataChannel. |
deadbeef | 953c2ce | 2017-01-09 22:53:41 | [diff] [blame] | 136 | void DestroyRtpDataChannel(RtpDataChannel* data_channel); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 137 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 138 | // Indicates whether any channels exist. |
| 139 | bool has_channels() const { |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 140 | return (!voice_channels_.empty() || !video_channels_.empty() || |
| 141 | !data_channels_.empty()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 142 | } |
| 143 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 144 | // RTX will be enabled/disabled in engines that support it. The supporting |
| 145 | // engines will start offering an RTX codec. Must be called before Init(). |
| 146 | bool SetVideoRtxEnabled(bool enable); |
| 147 | |
| 148 | // Starts/stops the local microphone and enables polling of the input level. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 149 | bool capturing() const { return capturing_; } |
| 150 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 151 | // The operations below occur on the main thread. |
| 152 | |
ivoc | d66b44d | 2016-01-15 11:06:36 | [diff] [blame] | 153 | // Starts AEC dump using existing file, with a specified maximum file size in |
| 154 | // bytes. When the limit is reached, logging will stop and the file will be |
| 155 | // closed. If max_size_bytes is set to <= 0, no limit will be used. |
| 156 | bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes); |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 | [diff] [blame] | 157 | |
ivoc | 797ef12 | 2015-10-22 10:25:41 | [diff] [blame] | 158 | // Stops recording AEC dump. |
| 159 | void StopAecDump(); |
| 160 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 161 | private: |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 162 | std::unique_ptr<MediaEngineInterface> media_engine_; // Nullable. |
| 163 | std::unique_ptr<DataEngineInterface> data_engine_; // Non-null. |
| 164 | bool initialized_ = false; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 165 | rtc::Thread* main_thread_; |
| 166 | rtc::Thread* worker_thread_; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 167 | rtc::Thread* network_thread_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 168 | |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 169 | // Vector contents are non-null. |
Steve Anton | 774115c | 2017-08-30 17:48:46 | [diff] [blame] | 170 | std::vector<std::unique_ptr<VoiceChannel>> voice_channels_; |
| 171 | std::vector<std::unique_ptr<VideoChannel>> video_channels_; |
| 172 | std::vector<std::unique_ptr<RtpDataChannel>> data_channels_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 173 | |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 174 | bool enable_rtx_ = false; |
| 175 | bool capturing_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | } // namespace cricket |
| 179 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 180 | #endif // PC_CHANNEL_MANAGER_H_ |