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 RtpSenders |
| 12 | // http://w3c.github.io/webrtc-pc/#rtcrtpsender-interface |
| 13 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 14 | #ifndef API_RTP_SENDER_INTERFACE_H_ |
| 15 | #define API_RTP_SENDER_INTERFACE_H_ |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 16 | |
Harald Alvestrand | b0e7057 | 2024-04-23 14:04:18 | [diff] [blame] | 17 | #include <cstdint> |
Jonas Oreland | 6545516 | 2022-06-08 09:25:46 | [diff] [blame] | 18 | #include <memory> |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 19 | #include <string> |
Harald Alvestrand | b0e7057 | 2024-04-23 14:04:18 | [diff] [blame] | 20 | #include <utility> |
deadbeef | a601f5c | 2016-06-06 21:27:39 | [diff] [blame] | 21 | #include <vector> |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 22 | |
Florent Castelli | acabb36 | 2022-10-18 15:05:16 | [diff] [blame] | 23 | #include "absl/functional/any_invocable.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 24 | #include "api/crypto/frame_encryptor_interface.h" |
Harald Alvestrand | 4a7b3ac | 2019-01-17 09:39:40 | [diff] [blame] | 25 | #include "api/dtls_transport_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 26 | #include "api/dtmf_sender_interface.h" |
Marina Ciocea | e77912b | 2020-02-27 15:16:55 | [diff] [blame] | 27 | #include "api/frame_transformer_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 28 | #include "api/media_stream_interface.h" |
| 29 | #include "api/media_types.h" |
Harald Alvestrand | e8a2b3c | 2023-10-31 13:30:30 | [diff] [blame] | 30 | #include "api/ref_count.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 31 | #include "api/rtc_error.h" |
| 32 | #include "api/rtp_parameters.h" |
Mirko Bonadei | d970807 | 2019-01-25 19:26:48 | [diff] [blame] | 33 | #include "api/scoped_refptr.h" |
Jonas Oreland | 6545516 | 2022-06-08 09:25:46 | [diff] [blame] | 34 | #include "api/video_codecs/video_encoder_factory.h" |
Mirko Bonadei | 35214fc | 2019-09-23 12:54:28 | [diff] [blame] | 35 | #include "rtc_base/system/rtc_export.h" |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 36 | |
| 37 | namespace webrtc { |
| 38 | |
Jakob Ivarsson | 68f4e27 | 2024-10-25 14:58:29 | [diff] [blame] | 39 | class RtpSenderObserverInterface { |
| 40 | public: |
| 41 | // The observer is called when the first media packet is sent for the observed |
| 42 | // sender. It is called immediately if the first packet was already sent. |
| 43 | virtual void OnFirstPacketSent(cricket::MediaType media_type) = 0; |
| 44 | |
| 45 | protected: |
| 46 | virtual ~RtpSenderObserverInterface() {} |
| 47 | }; |
| 48 | |
Florent Castelli | acabb36 | 2022-10-18 15:05:16 | [diff] [blame] | 49 | using SetParametersCallback = absl::AnyInvocable<void(RTCError) &&>; |
| 50 | |
Harald Alvestrand | b0e7057 | 2024-04-23 14:04:18 | [diff] [blame] | 51 | class RTC_EXPORT RtpSenderInterface : public webrtc::RefCountInterface, |
| 52 | public FrameTransformerHost { |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 53 | public: |
| 54 | // Returns true if successful in setting the track. |
| 55 | // Fails if an audio track is set on a video RtpSender, or vice-versa. |
| 56 | virtual bool SetTrack(MediaStreamTrackInterface* track) = 0; |
| 57 | virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0; |
| 58 | |
Harald Alvestrand | 4a7b3ac | 2019-01-17 09:39:40 | [diff] [blame] | 59 | // The dtlsTransport attribute exposes the DTLS transport on which the |
| 60 | // media is sent. It may be null. |
| 61 | // https://w3c.github.io/webrtc-pc/#dom-rtcrtpsender-transport |
Andrey Logvin | 24c1079 | 2022-08-31 08:55:33 | [diff] [blame] | 62 | virtual rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const = 0; |
Harald Alvestrand | 4a7b3ac | 2019-01-17 09:39:40 | [diff] [blame] | 63 | |
deadbeef | a601f5c | 2016-06-06 21:27:39 | [diff] [blame] | 64 | // Returns primary SSRC used by this sender for sending media. |
| 65 | // Returns 0 if not yet determined. |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 66 | // TODO(deadbeef): Change to std::optional. |
deadbeef | a601f5c | 2016-06-06 21:27:39 | [diff] [blame] | 67 | // TODO(deadbeef): Remove? With GetParameters this should be redundant. |
deadbeef | fac0655 | 2015-11-25 19:26:01 | [diff] [blame] | 68 | virtual uint32_t ssrc() const = 0; |
| 69 | |
| 70 | // Audio or video sender? |
| 71 | virtual cricket::MediaType media_type() const = 0; |
| 72 | |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 73 | // Not to be confused with "mid", this is a field we can temporarily use |
| 74 | // to uniquely identify a receiver until we implement Unified Plan SDP. |
| 75 | virtual std::string id() const = 0; |
| 76 | |
Seth Hampson | 5b4f075 | 2018-04-02 23:31:36 | [diff] [blame] | 77 | // Returns a list of media stream ids associated with this sender's track. |
| 78 | // These are signalled in the SDP so that the remote side can associate |
| 79 | // tracks. |
deadbeef | a601f5c | 2016-06-06 21:27:39 | [diff] [blame] | 80 | virtual std::vector<std::string> stream_ids() const = 0; |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 81 | |
Guido Urdaneta | 1ff16c8 | 2019-05-20 17:31:53 | [diff] [blame] | 82 | // Sets the IDs of the media streams associated with this sender's track. |
| 83 | // These are signalled in the SDP so that the remote side can associate |
| 84 | // tracks. |
Andrey Logvin | 24c1079 | 2022-08-31 08:55:33 | [diff] [blame] | 85 | virtual void SetStreams(const std::vector<std::string>& stream_ids) = 0; |
Guido Urdaneta | 1ff16c8 | 2019-05-20 17:31:53 | [diff] [blame] | 86 | |
Florent Castelli | 892acf0 | 2018-10-01 20:47:20 | [diff] [blame] | 87 | // Returns the list of encoding parameters that will be applied when the SDP |
| 88 | // local description is set. These initial encoding parameters can be set by |
| 89 | // PeerConnection::AddTransceiver, and later updated with Get/SetParameters. |
| 90 | // TODO(orphis): Make it pure virtual once Chrome has updated |
Andrey Logvin | 24c1079 | 2022-08-31 08:55:33 | [diff] [blame] | 91 | virtual std::vector<RtpEncodingParameters> init_send_encodings() const = 0; |
Florent Castelli | 892acf0 | 2018-10-01 20:47:20 | [diff] [blame] | 92 | |
Amit Hilbuch | e1e789b | 2019-02-20 18:40:12 | [diff] [blame] | 93 | virtual RtpParameters GetParameters() const = 0; |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 94 | // Note that only a subset of the parameters can currently be changed. See |
| 95 | // rtpparameters.h |
Åsa Persson | 5565981 | 2018-06-18 15:51:32 | [diff] [blame] | 96 | // The encodings are in increasing quality order for simulcast. |
Zach Stein | ba37b4b | 2018-01-23 23:02:36 | [diff] [blame] | 97 | virtual RTCError SetParameters(const RtpParameters& parameters) = 0; |
Florent Castelli | acabb36 | 2022-10-18 15:05:16 | [diff] [blame] | 98 | virtual void SetParametersAsync(const RtpParameters& parameters, |
| 99 | SetParametersCallback callback); |
skvlad | dc1c62c | 2016-03-17 02:07:43 | [diff] [blame] | 100 | |
Jakob Ivarsson | 68f4e27 | 2024-10-25 14:58:29 | [diff] [blame] | 101 | // Sets an observer which gets a callback when the first media packet is sent |
| 102 | // for this sender. |
| 103 | // Does not take ownership of observer. |
| 104 | // Must call SetObserver(nullptr) before the observer is destroyed. |
Dor Hen | 90c67e7 | 2024-10-27 12:49:27 | [diff] [blame] | 105 | virtual void SetObserver(RtpSenderObserverInterface* /* observer */) {} |
Jakob Ivarsson | 68f4e27 | 2024-10-25 14:58:29 | [diff] [blame] | 106 | |
deadbeef | 20cb0c1 | 2017-02-02 04:27:00 | [diff] [blame] | 107 | // Returns null for a video sender. |
| 108 | virtual rtc::scoped_refptr<DtmfSenderInterface> GetDtmfSender() const = 0; |
| 109 | |
Benjamin Wright | d81ac95 | 2018-08-30 00:02:10 | [diff] [blame] | 110 | // Sets a user defined frame encryptor that will encrypt the entire frame |
| 111 | // before it is sent across the network. This will encrypt the entire frame |
| 112 | // using the user provided encryption mechanism regardless of whether SRTP is |
| 113 | // enabled or not. |
| 114 | virtual void SetFrameEncryptor( |
Andrey Logvin | 24c1079 | 2022-08-31 08:55:33 | [diff] [blame] | 115 | rtc::scoped_refptr<FrameEncryptorInterface> frame_encryptor) = 0; |
Benjamin Wright | d81ac95 | 2018-08-30 00:02:10 | [diff] [blame] | 116 | |
| 117 | // Returns a pointer to the frame encryptor set previously by the |
| 118 | // user. This can be used to update the state of the object. |
Andrey Logvin | 24c1079 | 2022-08-31 08:55:33 | [diff] [blame] | 119 | virtual rtc::scoped_refptr<FrameEncryptorInterface> GetFrameEncryptor() |
| 120 | const = 0; |
Benjamin Wright | d81ac95 | 2018-08-30 00:02:10 | [diff] [blame] | 121 | |
Harald Alvestrand | b0e7057 | 2024-04-23 14:04:18 | [diff] [blame] | 122 | // TODO: bugs.webrtc.org/15929 - add [[deprecated("Use SetFrameTransformer")]] |
| 123 | // when usage in Chrome is removed |
Marina Ciocea | e77912b | 2020-02-27 15:16:55 | [diff] [blame] | 124 | virtual void SetEncoderToPacketizerFrameTransformer( |
Harald Alvestrand | b0e7057 | 2024-04-23 14:04:18 | [diff] [blame] | 125 | rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) { |
| 126 | SetFrameTransformer(std::move(frame_transformer)); |
| 127 | } |
Marina Ciocea | e77912b | 2020-02-27 15:16:55 | [diff] [blame] | 128 | |
Jonas Oreland | 6545516 | 2022-06-08 09:25:46 | [diff] [blame] | 129 | // Sets a user defined encoder selector. |
| 130 | // Overrides selector that is (optionally) provided by VideoEncoderFactory. |
| 131 | virtual void SetEncoderSelector( |
| 132 | std::unique_ptr<VideoEncoderFactory::EncoderSelectorInterface> |
Andrey Logvin | 24c1079 | 2022-08-31 08:55:33 | [diff] [blame] | 133 | encoder_selector) = 0; |
Jonas Oreland | 6545516 | 2022-06-08 09:25:46 | [diff] [blame] | 134 | |
Harald Alvestrand | b0e7057 | 2024-04-23 14:04:18 | [diff] [blame] | 135 | // Default implementation of SetFrameTransformer. |
| 136 | // TODO: bugs.webrtc.org/15929 - remove when all implementations are good |
| 137 | void SetFrameTransformer(rtc::scoped_refptr<FrameTransformerInterface> |
Dor Hen | 049b43b | 2024-10-15 07:51:54 | [diff] [blame] | 138 | /* frame_transformer */) override {} |
Harald Alvestrand | b0e7057 | 2024-04-23 14:04:18 | [diff] [blame] | 139 | |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 140 | protected: |
Mirko Bonadei | 79eb4dd | 2018-07-19 08:39:30 | [diff] [blame] | 141 | ~RtpSenderInterface() override = default; |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 142 | }; |
| 143 | |
deadbeef | 70ab1a1 | 2015-09-28 23:53:55 | [diff] [blame] | 144 | } // namespace webrtc |
| 145 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 146 | #endif // API_RTP_SENDER_INTERFACE_H_ |