<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hello libav-users,<div class=""><br class=""></div><div class="">With some investigation, i was able to confirm libavformat’s I/O Interrupt Callback is not being called by av_read_frame(). Currently, when av_read_frame() is called while consuming either USB or IP media streams, if the connection is terminated from actions such as the ethernet/usb cable being disconnected, av_read_frame() will hang. </div><div class=""><br class=""></div><div class=""><div class="">I was able to modify the av_read_frame() routine from libavformat such that the same I/O interrupt callback used for other libavformat I/O routines is called when reading packets from a stream. It appears to be a minimal change, with no API changes. </div><div class=""><br class=""></div><div class="">The only behavioral change is the I/O Interrupt Callback is called, and it respects a positive return value to indicate termination of I/O by av_read_frame().</div><div class=""><br class=""></div><div class="">It seems like I am correcting a design oversight: there is a facility for library clients to check on pending I/O, that’s the I/O interrupt callback. It is being called during other libavformat routines that perform I/O. Yet, for the critical step of reading packets from a media stream, it was not being called. Finding wrapper logic enabling the hooking in of the interrupt callback a mere 3 lines of code, I tried it, built windows x64 and win32 dlls and tested with my employer's computer vision system. It does exactly what is needed: when reading USB video or IP cameras or Internet streams, "if the cable gets pulled” the media library does not hang. Through the interrupt callback, my libavformat client code easily implements a timeout, signaling back to libavformat when to stop waiting for I/O.</div></div><div class=""><br class=""></div><div class="">Seeing multiple developers requesting this functionality online, I looked into making a patch for submission this back to the ffmpeg developers. It looks like the patch submission process is a bit more time consuming than my schedule allows. Pretty much because it would require my using git in a manner I am unfamiliar. (I barely use git myself, rarely directly.)</div><div class=""><br class=""></div><div class="">I did a git diff to create this, it is the entire change enabling this critical functionality:</div><div class=""><br class=""></div><div class=""><font face="Courier New" class="">————————</font></div><div class=""><font face="Courier New" class=""><div class="">diff --git a/libavformat/utils.c b/libavformat/utils.c</div><div class="">index 0711310..5971e31 100644</div><div class="">--- a/libavformat/utils.c</div><div class="">+++ b/libavformat/utils.c</div><div class="">@@ -1718,6 +1718,12 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt)</div><div class="">     }</div><div class=""> </div><div class="">     for (;;) {</div><div class="">+<span class="Apple-tab-span" style="white-space:pre">    </span>if (ff_check_interrupt(&s->interrupt_callback)) {</div><div class="">+<span class="Apple-tab-span" style="white-space:pre"> </span>   ret = AVERROR_EXIT;</div><div class="">+<span class="Apple-tab-span" style="white-space:pre">      </span>   av_log(s, AV_LOG_DEBUG, "interrupted\n");</div><div class="">+<span class="Apple-tab-span" style="white-space:pre">      </span>   return ret;</div><div class="">+<span class="Apple-tab-span" style="white-space:pre">      </span>}</div><div class="">+<span class="Apple-tab-span" style="white-space:pre">        </span></div><div class="">         AVPacketList *pktl = s->internal->packet_buffer;</div><div class=""> </div><div class="">         if (pktl) {</div><div class=""><br class=""></div></font></div><div class=""><font face="Courier New" class="">————————</font></div><div class=""><br class=""></div><div class="">I’ll continue looking into creating a formal submission to the ffmpeg developers - BUT if someone more familiar with the process wants to step in, by all means. I’ll be fumbling with those steps, under a constrained schedule…</div><div class=""><br class=""></div><div class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; font-family: Arial; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; line-height: normal; border-spacing: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><font class="Apple-style-span" face="Arial"><span class="Apple-style-span"><font class="Apple-style-span" face="Helvetica" size="3"><span class="Apple-style-span" style="font-size: 12px;"><div style="margin: 0px;" class=""><font face="Helvetica" size="3" style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-family: Helvetica;" class=""><font class="Apple-style-span" color="#0000FF">Sincerely,</font></font></div><div style="margin: 0px;" class=""><font face="Helvetica" size="3" style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-family: Helvetica;" class=""><font class="Apple-style-span" color="#0000FF">-Blake Senftner</font></font></div></span></font></span></font></span></div></span></div></span></div></span><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div class=""><font class="Apple-style-span" face="Arial"><span class="Apple-style-span"><font class="Apple-style-span" face="Helvetica" size="3"><span class="Apple-style-span" style="font-size: 12px;"><div style="margin: 0px;" class=""><font face="Helvetica" size="2" color="#959892" style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 10px; line-height: normal; font-family: Helvetica; color: rgb(149, 152, 146);" class=""><br class=""></font></div><div style="margin: 0px;" class=""><font face="Helvetica" size="2" color="#959892" style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 10px; line-height: normal; font-family: Helvetica; color: rgb(149, 152, 146);" class="">---> Blake loves the Planet Earth and is proud to display this email with Recycled Electrons.</font><span class="Apple-style-span" style="font-size: 10px; color: rgb(149, 152, 146);"> <---</span></div></span></font></span></font></div></span></div></span></div></span></div></span></div></span></div></span></div></span>
</div>
<br class=""></div></body></html>