Struct Packet

Source
pub struct Packet<'buf> { /* private fields */ }
Expand description

A transport stream Packet is a wrapper around a byte slice which allows the bytes to be interpreted as a packet structure per ISO/IEC 13818-1, Section 2.4.3.3.

Implementations§

Source§

impl<'buf> Packet<'buf>

Source

pub const SYNC_BYTE: u8 = 71u8

The value 0x47, which must appear in the first byte of every transport stream packet.

Source

pub const SIZE: usize = 188usize

The fixed 188 byte size of a transport stream packet.

Source

pub fn is_sync_byte(b: u8) -> bool

returns true if the given value is a valid synchronisation byte, the value Packet::SYNC_BYTE (0x47), which must appear at the start of every transport stream packet.

Source

pub fn new(buf: &'buf [u8]) -> Packet<'buf>

Panics if the given buffer is less than 188 bytes, or if the initial sync-byte does not have the correct value (0x47). Calling code is expected to have already checked those conditions.

Panics if the buffer size is not exactly Packet::SIZE (188) bytes, or if the first byte value is not equal to Packet::SYNC_BYTE (0x47).

Source

pub fn try_new(buf: &'buf [u8]) -> Option<Packet<'buf>>

Like new(), but returns None if the sync-byte has incorrect value (still panics if the buffer size is not 188 bytes).

Source

pub fn transport_error_indicator(&self) -> bool

May have been set if some previous processing of this TS data detected at least 1 uncorrectable bit error in this TS packet.

Source

pub fn payload_unit_start_indicator(&self) -> bool

a structure larger than a single packet payload needs to be split across multiple packets, payload_unit_start() indicates if this packet payload contains the start of the structure. If false, this packets payload is a continuation of a structure which began in an earlier packet within the transport stream.

Source

pub fn transport_priority(&self) -> bool

When 1, this TS packet has higher priority than other packets of the the same PID having PID 0.

Source

pub fn pid(&self) -> Pid

The sub-stream to which a particular packet belongs is indicated by this Packet Identifier value.

Source

pub fn transport_scrambling_control(&self) -> TransportScramblingControl

Value of the transport_scrambling_control field.

Source

pub fn adaptation_control(&self) -> AdaptationControl

The returned enum value indicates if adaptation_field(), payload() or both will return something.

Source

pub fn continuity_counter(&self) -> ContinuityCounter

Each packet with a given pid() value within a transport stream should have a continuity counter value which increases by 1 from the last counter value seen. Unexpected continuity counter values allow the receiver of the transport stream to detect discontinuities in the stream (e.g. due to data loss during transmission).

Source

pub fn adaptation_field(&self) -> Option<AdaptationField<'buf>>

An AdaptationField contains additional packet headers that may be present in the packet.

Source

pub fn payload(&self) -> Option<&'buf [u8]>

The data contained within the packet, not including the packet headers. Not all packets have a payload, and None is returned if adaptation_control() indicates that no payload is present. None may also be returned if the packet is malformed. If Some payload is returned, it is guaranteed not to be an empty slice.

Source

pub fn buffer(&self) -> &'buf [u8]

borrow a reference to the underlying buffer of this packet

Auto Trait Implementations§

§

impl<'buf> Freeze for Packet<'buf>

§

impl<'buf> RefUnwindSafe for Packet<'buf>

§

impl<'buf> Send for Packet<'buf>

§

impl<'buf> Sync for Packet<'buf>

§

impl<'buf> Unpin for Packet<'buf>

§

impl<'buf> UnwindSafe for Packet<'buf>

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