[FFmpeg-devel] [Patch] Download dash content with byte range info

Colin NG colin_ng at hotmail.com
Wed Nov 15 23:00:12 EET 2017


This patch is partial fix for ticket 6658 (Dash demuxer segfault).


________________________________
From: ffmpeg-devel <ffmpeg-devel-bounces at ffmpeg.org> on behalf of Steven Liu <lingjiujianke at gmail.com>
Sent: November 15, 2017 2:58 AM
To: FFmpeg development discussions and patches
Subject: Re: [FFmpeg-devel] [Patch] Download dash content with byte range info

2017-11-15 10:26 GMT+08:00 Colin NG <colin_ng at hotmail.com>:
> Please ignore the previous "patch" email.
>
>
>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index 0e3afd2..68196e9 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -522,6 +522,22 @@ static enum AVMediaType get_content_type(xmlNodePtr node)
     return type;
 }

+static struct fragment * getFragment(char *range)
Camel-Case code style, please use name looks like : get_fragment

+{
+    struct fragment * seg =  av_mallocz(sizeof(struct fragment));
check the seg , if av_mallocz is failed, it will error;
+
+    memset(seg, 0, sizeof(struct fragment));
unnecessary memset, because av_mallocz is set seg to 0 already.

+    seg->size = -1;
+    if (range)  {
+        char *str_end_offset;
+        char *str_offset = av_strtok(range, "-", &str_end_offset);
+        seg->url_offset = strtoll(str_offset, NULL, 10);
+        seg->size = strtoll(str_end_offset, NULL, 10) -seg->url_offset;
+    }
+
+    return seg;
+}
+
 static int parse_manifest_segmenturlnode(AVFormatContext *s, struct
representation *rep,
                                          xmlNodePtr fragmenturl_node,
                                          xmlNodePtr *baseurl_nodes,
@@ -530,11 +546,13 @@ static int
parse_manifest_segmenturlnode(AVFormatContext *s, struct representati
 {
     char *initialization_val = NULL;
     char *media_val = NULL;
+    char *range_val = NULL;

     if (!av_strcasecmp(fragmenturl_node->name, (const char
*)"Initialization")) {
         initialization_val = xmlGetProp(fragmenturl_node, "sourceURL");
-        if (initialization_val) {
-            rep->init_section = av_mallocz(sizeof(struct fragment));
+        range_val = xmlGetProp(fragmenturl_node, "range");
+        if (initialization_val || range_val) {
+            rep->init_section = getFragment(range_val);// byte range on
             if (!rep->init_section) {
                 xmlFree(initialization_val);
                 return AVERROR(ENOMEM);
@@ -550,11 +568,13 @@ static int
parse_manifest_segmenturlnode(AVFormatContext *s, struct representati
             }
             rep->init_section->size = -1;
             xmlFree(initialization_val);
+            xmlFree(range_val);
         }
     } else if (!av_strcasecmp(fragmenturl_node->name, (const char
*)"SegmentURL")) {
         media_val = xmlGetProp(fragmenturl_node, "media");
-        if (media_val) {
-            struct fragment *seg = av_mallocz(sizeof(struct fragment));
+        range_val = xmlGetProp(fragmenturl_node, "mediaRange");
+        if (media_val || range_val) {
+            struct fragment *seg =  getFragment(range_val);// byte range on
             if (!seg) {
                 xmlFree(media_val);
                 return AVERROR(ENOMEM);
@@ -571,12 +591,12 @@ static int
parse_manifest_segmenturlnode(AVFormatContext *s, struct representati
             seg->size = -1;
             dynarray_add(&rep->fragments, &rep->n_fragments, seg);
             xmlFree(media_val);
+            xmlFree(range_val);
         }
     }

     return 0;
 }
-
 static int parse_manifest_segmenttimeline(AVFormatContext *s, struct
representation *rep,
                                           xmlNodePtr fragment_timeline_node)
 {
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel at ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
ffmpeg-devel Info Page<http://ffmpeg.org/mailman/listinfo/ffmpeg-devel>
ffmpeg.org
This list is about FFmpeg development discussions and patches; but not for bug-reports. Please read the Code-of-conduct. To see the collection of prior postings to ...


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: diff2.txt
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20171115/eda9e333/attachment.txt>


More information about the ffmpeg-devel mailing list