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" |
Marina Ciocea | 412a31b | 2020-02-28 16:02:06 +0100 | [diff] [blame] | 22 | #include "api/frame_transformer_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 23 | #include "api/media_stream_interface.h" |
| 24 | #include "api/media_types.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 25 | #include "api/proxy.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 26 | #include "api/rtp_parameters.h" |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 27 | #include "api/scoped_refptr.h" |
Niels Möller | a837030 | 2019-09-02 15:16:49 +0200 | [diff] [blame] | 28 | #include "api/transport/rtp/rtp_source.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 29 | #include "rtc_base/ref_count.h" |
Mirko Bonadei | 35214fc | 2019-09-23 14:54:28 +0200 | [diff] [blame] | 30 | #include "rtc_base/system/rtc_export.h" |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 31 | |
| 32 | namespace webrtc { |
| 33 | |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 34 | class RtpReceiverObserverInterface { |
| 35 | public: |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 36 | // Note: Currently if there are multiple RtpReceivers of the same media type, |
| 37 | // they will all call OnFirstPacketReceived at once. |
| 38 | // |
| 39 | // In the future, it's likely that an RtpReceiver will only call |
| 40 | // OnFirstPacketReceived when a packet is received specifically for its |
| 41 | // SSRC/mid. |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 42 | virtual void OnFirstPacketReceived(cricket::MediaType media_type) = 0; |
| 43 | |
| 44 | protected: |
| 45 | virtual ~RtpReceiverObserverInterface() {} |
| 46 | }; |
| 47 | |
Mirko Bonadei | 35214fc | 2019-09-23 14:54:28 +0200 | [diff] [blame] | 48 | class RTC_EXPORT RtpReceiverInterface : public rtc::RefCountInterface { |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 49 | public: |
| 50 | virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0; |
Harald Alvestrand | 4a7b3ac | 2019-01-17 10:39:40 +0100 | [diff] [blame] | 51 | |
| 52 | // The dtlsTransport attribute exposes the DTLS transport on which the |
| 53 | // media is received. It may be null. |
| 54 | // https://w3c.github.io/webrtc-pc/#dom-rtcrtpreceiver-transport |
| 55 | // TODO(https://bugs.webrtc.org/907849) remove default implementation |
| 56 | virtual rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const; |
| 57 | |
Henrik Boström | 9e6fd2b | 2017-11-21 13:41:51 +0100 | [diff] [blame] | 58 | // The list of streams that |track| is associated with. This is the same as |
| 59 | // the [[AssociatedRemoteMediaStreams]] internal slot in the spec. |
Henrik Boström | 199e27b | 2018-07-04 20:51:53 +0200 | [diff] [blame] | 60 | // https://w3c.github.io/webrtc-pc/#dfn-associatedremotemediastreams |
Henrik Boström | 9e6fd2b | 2017-11-21 13:41:51 +0100 | [diff] [blame] | 61 | // 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] | 62 | // TODO(https://crbug.com/webrtc/9480): Remove streams() in favor of |
| 63 | // stream_ids() as soon as downstream projects are no longer dependent on |
| 64 | // stream objects. |
| 65 | virtual std::vector<std::string> stream_ids() const; |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 66 | virtual std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams() const; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 67 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 68 | // Audio or video receiver? |
| 69 | virtual cricket::MediaType media_type() const = 0; |
| 70 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 71 | // Not to be confused with "mid", this is a field we can temporarily use |
| 72 | // to uniquely identify a receiver until we implement Unified Plan SDP. |
| 73 | virtual std::string id() const = 0; |
| 74 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 75 | // The WebRTC specification only defines RTCRtpParameters in terms of senders, |
| 76 | // but this API also applies them to receivers, similar to ORTC: |
| 77 | // http://ortc.org/wp-content/uploads/2016/03/ortc.html#rtcrtpparameters*. |
| 78 | virtual RtpParameters GetParameters() const = 0; |
Saurav Das | 934afc6 | 2019-11-21 11:54:16 -0800 | [diff] [blame] | 79 | // TODO(dinosaurav): Delete SetParameters entirely after rolling to Chromium. |
| 80 | // Currently, doesn't support changing any parameters. |
| 81 | virtual bool SetParameters(const RtpParameters& parameters) { return false; } |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 82 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 83 | // Does not take ownership of observer. |
| 84 | // Must call SetObserver(nullptr) before the observer is destroyed. |
zhihuang | 184a3fd | 2016-06-14 11:47:14 -0700 | [diff] [blame] | 85 | virtual void SetObserver(RtpReceiverObserverInterface* observer) = 0; |
| 86 | |
Ruslan Burakov | 4bac79e | 2019-04-03 19:55:33 +0200 | [diff] [blame] | 87 | // Sets the jitter buffer minimum delay until media playout. Actual observed |
| 88 | // delay may differ depending on the congestion control. |delay_seconds| is a |
| 89 | // positive value including 0.0 measured in seconds. |nullopt| means default |
Ruslan Burakov | 428dcb2 | 2019-04-18 17:49:49 +0200 | [diff] [blame] | 90 | // value must be used. |
Ruslan Burakov | 4bac79e | 2019-04-03 19:55:33 +0200 | [diff] [blame] | 91 | virtual void SetJitterBufferMinimumDelay( |
Ruslan Burakov | 428dcb2 | 2019-04-18 17:49:49 +0200 | [diff] [blame] | 92 | absl::optional<double> delay_seconds) = 0; |
Ruslan Burakov | 4bac79e | 2019-04-03 19:55:33 +0200 | [diff] [blame] | 93 | |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 94 | // TODO(zhihuang): Remove the default implementation once the subclasses |
| 95 | // implement this. Currently, the only relevant subclass is the |
| 96 | // content::FakeRtpReceiver in Chromium. |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 97 | virtual std::vector<RtpSource> GetSources() const; |
| 98 | |
Benjamin Wright | d81ac95 | 2018-08-29 17:02:10 -0700 | [diff] [blame] | 99 | // Sets a user defined frame decryptor that will decrypt the entire frame |
| 100 | // before it is sent across the network. This will decrypt the entire frame |
| 101 | // using the user provided decryption mechanism regardless of whether SRTP is |
| 102 | // enabled or not. |
| 103 | virtual void SetFrameDecryptor( |
| 104 | rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor); |
| 105 | |
| 106 | // Returns a pointer to the frame decryptor set previously by the |
| 107 | // user. This can be used to update the state of the object. |
| 108 | virtual rtc::scoped_refptr<FrameDecryptorInterface> GetFrameDecryptor() const; |
| 109 | |
Marina Ciocea | 412a31b | 2020-02-28 16:02:06 +0100 | [diff] [blame] | 110 | // Sets a frame transformer between the depacketizer and the decoder to enable |
| 111 | // client code to transform received frames according to their own processing |
| 112 | // logic. |
| 113 | virtual void SetDepacketizerToDecoderFrameTransformer( |
| 114 | rtc::scoped_refptr<FrameTransformerInterface> frame_transformer); |
| 115 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 116 | protected: |
Danil Chapovalov | 2a5ce2b | 2018-02-07 09:38:31 +0100 | [diff] [blame] | 117 | ~RtpReceiverInterface() override = default; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | // Define proxy for RtpReceiverInterface. |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 121 | // TODO(deadbeef): Move this to .cc file and out of api/. What threads methods |
| 122 | // are called on is an implementation detail. |
Mirko Bonadei | 07a01d0 | 2021-02-26 07:18:39 +0000 | [diff] [blame] | 123 | BEGIN_SIGNALING_PROXY_MAP(RtpReceiver) |
| 124 | PROXY_SIGNALING_THREAD_DESTRUCTOR() |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 125 | PROXY_CONSTMETHOD0(rtc::scoped_refptr<MediaStreamTrackInterface>, track) |
Harald Alvestrand | 4a7b3ac | 2019-01-17 10:39:40 +0100 | [diff] [blame] | 126 | PROXY_CONSTMETHOD0(rtc::scoped_refptr<DtlsTransportInterface>, dtls_transport) |
Henrik Boström | 5b14778 | 2018-12-04 11:25:05 +0100 | [diff] [blame] | 127 | PROXY_CONSTMETHOD0(std::vector<std::string>, stream_ids) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 128 | PROXY_CONSTMETHOD0(std::vector<rtc::scoped_refptr<MediaStreamInterface>>, |
| 129 | streams) |
Tomas Gunnarsson | fc83cdc | 2020-09-10 13:04:50 +0200 | [diff] [blame] | 130 | BYPASS_PROXY_CONSTMETHOD0(cricket::MediaType, media_type) |
| 131 | BYPASS_PROXY_CONSTMETHOD0(std::string, id) |
Nico Weber | 22f9925 | 2019-02-20 10:13:16 -0500 | [diff] [blame] | 132 | PROXY_CONSTMETHOD0(RtpParameters, GetParameters) |
Nico Weber | 22f9925 | 2019-02-20 10:13:16 -0500 | [diff] [blame] | 133 | PROXY_METHOD1(void, SetObserver, RtpReceiverObserverInterface*) |
Ruslan Burakov | 4bac79e | 2019-04-03 19:55:33 +0200 | [diff] [blame] | 134 | PROXY_METHOD1(void, SetJitterBufferMinimumDelay, absl::optional<double>) |
Nico Weber | 22f9925 | 2019-02-20 10:13:16 -0500 | [diff] [blame] | 135 | PROXY_CONSTMETHOD0(std::vector<RtpSource>, GetSources) |
Benjamin Wright | d81ac95 | 2018-08-29 17:02:10 -0700 | [diff] [blame] | 136 | PROXY_METHOD1(void, |
| 137 | SetFrameDecryptor, |
Nico Weber | 22f9925 | 2019-02-20 10:13:16 -0500 | [diff] [blame] | 138 | rtc::scoped_refptr<FrameDecryptorInterface>) |
Benjamin Wright | d81ac95 | 2018-08-29 17:02:10 -0700 | [diff] [blame] | 139 | PROXY_CONSTMETHOD0(rtc::scoped_refptr<FrameDecryptorInterface>, |
Nico Weber | 22f9925 | 2019-02-20 10:13:16 -0500 | [diff] [blame] | 140 | GetFrameDecryptor) |
Marina Ciocea | 412a31b | 2020-02-28 16:02:06 +0100 | [diff] [blame] | 141 | PROXY_METHOD1(void, |
| 142 | SetDepacketizerToDecoderFrameTransformer, |
| 143 | rtc::scoped_refptr<FrameTransformerInterface>) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 144 | END_PROXY_MAP() |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 145 | |
| 146 | } // namespace webrtc |
| 147 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 148 | #endif // API_RTP_RECEIVER_INTERFACE_H_ |