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