PDA

View Full Version : snapImage Consistently fails...



Tonster321
July 25, 2003, 00:32:47
I am trying create a dll that that encapsulates the functionality of capturing the return from the firewire and simply return the BYTE buffer. Below is the relevant header and cpp code I use when initializing the class. Below that is where in my "ProcessImage" call the snap

Header Stuff:
*********************************
DShowLib::Grabber* m_pGrabber;
DShowLib::Grabber::tMemBufferCollectionPtr m_pMemBuffColl; DShowLib::Grabber::tMemBufferPtr m_pMemBuff;
CString m_CurrentVideoCaptureDevice;
CSize m_szMemBuffColl;
int size_buffer;
BYTE* pBuff[1];
BOOL bCollSet;

CPP Stuff:
*********************************

SomeClass::SomeClass() : m_pMemBuffColl(0)
{

//Setup Grabber
m_pGrabber = NULL;
m_pGrabber = new DShowLib::Grabber();
ASSERT( m_pGrabber );

if(!m_pGrabber)
{
AfxMessageBox("Grabber not initialized!");
}
else
{

if(!InitGrabberDevice())
{
AfxMessageBox("Unable to initialize Grabber device!");
}
else
{
m_szMemBuffColl.cx = m_pGrabber->getAcqSizeMaxX();//640;
m_szMemBuffColl.cy = m_pGrabber->getAcqSizeMaxY();//480;
size_buffer = m_pGrabber->getAcqSizeMaxX() * m_pGrabber->getAcqSizeMaxY() * 3; //3 byte per pixel.

pBuff[0] = new BYTE[size_buffer];
// Create a new membuffer collection that uses our own image buffers.
m_pMemBuffColl = m_pGrabber->newMemBufferCollection(size_buffer, pBuff, 1 );

if(m_pGrabber->getLastError()){AfxMessageBox(m_pGrabber->getLastError());}

bCollSet = m_pGrabber->setActiveMemBufferCollection(m_pMemBuffColl);
if(m_pGrabber->getLastError()){AfxMessageBox(m_pGrabber->getLastError());}
//Start live feed (false = not visible)
m_pGrabber->startLive(false);
if(m_pGrabber->getLastError()){
AfxMessageBox(m_pGrabber->getLastError());}
}

/*************moving on**************/

BOOL SomeClass::InitGrabberDevice()
{
if( !DShowLib::InitLibrary("xx-xxxxxxxxxx"))
{ return FALSE;}

DShowLib::Grabber::tVidCapDevListPtr pVidCapDevList = m_pGrabber->getAvailableVideoCaptureDevices();

if (m_pGrabber->getLastError()) AfxMessageBox( m_pGrabber->getLastError) ); CString text = "Video to 1394 Converter";
if ( pVidCapDevList != 0 )
//If we can get a list of Video Capture Devices
{DShowLib::Grabber::tVidCapDevListPtr::value_type: :iterator itdev =
std::find( pVidCapDevList->begin(), pVidCapDevList->end(), std::string(text) );
//Find the one we want

if ( !( itdev == pVidCapDevList->end() ) )
//Last item in list
{
m_CurrentVideoCaptureDevice = text; //Set up Video
}
}
// Open the video capture device
if ( m_CurrentVideoCaptureDevice != "" )
{
m_pGrabber->openDev( m_CurrentVideoCaptureDevice );
// Set the video format to RGB24 (640x480)
text = "RGB24 (640x480)";
DShowLib::Grabber::tVidFmtListPtr pVidFmtList = m_pGrabber->getAvailableVideoFormats();
if ( pVidFmtList!=0 )
{
DShowLib::Grabber::tVidFmtListPtr::value_type::ite rator itfmt =
std::find( pVidFmtList->begin(), pVidFmtList->end(), text );
if ( !(itfmt==pVidFmtList->end()) ) m_pGrabber->setVideoFormat( *itfmt );
}
// Set the video norm
text = "NTSC_M";
DShowLib::Grabber::tVidNrmListPtr pVidNrmList = m_pGrabber->getAvailableVideoNorms();
if ( pVidNrmList!=0 )
{
DShowLib::Grabber::tVidNrmListPtr::value_type::ite rator itnrm =
std::find( pVidNrmList->begin(), pVidNrmList->end(), text );
if ( !( itnrm==pVidNrmList->end() ) ) m_pGrabber->setVideoNorm( *itnrm );
}
// Set the input channel
text = "00 Video: Composite";
DShowLib::Grabber::tInChnListPtr pInChnList = m_pGrabber->getAvailableInputChannels();
if ( pInChnList!=0 )
{
DShowLib::Grabber::tInChnListPtr::value_type::iter ator itchn =
std::find( pInChnList->begin(), pInChnList->end(), text );
if ( !( itchn==pInChnList->end() ) ) m_pGrabber->setInputChannel( *itchn );
}
// Set the sinktype to 24 bit.
BOOL sinkSet;
sinkSet = m_pGrabber->setSinkType( DShowLib::FrameGrabberSink(
DShowLib::FrameGrabberSink::eSNAP, DShowLib::eRGB24 ) );
if(!sinkSet)AfxMessageBox("Unable to setSinkType");
}
return TRUE;
}


***ProcessImage*******

if(m_pGrabber->isLive())
{
if(m_pGrabber->getLastError())
{
AfxMessageBox(m_pGrabber->getLastError());
}
}
if(!m_pGrabber->snapImages(1))
{
AfxMessageBox("Not able to snap images, attempting to reset Grabber.");
OptCorrelator::ResetGrabber(); //replicates the init code in SomeClass contructor
if(!m_pGrabber->snapImages(1))
{
AfxMessageBox("Still not able to snap images at this time. Exiting ProcessImage(...) Function.");

if(m_pGrabber->getLastError())
{
AfxMessageBox(m_pGrabber->getLastError());
}
return FALSE;
}
}
else
.
.
.

snapImages(1) consistantly, but in a random fashion, fails. For example. I have a simple dialog app what loads this DLL through an interface I created in the dll. I import the interface header into the app, and create an instance of the Interface. The program simply bitblt's an image through an optical correlator and I see the results in my dialog app. I then try and capture the results and after a random period (can be anywhere from one to several bitblt's) the program consistently bombs on the snapImage function call.

Even using the debug dlls, I can't step into it to see where in the function it's hanging...

Any help is appreciated!

~Tonster321

Johannes Vogel
July 25, 2003, 10:26:26
Hello,

On first sight, we cannot see what causes the problem. Please send this request to support@imagingcontrol.com

Best regards
Johannes
IC Support