[FFmpeg-cvslog] lavc/avcodec: split flushing into decode- and encode-specific functions

Anton Khirnov git at videolan.org
Fri Jul 7 13:15:49 EEST 2023


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Tue Jun 20 12:52:49 2023 +0200| [6ff27024b8dc2a0f3ce4277b341401b5137a1990] | committer: Anton Khirnov

lavc/avcodec: split flushing into decode- and encode-specific functions

Will allow making some state private to encoding/decoding in the future.

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

 libavcodec/avcodec.c          | 17 +++--------------
 libavcodec/avcodec_internal.h |  3 +++
 libavcodec/decode.c           | 15 +++++++++++++++
 libavcodec/encode.c           | 10 ++++++++++
 4 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 638cb55146..c01dac2049 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -383,23 +383,12 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
                    "that doesn't support it\n");
             return;
         }
-        if (avci->in_frame)
-            av_frame_unref(avci->in_frame);
-        if (avci->recon_frame)
-            av_frame_unref(avci->recon_frame);
-    } else {
-        av_packet_unref(avci->last_pkt_props);
-        av_packet_unref(avci->in_pkt);
-
-        avctx->pts_correction_last_pts =
-        avctx->pts_correction_last_dts = INT64_MIN;
-
-        av_bsf_flush(avci->bsf);
-    }
+        ff_encode_flush_buffers(avctx);
+    } else
+        ff_decode_flush_buffers(avctx);
 
     avci->draining      = 0;
     avci->draining_done = 0;
-    avci->nb_draining_errors = 0;
     av_frame_unref(avci->buffer_frame);
     av_packet_unref(avci->buffer_pkt);
 
diff --git a/libavcodec/avcodec_internal.h b/libavcodec/avcodec_internal.h
index be60a36644..6ffe575c3e 100644
--- a/libavcodec/avcodec_internal.h
+++ b/libavcodec/avcodec_internal.h
@@ -50,4 +50,7 @@ int ff_encode_preinit(struct AVCodecContext *avctx);
  */
 int ff_decode_preinit(struct AVCodecContext *avctx);
 
+void ff_decode_flush_buffers(struct AVCodecContext *avctx);
+void ff_encode_flush_buffers(struct AVCodecContext *avctx);
+
 #endif // AVCODEC_AVCODEC_INTERNAL_H
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 336635f772..01ac35bf34 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1740,3 +1740,18 @@ AVBufferRef *ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx,
 
     return ref;
 }
+
+void ff_decode_flush_buffers(AVCodecContext *avctx)
+{
+    AVCodecInternal *avci = avctx->internal;
+
+        av_packet_unref(avci->last_pkt_props);
+        av_packet_unref(avci->in_pkt);
+
+        avctx->pts_correction_last_pts =
+        avctx->pts_correction_last_dts = INT64_MIN;
+
+        av_bsf_flush(avci->bsf);
+
+    avci->nb_draining_errors = 0;
+}
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 3a016b14c1..0b1947c781 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -785,3 +785,13 @@ int ff_encode_receive_frame(AVCodecContext *avctx, AVFrame *frame)
     av_frame_move_ref(frame, avci->recon_frame);
     return 0;
 }
+
+void ff_encode_flush_buffers(AVCodecContext *avctx)
+{
+    AVCodecInternal *avci = avctx->internal;
+
+        if (avci->in_frame)
+            av_frame_unref(avci->in_frame);
+        if (avci->recon_frame)
+            av_frame_unref(avci->recon_frame);
+}



More information about the ffmpeg-cvslog mailing list