blob: 38d79ee878c3beae345f3bd8b1b5b5a01411a110 [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>
kwiberg31022942016-03-11 14:18:21 -080015#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016#include <string>
17#include <vector>
18
Yves Gerey3e707812018-11-28 16:47:49 +010019#include "api/audio_options.h"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "api/crypto/crypto_options.h"
Yves Gerey3e707812018-11-28 16:47:49 +010021#include "api/media_transport_interface.h"
22#include "call/call.h"
23#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "media/base/media_channel.h"
25#include "media/base/media_config.h"
26#include "media/base/media_engine.h"
Steve Antonc9e15602017-11-06 15:40:09 -080027#include "pc/channel.h"
Steve Anton10542f22019-01-11 09:11:00 -080028#include "pc/rtp_transport_internal.h"
29#include "pc/session_description.h"
Yves Gerey3e707812018-11-28 16:47:49 +010030#include "rtc_base/platform_file.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "rtc_base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032
33namespace cricket {
34
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035// ChannelManager allows the MediaEngine to run on a separate thread, and takes
36// care of marshalling calls between threads. It also creates and keeps track of
37// voice and video channels; by doing so, it can temporarily pause all the
38// channels when a new audio or video device is chosen. The voice and video
39// channels are stored in separate vectors, to easily allow operations on just
40// voice or just video channels.
41// ChannelManager also allows the application to discover what devices it has
42// using device manager.
Steve Antonc9e15602017-11-06 15:40:09 -080043class ChannelManager final {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044 public:
Steve Antonc9e15602017-11-06 15:40:09 -080045 // Construct a ChannelManager with the specified media engine and data engine.
46 ChannelManager(std::unique_ptr<MediaEngineInterface> media_engine,
47 std::unique_ptr<DataEngineInterface> data_engine,
48 rtc::Thread* worker_thread,
49 rtc::Thread* network_thread);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050 ~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.orgd4e598d2014-07-29 17:36:52 +000054 rtc::Thread* worker_thread() const { return worker_thread_; }
55 bool set_worker_thread(rtc::Thread* thread) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +020056 if (initialized_) {
57 return false;
58 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059 worker_thread_ = thread;
60 return true;
61 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +020062 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.org28e20752013-07-10 00:45:36 +000070
Fredrik Solenberg709ed672015-09-15 12:26:33 +020071 MediaEngineInterface* media_engine() { return media_engine_.get(); }
72
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073 // Retrieves the list of supported audio & video codec types.
74 // Can be called before starting the media engine.
ossudedfd282016-06-14 07:12:39 -070075 void GetSupportedAudioSendCodecs(std::vector<AudioCodec>* codecs) const;
76 void GetSupportedAudioReceiveCodecs(std::vector<AudioCodec>* codecs) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077 void GetSupportedAudioRtpHeaderExtensions(RtpHeaderExtensions* ext) const;
magjed3cf8ece2016-11-10 03:36:53 -080078 void GetSupportedVideoCodecs(std::vector<VideoCodec>* codecs) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079 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.
Steve Anton774115c2017-08-30 10:48:46 -070090 // ChannelManager retains ownership of the created channels, so clients should
91 // call the appropriate Destroy*Channel method when done.
92
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093 // Creates a voice channel, to be associated with the specified session.
Anton Sukhanov98a462c2018-10-17 13:15:42 -070094 VoiceChannel* CreateVoiceChannel(
95 webrtc::Call* call,
96 const cricket::MediaConfig& media_config,
97 webrtc::RtpTransportInternal* rtp_transport,
98 webrtc::MediaTransportInterface* media_transport,
99 rtc::Thread* signaling_thread,
100 const std::string& content_name,
101 bool srtp_required,
102 const webrtc::CryptoOptions& crypto_options,
103 const AudioOptions& options);
Steve Anton774115c2017-08-30 10:48:46 -0700104 // Destroys a voice channel created by CreateVoiceChannel.
Fredrik Solenberg709ed672015-09-15 12:26:33 +0200105 void DestroyVoiceChannel(VoiceChannel* voice_channel);
Steve Anton774115c2017-08-30 10:48:46 -0700106
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107 // Creates a video channel, synced with the specified voice channel, and
108 // associated with the specified session.
deadbeefe814a0d2017-02-25 18:15:09 -0800109 // Version of the above that takes PacketTransportInternal.
Niels Möller46879152019-01-07 15:54:47 +0100110 VideoChannel* CreateVideoChannel(
111 webrtc::Call* call,
112 const cricket::MediaConfig& media_config,
113 webrtc::RtpTransportInternal* rtp_transport,
114 webrtc::MediaTransportInterface* media_transport,
115 rtc::Thread* signaling_thread,
116 const std::string& content_name,
117 bool srtp_required,
118 const webrtc::CryptoOptions& crypto_options,
119 const VideoOptions& options);
Steve Anton774115c2017-08-30 10:48:46 -0700120 // Destroys a video channel created by CreateVideoChannel.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121 void DestroyVideoChannel(VideoChannel* video_channel);
Steve Anton774115c2017-08-30 10:48:46 -0700122
Zhi Huang2dfc42d2017-12-04 13:38:48 -0800123 RtpDataChannel* CreateRtpDataChannel(
124 const cricket::MediaConfig& media_config,
125 webrtc::RtpTransportInternal* rtp_transport,
126 rtc::Thread* signaling_thread,
127 const std::string& content_name,
Zhi Huange830e682018-03-30 10:48:35 -0700128 bool srtp_required,
Benjamin Wrighta54daf12018-10-11 15:33:17 -0700129 const webrtc::CryptoOptions& crypto_options);
Steve Anton774115c2017-08-30 10:48:46 -0700130 // Destroys a data channel created by CreateRtpDataChannel.
deadbeef953c2ce2017-01-09 14:53:41 -0800131 void DestroyRtpDataChannel(RtpDataChannel* data_channel);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000132
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133 // Indicates whether any channels exist.
134 bool has_channels() const {
Steve Antonc9e15602017-11-06 15:40:09 -0800135 return (!voice_channels_.empty() || !video_channels_.empty() ||
136 !data_channels_.empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000137 }
138
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000139 // RTX will be enabled/disabled in engines that support it. The supporting
140 // engines will start offering an RTX codec. Must be called before Init().
141 bool SetVideoRtxEnabled(bool enable);
142
143 // Starts/stops the local microphone and enables polling of the input level.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144 bool capturing() const { return capturing_; }
145
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000146 // The operations below occur on the main thread.
147
ivocd66b44d2016-01-15 03:06:36 -0800148 // Starts AEC dump using existing file, with a specified maximum file size in
149 // bytes. When the limit is reached, logging will stop and the file will be
150 // closed. If max_size_bytes is set to <= 0, no limit will be used.
151 bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000152
ivoc797ef122015-10-22 03:25:41 -0700153 // Stops recording AEC dump.
154 void StopAecDump();
155
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000156 private:
Steve Antonc9e15602017-11-06 15:40:09 -0800157 std::unique_ptr<MediaEngineInterface> media_engine_; // Nullable.
158 std::unique_ptr<DataEngineInterface> data_engine_; // Non-null.
159 bool initialized_ = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000160 rtc::Thread* main_thread_;
161 rtc::Thread* worker_thread_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200162 rtc::Thread* network_thread_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163
Steve Antonc9e15602017-11-06 15:40:09 -0800164 // Vector contents are non-null.
Steve Anton774115c2017-08-30 10:48:46 -0700165 std::vector<std::unique_ptr<VoiceChannel>> voice_channels_;
166 std::vector<std::unique_ptr<VideoChannel>> video_channels_;
167 std::vector<std::unique_ptr<RtpDataChannel>> data_channels_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168
Steve Antonc9e15602017-11-06 15:40:09 -0800169 bool enable_rtx_ = false;
170 bool capturing_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171};
172
173} // namespace cricket
174
Steve Anton10542f22019-01-11 09:11:00 -0800175#endif // PC_CHANNEL_MANAGER_H_