blob: c8b42aa9d734427842a5d358808f078d25061820 [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
11#ifndef API_RTPTRANSCEIVERINTERFACE_H_
12#define API_RTPTRANSCEIVERINTERFACE_H_
13
14#include <string>
Steve Anton9158ef62017-11-27 13:01:52 -080015#include <vector>
Steve Anton6e634bf2017-11-13 10:44:53 -080016
17#include "api/optional.h"
18#include "api/rtpreceiverinterface.h"
19#include "api/rtpsenderinterface.h"
20#include "rtc_base/refcount.h"
21
22namespace webrtc {
23
Steve Anton9158ef62017-11-27 13:01:52 -080024// https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiverdirection
Steve Anton6e634bf2017-11-13 10:44:53 -080025enum class RtpTransceiverDirection {
26 kSendRecv,
27 kSendOnly,
28 kRecvOnly,
29 kInactive
30};
31
Steve Antondcc3c022017-12-22 16:02:54 -080032// This is provided as a debugging aid. The format of the output is unspecified.
33std::ostream& operator<<(std::ostream& os, RtpTransceiverDirection direction);
34
Steve Anton9158ef62017-11-27 13:01:52 -080035// Structure for initializing an RtpTransceiver in a call to
36// PeerConnectionInterface::AddTransceiver.
37// https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiverinit
38struct RtpTransceiverInit final {
39 // Direction of the RtpTransceiver. See RtpTransceiverInterface::direction().
40 RtpTransceiverDirection direction = RtpTransceiverDirection::kSendRecv;
41
42 // The added RtpTransceiver will be added to these streams.
Seth Hampson845e8782018-03-02 11:34:10 -080043 // TODO(shampson): Change name to stream_id & update native wrapper's naming
44 // as well.
Steve Anton9158ef62017-11-27 13:01:52 -080045 // TODO(bugs.webrtc.org/7600): Not implemented.
Steve Antonf9381f02017-12-14 10:23:57 -080046 std::vector<std::string> stream_labels;
Steve Anton9158ef62017-11-27 13:01:52 -080047
48 // TODO(bugs.webrtc.org/7600): Not implemented.
49 std::vector<RtpEncodingParameters> send_encodings;
50};
51
Steve Anton6e634bf2017-11-13 10:44:53 -080052// The RtpTransceiverInterface maps to the RTCRtpTransceiver defined by the
53// WebRTC specification. A transceiver represents a combination of an RtpSender
54// and an RtpReceiver than share a common mid. As defined in JSEP, an
55// RtpTransceiver is said to be associated with a media description if its mid
56// property is non-null; otherwise, it is said to be disassociated.
57// JSEP: https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-24
58//
59// Note that RtpTransceivers are only supported when using PeerConnection with
60// Unified Plan SDP.
61//
62// This class is thread-safe.
63//
64// WebRTC specification for RTCRtpTransceiver, the JavaScript analog:
65// https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver
66class RtpTransceiverInterface : public rtc::RefCountInterface {
67 public:
Steve Anton69470252018-02-09 11:43:08 -080068 // Media type of the transceiver. Any sender(s)/receiver(s) will have this
69 // type as well.
70 virtual cricket::MediaType media_type() const = 0;
71
Steve Anton6e634bf2017-11-13 10:44:53 -080072 // The mid attribute is the mid negotiated and present in the local and
73 // remote descriptions. Before negotiation is complete, the mid value may be
74 // null. After rollbacks, the value may change from a non-null value to null.
75 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-mid
76 virtual rtc::Optional<std::string> mid() const = 0;
77
78 // The sender attribute exposes the RtpSender corresponding to the RTP media
79 // that may be sent with the transceiver's mid. The sender is always present,
80 // regardless of the direction of media.
81 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-sender
82 virtual rtc::scoped_refptr<RtpSenderInterface> sender() const = 0;
83
84 // The receiver attribute exposes the RtpReceiver corresponding to the RTP
85 // media that may be received with the transceiver's mid. The receiver is
86 // always present, regardless of the direction of media.
87 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-receiver
88 virtual rtc::scoped_refptr<RtpReceiverInterface> receiver() const = 0;
89
90 // The stopped attribute indicates that the sender of this transceiver will no
91 // longer send, and that the receiver will no longer receive. It is true if
92 // either stop has been called or if setting the local or remote description
93 // has caused the RtpTransceiver to be stopped.
94 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-stopped
95 virtual bool stopped() const = 0;
96
97 // The direction attribute indicates the preferred direction of this
98 // transceiver, which will be used in calls to CreateOffer and CreateAnswer.
99 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction
100 virtual RtpTransceiverDirection direction() const = 0;
101
102 // Sets the preferred direction of this transceiver. An update of
103 // directionality does not take effect immediately. Instead, future calls to
104 // CreateOffer and CreateAnswer mark the corresponding media descriptions as
105 // sendrecv, sendonly, recvonly, or inactive.
106 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction
107 virtual void SetDirection(RtpTransceiverDirection new_direction) = 0;
108
109 // The current_direction attribute indicates the current direction negotiated
110 // for this transceiver. If this transceiver has never been represented in an
111 // offer/answer exchange, or if the transceiver is stopped, the value is null.
112 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-currentdirection
113 virtual rtc::Optional<RtpTransceiverDirection> current_direction() const = 0;
114
115 // The Stop method irreversibly stops the RtpTransceiver. The sender of this
116 // transceiver will no longer send, the receiver will no longer receive.
117 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-stop
118 virtual void Stop() = 0;
119
120 // The SetCodecPreferences method overrides the default codec preferences used
121 // by WebRTC for this transceiver.
122 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-setcodecpreferences
123 // TODO(steveanton): Not implemented.
124 virtual void SetCodecPreferences(
125 rtc::ArrayView<RtpCodecCapability> codecs) = 0;
126
127 protected:
128 virtual ~RtpTransceiverInterface() = default;
129};
130
131} // namespace webrtc
132
133#endif // API_RTPTRANSCEIVERINTERFACE_H_