[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 08:05:01 | [diff] [blame] | 2 | * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 08:05:01 | [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. |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #ifndef PC_CHANNEL_H_ |
| 12 | #define PC_CHANNEL_H_ |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 13 | |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 | [diff] [blame] | 14 | #include <stdint.h> |
| 15 | |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 16 | #include <functional> |
kwiberg | 3102294 | 2016-03-11 22:18:21 | [diff] [blame] | 17 | #include <memory> |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 18 | #include <optional> |
kjellander | a96e2d7 | 2016-02-05 07:52:28 | [diff] [blame] | 19 | #include <string> |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 20 | #include <utility> |
kjellander | a96e2d7 | 2016-02-05 07:52:28 | [diff] [blame] | 21 | #include <vector> |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 22 | |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 23 | #include "absl/strings/string_view.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 | [diff] [blame] | 24 | #include "api/crypto/crypto_options.h" |
Steve Anton | 3828c06 | 2017-12-06 18:34:51 | [diff] [blame] | 25 | #include "api/jsep.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 | [diff] [blame] | 26 | #include "api/media_types.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 27 | #include "api/rtp_parameters.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 | [diff] [blame] | 28 | #include "api/rtp_transceiver_direction.h" |
| 29 | #include "api/scoped_refptr.h" |
Artem Titov | d15a575 | 2021-02-10 13:31:24 | [diff] [blame] | 30 | #include "api/sequence_checker.h" |
Artem Titov | c374d11 | 2022-06-16 19:27:45 | [diff] [blame] | 31 | #include "api/task_queue/pending_task_safety_flag.h" |
Evan Shrubsole | daf96cf | 2025-03-31 12:34:02 | [diff] [blame] | 32 | #include "api/task_queue/task_queue_base.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 | [diff] [blame] | 33 | #include "call/rtp_demuxer.h" |
Zhi Huang | 365381f | 2018-04-13 23:44:34 | [diff] [blame] | 34 | #include "call/rtp_packet_sink_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 35 | #include "media/base/media_channel.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 36 | #include "media/base/stream_params.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 | [diff] [blame] | 37 | #include "modules/rtp_rtcp/source/rtp_packet_received.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 38 | #include "pc/channel_interface.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 | [diff] [blame] | 39 | #include "pc/rtp_transport_internal.h" |
| 40 | #include "pc/session_description.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 | [diff] [blame] | 41 | #include "rtc_base/async_packet_socket.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 | [diff] [blame] | 42 | #include "rtc_base/checks.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 43 | #include "rtc_base/containers/flat_set.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 | [diff] [blame] | 44 | #include "rtc_base/copy_on_write_buffer.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 | [diff] [blame] | 45 | #include "rtc_base/network/sent_packet.h" |
| 46 | #include "rtc_base/network_route.h" |
| 47 | #include "rtc_base/socket.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 | [diff] [blame] | 48 | #include "rtc_base/thread.h" |
Taylor Brandstetter | c03a187 | 2020-09-02 20:25:31 | [diff] [blame] | 49 | #include "rtc_base/thread_annotations.h" |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 50 | #include "rtc_base/unique_id_generator.h" |
Tommi | f888bb5 | 2015-12-12 00:37:01 | [diff] [blame] | 51 | |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 52 | namespace webrtc { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 53 | |
deadbeef | 062ce9f | 2016-08-27 04:42:15 | [diff] [blame] | 54 | // BaseChannel contains logic common to voice and video, including enable, |
| 55 | // marshaling calls to a worker and network threads, and connection and media |
| 56 | // monitors. |
| 57 | // |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 58 | // BaseChannel assumes signaling and other threads are allowed to make |
| 59 | // synchronous calls to the worker thread, the worker thread makes synchronous |
| 60 | // calls only to the network thread, and the network thread can't be blocked by |
| 61 | // other threads. |
| 62 | // All methods with _n suffix must be called on network thread, |
deadbeef | 062ce9f | 2016-08-27 04:42:15 | [diff] [blame] | 63 | // methods with _w suffix on worker thread |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 64 | // and methods with _s suffix on signaling thread. |
| 65 | // Network and worker threads may be the same thread. |
[email protected] | 7818752 | 2013-10-07 23:32:02 | [diff] [blame] | 66 | // |
Harald Alvestrand | 1251c64 | 2023-01-04 12:42:56 | [diff] [blame] | 67 | class VideoChannel; |
| 68 | class VoiceChannel; |
[email protected] | 7818752 | 2013-10-07 23:32:02 | [diff] [blame] | 69 | |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 70 | class BaseChannel : public ChannelInterface, |
Tommi | 99c8a80 | 2021-04-27 13:00:00 | [diff] [blame] | 71 | // TODO(tommi): Consider implementing these interfaces |
| 72 | // via composition. |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 73 | public MediaChannelNetworkInterface, |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 74 | public RtpPacketSinkInterface { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 75 | public: |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 76 | // If `srtp_required` is true, the channel will not send or receive any |
deadbeef | 7af91dd | 2016-12-13 19:29:11 | [diff] [blame] | 77 | // RTP/RTCP packets without using SRTP (either using SDES or DTLS-SRTP). |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 78 | // The BaseChannel does not own the UniqueRandomIdGenerator so it is the |
| 79 | // responsibility of the user to ensure it outlives this object. |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 80 | // TODO(zhihuang:) Create a BaseChannel::Config struct for the parameter lists |
| 81 | // which will make it easier to change the constructor. |
Harald Alvestrand | 2f55370 | 2023-03-07 10:10:03 | [diff] [blame] | 82 | |
| 83 | // Constructor for use when the MediaChannels are split |
Harald Alvestrand | 847208e | 2023-06-06 09:45:45 | [diff] [blame] | 84 | BaseChannel( |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 85 | TaskQueueBase* worker_thread, |
| 86 | Thread* network_thread, |
| 87 | TaskQueueBase* signaling_thread, |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 88 | std::unique_ptr<MediaSendChannelInterface> media_send_channel, |
| 89 | std::unique_ptr<MediaReceiveChannelInterface> media_receive_channel, |
Harald Alvestrand | 847208e | 2023-06-06 09:45:45 | [diff] [blame] | 90 | absl::string_view mid, |
| 91 | bool srtp_required, |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 92 | CryptoOptions crypto_options, |
| 93 | UniqueRandomIdGenerator* ssrc_generator); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 94 | virtual ~BaseChannel(); |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 95 | |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 96 | TaskQueueBase* worker_thread() const { return worker_thread_; } |
| 97 | Thread* network_thread() const { return network_thread_; } |
Tomas Gunnarsson | 5411b17 | 2022-01-24 07:45:26 | [diff] [blame] | 98 | const std::string& mid() const override { return demuxer_criteria_.mid(); } |
deadbeef | f534659 | 2017-01-25 05:51:21 | [diff] [blame] | 99 | // TODO(deadbeef): This is redundant; remove this. |
Tomas Gunnarsson | 94f0194 | 2022-01-03 14:59:12 | [diff] [blame] | 100 | absl::string_view transport_name() const override { |
Tomas Gunnarsson | bfd9ba8 | 2021-04-18 09:55:57 | [diff] [blame] | 101 | RTC_DCHECK_RUN_ON(network_thread()); |
| 102 | if (rtp_transport_) |
| 103 | return rtp_transport_->transport_name(); |
Tomas Gunnarsson | 94f0194 | 2022-01-03 14:59:12 | [diff] [blame] | 104 | return ""; |
Tomas Gunnarsson | bfd9ba8 | 2021-04-18 09:55:57 | [diff] [blame] | 105 | } |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 106 | |
Zhi Huang | cf990f5 | 2017-09-22 19:12:30 | [diff] [blame] | 107 | // This function returns true if using SRTP (DTLS-based keying or SDES). |
Zhi Huang | e830e68 | 2018-03-30 17:48:35 | [diff] [blame] | 108 | bool srtp_active() const { |
Harald Alvestrand | 476859d | 2020-12-07 11:16:45 | [diff] [blame] | 109 | RTC_DCHECK_RUN_ON(network_thread()); |
| 110 | return rtp_transport_ && rtp_transport_->IsSrtpActive(); |
| 111 | } |
| 112 | |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 113 | // Set an RTP level transport which could be an RtpTransport without |
| 114 | // encryption, an SrtpTransport for SDES or a DtlsSrtpTransport for DTLS-SRTP. |
| 115 | // This can be called from any thread and it hops to the network thread |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 116 | // internally. It would replace the `SetTransports` and its variants. |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 117 | bool SetRtpTransport(RtpTransportInternal* rtp_transport) override; |
Zhi Huang | 2dfc42d | 2017-12-04 21:38:48 | [diff] [blame] | 118 | |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 119 | RtpTransportInternal* rtp_transport() const { |
Harald Alvestrand | 476859d | 2020-12-07 11:16:45 | [diff] [blame] | 120 | RTC_DCHECK_RUN_ON(network_thread()); |
| 121 | return rtp_transport_; |
| 122 | } |
| 123 | |
Taylor Brandstetter | d0acbd8 | 2021-01-25 21:44:55 | [diff] [blame] | 124 | // Channel control |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 125 | bool SetLocalContent(const MediaContentDescription* content, |
| 126 | SdpType type, |
Tomas Gunnarsson | d908d74 | 2022-01-05 10:44:26 | [diff] [blame] | 127 | std::string& error_desc) override; |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 128 | bool SetRemoteContent(const MediaContentDescription* content, |
| 129 | SdpType type, |
Tomas Gunnarsson | d908d74 | 2022-01-05 10:44:26 | [diff] [blame] | 130 | std::string& error_desc) override; |
Taylor Brandstetter | c03a187 | 2020-09-02 20:25:31 | [diff] [blame] | 131 | // Controls whether this channel will receive packets on the basis of |
| 132 | // matching payload type alone. This is needed for legacy endpoints that |
| 133 | // don't signal SSRCs or use MID/RID, but doesn't make sense if there is |
| 134 | // more than channel of specific media type, As that creates an ambiguity. |
| 135 | // |
| 136 | // This method will also remove any existing streams that were bound to this |
| 137 | // channel on the basis of payload type, since one of these streams might |
| 138 | // actually belong to a new channel. See: crbug.com/webrtc/11477 |
Taylor Brandstetter | d0acbd8 | 2021-01-25 21:44:55 | [diff] [blame] | 139 | bool SetPayloadTypeDemuxingEnabled(bool enabled) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 140 | |
Tommi | 1959f8f | 2021-04-26 08:20:19 | [diff] [blame] | 141 | void Enable(bool enable) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 142 | |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 143 | const std::vector<StreamParams>& local_streams() const override { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 144 | return local_streams_; |
| 145 | } |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 146 | const std::vector<StreamParams>& remote_streams() const override { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 147 | return remote_streams_; |
| 148 | } |
| 149 | |
[email protected] | 6bfd619 | 2014-05-15 16:15:59 | [diff] [blame] | 150 | // Used for latency measurements. |
Tommi | 99c8a80 | 2021-04-27 13:00:00 | [diff] [blame] | 151 | void SetFirstPacketReceivedCallback(std::function<void()> callback) override; |
Jakob Ivarsson | 68f4e27 | 2024-10-25 14:58:29 | [diff] [blame] | 152 | void SetFirstPacketSentCallback(std::function<void()> callback) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 153 | |
zstein | 56162b9 | 2017-04-24 23:54:35 | [diff] [blame] | 154 | // From RtpTransport - public for testing only |
| 155 | void OnTransportReadyToSend(bool ready); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 156 | |
[email protected] | 4f85288 | 2015-03-12 20:09:44 | [diff] [blame] | 157 | // Only public for unit tests. Otherwise, consider protected. |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 158 | int SetOption(SocketType type, Socket::Option o, int val) override; |
[email protected] | 4f85288 | 2015-03-12 20:09:44 | [diff] [blame] | 159 | |
Zhi Huang | 365381f | 2018-04-13 23:44:34 | [diff] [blame] | 160 | // RtpPacketSinkInterface overrides. |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 161 | void OnRtpPacket(const RtpPacketReceived& packet) override; |
zstein | 3dcf0e9 | 2017-06-01 20:22:42 | [diff] [blame] | 162 | |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 163 | VideoMediaSendChannelInterface* video_media_send_channel() override { |
Harald Alvestrand | 25adc8e | 2022-05-03 13:44:34 | [diff] [blame] | 164 | RTC_CHECK(false) << "Attempt to fetch video channel from non-video"; |
| 165 | return nullptr; |
| 166 | } |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 167 | VoiceMediaSendChannelInterface* voice_media_send_channel() override { |
Harald Alvestrand | 36fafc8 | 2022-12-08 08:47:42 | [diff] [blame] | 168 | RTC_CHECK(false) << "Attempt to fetch voice channel from non-voice"; |
| 169 | return nullptr; |
| 170 | } |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 171 | VideoMediaReceiveChannelInterface* video_media_receive_channel() override { |
Harald Alvestrand | 36fafc8 | 2022-12-08 08:47:42 | [diff] [blame] | 172 | RTC_CHECK(false) << "Attempt to fetch video channel from non-video"; |
| 173 | return nullptr; |
| 174 | } |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 175 | VoiceMediaReceiveChannelInterface* voice_media_receive_channel() override { |
Harald Alvestrand | 25adc8e | 2022-05-03 13:44:34 | [diff] [blame] | 176 | RTC_CHECK(false) << "Attempt to fetch voice channel from non-voice"; |
| 177 | return nullptr; |
| 178 | } |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 179 | |
Amit Hilbuch | dd9390c | 2018-11-14 00:26:05 | [diff] [blame] | 180 | protected: |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 181 | void set_local_content_direction(RtpTransceiverDirection direction) |
Tomas Gunnarsson | b496c32 | 2022-01-05 10:26:36 | [diff] [blame] | 182 | RTC_RUN_ON(worker_thread()) { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 183 | local_content_direction_ = direction; |
| 184 | } |
Tomas Gunnarsson | b496c32 | 2022-01-05 10:26:36 | [diff] [blame] | 185 | |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 186 | RtpTransceiverDirection local_content_direction() const |
Tomas Gunnarsson | b496c32 | 2022-01-05 10:26:36 | [diff] [blame] | 187 | RTC_RUN_ON(worker_thread()) { |
| 188 | return local_content_direction_; |
| 189 | } |
| 190 | |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 191 | void set_remote_content_direction(RtpTransceiverDirection direction) |
Tomas Gunnarsson | b496c32 | 2022-01-05 10:26:36 | [diff] [blame] | 192 | RTC_RUN_ON(worker_thread()) { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 193 | remote_content_direction_ = direction; |
| 194 | } |
Tomas Gunnarsson | b496c32 | 2022-01-05 10:26:36 | [diff] [blame] | 195 | |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 196 | RtpTransceiverDirection remote_content_direction() const |
Tomas Gunnarsson | b496c32 | 2022-01-05 10:26:36 | [diff] [blame] | 197 | RTC_RUN_ON(worker_thread()) { |
| 198 | return remote_content_direction_; |
| 199 | } |
| 200 | |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 201 | RtpExtension::Filter extensions_filter() const { return extensions_filter_; } |
Tomas Gunnarsson | ac72dda | 2022-01-06 10:16:42 | [diff] [blame] | 202 | |
Tomas Gunnarsson | cc9b7ec | 2022-01-16 19:44:25 | [diff] [blame] | 203 | bool network_initialized() RTC_RUN_ON(network_thread()) { |
Harald Alvestrand | 2f55370 | 2023-03-07 10:10:03 | [diff] [blame] | 204 | return media_send_channel()->HasNetworkInterface(); |
Tomas Gunnarsson | cc9b7ec | 2022-01-16 19:44:25 | [diff] [blame] | 205 | } |
| 206 | |
Tomas Gunnarsson | b496c32 | 2022-01-05 10:26:36 | [diff] [blame] | 207 | bool enabled() const RTC_RUN_ON(worker_thread()) { return enabled_; } |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 208 | TaskQueueBase* signaling_thread() const { return signaling_thread_; } |
Tomas Gunnarsson | b496c32 | 2022-01-05 10:26:36 | [diff] [blame] | 209 | |
| 210 | // Call to verify that: |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 211 | // * The required content description directions have been set. |
| 212 | // * The channel is enabled. |
Tomas Gunnarsson | b496c32 | 2022-01-05 10:26:36 | [diff] [blame] | 213 | // * The SRTP filter is active if it's needed. |
| 214 | // * The transport has been writable before, meaning it should be at least |
| 215 | // possible to succeed in sending a packet. |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 216 | // |
| 217 | // When any of these properties change, UpdateMediaSendRecvState_w should be |
| 218 | // called. |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 219 | bool IsReadyToSendMedia_w() const RTC_RUN_ON(worker_thread()); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 220 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 221 | // NetworkInterface implementation, called by MediaEngine |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 222 | bool SendPacket(CopyOnWriteBuffer* packet, |
Evan Shrubsole | e6a1f70 | 2025-04-15 14:55:42 | [diff] [blame] | 223 | const AsyncSocketPacketOptions& options) override; |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 224 | bool SendRtcp(CopyOnWriteBuffer* packet, |
Evan Shrubsole | e6a1f70 | 2025-04-15 14:55:42 | [diff] [blame] | 225 | const AsyncSocketPacketOptions& options) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 226 | |
Zhi Huang | cd3fc5d | 2017-11-29 18:41:57 | [diff] [blame] | 227 | // From RtpTransportInternal |
| 228 | void OnWritableState(bool writable); |
Guo-wei Shieh | 1218d7a | 2015-12-05 17:59:56 | [diff] [blame] | 229 | |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 230 | void OnNetworkRouteChanged(std::optional<NetworkRoute> network_route); |
Honghai Zhang | cc411c0 | 2016-03-30 00:27:21 | [diff] [blame] | 231 | |
stefan | c1aeaf0 | 2015-10-15 14:26:07 | [diff] [blame] | 232 | bool SendPacket(bool rtcp, |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 233 | CopyOnWriteBuffer* packet, |
Evan Shrubsole | e6a1f70 | 2025-04-15 14:55:42 | [diff] [blame] | 234 | const AsyncSocketPacketOptions& options); |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 235 | |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 236 | void EnableMedia_w() RTC_RUN_ON(worker_thread()); |
| 237 | void DisableMedia_w() RTC_RUN_ON(worker_thread()); |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 238 | |
| 239 | // Performs actions if the RTP/RTCP writable state changed. This should |
| 240 | // be called whenever a channel's writable state changes or when RTCP muxing |
| 241 | // becomes active/inactive. |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 242 | void UpdateWritableState_n() RTC_RUN_ON(network_thread()); |
| 243 | void ChannelWritable_n() RTC_RUN_ON(network_thread()); |
| 244 | void ChannelNotWritable_n() RTC_RUN_ON(network_thread()); |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 245 | |
Taylor Brandstetter | d0acbd8 | 2021-01-25 21:44:55 | [diff] [blame] | 246 | bool SetPayloadTypeDemuxingEnabled_w(bool enabled) |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 247 | RTC_RUN_ON(worker_thread()); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 248 | |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 249 | // Should be called whenever the conditions for |
| 250 | // IsReadyToReceiveMedia/IsReadyToSendMedia are satisfied (or unsatisfied). |
| 251 | // Updates the send/recv state of the media channel. |
Niels Möller | db82165 | 2021-02-02 14:14:50 | [diff] [blame] | 252 | virtual void UpdateMediaSendRecvState_w() RTC_RUN_ON(worker_thread()) = 0; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 253 | |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 254 | bool UpdateLocalStreams_w(const std::vector<StreamParams>& streams, |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 255 | SdpType type, |
Tomas Gunnarsson | d908d74 | 2022-01-05 10:44:26 | [diff] [blame] | 256 | std::string& error_desc) |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 257 | RTC_RUN_ON(worker_thread()); |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 258 | bool UpdateRemoteStreams_w(const MediaContentDescription* content, |
| 259 | SdpType type, |
Tomas Gunnarsson | d908d74 | 2022-01-05 10:44:26 | [diff] [blame] | 260 | std::string& error_desc) |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 261 | RTC_RUN_ON(worker_thread()); |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 262 | virtual bool SetLocalContent_w(const MediaContentDescription* content, |
| 263 | SdpType type, |
Tomas Gunnarsson | d908d74 | 2022-01-05 10:44:26 | [diff] [blame] | 264 | std::string& error_desc) |
Niels Möller | db82165 | 2021-02-02 14:14:50 | [diff] [blame] | 265 | RTC_RUN_ON(worker_thread()) = 0; |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 266 | virtual bool SetRemoteContent_w(const MediaContentDescription* content, |
| 267 | SdpType type, |
| 268 | std::string& error_desc) |
| 269 | RTC_RUN_ON(worker_thread()) = 0; |
Lennart Grahl | 0d0ed76 | 2021-05-17 14:06:37 | [diff] [blame] | 270 | |
| 271 | // Returns a list of RTP header extensions where any extension URI is unique. |
| 272 | // Encrypted extensions will be either preferred or discarded, depending on |
| 273 | // the current crypto_options_. |
| 274 | RtpHeaderExtensions GetDeduplicatedRtpHeaderExtensions( |
jbauch | 5869f50 | 2017-06-29 19:31:36 | [diff] [blame] | 275 | const RtpHeaderExtensions& extensions); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 276 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 277 | // Add `payload_type` to `demuxer_criteria_` if payload type demuxing is |
Taylor Brandstetter | c03a187 | 2020-09-02 20:25:31 | [diff] [blame] | 278 | // enabled. |
Tomas Gunnarsson | c69453d | 2022-01-06 12:36:04 | [diff] [blame] | 279 | // Returns true if the demuxer payload type changed and a re-registration |
| 280 | // is needed. |
| 281 | bool MaybeAddHandledPayloadType(int payload_type) RTC_RUN_ON(worker_thread()); |
zstein | 3dcf0e9 | 2017-06-01 20:22:42 | [diff] [blame] | 282 | |
Tomas Gunnarsson | c69453d | 2022-01-06 12:36:04 | [diff] [blame] | 283 | // Returns true if the demuxer payload type criteria was non-empty before |
Tomas Gunnarsson | ac72dda | 2022-01-06 10:16:42 | [diff] [blame] | 284 | // clearing. |
| 285 | bool ClearHandledPayloadTypes() RTC_RUN_ON(worker_thread()); |
Taylor Brandstetter | d0acbd8 | 2021-01-25 21:44:55 | [diff] [blame] | 286 | |
Tomas Gunnarsson | c69453d | 2022-01-06 12:36:04 | [diff] [blame] | 287 | // Hops to the network thread to update the transport if an update is |
| 288 | // requested. If `update_demuxer` is false and `extensions` is not set, the |
| 289 | // function simply returns. If either of these is set, the function updates |
| 290 | // the transport with either or both of the demuxer criteria and the supplied |
| 291 | // rtp header extensions. |
Tommi | 2195d54 | 2022-01-31 19:58:11 | [diff] [blame] | 292 | // Returns `true` if either an update wasn't needed or one was successfully |
| 293 | // applied. If the return value is `false`, then updating the demuxer criteria |
| 294 | // failed, which needs to be treated as an error. |
| 295 | bool MaybeUpdateDemuxerAndRtpExtensions_w( |
Tomas Gunnarsson | c69453d | 2022-01-06 12:36:04 | [diff] [blame] | 296 | bool update_demuxer, |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 297 | std::optional<RtpHeaderExtensions> extensions, |
Tommi | 2195d54 | 2022-01-31 19:58:11 | [diff] [blame] | 298 | std::string& error_desc) RTC_RUN_ON(worker_thread()); |
Taylor Brandstetter | d0acbd8 | 2021-01-25 21:44:55 | [diff] [blame] | 299 | |
| 300 | bool RegisterRtpDemuxerSink_w() RTC_RUN_ON(worker_thread()); |
Taylor Brandstetter | d0acbd8 | 2021-01-25 21:44:55 | [diff] [blame] | 301 | |
Yura Yaroshevich | c325246 | 2020-05-18 10:26:14 | [diff] [blame] | 302 | // Return description of media channel to facilitate logging |
| 303 | std::string ToString() const; |
| 304 | |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 305 | const std::unique_ptr<MediaSendChannelInterface> media_send_channel_; |
| 306 | const std::unique_ptr<MediaReceiveChannelInterface> media_receive_channel_; |
Harald Alvestrand | 2f55370 | 2023-03-07 10:10:03 | [diff] [blame] | 307 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 308 | private: |
Tomas Gunnarsson | b496c32 | 2022-01-05 10:26:36 | [diff] [blame] | 309 | bool ConnectToRtpTransport_n() RTC_RUN_ON(network_thread()); |
| 310 | void DisconnectFromRtpTransport_n() RTC_RUN_ON(network_thread()); |
Evan Shrubsole | e6a1f70 | 2025-04-15 14:55:42 | [diff] [blame] | 311 | void SignalSentPacket_n(const SentPacketInfo& sent_packet); |
Piotr (Peter) Slatala | 179a392 | 2018-11-16 17:57:58 | [diff] [blame] | 312 | |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 313 | TaskQueueBase* const worker_thread_; |
| 314 | Thread* const network_thread_; |
| 315 | TaskQueueBase* const signaling_thread_; |
| 316 | scoped_refptr<PendingTaskSafetyFlag> alive_; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 317 | |
Jakob Ivarsson | 68f4e27 | 2024-10-25 14:58:29 | [diff] [blame] | 318 | // The functions are deleted after they have been called. |
Tommi | 99c8a80 | 2021-04-27 13:00:00 | [diff] [blame] | 319 | std::function<void()> on_first_packet_received_ |
| 320 | RTC_GUARDED_BY(network_thread()); |
Jakob Ivarsson | 68f4e27 | 2024-10-25 14:58:29 | [diff] [blame] | 321 | std::function<void()> on_first_packet_sent_ RTC_GUARDED_BY(network_thread()); |
Tomas Gunnarsson | 33c0ab4 | 2021-01-18 09:49:05 | [diff] [blame] | 322 | |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 323 | RtpTransportInternal* rtp_transport_ RTC_GUARDED_BY(network_thread()) = |
| 324 | nullptr; |
Zhi Huang | cd3fc5d | 2017-11-29 18:41:57 | [diff] [blame] | 325 | |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 326 | std::vector<std::pair<Socket::Option, int> > socket_options_ |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 327 | RTC_GUARDED_BY(network_thread()); |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 328 | std::vector<std::pair<Socket::Option, int> > rtcp_socket_options_ |
Harald Alvestrand | 27883a2 | 2020-11-26 07:24:32 | [diff] [blame] | 329 | RTC_GUARDED_BY(network_thread()); |
Taylor Brandstetter | 2ab9b28 | 2021-02-01 22:39:07 | [diff] [blame] | 330 | bool writable_ RTC_GUARDED_BY(network_thread()) = false; |
| 331 | bool was_ever_writable_n_ RTC_GUARDED_BY(network_thread()) = false; |
| 332 | bool was_ever_writable_ RTC_GUARDED_BY(worker_thread()) = false; |
deadbeef | 7af91dd | 2016-12-13 19:29:11 | [diff] [blame] | 333 | const bool srtp_required_ = true; |
Tommi | cc7a368 | 2021-05-04 12:59:38 | [diff] [blame] | 334 | |
Tomas Gunnarsson | ac72dda | 2022-01-06 10:16:42 | [diff] [blame] | 335 | // Set to either kPreferEncryptedExtension or kDiscardEncryptedExtension |
| 336 | // based on the supplied CryptoOptions. |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 337 | const RtpExtension::Filter extensions_filter_; |
Danil Chapovalov | 33b01f2 | 2016-05-11 17:55:27 | [diff] [blame] | 338 | |
Artem Titov | 880fa81 | 2021-07-30 20:30:23 | [diff] [blame] | 339 | // Currently the `enabled_` flag is accessed from the signaling thread as |
Taylor Brandstetter | bad33bf | 2016-08-25 20:31:14 | [diff] [blame] | 340 | // well, but it can be changed only when signaling thread does a synchronous |
| 341 | // call to the worker thread, so it should be safe. |
Tommi | 1959f8f | 2021-04-26 08:20:19 | [diff] [blame] | 342 | bool enabled_ RTC_GUARDED_BY(worker_thread()) = false; |
| 343 | bool enabled_s_ RTC_GUARDED_BY(signaling_thread()) = false; |
Taylor Brandstetter | c03a187 | 2020-09-02 20:25:31 | [diff] [blame] | 344 | bool payload_type_demuxing_enabled_ RTC_GUARDED_BY(worker_thread()) = true; |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 345 | std::vector<StreamParams> local_streams_ RTC_GUARDED_BY(worker_thread()); |
| 346 | std::vector<StreamParams> remote_streams_ RTC_GUARDED_BY(worker_thread()); |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 347 | RtpTransceiverDirection local_content_direction_ |
| 348 | RTC_GUARDED_BY(worker_thread()) = RtpTransceiverDirection::kInactive; |
| 349 | RtpTransceiverDirection remote_content_direction_ |
| 350 | RTC_GUARDED_BY(worker_thread()) = RtpTransceiverDirection::kInactive; |
Zhi Huang | c99b6c7 | 2017-11-11 00:44:46 | [diff] [blame] | 351 | |
Taylor Brandstetter | d3ef499 | 2020-10-16 01:22:57 | [diff] [blame] | 352 | // Cached list of payload types, used if payload type demuxing is re-enabled. |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 353 | flat_set<uint8_t> payload_types_ RTC_GUARDED_BY(worker_thread()); |
Tomas Gunnarsson | c69453d | 2022-01-06 12:36:04 | [diff] [blame] | 354 | // A stored copy of the rtp header extensions as applied to the transport. |
| 355 | RtpHeaderExtensions rtp_header_extensions_ RTC_GUARDED_BY(worker_thread()); |
Taylor Brandstetter | d0acbd8 | 2021-01-25 21:44:55 | [diff] [blame] | 356 | // TODO(bugs.webrtc.org/12239): Modified on worker thread, accessed |
| 357 | // on network thread in RegisterRtpDemuxerSink_n (called from Init_w) |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 358 | RtpDemuxerCriteria demuxer_criteria_; |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 359 | // This generator is used to generate SSRCs for local streams. |
| 360 | // This is needed in cases where SSRCs are not negotiated or set explicitly |
| 361 | // like in Simulcast. |
| 362 | // This object is not owned by the channel so it must outlive it. |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 363 | UniqueRandomIdGenerator* const ssrc_generator_; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 364 | }; |
| 365 | |
| 366 | // VoiceChannel is a specialization that adds support for early media, DTMF, |
| 367 | // and input/output level monitoring. |
Bjorn A Mellem | 7a9a092 | 2019-11-26 17:19:40 | [diff] [blame] | 368 | class VoiceChannel : public BaseChannel { |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 369 | public: |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 370 | VoiceChannel( |
| 371 | TaskQueueBase* worker_thread, |
| 372 | Thread* network_thread, |
| 373 | TaskQueueBase* signaling_thread, |
| 374 | std::unique_ptr<VoiceMediaSendChannelInterface> send_channel_impl, |
| 375 | std::unique_ptr<VoiceMediaReceiveChannelInterface> receive_channel_impl, |
| 376 | absl::string_view mid, |
| 377 | bool srtp_required, |
| 378 | CryptoOptions crypto_options, |
| 379 | UniqueRandomIdGenerator* ssrc_generator); |
Harald Alvestrand | 2f55370 | 2023-03-07 10:10:03 | [diff] [blame] | 380 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 381 | ~VoiceChannel(); |
solenberg | 1dd98f3 | 2015-09-10 08:57:14 | [diff] [blame] | 382 | |
Harald Alvestrand | 1251c64 | 2023-01-04 12:42:56 | [diff] [blame] | 383 | VideoChannel* AsVideoChannel() override { |
| 384 | RTC_CHECK_NOTREACHED(); |
| 385 | return nullptr; |
| 386 | } |
| 387 | VoiceChannel* AsVoiceChannel() override { return this; } |
| 388 | |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 389 | VoiceMediaSendChannelInterface* send_channel() { |
Florent Castelli | d797cb6 | 2023-06-27 20:07:09 | [diff] [blame] | 390 | return media_send_channel_->AsVoiceSendChannel(); |
Harald Alvestrand | 847208e | 2023-06-06 09:45:45 | [diff] [blame] | 391 | } |
| 392 | |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 393 | VoiceMediaReceiveChannelInterface* receive_channel() { |
Florent Castelli | d797cb6 | 2023-06-27 20:07:09 | [diff] [blame] | 394 | return media_receive_channel_->AsVoiceReceiveChannel(); |
Harald Alvestrand | 847208e | 2023-06-06 09:45:45 | [diff] [blame] | 395 | } |
| 396 | |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 397 | VoiceMediaSendChannelInterface* media_send_channel() override { |
Harald Alvestrand | 847208e | 2023-06-06 09:45:45 | [diff] [blame] | 398 | return send_channel(); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 399 | } |
| 400 | |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 401 | VoiceMediaSendChannelInterface* voice_media_send_channel() override { |
Harald Alvestrand | 847208e | 2023-06-06 09:45:45 | [diff] [blame] | 402 | return send_channel(); |
Harald Alvestrand | 36fafc8 | 2022-12-08 08:47:42 | [diff] [blame] | 403 | } |
| 404 | |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 405 | VoiceMediaReceiveChannelInterface* media_receive_channel() override { |
Harald Alvestrand | 847208e | 2023-06-06 09:45:45 | [diff] [blame] | 406 | return receive_channel(); |
Harald Alvestrand | 36fafc8 | 2022-12-08 08:47:42 | [diff] [blame] | 407 | } |
| 408 | |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 409 | VoiceMediaReceiveChannelInterface* voice_media_receive_channel() override { |
Harald Alvestrand | 847208e | 2023-06-06 09:45:45 | [diff] [blame] | 410 | return receive_channel(); |
Harald Alvestrand | 25adc8e | 2022-05-03 13:44:34 | [diff] [blame] | 411 | } |
| 412 | |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 413 | MediaType media_type() const override { return MediaType::AUDIO; } |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 414 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 415 | private: |
| 416 | // overrides from BaseChannel |
Tomas Gunnarsson | b496c32 | 2022-01-05 10:26:36 | [diff] [blame] | 417 | void UpdateMediaSendRecvState_w() RTC_RUN_ON(worker_thread()) override; |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 418 | bool SetLocalContent_w(const MediaContentDescription* content, |
| 419 | SdpType type, |
Tomas Gunnarsson | d908d74 | 2022-01-05 10:44:26 | [diff] [blame] | 420 | std::string& error_desc) |
Tomas Gunnarsson | b496c32 | 2022-01-05 10:26:36 | [diff] [blame] | 421 | RTC_RUN_ON(worker_thread()) override; |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 422 | bool SetRemoteContent_w(const MediaContentDescription* content, |
| 423 | SdpType type, |
Tomas Gunnarsson | d908d74 | 2022-01-05 10:44:26 | [diff] [blame] | 424 | std::string& error_desc) |
Tomas Gunnarsson | b496c32 | 2022-01-05 10:26:36 | [diff] [blame] | 425 | RTC_RUN_ON(worker_thread()) override; |
Peter Thatcher | c2ee2c8 | 2015-08-07 23:05:34 | [diff] [blame] | 426 | |
Philipp Hancke | a9d5141 | 2023-07-31 11:27:37 | [diff] [blame] | 427 | // Last AudioSenderParameter sent down to the media_channel() via |
Philipp Hancke | 5866e1a | 2023-08-25 13:28:47 | [diff] [blame] | 428 | // SetSenderParameters. |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 429 | AudioSenderParameter last_send_params_ RTC_GUARDED_BY(worker_thread()); |
Philipp Hancke | a9d5141 | 2023-07-31 11:27:37 | [diff] [blame] | 430 | // Last AudioReceiverParameters sent down to the media_channel() via |
Philipp Hancke | 5866e1a | 2023-08-25 13:28:47 | [diff] [blame] | 431 | // SetReceiverParameters. |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 432 | AudioReceiverParameters last_recv_params_ RTC_GUARDED_BY(worker_thread()); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 433 | }; |
| 434 | |
| 435 | // VideoChannel is a specialization for video. |
| 436 | class VideoChannel : public BaseChannel { |
| 437 | public: |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 438 | VideoChannel( |
| 439 | TaskQueueBase* worker_thread, |
| 440 | Thread* network_thread, |
| 441 | TaskQueueBase* signaling_thread, |
| 442 | std::unique_ptr<VideoMediaSendChannelInterface> media_send_channel, |
| 443 | std::unique_ptr<VideoMediaReceiveChannelInterface> media_receive_channel, |
| 444 | absl::string_view mid, |
| 445 | bool srtp_required, |
| 446 | CryptoOptions crypto_options, |
| 447 | UniqueRandomIdGenerator* ssrc_generator); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 448 | ~VideoChannel(); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 449 | |
Harald Alvestrand | 1251c64 | 2023-01-04 12:42:56 | [diff] [blame] | 450 | VideoChannel* AsVideoChannel() override { return this; } |
| 451 | VoiceChannel* AsVoiceChannel() override { |
| 452 | RTC_CHECK_NOTREACHED(); |
| 453 | return nullptr; |
| 454 | } |
| 455 | |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 456 | VideoMediaSendChannelInterface* send_channel() { |
Florent Castelli | d797cb6 | 2023-06-27 20:07:09 | [diff] [blame] | 457 | return media_send_channel_->AsVideoSendChannel(); |
Harald Alvestrand | 847208e | 2023-06-06 09:45:45 | [diff] [blame] | 458 | } |
| 459 | |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 460 | VideoMediaReceiveChannelInterface* receive_channel() { |
Florent Castelli | d797cb6 | 2023-06-27 20:07:09 | [diff] [blame] | 461 | return media_receive_channel_->AsVideoReceiveChannel(); |
Harald Alvestrand | 847208e | 2023-06-06 09:45:45 | [diff] [blame] | 462 | } |
| 463 | |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 464 | VideoMediaSendChannelInterface* media_send_channel() override { |
Harald Alvestrand | 847208e | 2023-06-06 09:45:45 | [diff] [blame] | 465 | return send_channel(); |
Fredrik Solenberg | 4b60c73 | 2015-05-07 12:07:48 | [diff] [blame] | 466 | } |
| 467 | |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 468 | VideoMediaSendChannelInterface* video_media_send_channel() override { |
Harald Alvestrand | 847208e | 2023-06-06 09:45:45 | [diff] [blame] | 469 | return send_channel(); |
Harald Alvestrand | 36fafc8 | 2022-12-08 08:47:42 | [diff] [blame] | 470 | } |
| 471 | |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 472 | VideoMediaReceiveChannelInterface* media_receive_channel() override { |
Harald Alvestrand | 847208e | 2023-06-06 09:45:45 | [diff] [blame] | 473 | return receive_channel(); |
Harald Alvestrand | 36fafc8 | 2022-12-08 08:47:42 | [diff] [blame] | 474 | } |
| 475 | |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 476 | VideoMediaReceiveChannelInterface* video_media_receive_channel() override { |
Harald Alvestrand | 847208e | 2023-06-06 09:45:45 | [diff] [blame] | 477 | return receive_channel(); |
Harald Alvestrand | 25adc8e | 2022-05-03 13:44:34 | [diff] [blame] | 478 | } |
| 479 | |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 480 | MediaType media_type() const override { return MediaType::VIDEO; } |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 481 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 482 | private: |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 483 | // overrides from BaseChannel |
Tomas Gunnarsson | b496c32 | 2022-01-05 10:26:36 | [diff] [blame] | 484 | void UpdateMediaSendRecvState_w() RTC_RUN_ON(worker_thread()) override; |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 485 | bool SetLocalContent_w(const MediaContentDescription* content, |
| 486 | SdpType type, |
Tomas Gunnarsson | d908d74 | 2022-01-05 10:44:26 | [diff] [blame] | 487 | std::string& error_desc) |
Tomas Gunnarsson | b496c32 | 2022-01-05 10:26:36 | [diff] [blame] | 488 | RTC_RUN_ON(worker_thread()) override; |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 489 | bool SetRemoteContent_w(const MediaContentDescription* content, |
| 490 | SdpType type, |
Tomas Gunnarsson | d908d74 | 2022-01-05 10:44:26 | [diff] [blame] | 491 | std::string& error_desc) |
Tomas Gunnarsson | b496c32 | 2022-01-05 10:26:36 | [diff] [blame] | 492 | RTC_RUN_ON(worker_thread()) override; |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 493 | |
Philipp Hancke | a9d5141 | 2023-07-31 11:27:37 | [diff] [blame] | 494 | // Last VideoSenderParameters sent down to the media_channel() via |
Philipp Hancke | 5866e1a | 2023-08-25 13:28:47 | [diff] [blame] | 495 | // SetSenderParameters. |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 496 | VideoSenderParameters last_send_params_ RTC_GUARDED_BY(worker_thread()); |
Philipp Hancke | a9d5141 | 2023-07-31 11:27:37 | [diff] [blame] | 497 | // Last VideoReceiverParameters sent down to the media_channel() via |
Philipp Hancke | 5866e1a | 2023-08-25 13:28:47 | [diff] [blame] | 498 | // SetReceiverParameters. |
Evan Shrubsole | 945e517 | 2025-04-08 14:11:45 | [diff] [blame] | 499 | VideoReceiverParameters last_recv_params_ RTC_GUARDED_BY(worker_thread()); |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 500 | }; |
| 501 | |
Evan Shrubsole | 3c825f1 | 2025-04-04 14:07:27 | [diff] [blame] | 502 | } // namespace webrtc |
| 503 | |
[email protected] | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 504 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 505 | #endif // PC_CHANNEL_H_ |