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

May 16, 2007, 09: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?

DShowLib::Grabber m_pGrabber;
tFrameHandlerSinkPtr pSink;

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

//perform a lot of capture operation and success

//now want to resize to buffer of size 100
FrameTypeInfo info;

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???

Sascha Schmidt
May 16, 2007, 13:23:23

please use "setMemBufferCollection" in the following way.


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

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

m_cGrabber.prepareLive( true );

FrameTypeInfo 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();


Alternatively you also can create a new Sink...

May 16, 2007, 15: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??


Stefan Geissler
May 16, 2007, 15: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.

May 16, 2007, 16: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


Stefan Geissler
May 16, 2007, 16: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.