diff mbox series

[FFmpeg-devel,1/3] avformat/dashenc: make AdaptationSet id an integer value

Message ID 20200119214200.2369-1-jamrial@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,1/3] avformat/dashenc: make AdaptationSet id an integer value | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

James Almer Jan. 19, 2020, 9:41 p.m. UTC
Unlike Representation id, it's defined as an integer in the spec, and not as a
string.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/dashenc.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

Comments

James Almer Feb. 11, 2020, 1:40 p.m. UTC | #1
On 1/19/2020 6:41 PM, James Almer wrote:
> Unlike Representation id, it's defined as an integer in the spec, and not as a
> string.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/dashenc.c | 20 ++++++++++++++------
>  1 file changed, 14 insertions(+), 6 deletions(-)

I'll apply the set soon.
James Almer Feb. 16, 2020, 6:29 p.m. UTC | #2
On 2/11/2020 10:40 AM, James Almer wrote:
> On 1/19/2020 6:41 PM, James Almer wrote:
>> Unlike Representation id, it's defined as an integer in the spec, and not as a
>> string.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>  libavformat/dashenc.c | 20 ++++++++++++++------
>>  1 file changed, 14 insertions(+), 6 deletions(-)
> 
> I'll apply the set soon.

Applied.
diff mbox series

Patch

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 3d8515d9ca..243194d33e 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -80,7 +80,7 @@  typedef struct Segment {
 } Segment;
 
 typedef struct AdaptationSet {
-    char id[10];
+    int id;
     char *descriptor;
     int64_t seg_duration;
     int64_t frag_duration;
@@ -805,7 +805,7 @@  static int write_adaptation_set(AVFormatContext *s, AVIOContext *out, int as_ind
     AVDictionaryEntry *lang, *role;
     int i;
 
-    avio_printf(out, "\t\t<AdaptationSet id=\"%s\" contentType=\"%s\" segmentAlignment=\"true\" bitstreamSwitching=\"true\"",
+    avio_printf(out, "\t\t<AdaptationSet id=\"%d\" contentType=\"%s\" segmentAlignment=\"true\" bitstreamSwitching=\"true\"",
                 as->id, as->media_type == AVMEDIA_TYPE_VIDEO ? "video" : "audio");
     if (as->media_type == AVMEDIA_TYPE_VIDEO && as->max_frame_rate.num && !as->ambiguous_frame_rate && av_cmp_q(as->min_frame_rate, as->max_frame_rate) < 0)
         avio_printf(out, " maxFrameRate=\"%d/%d\"", as->max_frame_rate.num, as->max_frame_rate.den);
@@ -932,7 +932,7 @@  static int parse_adaptation_sets(AVFormatContext *s)
         for (i = 0; i < s->nb_streams; i++) {
             if ((ret = add_adaptation_set(s, &as, s->streams[i]->codecpar->codec_type)) < 0)
                 return ret;
-            snprintf(as->id, sizeof(as->id), "%d", i);
+            as->id = i;
 
             c->streams[i].as_idx = c->nb_as;
             ++as->nb_streams;
@@ -953,12 +953,20 @@  static int parse_adaptation_sets(AVFormatContext *s)
             p++;
             continue;
         } else if (state == new_set && av_strstart(p, "id=", &p)) {
+            char id_str[10], *end_str;
+
+            n = strcspn(p, ",");
+            snprintf(id_str, sizeof(id_str), "%.*s", n, p);
+
+            i = strtol(id_str, &end_str, 10);
+            if (id_str == end_str || i < 0 || i > c->nb_as) {
+                av_log(s, AV_LOG_ERROR, "\"%s\" is not a valid value for an AdaptationSet id\n", id_str);
+                return AVERROR(EINVAL);
+            }
 
             if ((ret = add_adaptation_set(s, &as, AVMEDIA_TYPE_UNKNOWN)) < 0)
                 return ret;
-
-            n = strcspn(p, ",");
-            snprintf(as->id, sizeof(as->id), "%.*s", n, p);
+            as->id = i;
 
             p += n;
             if (*p)