blob: 9f55f0e29cbdb2b828a6c866d2c4af9ffe82a8ea [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.
Fredrik Solenberg709ed672015-09-15 12:26:33 +020083 VoiceChannel* CreateVoiceChannel(
nisseeaabdf62017-05-05 02:23:02 -070084 webrtc::Call* call,
85 const cricket::MediaConfig& media_config,
zhihuangb2cdd932017-01-19 16:54:25 -080086 DtlsTransportInternal* rtp_transport,
87 DtlsTransportInternal* rtcp_transport,
zhihuangf5b251b2017-01-12 19:37:48 -080088 rtc::Thread* signaling_thread,
Fredrik Solenberg709ed672015-09-15 12:26:33 +020089 const std::string& content_name,
deadbeef7af91dd2016-12-13 11:29:11 -080090 bool srtp_required,
Fredrik Solenberg709ed672015-09-15 12:26:33 +020091 const AudioOptions& options);
deadbeefe814a0d2017-02-25 18:15:09 -080092 // Version of the above that takes PacketTransportInternal.
93 VoiceChannel* CreateVoiceChannel(
nisseeaabdf62017-05-05 02:23:02 -070094 webrtc::Call* call,
95 const cricket::MediaConfig& media_config,
deadbeefe814a0d2017-02-25 18:15:09 -080096 rtc::PacketTransportInternal* rtp_transport,
97 rtc::PacketTransportInternal* rtcp_transport,
98 rtc::Thread* signaling_thread,
99 const std::string& content_name,
100 bool srtp_required,
101 const AudioOptions& options);
Steve Anton774115c2017-08-30 10:48:46 -0700102 // Destroys a voice channel created by CreateVoiceChannel.
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200103 void DestroyVoiceChannel(VoiceChannel* voice_channel);
Steve Anton774115c2017-08-30 10:48:46 -0700104
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105 // Creates a video channel, synced with the specified voice channel, and
106 // associated with the specified session.
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200107 VideoChannel* CreateVideoChannel(
nisseeaabdf62017-05-05 02:23:02 -0700108 webrtc::Call* call,
109 const cricket::MediaConfig& media_config,
zhihuangb2cdd932017-01-19 16:54:25 -0800110 DtlsTransportInternal* rtp_transport,
111 DtlsTransportInternal* rtcp_transport,
zhihuangf5b251b2017-01-12 19:37:48 -0800112 rtc::Thread* signaling_thread,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200113 const std::string& content_name,
deadbeef7af91dd2016-12-13 11:29:11 -0800114 bool srtp_required,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200115 const VideoOptions& options);
deadbeefe814a0d2017-02-25 18:15:09 -0800116 // Version of the above that takes PacketTransportInternal.
117 VideoChannel* CreateVideoChannel(
nisseeaabdf62017-05-05 02:23:02 -0700118 webrtc::Call* call,
119 const cricket::MediaConfig& media_config,
deadbeefe814a0d2017-02-25 18:15:09 -0800120 rtc::PacketTransportInternal* rtp_transport,
121 rtc::PacketTransportInternal* rtcp_transport,
122 rtc::Thread* signaling_thread,
123 const std::string& content_name,
124 bool srtp_required,
125 const VideoOptions& options);
Steve Anton774115c2017-08-30 10:48:46 -0700126 // Destroys a video channel created by CreateVideoChannel.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127 void DestroyVideoChannel(VideoChannel* video_channel);
Steve Anton774115c2017-08-30 10:48:46 -0700128
deadbeef953c2ce2017-01-09 14:53:41 -0800129 RtpDataChannel* CreateRtpDataChannel(
nisseeaabdf62017-05-05 02:23:02 -0700130 const cricket::MediaConfig& media_config,
zhihuangb2cdd932017-01-19 16:54:25 -0800131 DtlsTransportInternal* rtp_transport,
132 DtlsTransportInternal* rtcp_transport,
zhihuangf5b251b2017-01-12 19:37:48 -0800133 rtc::Thread* signaling_thread,
zhihuangebbe4f22016-12-06 10:45:42 -0800134 const std::string& content_name,
deadbeef953c2ce2017-01-09 14:53:41 -0800135 bool srtp_required);
Steve Anton774115c2017-08-30 10:48:46 -0700136 // Destroys a data channel created by CreateRtpDataChannel.
deadbeef953c2ce2017-01-09 14:53:41 -0800137 void DestroyRtpDataChannel(RtpDataChannel* data_channel);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000139 // Indicates whether any channels exist.
140 bool has_channels() const {
Steve Antonc9e15602017-11-06 15:40:09 -0800141 return (!voice_channels_.empty() || !video_channels_.empty() ||
142 !data_channels_.empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143 }
144
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000145 // RTX will be enabled/disabled in engines that support it. The supporting
146 // engines will start offering an RTX codec. Must be called before Init().
147 bool SetVideoRtxEnabled(bool enable);
148
149 // Starts/stops the local microphone and enables polling of the input level.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150 bool capturing() const { return capturing_; }
151
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152 // The operations below occur on the main thread.
153
ivocd66b44d2016-01-15 03:06:36 -0800154 // Starts AEC dump using existing file, with a specified maximum file size in
155 // bytes. When the limit is reached, logging will stop and the file will be
156 // closed. If max_size_bytes is set to <= 0, no limit will be used.
157 bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000158
ivoc797ef122015-10-22 03:25:41 -0700159 // Stops recording AEC dump.
160 void StopAecDump();
161
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162 private:
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200163 VoiceChannel* CreateVoiceChannel_w(
nisseeaabdf62017-05-05 02:23:02 -0700164 webrtc::Call* call,
165 const cricket::MediaConfig& media_config,
deadbeefe814a0d2017-02-25 18:15:09 -0800166 DtlsTransportInternal* rtp_dtls_transport,
167 DtlsTransportInternal* rtcp_dtls_transport,
168 rtc::PacketTransportInternal* rtp_packet_transport,
169 rtc::PacketTransportInternal* rtcp_packet_transport,
zhihuangf5b251b2017-01-12 19:37:48 -0800170 rtc::Thread* signaling_thread,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200171 const std::string& content_name,
deadbeef7af91dd2016-12-13 11:29:11 -0800172 bool srtp_required,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200173 const AudioOptions& options);
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200174 VideoChannel* CreateVideoChannel_w(
nisseeaabdf62017-05-05 02:23:02 -0700175 webrtc::Call* call,
176 const cricket::MediaConfig& media_config,
deadbeefe814a0d2017-02-25 18:15:09 -0800177 DtlsTransportInternal* rtp_dtls_transport,
178 DtlsTransportInternal* rtcp_dtls_transport,
179 rtc::PacketTransportInternal* rtp_packet_transport,
180 rtc::PacketTransportInternal* rtcp_packet_transport,
zhihuangf5b251b2017-01-12 19:37:48 -0800181 rtc::Thread* signaling_thread,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200182 const std::string& content_name,
deadbeef7af91dd2016-12-13 11:29:11 -0800183 bool srtp_required,
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200184 const VideoOptions& options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185
Steve Antonc9e15602017-11-06 15:40:09 -0800186 std::unique_ptr<MediaEngineInterface> media_engine_; // Nullable.
187 std::unique_ptr<DataEngineInterface> data_engine_; // Non-null.
188 bool initialized_ = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000189 rtc::Thread* main_thread_;
190 rtc::Thread* worker_thread_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200191 rtc::Thread* network_thread_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192
Steve Antonc9e15602017-11-06 15:40:09 -0800193 // Vector contents are non-null.
Steve Anton774115c2017-08-30 10:48:46 -0700194 std::vector<std::unique_ptr<VoiceChannel>> voice_channels_;
195 std::vector<std::unique_ptr<VideoChannel>> video_channels_;
196 std::vector<std::unique_ptr<RtpDataChannel>> data_channels_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000197
Steve Antonc9e15602017-11-06 15:40:09 -0800198 bool enable_rtx_ = false;
199 bool capturing_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200};
201
202} // namespace cricket
203
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200204#endif // PC_CHANNELMANAGER_H_