blob: cdda34b193e31d7743ce3d951d586b22c51607a3 [file] [log] [blame]
Steve Anton6e634bf2017-11-13 10:44:53 -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
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef API_RTP_TRANSCEIVER_INTERFACE_H_
12#define API_RTP_TRANSCEIVER_INTERFACE_H_
Steve Anton6e634bf2017-11-13 10:44:53 -080013
14#include <string>
Steve Anton9158ef62017-11-27 13:01:52 -080015#include <vector>
Steve Anton6e634bf2017-11-13 10:44:53 -080016
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020017#include "absl/types/optional.h"
Danil Chapovalov6e9d8952018-04-09 20:30:51 +020018#include "api/array_view.h"
Steve Anton10542f22019-01-11 09:11:00 -080019#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"
Markus Handell0357b3e2020-03-16 13:40:51 +010023#include "api/rtp_transceiver_direction.h"
Mirko Bonadeid9708072019-01-25 20:26:48 +010024#include "api/scoped_refptr.h"
Steve Anton10542f22019-01-11 09:11:00 -080025#include "rtc_base/ref_count.h"
Mirko Bonadei66e76792019-04-02 11:33:59 +020026#include "rtc_base/system/rtc_export.h"
Steve Anton6e634bf2017-11-13 10:44:53 -080027
28namespace webrtc {
29
Steve Anton9158ef62017-11-27 13:01:52 -080030// Structure for initializing an RtpTransceiver in a call to
31// PeerConnectionInterface::AddTransceiver.
32// https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiverinit
Mirko Bonadei66e76792019-04-02 11:33:59 +020033struct RTC_EXPORT RtpTransceiverInit final {
Mirko Bonadei79eb4dd2018-07-19 10:39:30 +020034 RtpTransceiverInit();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020035 RtpTransceiverInit(const RtpTransceiverInit&);
Mirko Bonadei79eb4dd2018-07-19 10:39:30 +020036 ~RtpTransceiverInit();
Steve Anton9158ef62017-11-27 13:01:52 -080037 // Direction of the RtpTransceiver. See RtpTransceiverInterface::direction().
38 RtpTransceiverDirection direction = RtpTransceiverDirection::kSendRecv;
39
40 // The added RtpTransceiver will be added to these streams.
Seth Hampson513449e2018-03-06 09:35:56 -080041 std::vector<std::string> stream_ids;
Steve Anton9158ef62017-11-27 13:01:52 -080042
43 // TODO(bugs.webrtc.org/7600): Not implemented.
44 std::vector<RtpEncodingParameters> send_encodings;
45};
46
Steve Anton6e634bf2017-11-13 10:44:53 -080047// 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
Mirko Bonadei35214fc2019-09-23 14:54:28 +020061class RTC_EXPORT RtpTransceiverInterface : public rtc::RefCountInterface {
Steve Anton6e634bf2017-11-13 10:44:53 -080062 public:
Steve Anton69470252018-02-09 11:43:08 -080063 // 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
Steve Anton6e634bf2017-11-13 10:44:53 -080067 // 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
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020071 virtual absl::optional<std::string> mid() const = 0;
Steve Anton6e634bf2017-11-13 10:44:53 -080072
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
Harald Alvestrand11dc6572020-08-10 14:41:03 +020092 // 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
Steve Anton6e634bf2017-11-13 10:44:53 -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
Harald Alvestrand11dc6572020-08-10 14:41:03 +0200112 // TODO(hta): Deprecate SetDirection without error and rename
113 // SetDirectionWithError to SetDirection, remove default implementations.
114 virtual void SetDirection(RtpTransceiverDirection new_direction);
115 virtual RTCError SetDirectionWithError(RtpTransceiverDirection new_direction);
Steve Anton6e634bf2017-11-13 10:44:53 -0800116
117 // The current_direction attribute indicates the current direction negotiated
118 // for this transceiver. If this transceiver has never been represented in an
119 // offer/answer exchange, or if the transceiver is stopped, the value is null.
120 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-currentdirection
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200121 virtual absl::optional<RtpTransceiverDirection> current_direction() const = 0;
Steve Anton6e634bf2017-11-13 10:44:53 -0800122
Steve Anton0f5400a2018-07-17 14:25:36 -0700123 // An internal slot designating for which direction the relevant
124 // PeerConnection events have been fired. This is to ensure that events like
125 // OnAddTrack only get fired once even if the same session description is
126 // applied again.
127 // Exposed in the public interface for use by Chromium.
Mirko Bonadei79eb4dd2018-07-19 10:39:30 +0200128 virtual absl::optional<RtpTransceiverDirection> fired_direction() const;
Steve Anton0f5400a2018-07-17 14:25:36 -0700129
Harald Alvestrand11dc6572020-08-10 14:41:03 +0200130 // Initiates a stop of the transceiver.
131 // The stop is complete when stopped() returns true.
132 // A stopped transceiver can be reused for a different track.
Steve Anton6e634bf2017-11-13 10:44:53 -0800133 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-stop
Harald Alvestrand11dc6572020-08-10 14:41:03 +0200134 // TODO(hta): Rename to Stop() when users of the non-standard Stop() are
135 // updated.
136 virtual RTCError StopStandard();
137
138 // Stops a transceiver immediately, without waiting for signalling.
139 // This is an internal function, and is exposed for historical reasons.
140 // https://w3c.github.io/webrtc-pc/#dfn-stop-the-rtcrtptransceiver
141 virtual void StopInternal();
142 RTC_DEPRECATED virtual void Stop();
Steve Anton6e634bf2017-11-13 10:44:53 -0800143
144 // The SetCodecPreferences method overrides the default codec preferences used
145 // by WebRTC for this transceiver.
146 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-setcodecpreferences
Florent Castelli2d9d82e2019-04-23 19:25:51 +0200147 virtual RTCError SetCodecPreferences(
148 rtc::ArrayView<RtpCodecCapability> codecs);
149 virtual std::vector<RtpCodecCapability> codec_preferences() const;
Steve Anton6e634bf2017-11-13 10:44:53 -0800150
Markus Handell0357b3e2020-03-16 13:40:51 +0100151 // Readonly attribute which contains the set of header extensions that was set
152 // with SetOfferedRtpHeaderExtensions, or a default set if it has not been
153 // called.
154 // https://w3c.github.io/webrtc-extensions/#rtcrtptransceiver-interface
155 virtual std::vector<RtpHeaderExtensionCapability> HeaderExtensionsToOffer()
156 const;
157
Markus Handell755c65d2020-06-24 01:06:10 +0200158 // The SetOfferedRtpHeaderExtensions method modifies the next SDP negotiation
159 // so that it negotiates use of header extensions which are not kStopped.
160 // https://w3c.github.io/webrtc-extensions/#rtcrtptransceiver-interface
161 virtual webrtc::RTCError SetOfferedRtpHeaderExtensions(
162 rtc::ArrayView<const RtpHeaderExtensionCapability>
163 header_extensions_to_offer);
164
Steve Anton6e634bf2017-11-13 10:44:53 -0800165 protected:
Mirko Bonadei79eb4dd2018-07-19 10:39:30 +0200166 ~RtpTransceiverInterface() override = default;
Steve Anton6e634bf2017-11-13 10:44:53 -0800167};
168
169} // namespace webrtc
170
Steve Anton10542f22019-01-11 09:11:00 -0800171#endif // API_RTP_TRANSCEIVER_INTERFACE_H_