blob: 2786a2ac1948f1f6697801a8d8242013ed8bef46 [file] [log] [blame]
deadbeef6979b022015-09-24 16:47:53 -07001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
deadbeef6979b022015-09-24 16:47:53 -07003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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 16:47:53 -07009 */
10
deadbeef70ab1a12015-09-28 16:53:55 -070011// This file contains interfaces for RtpSenders
12// http://w3c.github.io/webrtc-pc/#rtcrtpsender-interface
13
Steve Anton10542f22019-01-11 09:11:00 -080014#ifndef API_RTP_SENDER_INTERFACE_H_
15#define API_RTP_SENDER_INTERFACE_H_
deadbeef70ab1a12015-09-28 16:53:55 -070016
Jonas Oreland65455162022-06-08 11:25:46 +020017#include <memory>
deadbeef70ab1a12015-09-28 16:53:55 -070018#include <string>
deadbeefa601f5c2016-06-06 14:27:39 -070019#include <vector>
deadbeef70ab1a12015-09-28 16:53:55 -070020
Florent Castelliacabb362022-10-18 17:05:16 +020021#include "absl/functional/any_invocable.h"
Steve Anton10542f22019-01-11 09:11:00 -080022#include "api/crypto/frame_encryptor_interface.h"
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +010023#include "api/dtls_transport_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080024#include "api/dtmf_sender_interface.h"
Marina Cioceae77912b2020-02-27 16:16:55 +010025#include "api/frame_transformer_interface.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "api/media_stream_interface.h"
27#include "api/media_types.h"
Steve Anton10542f22019-01-11 09:11:00 -080028#include "api/rtc_error.h"
29#include "api/rtp_parameters.h"
Mirko Bonadeid9708072019-01-25 20:26:48 +010030#include "api/scoped_refptr.h"
Jonas Oreland65455162022-06-08 11:25:46 +020031#include "api/video_codecs/video_encoder_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080032#include "rtc_base/ref_count.h"
Mirko Bonadei35214fc2019-09-23 14:54:28 +020033#include "rtc_base/system/rtc_export.h"
deadbeef70ab1a12015-09-28 16:53:55 -070034
35namespace webrtc {
36
Florent Castelliacabb362022-10-18 17:05:16 +020037using SetParametersCallback = absl::AnyInvocable<void(RTCError) &&>;
38
Mirko Bonadei35214fc2019-09-23 14:54:28 +020039class RTC_EXPORT RtpSenderInterface : public rtc::RefCountInterface {
deadbeef70ab1a12015-09-28 16:53:55 -070040 public:
41 // Returns true if successful in setting the track.
42 // Fails if an audio track is set on a video RtpSender, or vice-versa.
43 virtual bool SetTrack(MediaStreamTrackInterface* track) = 0;
44 virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0;
45
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +010046 // The dtlsTransport attribute exposes the DTLS transport on which the
47 // media is sent. It may be null.
48 // https://w3c.github.io/webrtc-pc/#dom-rtcrtpsender-transport
Andrey Logvin24c10792022-08-31 08:55:33 +000049 virtual rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const = 0;
Harald Alvestrand4a7b3ac2019-01-17 10:39:40 +010050
deadbeefa601f5c2016-06-06 14:27:39 -070051 // Returns primary SSRC used by this sender for sending media.
52 // Returns 0 if not yet determined.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020053 // TODO(deadbeef): Change to absl::optional.
deadbeefa601f5c2016-06-06 14:27:39 -070054 // TODO(deadbeef): Remove? With GetParameters this should be redundant.
deadbeeffac06552015-11-25 11:26:01 -080055 virtual uint32_t ssrc() const = 0;
56
57 // Audio or video sender?
58 virtual cricket::MediaType media_type() const = 0;
59
deadbeef70ab1a12015-09-28 16:53:55 -070060 // Not to be confused with "mid", this is a field we can temporarily use
61 // to uniquely identify a receiver until we implement Unified Plan SDP.
62 virtual std::string id() const = 0;
63
Seth Hampson5b4f0752018-04-02 16:31:36 -070064 // Returns a list of media stream ids associated with this sender's track.
65 // These are signalled in the SDP so that the remote side can associate
66 // tracks.
deadbeefa601f5c2016-06-06 14:27:39 -070067 virtual std::vector<std::string> stream_ids() const = 0;
deadbeef70ab1a12015-09-28 16:53:55 -070068
Guido Urdaneta1ff16c82019-05-20 19:31:53 +020069 // Sets the IDs of the media streams associated with this sender's track.
70 // These are signalled in the SDP so that the remote side can associate
71 // tracks.
Andrey Logvin24c10792022-08-31 08:55:33 +000072 virtual void SetStreams(const std::vector<std::string>& stream_ids) = 0;
Guido Urdaneta1ff16c82019-05-20 19:31:53 +020073
Florent Castelli892acf02018-10-01 22:47:20 +020074 // Returns the list of encoding parameters that will be applied when the SDP
75 // local description is set. These initial encoding parameters can be set by
76 // PeerConnection::AddTransceiver, and later updated with Get/SetParameters.
77 // TODO(orphis): Make it pure virtual once Chrome has updated
Andrey Logvin24c10792022-08-31 08:55:33 +000078 virtual std::vector<RtpEncodingParameters> init_send_encodings() const = 0;
Florent Castelli892acf02018-10-01 22:47:20 +020079
Amit Hilbuche1e789b2019-02-20 10:40:12 -080080 virtual RtpParameters GetParameters() const = 0;
deadbeefb10f32f2017-02-08 01:38:21 -080081 // Note that only a subset of the parameters can currently be changed. See
82 // rtpparameters.h
Åsa Persson55659812018-06-18 17:51:32 +020083 // The encodings are in increasing quality order for simulcast.
Zach Steinba37b4b2018-01-23 15:02:36 -080084 virtual RTCError SetParameters(const RtpParameters& parameters) = 0;
Florent Castelliacabb362022-10-18 17:05:16 +020085 virtual void SetParametersAsync(const RtpParameters& parameters,
86 SetParametersCallback callback);
skvladdc1c62c2016-03-16 19:07:43 -070087
deadbeef20cb0c12017-02-01 20:27:00 -080088 // Returns null for a video sender.
89 virtual rtc::scoped_refptr<DtmfSenderInterface> GetDtmfSender() const = 0;
90
Benjamin Wrightd81ac952018-08-29 17:02:10 -070091 // Sets a user defined frame encryptor that will encrypt the entire frame
92 // before it is sent across the network. This will encrypt the entire frame
93 // using the user provided encryption mechanism regardless of whether SRTP is
94 // enabled or not.
95 virtual void SetFrameEncryptor(
Andrey Logvin24c10792022-08-31 08:55:33 +000096 rtc::scoped_refptr<FrameEncryptorInterface> frame_encryptor) = 0;
Benjamin Wrightd81ac952018-08-29 17:02:10 -070097
98 // Returns a pointer to the frame encryptor set previously by the
99 // user. This can be used to update the state of the object.
Andrey Logvin24c10792022-08-31 08:55:33 +0000100 virtual rtc::scoped_refptr<FrameEncryptorInterface> GetFrameEncryptor()
101 const = 0;
Benjamin Wrightd81ac952018-08-29 17:02:10 -0700102
Marina Cioceae77912b2020-02-27 16:16:55 +0100103 virtual void SetEncoderToPacketizerFrameTransformer(
Andrey Logvin24c10792022-08-31 08:55:33 +0000104 rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) = 0;
Marina Cioceae77912b2020-02-27 16:16:55 +0100105
Jonas Oreland65455162022-06-08 11:25:46 +0200106 // Sets a user defined encoder selector.
107 // Overrides selector that is (optionally) provided by VideoEncoderFactory.
108 virtual void SetEncoderSelector(
109 std::unique_ptr<VideoEncoderFactory::EncoderSelectorInterface>
Andrey Logvin24c10792022-08-31 08:55:33 +0000110 encoder_selector) = 0;
Jonas Oreland65455162022-06-08 11:25:46 +0200111
Philipp Hancked237c2b2022-10-25 09:54:28 +0200112 // TODO(crbug.com/1354101): make pure virtual again after Chrome roll.
Philipp Hanckea1b4eb22022-11-04 14:45:23 +0100113 virtual RTCError GenerateKeyFrame(const std::vector<std::string>& rids) {
114 return RTCError::OK();
115 }
Philipp Hancked237c2b2022-10-25 09:54:28 +0200116
deadbeef70ab1a12015-09-28 16:53:55 -0700117 protected:
Mirko Bonadei79eb4dd2018-07-19 10:39:30 +0200118 ~RtpSenderInterface() override = default;
deadbeef70ab1a12015-09-28 16:53:55 -0700119};
120
deadbeef70ab1a12015-09-28 16:53:55 -0700121} // namespace webrtc
122
Steve Anton10542f22019-01-11 09:11:00 -0800123#endif // API_RTP_SENDER_INTERFACE_H_