diff options
Diffstat (limited to 'gst/smpte/gstsmpte.c')
-rw-r--r-- | gst/smpte/gstsmpte.c | 292 |
1 files changed, 148 insertions, 144 deletions
diff --git a/gst/smpte/gstsmpte.c b/gst/smpte/gstsmpte.c index 5899a9a1..91b91d9d 100644 --- a/gst/smpte/gstsmpte.c +++ b/gst/smpte/gstsmpte.c @@ -34,43 +34,39 @@ static GstElementDetails smpte_details = { }; static GstStaticPadTemplate gst_smpte_src_template = -GST_STATIC_PAD_TEMPLATE ( - "src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ( - GST_VIDEO_CAPS_YUV("I420") - ) -); +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420") + ) + ); static GstStaticPadTemplate gst_smpte_sink1_template = -GST_STATIC_PAD_TEMPLATE ( - "sink1", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ( - GST_VIDEO_CAPS_YUV("I420") - ) -); +GST_STATIC_PAD_TEMPLATE ("sink1", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420") + ) + ); static GstStaticPadTemplate gst_smpte_sink2_template = -GST_STATIC_PAD_TEMPLATE ( - "sink2", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ( - GST_VIDEO_CAPS_YUV("I420") - ) -); +GST_STATIC_PAD_TEMPLATE ("sink2", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420") + ) + ); /* SMPTE signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_TYPE, ARG_BORDER, @@ -80,48 +76,51 @@ enum { #define GST_TYPE_SMPTE_TRANSITION_TYPE (gst_smpte_transition_type_get_type()) static GType -gst_smpte_transition_type_get_type (void) +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; + gint i = 0; definitions = gst_mask_get_definitions (); - smpte_transitions = g_new0 (GEnumValue, g_list_length ((GList *)definitions)+1); + 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); + 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_base_init (GstSMPTEClass *klass); -static void gst_smpte_init (GstSMPTE *smpte); +static void gst_smpte_class_init (GstSMPTEClass * klass); +static void gst_smpte_base_init (GstSMPTEClass * klass); +static void gst_smpte_init (GstSMPTE * smpte); -static void gst_smpte_loop (GstElement *element); +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 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 @@ -131,45 +130,46 @@ gst_smpte_get_type (void) if (!smpte_type) { static const GTypeInfo smpte_info = { - sizeof(GstSMPTEClass), - (GBaseInitFunc)gst_smpte_base_init, + sizeof (GstSMPTEClass), + (GBaseInitFunc) gst_smpte_base_init, NULL, - (GClassInitFunc)gst_smpte_class_init, + (GClassInitFunc) gst_smpte_class_init, NULL, NULL, - sizeof(GstSMPTE), + sizeof (GstSMPTE), 0, - (GInstanceInitFunc)gst_smpte_init, + (GInstanceInitFunc) gst_smpte_init, }; - smpte_type = g_type_register_static(GST_TYPE_ELEMENT, "GstSMPTE", &smpte_info, 0); + smpte_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstSMPTE", &smpte_info, 0); } return smpte_type; } static void -gst_smpte_base_init (GstSMPTEClass *klass) +gst_smpte_base_init (GstSMPTEClass * klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get(&gst_smpte_sink1_template)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get(&gst_smpte_sink2_template)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get(&gst_smpte_src_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_smpte_sink1_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_smpte_sink2_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_smpte_src_template)); gst_element_class_set_details (element_class, &smpte_details); } static void -gst_smpte_class_init (GstSMPTEClass *klass) +gst_smpte_class_init (GstSMPTEClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; - gobject_class = (GObjectClass*)klass; - gstelement_class = (GstElementClass*)klass; + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; - parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + 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; @@ -177,39 +177,42 @@ gst_smpte_class_init (GstSMPTEClass *klass) _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)); + g_param_spec_enum ("type", "Type", "The type of transition to use", + GST_TYPE_SMPTE_TRANSITION_TYPE, 1, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FPS, - g_param_spec_float ("fps", "FPS", "Frames per second if no input files are given", - 0., G_MAXFLOAT, 25., G_PARAM_READWRITE)); + g_param_spec_float ("fps", "FPS", + "Frames per second if no input files are given", 0., G_MAXFLOAT, 25., + G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BORDER, - g_param_spec_int ("border", "Border", "The border width of the transition", - 0, G_MAXINT, 0, G_PARAM_READWRITE)); + g_param_spec_int ("border", "Border", + "The border width of the transition", 0, G_MAXINT, 0, + G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DEPTH, - g_param_spec_int ("depth", "Depth", "Depth of the mask in bits", - 1, 24, 16, G_PARAM_READWRITE)); + g_param_spec_int ("depth", "Depth", "Depth of the mask in bits", 1, 24, + 16, 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 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) +fill_i420 (guint8 * data, gint width, gint height, gint color) { gint size = width * height, size4 = size >> 2; guint8 *yp = data; guint8 *up = data + size; guint8 *vp = data + size + size4; - + memset (yp, y_colors[color], size); memset (up, u_colors[color], size4); memset (vp, v_colors[color], size4); } static gboolean -gst_smpte_update_mask (GstSMPTE *smpte, gint type, gint depth, gint width, gint height) +gst_smpte_update_mask (GstSMPTE * smpte, gint type, gint depth, gint width, + gint height) { GstMask *newmask; @@ -230,7 +233,7 @@ gst_smpte_update_mask (GstSMPTE *smpte, gint type, gint depth, gint width, gint } static gboolean -gst_smpte_sinkconnect (GstPad *pad, const GstCaps *caps) +gst_smpte_sinkconnect (GstPad * pad, const GstCaps * caps) { GstSMPTE *smpte; GstStructure *structure; @@ -243,29 +246,34 @@ gst_smpte_sinkconnect (GstPad *pad, const GstCaps *caps) ret = gst_structure_get_int (structure, "width", &smpte->width); ret &= gst_structure_get_int (structure, "height", &smpte->height); ret &= gst_structure_get_double (structure, "framerate", &smpte->fps); - if (!ret) return GST_PAD_LINK_REFUSED; + if (!ret) + return GST_PAD_LINK_REFUSED; - gst_smpte_update_mask (smpte, smpte->type, smpte->depth, smpte->width, smpte->height); + gst_smpte_update_mask (smpte, smpte->type, smpte->depth, smpte->width, + smpte->height); /* forward to the next plugin */ - return gst_pad_try_set_caps(smpte->srcpad, caps); + return gst_pad_try_set_caps (smpte->srcpad, caps); } -static void -gst_smpte_init (GstSMPTE *smpte) +static void +gst_smpte_init (GstSMPTE * smpte) { - smpte->sinkpad1 = gst_pad_new_from_template ( - gst_static_pad_template_get(&gst_smpte_sink1_template), "sink1"); + smpte->sinkpad1 = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_smpte_sink1_template), "sink1"); gst_pad_set_link_function (smpte->sinkpad1, gst_smpte_sinkconnect); gst_element_add_pad (GST_ELEMENT (smpte), smpte->sinkpad1); - smpte->sinkpad2 = gst_pad_new_from_template ( - gst_static_pad_template_get(&gst_smpte_sink2_template), "sink2"); + smpte->sinkpad2 = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_smpte_sink2_template), "sink2"); gst_pad_set_link_function (smpte->sinkpad2, gst_smpte_sinkconnect); gst_element_add_pad (GST_ELEMENT (smpte), smpte->sinkpad2); - smpte->srcpad = gst_pad_new_from_template ( - gst_static_pad_template_get(&gst_smpte_src_template), "src"); + smpte->srcpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_smpte_src_template), "src"); gst_element_add_pad (GST_ELEMENT (smpte), smpte->srcpad); gst_element_set_loop_function (GST_ELEMENT (smpte), gst_smpte_loop); @@ -278,48 +286,53 @@ gst_smpte_init (GstSMPTE *smpte) smpte->type = 1; smpte->border = 0; smpte->depth = 16; - gst_smpte_update_mask (smpte, smpte->type, smpte->depth, smpte->width, smpte->height); + gst_smpte_update_mask (smpte, smpte->type, smpte->depth, smpte->width, + smpte->height); } static void -gst_smpte_blend_i420 (guint8 *in1, guint8 *in2, guint8 *out, GstMask *mask, - gint width, gint height, gint border, gint pos) +gst_smpte_blend_i420 (guint8 * in1, guint8 * in2, guint8 * out, GstMask * mask, + gint width, gint height, gint border, gint pos) { guint32 *maskp; gint value; gint i, j; gint min, max; - guint8 *in1u, *in1v, *in2u, *in2v, *outu, *outv; + guint8 *in1u, *in1v, *in2u, *in2v, *outu, *outv; gint lumsize = width * height; gint chromsize = lumsize >> 2; - if (border == 0) border++; + if (border == 0) + border++; - min = pos - border; + min = pos - border; max = pos; - in1u = in1 + lumsize; in1v = in1u + chromsize; - in2u = in2 + lumsize; in2v = in2u + chromsize; - outu = out + lumsize; outv = outu + chromsize; - + in1u = in1 + lumsize; + in1v = in1u + chromsize; + in2u = in2 + lumsize; + in2v = in2u + chromsize; + outu = out + lumsize; + outv = outu + chromsize; + maskp = mask->data; for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { value = *maskp++; value = ((CLAMP (value, min, max) - min) << 8) / border; - + *out++ = ((*in1++ * value) + (*in2++ * (256 - value))) >> 8; if (!(i & 1) && !(j & 1)) { - *outu++ = ((*in1u++ * value) + (*in2u++ * (256 - value))) >> 8; - *outv++ = ((*in1v++ * value) + (*in2v++ * (256 - value))) >> 8; + *outu++ = ((*in1u++ * value) + (*in2u++ * (256 - value))) >> 8; + *outv++ = ((*in1v++ * value) + (*in2v++ * (256 - value))) >> 8; } } } } static void -gst_smpte_loop (GstElement *element) +gst_smpte_loop (GstElement * element) { GstSMPTE *smpte; GstBuffer *outbuf; @@ -335,8 +348,7 @@ gst_smpte_loop (GstElement *element) if (GST_IS_EVENT (in1)) { gst_pad_push (smpte->srcpad, GST_DATA (in1)); in1 = NULL; - } - else + } else ts = GST_BUFFER_TIMESTAMP (in1); } if (GST_PAD_IS_USABLE (smpte->sinkpad2) && in2 == NULL) { @@ -344,8 +356,7 @@ gst_smpte_loop (GstElement *element) if (GST_IS_EVENT (in2)) { gst_pad_push (smpte->srcpad, GST_DATA (in2)); in2 = NULL; - } - else + } else ts = GST_BUFFER_TIMESTAMP (in2); } @@ -358,33 +369,33 @@ gst_smpte_loop (GstElement *element) fill_i420 (GST_BUFFER_DATA (in2), smpte->width, smpte->height, 0); } - if (smpte->position < smpte->duration) { + if (smpte->position < smpte->duration) { outbuf = gst_buffer_new_and_alloc (smpte->width * smpte->height * 3); if (!GST_PAD_CAPS (smpte->srcpad)) { GstCaps *caps; - caps = gst_caps_copy (gst_static_caps_get ( - &gst_smpte_src_template.static_caps)); - gst_caps_set_simple (caps, - "width", G_TYPE_INT, smpte->width, - "height", G_TYPE_INT, smpte->height, - "framerate", G_TYPE_DOUBLE, smpte->fps, NULL); + + caps = + gst_caps_copy (gst_static_caps_get (&gst_smpte_src_template. + static_caps)); + gst_caps_set_simple (caps, "width", G_TYPE_INT, smpte->width, "height", + G_TYPE_INT, smpte->height, "framerate", G_TYPE_DOUBLE, smpte->fps, + NULL); if (!gst_pad_try_set_caps (smpte->srcpad, caps)) { - GST_ELEMENT_ERROR (smpte, CORE, NEGOTIATION, (NULL), (NULL)); - return; + GST_ELEMENT_ERROR (smpte, CORE, NEGOTIATION, (NULL), (NULL)); + return; } } - gst_smpte_blend_i420 (GST_BUFFER_DATA (in1), - GST_BUFFER_DATA (in2), - GST_BUFFER_DATA (outbuf), - smpte->mask, smpte->width, smpte->height, - smpte->border, - ((1 << smpte->depth) + smpte->border) * - smpte->position / smpte->duration); - } - else { + gst_smpte_blend_i420 (GST_BUFFER_DATA (in1), + GST_BUFFER_DATA (in2), + GST_BUFFER_DATA (outbuf), + smpte->mask, smpte->width, smpte->height, + smpte->border, + ((1 << smpte->depth) + smpte->border) * + smpte->position / smpte->duration); + } else { outbuf = in2; gst_buffer_ref (in2); } @@ -401,20 +412,20 @@ gst_smpte_loop (GstElement *element) } static void -gst_smpte_set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec) +gst_smpte_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) { GstSMPTE *smpte; - smpte = GST_SMPTE(object); + smpte = GST_SMPTE (object); switch (prop_id) { case ARG_TYPE: { gint type = g_value_get_enum (value); - gst_smpte_update_mask (smpte, type, smpte->depth, - smpte->width, smpte->height); + gst_smpte_update_mask (smpte, type, smpte->depth, + smpte->width, smpte->height); break; } case ARG_BORDER: @@ -427,8 +438,8 @@ gst_smpte_set_property (GObject *object, guint prop_id, { gint depth = g_value_get_int (value); - gst_smpte_update_mask (smpte, smpte->type, depth, - smpte->width, smpte->height); + gst_smpte_update_mask (smpte, smpte->type, depth, + smpte->width, smpte->height); break; } default: @@ -438,12 +449,12 @@ gst_smpte_set_property (GObject *object, guint prop_id, } static void -gst_smpte_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) +gst_smpte_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) { GstSMPTE *smpte; - smpte = GST_SMPTE(object); + smpte = GST_SMPTE (object); switch (prop_id) { case ARG_TYPE: @@ -468,20 +479,13 @@ gst_smpte_get_property (GObject *object, guint prop_id, static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { - return gst_element_register(plugin, "smpte", - GST_RANK_NONE, GST_TYPE_SMPTE); + return gst_element_register (plugin, "smpte", GST_RANK_NONE, GST_TYPE_SMPTE); } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "smpte", - "Apply the standard SMPTE transitions on video images", - plugin_init, - VERSION, - "LGPL", - GST_PACKAGE, - GST_ORIGIN -) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "smpte", + "Apply the standard SMPTE transitions on video images", + plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN) |