Macro mpeg2ts_reader::demux_context[][src]

macro_rules! demux_context {
    ($name:ident, $filter:ty) => { ... };
}

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

This macro takes two arguments; the name for the new type, and the name of an existing implementation of PacketFilter. It then..

  1. creates a struct with the given name, wrapping an instance of FilterChangeset
  2. provides an implementation of default() for that struct
  3. provides an implementation of DemuxContext

NB The implementation of DemuxContext will assume that your own implementation of the type will provide a do_construct() method, to which its implementation of DemuxContext::construct() will delegate.

Example

use mpeg2ts_reader::demultiplex;
// Create an enum that implements PacketFilter as required by your application.
packet_filter_switch!{
    MyFilterSwitch<MyDemuxContext> {
        Pat: demultiplex::PatPacketFilter<MyDemuxContext>,
        Pmt: demultiplex::PmtPacketFilter<MyDemuxContext>,
        Nul: demultiplex::NullPacketFilter<MyDemuxContext>,
    }
};

// Create an implementation of the DemuxContext trait for the PacketFilter implementation
// created above.
demux_context!(MyDemuxContext, MyFilterSwitch);
impl MyDemuxContext {
    fn do_construct(&mut self, req: demultiplex::FilterRequest<'_, '_>) -> MyFilterSwitch {
        // ...inspect 'req', construct appropriate 'MyFilterSwitch' variant
    }
}

let mut ctx = MyDemuxContext::new();
// .. use the ctx value while demultiplexing some data ..