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