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 */
84 #define GST_TYPE_SMPTE_TRANSITION_TYPE (gst_smpte_transition_type_get_type())
86 gst_smpte_transition_type_get_type (void)
88 static GType smpte_transition_type = 0;
89 GEnumValue *smpte_transitions;
91 if (!smpte_transition_type) {
92 const GList *definitions;
95 definitions = gst_mask_get_definitions ();
96 smpte_transitions = g_new0 (GEnumValue, g_list_length ((GList *)definitions)+1);
99 GstMaskDefinition *definition = (GstMaskDefinition *) definitions->data;
100 definitions = g_list_next (definitions);
102 smpte_transitions[i].value = definition->type;
103 smpte_transitions[i].value_name = definition->short_name;
104 smpte_transitions[i].value_nick = definition->long_name;
109 smpte_transition_type = g_enum_register_static ("GstSMPTETransitionType", smpte_transitions);
111 return smpte_transition_type;
115 static void gst_smpte_class_init (GstSMPTEClass *klass);
116 static void gst_smpte_init (GstSMPTE *smpte);
118 static void gst_smpte_loop (GstElement *element);
120 static void gst_smpte_set_property (GObject *object, guint prop_id,
121 const GValue *value, GParamSpec *pspec);
122 static void gst_smpte_get_property (GObject *object, guint prop_id,
123 GValue *value, GParamSpec *pspec);
125 static GstElementClass *parent_class = NULL;
126 /*static guint gst_smpte_signals[LAST_SIGNAL] = { 0 }; */
129 gst_smpte_get_type (void)
131 static GType smpte_type = 0;
134 static const GTypeInfo smpte_info = {
135 sizeof(GstSMPTEClass),
138 (GClassInitFunc)gst_smpte_class_init,
143 (GInstanceInitFunc)gst_smpte_init,
145 smpte_type = g_type_register_static(GST_TYPE_ELEMENT, "GstSMPTE", &smpte_info, 0);
151 gst_smpte_class_init (GstSMPTEClass *klass)
153 GObjectClass *gobject_class;
154 GstElementClass *gstelement_class;
156 gobject_class = (GObjectClass*)klass;
157 gstelement_class = (GstElementClass*)klass;
159 parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
161 gobject_class->set_property = gst_smpte_set_property;
162 gobject_class->get_property = gst_smpte_get_property;
166 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TYPE,
167 g_param_spec_enum ("type", "Type", "The type of transition to use",
168 GST_TYPE_SMPTE_TRANSITION_TYPE, 1, G_PARAM_READWRITE));
172 /* wht yel cya grn mag red blu blk -I Q */
173 static int y_colors[] = { 255, 226, 179, 150, 105, 76, 29, 16, 16, 0 };
174 static int u_colors[] = { 128, 0, 170, 46, 212, 85, 255, 128, 0, 128 };
175 static int v_colors[] = { 128, 155, 0, 21, 235, 255, 107, 128, 128, 255 };
178 fill_i420 (guint8 *data, gint width, gint height, gint color)
181 guint8 *up = data + width * height;
182 guint8 *vp = data + width * height + (width * height) / 4;
184 gst_smpte_paint_rect (yp, width, 0, 0, width, height, y_colors[color]);
185 gst_smpte_paint_rect (up, width/2, 0, 0, width/2, height/2, u_colors[color]);
186 gst_smpte_paint_rect (vp, width/2, 0, 0, width/2, height/2, v_colors[color]);
190 gst_smpte_sinkconnect (GstPad *pad, GstCaps *caps)
194 smpte = GST_SMPTE (gst_pad_get_parent (pad));
196 if (!GST_CAPS_IS_FIXED (caps))
197 return GST_PAD_CONNECT_DELAYED;
199 gst_caps_get_int (caps, "width", &smpte->width);
200 gst_caps_get_int (caps, "height", &smpte->height);
202 smpte->mask = gst_mask_factory_new (smpte->type, 8, smpte->width, smpte->height);
204 /* forward to the next plugin */
205 return gst_pad_try_set_caps(smpte->srcpad, gst_caps_copy_1(caps));
209 gst_smpte_init (GstSMPTE *smpte)
211 smpte->sinkpad1 = gst_pad_new_from_template (
212 GST_PAD_TEMPLATE_GET (smpte_sink1_factory), "sink1");
213 gst_pad_set_connect_function (smpte->sinkpad1, gst_smpte_sinkconnect);
214 gst_element_add_pad (GST_ELEMENT (smpte), smpte->sinkpad1);
216 smpte->sinkpad2 = gst_pad_new_from_template (
217 GST_PAD_TEMPLATE_GET (smpte_sink2_factory), "sink2");
218 gst_pad_set_connect_function (smpte->sinkpad2, gst_smpte_sinkconnect);
219 gst_element_add_pad (GST_ELEMENT (smpte), smpte->sinkpad2);
221 smpte->srcpad = gst_pad_new_from_template (
222 GST_PAD_TEMPLATE_GET (smpte_src_factory), "src");
223 gst_element_add_pad (GST_ELEMENT (smpte), smpte->srcpad);
225 gst_element_set_loop_function (GST_ELEMENT (smpte), gst_smpte_loop);
229 smpte->duration = 64;
232 smpte->mask = gst_mask_factory_new (smpte->type, 8, smpte->width, smpte->height);
236 gst_smpte_blend_i420 (guint8 *in1, guint8 *in2, guint8 *out, GstMask *mask,
237 gint width, gint height)
240 guint8 *maskporig, *maskp;
241 guint8 *in1u, *in1v, *in2u, *in2v, *outu, *outv;
243 gint chromsize = (width * height) >> 2;
245 maskp = maskporig = mask->data;
247 for (i = width * height; i; i--) {
249 *out++ = ((*in2++ * value) + (*in1++ * (255 - value))) >> 8;
251 in1u = in1; in1v = in1 + chromsize;
252 in2u = in2; in2v = in2 + chromsize;
253 outu = out; outv = out + chromsize;
256 for (i = height/2; i; i--, maskp += width) {
257 for (j = width/2; j; j--, maskp += 2) {
259 *outu++ = ((*in2u++ * value) + (*in1u++ * (255 - value))) >> 8;
260 *outv++ = ((*in2v++ * value) + (*in1v++ * (255 - value))) >> 8;
266 gst_smpte_loop (GstElement *element)
271 GstBuffer *in1 = NULL, *in2 = NULL;
273 smpte = GST_SMPTE (element);
275 ts = smpte->position * GST_SECOND;
277 if (GST_PAD_IS_USABLE (smpte->sinkpad1)) {
278 in1 = gst_pad_pull (smpte->sinkpad1);
279 ts = GST_BUFFER_TIMESTAMP (in1);
282 in1 = gst_buffer_new_and_alloc (smpte->width * smpte->height * 3);
283 fill_i420 (GST_BUFFER_DATA (in1), smpte->width, smpte->height, 7);
286 if (GST_PAD_IS_USABLE (smpte->sinkpad2)) {
287 in2 = gst_pad_pull (smpte->sinkpad2);
288 ts = GST_BUFFER_TIMESTAMP (in2);
291 in2 = gst_buffer_new_and_alloc (smpte->width * smpte->height * 3);
292 fill_i420 (GST_BUFFER_DATA (in2), smpte->width, smpte->height, 0);
295 if (smpte->position < smpte->duration) {
296 outbuf = gst_buffer_new_and_alloc (smpte->width * smpte->height * 3);
298 if (!GST_PAD_CAPS (smpte->srcpad)) {
299 if (!gst_pad_try_set_caps (smpte->srcpad,
303 "format", GST_PROPS_FOURCC (GST_MAKE_FOURCC ('I','4','2','0')),
304 "width", GST_PROPS_INT (smpte->width),
305 "height", GST_PROPS_INT (smpte->height)
308 gst_element_error (element, "cannot set caps");
313 gst_mask_update (smpte->mask, smpte->position, smpte->duration);
315 gst_smpte_blend_i420 (GST_BUFFER_DATA (in1), GST_BUFFER_DATA (in2), GST_BUFFER_DATA (outbuf),
316 smpte->mask, smpte->width, smpte->height);
320 gst_buffer_ref (in2);
326 gst_buffer_unref (in1);
328 gst_buffer_unref (in2);
330 GST_BUFFER_TIMESTAMP (outbuf) = ts;
331 gst_pad_push (smpte->srcpad, outbuf);
335 gst_smpte_set_property (GObject *object, guint prop_id,
336 const GValue *value, GParamSpec *pspec)
340 smpte = GST_SMPTE(object);
346 gint type = g_value_get_enum (value);
348 newmask = gst_mask_factory_new (type, 8, smpte->width, smpte->height);
351 gst_mask_destroy (smpte->mask);
353 smpte->mask = newmask;
359 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
365 gst_smpte_get_property (GObject *object, guint prop_id,
366 GValue *value, GParamSpec *pspec)
370 smpte = GST_SMPTE(object);
375 g_value_set_enum (value, smpte->mask->type);
379 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
386 plugin_init (GModule *module, GstPlugin *plugin)
388 GstElementFactory *factory;
390 factory = gst_element_factory_new("smpte",GST_TYPE_SMPTE,
392 g_return_val_if_fail(factory != NULL, FALSE);
394 gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (smpte_sink1_factory));
395 gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (smpte_sink2_factory));
396 gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (smpte_src_factory));
398 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
403 GstPluginDesc plugin_desc = {