deadbeef | 6979b02 | 2015-09-24 23:47:53 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
deadbeef | 6979b02 | 2015-09-24 23:47:53 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 15:54:43 | [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 23:47:53 | [diff] [blame] | 9 | */ |
| 10 | |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [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 04:47:31 | [diff] [blame] | 14 | #ifndef API_RTPRECEIVERINTERFACE_H_ |
| 15 | #define API_RTPRECEIVERINTERFACE_H_ |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 16 | |
| 17 | #include <string> |
hbos | 8d609f6 | 2017-04-10 14:39:05 | [diff] [blame] | 18 | #include <vector> |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 19 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [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 23:53:55 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
| 28 | |
hbos | 8d609f6 | 2017-04-10 14:39:05 | [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 21:52:17 | [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 14:39:05 | [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 21:52:17 | [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 14:39:05 | [diff] [blame] | 67 | |
zhihuang | 0426222 | 2017-04-11 18:28:10 | [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 21:52:17 | [diff] [blame] | 70 | source_type_ == o.source_type() && audio_level_ == o.audio_level_; |
zhihuang | 0426222 | 2017-04-11 18:28:10 | [diff] [blame] | 71 | } |
| 72 | |
hbos | 8d609f6 | 2017-04-10 14:39:05 | [diff] [blame] | 73 | private: |
| 74 | int64_t timestamp_ms_; |
| 75 | uint32_t source_id_; |
| 76 | RtpSourceType source_type_; |
zstein | 2b70634 | 2017-08-24 21:52:17 | [diff] [blame] | 77 | rtc::Optional<uint8_t> audio_level_; |
hbos | 8d609f6 | 2017-04-10 14:39:05 | [diff] [blame] | 78 | }; |
| 79 | |
zhihuang | 184a3fd | 2016-06-14 18:47:14 | [diff] [blame] | 80 | class RtpReceiverObserverInterface { |
| 81 | public: |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [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 18:47:14 | [diff] [blame] | 88 | virtual void OnFirstPacketReceived(cricket::MediaType media_type) = 0; |
| 89 | |
| 90 | protected: |
| 91 | virtual ~RtpReceiverObserverInterface() {} |
| 92 | }; |
| 93 | |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 94 | class RtpReceiverInterface : public rtc::RefCountInterface { |
| 95 | public: |
| 96 | virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0; |
| 97 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 98 | // Audio or video receiver? |
| 99 | virtual cricket::MediaType media_type() const = 0; |
| 100 | |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 101 | // Not to be confused with "mid", this is a field we can temporarily use |
| 102 | // to uniquely identify a receiver until we implement Unified Plan SDP. |
| 103 | virtual std::string id() const = 0; |
| 104 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 18:40:30 | [diff] [blame] | 105 | // The WebRTC specification only defines RTCRtpParameters in terms of senders, |
| 106 | // but this API also applies them to receivers, similar to ORTC: |
| 107 | // http://ortc.org/wp-content/uploads/2016/03/ortc.html#rtcrtpparameters*. |
| 108 | virtual RtpParameters GetParameters() const = 0; |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 109 | // Currently, doesn't support changing any parameters, but may in the future. |
Taylor Brandstetter | db0cd9e | 2016-05-16 18:40:30 | [diff] [blame] | 110 | virtual bool SetParameters(const RtpParameters& parameters) = 0; |
| 111 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 23:30:35 | [diff] [blame] | 112 | // Does not take ownership of observer. |
| 113 | // Must call SetObserver(nullptr) before the observer is destroyed. |
zhihuang | 184a3fd | 2016-06-14 18:47:14 | [diff] [blame] | 114 | virtual void SetObserver(RtpReceiverObserverInterface* observer) = 0; |
| 115 | |
hbos | 8d609f6 | 2017-04-10 14:39:05 | [diff] [blame] | 116 | // TODO(zhihuang): Remove the default implementation once the subclasses |
| 117 | // implement this. Currently, the only relevant subclass is the |
| 118 | // content::FakeRtpReceiver in Chromium. |
| 119 | virtual std::vector<RtpSource> GetSources() const { |
| 120 | return std::vector<RtpSource>(); |
| 121 | } |
| 122 | |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 123 | protected: |
| 124 | virtual ~RtpReceiverInterface() {} |
| 125 | }; |
| 126 | |
| 127 | // Define proxy for RtpReceiverInterface. |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [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 10:49:07 | [diff] [blame] | 130 | BEGIN_SIGNALING_PROXY_MAP(RtpReceiver) |
deadbeef | d99a200 | 2017-01-18 16:55:23 | [diff] [blame] | 131 | PROXY_SIGNALING_THREAD_DESTRUCTOR() |
| 132 | PROXY_CONSTMETHOD0(rtc::scoped_refptr<MediaStreamTrackInterface>, track) |
| 133 | PROXY_CONSTMETHOD0(cricket::MediaType, media_type) |
| 134 | PROXY_CONSTMETHOD0(std::string, id) |
| 135 | PROXY_CONSTMETHOD0(RtpParameters, GetParameters); |
| 136 | PROXY_METHOD1(bool, SetParameters, const RtpParameters&) |
| 137 | PROXY_METHOD1(void, SetObserver, RtpReceiverObserverInterface*); |
hbos | 8d609f6 | 2017-04-10 14:39:05 | [diff] [blame] | 138 | PROXY_CONSTMETHOD0(std::vector<RtpSource>, GetSources); |
| 139 | END_PROXY_MAP() |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 140 | |
| 141 | } // namespace webrtc |
| 142 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 143 | #endif // API_RTPRECEIVERINTERFACE_H_ |