[FFmpeg-devel] [PATCH 1/4] avcodec: move avcodec_flush_buffers from decode.c to utils.c

James Almer jamrial at gmail.com
Thu Feb 27 20:01:59 EET 2020


It's not a decoding exclusive function.

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/decode.c | 36 ------------------------------------
 libavcodec/utils.c  | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 36 deletions(-)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 03b9da25f9..93b0db7ef8 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -2020,42 +2020,6 @@ int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
     return ret;
 }
 
-static void bsfs_flush(AVCodecContext *avctx)
-{
-    DecodeFilterContext *s = &avctx->internal->filter;
-
-    for (int i = 0; i < s->nb_bsfs; i++)
-        av_bsf_flush(s->bsfs[i]);
-}
-
-void avcodec_flush_buffers(AVCodecContext *avctx)
-{
-    AVCodecInternal *avci = avctx->internal;
-
-    avci->draining      = 0;
-    avci->draining_done = 0;
-    avci->nb_draining_errors = 0;
-    av_frame_unref(avci->buffer_frame);
-    av_frame_unref(avci->compat_decode_frame);
-    av_packet_unref(avci->buffer_pkt);
-    avci->buffer_pkt_valid = 0;
-
-    av_packet_unref(avci->ds.in_pkt);
-
-    if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
-        ff_thread_flush(avctx);
-    else if (avctx->codec->flush)
-        avctx->codec->flush(avctx);
-
-    avctx->pts_correction_last_pts =
-    avctx->pts_correction_last_dts = INT64_MIN;
-
-    bsfs_flush(avctx);
-
-    if (!avctx->refcounted_frames)
-        av_frame_unref(avci->to_free);
-}
-
 void ff_decode_bsfs_uninit(AVCodecContext *avctx)
 {
     DecodeFilterContext *s = &avctx->internal->filter;
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index c4dc136d3c..5257a1c627 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1084,6 +1084,39 @@ FF_ENABLE_DEPRECATION_WARNINGS
     goto end;
 }
 
+void avcodec_flush_buffers(AVCodecContext *avctx)
+{
+    AVCodecInternal *avci = avctx->internal;
+
+    avci->draining      = 0;
+    avci->draining_done = 0;
+    avci->nb_draining_errors = 0;
+    av_frame_unref(avci->buffer_frame);
+    av_frame_unref(avci->compat_decode_frame);
+    av_packet_unref(avci->buffer_pkt);
+    avci->buffer_pkt_valid = 0;
+
+    av_packet_unref(avci->ds.in_pkt);
+
+    if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME)
+        ff_thread_flush(avctx);
+    else if (avctx->codec->flush)
+        avctx->codec->flush(avctx);
+
+    avctx->pts_correction_last_pts =
+    avctx->pts_correction_last_dts = INT64_MIN;
+
+    if (av_codec_is_decoder(avctx->codec)) {
+        DecodeFilterContext *s = &avctx->internal->filter;
+
+        for (int i = 0; i < s->nb_bsfs; i++)
+            av_bsf_flush(s->bsfs[i]);
+    }
+
+    if (!avctx->refcounted_frames)
+        av_frame_unref(avci->to_free);
+}
+
 void avsubtitle_free(AVSubtitle *sub)
 {
     int i;
-- 
2.25.1



More information about the ffmpeg-devel mailing list