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