[FFmpeg-cvslog] avcodec/bsf: Add ff_bsf_get_packet_ref() function

Jan Sebechlebsky git at videolan.org
Wed Feb 20 18:58:03 EET 2019


ffmpeg | branch: master | Jan Sebechlebsky <sebechlebskyjan at gmail.com> | Thu Jul 28 18:18:13 2016 +0200| [87d5686151bcb2ab94bd1c962e94d7e41203e31a] | committer: Luca Barbato

avcodec/bsf: Add ff_bsf_get_packet_ref() function

Use of this function can save unnecessary malloc operation
in bitstream filter.

Signed-off-by: Jan Sebechlebsky <sebechlebskyjan at gmail.com>
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
Signed-off-by: Luca Barbato <lu_zero at gentoo.org>

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

 libavcodec/bsf.c | 16 ++++++++++++++++
 libavcodec/bsf.h | 11 +++++++++++
 2 files changed, 27 insertions(+)

diff --git a/libavcodec/bsf.c b/libavcodec/bsf.c
index 05cad546de..f6f894b50a 100644
--- a/libavcodec/bsf.c
+++ b/libavcodec/bsf.c
@@ -227,3 +227,19 @@ int ff_bsf_get_packet(AVBSFContext *ctx, AVPacket **pkt)
 
     return 0;
 }
+
+int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
+{
+    AVBSFInternal *in = ctx->internal;
+
+    if (in->eof)
+        return AVERROR_EOF;
+
+    if (!ctx->internal->buffer_pkt->data &&
+        !ctx->internal->buffer_pkt->side_data_elems)
+        return AVERROR(EAGAIN);
+
+    av_packet_move_ref(pkt, ctx->internal->buffer_pkt);
+
+    return 0;
+}
diff --git a/libavcodec/bsf.h b/libavcodec/bsf.h
index cf35fc8e01..39301a286f 100644
--- a/libavcodec/bsf.h
+++ b/libavcodec/bsf.h
@@ -28,6 +28,17 @@
  */
 int ff_bsf_get_packet(AVBSFContext *ctx, AVPacket **pkt);
 
+/**
+ * Called by bitstream filters to get packet for filtering.
+ * The reference to packet is moved to provided packet structure.
+ *
+ * @param ctx pointer to AVBSFContext of filter
+ * @param pkt pointer to packet to move reference to
+ *
+ * @return 0>= on success, negative AVERROR in case of failure
+ */
+int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt);
+
 const AVClass *ff_bsf_child_class_next(const AVClass *prev);
 
 #endif /* AVCODEC_BSF_H */



More information about the ffmpeg-cvslog mailing list