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
sourceimpl TrackLocalStaticSample
impl TrackLocalStaticSample
sourcepub fn new(codec: RTCRtpCodecCapability, id: String, stream_id: String) -> Self
pub fn new(codec: RTCRtpCodecCapability, id: String, stream_id: String) -> Self
returns a TrackLocalStaticSample
sourcepub fn codec(&self) -> RTCRtpCodecCapability
pub fn codec(&self) -> RTCRtpCodecCapability
codec gets the Codec of the track
sourcepub async fn write_sample(&self, sample: &Sample) -> Result<()>
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
sourcepub async fn write_sample_with_extensions(
&self,
sample: &Sample,
extensions: &[HeaderExtension]
) -> Result<()>
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.
sourcepub fn sample_writer(&self) -> SampleWriter<'_>
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
sourceimpl Debug for TrackLocalStaticSample
impl Debug for TrackLocalStaticSample
sourceimpl TrackLocal for TrackLocalStaticSample
impl TrackLocal for TrackLocalStaticSample
sourcefn bind<'life0, 'life1, 'async_trait>(
&'life0 self,
t: &'life1 TrackLocalContext
) -> Pin<Box<dyn Future<Output = Result<RTCRtpCodecParameters>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn bind<'life0, 'life1, 'async_trait>(
&'life0 self,
t: &'life1 TrackLocalContext
) -> Pin<Box<dyn Future<Output = Result<RTCRtpCodecParameters>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: '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
sourcefn unbind<'life0, 'life1, 'async_trait>(
&'life0 self,
t: &'life1 TrackLocalContext
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn unbind<'life0, 'life1, 'async_trait>(
&'life0 self,
t: &'life1 TrackLocalContext
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
unbind implements the teardown logic when the track is no longer needed. This happens because a track has been stopped.
sourcefn id(&self) -> &str
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’
sourcefn kind(&self) -> RTPCodecType
fn kind(&self) -> RTPCodecType
kind controls if this TrackLocal is audio or video