[FFmpeg-cvslog] Merge commit '3fb6b98b5e247434456916c35ba7e08efa03e85d'

James Almer git at videolan.org
Tue Oct 31 17:12:25 EET 2017


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Tue Oct 31 12:09:53 2017 -0300| [e1bc3f4396ade6033787717d3650fb62663eae87] | committer: James Almer

Merge commit '3fb6b98b5e247434456916c35ba7e08efa03e85d'

* commit '3fb6b98b5e247434456916c35ba7e08efa03e85d':
  vp9_superframe_bsf: cache input packets directly

Merged-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e1bc3f4396ade6033787717d3650fb62663eae87
---

 libavcodec/vp9_superframe_bsf.c | 52 +++++++++++++++++------------------------
 1 file changed, 21 insertions(+), 31 deletions(-)

diff --git a/libavcodec/vp9_superframe_bsf.c b/libavcodec/vp9_superframe_bsf.c
index 98da8d5eba..121d3a3d81 100644
--- a/libavcodec/vp9_superframe_bsf.c
+++ b/libavcodec/vp9_superframe_bsf.c
@@ -27,20 +27,17 @@
 #define MAX_CACHE 8
 typedef struct VP9BSFContext {
     int n_cache;
-    struct CachedBuf {
-        uint8_t *data;
-        int size;
-    } cache[MAX_CACHE];
+    AVPacket *cache[MAX_CACHE];
 } VP9BSFContext;
 
-static void stats(const struct CachedBuf *in, int n_in,
+static void stats(AVPacket * const *in, int n_in,
                   unsigned *_max, unsigned *_sum)
 {
     int n;
     unsigned max = 0, sum = 0;
 
     for (n = 0; n < n_in; n++) {
-        unsigned sz = in[n].size;
+        unsigned sz = in[n]->size;
 
         if (sz > max)
             max = sz;
@@ -51,7 +48,7 @@ static void stats(const struct CachedBuf *in, int n_in,
     *_sum = sum;
 }
 
-static int merge_superframe(const struct CachedBuf *in, int n_in, AVPacket *out)
+static int merge_superframe(AVPacket * const *in, int n_in, AVPacket *out)
 {
     unsigned max, sum, mag, marker, n, sz;
     uint8_t *ptr;
@@ -66,8 +63,8 @@ static int merge_superframe(const struct CachedBuf *in, int n_in, AVPacket *out)
         return res;
     ptr = out->data;
     for (n = 0; n < n_in; n++) {
-        memcpy(ptr, in[n].data, in[n].size);
-        ptr += in[n].size;
+        memcpy(ptr, in[n]->data, in[n]->size);
+        ptr += in[n]->size;
     }
 
 #define wloop(mag, wr) \
@@ -82,16 +79,16 @@ static int merge_superframe(const struct CachedBuf *in, int n_in, AVPacket *out)
     *ptr++ = marker;
     switch (mag) {
     case 0:
-        wloop(mag, *ptr = in[n].size);
+        wloop(mag, *ptr = in[n]->size);
         break;
     case 1:
-        wloop(mag, AV_WL16(ptr, in[n].size));
+        wloop(mag, AV_WL16(ptr, in[n]->size));
         break;
     case 2:
-        wloop(mag, AV_WL24(ptr, in[n].size));
+        wloop(mag, AV_WL24(ptr, in[n]->size));
         break;
     case 3:
-        wloop(mag, AV_WL32(ptr, in[n].size));
+        wloop(mag, AV_WL32(ptr, in[n]->size));
         break;
     }
     *ptr++ = marker;
@@ -137,7 +134,7 @@ static int vp9_superframe_filter(AVBSFContext *ctx, AVPacket *out)
     if (uses_superframe_syntax && s->n_cache > 0) {
         av_log(ctx, AV_LOG_ERROR,
                "Mixing of superframe syntax and naked VP9 frames not supported");
-        res = AVERROR_INVALIDDATA;
+        res = AVERROR(ENOSYS);
         goto done;
     } else if ((!invisible || uses_superframe_syntax) && !s->n_cache) {
         // passthrough
@@ -150,33 +147,26 @@ static int vp9_superframe_filter(AVBSFContext *ctx, AVPacket *out)
         goto done;
     }
 
-    s->cache[s->n_cache].size = in->size;
-    if (invisible && !uses_superframe_syntax) {
-        s->cache[s->n_cache].data = av_malloc(in->size);
-        if (!s->cache[s->n_cache].data) {
-            res = AVERROR(ENOMEM);
-            goto done;
-        }
-        memcpy(s->cache[s->n_cache++].data, in->data, in->size);
+    s->cache[s->n_cache++] = in;
+    in                     = NULL;
+    if (invisible) {
         res = AVERROR(EAGAIN);
         goto done;
     }
     av_assert0(s->n_cache > 0);
 
-    s->cache[s->n_cache].data = in->data;
-
     // build superframe
-    if ((res = merge_superframe(s->cache, s->n_cache + 1, out)) < 0)
+    if ((res = merge_superframe(s->cache, s->n_cache, out)) < 0)
         goto done;
 
-    for (n = 0; n < s->n_cache; n++)
-        av_freep(&s->cache[n].data);
-    s->n_cache = 0;
-
-    res = av_packet_copy_props(out, in);
+    res = av_packet_copy_props(out, s->cache[s->n_cache - 1]);
     if (res < 0)
         goto done;
 
+    for (n = 0; n < s->n_cache; n++)
+        av_packet_free(&s->cache[n]);
+    s->n_cache = 0;
+
 done:
     if (res < 0)
         av_packet_unref(out);
@@ -191,7 +181,7 @@ static void vp9_superframe_close(AVBSFContext *ctx)
 
     // free cached data
     for (n = 0; n < s->n_cache; n++)
-        av_freep(&s->cache[n].data);
+        av_packet_free(&s->cache[n]);
 }
 
 static const enum AVCodecID codec_ids[] = {


======================================================================

diff --cc libavcodec/vp9_superframe_bsf.c
index 98da8d5eba,3669216009..121d3a3d81
--- a/libavcodec/vp9_superframe_bsf.c
+++ b/libavcodec/vp9_superframe_bsf.c
@@@ -66,12 -63,11 +63,12 @@@ static int merge_superframe(AVPacket * 
          return res;
      ptr = out->data;
      for (n = 0; n < n_in; n++) {
-         memcpy(ptr, in[n].data, in[n].size);
-         ptr += in[n].size;
+         memcpy(ptr, in[n]->data, in[n]->size);
+         ptr += in[n]->size;
      }
  
 -#define wloop(mag, wr) do { \
 +#define wloop(mag, wr) \
 +    do { \
          for (n = 0; n < n_in; n++) { \
              wr; \
              ptr += mag + 1; \



More information about the ffmpeg-cvslog mailing list