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