blob: c6b601ea8f6cb0e0017b0bf0aca703de0249658a [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:361/*
kjellander65c7f672016-02-12 08:05:012 * Copyright 2004 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:363 *
kjellander65c7f672016-02-12 08:05:014 * 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:369 */
10
Mirko Bonadei92ea95e2017-09-15 04:47:3111#ifndef PC_CHANNELMANAGER_H_
12#define PC_CHANNELMANAGER_H_
henrike@webrtc.org28e20752013-07-10 00:45:3613
kwiberg31022942016-03-11 22:18:2114#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:3615#include <string>
16#include <vector>
17
Mirko Bonadei92ea95e2017-09-15 04:47:3118#include "media/base/mediaengine.h"
Steve Antonc9e15602017-11-06 23:40:0919#include "pc/channel.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3120#include "rtc_base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:3621
22namespace cricket {
23
henrike@webrtc.org28e20752013-07-10 00:45:3624// 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 23:40:0932class ChannelManager final {
henrike@webrtc.org28e20752013-07-10 00:45:3633 public:
Steve Antonc9e15602017-11-06 23:40:0934 // 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:3639 ~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:5243 rtc::Thread* worker_thread() const { return worker_thread_; }
44 bool set_worker_thread(rtc::Thread* thread) {
Danil Chapovalov33b01f22016-05-11 17:55:2745 if (initialized_) {
46 return false;
47 }
henrike@webrtc.org28e20752013-07-10 00:45:3648 worker_thread_ = thread;
49 return true;
50 }
Danil Chapovalov33b01f22016-05-11 17:55:2751 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:3659
Fredrik Solenberg709ed672015-09-15 10:26:3360 MediaEngineInterface* media_engine() { return media_engine_.get(); }
61
henrike@webrtc.org28e20752013-07-10 00:45:3662 // Retrieves the list of supported audio & video codec types.
63 // Can be called before starting the media engine.
ossudedfd282016-06-14 14:12:3964 void GetSupportedAudioSendCodecs(std::vector<AudioCodec>* codecs) const;
65 void GetSupportedAudioReceiveCodecs(std::vector<AudioCodec>* codecs) const;
henrike@webrtc.org28e20752013-07-10 00:45:3666 void GetSupportedAudioRtpHeaderExtensions(RtpHeaderExtensions* ext) const;
magjed3cf8ece2016-11-10 11:36:5367 void GetSupportedVideoCodecs(std::vector<VideoCodec>* codecs) const;
henrike@webrtc.org28e20752013-07-10 00:45:3668 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 17:48:4679 // 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:3682 // Creates a voice channel, to be associated with the specified session.
Zhi Huang2dfc42d2017-12-04 21:38:4883 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 Huange830e682018-03-30 17:48:3589 const rtc::CryptoOptions& crypto_options,
Zhi Huang2dfc42d2017-12-04 21:38:4890 const AudioOptions& options);
Steve Anton774115c2017-08-30 17:48:4691 // Destroys a voice channel created by CreateVoiceChannel.
Fredrik Solenberg709ed672015-09-15 10:26:3392 void DestroyVoiceChannel(VoiceChannel* voice_channel);
Steve Anton774115c2017-08-30 17:48:4693
henrike@webrtc.org28e20752013-07-10 00:45:3694 // Creates a video channel, synced with the specified voice channel, and
95 // associated with the specified session.
deadbeefe814a0d2017-02-26 02:15:0996 // Version of the above that takes PacketTransportInternal.
Zhi Huang2dfc42d2017-12-04 21:38:4897 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 Huange830e682018-03-30 17:48:35103 const rtc::CryptoOptions& crypto_options,
Zhi Huang2dfc42d2017-12-04 21:38:48104 const VideoOptions& options);
Steve Anton774115c2017-08-30 17:48:46105 // Destroys a video channel created by CreateVideoChannel.
henrike@webrtc.org28e20752013-07-10 00:45:36106 void DestroyVideoChannel(VideoChannel* video_channel);
Steve Anton774115c2017-08-30 17:48:46107
Zhi Huang2dfc42d2017-12-04 21:38:48108 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 Huange830e682018-03-30 17:48:35113 bool srtp_required,
114 const rtc::CryptoOptions& crypto_options);
Steve Anton774115c2017-08-30 17:48:46115 // Destroys a data channel created by CreateRtpDataChannel.
deadbeef953c2ce2017-01-09 22:53:41116 void DestroyRtpDataChannel(RtpDataChannel* data_channel);
henrike@webrtc.org28e20752013-07-10 00:45:36117
henrike@webrtc.org28e20752013-07-10 00:45:36118 // Indicates whether any channels exist.
119 bool has_channels() const {
Steve Antonc9e15602017-11-06 23:40:09120 return (!voice_channels_.empty() || !video_channels_.empty() ||
121 !data_channels_.empty());
henrike@webrtc.org28e20752013-07-10 00:45:36122 }
123
henrike@webrtc.org28e20752013-07-10 00:45:36124 // 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.org28e20752013-07-10 00:45:36129 bool capturing() const { return capturing_; }
130
henrike@webrtc.org28e20752013-07-10 00:45:36131 // The operations below occur on the main thread.
132
ivocd66b44d2016-01-15 11:06:36133 // 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.orga9890802013-12-13 00:21:03137
ivoc797ef122015-10-22 10:25:41138 // Stops recording AEC dump.
139 void StopAecDump();
140
henrike@webrtc.org28e20752013-07-10 00:45:36141 private:
Steve Antonc9e15602017-11-06 23:40:09142 std::unique_ptr<MediaEngineInterface> media_engine_; // Nullable.
143 std::unique_ptr<DataEngineInterface> data_engine_; // Non-null.
144 bool initialized_ = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52145 rtc::Thread* main_thread_;
146 rtc::Thread* worker_thread_;
Danil Chapovalov33b01f22016-05-11 17:55:27147 rtc::Thread* network_thread_;
henrike@webrtc.org28e20752013-07-10 00:45:36148
Steve Antonc9e15602017-11-06 23:40:09149 // Vector contents are non-null.
Steve Anton774115c2017-08-30 17:48:46150 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.org28e20752013-07-10 00:45:36153
Steve Antonc9e15602017-11-06 23:40:09154 bool enable_rtx_ = false;
155 bool capturing_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36156};
157
158} // namespace cricket
159
Mirko Bonadei92ea95e2017-09-15 04:47:31160#endif // PC_CHANNELMANAGER_H_