Create a custom DirectShow Filter SDK DLL
To create a new DirectShow®
filter, all you need to do is to implement a standard
Dynamic Link Library (DLL). A valid DLL must provide (export) the
functions declared in the FilterSDKLib.h include file.
Additionally, to compile the DLL, it must be linked against
FilterSDKLib.lib. This library file encapsulates the code
for a complete DirectShow® filter utilizing
the FilterSDK.axwrapper. The
FilterSDK.ax is a DirectShow® filter proxy which loads all
available Filter SDK DLLs and registers them as DirectShow®
filters. Also the DLL must provide a couple of global
variables containing information about the filter.
To speed up the development,
the MontiVision Development Kit includes two
wizards
which create DLLs as described above. The wizards are
capable of creating a project for Microsoft Visual C++ 6.0 or 7.0
(.NET). The wizards create a skeleton source file with all of the
necessary functions. All you have to do is to populate the
functions with your custom code. For more information on
creating a DLL project using wizards, have a look at the
wizards help page.
The settings of the new filter can be accessed through the
filters IMVFilterSDK COM interface.
The filter provides a property page for graphical configuration
within the MontiVision Workbench. New controls for the custom
paramters of the filters may be added to this property page
and control the filter through IMVFilterSDK.
Attention: Make sure you set up your
development enviroment as described in the installation page.
DLL Functions:
The functions your DLL has to implement
are as follows. Be careful not to declare them as static
functions.
STDAPI
TransformSample( BYTE*
pInBuffer,
BYTE*
pOutBuffer,
int
iWidth,
int
iHeight,
int
iBytePerPixel,
int
iPitch,
void*
pSavePointer,
void*
pTempPointer,
PVOID
pIOInBuffer,
int
iIOInBufferSize,
PVOID
pIOOutBuffer,
int iIOOutBufferSize,
SAMPLE_TIMES times);
This is the transform function of the
filter. It is called for every frame that is to be processed by the
filter. Have a look at this help page for more
information on the transform function.
Parameter:
|
|
pInBuffer |
Pointer to a buffer containing the input
image. |
|
|
pOutBuffer |
Pointer to a buffer for the output image. |
|
|
iWidth |
Image width in pixels. |
|
|
iHeight |
Image height in pixels. |
|
|
iBytePerPixel |
Bytes per pixel. |
|
|
iPitch |
Bytes per row.
Note: Images are DWORD aligned!
iPitch = (iWidth * iBytePerPixel) + padding |
|
|
pSavePointer |
Void pointer for your plugin to save its
data. |
|
|
pTempPointer |
Void pointer for temporary data. |
|
|
pIOInBuffer |
Pointer to the buffer from the I/O input pin. The
pointer is NULL if no I/O input pin is available or connected. |
|
|
iIOInBufferSize |
Size of the I/O input pin buffer. |
|
|
pIOOutBuffer |
Pointer to the buffer from the I/O output pin. The
pointer is NULL if no I/O input pin is available or connected. |
|
|
iIOOutBufferSize |
Size of the I/O output pin
buffer. |
|
|
times |
Structure with sample times. |
typedef struct
_SAMPLE_TIMES
{
LONGLONG timeStart;
LONGLONG timeEnd;
LONGLONG timeMediaStart;
LONGLONG timeMediaEnd;
}SAMPLE_TIMES;
Parameter:
|
|
timeStart |
Stream time at that the
sample begins. |
|
|
timeEnd |
Stream time at that the sample ends. |
|
|
timeMediaStart |
Media start time (Frame number). |
|
|
timeMediaEnd |
Media stop time (Frame number). |
STDAPI InitDLL( void**
ppSavePointer, void** ppTempPointer );
This function is called once directly
after the DLL is loaded. This si where all the initialization
should be done. The ppSavePointer is used for any data
your filter needs to store between function calls. It could
point to a variable or perhaps a structure. The ppSavePointer
is passed to every function call, so do not use global
variables! This is because your
filter would have a single instance of its global
variables per application and multiple instances of the filter
would access the same data.
Parameter:
|
|
ppSavePointer |
A pointer to a to pointer to transfer a parameter
structure (parameter block). |
|
|
ppTempPointer |
A pointer to a pointer to transfer temporary
data. |
STDAPI UninitDLL(
void* pSavePointer, void* pTempPointer );
This function is called right before the
DLL is unloaded. Use this function to clean up the filter, for
example freeing allocated memory.
Parameter:
|
|
pSavePointer |
A pointer to the parameter structure of
the InitDLL() function. |
|
|
pTempPointer |
A pointer to the temporary data of
the InitDLL() function. |
STDAPI
GetSizeOfParameters( DWORD *pdwSize, void* pSavePointer );
This function sets the pdwSize parameter
to the size of the filters parameter block.
Parameter:
|
|
pdwSize |
A pointer to a DWORD variable. |
|
|
pSavePointer |
A pointer to the parameter block. |
STDAPI
SaveParameters( void* pData, void* pSavePointer )
This function is called when a filter
graph is saved to a MontiVision Project file (*.mvp). Copy your
configuration data from your parameter block in pSavePointer
to pData.
Parameter:
|
|
pData |
A pointer to a pointer to a buffer to copy the
configuration data. |
|
|
pSavePointer |
A pointer to the parameter block. |
STDAPI
LoadParameters( void* pData, void* pSavePointer )
This function is called when a filter graph is loaded from
a MontiVision Project file (*.mvp). Copy your
configuration from the pData to your parameter block in
pSavePointer.
Parameter:
|
|
pData |
A pointer to a buffer containing the configuration
data. |
|
|
pSavePointer |
A pointer to the parameter block. |
STDAPI PropActivate(HWND hwnd,
void* pSavePointer, void* pTempPointer);
The PropActivate functon is called when opening the filters
property page. Initialize the filter property page within
this function. Look at the macros in windowsx.h to
write code with enhanced readability.
Parameter:
|
|
hwnd |
The window handle of the property page |
|
|
pSavePointer |
A pointer to the parameter structure of
the InitDLL() function. |
|
|
pTempPointer |
A pointer to the temporary data of
the InitDLL() function. |
STDAPI PropDeactivate(HWND
hwnd, void* pSavePointer, void* pTempPointer);
The PropDeactivate functon is called when closing the
filters property page.
Parameter:
|
|
hwnd |
The window handle of the property page |
|
|
pSavePointer |
A pointer to the parameter structure of
the InitDLL() function. |
|
|
pTempPointer |
A pointer to the temporary data of
the InitDLL() function. |
STDAPI PropApplyChanges(HWND
hwnd, void* pSavePointer, void* pTempPointer);
The PropApplyChanges functon is called on the Apply
button of the filters property dialog. Save the values of
the dialog controls if nessasary.
Parameter:
|
|
hwnd |
The window handle of the property page |
|
|
pSavePointer |
A pointer to the parameter structure of
the InitDLL() function. |
|
|
pTempPointer |
A pointer to the temporary data of
the InitDLL() function. |
int PropReceiveMessage(HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM
lParam,
void*
pSavePointer,
void* pTempPointer,
BOOL*
bSetDirty);
The PropReceiveMessage functon is called on every windows
message received by the property page. Handle the messages of
the property page controls within this function.
Parameter:
|
|
hwnd |
The window handle of the property page |
|
|
uMsg |
Received windows message. |
|
|
wParam |
wParam parameter of the received window
message. |
|
|
lParam |
lParam parameter of the received window
message. |
|
|
pSavePointer |
A pointer to the parameter structure of
the InitDLL() function. |
|
|
pTempPointer |
A pointer
to the temporary data of the
InitDLL() function. |
|
|
bSetDirty |
Set the flag to TRUE to enable the Apply butoon of
the property dialog. |
DLL variables:
The following table includes all global variables the DLL has to
export. Don't declare them as static variables.
|
Type
|
Name
|
Description
|
| TCHAR[] |
g_tcFilterName |
Contains the display name of the
filter. |
| TCHAR[] |
g_tcFileName |
Contains the name of the DLL, including extension. |
| TCHAR* |
g_tcPropPageName |
Property page name. |
| int |
g_iPropPageID |
Resource ID of the filter property page. |
| int |
g_iPropPageTitleID |
Resource ID of the filter property page name string
resource. |
| DWORD |
g_dwTypes |
Contains the supported video format of the filter. Possible
values are RGB_8, RGB_24 and RGB_32. |
| GUID |
g_FilterGUID
|
Contains the unique CUID of the filter. It is used to identify
the filter in DirectShow® |
| DWORD |
g_dwIOInputType |
Sets the type of I/O input pin. Set to one of the values from
the table below. |
| DWORD |
g_dwIOOutputType |
Sets the type of I/O output pin. Set to one of the values
from the table below. |
I/O Pin Types:
| I/O pin type
|
Description
|
| IO_NONE |
no pin |
| IO_STRING |
zero terminated string; max 4095 characters |
| IO_INT8 |
signed 8 bit integer |
| IO_UINT8 |
unsigned 8 bit integer |
| IO_INT16 |
signed 16 bit integer |
| IO_UINT16 |
unsigned 16 bit integer |
| IO_INT32 |
signed 32 bit integer |
| IO_UINT32 |
unsigned 32 bit integer |
| IO_FLOAT |
32 bit float |
| IO_BOOL |
32 bit boolean |
|