pub struct TrackLocalStaticSample { /* private fields */ }
Expand description

TrackLocalStaticSample is a TrackLocal that has a pre-set codec and accepts Samples. If you wish to send a RTP Packet use TrackLocalStaticRTP

Implementations§

source§

impl TrackLocalStaticSample

source

pub fn new(codec: RTCRtpCodecCapability, id: String, stream_id: String) -> Self

returns a TrackLocalStaticSample

source

pub fn codec(&self) -> RTCRtpCodecCapability

codec gets the Codec of the track

source

pub async fn write_sample(&self, sample: &Sample) -> Result<()>

write_sample writes a Sample to the TrackLocalStaticSample If one PeerConnection fails the packets will still be sent to all PeerConnections. The error message will contain the ID of the failed PeerConnections so you can remove them

source

pub async fn write_sample_with_extensions( &self, sample: &Sample, extensions: &[HeaderExtension] ) -> Result<()>

Write a sample with provided RTP extensions.

Alternatively to this method TrackLocalStaticSample::sample_writer can be used instead.

See TrackLocalStaticSample::write_sample for further details.

source

pub fn sample_writer(&self) -> SampleWriter<'_>

Create a builder for writing samples with additional data.

§Example
use rtp::extension::audio_level_extension::AudioLevelExtension;
use std::time::Duration;
use webrtc::api::media_engine::MIME_TYPE_VP8;
use webrtc::rtp_transceiver::rtp_codec::RTCRtpCodecCapability;
use webrtc::track::track_local::track_local_static_sample::TrackLocalStaticSample;

#[tokio::main]
async fn main() {
    let track = TrackLocalStaticSample::new(
       RTCRtpCodecCapability {
           mime_type: MIME_TYPE_VP8.to_owned(),
           ..Default::default()
       },
       "video".to_owned(),
       "webrtc-rs".to_owned(),
    );
    let result = track
        .sample_writer()
        .with_audio_level(AudioLevelExtension {
            level: 10,
            voice: true,
        })
        .write_sample(&media::Sample{
             data: bytes::Bytes::new(),
             duration: Duration::from_secs(1),
             ..Default::default()
        })
        .await;
}

Trait Implementations§

source§

impl Debug for TrackLocalStaticSample

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl TrackLocal for TrackLocalStaticSample

source§

fn bind<'life0, 'life1, 'async_trait>( &'life0 self, t: &'life1 TrackLocalContext ) -> Pin<Box<dyn Future<Output = Result<RTCRtpCodecParameters>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Bind is called by the PeerConnection after negotiation is complete This asserts that the code requested is supported by the remote peer. If so it setups all the state (SSRC and PayloadType) to have a call

source§

fn unbind<'life0, 'life1, 'async_trait>( &'life0 self, t: &'life1 TrackLocalContext ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

unbind implements the teardown logic when the track is no longer needed. This happens because a track has been stopped.

source§

fn id(&self) -> &str

id is the unique identifier for this Track. This should be unique for the stream, but doesn’t have to globally unique. A common example would be ‘audio’ or ‘video’ and StreamID would be ‘desktop’ or ‘webcam’

source§

fn stream_id(&self) -> &str

stream_id is the group this track belongs too. This must be unique

source§

fn kind(&self) -> RTPCodecType

kind controls if this TrackLocal is audio or video

source§

fn as_any(&self) -> &dyn Any

Auto Trait Implementations§

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
§

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

§

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

§

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

§

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V