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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #ifndef API_RTPRECEIVERINTERFACE_H_ |
| 15 | #define API_RTPRECEIVERINTERFACE_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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "api/mediastreaminterface.h" |
| 21 | #include "api/mediatypes.h" |
| 22 | #include "api/proxy.h" |
| 23 | #include "api/rtpparameters.h" |
| 24 | #include "rtc_base/refcount.h" |
| 25 | #include "rtc_base/scoped_ref_ptr.h" |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
| 28 | |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 29 | enum class RtpSourceType { |
| 30 | SSRC, |
| 31 | CSRC, |
| 32 | }; |
| 33 | |
| 34 | class RtpSource { |
| 35 | public: |
| 36 | RtpSource() = delete; |
| 37 | RtpSource(int64_t timestamp_ms, uint32_t source_id, RtpSourceType source_type) |
| 38 | : timestamp_ms_(timestamp_ms), |
| 39 | source_id_(source_id), |
| 40 | source_type_(source_type) {} |
| 41 | |
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, |
| 45 | uint8_t audio_level) |
| 46 | : timestamp_ms_(timestamp_ms), |
| 47 | source_id_(source_id), |
| 48 | source_type_(source_type), |
| 49 | audio_level_(audio_level) {} |
| 50 | |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 51 | int64_t timestamp_ms() const { return timestamp_ms_; } |
| 52 | void update_timestamp_ms(int64_t timestamp_ms) { |
| 53 | RTC_DCHECK_LE(timestamp_ms_, timestamp_ms); |
| 54 | timestamp_ms_ = timestamp_ms; |
| 55 | } |
| 56 | |
| 57 | // The identifier of the source can be the CSRC or the SSRC. |
| 58 | uint32_t source_id() const { return source_id_; } |
| 59 | |
| 60 | // The source can be either a contributing source or a synchronization source. |
| 61 | RtpSourceType source_type() const { return source_type_; } |
| 62 | |
zstein | 2b70634 | 2017-08-24 14:52:17 -0700 | [diff] [blame] | 63 | rtc::Optional<uint8_t> audio_level() const { return audio_level_; } |
| 64 | void set_audio_level(const rtc::Optional<uint8_t>& level) { |
| 65 | audio_level_ = level; |
| 66 | } |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 67 | |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 68 | bool operator==(const RtpSource& o) const { |
| 69 | return timestamp_ms_ == o.timestamp_ms() && source_id_ == o.source_id() && |
zstein | 2b70634 | 2017-08-24 14:52:17 -0700 | [diff] [blame] | 70 | source_type_ == o.source_type() && audio_level_ == o.audio_level_; |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 71 | } |
| 72 | |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 73 | private: |
| 74 | int64_t timestamp_ms_; |
| 75 | uint32_t source_id_; |
| 76 | RtpSourceType source_type_; |
zstein | 2b70634 | 2017-08-24 14:52:17 -0700 | [diff] [blame] | 77 | rtc::Optional<uint8_t> audio_level_; |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 80 | class RtpReceiverObserverInterface { |
| 81 | public: |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 82 | // Note: Currently if there are multiple RtpReceivers of the same media type, |
| 83 | // they will all call OnFirstPacketReceived at once. |
| 84 | // |
| 85 | // In the future, it's likely that an RtpReceiver will only call |
| 86 | // OnFirstPacketReceived when a packet is received specifically for its |
| 87 | // SSRC/mid. |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 88 | virtual void OnFirstPacketReceived(cricket::MediaType media_type) = 0; |
| 89 | |
| 90 | protected: |
| 91 | virtual ~RtpReceiverObserverInterface() {} |
| 92 | }; |
| 93 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 94 | class RtpReceiverInterface : public rtc::RefCountInterface { |
| 95 | public: |
| 96 | virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0; |
Henrik Boström | 9e6fd2b | 2017-11-21 13:41:51 +0100 | [diff] [blame] | 97 | // The list of streams that |track| is associated with. This is the same as |
| 98 | // the [[AssociatedRemoteMediaStreams]] internal slot in the spec. |
| 99 | // https://w3c.github.io/webrtc-pc/#dfn-x%5B%5Bassociatedremotemediastreams%5D%5D |
| 100 | // TODO(hbos): Make pure virtual as soon as Chromium's mock implements this. |
| 101 | virtual std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams() |
| 102 | const { |
| 103 | return std::vector<rtc::scoped_refptr<MediaStreamInterface>>(); |
| 104 | } |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 105 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 106 | // Audio or video receiver? |
| 107 | virtual cricket::MediaType media_type() const = 0; |
| 108 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 109 | // Not to be confused with "mid", this is a field we can temporarily use |
| 110 | // to uniquely identify a receiver until we implement Unified Plan SDP. |
| 111 | virtual std::string id() const = 0; |
| 112 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 113 | // The WebRTC specification only defines RTCRtpParameters in terms of senders, |
| 114 | // but this API also applies them to receivers, similar to ORTC: |
| 115 | // http://ortc.org/wp-content/uploads/2016/03/ortc.html#rtcrtpparameters*. |
| 116 | virtual RtpParameters GetParameters() const = 0; |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 117 | // Currently, doesn't support changing any parameters, but may in the future. |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 118 | virtual bool SetParameters(const RtpParameters& parameters) = 0; |
| 119 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 120 | // Does not take ownership of observer. |
| 121 | // Must call SetObserver(nullptr) before the observer is destroyed. |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 122 | virtual void SetObserver(RtpReceiverObserverInterface* observer) = 0; |
| 123 | |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 124 | // TODO(zhihuang): Remove the default implementation once the subclasses |
| 125 | // implement this. Currently, the only relevant subclass is the |
| 126 | // content::FakeRtpReceiver in Chromium. |
| 127 | virtual std::vector<RtpSource> GetSources() const { |
| 128 | return std::vector<RtpSource>(); |
| 129 | } |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 130 | // TODO(hta): Remove default implementation or move function to |
| 131 | // an internal interface. content::FakeRtpReceiver in Chromium needs this. |
| 132 | |
| 133 | // Returns an ID that changes if the attached track changes, but |
| 134 | // otherwise remains constant. Used to generate IDs for stats. |
| 135 | // The special value zero means that no track is attached. |
| 136 | virtual int AttachmentId() const { return 0; } |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 137 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 138 | protected: |
| 139 | virtual ~RtpReceiverInterface() {} |
| 140 | }; |
| 141 | |
| 142 | // Define proxy for RtpReceiverInterface. |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 143 | // TODO(deadbeef): Move this to .cc file and out of api/. What threads methods |
| 144 | // are called on is an implementation detail. |
nisse | 72c8d2b | 2016-04-15 03:49:07 -0700 | [diff] [blame] | 145 | BEGIN_SIGNALING_PROXY_MAP(RtpReceiver) |
deadbeef | d99a200 | 2017-01-18 08:55:23 -0800 | [diff] [blame] | 146 | PROXY_SIGNALING_THREAD_DESTRUCTOR() |
| 147 | PROXY_CONSTMETHOD0(rtc::scoped_refptr<MediaStreamTrackInterface>, track) |
Henrik Boström | 9e6fd2b | 2017-11-21 13:41:51 +0100 | [diff] [blame] | 148 | PROXY_CONSTMETHOD0(std::vector<rtc::scoped_refptr<MediaStreamInterface>>, |
| 149 | streams) |
deadbeef | d99a200 | 2017-01-18 08:55:23 -0800 | [diff] [blame] | 150 | PROXY_CONSTMETHOD0(cricket::MediaType, media_type) |
| 151 | PROXY_CONSTMETHOD0(std::string, id) |
| 152 | PROXY_CONSTMETHOD0(RtpParameters, GetParameters); |
| 153 | PROXY_METHOD1(bool, SetParameters, const RtpParameters&) |
| 154 | PROXY_METHOD1(void, SetObserver, RtpReceiverObserverInterface*); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 155 | PROXY_CONSTMETHOD0(std::vector<RtpSource>, GetSources); |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 156 | PROXY_CONSTMETHOD0(int, AttachmentId); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 157 | END_PROXY_MAP() |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 158 | |
| 159 | } // namespace webrtc |
| 160 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 161 | #endif // API_RTPRECEIVERINTERFACE_H_ |