[vlc-devel] [PATCH 41/42] vdpau: sharpen/blur filter
Rémi Denis-Courmont
remi at remlab.net
Fri Jun 28 20:30:29 CEST 2013
---
modules/hw/vdpau/Makefile.am | 5 ++
modules/hw/vdpau/chroma.c | 21 ++++++--
modules/hw/vdpau/picture.c | 2 +
modules/hw/vdpau/sharpen.c | 119 +++++++++++++++++++++++++++++++++++++++++++
modules/hw/vdpau/vlc_vdpau.h | 1 +
5 files changed, 145 insertions(+), 3 deletions(-)
create mode 100644 modules/hw/vdpau/sharpen.c
diff --git a/modules/hw/vdpau/Makefile.am b/modules/hw/vdpau/Makefile.am
index ecb2c21..16ab670 100644
--- a/modules/hw/vdpau/Makefile.am
+++ b/modules/hw/vdpau/Makefile.am
@@ -31,6 +31,11 @@ libvdpau_deinterlace_plugin_la_CFLAGS = $(AM_CFLAGS) # dummy
libvdpau_deinterlace_plugin_la_LIBADD = $(AM_LIBADD)
libvlc_LTLIBRARIES += libvdpau_deinterlace_plugin.la
+libvdpau_sharpen_plugin_la_SOURCES = sharpen.c picture.c
+libvdpau_sharpen_plugin_la_CFLAGS = $(AM_CFLAGS) # dummy
+libvdpau_sharpen_plugin_la_LIBADD = $(AM_LIBADD)
+libvlc_LTLIBRARIES += libvdpau_sharpen_plugin.la
+
libvdpau_chroma_plugin_la_SOURCES = chroma.c picture.c
libvdpau_chroma_plugin_la_CFLAGS = $(AM_CFLAGS) # dummy
libvdpau_chroma_plugin_la_LIBADD = $(AM_LIBADD)
diff --git a/modules/hw/vdpau/chroma.c b/modules/hw/vdpau/chroma.c
index 00da2fa..aac0053 100644
--- a/modules/hw/vdpau/chroma.c
+++ b/modules/hw/vdpau/chroma.c
@@ -268,6 +268,7 @@ static inline VdpVideoSurface picture_GetVideoSurface(const picture_t *pic)
static picture_t *MixerRender(filter_t *filter, picture_t *src)
{
filter_sys_t *sys = filter->p_sys;
+ VdpStatus err;
picture_t *dst = OutputAllocate(filter);
if (dst == NULL)
@@ -287,9 +288,24 @@ static picture_t *MixerRender(filter_t *filter, picture_t *src)
goto skip;
picture_CopyProperties(dst, src);
+ vlc_vdp_video_field_t *f = src->context;
+
+ /* Configure mixer depending on upstream video filters */
+ const VdpVideoMixerAttribute attrs[] = {
+ VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL,
+ };
+ const void *const values[] = {
+ &f->sharpen,
+ };
+
+ err = vdp_video_mixer_set_attribute_values(sys->vdp, sys->mixer,
+ sizeof (attrs) / sizeof (attrs[0]), attrs, values);
+ if (err != VDP_STATUS_OK)
+ msg_Err(filter, "video %s %s failure: %s", "mixer", "attributes",
+ vdp_get_error_string(sys->vdp, err));
+
/* Render video into output */
- VdpVideoMixerPictureStructure structure =
- ((vlc_vdp_video_field_t *)(src->context))->structure;
+ VdpVideoMixerPictureStructure structure = f->structure;
VdpVideoSurface past[MAX_PAST];
VdpVideoSurface surface = picture_GetVideoSurface(src);
VdpVideoSurface future[MAX_FUTURE];
@@ -304,7 +320,6 @@ static picture_t *MixerRender(filter_t *filter, picture_t *src)
filter->fmt_out.video.i_visible_width,
filter->fmt_out.video.i_visible_height
};
- VdpStatus err;
for (unsigned i = 0; i < MAX_PAST; i++)
{
diff --git a/modules/hw/vdpau/picture.c b/modules/hw/vdpau/picture.c
index d8ed5ad..5f78ef6 100644
--- a/modules/hw/vdpau/picture.c
+++ b/modules/hw/vdpau/picture.c
@@ -72,6 +72,7 @@ VdpStatus vlc_vdp_video_attach(vdp_t *vdp, VdpVideoSurface surface,
field->destroy = SurfaceDestroy;
field->frame = frame;
field->structure = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
+ field->sharpen = 0.f;
atomic_init(&frame->refs, 1);
frame->surface = surface;
@@ -102,6 +103,7 @@ picture_t *vlc_vdp_video_copy(picture_t *src)
field->destroy = SurfaceDestroy;
field->frame = frame;
field->structure = field->structure;
+ field->sharpen = field->sharpen;
atomic_fetch_add(&frame->refs, 1);
return dst;
diff --git a/modules/hw/vdpau/sharpen.c b/modules/hw/vdpau/sharpen.c
new file mode 100644
index 0000000..594c690
--- /dev/null
+++ b/modules/hw/vdpau/sharpen.c
@@ -0,0 +1,119 @@
+/*****************************************************************************
+ * sharpen.c: VDPAU sharpen video filter
+ *****************************************************************************
+ * Copyright (C) 2013 Rémi Denis-Courmont
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_filter.h>
+#include <vlc_atomic.h>
+#include "vlc_vdpau.h"
+
+struct filter_sys_t
+{
+ atomic_uint_fast32_t sigma;
+};
+
+static int SharpenCallback(vlc_object_t *obj, const char *varname,
+ vlc_value_t prev, vlc_value_t cur, void *data)
+{
+ filter_sys_t *sys = data;
+ union { uint32_t u; float f; } u;
+
+ if (cur.f_float > 2.f)
+ u.f = +1.f;
+ else
+ if (cur.f_float > -2.f)
+ u.f = cur.f_float / 2.f;
+ else
+ u.f = -1.f;
+
+ atomic_store(&sys->sigma, u.u);
+ (void) obj; (void) varname; (void) prev;
+ return VLC_SUCCESS;
+}
+
+static picture_t *Sharpen(filter_t *filter, picture_t *pic)
+{
+ filter_sys_t *sys = filter->p_sys;
+ vlc_vdp_video_field_t *f = pic->context;
+ union { uint32_t u; float f; } u;
+
+ if (unlikely(f == NULL))
+ return pic;
+
+ u.u = atomic_load(&sys->sigma);
+ f->sharpen += u.f;
+ if (f->sharpen > +1.f)
+ f->sharpen = +1.f;
+ if (f->sharpen < -1.f)
+ f->sharpen = -1.f;
+
+ return pic;
+}
+
+static const char *const options[] = { "sigma", NULL };
+
+static int Open(vlc_object_t *obj)
+{
+ filter_t *filter = (filter_t *)obj;
+
+ if (filter->fmt_in.video.i_chroma != VLC_CODEC_VDPAU_VIDEO_422
+ && filter->fmt_in.video.i_chroma != VLC_CODEC_VDPAU_VIDEO_420)
+ return VLC_EGENERIC;
+ if (!video_format_IsSimilar(&filter->fmt_in.video, &filter->fmt_out.video))
+ return VLC_EGENERIC;
+
+ filter_sys_t *sys = malloc(sizeof (*sys));
+ if (unlikely(sys == NULL))
+ return VLC_ENOMEM;
+
+ filter->pf_video_filter = Sharpen;
+ filter->p_sys = sys;
+
+ config_ChainParse(filter, "sharpen-", options, filter->p_cfg);
+ var_AddCallback(filter, "sharpen-sigma", SharpenCallback, sys);
+
+ union { uint32_t u; float f; } u;
+ u.f = var_CreateGetFloatCommand(filter, "sharpen-sigma");
+ atomic_init(&sys->sigma, u.u);
+
+ return VLC_SUCCESS;
+}
+
+static void Close(vlc_object_t *obj)
+{
+ filter_t *filter = (filter_t *)obj;
+ filter_sys_t *sys = filter->p_sys;
+
+ var_DelCallback(filter, "sharpen-sigma", SharpenCallback, sys);
+ free(sys);
+}
+
+vlc_module_begin()
+ set_description(N_("VDPAU sharpen video filter"))
+ set_category(CAT_VIDEO)
+ set_subcategory(SUBCAT_VIDEO_VFILTER)
+ set_capability("video filter2", 0)
+ add_shortcut("sharpen")
+ set_callbacks(Open, Close)
+vlc_module_end()
diff --git a/modules/hw/vdpau/vlc_vdpau.h b/modules/hw/vdpau/vlc_vdpau.h
index ea3f924..7bf9ca4 100644
--- a/modules/hw/vdpau/vlc_vdpau.h
+++ b/modules/hw/vdpau/vlc_vdpau.h
@@ -259,6 +259,7 @@ typedef struct vlc_vdp_video_field
void (*destroy)(void *); /* must be first @ref picture_Release() */
vlc_vdp_video_frame_t *frame;
VdpVideoMixerPictureStructure structure;
+ float sharpen;
} vlc_vdp_video_field_t;
/**
--
1.8.3.1
More information about the vlc-devel
mailing list