[FFmpeg-devel] [PATCH] lavfi/vf_hwmap: move some code into seperate function

Ruiling Song ruiling.song at intel.com
Sat Feb 2 04:33:54 EET 2019


This is just code fine. No functional change.

Signed-off-by: Ruiling Song <ruiling.song at intel.com>
---
 libavfilter/vf_hwmap.c | 83 ++++++++++++++++++++++++--------------------------
 1 file changed, 39 insertions(+), 44 deletions(-)

diff --git a/libavfilter/vf_hwmap.c b/libavfilter/vf_hwmap.c
index 290559a..14276ce 100644
--- a/libavfilter/vf_hwmap.c
+++ b/libavfilter/vf_hwmap.c
@@ -50,6 +50,37 @@ static int hwmap_query_formats(AVFilterContext *avctx)
     return 0;
 }
 
+static int create_hwframe_context(AVFilterContext *avctx, AVBufferRef *device,
+                                  int format, int sw_format,
+                                  int width, int height)
+{
+    HWMapContext      *ctx = avctx->priv;
+    int err;
+    AVHWFramesContext *frames;
+
+    ctx->hwframes_ref = av_hwframe_ctx_alloc(device);
+    if (!ctx->hwframes_ref) {
+        return AVERROR(ENOMEM);
+    }
+    frames = (AVHWFramesContext*)ctx->hwframes_ref->data;
+
+    frames->format    = format;
+    frames->sw_format = sw_format;
+    frames->width     = width;
+    frames->height    = height;
+
+    if (avctx->extra_hw_frames >= 0)
+        frames->initial_pool_size = 2 + avctx->extra_hw_frames;
+
+    err = av_hwframe_ctx_init(ctx->hwframes_ref);
+    if (err < 0) {
+        av_log(avctx, AV_LOG_ERROR, "Failed to initialise "
+               "hardware frames context: %d.\n", err);
+        return err;
+    }
+    return 0;
+}
+
 static int hwmap_config_output(AVFilterLink *outlink)
 {
     AVFilterContext *avctx = outlink->src;
@@ -130,29 +161,12 @@ static int hwmap_config_output(AVFilterLink *outlink)
             // overwrite the input hwframe context with a derived context
             // mapped from that back to the source type.
             AVBufferRef *source;
-            AVHWFramesContext *frames;
-
-            ctx->hwframes_ref = av_hwframe_ctx_alloc(device);
-            if (!ctx->hwframes_ref) {
-                err = AVERROR(ENOMEM);
-                goto fail;
-            }
-            frames = (AVHWFramesContext*)ctx->hwframes_ref->data;
-
-            frames->format    = outlink->format;
-            frames->sw_format = hwfc->sw_format;
-            frames->width     = hwfc->width;
-            frames->height    = hwfc->height;
-
-            if (avctx->extra_hw_frames >= 0)
-                frames->initial_pool_size = 2 + avctx->extra_hw_frames;
 
-            err = av_hwframe_ctx_init(ctx->hwframes_ref);
-            if (err < 0) {
-                av_log(avctx, AV_LOG_ERROR, "Failed to initialise "
-                       "target frames context: %d.\n", err);
-                goto fail;
-            }
+            err = create_hwframe_context(avctx, device, outlink->format,
+                                         hwfc->sw_format, hwfc->width,
+                                         hwfc->height);
+            if (err < 0)
+                 goto fail;
 
             err = av_hwframe_ctx_create_derived(&source,
                                                 inlink->format,
@@ -212,29 +226,10 @@ static int hwmap_config_output(AVFilterLink *outlink)
         }
 
         ctx->reverse = 1;
-
-        ctx->hwframes_ref = av_hwframe_ctx_alloc(device);
-        if (!ctx->hwframes_ref) {
-            err = AVERROR(ENOMEM);
-            goto fail;
-        }
-        hwfc = (AVHWFramesContext*)ctx->hwframes_ref->data;
-
-        hwfc->format    = outlink->format;
-        hwfc->sw_format = inlink->format;
-        hwfc->width     = inlink->w;
-        hwfc->height    = inlink->h;
-
-        if (avctx->extra_hw_frames >= 0)
-            hwfc->initial_pool_size = 2 + avctx->extra_hw_frames;
-
-        err = av_hwframe_ctx_init(ctx->hwframes_ref);
-        if (err < 0) {
-            av_log(avctx, AV_LOG_ERROR, "Failed to create frame "
-                   "context for reverse mapping: %d.\n", err);
+        err = create_hwframe_context(avctx, device, outlink->format,
+                                     inlink->format, inlink->w, inlink->h);
+        if (err < 0)
             goto fail;
-        }
-
     } else {
         av_log(avctx, AV_LOG_ERROR, "Mapping requires a hardware "
                "context (a device, or frames on input).\n");
-- 
2.7.4



More information about the ffmpeg-devel mailing list