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