Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
.gif)
| Previous | Next |
Video Format Negotiation in the Sample Video DSP Plug-in
Before Windows Media Player inserts a video DSP plug-in into the signal chain, the Player must determine whether the plug-in can process the video being played. The process by which the plug-in and the Player communicate about supported video formats is called format negotiation.
Providing the Supported Input and Output Types
The Player makes a series of calls to IMediaObject::GetInputType and IMediaObject::GetOutputType to query the plug-in about the formats it supports. In fact, the Player supplies an index value with each call so the plug-in can respond with the media type that corresponds to the index value. The plug-in is not required to support more than one format, but using this mechanism it can communicate to the Player the details of each format that it supports. It does this by filling in a DMO_MEDIA_TYPE structure using a pointer provided by the Player. When the Player provides an index number that exceeds the highest supported media type index value for the plug-in, the plug-in returns E_NO_MORE_ITEMS.
The sample video plug-in generated by the Windows Media Player Plug-in Wizard stores the list of supported video formats as an array of GUIDs. The following code is from the main header file:
static const GUID* k_guidValidSubtypes[] = {
&MEDIASUBTYPE_YV12,
&MEDIASUBTYPE_YUY2,
&MEDIASUBTYPE_UYVY,
&MEDIASUBTYPE_RGB32,
&MEDIASUBTYPE_RGB24,
&MEDIASUBTYPE RGB555,
&MEDIASUBTYPE RGB565
};
These formats are added to the array in order of preference for the plug-in. When the Player calls GetInputType, the plug-in returns the subtype that corresponds to the dwTypeIndex value requested by the Player. The following code from the sample implementation of GetInputType demonstrates this:
::ZeroMemory( pmt, sizeof( DMO_MEDIA_TYPE ) ); pmt->majortype = MEDIATYPE_Video; pmt->subtype = *k_guidValidSubtypes[dwTypeIndex];
The Player can call GetInputType and GetOutputType in any order, so the plug-in code must anticipate this. The sample implementation of GetOutputType tests whether the input type has already been defined. If it has, the plug-in only responds that it supports that type. Otherwise, the plug-in returns the type that corresponds to the supplied index, as the following code demonstrates:
// If input type has been defined, then use that as output type.
if (GUID_NULL != m_mtInput.majortype)
{
hr = ::MoCopyMediaType( pmt, &m_mtInput );
}
else // otherwise use default for this plug-in
{
::ZeroMemory( pmt, sizeof( DMO_MEDIA_TYPE ) );
pmt->majortype = MEDIATYPE_Video;
pmt->subtype = *k_guidValidSubtypes[dwTypeIndex];
}
Setting the Input and Output Types
When Windows Media Player is ready to set the media type for the plug-in, it calls IMediaObject::SetInputType and IMediaObject::SetOutputType, passing to each function a pointer to a DMO_MEDIA_TYPE structure that represents the requested media type. Note that there is no guarantee that the Player will call format negotiation methods in any particular order, so plug-in code must handle any case. For instance, if the Player calls SetOutputType before calling SetInputType, it is a valid course of action for the plug-in to reject the proposed output media type. The following code from the sample implementation of SetOutputType demonstrates this:
if( GUID_NULL != m_mtInput.majortype )
{
// validate that the output media type matches our requirements
// and matches our input type (if set)
hr = ValidateMediaType(pmt, &m_mtInput);
}
else
{
hr = DMO_E_TYPE_NOT_ACCEPTED;
}
The sample plug-in implementations of SetInputType and SetOutputType both call the custom function named ValidateMediaType. This plug-in function performs a series of tests on the proposed media type designed to ensure that the media type is well-formed and supported by the plug-in. ValidateMediaType performs the following tests:
- Verifies that the majortype and formattype members contain the correct values.
- Verifies that the subtype member matches one of the supported formats.
- Verifies that the information in the BITMAPINFOHEADER and VIDEOINFOHEADER or VIDEOINFOHEADER2 structures contain valid values.
- Tests whether the input and output media types match because the plug-in does not convert formats from input to output.
If the proposed media type passes the validation tests, it is stored in a member variable: m_mtInput for the input media type, m_mtOutput for the output media type.
See Also
| Previous | Next |