Re: [ivtv-devel] [POSSIBLE BUG] poll after open without read first always returns POLLERR.
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
Re: [ivtv-devel] [POSSIBLE BUG] poll after open without read first always returns POLLERR.
Hans Verkuil schreef: 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:1 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 I currently have another program which does the channel changing. But would it not be better that the driver, even not capturing, on a poll request with poll_item.events = POLLIN it should check if it is able to start a capture so reading can start and on the first next read will really start the capture. If it is not able to start capturing on a first read then return POLLERR otherwise return POLLIN. In this way when the driver is not capturing and a poll would return POLLIN my program can start reading. Sockets act this way. Currently my program just reads zero bytes before doing the poll and this works. And it will also work on a normal file. To explain my program: It is a small server. When a client connects it opens the device/file/socket and reads data from it. It copies the data unchanged to the client. If a second or third, etc.., client connects the read data is copied unchanged to all the clients. When the last client disconnects it closes the device/file/socket. The other program only changes the channels on request of a client. For the server and client sockets in my programs I use poll to check if something needs to be communicated. In this I would like to put the file descriptor of the device so it only reads if the device is able to deliver data. Regards, Michel. ___ ivtv-devel mailing list ivtv-devel@ivtvdriver.org http://ivtvdriver.org/mailman/listinfo/ivtv-devel
Re: [ivtv-devel] [POSSIBLE BUG] poll after open without read first always returns POLLERR.
Hi, Michel Verbraak: Currently my program just reads zero bytes before doing the poll and this works. And it will also work on a normal file. That's a reasonable workaround. However, I would suggest that poll(...,POLLIN) signals the intent to read from that device sufficiently clearly: starting the capture is the Right Thing to do here, IMHO. unchanged to the client. If a second or third, etc.., client connects the read data is copied unchanged to all the clients. When the last client disconnects it closes the device/file/socket. Cool. Does your program understand MPEG framing? If I was the client, I'd hate to get some random MPEG tail fragment when I connect to your server. :-/ -- Matthias Urlichs | {M:U} IT Design @ m-u-it.de | [EMAIL PROTECTED] Disclaimer: The quote was selected randomly. Really. | http://smurf.noris.de - - The process of creating new scripture by constructive abuse of the old reaches its climax in the letters ascribed to Paul. -- Robin Lane Fox ___ ivtv-devel mailing list ivtv-devel@ivtvdriver.org http://ivtvdriver.org/mailman/listinfo/ivtv-devel
Re: [ivtv-devel] [POSSIBLE BUG] poll after open without read first always returns POLLERR.
Matthias Urlichs schreef: Hi, Michel Verbraak: Currently my program just reads zero bytes before doing the poll and this works. And it will also work on a normal file. That's a reasonable workaround. However, I would suggest that poll(...,POLLIN) signals the intent to read from that device sufficiently clearly: starting the capture is the Right Thing to do here, IMHO. unchanged to the client. If a second or third, etc.., client connects the read data is copied unchanged to all the clients. When the last client disconnects it closes the device/file/socket. Cool. Does your program understand MPEG framing? If I was the client, I'd hate to get some random MPEG tail fragment when I connect to your server. :-/ My first version only started sending to a client on a gop start in the stream. Because I only had mpeg devices. But currently I left it out, xine is my test for now and it does not mind to start in the middle of an mpeg2 stream and I can also stream other containers like avi, quicktime, flash, etc... Maybe I will make a mpeg2 version and a another. Then the mpeg2 will send always from a gop start to the client. Regards, Michel. ___ ivtv-devel mailing list ivtv-devel@ivtvdriver.org http://ivtvdriver.org/mailman/listinfo/ivtv-devel
Re: [ivtv-devel] [POSSIBLE BUG] poll after open without read first always returns POLLERR.
On Sunday 04 February 2007 16:24, Matthias Urlichs wrote: Hi, Michel Verbraak: Currently my program just reads zero bytes before doing the poll and this works. And it will also work on a normal file. That's a reasonable workaround. However, I would suggest that poll(...,POLLIN) signals the intent to read from that device sufficiently clearly: starting the capture is the Right Thing to do here, IMHO. I agree with you here, but I wait for some more definite answer from the v4l mailinglist. Might take a few days, the v4l maintainer is abroad at the moment. Hans unchanged to the client. If a second or third, etc.., client connects the read data is copied unchanged to all the clients. When the last client disconnects it closes the device/file/socket. Cool. Does your program understand MPEG framing? If I was the client, I'd hate to get some random MPEG tail fragment when I connect to your server. :-/ ___ ivtv-devel mailing list ivtv-devel@ivtvdriver.org http://ivtvdriver.org/mailman/listinfo/ivtv-devel