[FFmpeg-devel] av_open_input_file hangs when given the wrong IP address

Edward Patton epatton
Mon Jul 20 23:51:14 CEST 2009


Hi

This may be related to Issue539. I am using av_open_input_file to start rtp video streaming. When I give it an incorrect IP address, the function does not return. I traced it to the function tcp_open(). At the function 

??? ret = select(fd_max + 1, NULL, &wfds, NULL, &tv);

if the IP address is not correct, the returned value is zero. A returned value of zero which causes it to stay in the for(;;) loop forever.
This patch works for my application.

Index: libavformat/tcp.c
===================================================================
--- tcp.c?????? (revision 19392)
+++ tcp.c?????? (working copy)
@@ -73,18 +75,31 @@

???????? /* wait until we are connected or until abort */
???????? for(;;) {
-??????????? if (url_interrupt_cb()) {
+??????????? if (url_interrupt_cb()) {
???????????????? ret = AVERROR(EINTR);
???????????????? goto fail1;
???????????? }
???????????? fd_max = fd;
???????????? FD_ZERO(&wfds);
???????????? FD_SET(fd, &wfds);
-??????????? tv.tv_sec = 0;
-??????????? tv.tv_usec = 100 * 1000;
+?????????? tv.tv_sec = 5; // Increased timeout to 5 sec. Should be adequate to find an IP addr.
+?????????? tv.tv_usec = 100 * 1000;
???????????? ret = select(fd_max + 1, NULL, &wfds, NULL, &tv);
+?????????????????????? // if negative, you have an error condition

+?????????????????????? // if zero, you have a timeout

+?????????????????????? // otherwise you have the number of sockets on which an event took place
+?????????? if (ret==0)
+?????????? {
+?????????????? ret = -1; //A timeout (ret=0) is also an error case because we could not find the host.
+?????????????? return(ret); 
+?????????? }
???????????? if (ret > 0 && FD_ISSET(fd, &wfds))
???????????????? break;
???????? }




      



More information about the ffmpeg-devel mailing list