[FFmpeg-devel] Non blocking av_read_frame

Nicolas George nicolas.george at normalesup.org
Fri Jul 6 10:52:37 CEST 2012

Le nonidi 19 messidor, an CCXX, Robert Nagy a écrit :
> It would be nice to have a non-blocking av_read_frame for some
> applications. Especially for applications using task-schedulers where
> blocking should be avoided.
> Maybe something along the lines of the attached patch, which should
> work for files and pipes, however I'm not sure how to integrate it
> with the rest of the protocols? Is it possible? Or should there be
> some form of capabilities flag?

>  #define AVIO_FLAG_READ  1                                      /**< read-only */
>  #define AVIO_FLAG_WRITE 2                                      /**< write-only */
>  #define AVIO_FLAG_READ_WRITE (AVIO_FLAG_READ|AVIO_FLAG_WRITE)  /**< read-write pseudo flag */
> +#define AVIO_FLAG_NONBLOCKING 4                                    /**< no-blocking */

We already have AVIO_FLAG_NONBLOCK a few lines below.

> +	
> +		access |= O_NONBLOCKING;
> +	

The correct flag is O_NONBLOCK.

Unfortunately, it is not so easy. At all.

For one, O_NONBLOCK does not work with plain files, because the OS does not
consider that actually blocking. So it would have no effect on slow reads
from a DVD or a NFS mount for example.

Second, a lot of protocols can not handle non-blocking reads, because they
expect to be able to read whole blocks (for example, a 4-bytes integer
indicating a size) at once, and they keep intermediate value in local
variables (for example: int size = avio_rb16(s); avio_read(s, buf, size)).
Rewriting them to handle non-blocking reads would take a lot of effort.

Third, the demuxers have exactly the same problem, but as their job is much
more complex, and they are much more numerous, it would take a huge amount
of effort.

IMHO, if you need non-blocking av_read_frame, you have to use threads.


  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120706/f0367ea9/attachment.asc>

More information about the ffmpeg-devel mailing list