2 * Copyright (C) 2011 David Schleef <ds@schleef.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
17 * Boston, MA 02110-1335, USA.
20 * SECTION:element-gstvideofilter2
29 #include <gst/base/gstbasetransform.h>
30 #include <gst/video/video.h>
31 #include "gstvideofilter2.h"
33 GST_DEBUG_CATEGORY_STATIC (gst_video_filter2_debug_category);
34 #define GST_CAT_DEFAULT gst_video_filter2_debug_category
39 static void gst_video_filter2_set_property (GObject * object,
40 guint property_id, const GValue * value, GParamSpec * pspec);
41 static void gst_video_filter2_get_property (GObject * object,
42 guint property_id, GValue * value, GParamSpec * pspec);
43 static void gst_video_filter2_dispose (GObject * object);
44 static void gst_video_filter2_finalize (GObject * object);
46 static GstCaps *gst_video_filter2_transform_caps (GstBaseTransform * trans,
47 GstPadDirection direction, GstCaps * caps);
49 gst_video_filter2_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
52 gst_video_filter2_set_caps (GstBaseTransform * trans, GstCaps * incaps,
54 static gboolean gst_video_filter2_start (GstBaseTransform * trans);
55 static gboolean gst_video_filter2_stop (GstBaseTransform * trans);
56 static GstFlowReturn gst_video_filter2_transform (GstBaseTransform * trans,
57 GstBuffer * inbuf, GstBuffer * outbuf);
58 static GstFlowReturn gst_video_filter2_transform_ip (GstBaseTransform * trans,
67 /* class initialization */
69 #define DEBUG_INIT(bla) \
70 GST_DEBUG_CATEGORY_INIT (gst_video_filter2_debug_category, "videofilter2", 0, \
71 "debug category for videofilter2 element");
73 GST_BOILERPLATE_FULL (GstVideoFilter2, gst_video_filter2, GstBaseTransform,
74 GST_TYPE_BASE_TRANSFORM, DEBUG_INIT);
77 gst_video_filter2_base_init (gpointer g_class)
79 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
82 GstPadTemplate *pad_template;
84 caps = gst_caps_new_empty ();
85 for (i = GST_VIDEO_FORMAT_I420; i <= GST_VIDEO_FORMAT_I420; i++) {
86 gst_caps_append (caps, gst_video_format_new_template_caps (i));
90 gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
92 gst_element_class_add_pad_template (element_class, pad_template);
93 gst_object_unref (pad_template);
95 gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, caps);
96 gst_element_class_add_pad_template (element_class, pad_template);
97 gst_object_unref (pad_template);
101 gst_video_filter2_class_init (GstVideoFilter2Class * klass)
103 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
104 GstBaseTransformClass *base_transform_class =
105 GST_BASE_TRANSFORM_CLASS (klass);
107 gobject_class->set_property = gst_video_filter2_set_property;
108 gobject_class->get_property = gst_video_filter2_get_property;
109 gobject_class->dispose = gst_video_filter2_dispose;
110 gobject_class->finalize = gst_video_filter2_finalize;
111 base_transform_class->transform_caps =
112 GST_DEBUG_FUNCPTR (gst_video_filter2_transform_caps);
113 base_transform_class->get_unit_size =
114 GST_DEBUG_FUNCPTR (gst_video_filter2_get_unit_size);
115 base_transform_class->set_caps =
116 GST_DEBUG_FUNCPTR (gst_video_filter2_set_caps);
117 base_transform_class->start = GST_DEBUG_FUNCPTR (gst_video_filter2_start);
118 base_transform_class->stop = GST_DEBUG_FUNCPTR (gst_video_filter2_stop);
119 base_transform_class->transform =
120 GST_DEBUG_FUNCPTR (gst_video_filter2_transform);
121 base_transform_class->transform_ip =
122 GST_DEBUG_FUNCPTR (gst_video_filter2_transform_ip);
127 gst_video_filter2_init (GstVideoFilter2 * videofilter2,
128 GstVideoFilter2Class * videofilter2_class)
131 gst_base_transform_set_qos_enabled (GST_BASE_TRANSFORM (videofilter2), TRUE);
135 gst_video_filter2_set_property (GObject * object, guint property_id,
136 const GValue * value, GParamSpec * pspec)
138 g_return_if_fail (GST_IS_VIDEO_FILTER2 (object));
140 switch (property_id) {
142 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
148 gst_video_filter2_get_property (GObject * object, guint property_id,
149 GValue * value, GParamSpec * pspec)
151 g_return_if_fail (GST_IS_VIDEO_FILTER2 (object));
153 switch (property_id) {
155 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
161 gst_video_filter2_dispose (GObject * object)
163 g_return_if_fail (GST_IS_VIDEO_FILTER2 (object));
165 /* clean up as possible. may be called multiple times */
167 G_OBJECT_CLASS (parent_class)->dispose (object);
171 gst_video_filter2_finalize (GObject * object)
173 g_return_if_fail (GST_IS_VIDEO_FILTER2 (object));
175 /* clean up object here */
177 G_OBJECT_CLASS (parent_class)->finalize (object);
181 gst_video_filter2_transform_caps (GstBaseTransform * trans,
182 GstPadDirection direction, GstCaps * caps)
184 return gst_caps_ref (caps);
188 gst_video_filter2_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
191 GstVideoFormat format;
195 ret = gst_video_format_parse_caps (caps, &format, &width, &height);
196 *size = gst_video_format_get_size (format, width, height);
202 gst_video_filter2_set_caps (GstBaseTransform * trans, GstCaps * incaps,
205 GstVideoFilter2 *videofilter2;
209 GstVideoFormat format;
211 g_return_val_if_fail (GST_IS_VIDEO_FILTER2 (trans), FALSE);
212 videofilter2 = GST_VIDEO_FILTER2 (trans);
214 ret = gst_video_format_parse_caps (incaps, &format, &width, &height);
217 videofilter2->format = format;
218 videofilter2->width = width;
219 videofilter2->height = height;
226 gst_video_filter2_start (GstBaseTransform * trans)
233 gst_video_filter2_stop (GstBaseTransform * trans)
240 gst_video_filter2_transform (GstBaseTransform * trans, GstBuffer * inbuf,
244 return GST_FLOW_ERROR;
248 gst_video_filter2_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
250 GstVideoFilter2 *video_filter2 = GST_VIDEO_FILTER2 (trans);
251 GstVideoFilter2Class *klass =
252 GST_VIDEO_FILTER2_CLASS (G_OBJECT_GET_CLASS (trans));
256 for (i = 0; klass->functions[i].format != GST_VIDEO_FORMAT_UNKNOWN; i++) {
257 if (klass->functions[i].format == video_filter2->format) {
258 ret = klass->functions[i].filter_ip (video_filter2, buf, 0,
259 video_filter2->height);
264 return GST_FLOW_ERROR;
270 gst_video_filter2_class_add_functions (GstVideoFilter2Class * klass,
271 const GstVideoFilter2Functions * functions)
273 klass->functions = functions;