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