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