This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 0e164cf74ada548b7e3b3359dcffe2024a989edf
Author:     Matthew Crossley <[email protected]>
AuthorDate: Fri Nov 6 12:11:26 2026 +0000
Commit:     stevenliu <[email protected]>
CommitDate: Tue Nov 17 00:24:10 2026 +0000

    avformat/dashdec: pace fragment-open retries to avoid exhausting max 
reloads on live content
    
    Mirror the sleep mechanism from HLS demuxer's `reload_playlist`.
    
    Demuxer would attempt to open fragments that do not yet exist in manifest 
and burn through
    allowed reloads before fragment is written.
    
    When next segment beyond advertised range of manifest, sleep for half a 
segment duration
    (or minimumUpdatePeriod if not available) then refresh before retrying.
    Open-ended timelines (negative repeats), SegmentList and duration-only 
representations are not paced,
    since the advertised range cannot be relied on for them.
    
    Subtitles and representations with a nonpositive parsed timescale are
    also excluded from pacing. A positive minimumUpdatePeriod caps the
    polling interval.
    
    Treat absent minimumUpdatePeriod as unset (-1) instead of 0, restore it if 
refresh fails.
    
    Signed-off-by: Matthew Crossley <[email protected]>
---
 libavformat/dashdec.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 64 insertions(+), 6 deletions(-)

diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index f6fa1ca511..85fb709c26 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -85,6 +85,7 @@ struct representation {
     AVFormatContext *parent;
     AVFormatContext *ctx;
     int stream_index;
+    enum AVMediaType type;
 
     char *id;
     char *lang;
@@ -1164,6 +1165,7 @@ static int parse_manifest_representation(AVFormatContext 
*s, const char *url,
         }
     }
 
+    rep->type = type;
     switch (type) {
     case AVMEDIA_TYPE_VIDEO:
         ret = av_dynarray_add_nofree(&c->videos, &c->n_videos, rep);
@@ -1370,6 +1372,8 @@ static int parse_manifest(AVFormatContext *s, const char 
*url, AVIOContext *in)
             c->is_live = 1;
         xmlFree(val);
 
+        c->minimum_update_period = -1;
+
         attr = node->properties;
         while (attr) {
             val = xmlGetProp(node, attr->name);
@@ -1602,6 +1606,7 @@ static int refresh_manifest(AVFormatContext *s)
     int n_subtitles = c->n_subtitles;
     struct representation **subtitles = c->subtitles;
     char *base_url = c->base_url;
+    int64_t minimum_update_period = c->minimum_update_period;
 
     c->base_url = NULL;
     c->n_videos = 0;
@@ -1610,6 +1615,7 @@ static int refresh_manifest(AVFormatContext *s)
     c->audios = NULL;
     c->n_subtitles = 0;
     c->subtitles = NULL;
+    c->minimum_update_period = -1;
     ret = parse_manifest(s, s->url, NULL);
     if (ret)
         goto finish;
@@ -1672,6 +1678,8 @@ finish:
         av_free(base_url);
     else
         c->base_url  = base_url;
+    if (ret)
+        c->minimum_update_period = minimum_update_period;
 
     if (c->subtitles)
         free_subtitle_list(c);
@@ -1726,10 +1734,12 @@ static struct fragment *get_current_fragment(struct 
representation *pls)
         }
     }
     if (c->is_live) {
-        min_seq_no = calc_min_seg_no(pls->parent, pls);
-        max_seq_no = calc_max_seg_no(pls, c);
-
-        if (pls->timelines || pls->fragments) {
+        int64_t reload_interval;
+        int64_t last_load;
+        int can_refresh;
+reload:
+        can_refresh = pls->timelines || pls->fragments;
+        if (can_refresh) {
             refresh_manifest(pls->parent);
         }
         min_seq_no = calc_min_seg_no(pls->parent, pls);
@@ -1740,6 +1750,54 @@ static struct fragment *get_current_fragment(struct 
representation *pls)
             pls->cur_seq_no = calc_cur_seg_no(pls->parent, pls);
         } else if (pls->cur_seq_no > max_seq_no) {
             av_log(pls->parent, AV_LOG_VERBOSE, "new fragment: min[%"PRId64"] 
max[%"PRId64"]\n", min_seq_no, max_seq_no);
+
+            int has_negative_repeat = 0;
+            for (int i = 0; i < pls->n_timelines; i++)
+                has_negative_repeat |= pls->timelines[i]->repeat < 0;
+
+            /* Only wait if refresh can reveal new segments or finalisation:
+             * can_refresh/minimum_update_period: manifest is dynamic and 
still updating
+             * type: subtitles must not block audio/video
+             * n_timelines: SegmentTimeline tells us where the end is
+             * has_negative_repeat: max_seq_no cannot be derived with negative 
repeats
+             * fragment_timescale: needed to compute poll interval */
+            if (
+                can_refresh &&
+                c->minimum_update_period != -1 &&
+                pls->type != AVMEDIA_TYPE_SUBTITLE &&
+                pls->n_timelines &&
+                !has_negative_repeat &&
+                pls->fragment_timescale > 0
+            ) {
+                reload_count++;
+                if (reload_count > c->max_reload) {
+                    av_log(pls->parent, AV_LOG_ERROR,
+                       "Reached max manifest reloads (%d) at seq %"PRId64"\n",
+                       c->max_reload, pls->cur_seq_no);
+                    return NULL;
+                }
+
+                /* Poll at half a segment duration, falling back to the
+                 * update period, with a floor to avoid busy-looping. */
+                int64_t duration = pls->fragment_duration <= 0 ?
+                                   pls->timelines[pls->n_timelines - 
1]->duration :
+                                   pls->fragment_duration;
+                reload_interval = duration > 0 ?
+                                  av_rescale(duration, AV_TIME_BASE, 
pls->fragment_timescale) :
+                                  c->minimum_update_period * AV_TIME_BASE;
+                reload_interval = FFMAX(reload_interval / 2, 100 * 1000);
+                if (c->minimum_update_period > 0)
+                    reload_interval = FFMIN(reload_interval,
+                                            c->minimum_update_period * 
AV_TIME_BASE);
+
+                last_load = av_gettime_relative();
+                while (av_gettime_relative() - last_load < reload_interval) {
+                    if (ff_check_interrupt(c->interrupt_callback))
+                        return NULL;
+                    av_usleep(100*1000);
+                }
+                goto reload;
+            }
         }
         seg = av_mallocz(sizeof(struct fragment));
         if (!seg) {
@@ -1900,7 +1958,7 @@ restart:
         free_fragment(&v->cur_seg);
         v->cur_seg = get_current_fragment(v);
         if (!v->cur_seg) {
-            ret = AVERROR_EOF;
+            ret = ff_check_interrupt(c->interrupt_callback) ? AVERROR_EXIT : 
AVERROR_EOF;
             goto end;
         }
 
@@ -1943,7 +2001,7 @@ restart:
         v->cur_seg = get_current_fragment(v);
     }
     if (!v->cur_seg) {
-        ret = AVERROR_EOF;
+        ret = ff_check_interrupt(c->interrupt_callback) ? AVERROR_EXIT : 
AVERROR_EOF;
         goto end;
     }
     ret = read_from_url(v, v->cur_seg, buf, buf_size);

-- 
To stop receiving notification emails like this one, please contact
[email protected].
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to