PR #25413 opened by danog
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25413
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25413.patch

Each reload of a live playlist allocates new init sections, so the
pointer check in update_init_section() failed for every new segment and
the section was downloaded again after each reload. The download also
closes the persistent connection, so fMP4 live streams opened a new
connection for nearly every segment.

Treat a section with the same URL, byte range and key as unchanged.

Signed-off-by: Daniil Gentili <[email protected]>



>From d85369bf9ba714c918da35d66a506529fbbb7bed Mon Sep 17 00:00:00 2001
From: Daniil Gentili <[email protected]>
Date: Sat, 24 Oct 2026 10:57:24 +0200
Subject: [PATCH] avformat/hls: don't reload an unchanged init section

Each reload of a live playlist allocates new init sections, so the
pointer check in update_init_section() failed for every new segment and
the section was downloaded again after each reload. The download also
closes the persistent connection, so fMP4 live streams opened a new
connection for nearly every segment.

Treat a section with the same URL, byte range and key as unchanged.

Signed-off-by: Daniil Gentili <[email protected]>
---
 libavformat/hls.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index c68b5e88cf5..8c1059832ca 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -1707,6 +1707,15 @@ cleanup:
     return ret;
 }
 
+static int same_init_section(const struct segment *a, const struct segment *b)
+{
+    return a && b && !strcmp(a->url, b->url) &&
+           a->url_offset == b->url_offset && a->size == b->size &&
+           a->key_type == b->key_type &&
+           (a->key_type == KEY_NONE ||
+            (!strcmp(a->key, b->key) && !memcmp(a->iv, b->iv, sizeof(a->iv))));
+}
+
 static int update_init_section(struct playlist *pls, struct segment *seg)
 {
     static const int max_init_section_size = 1024*1024;
@@ -1718,6 +1727,12 @@ static int update_init_section(struct playlist *pls, 
struct segment *seg)
     if (seg->init_section == pls->cur_init_section)
         return 0;
 
+    /* A reloaded live playlist lists the same section again. */
+    if (same_init_section(seg->init_section, pls->cur_init_section)) {
+        pls->cur_init_section = seg->init_section;
+        return 0;
+    }
+
     pls->cur_init_section = NULL;
 
     if (!seg->init_section)
-- 
2.54.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to