blob: 2af42aaa34c34ff6336d273ab066c84be6013d60 [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"
Mirko Bonadeid9708072019-01-25 20:26:48 +010023#include "api/scoped_refptr.h"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "rtc_base/ref_count.h"
Mirko Bonadei66e76792019-04-02 11:33:59 +020025#include "rtc_base/system/rtc_export.h"
Steve Anton6e634bf2017-11-13 10:44:53 -080026
27namespace webrtc {
28
Steve Anton9158ef62017-11-27 13:01:52 -080029// https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiverdirection
Steve Anton6e634bf2017-11-13 10:44:53 -080030enum class RtpTransceiverDirection {
31 kSendRecv,
32 kSendOnly,
33 kRecvOnly,
Markus Handell45c104b2020-03-11 10:51:13 +010034 kInactive,
35 kStopped,
Steve Anton6e634bf2017-11-13 10:44:53 -080036};
37
Steve Anton9158ef62017-11-27 13:01:52 -080038// Structure for initializing an RtpTransceiver in a call to
39// PeerConnectionInterface::AddTransceiver.
40// https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiverinit
Mirko Bonadei66e76792019-04-02 11:33:59 +020041struct RTC_EXPORT RtpTransceiverInit final {
Mirko Bonadei79eb4dd2018-07-19 10:39:30 +020042 RtpTransceiverInit();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020043 RtpTransceiverInit(const RtpTransceiverInit&);
Mirko Bonadei79eb4dd2018-07-19 10:39:30 +020044 ~RtpTransceiverInit();
Steve Anton9158ef62017-11-27 13:01:52 -080045 // Direction of the RtpTransceiver. See RtpTransceiverInterface::direction().
46 RtpTransceiverDirection direction = RtpTransceiverDirection::kSendRecv;
47
48 // The added RtpTransceiver will be added to these streams.
Seth Hampson513449e2018-03-06 09:35:56 -080049 std::vector<std::string> stream_ids;
Steve Anton9158ef62017-11-27 13:01:52 -080050
51 // TODO(bugs.webrtc.org/7600): Not implemented.
52 std::vector<RtpEncodingParameters> send_encodings;
53};
54
Steve Anton6e634bf2017-11-13 10:44:53 -080055// The RtpTransceiverInterface maps to the RTCRtpTransceiver defined by the
56// WebRTC specification. A transceiver represents a combination of an RtpSender
57// and an RtpReceiver than share a common mid. As defined in JSEP, an
58// RtpTransceiver is said to be associated with a media description if its mid
59// property is non-null; otherwise, it is said to be disassociated.
60// JSEP: https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-24
61//
62// Note that RtpTransceivers are only supported when using PeerConnection with
63// Unified Plan SDP.
64//
65// This class is thread-safe.
66//
67// WebRTC specification for RTCRtpTransceiver, the JavaScript analog:
68// https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver
Mirko Bonadei35214fc2019-09-23 14:54:28 +020069class RTC_EXPORT RtpTransceiverInterface : public rtc::RefCountInterface {
Steve Anton6e634bf2017-11-13 10:44:53 -080070 public:
Steve Anton69470252018-02-09 11:43:08 -080071 // Media type of the transceiver. Any sender(s)/receiver(s) will have this
72 // type as well.
73 virtual cricket::MediaType media_type() const = 0;
74
Steve Anton6e634bf2017-11-13 10:44:53 -080075 // The mid attribute is the mid negotiated and present in the local and
76 // remote descriptions. Before negotiation is complete, the mid value may be
77 // null. After rollbacks, the value may change from a non-null value to null.
78 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-mid
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020079 virtual absl::optional<std::string> mid() const = 0;
Steve Anton6e634bf2017-11-13 10:44:53 -080080
81 // The sender attribute exposes the RtpSender corresponding to the RTP media
82 // that may be sent with the transceiver's mid. The sender is always present,
83 // regardless of the direction of media.
84 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-sender
85 virtual rtc::scoped_refptr<RtpSenderInterface> sender() const = 0;
86
87 // The receiver attribute exposes the RtpReceiver corresponding to the RTP
88 // media that may be received with the transceiver's mid. The receiver is
89 // always present, regardless of the direction of media.
90 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-receiver
91 virtual rtc::scoped_refptr<RtpReceiverInterface> receiver() const = 0;
92
93 // The stopped attribute indicates that the sender of this transceiver will no
94 // longer send, and that the receiver will no longer receive. It is true if
95 // either stop has been called or if setting the local or remote description
96 // has caused the RtpTransceiver to be stopped.
97 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-stopped
98 virtual bool stopped() const = 0;
99
100 // The direction attribute indicates the preferred direction of this
101 // transceiver, which will be used in calls to CreateOffer and CreateAnswer.
102 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction
103 virtual RtpTransceiverDirection direction() const = 0;
104
105 // Sets the preferred direction of this transceiver. An update of
106 // directionality does not take effect immediately. Instead, future calls to
107 // CreateOffer and CreateAnswer mark the corresponding media descriptions as
108 // sendrecv, sendonly, recvonly, or inactive.
109 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction
110 virtual void SetDirection(RtpTransceiverDirection new_direction) = 0;
111
112 // The current_direction attribute indicates the current direction negotiated
113 // for this transceiver. If this transceiver has never been represented in an
114 // offer/answer exchange, or if the transceiver is stopped, the value is null.
115 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-currentdirection
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200116 virtual absl::optional<RtpTransceiverDirection> current_direction() const = 0;
Steve Anton6e634bf2017-11-13 10:44:53 -0800117
Steve Anton0f5400a2018-07-17 14:25:36 -0700118 // An internal slot designating for which direction the relevant
119 // PeerConnection events have been fired. This is to ensure that events like
120 // OnAddTrack only get fired once even if the same session description is
121 // applied again.
122 // Exposed in the public interface for use by Chromium.
Mirko Bonadei79eb4dd2018-07-19 10:39:30 +0200123 virtual absl::optional<RtpTransceiverDirection> fired_direction() const;
Steve Anton0f5400a2018-07-17 14:25:36 -0700124
Steve Anton6e634bf2017-11-13 10:44:53 -0800125 // The Stop method irreversibly stops the RtpTransceiver. The sender of this
126 // transceiver will no longer send, the receiver will no longer receive.
127 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-stop
128 virtual void Stop() = 0;
129
130 // The SetCodecPreferences method overrides the default codec preferences used
131 // by WebRTC for this transceiver.
132 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-setcodecpreferences
Florent Castelli2d9d82e2019-04-23 19:25:51 +0200133 virtual RTCError SetCodecPreferences(
134 rtc::ArrayView<RtpCodecCapability> codecs);
135 virtual std::vector<RtpCodecCapability> codec_preferences() const;
Steve Anton6e634bf2017-11-13 10:44:53 -0800136
137 protected:
Mirko Bonadei79eb4dd2018-07-19 10:39:30 +0200138 ~RtpTransceiverInterface() override = default;
Steve Anton6e634bf2017-11-13 10:44:53 -0800139};
140
141} // namespace webrtc
142
Steve Anton10542f22019-01-11 09:11:00 -0800143#endif // API_RTP_TRANSCEIVER_INTERFACE_H_