Expected video_unregister_device behavior.
It is my understanding that video_unregister_device is responsible for removing the /dev/video* device from the system. To this regard, I have seen a lot of usb camera drivers calling video_unregister_device in the usb disconnect callback to ensure that no one subsequently tries to open the device again. Mimicking the existing drivers, I did the same. What I found was that calling video_unregister_device resulted in calling the release function of the video_device structure despite the fact the device was still open. The log from my tests showed the following:
usb_probe_callback
- video_register_device calledvideo_open_callback - This seem to happen automatically upon video_register_devicevideo_close_callback - same as abovevideo_open_callback - caused by application open usb_disconnect_callback
- device physically disconnected
- calls video_unregister_device to prevent future opensvideo_release_callback
- called as a result of video_unregister_device but the device is
still open!video_close_callback
- application noticed read error and closed device
I have not yet looked to see why the video_release_callback is being called after video_unregister_device is called, but I would have expected it not to have been called until after the final video_close_callback has been issued. My question, is therefore, is this the desired behavior? Should a call to video_unregister_device immediately cause the video_release_callback to be called?
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
Quoted 25 lines · David Ellingsworth
It is my understanding that
video_unregister_deviceis responsible for removing the/dev/video*device from the system. To this regard, I have seen a lot of usb camera drivers callingvideo_unregister_devicein the usb disconnect callback to ensure that no one subsequently tries to open the device again. Mimicking the existing drivers, I did the same. What I found was that callingvideo_unregister_deviceresulted in calling the release function of thevideo_devicestructure despite the fact the device was still open. The log from my tests showed the following:
usb_probe_callback
-video_register_devicecalledvideo_open_callback- This seem to happen automatically uponvideo_register_devicevideo_close_callback- same as abovevideo_open_callback- caused by application openusb_disconnect_callback
- device physically disconnected
- callsvideo_unregister_deviceto prevent future opensvideo_release_callback
- called as a result ofvideo_unregister_devicebut the device is
still open!video_close_callback
- application noticed read error and closed device
Quoted 7 lines
I have not yet looked to see why the
video_release_callbackis being called aftervideo_unregister_deviceis called, but I would have expected it not to have been called until after the finalvideo_close_callbackhas been issued. My question, is therefore, is this the desired behavior? Should a call tovideo_unregister_deviceimmediately cause thevideo_release_callbackto be called?
I just wanted to follow up on this as I've found a work-around for the issue I was experiencing.
I had been using video_devdata(file) inside of close to retrieve the video device data from the file as I thought this was the preferred method. In the case above the return value of video_devdata in the final close is NULL. To overcome this limitation I set file->private_data in the open callback to my internal struct so I could retrieve it during the final close. Thus, giving the opportunity to properly free the struct. I suspect other drivers may have the same issue, but I have not investigated them as of yet.
Regards,
David Ellingsworth
--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list