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. |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 83 | VoiceChannel* CreateVoiceChannel( |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 84 | webrtc::Call* call, |
| 85 | const cricket::MediaConfig& media_config, |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 86 | DtlsTransportInternal* rtp_transport, |
| 87 | DtlsTransportInternal* rtcp_transport, |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 88 | rtc::Thread* signaling_thread, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 89 | const std::string& content_name, |
deadbeef | 7af91dd | 2016-12-13 11:29:11 -0800 | [diff] [blame] | 90 | bool srtp_required, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 91 | const AudioOptions& options); |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 92 | // Version of the above that takes PacketTransportInternal. |
| 93 | VoiceChannel* CreateVoiceChannel( |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 94 | webrtc::Call* call, |
| 95 | const cricket::MediaConfig& media_config, |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 96 | rtc::PacketTransportInternal* rtp_transport, |
| 97 | rtc::PacketTransportInternal* rtcp_transport, |
| 98 | rtc::Thread* signaling_thread, |
| 99 | const std::string& content_name, |
| 100 | bool srtp_required, |
| 101 | const AudioOptions& options); |
Steve Anton | 774115c | 2017-08-30 10:48:46 -0700 | [diff] [blame] | 102 | // Destroys a voice channel created by CreateVoiceChannel. |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 103 | void DestroyVoiceChannel(VoiceChannel* voice_channel); |
Steve Anton | 774115c | 2017-08-30 10:48:46 -0700 | [diff] [blame] | 104 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 105 | // Creates a video channel, synced with the specified voice channel, and |
| 106 | // associated with the specified session. |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 107 | VideoChannel* CreateVideoChannel( |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 108 | webrtc::Call* call, |
| 109 | const cricket::MediaConfig& media_config, |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 110 | DtlsTransportInternal* rtp_transport, |
| 111 | DtlsTransportInternal* rtcp_transport, |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 112 | rtc::Thread* signaling_thread, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 113 | const std::string& content_name, |
deadbeef | 7af91dd | 2016-12-13 11:29:11 -0800 | [diff] [blame] | 114 | bool srtp_required, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 115 | const VideoOptions& options); |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 116 | // Version of the above that takes PacketTransportInternal. |
| 117 | VideoChannel* CreateVideoChannel( |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 118 | webrtc::Call* call, |
| 119 | const cricket::MediaConfig& media_config, |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 120 | rtc::PacketTransportInternal* rtp_transport, |
| 121 | rtc::PacketTransportInternal* rtcp_transport, |
| 122 | rtc::Thread* signaling_thread, |
| 123 | const std::string& content_name, |
| 124 | bool srtp_required, |
| 125 | const VideoOptions& options); |
Steve Anton | 774115c | 2017-08-30 10:48:46 -0700 | [diff] [blame] | 126 | // Destroys a video channel created by CreateVideoChannel. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 127 | void DestroyVideoChannel(VideoChannel* video_channel); |
Steve Anton | 774115c | 2017-08-30 10:48:46 -0700 | [diff] [blame] | 128 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 129 | RtpDataChannel* CreateRtpDataChannel( |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 130 | const cricket::MediaConfig& media_config, |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 131 | DtlsTransportInternal* rtp_transport, |
| 132 | DtlsTransportInternal* rtcp_transport, |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 133 | rtc::Thread* signaling_thread, |
zhihuang | ebbe4f2 | 2016-12-06 10:45:42 -0800 | [diff] [blame] | 134 | const std::string& content_name, |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 135 | bool srtp_required); |
Steve Anton | 774115c | 2017-08-30 10:48:46 -0700 | [diff] [blame] | 136 | // Destroys a data channel created by CreateRtpDataChannel. |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 137 | void DestroyRtpDataChannel(RtpDataChannel* data_channel); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 138 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 139 | // Indicates whether any channels exist. |
| 140 | bool has_channels() const { |
Steve Anton | c9e1560 | 2017-11-06 15:40:09 -0800 | [diff] [blame] | 141 | return (!voice_channels_.empty() || !video_channels_.empty() || |
| 142 | !data_channels_.empty()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 143 | } |
| 144 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 145 | // RTX will be enabled/disabled in engines that support it. The supporting |
| 146 | // engines will start offering an RTX codec. Must be called before Init(). |
| 147 | bool SetVideoRtxEnabled(bool enable); |
| 148 | |
| 149 | // 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] | 150 | bool capturing() const { return capturing_; } |
| 151 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 152 | // The operations below occur on the main thread. |
| 153 | |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 154 | // Starts AEC dump using existing file, with a specified maximum file size in |
| 155 | // bytes. When the limit is reached, logging will stop and the file will be |
| 156 | // closed. If max_size_bytes is set to <= 0, no limit will be used. |
| 157 | bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes); |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 158 | |
ivoc | 797ef12 | 2015-10-22 03:25:41 -0700 | [diff] [blame] | 159 | // Stops recording AEC dump. |
| 160 | void StopAecDump(); |
| 161 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 162 | private: |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 163 | VoiceChannel* CreateVoiceChannel_w( |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 164 | webrtc::Call* call, |
| 165 | const cricket::MediaConfig& media_config, |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 166 | DtlsTransportInternal* rtp_dtls_transport, |
| 167 | DtlsTransportInternal* rtcp_dtls_transport, |
| 168 | rtc::PacketTransportInternal* rtp_packet_transport, |
| 169 | rtc::PacketTransportInternal* rtcp_packet_transport, |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 170 | rtc::Thread* signaling_thread, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 171 | const std::string& content_name, |
deadbeef | 7af91dd | 2016-12-13 11:29:11 -0800 | [diff] [blame] | 172 | bool srtp_required, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 173 | const AudioOptions& options); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 174 | VideoChannel* CreateVideoChannel_w( |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 175 | webrtc::Call* call, |
| 176 | const cricket::MediaConfig& media_config, |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 177 | DtlsTransportInternal* rtp_dtls_transport, |
| 178 | DtlsTransportInternal* rtcp_dtls_transport, |
| 179 | rtc::PacketTransportInternal* rtp_packet_transport, |
| 180 | rtc::PacketTransportInternal* rtcp_packet_transport, |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 181 | rtc::Thread* signaling_thread, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 182 | const std::string& content_name, |
deadbeef | 7af91dd | 2016-12-13 11:29:11 -0800 | [diff] [blame] | 183 | bool srtp_required, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 184 | const VideoOptions& options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 185 | |
Steve Anton | c9e1560 | 2017-11-06 15:40:09 -0800 | [diff] [blame] | 186 | std::unique_ptr<MediaEngineInterface> media_engine_; // Nullable. |
| 187 | std::unique_ptr<DataEngineInterface> data_engine_; // Non-null. |
| 188 | bool initialized_ = false; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 189 | rtc::Thread* main_thread_; |
| 190 | rtc::Thread* worker_thread_; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 191 | rtc::Thread* network_thread_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 192 | |
Steve Anton | c9e1560 | 2017-11-06 15:40:09 -0800 | [diff] [blame] | 193 | // Vector contents are non-null. |
Steve Anton | 774115c | 2017-08-30 10:48:46 -0700 | [diff] [blame] | 194 | std::vector<std::unique_ptr<VoiceChannel>> voice_channels_; |
| 195 | std::vector<std::unique_ptr<VideoChannel>> video_channels_; |
| 196 | std::vector<std::unique_ptr<RtpDataChannel>> data_channels_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 197 | |
Steve Anton | c9e1560 | 2017-11-06 15:40:09 -0800 | [diff] [blame] | 198 | bool enable_rtx_ = false; |
| 199 | bool capturing_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 200 | }; |
| 201 | |
| 202 | } // namespace cricket |
| 203 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 204 | #endif // PC_CHANNELMANAGER_H_ |