Thanks to visit codestin.com
Credit goes to webrtc.googlesource.com

blob: 3cd0f919cb919cc08c6bfbda7dc5313416bea87e [file] [log] [blame]
[email protected]28e20752013-07-10 00:45:361/*
kjellander65c7f672016-02-12 08:05:012 * Copyright 2004 The WebRTC project authors. All Rights Reserved.
[email protected]28e20752013-07-10 00:45:363 *
kjellander65c7f672016-02-12 08:05:014 * 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]28e20752013-07-10 00:45:369 */
10
Mirko Bonadei92ea95e2017-09-15 04:47:3111#ifndef PC_CHANNEL_H_
12#define PC_CHANNEL_H_
[email protected]28e20752013-07-10 00:45:3613
Harald Alvestrand5761e7b2021-01-29 14:45:0814#include <stdint.h>
15
Harald Alvestrandc24a2182022-02-23 13:44:5916#include <functional>
kwiberg31022942016-03-11 22:18:2117#include <memory>
Florent Castelli8037fc62024-08-29 13:00:4018#include <optional>
kjellandera96e2d72016-02-05 07:52:2819#include <string>
deadbeefcbecd352015-09-23 18:50:2720#include <utility>
kjellandera96e2d72016-02-05 07:52:2821#include <vector>
[email protected]28e20752013-07-10 00:45:3622
Harald Alvestrandc24a2182022-02-23 13:44:5923#include "absl/strings/string_view.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0824#include "api/crypto/crypto_options.h"
Steve Anton3828c062017-12-06 18:34:5125#include "api/jsep.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0826#include "api/media_types.h"
Harald Alvestrandc24a2182022-02-23 13:44:5927#include "api/rtp_parameters.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0828#include "api/rtp_transceiver_direction.h"
29#include "api/scoped_refptr.h"
Artem Titovd15a5752021-02-10 13:31:2430#include "api/sequence_checker.h"
Artem Titovc374d112022-06-16 19:27:4531#include "api/task_queue/pending_task_safety_flag.h"
Evan Shrubsoledaf96cf2025-03-31 12:34:0232#include "api/task_queue/task_queue_base.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0833#include "call/rtp_demuxer.h"
Zhi Huang365381f2018-04-13 23:44:3434#include "call/rtp_packet_sink_interface.h"
Steve Anton10542f22019-01-11 17:11:0035#include "media/base/media_channel.h"
Steve Anton10542f22019-01-11 17:11:0036#include "media/base/stream_params.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0837#include "modules/rtp_rtcp/source/rtp_packet_received.h"
Steve Anton10542f22019-01-11 17:11:0038#include "pc/channel_interface.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0839#include "pc/rtp_transport_internal.h"
40#include "pc/session_description.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0841#include "rtc_base/async_packet_socket.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0842#include "rtc_base/checks.h"
Harald Alvestrandc24a2182022-02-23 13:44:5943#include "rtc_base/containers/flat_set.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0844#include "rtc_base/copy_on_write_buffer.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0845#include "rtc_base/network/sent_packet.h"
46#include "rtc_base/network_route.h"
47#include "rtc_base/socket.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0848#include "rtc_base/thread.h"
Taylor Brandstetterc03a1872020-09-02 20:25:3149#include "rtc_base/thread_annotations.h"
Amit Hilbuchbcd39d42019-01-26 01:13:5650#include "rtc_base/unique_id_generator.h"
Tommif888bb52015-12-12 00:37:0151
Evan Shrubsole3c825f12025-04-04 14:07:2752namespace webrtc {
[email protected]28e20752013-07-10 00:45:3653
deadbeef062ce9f2016-08-27 04:42:1554// 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 Chapovalov33b01f22016-05-11 17:55:2758// 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,
deadbeef062ce9f2016-08-27 04:42:1563// methods with _w suffix on worker thread
Danil Chapovalov33b01f22016-05-11 17:55:2764// and methods with _s suffix on signaling thread.
65// Network and worker threads may be the same thread.
[email protected]78187522013-10-07 23:32:0266//
Harald Alvestrand1251c642023-01-04 12:42:5667class VideoChannel;
68class VoiceChannel;
[email protected]78187522013-10-07 23:32:0269
Amit Hilbuchdd9390c2018-11-14 00:26:0570class BaseChannel : public ChannelInterface,
Tommi99c8a802021-04-27 13:00:0071 // TODO(tommi): Consider implementing these interfaces
72 // via composition.
Evan Shrubsole945e5172025-04-08 14:11:4573 public MediaChannelNetworkInterface,
Evan Shrubsole3c825f12025-04-04 14:07:2774 public RtpPacketSinkInterface {
[email protected]28e20752013-07-10 00:45:3675 public:
Artem Titov880fa812021-07-30 20:30:2376 // If `srtp_required` is true, the channel will not send or receive any
deadbeef7af91dd2016-12-13 19:29:1177 // RTP/RTCP packets without using SRTP (either using SDES or DTLS-SRTP).
Amit Hilbuchbcd39d42019-01-26 01:13:5678 // The BaseChannel does not own the UniqueRandomIdGenerator so it is the
79 // responsibility of the user to ensure it outlives this object.
Zhi Huange830e682018-03-30 17:48:3580 // TODO(zhihuang:) Create a BaseChannel::Config struct for the parameter lists
81 // which will make it easier to change the constructor.
Harald Alvestrand2f553702023-03-07 10:10:0382
83 // Constructor for use when the MediaChannels are split
Harald Alvestrand847208e2023-06-06 09:45:4584 BaseChannel(
Evan Shrubsole3c825f12025-04-04 14:07:2785 TaskQueueBase* worker_thread,
86 Thread* network_thread,
87 TaskQueueBase* signaling_thread,
Evan Shrubsole945e5172025-04-08 14:11:4588 std::unique_ptr<MediaSendChannelInterface> media_send_channel,
89 std::unique_ptr<MediaReceiveChannelInterface> media_receive_channel,
Harald Alvestrand847208e2023-06-06 09:45:4590 absl::string_view mid,
91 bool srtp_required,
Evan Shrubsole3c825f12025-04-04 14:07:2792 CryptoOptions crypto_options,
93 UniqueRandomIdGenerator* ssrc_generator);
[email protected]28e20752013-07-10 00:45:3694 virtual ~BaseChannel();
Zhi Huang2dfc42d2017-12-04 21:38:4895
Evan Shrubsole3c825f12025-04-04 14:07:2796 TaskQueueBase* worker_thread() const { return worker_thread_; }
97 Thread* network_thread() const { return network_thread_; }
Tomas Gunnarsson5411b172022-01-24 07:45:2698 const std::string& mid() const override { return demuxer_criteria_.mid(); }
deadbeeff5346592017-01-25 05:51:2199 // TODO(deadbeef): This is redundant; remove this.
Tomas Gunnarsson94f01942022-01-03 14:59:12100 absl::string_view transport_name() const override {
Tomas Gunnarssonbfd9ba82021-04-18 09:55:57101 RTC_DCHECK_RUN_ON(network_thread());
102 if (rtp_transport_)
103 return rtp_transport_->transport_name();
Tomas Gunnarsson94f01942022-01-03 14:59:12104 return "";
Tomas Gunnarssonbfd9ba82021-04-18 09:55:57105 }
[email protected]28e20752013-07-10 00:45:36106
Zhi Huangcf990f52017-09-22 19:12:30107 // This function returns true if using SRTP (DTLS-based keying or SDES).
Zhi Huange830e682018-03-30 17:48:35108 bool srtp_active() const {
Harald Alvestrand476859d2020-12-07 11:16:45109 RTC_DCHECK_RUN_ON(network_thread());
110 return rtp_transport_ && rtp_transport_->IsSrtpActive();
111 }
112
Zhi Huang2dfc42d2017-12-04 21:38:48113 // 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 Titov880fa812021-07-30 20:30:23116 // internally. It would replace the `SetTransports` and its variants.
Evan Shrubsole3c825f12025-04-04 14:07:27117 bool SetRtpTransport(RtpTransportInternal* rtp_transport) override;
Zhi Huang2dfc42d2017-12-04 21:38:48118
Evan Shrubsole3c825f12025-04-04 14:07:27119 RtpTransportInternal* rtp_transport() const {
Harald Alvestrand476859d2020-12-07 11:16:45120 RTC_DCHECK_RUN_ON(network_thread());
121 return rtp_transport_;
122 }
123
Taylor Brandstetterd0acbd82021-01-25 21:44:55124 // Channel control
Evan Shrubsole3c825f12025-04-04 14:07:27125 bool SetLocalContent(const MediaContentDescription* content,
126 SdpType type,
Tomas Gunnarssond908d742022-01-05 10:44:26127 std::string& error_desc) override;
Evan Shrubsole3c825f12025-04-04 14:07:27128 bool SetRemoteContent(const MediaContentDescription* content,
129 SdpType type,
Tomas Gunnarssond908d742022-01-05 10:44:26130 std::string& error_desc) override;
Taylor Brandstetterc03a1872020-09-02 20:25:31131 // 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 Brandstetterd0acbd82021-01-25 21:44:55139 bool SetPayloadTypeDemuxingEnabled(bool enabled) override;
[email protected]28e20752013-07-10 00:45:36140
Tommi1959f8f2021-04-26 08:20:19141 void Enable(bool enable) override;
[email protected]28e20752013-07-10 00:45:36142
Evan Shrubsole945e5172025-04-08 14:11:45143 const std::vector<StreamParams>& local_streams() const override {
[email protected]28e20752013-07-10 00:45:36144 return local_streams_;
145 }
Evan Shrubsole945e5172025-04-08 14:11:45146 const std::vector<StreamParams>& remote_streams() const override {
[email protected]28e20752013-07-10 00:45:36147 return remote_streams_;
148 }
149
[email protected]6bfd6192014-05-15 16:15:59150 // Used for latency measurements.
Tommi99c8a802021-04-27 13:00:00151 void SetFirstPacketReceivedCallback(std::function<void()> callback) override;
Jakob Ivarsson68f4e272024-10-25 14:58:29152 void SetFirstPacketSentCallback(std::function<void()> callback) override;
[email protected]28e20752013-07-10 00:45:36153
zstein56162b92017-04-24 23:54:35154 // From RtpTransport - public for testing only
155 void OnTransportReadyToSend(bool ready);
[email protected]28e20752013-07-10 00:45:36156
[email protected]4f852882015-03-12 20:09:44157 // Only public for unit tests. Otherwise, consider protected.
Evan Shrubsole3c825f12025-04-04 14:07:27158 int SetOption(SocketType type, Socket::Option o, int val) override;
[email protected]4f852882015-03-12 20:09:44159
Zhi Huang365381f2018-04-13 23:44:34160 // RtpPacketSinkInterface overrides.
Evan Shrubsole3c825f12025-04-04 14:07:27161 void OnRtpPacket(const RtpPacketReceived& packet) override;
zstein3dcf0e92017-06-01 20:22:42162
Evan Shrubsole945e5172025-04-08 14:11:45163 VideoMediaSendChannelInterface* video_media_send_channel() override {
Harald Alvestrand25adc8e2022-05-03 13:44:34164 RTC_CHECK(false) << "Attempt to fetch video channel from non-video";
165 return nullptr;
166 }
Evan Shrubsole945e5172025-04-08 14:11:45167 VoiceMediaSendChannelInterface* voice_media_send_channel() override {
Harald Alvestrand36fafc82022-12-08 08:47:42168 RTC_CHECK(false) << "Attempt to fetch voice channel from non-voice";
169 return nullptr;
170 }
Evan Shrubsole945e5172025-04-08 14:11:45171 VideoMediaReceiveChannelInterface* video_media_receive_channel() override {
Harald Alvestrand36fafc82022-12-08 08:47:42172 RTC_CHECK(false) << "Attempt to fetch video channel from non-video";
173 return nullptr;
174 }
Evan Shrubsole945e5172025-04-08 14:11:45175 VoiceMediaReceiveChannelInterface* voice_media_receive_channel() override {
Harald Alvestrand25adc8e2022-05-03 13:44:34176 RTC_CHECK(false) << "Attempt to fetch voice channel from non-voice";
177 return nullptr;
178 }
Taylor Brandstetterbad33bf2016-08-25 20:31:14179
Amit Hilbuchdd9390c2018-11-14 00:26:05180 protected:
Evan Shrubsole3c825f12025-04-04 14:07:27181 void set_local_content_direction(RtpTransceiverDirection direction)
Tomas Gunnarssonb496c322022-01-05 10:26:36182 RTC_RUN_ON(worker_thread()) {
[email protected]28e20752013-07-10 00:45:36183 local_content_direction_ = direction;
184 }
Tomas Gunnarssonb496c322022-01-05 10:26:36185
Evan Shrubsole3c825f12025-04-04 14:07:27186 RtpTransceiverDirection local_content_direction() const
Tomas Gunnarssonb496c322022-01-05 10:26:36187 RTC_RUN_ON(worker_thread()) {
188 return local_content_direction_;
189 }
190
Evan Shrubsole3c825f12025-04-04 14:07:27191 void set_remote_content_direction(RtpTransceiverDirection direction)
Tomas Gunnarssonb496c322022-01-05 10:26:36192 RTC_RUN_ON(worker_thread()) {
[email protected]28e20752013-07-10 00:45:36193 remote_content_direction_ = direction;
194 }
Tomas Gunnarssonb496c322022-01-05 10:26:36195
Evan Shrubsole3c825f12025-04-04 14:07:27196 RtpTransceiverDirection remote_content_direction() const
Tomas Gunnarssonb496c322022-01-05 10:26:36197 RTC_RUN_ON(worker_thread()) {
198 return remote_content_direction_;
199 }
200
Evan Shrubsole3c825f12025-04-04 14:07:27201 RtpExtension::Filter extensions_filter() const { return extensions_filter_; }
Tomas Gunnarssonac72dda2022-01-06 10:16:42202
Tomas Gunnarssoncc9b7ec2022-01-16 19:44:25203 bool network_initialized() RTC_RUN_ON(network_thread()) {
Harald Alvestrand2f553702023-03-07 10:10:03204 return media_send_channel()->HasNetworkInterface();
Tomas Gunnarssoncc9b7ec2022-01-16 19:44:25205 }
206
Tomas Gunnarssonb496c322022-01-05 10:26:36207 bool enabled() const RTC_RUN_ON(worker_thread()) { return enabled_; }
Evan Shrubsole3c825f12025-04-04 14:07:27208 TaskQueueBase* signaling_thread() const { return signaling_thread_; }
Tomas Gunnarssonb496c322022-01-05 10:26:36209
210 // Call to verify that:
Taylor Brandstetterbad33bf2016-08-25 20:31:14211 // * The required content description directions have been set.
212 // * The channel is enabled.
Tomas Gunnarssonb496c322022-01-05 10:26:36213 // * 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 Brandstetterbad33bf2016-08-25 20:31:14216 //
217 // When any of these properties change, UpdateMediaSendRecvState_w should be
218 // called.
Harald Alvestrand27883a22020-11-26 07:24:32219 bool IsReadyToSendMedia_w() const RTC_RUN_ON(worker_thread());
[email protected]28e20752013-07-10 00:45:36220
[email protected]28e20752013-07-10 00:45:36221 // NetworkInterface implementation, called by MediaEngine
Evan Shrubsole3c825f12025-04-04 14:07:27222 bool SendPacket(CopyOnWriteBuffer* packet,
Evan Shrubsolee6a1f702025-04-15 14:55:42223 const AsyncSocketPacketOptions& options) override;
Evan Shrubsole3c825f12025-04-04 14:07:27224 bool SendRtcp(CopyOnWriteBuffer* packet,
Evan Shrubsolee6a1f702025-04-15 14:55:42225 const AsyncSocketPacketOptions& options) override;
[email protected]28e20752013-07-10 00:45:36226
Zhi Huangcd3fc5d2017-11-29 18:41:57227 // From RtpTransportInternal
228 void OnWritableState(bool writable);
Guo-wei Shieh1218d7a2015-12-05 17:59:56229
Evan Shrubsole3c825f12025-04-04 14:07:27230 void OnNetworkRouteChanged(std::optional<NetworkRoute> network_route);
Honghai Zhangcc411c02016-03-30 00:27:21231
stefanc1aeaf02015-10-15 14:26:07232 bool SendPacket(bool rtcp,
Evan Shrubsole3c825f12025-04-04 14:07:27233 CopyOnWriteBuffer* packet,
Evan Shrubsolee6a1f702025-04-15 14:55:42234 const AsyncSocketPacketOptions& options);
Danil Chapovalov33b01f22016-05-11 17:55:27235
Harald Alvestrand27883a22020-11-26 07:24:32236 void EnableMedia_w() RTC_RUN_ON(worker_thread());
237 void DisableMedia_w() RTC_RUN_ON(worker_thread());
Taylor Brandstetterbad33bf2016-08-25 20:31:14238
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 Alvestrand27883a22020-11-26 07:24:32242 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 Brandstetterbad33bf2016-08-25 20:31:14245
Taylor Brandstetterd0acbd82021-01-25 21:44:55246 bool SetPayloadTypeDemuxingEnabled_w(bool enabled)
Harald Alvestrand27883a22020-11-26 07:24:32247 RTC_RUN_ON(worker_thread());
[email protected]28e20752013-07-10 00:45:36248
Taylor Brandstetterbad33bf2016-08-25 20:31:14249 // 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öllerdb821652021-02-02 14:14:50252 virtual void UpdateMediaSendRecvState_w() RTC_RUN_ON(worker_thread()) = 0;
[email protected]28e20752013-07-10 00:45:36253
Evan Shrubsole945e5172025-04-08 14:11:45254 bool UpdateLocalStreams_w(const std::vector<StreamParams>& streams,
Evan Shrubsole3c825f12025-04-04 14:07:27255 SdpType type,
Tomas Gunnarssond908d742022-01-05 10:44:26256 std::string& error_desc)
Harald Alvestrand27883a22020-11-26 07:24:32257 RTC_RUN_ON(worker_thread());
Evan Shrubsole3c825f12025-04-04 14:07:27258 bool UpdateRemoteStreams_w(const MediaContentDescription* content,
259 SdpType type,
Tomas Gunnarssond908d742022-01-05 10:44:26260 std::string& error_desc)
Harald Alvestrand27883a22020-11-26 07:24:32261 RTC_RUN_ON(worker_thread());
Evan Shrubsole3c825f12025-04-04 14:07:27262 virtual bool SetLocalContent_w(const MediaContentDescription* content,
263 SdpType type,
Tomas Gunnarssond908d742022-01-05 10:44:26264 std::string& error_desc)
Niels Möllerdb821652021-02-02 14:14:50265 RTC_RUN_ON(worker_thread()) = 0;
Evan Shrubsole3c825f12025-04-04 14:07:27266 virtual bool SetRemoteContent_w(const MediaContentDescription* content,
267 SdpType type,
268 std::string& error_desc)
269 RTC_RUN_ON(worker_thread()) = 0;
Lennart Grahl0d0ed762021-05-17 14:06:37270
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(
jbauch5869f502017-06-29 19:31:36275 const RtpHeaderExtensions& extensions);
[email protected]28e20752013-07-10 00:45:36276
Artem Titov880fa812021-07-30 20:30:23277 // Add `payload_type` to `demuxer_criteria_` if payload type demuxing is
Taylor Brandstetterc03a1872020-09-02 20:25:31278 // enabled.
Tomas Gunnarssonc69453d2022-01-06 12:36:04279 // 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());
zstein3dcf0e92017-06-01 20:22:42282
Tomas Gunnarssonc69453d2022-01-06 12:36:04283 // Returns true if the demuxer payload type criteria was non-empty before
Tomas Gunnarssonac72dda2022-01-06 10:16:42284 // clearing.
285 bool ClearHandledPayloadTypes() RTC_RUN_ON(worker_thread());
Taylor Brandstetterd0acbd82021-01-25 21:44:55286
Tomas Gunnarssonc69453d2022-01-06 12:36:04287 // 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.
Tommi2195d542022-01-31 19:58:11292 // 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 Gunnarssonc69453d2022-01-06 12:36:04296 bool update_demuxer,
Florent Castelli8037fc62024-08-29 13:00:40297 std::optional<RtpHeaderExtensions> extensions,
Tommi2195d542022-01-31 19:58:11298 std::string& error_desc) RTC_RUN_ON(worker_thread());
Taylor Brandstetterd0acbd82021-01-25 21:44:55299
300 bool RegisterRtpDemuxerSink_w() RTC_RUN_ON(worker_thread());
Taylor Brandstetterd0acbd82021-01-25 21:44:55301
Yura Yaroshevichc3252462020-05-18 10:26:14302 // Return description of media channel to facilitate logging
303 std::string ToString() const;
304
Evan Shrubsole945e5172025-04-08 14:11:45305 const std::unique_ptr<MediaSendChannelInterface> media_send_channel_;
306 const std::unique_ptr<MediaReceiveChannelInterface> media_receive_channel_;
Harald Alvestrand2f553702023-03-07 10:10:03307
[email protected]28e20752013-07-10 00:45:36308 private:
Tomas Gunnarssonb496c322022-01-05 10:26:36309 bool ConnectToRtpTransport_n() RTC_RUN_ON(network_thread());
310 void DisconnectFromRtpTransport_n() RTC_RUN_ON(network_thread());
Evan Shrubsolee6a1f702025-04-15 14:55:42311 void SignalSentPacket_n(const SentPacketInfo& sent_packet);
Piotr (Peter) Slatala179a3922018-11-16 17:57:58312
Evan Shrubsole3c825f12025-04-04 14:07:27313 TaskQueueBase* const worker_thread_;
314 Thread* const network_thread_;
315 TaskQueueBase* const signaling_thread_;
316 scoped_refptr<PendingTaskSafetyFlag> alive_;
[email protected]28e20752013-07-10 00:45:36317
Jakob Ivarsson68f4e272024-10-25 14:58:29318 // The functions are deleted after they have been called.
Tommi99c8a802021-04-27 13:00:00319 std::function<void()> on_first_packet_received_
320 RTC_GUARDED_BY(network_thread());
Jakob Ivarsson68f4e272024-10-25 14:58:29321 std::function<void()> on_first_packet_sent_ RTC_GUARDED_BY(network_thread());
Tomas Gunnarsson33c0ab42021-01-18 09:49:05322
Evan Shrubsole3c825f12025-04-04 14:07:27323 RtpTransportInternal* rtp_transport_ RTC_GUARDED_BY(network_thread()) =
324 nullptr;
Zhi Huangcd3fc5d2017-11-29 18:41:57325
Evan Shrubsole3c825f12025-04-04 14:07:27326 std::vector<std::pair<Socket::Option, int> > socket_options_
Harald Alvestrand27883a22020-11-26 07:24:32327 RTC_GUARDED_BY(network_thread());
Evan Shrubsole3c825f12025-04-04 14:07:27328 std::vector<std::pair<Socket::Option, int> > rtcp_socket_options_
Harald Alvestrand27883a22020-11-26 07:24:32329 RTC_GUARDED_BY(network_thread());
Taylor Brandstetter2ab9b282021-02-01 22:39:07330 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;
deadbeef7af91dd2016-12-13 19:29:11333 const bool srtp_required_ = true;
Tommicc7a3682021-05-04 12:59:38334
Tomas Gunnarssonac72dda2022-01-06 10:16:42335 // Set to either kPreferEncryptedExtension or kDiscardEncryptedExtension
336 // based on the supplied CryptoOptions.
Evan Shrubsole3c825f12025-04-04 14:07:27337 const RtpExtension::Filter extensions_filter_;
Danil Chapovalov33b01f22016-05-11 17:55:27338
Artem Titov880fa812021-07-30 20:30:23339 // Currently the `enabled_` flag is accessed from the signaling thread as
Taylor Brandstetterbad33bf2016-08-25 20:31:14340 // well, but it can be changed only when signaling thread does a synchronous
341 // call to the worker thread, so it should be safe.
Tommi1959f8f2021-04-26 08:20:19342 bool enabled_ RTC_GUARDED_BY(worker_thread()) = false;
343 bool enabled_s_ RTC_GUARDED_BY(signaling_thread()) = false;
Taylor Brandstetterc03a1872020-09-02 20:25:31344 bool payload_type_demuxing_enabled_ RTC_GUARDED_BY(worker_thread()) = true;
Evan Shrubsole945e5172025-04-08 14:11:45345 std::vector<StreamParams> local_streams_ RTC_GUARDED_BY(worker_thread());
346 std::vector<StreamParams> remote_streams_ RTC_GUARDED_BY(worker_thread());
Evan Shrubsole3c825f12025-04-04 14:07:27347 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 Huangc99b6c72017-11-11 00:44:46351
Taylor Brandstetterd3ef4992020-10-16 01:22:57352 // Cached list of payload types, used if payload type demuxing is re-enabled.
Evan Shrubsole3c825f12025-04-04 14:07:27353 flat_set<uint8_t> payload_types_ RTC_GUARDED_BY(worker_thread());
Tomas Gunnarssonc69453d2022-01-06 12:36:04354 // A stored copy of the rtp header extensions as applied to the transport.
355 RtpHeaderExtensions rtp_header_extensions_ RTC_GUARDED_BY(worker_thread());
Taylor Brandstetterd0acbd82021-01-25 21:44:55356 // TODO(bugs.webrtc.org/12239): Modified on worker thread, accessed
357 // on network thread in RegisterRtpDemuxerSink_n (called from Init_w)
Evan Shrubsole3c825f12025-04-04 14:07:27358 RtpDemuxerCriteria demuxer_criteria_;
Amit Hilbuchbcd39d42019-01-26 01:13:56359 // 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 Shrubsole3c825f12025-04-04 14:07:27363 UniqueRandomIdGenerator* const ssrc_generator_;
[email protected]28e20752013-07-10 00:45:36364};
365
366// VoiceChannel is a specialization that adds support for early media, DTMF,
367// and input/output level monitoring.
Bjorn A Mellem7a9a0922019-11-26 17:19:40368class VoiceChannel : public BaseChannel {
[email protected]28e20752013-07-10 00:45:36369 public:
Evan Shrubsole945e5172025-04-08 14:11:45370 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 Alvestrand2f553702023-03-07 10:10:03380
[email protected]28e20752013-07-10 00:45:36381 ~VoiceChannel();
solenberg1dd98f32015-09-10 08:57:14382
Harald Alvestrand1251c642023-01-04 12:42:56383 VideoChannel* AsVideoChannel() override {
384 RTC_CHECK_NOTREACHED();
385 return nullptr;
386 }
387 VoiceChannel* AsVoiceChannel() override { return this; }
388
Evan Shrubsole945e5172025-04-08 14:11:45389 VoiceMediaSendChannelInterface* send_channel() {
Florent Castellid797cb62023-06-27 20:07:09390 return media_send_channel_->AsVoiceSendChannel();
Harald Alvestrand847208e2023-06-06 09:45:45391 }
392
Evan Shrubsole945e5172025-04-08 14:11:45393 VoiceMediaReceiveChannelInterface* receive_channel() {
Florent Castellid797cb62023-06-27 20:07:09394 return media_receive_channel_->AsVoiceReceiveChannel();
Harald Alvestrand847208e2023-06-06 09:45:45395 }
396
Evan Shrubsole945e5172025-04-08 14:11:45397 VoiceMediaSendChannelInterface* media_send_channel() override {
Harald Alvestrand847208e2023-06-06 09:45:45398 return send_channel();
[email protected]28e20752013-07-10 00:45:36399 }
400
Evan Shrubsole945e5172025-04-08 14:11:45401 VoiceMediaSendChannelInterface* voice_media_send_channel() override {
Harald Alvestrand847208e2023-06-06 09:45:45402 return send_channel();
Harald Alvestrand36fafc82022-12-08 08:47:42403 }
404
Evan Shrubsole945e5172025-04-08 14:11:45405 VoiceMediaReceiveChannelInterface* media_receive_channel() override {
Harald Alvestrand847208e2023-06-06 09:45:45406 return receive_channel();
Harald Alvestrand36fafc82022-12-08 08:47:42407 }
408
Evan Shrubsole945e5172025-04-08 14:11:45409 VoiceMediaReceiveChannelInterface* voice_media_receive_channel() override {
Harald Alvestrand847208e2023-06-06 09:45:45410 return receive_channel();
Harald Alvestrand25adc8e2022-05-03 13:44:34411 }
412
Evan Shrubsole3c825f12025-04-04 14:07:27413 MediaType media_type() const override { return MediaType::AUDIO; }
[email protected]28e20752013-07-10 00:45:36414
[email protected]28e20752013-07-10 00:45:36415 private:
416 // overrides from BaseChannel
Tomas Gunnarssonb496c322022-01-05 10:26:36417 void UpdateMediaSendRecvState_w() RTC_RUN_ON(worker_thread()) override;
Evan Shrubsole3c825f12025-04-04 14:07:27418 bool SetLocalContent_w(const MediaContentDescription* content,
419 SdpType type,
Tomas Gunnarssond908d742022-01-05 10:44:26420 std::string& error_desc)
Tomas Gunnarssonb496c322022-01-05 10:26:36421 RTC_RUN_ON(worker_thread()) override;
Evan Shrubsole3c825f12025-04-04 14:07:27422 bool SetRemoteContent_w(const MediaContentDescription* content,
423 SdpType type,
Tomas Gunnarssond908d742022-01-05 10:44:26424 std::string& error_desc)
Tomas Gunnarssonb496c322022-01-05 10:26:36425 RTC_RUN_ON(worker_thread()) override;
Peter Thatcherc2ee2c82015-08-07 23:05:34426
Philipp Hanckea9d51412023-07-31 11:27:37427 // Last AudioSenderParameter sent down to the media_channel() via
Philipp Hancke5866e1a2023-08-25 13:28:47428 // SetSenderParameters.
Evan Shrubsole945e5172025-04-08 14:11:45429 AudioSenderParameter last_send_params_ RTC_GUARDED_BY(worker_thread());
Philipp Hanckea9d51412023-07-31 11:27:37430 // Last AudioReceiverParameters sent down to the media_channel() via
Philipp Hancke5866e1a2023-08-25 13:28:47431 // SetReceiverParameters.
Evan Shrubsole945e5172025-04-08 14:11:45432 AudioReceiverParameters last_recv_params_ RTC_GUARDED_BY(worker_thread());
[email protected]28e20752013-07-10 00:45:36433};
434
435// VideoChannel is a specialization for video.
436class VideoChannel : public BaseChannel {
437 public:
Evan Shrubsole945e5172025-04-08 14:11:45438 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]28e20752013-07-10 00:45:36448 ~VideoChannel();
[email protected]28e20752013-07-10 00:45:36449
Harald Alvestrand1251c642023-01-04 12:42:56450 VideoChannel* AsVideoChannel() override { return this; }
451 VoiceChannel* AsVoiceChannel() override {
452 RTC_CHECK_NOTREACHED();
453 return nullptr;
454 }
455
Evan Shrubsole945e5172025-04-08 14:11:45456 VideoMediaSendChannelInterface* send_channel() {
Florent Castellid797cb62023-06-27 20:07:09457 return media_send_channel_->AsVideoSendChannel();
Harald Alvestrand847208e2023-06-06 09:45:45458 }
459
Evan Shrubsole945e5172025-04-08 14:11:45460 VideoMediaReceiveChannelInterface* receive_channel() {
Florent Castellid797cb62023-06-27 20:07:09461 return media_receive_channel_->AsVideoReceiveChannel();
Harald Alvestrand847208e2023-06-06 09:45:45462 }
463
Evan Shrubsole945e5172025-04-08 14:11:45464 VideoMediaSendChannelInterface* media_send_channel() override {
Harald Alvestrand847208e2023-06-06 09:45:45465 return send_channel();
Fredrik Solenberg4b60c732015-05-07 12:07:48466 }
467
Evan Shrubsole945e5172025-04-08 14:11:45468 VideoMediaSendChannelInterface* video_media_send_channel() override {
Harald Alvestrand847208e2023-06-06 09:45:45469 return send_channel();
Harald Alvestrand36fafc82022-12-08 08:47:42470 }
471
Evan Shrubsole945e5172025-04-08 14:11:45472 VideoMediaReceiveChannelInterface* media_receive_channel() override {
Harald Alvestrand847208e2023-06-06 09:45:45473 return receive_channel();
Harald Alvestrand36fafc82022-12-08 08:47:42474 }
475
Evan Shrubsole945e5172025-04-08 14:11:45476 VideoMediaReceiveChannelInterface* video_media_receive_channel() override {
Harald Alvestrand847208e2023-06-06 09:45:45477 return receive_channel();
Harald Alvestrand25adc8e2022-05-03 13:44:34478 }
479
Evan Shrubsole3c825f12025-04-04 14:07:27480 MediaType media_type() const override { return MediaType::VIDEO; }
[email protected]28e20752013-07-10 00:45:36481
[email protected]28e20752013-07-10 00:45:36482 private:
[email protected]28e20752013-07-10 00:45:36483 // overrides from BaseChannel
Tomas Gunnarssonb496c322022-01-05 10:26:36484 void UpdateMediaSendRecvState_w() RTC_RUN_ON(worker_thread()) override;
Evan Shrubsole3c825f12025-04-04 14:07:27485 bool SetLocalContent_w(const MediaContentDescription* content,
486 SdpType type,
Tomas Gunnarssond908d742022-01-05 10:44:26487 std::string& error_desc)
Tomas Gunnarssonb496c322022-01-05 10:26:36488 RTC_RUN_ON(worker_thread()) override;
Evan Shrubsole3c825f12025-04-04 14:07:27489 bool SetRemoteContent_w(const MediaContentDescription* content,
490 SdpType type,
Tomas Gunnarssond908d742022-01-05 10:44:26491 std::string& error_desc)
Tomas Gunnarssonb496c322022-01-05 10:26:36492 RTC_RUN_ON(worker_thread()) override;
[email protected]28e20752013-07-10 00:45:36493
Philipp Hanckea9d51412023-07-31 11:27:37494 // Last VideoSenderParameters sent down to the media_channel() via
Philipp Hancke5866e1a2023-08-25 13:28:47495 // SetSenderParameters.
Evan Shrubsole945e5172025-04-08 14:11:45496 VideoSenderParameters last_send_params_ RTC_GUARDED_BY(worker_thread());
Philipp Hanckea9d51412023-07-31 11:27:37497 // Last VideoReceiverParameters sent down to the media_channel() via
Philipp Hancke5866e1a2023-08-25 13:28:47498 // SetReceiverParameters.
Evan Shrubsole945e5172025-04-08 14:11:45499 VideoReceiverParameters last_recv_params_ RTC_GUARDED_BY(worker_thread());
[email protected]28e20752013-07-10 00:45:36500};
501
Evan Shrubsole3c825f12025-04-04 14:07:27502} // namespace webrtc
503
[email protected]28e20752013-07-10 00:45:36504
Mirko Bonadei92ea95e2017-09-15 04:47:31505#endif // PC_CHANNEL_H_