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