xref: /aosp_15_r20/external/webrtc/api/rtp_transceiver_interface.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 API_RTP_TRANSCEIVER_INTERFACE_H_
12*d9f75844SAndroid Build Coastguard Worker #define API_RTP_TRANSCEIVER_INTERFACE_H_
13*d9f75844SAndroid Build Coastguard Worker 
14*d9f75844SAndroid Build Coastguard Worker #include <string>
15*d9f75844SAndroid Build Coastguard Worker #include <vector>
16*d9f75844SAndroid Build Coastguard Worker 
17*d9f75844SAndroid Build Coastguard Worker #include "absl/base/attributes.h"
18*d9f75844SAndroid Build Coastguard Worker #include "absl/types/optional.h"
19*d9f75844SAndroid Build Coastguard Worker #include "api/array_view.h"
20*d9f75844SAndroid Build Coastguard Worker #include "api/media_types.h"
21*d9f75844SAndroid Build Coastguard Worker #include "api/rtp_parameters.h"
22*d9f75844SAndroid Build Coastguard Worker #include "api/rtp_receiver_interface.h"
23*d9f75844SAndroid Build Coastguard Worker #include "api/rtp_sender_interface.h"
24*d9f75844SAndroid Build Coastguard Worker #include "api/rtp_transceiver_direction.h"
25*d9f75844SAndroid Build Coastguard Worker #include "api/scoped_refptr.h"
26*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/ref_count.h"
27*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/system/rtc_export.h"
28*d9f75844SAndroid Build Coastguard Worker 
29*d9f75844SAndroid Build Coastguard Worker namespace webrtc {
30*d9f75844SAndroid Build Coastguard Worker 
31*d9f75844SAndroid Build Coastguard Worker // Structure for initializing an RtpTransceiver in a call to
32*d9f75844SAndroid Build Coastguard Worker // PeerConnectionInterface::AddTransceiver.
33*d9f75844SAndroid Build Coastguard Worker // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiverinit
34*d9f75844SAndroid Build Coastguard Worker struct RTC_EXPORT RtpTransceiverInit final {
35*d9f75844SAndroid Build Coastguard Worker   RtpTransceiverInit();
36*d9f75844SAndroid Build Coastguard Worker   RtpTransceiverInit(const RtpTransceiverInit&);
37*d9f75844SAndroid Build Coastguard Worker   ~RtpTransceiverInit();
38*d9f75844SAndroid Build Coastguard Worker   // Direction of the RtpTransceiver. See RtpTransceiverInterface::direction().
39*d9f75844SAndroid Build Coastguard Worker   RtpTransceiverDirection direction = RtpTransceiverDirection::kSendRecv;
40*d9f75844SAndroid Build Coastguard Worker 
41*d9f75844SAndroid Build Coastguard Worker   // The added RtpTransceiver will be added to these streams.
42*d9f75844SAndroid Build Coastguard Worker   std::vector<std::string> stream_ids;
43*d9f75844SAndroid Build Coastguard Worker 
44*d9f75844SAndroid Build Coastguard Worker   // TODO(bugs.webrtc.org/7600): Not implemented.
45*d9f75844SAndroid Build Coastguard Worker   std::vector<RtpEncodingParameters> send_encodings;
46*d9f75844SAndroid Build Coastguard Worker };
47*d9f75844SAndroid Build Coastguard Worker 
48*d9f75844SAndroid Build Coastguard Worker // The RtpTransceiverInterface maps to the RTCRtpTransceiver defined by the
49*d9f75844SAndroid Build Coastguard Worker // WebRTC specification. A transceiver represents a combination of an RtpSender
50*d9f75844SAndroid Build Coastguard Worker // and an RtpReceiver than share a common mid. As defined in JSEP, an
51*d9f75844SAndroid Build Coastguard Worker // RtpTransceiver is said to be associated with a media description if its mid
52*d9f75844SAndroid Build Coastguard Worker // property is non-null; otherwise, it is said to be disassociated.
53*d9f75844SAndroid Build Coastguard Worker // JSEP: https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-24
54*d9f75844SAndroid Build Coastguard Worker //
55*d9f75844SAndroid Build Coastguard Worker // Note that RtpTransceivers are only supported when using PeerConnection with
56*d9f75844SAndroid Build Coastguard Worker // Unified Plan SDP.
57*d9f75844SAndroid Build Coastguard Worker //
58*d9f75844SAndroid Build Coastguard Worker // This class is thread-safe.
59*d9f75844SAndroid Build Coastguard Worker //
60*d9f75844SAndroid Build Coastguard Worker // WebRTC specification for RTCRtpTransceiver, the JavaScript analog:
61*d9f75844SAndroid Build Coastguard Worker // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver
62*d9f75844SAndroid Build Coastguard Worker class RTC_EXPORT RtpTransceiverInterface : public rtc::RefCountInterface {
63*d9f75844SAndroid Build Coastguard Worker  public:
64*d9f75844SAndroid Build Coastguard Worker   // Media type of the transceiver. Any sender(s)/receiver(s) will have this
65*d9f75844SAndroid Build Coastguard Worker   // type as well.
66*d9f75844SAndroid Build Coastguard Worker   virtual cricket::MediaType media_type() const = 0;
67*d9f75844SAndroid Build Coastguard Worker 
68*d9f75844SAndroid Build Coastguard Worker   // The mid attribute is the mid negotiated and present in the local and
69*d9f75844SAndroid Build Coastguard Worker   // remote descriptions. Before negotiation is complete, the mid value may be
70*d9f75844SAndroid Build Coastguard Worker   // null. After rollbacks, the value may change from a non-null value to null.
71*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-mid
72*d9f75844SAndroid Build Coastguard Worker   virtual absl::optional<std::string> mid() const = 0;
73*d9f75844SAndroid Build Coastguard Worker 
74*d9f75844SAndroid Build Coastguard Worker   // The sender attribute exposes the RtpSender corresponding to the RTP media
75*d9f75844SAndroid Build Coastguard Worker   // that may be sent with the transceiver's mid. The sender is always present,
76*d9f75844SAndroid Build Coastguard Worker   // regardless of the direction of media.
77*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-sender
78*d9f75844SAndroid Build Coastguard Worker   virtual rtc::scoped_refptr<RtpSenderInterface> sender() const = 0;
79*d9f75844SAndroid Build Coastguard Worker 
80*d9f75844SAndroid Build Coastguard Worker   // The receiver attribute exposes the RtpReceiver corresponding to the RTP
81*d9f75844SAndroid Build Coastguard Worker   // media that may be received with the transceiver's mid. The receiver is
82*d9f75844SAndroid Build Coastguard Worker   // always present, regardless of the direction of media.
83*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-receiver
84*d9f75844SAndroid Build Coastguard Worker   virtual rtc::scoped_refptr<RtpReceiverInterface> receiver() const = 0;
85*d9f75844SAndroid Build Coastguard Worker 
86*d9f75844SAndroid Build Coastguard Worker   // The stopped attribute indicates that the sender of this transceiver will no
87*d9f75844SAndroid Build Coastguard Worker   // longer send, and that the receiver will no longer receive. It is true if
88*d9f75844SAndroid Build Coastguard Worker   // either stop has been called or if setting the local or remote description
89*d9f75844SAndroid Build Coastguard Worker   // has caused the RtpTransceiver to be stopped.
90*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-stopped
91*d9f75844SAndroid Build Coastguard Worker   virtual bool stopped() const = 0;
92*d9f75844SAndroid Build Coastguard Worker 
93*d9f75844SAndroid Build Coastguard Worker   // The stopping attribute indicates that the user has indicated that the
94*d9f75844SAndroid Build Coastguard Worker   // sender of this transceiver will stop sending, and that the receiver will
95*d9f75844SAndroid Build Coastguard Worker   // no longer receive. It is always true if stopped() is true.
96*d9f75844SAndroid Build Coastguard Worker   // If stopping() is true and stopped() is false, it means that the
97*d9f75844SAndroid Build Coastguard Worker   // transceiver's stop() method has been called, but the negotiation with
98*d9f75844SAndroid Build Coastguard Worker   // the other end for shutting down the transceiver is not yet done.
99*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-pc/#dfn-stopping-0
100*d9f75844SAndroid Build Coastguard Worker   virtual bool stopping() const = 0;
101*d9f75844SAndroid Build Coastguard Worker 
102*d9f75844SAndroid Build Coastguard Worker   // The direction attribute indicates the preferred direction of this
103*d9f75844SAndroid Build Coastguard Worker   // transceiver, which will be used in calls to CreateOffer and CreateAnswer.
104*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction
105*d9f75844SAndroid Build Coastguard Worker   virtual RtpTransceiverDirection direction() const = 0;
106*d9f75844SAndroid Build Coastguard Worker 
107*d9f75844SAndroid Build Coastguard Worker   // Sets the preferred direction of this transceiver. An update of
108*d9f75844SAndroid Build Coastguard Worker   // directionality does not take effect immediately. Instead, future calls to
109*d9f75844SAndroid Build Coastguard Worker   // CreateOffer and CreateAnswer mark the corresponding media descriptions as
110*d9f75844SAndroid Build Coastguard Worker   // sendrecv, sendonly, recvonly, or inactive.
111*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction
112*d9f75844SAndroid Build Coastguard Worker   // TODO(hta): Deprecate SetDirection without error and rename
113*d9f75844SAndroid Build Coastguard Worker   // SetDirectionWithError to SetDirection, remove default implementations.
114*d9f75844SAndroid Build Coastguard Worker   ABSL_DEPRECATED("Use SetDirectionWithError instead")
115*d9f75844SAndroid Build Coastguard Worker   virtual void SetDirection(RtpTransceiverDirection new_direction);
116*d9f75844SAndroid Build Coastguard Worker   virtual RTCError SetDirectionWithError(RtpTransceiverDirection new_direction);
117*d9f75844SAndroid Build Coastguard Worker 
118*d9f75844SAndroid Build Coastguard Worker   // The current_direction attribute indicates the current direction negotiated
119*d9f75844SAndroid Build Coastguard Worker   // for this transceiver. If this transceiver has never been represented in an
120*d9f75844SAndroid Build Coastguard Worker   // offer/answer exchange, or if the transceiver is stopped, the value is null.
121*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-currentdirection
122*d9f75844SAndroid Build Coastguard Worker   virtual absl::optional<RtpTransceiverDirection> current_direction() const = 0;
123*d9f75844SAndroid Build Coastguard Worker 
124*d9f75844SAndroid Build Coastguard Worker   // An internal slot designating for which direction the relevant
125*d9f75844SAndroid Build Coastguard Worker   // PeerConnection events have been fired. This is to ensure that events like
126*d9f75844SAndroid Build Coastguard Worker   // OnAddTrack only get fired once even if the same session description is
127*d9f75844SAndroid Build Coastguard Worker   // applied again.
128*d9f75844SAndroid Build Coastguard Worker   // Exposed in the public interface for use by Chromium.
129*d9f75844SAndroid Build Coastguard Worker   virtual absl::optional<RtpTransceiverDirection> fired_direction() const;
130*d9f75844SAndroid Build Coastguard Worker 
131*d9f75844SAndroid Build Coastguard Worker   // Initiates a stop of the transceiver.
132*d9f75844SAndroid Build Coastguard Worker   // The stop is complete when stopped() returns true.
133*d9f75844SAndroid Build Coastguard Worker   // A stopped transceiver can be reused for a different track.
134*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-stop
135*d9f75844SAndroid Build Coastguard Worker   // TODO(hta): Rename to Stop() when users of the non-standard Stop() are
136*d9f75844SAndroid Build Coastguard Worker   // updated.
137*d9f75844SAndroid Build Coastguard Worker   virtual RTCError StopStandard();
138*d9f75844SAndroid Build Coastguard Worker 
139*d9f75844SAndroid Build Coastguard Worker   // Stops a transceiver immediately, without waiting for signalling.
140*d9f75844SAndroid Build Coastguard Worker   // This is an internal function, and is exposed for historical reasons.
141*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-pc/#dfn-stop-the-rtcrtptransceiver
142*d9f75844SAndroid Build Coastguard Worker   virtual void StopInternal();
143*d9f75844SAndroid Build Coastguard Worker   ABSL_DEPRECATED("Use StopStandard instead") virtual void Stop();
144*d9f75844SAndroid Build Coastguard Worker 
145*d9f75844SAndroid Build Coastguard Worker   // The SetCodecPreferences method overrides the default codec preferences used
146*d9f75844SAndroid Build Coastguard Worker   // by WebRTC for this transceiver.
147*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-setcodecpreferences
148*d9f75844SAndroid Build Coastguard Worker   virtual RTCError SetCodecPreferences(
149*d9f75844SAndroid Build Coastguard Worker       rtc::ArrayView<RtpCodecCapability> codecs) = 0;
150*d9f75844SAndroid Build Coastguard Worker   virtual std::vector<RtpCodecCapability> codec_preferences() const = 0;
151*d9f75844SAndroid Build Coastguard Worker 
152*d9f75844SAndroid Build Coastguard Worker   // Readonly attribute which contains the set of header extensions that was set
153*d9f75844SAndroid Build Coastguard Worker   // with SetOfferedRtpHeaderExtensions, or a default set if it has not been
154*d9f75844SAndroid Build Coastguard Worker   // called.
155*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-extensions/#rtcrtptransceiver-interface
156*d9f75844SAndroid Build Coastguard Worker   virtual std::vector<RtpHeaderExtensionCapability> HeaderExtensionsToOffer()
157*d9f75844SAndroid Build Coastguard Worker       const = 0;
158*d9f75844SAndroid Build Coastguard Worker 
159*d9f75844SAndroid Build Coastguard Worker   // Readonly attribute which is either empty if negotation has not yet
160*d9f75844SAndroid Build Coastguard Worker   // happened, or a vector of the negotiated header extensions.
161*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-extensions/#rtcrtptransceiver-interface
162*d9f75844SAndroid Build Coastguard Worker   virtual std::vector<RtpHeaderExtensionCapability> HeaderExtensionsNegotiated()
163*d9f75844SAndroid Build Coastguard Worker       const = 0;
164*d9f75844SAndroid Build Coastguard Worker 
165*d9f75844SAndroid Build Coastguard Worker   // The SetOfferedRtpHeaderExtensions method modifies the next SDP negotiation
166*d9f75844SAndroid Build Coastguard Worker   // so that it negotiates use of header extensions which are not kStopped.
167*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-extensions/#rtcrtptransceiver-interface
168*d9f75844SAndroid Build Coastguard Worker   virtual webrtc::RTCError SetOfferedRtpHeaderExtensions(
169*d9f75844SAndroid Build Coastguard Worker       rtc::ArrayView<const RtpHeaderExtensionCapability>
170*d9f75844SAndroid Build Coastguard Worker           header_extensions_to_offer) = 0;
171*d9f75844SAndroid Build Coastguard Worker 
172*d9f75844SAndroid Build Coastguard Worker  protected:
173*d9f75844SAndroid Build Coastguard Worker   ~RtpTransceiverInterface() override = default;
174*d9f75844SAndroid Build Coastguard Worker };
175*d9f75844SAndroid Build Coastguard Worker 
176*d9f75844SAndroid Build Coastguard Worker }  // namespace webrtc
177*d9f75844SAndroid Build Coastguard Worker 
178*d9f75844SAndroid Build Coastguard Worker #endif  // API_RTP_TRANSCEIVER_INTERFACE_H_
179