Skip to main content

RTCRtpReceiver

Struct RTCRtpReceiver 

Source
pub struct RTCRtpReceiver<'a> { /* private fields */ }
Expand description

Represents an RTP receiver for a media stream track.

The RTCRtpReceiver interface allows an application to inspect the receipt of a MediaStreamTrack as defined in the W3C WebRTC specification.

§Lifetime

This struct borrows the RTCPeerConnection mutably, ensuring exclusive access during RTP receiver operations.

Implementations§

Source§

impl RTCRtpReceiver<'_>

Source

pub fn transport(&self) -> Option<RTCDtlsTransport<'_>>

The DTLS transport over which this receiver’s RTP packets are received.

§Nullability

None until this receiver’s transceiver has been associated by negotiation. The spec sources this from the [[ReceiverTransport]] slot, which is per-receiver and is filled while applying a local or remote description — so the predicate is that transceiver’s mid, not a connection-wide flag.

Deliberately not keyed on whether the DTLS endpoint has been built: an offerer associates its transceivers at setLocalDescription, before the answer starts DTLS, and a browser reports a transport there too. The handle simply reports RTCDtlsTransportState::New until the handshake begins.

Under bundling every sender and receiver shares one transport, so all of these compare equal by id().

§Specifications
Source

pub fn streams(&self) -> &[MediaStreamId]

The ids of the remote MediaStreams this receiver’s track is in: one per a=msid line of the remote media section, in order, without the - that stands for no stream (RFC 8830 sections 2 and 3; W3C [[AssociatedRemoteMediaStreams]], the streams of the track event). Empty until an answer is applied, and for a track in no stream.

Source

pub fn track_mut(&mut self) -> &mut MediaStreamTrack

The receiver’s track, mutably: what the application changes on it (enabled, apply_constraints, stop). Stopping it does not stop the receiver (W3C 5.3).

Source

pub fn report_received_frame(&mut self, now: Instant, width: u32, height: u32)

Reports a video frame the application received on this receiver, width x height pixels, at now: its decoder, or a depacketizer that reads the frame size from a key frame, supplies it. The receiver’s track then reports the frame’s size, its aspect ratio and a frame-rate estimate from the frames of the last second in its settings (W3C webrtc-pc 9.3.1). Ignored for an audio receiver.

Source

pub fn track(&self) -> &MediaStreamTrack

Returns the track associated with this receiver.

The track method returns the MediaStreamTrack that is associated with this receiver as specified in the W3C WebRTC specification.

§Returns

Returns a reference to the MediaStreamTrack associated with this receiver.

Source

pub fn get_capabilities(&self, kind: RtpCodecKind) -> Option<RTCRtpCapabilities>

The RTP capabilities of the engine for receiving kind: every codec the media engine has registered for it (the retransmission format once, without an sdpFmtpLine) and the header extensions registered for receiving. Nothing negotiated is read (W3C RTCRtpReceiver.getCapabilities, a static method). None for a kind that is neither audio nor video.

§Parameters
  • kind - The codec kind (audio or video)
Source

pub fn h264_depacketizer(&self, codec: &RTCRtpCodec) -> Result<H264Packet>

An H.264 depacketizer for codec (one of this receiver’s negotiated codecs, whose fmtp line is the sender’s) built with the connection’s de-interleaving settings (MediaEngine::h264_depacketizer): under the StrictRfc behaviour profile an interleaved stream’s PDON starts at 0 as RFC 6184 section 7.2.2 has it; by default it does not, a departure from that section (MediaEngine::set_h264_literal_pdon).

§Errors

As RTCRtpCodec::h264_depacketizer.

Source

pub fn jitter_buffer_target(&self) -> Option<Duration>

The jitter buffer target the application asked for (W3C jitterBufferTarget): None (null) leaves the delay to the engine.

The engine keeps the value for the application’s jitter buffer to read; the jitter buffer interceptors take their delay when they are built.

Source

pub fn set_jitter_buffer_target( &mut self, target: Option<Duration>, ) -> Result<()>

Sets the jitter buffer target; None resets it to the engine’s choice.

§Errors

Error::RangeError for a target above 4000 milliseconds (a Duration cannot be negative, the other value W3C refuses); the stored target is then unchanged.

Source

pub fn get_parameters(&mut self) -> &RTCRtpReceiveParameters

Returns the RTP receive parameters for this receiver.

The get_parameters method returns the current parameters for how the receiver’s track is decoded as defined in the W3C WebRTC specification.

§Returns

Returns a reference to the RTP receive parameters.

Source

pub fn get_contributing_sources( &self, ) -> impl Iterator<Item = &RTCRtpContributingSource>

Returns an iterator over the contributing sources for this receiver.

The get_contributing_sources method returns information about the contributing sources (CSRCs) for the most recent RTP packets received by this receiver as defined in the W3C WebRTC specification.

Contributing sources represent mixers or other entities that have contributed to the RTP stream.

§Returns

Returns an iterator over RTCRtpContributingSource objects.

Source

pub fn get_synchronization_sources( &self, ) -> impl Iterator<Item = &RTCRtpSynchronizationSource>

Returns an iterator over the synchronization sources for this receiver.

The get_synchronization_sources method returns information about the synchronization sources (SSRCs) for the most recent RTP packets received by this receiver as defined in the W3C WebRTC specification.

Synchronization sources represent the original sources of the RTP packets.

§Returns

Returns an iterator over RTCRtpSynchronizationSource objects.

Source

pub fn write_rtcp( &mut self, now: Instant, packets: Vec<Box<dyn Packet>>, ) -> Result<()>

Writes RTCP feedback packets for this receiver.

This method allows sending receiver-side RTCP feedback such as:

  • Receiver Reports (RR)
  • Picture Loss Indication (PLI)
  • Full Intra Request (FIR)
  • Negative Acknowledgements (NACK)
§Parameters
  • packets - A vector of RTCP packets to send
§Returns

Returns Ok(()) if the packets were queued successfully.

§Errors

Returns an error if internal handle_write returns error

§Examples
// Send a Picture Loss Indication to request a keyframe
use rtci::peer_connection::RTCPeerConnection;
use rtci::rtcp::payload_feedbacks::picture_loss_indication::PictureLossIndication;
use rtci::rtp_transceiver::RTCRtpReceiverId;
use std::time::Instant;

if let Some(mut receiver) = peer_connection.rtp_receiver(receiver_id) {
    let pli = PictureLossIndication {
        sender_ssrc: 0,
        media_ssrc: remote_ssrc,
    };
    receiver.write_rtcp(Instant::now(), vec![Box::new(pli)])?;
}
Source

pub fn encoded_frame_metadata( &mut self, packets: &[Packet], ) -> Result<RTCEncodedFrameMetadataKind>

W3C webrtc-encoded-transform 4, getMetadata() of a received encoded frame: the metadata of the frame the application reassembled from packets, the RTP packets poll_read delivered for it (one SSRC and RTP timestamp, in sequence number order).

From the packets: synchronizationSource, payloadType, contributingSources, rtpTimestamp, mimeType (the codec negotiated for the payload type), an audio frame’s sequenceNumber and audioLevel (RFC 6464, linear), a video frame’s type, size and layer indices from the payload (see RTCEncodedVideoFrameMetadata). From what the receiver recorded as the packets passed: receiveTime, captureTime and senderCaptureTimeOffset, and the Dependency Descriptor’s frameId and dependencies.

§Errors

TypeError when packets is empty or its packets are not of one frame (different SSRCs or RTP timestamps).

Source

pub fn video_orientation( &self, packets: &[Packet], ) -> Option<VideoOrientationExtension>

The orientation of a received video frame: the Coordination of Video Orientation element (urn:3gpp:video-orientation, 3GPP TS 26.114 section 7.4.5) of packets, the RTP packets poll_read delivered for the frame (or a single packet). RFC 7742 section 4: “All implementations SHOULD support interpretation of the R0 and R1 bits and MAY support the other CVO bits”; all of them are read (camera, flip, rotation).

The element of the last packet that carries one (TS 26.114 puts it in the frame’s last packet, the one with the marker bit). None when no packet carries it, when the receiver does not read the extension (RFC 8834 section 10: only an extension the section negotiated for receiving is read), and for an audio receiver. A frame without the element does not change the orientation: the renderer keeps the one it last applied. The engine does not render: turning the picture by VideoOrientationExtension::rotation (and mirroring it when flip) is the application’s.

Not a W3C method: a fork addition (the sending side is RTCRtpSender::write_rtp_with_video_orientation).

Source

pub fn send_key_frame_request(&mut self, now: Instant) -> Result<bool>

webrtc-encoded-transform 6.5 “send request key frame” (sendKeyFrameRequest() of a receiver’s transform): sends a Full Intra Request (RFC 5104 4.3.1) for the streams this receiver receives.

Returns whether one was sent. Nothing is sent, and the request resolves, when a FIR is not appropriate: the transceiver is stopped or does not receive by the current description, no stream has arrived yet, or ccm fir was not negotiated for the receiver’s codecs (RFC 5104 section 7: a CCM message is sent only when negotiated).

§Errors

InvalidStateError for a receiver that is not a video receiver.

Source

pub fn set_remote_bitrate_limit( &mut self, now: Instant, bitrate: Option<u64>, ) -> Result<()>

Asks the remote sender of this receiver’s streams to keep its media under bitrate bits per second (total media bit rate at the IP layer), or lifts that limit with None: RFC 5104 TMMBR, sent by the congestion control interceptor (interceptor::TmmbrControl::{Limit, Clear}), repeated until the sender acknowledges it with a TMMBN.

Only effective for a stream that negotiated a=rtcp-fb:<pt> ccm tmmbr (RFC 5104 section 7.2: no CCM message is sent that was not negotiated) and with the default interceptors (their congestion control interceptor holds the request state); otherwise nothing is sent. The limit applies to every SSRC the receiver’s track receives.

Source

pub fn set_nack_horizon( &mut self, now: Instant, ssrc: u32, oldest_useful: Option<u16>, ) -> Result<()>

Tells the NACK generator the oldest sequence number of the received stream ssrc that the application can still use, or removes that horizon with None. RFC 4588 6.3: “the receiver should generally assess whether the retransmitted packet would still be useful at the time it is received”. A video pipeline that has released or given up every frame before oldest_useful gives it here after each frame, and the generator (interceptor::NackControl::Horizon) no longer asks for missing packets older than it; newer ones are asked for as before. A request for an older packet that still waits in the RTCP session for its packet (RFC 4585 3.5.2) is dropped there, so no NACK sent after this call names a packet before oldest_useful. Sequence numbers compare with wrap-around (RFC 3550 A.1), so the horizon is to be moved on as playout advances.

Only effective with the default interceptors (their NACK generator holds the request state). An SSRC this receiver’s track does not receive is ignored.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for RTCRtpReceiver<'a>

§

impl<'a> !Sync for RTCRtpReceiver<'a>

§

impl<'a> !UnwindSafe for RTCRtpReceiver<'a>

§

impl<'a> Forget for RTCRtpReceiver<'a>

§

impl<'a> Freeze for RTCRtpReceiver<'a>
where &'a mut RTCPeerConnection: Freeze,

§

impl<'a> Move for RTCRtpReceiver<'a>

§

impl<'a> Send for RTCRtpReceiver<'a>
where RawVecInner: Send, &'static [u8]: Send, Arc<dyn SigningKey>: Send, RawTable<(u8, RTCRtpCodec)>: Send, RawTable<(u16, MediaEngineHeaderExtension)>: Send, Arc<dyn RTCCryptoProvider>: Send, Arc<dyn Fn(SocketAddr) -> bool + Sync + Send>: Send, Arc<dyn Fn(SocketAddr, AddressDirection, AddressPurpose) -> bool + Sync + Send>: Send, Arc<PacingGroup>: Send, Arc<Mutex<Bucket>>: Send, Arc<dyn Fn(isize) -> String + Sync + Send>: Send, Arc<RootCertStore>: Send, Arc<dyn ServerCertVerifier>: Send, BoxRaw<dyn Interceptor<Wout = TransportMessage<AttributedPacket>, Error = Error, Rout = TransportMessage<AttributedPacket>, Eout = (), Time = Instant>>: Send, BytesMut: Send, Bytes: Send, BoxRaw<dyn Packet>: Send, &'static str: Send, BoxRaw<dyn Cipher>: Send, RawTable<(u32, SrtpSsrcState)>: Send, RawTable<(u32, SrtcpSsrcState)>: Send, BoxRaw<dyn Fn() -> Box<dyn ReplayDetector> + Sync + Send>: Send, BoxRaw<RestartUndo>: Send, RawTable<(u64, Candidate)>: Send, RawTable<(IpAddr, IpAddr)>: Send, BoxRaw<Candidate>: Send, Arc<HandshakeConfig>: Send, RawTable<(SocketAddr, DTLSConn)>: Send, Arc<Atomic<bool>>: Send, BoxRaw<Endpoint>: Send, Arc<DtlsSessionGroup>: Send, Arc<()>: Send, RawTable<(u32, ())>: Send, RawTable<(String, TransportId)>: Send, RawTable<((SocketAddr, SocketAddr), Option<TransportId>)>: Send, RawTable<(u64, Option<TransportId>)>: Send, RawTable<(u32, AssociationHandle)>: Send, RawTable<((SocketAddr, u16, u16), AssociationHandle)>: Send, RawTable<(u64, u32)>: Send, BoxRaw<dyn AssociationIdGenerator>: Send, Arc<EndpointConfig>: Send, Arc<ServerConfig>: Send, Arc<CookieSigner>: Send, RawTable<(AssociationHandle, Association)>: Send, RawTable<((AssociationHandle, u16), ())>: Send, RawTable<((AssociationHandle, u16), (ReliabilityType, u32))>: Send, RawTable<(AssociationHandle, ())>: Send, RawTable<(AssociationHandle, TransportContext)>: Send, RawTable<((AssociationHandle, u16), PartialMessage)>: Send, RawTable<(AssociationHandle, usize)>: Send, RawTable<(u32, usize)>: Send, RawTable<((String, String), Instant)>: Send, RawTable<(u32, String)>: Send, RawTable<(u32, (String, String))>: Send, NodeRef<Owned, usize, f64, LeafOrInternal>: Send, BoxRaw<(usize, f64)>: Send, NodeRef<Owned, u32, SetValZST, LeafOrInternal>: Send, BoxRaw<(u32, SetValZST)>: Send, NodeRef<Owned, usize, (f64, f64), LeafOrInternal>: Send, BoxRaw<(usize, (f64, f64))>: Send, NodeRef<Owned, usize, SetValZST, LeafOrInternal>: Send, BoxRaw<(usize, SetValZST)>: Send, RawTable<(usize, FecSessionTransport)>: Send, RawTable<(usize, ())>: Send, RawTable<(u32, SentSdes)>: Send, RawTable<(u32, u16)>: Send, RawTable<(u32, HashMap<u16, Instant>)>: Send, RawTable<(u32, DeliveredWindow)>: Send, NodeRef<Owned, usize, TransportStatsAccumulator, LeafOrInternal>: Send, BoxRaw<(usize, TransportStatsAccumulator)>: Send, RawTable<(String, usize)>: Send, RawTable<(String, IceCandidatePairAccumulator)>: Send, RawTable<(String, IceCandidateAccumulator)>: Send, RawTable<(String, CertificateStatsAccumulator)>: Send, RawTable<(String, CodecStatsAccumulator)>: Send, RawTable<(usize, DataChannelStatsAccumulator)>: Send, RawTable<(u32, InboundRtpStreamAccumulator)>: Send, RawTable<(u32, OutboundRtpStreamAccumulator)>: Send, RawTable<(String, MediaSourceStatsAccumulator)>: Send, RawTable<(String, AudioPlayoutStatsAccumulator)>: Send, RawTable<(u32, u32)>: Send, RawTable<(usize, u64)>: Send, OnceLock<SystemInstant>: Send, RawTable<(usize, RTCDataChannelInternal)>: Send, RawTable<(u16, usize)>: Send, RawTable<(bool, ())>: Send, RawTable<(u32, ClockRateStreams)>: Send, RawTable<(String, ())>: Send, RawTable<(u32, (Instant, u64))>: Send, NodeRef<Owned, StreamId, Connection, LeafOrInternal>: Send, BoxRaw<(StreamId, Connection)>: Send, NodeRef<Owned, ListenerId, Listener, LeafOrInternal>: Send, BoxRaw<(ListenerId, Listener)>: Send, RawTable<(IpAddr, ())>: Send, RawTable<(SocketAddr, ())>: Send, RawTable<(StreamId, ())>: Send, RawTable<(StreamId, TransportId)>: Send, RawTable<((TransportId, SocketAddr, SocketAddr), ())>: Send, RawTable<(TransportId, ())>: Send, Arc<Login>: Send, RawTable<(TransactionId, Transaction)>: Send, RawTable<(SocketAddr, usize)>: Send, RawTable<(SocketAddr, RtoEstimator)>: Send, RawTable<(SocketAddr, RelayState)>: Send, BoxRaw<Error>: Send, Repr: Send, BoxRaw<dyn Error + Sync + Send>: Send, BoxRaw<AllocateState>: Send, Arc<Credential>: Send, RawTable<(IpAddr, Vec<(SocketAddr, Vec<u8>)>)>: Send, Arc<ClientConfig>: Send, RawTable<(TransactionId, ClientTransaction)>: Send, RawTable<((IpAddr, SocketAddr), AddressRank)>: Send,

§

impl<'a> Unpin for RTCRtpReceiver<'a>
where &'a mut RTCPeerConnection: Unpin,

§

impl<'a> UnsafeUnpin for RTCRtpReceiver<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.