Merge pull request #3325 from a-wi:Dshow_capture_v3
This commit is contained in:
commit
b4c3f465fb
@ -212,7 +212,7 @@ DEFINE_GUID(MEDIASUBTYPE_RGB24,0xe436eb7d,0x524f,0x11ce,0x9f,0x53,0x00,0x20,0xaf
|
|||||||
DEFINE_GUID(MEDIASUBTYPE_RGB32,0xe436eb7e,0x524f,0x11ce,0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70);
|
DEFINE_GUID(MEDIASUBTYPE_RGB32,0xe436eb7e,0x524f,0x11ce,0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70);
|
||||||
DEFINE_GUID(MEDIASUBTYPE_RGB555,0xe436eb7c,0x524f,0x11ce,0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70);
|
DEFINE_GUID(MEDIASUBTYPE_RGB555,0xe436eb7c,0x524f,0x11ce,0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70);
|
||||||
DEFINE_GUID(MEDIASUBTYPE_RGB565,0xe436eb7b,0x524f,0x11ce,0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70);
|
DEFINE_GUID(MEDIASUBTYPE_RGB565,0xe436eb7b,0x524f,0x11ce,0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70);
|
||||||
DEFINE_GUID(MEDIASUBTYPE_I420,0x49343230,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
|
DEFINE_GUID(MEDIASUBTYPE_I420,0x30323449,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
|
||||||
DEFINE_GUID(MEDIASUBTYPE_UYVY,0x59565955,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
|
DEFINE_GUID(MEDIASUBTYPE_UYVY,0x59565955,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
|
||||||
DEFINE_GUID(MEDIASUBTYPE_Y211,0x31313259,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
|
DEFINE_GUID(MEDIASUBTYPE_Y211,0x31313259,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
|
||||||
DEFINE_GUID(MEDIASUBTYPE_Y411,0x31313459,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
|
DEFINE_GUID(MEDIASUBTYPE_Y411,0x31313459,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
|
||||||
@ -336,8 +336,33 @@ interface ISampleGrabber : public IUnknown
|
|||||||
|
|
||||||
//STUFF YOU CAN CHANGE
|
//STUFF YOU CAN CHANGE
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
|
||||||
//change for verbose debug info
|
//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
|
//if you need VI to use multi threaded com
|
||||||
//#define VI_COM_MULTI_THREADED
|
//#define VI_COM_MULTI_THREADED
|
||||||
@ -697,7 +722,7 @@ public:
|
|||||||
LeaveCriticalSection(&critSection);
|
LeaveCriticalSection(&critSection);
|
||||||
SetEvent(hEvent);
|
SetEvent(hEvent);
|
||||||
}else{
|
}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){
|
void videoDevice::setSize(int w, int h){
|
||||||
if(sizeSet){
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -863,7 +888,7 @@ void videoDevice::destroyGraph(){
|
|||||||
// We must get the enumerator again every time because removing a filter from the graph
|
// 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.
|
// invalidates the enumerator. We always get only the first filter from each enumerator.
|
||||||
hr = pGraph->EnumFilters(&pEnum);
|
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;
|
IBaseFilter * pFilter = NULL;
|
||||||
if (pEnum->Next(1, &pFilter, &cFetched) == S_OK)
|
if (pEnum->Next(1, &pFilter, &cFetched) == S_OK)
|
||||||
@ -883,10 +908,10 @@ void videoDevice::destroyGraph(){
|
|||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(verbose)printf("SETUP: removing filter %s...\n", buffer);
|
DebugPrintOut("SETUP: removing filter %s...\n", buffer);
|
||||||
hr = pGraph->RemoveFilter(pFilter);
|
hr = pGraph->RemoveFilter(pFilter);
|
||||||
if (FAILED(hr)) { if(verbose)printf("SETUP: pGraph->RemoveFilter() failed. \n"); return; }
|
if (FAILED(hr)) { DebugPrintOut("SETUP: pGraph->RemoveFilter() failed.\n"); return; }
|
||||||
if(verbose)printf("SETUP: filter removed %s \n",buffer);
|
DebugPrintOut("SETUP: filter removed %s\n",buffer);
|
||||||
|
|
||||||
pFilter->Release();
|
pFilter->Release();
|
||||||
pFilter = NULL;
|
pFilter = NULL;
|
||||||
@ -909,7 +934,7 @@ void videoDevice::destroyGraph(){
|
|||||||
|
|
||||||
videoDevice::~videoDevice(){
|
videoDevice::~videoDevice(){
|
||||||
|
|
||||||
if(setupStarted){ if(verbose)printf("\nSETUP: Disconnecting device %i\n", myID); }
|
if(setupStarted){ DebugPrintOut("\nSETUP: Disconnecting device %i\n", myID); }
|
||||||
else{
|
else{
|
||||||
if(sgCallback){
|
if(sgCallback){
|
||||||
sgCallback->Release();
|
sgCallback->Release();
|
||||||
@ -924,7 +949,7 @@ videoDevice::~videoDevice(){
|
|||||||
if( (sgCallback) && (pGrabber) )
|
if( (sgCallback) && (pGrabber) )
|
||||||
{
|
{
|
||||||
pGrabber->SetCallback(NULL, 1);
|
pGrabber->SetCallback(NULL, 1);
|
||||||
if(verbose)printf("SETUP: freeing Grabber Callback\n");
|
DebugPrintOut("SETUP: freeing Grabber Callback\n");
|
||||||
sgCallback->Release();
|
sgCallback->Release();
|
||||||
|
|
||||||
//delete our pixels
|
//delete our pixels
|
||||||
@ -940,51 +965,51 @@ videoDevice::~videoDevice(){
|
|||||||
if( (pControl) )
|
if( (pControl) )
|
||||||
{
|
{
|
||||||
HR = pControl->Pause();
|
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();
|
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
|
//Disconnect filters from capture device
|
||||||
if( (pVideoInputFilter) )NukeDownstream(pVideoInputFilter);
|
if( (pVideoInputFilter) )NukeDownstream(pVideoInputFilter);
|
||||||
|
|
||||||
//Release and zero pointers to our filters etc
|
//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)->Release();
|
||||||
(pDestFilter) = 0;
|
(pDestFilter) = 0;
|
||||||
}
|
}
|
||||||
if( (pVideoInputFilter) ){ if(verbose)printf("SETUP: freeing Capture Source \n");
|
if( (pVideoInputFilter) ){ DebugPrintOut("SETUP: freeing Capture Source\n");
|
||||||
(pVideoInputFilter)->Release();
|
(pVideoInputFilter)->Release();
|
||||||
(pVideoInputFilter) = 0;
|
(pVideoInputFilter) = 0;
|
||||||
}
|
}
|
||||||
if( (pGrabberF) ){ if(verbose)printf("SETUP: freeing Grabber Filter \n");
|
if( (pGrabberF) ){ DebugPrintOut("SETUP: freeing Grabber Filter\n");
|
||||||
(pGrabberF)->Release();
|
(pGrabberF)->Release();
|
||||||
(pGrabberF) = 0;
|
(pGrabberF) = 0;
|
||||||
}
|
}
|
||||||
if( (pGrabber) ){ if(verbose)printf("SETUP: freeing Grabber \n");
|
if( (pGrabber) ){ DebugPrintOut("SETUP: freeing Grabber\n");
|
||||||
(pGrabber)->Release();
|
(pGrabber)->Release();
|
||||||
(pGrabber) = 0;
|
(pGrabber) = 0;
|
||||||
}
|
}
|
||||||
if( (pControl) ){ if(verbose)printf("SETUP: freeing Control \n");
|
if( (pControl) ){ DebugPrintOut("SETUP: freeing Control\n");
|
||||||
(pControl)->Release();
|
(pControl)->Release();
|
||||||
(pControl) = 0;
|
(pControl) = 0;
|
||||||
}
|
}
|
||||||
if( (pMediaEvent) ){ if(verbose)printf("SETUP: freeing Media Event \n");
|
if( (pMediaEvent) ){ DebugPrintOut("SETUP: freeing Media Event\n");
|
||||||
(pMediaEvent)->Release();
|
(pMediaEvent)->Release();
|
||||||
(pMediaEvent) = 0;
|
(pMediaEvent) = 0;
|
||||||
}
|
}
|
||||||
if( (streamConf) ){ if(verbose)printf("SETUP: freeing Stream \n");
|
if( (streamConf) ){ DebugPrintOut("SETUP: freeing Stream\n");
|
||||||
(streamConf)->Release();
|
(streamConf)->Release();
|
||||||
(streamConf) = 0;
|
(streamConf) = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (pAmMediaType) ){ if(verbose)printf("SETUP: freeing Media Type \n");
|
if( (pAmMediaType) ){ DebugPrintOut("SETUP: freeing Media Type\n");
|
||||||
MyDeleteMediaType(pAmMediaType);
|
MyDeleteMediaType(pAmMediaType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((pMediaEvent)){
|
if((pMediaEvent)){
|
||||||
if(verbose)printf("SETUP: freeing Media Event \n");
|
DebugPrintOut("SETUP: freeing Media Event\n");
|
||||||
(pMediaEvent)->Release();
|
(pMediaEvent)->Release();
|
||||||
(pMediaEvent) = 0;
|
(pMediaEvent) = 0;
|
||||||
}
|
}
|
||||||
@ -993,11 +1018,11 @@ videoDevice::~videoDevice(){
|
|||||||
if( (pGraph) )destroyGraph();
|
if( (pGraph) )destroyGraph();
|
||||||
|
|
||||||
//Release and zero our capture graph and our main graph
|
//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)->Release();
|
||||||
(pCaptureGraph) = 0;
|
(pCaptureGraph) = 0;
|
||||||
}
|
}
|
||||||
if( (pGraph) ){ if(verbose)printf("SETUP: freeing Main Graph \n");
|
if( (pGraph) ){ DebugPrintOut("SETUP: freeing Main Graph\n");
|
||||||
(pGraph)->Release();
|
(pGraph)->Release();
|
||||||
(pGraph) = 0;
|
(pGraph) = 0;
|
||||||
}
|
}
|
||||||
@ -1013,7 +1038,7 @@ videoDevice::~videoDevice(){
|
|||||||
delete pCaptureGraph;
|
delete pCaptureGraph;
|
||||||
delete pGraph;
|
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
|
//setup a max no of device objects
|
||||||
for(int i=0; i<VI_MAX_CAMERAS; i++) VDList[i] = new videoDevice();
|
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
|
//added for the pixelink firewire camera
|
||||||
//MEDIASUBTYPE_Y800 = (GUID)FOURCCMap(FCC('Y800'));
|
//MEDIASUBTYPE_Y800 = (GUID)FOURCCMap(FCC('Y800'));
|
||||||
@ -1101,7 +1126,11 @@ videoInput::videoInput(){
|
|||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
void videoInput::setVerbose(bool _verbose){
|
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;
|
bCallback = useCallback;
|
||||||
callbackSetCount = 1;
|
callbackSetCount = 1;
|
||||||
}else{
|
}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(VDList[deviceNumber]->pVideoInputFilter)VDList[deviceNumber]->pVideoInputFilter = NULL;
|
||||||
|
|
||||||
if(FAILED(hr)){
|
if(FAILED(hr)){
|
||||||
printf("SETUP: couldn't set requested format\n");
|
DebugPrintOut("SETUP: couldn't set requested format\n");
|
||||||
}else{
|
}else{
|
||||||
long lValue = 0;
|
long lValue = 0;
|
||||||
hr = pVideoDec->get_AvailableTVFormats(&lValue);
|
hr = pVideoDec->get_AvailableTVFormats(&lValue);
|
||||||
@ -1264,7 +1293,7 @@ bool videoInput::setFormat(int deviceNumber, int format){
|
|||||||
{
|
{
|
||||||
hr = pVideoDec->put_TVFormat(VDList[deviceNumber]->formatType);
|
hr = pVideoDec->put_TVFormat(VDList[deviceNumber]->formatType);
|
||||||
if( FAILED(hr) ){
|
if( FAILED(hr) ){
|
||||||
printf("SETUP: couldn't set requested format\n");
|
DebugPrintOut("SETUP: couldn't set requested format\n");
|
||||||
}else{
|
}else{
|
||||||
returnVal = true;
|
returnVal = true;
|
||||||
}
|
}
|
||||||
@ -1304,7 +1333,7 @@ int videoInput::listDevices(bool silent){
|
|||||||
//COM Library Intialization
|
//COM Library Intialization
|
||||||
comInit();
|
comInit();
|
||||||
|
|
||||||
if(!silent)printf("\nVIDEOINPUT SPY MODE!\n\n");
|
if(!silent) DebugPrintOut("\nVIDEOINPUT SPY MODE!\n\n");
|
||||||
|
|
||||||
|
|
||||||
ICreateDevEnum *pDevEnum = NULL;
|
ICreateDevEnum *pDevEnum = NULL;
|
||||||
@ -1325,7 +1354,7 @@ int videoInput::listDevices(bool silent){
|
|||||||
|
|
||||||
if(hr == S_OK){
|
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;
|
IMoniker *pMoniker = NULL;
|
||||||
|
|
||||||
while (pEnum->Next(1, &pMoniker, NULL) == S_OK){
|
while (pEnum->Next(1, &pMoniker, NULL) == S_OK){
|
||||||
@ -1359,7 +1388,7 @@ int videoInput::listDevices(bool silent){
|
|||||||
}
|
}
|
||||||
deviceNames[deviceCounter][count] = 0;
|
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();
|
pPropBag->Release();
|
||||||
@ -1378,7 +1407,7 @@ int videoInput::listDevices(bool silent){
|
|||||||
pEnum = NULL;
|
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();
|
comUnInit();
|
||||||
@ -1516,10 +1545,10 @@ bool videoInput::getPixels(int id, unsigned char * dstBuffer, bool flipRedAndBlu
|
|||||||
processPixels(src, dst, width, height, flipRedAndBlue, flipImage);
|
processPixels(src, dst, width, height, flipRedAndBlue, flipImage);
|
||||||
success = true;
|
success = true;
|
||||||
}else{
|
}else{
|
||||||
if(verbose)printf("ERROR: GetPixels() - bufferSizes do not match!\n");
|
DebugPrintOut("ERROR: GetPixels() - bufferSizes do not match!\n");
|
||||||
}
|
}
|
||||||
}else{
|
}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++;
|
VDList[id]->nFramesRunning++;
|
||||||
|
|
||||||
if(freeze && VDList[id]->autoReconnect){
|
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( !restartDevice(VDList[id]->myID) ){
|
||||||
if(verbose)printf("ERROR: Unable to reconnect to device\n");
|
DebugPrintOut("ERROR: Unable to reconnect to device\n");
|
||||||
}else{
|
}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);
|
hr = getDevice(&VD->pVideoInputFilter, deviceID, VD->wDeviceName, VD->nDeviceName);
|
||||||
if (FAILED(hr)){
|
if (FAILED(hr)){
|
||||||
printf("setVideoSetting - getDevice Error\n");
|
DebugPrintOut("setVideoSetting - getDevice Error\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1654,7 +1683,7 @@ bool videoInput::getVideoSettingFilter(int deviceID, long Property, long &min, l
|
|||||||
|
|
||||||
hr = VD->pVideoInputFilter->QueryInterface(IID_IAMVideoProcAmp, (void**)&pAMVideoProcAmp);
|
hr = VD->pVideoInputFilter->QueryInterface(IID_IAMVideoProcAmp, (void**)&pAMVideoProcAmp);
|
||||||
if(FAILED(hr)){
|
if(FAILED(hr)){
|
||||||
printf("setVideoSetting - QueryInterface Error\n");
|
DebugPrintOut("setVideoSetting - QueryInterface Error\n");
|
||||||
if(VD->pVideoInputFilter)VD->pVideoInputFilter->Release();
|
if(VD->pVideoInputFilter)VD->pVideoInputFilter->Release();
|
||||||
if(VD->pVideoInputFilter)VD->pVideoInputFilter = NULL;
|
if(VD->pVideoInputFilter)VD->pVideoInputFilter = NULL;
|
||||||
return false;
|
return false;
|
||||||
@ -1663,10 +1692,10 @@ bool videoInput::getVideoSettingFilter(int deviceID, long Property, long &min, l
|
|||||||
char propStr[16];
|
char propStr[16];
|
||||||
getVideoPropertyAsString(Property,propStr);
|
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);
|
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, ¤tValue, &flags);
|
pAMVideoProcAmp->Get(Property, ¤tValue, &flags);
|
||||||
|
|
||||||
if(pAMVideoProcAmp)pAMVideoProcAmp->Release();
|
if(pAMVideoProcAmp)pAMVideoProcAmp->Release();
|
||||||
@ -1707,7 +1736,7 @@ bool videoInput::setVideoSettingFilterPct(int deviceID, long Property, float pct
|
|||||||
float halfStep = (float)stepAmnt * 0.5f;
|
float halfStep = (float)stepAmnt * 0.5f;
|
||||||
if( mod < halfStep ) rasterValue -= mod;
|
if( mod < halfStep ) rasterValue -= mod;
|
||||||
else rasterValue += stepAmnt - 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);
|
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);
|
hr = getDevice(&VD->pVideoInputFilter, deviceID, VD->wDeviceName, VD->nDeviceName);
|
||||||
if (FAILED(hr)){
|
if (FAILED(hr)){
|
||||||
printf("setVideoSetting - getDevice Error\n");
|
DebugPrintOut("setVideoSetting - getDevice Error\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1736,21 +1765,21 @@ bool videoInput::setVideoSettingFilter(int deviceID, long Property, long lValue,
|
|||||||
|
|
||||||
hr = VD->pVideoInputFilter->QueryInterface(IID_IAMVideoProcAmp, (void**)&pAMVideoProcAmp);
|
hr = VD->pVideoInputFilter->QueryInterface(IID_IAMVideoProcAmp, (void**)&pAMVideoProcAmp);
|
||||||
if(FAILED(hr)){
|
if(FAILED(hr)){
|
||||||
printf("setVideoSetting - QueryInterface Error\n");
|
DebugPrintOut("setVideoSetting - QueryInterface Error\n");
|
||||||
if(VD->pVideoInputFilter)VD->pVideoInputFilter->Release();
|
if(VD->pVideoInputFilter)VD->pVideoInputFilter->Release();
|
||||||
if(VD->pVideoInputFilter)VD->pVideoInputFilter = NULL;
|
if(VD->pVideoInputFilter)VD->pVideoInputFilter = NULL;
|
||||||
return false;
|
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;
|
long CurrVal, Min, Max, SteppingDelta, Default, CapsFlags, AvailableCapsFlags = 0;
|
||||||
|
|
||||||
|
|
||||||
pAMVideoProcAmp->GetRange(Property, &Min, &Max, &SteppingDelta, &Default, &AvailableCapsFlags);
|
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);
|
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) {
|
if (useDefaultValue) {
|
||||||
pAMVideoProcAmp->Set(Property, Default, VideoProcAmp_Flags_Auto);
|
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;
|
float halfStep = (float)stepAmnt * 0.5f;
|
||||||
if( mod < halfStep ) rasterValue -= mod;
|
if( mod < halfStep ) rasterValue -= mod;
|
||||||
else rasterValue += stepAmnt - 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);
|
return setVideoSettingCamera(deviceID, Property, rasterValue, Flags, false);
|
||||||
@ -1814,19 +1843,19 @@ bool videoInput::setVideoSettingCamera(int deviceID, long Property, long lValue,
|
|||||||
char propStr[16];
|
char propStr[16];
|
||||||
getCameraPropertyAsString(Property,propStr);
|
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);
|
hr = VDList[deviceID]->pVideoInputFilter->QueryInterface(IID_IAMCameraControl, (void**)&pIAMCameraControl);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
printf("Error\n");
|
DebugPrintOut("Error\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
long CurrVal, Min, Max, SteppingDelta, Default, CapsFlags, AvailableCapsFlags;
|
long CurrVal, Min, Max, SteppingDelta, Default, CapsFlags, AvailableCapsFlags;
|
||||||
pIAMCameraControl->GetRange(Property, &Min, &Max, &SteppingDelta, &Default, &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);
|
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) {
|
if (useDefaultValue) {
|
||||||
pIAMCameraControl->Set(Property, Default, CameraControl_Flags_Auto);
|
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);
|
hr = getDevice(&VD->pVideoInputFilter, deviceID, VD->wDeviceName, VD->nDeviceName);
|
||||||
if (FAILED(hr)){
|
if (FAILED(hr)){
|
||||||
printf("setVideoSetting - getDevice Error\n");
|
DebugPrintOut("setVideoSetting - getDevice Error\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1862,7 +1891,7 @@ bool videoInput::getVideoSettingCamera(int deviceID, long Property, long &min, l
|
|||||||
|
|
||||||
hr = VD->pVideoInputFilter->QueryInterface(IID_IAMCameraControl, (void**)&pIAMCameraControl);
|
hr = VD->pVideoInputFilter->QueryInterface(IID_IAMCameraControl, (void**)&pIAMCameraControl);
|
||||||
if(FAILED(hr)){
|
if(FAILED(hr)){
|
||||||
printf("setVideoSetting - QueryInterface Error\n");
|
DebugPrintOut("setVideoSetting - QueryInterface Error\n");
|
||||||
if(VD->pVideoInputFilter)VD->pVideoInputFilter->Release();
|
if(VD->pVideoInputFilter)VD->pVideoInputFilter->Release();
|
||||||
if(VD->pVideoInputFilter)VD->pVideoInputFilter = NULL;
|
if(VD->pVideoInputFilter)VD->pVideoInputFilter = NULL;
|
||||||
return false;
|
return false;
|
||||||
@ -1870,10 +1899,10 @@ bool videoInput::getVideoSettingCamera(int deviceID, long Property, long &min, l
|
|||||||
|
|
||||||
char propStr[16];
|
char propStr[16];
|
||||||
getCameraPropertyAsString(Property,propStr);
|
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);
|
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, ¤tValue, &flags);
|
pIAMCameraControl->Get(Property, ¤tValue, &flags);
|
||||||
|
|
||||||
if(pIAMCameraControl)pIAMCameraControl->Release();
|
if(pIAMCameraControl)pIAMCameraControl->Release();
|
||||||
@ -1981,7 +2010,7 @@ bool videoInput::comInit(){
|
|||||||
//if another library has started com as single threaded
|
//if another library has started com as single threaded
|
||||||
//and we need it multi-threaded - send warning but don't fail
|
//and we need it multi-threaded - send warning but don't fail
|
||||||
if( hr == RPC_E_CHANGED_MODE){
|
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(deviceNumber>devicesFound-1)
|
||||||
{
|
{
|
||||||
if(verbose)printf("SETUP: device[%i] not found - you have %i devices available\n", deviceNumber, devicesFound);
|
DebugPrintOut("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);
|
if(devicesFound>=0) DebugPrintOut("SETUP: this means that the last device you can use is device[%i]\n", devicesFound-1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(VDList[deviceNumber]->readyToCapture)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2329,8 +2358,8 @@ static void findClosestSizeAndSubtype(videoDevice * VD, int widthIn, int heightI
|
|||||||
//Don't want to get stuck in a loop
|
//Don't want to get stuck in a loop
|
||||||
if(stepX < 1 || stepY < 1) continue;
|
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);
|
//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);
|
||||||
//if(verbose)printf("min frame duration is %i max duration is %i\n", scc.MinFrameInterval, scc.MaxFrameInterval);
|
//DebugPrintOut("min frame duration is %i max duration is %i\n", scc.MinFrameInterval, scc.MaxFrameInterval);
|
||||||
|
|
||||||
bool exactMatch = false;
|
bool exactMatch = false;
|
||||||
bool exactMatchX = false;
|
bool exactMatchX = false;
|
||||||
@ -2416,7 +2445,15 @@ static bool setSizeAndSubtype(videoDevice * VD, int attemptWidth, int attemptHei
|
|||||||
VD->pAmMediaType->subtype = mediatype;
|
VD->pAmMediaType->subtype = mediatype;
|
||||||
|
|
||||||
//buffer size
|
//buffer size
|
||||||
VD->pAmMediaType->lSampleSize = attemptWidth*attemptHeight*3;
|
if (mediatype == MEDIASUBTYPE_RGB24)
|
||||||
|
{
|
||||||
|
VD->pAmMediaType->lSampleSize = attemptWidth*attemptHeight*3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// For compressed data, the value can be zero.
|
||||||
|
VD->pAmMediaType->lSampleSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
//set fps if requested
|
//set fps if requested
|
||||||
if( VD->requestedFrameTime != -1){
|
if( VD->requestedFrameTime != -1){
|
||||||
@ -2449,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)
|
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
|
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 GRAPH BUILDER //
|
||||||
// Create the filter graph manager and query for interfaces.
|
// Create the filter graph manager and query for interfaces.
|
||||||
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void **)&VD->pCaptureGraph);
|
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 (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;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2465,7 +2502,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
|
|||||||
hr = CoCreateInstance(CLSID_FilterGraph, 0, CLSCTX_INPROC_SERVER,IID_IGraphBuilder, (void**)&VD->pGraph);
|
hr = CoCreateInstance(CLSID_FilterGraph, 0, CLSCTX_INPROC_SERVER,IID_IGraphBuilder, (void**)&VD->pGraph);
|
||||||
if (FAILED(hr))
|
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);
|
stopDevice(deviceID);
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
@ -2474,7 +2511,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
|
|||||||
hr = VD->pCaptureGraph->SetFiltergraph(VD->pGraph);
|
hr = VD->pCaptureGraph->SetFiltergraph(VD->pGraph);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
if(verbose)printf("ERROR - Could not set filtergraph\n");
|
DebugPrintOut("ERROR - Could not set filtergraph\n");
|
||||||
stopDevice(deviceID);
|
stopDevice(deviceID);
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
@ -2485,8 +2522,8 @@ int videoInput::start(int deviceID, videoDevice *VD){
|
|||||||
hr = VD->pGraph->QueryInterface(IID_IMediaControl, (void **)&VD->pControl);
|
hr = VD->pGraph->QueryInterface(IID_IMediaControl, (void **)&VD->pControl);
|
||||||
if (FAILED(hr))
|
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);
|
stopDevice(deviceID);
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2496,10 +2533,10 @@ int videoInput::start(int deviceID, videoDevice *VD){
|
|||||||
hr = getDevice(&VD->pVideoInputFilter, deviceID, VD->wDeviceName, VD->nDeviceName);
|
hr = getDevice(&VD->pVideoInputFilter, deviceID, VD->wDeviceName, VD->nDeviceName);
|
||||||
|
|
||||||
if (SUCCEEDED(hr)){
|
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);
|
hr = VD->pGraph->AddFilter(VD->pVideoInputFilter, VD->wDeviceName);
|
||||||
}else{
|
}else{
|
||||||
if(verbose)printf("ERROR - Could not find specified video device\n");
|
DebugPrintOut("ERROR - Could not find specified video device\n");
|
||||||
stopDevice(deviceID);
|
stopDevice(deviceID);
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
@ -2508,7 +2545,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
|
|||||||
IAMStreamConfig *streamConfTest = NULL;
|
IAMStreamConfig *streamConfTest = NULL;
|
||||||
hr = VD->pCaptureGraph->FindInterface(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, VD->pVideoInputFilter, IID_IAMStreamConfig, (void **)&streamConfTest);
|
hr = VD->pCaptureGraph->FindInterface(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, VD->pVideoInputFilter, IID_IAMStreamConfig, (void **)&streamConfTest);
|
||||||
if(FAILED(hr)){
|
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{
|
}else{
|
||||||
CAPTURE_MODE = PIN_CATEGORY_PREVIEW;
|
CAPTURE_MODE = PIN_CATEGORY_PREVIEW;
|
||||||
streamConfTest->Release();
|
streamConfTest->Release();
|
||||||
@ -2520,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
|
//webcams tend not to have a crossbar so this function will also detect a webcams and not apply the crossbar
|
||||||
if(VD->useCrossbar)
|
if(VD->useCrossbar)
|
||||||
{
|
{
|
||||||
if(verbose)printf("SETUP: Checking crossbar\n");
|
DebugPrintOut("SETUP: Checking crossbar\n");
|
||||||
routeCrossbar(&VD->pCaptureGraph, &VD->pVideoInputFilter, VD->connection, CAPTURE_MODE);
|
routeCrossbar(&VD->pCaptureGraph, &VD->pVideoInputFilter, VD->connection, CAPTURE_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2528,7 +2565,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
|
|||||||
//we do this because webcams don't have a preview mode
|
//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);
|
hr = VD->pCaptureGraph->FindInterface(&CAPTURE_MODE, &MEDIATYPE_Video, VD->pVideoInputFilter, IID_IAMStreamConfig, (void **)&VD->streamConf);
|
||||||
if(FAILED(hr)){
|
if(FAILED(hr)){
|
||||||
if(verbose)printf("ERROR: Couldn't config the stream!\n");
|
DebugPrintOut("ERROR: Couldn't config the stream!\n");
|
||||||
stopDevice(deviceID);
|
stopDevice(deviceID);
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
@ -2536,7 +2573,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
|
|||||||
//NOW LETS DEAL WITH GETTING THE RIGHT SIZE
|
//NOW LETS DEAL WITH GETTING THE RIGHT SIZE
|
||||||
hr = VD->streamConf->GetFormat(&VD->pAmMediaType);
|
hr = VD->streamConf->GetFormat(&VD->pAmMediaType);
|
||||||
if(FAILED(hr)){
|
if(FAILED(hr)){
|
||||||
if(verbose)printf("ERROR: Couldn't getFormat for pAmMediaType!\n");
|
DebugPrintOut("ERROR: Couldn't getFormat for pAmMediaType!\n");
|
||||||
stopDevice(deviceID);
|
stopDevice(deviceID);
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
@ -2550,15 +2587,16 @@ int videoInput::start(int deviceID, videoDevice *VD){
|
|||||||
bool foundSize = false;
|
bool foundSize = false;
|
||||||
|
|
||||||
if(customSize){
|
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];
|
char guidStr[8];
|
||||||
// try specified format and size
|
// try specified format and size
|
||||||
getMediaSubtypeAsString(VD->tryVideoType, guidStr);
|
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) ){
|
if( setSizeAndSubtype(VD, VD->tryWidth, VD->tryHeight, VD->tryVideoType) ){
|
||||||
VD->setSize(VD->tryWidth, VD->tryHeight);
|
VD->setSize(VD->tryWidth, VD->tryHeight);
|
||||||
|
VD->videoType = VD->tryVideoType;
|
||||||
foundSize = true;
|
foundSize = true;
|
||||||
} else {
|
} else {
|
||||||
// try specified size with all formats
|
// try specified size with all formats
|
||||||
@ -2566,9 +2604,10 @@ int videoInput::start(int deviceID, videoDevice *VD){
|
|||||||
|
|
||||||
getMediaSubtypeAsString(mediaSubtypes[i], guidStr);
|
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]) ){
|
if( setSizeAndSubtype(VD, VD->tryWidth, VD->tryHeight, mediaSubtypes[i]) ){
|
||||||
VD->setSize(VD->tryWidth, VD->tryHeight);
|
VD->setSize(VD->tryWidth, VD->tryHeight);
|
||||||
|
VD->videoType = mediaSubtypes[i];
|
||||||
foundSize = true;
|
foundSize = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -2578,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 we didn't find the requested size - lets try and find the closest matching size
|
||||||
if( foundSize == false ){
|
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 closestWidth = -1;
|
||||||
int closestHeight = -1;
|
int closestHeight = -1;
|
||||||
@ -2589,7 +2628,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
|
|||||||
if( closestWidth != -1 && closestHeight != -1){
|
if( closestWidth != -1 && closestHeight != -1){
|
||||||
getMediaSubtypeAsString(newMediaSubtype, guidStr);
|
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) ){
|
if( setSizeAndSubtype(VD, closestWidth, closestHeight, newMediaSubtype) ){
|
||||||
VD->setSize(closestWidth, closestHeight);
|
VD->setSize(closestWidth, closestHeight);
|
||||||
foundSize = true;
|
foundSize = true;
|
||||||
@ -2611,21 +2650,21 @@ int videoInput::start(int deviceID, videoDevice *VD){
|
|||||||
// Create the Sample Grabber.
|
// Create the Sample Grabber.
|
||||||
hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER,IID_IBaseFilter, (void**)&VD->pGrabberF);
|
hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER,IID_IBaseFilter, (void**)&VD->pGrabberF);
|
||||||
if (FAILED(hr)){
|
if (FAILED(hr)){
|
||||||
if(verbose)printf("Could not Create Sample Grabber - CoCreateInstance()\n");
|
DebugPrintOut("Could not Create Sample Grabber - CoCreateInstance()\n");
|
||||||
stopDevice(deviceID);
|
stopDevice(deviceID);
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = VD->pGraph->AddFilter(VD->pGrabberF, L"Sample Grabber");
|
hr = VD->pGraph->AddFilter(VD->pGrabberF, L"Sample Grabber");
|
||||||
if (FAILED(hr)){
|
if (FAILED(hr)){
|
||||||
if(verbose)printf("Could not add Sample Grabber - AddFilter()\n");
|
DebugPrintOut("Could not add Sample Grabber - AddFilter()\n");
|
||||||
stopDevice(deviceID);
|
stopDevice(deviceID);
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = VD->pGrabberF->QueryInterface(IID_ISampleGrabber, (void**)&VD->pGrabber);
|
hr = VD->pGrabberF->QueryInterface(IID_ISampleGrabber, (void**)&VD->pGrabber);
|
||||||
if (FAILED(hr)){
|
if (FAILED(hr)){
|
||||||
if(verbose)printf("ERROR: Could not query SampleGrabber\n");
|
DebugPrintOut("ERROR: Could not query SampleGrabber\n");
|
||||||
stopDevice(deviceID);
|
stopDevice(deviceID);
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
@ -2644,11 +2683,11 @@ int videoInput::start(int deviceID, videoDevice *VD){
|
|||||||
//We use SampleCB
|
//We use SampleCB
|
||||||
hr = VD->pGrabber->SetCallback(VD->sgCallback, 0);
|
hr = VD->pGrabber->SetCallback(VD->sgCallback, 0);
|
||||||
if (FAILED(hr)){
|
if (FAILED(hr)){
|
||||||
if(verbose)printf("ERROR: problem setting callback\n");
|
DebugPrintOut("ERROR: problem setting callback\n");
|
||||||
stopDevice(deviceID);
|
stopDevice(deviceID);
|
||||||
return hr;
|
return hr;
|
||||||
}else{
|
}else{
|
||||||
if(verbose)printf("SETUP: Capture callback set\n");
|
DebugPrintOut("SETUP: Capture callback set\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2671,7 +2710,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
|
|||||||
VD->streamConf->Release();
|
VD->streamConf->Release();
|
||||||
VD->streamConf = NULL;
|
VD->streamConf = NULL;
|
||||||
}else{
|
}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);
|
stopDevice(deviceID);
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
}
|
}
|
||||||
@ -2681,14 +2720,14 @@ int videoInput::start(int deviceID, videoDevice *VD){
|
|||||||
//used to give the video stream somewhere to go to.
|
//used to give the video stream somewhere to go to.
|
||||||
hr = CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)(&VD->pDestFilter));
|
hr = CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)(&VD->pDestFilter));
|
||||||
if (FAILED(hr)){
|
if (FAILED(hr)){
|
||||||
if(verbose)printf("ERROR: Could not create filter - NullRenderer\n");
|
DebugPrintOut("ERROR: Could not create filter - NullRenderer\n");
|
||||||
stopDevice(deviceID);
|
stopDevice(deviceID);
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = VD->pGraph->AddFilter(VD->pDestFilter, L"NullRenderer");
|
hr = VD->pGraph->AddFilter(VD->pDestFilter, L"NullRenderer");
|
||||||
if (FAILED(hr)){
|
if (FAILED(hr)){
|
||||||
if(verbose)printf("ERROR: Could not add filter - NullRenderer\n");
|
DebugPrintOut("ERROR: Could not add filter - NullRenderer\n");
|
||||||
stopDevice(deviceID);
|
stopDevice(deviceID);
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
@ -2698,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);
|
hr = VD->pCaptureGraph->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, VD->pVideoInputFilter, VD->pGrabberF, VD->pDestFilter);
|
||||||
|
|
||||||
if (FAILED(hr)){
|
if (FAILED(hr)){
|
||||||
if(verbose)printf("ERROR: Could not connect pins - RenderStream()\n");
|
DebugPrintOut("ERROR: Could not connect pins - RenderStream()\n");
|
||||||
stopDevice(deviceID);
|
stopDevice(deviceID);
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
@ -2709,7 +2748,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
|
|||||||
IMediaFilter *pMediaFilter = 0;
|
IMediaFilter *pMediaFilter = 0;
|
||||||
hr = VD->pGraph->QueryInterface(IID_IMediaFilter, (void**)&pMediaFilter);
|
hr = VD->pGraph->QueryInterface(IID_IMediaFilter, (void**)&pMediaFilter);
|
||||||
if (FAILED(hr)){
|
if (FAILED(hr)){
|
||||||
if(verbose)printf("ERROR: Could not get IID_IMediaFilter interface\n");
|
DebugPrintOut("ERROR: Could not get IID_IMediaFilter interface\n");
|
||||||
}else{
|
}else{
|
||||||
pMediaFilter->SetSyncSource(NULL);
|
pMediaFilter->SetSyncSource(NULL);
|
||||||
pMediaFilter->Release();
|
pMediaFilter->Release();
|
||||||
@ -2721,7 +2760,7 @@ int videoInput::start(int deviceID, videoDevice *VD){
|
|||||||
hr = VD->pControl->Run();
|
hr = VD->pControl->Run();
|
||||||
|
|
||||||
if (FAILED(hr)){
|
if (FAILED(hr)){
|
||||||
if(verbose)printf("ERROR: Could not start graph\n");
|
DebugPrintOut("ERROR: Could not start graph\n");
|
||||||
stopDevice(deviceID);
|
stopDevice(deviceID);
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
@ -2739,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;
|
VD->readyToCapture = true;
|
||||||
|
|
||||||
//Release filters - seen someone else do this
|
//Release filters - seen someone else do this
|
||||||
@ -3016,7 +3055,7 @@ HRESULT videoInput::routeCrossbar(ICaptureGraphBuilder2 **ppBuild, IBaseFilter *
|
|||||||
|
|
||||||
bool foundDevice = false;
|
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();
|
pXBar1->Release();
|
||||||
|
|
||||||
IAMCrossbar *Crossbar;
|
IAMCrossbar *Crossbar;
|
||||||
@ -3036,24 +3075,24 @@ HRESULT videoInput::routeCrossbar(ICaptureGraphBuilder2 **ppBuild, IBaseFilter *
|
|||||||
hr = Crossbar->get_CrossbarPinInfo( iPin , pIndex , &pRIndex , &pType);
|
hr = Crossbar->get_CrossbarPinInfo( iPin , pIndex , &pRIndex , &pType);
|
||||||
|
|
||||||
if( pType == conType){
|
if( pType == conType){
|
||||||
if(verbose)printf("SETUP: Found Physical Interface");
|
DebugPrintOut("SETUP: Found Physical Interface");
|
||||||
|
|
||||||
switch(conType){
|
switch(conType){
|
||||||
|
|
||||||
case PhysConn_Video_Composite:
|
case PhysConn_Video_Composite:
|
||||||
if(verbose)printf(" - Composite\n");
|
DebugPrintOut(" - Composite\n");
|
||||||
break;
|
break;
|
||||||
case PhysConn_Video_SVideo:
|
case PhysConn_Video_SVideo:
|
||||||
if(verbose)printf(" - S-Video\n");
|
DebugPrintOut(" - S-Video\n");
|
||||||
break;
|
break;
|
||||||
case PhysConn_Video_Tuner:
|
case PhysConn_Video_Tuner:
|
||||||
if(verbose)printf(" - Tuner\n");
|
DebugPrintOut(" - Tuner\n");
|
||||||
break;
|
break;
|
||||||
case PhysConn_Video_USB:
|
case PhysConn_Video_USB:
|
||||||
if(verbose)printf(" - USB\n");
|
DebugPrintOut(" - USB\n");
|
||||||
break;
|
break;
|
||||||
case PhysConn_Video_1394:
|
case PhysConn_Video_1394:
|
||||||
if(verbose)printf(" - Firewire\n");
|
DebugPrintOut(" - Firewire\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3074,7 +3113,7 @@ HRESULT videoInput::routeCrossbar(ICaptureGraphBuilder2 **ppBuild, IBaseFilter *
|
|||||||
}
|
}
|
||||||
Crossbar->Route(pOIndex,pIndex);
|
Crossbar->Route(pOIndex,pIndex);
|
||||||
}else{
|
}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
|
//we only free the crossbar when we close or restart the device
|
||||||
@ -3086,20 +3125,13 @@ HRESULT videoInput::routeCrossbar(ICaptureGraphBuilder2 **ppBuild, IBaseFilter *
|
|||||||
if(pXBar1)pXBar1 = NULL;
|
if(pXBar1)pXBar1 = NULL;
|
||||||
|
|
||||||
}else{
|
}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;
|
||||||
}
|
}
|
||||||
|
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SuppressVideoInputMessages
|
|
||||||
{
|
|
||||||
SuppressVideoInputMessages() { videoInput::setVerbose(false); }
|
|
||||||
};
|
|
||||||
|
|
||||||
static SuppressVideoInputMessages do_it;
|
|
||||||
|
|
||||||
namespace cv
|
namespace cv
|
||||||
{
|
{
|
||||||
videoInput VideoCapture_DShow::g_VI;
|
videoInput VideoCapture_DShow::g_VI;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user