2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #include <gst/video/video.h>
28 /* elementfactory information */
29 static GstElementDetails smpte_details = {
31 "Filter/Editor/Video",
32 "Apply the standard SMPTE transitions on video images",
33 "Wim Taymans <wim.taymans@chello.be>"
36 static GstStaticPadTemplate gst_smpte_src_template =
37 GST_STATIC_PAD_TEMPLATE ("src",
40 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420")
44 static GstStaticPadTemplate gst_smpte_sink1_template =
45 GST_STATIC_PAD_TEMPLATE ("sink1",
48 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420")
52 static GstStaticPadTemplate gst_smpte_sink2_template =
53 GST_STATIC_PAD_TEMPLATE ("sink2",
56 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420")
61 /* SMPTE signals and args */
77 #define GST_TYPE_SMPTE_TRANSITION_TYPE (gst_smpte_transition_type_get_type())
79 gst_smpte_transition_type_get_type (void)
81 static GType smpte_transition_type = 0;
82 GEnumValue *smpte_transitions;
84 if (!smpte_transition_type) {
85 const GList *definitions;
88 definitions = gst_mask_get_definitions ();
90 g_new0 (GEnumValue, g_list_length ((GList *) definitions) + 1);
93 GstMaskDefinition *definition = (GstMaskDefinition *) definitions->data;
95 definitions = g_list_next (definitions);
97 smpte_transitions[i].value = definition->type;
98 smpte_transitions[i].value_nick = definition->short_name;
99 smpte_transitions[i].value_name = definition->long_name;
104 smpte_transition_type =
105 g_enum_register_static ("GstSMPTETransitionType", smpte_transitions);
107 return smpte_transition_type;
111 static void gst_smpte_class_init (GstSMPTEClass * klass);
112 static void gst_smpte_base_init (GstSMPTEClass * klass);
113 static void gst_smpte_init (GstSMPTE * smpte);
115 static GstFlowReturn gst_smpte_collected (GstCollectPads * pads,
118 static void gst_smpte_set_property (GObject * object, guint prop_id,
119 const GValue * value, GParamSpec * pspec);
120 static void gst_smpte_get_property (GObject * object, guint prop_id,
121 GValue * value, GParamSpec * pspec);
123 static GstElementClass *parent_class = NULL;
125 /*static guint gst_smpte_signals[LAST_SIGNAL] = { 0 }; */
128 gst_smpte_get_type (void)
130 static GType smpte_type = 0;
133 static const GTypeInfo smpte_info = {
134 sizeof (GstSMPTEClass),
135 (GBaseInitFunc) gst_smpte_base_init,
137 (GClassInitFunc) gst_smpte_class_init,
142 (GInstanceInitFunc) gst_smpte_init,
146 g_type_register_static (GST_TYPE_ELEMENT, "GstSMPTE", &smpte_info, 0);
152 gst_smpte_base_init (GstSMPTEClass * klass)
154 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
156 gst_element_class_add_pad_template (element_class,
157 gst_static_pad_template_get (&gst_smpte_sink1_template));
158 gst_element_class_add_pad_template (element_class,
159 gst_static_pad_template_get (&gst_smpte_sink2_template));
160 gst_element_class_add_pad_template (element_class,
161 gst_static_pad_template_get (&gst_smpte_src_template));
162 gst_element_class_set_details (element_class, &smpte_details);
166 gst_smpte_class_init (GstSMPTEClass * klass)
168 GObjectClass *gobject_class;
169 GstElementClass *gstelement_class;
171 gobject_class = (GObjectClass *) klass;
172 gstelement_class = (GstElementClass *) klass;
174 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
176 gobject_class->set_property = gst_smpte_set_property;
177 gobject_class->get_property = gst_smpte_get_property;
181 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TYPE,
182 g_param_spec_enum ("type", "Type", "The type of transition to use",
183 GST_TYPE_SMPTE_TRANSITION_TYPE, 1, G_PARAM_READWRITE));
184 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FPS,
185 g_param_spec_float ("fps", "FPS",
186 "Frames per second if no input files are given", 0., G_MAXFLOAT, 25.,
188 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BORDER,
189 g_param_spec_int ("border", "Border",
190 "The border width of the transition", 0, G_MAXINT, 0,
192 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DEPTH,
193 g_param_spec_int ("depth", "Depth", "Depth of the mask in bits", 1, 24,
194 16, G_PARAM_READWRITE));
197 /* wht yel cya grn mag red blu blk -I Q */
198 static int y_colors[] = { 255, 226, 179, 150, 105, 76, 29, 16, 16, 0 };
199 static int u_colors[] = { 128, 0, 170, 46, 212, 85, 255, 128, 0, 128 };
200 static int v_colors[] = { 128, 155, 0, 21, 235, 255, 107, 128, 128, 255 };
203 fill_i420 (guint8 * data, gint width, gint height, gint color)
205 gint size = width * height, size4 = size >> 2;
207 guint8 *up = data + size;
208 guint8 *vp = data + size + size4;
210 memset (yp, y_colors[color], size);
211 memset (up, u_colors[color], size4);
212 memset (vp, v_colors[color], size4);
216 gst_smpte_update_mask (GstSMPTE * smpte, gint type, gint depth, gint width,
221 newmask = gst_mask_factory_new (type, depth, width, height);
224 gst_mask_destroy (smpte->mask);
226 smpte->mask = newmask;
228 smpte->depth = depth;
229 smpte->width = width;
230 smpte->height = height;
238 gst_smpte_setcaps (GstPad * pad, GstCaps * caps)
241 GstStructure *structure;
244 smpte = GST_SMPTE (GST_PAD_PARENT (pad));
246 structure = gst_caps_get_structure (caps, 0);
248 ret = gst_structure_get_int (structure, "width", &smpte->width);
249 ret &= gst_structure_get_int (structure, "height", &smpte->height);
250 ret &= gst_structure_get_double (structure, "framerate", &smpte->fps);
254 gst_smpte_update_mask (smpte, smpte->type, smpte->depth, smpte->width,
257 /* forward to the next plugin */
262 gst_smpte_init (GstSMPTE * smpte)
265 gst_pad_new_from_static_template (&gst_smpte_sink1_template, "sink1");
266 gst_pad_set_setcaps_function (smpte->sinkpad1, gst_smpte_setcaps);
267 gst_element_add_pad (GST_ELEMENT (smpte), smpte->sinkpad1);
270 gst_pad_new_from_static_template (&gst_smpte_sink2_template, "sink2");
271 gst_pad_set_setcaps_function (smpte->sinkpad2, gst_smpte_setcaps);
272 gst_element_add_pad (GST_ELEMENT (smpte), smpte->sinkpad2);
275 gst_pad_new_from_static_template (&gst_smpte_src_template, "src");
276 gst_element_add_pad (GST_ELEMENT (smpte), smpte->srcpad);
278 smpte->collect = gst_collect_pads_new ();
279 gst_collect_pads_set_function (smpte->collect,
280 (GstCollectPadsFunction) GST_DEBUG_FUNCPTR (gst_smpte_collected), smpte);
281 gst_collect_pads_start (smpte->collect);
283 gst_collect_pads_add_pad (smpte->collect, smpte->sinkpad1,
284 sizeof (GstCollectData));
285 gst_collect_pads_add_pad (smpte->collect, smpte->sinkpad2,
286 sizeof (GstCollectData));
291 smpte->duration = 512;
296 gst_smpte_update_mask (smpte, smpte->type, smpte->depth, smpte->width,
301 gst_smpte_blend_i420 (guint8 * in1, guint8 * in2, guint8 * out, GstMask * mask,
302 gint width, gint height, gint border, gint pos)
308 guint8 *in1u, *in1v, *in2u, *in2v, *outu, *outv;
309 gint lumsize = width * height;
310 gint chromsize = lumsize >> 2;
318 in1u = in1 + lumsize;
319 in1v = in1u + chromsize;
320 in2u = in2 + lumsize;
321 in2v = in2u + chromsize;
322 outu = out + lumsize;
323 outv = outu + chromsize;
327 for (i = 0; i < height; i++) {
328 for (j = 0; j < width; j++) {
330 value = ((CLAMP (value, min, max) - min) << 8) / border;
332 *out++ = ((*in1++ * value) + (*in2++ * (256 - value))) >> 8;
333 if (!(i & 1) && !(j & 1)) {
334 *outu++ = ((*in1u++ * value) + (*in2u++ * (256 - value))) >> 8;
335 *outv++ = ((*in1v++ * value) + (*in2v++ * (256 - value))) >> 8;
342 gst_smpte_collected (GstCollectPads * pads, GstSMPTE * smpte)
346 GstBuffer *in1 = NULL, *in2 = NULL;
349 ts = smpte->position * GST_SECOND / smpte->fps;
351 for (collected = pads->data; collected; collected = g_slist_next (collected)) {
352 GstCollectData *data;
354 data = (GstCollectData *) collected->data;
356 if (data->pad == smpte->sinkpad1)
357 in1 = gst_collect_pads_pop (pads, data);
358 else if (data->pad == smpte->sinkpad2)
359 in2 = gst_collect_pads_pop (pads, data);
363 in1 = gst_buffer_new_and_alloc (smpte->width * smpte->height * 3);
364 fill_i420 (GST_BUFFER_DATA (in1), smpte->width, smpte->height, 7);
367 in2 = gst_buffer_new_and_alloc (smpte->width * smpte->height * 3);
368 fill_i420 (GST_BUFFER_DATA (in2), smpte->width, smpte->height, 0);
371 if (smpte->position < smpte->duration) {
372 outbuf = gst_buffer_new_and_alloc (smpte->width * smpte->height * 3);
374 /* set caps if not done yet */
375 if (!GST_PAD_CAPS (smpte->srcpad)) {
379 gst_caps_copy (gst_static_caps_get (&gst_smpte_src_template.
381 gst_caps_set_simple (caps, "width", G_TYPE_INT, smpte->width, "height",
382 G_TYPE_INT, smpte->height, "framerate", G_TYPE_DOUBLE, smpte->fps,
385 gst_pad_set_caps (smpte->srcpad, caps);
387 gst_buffer_set_caps (outbuf, GST_PAD_CAPS (smpte->srcpad));
389 gst_smpte_blend_i420 (GST_BUFFER_DATA (in1),
390 GST_BUFFER_DATA (in2),
391 GST_BUFFER_DATA (outbuf),
392 smpte->mask, smpte->width, smpte->height,
394 ((1 << smpte->depth) + smpte->border) *
395 smpte->position / smpte->duration);
399 gst_buffer_ref (in2);
405 gst_buffer_unref (in1);
407 gst_buffer_unref (in2);
409 GST_BUFFER_TIMESTAMP (outbuf) = ts;
411 return gst_pad_push (smpte->srcpad, outbuf);
415 gst_smpte_set_property (GObject * object, guint prop_id,
416 const GValue * value, GParamSpec * pspec)
420 smpte = GST_SMPTE (object);
425 gint type = g_value_get_enum (value);
427 gst_smpte_update_mask (smpte, type, smpte->depth,
428 smpte->width, smpte->height);
432 smpte->border = g_value_get_int (value);
435 smpte->fps = g_value_get_float (value);
439 gint depth = g_value_get_int (value);
441 gst_smpte_update_mask (smpte, smpte->type, depth,
442 smpte->width, smpte->height);
446 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
452 gst_smpte_get_property (GObject * object, guint prop_id,
453 GValue * value, GParamSpec * pspec)
457 smpte = GST_SMPTE (object);
462 g_value_set_enum (value, smpte->mask->type);
466 g_value_set_float (value, smpte->fps);
469 g_value_set_int (value, smpte->border);
472 g_value_set_int (value, smpte->depth);
475 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
482 plugin_init (GstPlugin * plugin)
484 return gst_element_register (plugin, "smpte", GST_RANK_NONE, GST_TYPE_SMPTE);
487 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
490 "Apply the standard SMPTE transitions on video images",
491 plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)