[04/15] chomp_bsf: convert to the new API

Message ID 1456412755-9220-5-git-send-email-anton@khirnov.net
State New
Headers show

Commit Message

Anton Khirnov Feb. 25, 2016, 3:05 p.m.
---
 libavcodec/allcodecs.c         |  1 -
 libavcodec/bitstream_filters.c |  4 ++++
 libavcodec/chomp_bsf.c         | 29 ++++++++++++++++-------------
 3 files changed, 20 insertions(+), 14 deletions(-)

Patch

diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 4d03363..35d14c3 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -538,7 +538,6 @@  void avcodec_register_all(void)
     REGISTER_PARSER(VP8,                vp8);
 
     /* bitstream filters */
-    REGISTER_BSF(CHOMP,                 chomp);
     REGISTER_BSF(DUMP_EXTRADATA,        dump_extradata);
     REGISTER_BSF(H264_MP4TOANNEXB,      h264_mp4toannexb);
     REGISTER_BSF(HEVC_MP4TOANNEXB,      hevc_mp4toannexb);
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index e23b2d6..6f0e27b 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -23,11 +23,15 @@ 
 #include "libavcodec/avcodec.h"
 
 extern const AVBitStreamFilter ff_aac_adtstoasc_bsf;
+extern const AVBitStreamFilter ff_chomp_bsf;
 
 static const AVBitStreamFilter *bitstream_filters[] = {
 #if CONFIG_AAC_ADTSTOASC_BSF
     &ff_aac_adtstoasc_bsf,
 #endif
+#if CONFIG_CHOMP_BSF
+    &ff_chomp_bsf,
+#endif
     NULL,
 };
 
diff --git a/libavcodec/chomp_bsf.c b/libavcodec/chomp_bsf.c
index 9ed7496..2e76113 100644
--- a/libavcodec/chomp_bsf.c
+++ b/libavcodec/chomp_bsf.c
@@ -20,19 +20,23 @@ 
  */
 
 #include "avcodec.h"
+#include "bsf.h"
 #include "internal.h"
 
-static int chomp_filter(AVBitStreamFilterContext *bsfc,
-                        AVCodecContext *avctx, const char *args,
-                        uint8_t  **poutbuf, int *poutbuf_size,
-                        const uint8_t *buf, int      buf_size,
-                        int keyframe)
+static int chomp_filter(AVBSFContext *ctx, AVPacket *out)
 {
-    while (buf_size > 0 && !buf[buf_size-1])
-        buf_size--;
+    AVPacket *in;
+    int ret;
 
-    *poutbuf = (uint8_t*) buf;
-    *poutbuf_size = buf_size;
+    ret = ff_bsf_get_packet(ctx, &in);
+    if (ret < 0)
+        return ret;
+
+    while (in->size > 0 && !in->data[in->size - 1])
+        in->size--;
+
+    av_packet_move_ref(out, in);
+    av_packet_free(&in);
 
     return 0;
 }
@@ -40,8 +44,7 @@  static int chomp_filter(AVBitStreamFilterContext *bsfc,
 /**
  * This filter removes a string of NULL bytes from the end of a packet.
  */
-AVBitStreamFilter ff_chomp_bsf = {
-    "chomp",
-    0,
-    chomp_filter,
+const AVBitStreamFilter ff_chomp_bsf = {
+    .name   = "chomp",
+    .filter = chomp_filter,
 };