[FFmpeg-devel] [PATCH 2/2] Use AVERROR_INTERRUPTED with url_interrupt_cb.

Nicolas George nicolas.george
Sat Mar 12 14:35:56 CET 2011


Functions interrupted by url_interrupt_cb should not be restarted.
Therefore using AVERROR(EINTR) was wrong, as it did not allow to distinguish
when the underlying system call was interrupted and actually needed to be
restarted.

This fixes roundup issues 2657 and 2659 (ffplay not exiting for streamed
content).

Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavformat/applehttp.c      |    2 +-
 libavformat/applehttpproto.c |    4 ++--
 libavformat/avio.c           |    2 +-
 libavformat/avio.h           |    2 +-
 libavformat/rtpproto.c       |    2 +-
 libavformat/rtsp.c           |    2 +-
 libavformat/tcp.c            |    6 ++++--
 libavformat/udp.c            |    2 +-
 libavformat/utils.c          |    2 +-
 9 files changed, 13 insertions(+), 11 deletions(-)


Remark: I tested the mmsh protocol using the URL in the Roundup issues.
This, in turn, tests HTTP and TCP.

I do not know good test URL for other protocols. The change is
straightforward enough, though.



diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c
index 5118d03..abdd769 100644
--- a/libavformat/applehttp.c
+++ b/libavformat/applehttp.c
@@ -528,7 +528,7 @@ reload:
         return AVERROR_EOF;
     while (av_gettime() - c->last_load_time < c->target_duration*1000000) {
         if (url_interrupt_cb())
-            return AVERROR(EINTR);
+            return AVERROR_INTERRUPTED;
         usleep(100*1000);
     }
     /* Enough time has elapsed since the last reload */
diff --git a/libavformat/applehttpproto.c b/libavformat/applehttpproto.c
index 471f94b..5e23e99 100644
--- a/libavformat/applehttpproto.c
+++ b/libavformat/applehttpproto.c
@@ -318,7 +318,7 @@ retry:
             return AVERROR_EOF;
         while (av_gettime() - s->last_load_time < s->target_duration*1000000) {
             if (url_interrupt_cb())
-                return AVERROR(EINTR);
+                return AVERROR_INTERRUPTED;
             usleep(100*1000);
         }
         goto retry;
@@ -328,7 +328,7 @@ retry:
     ret = url_open(&s->seg_hd, url, URL_RDONLY);
     if (ret < 0) {
         if (url_interrupt_cb())
-            return AVERROR(EINTR);
+            return AVERROR_INTERRUPTED;
         av_log(NULL, AV_LOG_WARNING, "Unable to open %s\n", url);
         s->cur_seq_no++;
         goto retry;
diff --git a/libavformat/avio.c b/libavformat/avio.c
index 2265549..cf37b7e 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -238,7 +238,7 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int
            fast_retries = FFMAX(fast_retries, 2);
         len += ret;
         if (url_interrupt_cb())
-            return AVERROR(EINTR);
+            return AVERROR_INTERRUPTED;
     }
     return len;
 }
diff --git a/libavformat/avio.h b/libavformat/avio.h
index dd4380e..34f64b9 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -237,7 +237,7 @@ void url_get_filename(URLContext *h, char *buf, int buf_size);
 
 /**
  * The callback is called in blocking functions to test regulary if
- * asynchronous interruption is needed. AVERROR(EINTR) is returned
+ * asynchronous interruption is needed. AVERROR_INTERRUPTED is returned
  * in this case by the interrupted function. 'NULL' means no interrupt
  * callback is given.
  */
diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c
index 269b1b2..85e7eb6 100644
--- a/libavformat/rtpproto.c
+++ b/libavformat/rtpproto.c
@@ -241,7 +241,7 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size)
 #else
     for(;;) {
         if (url_interrupt_cb())
-            return AVERROR(EINTR);
+            return AVERROR_INTERRUPTED;
         /* build fdset to listen to RTP and RTCP packets */
         n = poll(p, 2, 100);
         if (n > 0) {
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index a24f12b..0d1eb71 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -1565,7 +1565,7 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
 
     for (;;) {
         if (url_interrupt_cb())
-            return AVERROR(EINTR);
+            return AVERROR_INTERRUPTED;
         if (wait_end && wait_end - av_gettime() < 0)
             return AVERROR(EAGAIN);
         max_p = 0;
diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index b01f0b8..1cc30c3 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -73,8 +73,10 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
     if (ret < 0) {
         struct pollfd p = {fd, POLLOUT, 0};
         if (ff_neterrno() == AVERROR(EINTR)) {
-            if (url_interrupt_cb())
+            if (url_interrupt_cb()) {
+                ret = AVERROR_INTERRUPTED;
                 goto fail1;
+            }
             goto redo;
         }
         if (ff_neterrno() != AVERROR(EINPROGRESS) &&
@@ -84,7 +86,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
         /* wait until we are connected or until abort */
         for(;;) {
             if (url_interrupt_cb()) {
-                ret = AVERROR(EINTR);
+                ret = AVERROR_INTERRUPTED;
                 goto fail1;
             }
             ret = poll(&p, 1, 100);
diff --git a/libavformat/udp.c b/libavformat/udp.c
index 0196573..e84bc40 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -452,7 +452,7 @@ static int udp_read(URLContext *h, uint8_t *buf, int size)
 
     for(;;) {
         if (url_interrupt_cb())
-            return AVERROR(EINTR);
+            return AVERROR_INTERRUPTED;
         ret = poll(&p, 1, 100);
         if (ret < 0) {
             if (ff_neterrno() == AVERROR(EINTR))
diff --git a/libavformat/utils.c b/libavformat/utils.c
index ccf9c65..4236aa3 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2267,7 +2267,7 @@ int av_find_stream_info(AVFormatContext *ic)
     read_size = 0;
     for(;;) {
         if(url_interrupt_cb()){
-            ret= AVERROR(EINTR);
+            ret= AVERROR_INTERRUPTED;
             av_log(ic, AV_LOG_DEBUG, "interrupted\n");
             break;
         }
-- 
1.7.2.3




More information about the ffmpeg-devel mailing list