IID_IAMStreamConfig
This interface can be used to query and set video stream parameters such as the color format, image size, and frame rate.
Setting the stream format The IAMStreamConfig::SetFormat function must not be accessed with a running or paused filter. If this is done, the error VFW_E_NOT_STOPPED will be returned. The filter graph should be stopped before the stream format is changed. |
Using binning/subsampling and setting AOI via IAMStreamConfig The following limitations apply when setting binning/subsampling and AOI via IAMStreamConfig. For this reason we recommend to set binning/subsampling and AOI using the uEye specific Interfaces IuEyeResample and IuEyeAOI. •DirectShow does not differentiate between binning and subsampling. If a uEye camera supports both functions, binning is always enabled. •Binning and subsampling cannot be used with an AOI. If an AOI is set, binning and subsampling cannot be enabled (and vice versa). •Binning and subsampling are only possible with the 2x factor. |
Setting the frame rate The possible frame rate of a camera depends on the set pixel clock. |
Example: Setting the frame rate
HRESULT SetFramerate(IUnknown* pUnknown, double framerate)
{
HRESULT hr = S_OK;
IAMStreamConfig* pStreamCfg = NULL;
/* Query the filter pin's IID_IAMStreamConfig interface */
hr = pUnknown->QueryInterface(IID_IAMStreamConfig, reinterpret_cast<void**>(&pStreamCfg));
if (FAILED(hr))
{
/* Return with error */
return hr;
}
AM_MEDIA_TYPE* pmt = NULL;
hr = pStreamCfg->GetFormat(&pmt);
if (FAILED(hr))
{
/* Release the IID_IAMStreamConfig interface */
pStreamCfg->Release();
pStreamCfg = NULL;
/* Return with error */
return hr;
}
VIDEOINFOHEADER* pvih = (VIDEOINFOHEADER*)pmt->pbFormat;
/* Frame time given in 100ns intervals */
pvih->AvgTimePerFrame = LONGLONG(10000000 / double(framerate / 100.0));
/* Set the new format to the pin */
hr = pStreamCfg->SetFormat(pmt);
/* Release the media type */
pvih = NULL;
DeleteMediaType(pmt);
pmt = NULL;
/* Release the IID_IAMStreamConfig interface */
pStreamCfg->Release();
pStreamCfg = NULL;
return hr;
}
Setting an area of interest (AOI) using the MediaType
To set an AOI with an offset (xOff, yOff), rcSource must be correspondingly set in the media type's VIDEOINFOHEADER. When doing so, it is important for
•the width and height of the rcSource to match the fields biWidth and biHeight in the BITMAPINFOHEADER
•the width and height to be less than/equal to the minimum image dimensions
•the two RECT structures to be fully positioned within the maximum image area
•the vertices of the RECT structures to be correctly aligned
The minimum and maximum image dimensions and alignment requirements can be determined via IAMStreamConfig::GetStreamCaps(). Information acquired via GetStreamCaps() always relates to the specified media type. However, the data used for the image section are generally applicable and can be used for all media types.
Example: Setting an AOI with an offset
HRESULT SetAOI(IUnknown* pUnknown)
{
HRESULT SetAOI(IUnknown* pUnknown)
{
/* we want to set an AOI of 100 x 100 pixels at offset (10, 10) */
int iAOI_Width = 100;
int iAOI_Height = 100;
int iAOI_PosX = 10;
int iAOI_PosY = 10;
HRESULT hr = S_OK;
IAMStreamConfig* pStreamCfg = NULL;
/* query the filter pin's IID_IAMStreamConfig interface */
hr = pUnknown->QueryInterface(IID_IAMStreamConfig, reinterpret_cast<void**>(&pStreamCfg));
if (FAILED(hr))
{
/* return with error */
return hr;
}
AM_MEDIA_TYPE* pmt = NULL;
#if defined WITH_VALIDATION
/* query the capabilities and value ranges for the media type with index 0.
* Note we are not interested in the media type itself, we are interested in
* the generic capabilities that apply to all supported media types.
*/
VIDEO_STREAM_CONFIG_CAPS vscc;
ZeroMemory(&vscc,sizeof(VIDEO_STREAM_CONFIG_CAPS));
hr = pStreamCfg->GetStreamCaps(0, &pmt, (BYTE*)&vscc);
if (FAILED(hr))
{
/* release the IID_IAMStreamConfig interface */
pStreamCfg->Release();
pStreamCfg = NULL;
/* return with error */
return hr;
}
/* the media type 0 is not needed here */
DeleteMediaType(pmt);
pmt = NULL;
/* maximum dimensions of the AOI */
int iMaxWidth = vscc.InputSize.cx;
int iMaxHeight = vscc.InputSize.cy;
/* minimum dimensions of the AOI */
int iMinWidth = vscc.MinCroppingSize.cx;
int iMinHeight = vscc.MinCroppingSize.cy;
/* step width for the AOI dimensions (not needed here, just for demonstration) */
int iSteppingX = vscc.CropGranularityX;
int iSteppingY = vscc.CropGranularityY;
/* required alignment for the AOI coordinates */
int iAlignX = vscc.CropAlignX;
int iAlignY = vscc.CropAlignY;
/* check our AOI to be acceptable for the pin */
if (iAOI_Width > iMaxWidth || iAOI_Width < iMinWidth)
{
/* release the IID_IAMStreamConfig interface */
pStreamCfg->Release();
pStreamCfg = NULL;
/* return with error */
return E_INVALIDARG;
}
if (iAOI_Height > iMaxHeight || iAOI_Height < iMinHeight)
{
/* release the IID_IAMStreamConfig interface */
pStreamCfg->Release();
pStreamCfg = NULL;
/* return with error */
return E_INVALIDARG;
}
if ((iAOI_PosX + iAOI_Width) > iMaxWidth)
{
/* release the IID_IAMStreamConfig interface */
pStreamCfg->Release();
pStreamCfg = NULL;
/* return with error */
return E_INVALIDARG;
}
if ((iAOI_PosY + iAOI_Height) > iMaxHeight)
{
/* release the IID_IAMStreamConfig interface */
pStreamCfg->Release();
pStreamCfg = NULL;
/* return with error */
return E_INVALIDARG;
}
/* force alignment */
iAOI_Width &= ~(iAlignX - 1);
iAOI_Height &= ~(iAlignY - 1);
iAOI_PosX &= ~(iAlignX - 1);
iAOI_PosY &= ~(iAlignY - 1);
#endif /* defined WITH_VALIDATION */
/* query the currently active media type from the pin.
* Note we want to change this media type to define our AOI.
*/
hr = pStreamCfg->GetFormat(&pmt);
if (FAILED(hr))
{
/* release the IID_IAMStreamConfig interface */
pStreamCfg->Release();
pStreamCfg = NULL;
/* return with error */
return hr;
}
/* change the media type to define our AOI */
VIDEOINFOHEADER* pvih = (VIDEOINFOHEADER*)pmt->pbFormat;
/* set the source RECT to the AOI coordinates */
SetRect(&pvih->rcSource, iAOI_PosX, iAOI_PosY, iAOI_PosX + iAOI_Width, iAOI_PosY + iAOI_Height);
/* adjust the width and height fields of the media type's BITMAPINFOHEADER to reflect the AOI's size */
pvih->bmiHeader.biWidth = iAOI_Width;
pvih->bmiHeader.biHeight = iAOI_Height;
/* Note .biWidth, .biHeight and rcSource must be consistently
* specified when we set the changed format to the filter.
* The filter implementation will adjust the remaining format
* related or depending fields of the media type to meet these.
*/
/* set the new format to the pin */
hr = pStreamCfg->SetFormat(pmt);
/* release the media type */
pvih = NULL;
DeleteMediaType(pmt);
pmt = NULL;
/* release the IID_IAMStreamConfig interface */
pStreamCfg->Release();
pStreamCfg = NULL;
return hr;
}