diff mbox series

[FFmpeg-devel,v5,2/2] libavformat/dashenc: Enable HTTP persistent connections for dashenc_delete_file

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

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Basel Sayeh Dec. 6, 2022, 2:36 p.m. UTC
Signed-off-by: Basel Sayeh <basel.sayeh@hotmail.com>
---
 libavformat/dashenc.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 9c1bcad9e3..ba0eb913a1 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -179,6 +179,7 @@  typedef struct DASHContext {
     int master_playlist_created;
     AVIOContext *mpd_out;
     AVIOContext *m3u8_out;
+    AVIOContext *http_delete;
     int streaming;
     int64_t timeout;
     int index_correction;
@@ -642,6 +643,7 @@  static void dash_free(AVFormatContext *s)
 
     ff_format_io_close(s, &c->mpd_out);
     ff_format_io_close(s, &c->m3u8_out);
+    ff_format_io_close(s, &c->http_delete);
 }
 
 static void output_segment_list(OutputStream *os, AVIOContext *out, AVFormatContext *s,
@@ -1855,18 +1857,22 @@  static void dashenc_delete_file(AVFormatContext *s, char *filename) {
     int http_base_proto = ff_is_http_proto(filename);
 
     if (http_base_proto) {
-        AVIOContext *out = NULL;
         AVDictionary *http_opts = NULL;
 
         set_http_options(&http_opts, c);
         av_dict_set(&http_opts, "method", "DELETE", 0);
 
-        if (dashenc_io_open(s, &out, filename, &http_opts) < 0) {
+        if (dashenc_io_open(s, &c->http_delete, filename, &http_opts) < 0) {
             av_log(s, AV_LOG_ERROR, "failed to delete %s\n", filename);
+        } else {
+            //Nothing to write
+            avio_flush(c->http_delete);
+            dashenc_io_close(s, &c->http_delete, filename);
         }
-
         av_dict_free(&http_opts);
-        ff_format_io_close(s, &out);
+
+        if (!c->http_persistent)
+            ff_format_io_close(s, &c->http_delete);
     } else {
         int res = ffurl_delete(filename);
         if (res < 0) {