Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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. |
| 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #ifndef PC_RTP_TRANSCEIVER_H_ |
| 12 | #define PC_RTP_TRANSCEIVER_H_ |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 13 | |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 +0000 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 +0000 | [diff] [blame] | 16 | #include <functional> |
Harald Alvestrand | 3af79d1 | 2022-04-29 15:04:58 +0000 | [diff] [blame] | 17 | #include <memory> |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 18 | #include <string> |
| 19 | #include <vector> |
| 20 | |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 +0000 | [diff] [blame] | 21 | #include "absl/types/optional.h" |
| 22 | #include "api/array_view.h" |
Harald Alvestrand | 8f42992 | 2022-05-04 10:32:30 +0000 | [diff] [blame] | 23 | #include "api/audio_options.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 24 | #include "api/jsep.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 +0000 | [diff] [blame] | 25 | #include "api/media_types.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 +0000 | [diff] [blame] | 26 | #include "api/rtc_error.h" |
| 27 | #include "api/rtp_parameters.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 28 | #include "api/rtp_receiver_interface.h" |
| 29 | #include "api/rtp_sender_interface.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 +0000 | [diff] [blame] | 30 | #include "api/rtp_transceiver_direction.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 31 | #include "api/rtp_transceiver_interface.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 +0000 | [diff] [blame] | 32 | #include "api/scoped_refptr.h" |
| 33 | #include "api/task_queue/task_queue_base.h" |
Harald Alvestrand | 8f42992 | 2022-05-04 10:32:30 +0000 | [diff] [blame] | 34 | #include "api/video/video_bitrate_allocator_factory.h" |
| 35 | #include "media/base/media_channel.h" |
Ruslan Burakov | 501bfba | 2019-02-11 10:29:19 +0100 | [diff] [blame] | 36 | #include "pc/channel_interface.h" |
Markus Handell | a1b8201 | 2021-05-26 18:56:30 +0200 | [diff] [blame] | 37 | #include "pc/proxy.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 38 | #include "pc/rtp_receiver.h" |
Markus Handell | e93fe6c | 2021-05-20 22:46:31 +0200 | [diff] [blame] | 39 | #include "pc/rtp_receiver_proxy.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 40 | #include "pc/rtp_sender.h" |
Markus Handell | e93fe6c | 2021-05-20 22:46:31 +0200 | [diff] [blame] | 41 | #include "pc/rtp_sender_proxy.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 42 | #include "pc/rtp_transport_internal.h" |
| 43 | #include "pc/session_description.h" |
Tommi | 99c8a80 | 2021-04-27 15:00:00 +0200 | [diff] [blame] | 44 | #include "rtc_base/task_utils/pending_task_safety_flag.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 +0000 | [diff] [blame] | 45 | #include "rtc_base/third_party/sigslot/sigslot.h" |
| 46 | #include "rtc_base/thread_annotations.h" |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 47 | |
Harald Alvestrand | 9e334b7 | 2022-05-04 13:38:31 +0000 | [diff] [blame] | 48 | namespace cricket { |
| 49 | class ChannelManager; |
| 50 | } |
| 51 | |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 52 | namespace webrtc { |
| 53 | |
Harald Alvestrand | 8f42992 | 2022-05-04 10:32:30 +0000 | [diff] [blame] | 54 | class PeerConnectionSdpMethods; |
| 55 | |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 56 | // Implementation of the public RtpTransceiverInterface. |
| 57 | // |
| 58 | // The RtpTransceiverInterface is only intended to be used with a PeerConnection |
| 59 | // that enables Unified Plan SDP. Thus, the methods that only need to implement |
| 60 | // public API features and are not used internally can assume exactly one sender |
| 61 | // and receiver. |
| 62 | // |
| 63 | // Since the RtpTransceiver is used internally by PeerConnection for tracking |
| 64 | // RtpSenders, RtpReceivers, and BaseChannels, and PeerConnection needs to be |
| 65 | // backwards compatible with Plan B SDP, this implementation is more flexible |
| 66 | // than that required by the WebRTC specification. |
| 67 | // |
| 68 | // With Plan B SDP, an RtpTransceiver can have any number of senders and |
| 69 | // receivers which map to a=ssrc lines in the m= section. |
| 70 | // With Unified Plan SDP, an RtpTransceiver will have exactly one sender and one |
| 71 | // receiver which are encapsulated by the m= section. |
| 72 | // |
| 73 | // This class manages the RtpSenders, RtpReceivers, and BaseChannel associated |
| 74 | // with this m= section. Since the transceiver, senders, and receivers are |
| 75 | // reference counted and can be referenced from JavaScript (in Chromium), these |
| 76 | // objects must be ready to live for an arbitrary amount of time. The |
Harald Alvestrand | 8f42992 | 2022-05-04 10:32:30 +0000 | [diff] [blame] | 77 | // BaseChannel is not reference counted, so |
| 78 | // the PeerConnection must take care of creating/deleting the BaseChannel. |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 79 | // |
| 80 | // The RtpTransceiver is specialized to either audio or video according to the |
| 81 | // MediaType specified in the constructor. Audio RtpTransceivers will have |
| 82 | // AudioRtpSenders, AudioRtpReceivers, and a VoiceChannel. Video RtpTransceivers |
| 83 | // will have VideoRtpSenders, VideoRtpReceivers, and a VideoChannel. |
Tomas Gunnarsson | 0d5ce62 | 2022-03-18 15:57:15 +0100 | [diff] [blame] | 84 | class RtpTransceiver : public RtpTransceiverInterface, |
| 85 | public sigslot::has_slots<> { |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 86 | public: |
Steve Anton | 79e7960 | 2017-11-20 10:25:56 -0800 | [diff] [blame] | 87 | // Construct a Plan B-style RtpTransceiver with no senders, receivers, or |
| 88 | // channel set. |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 89 | // `media_type` specifies the type of RtpTransceiver (and, by transitivity, |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 90 | // the type of senders, receivers, and channel). Can either by audio or video. |
Tommi | 99c8a80 | 2021-04-27 15:00:00 +0200 | [diff] [blame] | 91 | RtpTransceiver(cricket::MediaType media_type, |
| 92 | cricket::ChannelManager* channel_manager); |
Steve Anton | 79e7960 | 2017-11-20 10:25:56 -0800 | [diff] [blame] | 93 | // Construct a Unified Plan-style RtpTransceiver with the given sender and |
| 94 | // receiver. The media type will be derived from the media types of the sender |
| 95 | // and receiver. The sender and receiver should have the same media type. |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 96 | // `HeaderExtensionsToOffer` is used for initializing the return value of |
Markus Handell | 0357b3e | 2020-03-16 13:40:51 +0100 | [diff] [blame] | 97 | // HeaderExtensionsToOffer(). |
Steve Anton | 79e7960 | 2017-11-20 10:25:56 -0800 | [diff] [blame] | 98 | RtpTransceiver( |
| 99 | rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> sender, |
| 100 | rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>> |
Florent Castelli | 2d9d82e | 2019-04-23 19:25:51 +0200 | [diff] [blame] | 101 | receiver, |
Markus Handell | 0357b3e | 2020-03-16 13:40:51 +0100 | [diff] [blame] | 102 | cricket::ChannelManager* channel_manager, |
Harald Alvestrand | 280054f | 2020-11-10 13:12:53 +0000 | [diff] [blame] | 103 | std::vector<RtpHeaderExtensionCapability> HeaderExtensionsToOffer, |
| 104 | std::function<void()> on_negotiation_needed); |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 105 | ~RtpTransceiver() override; |
| 106 | |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 107 | // Returns the Voice/VideoChannel set for this transceiver. May be null if |
| 108 | // the transceiver is not in the currently set local/remote description. |
Harald Alvestrand | 3af79d1 | 2022-04-29 15:04:58 +0000 | [diff] [blame] | 109 | cricket::ChannelInterface* channel() const { return channel_.get(); } |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 110 | |
Harald Alvestrand | 8f42992 | 2022-05-04 10:32:30 +0000 | [diff] [blame] | 111 | // Creates the Voice/VideoChannel and sets it. |
| 112 | RTCError CreateChannel( |
| 113 | absl::string_view mid, |
| 114 | Call* call_ptr, |
| 115 | const cricket::MediaConfig& media_config, |
| 116 | bool srtp_required, |
| 117 | CryptoOptions crypto_options, |
| 118 | const cricket::AudioOptions& audio_options, |
| 119 | const cricket::VideoOptions& video_options, |
| 120 | VideoBitrateAllocatorFactory* video_bitrate_allocator_factory, |
| 121 | std::function<RtpTransportInternal*(absl::string_view)> transport_lookup); |
| 122 | |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 123 | // Sets the Voice/VideoChannel. The caller must pass in the correct channel |
Tomas Gunnarsson | 4f8a58c | 2022-01-19 11:36:23 +0100 | [diff] [blame] | 124 | // implementation based on the type of the transceiver. The call must |
| 125 | // furthermore be made on the signaling thread. |
| 126 | // |
| 127 | // `channel`: The channel instance to be associated with the transceiver. |
Harald Alvestrand | daee870 | 2022-04-29 11:42:55 +0000 | [diff] [blame] | 128 | // This must be a valid pointer. |
| 129 | // The state of the object |
Tomas Gunnarsson | 4f8a58c | 2022-01-19 11:36:23 +0100 | [diff] [blame] | 130 | // is expected to be newly constructed and not initalized for network |
| 131 | // activity (see next parameter for more). |
| 132 | // |
Harald Alvestrand | 3af79d1 | 2022-04-29 15:04:58 +0000 | [diff] [blame] | 133 | // The transceiver takes ownership of `channel`. |
Tomas Gunnarsson | 4f8a58c | 2022-01-19 11:36:23 +0100 | [diff] [blame] | 134 | // |
Harald Alvestrand | daee870 | 2022-04-29 11:42:55 +0000 | [diff] [blame] | 135 | // `transport_lookup`: This |
Tomas Gunnarsson | 4f8a58c | 2022-01-19 11:36:23 +0100 | [diff] [blame] | 136 | // callback function will be used to look up the `RtpTransport` object |
| 137 | // to associate with the channel via `BaseChannel::SetRtpTransport`. |
| 138 | // The lookup function will be called on the network thread, synchronously |
| 139 | // during the call to `SetChannel`. This means that the caller of |
| 140 | // `SetChannel()` may provide a callback function that references state |
| 141 | // that exists within the calling scope of SetChannel (e.g. a variable |
| 142 | // on the stack). |
| 143 | // The reason for this design is to limit the number of times we jump |
| 144 | // synchronously to the network thread from the signaling thread. |
| 145 | // The callback allows us to combine the transport lookup with network |
| 146 | // state initialization of the channel object. |
Harald Alvestrand | daee870 | 2022-04-29 11:42:55 +0000 | [diff] [blame] | 147 | // ClearChannel() must be used before calling SetChannel() again. |
Harald Alvestrand | 3af79d1 | 2022-04-29 15:04:58 +0000 | [diff] [blame] | 148 | void SetChannel(std::unique_ptr<cricket::ChannelInterface> channel, |
Tomas Gunnarsson | 4f8a58c | 2022-01-19 11:36:23 +0100 | [diff] [blame] | 149 | std::function<RtpTransportInternal*(const std::string&)> |
| 150 | transport_lookup); |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 151 | |
Harald Alvestrand | 19ebabc | 2022-04-28 13:31:17 +0000 | [diff] [blame] | 152 | // Clear the association between the transceiver and the channel. |
| 153 | void ClearChannel(); |
| 154 | |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 155 | // Adds an RtpSender of the appropriate type to be owned by this transceiver. |
| 156 | // Must not be null. |
| 157 | void AddSender( |
| 158 | rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> sender); |
| 159 | |
| 160 | // Removes the given RtpSender. Returns false if the sender is not owned by |
| 161 | // this transceiver. |
| 162 | bool RemoveSender(RtpSenderInterface* sender); |
| 163 | |
| 164 | // Returns a vector of the senders owned by this transceiver. |
| 165 | std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>> |
| 166 | senders() const { |
| 167 | return senders_; |
| 168 | } |
| 169 | |
| 170 | // Adds an RtpReceiver of the appropriate type to be owned by this |
| 171 | // transceiver. Must not be null. |
| 172 | void AddReceiver( |
| 173 | rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>> |
| 174 | receiver); |
| 175 | |
| 176 | // Removes the given RtpReceiver. Returns false if the sender is not owned by |
| 177 | // this transceiver. |
| 178 | bool RemoveReceiver(RtpReceiverInterface* receiver); |
| 179 | |
| 180 | // Returns a vector of the receivers owned by this transceiver. |
| 181 | std::vector< |
| 182 | rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>> |
| 183 | receivers() const { |
| 184 | return receivers_; |
| 185 | } |
| 186 | |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 187 | // Returns the backing object for the transceiver's Unified Plan sender. |
| 188 | rtc::scoped_refptr<RtpSenderInternal> sender_internal() const; |
| 189 | |
| 190 | // Returns the backing object for the transceiver's Unified Plan receiver. |
| 191 | rtc::scoped_refptr<RtpReceiverInternal> receiver_internal() const; |
| 192 | |
Steve Anton | dcc3c02 | 2017-12-22 16:02:54 -0800 | [diff] [blame] | 193 | // RtpTransceivers are not associated until they have a corresponding media |
| 194 | // section set in SetLocalDescription or SetRemoteDescription. Therefore, |
| 195 | // when setting a local offer we need a way to remember which transceiver was |
| 196 | // used to create which media section in the offer. Storing the mline index |
| 197 | // in CreateOffer is specified in JSEP to allow us to do that. |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 198 | absl::optional<size_t> mline_index() const { return mline_index_; } |
| 199 | void set_mline_index(absl::optional<size_t> mline_index) { |
Steve Anton | dcc3c02 | 2017-12-22 16:02:54 -0800 | [diff] [blame] | 200 | mline_index_ = mline_index; |
| 201 | } |
| 202 | |
| 203 | // Sets the MID for this transceiver. If the MID is not null, then the |
| 204 | // transceiver is considered "associated" with the media section that has the |
| 205 | // same MID. |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 206 | void set_mid(const absl::optional<std::string>& mid) { mid_ = mid; } |
Steve Anton | dcc3c02 | 2017-12-22 16:02:54 -0800 | [diff] [blame] | 207 | |
| 208 | // Sets the intended direction for this transceiver. Intended to be used |
| 209 | // internally over SetDirection since this does not trigger a negotiation |
| 210 | // needed callback. |
| 211 | void set_direction(RtpTransceiverDirection direction) { |
| 212 | direction_ = direction; |
| 213 | } |
| 214 | |
| 215 | // Sets the current direction for this transceiver as negotiated in an offer/ |
| 216 | // answer exchange. The current direction is null before an answer with this |
| 217 | // transceiver has been set. |
| 218 | void set_current_direction(RtpTransceiverDirection direction); |
| 219 | |
Steve Anton | 0f5400a | 2018-07-17 14:25:36 -0700 | [diff] [blame] | 220 | // Sets the fired direction for this transceiver. The fired direction is null |
| 221 | // until SetRemoteDescription is called or an answer is set (either local or |
Henrik Boström | 0a16276 | 2022-05-02 15:47:52 +0200 | [diff] [blame] | 222 | // remote) after which the only valid reason to go back to null is rollback. |
| 223 | void set_fired_direction(absl::optional<RtpTransceiverDirection> direction); |
Steve Anton | 0f5400a | 2018-07-17 14:25:36 -0700 | [diff] [blame] | 224 | |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 225 | // According to JSEP rules for SetRemoteDescription, RtpTransceivers can be |
| 226 | // reused only if they were added by AddTrack. |
| 227 | void set_created_by_addtrack(bool created_by_addtrack) { |
| 228 | created_by_addtrack_ = created_by_addtrack; |
| 229 | } |
Eldar Rello | 353a718 | 2019-11-25 18:49:44 +0200 | [diff] [blame] | 230 | // If AddTrack has been called then transceiver can't be removed during |
| 231 | // rollback. |
| 232 | void set_reused_for_addtrack(bool reused_for_addtrack) { |
| 233 | reused_for_addtrack_ = reused_for_addtrack; |
| 234 | } |
| 235 | |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 236 | bool created_by_addtrack() const { return created_by_addtrack_; } |
| 237 | |
Eldar Rello | 353a718 | 2019-11-25 18:49:44 +0200 | [diff] [blame] | 238 | bool reused_for_addtrack() const { return reused_for_addtrack_; } |
| 239 | |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 240 | // Returns true if this transceiver has ever had the current direction set to |
| 241 | // sendonly or sendrecv. |
| 242 | bool has_ever_been_used_to_send() const { |
| 243 | return has_ever_been_used_to_send_; |
| 244 | } |
| 245 | |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 246 | // Informs the transceiver that its owning |
| 247 | // PeerConnection is closed. |
| 248 | void SetPeerConnectionClosed(); |
| 249 | |
Harald Alvestrand | c75c428 | 2020-08-26 12:17:54 +0000 | [diff] [blame] | 250 | // Executes the "stop the RTCRtpTransceiver" procedure from |
| 251 | // the webrtc-pc specification, described under the stop() method. |
| 252 | void StopTransceiverProcedure(); |
| 253 | |
Steve Anton | 52d8677 | 2018-02-20 15:48:12 -0800 | [diff] [blame] | 254 | // Fired when the RtpTransceiver state changes such that negotiation is now |
| 255 | // needed (e.g., in response to a direction change). |
Harald Alvestrand | 280054f | 2020-11-10 13:12:53 +0000 | [diff] [blame] | 256 | // sigslot::signal0<> SignalNegotiationNeeded; |
Steve Anton | 52d8677 | 2018-02-20 15:48:12 -0800 | [diff] [blame] | 257 | |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 258 | // RtpTransceiverInterface implementation. |
Steve Anton | 6947025 | 2018-02-09 11:43:08 -0800 | [diff] [blame] | 259 | cricket::MediaType media_type() const override; |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 260 | absl::optional<std::string> mid() const override; |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 261 | rtc::scoped_refptr<RtpSenderInterface> sender() const override; |
| 262 | rtc::scoped_refptr<RtpReceiverInterface> receiver() const override; |
| 263 | bool stopped() const override; |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 264 | bool stopping() const override; |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 265 | RtpTransceiverDirection direction() const override; |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 266 | RTCError SetDirectionWithError( |
| 267 | RtpTransceiverDirection new_direction) override; |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 268 | absl::optional<RtpTransceiverDirection> current_direction() const override; |
Steve Anton | 0f5400a | 2018-07-17 14:25:36 -0700 | [diff] [blame] | 269 | absl::optional<RtpTransceiverDirection> fired_direction() const override; |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 270 | RTCError StopStandard() override; |
| 271 | void StopInternal() override; |
Florent Castelli | 2d9d82e | 2019-04-23 19:25:51 +0200 | [diff] [blame] | 272 | RTCError SetCodecPreferences( |
| 273 | rtc::ArrayView<RtpCodecCapability> codecs) override; |
| 274 | std::vector<RtpCodecCapability> codec_preferences() const override { |
| 275 | return codec_preferences_; |
| 276 | } |
Markus Handell | 0357b3e | 2020-03-16 13:40:51 +0100 | [diff] [blame] | 277 | std::vector<RtpHeaderExtensionCapability> HeaderExtensionsToOffer() |
| 278 | const override; |
Markus Handell | 5932fe1 | 2020-12-17 22:19:40 +0100 | [diff] [blame] | 279 | std::vector<RtpHeaderExtensionCapability> HeaderExtensionsNegotiated() |
| 280 | const override; |
Markus Handell | 755c65d | 2020-06-24 01:06:10 +0200 | [diff] [blame] | 281 | RTCError SetOfferedRtpHeaderExtensions( |
| 282 | rtc::ArrayView<const RtpHeaderExtensionCapability> |
| 283 | header_extensions_to_offer) override; |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 284 | |
Tommi | cc7a368 | 2021-05-04 14:59:38 +0200 | [diff] [blame] | 285 | // Called on the signaling thread when the local or remote content description |
| 286 | // is updated. Used to update the negotiated header extensions. |
| 287 | // TODO(tommi): The implementation of this method is currently very simple and |
| 288 | // only used for updating the negotiated headers. However, we're planning to |
| 289 | // move all the updates done on the channel from the transceiver into this |
| 290 | // method. This will happen with the ownership of the channel object being |
| 291 | // moved into the transceiver. |
| 292 | void OnNegotiationUpdate(SdpType sdp_type, |
| 293 | const cricket::MediaContentDescription* content); |
| 294 | |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 295 | private: |
Tommi | 99c8a80 | 2021-04-27 15:00:00 +0200 | [diff] [blame] | 296 | void OnFirstPacketReceived(); |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 297 | void StopSendingAndReceiving(); |
Harald Alvestrand | daee870 | 2022-04-29 11:42:55 +0000 | [diff] [blame] | 298 | // Delete a channel, and ensure that references to its media channel |
| 299 | // are updated before deleting it. |
| 300 | void PushNewMediaChannelAndDeleteChannel( |
Harald Alvestrand | 3af79d1 | 2022-04-29 15:04:58 +0000 | [diff] [blame] | 301 | std::unique_ptr<cricket::ChannelInterface> channel_to_delete); |
Steve Anton | 6077675 | 2018-01-10 11:51:34 -0800 | [diff] [blame] | 302 | |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 303 | // Enforce that this object is created, used and destroyed on one thread. |
Tommi | 99c8a80 | 2021-04-27 15:00:00 +0200 | [diff] [blame] | 304 | TaskQueueBase* const thread_; |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 305 | const bool unified_plan_; |
| 306 | const cricket::MediaType media_type_; |
Tommi | 99c8a80 | 2021-04-27 15:00:00 +0200 | [diff] [blame] | 307 | rtc::scoped_refptr<PendingTaskSafetyFlag> signaling_thread_safety_; |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 308 | std::vector<rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>>> |
| 309 | senders_; |
| 310 | std::vector< |
| 311 | rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>> |
| 312 | receivers_; |
| 313 | |
Tommi | 99c8a80 | 2021-04-27 15:00:00 +0200 | [diff] [blame] | 314 | bool stopped_ RTC_GUARDED_BY(thread_) = false; |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 315 | bool stopping_ RTC_GUARDED_BY(thread_) = false; |
| 316 | bool is_pc_closed_ = false; |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 317 | RtpTransceiverDirection direction_ = RtpTransceiverDirection::kInactive; |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 318 | absl::optional<RtpTransceiverDirection> current_direction_; |
Steve Anton | 0f5400a | 2018-07-17 14:25:36 -0700 | [diff] [blame] | 319 | absl::optional<RtpTransceiverDirection> fired_direction_; |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 320 | absl::optional<std::string> mid_; |
| 321 | absl::optional<size_t> mline_index_; |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 322 | bool created_by_addtrack_ = false; |
Eldar Rello | 353a718 | 2019-11-25 18:49:44 +0200 | [diff] [blame] | 323 | bool reused_for_addtrack_ = false; |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 324 | bool has_ever_been_used_to_send_ = false; |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 325 | |
Harald Alvestrand | 19ebabc | 2022-04-28 13:31:17 +0000 | [diff] [blame] | 326 | // Accessed on both thread_ and the network thread. Considered safe |
| 327 | // because all access on the network thread is within an invoke() |
| 328 | // from thread_. |
Harald Alvestrand | 3af79d1 | 2022-04-29 15:04:58 +0000 | [diff] [blame] | 329 | std::unique_ptr<cricket::ChannelInterface> channel_ = nullptr; |
Florent Castelli | 2d9d82e | 2019-04-23 19:25:51 +0200 | [diff] [blame] | 330 | cricket::ChannelManager* channel_manager_ = nullptr; |
| 331 | std::vector<RtpCodecCapability> codec_preferences_; |
Markus Handell | 755c65d | 2020-06-24 01:06:10 +0200 | [diff] [blame] | 332 | std::vector<RtpHeaderExtensionCapability> header_extensions_to_offer_; |
Tommi | cc7a368 | 2021-05-04 14:59:38 +0200 | [diff] [blame] | 333 | |
Artem Titov | 880fa81 | 2021-07-30 22:30:23 +0200 | [diff] [blame] | 334 | // `negotiated_header_extensions_` is read and written to on the signaling |
Tommi | cc7a368 | 2021-05-04 14:59:38 +0200 | [diff] [blame] | 335 | // thread from the SdpOfferAnswerHandler class (e.g. |
| 336 | // PushdownMediaDescription(). |
| 337 | cricket::RtpHeaderExtensions negotiated_header_extensions_ |
| 338 | RTC_GUARDED_BY(thread_); |
| 339 | |
Harald Alvestrand | 280054f | 2020-11-10 13:12:53 +0000 | [diff] [blame] | 340 | const std::function<void()> on_negotiation_needed_; |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 341 | }; |
| 342 | |
Mirko Bonadei | 9d9b8de | 2021-02-26 09:51:26 +0100 | [diff] [blame] | 343 | BEGIN_PRIMARY_PROXY_MAP(RtpTransceiver) |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 +0000 | [diff] [blame] | 344 | |
Mirko Bonadei | 9d9b8de | 2021-02-26 09:51:26 +0100 | [diff] [blame] | 345 | PROXY_PRIMARY_THREAD_DESTRUCTOR() |
Tomas Gunnarsson | fc83cdc | 2020-09-10 13:04:50 +0200 | [diff] [blame] | 346 | BYPASS_PROXY_CONSTMETHOD0(cricket::MediaType, media_type) |
Nico Weber | 22f9925 | 2019-02-20 10:13:16 -0500 | [diff] [blame] | 347 | PROXY_CONSTMETHOD0(absl::optional<std::string>, mid) |
| 348 | PROXY_CONSTMETHOD0(rtc::scoped_refptr<RtpSenderInterface>, sender) |
| 349 | PROXY_CONSTMETHOD0(rtc::scoped_refptr<RtpReceiverInterface>, receiver) |
| 350 | PROXY_CONSTMETHOD0(bool, stopped) |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 351 | PROXY_CONSTMETHOD0(bool, stopping) |
Nico Weber | 22f9925 | 2019-02-20 10:13:16 -0500 | [diff] [blame] | 352 | PROXY_CONSTMETHOD0(RtpTransceiverDirection, direction) |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 353 | PROXY_METHOD1(webrtc::RTCError, SetDirectionWithError, RtpTransceiverDirection) |
Nico Weber | 22f9925 | 2019-02-20 10:13:16 -0500 | [diff] [blame] | 354 | PROXY_CONSTMETHOD0(absl::optional<RtpTransceiverDirection>, current_direction) |
| 355 | PROXY_CONSTMETHOD0(absl::optional<RtpTransceiverDirection>, fired_direction) |
Harald Alvestrand | 6060df5 | 2020-08-11 09:54:02 +0200 | [diff] [blame] | 356 | PROXY_METHOD0(webrtc::RTCError, StopStandard) |
| 357 | PROXY_METHOD0(void, StopInternal) |
Florent Castelli | 2d9d82e | 2019-04-23 19:25:51 +0200 | [diff] [blame] | 358 | PROXY_METHOD1(webrtc::RTCError, |
| 359 | SetCodecPreferences, |
| 360 | rtc::ArrayView<RtpCodecCapability>) |
| 361 | PROXY_CONSTMETHOD0(std::vector<RtpCodecCapability>, codec_preferences) |
Markus Handell | 0357b3e | 2020-03-16 13:40:51 +0100 | [diff] [blame] | 362 | PROXY_CONSTMETHOD0(std::vector<RtpHeaderExtensionCapability>, |
| 363 | HeaderExtensionsToOffer) |
Markus Handell | 5932fe1 | 2020-12-17 22:19:40 +0100 | [diff] [blame] | 364 | PROXY_CONSTMETHOD0(std::vector<RtpHeaderExtensionCapability>, |
| 365 | HeaderExtensionsNegotiated) |
Markus Handell | 755c65d | 2020-06-24 01:06:10 +0200 | [diff] [blame] | 366 | PROXY_METHOD1(webrtc::RTCError, |
| 367 | SetOfferedRtpHeaderExtensions, |
| 368 | rtc::ArrayView<const RtpHeaderExtensionCapability>) |
Markus Handell | 3d46d0b | 2021-05-27 21:42:57 +0200 | [diff] [blame] | 369 | END_PROXY_MAP(RtpTransceiver) |
Steve Anton | 6e634bf | 2017-11-13 10:44:53 -0800 | [diff] [blame] | 370 | |
| 371 | } // namespace webrtc |
| 372 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 373 | #endif // PC_RTP_TRANSCEIVER_H_ |