deadbeef | 6979b02 | 2015-09-24 16:47:53 -0700 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
deadbeef | 6979b02 | 2015-09-24 16:47:53 -0700 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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. |
deadbeef | 6979b02 | 2015-09-24 16:47:53 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 11 | // This file contains interfaces for RtpReceivers |
| 12 | // http://w3c.github.io/webrtc-pc/#rtcrtpreceiver-interface |
| 13 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 14 | #ifndef API_RTP_RECEIVER_INTERFACE_H_ |
| 15 | #define API_RTP_RECEIVER_INTERFACE_H_ |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 16 | |
| 17 | #include <string> |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 18 | #include <vector> |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 19 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 20 | #include "api/crypto/frame_decryptor_interface.h" |
Harald Alvestrand | 4a7b3ac | 2019-01-17 10:39:40 +0100 | [diff] [blame] | 21 | #include "api/dtls_transport_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 22 | #include "api/media_stream_interface.h" |
| 23 | #include "api/media_types.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #include "api/proxy.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 25 | #include "api/rtp_parameters.h" |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 26 | #include "api/scoped_refptr.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 27 | #include "rtc_base/ref_count.h" |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 28 | |
| 29 | namespace webrtc { |
| 30 | |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 31 | enum class RtpSourceType { |
| 32 | SSRC, |
| 33 | CSRC, |
| 34 | }; |
| 35 | |
| 36 | class RtpSource { |
| 37 | public: |
| 38 | RtpSource() = delete; |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 39 | RtpSource(int64_t timestamp_ms, |
| 40 | uint32_t source_id, |
| 41 | RtpSourceType source_type); |
zstein | 2b70634 | 2017-08-24 14:52:17 -0700 | [diff] [blame] | 42 | RtpSource(int64_t timestamp_ms, |
| 43 | uint32_t source_id, |
| 44 | RtpSourceType source_type, |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 45 | uint8_t audio_level); |
| 46 | RtpSource(const RtpSource&); |
| 47 | RtpSource& operator=(const RtpSource&); |
| 48 | ~RtpSource(); |
zstein | 2b70634 | 2017-08-24 14:52:17 -0700 | [diff] [blame] | 49 | |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 50 | int64_t timestamp_ms() const { return timestamp_ms_; } |
| 51 | void update_timestamp_ms(int64_t timestamp_ms) { |
| 52 | RTC_DCHECK_LE(timestamp_ms_, timestamp_ms); |
| 53 | timestamp_ms_ = timestamp_ms; |
| 54 | } |
| 55 | |
| 56 | // The identifier of the source can be the CSRC or the SSRC. |
| 57 | uint32_t source_id() const { return source_id_; } |
| 58 | |
| 59 | // The source can be either a contributing source or a synchronization source. |
| 60 | RtpSourceType source_type() const { return source_type_; } |
| 61 | |
Danil Chapovalov | 0bc58cf | 2018-06-21 13:32:56 +0200 | [diff] [blame] | 62 | absl::optional<uint8_t> audio_level() const { return audio_level_; } |
| 63 | void set_audio_level(const absl::optional<uint8_t>& level) { |
zstein | 2b70634 | 2017-08-24 14:52:17 -0700 | [diff] [blame] | 64 | audio_level_ = level; |
| 65 | } |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 66 | |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 67 | bool operator==(const RtpSource& o) const { |
| 68 | return timestamp_ms_ == o.timestamp_ms() && source_id_ == o.source_id() && |
zstein | 2b70634 | 2017-08-24 14:52:17 -0700 | [diff] [blame] | 69 | source_type_ == o.source_type() && audio_level_ == o.audio_level_; |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 70 | } |
| 71 | |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 72 | private: |
| 73 | int64_t timestamp_ms_; |
| 74 | uint32_t source_id_; |
| 75 | RtpSourceType source_type_; |
Danil Chapovalov | 0bc58cf | 2018-06-21 13:32:56 +0200 | [diff] [blame] | 76 | absl::optional<uint8_t> audio_level_; |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 79 | class RtpReceiverObserverInterface { |
| 80 | public: |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 81 | // Note: Currently if there are multiple RtpReceivers of the same media type, |
| 82 | // they will all call OnFirstPacketReceived at once. |
| 83 | // |
| 84 | // In the future, it's likely that an RtpReceiver will only call |
| 85 | // OnFirstPacketReceived when a packet is received specifically for its |
| 86 | // SSRC/mid. |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 87 | virtual void OnFirstPacketReceived(cricket::MediaType media_type) = 0; |
| 88 | |
| 89 | protected: |
| 90 | virtual ~RtpReceiverObserverInterface() {} |
| 91 | }; |
| 92 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 93 | class RtpReceiverInterface : public rtc::RefCountInterface { |
| 94 | public: |
| 95 | virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0; |
Harald Alvestrand | 4a7b3ac | 2019-01-17 10:39:40 +0100 | [diff] [blame] | 96 | |
| 97 | // The dtlsTransport attribute exposes the DTLS transport on which the |
| 98 | // media is received. It may be null. |
| 99 | // https://w3c.github.io/webrtc-pc/#dom-rtcrtpreceiver-transport |
| 100 | // TODO(https://bugs.webrtc.org/907849) remove default implementation |
| 101 | virtual rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const; |
| 102 | |
Henrik Boström | 9e6fd2b | 2017-11-21 13:41:51 +0100 | [diff] [blame] | 103 | // The list of streams that |track| is associated with. This is the same as |
| 104 | // the [[AssociatedRemoteMediaStreams]] internal slot in the spec. |
Henrik Boström | 199e27b | 2018-07-04 20:51:53 +0200 | [diff] [blame] | 105 | // https://w3c.github.io/webrtc-pc/#dfn-associatedremotemediastreams |
Henrik Boström | 9e6fd2b | 2017-11-21 13:41:51 +0100 | [diff] [blame] | 106 | // TODO(hbos): Make pure virtual as soon as Chromium's mock implements this. |
Henrik Boström | 199e27b | 2018-07-04 20:51:53 +0200 | [diff] [blame] | 107 | // TODO(https://crbug.com/webrtc/9480): Remove streams() in favor of |
| 108 | // stream_ids() as soon as downstream projects are no longer dependent on |
| 109 | // stream objects. |
| 110 | virtual std::vector<std::string> stream_ids() const; |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 111 | virtual std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams() const; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 112 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 113 | // Audio or video receiver? |
| 114 | virtual cricket::MediaType media_type() const = 0; |
| 115 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 116 | // Not to be confused with "mid", this is a field we can temporarily use |
| 117 | // to uniquely identify a receiver until we implement Unified Plan SDP. |
| 118 | virtual std::string id() const = 0; |
| 119 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 120 | // The WebRTC specification only defines RTCRtpParameters in terms of senders, |
| 121 | // but this API also applies them to receivers, similar to ORTC: |
| 122 | // http://ortc.org/wp-content/uploads/2016/03/ortc.html#rtcrtpparameters*. |
| 123 | virtual RtpParameters GetParameters() const = 0; |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 124 | // Currently, doesn't support changing any parameters, but may in the future. |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 125 | virtual bool SetParameters(const RtpParameters& parameters) = 0; |
| 126 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 127 | // Does not take ownership of observer. |
| 128 | // Must call SetObserver(nullptr) before the observer is destroyed. |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 129 | virtual void SetObserver(RtpReceiverObserverInterface* observer) = 0; |
| 130 | |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 131 | // TODO(zhihuang): Remove the default implementation once the subclasses |
| 132 | // implement this. Currently, the only relevant subclass is the |
| 133 | // content::FakeRtpReceiver in Chromium. |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 134 | virtual std::vector<RtpSource> GetSources() const; |
| 135 | |
Benjamin Wright | d81ac95 | 2018-08-29 17:02:10 -0700 | [diff] [blame] | 136 | // Sets a user defined frame decryptor that will decrypt the entire frame |
| 137 | // before it is sent across the network. This will decrypt the entire frame |
| 138 | // using the user provided decryption mechanism regardless of whether SRTP is |
| 139 | // enabled or not. |
| 140 | virtual void SetFrameDecryptor( |
| 141 | rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor); |
| 142 | |
| 143 | // Returns a pointer to the frame decryptor set previously by the |
| 144 | // user. This can be used to update the state of the object. |
| 145 | virtual rtc::scoped_refptr<FrameDecryptorInterface> GetFrameDecryptor() const; |
| 146 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 147 | protected: |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 148 | ~RtpReceiverInterface() override = default; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | // Define proxy for RtpReceiverInterface. |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 152 | // TODO(deadbeef): Move this to .cc file and out of api/. What threads methods |
| 153 | // are called on is an implementation detail. |
nisse | 72c8d2b | 2016-04-15 03:49:07 -0700 | [diff] [blame] | 154 | BEGIN_SIGNALING_PROXY_MAP(RtpReceiver) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 155 | PROXY_SIGNALING_THREAD_DESTRUCTOR() |
| 156 | PROXY_CONSTMETHOD0(rtc::scoped_refptr<MediaStreamTrackInterface>, track) |
Harald Alvestrand | 4a7b3ac | 2019-01-17 10:39:40 +0100 | [diff] [blame] | 157 | PROXY_CONSTMETHOD0(rtc::scoped_refptr<DtlsTransportInterface>, dtls_transport) |
Henrik Boström | 5b14778 | 2018-12-04 11:25:05 +0100 | [diff] [blame] | 158 | PROXY_CONSTMETHOD0(std::vector<std::string>, stream_ids) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 159 | PROXY_CONSTMETHOD0(std::vector<rtc::scoped_refptr<MediaStreamInterface>>, |
| 160 | streams) |
| 161 | PROXY_CONSTMETHOD0(cricket::MediaType, media_type) |
| 162 | PROXY_CONSTMETHOD0(std::string, id) |
Nico Weber | 22f9925 | 2019-02-20 10:13:16 -0500 | [diff] [blame] | 163 | PROXY_CONSTMETHOD0(RtpParameters, GetParameters) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 164 | PROXY_METHOD1(bool, SetParameters, const RtpParameters&) |
Nico Weber | 22f9925 | 2019-02-20 10:13:16 -0500 | [diff] [blame] | 165 | PROXY_METHOD1(void, SetObserver, RtpReceiverObserverInterface*) |
| 166 | PROXY_CONSTMETHOD0(std::vector<RtpSource>, GetSources) |
Benjamin Wright | d81ac95 | 2018-08-29 17:02:10 -0700 | [diff] [blame] | 167 | PROXY_METHOD1(void, |
| 168 | SetFrameDecryptor, |
Nico Weber | 22f9925 | 2019-02-20 10:13:16 -0500 | [diff] [blame] | 169 | rtc::scoped_refptr<FrameDecryptorInterface>) |
Benjamin Wright | d81ac95 | 2018-08-29 17:02:10 -0700 | [diff] [blame] | 170 | PROXY_CONSTMETHOD0(rtc::scoped_refptr<FrameDecryptorInterface>, |
Nico Weber | 22f9925 | 2019-02-20 10:13:16 -0500 | [diff] [blame] | 171 | GetFrameDecryptor) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 172 | END_PROXY_MAP() |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 173 | |
| 174 | } // namespace webrtc |
| 175 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 176 | #endif // API_RTP_RECEIVER_INTERFACE_H_ |