blob: aec0d155b0950ca15b672a49bef35817d66c871b [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"
23#include "api/scoped_refptr.h"
24#include "rtc_base/ref_count.h"
25
26namespace webrtc {
27
28// https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiverdirection
29enum class RtpTransceiverDirection {
30 kSendRecv,
31 kSendOnly,
32 kRecvOnly,
33 kInactive
34};
35
36// Structure for initializing an RtpTransceiver in a call to
37// PeerConnectionInterface::AddTransceiver.
38// https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiverinit
39struct RtpTransceiverInit final {
40 RtpTransceiverInit();
41 RtpTransceiverInit(const RtpTransceiverInit&);
42 ~RtpTransceiverInit();
43 // Direction of the RtpTransceiver. See RtpTransceiverInterface::direction().
44 RtpTransceiverDirection direction = RtpTransceiverDirection::kSendRecv;
45
46 // The added RtpTransceiver will be added to these streams.
47 std::vector<std::string> stream_ids;
48
49 // TODO(bugs.webrtc.org/7600): Not implemented.
50 std::vector<RtpEncodingParameters> send_encodings;
51};
52
53// The RtpTransceiverInterface maps to the RTCRtpTransceiver defined by the
54// WebRTC specification. A transceiver represents a combination of an RtpSender
55// and an RtpReceiver than share a common mid. As defined in JSEP, an
56// RtpTransceiver is said to be associated with a media description if its mid
57// property is non-null; otherwise, it is said to be disassociated.
58// JSEP: https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-24
59//
60// Note that RtpTransceivers are only supported when using PeerConnection with
61// Unified Plan SDP.
62//
63// This class is thread-safe.
64//
65// WebRTC specification for RTCRtpTransceiver, the JavaScript analog:
66// https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver
67class RtpTransceiverInterface : public rtc::RefCountInterface {
68 public:
69 // Media type of the transceiver. Any sender(s)/receiver(s) will have this
70 // type as well.
71 virtual cricket::MediaType media_type() const = 0;
72
73 // The mid attribute is the mid negotiated and present in the local and
74 // remote descriptions. Before negotiation is complete, the mid value may be
75 // null. After rollbacks, the value may change from a non-null value to null.
76 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-mid
77 virtual absl::optional<std::string> mid() const = 0;
78
79 // The sender attribute exposes the RtpSender corresponding to the RTP media
80 // that may be sent with the transceiver's mid. The sender is always present,
81 // regardless of the direction of media.
82 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-sender
83 virtual rtc::scoped_refptr<RtpSenderInterface> sender() const = 0;
84
85 // The receiver attribute exposes the RtpReceiver corresponding to the RTP
86 // media that may be received with the transceiver's mid. The receiver is
87 // always present, regardless of the direction of media.
88 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-receiver
89 virtual rtc::scoped_refptr<RtpReceiverInterface> receiver() const = 0;
90
91 // The stopped attribute indicates that the sender of this transceiver will no
92 // longer send, and that the receiver will no longer receive. It is true if
93 // either stop has been called or if setting the local or remote description
94 // has caused the RtpTransceiver to be stopped.
95 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-stopped
96 virtual bool stopped() const = 0;
97
98 // The direction attribute indicates the preferred direction of this
99 // transceiver, which will be used in calls to CreateOffer and CreateAnswer.
100 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction
101 virtual RtpTransceiverDirection direction() const = 0;
102
103 // Sets the preferred direction of this transceiver. An update of
104 // directionality does not take effect immediately. Instead, future calls to
105 // CreateOffer and CreateAnswer mark the corresponding media descriptions as
106 // sendrecv, sendonly, recvonly, or inactive.
107 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction
108 virtual void SetDirection(RtpTransceiverDirection new_direction) = 0;
109
110 // The current_direction attribute indicates the current direction negotiated
111 // for this transceiver. If this transceiver has never been represented in an
112 // offer/answer exchange, or if the transceiver is stopped, the value is null.
113 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-currentdirection
114 virtual absl::optional<RtpTransceiverDirection> current_direction() const = 0;
115
116 // An internal slot designating for which direction the relevant
117 // PeerConnection events have been fired. This is to ensure that events like
118 // OnAddTrack only get fired once even if the same session description is
119 // applied again.
120 // Exposed in the public interface for use by Chromium.
121 virtual absl::optional<RtpTransceiverDirection> fired_direction() const;
122
123 // The Stop method irreversibly stops the RtpTransceiver. The sender of this
124 // transceiver will no longer send, the receiver will no longer receive.
125 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-stop
126 virtual void Stop() = 0;
127
128 // The SetCodecPreferences method overrides the default codec preferences used
129 // by WebRTC for this transceiver.
130 // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-setcodecpreferences
131 // TODO(steveanton): Not implemented.
132 virtual void SetCodecPreferences(rtc::ArrayView<RtpCodecCapability> codecs);
133
134 protected:
135 ~RtpTransceiverInterface() override = default;
136};
137
138} // namespace webrtc
139
140#endif // API_RTP_TRANSCEIVER_INTERFACE_H_