diff mbox series

[FFmpeg-devel,15/31] fftools/ffmpeg: move hwaccel_retrieve_data() from ffmpeg_hw to ffmpeg_dec

Message ID 20240124081702.4759-15-anton@khirnov.net
State Accepted
Commit a3a9c4ae66e474c51aa36b9c0b8ee5c1419559f1
Headers show
Series [FFmpeg-devel,01/31] fftools/ffmpeg_dec: split Decoder into a private and public part | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Jan. 24, 2024, 8:16 a.m. UTC
This function is decoding-only and has no interaction with the rest of
ffmpeg_hw. It thus belongs more properly in ffmpeg_dec.
---
 fftools/ffmpeg.h     |  2 --
 fftools/ffmpeg_dec.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 fftools/ffmpeg_hw.c  | 42 ------------------------------------------
 3 files changed, 42 insertions(+), 44 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index e87af70698..80c09d1662 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -731,8 +731,6 @@  void hw_device_free_all(void);
  */
 AVBufferRef *hw_device_for_filter(void);
 
-int hwaccel_retrieve_data(AVCodecContext *avctx, AVFrame *input);
-
 /**
  * @param dec_opts Dictionary filled with decoder options. Its ownership
  *                 is transferred to the decoder.
diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index f647db3611..f65857bea3 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -265,6 +265,48 @@  static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr
     return FFMAX(dp->last_frame_duration_est, 1);
 }
 
+static int hwaccel_retrieve_data(AVCodecContext *avctx, AVFrame *input)
+{
+    InputStream *ist = avctx->opaque;
+    AVFrame *output = NULL;
+    enum AVPixelFormat output_format = ist->hwaccel_output_format;
+    int err;
+
+    if (input->format == output_format) {
+        // Nothing to do.
+        return 0;
+    }
+
+    output = av_frame_alloc();
+    if (!output)
+        return AVERROR(ENOMEM);
+
+    output->format = output_format;
+
+    err = av_hwframe_transfer_data(output, input, 0);
+    if (err < 0) {
+        av_log(avctx, AV_LOG_ERROR, "Failed to transfer data to "
+               "output frame: %d.\n", err);
+        goto fail;
+    }
+
+    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);
+    return err;
+}
+
 static int video_frame_process(InputStream *ist, AVFrame *frame)
 {
     DecoderPriv *dp = dp_from_dec(ist->decoder);
diff --git a/fftools/ffmpeg_hw.c b/fftools/ffmpeg_hw.c
index 46bc7e39c2..8608d24517 100644
--- a/fftools/ffmpeg_hw.c
+++ b/fftools/ffmpeg_hw.c
@@ -297,48 +297,6 @@  void hw_device_free_all(void)
     nb_hw_devices = 0;
 }
 
-int hwaccel_retrieve_data(AVCodecContext *avctx, AVFrame *input)
-{
-    InputStream *ist = avctx->opaque;
-    AVFrame *output = NULL;
-    enum AVPixelFormat output_format = ist->hwaccel_output_format;
-    int err;
-
-    if (input->format == output_format) {
-        // Nothing to do.
-        return 0;
-    }
-
-    output = av_frame_alloc();
-    if (!output)
-        return AVERROR(ENOMEM);
-
-    output->format = output_format;
-
-    err = av_hwframe_transfer_data(output, input, 0);
-    if (err < 0) {
-        av_log(avctx, AV_LOG_ERROR, "Failed to transfer data to "
-               "output frame: %d.\n", err);
-        goto fail;
-    }
-
-    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);
-    return err;
-}
-
 AVBufferRef *hw_device_for_filter(void)
 {
     // Pick the last hardware device if the user doesn't pick the device for