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 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #ifndef PC_CHANNEL_MANAGER_H_ |
| 12 | #define PC_CHANNEL_MANAGER_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | #include <stdint.h> |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 15 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 16 | #include <string> |
| 17 | #include <vector> |
| 18 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 19 | #include "api/audio_options.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 20 | #include "api/crypto/crypto_options.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 21 | #include "api/media_transport_interface.h" |
| 22 | #include "call/call.h" |
| 23 | #include "media/base/codec.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 24 | #include "media/base/media_channel.h" |
| 25 | #include "media/base/media_config.h" |
| 26 | #include "media/base/media_engine.h" |
Steve Anton | c9e1560 | 2017-11-06 15:40:09 -0800 | [diff] [blame] | 27 | #include "pc/channel.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 28 | #include "pc/rtp_transport_internal.h" |
| 29 | #include "pc/session_description.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 30 | #include "rtc_base/platform_file.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 31 | #include "rtc_base/thread.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 32 | |
| 33 | namespace cricket { |
| 34 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 35 | // ChannelManager allows the MediaEngine to run on a separate thread, and takes |
| 36 | // care of marshalling calls between threads. It also creates and keeps track of |
| 37 | // voice and video channels; by doing so, it can temporarily pause all the |
| 38 | // channels when a new audio or video device is chosen. The voice and video |
| 39 | // channels are stored in separate vectors, to easily allow operations on just |
| 40 | // voice or just video channels. |
| 41 | // ChannelManager also allows the application to discover what devices it has |
| 42 | // using device manager. |
Steve Anton | c9e1560 | 2017-11-06 15:40:09 -0800 | [diff] [blame] | 43 | class ChannelManager final { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 44 | public: |
Steve Anton | c9e1560 | 2017-11-06 15:40:09 -0800 | [diff] [blame] | 45 | // Construct a ChannelManager with the specified media engine and data engine. |
| 46 | ChannelManager(std::unique_ptr<MediaEngineInterface> media_engine, |
| 47 | std::unique_ptr<DataEngineInterface> data_engine, |
| 48 | rtc::Thread* worker_thread, |
| 49 | rtc::Thread* network_thread); |
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. |
Steve Anton | 774115c | 2017-08-30 10:48:46 -0700 | [diff] [blame] | 90 | // ChannelManager retains ownership of the created channels, so clients should |
| 91 | // call the appropriate Destroy*Channel method when done. |
| 92 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 93 | // Creates a voice channel, to be associated with the specified session. |
Anton Sukhanov | 98a462c | 2018-10-17 13:15:42 -0700 | [diff] [blame] | 94 | VoiceChannel* CreateVoiceChannel( |
| 95 | webrtc::Call* call, |
| 96 | const cricket::MediaConfig& media_config, |
| 97 | webrtc::RtpTransportInternal* rtp_transport, |
| 98 | webrtc::MediaTransportInterface* media_transport, |
| 99 | rtc::Thread* signaling_thread, |
| 100 | const std::string& content_name, |
| 101 | bool srtp_required, |
| 102 | const webrtc::CryptoOptions& crypto_options, |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 103 | rtc::UniqueRandomIdGenerator* ssrc_generator, |
Anton Sukhanov | 98a462c | 2018-10-17 13:15:42 -0700 | [diff] [blame] | 104 | const AudioOptions& options); |
Steve Anton | 774115c | 2017-08-30 10:48:46 -0700 | [diff] [blame] | 105 | // Destroys a voice channel created by CreateVoiceChannel. |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 106 | void DestroyVoiceChannel(VoiceChannel* voice_channel); |
Steve Anton | 774115c | 2017-08-30 10:48:46 -0700 | [diff] [blame] | 107 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 108 | // Creates a video channel, synced with the specified voice channel, and |
| 109 | // associated with the specified session. |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 110 | // Version of the above that takes PacketTransportInternal. |
Niels Möller | 4687915 | 2019-01-07 15:54:47 +0100 | [diff] [blame] | 111 | VideoChannel* CreateVideoChannel( |
| 112 | webrtc::Call* call, |
| 113 | const cricket::MediaConfig& media_config, |
| 114 | webrtc::RtpTransportInternal* rtp_transport, |
| 115 | webrtc::MediaTransportInterface* media_transport, |
| 116 | rtc::Thread* signaling_thread, |
| 117 | const std::string& content_name, |
| 118 | bool srtp_required, |
| 119 | const webrtc::CryptoOptions& crypto_options, |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 120 | rtc::UniqueRandomIdGenerator* ssrc_generator, |
Jonas Oreland | a3aa9bd | 2019-04-17 07:38:40 +0200 | [diff] [blame] | 121 | const VideoOptions& options, |
| 122 | webrtc::VideoBitrateAllocatorFactory* video_bitrate_allocator_factory); |
Steve Anton | 774115c | 2017-08-30 10:48:46 -0700 | [diff] [blame] | 123 | // Destroys a video channel created by CreateVideoChannel. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 124 | void DestroyVideoChannel(VideoChannel* video_channel); |
Steve Anton | 774115c | 2017-08-30 10:48:46 -0700 | [diff] [blame] | 125 | |
Zhi Huang | 2dfc42d | 2017-12-04 13:38:48 -0800 | [diff] [blame] | 126 | RtpDataChannel* CreateRtpDataChannel( |
| 127 | const cricket::MediaConfig& media_config, |
| 128 | webrtc::RtpTransportInternal* rtp_transport, |
| 129 | rtc::Thread* signaling_thread, |
| 130 | const std::string& content_name, |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 131 | bool srtp_required, |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 132 | const webrtc::CryptoOptions& crypto_options, |
| 133 | rtc::UniqueRandomIdGenerator* ssrc_generator); |
Steve Anton | 774115c | 2017-08-30 10:48:46 -0700 | [diff] [blame] | 134 | // Destroys a data channel created by CreateRtpDataChannel. |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 135 | void DestroyRtpDataChannel(RtpDataChannel* data_channel); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 136 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 137 | // Indicates whether any channels exist. |
| 138 | bool has_channels() const { |
Steve Anton | c9e1560 | 2017-11-06 15:40:09 -0800 | [diff] [blame] | 139 | return (!voice_channels_.empty() || !video_channels_.empty() || |
| 140 | !data_channels_.empty()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 141 | } |
| 142 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 143 | // RTX will be enabled/disabled in engines that support it. The supporting |
| 144 | // engines will start offering an RTX codec. Must be called before Init(). |
| 145 | bool SetVideoRtxEnabled(bool enable); |
| 146 | |
| 147 | // 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] | 148 | bool capturing() const { return capturing_; } |
| 149 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 150 | // The operations below occur on the main thread. |
| 151 | |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 152 | // Starts AEC dump using existing file, with a specified maximum file size in |
| 153 | // bytes. When the limit is reached, logging will stop and the file will be |
| 154 | // closed. If max_size_bytes is set to <= 0, no limit will be used. |
| 155 | bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes); |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 156 | |
ivoc | 797ef12 | 2015-10-22 03:25:41 -0700 | [diff] [blame] | 157 | // Stops recording AEC dump. |
| 158 | void StopAecDump(); |
| 159 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 160 | private: |
Steve Anton | c9e1560 | 2017-11-06 15:40:09 -0800 | [diff] [blame] | 161 | std::unique_ptr<MediaEngineInterface> media_engine_; // Nullable. |
| 162 | std::unique_ptr<DataEngineInterface> data_engine_; // Non-null. |
| 163 | bool initialized_ = false; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 164 | rtc::Thread* main_thread_; |
| 165 | rtc::Thread* worker_thread_; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 166 | rtc::Thread* network_thread_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 167 | |
Steve Anton | c9e1560 | 2017-11-06 15:40:09 -0800 | [diff] [blame] | 168 | // Vector contents are non-null. |
Steve Anton | 774115c | 2017-08-30 10:48:46 -0700 | [diff] [blame] | 169 | std::vector<std::unique_ptr<VoiceChannel>> voice_channels_; |
| 170 | std::vector<std::unique_ptr<VideoChannel>> video_channels_; |
| 171 | std::vector<std::unique_ptr<RtpDataChannel>> data_channels_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 172 | |
Steve Anton | c9e1560 | 2017-11-06 15:40:09 -0800 | [diff] [blame] | 173 | bool enable_rtx_ = false; |
| 174 | bool capturing_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 175 | }; |
| 176 | |
| 177 | } // namespace cricket |
| 178 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 179 | #endif // PC_CHANNEL_MANAGER_H_ |