PDA

View Full Version : Opening same device on multiple grabbers



Sander
November 22, 2010, 17:55:49
Dear forum,

I have a question/was wondering about the following.
When I create two grabbers, and request the availiable devices like this :
(all error checking is left out)


DShowLib::Grabber grabber_One;
DShowLib::Grabber grabber_Two;
DShowLib::Grabber::tVidCapDevListPtr devList_One = grabber_One.getAvailableVideoCaptureDevices();
DShowLib::Grabber::tVidCapDevListPtr devList_Two = grabber_Two.getAvailableVideoCaptureDevices();


And then open the same device on both grabbers, and close it immediately again:



grabber_One.openDev(devList_One->at(0));
grabber_Two.openDev(devList_Two->at(0));
grabber_One.closeDev();
grabber_Two.closeDev();


The above code works fine. However when replacing the second line with :



grabber_Two.openDev(devList_One->at(0));


Using the devicelist requested from the first grabber, a crash will happen when closing the last device. ("TIS_UDSHL07_VC6D.DLL): 0xC0000005: Access Violation")

Replacing the second line with :



grabber_Two.openDev(devList_One->at(0).getName());


Works fine again.

Any thoughts on what should be expected and why one is working and the other is not?

Stefan Geissler
November 23, 2010, 09:55:02
Hello

On my machine


DShowLib::Grabber grabber_One;
DShowLib::Grabber grabber_Two;
DShowLib::Grabber::tVidCapDevListPtr devList_One = grabber_One.getAvailableVideoCaptureDevices();
DShowLib::Grabber::tVidCapDevListPtr devList_Two = grabber_Two.getAvailableVideoCaptureDevices();


grabber_One.openDev(devList_One->at(0));
grabber_Two.openDev(devList_One->at(0));

works fine.

You should keep mind, that "openDev" can recieve different parameters. "devList_One->at(0))" returns a reference on a device, while "devList_One->at(0).getName()" only returns a string, not a device or camera. That means, that "openDev" acts very different. Thus, using "getName()" advises the "openDev" function to create different instances of the camera, while "devList_One->at(0))" returns the same instance (pointer) of the already created device / camera. This will cause the access violation in



DShowLib::Grabber grabber_One;
DShowLib::Grabber grabber_Two;
DShowLib::Grabber::tVidCapDevListPtr devList_One = grabber_One.getAvailableVideoCaptureDevices();
DShowLib::Grabber::tVidCapDevListPtr devList_Two = grabber_Two.getAvailableVideoCaptureDevices();


grabber_One.openDev(devList_One->at(0));
grabber_Two.openDev(devList_One->at(0));
grabber_One.closeDev();
grabber_Two.closeDev(); // <- Access violation, because object in grabber is deleted.

the second "closeDev" line, because the camera has already been closed and deleted, but the grabber_two object does not know about this.

Therefore: Do not open a device twice by reference with "devList_One->at(0))".

Sander
November 23, 2010, 11:51:57
Thanks for your fast and clear answer.
One small additional one: Isn't it possible to determine this already on the second call to "openDev"? Or have it return an error when trying to do so, cause right now the problems only arise when closing the device.

Stefan Geissler
November 23, 2010, 14:06:17
No, it is not possible to check, whether a pointer is already in use by another object. However, it is possible to open a device twice with different instances. There are situations, in which this is wanted. Imagine, you have a simple DirectShow application, that shows only the live video, but it can not handle the properties. In this case, you can open the device a second time with IC and configure the properties.

Only the live video can be started only once.