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