#2694 closed defect (fixed)
interrupt_callback not working
Reported by: | sporn | Owned by: | |
---|---|---|---|
Priority: | important | Component: | avformat |
Version: | git-master | Keywords: | regression |
Cc: | nfxjfg@googlemail.com | Blocked By: | |
Blocking: | Reproduced by developer: | no | |
Analyzed by developer: | no |
Description
Summary of the bug:
How to reproduce:
This used to work (interrupt on no network connnection) until I updated to latest version of ffmpeg, now it hangs indefinitely on avformat_open_input and read frame. The interrupt is never fired. (timestamp is something i've added myself)
static int interrupt_cb(void *ctx) { AVFormatContext* formatContext = reinterpret_cast<AVFormatContext*>(ctx); //timeout after 5 seconds of no activity if (formatContext->timestamp>0 && (GetTickCount() - formatContext->timestamp >5000)) return 1; return 0; } static AVFormatContext* open_file( char* fileName ) { AVDictionary *options = NULL; av_dict_set(&options, "analyzeduration", "1500000", 0); AVFormatContext* formatContext = avformat_alloc_context( ); formatContext->interrupt_callback.callback = interrupt_cb; formatContext->interrupt_callback.opaque = formatContext; formatContext->timestamp = GetTickCount(); formatContext->flags|=AVFMT_FLAG_NONBLOCK; if ( avformat_open_input( &formatContext, fileName, NULL, NULL ) !=0 ) { return NULL; } av_dict_free(&options); return formatContext; }
Patches should be submitted to the ffmpeg-devel mailing list and not this bug tracker.
Change History (32)
comment:1 by , 11 years ago
Keywords: | regression added; interrupt callback block avformat_open_input removed |
---|---|
Priority: | critical → important |
comment:2 by , 11 years ago
"If you believe this problem is a regression, please use git bisect to find the change that introduced the bug for you."
I've regressed the code all the way back to the 1.13 release and it's doing the same thing. I have no idea what git bisect is. This is a total show stopper for me - could you try and reproduce it so I know it's not something i'm doing wrong?
comment:3 by , 11 years ago
Calling avio_open2 instead of avformat_open_input and passing the callback as a parameter works
follow-up: 6 comment:5 by , 11 years ago
my old version was from december 2011
i've managed to update all our code to work with the latest version of ffmpeg (taken me 3 weeks!) - the only thing left is timing out on broken streams or non existant urls. Calling
avio_open2 directly does fire the interrupt. Calling avformat_open_input does not - it just hangs indefinitely.
I'm happy to pay for your time to look into this - sean -at- ispyconnect.com
comment:6 by , 11 years ago
Replying to sporn:
my old version was from december 2011
december 2011 does not sound like a FFmpeg version identifier.
I'm happy to pay for your time to look into this - sean -at- ispyconnect.com
If you can post source code that allows to reproduce the problem (source code, not an extract) you may not have to pay. If you cannot provide failing source code, I wonder how payment would allow anybody else to reproduce your problem.
follow-up: 8 comment:7 by , 11 years ago
OK the last version was:
This is a FFmpeg Win32 shared build by Kyle Schwarz.
Zeranoe's FFmpeg Builds Home Page: http://ffmpeg.zeranoe.com/builds/
Built on Nov 30 2011 00:55:18
FFmpeg version git-b55dd10
libavutil 51. 29. 1 / 51. 29. 1
libavcodec 53. 39. 1 / 53. 39. 1
libavformat 53. 22. 0 / 53. 22. 0
libavdevice 53. 4. 0 / 53. 4. 0
libavfilter 2. 50. 0 / 2. 50. 0
libswscale 2. 1. 0 / 2. 1. 0
libpostproc 51. 2. 0 / 51. 2. 0
the source to reproduce the issue is above and it's trivial
comment:8 by , 11 years ago
Replying to sporn:
FFmpeg version git-b55dd10
Now that you know of a working revision, you can start bisecting.
the source to reproduce the issue is above and it's trivial
It does not compile here;-(
comment:9 by , 11 years ago
I'm working with c++ in visual studio using a zeranoe build. Basically the issue is that avformat_open_input does not ever fire an interrupt callback and so hangs on broken streams. I don't know how much more simple I can make it. I have no idea how to provide you with a compilable example, I'm just looking for some help that i'm happy to pay for. I've spent the last 12 hours on this and gotten nowhere.
comment:10 by , 11 years ago
you can try it with ffplay:
ffplay mmsh://live1.wm.skynews.servecast.net/skynews_wmlz_live300k
- then disconnect the network connection - the stream doesn't end and the application doesn't exit
comment:11 by , 11 years ago
or try this (a non-existant video stream):
ffplay http://192.168.1.5/videostream.asf
ffplay will hang indefintely. It should fire an interrupt and abort (and it used to) but it doesn't any more. The interrupt is hooked up in ffplay but just like in my application it's never being fired.
comment:12 by , 11 years ago
$ time ffplay http://192.168.1.5/videostream.asf ffplay version N-54130-g98abe16 Copyright (c) 2003-2013 the FFmpeg developers built on Jun 21 2013 11:32:10 with gcc 4.7 (SUSE Linux) configuration: --enable-gpl --disable-indev=jack libavutil 52. 37.101 / 52. 37.101 libavcodec 55. 16.100 / 55. 16.100 libavformat 55. 9.100 / 55. 9.100 libavdevice 55. 2.100 / 55. 2.100 libavfilter 3. 77.101 / 3. 77.101 libswscale 2. 3.100 / 2. 3.100 libswresample 0. 17.102 / 0. 17.102 libpostproc 52. 3.100 / 52. 3.100 Connection to tcp://192.168.1.5:80 failed: No route to host f=0/0 http://192.168.1.5/videostream.asf: Input/output error real 0m3.023s user 0m0.025s sys 0m0.017s
comment:13 by , 11 years ago
D:\Projects\iSpy\FFMPEG\ffmpeg\bin>ffplay http://192.168.1.5:80/videostream.asf
ffplay version N-54126-g8cdea50 Copyright (c) 2003-2013 the FFmpeg developers
built on Jun 20 2013 23:40:19 with gcc 4.7.3 (GCC)
configuration: --disable-static --enable-shared --enable-gpl --enable-version3
--disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --ena
ble-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --e
nable-libcaca --enable-libfreetype --enable-libgsm --enable-libilbc --enable-lib
modplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrw
b --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinge
r --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --en
able-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --e
nable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
libavutil 52. 37.101 / 52. 37.101
libavcodec 55. 16.100 / 55. 16.100
libavformat 55. 9.100 / 55. 9.100
libavdevice 55. 2.100 / 55. 2.100
libavfilter 3. 77.101 / 3. 77.101
libswscale 2. 3.100 / 2. 3.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 3.100 / 52. 3.100
nan : 0.000 fd= 0 aq= 0KB vq= 0KB sq= 0B f=0/0
(hang)
comment:15 by , 11 years ago
Are you sure this is a regression?
I tested b55dd10 (the version that you wrote above works fine) and it shows the same behaviour as current git head: If I disconnect the network, the player freezes and waits forever. This appears to be intended behaviour since playback continues as soon as I reconnect.
$ ffplay mmsh://live1.wm.skynews.servecast.net/skynews_wmlz_live300k -autoexit ffplay version N-35295-gb55dd10, Copyright (c) 2003-2011 the FFmpeg developers built on Jun 22 2013 18:06:03 with gcc 4.3.2 [gcc-4_3-branch revision 141291] configuration: libavutil 51. 29. 1 / 51. 29. 1 libavcodec 53. 39. 1 / 53. 39. 1 libavformat 53. 22. 0 / 53. 22. 0 libavdevice 53. 4. 0 / 53. 4. 0 libavfilter 2. 50. 0 / 2. 50. 0 libswscale 2. 1. 0 / 2. 1. 0 [wmv3 @ 0x8e6dca0] Extra data: 8 bits left, value: 0 [asf @ 0x8e5b2a0] parser not found for codec wmav2, packets or times may be invalid. [asf @ 0x8e5b2a0] Estimating duration from bitrate, this may be inaccurate Input #0, asf, from 'mmsh://live1.wm.skynews.servecast.net/skynews_wmlz_live300k': Metadata: title : Sky News artist : BSkyB copyright : BSkyB WMFSDKVersion : 11.0.5721.5145 WMFSDKNeeded : 0.0.0.0000 IsVBR : 0 Duration: N/A, start: 832056.145000, bitrate: 252 kb/s Stream #0:0(eng): Audio: wmav2 (a[1][0][0] / 0x0161), 44100 Hz, 1 channels, s16, 32 kb/s Stream #0:1(eng): Video: wmv3 (Main) (WMV3 / 0x33564D57), yuv420p, 320x180, 220 kb/s, 25 tbr, 1k tbn, 1k tbc [wmv3 @ 0x8e6dca0] Extra data: 8 bits left, value: 0 ...
(waits forever if network gets disconnected)
ffmpeg (the application) also does not quit on network disconnection but waits forever.
comment:16 by , 11 years ago
I've tested it with my application - that also reconnects if the network connection reconnects but it's not anything to do with my code - ffmpeg seems to be doing that internally. The interrupt callback is never being called in my code or in ffplay. The blocking functions used to call the interrupt which gave you the option to abort after a period of time (critical for us as we use ffmpeg to live stream IP cameras and alerting on broken streams is basic functionality).
It seems that this issue may be windows specific. Shouldn't the two basic ffplay commands with non existent streams work the same? Yours times out on linux and mine doesn't on windows...
I've tracked it down to a breaking change between 2 versions of ffmpeg, one that works (breaks on a non-existent stream which means the interrupt is working) from Oct 5, 2012 and the next doesn't - Oct 9, 2012. Both are built with the exact same configuration:
D:\Projects\ffmpeg\test1>ffplay http://192.168.1.5/videostream.asf ffplay version N-45080-gd9dfe9a Copyright (c) 2003-2012 the FFmpeg developers built on Oct 5 2012 16:47:17 with gcc 4.7.1 (GCC) configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --disable-pthreads --enable-runtime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libass --enable-libcelt --enable-libopencore-amrnb --en able-libopencore-amrwb --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libopenjpeg --enable-librtmp --enable-libschroedinger - -enable-libspeex --enable-libtheora --enable-libutvideo --enable-libvo-aacenc -- enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enab le-libxavs --enable-libxvid --enable-zlib libavutil 51. 73.102 / 51. 73.102 libavcodec 54. 63.100 / 54. 63.100 libavformat 54. 29.105 / 54. 29.105 libavdevice 54. 3.100 / 54. 3.100 libavfilter 3. 19.102 / 3. 19.102 libswscale 2. 1.101 / 2. 1.101 libswresample 0. 16.100 / 0. 16.100 libpostproc 52. 1.100 / 52. 1.100 http://192.168.1.5/videostream.asf: Input/output error
(!!WORKS)
D:\Projects\ffmpeg\test2>ffplay http://192.168.1.5/videostream.asf ffplay version N-45220-gf3f35f7 Copyright (c) 2003-2012 the FFmpeg developers built on Oct 9 2012 20:02:43 with gcc 4.7.1 (GCC) configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --disable-pthreads --enable-runtime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libass --enable-libcelt --enable-libopencore-amrnb --en able-libopencore-amrwb --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libopenjpeg --enable-librtmp --enable-libschroedinger - -enable-libspeex --enable-libtheora --enable-libutvideo --enable-libvo-aacenc -- enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enab le-libxavs --enable-libxvid --enable-zlib libavutil 51. 74.100 / 51. 74.100 libavcodec 54. 65.100 / 54. 65.100 libavformat 54. 31.100 / 54. 31.100 libavdevice 54. 3.100 / 54. 3.100 libavfilter 3. 19.102 / 3. 19.102 libswscale 2. 1.101 / 2. 1.101 libswresample 0. 16.100 / 0. 16.100 libpostproc 52. 1.100 / 52. 1.100
(!! HANGS)
(also important to note that if i supply it with a valid url to a stream but no network connection then it hangs and doesn't connect when the network connection is restored)
comment:17 by , 11 years ago
I've found this:
https://github.com/FFmpeg/FFmpeg/commit/b6f435fbc87c024f8403fca69e6e6b98bccf93fa
- committed on the 9th October. It looks like when adding the timeout AVOption they've broken the interrupt callback. If I do
av_dict_set(&options, "timeout", "1000", 0);
...then the connection attempt will timeout after 1 second.
This would also explain why it's working on linux as the default timeout (used when no timeout is specified) will be different to the default windows tcp timeout (which for whatever reason in this case seems to be indefinite).
For me adding the timeout AVOption fixes my issue. It'd be good to figure out why the interrupt_callback is broken and get that fixed though. Seems it's either not being passed properly or is being reset somewhere along the way.
The AVoption "timeout" should also be added to ffplay.c - to stop it hanging and to hopefully stop anyone else from going through what i've been through for the past week.
comment:18 by , 11 years ago
Adding
av_dict_set(&options, "timeout", "8000", 0);
...breaks rtsp streams because "timeout" to the rtsp class means timeout whilst listening for incoming connections, not timeout for requests.
Whatever broke the http interrupt_callback has also broken the rtsp interrupt_callback as that's not getting called either and now i'm out of workarounds :(
comment:19 by , 11 years ago
Keywords: | win added |
---|---|
Reproduced by developer: | set |
Status: | new → open |
I can reproduce the hang on Windows, but it also hangs with 2e009c6 here, so I don't think this is a regression since b6f435f.
follow-up: 21 comment:20 by , 11 years ago
Reproduced by developer: | unset |
---|
follow-up: 23 comment:21 by , 11 years ago
Right so you reproduced it and have now said that you cant reproduce it?
The real cause of the bug is that interrupt_callback isn't working. Any chance you could take a moment just to check that? Do you know how to do that? Happy to help...
comment:22 by , 11 years ago
I could reproduce the hang but you said that the problem is a regression (ie that it worked with an older version of FFmpeg) but I was unable to find a working revision.
comment:23 by , 11 years ago
Replying to sporn:
The real cause of the bug is that interrupt_callback isn't working. Any chance you could take a moment just to check that?
Sure, if you can provide source code that compiles with gcc I can also test that.
comment:24 by , 11 years ago
Give this a go:
http://hosting.ispyconnect.com/testinterrupt.c
... i'm doing this blind as i can't compile it here - just updated it.
comment:25 by , 11 years ago
(The includes look wrong, I replaced them with something like "include libavformat/avformat.h")
The command prints many lines of "Interrupt callback called" on the console - does this mean there is no issue and the callbacks work fine?
follow-up: 28 comment:26 by , 11 years ago
What are you testing it on? Linux? It's definitely not working here
comment:27 by , 11 years ago
Cc: | added |
---|
comment:28 by , 11 years ago
Replying to sporn:
What are you testing it on? Linux? It's definitely not working here
I tested on Linux and Windows 7.
comment:29 by , 11 years ago
well.. that doesn't make any sense - the reason ffplay is hanging on non-existent streams is because the interrupt callback isn't working... unless something has been fixed in the last couple of days...
comment:30 by , 11 years ago
Could you confirm that testinterrupt.c shows no output for you? And perhaps attach an actually working version (after all, I had to edit it)?
How did you compile the libraries? Which configure options and which compiler?
comment:31 by , 11 years ago
Keywords: | win removed |
---|---|
Resolution: | → fixed |
Status: | open → closed |
Should be fixed in 390aabb2a1ade0cefec6ab10e39b391b43de5c45 & 68b7b534be5912dbd28283d0d566a2ee88e51f9b
I could not find an issue with the callback not being called though, this just fixes the timeout issue (which was a regression)
comment:32 by , 11 years ago
Sorry - it turned out to be my fault (kind of)- i added an int field (called timestamp) to an ffmpeg header file (avformat.h) which somehow broke the callback (I have no idea how). Removing the int declaration fixed the interrupt callback.
If you believe this problem is a regression, please use git bisect to find the change that introduced the bug for you.