PDA

View Full Version : Resize internal ring buffer possible???



ray@frontier
May 16, 2007, 10:50:53
Hello, I would like to dynamic resize the internal ring buffer for capturing image and I found a "setMemBufferCollection" function which may fulfill my requirement. I have written following code, but I am afraid I cannot successfully resize the buffer since I get a "false" return value.

Can any one tell me that the correct way of using "setMemBufferCollection" function?


Code:
//header
DShowLib::Grabber m_pGrabber;
tFrameHandlerSinkPtr pSink;

FrameTypeInfoArray acceptedTypes = FrameTypeInfoArray::createStandardTypesArray();
//create buffer of size 5
pSink = FrameHandlerSink::create( acceptedTypes, 5 );
m_pGrabber.setSinkType( pSink );
m_pGrabber.startLive(false);


//perform a lot of capture operation and success


//now want to resize to buffer of size 100
FrameTypeInfo info;
pSink.getOutputFrameType(info);

m_pGrabber.stopLive();
bool aaa = pSink.setMemBufferCollection(0); //this return value is "true", ok!!!
bool bbb = pSink.setMemBufferCollection(MemBufferCollection:: create( info, 100);// this return value is "false", why???
m_pGrabber->startLive(false);

Sascha Schmidt
May 16, 2007, 14:23:23
Hallo,

please use "setMemBufferCollection" in the following way.



m_cGrabber.showDevicePage(this->m_hWnd);

FrameTypeInfoArray acceptedTypes = FrameTypeInfoArray::createStandardTypesArray();
tFrameHandlerSinkPtr pSink = FrameHandlerSink::create( acceptedTypes, 5 );

// Set the sink.
m_cGrabber.setSinkType( pSink );

m_cGrabber.prepareLive( true );

FrameTypeInfo info;
pSink->getOutputFrameType(info);

// Create a new MemBuffer collection that uses our own image buffers.
tMemBufferCollectionPtr pCollection = MemBufferCollection::create( info, 100 );

// Resize MembufferSize
VERIFY( pSink->setMemBufferCollection( pCollection ) );

tMemBufferCollectionPtr pC = pSink->getMemBufferCollection();
int x = pC->getBufferCount();

m_cGrabber.startLive();


Alternatively you also can create a new Sink...

ray@frontier
May 16, 2007, 16:24:59
Thank you for your suggestion, I will try it later.

But my problem is a bit different. My situation is I must call startLive(false) and perform several snapImages() operation with small size of MemBufferCollection and then resize to large set of ring buffer and perform several snapImages() operation. And then repeat switching between small and large buffer.

What can I implement like that??

Ray

Stefan Geissler
May 16, 2007, 16:41:12
Hi Ray,

While the live video stream is running it is not possible to change the size of the ring buffer.

Why do you need to resize the ringbuffer? You can obtain the index of the last filled buffer as follows:


DWORD dwIndex = m_pSink->getLastAcqMemBuffer()->getCollectionPos();

If you know how many images you have snapped, then you can go backwards through the memorybuffer collection. If the dwIndex is less than zero, then you would calculate the index as


DWORD newIndex = pSink->getMemBufferCollection()->getBufferCount() -1 -dwIndex;


This avoids stopping the live video stream and allocating new memory. You would keep your ring buffer size at 100 all the time.

ray@frontier
May 16, 2007, 17:19:21
Sorry for making you get confused.


Actually my process is something like that:

1. Snap 1000 images continuously

2. After snaping all 1000 images, "offline" process those image together to construct a 3D object

3. After processing, I need to reserve memory for display a 3D using OpenGL (that is why I want to resize/ even remove the ring buffer temporary)

4. And then repeatedly do step 1 - 3 for other 3D objects

Ray

Stefan Geissler
May 16, 2007, 17:26:28
Hi Ray,

Ok, well, you can delete the ring buffer by setting it to NULL:



// Create a new MemBuffer collection that uses our own image buffers.
tMemBufferCollectionPtr pCollection = MemBufferCollection::create( info, 100 );
// Delete it.
pCollection = NULL;


This should work.