[Libav-user] Asynchronous / timeout connections and packet reading?

Andrey Utkin andrey.krieger.utkin at gmail.com
Fri Jan 20 18:23:51 CET 2012

2012/1/20 Camera Man <i.like.privacy.too at gmail.com>:
> On 01/20/2012 11:21 AM, Andrey Utkin wrote:
> The thing 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.
> How often / when is it called? If it's a tcp-rtsp connection? what if it's a
> udp-rtsp connection?
> 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.
> That was what I was planning to do, but I was not aware of the interrupt
> callback. Is there documentation anywhere about when it is called?

It is called in many layers. Generally, in all places where procedure
MUST deliver data portion to upper layer, but no data yet. Thus we may
block the execution until data arrives, without application becoming
Simply, when operation like recv() gave insufficient number of bytes,
procedure checks interrupt_callback, and, if not interrupted, sleep()s
for sth like 100ms before trying recv() again.
Both TCP and UDP protocol readers in libavformat are using it.

Andrey Utkin

More information about the Libav-user mailing list