diff mbox series

[FFmpeg-devel] Added support to get specific periods from the mpeg-dash demuxer instead of just the longest one.

Message ID 20241023165150.26202-1-lletourn49@gmail.com
State New
Headers show
Series [FFmpeg-devel] Added support to get specific periods from the mpeg-dash demuxer instead of just the longest one. | expand

Checks

Context Check Description
yinshiyou/commit_msg_loongarch64 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".

Commit Message

Louis Letourneau Oct. 23, 2024, 4:51 p.m. UTC
From: Louis Letourneau <lletourn49@gmail.com>

---
 libavformat/dashdec.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index a1d274f2f0..345454e6b6 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -150,6 +150,7 @@  typedef struct DASHContext {
 
     int is_live;
     AVIOInterruptCB *interrupt_callback;
+    int64_t period_index;
     char *allowed_extensions;
     AVDictionary *avio_opts;
     int max_url_size;
@@ -1220,6 +1221,7 @@  static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in)
     char *val  = NULL;
     uint32_t period_duration_sec = 0;
     uint32_t period_start_sec = 0;
+    int64_t period_index = -1;
 
     if (!in) {
         close_in = 1;
@@ -1314,6 +1316,7 @@  static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in)
         // at now we can handle only one period, with the longest duration
         node = xmlFirstElementChild(node);
         while (node) {
+            period_index++;
             if (!av_strcasecmp(node->name, "Period")) {
                 period_duration_sec = 0;
                 period_start_sec = 0;
@@ -1328,13 +1331,15 @@  static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in)
                     attr = attr->next;
                     xmlFree(val);
                 }
-                if ((period_duration_sec) >= (c->period_duration)) {
+                if ((period_duration_sec) >= (c->period_duration) || period_index == c->period_index) {
                     period_node = node;
                     c->period_duration = period_duration_sec;
                     c->period_start = period_start_sec;
                     if (c->period_start > 0)
                         c->media_presentation_duration = c->period_duration;
                 }
+                if(period_index == c->period_index)
+                    break;
             } else if (!av_strcasecmp(node->name, "ProgramInformation")) {
                 parse_programinformation(s, node);
             }
@@ -1345,6 +1350,11 @@  static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in)
             ret = AVERROR_INVALIDDATA;
             goto cleanup;
         }
+        if(c->period_index > period_index) {
+            av_log(s, AV_LOG_ERROR, "Period index out of bounds. Asked '%ld' vs Highest period index '%ld'\n", c->period_index, period_index);
+            ret = AVERROR_INVALIDDATA;
+            goto cleanup;
+        }
 
         adaptionset_node = xmlFirstElementChild(period_node);
         while (adaptionset_node) {
@@ -2341,6 +2351,8 @@  static int dash_probe(const AVProbeData *p)
 #define OFFSET(x) offsetof(DASHContext, x)
 #define FLAGS AV_OPT_FLAG_DECODING_PARAM
 static const AVOption dash_options[] = {
+    {"period_index", "Period to use in a multi period dash. If negative, the longest period is used",
+        OFFSET(period_index), AV_OPT_TYPE_INT64, {.i64 = -1}, INT_MIN, INT_MAX, FLAGS},
     {"allowed_extensions", "List of file extensions that dash is allowed to access",
         OFFSET(allowed_extensions), AV_OPT_TYPE_STRING,
         {.str = "aac,m4a,m4s,m4v,mov,mp4,webm,ts"},