mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-30 12:49:40 +00:00
filter: add support for denoising.
Noise reduction is configured with a float value. The supported range is 0.0 .. 1.0 with 0.0 being the default, and that means no denoise operation at all. Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
This commit is contained in:
parent
81395418e9
commit
22f55bd513
3 changed files with 94 additions and 0 deletions
|
@ -387,6 +387,7 @@ gst_vaapi_filter_get_formats
|
|||
gst_vaapi_filter_set_operation
|
||||
gst_vaapi_filter_set_format
|
||||
gst_vaapi_filter_set_cropping_rectangle
|
||||
gst_vaapi_filter_set_denoising_level
|
||||
<SUBSECTION Standard>
|
||||
GST_VAAPI_FILTER
|
||||
</SECTION>
|
||||
|
|
|
@ -182,6 +182,7 @@ enum {
|
|||
|
||||
PROP_FORMAT = GST_VAAPI_FILTER_OP_FORMAT,
|
||||
PROP_CROP = GST_VAAPI_FILTER_OP_CROP,
|
||||
PROP_DENOISE = GST_VAAPI_FILTER_OP_DENOISE,
|
||||
|
||||
N_PROPERTIES
|
||||
};
|
||||
|
@ -216,6 +217,18 @@ init_properties(void)
|
|||
"The cropping rectangle",
|
||||
GST_VAAPI_TYPE_RECTANGLE,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
/**
|
||||
* GstVaapiFilter:denoise:
|
||||
*
|
||||
* The level of noise reduction to apply.
|
||||
*/
|
||||
g_properties[PROP_DENOISE] =
|
||||
g_param_spec_float("denoise",
|
||||
"Denoising Level",
|
||||
"The level of denoising to apply",
|
||||
0.0, 1.0, 0.0,
|
||||
G_PARAM_READWRITE);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -253,6 +266,11 @@ op_data_new(GstVaapiFilterOp op, GParamSpec *pspec)
|
|||
case GST_VAAPI_FILTER_OP_CROP:
|
||||
op_data->va_type = VAProcFilterNone;
|
||||
break;
|
||||
case GST_VAAPI_FILTER_OP_DENOISE:
|
||||
op_data->va_type = VAProcFilterNoiseReduction;
|
||||
op_data->va_cap_size = sizeof(VAProcFilterCap);
|
||||
op_data->va_buffer_size = sizeof(VAProcFilterParameterBuffer);
|
||||
break;
|
||||
default:
|
||||
g_assert(0 && "unsupported operation");
|
||||
goto error;
|
||||
|
@ -485,6 +503,53 @@ op_ensure_buffer(GstVaapiFilter *filter, GstVaapiFilterOpData *op_data)
|
|||
&op_data->va_buffer, NULL);
|
||||
}
|
||||
|
||||
/* Update a generic filter (float value) */
|
||||
#if USE_VA_VPP
|
||||
static gboolean
|
||||
op_set_generic_unlocked(GstVaapiFilter *filter, GstVaapiFilterOpData *op_data,
|
||||
gfloat value)
|
||||
{
|
||||
VAProcFilterParameterBuffer *buf;
|
||||
VAProcFilterCap *filter_cap;
|
||||
gfloat va_value;
|
||||
|
||||
if (!op_data || !op_ensure_buffer(filter, op_data))
|
||||
return FALSE;
|
||||
|
||||
op_data->is_enabled =
|
||||
(value != G_PARAM_SPEC_FLOAT(op_data->pspec)->default_value);
|
||||
if (!op_data->is_enabled)
|
||||
return TRUE;
|
||||
|
||||
filter_cap = op_data->va_caps;
|
||||
if (!op_data_get_value_float(op_data, &filter_cap->range, value, &va_value))
|
||||
return FALSE;
|
||||
|
||||
buf = vaapi_map_buffer(filter->va_display, op_data->va_buffer);
|
||||
if (!buf)
|
||||
return FALSE;
|
||||
|
||||
buf->type = op_data->va_type;
|
||||
buf->value = va_value;
|
||||
vaapi_unmap_buffer(filter->va_display, op_data->va_buffer, NULL);
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline gboolean
|
||||
op_set_generic(GstVaapiFilter *filter, GstVaapiFilterOpData *op_data,
|
||||
gfloat value)
|
||||
{
|
||||
gboolean success = FALSE;
|
||||
|
||||
#if USE_VA_VPP
|
||||
GST_VAAPI_DISPLAY_LOCK(filter->display);
|
||||
success = op_set_generic_unlocked(filter, op_data, value);
|
||||
GST_VAAPI_DISPLAY_UNLOCK(filter->display);
|
||||
#endif
|
||||
return success;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* --- Surface Formats --- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -796,6 +861,10 @@ gst_vaapi_filter_set_operation(GstVaapiFilter *filter, GstVaapiFilterOp op,
|
|||
case GST_VAAPI_FILTER_OP_CROP:
|
||||
return gst_vaapi_filter_set_cropping_rectangle(filter, value ?
|
||||
g_value_get_boxed(value) : NULL);
|
||||
case GST_VAAPI_FILTER_OP_DENOISE:
|
||||
return op_set_generic(filter, op_data,
|
||||
(value ? g_value_get_float(value) :
|
||||
G_PARAM_SPEC_FLOAT(op_data->pspec)->default_value));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -1005,3 +1074,22 @@ gst_vaapi_filter_set_cropping_rectangle(GstVaapiFilter *filter,
|
|||
filter->crop_rect = *rect;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_vaapi_filter_set_denoising_level:
|
||||
* @filter: a #GstVaapiFilter
|
||||
* @level: the level of noise reduction to apply
|
||||
*
|
||||
* Sets the noise reduction level to apply. If @level is 0.0f, this
|
||||
* corresponds to disabling the noise reduction algorithm.
|
||||
*
|
||||
* Return value: %TRUE if the operation is supported, %FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
gst_vaapi_filter_set_denoising_level(GstVaapiFilter *filter, gfloat level)
|
||||
{
|
||||
g_return_val_if_fail(filter != NULL, FALSE);
|
||||
|
||||
return op_set_generic(filter,
|
||||
find_operation(filter, GST_VAAPI_FILTER_OP_DENOISE), level);
|
||||
}
|
||||
|
|
|
@ -33,12 +33,14 @@ typedef struct _GstVaapiFilterOpInfo GstVaapiFilterOpInfo;
|
|||
/**
|
||||
* @GST_VAAPI_FILTER_OP_FORMAT: Force output pixel format (#GstVideoFormat).
|
||||
* @GST_VAAPI_FILTER_OP_CROP: Crop source surface (#GstVaapiRectangle).
|
||||
* @GST_VAAPI_FILTER_OP_DENOISE: Noise reduction (float).
|
||||
*
|
||||
* The set of operations that could be applied to the filter.
|
||||
*/
|
||||
typedef enum {
|
||||
GST_VAAPI_FILTER_OP_FORMAT = 1,
|
||||
GST_VAAPI_FILTER_OP_CROP,
|
||||
GST_VAAPI_FILTER_OP_DENOISE,
|
||||
} GstVaapiFilterOp;
|
||||
|
||||
/**
|
||||
|
@ -107,4 +109,7 @@ gboolean
|
|||
gst_vaapi_filter_set_cropping_rectangle(GstVaapiFilter *filter,
|
||||
const GstVaapiRectangle *rect);
|
||||
|
||||
gboolean
|
||||
gst_vaapi_filter_set_denoising_level(GstVaapiFilter *filter, gfloat level);
|
||||
|
||||
#endif /* GST_VAAPI_FILTER_H */
|
||||
|
|
Loading…
Reference in a new issue