[FFmpeg-devel] fix ftp hang up because not return AVRRROR_EOF

Jan Ekström jeebjp at gmail.com
Wed Jun 13 21:18:32 EEST 2018


On Wed, Jun 13, 2018 at 1:27 PM, Gj X <xiong2634528861 at gmail.com> wrote:
> fix:
> diff --git a/libavformat/ftp.c b/libavformat/ftp.c
> index 9aa7a45629..3474a0adbc 100644
> --- a/libavformat/ftp.c
> +++ b/libavformat/ftp.c
> @@ -777,7 +777,11 @@ static int ftp_read(URLContext *h, unsigned char *buf,
> int size)
>  {
>      FTPContext *s = h->priv_data;
>      int read, err, retry_done = 0;
> -
> +    if(s->position >= s->filesize)
> +    {
> +        ff_dlog(h,"ftp protocol reach file end\n");
> +        return AVERROR_EOF;
> +    }
>      ff_dlog(h, "ftp protocol read %d bytes\n", size);
>    retry:
>      if (s->state == DISCONNECTED) {
>

Hi,

Thanks for your contribution. I just looked at that function and it
seems like `ftp_read` needs some improvement.

But staying on the 0 != EOF fixup topic, probably something like this
should prod it to work:

diff --git a/libavformat/ftp.c b/libavformat/ftp.c
index 9aa7a45629..f07e9fcdd9 100644
--- a/libavformat/ftp.c
+++ b/libavformat/ftp.c
@@ -783,13 +783,13 @@ static int ftp_read(URLContext *h, unsigned char
*buf, int size)
     if (s->state == DISCONNECTED) {
         /* optimization */
         if (s->position >= s->filesize)
-            return 0;
+            return AVERROR_EOF;
         if ((err = ftp_connect_data_connection(h)) < 0)
             return err;
     }
     if (s->state == READY) {
         if (s->position >= s->filesize)
-            return 0;
+            return AVERROR_EOF;
         if ((err = ftp_retrieve(s)) < 0)
             return err;
     }
@@ -823,7 +823,7 @@ static int ftp_read(URLContext *h, unsigned char
*buf, int size)
                 goto retry;
             }
         }
-        return read;
+        return read ? read : AVERROR_EOF;
     }

     av_log(h, AV_LOG_DEBUG, "FTP read failed\n");


More information about the ffmpeg-devel mailing list