blob: 91d7b3c561b1539525b6f70aeb3e6308d8f67d2c [file] [log] [blame]
deadbeef6979b022015-09-24 23:47:531/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
deadbeef6979b022015-09-24 23:47:533 *
kjellanderb24317b2016-02-10 15:54:434 * 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.
deadbeef6979b022015-09-24 23:47:539 */
10
deadbeef70ab1a12015-09-28 23:53:5511// This file contains interfaces for RtpSenders
12// http://w3c.github.io/webrtc-pc/#rtcrtpsender-interface
13
Steve Anton10542f22019-01-11 17:11:0014#ifndef API_RTP_SENDER_INTERFACE_H_
15#define API_RTP_SENDER_INTERFACE_H_
deadbeef70ab1a12015-09-28 23:53:5516
Harald Alvestrandb0e70572024-04-23 14:04:1817#include <cstdint>
Jonas Oreland65455162022-06-08 09:25:4618#include <memory>
deadbeef70ab1a12015-09-28 23:53:5519#include <string>
Harald Alvestrandb0e70572024-04-23 14:04:1820#include <utility>
deadbeefa601f5c2016-06-06 21:27:3921#include <vector>
deadbeef70ab1a12015-09-28 23:53:5522
Florent Castelliacabb362022-10-18 15:05:1623#include "absl/functional/any_invocable.h"
Steve Anton10542f22019-01-11 17:11:0024#include "api/crypto/frame_encryptor_interface.h"
Harald Alvestrand4a7b3ac2019-01-17 09:39:4025#include "api/dtls_transport_interface.h"
Steve Anton10542f22019-01-11 17:11:0026#include "api/dtmf_sender_interface.h"
Marina Cioceae77912b2020-02-27 15:16:5527#include "api/frame_transformer_interface.h"
Steve Anton10542f22019-01-11 17:11:0028#include "api/media_stream_interface.h"
29#include "api/media_types.h"
Harald Alvestrande8a2b3c2023-10-31 13:30:3030#include "api/ref_count.h"
Steve Anton10542f22019-01-11 17:11:0031#include "api/rtc_error.h"
32#include "api/rtp_parameters.h"
Mirko Bonadeid9708072019-01-25 19:26:4833#include "api/scoped_refptr.h"
Jonas Oreland65455162022-06-08 09:25:4634#include "api/video_codecs/video_encoder_factory.h"
Mirko Bonadei35214fc2019-09-23 12:54:2835#include "rtc_base/system/rtc_export.h"
deadbeef70ab1a12015-09-28 23:53:5536
37namespace webrtc {
38
Jakob Ivarsson68f4e272024-10-25 14:58:2939class 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 Castelliacabb362022-10-18 15:05:1649using SetParametersCallback = absl::AnyInvocable<void(RTCError) &&>;
50
Harald Alvestrandb0e70572024-04-23 14:04:1851class RTC_EXPORT RtpSenderInterface : public webrtc::RefCountInterface,
52 public FrameTransformerHost {
deadbeef70ab1a12015-09-28 23:53:5553 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 Alvestrand4a7b3ac2019-01-17 09:39:4059 // 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 Logvin24c10792022-08-31 08:55:3362 virtual rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const = 0;
Harald Alvestrand4a7b3ac2019-01-17 09:39:4063
deadbeefa601f5c2016-06-06 21:27:3964 // Returns primary SSRC used by this sender for sending media.
65 // Returns 0 if not yet determined.
Florent Castelli8037fc62024-08-29 13:00:4066 // TODO(deadbeef): Change to std::optional.
deadbeefa601f5c2016-06-06 21:27:3967 // TODO(deadbeef): Remove? With GetParameters this should be redundant.
deadbeeffac06552015-11-25 19:26:0168 virtual uint32_t ssrc() const = 0;
69
70 // Audio or video sender?
71 virtual cricket::MediaType media_type() const = 0;
72
deadbeef70ab1a12015-09-28 23:53:5573 // 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 Hampson5b4f0752018-04-02 23:31:3677 // 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.
deadbeefa601f5c2016-06-06 21:27:3980 virtual std::vector<std::string> stream_ids() const = 0;
deadbeef70ab1a12015-09-28 23:53:5581
Guido Urdaneta1ff16c82019-05-20 17:31:5382 // 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 Logvin24c10792022-08-31 08:55:3385 virtual void SetStreams(const std::vector<std::string>& stream_ids) = 0;
Guido Urdaneta1ff16c82019-05-20 17:31:5386
Florent Castelli892acf02018-10-01 20:47:2087 // 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 Logvin24c10792022-08-31 08:55:3391 virtual std::vector<RtpEncodingParameters> init_send_encodings() const = 0;
Florent Castelli892acf02018-10-01 20:47:2092
Amit Hilbuche1e789b2019-02-20 18:40:1293 virtual RtpParameters GetParameters() const = 0;
deadbeefb10f32f2017-02-08 09:38:2194 // Note that only a subset of the parameters can currently be changed. See
95 // rtpparameters.h
Åsa Persson55659812018-06-18 15:51:3296 // The encodings are in increasing quality order for simulcast.
Zach Steinba37b4b2018-01-23 23:02:3697 virtual RTCError SetParameters(const RtpParameters& parameters) = 0;
Florent Castelliacabb362022-10-18 15:05:1698 virtual void SetParametersAsync(const RtpParameters& parameters,
99 SetParametersCallback callback);
skvladdc1c62c2016-03-17 02:07:43100
Jakob Ivarsson68f4e272024-10-25 14:58:29101 // 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 Hen90c67e72024-10-27 12:49:27105 virtual void SetObserver(RtpSenderObserverInterface* /* observer */) {}
Jakob Ivarsson68f4e272024-10-25 14:58:29106
deadbeef20cb0c12017-02-02 04:27:00107 // Returns null for a video sender.
108 virtual rtc::scoped_refptr<DtmfSenderInterface> GetDtmfSender() const = 0;
109
Benjamin Wrightd81ac952018-08-30 00:02:10110 // 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 Logvin24c10792022-08-31 08:55:33115 rtc::scoped_refptr<FrameEncryptorInterface> frame_encryptor) = 0;
Benjamin Wrightd81ac952018-08-30 00:02:10116
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 Logvin24c10792022-08-31 08:55:33119 virtual rtc::scoped_refptr<FrameEncryptorInterface> GetFrameEncryptor()
120 const = 0;
Benjamin Wrightd81ac952018-08-30 00:02:10121
Harald Alvestrandb0e70572024-04-23 14:04:18122 // TODO: bugs.webrtc.org/15929 - add [[deprecated("Use SetFrameTransformer")]]
123 // when usage in Chrome is removed
Marina Cioceae77912b2020-02-27 15:16:55124 virtual void SetEncoderToPacketizerFrameTransformer(
Harald Alvestrandb0e70572024-04-23 14:04:18125 rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) {
126 SetFrameTransformer(std::move(frame_transformer));
127 }
Marina Cioceae77912b2020-02-27 15:16:55128
Jonas Oreland65455162022-06-08 09:25:46129 // 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 Logvin24c10792022-08-31 08:55:33133 encoder_selector) = 0;
Jonas Oreland65455162022-06-08 09:25:46134
Harald Alvestrandb0e70572024-04-23 14:04:18135 // Default implementation of SetFrameTransformer.
136 // TODO: bugs.webrtc.org/15929 - remove when all implementations are good
137 void SetFrameTransformer(rtc::scoped_refptr<FrameTransformerInterface>
Dor Hen049b43b2024-10-15 07:51:54138 /* frame_transformer */) override {}
Harald Alvestrandb0e70572024-04-23 14:04:18139
deadbeef70ab1a12015-09-28 23:53:55140 protected:
Mirko Bonadei79eb4dd2018-07-19 08:39:30141 ~RtpSenderInterface() override = default;
deadbeef70ab1a12015-09-28 23:53:55142};
143
deadbeef70ab1a12015-09-28 23:53:55144} // namespace webrtc
145
Steve Anton10542f22019-01-11 17:11:00146#endif // API_RTP_SENDER_INTERFACE_H_