henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 2 | * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 4 | * 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #ifndef PC_CHANNEL_MANAGER_H_ |
| 12 | #define PC_CHANNEL_MANAGER_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | #include <stdint.h> |
Anton Sukhanov | 4f08faa | 2019-05-21 11:12:57 -0700 | [diff] [blame] | 15 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 16 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 17 | #include <string> |
| 18 | #include <vector> |
| 19 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 20 | #include "api/audio_options.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 21 | #include "api/crypto/crypto_options.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 +0000 | [diff] [blame] | 22 | #include "api/rtp_parameters.h" |
| 23 | #include "api/video/video_bitrate_allocator_factory.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 24 | #include "call/call.h" |
| 25 | #include "media/base/codec.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 26 | #include "media/base/media_channel.h" |
| 27 | #include "media/base/media_config.h" |
| 28 | #include "media/base/media_engine.h" |
Harald Alvestrand | 25adc8e | 2022-05-03 13:44:34 +0000 | [diff] [blame] | 29 | #include "pc/channel_factory_interface.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 30 | #include "pc/channel_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 31 | #include "pc/session_description.h" |
Niels Möller | e8e4dc4 | 2019-06-11 14:04:16 +0200 | [diff] [blame] | 32 | #include "rtc_base/system/file_wrapper.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 33 | #include "rtc_base/thread.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 34 | #include "rtc_base/thread_annotations.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 +0000 | [diff] [blame] | 35 | #include "rtc_base/unique_id_generator.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 36 | |
| 37 | namespace cricket { |
| 38 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 39 | // 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 Gunnarsson | 16de216 | 2022-01-26 10:21:57 +0100 | [diff] [blame] | 47 | class ChannelManager : public ChannelFactoryInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 48 | public: |
Tomas Gunnarsson | 0b5ec18 | 2021-04-01 16:49:42 +0200 | [diff] [blame] | 49 | // 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 Gunnarsson | 0b5ec18 | 2021-04-01 16:49:42 +0200 | [diff] [blame] | 54 | bool enable_rtx, |
| 55 | rtc::Thread* worker_thread, |
| 56 | rtc::Thread* network_thread); |
| 57 | |
| 58 | ChannelManager() = delete; |
Tomas Gunnarsson | 5411b17 | 2022-01-24 08:45:26 +0100 | [diff] [blame] | 59 | ~ChannelManager() override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 60 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 61 | rtc::Thread* worker_thread() const { return worker_thread_; } |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 62 | rtc::Thread* network_thread() const { return network_thread_; } |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 63 | MediaEngineInterface* media_engine() { return media_engine_.get(); } |
Tomas Gunnarsson | 5411b17 | 2022-01-24 08:45:26 +0100 | [diff] [blame] | 64 | rtc::UniqueRandomIdGenerator& ssrc_generator() { return ssrc_generator_; } |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 65 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 66 | // Retrieves the list of supported audio & video codec types. |
| 67 | // Can be called before starting the media engine. |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 68 | void GetSupportedAudioSendCodecs(std::vector<AudioCodec>* codecs) const; |
| 69 | void GetSupportedAudioReceiveCodecs(std::vector<AudioCodec>* codecs) const; |
Johannes Kron | 3e98368 | 2020-03-29 22:17:00 +0200 | [diff] [blame] | 70 | void GetSupportedVideoSendCodecs(std::vector<VideoCodec>* codecs) const; |
| 71 | void GetSupportedVideoReceiveCodecs(std::vector<VideoCodec>* codecs) const; |
Markus Handell | 0357b3e | 2020-03-16 13:40:51 +0100 | [diff] [blame] | 72 | 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 78 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 79 | // The operations below all occur on the worker thread. |
Harald Alvestrand | 3af79d1 | 2022-04-29 15:04:58 +0000 | [diff] [blame] | 80 | // The caller is responsible for ensuring that destruction happens |
| 81 | // on the worker thread. |
Steve Anton | 774115c | 2017-08-30 10:48:46 -0700 | [diff] [blame] | 82 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | // Creates a voice channel, to be associated with the specified session. |
Harald Alvestrand | 3af79d1 | 2022-04-29 15:04:58 +0000 | [diff] [blame] | 84 | std::unique_ptr<VoiceChannel> CreateVoiceChannel( |
| 85 | webrtc::Call* call, |
| 86 | const MediaConfig& media_config, |
Harald Alvestrand | 8f42992 | 2022-05-04 10:32:30 +0000 | [diff] [blame] | 87 | absl::string_view mid, |
Harald Alvestrand | 3af79d1 | 2022-04-29 15:04:58 +0000 | [diff] [blame] | 88 | bool srtp_required, |
| 89 | const webrtc::CryptoOptions& crypto_options, |
| 90 | const AudioOptions& options) override; |
Steve Anton | 774115c | 2017-08-30 10:48:46 -0700 | [diff] [blame] | 91 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 92 | // Creates a video channel, synced with the specified voice channel, and |
| 93 | // associated with the specified session. |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 94 | // Version of the above that takes PacketTransportInternal. |
Harald Alvestrand | 3af79d1 | 2022-04-29 15:04:58 +0000 | [diff] [blame] | 95 | std::unique_ptr<VideoChannel> CreateVideoChannel( |
Niels Möller | 4687915 | 2019-01-07 15:54:47 +0100 | [diff] [blame] | 96 | webrtc::Call* call, |
Tomas Gunnarsson | 0b5ec18 | 2021-04-01 16:49:42 +0200 | [diff] [blame] | 97 | const MediaConfig& media_config, |
Harald Alvestrand | 8f42992 | 2022-05-04 10:32:30 +0000 | [diff] [blame] | 98 | absl::string_view mid, |
Niels Möller | 4687915 | 2019-01-07 15:54:47 +0100 | [diff] [blame] | 99 | bool srtp_required, |
| 100 | const webrtc::CryptoOptions& crypto_options, |
Jonas Oreland | a3aa9bd | 2019-04-17 07:38:40 +0200 | [diff] [blame] | 101 | const VideoOptions& options, |
Tomas Gunnarsson | 5411b17 | 2022-01-24 08:45:26 +0100 | [diff] [blame] | 102 | webrtc::VideoBitrateAllocatorFactory* video_bitrate_allocator_factory) |
| 103 | override; |
| 104 | |
ivoc | d66b44d | 2016-01-15 03:06:36 -0800 | [diff] [blame] | 105 | // 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öller | e8e4dc4 | 2019-06-11 14:04:16 +0200 | [diff] [blame] | 108 | bool StartAecDump(webrtc::FileWrapper file, int64_t max_size_bytes); |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 109 | |
ivoc | 797ef12 | 2015-10-22 03:25:41 -0700 | [diff] [blame] | 110 | // Stops recording AEC dump. |
| 111 | void StopAecDump(); |
| 112 | |
Tomas Gunnarsson | 16de216 | 2022-01-26 10:21:57 +0100 | [diff] [blame] | 113 | protected: |
Tomas Gunnarsson | 0b5ec18 | 2021-04-01 16:49:42 +0200 | [diff] [blame] | 114 | ChannelManager(std::unique_ptr<MediaEngineInterface> media_engine, |
Tomas Gunnarsson | 0b5ec18 | 2021-04-01 16:49:42 +0200 | [diff] [blame] | 115 | bool enable_rtx, |
| 116 | rtc::Thread* worker_thread, |
| 117 | rtc::Thread* network_thread); |
| 118 | |
Tomas Gunnarsson | 5411b17 | 2022-01-24 08:45:26 +0100 | [diff] [blame] | 119 | // 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 Gunnarsson | 16de216 | 2022-01-26 10:21:57 +0100 | [diff] [blame] | 125 | private: |
Tomas Gunnarsson | 0b5ec18 | 2021-04-01 16:49:42 +0200 | [diff] [blame] | 126 | const std::unique_ptr<MediaEngineInterface> media_engine_; // Nullable. |
Tomas Gunnarsson | 5411b17 | 2022-01-24 08:45:26 +0100 | [diff] [blame] | 127 | rtc::Thread* const signaling_thread_; |
Tomas Gunnarsson | b620e2d | 2021-03-30 23:47:49 +0200 | [diff] [blame] | 128 | rtc::Thread* const worker_thread_; |
| 129 | rtc::Thread* const network_thread_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 130 | |
Tomas Gunnarsson | 5411b17 | 2022-01-24 08:45:26 +0100 | [diff] [blame] | 131 | // 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 Gunnarsson | 0b5ec18 | 2021-04-01 16:49:42 +0200 | [diff] [blame] | 137 | const bool enable_rtx_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | } // namespace cricket |
| 141 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 142 | #endif // PC_CHANNEL_MANAGER_H_ |