Crate mpeg2ts_reader[][src]

Structures for parsing MPEG2 Transport Stream data, per the ISO/IEC 13818-1 standard.

Design principals

  • Avoid copying and allocating if possible. Most of the implementation works by borrowing slices of the underlying byte buffer. The implementation tries to avoid buffering up intermediate data where practical.
  • Non-blocking. It should be possible to integrate this library into a system non-blocking event-loop. The caller has to ‘push’ data.
  • Extensible. The standard calls out a number of ‘reserved values’ and other points of extension. This library should make it possible for other crates to implement such extensions.
  • Minimal. Lots of commonly used Transport Stream functionality is specified in standards from by ISDB / DVB / ATSC / SCTE / etc. and not in 13818-1 itself. I hope support for these features can be added via external crates. (None implemented any yet!)
  • Transport Neutral. There is currently no code here supporting consuming from files or the network. The APIs accept &[u8], and the caller handles providing the data from wherever.

Planned API changes

  • Add ‘context’ objects
    • Real usage will likely need to thread context objects through the API in order to track application-specific details.
    • Currently mutable state is stored in the instance for each type of syntax parser, and it would be nice to explore extracting this out into parser-specific context types
  • Event generation / remove warn!()
    • currently problems are reported to the log crate
    • I would much prefer a way to emit ‘events’ for interesting data that can’t just be an error return value, and to not have any logging code mixed with parsing logic
  • General
    • lots of places return Option but should return Result and a descriptive error



Main types implementing the demultiplexer state-machine.


Descriptors provide metadata about an element of a Transport Stream.


MPEG Cyclic Redundancy Check calculation


A Packet struct and associated infrastructure to read an MPEG Transport Stream packet


Support for Packetised Elementary Stream syntax within Transport Stream packet payloads. Elementary streams are split into ‘elementary stream packets’, which are then further split into the payloads of transport stream packets.


Types for processing tables of Program Specific Information in a transport stream.



Creates the boilerplate needed for a filter-implementation-specific DemuxContext.


Builds an enum to encapsulate all possible implementations of Descriptor that you want to be able to handle in your application.


Creates an enum which implements PacketFilter by delegating to other PacketFilter implementations, depending on the enum-variant. It’s intended that the types created by this macro be used as the type-parameter for an instance of the Demultiplex type, allowing Demultiplex to support many kinds of PacketFilter, without the cost of having to box them.



The types of Elementary Stream specified in ISO/IEC 13818-1.



The identifier of TS Packets containing ‘stuffing’ data, with value 0x1fff