1 /* 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. 3 * 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. 9 */ 10 11 // This file contains interfaces for RtpSenders 12 // http://w3c.github.io/webrtc-pc/#rtcrtpsender-interface 13 14 #ifndef API_RTP_SENDER_INTERFACE_H_ 15 #define API_RTP_SENDER_INTERFACE_H_ 16 17 #include <string> 18 #include <vector> 19 20 #include "api/crypto/frame_encryptor_interface.h" 21 #include "api/dtls_transport_interface.h" 22 #include "api/dtmf_sender_interface.h" 23 #include "api/frame_transformer_interface.h" 24 #include "api/media_stream_interface.h" 25 #include "api/media_types.h" 26 #include "api/proxy.h" 27 #include "api/rtc_error.h" 28 #include "api/rtp_parameters.h" 29 #include "api/scoped_refptr.h" 30 #include "rtc_base/ref_count.h" 31 #include "rtc_base/system/rtc_export.h" 32 33 namespace webrtc { 34 35 class RTC_EXPORT RtpSenderInterface : public rtc::RefCountInterface { 36 public: 37 // Returns true if successful in setting the track. 38 // Fails if an audio track is set on a video RtpSender, or vice-versa. 39 virtual bool SetTrack(MediaStreamTrackInterface* track) = 0; 40 virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0; 41 42 // The dtlsTransport attribute exposes the DTLS transport on which the 43 // media is sent. It may be null. 44 // https://w3c.github.io/webrtc-pc/#dom-rtcrtpsender-transport 45 // TODO(https://bugs.webrtc.org/907849) remove default implementation 46 virtual rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const; 47 48 // Returns primary SSRC used by this sender for sending media. 49 // Returns 0 if not yet determined. 50 // TODO(deadbeef): Change to absl::optional. 51 // TODO(deadbeef): Remove? With GetParameters this should be redundant. 52 virtual uint32_t ssrc() const = 0; 53 54 // Audio or video sender? 55 virtual cricket::MediaType media_type() const = 0; 56 57 // Not to be confused with "mid", this is a field we can temporarily use 58 // to uniquely identify a receiver until we implement Unified Plan SDP. 59 virtual std::string id() const = 0; 60 61 // Returns a list of media stream ids associated with this sender's track. 62 // These are signalled in the SDP so that the remote side can associate 63 // tracks. 64 virtual std::vector<std::string> stream_ids() const = 0; 65 66 // Sets the IDs of the media streams associated with this sender's track. 67 // These are signalled in the SDP so that the remote side can associate 68 // tracks. SetStreams(const std::vector<std::string> & stream_ids)69 virtual void SetStreams(const std::vector<std::string>& stream_ids) {} 70 71 // Returns the list of encoding parameters that will be applied when the SDP 72 // local description is set. These initial encoding parameters can be set by 73 // PeerConnection::AddTransceiver, and later updated with Get/SetParameters. 74 // TODO(orphis): Make it pure virtual once Chrome has updated 75 virtual std::vector<RtpEncodingParameters> init_send_encodings() const; 76 77 virtual RtpParameters GetParameters() const = 0; 78 // Note that only a subset of the parameters can currently be changed. See 79 // rtpparameters.h 80 // The encodings are in increasing quality order for simulcast. 81 virtual RTCError SetParameters(const RtpParameters& parameters) = 0; 82 83 // Returns null for a video sender. 84 virtual rtc::scoped_refptr<DtmfSenderInterface> GetDtmfSender() const = 0; 85 86 // Sets a user defined frame encryptor that will encrypt the entire frame 87 // before it is sent across the network. This will encrypt the entire frame 88 // using the user provided encryption mechanism regardless of whether SRTP is 89 // enabled or not. 90 virtual void SetFrameEncryptor( 91 rtc::scoped_refptr<FrameEncryptorInterface> frame_encryptor); 92 93 // Returns a pointer to the frame encryptor set previously by the 94 // user. This can be used to update the state of the object. 95 virtual rtc::scoped_refptr<FrameEncryptorInterface> GetFrameEncryptor() const; 96 97 virtual void SetEncoderToPacketizerFrameTransformer( 98 rtc::scoped_refptr<FrameTransformerInterface> frame_transformer); 99 100 protected: 101 ~RtpSenderInterface() override = default; 102 }; 103 104 // Define proxy for RtpSenderInterface. 105 // TODO(deadbeef): Move this to .cc file and out of api/. What threads methods 106 // are called on is an implementation detail. 107 BEGIN_SIGNALING_PROXY_MAP(RtpSender) 108 PROXY_SIGNALING_THREAD_DESTRUCTOR() 109 PROXY_METHOD1(bool, SetTrack, MediaStreamTrackInterface*) 110 PROXY_CONSTMETHOD0(rtc::scoped_refptr<MediaStreamTrackInterface>, track) 111 PROXY_CONSTMETHOD0(rtc::scoped_refptr<DtlsTransportInterface>, dtls_transport) 112 PROXY_CONSTMETHOD0(uint32_t, ssrc) 113 PROXY_CONSTMETHOD0(cricket::MediaType, media_type) 114 PROXY_CONSTMETHOD0(std::string, id) 115 PROXY_CONSTMETHOD0(std::vector<std::string>, stream_ids) 116 PROXY_CONSTMETHOD0(std::vector<RtpEncodingParameters>, init_send_encodings) 117 PROXY_CONSTMETHOD0(RtpParameters, GetParameters) 118 PROXY_METHOD1(RTCError, SetParameters, const RtpParameters&) 119 PROXY_CONSTMETHOD0(rtc::scoped_refptr<DtmfSenderInterface>, GetDtmfSender) 120 PROXY_METHOD1(void, 121 SetFrameEncryptor, 122 rtc::scoped_refptr<FrameEncryptorInterface>) 123 PROXY_CONSTMETHOD0(rtc::scoped_refptr<FrameEncryptorInterface>, 124 GetFrameEncryptor) 125 PROXY_METHOD1(void, SetStreams, const std::vector<std::string>&) 126 PROXY_METHOD1(void, 127 SetEncoderToPacketizerFrameTransformer, 128 rtc::scoped_refptr<FrameTransformerInterface>) 129 END_PROXY_MAP() 130 131 } // namespace webrtc 132 133 #endif // API_RTP_SENDER_INTERFACE_H_ 134