diff mbox

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

Message ID DM5PR22MB068111352AD8A3DA668A15D0FE2E0@DM5PR22MB0681.namprd22.prod.outlook.com
State Superseded
Headers show

Commit Message

Colin NG Nov. 16, 2017, 12:59 a.m. UTC
Made change suggested by Carl and add some minor fixes.

Comments

Steven Liu Nov. 16, 2017, 1:49 a.m. UTC | #1
s/get_Fragment/get_fragment_range/g

Maybe better





> 在 2017年11月16日,上午8:59,Colin NG <colin_ng@hotmail.com> 写道:
> 
> Made change suggested by Carl and add some minor fixes.
> 
> 
> ________________________________
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> on behalf of Carl Eugen Hoyos <ceffmpeg@gmail.com>
> Sent: November 15, 2017 5:37 PM
> To: FFmpeg development discussions and patches
> Subject: Re: [FFmpeg-devel] [Patch] Download dash content with byte range info
> 
> 2017-11-15 22:00 GMT+01:00 Colin NG <colin_ng@hotmail.com>:
>> This patch is partial fix for ticket 6658 (Dash demuxer segfault).
> 
>> +static struct fragment * get_Fragment(char *range) {
>> +    struct fragment * seg =  av_mallocz(sizeof(struct fragment));
> 
> Please make it (code-style):
> ... fragment *get_Fragment...
> ... fragment *seg =...
> 
>> +    if (!seg)
>> +        goto finish;
> 
> No.
> 
> You can "return NULL;" but since this is a little misleading,
> it may be better to return AVERROR(ENOMEM) and instead
> of the existing check for NULL below, check for "< 0".
> 
> Carl Eugen
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@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 ...
> 
> 
> 
> <diff5.txt>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Michael Niedermayer Nov. 16, 2017, 1:58 a.m. UTC | #2
On Thu, Nov 16, 2017 at 12:59:51AM +0000, Colin NG wrote:
> Made change suggested by Carl and add some minor fixes.

please submit git patches so they can be applied automatically
(git format-patch  / send-email)

while technically this can be applied, it cant in practice as the
whole email ends in the commit message

[...]
diff mbox

Patch

diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index 0e3afd2..33255f2 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 * get_Fragment(char *range) {
+    struct fragment * seg = av_mallocz(sizeof(struct fragment));
+
+    if (!seg)
+        return NULL;
+
+    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+1;
+    }
+    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 = get_Fragment(range_val);
             if (!rep->init_section) {
                 xmlFree(initialization_val);
                 return AVERROR(ENOMEM);
@@ -548,13 +566,14 @@  static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representati
                 xmlFree(initialization_val);
                 return AVERROR(ENOMEM);
             }
-            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 =  get_Fragment(range_val);
             if (!seg) {
                 xmlFree(media_val);
                 return AVERROR(ENOMEM);
@@ -568,15 +587,14 @@  static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representati
                 xmlFree(media_val);
                 return AVERROR(ENOMEM);
             }
-            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)
 {