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, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 93 | TransportController* transport_controller, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 94 | const std::string& content_name, |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 95 | const std::string* bundle_transport_name, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 96 | bool rtcp, |
| 97 | const AudioOptions& options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 98 | // Destroys a voice channel created with the Create API. |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 99 | void DestroyVoiceChannel(VoiceChannel* voice_channel); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 100 | // Creates a video channel, synced with the specified voice channel, and |
| 101 | // associated with the specified session. |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 102 | VideoChannel* CreateVideoChannel( |
| 103 | webrtc::MediaControllerInterface* media_controller, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 104 | TransportController* transport_controller, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 105 | const std::string& content_name, |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 106 | const std::string* bundle_transport_name, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 107 | bool rtcp, |
| 108 | const VideoOptions& options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 109 | // Destroys a video channel created with the Create API. |
| 110 | void DestroyVideoChannel(VideoChannel* video_channel); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 111 | DataChannel* CreateDataChannel(TransportController* transport_controller, |
| 112 | const std::string& content_name, |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 113 | const std::string* bundle_transport_name, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 114 | bool rtcp, |
| 115 | DataChannelType data_channel_type); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 116 | // Destroys a data channel created with the Create API. |
| 117 | void DestroyDataChannel(DataChannel* data_channel); |
| 118 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 119 | // Indicates whether any channels exist. |
| 120 | bool has_channels() const { |
Fredrik Solenberg | ccb49e7 | 2015-05-19 11:37:56 +0200 | [diff] [blame] | 121 | return (!voice_channels_.empty() || !video_channels_.empty()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 122 | } |
| 123 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [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 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 128 | // Define crypto options to set on newly created channels. Doesn't change |
| 129 | // options on already created channels. |
| 130 | bool SetCryptoOptions(const rtc::CryptoOptions& crypto_options); |
| 131 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 132 | // 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] | 133 | bool capturing() const { return capturing_; } |
| 134 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 135 | // The operations below occur on the main thread. |
| 136 | |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 137 | // Starts AEC dump using existing file, with a specified maximum file size in |
| 138 | // bytes. When the limit is reached, logging will stop and the file will be |
| 139 | // closed. If max_size_bytes is set to <= 0, no limit will be used. |
| 140 | bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes); |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 141 | |
ivoc | 797ef12 | 2015-10-22 03:25:41 -0700 | [diff] [blame] | 142 | // Stops recording AEC dump. |
| 143 | void StopAecDump(); |
| 144 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 145 | private: |
| 146 | typedef std::vector<VoiceChannel*> VoiceChannels; |
| 147 | typedef std::vector<VideoChannel*> VideoChannels; |
| 148 | typedef std::vector<DataChannel*> DataChannels; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 149 | |
| 150 | void Construct(MediaEngineInterface* me, |
| 151 | DataEngineInterface* dme, |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 152 | rtc::Thread* worker_thread, |
| 153 | rtc::Thread* network_thread); |
henrika@webrtc.org | 62f6e75 | 2015-02-11 08:38:35 +0000 | [diff] [blame] | 154 | bool InitMediaEngine_w(); |
hbos@webrtc.org | 4aef5fe | 2015-02-25 10:09:05 +0000 | [diff] [blame] | 155 | void DestructorDeletes_w(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 156 | void Terminate_w(); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 157 | bool SetCryptoOptions_w(const rtc::CryptoOptions& crypto_options); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 158 | VoiceChannel* CreateVoiceChannel_w( |
| 159 | webrtc::MediaControllerInterface* media_controller, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 160 | TransportController* transport_controller, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 161 | const std::string& content_name, |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 162 | const std::string* bundle_transport_name, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 163 | bool rtcp, |
| 164 | const AudioOptions& options); |
| 165 | void DestroyVoiceChannel_w(VoiceChannel* voice_channel); |
| 166 | VideoChannel* CreateVideoChannel_w( |
| 167 | webrtc::MediaControllerInterface* media_controller, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 168 | TransportController* transport_controller, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 169 | const std::string& content_name, |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 170 | const std::string* bundle_transport_name, |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 171 | bool rtcp, |
| 172 | const VideoOptions& options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 173 | void DestroyVideoChannel_w(VideoChannel* video_channel); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 174 | DataChannel* CreateDataChannel_w(TransportController* transport_controller, |
| 175 | const std::string& content_name, |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 176 | const std::string* bundle_transport_name, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 177 | bool rtcp, |
| 178 | DataChannelType data_channel_type); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 179 | void DestroyDataChannel_w(DataChannel* data_channel); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 180 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 181 | std::unique_ptr<MediaEngineInterface> media_engine_; |
| 182 | std::unique_ptr<DataEngineInterface> data_media_engine_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 183 | bool initialized_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 184 | rtc::Thread* main_thread_; |
| 185 | rtc::Thread* worker_thread_; |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 186 | rtc::Thread* network_thread_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 187 | |
| 188 | VoiceChannels voice_channels_; |
| 189 | VideoChannels video_channels_; |
| 190 | DataChannels data_channels_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 191 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 192 | bool enable_rtx_; |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 193 | rtc::CryptoOptions crypto_options_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 194 | |
| 195 | bool capturing_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | } // namespace cricket |
| 199 | |
Per | fb45d17 | 2016-02-29 12:07:35 +0100 | [diff] [blame] | 200 | #endif // WEBRTC_PC_CHANNELMANAGER_H_ |