diff mbox series

[FFmpeg-devel,2/2] ffmpeg_hw: reuse filter_frame in hwaccel_retrieve_data()

Message ID 20211119154856.44240-2-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/2] ffmpeg: unref ist->filter_frame in the only place it's used | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

James Almer Nov. 19, 2021, 3:48 p.m. UTC
This avoids an AVFrame allocation per decoded frame.

Signed-off-by: James Almer <jamrial@gmail.com>
---
ist->filter_frame is safe to use here since send_frame_to_filters() also unrefs
it immediately after using it. But if this is deemed ugly/evil, I'll just add a
new AVFrame to InputStream.

 fftools/ffmpeg_hw.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg_hw.c b/fftools/ffmpeg_hw.c
index 14e702bd92..4201e44c43 100644
--- a/fftools/ffmpeg_hw.c
+++ b/fftools/ffmpeg_hw.c
@@ -500,7 +500,7 @@  int hw_device_setup_for_encode(OutputStream *ost)
 static int hwaccel_retrieve_data(AVCodecContext *avctx, AVFrame *input)
 {
     InputStream *ist = avctx->opaque;
-    AVFrame *output = NULL;
+    AVFrame *output = ist->filter_frame;
     enum AVPixelFormat output_format = ist->hwaccel_output_format;
     int err;
 
@@ -509,10 +509,6 @@  static int hwaccel_retrieve_data(AVCodecContext *avctx, AVFrame *input)
         return 0;
     }
 
-    output = av_frame_alloc();
-    if (!output)
-        return AVERROR(ENOMEM);
-
     output->format = output_format;
 
     err = av_hwframe_transfer_data(output, input, 0);
@@ -524,18 +520,16 @@  static int hwaccel_retrieve_data(AVCodecContext *avctx, AVFrame *input)
 
     err = av_frame_copy_props(output, input);
     if (err < 0) {
-        av_frame_unref(output);
         goto fail;
     }
 
     av_frame_unref(input);
     av_frame_move_ref(input, output);
-    av_frame_free(&output);
 
     return 0;
 
 fail:
-    av_frame_free(&output);
+    av_frame_unref(output);
     return err;
 }