h264_metadata: Add option to delete filler data
[libav.git] / libavfilter / vf_hwmap.c
index 2983528..d5ad276 100644 (file)
@@ -54,7 +54,7 @@ static int hwmap_config_output(AVFilterLink *outlink)
     AVHWFramesContext *hwfc;
     AVBufferRef *device;
     const AVPixFmtDescriptor *desc;
-    int err;
+    int err, device_is_derived;
 
     av_log(avctx, AV_LOG_DEBUG, "Configure hwmap %s -> %s.\n",
            av_get_pix_fmt_name(inlink->format),
@@ -63,6 +63,7 @@ static int hwmap_config_output(AVFilterLink *outlink)
     av_buffer_unref(&ctx->hwframes_ref);
 
     device = avctx->hw_device_ctx;
+    device_is_derived = 0;
 
     if (inlink->hw_frames_ctx) {
         hwfc = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
@@ -73,6 +74,7 @@ static int hwmap_config_output(AVFilterLink *outlink)
             type = av_hwdevice_find_type_by_name(ctx->derive_device_type);
             if (type == AV_HWDEVICE_TYPE_NONE) {
                 av_log(avctx, AV_LOG_ERROR, "Invalid device type.\n");
+                err = AVERROR(EINVAL);
                 goto fail;
             }
 
@@ -83,6 +85,7 @@ static int hwmap_config_output(AVFilterLink *outlink)
                        "device context: %d.\n", err);
                 goto fail;
             }
+            device_is_derived = 1;
         }
 
         desc = av_pix_fmt_desc_get(outlink->format);
@@ -135,7 +138,9 @@ static int hwmap_config_output(AVFilterLink *outlink)
             frames->sw_format = hwfc->sw_format;
             frames->width     = hwfc->width;
             frames->height    = hwfc->height;
-            frames->initial_pool_size = 64;
+
+            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) {
@@ -215,6 +220,9 @@ static int hwmap_config_output(AVFilterLink *outlink)
         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 "
@@ -237,9 +245,13 @@ static int hwmap_config_output(AVFilterLink *outlink)
     outlink->w = inlink->w;
     outlink->h = inlink->h;
 
+    if (device_is_derived)
+        av_buffer_unref(&device);
     return 0;
 
 fail:
+    if (device_is_derived)
+        av_buffer_unref(&device);
     av_buffer_unref(&ctx->hwframes_ref);
     return err;
 }