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