[FFmpeg-devel] [PATCH 07/21] fftools/ffmpeg_hw: inline hwaccel_decode_init() into its caller

Anton Khirnov anton at khirnov.net
Wed Jun 14 19:48:54 EEST 2023


The function is now trivial and cannot fail, so all error handling in
its caller can be removed.
---
 fftools/ffmpeg.h     |  2 +-
 fftools/ffmpeg_dec.c | 15 +--------------
 fftools/ffmpeg_hw.c  | 11 +----------
 3 files changed, 3 insertions(+), 25 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 7189629ad4..aeecf92fe6 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -805,7 +805,7 @@ void hw_device_free_all(void);
  */
 AVBufferRef *hw_device_for_filter(void);
 
-int hwaccel_decode_init(AVCodecContext *avctx);
+int hwaccel_retrieve_data(AVCodecContext *avctx, AVFrame *input);
 
 int dec_open(InputStream *ist);
 void dec_free(Decoder **pdec);
diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index 6582917a39..ca9fbb9bd8 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -538,7 +538,6 @@ static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat
 {
     InputStream *ist = s->opaque;
     const enum AVPixelFormat *p;
-    int ret;
 
     for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
         const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(*p);
@@ -562,19 +561,7 @@ static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat
             }
         }
         if (config && config->device_type == ist->hwaccel_device_type) {
-            ret = hwaccel_decode_init(s);
-            if (ret < 0) {
-                if (ist->hwaccel_id == HWACCEL_GENERIC) {
-                    av_log(NULL, AV_LOG_FATAL,
-                           "%s hwaccel requested for input stream #%d:%d, "
-                           "but cannot be initialized.\n",
-                           av_hwdevice_get_type_name(config->device_type),
-                           ist->file_index, ist->index);
-                    return AV_PIX_FMT_NONE;
-                }
-                continue;
-            }
-
+            ist->hwaccel_retrieve_data = hwaccel_retrieve_data;
             ist->hwaccel_pix_fmt = *p;
             break;
         }
diff --git a/fftools/ffmpeg_hw.c b/fftools/ffmpeg_hw.c
index 4a0b346fe1..46bc7e39c2 100644
--- a/fftools/ffmpeg_hw.c
+++ b/fftools/ffmpeg_hw.c
@@ -297,7 +297,7 @@ void hw_device_free_all(void)
     nb_hw_devices = 0;
 }
 
-static int hwaccel_retrieve_data(AVCodecContext *avctx, AVFrame *input)
+int hwaccel_retrieve_data(AVCodecContext *avctx, AVFrame *input)
 {
     InputStream *ist = avctx->opaque;
     AVFrame *output = NULL;
@@ -339,15 +339,6 @@ fail:
     return err;
 }
 
-int hwaccel_decode_init(AVCodecContext *avctx)
-{
-    InputStream *ist = avctx->opaque;
-
-    ist->hwaccel_retrieve_data = &hwaccel_retrieve_data;
-
-    return 0;
-}
-
 AVBufferRef *hw_device_for_filter(void)
 {
     // Pick the last hardware device if the user doesn't pick the device for
-- 
2.40.1



More information about the ffmpeg-devel mailing list