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

Michael Niedermayer michael at niedermayer.cc
Fri Nov 17 19:15:02 EET 2017


On Thu, Nov 16, 2017 at 08:33:35PM +0000, Colin NG wrote:
> ---
>  libavformat/dashdec.c | 32 +++++++++++++++++++++++++-------
>  1 file changed, 25 insertions(+), 7 deletions(-)
> 
> 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);
>          }

I think this is leaking range_val in some error paths


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Democracy is the form of government in which you can choose your dictator
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20171117/090117f7/attachment.sig>


More information about the ffmpeg-devel mailing list