[Libav-user] Using custom asynchronous I/O with avio_alloc_context
Nicolas
efyxps at gmail.com
Mon Mar 11 14:59:32 CET 2013
Hi,
Thanks for these useful informations. It works great, I used libpcl.
Cheers.
On Sun, Mar 10, 2013 at 7:44 PM, Nicolas George <
nicolas.george at normalesup.org> wrote:
> Le nonidi 19 ventôse, an CCXXI, Nicolas a écrit :
> > I am using libav with custom I/O (with avio_alloc_context()) for reading
> > various stream.
> >
> > In my project, all my I/O are asynchronous but ffmpeg callbacks work in a
> > synchronous way. So right now, what I am doing is to use an internal
> buffer
> > 4 times bigger than my avio buffer and each time my read callback is
> called
> > I copy a part of my buffer and get new data asynchronously, this works
> well
> > for reading, but when I seek my media I don't have (yet) data in my
> > internal buffer. In such case what should I return in my read callback?
> >
> > Also, there is a flag AVIO_FLAG_NONBLOCKING that I could pass to
> > avio_alloc_context but i couldn't figure how to use it (what should I
> > return in my read callback?)
> >
> > is there any way to use custom I/O in an asynchronous fashion?
>
> Unfortunately, no, there is currently no way of working with asynchronous
> and non-blocking I/O. Some of the network protocols can be set to work
> non-blocking, but not all, and the demuxers themselves can not work in
> non-blocking mode.
>
> The usual solution for that is to use threads. You could, for example, run
> the demuxer in a separate thread. When the demuxer calls the read function
> in your custom I/O context, the thread becomes blocked waiting for data
> from
> the main thread, and when it has demuxed a packet, it can wake the main
> thread using some kind of signalfd/self-pipe. That way, the demuxing thread
> do not force you to abandon your async model (using a few threads has a
> tendency to force you to use threads everywhere).
>
> Also note that since you are using the thread not for concurrency but only
> to keep the local context of the demuxer, you do not have to use "real"
> threads, you can consider using, for examples, GNU Pth, or libpcl.
>
> Regards,
>
> --
> Nicolas George
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.12 (GNU/Linux)
>
> iEYEARECAAYFAlE81JAACgkQsGPZlzblTJMtkACeLJzEZTJoWgQsPoMRjEHrKCuZ
> aJMAoJaX+tNbEtsk0lmfasNLFnVD1BQd
> =qnqx
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130311/640759a6/attachment.html>
More information about the Libav-user
mailing list