]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/vp9_superframe_bsf.c
avformat/dump: Remove remnants of codec timebase
[ffmpeg] / libavcodec / vp9_superframe_bsf.c
index 04b158fa1212093ddf9ace28fe7d42f35d11b9b8..57681e29e429c36ca26676766d007dce5d4ff7ce 100644 (file)
@@ -1,28 +1,29 @@
 /*
- * VP9 invisible (alt-ref) frame to superframe merge bitstream filter
+ * Vp9 invisible (alt-ref) frame to superframe merge bitstream filter
  * Copyright (c) 2016 Ronald S. Bultje <rsbultje@gmail.com>
  *
- * This file is part of Libav.
+ * This file is part of FFmpeg.
  *
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
  *
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include "libavutil/avassert.h"
-#include "avcodec.h"
-#include "bitstream.h"
+
 #include "bsf.h"
+#include "bsf_internal.h"
+#include "get_bits.h"
 
 #define MAX_CACHE 8
 typedef struct VP9BSFContext {
@@ -67,7 +68,8 @@ static int merge_superframe(AVPacket * const *in, int n_in, AVPacket *out)
         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; \
@@ -96,72 +98,66 @@ static int merge_superframe(AVPacket * const *in, int n_in, AVPacket *out)
     return 0;
 }
 
-static int vp9_superframe_filter(AVBSFContext *ctx, AVPacket *out)
+static int vp9_superframe_filter(AVBSFContext *ctx, AVPacket *pkt)
 {
-    BitstreamContext bc;
+    GetBitContext gb;
     VP9BSFContext *s = ctx->priv_data;
-    AVPacket *in;
     int res, invisible, profile, marker, uses_superframe_syntax = 0, n;
 
-    res = ff_bsf_get_packet(ctx, &in);
+    res = ff_bsf_get_packet_ref(ctx, pkt);
     if (res < 0)
         return res;
 
-    marker = in->data[in->size - 1];
+    marker = pkt->data[pkt->size - 1];
     if ((marker & 0xe0) == 0xc0) {
         int nbytes = 1 + ((marker >> 3) & 0x3);
         int n_frames = 1 + (marker & 0x7), idx_sz = 2 + n_frames * nbytes;
 
-        uses_superframe_syntax = in->size >= idx_sz && in->data[in->size - idx_sz] == marker;
+        uses_superframe_syntax = pkt->size >= idx_sz && pkt->data[pkt->size - idx_sz] == marker;
     }
 
-    res = bitstream_init8(&bc, in->data, in->size);
-    if (res < 0)
+    if ((res = init_get_bits8(&gb, pkt->data, pkt->size)) < 0)
         goto done;
 
-    bitstream_read(&bc, 2); // frame marker
-    profile  = bitstream_read(&bc, 1);
-    profile |= bitstream_read(&bc, 1) << 1;
-    if (profile == 3)
-        profile += bitstream_read(&bc, 1);
+    get_bits(&gb, 2); // frame marker
+    profile  = get_bits1(&gb);
+    profile |= get_bits1(&gb) << 1;
+    if (profile == 3) profile += get_bits1(&gb);
 
-    if (bitstream_read(&bc, 1)) {
+    if (get_bits1(&gb)) {
         invisible = 0;
     } else {
-        bitstream_read(&bc, 1); // keyframe
-        invisible = !bitstream_read(&bc, 1);
+        get_bits1(&gb); // keyframe
+        invisible = !get_bits1(&gb);
     }
 
     if (uses_superframe_syntax && s->n_cache > 0) {
         av_log(ctx, AV_LOG_ERROR,
-               "Mixing of superframe syntax and naked VP9 frames not supported");
+               "Mixing of superframe syntax and naked VP9 frames not supported\n");
         res = AVERROR(ENOSYS);
         goto done;
     } else if ((!invisible || uses_superframe_syntax) && !s->n_cache) {
         // passthrough
-        av_packet_move_ref(out, in);
-        goto done;
+        return 0;
     } else if (s->n_cache + 1 >= MAX_CACHE) {
         av_log(ctx, AV_LOG_ERROR,
-               "Too many invisible frames");
+               "Too many invisible frames\n");
         res = AVERROR_INVALIDDATA;
         goto done;
     }
 
-    res = av_packet_ref(s->cache[s->n_cache++], in);
-    if (res < 0)
-        goto done;
+    av_packet_move_ref(s->cache[s->n_cache++], pkt);
+
     if (invisible) {
-        res = AVERROR(EAGAIN);
-        goto done;
+        return AVERROR(EAGAIN);
     }
     av_assert0(s->n_cache > 0);
 
     // build superframe
-    if ((res = merge_superframe(s->cache, s->n_cache, out)) < 0)
+    if ((res = merge_superframe(s->cache, s->n_cache, pkt)) < 0)
         goto done;
 
-    res = av_packet_copy_props(out, s->cache[s->n_cache - 1]);
+    res = av_packet_copy_props(pkt, s->cache[s->n_cache - 1]);
     if (res < 0)
         goto done;
 
@@ -171,8 +167,7 @@ static int vp9_superframe_filter(AVBSFContext *ctx, AVPacket *out)
 
 done:
     if (res < 0)
-        av_packet_unref(out);
-    av_packet_free(&in);
+        av_packet_unref(pkt);
     return res;
 }