Re: Poll and empty queues

Hans Verkuil
2014-06-03T06:39:13Z

Hi Nicholas,

On 06/02/2014 09:47 PM, Nicolas Dufresne wrote:
> Hi everyone,
>
> Recently in GStreamer we notice that we where not handling the POLLERR
> flag at all. Though we found that what the code do, and what the doc
> says is slightly ambiguous.
>
> "When the application did not call VIDIOC_QBUF or
> VIDIOC_STREAMON yet the poll() function succeeds, but sets the
> POLLERR flag in the revents field."
>
> In our case, we first seen this error with a capture device. How things
> worked is that we first en-queue all allocated buffers. Our
> interpretation was that this would avoid not calling "VIDIOC_QBUF [...]
> yet", and only then we would call VIDIOC_STREAMON. This way, in our
> interpretation we would never get that error.
>
> Though, this is not what the code does. Looking at videobuf2, if simply
> return this error when the queue is empty.
>
> /*
> * There is nothing to wait for if no buffers have already been queued.
> */
> if (list_empty(&q->queued_list))
> return res | POLLERR;
>
> So basically, we endup in this situation where as soon as all existing
> buffers has been dequeued, we can't rely on the driver to wait for a
> buffer to be queued and then filled again. This basically forces us into
> adding a new user-space mechanism, to wait for buffer to come back. We
> are wandering if this is a bug. If not, maybe it would be nice to
> improve the documentation.

Just for my understanding: I assume that gstreamer polls in one process or
thread and does the queuing/dequeuing in a different process/thread, is that
correct?

If it was all in one process, then it would make no sense polling for a
buffer to become available if you never queued one.

That is probably the reasoning behind what poll does today. That said, I've
always thought it was wrong and that it should be replaced by something like:

if (!vb2_is_streaming(q))
return res | POLLERR;

I.e.: only return an error if we're not streaming.

Regards,

Hans