[FFmpeg-devel] [PATCH] mov reference files search improvement

Baptiste Coudurier baptiste.coudurier
Thu Sep 17 20:06:21 CEST 2009


Hi,

On 09/17/2009 07:59 AM, Maksym Veremeyenko wrote:
> Hi!
>
> Another one attempt to post an updated patched to support $subj
>
> Please, comment, commit or reject.
>
>
> ------------------------------------------------------------------------
>
> Index: libavformat/isom.h
> ===================================================================
> --- libavformat/isom.h	(revision 19804)
> +++ libavformat/isom.h	(working copy)
> @@ -56,6 +56,10 @@
>   typedef struct {
>       uint32_t type;
>       char *path;
> +    char *dir;
> +    char volume[28];
> +    char filename[64];
> +    int16_t nlvl_to, nlvl_from;
>   } MOVDref;
>
>   typedef struct {
> Index: libavformat/mov.c
> ===================================================================
> --- libavformat/mov.c	(revision 19804)
> +++ libavformat/mov.c	(working copy)
> @@ -274,19 +274,36 @@
>           if (dref->type == MKTAG('a','l','i','s')&&  size>  150) {
>               /* macintosh alias record */
>               uint16_t volume_len, len;
> -            char volume[28];
>               int16_t type;
>
>               url_fskip(pb, 10);
>
> +            /* read volume name */
>               volume_len = get_byte(pb);
>               volume_len = FFMIN(volume_len, 27);
> -            get_buffer(pb, volume, 27);
> -            volume[volume_len] = 0;
> -            av_log(c->fc, AV_LOG_DEBUG, "volume %s, len %d\n", volume, volume_len);
> +            get_buffer(pb, dref->volume, 27);
> +            dref->volume[volume_len] = 0;
> +            av_log(c->fc, AV_LOG_DEBUG, "volume %s, len %d\n", dref->volume, volume_len);
>
> -            url_fskip(pb, 112);
> +            url_fskip(pb, 12);
>
> +            /* read file name */
> +            len = get_byte(pb);
> +            len = FFMIN(len, 63);
> +            get_buffer(pb, dref->filename, 63);
> +            dref->filename[len] = 0;
> +            av_log(c->fc, AV_LOG_DEBUG, "filename %s, len %d\n", dref->filename, len);
> +
> +            url_fskip(pb, 16);
> +
> +            /* read next level up_from_alias/down_to_target */
> +            dref->nlvl_from = get_be16(pb);
> +            dref->nlvl_to = get_be16(pb);
> +            av_log(c->fc, AV_LOG_DEBUG, "nlvl From %d, nlvl To %d\n",
> +                   dref->nlvl_from, dref->nlvl_to);
> +
> +            url_fskip(pb, 16);
> +
>               for (type = 0; type != -1&&  url_ftell(pb)<  next; ) {
>                   type = get_be16(pb);
>                   len = get_be16(pb);
> @@ -295,11 +312,12 @@
>                       len += 1;
>                   if (type == 2) { // absolute path
>                       av_free(dref->path);
> -                    dref->path = av_mallocz(len+1);
> +                    dref->path = av_malloc(len + 1);
>                       if (!dref->path)
>                           return AVERROR(ENOMEM);
>                       get_buffer(pb, dref->path, len);
> -                    if (len>  volume_len&&  !strncmp(dref->path, volume, volume_len)) {
> +                    dref->path[len] = 0;
> +                    if (len>  volume_len&&  !strncmp(dref->path, dref->volume, volume_len)) {
>                           len -= volume_len;
>                           memmove(dref->path, dref->path+volume_len, len);
>                           dref->path[len] = 0;
> @@ -308,6 +326,17 @@
>                           if (dref->path[j] == ':')
>                               dref->path[j] = '/';
>                       av_log(c->fc, AV_LOG_DEBUG, "path %s\n", dref->path);
> +                } else if (type == 0) { // directory name
> +                    av_free(dref->dir);
> +                    dref->dir = av_malloc(len + 1);
> +                    if (!dref->dir)
> +                        return AVERROR(ENOMEM);
> +                    get_buffer(pb, dref->dir, len);
> +                    dref->dir[len] = 0;
> +                    for (j = 0; j<  len; j++)
> +                        if (dref->dir[j] == ':')
> +                            dref->dir[j] = '/';
> +                    av_log(c->fc, AV_LOG_DEBUG, "dir %s\n", dref->dir);
>                   } else
>                       url_fskip(pb, len);
>               }
> @@ -2228,8 +2257,10 @@
>           MOVStreamContext *sc = st->priv_data;
>
>           av_freep(&sc->ctts_data);
> -        for (j = 0; j<  sc->drefs_count; j++)
> +        for (j = 0; j<  sc->drefs_count; j++) {
>               av_freep(&sc->drefs[j].path);
> +            av_freep(&sc->drefs[j].dir);
> +        }
>           av_freep(&sc->drefs);
>           if (sc->pb&&  sc->pb != s->pb)
>               url_fclose(sc->pb);


This part is ok.

>
> ------------------------------------------------------------------------
>
> --- libavformat/mov.c.step1	2009-09-10 08:47:11.000000000 +0300
> +++ libavformat/mov.c	2009-09-10 11:11:40.000000000 +0300
> @@ -1542,6 +1542,52 @@
>       }
>   }
>
> +static int mov_open_dref(ByteIOContext **pb, char *src, MOVDref *ref)
> +{
> +    /* probe absolute path */
> +    if (!url_fopen(pb, ref->path, URL_RDONLY))
> +        return 0;
> +
> +    /* probe relative path */
> +    if (ref->nlvl_to>  0&&  ref->nlvl_from>  0) {
> +        char filename[1024];
> +        char *src_path;
> +        int i, l;
> +
> +        /* find a source dir */
> +        src_path = FFMAX(strrchr(src, '/'), strrchr(src, '\\'));

\ is allowed on unix.

 > [...]
 >
> +        /* find tail by ref->path and nlvl_To */

grammar problem

> +        for (i = 0, l = strlen(ref->path) - 1; l>= 0; l--)
> +            if ('/' == ref->path[l]) {
> +                if(i == ref->nlvl_to - 1) break;
> +                else                      i++;
> +            }
> +

strrchr ?

> +        /* check if it found */

grammar problem

[...]

You don't use dref->dir at all ?
I thought nlvl_to was useless after all ?

-- 
Baptiste COUDURIER
Key fingerprint                 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
FFmpeg maintainer                                  http://www.ffmpeg.org



More information about the ffmpeg-devel mailing list