henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 08:05:01 | [diff] [blame] | 2 | * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 08:05:01 | [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 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #ifndef PC_CHANNELMANAGER_H_ |
| 12 | #define PC_CHANNELMANAGER_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 13 | |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 14 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 18 | #include "media/base/mediaengine.h" |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 19 | #include "pc/channel.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 20 | #include "rtc_base/thread.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 21 | |
| 22 | namespace cricket { |
| 23 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 24 | // ChannelManager allows the MediaEngine to run on a separate thread, and takes |
| 25 | // care of marshalling calls between threads. It also creates and keeps track of |
| 26 | // voice and video channels; by doing so, it can temporarily pause all the |
| 27 | // channels when a new audio or video device is chosen. The voice and video |
| 28 | // channels are stored in separate vectors, to easily allow operations on just |
| 29 | // voice or just video channels. |
| 30 | // ChannelManager also allows the application to discover what devices it has |
| 31 | // using device manager. |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 32 | class ChannelManager final { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 33 | public: |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 34 | // Construct a ChannelManager with the specified media engine and data engine. |
| 35 | ChannelManager(std::unique_ptr<MediaEngineInterface> media_engine, |
| 36 | std::unique_ptr<DataEngineInterface> data_engine, |
| 37 | rtc::Thread* worker_thread, |
| 38 | rtc::Thread* network_thread); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 39 | ~ChannelManager(); |
| 40 | |
| 41 | // Accessors for the worker thread, allowing it to be set after construction, |
| 42 | // but before Init. set_worker_thread will return false if called after Init. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 43 | rtc::Thread* worker_thread() const { return worker_thread_; } |
| 44 | bool set_worker_thread(rtc::Thread* thread) { |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 45 | if (initialized_) { |
| 46 | return false; |
| 47 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 48 | worker_thread_ = thread; |
| 49 | return true; |
| 50 | } |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 51 | rtc::Thread* network_thread() const { return network_thread_; } |
| 52 | bool set_network_thread(rtc::Thread* thread) { |
| 53 | if (initialized_) { |
| 54 | return false; |
| 55 | } |
| 56 | network_thread_ = thread; |
| 57 | return true; |
| 58 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 59 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 10:26:33 | [diff] [blame] | 60 | MediaEngineInterface* media_engine() { return media_engine_.get(); } |
| 61 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 62 | // Retrieves the list of supported audio & video codec types. |
| 63 | // Can be called before starting the media engine. |
ossu | dedfd28 | 2016-06-14 14:12:39 | [diff] [blame] | 64 | void GetSupportedAudioSendCodecs(std::vector<AudioCodec>* codecs) const; |
| 65 | void GetSupportedAudioReceiveCodecs(std::vector<AudioCodec>* codecs) const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 66 | void GetSupportedAudioRtpHeaderExtensions(RtpHeaderExtensions* ext) const; |
magjed | 3cf8ece | 2016-11-10 11:36:53 | [diff] [blame] | 67 | void GetSupportedVideoCodecs(std::vector<VideoCodec>* codecs) const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 68 | void GetSupportedVideoRtpHeaderExtensions(RtpHeaderExtensions* ext) const; |
| 69 | void GetSupportedDataCodecs(std::vector<DataCodec>* codecs) const; |
| 70 | |
| 71 | // Indicates whether the media engine is started. |
| 72 | bool initialized() const { return initialized_; } |
| 73 | // Starts up the media engine. |
| 74 | bool Init(); |
| 75 | // Shuts down the media engine. |
| 76 | void Terminate(); |
| 77 | |
| 78 | // The operations below all occur on the worker thread. |
Steve Anton | 774115c | 2017-08-30 17:48:46 | [diff] [blame] | 79 | // ChannelManager retains ownership of the created channels, so clients should |
| 80 | // call the appropriate Destroy*Channel method when done. |
| 81 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 82 | // Creates a voice channel, to be associated with the specified session. |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 83 | VoiceChannel* CreateVoiceChannel(webrtc::Call* call, |
| 84 | const cricket::MediaConfig& media_config, |
| 85 | webrtc::RtpTransportInternal* rtp_transport, |
| 86 | rtc::Thread* signaling_thread, |
| 87 | const std::string& content_name, |
| 88 | bool srtp_required, |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 89 | const rtc::CryptoOptions& crypto_options, |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 90 | const AudioOptions& options); |
Steve Anton | 774115c | 2017-08-30 17:48:46 | [diff] [blame] | 91 | // Destroys a voice channel created by CreateVoiceChannel. |
Fredrik Solenberg | 709ed67 | 2015-09-15 10:26:33 | [diff] [blame] | 92 | void DestroyVoiceChannel(VoiceChannel* voice_channel); |
Steve Anton | 774115c | 2017-08-30 17:48:46 | [diff] [blame] | 93 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 94 | // Creates a video channel, synced with the specified voice channel, and |
| 95 | // associated with the specified session. |
deadbeef | e814a0d | 2017-02-26 02:15:09 | [diff] [blame] | 96 | // Version of the above that takes PacketTransportInternal. |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 97 | VideoChannel* CreateVideoChannel(webrtc::Call* call, |
| 98 | const cricket::MediaConfig& media_config, |
| 99 | webrtc::RtpTransportInternal* rtp_transport, |
| 100 | rtc::Thread* signaling_thread, |
| 101 | const std::string& content_name, |
| 102 | bool srtp_required, |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 103 | const rtc::CryptoOptions& crypto_options, |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 104 | const VideoOptions& options); |
Steve Anton | 774115c | 2017-08-30 17:48:46 | [diff] [blame] | 105 | // Destroys a video channel created by CreateVideoChannel. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 106 | void DestroyVideoChannel(VideoChannel* video_channel); |
Steve Anton | 774115c | 2017-08-30 17:48:46 | [diff] [blame] | 107 | |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 108 | RtpDataChannel* CreateRtpDataChannel( |
| 109 | const cricket::MediaConfig& media_config, |
| 110 | webrtc::RtpTransportInternal* rtp_transport, |
| 111 | rtc::Thread* signaling_thread, |
| 112 | const std::string& content_name, |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 113 | bool srtp_required, |
| 114 | const rtc::CryptoOptions& crypto_options); |
Steve Anton | 774115c | 2017-08-30 17:48:46 | [diff] [blame] | 115 | // Destroys a data channel created by CreateRtpDataChannel. |
deadbeef | 953c2ce | 2017-01-09 22:53:41 | [diff] [blame] | 116 | void DestroyRtpDataChannel(RtpDataChannel* data_channel); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 117 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 118 | // Indicates whether any channels exist. |
| 119 | bool has_channels() const { |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 120 | return (!voice_channels_.empty() || !video_channels_.empty() || |
| 121 | !data_channels_.empty()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 122 | } |
| 123 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 124 | // RTX will be enabled/disabled in engines that support it. The supporting |
| 125 | // engines will start offering an RTX codec. Must be called before Init(). |
| 126 | bool SetVideoRtxEnabled(bool enable); |
| 127 | |
| 128 | // Starts/stops the local microphone and enables polling of the input level. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 129 | bool capturing() const { return capturing_; } |
| 130 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 131 | // The operations below occur on the main thread. |
| 132 | |
ivoc | d66b44d | 2016-01-15 11:06:36 | [diff] [blame] | 133 | // Starts AEC dump using existing file, with a specified maximum file size in |
| 134 | // bytes. When the limit is reached, logging will stop and the file will be |
| 135 | // closed. If max_size_bytes is set to <= 0, no limit will be used. |
| 136 | bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes); |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 | [diff] [blame] | 137 | |
ivoc | 797ef12 | 2015-10-22 10:25:41 | [diff] [blame] | 138 | // Stops recording AEC dump. |
| 139 | void StopAecDump(); |
| 140 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 141 | private: |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 142 | std::unique_ptr<MediaEngineInterface> media_engine_; // Nullable. |
| 143 | std::unique_ptr<DataEngineInterface> data_engine_; // Non-null. |
| 144 | bool initialized_ = false; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 145 | rtc::Thread* main_thread_; |
| 146 | rtc::Thread* worker_thread_; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 147 | rtc::Thread* network_thread_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 148 | |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 149 | // Vector contents are non-null. |
Steve Anton | 774115c | 2017-08-30 17:48:46 | [diff] [blame] | 150 | std::vector<std::unique_ptr<VoiceChannel>> voice_channels_; |
| 151 | std::vector<std::unique_ptr<VideoChannel>> video_channels_; |
| 152 | std::vector<std::unique_ptr<RtpDataChannel>> data_channels_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 153 | |
Steve Anton | c9e1560 | 2017-11-06 23:40:09 | [diff] [blame] | 154 | bool enable_rtx_ = false; |
| 155 | bool capturing_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | } // namespace cricket |
| 159 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 160 | #endif // PC_CHANNELMANAGER_H_ |