diff mbox series

[FFmpeg-devel,v2,1/2] libavformat/hlsenc: Enable HTTP persistent connections for hls_delete_file

Message ID DB9P191MB14820D3E4B6892727B2594ABFE189@DB9P191MB1482.EURP191.PROD.OUTLOOK.COM
State New
Headers show
Series [FFmpeg-devel,v2,1/2] libavformat/hlsenc: Enable HTTP persistent connections for hls_delete_file | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 fail Make failed
andriy/make_x86 fail Make failed

Commit Message

Basel Sayeh Dec. 5, 2022, 12:22 p.m. UTC
hls_delete_file and dashenc_delete_file functions open a
 new HTTP connection regardless of the http_persistent value,
 So change the behaviour to keep http connections open
 if http_persistent is set

Signed-off-by: Basel Sayeh <basel.sayeh@hotmail.com>
---
 libavformat/hlsenc.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

Comments

Basel Sayeh Dec. 5, 2022, 12:32 p.m. UTC | #1
oops, another small mistake, please see v3
diff mbox series

Patch

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index a86fc8907f..a23c17eea2 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -252,6 +252,7 @@  typedef struct HLSContext {
     int http_persistent;
     AVIOContext *m3u8_out;
     AVIOContext *sub_m3u8_out;
+    AVIOContext *http_delete;
     int64_t timeout;
     int ignore_io_errors;
     char *headers;
@@ -569,15 +570,21 @@  static int hls_delete_file(HLSContext *hls, AVFormatContext *avf,
 {
     if (hls->method || (proto && !av_strcasecmp(proto, "http"))) {
         AVDictionary *opt = NULL;
-        AVIOContext  *out = NULL;
         int ret;
+
         set_http_options(avf, &opt, hls);
         av_dict_set(&opt, "method", "DELETE", 0);
-        ret = avf->io_open(avf, &out, path, AVIO_FLAG_WRITE, &opt);
+        ret = hlsenc_io_open(avf, &hls->http_delete, path, &opt);
         av_dict_free(&opt);
         if (ret < 0)
             return hls->ignore_io_errors ? 1 : ret;
-        ff_format_io_close(avf, &out);
+
+        //Nothing to write
+        avio_flush(hls->http_delete);
+        hlsenc_io_close(avf, &hls->http_delete, path);
+
+        if (!hls->http_persistent)
+            ff_format_io_close(avf, &out);
     } else if (unlink(path) < 0) {
         av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s: %s\n",
                path, strerror(errno));
@@ -662,7 +669,7 @@  static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
         }
 
         proto = avio_find_protocol_name(s->url);
-        if (ret = hls_delete_file(hls, vs->avf, path.str, proto))
+        if (ret = hls_delete_file(hls, s, path.str, proto))
             goto fail;
 
         if ((segment->sub_filename[0] != '\0')) {
@@ -679,7 +686,7 @@  static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
                 goto fail;
             }
 
-            if (ret = hls_delete_file(hls, vs->vtt_avf, path.str, proto))
+            if (ret = hls_delete_file(hls, s, path.str, proto))
                 goto fail;
         }
         av_bprint_clear(&path);
@@ -2707,6 +2714,7 @@  static void hls_deinit(AVFormatContext *s)
 
     ff_format_io_close(s, &hls->m3u8_out);
     ff_format_io_close(s, &hls->sub_m3u8_out);
+    ff_format_io_close(s, &hls->http_delete);
     av_freep(&hls->key_basename);
     av_freep(&hls->var_streams);
     av_freep(&hls->cc_streams);