blob: 8d1ec2800158041e900df93e1f2a1decd7c1b595 [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"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000022#include "api/rtp_parameters.h"
23#include "api/video/video_bitrate_allocator_factory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010024#include "call/call.h"
25#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "media/base/media_channel.h"
27#include "media/base/media_config.h"
28#include "media/base/media_engine.h"
Harald Alvestrand25adc8e2022-05-03 13:44:34 +000029#include "pc/channel_factory_interface.h"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000030#include "pc/channel_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080031#include "pc/session_description.h"
Niels Möllere8e4dc42019-06-11 14:04:16 +020032#include "rtc_base/system/file_wrapper.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020033#include "rtc_base/thread.h"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000034#include "rtc_base/thread_annotations.h"
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000035#include "rtc_base/unique_id_generator.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036
37namespace cricket {
38
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039// ChannelManager allows the MediaEngine to run on a separate thread, and takes
40// care of marshalling calls between threads. It also creates and keeps track of
41// voice and video channels; by doing so, it can temporarily pause all the
42// channels when a new audio or video device is chosen. The voice and video
43// channels are stored in separate vectors, to easily allow operations on just
44// voice or just video channels.
45// ChannelManager also allows the application to discover what devices it has
46// using device manager.
Tomas Gunnarsson16de2162022-01-26 10:21:57 +010047class ChannelManager : public ChannelFactoryInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048 public:
Tomas Gunnarsson0b5ec182021-04-01 16:49:42 +020049 // Returns an initialized instance of ChannelManager.
50 // If media_engine is non-nullptr, then the returned ChannelManager instance
51 // will own that reference and media engine initialization
52 static std::unique_ptr<ChannelManager> Create(
53 std::unique_ptr<MediaEngineInterface> media_engine,
Tomas Gunnarsson0b5ec182021-04-01 16:49:42 +020054 bool enable_rtx,
55 rtc::Thread* worker_thread,
56 rtc::Thread* network_thread);
57
58 ChannelManager() = delete;
Tomas Gunnarsson5411b172022-01-24 08:45:26 +010059 ~ChannelManager() override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000061 rtc::Thread* worker_thread() const { return worker_thread_; }
Danil Chapovalov33b01f22016-05-11 19:55:27 +020062 rtc::Thread* network_thread() const { return network_thread_; }
Fredrik Solenberg709ed672015-09-15 12:26:33 +020063 MediaEngineInterface* media_engine() { return media_engine_.get(); }
Tomas Gunnarsson5411b172022-01-24 08:45:26 +010064 rtc::UniqueRandomIdGenerator& ssrc_generator() { return ssrc_generator_; }
Fredrik Solenberg709ed672015-09-15 12:26:33 +020065
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066 // Retrieves the list of supported audio & video codec types.
67 // Can be called before starting the media engine.
ossudedfd282016-06-14 07:12:39 -070068 void GetSupportedAudioSendCodecs(std::vector<AudioCodec>* codecs) const;
69 void GetSupportedAudioReceiveCodecs(std::vector<AudioCodec>* codecs) const;
Johannes Kron3e983682020-03-29 22:17:00 +020070 void GetSupportedVideoSendCodecs(std::vector<VideoCodec>* codecs) const;
71 void GetSupportedVideoReceiveCodecs(std::vector<VideoCodec>* codecs) const;
Markus Handell0357b3e2020-03-16 13:40:51 +010072 RtpHeaderExtensions GetDefaultEnabledAudioRtpHeaderExtensions() const;
73 std::vector<webrtc::RtpHeaderExtensionCapability>
74 GetSupportedAudioRtpHeaderExtensions() const;
75 RtpHeaderExtensions GetDefaultEnabledVideoRtpHeaderExtensions() const;
76 std::vector<webrtc::RtpHeaderExtensionCapability>
77 GetSupportedVideoRtpHeaderExtensions() const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079 // The operations below all occur on the worker thread.
Harald Alvestrand3af79d12022-04-29 15:04:58 +000080 // The caller is responsible for ensuring that destruction happens
81 // on the worker thread.
Steve Anton774115c2017-08-30 10:48:46 -070082
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083 // Creates a voice channel, to be associated with the specified session.
Harald Alvestrand3af79d12022-04-29 15:04:58 +000084 std::unique_ptr<VoiceChannel> CreateVoiceChannel(
85 webrtc::Call* call,
86 const MediaConfig& media_config,
Harald Alvestrand8f429922022-05-04 10:32:30 +000087 absl::string_view mid,
Harald Alvestrand3af79d12022-04-29 15:04:58 +000088 bool srtp_required,
89 const webrtc::CryptoOptions& crypto_options,
90 const AudioOptions& options) override;
Steve Anton774115c2017-08-30 10:48:46 -070091
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092 // Creates a video channel, synced with the specified voice channel, and
93 // associated with the specified session.
deadbeefe814a0d2017-02-25 18:15:09 -080094 // Version of the above that takes PacketTransportInternal.
Harald Alvestrand3af79d12022-04-29 15:04:58 +000095 std::unique_ptr<VideoChannel> CreateVideoChannel(
Niels Möller46879152019-01-07 15:54:47 +010096 webrtc::Call* call,
Tomas Gunnarsson0b5ec182021-04-01 16:49:42 +020097 const MediaConfig& media_config,
Harald Alvestrand8f429922022-05-04 10:32:30 +000098 absl::string_view mid,
Niels Möller46879152019-01-07 15:54:47 +010099 bool srtp_required,
100 const webrtc::CryptoOptions& crypto_options,
Jonas Orelanda3aa9bd2019-04-17 07:38:40 +0200101 const VideoOptions& options,
Tomas Gunnarsson5411b172022-01-24 08:45:26 +0100102 webrtc::VideoBitrateAllocatorFactory* video_bitrate_allocator_factory)
103 override;
104
ivocd66b44d2016-01-15 03:06:36 -0800105 // Starts AEC dump using existing file, with a specified maximum file size in
106 // bytes. When the limit is reached, logging will stop and the file will be
107 // closed. If max_size_bytes is set to <= 0, no limit will be used.
Niels Möllere8e4dc42019-06-11 14:04:16 +0200108 bool StartAecDump(webrtc::FileWrapper file, int64_t max_size_bytes);
wu@webrtc.orga9890802013-12-13 00:21:03 +0000109
ivoc797ef122015-10-22 03:25:41 -0700110 // Stops recording AEC dump.
111 void StopAecDump();
112
Tomas Gunnarsson16de2162022-01-26 10:21:57 +0100113 protected:
Tomas Gunnarsson0b5ec182021-04-01 16:49:42 +0200114 ChannelManager(std::unique_ptr<MediaEngineInterface> media_engine,
Tomas Gunnarsson0b5ec182021-04-01 16:49:42 +0200115 bool enable_rtx,
116 rtc::Thread* worker_thread,
117 rtc::Thread* network_thread);
118
Tomas Gunnarsson5411b172022-01-24 08:45:26 +0100119 // Destroys a voice channel created by CreateVoiceChannel.
120 void DestroyVoiceChannel(VoiceChannel* voice_channel);
121
122 // Destroys a video channel created by CreateVideoChannel.
123 void DestroyVideoChannel(VideoChannel* video_channel);
124
Tomas Gunnarsson16de2162022-01-26 10:21:57 +0100125 private:
Tomas Gunnarsson0b5ec182021-04-01 16:49:42 +0200126 const std::unique_ptr<MediaEngineInterface> media_engine_; // Nullable.
Tomas Gunnarsson5411b172022-01-24 08:45:26 +0100127 rtc::Thread* const signaling_thread_;
Tomas Gunnarssonb620e2d2021-03-30 23:47:49 +0200128 rtc::Thread* const worker_thread_;
129 rtc::Thread* const network_thread_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130
Tomas Gunnarsson5411b172022-01-24 08:45:26 +0100131 // This object should be used to generate any SSRC that is not explicitly
132 // specified by the user (or by the remote party).
133 // TODO(bugs.webrtc.org/12666): This variable is used from both the signaling
134 // and worker threads. See if we can't restrict usage to a single thread.
135 rtc::UniqueRandomIdGenerator ssrc_generator_;
136
Tomas Gunnarsson0b5ec182021-04-01 16:49:42 +0200137 const bool enable_rtx_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138};
139
140} // namespace cricket
141
Steve Anton10542f22019-01-11 09:11:00 -0800142#endif // PC_CHANNEL_MANAGER_H_