1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-15 14:13:16 +02:00

libavformat/hlsenc: Enable HTTP persistent connections for hls_delete_file

Removed the unnecessary calls to ff_format_io_close
this patch introduced in hls_delete_file.
hls_delete_file functions open a new HTTP connection
regardless of the http_persistent value,
So change their behaviour to keep http connections open
if http_persistent is set

Signed-off-by: Basel Sayeh <basel.sayeh@hotmail.com>
This commit is contained in:
Basel Sayeh
2023-01-07 03:15:40 +03:00
committed by Steven Liu
parent 54c488223b
commit 77ad210fba

View File

@@ -252,6 +252,7 @@ typedef struct HLSContext {
int http_persistent; int http_persistent;
AVIOContext *m3u8_out; AVIOContext *m3u8_out;
AVIOContext *sub_m3u8_out; AVIOContext *sub_m3u8_out;
AVIOContext *http_delete;
int64_t timeout; int64_t timeout;
int ignore_io_errors; int ignore_io_errors;
char *headers; char *headers;
@@ -565,19 +566,22 @@ static void reflush_dynbuf(VariantStream *vs, int *range_length)
#endif #endif
static int hls_delete_file(HLSContext *hls, AVFormatContext *avf, static int hls_delete_file(HLSContext *hls, AVFormatContext *avf,
const char *path, const char *proto) char *path, const char *proto)
{ {
if (hls->method || (proto && !av_strcasecmp(proto, "http"))) { if (hls->method || (proto && !av_strcasecmp(proto, "http"))) {
AVDictionary *opt = NULL; AVDictionary *opt = NULL;
AVIOContext *out = NULL;
int ret; int ret;
set_http_options(avf, &opt, hls); set_http_options(avf, &opt, hls);
av_dict_set(&opt, "method", "DELETE", 0); 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); av_dict_free(&opt);
if (ret < 0) if (ret < 0)
return hls->ignore_io_errors ? 1 : ret; return hls->ignore_io_errors ? 1 : ret;
ff_format_io_close(avf, &out);
//Nothing to write
hlsenc_io_close(avf, &hls->http_delete, path);
} else if (unlink(path) < 0) { } else if (unlink(path) < 0) {
av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s: %s\n", av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s: %s\n",
path, strerror(errno)); path, strerror(errno));
@@ -662,7 +666,7 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
} }
proto = avio_find_protocol_name(s->url); 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; goto fail;
if ((segment->sub_filename[0] != '\0')) { if ((segment->sub_filename[0] != '\0')) {
@@ -679,7 +683,7 @@ static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
goto fail; 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; goto fail;
} }
av_bprint_clear(&path); av_bprint_clear(&path);
@@ -2707,6 +2711,7 @@ static void hls_deinit(AVFormatContext *s)
ff_format_io_close(s, &hls->m3u8_out); ff_format_io_close(s, &hls->m3u8_out);
ff_format_io_close(s, &hls->sub_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->key_basename);
av_freep(&hls->var_streams); av_freep(&hls->var_streams);
av_freep(&hls->cc_streams); av_freep(&hls->cc_streams);