Microsoft DirectX 8.1 (C++)

MPEG-2 Demultiplexer

The MPEG-2 Demultiplexer (Demux) filter demultiplexes MPEG-2 transport and program streams that are delivered in push-mode. For Microsoft® Windows® XP, this filter also supports program streams in pull mode (file playback). On earlier platforms, use the MPEG-2 Splitter filter for program streams in pull mode. This filter can be used in any type of filter graph, including a BDA digital TV filter graph.

When operating on a transport stream, the Demux is said to be in transport stream mode. When operating on a program stream, the Demux is said to be in program stream mode. In transport stream mode, the demultiplexing is based on a mapping of one or more packet IDs (PID) to an output pin. In program stream mode, the mapping is between one stream ID and one output pin. If a PID or stream ID is not mapped to an output pin, it is simply discarded by the Demux.

The Demux can also operate in pass-though mode on transport streams. For example, an application can map all the PIDs it is interested in to a single output pin, and create a stream of PID packets that can be written to file, re-broadcast, or processed in some other way. No re-multiplexing of the packets is performed in pass-through mode, and the output stream is not a compliant MPEG-2 transport stream. Packets with errors are not filtered out.

The following illustration shows possible data flows when the Demux is in transport stream mode.

Demux in Transport Stream Mode

Configuring the Filter

When the Demux is first instantiated and added to the filter graph, it has a single input pin and no output pins. In filter graphs that render digital television transmissions and are based on Microsoft® Broadcast Driver Architecture (BDA), the BDA Network Provider filter is responsible for creating the output pins on the Demux and mapping the pins to PIDs. In other filter graphs, it is the responsibility of the application to create and configure the output pins by setting the pin's media type when the pin is created and mapping the stream IDs (program stream mode) or PIDs (transport stream mode) to each pin.

The Demux configures itself internally for either transport or program streams only after some triggering event occurs that indicates which type of stream the filter should expect. The typical triggering event occurs when the first output pin is configured. For example, in program stream mode, an application will create a new output pin using the filter's IMpeg2Demultiplexer::CreateOutputPin method. This method returns an IPin interface pointer to the pin that was created. The application then uses this pointer in a call to QueryInterface to obtain the IMPEG2StreamIdMap interface. At this point the Demux will configure itself for program stream mode, because IMPEG2StreamIdMap is specific to program streams. The same process occurs for transport mode when the application calls QueryInterface on the first output pin and requests the IMPEG2PIDMap interface. Another triggering event is when the input pin of the Demux is connected; the connection media type will indicate to the Demux whether the incoming stream is a program stream or a transport stream.

The Demux must be configured before it can be put into the Run state. Once the Demux has configured itself for one type of stream, it cannot be reconfigured to operate on the other type of stream. To switch the Demux between program stream mode and transport stream mode, you must start over with a newly instantiated filter.

Configuring the Pins for Program Stream Mode

As described in the preceding section, after creating an output pin, the application queries the pin for the IMPEG2StreamIdMap interface. The application then calls the IMPEG2StreamIdMap::MapStreamId method to associate the pin with a specified elementary stream, and to indicate whether substream filtering is required. In MPEG-2 program streams (but not transport streams) the audio elementary stream may itself be further divided into multiple substreams. This is often done to provide multiple audio tracks. The application is responsible for providing the pin with the necessary substream filtering information so that the pin knows which substream to pass to the audio decoder.

To get the PIDs the table sections were delivered on, make sure that the demultiplexer's output pin media type's major type is MEDIATYPE_MPEG2_SECTIONS. The MPEG-2 demultiplexer includes the PID number that a PSI section was received on, when the output pin that has the mapping has MEDIATYPE_MPEG2_SECTIONS for its media type's major type.  The PID value is the low 13 bits of the media sample's AM_SAMPLE2_PROPERTIES.dwTypeSpecificFlags.  AM_SAMPLE2_PROPERTIES is retrieved via the media sample's IMediaSample2 interface.

See the IMPEG2StreamIdMap::MapStreamID reference page for more information.

Configuring the Pins for Transport Stream Mode

If the filter graph contains a BDA Network Provider source filter, this filter will automatically create all the necessary output pins on the Demux and map the PIDs for each pin. For audio and video streams there is generally one PID mapped per pin. For the Program Service Information (PSI) stream, several PIDs may be mapped to the output pin that connects to the Transport Information Filter (TIF). The BDA Network Provider works behind the scenes with the TIF to obtain PIDs for the various tables in the PSI stream, and configure the output pins on the Demux accordingly. If you are providing a transport stream through a custom filter that is not based on BDA, then either the filter or the application must do this work.

Clock Behavior

In push-mode, the Demux functions as the reference clock for the filter graph by implementing the IReferenceClock interface. With transport streams, this clock is slaved to the PCR stream corresponding to the last-mapped audio or video stream. If more PCR streams exist, they are tracked, but not used. With program streams, the Demux slaves its clock to the SCR stream. Slaving the clock to the PCR or SCR stream prevents overflow and underflow conditions in downstream buffers that would otherwise occur due to variations between the local system clock and the stream clock.

The Demux also guarantees monotonically increasing presentation time stamps to the downstream filters. This means, for example, that if a transport stream includes a segment such as a commercial that was created with a different clock than the main program, the Demux will adjust the presentation time stamps to hide the discontinuity from the downstream decoders and renderers.

Note:   Neither the MPEG-2 Demultiplexer nor the MPEG-2 Splitter support frame-accurate seeking.

Filter Interfaces IMpeg2Demultiplexer (Push-mode only), IBaseFilter, IReferenceClock (Push-mode only), ISpecifyPropertyPages
Input Pin Media Types MEDIATYPE_Stream, MEDIASUBTYPE_MPEG2_TRANSPORT, Format_None
MEDIATYPE_Stream, MEDIASUBTYPE_MPEG2_PROGRAM, Format_None
Input Pin Interfaces IPin
Output Pin Media Types Audio and video elementary stream must have a major type of audio or video. The Demux sets no limitations on the media subtype.
Output Pin Interfaces IMPEG2StreamIdMap (Push-mode only),  IMPEG2PIDMap, IPin (Push-mode only)
Filter CLSID CLSID_MPEG2Demultiplexer
Property Page CLSID Use the ISpecifyPropertyPages interface to access the propery pages.
Executable mpg2splt.ax
Merit MERIT_NORMAL
Filter Category CLSID_LegacyAmFilterCategory