Struct mpeg2ts_reader::packet::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
sourceimpl<'buf> Packet<'buf>
impl<'buf> Packet<'buf>
sourcepub const SYNC_BYTE: u8 = 71u8
pub const SYNC_BYTE: u8 = 71u8
The value 0x47
, which must appear in the first byte of every transport stream packet.
sourcepub fn is_sync_byte(b: u8) -> bool
pub fn is_sync_byte(b: u8) -> bool
returns true
if the given value is a valid synchronisation byte, the value 0x42
, which
must appear at the start of every transport stream packet.
sourcepub fn new(buf: &'buf [u8]) -> Packet<'_>
pub fn new(buf: &'buf [u8]) -> Packet<'_>
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.
pub fn transport_error_indicator(&self) -> bool
sourcepub fn payload_unit_start_indicator(&self) -> bool
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.
pub fn transport_priority(&self) -> bool
sourcepub fn pid(&self) -> u16
pub fn pid(&self) -> u16
The sub-stream to which a particular packet belongs is indicated by this Packet Identifier value.
pub fn transport_scrambling_control(&self) -> TransportScramblingControl
sourcepub fn adaptation_control(&self) -> AdaptationControl
pub fn adaptation_control(&self) -> AdaptationControl
The returned enum value indicates if adaptation_field()
, payload()
or both will return
something.
sourcepub fn continuity_counter(&self) -> ContinuityCounter
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).
sourcepub fn adaptation_field(&self) -> Option<AdaptationField<'_>>
pub fn adaptation_field(&self) -> Option<AdaptationField<'_>>
An AdaptationField
contains additional packet headers that may be present in the packet.
sourcepub fn payload(&self) -> Option<&'buf [u8]>
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.