[Libav-user] Asynchronous / timeout connections and packet reading?
Andrey Utkin
andrey.krieger.utkin at gmail.com
Fri Jan 20 17:21:19 CET 2012
2012/1/20 Camera Man <i.like.privacy.too at gmail.com>:
> I have an rtsp camera feed that I'm happily reading data off.
>
> Occasionally, the camera stops responding and needs to be reset -- in which
> case, blocking reads and connects can take more than a minute to fail.
>
> Is there any way to do that asynchronously? e.g., "read packet but return
> immediately if no packet there" or something like that? and/or, is it
> possible to select() on the sockets so I know if anything is going to block
> before trying to read?
>
> Alternatively, is there a way I can set up (say) a 1-second timeout and
> retry?
>
> Or is the only way to achieve this asynchrony is by starting another thread?
>
> Thanks in advnace.
The think you perhaps want to use is AVFormatContext.interrupt_callback.
You can implement a callback procedure that checks the time spent
since last packet was retrieved from av_read_frame(). But look out to
not make it too heavy function.
Another way is to introduce a monitoring thread, that'll wake each N
seconds, checking if quantity of retrieved data has progressed, and if
no, set some flag. And interrupt_callback function will check this
flag value.
--
Andrey Utkin
More information about the Libav-user
mailing list