From 9b067365c95ee0d987a74acd10a9c9890abab5db Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 10 Oct 2002 21:19:12 +0000 Subject: Added the base framework for the SMPTE transitions and wipes. Original commit message from CVS: Added the base framework for the SMPTE transitions and wipes. --- gst/smpte/Makefile.am | 14 ++ gst/smpte/barboxwipes.c | 152 ++++++++++++++++++ gst/smpte/gstmask.c | 124 +++++++++++++++ gst/smpte/gstmask.h | 73 +++++++++ gst/smpte/gstsmpte.c | 409 ++++++++++++++++++++++++++++++++++++++++++++++++ gst/smpte/gstsmpte.h | 63 ++++++++ gst/smpte/paint.c | 51 ++++++ gst/smpte/paint.h | 35 +++++ 8 files changed, 921 insertions(+) create mode 100644 gst/smpte/Makefile.am create mode 100644 gst/smpte/barboxwipes.c create mode 100644 gst/smpte/gstmask.c create mode 100644 gst/smpte/gstmask.h create mode 100644 gst/smpte/gstsmpte.c create mode 100644 gst/smpte/gstsmpte.h create mode 100644 gst/smpte/paint.c create mode 100644 gst/smpte/paint.h (limited to 'gst') diff --git a/gst/smpte/Makefile.am b/gst/smpte/Makefile.am new file mode 100644 index 00000000..91a6d127 --- /dev/null +++ b/gst/smpte/Makefile.am @@ -0,0 +1,14 @@ +plugindir = $(libdir)/gst + +plugin_LTLIBRARIES = libgstsmpte.la + +libgstsmpte_la_SOURCES = gstsmpte.c gstmask.c barboxwipes.c paint.c + +noinst_HEADERS = gstsmpte.h gstmask.h paint.h + +libgstsmpte_la_CFLAGS = -O2 -ffast-math $(GST_CFLAGS) +libgstsmpte_la_LIBADD = +libgstsmpte_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) + +EXTRA_DIST = + diff --git a/gst/smpte/barboxwipes.c b/gst/smpte/barboxwipes.c new file mode 100644 index 00000000..031c282a --- /dev/null +++ b/gst/smpte/barboxwipes.c @@ -0,0 +1,152 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "paint.h" +#include "gstmask.h" + +static void +gst_bar_wipe_lr_update (GstMask *mask, + GstClockTime position, + GstClockTime duration) +{ + gint width = mask->width; + gint height = mask->height; + gint split = (position * width) / duration; + + gst_smpte_paint_rect (mask->data, width, split, 0, width - split, height, 0); + gst_smpte_paint_rect (mask->data, width, 0, 0, split, height, 255); +} + +static void +gst_bar_wipe_tb_update (GstMask *mask, + GstClockTime position, + GstClockTime duration) +{ + gint width = mask->width; + gint height = mask->height; + gint split = (position * height) / duration; + + gst_smpte_paint_rect (mask->data, width, 0, 0, width, split, 255); + gst_smpte_paint_rect (mask->data, width, 0, split, width, height - split, 0); +} + +static void +gst_box_wipe_update (GstMask *mask, + GstClockTime position, + GstClockTime duration) +{ + static gint box_wipe_impacts[8][4] = + { + /* 3 -> 6 */ + { 0, 0, 0, 0 }, + { 2, 2, 0, 0 }, + { 2, 2, 2, 2 }, + { 0, 0, 2, 2 }, + /* 23 -> 26 */ + { 1, 1, 0, 0 }, + { 2, 2, 1, 1 }, + { 1, 1, 2, 2 }, + { 0, 0, 1, 1 }, + }; + gint *impacts = box_wipe_impacts[(mask->type & 0x0F) - 3]; + gint width = mask->width; + gint height = mask->height; + gint splitx = (position * width) / duration; + gint splity = (position * height) / duration; + + gst_smpte_paint_rect (mask->data, width, 0, 0, width, height, 0); + gst_smpte_paint_rect (mask->data, width, + (impacts[0] * width)/2 - (impacts[1] * splitx)/2, + (impacts[2] * height)/2 - (impacts[3] * splity)/2, + splitx, splity, 255); +} + +static void +gst_fourc_box_wipe_update (GstMask *mask, + GstClockTime position, + GstClockTime duration) +{ + static gint box_wipe_impacts[8][4] = + { + { 0, 0, 0, 0 }, + { 1, 1, 1, 1 }, + { 4, 2, 0, 0 }, + { 3, 1, 1, 1 }, + { 4, 2, 4, 2 }, + { 1, 1, 3, 1 }, + { 0, 0, 4, 2 }, + { 3, 1, 3, 1 }, + }; + gint *impacts; + gint width = mask->width; + gint height = mask->height; + gint splitx = (position * width/2) / duration; + gint splity = (position * height/2) / duration; + gint i; + + gst_smpte_paint_rect (mask->data, width, 0, 0, width, height, 0); + + for (i = 7; i > 0; i -= 2) { + impacts = box_wipe_impacts[mask->type - i]; + gst_smpte_paint_rect (mask->data, width, + (impacts[0] * width)/4 - (impacts[1] * splitx)/2, + (impacts[2] * height)/4 - (impacts[3] * splity)/2, + splitx, splity, 255); + } +} + +static GstMaskDefinition definitions[] = { + { 1, "bar_wipe_lr", "A bar moves from left to right", + _gst_mask_default_new, _gst_mask_default_destroy, gst_bar_wipe_lr_update }, + { 2, "bar_wipe_tb", "A bar moves from top to bottom", + _gst_mask_default_new, _gst_mask_default_destroy, gst_bar_wipe_tb_update }, + { 3, "box_wipe_tl", "A box expands from the upper-left corner to the lower-right corner", + _gst_mask_default_new, _gst_mask_default_destroy, gst_box_wipe_update }, + { 4, "box_wipe_tr", "A box expands from the upper-right corner to the lower-left corner", + _gst_mask_default_new, _gst_mask_default_destroy, gst_box_wipe_update }, + { 5, "box_wipe_br", "A box expands from the lower-right corner to the upper-left corner", + _gst_mask_default_new, _gst_mask_default_destroy, gst_box_wipe_update }, + { 6, "box_wipe_bl", "A box expands from the lower-left corner to the upper-right corner", + _gst_mask_default_new, _gst_mask_default_destroy, gst_box_wipe_update }, + { 23, "box_wipe_tc", "A box expands from the top edge's midpoint to the bottom corners", + _gst_mask_default_new, _gst_mask_default_destroy, gst_box_wipe_update }, + { 24, "box_wipe_rc", "A box expands from the right edge's midpoint to the left corners", + _gst_mask_default_new, _gst_mask_default_destroy, gst_box_wipe_update }, + { 25, "box_wipe_bc", "A box expands from the bottom edge's midpoint to the top corners", + _gst_mask_default_new, _gst_mask_default_destroy, gst_box_wipe_update }, + { 26, "box_wipe_lc", "A box expands from the left edge's midpoint to the right corners", + _gst_mask_default_new, _gst_mask_default_destroy, gst_box_wipe_update }, + { 7 , "four_box_wipe_ci", "A box shape expands from each of the four corners toward the center", + _gst_mask_default_new, _gst_mask_default_destroy, gst_fourc_box_wipe_update }, + { 8 , "four_box_wipe_co", "A box shape expands from the center of each quadrant toward the corners of each quadrant", + _gst_mask_default_new, _gst_mask_default_destroy, gst_fourc_box_wipe_update }, + { 0, NULL, NULL, NULL } +}; + +void +_gst_barboxwipes_register (void) +{ + gint i = 0; + + while (definitions[i].short_name) { + _gst_mask_register (&definitions[i]); + i++; + } +} + diff --git a/gst/smpte/gstmask.c b/gst/smpte/gstmask.c new file mode 100644 index 00000000..a26d7190 --- /dev/null +++ b/gst/smpte/gstmask.c @@ -0,0 +1,124 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#include "gstmask.h" + +extern void _gst_barboxwipes_register (void); + +static GList *masks = NULL; + +void +_gst_mask_init (void) +{ + _gst_barboxwipes_register (); +} + +static gint +gst_mask_compare (GstMaskDefinition *def1, + GstMaskDefinition *def2) +{ + return (def1->type - def2->type); +} + +void +_gst_mask_register (GstMaskDefinition *definition) +{ + masks = g_list_insert_sorted (masks, definition, (GCompareFunc) gst_mask_compare); +} + +const GList* +gst_mask_get_definitions (void) +{ + return masks; +} + +static GstMaskDefinition* +gst_mask_find_definition (gint type) +{ + GList *walk = masks; + + while (walk) { + GstMaskDefinition *def = (GstMaskDefinition *) walk->data; + + if (def->type == type) + return def; + + walk = g_list_next (walk); + } + return NULL; +} + +GstMask* +gst_mask_factory_new (gint type, gint bpp, gint width, gint height) +{ + GstMaskDefinition *definition; + GstMask *mask = NULL; + + definition = gst_mask_find_definition (type); + if (definition) { + mask = definition->new_func (definition, bpp, width, height); + } + + return mask; +} + +GstMask* +_gst_mask_default_new (GstMaskDefinition *definition, + gint bpp, gint width, gint height) +{ + GstMask *mask; + + mask = g_new0 (GstMask, 1); + + mask->type = definition->type; + mask->bpp = bpp; + mask->width = width; + mask->height = height; + mask->update_func = definition->update_func; + mask->destroy_func = definition->destroy_func; + mask->data = g_malloc (width * height * (bpp+7)>>3); + + return mask; +} + +void +_gst_mask_default_destroy (GstMask *mask) +{ + g_free (mask->data); + g_free (mask); +} + +void +gst_mask_destroy (GstMask *mask) +{ + if (mask->destroy_func) + mask->destroy_func (mask); +} + +void +gst_mask_update (GstMask *mask, + GstClockTime position, + GstClockTime duration) +{ + g_return_if_fail (mask != NULL); + + if (mask->update_func) + mask->update_func (mask, position, duration); +} diff --git a/gst/smpte/gstmask.h b/gst/smpte/gstmask.h new file mode 100644 index 00000000..f53fb99f --- /dev/null +++ b/gst/smpte/gstmask.h @@ -0,0 +1,73 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#ifndef __GST_MASK_H__ +#define __GST_MASK_H__ + +#include + + +typedef struct _GstMask GstMask; +typedef struct _GstMaskDefinition GstMaskDefinition; + +typedef GstMask* (*GstMaskNewFunc) (GstMaskDefinition *definition, + gint bpp, gint width, gint height); +typedef void (*GstMaskDestroyFunc) (GstMask *mask); +typedef void (*GstMaskUpdateFunc) (GstMask *mask, + GstClockTime position, + GstClockTime duration); +struct _GstMaskDefinition { + gint type; + gchar *short_name; + gchar *long_name; + GstMaskNewFunc new_func; + GstMaskDestroyFunc destroy_func; + GstMaskUpdateFunc update_func; +}; + +struct _GstMask { + gint type; + guint8 *data; + + gint width; + gint height; + gint bpp; + + GstMaskUpdateFunc update_func; + GstMaskDestroyFunc destroy_func; +}; + +void _gst_mask_init (void); +void _gst_mask_register (GstMaskDefinition *definition); + +GstMask* _gst_mask_default_new (GstMaskDefinition *definition, + gint bpp, gint width, gint height); +void _gst_mask_default_destroy (GstMask *mask); + +const GList* gst_mask_get_definitions (void); +GstMask* gst_mask_factory_new (gint type, gint bpp, gint width, gint height); +void gst_mask_destroy (GstMask *mask); + +void gst_mask_update (GstMask *mask, + GstClockTime position, + GstClockTime duration); + + +#endif /* __GST_MASK_H__ */ diff --git a/gst/smpte/gstsmpte.c b/gst/smpte/gstsmpte.c new file mode 100644 index 00000000..536be8d4 --- /dev/null +++ b/gst/smpte/gstsmpte.c @@ -0,0 +1,409 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include +#include "paint.h" + +/* elementfactory information */ +static GstElementDetails smpte_details = { + "SMPTE transitions", + "Filter/Video", + "LGPL", + "Apply the standard SMPTE transitions on video images", + VERSION, + "Wim Taymans ", + "(C) 2002", +}; + +GST_PAD_TEMPLATE_FACTORY (smpte_src_factory, + "src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_CAPS_NEW ( + "smpte_src", + "video/raw", + "format", GST_PROPS_FOURCC (GST_STR_FOURCC ("I420")) + ) +) + +GST_PAD_TEMPLATE_FACTORY (smpte_sink1_factory, + "sink1", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_CAPS_NEW ( + "smpte_sink1", + "video/raw", + "format", GST_PROPS_FOURCC (GST_STR_FOURCC ("I420")), + "width", GST_PROPS_INT_RANGE (0, 4096), + "height", GST_PROPS_INT_RANGE (0, 4096) + ) +) + +GST_PAD_TEMPLATE_FACTORY (smpte_sink2_factory, + "sink2", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_CAPS_NEW ( + "smpte_sink2", + "video/raw", + "format", GST_PROPS_FOURCC (GST_STR_FOURCC ("I420")), + "width", GST_PROPS_INT_RANGE (0, 4096), + "height", GST_PROPS_INT_RANGE (0, 4096) + ) +) + + +/* SMPTE signals and args */ +enum { + /* FILL ME */ + LAST_SIGNAL +}; + +enum { + ARG_0, + ARG_TYPE, +}; + +#define GST_TYPE_SMPTE_TRANSITION_TYPE (gst_smpte_transition_type_get_type()) +static GType +gst_smpte_transition_type_get_type (void) +{ + static GType smpte_transition_type = 0; + GEnumValue *smpte_transitions; + + if (!smpte_transition_type) { + const GList *definitions; + gint i=0; + + definitions = gst_mask_get_definitions (); + smpte_transitions = g_new0 (GEnumValue, g_list_length ((GList *)definitions)+1); + + while (definitions) { + GstMaskDefinition *definition = (GstMaskDefinition *) definitions->data; + definitions = g_list_next (definitions); + + smpte_transitions[i].value = definition->type; + smpte_transitions[i].value_name = definition->short_name; + smpte_transitions[i].value_nick = definition->long_name; + + i++; + } + + smpte_transition_type = g_enum_register_static ("GstSMPTETransitionType", smpte_transitions); + } + return smpte_transition_type; +} + + +static void gst_smpte_class_init (GstSMPTEClass *klass); +static void gst_smpte_init (GstSMPTE *smpte); + +static void gst_smpte_loop (GstElement *element); + +static void gst_smpte_set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec); +static void gst_smpte_get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec); + +static GstElementClass *parent_class = NULL; +/*static guint gst_smpte_signals[LAST_SIGNAL] = { 0 }; */ + +static GType +gst_smpte_get_type (void) +{ + static GType smpte_type = 0; + + if (!smpte_type) { + static const GTypeInfo smpte_info = { + sizeof(GstSMPTEClass), + NULL, + NULL, + (GClassInitFunc)gst_smpte_class_init, + NULL, + NULL, + sizeof(GstSMPTE), + 0, + (GInstanceInitFunc)gst_smpte_init, + }; + smpte_type = g_type_register_static(GST_TYPE_ELEMENT, "GstSMPTE", &smpte_info, 0); + } + return smpte_type; +} + +static void +gst_smpte_class_init (GstSMPTEClass *klass) +{ + GObjectClass *gobject_class; + GstElementClass *gstelement_class; + + gobject_class = (GObjectClass*)klass; + gstelement_class = (GstElementClass*)klass; + + parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + + gobject_class->set_property = gst_smpte_set_property; + gobject_class->get_property = gst_smpte_get_property; + + _gst_mask_init (); + + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TYPE, + g_param_spec_enum ("type", "Type", "The type of transition to use", + GST_TYPE_SMPTE_TRANSITION_TYPE, 1, G_PARAM_READWRITE)); + +} + +/* wht yel cya grn mag red blu blk -I Q */ +static int y_colors[] = { 255, 226, 179, 150, 105, 76, 29, 16, 16, 0 }; +static int u_colors[] = { 128, 0, 170, 46, 212, 85, 255, 128, 0, 128 }; +static int v_colors[] = { 128, 155, 0, 21, 235, 255, 107, 128, 128, 255 }; + +static void +fill_i420 (guint8 *data, gint width, gint height, gint color) +{ + guint8 *yp = data; + guint8 *up = data + width * height; + guint8 *vp = data + width * height + (width * height) / 4; + + gst_smpte_paint_rect (yp, width, 0, 0, width, height, y_colors[color]); + gst_smpte_paint_rect (up, width/2, 0, 0, width/2, height/2, u_colors[color]); + gst_smpte_paint_rect (vp, width/2, 0, 0, width/2, height/2, v_colors[color]); +} + +static gboolean +gst_smpte_sinkconnect (GstPad *pad, GstCaps *caps) +{ + GstSMPTE *smpte; + + smpte = GST_SMPTE (gst_pad_get_parent (pad)); + + if (!GST_CAPS_IS_FIXED (caps)) + return GST_PAD_CONNECT_DELAYED; + + gst_caps_get_int (caps, "width", &smpte->width); + gst_caps_get_int (caps, "height", &smpte->height); + + smpte->mask = gst_mask_factory_new (smpte->type, 8, smpte->width, smpte->height); + + /* forward to the next plugin */ + return gst_pad_try_set_caps(smpte->srcpad, gst_caps_copy_1(caps)); +} + +static void +gst_smpte_init (GstSMPTE *smpte) +{ + smpte->sinkpad1 = gst_pad_new_from_template ( + GST_PAD_TEMPLATE_GET (smpte_sink1_factory), "sink1"); + gst_pad_set_connect_function (smpte->sinkpad1, gst_smpte_sinkconnect); + gst_element_add_pad (GST_ELEMENT (smpte), smpte->sinkpad1); + + smpte->sinkpad2 = gst_pad_new_from_template ( + GST_PAD_TEMPLATE_GET (smpte_sink2_factory), "sink2"); + gst_pad_set_connect_function (smpte->sinkpad2, gst_smpte_sinkconnect); + gst_element_add_pad (GST_ELEMENT (smpte), smpte->sinkpad2); + + smpte->srcpad = gst_pad_new_from_template ( + GST_PAD_TEMPLATE_GET (smpte_src_factory), "src"); + gst_element_add_pad (GST_ELEMENT (smpte), smpte->srcpad); + + gst_element_set_loop_function (GST_ELEMENT (smpte), gst_smpte_loop); + + smpte->width = 320; + smpte->height = 200; + smpte->duration = 64; + smpte->position = 0; + smpte->type = 1; + smpte->mask = gst_mask_factory_new (smpte->type, 8, smpte->width, smpte->height); +} + +static void +gst_smpte_blend_i420 (guint8 *in1, guint8 *in2, guint8 *out, GstMask *mask, + gint width, gint height) +{ + gint i, j; + guint8 *maskporig, *maskp; + guint8 *in1u, *in1v, *in2u, *in2v, *outu, *outv; + guint8 value; + gint chromsize = (width * height) >> 2; + + maskp = maskporig = mask->data; + + for (i = width * height; i; i--) { + value = *maskp++; + *out++ = ((*in2++ * value) + (*in1++ * (255 - value))) >> 8; + } + in1u = in1; in1v = in1 + chromsize; + in2u = in2; in2v = in2 + chromsize; + outu = out; outv = out + chromsize; + + maskp = maskporig; + for (i = height/2; i; i--, maskp += width) { + for (j = width/2; j; j--, maskp += 2) { + value = *maskp; + *outu++ = ((*in2u++ * value) + (*in1u++ * (255 - value))) >> 8; + *outv++ = ((*in2v++ * value) + (*in1v++ * (255 - value))) >> 8; + } + } +} + +static void +gst_smpte_loop (GstElement *element) +{ + GstSMPTE *smpte; + GstBuffer *outbuf; + GstClockTime ts; + GstBuffer *in1 = NULL, *in2 = NULL; + + smpte = GST_SMPTE (element); + + ts = smpte->position * GST_SECOND; + + if (GST_PAD_IS_USABLE (smpte->sinkpad1)) { + in1 = gst_pad_pull (smpte->sinkpad1); + ts = GST_BUFFER_TIMESTAMP (in1); + } + else { + in1 = gst_buffer_new_and_alloc (smpte->width * smpte->height * 3); + fill_i420 (GST_BUFFER_DATA (in1), smpte->width, smpte->height, 7); + } + + if (GST_PAD_IS_USABLE (smpte->sinkpad2)) { + in2 = gst_pad_pull (smpte->sinkpad2); + ts = GST_BUFFER_TIMESTAMP (in2); + } + else { + in2 = gst_buffer_new_and_alloc (smpte->width * smpte->height * 3); + fill_i420 (GST_BUFFER_DATA (in2), smpte->width, smpte->height, 0); + } + + if (smpte->position < smpte->duration) { + outbuf = gst_buffer_new_and_alloc (smpte->width * smpte->height * 3); + + if (!GST_PAD_CAPS (smpte->srcpad)) { + if (!gst_pad_try_set_caps (smpte->srcpad, + GST_CAPS_NEW ( + "smpte_srccaps", + "video/raw", + "format", GST_PROPS_FOURCC (GST_MAKE_FOURCC ('I','4','2','0')), + "width", GST_PROPS_INT (smpte->width), + "height", GST_PROPS_INT (smpte->height) + ))) + { + gst_element_error (element, "cannot set caps"); + return; + } + } + + gst_mask_update (smpte->mask, smpte->position, smpte->duration); + + gst_smpte_blend_i420 (GST_BUFFER_DATA (in1), GST_BUFFER_DATA (in2), GST_BUFFER_DATA (outbuf), + smpte->mask, smpte->width, smpte->height); + } + else { + outbuf = in2; + gst_buffer_ref (in2); + } + + smpte->position++; + + if (in1) + gst_buffer_unref (in1); + if (in2) + gst_buffer_unref (in2); + + GST_BUFFER_TIMESTAMP (outbuf) = ts; + gst_pad_push (smpte->srcpad, outbuf); +} + +static void +gst_smpte_set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + GstSMPTE *smpte; + + smpte = GST_SMPTE(object); + + switch (prop_id) { + case ARG_TYPE: + { + GstMask *newmask; + gint type = g_value_get_enum (value); + + newmask = gst_mask_factory_new (type, 8, smpte->width, smpte->height); + if (newmask) { + if (smpte->mask) { + gst_mask_destroy (smpte->mask); + } + smpte->mask = newmask; + smpte->type = type; + } + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_smpte_get_property (GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + GstSMPTE *smpte; + + smpte = GST_SMPTE(object); + + switch (prop_id) { + case ARG_TYPE: + if (smpte->mask) { + g_value_set_enum (value, smpte->mask->type); + } + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + + +static gboolean +plugin_init (GModule *module, GstPlugin *plugin) +{ + GstElementFactory *factory; + + factory = gst_element_factory_new("smpte",GST_TYPE_SMPTE, + &smpte_details); + g_return_val_if_fail(factory != NULL, FALSE); + + gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (smpte_sink1_factory)); + gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (smpte_sink2_factory)); + gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (smpte_src_factory)); + + gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory)); + + return TRUE; +} + +GstPluginDesc plugin_desc = { + GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "smpte", + plugin_init +}; + diff --git a/gst/smpte/gstsmpte.h b/gst/smpte/gstsmpte.h new file mode 100644 index 00000000..5ba6278a --- /dev/null +++ b/gst/smpte/gstsmpte.h @@ -0,0 +1,63 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#ifndef __GST_SMPTE_H__ +#define __GST_SMPTE_H__ + +#include +#include + +#define GST_TYPE_SMPTE \ + (gst_smpte_get_type()) +#define GST_SMPTE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_SMPTE,GstSMPTE)) +#define GST_SMPTE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_SMPTE,GstSMPTE)) +#define GST_IS_SMPTE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_SMPTE)) +#define GST_IS_SMPTE_CLASS(obj) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SMPTE)) + +typedef struct _GstSMPTE GstSMPTE; +typedef struct _GstSMPTEClass GstSMPTEClass; + +struct _GstSMPTE { + GstElement element; + + gint format; + gint width; + gint height; + + gint duration; + gint position; + + GstPad *srcpad, + *sinkpad1, + *sinkpad2; + + gint type; + GstMask *mask; +}; + +struct _GstSMPTEClass { + GstElementClass parent_class; +}; + +#endif /* __GST_SMPTE_H__ */ diff --git a/gst/smpte/paint.c b/gst/smpte/paint.c new file mode 100644 index 00000000..0fb96d77 --- /dev/null +++ b/gst/smpte/paint.c @@ -0,0 +1,51 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "paint.h" + +void +gst_smpte_paint_rect (guint8 *dest, gint stride, gint x, gint y, gint w, gint h, guint8 color) +{ + guint8 *d = dest + stride * y + x; + gint i; + + for (i = 0; i < h; i++) { + memset (d, color, w); + d += stride; + } +} + +void +gst_smpte_paint_rect_s (guint8 *dest, gint stride, gint x, gint y, gint w, gint h, guint8 color) +{ + guint8 *d = dest + stride * y + x; + gint i, j; + gint border = 100; + + for (i = 0; i < h; i++) { + if (w - border > 0) { + memset (d, color, w - border); + } + + for (j = 0; j < border - w; j++) { + *(d+w+j) = (color*(border-j)/border); + } + d += stride; + } +} diff --git a/gst/smpte/paint.h b/gst/smpte/paint.h new file mode 100644 index 00000000..fc51a638 --- /dev/null +++ b/gst/smpte/paint.h @@ -0,0 +1,35 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_SMPTE_PAINT_H__ +#define __GST_SMPTE_PAINT_H__ + +#include + +void gst_smpte_paint_rect (guint8 *dest, gint stride, + gint x, gint y, gint w, gint h, + guint8 color); + +void gst_smpte_paint_rect_s (guint8 *dest, gint stride, + gint x, gint y, gint w, gint h, + guint8 color); + + + +#endif /* __GST_SMPTE_PAINT_H__ */ -- cgit v1.2.1