blob: f79bf8f50a1cbd7ea92b477cb66d148354990ef6 [file] [log] [blame]
deadbeef6979b022015-09-24 16:47:53 -07001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
deadbeef6979b022015-09-24 16:47:53 -07003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.
deadbeef6979b022015-09-24 16:47:53 -07009 */
10
deadbeef70ab1a12015-09-28 16:53:55 -070011// This file contains interfaces for RtpReceivers
12// http://w3c.github.io/webrtc-pc/#rtcrtpreceiver-interface
13
Steve Anton10542f22019-01-11 09:11:00 -080014#ifndef API_RTP_RECEIVER_INTERFACE_H_
15#define API_RTP_RECEIVER_INTERFACE_H_
deadbeef70ab1a12015-09-28 16:53:55 -070016
17#include <string>
hbos8d609f62017-04-10 07:39:05 -070018#include <vector>
deadbeef70ab1a12015-09-28 16:53:55 -070019
Steve Anton10542f22019-01-11 09:11:00 -080020#include "api/crypto/frame_decryptor_interface.h"
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +010021#include "api/dtls_transport_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080022#include "api/media_stream_interface.h"
23#include "api/media_types.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "api/proxy.h"
Steve Anton10542f22019-01-11 09:11:00 -080025#include "api/rtp_parameters.h"
Mirko Bonadeid9708072019-01-25 20:26:48 +010026#include "api/scoped_refptr.h"
Johannes Kronb5d91832019-05-21 13:19:22 +020027#include "rtc_base/deprecation.h"
Steve Anton10542f22019-01-11 09:11:00 -080028#include "rtc_base/ref_count.h"
deadbeef70ab1a12015-09-28 16:53:55 -070029
30namespace webrtc {
31
hbos8d609f62017-04-10 07:39:05 -070032enum class RtpSourceType {
33 SSRC,
34 CSRC,
35};
36
37class RtpSource {
38 public:
39 RtpSource() = delete;
Johannes Kronb5d91832019-05-21 13:19:22 +020040
zstein2b706342017-08-24 14:52:17 -070041 RtpSource(int64_t timestamp_ms,
42 uint32_t source_id,
43 RtpSourceType source_type,
Johannes Kronb5d91832019-05-21 13:19:22 +020044 absl::optional<uint8_t> audio_level,
45 uint32_t rtp_timestamp);
46
47 // DEPRECATED: Will be removed after 2019-07-31.
48 RTC_DEPRECATED RtpSource(int64_t timestamp_ms,
49 uint32_t source_id,
50 RtpSourceType source_type);
51 // DEPRECATED: Will be removed after 2019-07-31.
52 RTC_DEPRECATED RtpSource(int64_t timestamp_ms,
53 uint32_t source_id,
54 RtpSourceType source_type,
55 uint8_t audio_level);
56
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +010057 RtpSource(const RtpSource&);
58 RtpSource& operator=(const RtpSource&);
59 ~RtpSource();
zstein2b706342017-08-24 14:52:17 -070060
hbos8d609f62017-04-10 07:39:05 -070061 int64_t timestamp_ms() const { return timestamp_ms_; }
62 void update_timestamp_ms(int64_t timestamp_ms) {
63 RTC_DCHECK_LE(timestamp_ms_, timestamp_ms);
64 timestamp_ms_ = timestamp_ms;
65 }
66
67 // The identifier of the source can be the CSRC or the SSRC.
68 uint32_t source_id() const { return source_id_; }
69
70 // The source can be either a contributing source or a synchronization source.
71 RtpSourceType source_type() const { return source_type_; }
72
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020073 absl::optional<uint8_t> audio_level() const { return audio_level_; }
74 void set_audio_level(const absl::optional<uint8_t>& level) {
zstein2b706342017-08-24 14:52:17 -070075 audio_level_ = level;
76 }
hbos8d609f62017-04-10 07:39:05 -070077
Johannes Kronb5d91832019-05-21 13:19:22 +020078 uint32_t rtp_timestamp() const { return rtp_timestamp_; }
79
zhihuang04262222017-04-11 11:28:10 -070080 bool operator==(const RtpSource& o) const {
81 return timestamp_ms_ == o.timestamp_ms() && source_id_ == o.source_id() &&
Johannes Kronb5d91832019-05-21 13:19:22 +020082 source_type_ == o.source_type() && audio_level_ == o.audio_level_ &&
83 rtp_timestamp_ == o.rtp_timestamp();
zhihuang04262222017-04-11 11:28:10 -070084 }
85
hbos8d609f62017-04-10 07:39:05 -070086 private:
87 int64_t timestamp_ms_;
88 uint32_t source_id_;
89 RtpSourceType source_type_;
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020090 absl::optional<uint8_t> audio_level_;
Johannes Kronb5d91832019-05-21 13:19:22 +020091 uint32_t rtp_timestamp_;
hbos8d609f62017-04-10 07:39:05 -070092};
93
zhihuang184a3fd2016-06-14 11:47:14 -070094class RtpReceiverObserverInterface {
95 public:
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -070096 // Note: Currently if there are multiple RtpReceivers of the same media type,
97 // they will all call OnFirstPacketReceived at once.
98 //
99 // In the future, it's likely that an RtpReceiver will only call
100 // OnFirstPacketReceived when a packet is received specifically for its
101 // SSRC/mid.
zhihuang184a3fd2016-06-14 11:47:14 -0700102 virtual void OnFirstPacketReceived(cricket::MediaType media_type) = 0;
103
104 protected:
105 virtual ~RtpReceiverObserverInterface() {}
106};
107
deadbeef70ab1a12015-09-28 16:53:55 -0700108class RtpReceiverInterface : public rtc::RefCountInterface {
109 public:
110 virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0;
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +0100111
112 // The dtlsTransport attribute exposes the DTLS transport on which the
113 // media is received. It may be null.
114 // https://w3c.github.io/webrtc-pc/#dom-rtcrtpreceiver-transport
115 // TODO(https://bugs.webrtc.org/907849) remove default implementation
116 virtual rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const;
117
Henrik Boström9e6fd2b2017-11-21 13:41:51 +0100118 // The list of streams that |track| is associated with. This is the same as
119 // the [[AssociatedRemoteMediaStreams]] internal slot in the spec.
Henrik Boström199e27b2018-07-04 20:51:53 +0200120 // https://w3c.github.io/webrtc-pc/#dfn-associatedremotemediastreams
Henrik Boström9e6fd2b2017-11-21 13:41:51 +0100121 // TODO(hbos): Make pure virtual as soon as Chromium's mock implements this.
Henrik Boström199e27b2018-07-04 20:51:53 +0200122 // TODO(https://crbug.com/webrtc/9480): Remove streams() in favor of
123 // stream_ids() as soon as downstream projects are no longer dependent on
124 // stream objects.
125 virtual std::vector<std::string> stream_ids() const;
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +0100126 virtual std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams() const;
deadbeef70ab1a12015-09-28 16:53:55 -0700127
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700128 // Audio or video receiver?
129 virtual cricket::MediaType media_type() const = 0;
130
deadbeef70ab1a12015-09-28 16:53:55 -0700131 // Not to be confused with "mid", this is a field we can temporarily use
132 // to uniquely identify a receiver until we implement Unified Plan SDP.
133 virtual std::string id() const = 0;
134
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700135 // The WebRTC specification only defines RTCRtpParameters in terms of senders,
136 // but this API also applies them to receivers, similar to ORTC:
137 // http://ortc.org/wp-content/uploads/2016/03/ortc.html#rtcrtpparameters*.
138 virtual RtpParameters GetParameters() const = 0;
deadbeefb10f32f2017-02-08 01:38:21 -0800139 // Currently, doesn't support changing any parameters, but may in the future.
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700140 virtual bool SetParameters(const RtpParameters& parameters) = 0;
141
Taylor Brandstetterba29c6a2016-06-27 16:30:35 -0700142 // Does not take ownership of observer.
143 // Must call SetObserver(nullptr) before the observer is destroyed.
zhihuang184a3fd2016-06-14 11:47:14 -0700144 virtual void SetObserver(RtpReceiverObserverInterface* observer) = 0;
145
Ruslan Burakov4bac79e2019-04-03 19:55:33 +0200146 // Sets the jitter buffer minimum delay until media playout. Actual observed
147 // delay may differ depending on the congestion control. |delay_seconds| is a
148 // positive value including 0.0 measured in seconds. |nullopt| means default
Ruslan Burakov428dcb22019-04-18 17:49:49 +0200149 // value must be used.
Ruslan Burakov4bac79e2019-04-03 19:55:33 +0200150 virtual void SetJitterBufferMinimumDelay(
Ruslan Burakov428dcb22019-04-18 17:49:49 +0200151 absl::optional<double> delay_seconds) = 0;
Ruslan Burakov4bac79e2019-04-03 19:55:33 +0200152
hbos8d609f62017-04-10 07:39:05 -0700153 // TODO(zhihuang): Remove the default implementation once the subclasses
154 // implement this. Currently, the only relevant subclass is the
155 // content::FakeRtpReceiver in Chromium.
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +0100156 virtual std::vector<RtpSource> GetSources() const;
157
Benjamin Wrightd81ac952018-08-29 17:02:10 -0700158 // Sets a user defined frame decryptor that will decrypt the entire frame
159 // before it is sent across the network. This will decrypt the entire frame
160 // using the user provided decryption mechanism regardless of whether SRTP is
161 // enabled or not.
162 virtual void SetFrameDecryptor(
163 rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor);
164
165 // Returns a pointer to the frame decryptor set previously by the
166 // user. This can be used to update the state of the object.
167 virtual rtc::scoped_refptr<FrameDecryptorInterface> GetFrameDecryptor() const;
168
deadbeef70ab1a12015-09-28 16:53:55 -0700169 protected:
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +0100170 ~RtpReceiverInterface() override = default;
deadbeef70ab1a12015-09-28 16:53:55 -0700171};
172
173// Define proxy for RtpReceiverInterface.
deadbeefb10f32f2017-02-08 01:38:21 -0800174// TODO(deadbeef): Move this to .cc file and out of api/. What threads methods
175// are called on is an implementation detail.
nisse72c8d2b2016-04-15 03:49:07 -0700176BEGIN_SIGNALING_PROXY_MAP(RtpReceiver)
Yves Gerey665174f2018-06-19 15:03:05 +0200177PROXY_SIGNALING_THREAD_DESTRUCTOR()
178PROXY_CONSTMETHOD0(rtc::scoped_refptr<MediaStreamTrackInterface>, track)
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +0100179PROXY_CONSTMETHOD0(rtc::scoped_refptr<DtlsTransportInterface>, dtls_transport)
Henrik Boström5b147782018-12-04 11:25:05 +0100180PROXY_CONSTMETHOD0(std::vector<std::string>, stream_ids)
Yves Gerey665174f2018-06-19 15:03:05 +0200181PROXY_CONSTMETHOD0(std::vector<rtc::scoped_refptr<MediaStreamInterface>>,
182 streams)
183PROXY_CONSTMETHOD0(cricket::MediaType, media_type)
184PROXY_CONSTMETHOD0(std::string, id)
Nico Weber22f99252019-02-20 10:13:16 -0500185PROXY_CONSTMETHOD0(RtpParameters, GetParameters)
Yves Gerey665174f2018-06-19 15:03:05 +0200186PROXY_METHOD1(bool, SetParameters, const RtpParameters&)
Nico Weber22f99252019-02-20 10:13:16 -0500187PROXY_METHOD1(void, SetObserver, RtpReceiverObserverInterface*)
Ruslan Burakov4bac79e2019-04-03 19:55:33 +0200188PROXY_METHOD1(void, SetJitterBufferMinimumDelay, absl::optional<double>)
Nico Weber22f99252019-02-20 10:13:16 -0500189PROXY_CONSTMETHOD0(std::vector<RtpSource>, GetSources)
Benjamin Wrightd81ac952018-08-29 17:02:10 -0700190PROXY_METHOD1(void,
191 SetFrameDecryptor,
Nico Weber22f99252019-02-20 10:13:16 -0500192 rtc::scoped_refptr<FrameDecryptorInterface>)
Benjamin Wrightd81ac952018-08-29 17:02:10 -0700193PROXY_CONSTMETHOD0(rtc::scoped_refptr<FrameDecryptorInterface>,
Nico Weber22f99252019-02-20 10:13:16 -0500194 GetFrameDecryptor)
Yves Gerey665174f2018-06-19 15:03:05 +0200195END_PROXY_MAP()
deadbeef70ab1a12015-09-28 16:53:55 -0700196
197} // namespace webrtc
198
Steve Anton10542f22019-01-11 09:11:00 -0800199#endif // API_RTP_RECEIVER_INTERFACE_H_