Commit 3b795725ef for ffmpeg
commit 3b795725efe7af9f6be3cb19adf2219ea22dfe6f
Author: Kacper Michajłow <kasper93@gmail.com>
Date: Wed Oct 28 00:01:04 2026 +0100
avformat/dashdec: index segment lists from their start number
The number of the current segment counts from the start number of the
Representation, but for a SegmentList it was used as the index into the
list. A list with startNumber="1", as the dash muxer writes for a single
file, skipped its first segment and then failed with "missing template
URL". On a manifest update, a live list moved the number by the change
of the start number, in the wrong direction and against the start number
of the first manifest, so it repeated segments and kept reloading at its
end. Index the list from the start number, and on an update keep the
number, take the start number of the new list and move to its first
segment when the number has left the list.
Limit startNumber to the range of xs:unsignedInt, its type in the
schema, so that the number of the last segment of a list cannot
overflow.
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index f2525bbe08..d57d9575cf 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -104,7 +104,6 @@ struct representation {
int64_t first_seq_no;
int64_t last_seq_no;
- int64_t start_number; /* used in case when we have dynamic list of segment to know which segments are new one*/
int64_t fragment_duration;
int64_t fragment_timescale;
@@ -890,11 +889,11 @@ end:
val = get_val_from_nodes_tab((arg), (cnt), "startNumber"); \
if (val) { \
int64_t start_number = (int64_t) strtoll(val, NULL, 10); \
- if (start_number < 0) { \
+ if (start_number < 0 || start_number > UINT32_MAX) { \
av_log(s, AV_LOG_WARNING, "startNumber invalid, autochanged to 0.\n"); \
start_number = 0; \
} \
- rep->start_number = rep->first_seq_no = start_number; \
+ rep->first_seq_no = start_number; \
av_log(s, AV_LOG_TRACE, "rep->first_seq_no = [%"PRId64"]\n", rep->first_seq_no); \
xmlFree(val); \
} \
@@ -1577,15 +1576,11 @@ static void move_segments(struct representation *rep_src, struct representation
{
if (rep_dest && rep_src ) {
free_fragment_list(rep_dest);
- if (rep_src->start_number > (rep_dest->start_number + rep_dest->n_fragments))
- rep_dest->cur_seq_no = 0;
- else {
- rep_dest->cur_seq_no += rep_src->start_number - rep_dest->start_number;
- if (rep_dest->cur_seq_no < 0)
- rep_dest->cur_seq_no = 0;
- }
+ if (rep_dest->cur_seq_no < rep_src->first_seq_no)
+ rep_dest->cur_seq_no = rep_src->first_seq_no;
rep_dest->fragments = rep_src->fragments;
rep_dest->n_fragments = rep_src->n_fragments;
+ rep_dest->first_seq_no = rep_src->first_seq_no;
rep_dest->parent = rep_src->parent;
rep_dest->last_seq_no = calc_max_seg_no(rep_dest, c);
rep_src->fragments = NULL;
@@ -1707,8 +1702,9 @@ static struct fragment *get_current_fragment(struct representation *pls)
int reload_count = 0;
while (( !ff_check_interrupt(c->interrupt_callback)&& pls->n_fragments > 0)) {
- if (pls->cur_seq_no >= 0 && pls->cur_seq_no < pls->n_fragments) {
- seg_ptr = pls->fragments[pls->cur_seq_no];
+ if (pls->cur_seq_no >= pls->first_seq_no &&
+ pls->cur_seq_no < pls->first_seq_no + pls->n_fragments) {
+ seg_ptr = pls->fragments[pls->cur_seq_no - pls->first_seq_no];
seg = av_mallocz(sizeof(struct fragment));
if (!seg) {
return NULL;