Skip to main content

PacketBuilder

Struct PacketBuilder 

Source
pub struct PacketBuilder { /* private fields */ }
Expand description

A stateful helper for building correctly-timestamped CodecPackets.

Create one builder per stream. Call build_video_frame for each video frame or build_audio_frame for each audio frame; the builder tracks the running PTS/DTS automatically.

Implementations§

Source§

impl PacketBuilder

Source

pub fn new(stream_index: u32, time_base: (u32, u32), fps: f32) -> Self

Create a new builder.

  • stream_index: stream index embedded into every packet.
  • time_base: (numerator, denominator) of the stream time base.
  • fps: frame rate; used to compute frame_duration.

frame_duration is computed as round(time_base.denominator / (fps * time_base.numerator)), clamped to at least 1.

Source

pub fn build_video_frame( &mut self, data: Vec<u8>, keyframe: bool, ) -> CodecPacket

Build a video frame packet and advance the timestamp counters.

The PTS and DTS of the returned packet reflect the state before the counters are advanced, so the first packet always has PTS/DTS = 0.

Source

pub fn build_audio_frame(&mut self, data: Vec<u8>, samples: u32) -> CodecPacket

Build an audio frame packet.

samples is the number of PCM samples in the frame. The duration is derived from samples * time_base.numerator / sample_rate, but since PacketBuilder is not audio-sample-rate aware, the caller should pass the actual per-frame sample count and the method uses frame_duration as a fallback when samples == 0.

For audio the keyframe flag is always false (all audio frames are independently decodable).

Source

pub fn next_pts(&self) -> u64

Return the current PTS counter (PTS that will be assigned to the next packet).

Source

pub fn frame_duration(&self) -> u32

Return the current frame duration in time-base units.

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

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>,

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.