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.
24 /* elementfactory information */
25 static GstElementDetails smpte_details = {
29 "Apply the standard SMPTE transitions on video images",
31 "Wim Taymans <wim.taymans@chello.be>",
35 GST_PAD_TEMPLATE_FACTORY (smpte_src_factory,
42 "format", GST_PROPS_FOURCC (GST_STR_FOURCC ("I420"))
46 GST_PAD_TEMPLATE_FACTORY (smpte_sink1_factory,
53 "format", GST_PROPS_FOURCC (GST_STR_FOURCC ("I420")),
54 "width", GST_PROPS_INT_RANGE (0, 4096),
55 "height", GST_PROPS_INT_RANGE (0, 4096)
59 GST_PAD_TEMPLATE_FACTORY (smpte_sink2_factory,
66 "format", GST_PROPS_FOURCC (GST_STR_FOURCC ("I420")),
67 "width", GST_PROPS_INT_RANGE (0, 4096),
68 "height", GST_PROPS_INT_RANGE (0, 4096)
73 /* SMPTE signals and args */
87 #define GST_TYPE_SMPTE_TRANSITION_TYPE (gst_smpte_transition_type_get_type())
89 gst_smpte_transition_type_get_type (void)
91 static GType smpte_transition_type = 0;
92 GEnumValue *smpte_transitions;
94 if (!smpte_transition_type) {
95 const GList *definitions;
98 definitions = gst_mask_get_definitions ();
99 smpte_transitions = g_new0 (GEnumValue, g_list_length ((GList *)definitions)+1);
101 while (definitions) {
102 GstMaskDefinition *definition = (GstMaskDefinition *) definitions->data;
103 definitions = g_list_next (definitions);
105 smpte_transitions[i].value = definition->type;
106 smpte_transitions[i].value_name = definition->short_name;
107 smpte_transitions[i].value_nick = definition->long_name;
112 smpte_transition_type =
113 g_enum_register_static ("GstSMPTETransitionType", smpte_transitions);
115 return smpte_transition_type;
119 static void gst_smpte_class_init (GstSMPTEClass *klass);
120 static void gst_smpte_init (GstSMPTE *smpte);
122 static void gst_smpte_loop (GstElement *element);
124 static void gst_smpte_set_property (GObject *object, guint prop_id,
125 const GValue *value, GParamSpec *pspec);
126 static void gst_smpte_get_property (GObject *object, guint prop_id,
127 GValue *value, GParamSpec *pspec);
129 static GstElementClass *parent_class = NULL;
130 /*static guint gst_smpte_signals[LAST_SIGNAL] = { 0 }; */
133 gst_smpte_get_type (void)
135 static GType smpte_type = 0;
138 static const GTypeInfo smpte_info = {
139 sizeof(GstSMPTEClass),
142 (GClassInitFunc)gst_smpte_class_init,
147 (GInstanceInitFunc)gst_smpte_init,
149 smpte_type = g_type_register_static(GST_TYPE_ELEMENT, "GstSMPTE", &smpte_info, 0);
155 gst_smpte_class_init (GstSMPTEClass *klass)
157 GObjectClass *gobject_class;
158 GstElementClass *gstelement_class;
160 gobject_class = (GObjectClass*)klass;
161 gstelement_class = (GstElementClass*)klass;
163 parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
165 gobject_class->set_property = gst_smpte_set_property;
166 gobject_class->get_property = gst_smpte_get_property;
170 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TYPE,
171 g_param_spec_enum ("type", "Type", "The type of transition to use",
172 GST_TYPE_SMPTE_TRANSITION_TYPE, 1, G_PARAM_READWRITE));
173 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FPS,
174 g_param_spec_int ("fps", "FPS", "Frames per second if no input files are given",
175 1, 255, 1, G_PARAM_READWRITE));
176 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BORDER,
177 g_param_spec_int ("border", "Border", "The border width of the transition",
178 0, G_MAXINT, 0, G_PARAM_READWRITE));
179 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DEPTH,
180 g_param_spec_int ("depth", "Depth", "Depth of the mask in bits",
181 1, 24, 16, G_PARAM_READWRITE));
184 /* wht yel cya grn mag red blu blk -I Q */
185 static int y_colors[] = { 255, 226, 179, 150, 105, 76, 29, 16, 16, 0 };
186 static int u_colors[] = { 128, 0, 170, 46, 212, 85, 255, 128, 0, 128 };
187 static int v_colors[] = { 128, 155, 0, 21, 235, 255, 107, 128, 128, 255 };
190 fill_i420 (guint8 *data, gint width, gint height, gint color)
192 gint size = width * height, size4 = size >> 2;
194 guint8 *up = data + size;
195 guint8 *vp = data + size + size4;
197 memset (yp, y_colors[color], size);
198 memset (up, u_colors[color], size4);
199 memset (vp, v_colors[color], size4);
203 gst_smpte_update_mask (GstSMPTE *smpte, gint type, gint depth, gint width, gint height)
207 newmask = gst_mask_factory_new (type, depth, width, height);
210 gst_mask_destroy (smpte->mask);
212 smpte->mask = newmask;
214 smpte->depth = depth;
215 smpte->width = width;
216 smpte->height = height;
224 gst_smpte_sinkconnect (GstPad *pad, GstCaps *caps)
228 smpte = GST_SMPTE (gst_pad_get_parent (pad));
230 if (!GST_CAPS_IS_FIXED (caps))
231 return GST_PAD_LINK_DELAYED;
233 gst_caps_get_int (caps, "width", &smpte->width);
234 gst_caps_get_int (caps, "height", &smpte->height);
236 gst_smpte_update_mask (smpte, smpte->type, smpte->depth, smpte->width, smpte->height);
238 /* forward to the next plugin */
239 return gst_pad_try_set_caps(smpte->srcpad, gst_caps_copy_1(caps));
243 gst_smpte_init (GstSMPTE *smpte)
245 smpte->sinkpad1 = gst_pad_new_from_template (
246 GST_PAD_TEMPLATE_GET (smpte_sink1_factory), "sink1");
247 gst_pad_set_link_function (smpte->sinkpad1, gst_smpte_sinkconnect);
248 gst_element_add_pad (GST_ELEMENT (smpte), smpte->sinkpad1);
250 smpte->sinkpad2 = gst_pad_new_from_template (
251 GST_PAD_TEMPLATE_GET (smpte_sink2_factory), "sink2");
252 gst_pad_set_link_function (smpte->sinkpad2, gst_smpte_sinkconnect);
253 gst_element_add_pad (GST_ELEMENT (smpte), smpte->sinkpad2);
255 smpte->srcpad = gst_pad_new_from_template (
256 GST_PAD_TEMPLATE_GET (smpte_src_factory), "src");
257 gst_element_add_pad (GST_ELEMENT (smpte), smpte->srcpad);
259 gst_element_set_loop_function (GST_ELEMENT (smpte), gst_smpte_loop);
263 smpte->duration = 64;
269 gst_smpte_update_mask (smpte, smpte->type, smpte->depth, smpte->width, smpte->height);
273 gst_smpte_blend_i420 (guint8 *in1, guint8 *in2, guint8 *out, GstMask *mask,
274 gint width, gint height, gint border, gint pos)
280 guint8 *in1u, *in1v, *in2u, *in2v, *outu, *outv;
281 gint lumsize = width * height;
282 gint chromsize = lumsize >> 2;
284 if (border == 0) border++;
289 in1u = in1 + lumsize; in1v = in1u + chromsize;
290 in2u = in2 + lumsize; in2v = in2u + chromsize;
291 outu = out + lumsize; outv = outu + chromsize;
295 for (i = 0; i < height; i++) {
296 for (j = 0; j < width; j++) {
298 value = ((CLAMP (value, min, max) - min) << 8) / border;
300 *out++ = ((*in1++ * value) + (*in2++ * (256 - value))) >> 8;
301 if (!(i & 1) && !(j & 1)) {
302 *outu++ = ((*in1u++ * value) + (*in2u++ * (256 - value))) >> 8;
303 *outv++ = ((*in1v++ * value) + (*in2v++ * (256 - value))) >> 8;
310 gst_smpte_loop (GstElement *element)
315 GstBuffer *in1 = NULL, *in2 = NULL;
317 smpte = GST_SMPTE (element);
319 ts = smpte->position * GST_SECOND / smpte->fps;
321 if (GST_PAD_IS_USABLE (smpte->sinkpad1)) {
322 in1 = gst_pad_pull (smpte->sinkpad1);
323 ts = GST_BUFFER_TIMESTAMP (in1);
326 in1 = gst_buffer_new_and_alloc (smpte->width * smpte->height * 3);
327 fill_i420 (GST_BUFFER_DATA (in1), smpte->width, smpte->height, 7);
330 if (GST_PAD_IS_USABLE (smpte->sinkpad2)) {
331 in2 = gst_pad_pull (smpte->sinkpad2);
332 ts = GST_BUFFER_TIMESTAMP (in2);
335 in2 = gst_buffer_new_and_alloc (smpte->width * smpte->height * 3);
336 fill_i420 (GST_BUFFER_DATA (in2), smpte->width, smpte->height, 0);
339 if (smpte->position < smpte->duration) {
340 outbuf = gst_buffer_new_and_alloc (smpte->width * smpte->height * 3);
342 if (!GST_PAD_CAPS (smpte->srcpad)) {
343 if (!gst_pad_try_set_caps (smpte->srcpad,
347 "format", GST_PROPS_FOURCC (GST_MAKE_FOURCC ('I','4','2','0')),
348 "width", GST_PROPS_INT (smpte->width),
349 "height", GST_PROPS_INT (smpte->height)
352 gst_element_error (element, "cannot set caps");
357 gst_smpte_blend_i420 (GST_BUFFER_DATA (in1),
358 GST_BUFFER_DATA (in2),
359 GST_BUFFER_DATA (outbuf),
360 smpte->mask, smpte->width, smpte->height,
362 ((1 << smpte->depth) + smpte->border) *
363 smpte->position / smpte->duration);
367 gst_buffer_ref (in2);
373 gst_buffer_unref (in1);
375 gst_buffer_unref (in2);
377 GST_BUFFER_TIMESTAMP (outbuf) = ts;
378 gst_pad_push (smpte->srcpad, outbuf);
382 gst_smpte_set_property (GObject *object, guint prop_id,
383 const GValue *value, GParamSpec *pspec)
387 smpte = GST_SMPTE(object);
392 gint type = g_value_get_enum (value);
394 gst_smpte_update_mask (smpte, type, smpte->depth,
395 smpte->width, smpte->height);
399 smpte->fps = g_value_get_int (value);
402 smpte->border = g_value_get_int (value);
406 gint depth = g_value_get_int (value);
408 gst_smpte_update_mask (smpte, smpte->type, depth,
409 smpte->width, smpte->height);
413 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
419 gst_smpte_get_property (GObject *object, guint prop_id,
420 GValue *value, GParamSpec *pspec)
424 smpte = GST_SMPTE(object);
429 g_value_set_enum (value, smpte->mask->type);
433 g_value_set_int (value, smpte->fps);
436 g_value_set_int (value, smpte->border);
439 g_value_set_int (value, smpte->depth);
442 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
449 plugin_init (GModule *module, GstPlugin *plugin)
451 GstElementFactory *factory;
453 factory = gst_element_factory_new("smpte",GST_TYPE_SMPTE,
455 g_return_val_if_fail(factory != NULL, FALSE);
457 gst_element_factory_add_pad_template (factory,
458 GST_PAD_TEMPLATE_GET (smpte_sink1_factory));
459 gst_element_factory_add_pad_template (factory,
460 GST_PAD_TEMPLATE_GET (smpte_sink2_factory));
461 gst_element_factory_add_pad_template (factory,
462 GST_PAD_TEMPLATE_GET (smpte_src_factory));
464 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
469 GstPluginDesc plugin_desc = {