diff mbox

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

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

Commit Message

Colin NG Nov. 17, 2017, 11:13 p.m. UTC
---
 libavformat/dashdec.c | 39 +++++++++++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 6 deletions(-)

Comments

Steven Liu Nov. 19, 2017, 12:58 a.m. UTC | #1
> 在 2017年11月18日,07:13,Colin NG <colin_ng@hotmail.com> 写道:
> 
> ---
> libavformat/dashdec.c | 39 +++++++++++++++++++++++++++++++++------
> 1 file changed, 33 insertions(+), 6 deletions(-)
> 
> diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
> index 0e3afd2..671ae9d 100644
> --- a/libavformat/dashdec.c
> +++ b/libavformat/dashdec.c
> @@ -522,6 +522,25 @@ static enum AVMediaType get_content_type(xmlNodePtr node)
>     return type;
> }
> 
> +static struct fragment * get_Fragment(char *range)
static struct fragment *get_fragment(char *range)
> +{
> +    struct fragment * seg =  av_mallocz(sizeof(struct fragment));
> +
> +    if (!seg)
> +        return NULL;
> +
> +    memset(seg, 0, sizeof(struct fragment));
remove memset.
> +    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,33 +549,40 @@ 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);
> +                xmlFree(range_val);
>                 return AVERROR(ENOMEM);
>             }
>             rep->init_section->url = get_content_url(baseurl_nodes, 4,
>                                                      rep_id_val,
>                                                      rep_bandwidth_val,
>                                                      initialization_val);
> +
>             if (!rep->init_section->url) {
>                 av_free(rep->init_section);
>                 xmlFree(initialization_val);
> +                xmlFree(range_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);
> +                xmlFree(range_val);
>                 return AVERROR(ENOMEM);
>             }
>             seg->url = get_content_url(baseurl_nodes, 4,
> @@ -566,11 +592,12 @@ static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representati
>             if (!seg->url) {
>                 av_free(seg);
>                 xmlFree(media_val);
> +                xmlFree(range_val);
>                 return AVERROR(ENOMEM);
>             }
> -            seg->size = -1;
>             dynarray_add(&rep->fragments, &rep->n_fragments, seg);
>             xmlFree(media_val);
> +            xmlFree(range_val);
>         }
>     }
> 
> -- 
> 2.7.4
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
diff mbox

Patch

diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index 0e3afd2..671ae9d 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -522,6 +522,25 @@  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;
+
+    memset(seg, 0, sizeof(struct fragment));
+    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,33 +549,40 @@  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);
+                xmlFree(range_val);
                 return AVERROR(ENOMEM);
             }
             rep->init_section->url = get_content_url(baseurl_nodes, 4,
                                                      rep_id_val,
                                                      rep_bandwidth_val,
                                                      initialization_val);
+
             if (!rep->init_section->url) {
                 av_free(rep->init_section);
                 xmlFree(initialization_val);
+                xmlFree(range_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);
+                xmlFree(range_val);
                 return AVERROR(ENOMEM);
             }
             seg->url = get_content_url(baseurl_nodes, 4,
@@ -566,11 +592,12 @@  static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representati
             if (!seg->url) {
                 av_free(seg);
                 xmlFree(media_val);
+                xmlFree(range_val);
                 return AVERROR(ENOMEM);
             }
-            seg->size = -1;
             dynarray_add(&rep->fragments, &rep->n_fragments, seg);
             xmlFree(media_val);
+            xmlFree(range_val);
         }
     }