diff mbox series

[FFmpeg-devel,RFC] Reconnect and PUT file continue by ffmpeg base https on windows

Message ID EEDB7589-1DDC-4F94-B5D3-436C4CD857A4@chinaffmpeg.org
State New
Headers show
Series [FFmpeg-devel,RFC] Reconnect and PUT file continue by ffmpeg base https on windows | expand

Checks

Context Check Description
andriy/configurex86 warning Failed to apply patch

Commit Message

Steven Liu Sept. 11, 2021, 9:45 a.m. UTC
Hello everyone,

    There have two tickets about Reconnect and PUT file continue by hlsenc.
    The first one is https://trac.ffmpeg.org/ticket/7975.
    It be fixed use the way ff_http_get_shutdown_status after furl_shutdown,
    But it get second problem.
    The ff_http_get_shutdown_status will block in Schannel on windows operating system in http_persistent mode.
    It’s ok by other operating system or non http_persistent mode.
    I think three ways to fix the new problem https://trac.ffmpeg.org/ticket/9010 but i cannot sure which way should better.


First way:
set socket flags of tcp NONBLOCK
-----------------------------------------
$ git diff
-----------------------------------------
I think this is not pretty. :(
There maybe have some other ways, Do you have some suggestions.

Thanks
Steven
diff mbox series

Patch

diff --git a/libavformat/tls_schannel.c b/libavformat/tls_schannel.c
index d4959f75fa..f5d048f9e5 100644
--- a/libavformat/tls_schannel.c
+++ b/libavformat/tls_schannel.c
@@ -414,14 +414,15 @@  static int tls_read(URLContext *h, uint8_t *buf, int len)
                return ret;
            }
        }
-
+    c->tls_shared.tcp->flags &= ~AVIO_FLAG_NONBLOCK;
+    c->tls_shared.tcp->flags |= h->flags & AVIO_FLAG_NONBLOCK;
        ret = ffurl_read(s->tcp, c->enc_buf + c->enc_buf_offset,
                         c->enc_buf_size - c->enc_buf_offset);
        if (ret == AVERROR_EOF) {
            c->connection_closed = 1;
            ret = 0;
        } else if (ret < 0) {
-            av_log(h, AV_LOG_ERROR, "Unable to read from socket\n");
+            av_log(h, AV_LOG_ERROR, "Unable to read from socket ret = [%s]\n", av_err2str(ret));
            return ret;
        }

-----------------------------------------
This way will get error code when ret < 0,
but all the hls PUT will success process,
there maybe have some risk for other module if merge this modify,
-----------------------------------------
Second way:
$ git diff
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 7c37bc50b9..86cdb897a4 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -314,9 +314,11 @@  static int hlsenc_io_close(AVFormatContext *s, AVIOContext **pb, char *filename)
#if CONFIG_HTTP_PROTOCOL
    } else {
        URLContext *http_url_context = ffio_geturlcontext(*pb);
+        const char *proto = avio_find_protocol_name(filename);
        av_assert0(http_url_context);
        avio_flush(*pb);
        ffurl_shutdown(http_url_context, AVIO_FLAG_WRITE);
+    if (av_strcasecmp(proto, "https"))
        ret = ff_http_get_shutdown_status(http_url_context);
#endif
    }

-----------------------------------------
This way can fix the problem too,
But this will ignore all the http status which return from server base on all operating systems.


Third way:
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 7c37bc50b9..0ede8856a4 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -317,7 +317,9 @@  static int hlsenc_io_close(AVFormatContext *s, AVIOContext **pb, char *filename)
        av_assert0(http_url_context);
        avio_flush(*pb);
        ffurl_shutdown(http_url_context, AVIO_FLAG_WRITE);
+#if !CONFIG_SCHANNEL
        ret = ff_http_get_shutdown_status(http_url_context);
+#endif
#endif
    }
    return ret;