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
impl PacketBuilder
Sourcepub fn new(stream_index: u32, time_base: (u32, u32), fps: f32) -> Self
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 computeframe_duration.
frame_duration is computed as
round(time_base.denominator / (fps * time_base.numerator)),
clamped to at least 1.
Sourcepub fn build_video_frame(
&mut self,
data: Vec<u8>,
keyframe: bool,
) -> CodecPacket
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.
Sourcepub fn build_audio_frame(&mut self, data: Vec<u8>, samples: u32) -> CodecPacket
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).
Sourcepub fn next_pts(&self) -> u64
pub fn next_pts(&self) -> u64
Return the current PTS counter (PTS that will be assigned to the next packet).
Sourcepub fn frame_duration(&self) -> u32
pub fn frame_duration(&self) -> u32
Return the current frame duration in time-base units.
Auto Trait Implementations§
impl Freeze for PacketBuilder
impl RefUnwindSafe for PacketBuilder
impl Send for PacketBuilder
impl Sync for PacketBuilder
impl Unpin for PacketBuilder
impl UnsafeUnpin for PacketBuilder
impl UnwindSafe for PacketBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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