blob: 72d218a228d97b480f4ad42512fcb4d3febcaf7b [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellander65c7f672016-02-12 00:05:01 -08002 * Copyright 2004 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellander65c7f672016-02-12 00:05:01 -08004 * 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.org28e20752013-07-10 00:45:36 +00009 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef PC_CHANNELMANAGER_H_
12#define PC_CHANNELMANAGER_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
kwiberg31022942016-03-11 14:18:21 -080014#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015#include <string>
16#include <vector>
17
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "media/base/mediaengine.h"
Steve Antonc9e15602017-11-06 15:40:09 -080019#include "pc/channel.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "rtc_base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000021
22namespace cricket {
23
henrike@webrtc.org28e20752013-07-10 00:45:36 +000024// 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 Antonc9e15602017-11-06 15:40:09 -080032class ChannelManager final {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033 public:
Steve Antonc9e15602017-11-06 15:40:09 -080034 // 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.org28e20752013-07-10 00:45:36 +000039 ~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.orgd4e598d2014-07-29 17:36:52 +000043 rtc::Thread* worker_thread() const { return worker_thread_; }
44 bool set_worker_thread(rtc::Thread* thread) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +020045 if (initialized_) {
46 return false;
47 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048 worker_thread_ = thread;
49 return true;
50 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +020051 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.org28e20752013-07-10 00:45:36 +000059
Fredrik Solenberg709ed672015-09-15 12:26:33 +020060 MediaEngineInterface* media_engine() { return media_engine_.get(); }
61
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062 // Retrieves the list of supported audio & video codec types.
63 // Can be called before starting the media engine.
ossudedfd282016-06-14 07:12:39 -070064 void GetSupportedAudioSendCodecs(std::vector<AudioCodec>* codecs) const;
65 void GetSupportedAudioReceiveCodecs(std::vector<AudioCodec>* codecs) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066 void GetSupportedAudioRtpHeaderExtensions(RtpHeaderExtensions* ext) const;
magjed3cf8ece2016-11-10 03:36:53 -080067 void GetSupportedVideoCodecs(std::vector<VideoCodec>* codecs) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068 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 Anton774115c2017-08-30 10:48:46 -070079 // ChannelManager retains ownership of the created channels, so clients should
80 // call the appropriate Destroy*Channel method when done.
81
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082 // Creates a voice channel, to be associated with the specified session.
Zhi Huang2dfc42d2017-12-04 13:38:48 -080083 // TODO(zhihuang): Replace this with the method taking an
84 // RtpTransportInternal*;
Fredrik Solenberg709ed672015-09-15 12:26:33 +020085 VoiceChannel* CreateVoiceChannel(
nisseeaabdf62017-05-05 02:23:02 -070086 webrtc::Call* call,
87 const cricket::MediaConfig& media_config,
zhihuangb2cdd932017-01-19 16:54:25 -080088 DtlsTransportInternal* rtp_transport,
89 DtlsTransportInternal* rtcp_transport,
zhihuangf5b251b2017-01-12 19:37:48 -080090 rtc::Thread* signaling_thread,
Fredrik Solenberg709ed672015-09-15 12:26:33 +020091 const std::string& content_name,
deadbeef7af91dd2016-12-13 11:29:11 -080092 bool srtp_required,
Fredrik Solenberg709ed672015-09-15 12:26:33 +020093 const AudioOptions& options);
deadbeefe814a0d2017-02-25 18:15:09 -080094 // Version of the above that takes PacketTransportInternal.
Zhi Huang2dfc42d2017-12-04 13:38:48 -080095 // TODO(zhihuang): Replace this with the method taking an
96 // RtpTransportInternal*;
deadbeefe814a0d2017-02-25 18:15:09 -080097 VoiceChannel* CreateVoiceChannel(
nisseeaabdf62017-05-05 02:23:02 -070098 webrtc::Call* call,
99 const cricket::MediaConfig& media_config,
deadbeefe814a0d2017-02-25 18:15:09 -0800100 rtc::PacketTransportInternal* rtp_transport,
101 rtc::PacketTransportInternal* rtcp_transport,
102 rtc::Thread* signaling_thread,
103 const std::string& content_name,
104 bool srtp_required,
105 const AudioOptions& options);
Zhi Huang2dfc42d2017-12-04 13:38:48 -0800106
107 VoiceChannel* CreateVoiceChannel(webrtc::Call* call,
108 const cricket::MediaConfig& media_config,
109 webrtc::RtpTransportInternal* rtp_transport,
110 rtc::Thread* signaling_thread,
111 const std::string& content_name,
112 bool srtp_required,
113 const AudioOptions& options);
Steve Anton774115c2017-08-30 10:48:46 -0700114 // Destroys a voice channel created by CreateVoiceChannel.
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200115 void DestroyVoiceChannel(VoiceChannel* voice_channel);
Steve Anton774115c2017-08-30 10:48:46 -0700116
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117 // Creates a video channel, synced with the specified voice channel, and
118 // associated with the specified session.
Zhi Huang2dfc42d2017-12-04 13:38:48 -0800119 // TODO(zhihuang): Replace this with the method taking an
120 // RtpTransportInternal*;
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200121 VideoChannel* CreateVideoChannel(
nisseeaabdf62017-05-05 02:23:02 -0700122 webrtc::Call* call,
123 const cricket::MediaConfig& media_config,
zhihuangb2cdd932017-01-19 16:54:25 -0800124 DtlsTransportInternal* rtp_transport,
125 DtlsTransportInternal* rtcp_transport,
zhihuangf5b251b2017-01-12 19:37:48 -0800126 rtc::Thread* signaling_thread,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200127 const std::string& content_name,
deadbeef7af91dd2016-12-13 11:29:11 -0800128 bool srtp_required,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200129 const VideoOptions& options);
deadbeefe814a0d2017-02-25 18:15:09 -0800130 // Version of the above that takes PacketTransportInternal.
Zhi Huang2dfc42d2017-12-04 13:38:48 -0800131 // TODO(zhihuang): Replace this with the method taking an
132 // RtpTransportInternal*;
deadbeefe814a0d2017-02-25 18:15:09 -0800133 VideoChannel* CreateVideoChannel(
nisseeaabdf62017-05-05 02:23:02 -0700134 webrtc::Call* call,
135 const cricket::MediaConfig& media_config,
deadbeefe814a0d2017-02-25 18:15:09 -0800136 rtc::PacketTransportInternal* rtp_transport,
137 rtc::PacketTransportInternal* rtcp_transport,
138 rtc::Thread* signaling_thread,
139 const std::string& content_name,
140 bool srtp_required,
141 const VideoOptions& options);
Zhi Huang2dfc42d2017-12-04 13:38:48 -0800142 VideoChannel* CreateVideoChannel(webrtc::Call* call,
143 const cricket::MediaConfig& media_config,
144 webrtc::RtpTransportInternal* rtp_transport,
145 rtc::Thread* signaling_thread,
146 const std::string& content_name,
147 bool srtp_required,
148 const VideoOptions& options);
Steve Anton774115c2017-08-30 10:48:46 -0700149 // Destroys a video channel created by CreateVideoChannel.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150 void DestroyVideoChannel(VideoChannel* video_channel);
Steve Anton774115c2017-08-30 10:48:46 -0700151
Zhi Huang2dfc42d2017-12-04 13:38:48 -0800152 // TODO(zhihuang): Replace this with the method taking an
153 // RtpTransportInternal*;
deadbeef953c2ce2017-01-09 14:53:41 -0800154 RtpDataChannel* CreateRtpDataChannel(
nisseeaabdf62017-05-05 02:23:02 -0700155 const cricket::MediaConfig& media_config,
zhihuangb2cdd932017-01-19 16:54:25 -0800156 DtlsTransportInternal* rtp_transport,
157 DtlsTransportInternal* rtcp_transport,
zhihuangf5b251b2017-01-12 19:37:48 -0800158 rtc::Thread* signaling_thread,
zhihuangebbe4f22016-12-06 10:45:42 -0800159 const std::string& content_name,
deadbeef953c2ce2017-01-09 14:53:41 -0800160 bool srtp_required);
Zhi Huang2dfc42d2017-12-04 13:38:48 -0800161 RtpDataChannel* CreateRtpDataChannel(
162 const cricket::MediaConfig& media_config,
163 webrtc::RtpTransportInternal* rtp_transport,
164 rtc::Thread* signaling_thread,
165 const std::string& content_name,
166 bool srtp_required);
Steve Anton774115c2017-08-30 10:48:46 -0700167 // Destroys a data channel created by CreateRtpDataChannel.
deadbeef953c2ce2017-01-09 14:53:41 -0800168 void DestroyRtpDataChannel(RtpDataChannel* data_channel);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170 // Indicates whether any channels exist.
171 bool has_channels() const {
Steve Antonc9e15602017-11-06 15:40:09 -0800172 return (!voice_channels_.empty() || !video_channels_.empty() ||
173 !data_channels_.empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174 }
175
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000176 // RTX will be enabled/disabled in engines that support it. The supporting
177 // engines will start offering an RTX codec. Must be called before Init().
178 bool SetVideoRtxEnabled(bool enable);
179
180 // Starts/stops the local microphone and enables polling of the input level.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 bool capturing() const { return capturing_; }
182
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000183 // The operations below occur on the main thread.
184
ivocd66b44d2016-01-15 03:06:36 -0800185 // Starts AEC dump using existing file, with a specified maximum file size in
186 // bytes. When the limit is reached, logging will stop and the file will be
187 // closed. If max_size_bytes is set to <= 0, no limit will be used.
188 bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000189
ivoc797ef122015-10-22 03:25:41 -0700190 // Stops recording AEC dump.
191 void StopAecDump();
192
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193 private:
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200194 VoiceChannel* CreateVoiceChannel_w(
nisseeaabdf62017-05-05 02:23:02 -0700195 webrtc::Call* call,
196 const cricket::MediaConfig& media_config,
deadbeefe814a0d2017-02-25 18:15:09 -0800197 DtlsTransportInternal* rtp_dtls_transport,
198 DtlsTransportInternal* rtcp_dtls_transport,
199 rtc::PacketTransportInternal* rtp_packet_transport,
200 rtc::PacketTransportInternal* rtcp_packet_transport,
zhihuangf5b251b2017-01-12 19:37:48 -0800201 rtc::Thread* signaling_thread,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200202 const std::string& content_name,
deadbeef7af91dd2016-12-13 11:29:11 -0800203 bool srtp_required,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200204 const AudioOptions& options);
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200205 VideoChannel* CreateVideoChannel_w(
nisseeaabdf62017-05-05 02:23:02 -0700206 webrtc::Call* call,
207 const cricket::MediaConfig& media_config,
deadbeefe814a0d2017-02-25 18:15:09 -0800208 DtlsTransportInternal* rtp_dtls_transport,
209 DtlsTransportInternal* rtcp_dtls_transport,
210 rtc::PacketTransportInternal* rtp_packet_transport,
211 rtc::PacketTransportInternal* rtcp_packet_transport,
zhihuangf5b251b2017-01-12 19:37:48 -0800212 rtc::Thread* signaling_thread,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200213 const std::string& content_name,
deadbeef7af91dd2016-12-13 11:29:11 -0800214 bool srtp_required,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200215 const VideoOptions& options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000216
Steve Antonc9e15602017-11-06 15:40:09 -0800217 std::unique_ptr<MediaEngineInterface> media_engine_; // Nullable.
218 std::unique_ptr<DataEngineInterface> data_engine_; // Non-null.
219 bool initialized_ = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000220 rtc::Thread* main_thread_;
221 rtc::Thread* worker_thread_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200222 rtc::Thread* network_thread_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000223
Steve Antonc9e15602017-11-06 15:40:09 -0800224 // Vector contents are non-null.
Steve Anton774115c2017-08-30 10:48:46 -0700225 std::vector<std::unique_ptr<VoiceChannel>> voice_channels_;
226 std::vector<std::unique_ptr<VideoChannel>> video_channels_;
227 std::vector<std::unique_ptr<RtpDataChannel>> data_channels_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228
Steve Antonc9e15602017-11-06 15:40:09 -0800229 bool enable_rtx_ = false;
230 bool capturing_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231};
232
233} // namespace cricket
234
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200235#endif // PC_CHANNELMANAGER_H_