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