TSReader

MultiDec Plugins


Updated November 17, 2009

Introduction

MultiDec (MD) Plugins allow access to data from individual PIDs received by TSReader. By developing plugin you can parse MPEG-2 TS packets independantly of the functions in TSReader. MD Plugins are standard Windows DLLs and we provide a sample in the TSReader/MDPlugins folder. A knowledge of C or C++ is assumed.

The concept for MD Plugins was developed when a German program called MultiDec was written. It was a third party application based around a TechnoTrend / Hauppauge DVB-S receiver PCI-card that used a Texas Intruments DSP to demultiplex the MPEG-2 TS and also decode a video and audio stream back to analog. Because of the design of the DSP firmware, there's one very odd thing about MD Plugins - when they receive data from the container application (TSReader in this case) they receive the MPEG-2 packets minus the four byte header at the start of each TS packet.

This rather odd approach means that parsing MPEG-2 sections can be tricky since the indicator that flags the section starting in the current packet is within the first four bytes. To come up with a simple workaround, TSReader supports a mode where the entire 188 byte packet is sent to the plugin. Additionally, TSReader Standard and Professional can supply the entire transport stream to a plugin - with the ability for the plugin to modify the data before TSReader sees it. This capability has been used by one developer to write a converter plugin that makes TSReader see a standard MPEG-2 transport stream from an input stream of DIRECTV DSS packets - very impressive.

Exported Functions

TSReader calls into plugins via functions exported by the developer from their plugin. The following documents these functions.

void On_Start(HINSTANCE hInstance, HWND hWnd, BOOL bLogSet, int nDLLID, char * szHotKey)

This function is called when TSReader first starts up the plugin. The plugin should save the hInstance, hWnd and nDLLID values for later. The bLogSet and szHotKey parameters are not used by TSReader.

void On_Exit(HINSTANCE hInstance, HWND hWnd, BOOL bLogSet)

The opposite of the On_Start function - this is called when TSReader is shutting down.

void On_Channel_Change(TPROGRAM CurrentProgram)

When the user changes channel in TSReader (by selecting a different PMT), this function is called.

void On_Send_Dll_ID_Name(char * szName)

This function is used to return the name of the plugin to TSReader. This is used by TSReader to add the plugin to the "Plugins" menu in TSReader.

void On_Filter_Receive(int nMyFilter, int nLength, unsigned char * pBuffer)

This function is called when a packet is received matching the selected PID. See the section below about differences in this function.

void On_Menu_Select(unsigned int nMenuID)

This function is called when a menu item in TSReader's Plugins menu is selected by the user.

Receiving data in the On_Filter_Receive function

As mentioned previously, by default MD Plugins passed 184 byte packets, i.e. the transport packet headers are missing. If the plugin wishes to receive complete TS packets (188 bytes each) the PID to be hooked must have 0x8000 added. For example, to hook PID 1 (the CAT) and receive 188 byte packets a value of 0x8001 would be sent.

For TSReader Standard and Profesional to receive the entire transport stream, the plugin asks for PID 0x9fff (PID 0x1fff with the top bit set). However, once this is done, the On_Filter_Receive prototype needs to be changed slightly to:

int On_Filter_Receive(int nMyFilter, int * nLength, unsigned char * pBuffer)

In other words, the second parameter becomes a pointer to the size of the data being supplied by TSReader. This way packets can be removed (or added) by the plugin to the stream that TSReader sees and a new buffer length can be returned to TSReader.For compatibility with some plugins, the return value from this function call can also specify the new size of the data pointed to by pBuffer - this takes precedent over the * nLength value, however, the nLength must still be sent as a pointer.

Communicating with TSReader

TSReader needs to be told which PID to hook or unhook. This is accomplished by the plugin sending a WM_USER style message to the TSReader main window. The handle of this Windows is communicated to the plugin during the On_Start call.