On Sunday 04 February 2007 15:23, Michel Verbraak wrote: > Hans Verkuil schreef: > > On Sunday 04 February 2007 13:43, Michel Verbraak wrote: > >> I was debugging a small program of mine and found that: > >> > >> - when I do a poll after opening the device, and not doing a read > >> first, it would always give me a POLLERR instead of a POLLIN. > >> > >> Example: > >> > >> videofd=open("/dev/video0", O_RDONLY); > >> > >> // Add video device > >> poll_item.fd = videofd; > >> poll_item.events = POLLIN; > >> poll_item.revents = 0; > >> > >> // poll infinite > >> retvalue = poll(&poll_item, 1, -1); > >> > >> poll_item.revents is allways POLLERR. > >> > >> When I do a read(videofd, buffer, 0); directly after the open and > >> then do the poll I get POLLIN. > >> > >> I can trace this back to the fact that the bit IVTV_F_S_STREAMING > >> is only set, in function ivtv_v4l2_read in file ivtv-fileops.c, > >> when at least one read is done. Even if the request is to read 0 > >> (zero) bytes. > >> > >> I do not know if this is by design. > >> But I would think that it should be possible to first do a poll to > >> see if data is available to read before I even do any reading. So > >> probably the IVTV_F_S_STREAMING bit should be set in the function > >> ivtv_v4l2_open in file ivtv-fileops.c. > >> > >> This problem is in ivtv 0.10.0RC1 and I would think even in the > >> earlier versions. > >> > >> I did not yet spend time to find a fix because I would first like > >> to know if this is by design or not. > > > > It's by design, but I'm not certain whether it is the right design. > > Basically just opening the device will not start a capture, it has > > to be started explicitly, either by a read or by an IVTV_IOC_PLAY > > ioctl. It is unclear what poll should do if no capture is in > > progress. Wait indefinitely? Automatically start a capture? Or > > return an error? I can't find a clear answer in the V4L2 spec. > > > > I'll ask on the video4linux mailinglist, see what the correct > > policy is. > > > > Thanks, > > > > Hans > > > > _______________________________________________ > > ivtv-devel mailing list > > ivtv-devel@ivtvdriver.org > > http://ivtvdriver.org/mailman/listinfo/ivtv-devel > > The program I'm writing does not known it is reading from an ivtv > device. The file handle could be a device or a file or a socket. > I would like to keep it this way because otherwise I have to make two > different programs or during startup I have to specify if it is an > ivtv device or the other. During startup I only specify te location > like /dev/video0 or /movies/somemovie.avi or 192.168.1.1:10000 and > the program either opens the device or file or creates a tcp socket.
And some other program or thread will actually start the capture? Just opening a v4l2 device will NEVER automatically start a capture. Otherwise even opening a video device just to change the frequency would have the nasty side-effect of beginning a capture. Regards, Hans _______________________________________________ ivtv-devel mailing list ivtv-devel@ivtvdriver.org http://ivtvdriver.org/mailman/listinfo/ivtv-devel