[FFmpeg-devel] [PATCH 09/21] fftools/ffmpeg_dec: move InputStream.hwaccel_pix_fmt to Decoder

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


It is purely decoder-internal state.
---
 fftools/ffmpeg.h       | 2 --
 fftools/ffmpeg_dec.c   | 8 ++++++--
 fftools/ffmpeg_demux.c | 2 --
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 2559225dd6..3c7e819507 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -393,8 +393,6 @@ typedef struct InputStream {
     char  *hwaccel_device;
     enum AVPixelFormat hwaccel_output_format;
 
-    enum AVPixelFormat hwaccel_pix_fmt;
-
     /* stats */
     // number of frames/samples retrieved from the decoder
     uint64_t frames_decoded;
diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index 85132050d8..586be83dc1 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -35,6 +35,8 @@ struct Decoder {
     AVFrame         *frame;
     AVPacket        *pkt;
 
+    enum AVPixelFormat hwaccel_pix_fmt;
+
     // pts/estimated duration of the last decoded frame
     // * in decoder timebase for video,
     // * in last_frame_tb (may change during decoding) for audio
@@ -79,6 +81,7 @@ static int dec_alloc(Decoder **pdec)
     dec->last_filter_in_rescale_delta = AV_NOPTS_VALUE;
     dec->last_frame_pts               = AV_NOPTS_VALUE;
     dec->last_frame_tb                = (AVRational){ 1, 1 };
+    dec->hwaccel_pix_fmt              = AV_PIX_FMT_NONE;
 
     *pdec = dec;
 
@@ -272,7 +275,7 @@ static int video_frame_process(InputStream *ist, AVFrame *frame)
     if(ist->top_field_first>=0)
         frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
 
-    if (frame->format == ist->hwaccel_pix_fmt) {
+    if (frame->format == d->hwaccel_pix_fmt) {
         int err = hwaccel_retrieve_data(ist->dec_ctx, frame);
         if (err < 0)
             return err;
@@ -537,6 +540,7 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof)
 static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat *pix_fmts)
 {
     InputStream *ist = s->opaque;
+    Decoder       *d = ist->decoder;
     const enum AVPixelFormat *p;
 
     for (p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
@@ -561,7 +565,7 @@ static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat
             }
         }
         if (config && config->device_type == ist->hwaccel_device_type) {
-            ist->hwaccel_pix_fmt = *p;
+            d->hwaccel_pix_fmt = *p;
             break;
         }
     }
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 84c286dd65..1c6a5aab7b 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -1149,8 +1149,6 @@ static void ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
             if (!ist->hwaccel_device)
                 report_and_exit(AVERROR(ENOMEM));
         }
-
-        ist->hwaccel_pix_fmt = AV_PIX_FMT_NONE;
     }
 
     ist->dec = choose_decoder(o, ic, st, ist->hwaccel_id, ist->hwaccel_device_type);
-- 
2.40.1



More information about the ffmpeg-devel mailing list