[FFmpeg-devel,1/8] avcodec/bsf: add a flushing mechanism to AVBSFContext

Submitted by James Almer on July 27, 2018, 2:57 p.m.

Details

Message ID 20180727145749.9436-1-jamrial@gmail.com
State New
Headers show

Commit Message

James Almer July 27, 2018, 2:57 p.m.
Meant to reset the internal bsf state without the need to reinitialize it.

Signed-off-by: James Almer <jamrial@gmail.com>
---
Missing APIChanges entry and version bump.

 libavcodec/avcodec.h |  6 ++++++
 libavcodec/bsf.c     | 10 ++++++++++
 2 files changed, 16 insertions(+)

Patch hide | download patch | download mbox

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 1266879206..56be65bd56 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -5769,6 +5769,7 @@  typedef struct AVBitStreamFilter {
     int (*init)(AVBSFContext *ctx);
     int (*filter)(AVBSFContext *ctx, AVPacket *pkt);
     void (*close)(AVBSFContext *ctx);
+    void (*flush)(AVBSFContext *ctx);
 } AVBitStreamFilter;
 
 #if FF_API_OLD_BSF
@@ -5895,6 +5896,11 @@  int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt);
  */
 int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt);
 
+/**
+ * Reset the internal bitstream filter state / flush internal buffers.
+ */
+void av_bsf_flush(AVBSFContext *ctx);
+
 /**
  * Free a bitstream filter context and everything associated with it; write NULL
  * into the supplied pointer.
diff --git a/libavcodec/bsf.c b/libavcodec/bsf.c
index bd611ea16b..03841da682 100644
--- a/libavcodec/bsf.c
+++ b/libavcodec/bsf.c
@@ -172,6 +172,16 @@  int av_bsf_init(AVBSFContext *ctx)
     return 0;
 }
 
+void av_bsf_flush(AVBSFContext *ctx)
+{
+    ctx->internal->eof = 0;
+
+    av_packet_unref(ctx->internal->buffer_pkt);
+
+    if (ctx->filter->flush)
+        ctx->filter->flush(ctx);
+}
+
 int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
 {
     int ret;