@ -336,8 +336,33 @@ interface ISampleGrabber : public IUnknown
//STUFF YOU CAN CHANGE
# ifdef _DEBUG
//change for verbose debug info
static bool verbose = true ;
static bool gs_verbose = true ;
static void DebugPrintOut ( const char * format , . . . )
{
if ( gs_verbose )
{
va_list args ;
va_start ( args , format ) ;
if ( : : IsDebuggerPresent ( ) )
{
CHAR szMsg [ 512 ] ;
: : StringCbVPrintfA ( szMsg , sizeof ( szMsg ) , format , args ) ;
: : OutputDebugStringA ( szMsg ) ;
}
else
{
vprintf ( format , args ) ;
}
va_end ( args ) ;
}
}
# else
# define DebugPrintOut(...) void()
# endif
//if you need VI to use multi threaded com
//#define VI_COM_MULTI_THREADED
@ -697,7 +722,7 @@ public:
LeaveCriticalSection ( & critSection ) ;
SetEvent ( hEvent ) ;
} else {
printf ( " ERROR: SampleCB() - buffer sizes do not match \n " ) ;
DebugPrintOut ( " ERROR: SampleCB() - buffer sizes do not match \n " ) ;
}
}
@ -785,7 +810,7 @@ videoDevice::videoDevice(){
void videoDevice : : setSize ( int w , int h ) {
if ( sizeSet ) {
if ( verbose ) printf ( " SETUP: Error device size should not be set more than once \n " ) ;
DebugPrintOut ( " SETUP: Error device size should not be set more than once \n " ) ;
}
else
{
@ -863,7 +888,7 @@ void videoDevice::destroyGraph(){
// We must get the enumerator again every time because removing a filter from the graph
// invalidates the enumerator. We always get only the first filter from each enumerator.
hr = pGraph - > EnumFilters ( & pEnum ) ;
if ( FAILED ( hr ) ) { if ( verbose ) printf ( " SETUP: pGraph->EnumFilters() failed. \n " ) ; return ; }
if ( FAILED ( hr ) ) { DebugPrintOut ( " SETUP: pGraph->EnumFilters() failed. \n " ) ; return ; }
IBaseFilter * pFilter = NULL ;
if ( pEnum - > Next ( 1 , & pFilter , & cFetched ) = = S_OK )
@ -883,10 +908,10 @@ void videoDevice::destroyGraph(){
count + + ;
}
if ( verbose ) printf ( " SETUP: removing filter %s... \n " , buffer ) ;
DebugPrintOut ( " SETUP: removing filter %s... \n " , buffer ) ;
hr = pGraph - > RemoveFilter ( pFilter ) ;
if ( FAILED ( hr ) ) { if ( verbose ) printf ( " SETUP: pGraph->RemoveFilter() failed. \n " ) ; return ; }
if ( verbose ) printf ( " SETUP: filter removed %s \n " , buffer ) ;
if ( FAILED ( hr ) ) { DebugPrintOut ( " SETUP: pGraph->RemoveFilter() failed. \n " ) ; return ; }
DebugPrintOut ( " SETUP: filter removed %s \n " , buffer ) ;
pFilter - > Release ( ) ;
pFilter = NULL ;
@ -909,7 +934,7 @@ void videoDevice::destroyGraph(){
videoDevice : : ~ videoDevice ( ) {
if ( setupStarted ) { if ( verbose ) printf ( " \n SETUP: Disconnecting device %i \n " , myID ) ; }
if ( setupStarted ) { DebugPrintOut ( " \n SETUP: Disconnecting device %i \n " , myID ) ; }
else {
if ( sgCallback ) {
sgCallback - > Release ( ) ;
@ -924,7 +949,7 @@ videoDevice::~videoDevice(){
if ( ( sgCallback ) & & ( pGrabber ) )
{
pGrabber - > SetCallback ( NULL , 1 ) ;
if ( verbose ) printf ( " SETUP: freeing Grabber Callback \n " ) ;
DebugPrintOut ( " SETUP: freeing Grabber Callback \n " ) ;
sgCallback - > Release ( ) ;
//delete our pixels
@ -940,51 +965,51 @@ videoDevice::~videoDevice(){
if ( ( pControl ) )
{
HR = pControl - > Pause ( ) ;
if ( FAILED ( HR ) ) if ( verbose ) printf ( " ERROR - Could not pause pControl \n " ) ;
if ( FAILED ( HR ) ) DebugPrintOut ( " ERROR - Could not pause pControl \n " ) ;
HR = pControl - > Stop ( ) ;
if ( FAILED ( HR ) ) if ( verbose ) printf ( " ERROR - Could not stop pControl \n " ) ;
if ( FAILED ( HR ) ) DebugPrintOut ( " ERROR - Could not stop pControl \n " ) ;
}
//Disconnect filters from capture device
if ( ( pVideoInputFilter ) ) NukeDownstream ( pVideoInputFilter ) ;
//Release and zero pointers to our filters etc
if ( ( pDestFilter ) ) { if ( verbose ) printf ( " SETUP: freeing Renderer \n " ) ;
if ( ( pDestFilter ) ) { DebugPrintOut ( " SETUP: freeing Renderer \n " ) ;
( pDestFilter ) - > Release ( ) ;
( pDestFilter ) = 0 ;
}
if ( ( pVideoInputFilter ) ) { if ( verbose ) printf ( " SETUP: freeing Capture Source \n " ) ;
if ( ( pVideoInputFilter ) ) { DebugPrintOut ( " SETUP: freeing Capture Source \n " ) ;
( pVideoInputFilter ) - > Release ( ) ;
( pVideoInputFilter ) = 0 ;
}
if ( ( pGrabberF ) ) { if ( verbose ) printf ( " SETUP: freeing Grabber Filter \n " ) ;
if ( ( pGrabberF ) ) { DebugPrintOut ( " SETUP: freeing Grabber Filter \n " ) ;
( pGrabberF ) - > Release ( ) ;
( pGrabberF ) = 0 ;
}
if ( ( pGrabber ) ) { if ( verbose ) printf ( " SETUP: freeing Grabber \n " ) ;
if ( ( pGrabber ) ) { DebugPrintOut ( " SETUP: freeing Grabber \n " ) ;
( pGrabber ) - > Release ( ) ;
( pGrabber ) = 0 ;
}
if ( ( pControl ) ) { if ( verbose ) printf ( " SETUP: freeing Control \n " ) ;
if ( ( pControl ) ) { DebugPrintOut ( " SETUP: freeing Control \n " ) ;
( pControl ) - > Release ( ) ;
( pControl ) = 0 ;
}
if ( ( pMediaEvent ) ) { if ( verbose ) printf ( " SETUP: freeing Media Event \n " ) ;
if ( ( pMediaEvent ) ) { DebugPrintOut ( " SETUP: freeing Media Event \n " ) ;
( pMediaEvent ) - > Release ( ) ;
( pMediaEvent ) = 0 ;
}
if ( ( streamConf ) ) { if ( verbose ) printf ( " SETUP: freeing Stream \n " ) ;
if ( ( streamConf ) ) { DebugPrintOut ( " SETUP: freeing Stream \n " ) ;
( streamConf ) - > Release ( ) ;
( streamConf ) = 0 ;
}
if ( ( pAmMediaType ) ) { if ( verbose ) printf ( " SETUP: freeing Media Type \n " ) ;
if ( ( pAmMediaType ) ) { DebugPrintOut ( " SETUP: freeing Media Type \n " ) ;
MyDeleteMediaType ( pAmMediaType ) ;
}
if ( ( pMediaEvent ) ) {
if ( verbose ) printf ( " SETUP: freeing Media Event \n " ) ;
DebugPrintOut ( " SETUP: freeing Media Event \n " ) ;
( pMediaEvent ) - > Release ( ) ;
( pMediaEvent ) = 0 ;
}
@ -993,11 +1018,11 @@ videoDevice::~videoDevice(){
if ( ( pGraph ) ) destroyGraph ( ) ;
//Release and zero our capture graph and our main graph
if ( ( pCaptureGraph ) ) { if ( verbose ) printf ( " SETUP: freeing Capture Graph \n " ) ;
if ( ( pCaptureGraph ) ) { DebugPrintOut ( " SETUP: freeing Capture Graph \n " ) ;
( pCaptureGraph ) - > Release ( ) ;
( pCaptureGraph ) = 0 ;
}
if ( ( pGraph ) ) { if ( verbose ) printf ( " SETUP: freeing Main Graph \n " ) ;
if ( ( pGraph ) ) { DebugPrintOut ( " SETUP: freeing Main Graph \n " ) ;
( pGraph ) - > Release ( ) ;
( pGraph ) = 0 ;
}
@ -1013,7 +1038,7 @@ videoDevice::~videoDevice(){
delete pCaptureGraph ;
delete pGraph ;
if ( verbose ) printf ( " SETUP: Device %i disconnected and freed \n \n " , myID ) ;
DebugPrintOut ( " SETUP: Device %i disconnected and freed \n \n " , myID ) ;
}
@ -1037,7 +1062,7 @@ videoInput::videoInput(){
//setup a max no of device objects
for ( int i = 0 ; i < VI_MAX_CAMERAS ; i + + ) VDList [ i ] = new videoDevice ( ) ;
if ( verbose ) printf ( " \n ***** VIDEOINPUT LIBRARY - %2.04f - TFW07 ***** \n \n " , VI_VERSION ) ;
DebugPrintOut ( " \n ***** VIDEOINPUT LIBRARY - %2.04f - TFW07 ***** \n \n " , VI_VERSION ) ;
//added for the pixelink firewire camera
//MEDIASUBTYPE_Y800 = (GUID)FOURCCMap(FCC('Y800'));
@ -1101,7 +1126,11 @@ videoInput::videoInput(){
// ----------------------------------------------------------------------
void videoInput : : setVerbose ( bool _verbose ) {
verbose = _verbose ;
# ifdef _DEBUG
gs_verbose = _verbose ;
# else
( void ) _verbose ; // Suppress 'unreferenced parameter' warning
# endif
}
// ----------------------------------------------------------------------
@ -1114,7 +1143,7 @@ void videoInput::setUseCallback(bool useCallback){
bCallback = useCallback ;
callbackSetCount = 1 ;
} else {
printf ( " ERROR: setUseCallback can only be called before setup \n " ) ;
DebugPrintOut ( " ERROR: setUseCallback can only be called before setup \n " ) ;
}
}
@ -1256,7 +1285,7 @@ bool videoInput::setFormat(int deviceNumber, int format){
if ( VDList [ deviceNumber ] - > pVideoInputFilter ) VDList [ deviceNumber ] - > pVideoInputFilter = NULL ;
if ( FAILED ( hr ) ) {
printf ( " SETUP: couldn't set requested format \n " ) ;
DebugPrintOut ( " SETUP: couldn't set requested format \n " ) ;
} else {
long lValue = 0 ;
hr = pVideoDec - > get_AvailableTVFormats ( & lValue ) ;
@ -1264,7 +1293,7 @@ bool videoInput::setFormat(int deviceNumber, int format){
{
hr = pVideoDec - > put_TVFormat ( VDList [ deviceNumber ] - > formatType ) ;
if ( FAILED ( hr ) ) {
printf ( " SETUP: couldn't set requested format \n " ) ;
DebugPrintOut ( " SETUP: couldn't set requested format \n " ) ;
} else {
returnVal = true ;
}
@ -1304,7 +1333,7 @@ int videoInput::listDevices(bool silent){
//COM Library Intialization
comInit ( ) ;
if ( ! silent ) printf ( " \n VIDEOINPUT SPY MODE! \n \n " ) ;
if ( ! silent ) DebugPrintOut ( " \n VIDEOINPUT SPY MODE! \n \n " ) ;
ICreateDevEnum * pDevEnum = NULL ;
@ -1325,7 +1354,7 @@ int videoInput::listDevices(bool silent){
if ( hr = = S_OK ) {
if ( ! silent ) printf ( " SETUP: Looking For Capture Devices \n " ) ;
if ( ! silent ) DebugPrintOut ( " SETUP: Looking For Capture Devices \n " ) ;
IMoniker * pMoniker = NULL ;
while ( pEnum - > Next ( 1 , & pMoniker , NULL ) = = S_OK ) {
@ -1359,7 +1388,7 @@ int videoInput::listDevices(bool silent){
}
deviceNames [ deviceCounter ] [ count ] = 0 ;
if ( ! silent ) printf ( " SETUP: %i) %s \n " , deviceCounter , deviceNames [ deviceCounter ] ) ;
if ( ! silent ) DebugPrintOut ( " SETUP: %i) %s \n " , deviceCounter , deviceNames [ deviceCounter ] ) ;
}
pPropBag - > Release ( ) ;
@ -1378,7 +1407,7 @@ int videoInput::listDevices(bool silent){
pEnum = NULL ;
}
if ( ! silent ) printf ( " SETUP: %i Device(s) found \n \n " , deviceCounter ) ;
if ( ! silent ) DebugPrintOut ( " SETUP: %i Device(s) found \n \n " , deviceCounter ) ;
}
comUnInit ( ) ;
@ -1516,10 +1545,10 @@ bool videoInput::getPixels(int id, unsigned char * dstBuffer, bool flipRedAndBlu
processPixels ( src , dst , width , height , flipRedAndBlue , flipImage ) ;
success = true ;
} else {
if ( verbose ) printf ( " ERROR: GetPixels() - bufferSizes do not match! \n " ) ;
DebugPrintOut ( " ERROR: GetPixels() - bufferSizes do not match! \n " ) ;
}
} else {
if ( verbose ) printf ( " ERROR: GetPixels() - Unable to grab frame for device %i \n " , id ) ;
DebugPrintOut ( " ERROR: GetPixels() - Unable to grab frame for device %i \n " , id ) ;
}
}
}
@ -1571,11 +1600,11 @@ bool videoInput::isFrameNew(int id){
VDList [ id ] - > nFramesRunning + + ;
if ( freeze & & VDList [ id ] - > autoReconnect ) {
if ( verbose ) printf ( " ERROR: Device seems frozen - attempting to reconnect \n " ) ;
DebugPrintOut ( " ERROR: Device seems frozen - attempting to reconnect \n " ) ;
if ( ! restartDevice ( VDList [ id ] - > myID ) ) {
if ( verbose ) printf ( " ERROR: Unable to reconnect to device \n " ) ;
DebugPrintOut ( " ERROR: Unable to reconnect to device \n " ) ;
} else {
if ( verbose ) printf ( " SUCCESS: Able to reconnect to device \n " ) ;
DebugPrintOut ( " SUCCESS: Able to reconnect to device \n " ) ;
}
}
@ -1646,7 +1675,7 @@ bool videoInput::getVideoSettingFilter(int deviceID, long Property, long &min, l
hr = getDevice ( & VD - > pVideoInputFilter , deviceID , VD - > wDeviceName , VD - > nDeviceName ) ;
if ( FAILED ( hr ) ) {
printf ( " setVideoSetting - getDevice Error \n " ) ;
DebugPrintOut ( " setVideoSetting - getDevice Error \n " ) ;
return false ;
}
@ -1654,7 +1683,7 @@ bool videoInput::getVideoSettingFilter(int deviceID, long Property, long &min, l
hr = VD - > pVideoInputFilter - > QueryInterface ( IID_IAMVideoProcAmp , ( void * * ) & pAMVideoProcAmp ) ;
if ( FAILED ( hr ) ) {
printf ( " setVideoSetting - QueryInterface Error \n " ) ;
DebugPrintOut ( " setVideoSetting - QueryInterface Error \n " ) ;
if ( VD - > pVideoInputFilter ) VD - > pVideoInputFilter - > Release ( ) ;
if ( VD - > pVideoInputFilter ) VD - > pVideoInputFilter = NULL ;
return false ;
@ -1663,10 +1692,10 @@ bool videoInput::getVideoSettingFilter(int deviceID, long Property, long &min, l
char propStr [ 16 ] ;
getVideoPropertyAsString ( Property , propStr ) ;
if ( verbose ) printf ( " Setting video setting %s. \n " , propStr ) ;
DebugPrintOut ( " Setting video setting %s. \n " , propStr ) ;
pAMVideoProcAmp - > GetRange ( Property , & min , & max , & SteppingDelta , & defaultValue , & flags ) ;
if ( verbose ) printf ( " Range for video setting %s: Min:%ld Max:%ld SteppingDelta:%ld Default:%ld Flags:%ld \n " , propStr , min , max , SteppingDelta , defaultValue , flags ) ;
DebugPrintOut ( " Range for video setting %s: Min:%ld Max:%ld SteppingDelta:%ld Default:%ld Flags:%ld \n " , propStr , min , max , SteppingDelta , defaultValue , flags ) ;
pAMVideoProcAmp - > Get ( Property , & currentValue , & flags ) ;
if ( pAMVideoProcAmp ) pAMVideoProcAmp - > Release ( ) ;
@ -1707,7 +1736,7 @@ bool videoInput::setVideoSettingFilterPct(int deviceID, long Property, float pct
float halfStep = ( float ) stepAmnt * 0.5f ;
if ( mod < halfStep ) rasterValue - = mod ;
else rasterValue + = stepAmnt - mod ;
printf ( " RASTER - pctValue is %f - value is %li - step is %li - mod is %li - rasterValue is %li \n " , pctValue , value , stepAmnt , mod , rasterValue ) ;
DebugPrintOut ( " RASTER - pctValue is %f - value is %li - step is %li - mod is %li - rasterValue is %li \n " , pctValue , value , stepAmnt , mod , rasterValue ) ;
}
return setVideoSettingFilter ( deviceID , Property , rasterValue , Flags , false ) ;
@ -1728,7 +1757,7 @@ bool videoInput::setVideoSettingFilter(int deviceID, long Property, long lValue,
hr = getDevice ( & VD - > pVideoInputFilter , deviceID , VD - > wDeviceName , VD - > nDeviceName ) ;
if ( FAILED ( hr ) ) {
printf ( " setVideoSetting - getDevice Error \n " ) ;
DebugPrintOut ( " setVideoSetting - getDevice Error \n " ) ;
return false ;
}
@ -1736,21 +1765,21 @@ bool videoInput::setVideoSettingFilter(int deviceID, long Property, long lValue,
hr = VD - > pVideoInputFilter - > QueryInterface ( IID_IAMVideoProcAmp , ( void * * ) & pAMVideoProcAmp ) ;
if ( FAILED ( hr ) ) {
printf ( " setVideoSetting - QueryInterface Error \n " ) ;
DebugPrintOut ( " setVideoSetting - QueryInterface Error \n " ) ;
if ( VD - > pVideoInputFilter ) VD - > pVideoInputFilter - > Release ( ) ;
if ( VD - > pVideoInputFilter ) VD - > pVideoInputFilter = NULL ;
return false ;
}
if ( verbose ) printf ( " Setting video setting %s. \n " , propStr ) ;
DebugPrintOut ( " Setting video setting %s. \n " , propStr ) ;
long CurrVal , Min , Max , SteppingDelta , Default , CapsFlags , AvailableCapsFlags = 0 ;
pAMVideoProcAmp - > GetRange ( Property , & Min , & Max , & SteppingDelta , & Default , & AvailableCapsFlags ) ;
if ( verbose ) printf ( " Range for video setting %s: Min:%ld Max:%ld SteppingDelta:%ld Default:%ld Flags:%ld \n " , propStr , Min , Max , SteppingDelta , Default , AvailableCapsFlags ) ;
DebugPrintOut ( " Range for video setting %s: Min:%ld Max:%ld SteppingDelta:%ld Default:%ld Flags:%ld \n " , propStr , Min , Max , SteppingDelta , Default , AvailableCapsFlags ) ;
pAMVideoProcAmp - > Get ( Property , & CurrVal , & CapsFlags ) ;
if ( verbose ) printf ( " Current value: %ld Flags %ld (%s) \n " , CurrVal , CapsFlags , ( CapsFlags = = 1 ? " Auto " : ( CapsFlags = = 2 ? " Manual " : " Unknown " ) ) ) ;
DebugPrintOut ( " Current value: %ld Flags %ld (%s) \n " , CurrVal , CapsFlags , ( CapsFlags = = 1 ? " Auto " : ( CapsFlags = = 2 ? " Manual " : " Unknown " ) ) ) ;
if ( useDefaultValue ) {
pAMVideoProcAmp - > Set ( Property , Default , VideoProcAmp_Flags_Auto ) ;
@ -1797,7 +1826,7 @@ bool videoInput::setVideoSettingCameraPct(int deviceID, long Property, float pct
float halfStep = ( float ) stepAmnt * 0.5f ;
if ( mod < halfStep ) rasterValue - = mod ;
else rasterValue + = stepAmnt - mod ;
printf ( " RASTER - pctValue is %f - value is %li - step is %li - mod is %li - rasterValue is %li \n " , pctValue , value , stepAmnt , mod , rasterValue ) ;
DebugPrintOut ( " RASTER - pctValue is %f - value is %li - step is %li - mod is %li - rasterValue is %li \n " , pctValue , value , stepAmnt , mod , rasterValue ) ;
}
return setVideoSettingCamera ( deviceID , Property , rasterValue , Flags , false ) ;
@ -1814,19 +1843,19 @@ bool videoInput::setVideoSettingCamera(int deviceID, long Property, long lValue,
char propStr [ 16 ] ;
getCameraPropertyAsString ( Property , propStr ) ;
if ( verbose ) printf ( " Setting video setting %s. \n " , propStr ) ;
DebugPrintOut ( " Setting video setting %s. \n " , propStr ) ;
hr = VDList [ deviceID ] - > pVideoInputFilter - > QueryInterface ( IID_IAMCameraControl , ( void * * ) & pIAMCameraControl ) ;
if ( FAILED ( hr ) ) {
printf ( " Error \n " ) ;
DebugPrintOut ( " Error \n " ) ;
return false ;
}
else
{
long CurrVal , Min , Max , SteppingDelta , Default , CapsFlags , AvailableCapsFlags ;
pIAMCameraControl - > GetRange ( Property , & Min , & Max , & SteppingDelta , & Default , & AvailableCapsFlags ) ;
if ( verbose ) printf ( " Range for video setting %s: Min:%ld Max:%ld SteppingDelta:%ld Default:%ld Flags:%ld \n " , propStr , Min , Max , SteppingDelta , Default , AvailableCapsFlags ) ;
DebugPrintOut ( " Range for video setting %s: Min:%ld Max:%ld SteppingDelta:%ld Default:%ld Flags:%ld \n " , propStr , Min , Max , SteppingDelta , Default , AvailableCapsFlags ) ;
pIAMCameraControl - > Get ( Property , & CurrVal , & CapsFlags ) ;
if ( verbose ) printf ( " Current value: %ld Flags %ld (%s) \n " , CurrVal , CapsFlags , ( CapsFlags = = 1 ? " Auto " : ( CapsFlags = = 2 ? " Manual " : " Unknown " ) ) ) ;
DebugPrintOut ( " Current value: %ld Flags %ld (%s) \n " , CurrVal , CapsFlags , ( CapsFlags = = 1 ? " Auto " : ( CapsFlags = = 2 ? " Manual " : " Unknown " ) ) ) ;
if ( useDefaultValue ) {
pIAMCameraControl - > Set ( Property , Default , CameraControl_Flags_Auto ) ;
}
@ -1854,7 +1883,7 @@ bool videoInput::getVideoSettingCamera(int deviceID, long Property, long &min, l
hr = getDevice ( & VD - > pVideoInputFilter , deviceID , VD - > wDeviceName , VD - > nDeviceName ) ;
if ( FAILED ( hr ) ) {
printf ( " setVideoSetting - getDevice Error \n " ) ;
DebugPrintOut ( " setVideoSetting - getDevice Error \n " ) ;
return false ;
}
@ -1862,7 +1891,7 @@ bool videoInput::getVideoSettingCamera(int deviceID, long Property, long &min, l
hr = VD - > pVideoInputFilter - > QueryInterface ( IID_IAMCameraControl , ( void * * ) & pIAMCameraControl ) ;
if ( FAILED ( hr ) ) {
printf ( " setVideoSetting - QueryInterface Error \n " ) ;
DebugPrintOut ( " setVideoSetting - QueryInterface Error \n " ) ;
if ( VD - > pVideoInputFilter ) VD - > pVideoInputFilter - > Release ( ) ;
if ( VD - > pVideoInputFilter ) VD - > pVideoInputFilter = NULL ;
return false ;
@ -1870,10 +1899,10 @@ bool videoInput::getVideoSettingCamera(int deviceID, long Property, long &min, l
char propStr [ 16 ] ;
getCameraPropertyAsString ( Property , propStr ) ;
if ( verbose ) printf ( " Setting video setting %s. \n " , propStr ) ;
DebugPrintOut ( " Setting video setting %s. \n " , propStr ) ;
pIAMCameraControl - > GetRange ( Property , & min , & max , & SteppingDelta , & defaultValue , & flags ) ;
if ( verbose ) printf ( " Range for video setting %s: Min:%ld Max:%ld SteppingDelta:%ld Default:%ld Flags:%ld \n " , propStr , min , max , SteppingDelta , defaultValue , flags ) ;
DebugPrintOut ( " Range for video setting %s: Min:%ld Max:%ld SteppingDelta:%ld Default:%ld Flags:%ld \n " , propStr , min , max , SteppingDelta , defaultValue , flags ) ;
pIAMCameraControl - > Get ( Property , & currentValue , & flags ) ;
if ( pIAMCameraControl ) pIAMCameraControl - > Release ( ) ;
@ -1981,7 +2010,7 @@ bool videoInput::comInit(){
//if another library has started com as single threaded
//and we need it multi-threaded - send warning but don't fail
if ( hr = = RPC_E_CHANGED_MODE ) {
if ( verbose ) printf ( " SETUP - COM already setup - threaded VI might not be possible \n " ) ;
DebugPrintOut ( " SETUP - COM already setup - threaded VI might not be possible \n " ) ;
}
}
@ -2066,14 +2095,14 @@ bool videoInput::setup(int deviceNumber){
if ( deviceNumber > devicesFound - 1 )
{
if ( verbose ) printf ( " SETUP: device[%i] not found - you have %i devices available \n " , deviceNumber , devicesFound ) ;
if ( devicesFound > = 0 ) if ( verbose ) printf ( " SETUP: this means that the last device you can use is device[%i] \n " , devicesFound - 1 ) ;
DebugPrintOut ( " SETUP: device[%i] not found - you have %i devices available \n " , deviceNumber , devicesFound ) ;
if ( devicesFound > = 0 ) DebugPrintOut ( " SETUP: this means that the last device you can use is device[%i] \n " , devicesFound - 1 ) ;
return false ;
}
if ( VDList [ deviceNumber ] - > readyToCapture )
{
if ( verbose ) printf ( " SETUP: can't setup, device %i is currently being used \n " , VDList [ deviceNumber ] - > myID ) ;
DebugPrintOut ( " SETUP: can't setup, device %i is currently being used \n " , VDList [ deviceNumber ] - > myID ) ;
return false ;
}
@ -2329,8 +2358,8 @@ static void findClosestSizeAndSubtype(videoDevice * VD, int widthIn, int heightI
//Don't want to get stuck in a loop
if ( stepX < 1 | | stepY < 1 ) continue ;
//if(verbose)printf("min is %i %i max is %i %i - res is %i %i \n", scc.MinOutputSize.cx, scc.MinOutputSize.cy, scc.MaxOutputSize.cx, scc.MaxOutputSize.cy, stepX, stepY);
//if(verbose)printf ("min frame duration is %i max duration is %i\n", scc.MinFrameInterval, scc.MaxFrameInterval);
//DebugPrintOut("min is %i %i max is %i %i - res is %i %i \n", scc.MinOutputSize.cx, scc.MinOutputSize.cy, scc.MaxOutputSize.cx, scc.MaxOutputSize.cy, stepX, stepY);
//DebugPrintOut ("min frame duration is %i max duration is %i\n", scc.MinFrameInterval, scc.MaxFrameInterval);
bool exactMatch = false ;
bool exactMatchX = false ;
@ -2457,14 +2486,14 @@ int videoInput::start(int deviceID, videoDevice *VD){
CAPTURE_MODE = PIN_CATEGORY_CAPTURE ; //Don't worry - it ends up being preview (which is faster)
callbackSetCount = 1 ; //make sure callback method is not changed after setup called
if ( verbose ) printf ( " SETUP: Setting up device %i \n " , deviceID ) ;
DebugPrintOut ( " SETUP: Setting up device %i \n " , deviceID ) ;
// CREATE THE GRAPH BUILDER //
// Create the filter graph manager and query for interfaces.
hr = CoCreateInstance ( CLSID_CaptureGraphBuilder2 , NULL , CLSCTX_INPROC_SERVER , IID_ICaptureGraphBuilder2 , ( void * * ) & VD - > pCaptureGraph ) ;
if ( FAILED ( hr ) ) // FAILED is a macro that tests the return value
{
if ( verbose ) printf ( " ERROR - Could not create the Filter Graph Manager \n " ) ;
DebugPrintOut ( " ERROR - Could not create the Filter Graph Manager \n " ) ;
return hr ;
}
@ -2473,7 +2502,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
hr = CoCreateInstance ( CLSID_FilterGraph , 0 , CLSCTX_INPROC_SERVER , IID_IGraphBuilder , ( void * * ) & VD - > pGraph ) ;
if ( FAILED ( hr ) )
{
if ( verbose ) printf ( " ERROR - Could not add the graph builder! \n " ) ;
DebugPrintOut ( " ERROR - Could not add the graph builder! \n " ) ;
stopDevice ( deviceID ) ;
return hr ;
}
@ -2482,7 +2511,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
hr = VD - > pCaptureGraph - > SetFiltergraph ( VD - > pGraph ) ;
if ( FAILED ( hr ) )
{
if ( verbose ) printf ( " ERROR - Could not set filtergraph \n " ) ;
DebugPrintOut ( " ERROR - Could not set filtergraph \n " ) ;
stopDevice ( deviceID ) ;
return hr ;
}
@ -2493,7 +2522,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
hr = VD - > pGraph - > QueryInterface ( IID_IMediaControl , ( void * * ) & VD - > pControl ) ;
if ( FAILED ( hr ) )
{
if ( verbose ) printf ( " ERROR - Could not create the Media Control object \n " ) ;
DebugPrintOut ( " ERROR - Could not create the Media Control object \n " ) ;
stopDevice ( deviceID ) ;
return hr ;
}
@ -2504,10 +2533,10 @@ int videoInput::start(int deviceID, videoDevice *VD){
hr = getDevice ( & VD - > pVideoInputFilter , deviceID , VD - > wDeviceName , VD - > nDeviceName ) ;
if ( SUCCEEDED ( hr ) ) {
if ( verbose ) printf ( " SETUP: %s \n " , VD - > nDeviceName ) ;
DebugPrintOut ( " SETUP: %s \n " , VD - > nDeviceName ) ;
hr = VD - > pGraph - > AddFilter ( VD - > pVideoInputFilter , VD - > wDeviceName ) ;
} else {
if ( verbose ) printf ( " ERROR - Could not find specified video device \n " ) ;
DebugPrintOut ( " ERROR - Could not find specified video device \n " ) ;
stopDevice ( deviceID ) ;
return hr ;
}
@ -2516,7 +2545,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
IAMStreamConfig * streamConfTest = NULL ;
hr = VD - > pCaptureGraph - > FindInterface ( & PIN_CATEGORY_PREVIEW , & MEDIATYPE_Video , VD - > pVideoInputFilter , IID_IAMStreamConfig , ( void * * ) & streamConfTest ) ;
if ( FAILED ( hr ) ) {
if ( verbose ) printf ( " SETUP: Couldn't find preview pin using SmartTee \n " ) ;
DebugPrintOut ( " SETUP: Couldn't find preview pin using SmartTee \n " ) ;
} else {
CAPTURE_MODE = PIN_CATEGORY_PREVIEW ;
streamConfTest - > Release ( ) ;
@ -2528,7 +2557,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
//webcams tend not to have a crossbar so this function will also detect a webcams and not apply the crossbar
if ( VD - > useCrossbar )
{
if ( verbose ) printf ( " SETUP: Checking crossbar \n " ) ;
DebugPrintOut ( " SETUP: Checking crossbar \n " ) ;
routeCrossbar ( & VD - > pCaptureGraph , & VD - > pVideoInputFilter , VD - > connection , CAPTURE_MODE ) ;
}
@ -2536,7 +2565,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
//we do this because webcams don't have a preview mode
hr = VD - > pCaptureGraph - > FindInterface ( & CAPTURE_MODE , & MEDIATYPE_Video , VD - > pVideoInputFilter , IID_IAMStreamConfig , ( void * * ) & VD - > streamConf ) ;
if ( FAILED ( hr ) ) {
if ( verbose ) printf ( " ERROR: Couldn't config the stream! \n " ) ;
DebugPrintOut ( " ERROR: Couldn't config the stream! \n " ) ;
stopDevice ( deviceID ) ;
return hr ;
}
@ -2544,7 +2573,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
//NOW LETS DEAL WITH GETTING THE RIGHT SIZE
hr = VD - > streamConf - > GetFormat ( & VD - > pAmMediaType ) ;
if ( FAILED ( hr ) ) {
if ( verbose ) printf ( " ERROR: Couldn't getFormat for pAmMediaType! \n " ) ;
DebugPrintOut ( " ERROR: Couldn't getFormat for pAmMediaType! \n " ) ;
stopDevice ( deviceID ) ;
return hr ;
}
@ -2558,12 +2587,12 @@ int videoInput::start(int deviceID, videoDevice *VD){
bool foundSize = false ;
if ( customSize ) {
if ( verbose ) printf ( " SETUP: Default Format is set to %i by %i \n " , currentWidth , currentHeight ) ;
DebugPrintOut ( " SETUP: Default Format is set to %ix%i \n " , currentWidth , currentHeight ) ;
char guidStr [ 8 ] ;
// try specified format and size
getMediaSubtypeAsString ( VD - > tryVideoType , guidStr ) ;
if ( verbose ) printf ( " SETUP: trying specified format %s @ %i by %i \n " , guidStr , VD - > tryWidth , VD - > tryHeight ) ;
DebugPrintOut ( " SETUP: trying specified format %s @ %ix %i \n " , guidStr , VD - > tryWidth , VD - > tryHeight ) ;
if ( setSizeAndSubtype ( VD , VD - > tryWidth , VD - > tryHeight , VD - > tryVideoType ) ) {
VD - > setSize ( VD - > tryWidth , VD - > tryHeight ) ;
@ -2575,7 +2604,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
getMediaSubtypeAsString ( mediaSubtypes [ i ] , guidStr ) ;
if ( verbose ) printf ( " SETUP: trying format %s @ %i by %i \n " , guidStr , VD - > tryWidth , VD - > tryHeight ) ;
DebugPrintOut ( " SETUP: trying format %s @ %ix %i \n " , guidStr , VD - > tryWidth , VD - > tryHeight ) ;
if ( setSizeAndSubtype ( VD , VD - > tryWidth , VD - > tryHeight , mediaSubtypes [ i ] ) ) {
VD - > setSize ( VD - > tryWidth , VD - > tryHeight ) ;
VD - > videoType = mediaSubtypes [ i ] ;
@ -2588,7 +2617,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
//if we didn't find the requested size - lets try and find the closest matching size
if ( foundSize = = false ) {
if ( verbose ) printf ( " SETUP: couldn't find requested size - searching for closest matching size \n " ) ;
DebugPrintOut ( " SETUP: couldn't find requested size - searching for closest matching size \n " ) ;
int closestWidth = - 1 ;
int closestHeight = - 1 ;
@ -2599,7 +2628,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
if ( closestWidth ! = - 1 & & closestHeight ! = - 1 ) {
getMediaSubtypeAsString ( newMediaSubtype , guidStr ) ;
if ( verbose ) printf ( " SETUP: closest supported size is %s @ %i %i \n " , guidStr , closestWidth , closestHeight ) ;
DebugPrintOut ( " SETUP: closest supported size is %s @ %i %i \n " , guidStr , closestWidth , closestHeight ) ;
if ( setSizeAndSubtype ( VD , closestWidth , closestHeight , newMediaSubtype ) ) {
VD - > setSize ( closestWidth , closestHeight ) ;
foundSize = true ;
@ -2621,21 +2650,21 @@ int videoInput::start(int deviceID, videoDevice *VD){
// Create the Sample Grabber.
hr = CoCreateInstance ( CLSID_SampleGrabber , NULL , CLSCTX_INPROC_SERVER , IID_IBaseFilter , ( void * * ) & VD - > pGrabberF ) ;
if ( FAILED ( hr ) ) {
if ( verbose ) printf ( " Could not Create Sample Grabber - CoCreateInstance() \n " ) ;
DebugPrintOut ( " Could not Create Sample Grabber - CoCreateInstance() \n " ) ;
stopDevice ( deviceID ) ;
return hr ;
}
hr = VD - > pGraph - > AddFilter ( VD - > pGrabberF , L " Sample Grabber " ) ;
if ( FAILED ( hr ) ) {
if ( verbose ) printf ( " Could not add Sample Grabber - AddFilter() \n " ) ;
DebugPrintOut ( " Could not add Sample Grabber - AddFilter() \n " ) ;
stopDevice ( deviceID ) ;
return hr ;
}
hr = VD - > pGrabberF - > QueryInterface ( IID_ISampleGrabber , ( void * * ) & VD - > pGrabber ) ;
if ( FAILED ( hr ) ) {
if ( verbose ) printf ( " ERROR: Could not query SampleGrabber \n " ) ;
DebugPrintOut ( " ERROR: Could not query SampleGrabber \n " ) ;
stopDevice ( deviceID ) ;
return hr ;
}
@ -2654,11 +2683,11 @@ int videoInput::start(int deviceID, videoDevice *VD){
//We use SampleCB
hr = VD - > pGrabber - > SetCallback ( VD - > sgCallback , 0 ) ;
if ( FAILED ( hr ) ) {
if ( verbose ) printf ( " ERROR: problem setting callback \n " ) ;
DebugPrintOut ( " ERROR: problem setting callback \n " ) ;
stopDevice ( deviceID ) ;
return hr ;
} else {
if ( verbose ) printf ( " SETUP: Capture callback set \n " ) ;
DebugPrintOut ( " SETUP: Capture callback set \n " ) ;
}
}
@ -2681,7 +2710,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
VD - > streamConf - > Release ( ) ;
VD - > streamConf = NULL ;
} else {
if ( verbose ) printf ( " ERROR: connecting device - prehaps it is already being used? \n " ) ;
DebugPrintOut ( " ERROR: connecting device - prehaps it is already being used? \n " ) ;
stopDevice ( deviceID ) ;
return S_FALSE ;
}
@ -2691,14 +2720,14 @@ int videoInput::start(int deviceID, videoDevice *VD){
//used to give the video stream somewhere to go to.
hr = CoCreateInstance ( CLSID_NullRenderer , NULL , CLSCTX_INPROC_SERVER , IID_IBaseFilter , ( void * * ) ( & VD - > pDestFilter ) ) ;
if ( FAILED ( hr ) ) {
if ( verbose ) printf ( " ERROR: Could not create filter - NullRenderer \n " ) ;
DebugPrintOut ( " ERROR: Could not create filter - NullRenderer \n " ) ;
stopDevice ( deviceID ) ;
return hr ;
}
hr = VD - > pGraph - > AddFilter ( VD - > pDestFilter , L " NullRenderer " ) ;
if ( FAILED ( hr ) ) {
if ( verbose ) printf ( " ERROR: Could not add filter - NullRenderer \n " ) ;
DebugPrintOut ( " ERROR: Could not add filter - NullRenderer \n " ) ;
stopDevice ( deviceID ) ;
return hr ;
}
@ -2708,7 +2737,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
hr = VD - > pCaptureGraph - > RenderStream ( & PIN_CATEGORY_PREVIEW , & MEDIATYPE_Video , VD - > pVideoInputFilter , VD - > pGrabberF , VD - > pDestFilter ) ;
if ( FAILED ( hr ) ) {
if ( verbose ) printf ( " ERROR: Could not connect pins - RenderStream() \n " ) ;
DebugPrintOut ( " ERROR: Could not connect pins - RenderStream() \n " ) ;
stopDevice ( deviceID ) ;
return hr ;
}
@ -2719,7 +2748,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
IMediaFilter * pMediaFilter = 0 ;
hr = VD - > pGraph - > QueryInterface ( IID_IMediaFilter , ( void * * ) & pMediaFilter ) ;
if ( FAILED ( hr ) ) {
if ( verbose ) printf ( " ERROR: Could not get IID_IMediaFilter interface \n " ) ;
DebugPrintOut ( " ERROR: Could not get IID_IMediaFilter interface \n " ) ;
} else {
pMediaFilter - > SetSyncSource ( NULL ) ;
pMediaFilter - > Release ( ) ;
@ -2731,7 +2760,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
hr = VD - > pControl - > Run ( ) ;
if ( FAILED ( hr ) ) {
if ( verbose ) printf ( " ERROR: Could not start graph \n " ) ;
DebugPrintOut ( " ERROR: Could not start graph \n " ) ;
stopDevice ( deviceID ) ;
return hr ;
}
@ -2749,7 +2778,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
}
if ( verbose ) printf ( " SETUP: Device is setup and ready to capture. \n \n " ) ;
DebugPrintOut ( " SETUP: Device is setup and ready to capture. \n \n " ) ;
VD - > readyToCapture = true ;
//Release filters - seen someone else do this
@ -3026,7 +3055,7 @@ HRESULT videoInput::routeCrossbar(ICaptureGraphBuilder2 **ppBuild, IBaseFilter *
bool foundDevice = false ;
if ( verbose ) printf ( " SETUP: You are not a webcam! Setting Crossbar \n " ) ;
DebugPrintOut ( " SETUP: You are not a webcam! Setting Crossbar \n " ) ;
pXBar1 - > Release ( ) ;
IAMCrossbar * Crossbar ;
@ -3046,24 +3075,24 @@ HRESULT videoInput::routeCrossbar(ICaptureGraphBuilder2 **ppBuild, IBaseFilter *
hr = Crossbar - > get_CrossbarPinInfo ( iPin , pIndex , & pRIndex , & pType ) ;
if ( pType = = conType ) {
if ( verbose ) printf ( " SETUP: Found Physical Interface " ) ;
DebugPrintOut ( " SETUP: Found Physical Interface " ) ;
switch ( conType ) {
case PhysConn_Video_Composite :
if ( verbose ) printf ( " - Composite \n " ) ;
DebugPrintOut ( " - Composite \n " ) ;
break ;
case PhysConn_Video_SVideo :
if ( verbose ) printf ( " - S-Video \n " ) ;
DebugPrintOut ( " - S-Video \n " ) ;
break ;
case PhysConn_Video_Tuner :
if ( verbose ) printf ( " - Tuner \n " ) ;
DebugPrintOut ( " - Tuner \n " ) ;
break ;
case PhysConn_Video_USB :
if ( verbose ) printf ( " - USB \n " ) ;
DebugPrintOut ( " - USB \n " ) ;
break ;
case PhysConn_Video_1394 :
if ( verbose ) printf ( " - Firewire \n " ) ;
DebugPrintOut ( " - Firewire \n " ) ;
break ;
}
@ -3084,7 +3113,7 @@ HRESULT videoInput::routeCrossbar(ICaptureGraphBuilder2 **ppBuild, IBaseFilter *
}
Crossbar - > Route ( pOIndex , pIndex ) ;
} else {
if ( verbose ) printf ( " SETUP: Didn't find specified Physical Connection type. Using Defualt. \n " ) ;
DebugPrintOut ( " SETUP: Didn't find specified Physical Connection type. Using Defualt. \n " ) ;
}
//we only free the crossbar when we close or restart the device
@ -3096,20 +3125,13 @@ HRESULT videoInput::routeCrossbar(ICaptureGraphBuilder2 **ppBuild, IBaseFilter *
if ( pXBar1 ) pXBar1 = NULL ;
} else {
if ( verbose ) printf ( " SETUP: You are a webcam or snazzy firewire cam! No Crossbar needed \n " ) ;
DebugPrintOut ( " SETUP: You are a webcam or snazzy firewire cam! No Crossbar needed \n " ) ;
return hr ;
}
return hr ;
}
struct SuppressVideoInputMessages
{
SuppressVideoInputMessages ( ) { videoInput : : setVerbose ( false ) ; }
} ;
static SuppressVideoInputMessages do_it ;
namespace cv
{
videoInput VideoCapture_DShow : : g_VI ;