[FFmpeg-cvslog] ftp: reconnect on tcp read error

Lukasz Marek git at videolan.org
Sat Jun 8 16:05:28 CEST 2013


ffmpeg | branch: master | Lukasz Marek <lukasz.m.luki at gmail.com> | Sun Jun  2 01:41:03 2013 +0200| [23a76b71deead18fb75fc1f5af7281940778afb5] | committer: Lukasz Marek

ftp: reconnect on tcp read error

This commit reconnect both connections and retries before ftp_read returns an error.
Practical use case: resume after lock screen on iOS devices.

Signed-off-by: Lukasz Marek <lukasz.m.luki at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=23a76b71deead18fb75fc1f5af7281940778afb5
---

 libavformat/ftp.c |   15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/libavformat/ftp.c b/libavformat/ftp.c
index faa82dd..e818b8b 100644
--- a/libavformat/ftp.c
+++ b/libavformat/ftp.c
@@ -499,8 +499,10 @@ static int ftp_abort(URLContext *h)
 {
     int err;
     ftp_close_both_connections(h->priv_data);
-    if ((err = ftp_connect_control_connection(h)) < 0)
+    if ((err = ftp_connect_control_connection(h)) < 0) {
+        av_log(h, AV_LOG_ERROR, "Reconnect failed.\n");
         return err;
+    }
     return 0;
 }
 
@@ -602,10 +604,14 @@ static int ftp_read(URLContext *h, unsigned char *buf, int size)
     av_dlog(h, "ftp protocol read %d bytes\n", size);
   retry:
     if (s->state == DISCONNECTED) {
+        if (s->position >= s->filesize)
+            return 0;
         if ((err = ftp_connect_data_connection(h)) < 0)
             return err;
     }
     if (s->state == READY) {
+        if (s->position >= s->filesize)
+            return 0;
         if ((err = ftp_retrieve(s)) < 0)
             return err;
     }
@@ -618,15 +624,12 @@ static int ftp_read(URLContext *h, unsigned char *buf, int size)
                     return AVERROR(EIO);
             }
         }
-        if (!read && s->position < s->filesize && !h->is_streamed) {
+        if (read <= 0 && s->position < s->filesize && !h->is_streamed) {
             /* Server closed connection. Probably due to inactivity */
-            /* TODO: Consider retry before reconnect */
             int64_t pos = s->position;
             av_log(h, AV_LOG_INFO, "Reconnect to FTP server.\n");
-            if ((err = ftp_abort(h)) < 0) {
-                av_log(h, AV_LOG_ERROR, "Reconnect failed.\n");
+            if ((err = ftp_abort(h)) < 0)
                 return err;
-            }
             if ((err = ftp_seek(h, pos, SEEK_SET)) < 0) {
                 av_log(h, AV_LOG_ERROR, "Position cannot be restored.\n");
                 return err;



More information about the ffmpeg-cvslog mailing list