blob: fa4bf7b92579ccc06e3624d635854d90135cbc61 [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
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef PC_CHANNEL_MANAGER_H_
12#define PC_CHANNEL_MANAGER_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <stdint.h>
Anton Sukhanov4f08faa2019-05-21 11:12:57 -070015
kwiberg31022942016-03-11 14:18:21 -080016#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000017#include <string>
18#include <vector>
19
Yves Gerey3e707812018-11-28 16:47:49 +010020#include "api/audio_options.h"
Steve Anton10542f22019-01-11 09:11:00 -080021#include "api/crypto/crypto_options.h"
Niels Möller65f17ca2019-09-12 13:59:36 +020022#include "api/transport/media/media_transport_config.h"
Yves Gerey3e707812018-11-28 16:47:49 +010023#include "call/call.h"
24#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080025#include "media/base/media_channel.h"
26#include "media/base/media_config.h"
27#include "media/base/media_engine.h"
Steve Antonc9e15602017-11-06 15:40:09 -080028#include "pc/channel.h"
Steve Anton10542f22019-01-11 09:11:00 -080029#include "pc/rtp_transport_internal.h"
30#include "pc/session_description.h"
Niels Möllere8e4dc42019-06-11 14:04:16 +020031#include "rtc_base/system/file_wrapper.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "rtc_base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033
34namespace cricket {
35
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036// ChannelManager allows the MediaEngine to run on a separate thread, and takes
37// care of marshalling calls between threads. It also creates and keeps track of
38// voice and video channels; by doing so, it can temporarily pause all the
39// channels when a new audio or video device is chosen. The voice and video
40// channels are stored in separate vectors, to easily allow operations on just
41// voice or just video channels.
42// ChannelManager also allows the application to discover what devices it has
43// using device manager.
Steve Antonc9e15602017-11-06 15:40:09 -080044class ChannelManager final {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000045 public:
Steve Antonc9e15602017-11-06 15:40:09 -080046 // Construct a ChannelManager with the specified media engine and data engine.
47 ChannelManager(std::unique_ptr<MediaEngineInterface> media_engine,
48 std::unique_ptr<DataEngineInterface> data_engine,
49 rtc::Thread* worker_thread,
50 rtc::Thread* network_thread);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051 ~ChannelManager();
52
53 // Accessors for the worker thread, allowing it to be set after construction,
54 // but before Init. set_worker_thread will return false if called after Init.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000055 rtc::Thread* worker_thread() const { return worker_thread_; }
56 bool set_worker_thread(rtc::Thread* thread) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +020057 if (initialized_) {
58 return false;
59 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060 worker_thread_ = thread;
61 return true;
62 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +020063 rtc::Thread* network_thread() const { return network_thread_; }
64 bool set_network_thread(rtc::Thread* thread) {
65 if (initialized_) {
66 return false;
67 }
68 network_thread_ = thread;
69 return true;
70 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071
Fredrik Solenberg709ed672015-09-15 12:26:33 +020072 MediaEngineInterface* media_engine() { return media_engine_.get(); }
73
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074 // Retrieves the list of supported audio & video codec types.
75 // Can be called before starting the media engine.
ossudedfd282016-06-14 07:12:39 -070076 void GetSupportedAudioSendCodecs(std::vector<AudioCodec>* codecs) const;
77 void GetSupportedAudioReceiveCodecs(std::vector<AudioCodec>* codecs) const;
Johannes Kron8e8b36a2020-02-07 14:23:45 +000078 void GetSupportedVideoCodecs(std::vector<VideoCodec>* codecs) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079 void GetSupportedDataCodecs(std::vector<DataCodec>* codecs) const;
Markus Handell0357b3e2020-03-16 13:40:51 +010080 RtpHeaderExtensions GetDefaultEnabledAudioRtpHeaderExtensions() const;
81 std::vector<webrtc::RtpHeaderExtensionCapability>
82 GetSupportedAudioRtpHeaderExtensions() const;
83 RtpHeaderExtensions GetDefaultEnabledVideoRtpHeaderExtensions() const;
84 std::vector<webrtc::RtpHeaderExtensionCapability>
85 GetSupportedVideoRtpHeaderExtensions() const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086
87 // Indicates whether the media engine is started.
88 bool initialized() const { return initialized_; }
89 // Starts up the media engine.
90 bool Init();
91 // Shuts down the media engine.
92 void Terminate();
93
94 // The operations below all occur on the worker thread.
Steve Anton774115c2017-08-30 10:48:46 -070095 // ChannelManager retains ownership of the created channels, so clients should
96 // call the appropriate Destroy*Channel method when done.
97
henrike@webrtc.org28e20752013-07-10 00:45:36 +000098 // Creates a voice channel, to be associated with the specified session.
Anton Sukhanov98a462c2018-10-17 13:15:42 -070099 VoiceChannel* CreateVoiceChannel(
100 webrtc::Call* call,
101 const cricket::MediaConfig& media_config,
102 webrtc::RtpTransportInternal* rtp_transport,
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700103 const webrtc::MediaTransportConfig& media_transport_config,
Anton Sukhanov98a462c2018-10-17 13:15:42 -0700104 rtc::Thread* signaling_thread,
105 const std::string& content_name,
106 bool srtp_required,
107 const webrtc::CryptoOptions& crypto_options,
Amit Hilbuchbcd39d42019-01-25 17:13:56 -0800108 rtc::UniqueRandomIdGenerator* ssrc_generator,
Anton Sukhanov98a462c2018-10-17 13:15:42 -0700109 const AudioOptions& options);
Steve Anton774115c2017-08-30 10:48:46 -0700110 // Destroys a voice channel created by CreateVoiceChannel.
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200111 void DestroyVoiceChannel(VoiceChannel* voice_channel);
Steve Anton774115c2017-08-30 10:48:46 -0700112
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113 // Creates a video channel, synced with the specified voice channel, and
114 // associated with the specified session.
deadbeefe814a0d2017-02-25 18:15:09 -0800115 // Version of the above that takes PacketTransportInternal.
Niels Möller46879152019-01-07 15:54:47 +0100116 VideoChannel* CreateVideoChannel(
117 webrtc::Call* call,
118 const cricket::MediaConfig& media_config,
119 webrtc::RtpTransportInternal* rtp_transport,
Anton Sukhanov4f08faa2019-05-21 11:12:57 -0700120 const webrtc::MediaTransportConfig& media_transport_config,
Niels Möller46879152019-01-07 15:54:47 +0100121 rtc::Thread* signaling_thread,
122 const std::string& content_name,
123 bool srtp_required,
124 const webrtc::CryptoOptions& crypto_options,
Amit Hilbuchbcd39d42019-01-25 17:13:56 -0800125 rtc::UniqueRandomIdGenerator* ssrc_generator,
Jonas Orelanda3aa9bd2019-04-17 07:38:40 +0200126 const VideoOptions& options,
127 webrtc::VideoBitrateAllocatorFactory* video_bitrate_allocator_factory);
Steve Anton774115c2017-08-30 10:48:46 -0700128 // Destroys a video channel created by CreateVideoChannel.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000129 void DestroyVideoChannel(VideoChannel* video_channel);
Steve Anton774115c2017-08-30 10:48:46 -0700130
Zhi Huang2dfc42d2017-12-04 13:38:48 -0800131 RtpDataChannel* CreateRtpDataChannel(
132 const cricket::MediaConfig& media_config,
133 webrtc::RtpTransportInternal* rtp_transport,
134 rtc::Thread* signaling_thread,
135 const std::string& content_name,
Zhi Huange830e682018-03-30 10:48:35 -0700136 bool srtp_required,
Amit Hilbuchbcd39d42019-01-25 17:13:56 -0800137 const webrtc::CryptoOptions& crypto_options,
138 rtc::UniqueRandomIdGenerator* ssrc_generator);
Steve Anton774115c2017-08-30 10:48:46 -0700139 // Destroys a data channel created by CreateRtpDataChannel.
deadbeef953c2ce2017-01-09 14:53:41 -0800140 void DestroyRtpDataChannel(RtpDataChannel* data_channel);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000141
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142 // Indicates whether any channels exist.
143 bool has_channels() const {
Steve Antonc9e15602017-11-06 15:40:09 -0800144 return (!voice_channels_.empty() || !video_channels_.empty() ||
145 !data_channels_.empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000146 }
147
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000148 // RTX will be enabled/disabled in engines that support it. The supporting
149 // engines will start offering an RTX codec. Must be called before Init().
150 bool SetVideoRtxEnabled(bool enable);
151
152 // Starts/stops the local microphone and enables polling of the input level.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153 bool capturing() const { return capturing_; }
154
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 // The operations below occur on the main thread.
156
ivocd66b44d2016-01-15 03:06:36 -0800157 // Starts AEC dump using existing file, with a specified maximum file size in
158 // bytes. When the limit is reached, logging will stop and the file will be
159 // closed. If max_size_bytes is set to <= 0, no limit will be used.
Niels Möllere8e4dc42019-06-11 14:04:16 +0200160 bool StartAecDump(webrtc::FileWrapper file, int64_t max_size_bytes);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000161
ivoc797ef122015-10-22 03:25:41 -0700162 // Stops recording AEC dump.
163 void StopAecDump();
164
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 private:
Steve Antonc9e15602017-11-06 15:40:09 -0800166 std::unique_ptr<MediaEngineInterface> media_engine_; // Nullable.
167 std::unique_ptr<DataEngineInterface> data_engine_; // Non-null.
168 bool initialized_ = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000169 rtc::Thread* main_thread_;
170 rtc::Thread* worker_thread_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200171 rtc::Thread* network_thread_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172
Steve Antonc9e15602017-11-06 15:40:09 -0800173 // Vector contents are non-null.
Steve Anton774115c2017-08-30 10:48:46 -0700174 std::vector<std::unique_ptr<VoiceChannel>> voice_channels_;
175 std::vector<std::unique_ptr<VideoChannel>> video_channels_;
176 std::vector<std::unique_ptr<RtpDataChannel>> data_channels_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177
Steve Antonc9e15602017-11-06 15:40:09 -0800178 bool enable_rtx_ = false;
179 bool capturing_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000180};
181
182} // namespace cricket
183
Steve Anton10542f22019-01-11 09:11:00 -0800184#endif // PC_CHANNEL_MANAGER_H_