[FFmpeg-devel] [PATCH] : libavformat segfault when a RTSP reading is interrupted

Eric Paul eric.paul
Thu Jul 5 15:13:01 CEST 2007


(Please, forgive my possibly bad English, I'm no native ...)

I've tried to use ffmpeg to read an RTSP stream. It works pretty well, but
when the stream ends, my application hang.

I've browsed the code and I've found that you can set a callback to tell
libavformat that you want to interrupt the reading. So I've used libavformat
url_set_interrupt_cb function and a thread to manage a timeout for
av_read_frame when reading a RTSP stream. Again, it works pretty well, but
sometimes libavformat segfaults.

Back to the code, it seems that when reading is interrupted by the callback
(in libavformat/rtsp.c udp_read_packet line 1130 rev 9482 in my case), the
struct pointer rtsp_st in function rtsp_read_packet is uninitialized, so the
next line of code which read rtsp_st->rtp_ctx segfaults !

As udp_read_packet returns -1 when interrupted by the callback, I've done a
(very) little patch which seems to correct the problem (patch attached).

By the way, it should be interesting to change the callback signature to
something like :

int URLInterruptCB(void*) instead of int URLInterruptCB(void)

This way, you can give the callback a parameter which is better to avoid
using a global variable to tell the callback you want to interrupt. If this
is ok, I can do it myself :-)

Tell me if I've not totally missed the point,

    Professionnal Segfault Hunter.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch_rtsp
Type: application/octet-stream
Size: 496 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070705/f40e30fb/attachment.obj>

More information about the ffmpeg-devel mailing list