diff mbox

[FFmpeg-devel] Make the process of uuid-xmp atom faster.

Message ID 20161111023616.9417-1-mengchen.mc@alibaba-inc.com
State Superseded
Headers show

Commit Message

=?GBK?B?w8+zvSjj1bfqKQ==?= Nov. 11, 2016, 2:36 a.m. UTC
---
 libavformat/mov.c | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

Comments

Steven Liu Nov. 11, 2016, 3:09 a.m. UTC | #1
2016-11-11 10:36 GMT+08:00 Chen Meng <mengchen.mc@alibaba-inc.com>:

> ---
>  libavformat/mov.c | 32 ++++++++++++++++++--------------
>  1 file changed, 18 insertions(+), 14 deletions(-)
>
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 9ec7d03..436c234 100644
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -4549,24 +4549,28 @@ static int mov_read_uuid(MOVContext *c,
> AVIOContext *pb, MOVAtom atom)
>      } else if (!memcmp(uuid, uuid_xmp, sizeof(uuid))) {
>          uint8_t *buffer;
>          size_t len = atom.size - sizeof(uuid);
> -
> -        buffer = av_mallocz(len + 1);
> -        if (!buffer) {
> -            return AVERROR(ENOMEM);
> -        }
> -        ret = avio_read(pb, buffer, len);
> -        if (ret < 0) {
> -            av_free(buffer);
> -            return ret;
> -        } else if (ret != len) {
> -            av_free(buffer);
> -            return AVERROR_INVALIDDATA;
> -        }
>          if (c->export_xmp) {
> +            buffer = av_mallocz(len + 1);
> +            if (!buffer) {
> +                return AVERROR(ENOMEM);
> +            }
> +            ret = avio_read(pb, buffer, len);
> +            if (ret < 0) {
> +                av_free(buffer);
> +                return ret;
> +            } else if (ret != len) {
> +                av_free(buffer);
> +                return AVERROR_INVALIDDATA;
> +            }
>              buffer[len] = '\0';
>              av_dict_set(&c->fc->metadata, "xmp", buffer, 0);
> +            av_free(buffer);
> +        } else {
> +            // skip all uuid atom, which makes it fast for long uuid-xmp
> file
> +            ret = avio_skip(pb, len);
> +            if (ret < 0)
> +                return ret;
>          }
> -        av_free(buffer);
>      }
>      return 0;
>  }
> --
> 2.10.2
>
> LGTM,   Except Submitter name used GBK at
https://patchwork.ffmpeg.org/project/ffmpeg/list/

> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
diff mbox

Patch

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 9ec7d03..436c234 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4549,24 +4549,28 @@  static int mov_read_uuid(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     } else if (!memcmp(uuid, uuid_xmp, sizeof(uuid))) {
         uint8_t *buffer;
         size_t len = atom.size - sizeof(uuid);
-
-        buffer = av_mallocz(len + 1);
-        if (!buffer) {
-            return AVERROR(ENOMEM);
-        }
-        ret = avio_read(pb, buffer, len);
-        if (ret < 0) {
-            av_free(buffer);
-            return ret;
-        } else if (ret != len) {
-            av_free(buffer);
-            return AVERROR_INVALIDDATA;
-        }
         if (c->export_xmp) {
+            buffer = av_mallocz(len + 1);
+            if (!buffer) {
+                return AVERROR(ENOMEM);
+            }
+            ret = avio_read(pb, buffer, len);
+            if (ret < 0) {
+                av_free(buffer);
+                return ret;
+            } else if (ret != len) {
+                av_free(buffer);
+                return AVERROR_INVALIDDATA;
+            }
             buffer[len] = '\0';
             av_dict_set(&c->fc->metadata, "xmp", buffer, 0);
+            av_free(buffer);
+        } else {
+            // skip all uuid atom, which makes it fast for long uuid-xmp file
+            ret = avio_skip(pb, len);
+            if (ret < 0)
+                return ret;
         }
-        av_free(buffer);
     }
     return 0;
 }