diff options
author | Thomas Vander Stichele <thomas@apestaart.org> | 2004-03-14 22:34:33 +0000 |
---|---|---|
committer | Thomas Vander Stichele <thomas@apestaart.org> | 2004-03-14 22:34:33 +0000 |
commit | 5d25c00e4b613b9cdf2c04fa3a68dffa03834a68 (patch) | |
tree | 74a5b1eaf3a324b520e64e87404fd0b3018a7829 /ext | |
parent | 1e83b097f7b732ae49e294a5a398bdc3e88854a8 (diff) |
gst-indent
Original commit message from CVS:
gst-indent
Diffstat (limited to 'ext')
55 files changed, 4854 insertions, 4745 deletions
diff --git a/ext/aalib/gstaasink.c b/ext/aalib/gstaasink.c index 6dfdb50c..e34bcf03 100644 --- a/ext/aalib/gstaasink.c +++ b/ext/aalib/gstaasink.c @@ -36,14 +36,16 @@ static GstElementDetails gst_aasink_details = { }; /* aasink signals and args */ -enum { +enum +{ SIGNAL_FRAME_DISPLAYED, SIGNAL_HAVE_SIZE, LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_WIDTH, ARG_HEIGHT, @@ -58,27 +60,25 @@ enum { ARG_FRAME_TIME, }; -static GstStaticPadTemplate sink_template = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420")) -); +static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420")) + ); -static void gst_aasink_base_init (gpointer g_class); -static void gst_aasink_class_init (GstAASinkClass *klass); -static void gst_aasink_init (GstAASink *aasink); +static void gst_aasink_base_init (gpointer g_class); +static void gst_aasink_class_init (GstAASinkClass * klass); +static void gst_aasink_init (GstAASink * aasink); -static void gst_aasink_set_clock (GstElement *element, GstClock *clock); -static void gst_aasink_chain (GstPad *pad, GstData *_data); +static void gst_aasink_set_clock (GstElement * element, GstClock * clock); +static void gst_aasink_chain (GstPad * pad, GstData * _data); -static void gst_aasink_set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec); -static void gst_aasink_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec); +static void gst_aasink_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_aasink_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); -static GstElementStateReturn gst_aasink_change_state (GstElement *element); +static GstElementStateReturn gst_aasink_change_state (GstElement * element); static GstElementClass *parent_class = NULL; static guint gst_aasink_signals[LAST_SIGNAL] = { 0 }; @@ -90,17 +90,18 @@ gst_aasink_get_type (void) if (!aasink_type) { static const GTypeInfo aasink_info = { - sizeof(GstAASinkClass), + sizeof (GstAASinkClass), gst_aasink_base_init, NULL, (GClassInitFunc) gst_aasink_class_init, NULL, NULL, - sizeof(GstAASink), + sizeof (GstAASink), 0, - (GInstanceInitFunc)gst_aasink_init, + (GInstanceInitFunc) gst_aasink_init, }; - aasink_type = g_type_register_static(GST_TYPE_ELEMENT, "GstAASink", &aasink_info, 0); + aasink_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstAASink", &aasink_info, 0); } return aasink_type; } @@ -110,19 +111,20 @@ static GType gst_aasink_drivers_get_type (void) { static GType driver_type = 0; + if (!driver_type) { GEnumValue *drivers; const struct aa_driver *driver; gint n_drivers; gint i; - for (n_drivers = 0; aa_drivers[n_drivers]; n_drivers++){ + for (n_drivers = 0; aa_drivers[n_drivers]; n_drivers++) { /* count number of drivers */ } - - drivers = g_new0(GEnumValue, n_drivers + 1); - for (i = 0; i < n_drivers; i++){ + drivers = g_new0 (GEnumValue, n_drivers + 1); + + for (i = 0; i < n_drivers; i++) { driver = aa_drivers[i]; drivers[i].value = i; drivers[i].value_name = g_strdup (driver->shortname); @@ -142,18 +144,19 @@ static GType gst_aasink_dither_get_type (void) { static GType dither_type = 0; + if (!dither_type) { GEnumValue *ditherers; gint n_ditherers; gint i; - for (n_ditherers = 0; aa_dithernames[n_ditherers]; n_ditherers++){ + for (n_ditherers = 0; aa_dithernames[n_ditherers]; n_ditherers++) { /* count number of ditherers */ } - - ditherers = g_new0(GEnumValue, n_ditherers + 1); - for (i = 0; i < n_ditherers; i++){ + ditherers = g_new0 (GEnumValue, n_ditherers + 1); + + for (i = 0; i < n_ditherers; i++) { ditherers[i].value = i; ditherers[i].value_name = g_strdup (aa_dithernames[i]); ditherers[i].value_nick = g_strdup (aa_dithernames[i]); @@ -178,74 +181,52 @@ gst_aasink_base_init (gpointer g_class) } static void -gst_aasink_class_init (GstAASinkClass *klass) +gst_aasink_class_init (GstAASinkClass * 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); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_WIDTH, - g_param_spec_int("width","width","width", - G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); /* CHECKME */ - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_HEIGHT, - g_param_spec_int("height","height","height", - G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); /* CHECKME */ - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_DRIVER, - g_param_spec_enum("driver","driver","driver", - GST_TYPE_AADRIVERS,0,G_PARAM_READWRITE)); /* CHECKME! */ - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_DITHER, - g_param_spec_enum("dither","dither","dither", - GST_TYPE_AADITHER,0,G_PARAM_READWRITE)); /* CHECKME! */ - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_BRIGHTNESS, - g_param_spec_int("brightness","brightness","brightness", - G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); /* CHECKME */ - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_CONTRAST, - g_param_spec_int("contrast","contrast","contrast", - G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); /* CHECKME */ - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_GAMMA, - g_param_spec_float("gamma","gamma","gamma", - 0.0,5.0,1.0,G_PARAM_READWRITE)); /* CHECKME */ - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_INVERSION, - g_param_spec_boolean("inversion","inversion","inversion", - TRUE,G_PARAM_READWRITE)); /* CHECKME */ - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_RANDOMVAL, - g_param_spec_int("randomval","randomval","randomval", - G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); /* CHECKME */ - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_FRAMES_DISPLAYED, - g_param_spec_int("frames_displayed","frames_displayed","frames_displayed", - G_MININT,G_MAXINT,0,G_PARAM_READABLE)); /* CHECKME */ - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_FRAME_TIME, - g_param_spec_int("frame_time","frame_time","frame_time", - G_MININT,G_MAXINT,0,G_PARAM_READABLE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_WIDTH, g_param_spec_int ("width", "width", "width", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_HEIGHT, g_param_spec_int ("height", "height", "height", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DRIVER, g_param_spec_enum ("driver", "driver", "driver", GST_TYPE_AADRIVERS, 0, G_PARAM_READWRITE)); /* CHECKME! */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DITHER, g_param_spec_enum ("dither", "dither", "dither", GST_TYPE_AADITHER, 0, G_PARAM_READWRITE)); /* CHECKME! */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BRIGHTNESS, g_param_spec_int ("brightness", "brightness", "brightness", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CONTRAST, g_param_spec_int ("contrast", "contrast", "contrast", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_GAMMA, g_param_spec_float ("gamma", "gamma", "gamma", 0.0, 5.0, 1.0, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_INVERSION, g_param_spec_boolean ("inversion", "inversion", "inversion", TRUE, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_RANDOMVAL, g_param_spec_int ("randomval", "randomval", "randomval", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FRAMES_DISPLAYED, g_param_spec_int ("frames_displayed", "frames_displayed", "frames_displayed", G_MININT, G_MAXINT, 0, G_PARAM_READABLE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FRAME_TIME, g_param_spec_int ("frame_time", "frame_time", "frame_time", G_MININT, G_MAXINT, 0, G_PARAM_READABLE)); /* CHECKME */ gobject_class->set_property = gst_aasink_set_property; gobject_class->get_property = gst_aasink_get_property; gst_aasink_signals[SIGNAL_FRAME_DISPLAYED] = - g_signal_new ("frame-displayed", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstAASinkClass, frame_displayed), NULL, NULL, - g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + g_signal_new ("frame-displayed", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstAASinkClass, frame_displayed), + NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); gst_aasink_signals[SIGNAL_HAVE_SIZE] = - g_signal_new ("have-size", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstAASinkClass, have_size), NULL, NULL, - gst_marshal_VOID__INT_INT, G_TYPE_NONE, 2, - G_TYPE_UINT, G_TYPE_UINT); + g_signal_new ("have-size", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GstAASinkClass, have_size), NULL, NULL, + gst_marshal_VOID__INT_INT, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT); gstelement_class->change_state = gst_aasink_change_state; - gstelement_class->set_clock = gst_aasink_set_clock; + gstelement_class->set_clock = gst_aasink_set_clock; } static GstCaps * -gst_aasink_fixate (GstPad *pad, const GstCaps *caps) +gst_aasink_fixate (GstPad * pad, const GstCaps * caps) { GstStructure *structure; GstCaps *newcaps; - if (gst_caps_get_size (caps) > 1) return NULL; + if (gst_caps_get_size (caps) > 1) + return NULL; newcaps = gst_caps_copy (caps); structure = gst_caps_get_structure (newcaps, 0); @@ -257,7 +238,7 @@ gst_aasink_fixate (GstPad *pad, const GstCaps *caps) return newcaps; } if (gst_caps_structure_fixate_field_nearest_double (structure, "framerate", - 30.0)) { + 30.0)) { return newcaps; } @@ -266,7 +247,7 @@ gst_aasink_fixate (GstPad *pad, const GstCaps *caps) } static GstPadLinkReturn -gst_aasink_sinkconnect (GstPad *pad, const GstCaps *caps) +gst_aasink_sinkconnect (GstPad * pad, const GstCaps * caps) { GstAASink *aasink; GstStructure *structure; @@ -280,16 +261,16 @@ gst_aasink_sinkconnect (GstPad *pad, const GstCaps *caps) /* FIXME aasink->format is never set */ GST_DEBUG ("aasink: setting %08lx (" GST_FOURCC_FORMAT ")", - aasink->format, GST_FOURCC_ARGS(aasink->format)); - - g_signal_emit( G_OBJECT (aasink), gst_aasink_signals[SIGNAL_HAVE_SIZE], 0, - aasink->width, aasink->height); + aasink->format, GST_FOURCC_ARGS (aasink->format)); + + g_signal_emit (G_OBJECT (aasink), gst_aasink_signals[SIGNAL_HAVE_SIZE], 0, + aasink->width, aasink->height); return GST_PAD_LINK_OK; } static void -gst_aasink_set_clock (GstElement *element, GstClock *clock) +gst_aasink_set_clock (GstElement * element, GstClock * clock) { GstAASink *aasink = GST_AASINK (element); @@ -297,16 +278,18 @@ gst_aasink_set_clock (GstElement *element, GstClock *clock) } static void -gst_aasink_init (GstAASink *aasink) +gst_aasink_init (GstAASink * aasink) { - aasink->sinkpad = gst_pad_new_from_template ( - gst_element_get_pad_template (GST_ELEMENT (aasink), "sink"), "sink"); + aasink->sinkpad = + gst_pad_new_from_template (gst_element_get_pad_template (GST_ELEMENT + (aasink), "sink"), "sink"); gst_element_add_pad (GST_ELEMENT (aasink), aasink->sinkpad); gst_pad_set_chain_function (aasink->sinkpad, gst_aasink_chain); gst_pad_set_link_function (aasink->sinkpad, gst_aasink_sinkconnect); gst_pad_set_fixate_function (aasink->sinkpad, gst_aasink_fixate); - memcpy(&aasink->ascii_surf, &aa_defparams, sizeof (struct aa_hardware_params)); + memcpy (&aasink->ascii_surf, &aa_defparams, + sizeof (struct aa_hardware_params)); aasink->ascii_parms.bright = 0; aasink->ascii_parms.contrast = 16; aasink->ascii_parms.gamma = 1.0; @@ -320,13 +303,12 @@ gst_aasink_init (GstAASink *aasink) aasink->clock = NULL; - GST_FLAG_SET(aasink, GST_ELEMENT_THREAD_SUGGESTED); + GST_FLAG_SET (aasink, GST_ELEMENT_THREAD_SUGGESTED); } static void -gst_aasink_scale (GstAASink *aasink, gchar *src, gchar *dest, - gint sw, gint sh, - gint dw, gint dh) +gst_aasink_scale (GstAASink * aasink, gchar * src, gchar * dest, + gint sw, gint sh, gint dw, gint dh) { gint ypos, yinc, y; gint xpos, xinc, x; @@ -340,20 +322,20 @@ gst_aasink_scale (GstAASink *aasink, gchar *src, gchar *dest, for (y = dh; y; y--) { while (ypos > 0x10000) { ypos -= 0x10000; - src += sw; + src += sw; } xpos = 0x10000; { guchar *destp = dest; guchar *srcp = src; - for ( x=dw; x; x-- ) { - while (xpos >= 0x10000L) { - srcp++; - xpos -= 0x10000L; - } - *destp++ = *srcp; - xpos += xinc; + for (x = dw; x; x--) { + while (xpos >= 0x10000L) { + srcp++; + xpos -= 0x10000L; + } + *destp++ = *srcp; + xpos += xinc; } } dest += dw; @@ -362,7 +344,7 @@ gst_aasink_scale (GstAASink *aasink, gchar *src, gchar *dest, } static void -gst_aasink_chain (GstPad *pad, GstData *_data) +gst_aasink_chain (GstPad * pad, GstData * _data) { GstBuffer *buf = GST_BUFFER (_data); GstAASink *aasink; @@ -373,33 +355,35 @@ gst_aasink_chain (GstPad *pad, GstData *_data) aasink = GST_AASINK (gst_pad_get_parent (pad)); - gst_aasink_scale (aasink, - GST_BUFFER_DATA (buf), /* src */ - aa_image (aasink->context), /* dest */ - aasink->width, /* sw */ - aasink->height, /* sh */ - aa_imgwidth (aasink->context), /* dw */ - aa_imgheight (aasink->context)); /* dh */ + gst_aasink_scale (aasink, GST_BUFFER_DATA (buf), /* src */ + aa_image (aasink->context), /* dest */ + aasink->width, /* sw */ + aasink->height, /* sh */ + aa_imgwidth (aasink->context), /* dw */ + aa_imgheight (aasink->context)); /* dh */ - GST_DEBUG ("videosink: clock wait: %" G_GUINT64_FORMAT, GST_BUFFER_TIMESTAMP(buf)); + GST_DEBUG ("videosink: clock wait: %" G_GUINT64_FORMAT, + GST_BUFFER_TIMESTAMP (buf)); if (aasink->clock && GST_BUFFER_TIMESTAMP_IS_VALID (buf)) { gst_element_wait (GST_ELEMENT (aasink), GST_BUFFER_TIMESTAMP (buf)); } - aa_render (aasink->context, &aasink->ascii_parms, - 0, 0, aa_imgwidth (aasink->context), aa_imgheight (aasink->context)); + aa_render (aasink->context, &aasink->ascii_parms, + 0, 0, aa_imgwidth (aasink->context), aa_imgheight (aasink->context)); aa_flush (aasink->context); aa_getevent (aasink->context, FALSE); - g_signal_emit(G_OBJECT(aasink),gst_aasink_signals[SIGNAL_FRAME_DISPLAYED], 0); + g_signal_emit (G_OBJECT (aasink), gst_aasink_signals[SIGNAL_FRAME_DISPLAYED], + 0); - gst_buffer_unref(buf); + gst_buffer_unref (buf); } static void -gst_aasink_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +gst_aasink_set_property (GObject * object, guint prop_id, const GValue * value, + GParamSpec * pspec) { GstAASink *aasink; @@ -415,31 +399,31 @@ gst_aasink_set_property (GObject *object, guint prop_id, const GValue *value, GP case ARG_HEIGHT: aasink->ascii_surf.height = g_value_get_int (value); break; - case ARG_DRIVER: { + case ARG_DRIVER:{ aasink->aa_driver = g_value_get_enum (value); break; } - case ARG_DITHER: { + case ARG_DITHER:{ aasink->ascii_parms.dither = g_value_get_enum (value); break; } - case ARG_BRIGHTNESS: { + case ARG_BRIGHTNESS:{ aasink->ascii_parms.bright = g_value_get_int (value); break; } - case ARG_CONTRAST: { + case ARG_CONTRAST:{ aasink->ascii_parms.contrast = g_value_get_int (value); break; } - case ARG_GAMMA: { + case ARG_GAMMA:{ aasink->ascii_parms.gamma = g_value_get_float (value); break; } - case ARG_INVERSION: { + case ARG_INVERSION:{ aasink->ascii_parms.inversion = g_value_get_boolean (value); break; } - case ARG_RANDOMVAL: { + case ARG_RANDOMVAL:{ aasink->ascii_parms.randomval = g_value_get_int (value); break; } @@ -449,59 +433,60 @@ gst_aasink_set_property (GObject *object, guint prop_id, const GValue *value, GP } static void -gst_aasink_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +gst_aasink_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { GstAASink *aasink; /* it's not null if we got it, but it might not be ours */ - aasink = GST_AASINK(object); + aasink = GST_AASINK (object); switch (prop_id) { - case ARG_WIDTH: { + case ARG_WIDTH:{ g_value_set_int (value, aasink->ascii_surf.width); break; } - case ARG_HEIGHT: { + case ARG_HEIGHT:{ g_value_set_int (value, aasink->ascii_surf.height); break; } - case ARG_DRIVER: { + case ARG_DRIVER:{ g_value_set_enum (value, aasink->aa_driver); break; } - case ARG_DITHER: { + case ARG_DITHER:{ g_value_set_enum (value, aasink->ascii_parms.dither); break; } - case ARG_BRIGHTNESS: { + case ARG_BRIGHTNESS:{ g_value_set_int (value, aasink->ascii_parms.bright); break; } - case ARG_CONTRAST: { + case ARG_CONTRAST:{ g_value_set_int (value, aasink->ascii_parms.contrast); break; } - case ARG_GAMMA: { + case ARG_GAMMA:{ g_value_set_float (value, aasink->ascii_parms.gamma); break; } - case ARG_INVERSION: { + case ARG_INVERSION:{ g_value_set_boolean (value, aasink->ascii_parms.inversion); break; } - case ARG_RANDOMVAL: { + case ARG_RANDOMVAL:{ g_value_set_int (value, aasink->ascii_parms.randomval); break; } - case ARG_FRAMES_DISPLAYED: { + case ARG_FRAMES_DISPLAYED:{ g_value_set_int (value, aasink->frames_displayed); break; } - case ARG_FRAME_TIME: { - g_value_set_int (value, aasink->frame_time/1000000); + case ARG_FRAME_TIME:{ + g_value_set_int (value, aasink->frame_time / 1000000); break; } - default: { + default:{ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } @@ -509,20 +494,20 @@ gst_aasink_get_property (GObject *object, guint prop_id, GValue *value, GParamSp } static gboolean -gst_aasink_open (GstAASink *aasink) +gst_aasink_open (GstAASink * aasink) { - g_return_val_if_fail (!GST_FLAG_IS_SET (aasink ,GST_AASINK_OPEN), FALSE); + g_return_val_if_fail (!GST_FLAG_IS_SET (aasink, GST_AASINK_OPEN), FALSE); - aa_recommendhidisplay(aa_drivers[aasink->aa_driver]->shortname); + aa_recommendhidisplay (aa_drivers[aasink->aa_driver]->shortname); aasink->context = aa_autoinit (&aasink->ascii_surf); if (aasink->context == NULL) { GST_ELEMENT_ERROR (GST_ELEMENT (aasink), LIBRARY, TOO_LAZY, (NULL), - ("error opening aalib context")); + ("error opening aalib context")); return FALSE; } - aa_autoinitkbd(aasink->context, 0); - aa_resizehandler(aasink->context, (void *)aa_resize); + aa_autoinitkbd (aasink->context, 0); + aa_resizehandler (aasink->context, (void *) aa_resize); GST_FLAG_SET (aasink, GST_AASINK_OPEN); @@ -530,9 +515,9 @@ gst_aasink_open (GstAASink *aasink) } static void -gst_aasink_close (GstAASink *aasink) +gst_aasink_close (GstAASink * aasink) { - g_return_if_fail (GST_FLAG_IS_SET (aasink ,GST_AASINK_OPEN)); + g_return_if_fail (GST_FLAG_IS_SET (aasink, GST_AASINK_OPEN)); aa_close (aasink->context); @@ -540,7 +525,7 @@ gst_aasink_close (GstAASink *aasink) } static GstElementStateReturn -gst_aasink_change_state (GstElement *element) +gst_aasink_change_state (GstElement * element) { g_return_val_if_fail (GST_IS_AASINK (element), GST_STATE_FAILURE); @@ -550,7 +535,7 @@ gst_aasink_change_state (GstElement *element) } else { if (!GST_FLAG_IS_SET (element, GST_AASINK_OPEN)) { if (!gst_aasink_open (GST_AASINK (element))) - return GST_STATE_FAILURE; + return GST_STATE_FAILURE; } } @@ -561,7 +546,7 @@ gst_aasink_change_state (GstElement *element) } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { if (!gst_element_register (plugin, "aasink", GST_RANK_NONE, GST_TYPE_AASINK)) return FALSE; @@ -569,14 +554,8 @@ plugin_init (GstPlugin *plugin) return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "aasink", - "ASCII Art video sink", - plugin_init, - VERSION, - "GPL", - GST_PACKAGE, - GST_ORIGIN -) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "aasink", + "ASCII Art video sink", + plugin_init, VERSION, "GPL", GST_PACKAGE, GST_ORIGIN) diff --git a/ext/aalib/gstaasink.h b/ext/aalib/gstaasink.h index e50362f6..d11ff20e 100644 --- a/ext/aalib/gstaasink.h +++ b/ext/aalib/gstaasink.h @@ -26,8 +26,9 @@ #include <aalib.h> #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define GST_TYPE_AASINK \ @@ -41,48 +42,51 @@ extern "C" { #define GST_IS_AASINK_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AASINK)) -typedef enum { - GST_AASINK_OPEN = GST_ELEMENT_FLAG_LAST, + typedef enum + { + GST_AASINK_OPEN = GST_ELEMENT_FLAG_LAST, - GST_AASINK_FLAG_LAST = GST_ELEMENT_FLAG_LAST + 2, -} GstAASinkFlags; + GST_AASINK_FLAG_LAST = GST_ELEMENT_FLAG_LAST + 2, + } GstAASinkFlags; -typedef struct _GstAASink GstAASink; -typedef struct _GstAASinkClass GstAASinkClass; + typedef struct _GstAASink GstAASink; + typedef struct _GstAASinkClass GstAASinkClass; -struct _GstAASink { - GstElement element; + struct _GstAASink + { + GstElement element; - GstPad *sinkpad; + GstPad *sinkpad; - gulong format; - gint width, height; + gulong format; + gint width, height; - gint frames_displayed; - guint64 frame_time; + gint frames_displayed; + guint64 frame_time; - GstClock *clock; + GstClock *clock; - aa_context *context; - struct aa_hardware_params ascii_surf; - struct aa_renderparams ascii_parms; - aa_palette palette; - gint aa_driver; -}; + aa_context *context; + struct aa_hardware_params ascii_surf; + struct aa_renderparams ascii_parms; + aa_palette palette; + gint aa_driver; + }; -struct _GstAASinkClass { - GstElementClass parent_class; + struct _GstAASinkClass + { + GstElementClass parent_class; - /* signals */ - void (*frame_displayed) (GstElement *element); - void (*have_size) (GstElement *element, guint width, guint height); -}; + /* signals */ + void (*frame_displayed) (GstElement * element); + void (*have_size) (GstElement * element, guint width, guint height); + }; -GType gst_aasink_get_type(void); + GType gst_aasink_get_type (void); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __GST_AASINKE_H__ */ +#endif /* __GST_AASINKE_H__ */ diff --git a/ext/dv/gstdvdec.h b/ext/dv/gstdvdec.h index 4dffd96f..6052c76f 100644 --- a/ext/dv/gstdvdec.h +++ b/ext/dv/gstdvdec.h @@ -24,8 +24,9 @@ #include <gst/gst.h> #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #include <libdv/dv.h> @@ -33,55 +34,55 @@ extern "C" { /* This is the definition of the element's object structure. */ -typedef struct _GstDVDec GstDVDec; + typedef struct _GstDVDec GstDVDec; /* The structure itself is derived from GstElement, as can be seen by the * fact that there's a complete instance of the GstElement structure at * the beginning of the object. This allows the element to be cast to * an Element or even an Object. */ -struct _GstDVDec { - GstElement element; - - /* We need to keep track of our pads, so we do so here. */ - GstPad *sinkpad, - *videosrcpad, - *audiosrcpad; - - dv_decoder_t *decoder; - gboolean clamp_luma; - gboolean clamp_chroma; - gint quality; - - GstByteStream *bs; - dv_color_space_t space; - gint bpp; - gboolean PAL; - gdouble framerate; - gint height; - gint frequency; - gint channels; - - gint length; - guint64 next_ts; - guint64 end_position; - gboolean need_discont; - gboolean loop; - - gboolean found_header; - - gint16 *audio_buffers[4]; -}; + struct _GstDVDec + { + GstElement element; + + /* We need to keep track of our pads, so we do so here. */ + GstPad *sinkpad, *videosrcpad, *audiosrcpad; + + dv_decoder_t *decoder; + gboolean clamp_luma; + gboolean clamp_chroma; + gint quality; + + GstByteStream *bs; + dv_color_space_t space; + gint bpp; + gboolean PAL; + gdouble framerate; + gint height; + gint frequency; + gint channels; + + gint length; + guint64 next_ts; + guint64 end_position; + gboolean need_discont; + gboolean loop; + + gboolean found_header; + + gint16 *audio_buffers[4]; + }; /* The other half of the object is its class. The class also derives from * the same parent, though it must be the class structure this time. * Function pointers for polymophic methods and signals are placed in this * structure. */ -typedef struct _GstDVDecClass GstDVDecClass; + typedef struct _GstDVDecClass GstDVDecClass; -struct _GstDVDecClass { - GstElementClass parent_class; -}; + struct _GstDVDecClass + { + GstElementClass parent_class; + }; /* Five standard preprocessing macros are used in the Gtk+ object system. * The first uses the object's _get_type function to return the GType @@ -107,12 +108,12 @@ struct _GstDVDecClass { /* This is the only prototype needed, because it is used in the above * GST_TYPE_DVDEC macro. */ -GType gst_dvdec_get_type(void); + GType gst_dvdec_get_type (void); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __GST_DVDEC_H__ */ +#endif /* __GST_DVDEC_H__ */ diff --git a/ext/esd/esdmon.c b/ext/esd/esdmon.c index 25e9df81..4a7f4ca1 100644 --- a/ext/esd/esdmon.c +++ b/ext/esd/esdmon.c @@ -37,12 +37,14 @@ static GstElementDetails esdmon_details = { }; /* Signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_DEPTH, ARG_BYTESPERREAD, @@ -52,43 +54,37 @@ enum { ARG_HOST, }; -static GstStaticPadTemplate src_factory = -GST_STATIC_PAD_TEMPLATE ( - "src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ( - "audio/x-raw-int, " - "endianness = (int) " G_STRINGIFY (G_BYTE_ORDER) ", " - "signed = (boolean) TRUE, " - "width = (int) 16, " - "depth = (int) 16, " - "rate = [ 8000, 96000 ], " - "channels = [ 1, 2 ]; " - "audio/x-raw-int, " - "signed = (boolean) FALSE, " - "width = (int) 8, " - "depth = (int) 8, " - "rate = [ 8000, 96000 ], " - "channels = [ 1, 2 ]" - ) -); - -static void gst_esdmon_base_init (gpointer g_class); -static void gst_esdmon_class_init (gpointer g_class, gpointer class_data); -static void gst_esdmon_init (GTypeInstance *instance, gpointer g_class); - -static gboolean gst_esdmon_open_audio (GstEsdmon *src); -static void gst_esdmon_close_audio (GstEsdmon *src); -static GstElementStateReturn gst_esdmon_change_state (GstElement *element); -static gboolean gst_esdmon_sync_parms (GstEsdmon *esdmon); - -static GstData * gst_esdmon_get (GstPad *pad); - -static void gst_esdmon_set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec); -static void gst_esdmon_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec); +static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-raw-int, " + "endianness = (int) " G_STRINGIFY (G_BYTE_ORDER) ", " + "signed = (boolean) TRUE, " + "width = (int) 16, " + "depth = (int) 16, " + "rate = [ 8000, 96000 ], " + "channels = [ 1, 2 ]; " + "audio/x-raw-int, " + "signed = (boolean) FALSE, " + "width = (int) 8, " + "depth = (int) 8, " "rate = [ 8000, 96000 ], " "channels = [ 1, 2 ]") + ); + +static void gst_esdmon_base_init (gpointer g_class); +static void gst_esdmon_class_init (gpointer g_class, gpointer class_data); +static void gst_esdmon_init (GTypeInstance * instance, gpointer g_class); + +static gboolean gst_esdmon_open_audio (GstEsdmon * src); +static void gst_esdmon_close_audio (GstEsdmon * src); +static GstElementStateReturn gst_esdmon_change_state (GstElement * element); +static gboolean gst_esdmon_sync_parms (GstEsdmon * esdmon); + +static GstData *gst_esdmon_get (GstPad * pad); + +static void gst_esdmon_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_esdmon_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); #define GST_TYPE_ESDMON_DEPTHS (gst_esdmon_depths_get_type()) static GType @@ -101,7 +97,8 @@ gst_esdmon_depths_get_type (void) {0, NULL, NULL}, }; if (!esdmon_depths_type) { - esdmon_depths_type = g_enum_register_static("GstEsdmonDepths", esdmon_depths); + esdmon_depths_type = + g_enum_register_static ("GstEsdmonDepths", esdmon_depths); } return esdmon_depths_type; } @@ -117,13 +114,15 @@ gst_esdmon_channels_get_type (void) {0, NULL, NULL}, }; if (!esdmon_channels_type) { - esdmon_channels_type = g_enum_register_static("GstEsdmonChannels", esdmon_channels); + esdmon_channels_type = + g_enum_register_static ("GstEsdmonChannels", esdmon_channels); } return esdmon_channels_type; } static GstElementClass *parent_class = NULL; + /*static guint gst_esdmon_signals[LAST_SIGNAL] = { 0 }; */ GType @@ -133,17 +132,18 @@ gst_esdmon_get_type (void) if (!esdmon_type) { static const GTypeInfo esdmon_info = { - sizeof(GstEsdmonClass), + sizeof (GstEsdmonClass), gst_esdmon_base_init, NULL, gst_esdmon_class_init, NULL, NULL, - sizeof(GstEsdmon), + sizeof (GstEsdmon), 0, gst_esdmon_init, }; - esdmon_type = g_type_register_static(GST_TYPE_ELEMENT, "GstEsdmon", &esdmon_info, 0); + esdmon_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstEsdmon", &esdmon_info, 0); } return esdmon_type; } @@ -153,7 +153,7 @@ gst_esdmon_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - gst_element_class_add_pad_template (element_class, + gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&src_factory)); gst_element_class_set_details (element_class, &esdmon_details); } @@ -166,24 +166,12 @@ gst_esdmon_class_init (gpointer g_class, gpointer class_data) parent_class = g_type_class_peek_parent (g_class); - g_object_class_install_property(gobject_class, ARG_BYTESPERREAD, - g_param_spec_ulong("bytes_per_read","bytes_per_read","bytes_per_read", - 0,G_MAXULONG,0,G_PARAM_READWRITE)); /* CHECKME */ - g_object_class_install_property(gobject_class, ARG_CUROFFSET, - g_param_spec_ulong("curoffset","curoffset","curoffset", - 0,G_MAXULONG,0,G_PARAM_READABLE)); /* CHECKME */ - g_object_class_install_property(gobject_class, ARG_DEPTH, - g_param_spec_enum("depth","depth","depth", - GST_TYPE_ESDMON_DEPTHS,16,G_PARAM_READWRITE)); /* CHECKME! */ - g_object_class_install_property(gobject_class, ARG_CHANNELS, - g_param_spec_enum("channels","channels","channels", - GST_TYPE_ESDMON_CHANNELS,2,G_PARAM_READWRITE)); /* CHECKME! */ - g_object_class_install_property(gobject_class, ARG_RATE, - g_param_spec_int("frequency","frequency","frequency", - G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); /* CHECKME */ - g_object_class_install_property(gobject_class, ARG_HOST, - g_param_spec_string("host","host","host", - NULL, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (gobject_class, ARG_BYTESPERREAD, g_param_spec_ulong ("bytes_per_read", "bytes_per_read", "bytes_per_read", 0, G_MAXULONG, 0, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (gobject_class, ARG_CUROFFSET, g_param_spec_ulong ("curoffset", "curoffset", "curoffset", 0, G_MAXULONG, 0, G_PARAM_READABLE)); /* CHECKME */ + g_object_class_install_property (gobject_class, ARG_DEPTH, g_param_spec_enum ("depth", "depth", "depth", GST_TYPE_ESDMON_DEPTHS, 16, G_PARAM_READWRITE)); /* CHECKME! */ + g_object_class_install_property (gobject_class, ARG_CHANNELS, g_param_spec_enum ("channels", "channels", "channels", GST_TYPE_ESDMON_CHANNELS, 2, G_PARAM_READWRITE)); /* CHECKME! */ + g_object_class_install_property (gobject_class, ARG_RATE, g_param_spec_int ("frequency", "frequency", "frequency", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (gobject_class, ARG_HOST, g_param_spec_string ("host", "host", "host", NULL, G_PARAM_READWRITE)); /* CHECKME */ gobject_class->set_property = gst_esdmon_set_property; gobject_class->get_property = gst_esdmon_get_property; @@ -192,16 +180,16 @@ gst_esdmon_class_init (gpointer g_class, gpointer class_data) } static void -gst_esdmon_init(GTypeInstance *instance, gpointer g_class) +gst_esdmon_init (GTypeInstance * instance, gpointer g_class) { GstEsdmon *esdmon = GST_ESDMON (instance); - esdmon->srcpad = gst_pad_new_from_template ( - gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (esdmon), "src"), - "src"); - gst_pad_set_get_function(esdmon->srcpad, gst_esdmon_get); + esdmon->srcpad = + gst_pad_new_from_template (gst_element_class_get_pad_template + (GST_ELEMENT_GET_CLASS (esdmon), "src"), "src"); + gst_pad_set_get_function (esdmon->srcpad, gst_esdmon_get); gst_pad_use_explicit_caps (esdmon->srcpad); - gst_element_add_pad(GST_ELEMENT(esdmon), esdmon->srcpad); + gst_element_add_pad (GST_ELEMENT (esdmon), esdmon->srcpad); esdmon->fd = -1; /* FIXME: get default from somewhere better than just putting them inline. */ @@ -216,12 +204,13 @@ gst_esdmon_init(GTypeInstance *instance, gpointer g_class) } static gboolean -gst_esdmon_sync_parms (GstEsdmon *esdmon) +gst_esdmon_sync_parms (GstEsdmon * esdmon) { g_return_val_if_fail (esdmon != NULL, FALSE); g_return_val_if_fail (GST_IS_ESDMON (esdmon), FALSE); - if (esdmon->fd == -1) return TRUE; + if (esdmon->fd == -1) + return TRUE; /* Need to set fd to use new parameters: only way to do this is to reopen. */ gst_esdmon_close_audio (esdmon); @@ -229,7 +218,7 @@ gst_esdmon_sync_parms (GstEsdmon *esdmon) } static GstData * -gst_esdmon_get (GstPad *pad) +gst_esdmon_get (GstPad * pad) { GstEsdmon *esdmon; GstBuffer *buf; @@ -237,36 +226,33 @@ gst_esdmon_get (GstPad *pad) glong readsamples; g_return_val_if_fail (pad != NULL, NULL); - esdmon = GST_ESDMON(gst_pad_get_parent (pad)); + esdmon = GST_ESDMON (gst_pad_get_parent (pad)); GST_DEBUG ("attempting to read something from esdmon"); buf = gst_buffer_new (); g_return_val_if_fail (buf, NULL); - GST_BUFFER_DATA (buf) = (gpointer)g_malloc (esdmon->bytes_per_read); + GST_BUFFER_DATA (buf) = (gpointer) g_malloc (esdmon->bytes_per_read); - readbytes = read (esdmon->fd, - GST_BUFFER_DATA (buf), - esdmon->bytes_per_read); + readbytes = read (esdmon->fd, GST_BUFFER_DATA (buf), esdmon->bytes_per_read); if (readbytes == 0) { - gst_element_set_eos (GST_ELEMENT (esdmon)); - return NULL; + gst_element_set_eos (GST_ELEMENT (esdmon)); + return NULL; } if (!GST_PAD_CAPS (pad)) { gint sign = (esdmon->depth == 8 ? FALSE : TRUE); + /* set caps on src pad */ if (gst_pad_set_explicit_caps (esdmon->srcpad, - gst_caps_new_simple ("audio/x-raw-int", - "endianness", G_TYPE_INT, G_BYTE_ORDER, - "signed", G_TYPE_BOOLEAN, sign, - "width", G_TYPE_INT, esdmon->depth, - "depth", G_TYPE_INT, esdmon->depth, - "rate", G_TYPE_INT, esdmon->frequency, - "channels", G_TYPE_INT, esdmon->channels - )) <= 0) - { + gst_caps_new_simple ("audio/x-raw-int", + "endianness", G_TYPE_INT, G_BYTE_ORDER, + "signed", G_TYPE_BOOLEAN, sign, + "width", G_TYPE_INT, esdmon->depth, + "depth", G_TYPE_INT, esdmon->depth, + "rate", G_TYPE_INT, esdmon->frequency, + "channels", G_TYPE_INT, esdmon->channels)) <= 0) { GST_ELEMENT_ERROR (esdmon, CORE, NEGOTIATION, (NULL), (NULL)); return NULL; } @@ -275,25 +261,28 @@ gst_esdmon_get (GstPad *pad) GST_BUFFER_SIZE (buf) = readbytes; GST_BUFFER_OFFSET (buf) = esdmon->curoffset; GST_BUFFER_TIMESTAMP (buf) = esdmon->basetime + - esdmon->samples_since_basetime * GST_SECOND / esdmon->frequency; + esdmon->samples_since_basetime * GST_SECOND / esdmon->frequency; esdmon->curoffset += readbytes; readsamples = readbytes / esdmon->channels; - if (esdmon->depth == 16) readsamples /= 2; + if (esdmon->depth == 16) + readsamples /= 2; esdmon->samples_since_basetime += readsamples; - GST_DEBUG ("pushed buffer from esdmon of %ld bytes, timestamp %" G_GINT64_FORMAT, readbytes, GST_BUFFER_TIMESTAMP (buf)); + GST_DEBUG ("pushed buffer from esdmon of %ld bytes, timestamp %" + G_GINT64_FORMAT, readbytes, GST_BUFFER_TIMESTAMP (buf)); return GST_DATA (buf); } static void -gst_esdmon_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +gst_esdmon_set_property (GObject * object, guint prop_id, const GValue * value, + GParamSpec * pspec) { GstEsdmon *esdmon; /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_ESDMON(object)); - esdmon = GST_ESDMON(object); + g_return_if_fail (GST_IS_ESDMON (object)); + esdmon = GST_ESDMON (object); switch (prop_id) { case ARG_BYTESPERREAD: @@ -310,7 +299,8 @@ gst_esdmon_set_property (GObject *object, guint prop_id, const GValue *value, GP break; case ARG_RATE: /* Preserve the timestamps */ - esdmon->basetime = esdmon->samples_since_basetime * GST_SECOND / esdmon->frequency; + esdmon->basetime = + esdmon->samples_since_basetime * GST_SECOND / esdmon->frequency; esdmon->samples_since_basetime = 0; /* Set the new frequency */ @@ -318,11 +308,12 @@ gst_esdmon_set_property (GObject *object, guint prop_id, const GValue *value, GP gst_esdmon_sync_parms (esdmon); break; case ARG_HOST: - if (esdmon->host != NULL) g_free(esdmon->host); + if (esdmon->host != NULL) + g_free (esdmon->host); if (g_value_get_string (value) == NULL) - esdmon->host = NULL; + esdmon->host = NULL; else - esdmon->host = g_strdup (g_value_get_string (value)); + esdmon->host = g_strdup (g_value_get_string (value)); break; default: break; @@ -330,13 +321,14 @@ gst_esdmon_set_property (GObject *object, guint prop_id, const GValue *value, GP } static void -gst_esdmon_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +gst_esdmon_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { GstEsdmon *esdmon; /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_ESDMON(object)); - esdmon = GST_ESDMON(object); + g_return_if_fail (GST_IS_ESDMON (object)); + esdmon = GST_ESDMON (object); switch (prop_id) { case ARG_BYTESPERREAD: @@ -364,42 +356,46 @@ gst_esdmon_get_property (GObject *object, guint prop_id, GValue *value, GParamSp } gboolean -gst_esdmon_factory_init (GstPlugin *plugin) +gst_esdmon_factory_init (GstPlugin * plugin) { if (!gst_element_register (plugin, "esdmon", GST_RANK_NONE, GST_TYPE_ESDMON)) return FALSE; - + return TRUE; } static gboolean -gst_esdmon_open_audio (GstEsdmon *src) +gst_esdmon_open_audio (GstEsdmon * src) { /* Name used by esound for this connection. */ - const char * connname = "GStreamer"; + const char *connname = "GStreamer"; /* Bitmap describing audio format. */ esd_format_t esdformat = ESD_STREAM | ESD_PLAY; g_return_val_if_fail (src->fd == -1, FALSE); - if (src->depth == 16) esdformat |= ESD_BITS16; - else if (src->depth == 8) esdformat |= ESD_BITS8; + if (src->depth == 16) + esdformat |= ESD_BITS16; + else if (src->depth == 8) + esdformat |= ESD_BITS8; else { GST_DEBUG ("esdmon: invalid bit depth (%d)", src->depth); return FALSE; } - if (src->channels == 2) esdformat |= ESD_STEREO; - else if (src->channels == 1) esdformat |= ESD_MONO; + if (src->channels == 2) + esdformat |= ESD_STEREO; + else if (src->channels == 1) + esdformat |= ESD_MONO; else { GST_DEBUG ("esdmon: invalid number of channels (%d)", src->channels); return FALSE; } GST_DEBUG ("esdmon: attempting to open connection to esound server"); - src->fd = esd_monitor_stream(esdformat, src->frequency, src->host, connname); - if ( src->fd < 0 ) { + src->fd = esd_monitor_stream (esdformat, src->frequency, src->host, connname); + if (src->fd < 0) { GST_DEBUG ("esdmon: can't open connection to esound server"); return FALSE; } @@ -410,11 +406,12 @@ gst_esdmon_open_audio (GstEsdmon *src) } static void -gst_esdmon_close_audio (GstEsdmon *src) +gst_esdmon_close_audio (GstEsdmon * src) { - if (src->fd < 0) return; + if (src->fd < 0) + return; - close(src->fd); + close (src->fd); src->fd = -1; GST_FLAG_UNSET (src, GST_ESDMON_OPEN); @@ -423,7 +420,7 @@ gst_esdmon_close_audio (GstEsdmon *src) } static GstElementStateReturn -gst_esdmon_change_state (GstElement *element) +gst_esdmon_change_state (GstElement * element) { g_return_val_if_fail (GST_IS_ESDMON (element), FALSE); @@ -443,4 +440,3 @@ gst_esdmon_change_state (GstElement *element) return GST_ELEMENT_CLASS (parent_class)->change_state (element); return GST_STATE_SUCCESS; } - diff --git a/ext/esd/esdmon.h b/ext/esd/esdmon.h index f50e6544..5b8c7e49 100644 --- a/ext/esd/esdmon.h +++ b/ext/esd/esdmon.h @@ -26,7 +26,6 @@ #include <gst/gst.h> G_BEGIN_DECLS - #define GST_TYPE_ESDMON \ (gst_esdmon_get_type()) #define GST_ESDMON(obj) \ @@ -37,21 +36,22 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_ESDMON)) #define GST_IS_ESDMON_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_ESDMON)) - -typedef enum { - GST_ESDMON_OPEN = GST_ELEMENT_FLAG_LAST, - GST_ESDMON_FLAG_LAST = GST_ELEMENT_FLAG_LAST+2, + typedef enum +{ + GST_ESDMON_OPEN = GST_ELEMENT_FLAG_LAST, + GST_ESDMON_FLAG_LAST = GST_ELEMENT_FLAG_LAST + 2, } GstEsdSrcFlags; typedef struct _GstEsdmon GstEsdmon; typedef struct _GstEsdmonClass GstEsdmonClass; -struct _GstEsdmon { +struct _GstEsdmon +{ GstElement element; GstPad *srcpad; - gchar* host; + gchar *host; int fd; @@ -65,14 +65,13 @@ struct _GstEsdmon { guint64 bytes_per_read; }; -struct _GstEsdmonClass { +struct _GstEsdmonClass +{ GstElementClass parent_class; }; -GType gst_esdmon_get_type(void); -gboolean gst_esdmon_factory_init(GstPlugin *plugin); +GType gst_esdmon_get_type (void); +gboolean gst_esdmon_factory_init (GstPlugin * plugin); G_END_DECLS - #endif /* __GST_ESDMON_H__ */ - diff --git a/ext/esd/esdsink.c b/ext/esd/esdsink.c index 4672ab79..ce7045e7 100644 --- a/ext/esd/esdsink.c +++ b/ext/esd/esdsink.c @@ -40,12 +40,14 @@ static GstElementDetails esdsink_details = { }; /* Signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_MUTE, ARG_HOST, @@ -53,41 +55,36 @@ enum { ARG_FALLBACK, }; -static GstStaticPadTemplate sink_factory = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ( - "audio/x-raw-int, " - "endianness = (int) " G_STRINGIFY (G_BYTE_ORDER) ", " - "signed = (boolean) TRUE, " - "width = (int) 16, " - "depth = (int) 16, " - "rate = 44100, " - "channels = 2" - ) -); - -static void gst_esdsink_base_init (gpointer g_class); -static void gst_esdsink_class_init (gpointer g_class, gpointer class_data); -static void gst_esdsink_init (GTypeInstance *instance, gpointer g_class); - -static gboolean gst_esdsink_open_audio (GstEsdsink *sink); -static void gst_esdsink_close_audio (GstEsdsink *sink); -static GstElementStateReturn gst_esdsink_change_state (GstElement *element); - -static GstClockTime gst_esdsink_get_time (GstClock *clock, gpointer data); -static GstClock * gst_esdsink_get_clock (GstElement *element); -static void gst_esdsink_set_clock (GstElement *element, GstClock *clock); -static void gst_esdsink_chain (GstPad *pad, GstData *_data); - -static void gst_esdsink_set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec); -static void gst_esdsink_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec); +static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-raw-int, " + "endianness = (int) " G_STRINGIFY (G_BYTE_ORDER) ", " + "signed = (boolean) TRUE, " + "width = (int) 16, " + "depth = (int) 16, " "rate = 44100, " "channels = 2") + ); + +static void gst_esdsink_base_init (gpointer g_class); +static void gst_esdsink_class_init (gpointer g_class, gpointer class_data); +static void gst_esdsink_init (GTypeInstance * instance, gpointer g_class); + +static gboolean gst_esdsink_open_audio (GstEsdsink * sink); +static void gst_esdsink_close_audio (GstEsdsink * sink); +static GstElementStateReturn gst_esdsink_change_state (GstElement * element); + +static GstClockTime gst_esdsink_get_time (GstClock * clock, gpointer data); +static GstClock *gst_esdsink_get_clock (GstElement * element); +static void gst_esdsink_set_clock (GstElement * element, GstClock * clock); +static void gst_esdsink_chain (GstPad * pad, GstData * _data); + +static void gst_esdsink_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_esdsink_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); static GstElementClass *parent_class = NULL; + /*static guint gst_esdsink_signals[LAST_SIGNAL] = { 0 }; */ GType @@ -97,17 +94,19 @@ gst_esdsink_get_type (void) if (!esdsink_type) { static const GTypeInfo esdsink_info = { - sizeof(GstEsdsinkClass), + sizeof (GstEsdsinkClass), gst_esdsink_base_init, NULL, gst_esdsink_class_init, NULL, NULL, - sizeof(GstEsdsink), + sizeof (GstEsdsink), 0, gst_esdsink_init, }; - esdsink_type = g_type_register_static(GST_TYPE_ELEMENT, "GstEsdsink", &esdsink_info, 0); + esdsink_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstEsdsink", &esdsink_info, + 0); } return esdsink_type; } @@ -117,7 +116,7 @@ gst_esdsink_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - gst_element_class_add_pad_template (element_class, + gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&sink_factory)); gst_element_class_set_details (element_class, &esdsink_details); } @@ -130,64 +129,64 @@ gst_esdsink_class_init (gpointer g_class, gpointer class_data) parent_class = g_type_class_peek_parent (g_class); - g_object_class_install_property(gobject_class, ARG_MUTE, - g_param_spec_boolean("mute","mute","mute", - TRUE,G_PARAM_READWRITE)); /* CHECKME */ - g_object_class_install_property(gobject_class, ARG_HOST, - g_param_spec_string("host","host","host", - NULL, G_PARAM_READWRITE)); /* CHECKME */ - g_object_class_install_property(gobject_class, ARG_SYNC, - g_param_spec_boolean("sync","sync","Synchronize output to clock", - TRUE,G_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, ARG_MUTE, g_param_spec_boolean ("mute", "mute", "mute", TRUE, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (gobject_class, ARG_HOST, g_param_spec_string ("host", "host", "host", NULL, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (gobject_class, ARG_SYNC, + g_param_spec_boolean ("sync", "sync", "Synchronize output to clock", + TRUE, G_PARAM_READWRITE)); #if 0 /* This option is disabled because it is dumb in GStreamer's architecture. */ - g_object_class_install_property(gobject_class, ARG_FALLBACK, - g_param_spec_boolean("fallback","fallback","Fall back to using OSS if Esound daemon is not present", - FALSE,G_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, ARG_FALLBACK, + g_param_spec_boolean ("fallback", "fallback", + "Fall back to using OSS if Esound daemon is not present", FALSE, + G_PARAM_READWRITE)); #endif gobject_class->set_property = gst_esdsink_set_property; gobject_class->get_property = gst_esdsink_get_property; gstelement_class->change_state = gst_esdsink_change_state; - gstelement_class->set_clock = gst_esdsink_set_clock; - gstelement_class->get_clock = gst_esdsink_get_clock; + gstelement_class->set_clock = gst_esdsink_set_clock; + gstelement_class->get_clock = gst_esdsink_get_clock; } static void -gst_esdsink_init(GTypeInstance *instance, gpointer g_class) +gst_esdsink_init (GTypeInstance * instance, gpointer g_class) { GstEsdsink *esdsink = GST_ESDSINK (instance); - - esdsink->sinkpad = gst_pad_new_from_template ( - gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (instance), "sink"), - "sink"); - gst_element_add_pad(GST_ELEMENT(esdsink), esdsink->sinkpad); - gst_pad_set_chain_function(esdsink->sinkpad, GST_DEBUG_FUNCPTR(gst_esdsink_chain)); + + esdsink->sinkpad = + gst_pad_new_from_template (gst_element_class_get_pad_template + (GST_ELEMENT_GET_CLASS (instance), "sink"), "sink"); + gst_element_add_pad (GST_ELEMENT (esdsink), esdsink->sinkpad); + gst_pad_set_chain_function (esdsink->sinkpad, + GST_DEBUG_FUNCPTR (gst_esdsink_chain)); GST_FLAG_SET (esdsink, GST_ELEMENT_EVENT_AWARE); esdsink->mute = FALSE; esdsink->fd = -1; /* FIXME: get default from somewhere better than just putting them inline. */ - /*esdsink->negotiated = FALSE;*/ + /*esdsink->negotiated = FALSE; */ /* we have static caps on our template, so it always is negotiated */ esdsink->negotiated = TRUE; esdsink->format = 16; esdsink->depth = 16; esdsink->channels = 2; esdsink->frequency = 44100; - esdsink->bytes_per_sample = esdsink->channels * (esdsink->depth/8); + esdsink->bytes_per_sample = esdsink->channels * (esdsink->depth / 8); esdsink->host = getenv ("ESPEAKER"); - esdsink->provided_clock = gst_audio_clock_new("esdclock", gst_esdsink_get_time, esdsink); - gst_object_set_parent(GST_OBJECT(esdsink->provided_clock), GST_OBJECT(esdsink)); + esdsink->provided_clock = + gst_audio_clock_new ("esdclock", gst_esdsink_get_time, esdsink); + gst_object_set_parent (GST_OBJECT (esdsink->provided_clock), + GST_OBJECT (esdsink)); esdsink->sync = TRUE; esdsink->fallback = FALSE; } #ifdef unused static GstPadLinkReturn -gst_esdsink_link (GstPad *pad, const GstCaps *caps) +gst_esdsink_link (GstPad * pad, const GstCaps * caps) { GstEsdsink *esdsink; GstStructure *structure; @@ -199,7 +198,7 @@ gst_esdsink_link (GstPad *pad, const GstCaps *caps) gst_structure_get_int (structure, "channels", &esdsink->channels); gst_structure_get_int (structure, "rate", &esdsink->frequency); - esdsink->bytes_per_sample = esdsink->channels * (esdsink->depth/8); + esdsink->bytes_per_sample = esdsink->channels * (esdsink->depth / 8); gst_esdsink_close_audio (esdsink); if (gst_esdsink_open_audio (esdsink)) { @@ -215,29 +214,29 @@ gst_esdsink_link (GstPad *pad, const GstCaps *caps) #endif static GstClockTime -gst_esdsink_get_time (GstClock *clock, gpointer data) +gst_esdsink_get_time (GstClock * clock, gpointer data) { - GstEsdsink *esdsink = GST_ESDSINK(data); + GstEsdsink *esdsink = GST_ESDSINK (data); GstClockTime res; res = (esdsink->handled * GST_SECOND) / esdsink->frequency; - //- GST_SECOND * 2; + //- GST_SECOND * 2; return res; } static GstClock * -gst_esdsink_get_clock (GstElement *element) +gst_esdsink_get_clock (GstElement * element) { GstEsdsink *esdsink; esdsink = GST_ESDSINK (element); - return GST_CLOCK(esdsink->provided_clock); + return GST_CLOCK (esdsink->provided_clock); } static void -gst_esdsink_set_clock (GstElement *element, GstClock *clock) +gst_esdsink_set_clock (GstElement * element, GstClock * clock) { GstEsdsink *esdsink; @@ -247,7 +246,7 @@ gst_esdsink_set_clock (GstElement *element, GstClock *clock) } static void -gst_esdsink_chain (GstPad *pad, GstData *_data) +gst_esdsink_chain (GstPad * pad, GstData * _data) { GstBuffer *buf = GST_BUFFER (_data); GstEsdsink *esdsink; @@ -256,24 +255,24 @@ gst_esdsink_chain (GstPad *pad, GstData *_data) if (!esdsink->negotiated) { GST_ELEMENT_ERROR (esdsink, CORE, NEGOTIATION, (NULL), - ("element wasn't negotiated before chain function")); + ("element wasn't negotiated before chain function")); goto done; } - if (GST_IS_EVENT(buf)){ - GstEvent *event = GST_EVENT(buf); + if (GST_IS_EVENT (buf)) { + GstEvent *event = GST_EVENT (buf); - switch(GST_EVENT_TYPE(event)){ + switch (GST_EVENT_TYPE (event)) { case GST_EVENT_EOS: gst_audio_clock_set_active (GST_AUDIO_CLOCK (esdsink->provided_clock), FALSE); gst_pad_event_default (pad, event); return; default: - gst_pad_event_default(pad, event); + gst_pad_event_default (pad, event); return; } - gst_event_unref(event); + gst_event_unref (event); return; } @@ -286,17 +285,17 @@ gst_esdsink_chain (GstPad *pad, GstData *_data) to_write = size; GST_LOG ("fd=%d data=%p size=%d", - esdsink->fd, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf)); - while (to_write > 0){ + esdsink->fd, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf)); + while (to_write > 0) { int done; - done = write (esdsink->fd, data, to_write); + done = write (esdsink->fd, data, to_write); - if(done < 0){ - if(errno==EINTR){ + if (done < 0) { + if (errno == EINTR) { goto done; } - g_assert_not_reached(); + g_assert_not_reached (); } to_write -= done; @@ -307,7 +306,7 @@ gst_esdsink_chain (GstPad *pad, GstData *_data) } } - gst_audio_clock_update_time ((GstAudioClock *)esdsink->provided_clock, + gst_audio_clock_update_time ((GstAudioClock *) esdsink->provided_clock, gst_esdsink_get_time (esdsink->provided_clock, esdsink)); done: @@ -315,24 +314,25 @@ done: } static void -gst_esdsink_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +gst_esdsink_set_property (GObject * object, guint prop_id, const GValue * value, + GParamSpec * pspec) { GstEsdsink *esdsink; /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_ESDSINK(object)); - esdsink = GST_ESDSINK(object); + g_return_if_fail (GST_IS_ESDSINK (object)); + esdsink = GST_ESDSINK (object); switch (prop_id) { case ARG_MUTE: esdsink->mute = g_value_get_boolean (value); break; case ARG_HOST: - g_free(esdsink->host); + g_free (esdsink->host); if (g_value_get_string (value) == NULL) - esdsink->host = NULL; + esdsink->host = NULL; else - esdsink->host = g_strdup (g_value_get_string (value)); + esdsink->host = g_strdup (g_value_get_string (value)); break; case ARG_SYNC: esdsink->sync = g_value_get_boolean (value); @@ -346,11 +346,12 @@ gst_esdsink_set_property (GObject *object, guint prop_id, const GValue *value, G } static void -gst_esdsink_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +gst_esdsink_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { GstEsdsink *esdsink; - esdsink = GST_ESDSINK(object); + esdsink = GST_ESDSINK (object); switch (prop_id) { case ARG_MUTE: @@ -372,50 +373,58 @@ gst_esdsink_get_property (GObject *object, guint prop_id, GValue *value, GParamS } gboolean -gst_esdsink_factory_init (GstPlugin *plugin) +gst_esdsink_factory_init (GstPlugin * plugin) { - if (!gst_element_register (plugin, "esdsink", GST_RANK_NONE, GST_TYPE_ESDSINK)) + if (!gst_element_register (plugin, "esdsink", GST_RANK_NONE, + GST_TYPE_ESDSINK)) return FALSE; return TRUE; } static gboolean -gst_esdsink_open_audio (GstEsdsink *sink) +gst_esdsink_open_audio (GstEsdsink * sink) { /* Name used by esound for this connection. */ - const char * connname = "GStreamer"; + const char *connname = "GStreamer"; /* Bitmap describing audio format. */ esd_format_t esdformat = ESD_STREAM | ESD_PLAY; g_return_val_if_fail (sink->fd == -1, FALSE); - if (sink->depth == 16) esdformat |= ESD_BITS16; - else if (sink->depth == 8) esdformat |= ESD_BITS8; + if (sink->depth == 16) + esdformat |= ESD_BITS16; + else if (sink->depth == 8) + esdformat |= ESD_BITS8; else { GST_ELEMENT_ERROR (sink, STREAM, FORMAT, (NULL), - ("invalid bit depth (%d)", sink->depth)); + ("invalid bit depth (%d)", sink->depth)); return FALSE; } - if (sink->channels == 2) esdformat |= ESD_STEREO; - else if (sink->channels == 1) esdformat |= ESD_MONO; + if (sink->channels == 2) + esdformat |= ESD_STEREO; + else if (sink->channels == 1) + esdformat |= ESD_MONO; else { GST_ELEMENT_ERROR (sink, STREAM, FORMAT, (NULL), - ("invalid number of channels (%d)", sink->channels)); + ("invalid number of channels (%d)", sink->channels)); return FALSE; } GST_INFO ("attempting to open connection to esound server"); - if(sink->fallback){ - sink->fd = esd_play_stream_fallback(esdformat, sink->frequency, sink->host, connname); - }else{ - sink->fd = esd_play_stream(esdformat, sink->frequency, sink->host, connname); + if (sink->fallback) { + sink->fd = + esd_play_stream_fallback (esdformat, sink->frequency, sink->host, + connname); + } else { + sink->fd = + esd_play_stream (esdformat, sink->frequency, sink->host, connname); } - if ( sink->fd < 0 ) { + if (sink->fd < 0) { GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), - ("can't open connection to esound server")); + ("can't open connection to esound server")); return FALSE; } GST_INFO ("successfully opened connection to esound server"); @@ -424,19 +433,19 @@ gst_esdsink_open_audio (GstEsdsink *sink) } static void -gst_esdsink_close_audio (GstEsdsink *sink) +gst_esdsink_close_audio (GstEsdsink * sink) { - if (sink->fd < 0) + if (sink->fd < 0) return; - close(sink->fd); + close (sink->fd); sink->fd = -1; GST_INFO ("esdsink: closed sound device"); } static GstElementStateReturn -gst_esdsink_change_state (GstElement *element) +gst_esdsink_change_state (GstElement * element) { GstEsdsink *esdsink; @@ -445,7 +454,7 @@ gst_esdsink_change_state (GstElement *element) switch (GST_STATE_TRANSITION (element)) { case GST_STATE_NULL_TO_READY: if (!gst_esdsink_open_audio (GST_ESDSINK (element))) { - return GST_STATE_FAILURE; + return GST_STATE_FAILURE; } break; case GST_STATE_READY_TO_PAUSED: @@ -473,4 +482,3 @@ gst_esdsink_change_state (GstElement *element) return GST_STATE_SUCCESS; } - diff --git a/ext/esd/esdsink.h b/ext/esd/esdsink.h index 9bf81641..f88f29b1 100644 --- a/ext/esd/esdsink.h +++ b/ext/esd/esdsink.h @@ -25,7 +25,6 @@ #include <gst/audio/audioclock.h> G_BEGIN_DECLS - #define GST_TYPE_ESDSINK \ (gst_esdsink_get_type()) #define GST_ESDSINK(obj) \ @@ -36,41 +35,41 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_ESDSINK)) #define GST_IS_ESDSINK_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_ESDSINK)) - typedef struct _GstEsdsink GstEsdsink; typedef struct _GstEsdsinkClass GstEsdsinkClass; -struct _GstEsdsink { - GstElement element; +struct _GstEsdsink +{ + GstElement element; - GstPad *sinkpad; + GstPad *sinkpad; - GstClock *provided_clock; - GstClock *clock; + GstClock *provided_clock; + GstClock *clock; - gboolean mute; - int fd; - gint format; - gint depth; - gint channels; - gint frequency; - gboolean negotiated; - gchar *host; - int handled; - int bytes_per_sample; - gboolean sync; - gboolean resync; - gboolean fallback; + gboolean mute; + int fd; + gint format; + gint depth; + gint channels; + gint frequency; + gboolean negotiated; + gchar *host; + int handled; + int bytes_per_sample; + gboolean sync; + gboolean resync; + gboolean fallback; }; -struct _GstEsdsinkClass { +struct _GstEsdsinkClass +{ GstElementClass parent_class; }; -GType gst_esdsink_get_type(void); -gboolean gst_esdsink_factory_init (GstPlugin *plugin); +GType gst_esdsink_get_type (void); +gboolean gst_esdsink_factory_init (GstPlugin * plugin); G_END_DECLS - #endif /* __GST_ESDSINK_H__ */ diff --git a/ext/esd/gstesd.c b/ext/esd/gstesd.c index ea480a30..4ee03364 100644 --- a/ext/esd/gstesd.c +++ b/ext/esd/gstesd.c @@ -27,30 +27,27 @@ GST_DEBUG_CATEGORY (esd_debug); static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { gboolean ret; - if (!gst_library_load ("gstaudio")) return FALSE; + if (!gst_library_load ("gstaudio")) + return FALSE; - ret = gst_esdsink_factory_init(plugin); - if(ret == FALSE) return FALSE; + ret = gst_esdsink_factory_init (plugin); + if (ret == FALSE) + return FALSE; - ret = gst_esdmon_factory_init(plugin); - if(ret == FALSE) return FALSE; + ret = gst_esdmon_factory_init (plugin); + if (ret == FALSE) + return FALSE; GST_DEBUG_CATEGORY_INIT (esd_debug, "esd", 0, "ESounD elements"); return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "esdsink", - "ESD Element Plugins", - plugin_init, - VERSION, - "LGPL", - GST_PACKAGE, - GST_ORIGIN) - +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "esdsink", + "ESD Element Plugins", + plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN) diff --git a/ext/flac/flac_compat.h b/ext/flac/flac_compat.h index 87b5b864..defa969d 100644 --- a/ext/flac/flac_compat.h +++ b/ext/flac/flac_compat.h @@ -16,7 +16,7 @@ /* FIXME when there's a autoconf symbol */ #ifndef FLAC_VERSION -#ifndef FLAC__VERSION_STRING /* removed in 1.0.4 */ +#ifndef FLAC__VERSION_STRING /* removed in 1.0.4 */ #define FLAC_VERSION 0x010004 #else #ifdef FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE diff --git a/ext/flac/gstflac.c b/ext/flac/gstflac.c index 3c06cacf..c1dba934 100644 --- a/ext/flac/gstflac.c +++ b/ext/flac/gstflac.c @@ -28,7 +28,7 @@ #include "flac_compat.h" static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { if (!gst_library_load ("gstbytestream")) return FALSE; @@ -37,25 +37,23 @@ plugin_init (GstPlugin *plugin) if (!gst_plugin_load ("gsttags")) return FALSE; - if (!gst_element_register (plugin, "flacenc", GST_RANK_NONE, GST_TYPE_FLACENC)) + if (!gst_element_register (plugin, "flacenc", GST_RANK_NONE, + GST_TYPE_FLACENC)) return FALSE; - if (!gst_element_register (plugin, "flacdec", GST_RANK_PRIMARY, GST_TYPE_FLACDEC)) + if (!gst_element_register (plugin, "flacdec", GST_RANK_PRIMARY, + GST_TYPE_FLACDEC)) return FALSE; - if (!gst_element_register (plugin, "flactag", GST_RANK_PRIMARY, gst_flac_tag_get_type ())) + if (!gst_element_register (plugin, "flactag", GST_RANK_PRIMARY, + gst_flac_tag_get_type ())) return FALSE; - + return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "flac", - "The FLAC Lossless compressor Codec", - plugin_init, - VERSION, - "LGPL", - GST_PACKAGE, - GST_ORIGIN) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "flac", + "The FLAC Lossless compressor Codec", + plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN) diff --git a/ext/flac/gstflacdec.c b/ext/flac/gstflacdec.c index 25769bcf..3882df1a 100644 --- a/ext/flac/gstflacdec.c +++ b/ext/flac/gstflacdec.c @@ -41,104 +41,101 @@ GstElementDetails flacdec_details = { }; /* FlacDec signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_METADATA }; -static void gst_flacdec_base_init (gpointer g_class); -static void gst_flacdec_class_init (FlacDecClass *klass); -static void gst_flacdec_init (FlacDec *flacdec); +static void gst_flacdec_base_init (gpointer g_class); +static void gst_flacdec_class_init (FlacDecClass * klass); +static void gst_flacdec_init (FlacDec * flacdec); + +static void gst_flacdec_loop (GstElement * element); +static GstElementStateReturn gst_flacdec_change_state (GstElement * element); +static const GstFormat *gst_flacdec_get_src_formats (GstPad * pad); +static gboolean gst_flacdec_convert_src (GstPad * pad, GstFormat src_format, + gint64 src_value, GstFormat * dest_format, gint64 * dest_value); +static const GstQueryType *gst_flacdec_get_src_query_types (GstPad * pad); +static gboolean gst_flacdec_src_query (GstPad * pad, GstQueryType type, + GstFormat * format, gint64 * value); +static const GstEventMask *gst_flacdec_get_src_event_masks (GstPad * pad); +static gboolean gst_flacdec_src_event (GstPad * pad, GstEvent * event); -static void gst_flacdec_loop (GstElement *element); -static GstElementStateReturn - gst_flacdec_change_state (GstElement *element); -static const GstFormat* gst_flacdec_get_src_formats (GstPad *pad); -static gboolean gst_flacdec_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value, - GstFormat *dest_format, gint64 *dest_value); -static const GstQueryType* - gst_flacdec_get_src_query_types (GstPad *pad); -static gboolean gst_flacdec_src_query (GstPad *pad, GstQueryType type, - GstFormat *format, gint64 *value); -static const GstEventMask* - gst_flacdec_get_src_event_masks (GstPad *pad); -static gboolean gst_flacdec_src_event (GstPad *pad, GstEvent *event); - -static FLAC__SeekableStreamDecoderReadStatus - gst_flacdec_read (const FLAC__SeekableStreamDecoder *decoder, - FLAC__byte buffer[], unsigned *bytes, - void *client_data); -static FLAC__SeekableStreamDecoderSeekStatus - gst_flacdec_seek (const FLAC__SeekableStreamDecoder *decoder, - FLAC__uint64 position, void *client_data); -static FLAC__SeekableStreamDecoderTellStatus - gst_flacdec_tell (const FLAC__SeekableStreamDecoder *decoder, - FLAC__uint64 *position, void *client_data); -static FLAC__SeekableStreamDecoderLengthStatus - gst_flacdec_length (const FLAC__SeekableStreamDecoder *decoder, - FLAC__uint64 *length, void *client_data); -static FLAC__bool gst_flacdec_eof (const FLAC__SeekableStreamDecoder *decoder, - void *client_data); -static FLAC__StreamDecoderWriteStatus - gst_flacdec_write (const FLAC__SeekableStreamDecoder *decoder, - const FLAC__Frame *frame, - const FLAC__int32 * const buffer[], - void *client_data); -static void gst_flacdec_metadata_callback (const FLAC__SeekableStreamDecoder *decoder, - const FLAC__StreamMetadata *metadata, - void *client_data); -static void gst_flacdec_error_callback (const FLAC__SeekableStreamDecoder *decoder, - FLAC__StreamDecoderErrorStatus status, - void *client_data); +static FLAC__SeekableStreamDecoderReadStatus +gst_flacdec_read (const FLAC__SeekableStreamDecoder * decoder, + FLAC__byte buffer[], unsigned *bytes, void *client_data); +static FLAC__SeekableStreamDecoderSeekStatus +gst_flacdec_seek (const FLAC__SeekableStreamDecoder * decoder, + FLAC__uint64 position, void *client_data); +static FLAC__SeekableStreamDecoderTellStatus +gst_flacdec_tell (const FLAC__SeekableStreamDecoder * decoder, + FLAC__uint64 * position, void *client_data); +static FLAC__SeekableStreamDecoderLengthStatus +gst_flacdec_length (const FLAC__SeekableStreamDecoder * decoder, + FLAC__uint64 * length, void *client_data); +static FLAC__bool gst_flacdec_eof (const FLAC__SeekableStreamDecoder * decoder, + void *client_data); +static FLAC__StreamDecoderWriteStatus +gst_flacdec_write (const FLAC__SeekableStreamDecoder * decoder, + const FLAC__Frame * frame, + const FLAC__int32 * const buffer[], void *client_data); +static void gst_flacdec_metadata_callback (const FLAC__SeekableStreamDecoder * + decoder, const FLAC__StreamMetadata * metadata, void *client_data); +static void gst_flacdec_error_callback (const FLAC__SeekableStreamDecoder * + decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); static GstElementClass *parent_class = NULL; + /*static guint gst_flacdec_signals[LAST_SIGNAL] = { 0 }; */ GType -flacdec_get_type(void) { +flacdec_get_type (void) +{ static GType flacdec_type = 0; if (!flacdec_type) { static const GTypeInfo flacdec_info = { - sizeof(FlacDecClass), + sizeof (FlacDecClass), gst_flacdec_base_init, NULL, - (GClassInitFunc)gst_flacdec_class_init, + (GClassInitFunc) gst_flacdec_class_init, NULL, NULL, - sizeof(FlacDec), + sizeof (FlacDec), 0, - (GInstanceInitFunc)gst_flacdec_init, + (GInstanceInitFunc) gst_flacdec_init, }; - flacdec_type = g_type_register_static (GST_TYPE_ELEMENT, "FlacDec", &flacdec_info, 0); + flacdec_type = + g_type_register_static (GST_TYPE_ELEMENT, "FlacDec", &flacdec_info, 0); } return flacdec_type; } -static GstCaps* +static GstCaps * flac_caps_factory (void) { return gst_caps_new_simple ("audio/x-flac", NULL); - /* "rate", GST_PROPS_INT_RANGE (11025, 48000), - * "channels", GST_PROPS_INT_RANGE (1, 2), */ + /* "rate", GST_PROPS_INT_RANGE (11025, 48000), + * "channels", GST_PROPS_INT_RANGE (1, 2), */ } -static GstCaps* +static GstCaps * raw_caps_factory (void) { return gst_caps_new_simple ("audio/x-raw-int", - "endianness", G_TYPE_INT, G_BYTE_ORDER, - "signed", G_TYPE_BOOLEAN, TRUE, - "width", G_TYPE_INT, 16, - "depth", G_TYPE_INT, 16, - "rate", GST_TYPE_INT_RANGE, 11025, 48000, - "channels", GST_TYPE_INT_RANGE, 1, 2, - NULL); + "endianness", G_TYPE_INT, G_BYTE_ORDER, + "signed", G_TYPE_BOOLEAN, TRUE, + "width", G_TYPE_INT, 16, + "depth", G_TYPE_INT, 16, + "rate", GST_TYPE_INT_RANGE, 11025, 48000, + "channels", GST_TYPE_INT_RANGE, 1, 2, NULL); } static void @@ -152,7 +149,7 @@ gst_flacdec_base_init (gpointer g_class) sink_template = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, flac_caps); - src_template = gst_pad_template_new ("src", GST_PAD_SRC, + src_template = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, raw_caps); gst_element_class_add_pad_template (element_class, sink_template); gst_element_class_add_pad_template (element_class, src_template); @@ -160,21 +157,21 @@ gst_flacdec_base_init (gpointer g_class) } static void -gst_flacdec_class_init (FlacDecClass *klass) +gst_flacdec_class_init (FlacDecClass * klass) { GstElementClass *gstelement_class; GObjectClass *gobject_class; - gstelement_class = (GstElementClass*)klass; - gobject_class = (GObjectClass*) klass; + gstelement_class = (GstElementClass *) klass; + gobject_class = (GObjectClass *) klass; - parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + parent_class = g_type_class_ref (GST_TYPE_ELEMENT); gstelement_class->change_state = gst_flacdec_change_state; } -static void -gst_flacdec_init (FlacDec *flacdec) +static void +gst_flacdec_init (FlacDec * flacdec) { flacdec->sinkpad = gst_pad_new_from_template (sink_template, "sink"); gst_element_add_pad (GST_ELEMENT (flacdec), flacdec->sinkpad); @@ -185,9 +182,11 @@ gst_flacdec_init (FlacDec *flacdec) gst_element_add_pad (GST_ELEMENT (flacdec), flacdec->srcpad); gst_pad_set_formats_function (flacdec->srcpad, gst_flacdec_get_src_formats); gst_pad_set_convert_function (flacdec->srcpad, gst_flacdec_convert_src); - gst_pad_set_query_type_function (flacdec->srcpad, gst_flacdec_get_src_query_types); + gst_pad_set_query_type_function (flacdec->srcpad, + gst_flacdec_get_src_query_types); gst_pad_set_query_function (flacdec->srcpad, gst_flacdec_src_query); - gst_pad_set_event_mask_function (flacdec->srcpad, gst_flacdec_get_src_event_masks); + gst_pad_set_event_mask_function (flacdec->srcpad, + gst_flacdec_get_src_event_masks); gst_pad_set_event_function (flacdec->srcpad, gst_flacdec_src_event); gst_pad_use_explicit_caps (flacdec->srcpad); @@ -197,30 +196,39 @@ gst_flacdec_init (FlacDec *flacdec) flacdec->eos = FALSE; flacdec->seek_pending = FALSE; - FLAC__seekable_stream_decoder_set_read_callback (flacdec->decoder, gst_flacdec_read); - FLAC__seekable_stream_decoder_set_seek_callback (flacdec->decoder, gst_flacdec_seek); - FLAC__seekable_stream_decoder_set_tell_callback (flacdec->decoder, gst_flacdec_tell); - FLAC__seekable_stream_decoder_set_length_callback (flacdec->decoder, gst_flacdec_length); - FLAC__seekable_stream_decoder_set_eof_callback (flacdec->decoder, gst_flacdec_eof); + FLAC__seekable_stream_decoder_set_read_callback (flacdec->decoder, + gst_flacdec_read); + FLAC__seekable_stream_decoder_set_seek_callback (flacdec->decoder, + gst_flacdec_seek); + FLAC__seekable_stream_decoder_set_tell_callback (flacdec->decoder, + gst_flacdec_tell); + FLAC__seekable_stream_decoder_set_length_callback (flacdec->decoder, + gst_flacdec_length); + FLAC__seekable_stream_decoder_set_eof_callback (flacdec->decoder, + gst_flacdec_eof); #if FLAC_VERSION >= 0x010003 - FLAC__seekable_stream_decoder_set_write_callback (flacdec->decoder, gst_flacdec_write); + FLAC__seekable_stream_decoder_set_write_callback (flacdec->decoder, + gst_flacdec_write); #else FLAC__seekable_stream_decoder_set_write_callback (flacdec->decoder, - (FLAC__StreamDecoderWriteStatus (*) - (const FLAC__SeekableStreamDecoder *decoder, - const FLAC__Frame *frame, - const FLAC__int32 *buffer[], - void *client_data)) - (gst_flacdec_write)); + (FLAC__StreamDecoderWriteStatus (*) + (const FLAC__SeekableStreamDecoder * decoder, + const FLAC__Frame * frame, + const FLAC__int32 * buffer[], void *client_data)) + (gst_flacdec_write)); #endif - FLAC__seekable_stream_decoder_set_metadata_respond (flacdec->decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT); - FLAC__seekable_stream_decoder_set_metadata_callback (flacdec->decoder, gst_flacdec_metadata_callback); - FLAC__seekable_stream_decoder_set_error_callback (flacdec->decoder, gst_flacdec_error_callback); + FLAC__seekable_stream_decoder_set_metadata_respond (flacdec->decoder, + FLAC__METADATA_TYPE_VORBIS_COMMENT); + FLAC__seekable_stream_decoder_set_metadata_callback (flacdec->decoder, + gst_flacdec_metadata_callback); + FLAC__seekable_stream_decoder_set_error_callback (flacdec->decoder, + gst_flacdec_error_callback); FLAC__seekable_stream_decoder_set_client_data (flacdec->decoder, flacdec); } static gboolean -gst_flacdec_update_metadata (FlacDec *flacdec, const FLAC__StreamMetadata *metadata) +gst_flacdec_update_metadata (FlacDec * flacdec, + const FLAC__StreamMetadata * metadata) { GstTagList *list; guint32 number_of_comments, cursor, str_len; @@ -233,17 +241,15 @@ gst_flacdec_update_metadata (FlacDec *flacdec, const FLAC__StreamMetadata *metad number_of_comments = metadata->data.vorbis_comment.num_comments; value = NULL; - GST_DEBUG ("%d tag(s) found", number_of_comments); - for (cursor = 0; cursor < number_of_comments; cursor++) - { + GST_DEBUG ("%d tag(s) found", number_of_comments); + for (cursor = 0; cursor < number_of_comments; cursor++) { str_ptr = metadata->data.vorbis_comment.comments[cursor].entry; str_len = metadata->data.vorbis_comment.comments[cursor].length; - p_value = g_strstr_len ( str_ptr, str_len , "=" ); - if (p_value) - { + p_value = g_strstr_len (str_ptr, str_len, "="); + if (p_value) { name = g_strndup (str_ptr, p_value - str_ptr); value = g_strndup (p_value + 1, str_ptr + str_len - p_value - 1); - + GST_DEBUG ("%s : %s", name, value); gst_vorbis_tag_add (list, name, value); g_free (name); @@ -260,30 +266,29 @@ gst_flacdec_update_metadata (FlacDec *flacdec, const FLAC__StreamMetadata *metad } -static void -gst_flacdec_metadata_callback (const FLAC__SeekableStreamDecoder *decoder, - const FLAC__StreamMetadata *metadata, void *client_data) +static void +gst_flacdec_metadata_callback (const FLAC__SeekableStreamDecoder * decoder, + const FLAC__StreamMetadata * metadata, void *client_data) { FlacDec *flacdec; - + flacdec = GST_FLACDEC (client_data); - switch (metadata->type) - { + switch (metadata->type) { case FLAC__METADATA_TYPE_STREAMINFO: - flacdec->stream_samples = metadata->data.stream_info.total_samples; - break; + flacdec->stream_samples = metadata->data.stream_info.total_samples; + break; case FLAC__METADATA_TYPE_VORBIS_COMMENT: - gst_flacdec_update_metadata (flacdec, metadata); - break; + gst_flacdec_update_metadata (flacdec, metadata); + break; default: - break; + break; } } -static void -gst_flacdec_error_callback (const FLAC__SeekableStreamDecoder *decoder, - FLAC__StreamDecoderErrorStatus status, void *client_data) +static void +gst_flacdec_error_callback (const FLAC__SeekableStreamDecoder * decoder, + FLAC__StreamDecoderErrorStatus status, void *client_data) { FlacDec *flacdec; gchar *error; @@ -308,9 +313,9 @@ gst_flacdec_error_callback (const FLAC__SeekableStreamDecoder *decoder, GST_ELEMENT_ERROR (flacdec, STREAM, DECODE, (NULL), (error)); } -static FLAC__SeekableStreamDecoderSeekStatus -gst_flacdec_seek (const FLAC__SeekableStreamDecoder *decoder, - FLAC__uint64 position, void *client_data) +static FLAC__SeekableStreamDecoderSeekStatus +gst_flacdec_seek (const FLAC__SeekableStreamDecoder * decoder, + FLAC__uint64 position, void *client_data) { FlacDec *flacdec; @@ -323,9 +328,9 @@ gst_flacdec_seek (const FLAC__SeekableStreamDecoder *decoder, return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK; } -static FLAC__SeekableStreamDecoderTellStatus -gst_flacdec_tell (const FLAC__SeekableStreamDecoder *decoder, - FLAC__uint64 *position, void *client_data) +static FLAC__SeekableStreamDecoderTellStatus +gst_flacdec_tell (const FLAC__SeekableStreamDecoder * decoder, + FLAC__uint64 * position, void *client_data) { FlacDec *flacdec; @@ -340,9 +345,9 @@ gst_flacdec_tell (const FLAC__SeekableStreamDecoder *decoder, return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK; } -static FLAC__SeekableStreamDecoderLengthStatus -gst_flacdec_length (const FLAC__SeekableStreamDecoder *decoder, - FLAC__uint64 *length, void *client_data) +static FLAC__SeekableStreamDecoderLengthStatus +gst_flacdec_length (const FLAC__SeekableStreamDecoder * decoder, + FLAC__uint64 * length, void *client_data) { FlacDec *flacdec; @@ -358,8 +363,7 @@ gst_flacdec_length (const FLAC__SeekableStreamDecoder *decoder, } static FLAC__bool -gst_flacdec_eof (const FLAC__SeekableStreamDecoder *decoder, - void *client_data) +gst_flacdec_eof (const FLAC__SeekableStreamDecoder * decoder, void *client_data) { FlacDec *flacdec; @@ -370,9 +374,8 @@ gst_flacdec_eof (const FLAC__SeekableStreamDecoder *decoder, } static FLAC__SeekableStreamDecoderReadStatus -gst_flacdec_read (const FLAC__SeekableStreamDecoder *decoder, - FLAC__byte buffer[], unsigned *bytes, - void *client_data) +gst_flacdec_read (const FLAC__SeekableStreamDecoder * decoder, + FLAC__byte buffer[], unsigned *bytes, void *client_data) { FlacDec *flacdec; gint insize = 0; @@ -381,39 +384,39 @@ gst_flacdec_read (const FLAC__SeekableStreamDecoder *decoder, flacdec = GST_FLACDEC (client_data); //g_print ("read %u\n", *bytes); - + while (insize == 0) { insize = gst_bytestream_peek_bytes (flacdec->bs, &indata, *bytes); if (insize < *bytes) { GstEvent *event; guint32 avail; - + gst_bytestream_get_status (flacdec->bs, &avail, &event); switch (GST_EVENT_TYPE (event)) { - case GST_EVENT_EOS: - GST_DEBUG ("eos"); - flacdec->eos = TRUE; + case GST_EVENT_EOS: + GST_DEBUG ("eos"); + flacdec->eos = TRUE; gst_event_unref (event); - if (avail == 0) { - return 0; - } - break; - case GST_EVENT_DISCONTINUOUS: - GST_DEBUG ("discont"); + if (avail == 0) { + return 0; + } + break; + case GST_EVENT_DISCONTINUOUS: + GST_DEBUG ("discont"); /* we are not yet sending the discont, we'll do that in the next write operation */ flacdec->need_discont = TRUE; gst_event_unref (event); break; - default: + default: gst_pad_event_default (flacdec->sinkpad, event); - break; + break; } if (avail > 0) - insize = gst_bytestream_peek_bytes (flacdec->bs, &indata, avail); + insize = gst_bytestream_peek_bytes (flacdec->bs, &indata, avail); else - insize = 0; + insize = 0; } } @@ -425,10 +428,9 @@ gst_flacdec_read (const FLAC__SeekableStreamDecoder *decoder, } static FLAC__StreamDecoderWriteStatus -gst_flacdec_write (const FLAC__SeekableStreamDecoder *decoder, - const FLAC__Frame *frame, - const FLAC__int32 * const buffer[], - void *client_data) +gst_flacdec_write (const FLAC__SeekableStreamDecoder * decoder, + const FLAC__Frame * frame, + const FLAC__int32 * const buffer[], void *client_data) { FlacDec *flacdec; GstBuffer *outbuf; @@ -445,41 +447,39 @@ gst_flacdec_write (const FLAC__SeekableStreamDecoder *decoder, GstEvent *discont; flacdec->need_discont = FALSE; - + if (!GST_PAD_CAPS (flacdec->srcpad)) { if (flacdec->seek_pending) { - flacdec->total_samples = flacdec->seek_value; + flacdec->total_samples = flacdec->seek_value; } if (GST_PAD_IS_USABLE (flacdec->srcpad)) { - GST_DEBUG ("send discont"); - - format = GST_FORMAT_TIME; - gst_pad_convert (flacdec->srcpad, GST_FORMAT_DEFAULT, - flacdec->total_samples, &format, &time); - format = GST_FORMAT_BYTES; - gst_pad_convert (flacdec->srcpad, GST_FORMAT_DEFAULT, - flacdec->total_samples, &format, &bytes); - discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, time, - GST_FORMAT_BYTES, bytes, - GST_FORMAT_DEFAULT, flacdec->total_samples, - NULL); - - gst_pad_push (flacdec->srcpad, GST_DATA (discont)); + GST_DEBUG ("send discont"); + + format = GST_FORMAT_TIME; + gst_pad_convert (flacdec->srcpad, GST_FORMAT_DEFAULT, + flacdec->total_samples, &format, &time); + format = GST_FORMAT_BYTES; + gst_pad_convert (flacdec->srcpad, GST_FORMAT_DEFAULT, + flacdec->total_samples, &format, &bytes); + discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, time, + GST_FORMAT_BYTES, bytes, + GST_FORMAT_DEFAULT, flacdec->total_samples, NULL); + + gst_pad_push (flacdec->srcpad, GST_DATA (discont)); } } } - + if (!GST_PAD_CAPS (flacdec->srcpad)) { gst_pad_set_explicit_caps (flacdec->srcpad, - gst_caps_new_simple ("audio/x-raw-int", - "endianness", G_TYPE_INT, G_BYTE_ORDER, - "signed", G_TYPE_BOOLEAN, TRUE, - "width", G_TYPE_INT, depth, - "depth", G_TYPE_INT, depth, - "rate", G_TYPE_INT, frame->header.sample_rate, - "channels", G_TYPE_INT, channels, - NULL)); + gst_caps_new_simple ("audio/x-raw-int", + "endianness", G_TYPE_INT, G_BYTE_ORDER, + "signed", G_TYPE_BOOLEAN, TRUE, + "width", G_TYPE_INT, depth, + "depth", G_TYPE_INT, depth, + "rate", G_TYPE_INT, frame->header.sample_rate, + "channels", G_TYPE_INT, channels, NULL)); flacdec->depth = depth; flacdec->channels = channels; @@ -488,29 +488,28 @@ gst_flacdec_write (const FLAC__SeekableStreamDecoder *decoder, if (GST_PAD_IS_USABLE (flacdec->srcpad)) { outbuf = gst_buffer_new (); - GST_BUFFER_SIZE (outbuf) = samples * channels * ((depth+7)>>3); + GST_BUFFER_SIZE (outbuf) = samples * channels * ((depth + 7) >> 3); GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf)); - GST_BUFFER_TIMESTAMP (outbuf) = flacdec->total_samples * GST_SECOND / frame->header.sample_rate; - + GST_BUFFER_TIMESTAMP (outbuf) = + flacdec->total_samples * GST_SECOND / frame->header.sample_rate; + if (depth == 8) { - guint8 *outbuffer = (guint8 *)GST_BUFFER_DATA (outbuf); - - for (i=0; i<samples; i++) { - for (j=0; j < channels; j++) { - *outbuffer++ = (guint8) buffer[j][i]; - } + guint8 *outbuffer = (guint8 *) GST_BUFFER_DATA (outbuf); + + for (i = 0; i < samples; i++) { + for (j = 0; j < channels; j++) { + *outbuffer++ = (guint8) buffer[j][i]; + } } - } - else if (depth == 16) { - guint16 *outbuffer = (guint16 *)GST_BUFFER_DATA (outbuf); - - for (i=0; i<samples; i++) { - for (j=0; j < channels; j++) { - *outbuffer++ = (guint16) buffer[j][i]; - } + } else if (depth == 16) { + guint16 *outbuffer = (guint16 *) GST_BUFFER_DATA (outbuf); + + for (i = 0; i < samples; i++) { + for (j = 0; j < channels; j++) { + *outbuffer++ = (guint16) buffer[j][i]; + } } - } - else { + } else { g_warning ("flacdec: invalid depth %d found\n", depth); return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; } @@ -521,8 +520,8 @@ gst_flacdec_write (const FLAC__SeekableStreamDecoder *decoder, return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; } -static void -gst_flacdec_loop (GstElement *element) +static void +gst_flacdec_loop (GstElement * element) { FlacDec *flacdec; gboolean res; @@ -530,30 +529,28 @@ gst_flacdec_loop (GstElement *element) flacdec = GST_FLACDEC (element); GST_DEBUG ("flacdec: entering loop"); - if (flacdec->init) { + if (flacdec->init) { FLAC__StreamDecoderState res; - GST_DEBUG ("flacdec: initializing decoder"); + + GST_DEBUG ("flacdec: initializing decoder"); res = FLAC__seekable_stream_decoder_init (flacdec->decoder); if (res != FLAC__SEEKABLE_STREAM_DECODER_OK) { GST_ELEMENT_ERROR (flacdec, LIBRARY, INIT, (NULL), - (FLAC__SeekableStreamDecoderStateString[res])); + (FLAC__SeekableStreamDecoderStateString[res])); return; } - /* FLAC__seekable_stream_decoder_process_metadata (flacdec->decoder);*/ + /* FLAC__seekable_stream_decoder_process_metadata (flacdec->decoder); */ flacdec->init = FALSE; } if (flacdec->seek_pending) { - GST_DEBUG ("perform seek to sample %" G_GINT64_FORMAT, - flacdec->seek_value); + GST_DEBUG ("perform seek to sample %" G_GINT64_FORMAT, flacdec->seek_value); - if (FLAC__seekable_stream_decoder_seek_absolute (flacdec->decoder, - flacdec->seek_value)) - { + if (FLAC__seekable_stream_decoder_seek_absolute (flacdec->decoder, + flacdec->seek_value)) { flacdec->total_samples = flacdec->seek_value; GST_DEBUG ("seek done"); - } - else { + } else { GST_DEBUG ("seek failed"); } flacdec->seek_pending = FALSE; @@ -562,13 +559,12 @@ gst_flacdec_loop (GstElement *element) GST_DEBUG ("flacdec: processing single"); res = FLAC__seekable_stream_decoder_process_single (flacdec->decoder); GST_DEBUG ("flacdec: checking for EOS"); - if (FLAC__seekable_stream_decoder_get_state (flacdec->decoder) == - FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM) - { + if (FLAC__seekable_stream_decoder_get_state (flacdec->decoder) == + FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM) { GstEvent *event; GST_DEBUG ("flacdec: sending EOS event"); - FLAC__seekable_stream_decoder_reset(flacdec->decoder); + FLAC__seekable_stream_decoder_reset (flacdec->decoder); if (GST_PAD_IS_USABLE (flacdec->srcpad)) { event = gst_event_new (GST_EVENT_EOS); @@ -581,8 +577,8 @@ gst_flacdec_loop (GstElement *element) static const GstFormat * -gst_flacdec_get_src_formats (GstPad *pad) -{ +gst_flacdec_get_src_formats (GstPad * pad) +{ static const GstFormat formats[] = { GST_FORMAT_DEFAULT, GST_FORMAT_BYTES, @@ -590,63 +586,63 @@ gst_flacdec_get_src_formats (GstPad *pad) 0, }; return formats; -} +} static gboolean -gst_flacdec_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value, - GstFormat *dest_format, gint64 *dest_value) +gst_flacdec_convert_src (GstPad * pad, GstFormat src_format, gint64 src_value, + GstFormat * dest_format, gint64 * dest_value) { gboolean res = TRUE; FlacDec *flacdec = GST_FLACDEC (gst_pad_get_parent (pad)); guint scale = 1; gint bytes_per_sample; - bytes_per_sample = flacdec->channels * ((flacdec->depth+7)>>3); + bytes_per_sample = flacdec->channels * ((flacdec->depth + 7) >> 3); switch (src_format) { case GST_FORMAT_BYTES: switch (*dest_format) { - case GST_FORMAT_DEFAULT: - if (bytes_per_sample == 0) - return FALSE; - *dest_value = src_value / bytes_per_sample; - break; - case GST_FORMAT_TIME: + case GST_FORMAT_DEFAULT: + if (bytes_per_sample == 0) + return FALSE; + *dest_value = src_value / bytes_per_sample; + break; + case GST_FORMAT_TIME: { - gint byterate = bytes_per_sample * flacdec->frequency; + gint byterate = bytes_per_sample * flacdec->frequency; - if (byterate == 0) - return FALSE; - *dest_value = src_value * GST_SECOND / byterate; - break; + if (byterate == 0) + return FALSE; + *dest_value = src_value * GST_SECOND / byterate; + break; } - default: - res = FALSE; + default: + res = FALSE; } break; case GST_FORMAT_DEFAULT: switch (*dest_format) { - case GST_FORMAT_BYTES: + case GST_FORMAT_BYTES: *dest_value = src_value * bytes_per_sample; - break; - case GST_FORMAT_TIME: + break; + case GST_FORMAT_TIME: if (flacdec->frequency == 0) return FALSE; - *dest_value = src_value * GST_SECOND / flacdec->frequency; - break; - default: - res = FALSE; + *dest_value = src_value * GST_SECOND / flacdec->frequency; + break; + default: + res = FALSE; } break; case GST_FORMAT_TIME: switch (*dest_format) { - case GST_FORMAT_BYTES: - scale = bytes_per_sample; - case GST_FORMAT_DEFAULT: + case GST_FORMAT_BYTES: + scale = bytes_per_sample; + case GST_FORMAT_DEFAULT: *dest_value = src_value * scale * flacdec->frequency / GST_SECOND; - break; - default: - res = FALSE; + break; + default: + res = FALSE; } break; default: @@ -656,19 +652,19 @@ gst_flacdec_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value, } static const GstQueryType * -gst_flacdec_get_src_query_types (GstPad *pad) -{ +gst_flacdec_get_src_query_types (GstPad * pad) +{ static const GstQueryType types[] = { GST_QUERY_TOTAL, GST_QUERY_POSITION, 0, }; return types; -} +} static gboolean -gst_flacdec_src_query (GstPad *pad, GstQueryType type, - GstFormat *format, gint64 *value) +gst_flacdec_src_query (GstPad * pad, GstQueryType type, + GstFormat * format, gint64 * value) { gboolean res = TRUE; FlacDec *flacdec = GST_FLACDEC (gst_pad_get_parent (pad)); @@ -679,21 +675,17 @@ gst_flacdec_src_query (GstPad *pad, GstQueryType type, guint64 samples; if (flacdec->stream_samples == 0) - samples = flacdec->total_samples; + samples = flacdec->total_samples; else - samples = flacdec->stream_samples; + samples = flacdec->stream_samples; - gst_pad_convert (flacdec->srcpad, - GST_FORMAT_DEFAULT, - samples, - format, value); + gst_pad_convert (flacdec->srcpad, + GST_FORMAT_DEFAULT, samples, format, value); break; } case GST_QUERY_POSITION: - gst_pad_convert (flacdec->srcpad, - GST_FORMAT_DEFAULT, - flacdec->total_samples, - format, value); + gst_pad_convert (flacdec->srcpad, + GST_FORMAT_DEFAULT, flacdec->total_samples, format, value); break; default: res = FALSE; @@ -702,20 +694,20 @@ gst_flacdec_src_query (GstPad *pad, GstQueryType type, return res; } - + static const GstEventMask * -gst_flacdec_get_src_event_masks (GstPad *pad) +gst_flacdec_get_src_event_masks (GstPad * pad) { static const GstEventMask masks[] = { - { GST_EVENT_SEEK, GST_SEEK_FLAG_ACCURATE }, - { 0, 0 }, + {GST_EVENT_SEEK, GST_SEEK_FLAG_ACCURATE}, + {0, 0}, }; return masks; } static gboolean -gst_flacdec_src_event (GstPad *pad, GstEvent *event) -{ +gst_flacdec_src_event (GstPad * pad, GstEvent * event) +{ gboolean res = TRUE; FlacDec *flacdec = GST_FLACDEC (gst_pad_get_parent (pad)); GstFormat format; @@ -724,11 +716,10 @@ gst_flacdec_src_event (GstPad *pad, GstEvent *event) case GST_EVENT_SEEK: format = GST_FORMAT_DEFAULT; - if (gst_pad_convert (flacdec->srcpad, - GST_EVENT_SEEK_FORMAT (event), - GST_EVENT_SEEK_OFFSET (event), - &format, &flacdec->seek_value)) - flacdec->seek_pending = TRUE; + if (gst_pad_convert (flacdec->srcpad, + GST_EVENT_SEEK_FORMAT (event), + GST_EVENT_SEEK_OFFSET (event), &format, &flacdec->seek_value)) + flacdec->seek_pending = TRUE; else res = FALSE; break; @@ -741,7 +732,7 @@ gst_flacdec_src_event (GstPad *pad, GstEvent *event) } static GstElementStateReturn -gst_flacdec_change_state (GstElement *element) +gst_flacdec_change_state (GstElement * element) { FlacDec *flacdec = GST_FLACDEC (element); diff --git a/ext/flac/gstflacdec.h b/ext/flac/gstflacdec.h index 5b5fd110..c525c3a2 100644 --- a/ext/flac/gstflacdec.h +++ b/ext/flac/gstflacdec.h @@ -28,8 +28,9 @@ #include <FLAC/all.h> #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define GST_TYPE_FLACDEC flacdec_get_type() @@ -38,40 +39,42 @@ extern "C" { #define GST_IS_FLACDEC(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, GST_TYPE_FLACDEC) #define GST_IS_FLACDEC_CLASS(obj) G_TYPE_CHECK_CLASS_TYPE(klass, GST_TYPE_FLACDEC) -typedef struct _FlacDec FlacDec; -typedef struct _FlacDecClass FlacDecClass; + typedef struct _FlacDec FlacDec; + typedef struct _FlacDecClass FlacDecClass; -struct _FlacDec { - GstElement element; + struct _FlacDec + { + GstElement element; - GstPad *sinkpad,*srcpad; - GstByteStream *bs; + GstPad *sinkpad, *srcpad; + GstByteStream *bs; - FLAC__SeekableStreamDecoder *decoder; - gint channels; - gint depth; - gint frequency; + FLAC__SeekableStreamDecoder *decoder; + gint channels; + gint depth; + gint frequency; - gboolean need_discont; - gboolean seek_pending; - gint64 seek_value; + gboolean need_discont; + gboolean seek_pending; + gint64 seek_value; - gboolean init; - guint64 total_samples; - guint64 stream_samples; + gboolean init; + guint64 total_samples; + guint64 stream_samples; - gboolean eos; -}; + gboolean eos; + }; -struct _FlacDecClass { - GstElementClass parent_class; -}; + struct _FlacDecClass + { + GstElementClass parent_class; + }; -GType flacdec_get_type(void); + GType flacdec_get_type (void); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __FLACDEC_H__ */ +#endif /* __FLACDEC_H__ */ diff --git a/ext/flac/gstflacenc.c b/ext/flac/gstflacenc.c index eacedeb4..7e658047 100644 --- a/ext/flac/gstflacenc.c +++ b/ext/flac/gstflacenc.c @@ -40,12 +40,14 @@ GstElementDetails flacenc_details = { }; /* FlacEnc signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_QUALITY, ARG_STREAMABLE_SUBSET, @@ -62,34 +64,32 @@ enum { ARG_RICE_PARAMETER_SEARCH_DIST, }; -static void gst_flacenc_base_init (gpointer g_class); -static void gst_flacenc_init (FlacEnc *flacenc); -static void gst_flacenc_class_init (FlacEncClass *klass); -static void gst_flacenc_dispose (GObject *object); +static void gst_flacenc_base_init (gpointer g_class); +static void gst_flacenc_init (FlacEnc * flacenc); +static void gst_flacenc_class_init (FlacEncClass * klass); +static void gst_flacenc_dispose (GObject * object); static GstPadLinkReturn - gst_flacenc_sinkconnect (GstPad *pad, const GstCaps *caps); -static void gst_flacenc_chain (GstPad *pad, GstData *_data); - -static gboolean gst_flacenc_update_quality (FlacEnc *flacenc, gint quality); -static void gst_flacenc_set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec); -static void gst_flacenc_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec); -static GstElementStateReturn - gst_flacenc_change_state (GstElement *element); - -static FLAC__StreamEncoderWriteStatus - gst_flacenc_write_callback (const FLAC__SeekableStreamEncoder *encoder, - const FLAC__byte buffer[], unsigned bytes, - unsigned samples, unsigned current_frame, - void *client_data); +gst_flacenc_sinkconnect (GstPad * pad, const GstCaps * caps); +static void gst_flacenc_chain (GstPad * pad, GstData * _data); + +static gboolean gst_flacenc_update_quality (FlacEnc * flacenc, gint quality); +static void gst_flacenc_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_flacenc_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); +static GstElementStateReturn gst_flacenc_change_state (GstElement * element); + +static FLAC__StreamEncoderWriteStatus +gst_flacenc_write_callback (const FLAC__SeekableStreamEncoder * encoder, + const FLAC__byte buffer[], unsigned bytes, + unsigned samples, unsigned current_frame, void *client_data); static FLAC__SeekableStreamEncoderSeekStatus - gst_flacenc_seek_callback (const FLAC__SeekableStreamEncoder *encoder, - FLAC__uint64 absolute_byte_offset, - void *client_data); +gst_flacenc_seek_callback (const FLAC__SeekableStreamEncoder * encoder, + FLAC__uint64 absolute_byte_offset, void *client_data); static GstElementClass *parent_class = NULL; + /*static guint gst_flacenc_signals[LAST_SIGNAL] = { 0 }; */ GType @@ -99,15 +99,15 @@ flacenc_get_type (void) if (!flacenc_type) { static const GTypeInfo flacenc_info = { - sizeof(FlacEncClass), + sizeof (FlacEncClass), gst_flacenc_base_init, NULL, - (GClassInitFunc)gst_flacenc_class_init, + (GClassInitFunc) gst_flacenc_class_init, NULL, NULL, - sizeof(FlacEnc), + sizeof (FlacEnc), 0, - (GInstanceInitFunc)gst_flacenc_init, + (GInstanceInitFunc) gst_flacenc_init, }; static const GInterfaceInfo tag_setter_info = { @@ -116,38 +116,40 @@ flacenc_get_type (void) NULL }; - flacenc_type = g_type_register_static (GST_TYPE_ELEMENT, "FlacEnc", &flacenc_info, 0); - g_type_add_interface_static (flacenc_type, GST_TYPE_TAG_SETTER, &tag_setter_info); + flacenc_type = + g_type_register_static (GST_TYPE_ELEMENT, "FlacEnc", &flacenc_info, 0); + g_type_add_interface_static (flacenc_type, GST_TYPE_TAG_SETTER, + &tag_setter_info); } return flacenc_type; } -typedef struct { - gboolean exhaustive_model_search; - gboolean escape_coding; - gboolean mid_side; - gboolean loose_mid_side; - guint qlp_coeff_precision; - gboolean qlp_coeff_prec_search; - guint min_residual_partition_order; - guint max_residual_partition_order; - guint rice_parameter_search_dist; - guint max_lpc_order; - guint blocksize; +typedef struct +{ + gboolean exhaustive_model_search; + gboolean escape_coding; + gboolean mid_side; + gboolean loose_mid_side; + guint qlp_coeff_precision; + gboolean qlp_coeff_prec_search; + guint min_residual_partition_order; + guint max_residual_partition_order; + guint rice_parameter_search_dist; + guint max_lpc_order; + guint blocksize; } FlacEncParams; -static const FlacEncParams flacenc_params[] = -{ - { FALSE, FALSE, FALSE, FALSE, 0, FALSE, 2, 2, 0, 0, 1152 }, - { FALSE, FALSE, TRUE, TRUE, 0, FALSE, 2, 2, 0, 0, 1152 }, - { FALSE, FALSE, TRUE, FALSE, 0, FALSE, 0, 3, 0, 0, 1152 }, - { FALSE, FALSE, FALSE, FALSE, 0, FALSE, 3, 3, 0, 6, 4608 }, - { FALSE, FALSE, TRUE, TRUE, 0, FALSE, 3, 3, 0, 8, 4608 }, - { FALSE, FALSE, TRUE, FALSE, 0, FALSE, 3, 3, 0, 8, 4608 }, - { FALSE, FALSE, TRUE, FALSE, 0, FALSE, 0, 4, 0, 8, 4608 }, - { TRUE, FALSE, TRUE, FALSE, 0, FALSE, 0, 6, 0, 8, 4608 }, - { TRUE, FALSE, TRUE, FALSE, 0, FALSE, 0, 6, 0, 12, 4608 }, - { TRUE, TRUE, TRUE, FALSE, 0, FALSE, 0, 16, 0, 32, 4608 }, +static const FlacEncParams flacenc_params[] = { + {FALSE, FALSE, FALSE, FALSE, 0, FALSE, 2, 2, 0, 0, 1152}, + {FALSE, FALSE, TRUE, TRUE, 0, FALSE, 2, 2, 0, 0, 1152}, + {FALSE, FALSE, TRUE, FALSE, 0, FALSE, 0, 3, 0, 0, 1152}, + {FALSE, FALSE, FALSE, FALSE, 0, FALSE, 3, 3, 0, 6, 4608}, + {FALSE, FALSE, TRUE, TRUE, 0, FALSE, 3, 3, 0, 8, 4608}, + {FALSE, FALSE, TRUE, FALSE, 0, FALSE, 3, 3, 0, 8, 4608}, + {FALSE, FALSE, TRUE, FALSE, 0, FALSE, 0, 4, 0, 8, 4608}, + {TRUE, FALSE, TRUE, FALSE, 0, FALSE, 0, 6, 0, 8, 4608}, + {TRUE, FALSE, TRUE, FALSE, 0, FALSE, 0, 6, 0, 12, 4608}, + {TRUE, TRUE, TRUE, FALSE, 0, FALSE, 0, 16, 0, 32, 4608}, }; #define DEFAULT_QUALITY 5 @@ -157,44 +159,44 @@ GType gst_flacenc_quality_get_type (void) { static GType qtype = 0; + if (qtype == 0) { static const GEnumValue values[] = { - { 0, "0", "0 - Fastest compression" }, - { 1, "1", "1" }, - { 2, "2", "2" }, - { 3, "3", "3" }, - { 4, "4", "4" }, - { 5, "5", "5 - Default" }, - { 6, "6", "6" }, - { 7, "7", "7" }, - { 8, "8", "8 - Highest compression " }, - { 9, "9", "9 - Insane" }, - { 0, NULL, NULL } + {0, "0", "0 - Fastest compression"}, + {1, "1", "1"}, + {2, "2", "2"}, + {3, "3", "3"}, + {4, "4", "4"}, + {5, "5", "5 - Default"}, + {6, "6", "6"}, + {7, "7", "7"}, + {8, "8", "8 - Highest compression "}, + {9, "9", "9 - Insane"}, + {0, NULL, NULL} }; qtype = g_enum_register_static ("FlacEncQuality", values); } return qtype; } -static GstCaps* +static GstCaps * flac_caps_factory (void) { return gst_caps_new_simple ("audio/x-flac", NULL); - /* "rate", GST_PROPS_INT_RANGE (11025, 48000), - * "channels", GST_PROPS_INT_RANGE (1, 2), */ + /* "rate", GST_PROPS_INT_RANGE (11025, 48000), + * "channels", GST_PROPS_INT_RANGE (1, 2), */ } -static GstCaps* +static GstCaps * raw_caps_factory (void) { return gst_caps_new_simple ("audio/x-raw-int", - "endianness", G_TYPE_INT, G_BYTE_ORDER, - "signed", G_TYPE_BOOLEAN, TRUE, - "width", G_TYPE_INT, 16, - "depth", G_TYPE_INT, 16, - "rate", GST_TYPE_INT_RANGE, 11025, 48000, - "channels", GST_TYPE_INT_RANGE, 1, 2, - NULL); + "endianness", G_TYPE_INT, G_BYTE_ORDER, + "signed", G_TYPE_BOOLEAN, TRUE, + "width", G_TYPE_INT, 16, + "depth", G_TYPE_INT, 16, + "rate", GST_TYPE_INT_RANGE, 11025, 48000, + "channels", GST_TYPE_INT_RANGE, 1, 2, NULL); } static void @@ -206,125 +208,123 @@ gst_flacenc_base_init (gpointer g_class) raw_caps = raw_caps_factory (); flac_caps = flac_caps_factory (); - sink_template = gst_pad_template_new ("sink", GST_PAD_SINK, - GST_PAD_ALWAYS, - raw_caps); - src_template = gst_pad_template_new ("src", GST_PAD_SRC, - GST_PAD_ALWAYS, - flac_caps); + sink_template = gst_pad_template_new ("sink", GST_PAD_SINK, + GST_PAD_ALWAYS, raw_caps); + src_template = gst_pad_template_new ("src", GST_PAD_SRC, + GST_PAD_ALWAYS, flac_caps); gst_element_class_add_pad_template (element_class, sink_template); gst_element_class_add_pad_template (element_class, src_template); gst_element_class_set_details (element_class, &flacenc_details); } static void -gst_flacenc_class_init (FlacEncClass *klass) +gst_flacenc_class_init (FlacEncClass * 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); - /* we have no properties atm so this is a bit silly */ gobject_class->set_property = gst_flacenc_set_property; gobject_class->get_property = gst_flacenc_get_property; - gobject_class->dispose = gst_flacenc_dispose; + gobject_class->dispose = gst_flacenc_dispose; g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QUALITY, - g_param_spec_enum ("quality", - "Quality", - "Speed versus compression tradeoff", - GST_TYPE_FLACENC_QUALITY, DEFAULT_QUALITY, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_STREAMABLE_SUBSET, - g_param_spec_boolean ("streamable_subset", - "Streamable subset", - "true to limit encoder to generating a Subset stream, else false", - TRUE, G_PARAM_READWRITE)); + g_param_spec_enum ("quality", + "Quality", + "Speed versus compression tradeoff", + GST_TYPE_FLACENC_QUALITY, DEFAULT_QUALITY, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), + ARG_STREAMABLE_SUBSET, g_param_spec_boolean ("streamable_subset", + "Streamable subset", + "true to limit encoder to generating a Subset stream, else false", + TRUE, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MID_SIDE_STEREO, - g_param_spec_boolean ("mid_side_stereo", - "Do mid side stereo", - "Do mid side stereo (only for stereo input)", - flacenc_params[DEFAULT_QUALITY].mid_side, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LOOSE_MID_SIDE_STEREO, - g_param_spec_boolean ("loose_mid_side_stereo", - "Loose mid side stereo", - "Loose mid side stereo", - flacenc_params[DEFAULT_QUALITY].loose_mid_side, G_PARAM_READWRITE)); + g_param_spec_boolean ("mid_side_stereo", "Do mid side stereo", + "Do mid side stereo (only for stereo input)", + flacenc_params[DEFAULT_QUALITY].mid_side, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), + ARG_LOOSE_MID_SIDE_STEREO, g_param_spec_boolean ("loose_mid_side_stereo", + "Loose mid side stereo", "Loose mid side stereo", + flacenc_params[DEFAULT_QUALITY].loose_mid_side, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BLOCKSIZE, - g_param_spec_uint ("blocksize", - "Blocksize", - "Blocksize in samples", - FLAC__MIN_BLOCK_SIZE, FLAC__MAX_BLOCK_SIZE, - flacenc_params[DEFAULT_QUALITY].blocksize, G_PARAM_READWRITE)); + g_param_spec_uint ("blocksize", "Blocksize", "Blocksize in samples", + FLAC__MIN_BLOCK_SIZE, FLAC__MAX_BLOCK_SIZE, + flacenc_params[DEFAULT_QUALITY].blocksize, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MAX_LPC_ORDER, - g_param_spec_uint ("max_lpc_order", - "Max LPC order", - "Max LPC order; 0 => use only fixed predictors", - 0, FLAC__MAX_LPC_ORDER, - flacenc_params[DEFAULT_QUALITY].max_lpc_order, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QLP_COEFF_PRECISION, - g_param_spec_uint ("qlp_coeff_precision", - "QLP coefficients precision", - "Precision in bits of quantized linear-predictor coefficients; 0 = automatic", - 0, 32, - flacenc_params[DEFAULT_QUALITY].qlp_coeff_precision, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QLP_COEFF_PREC_SEARCH, - g_param_spec_boolean ("qlp_coeff_prec_search", - "Do QLP coefficients precision search", - "false = use qlp_coeff_precision, " - "true = search around qlp_coeff_precision, take best", - flacenc_params[DEFAULT_QUALITY].qlp_coeff_prec_search, G_PARAM_READWRITE)); + g_param_spec_uint ("max_lpc_order", "Max LPC order", + "Max LPC order; 0 => use only fixed predictors", 0, + FLAC__MAX_LPC_ORDER, flacenc_params[DEFAULT_QUALITY].max_lpc_order, + G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), + ARG_QLP_COEFF_PRECISION, g_param_spec_uint ("qlp_coeff_precision", + "QLP coefficients precision", + "Precision in bits of quantized linear-predictor coefficients; 0 = automatic", + 0, 32, flacenc_params[DEFAULT_QUALITY].qlp_coeff_precision, + G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), + ARG_QLP_COEFF_PREC_SEARCH, g_param_spec_boolean ("qlp_coeff_prec_search", + "Do QLP coefficients precision search", + "false = use qlp_coeff_precision, " + "true = search around qlp_coeff_precision, take best", + flacenc_params[DEFAULT_QUALITY].qlp_coeff_prec_search, + G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ESCAPE_CODING, - g_param_spec_boolean ("escape_coding", - "Do Escape coding", - "search for escape codes in the entropy coding stage " - "for slightly better compression", - flacenc_params[DEFAULT_QUALITY].escape_coding, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_EXHAUSTIVE_MODEL_SEARCH, - g_param_spec_boolean ("exhaustive_model_search", - "Do exhaustive model search", - "do exhaustive search of LP coefficient quantization (expensive!)", - flacenc_params[DEFAULT_QUALITY].exhaustive_model_search, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MIN_RESIDUAL_PARTITION_ORDER, - g_param_spec_uint ("min_residual_partition_order", - "Min residual partition order", - "Min residual partition order (above 4 doesn't usually help much)", - 0, 16, - flacenc_params[DEFAULT_QUALITY].min_residual_partition_order, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MAX_RESIDUAL_PARTITION_ORDER, - g_param_spec_uint ("max_residual_partition_order", - "Max residual partition order", - "Max residual partition order (above 4 doesn't usually help much)", - 0, 16, - flacenc_params[DEFAULT_QUALITY].max_residual_partition_order, G_PARAM_READWRITE)); - g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_RICE_PARAMETER_SEARCH_DIST, - g_param_spec_uint ("rice_parameter_search_dist", - "rice_parameter_search_dist", - "0 = try only calc'd parameter k; else try all [k-dist..k+dist] " - "parameters, use best", - 0, FLAC__MAX_RICE_PARTITION_ORDER, - flacenc_params[DEFAULT_QUALITY].rice_parameter_search_dist, G_PARAM_READWRITE)); + g_param_spec_boolean ("escape_coding", "Do Escape coding", + "search for escape codes in the entropy coding stage " + "for slightly better compression", + flacenc_params[DEFAULT_QUALITY].escape_coding, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), + ARG_EXHAUSTIVE_MODEL_SEARCH, + g_param_spec_boolean ("exhaustive_model_search", + "Do exhaustive model search", + "do exhaustive search of LP coefficient quantization (expensive!)", + flacenc_params[DEFAULT_QUALITY].exhaustive_model_search, + G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), + ARG_MIN_RESIDUAL_PARTITION_ORDER, + g_param_spec_uint ("min_residual_partition_order", + "Min residual partition order", + "Min residual partition order (above 4 doesn't usually help much)", 0, + 16, flacenc_params[DEFAULT_QUALITY].min_residual_partition_order, + G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), + ARG_MAX_RESIDUAL_PARTITION_ORDER, + g_param_spec_uint ("max_residual_partition_order", + "Max residual partition order", + "Max residual partition order (above 4 doesn't usually help much)", 0, + 16, flacenc_params[DEFAULT_QUALITY].max_residual_partition_order, + G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), + ARG_RICE_PARAMETER_SEARCH_DIST, + g_param_spec_uint ("rice_parameter_search_dist", + "rice_parameter_search_dist", + "0 = try only calc'd parameter k; else try all [k-dist..k+dist] " + "parameters, use best", 0, FLAC__MAX_RICE_PARTITION_ORDER, + flacenc_params[DEFAULT_QUALITY].rice_parameter_search_dist, + G_PARAM_READWRITE)); gstelement_class->change_state = gst_flacenc_change_state; } static void -gst_flacenc_init (FlacEnc *flacenc) +gst_flacenc_init (FlacEnc * flacenc) { flacenc->sinkpad = gst_pad_new_from_template (sink_template, "sink"); - gst_element_add_pad(GST_ELEMENT(flacenc),flacenc->sinkpad); - gst_pad_set_chain_function(flacenc->sinkpad,gst_flacenc_chain); + gst_element_add_pad (GST_ELEMENT (flacenc), flacenc->sinkpad); + gst_pad_set_chain_function (flacenc->sinkpad, gst_flacenc_chain); gst_pad_set_link_function (flacenc->sinkpad, gst_flacenc_sinkconnect); flacenc->srcpad = gst_pad_new_from_template (src_template, "src"); - gst_element_add_pad(GST_ELEMENT(flacenc),flacenc->srcpad); + gst_element_add_pad (GST_ELEMENT (flacenc), flacenc->srcpad); GST_FLAG_SET (flacenc, GST_ELEMENT_EVENT_AWARE); - flacenc->encoder = FLAC__seekable_stream_encoder_new(); + flacenc->encoder = FLAC__seekable_stream_encoder_new (); flacenc->negotiated = FALSE; flacenc->first = TRUE; @@ -335,17 +335,17 @@ gst_flacenc_init (FlacEnc *flacenc) } static void -gst_flacenc_dispose (GObject *object) +gst_flacenc_dispose (GObject * object) { FlacEnc *flacenc = GST_FLACENC (object); FLAC__seekable_stream_encoder_delete (flacenc->encoder); - + G_OBJECT_CLASS (parent_class)->dispose (object); } static GstPadLinkReturn -gst_flacenc_sinkconnect (GstPad *pad, const GstCaps *caps) +gst_flacenc_sinkconnect (GstPad * pad, const GstCaps * caps) { GstPadLinkReturn ret; FlacEnc *flacenc; @@ -358,7 +358,7 @@ gst_flacenc_sinkconnect (GstPad *pad, const GstCaps *caps) gst_structure_get_int (structure, "channels", &flacenc->channels); gst_structure_get_int (structure, "depth", &flacenc->depth); gst_structure_get_int (structure, "rate", &flacenc->sample_rate); - + caps = gst_caps_new_simple ("audio/x-flac", "channels", G_TYPE_INT, flacenc->channels, "rate", G_TYPE_INT, flacenc->sample_rate, NULL); @@ -367,12 +367,12 @@ gst_flacenc_sinkconnect (GstPad *pad, const GstCaps *caps) return ret; } - FLAC__seekable_stream_encoder_set_bits_per_sample (flacenc->encoder, - flacenc->depth); - FLAC__seekable_stream_encoder_set_sample_rate (flacenc->encoder, - flacenc->sample_rate); - FLAC__seekable_stream_encoder_set_channels (flacenc->encoder, - flacenc->channels); + FLAC__seekable_stream_encoder_set_bits_per_sample (flacenc->encoder, + flacenc->depth); + FLAC__seekable_stream_encoder_set_sample_rate (flacenc->encoder, + flacenc->sample_rate); + FLAC__seekable_stream_encoder_set_channels (flacenc->encoder, + flacenc->channels); flacenc->negotiated = TRUE; @@ -380,7 +380,7 @@ gst_flacenc_sinkconnect (GstPad *pad, const GstCaps *caps) } static gboolean -gst_flacenc_update_quality (FlacEnc *flacenc, gint quality) +gst_flacenc_update_quality (FlacEnc * flacenc, gint quality) { flacenc->quality = quality; @@ -396,17 +396,22 @@ gst_flacenc_update_quality (FlacEnc *flacenc, gint quality) g_object_freeze_notify (G_OBJECT (flacenc)); - DO_UPDATE (do_mid_side_stereo, mid_side, "mid_side_stereo"); - DO_UPDATE (loose_mid_side_stereo, loose_mid_side, "loose_mid_side"); - DO_UPDATE (blocksize, blocksize, "blocksize"); - DO_UPDATE (max_lpc_order, max_lpc_order, "max_lpc_order"); - DO_UPDATE (qlp_coeff_precision, qlp_coeff_precision, "qlp_coeff_precision"); - DO_UPDATE (do_qlp_coeff_prec_search, qlp_coeff_prec_search, "qlp_coeff_prec_search"); - DO_UPDATE (do_escape_coding, escape_coding, "escape_coding"); - DO_UPDATE (do_exhaustive_model_search, exhaustive_model_search, "exhaustive_model_search"); - DO_UPDATE (min_residual_partition_order, min_residual_partition_order, "min_residual_partition_order"); - DO_UPDATE (max_residual_partition_order, max_residual_partition_order, "max_residual_partition_order"); - DO_UPDATE (rice_parameter_search_dist, rice_parameter_search_dist, "rice_parameter_search_dist"); + DO_UPDATE (do_mid_side_stereo, mid_side, "mid_side_stereo"); + DO_UPDATE (loose_mid_side_stereo, loose_mid_side, "loose_mid_side"); + DO_UPDATE (blocksize, blocksize, "blocksize"); + DO_UPDATE (max_lpc_order, max_lpc_order, "max_lpc_order"); + DO_UPDATE (qlp_coeff_precision, qlp_coeff_precision, "qlp_coeff_precision"); + DO_UPDATE (do_qlp_coeff_prec_search, qlp_coeff_prec_search, + "qlp_coeff_prec_search"); + DO_UPDATE (do_escape_coding, escape_coding, "escape_coding"); + DO_UPDATE (do_exhaustive_model_search, exhaustive_model_search, + "exhaustive_model_search"); + DO_UPDATE (min_residual_partition_order, min_residual_partition_order, + "min_residual_partition_order"); + DO_UPDATE (max_residual_partition_order, max_residual_partition_order, + "max_residual_partition_order"); + DO_UPDATE (rice_parameter_search_dist, rice_parameter_search_dist, + "rice_parameter_search_dist"); #undef DO_UPDATE @@ -416,38 +421,38 @@ gst_flacenc_update_quality (FlacEnc *flacenc, gint quality) } static FLAC__SeekableStreamEncoderSeekStatus -gst_flacenc_seek_callback (const FLAC__SeekableStreamEncoder *encoder, - FLAC__uint64 absolute_byte_offset, - void *client_data) +gst_flacenc_seek_callback (const FLAC__SeekableStreamEncoder * encoder, + FLAC__uint64 absolute_byte_offset, void *client_data) { -FlacEnc *flacenc; -GstEvent *event; + FlacEnc *flacenc; + GstEvent *event; flacenc = GST_FLACENC (client_data); - if (flacenc->stopped) + if (flacenc->stopped) return FLAC__STREAM_ENCODER_OK; - event = gst_event_new_seek ((GstSeekType)(int)(GST_FORMAT_BYTES | GST_SEEK_METHOD_SET), absolute_byte_offset); + event = + gst_event_new_seek ((GstSeekType) (int) (GST_FORMAT_BYTES | + GST_SEEK_METHOD_SET), absolute_byte_offset); if (event) gst_pad_push (flacenc->srcpad, GST_DATA (event)); - - return FLAC__STREAM_ENCODER_OK; + + return FLAC__STREAM_ENCODER_OK; } -static FLAC__StreamEncoderWriteStatus -gst_flacenc_write_callback (const FLAC__SeekableStreamEncoder *encoder, - const FLAC__byte buffer[], unsigned bytes, - unsigned samples, unsigned current_frame, - void *client_data) +static FLAC__StreamEncoderWriteStatus +gst_flacenc_write_callback (const FLAC__SeekableStreamEncoder * encoder, + const FLAC__byte buffer[], unsigned bytes, + unsigned samples, unsigned current_frame, void *client_data) { FlacEnc *flacenc; GstBuffer *outbuf; - + flacenc = GST_FLACENC (client_data); - if (flacenc->stopped) + if (flacenc->stopped) return FLAC__STREAM_ENCODER_OK; outbuf = gst_buffer_new_and_alloc (bytes); @@ -465,30 +470,29 @@ gst_flacenc_write_callback (const FLAC__SeekableStreamEncoder *encoder, return FLAC__STREAM_ENCODER_OK; } -static void -add_one_tag (const GstTagList *list, const gchar *tag, - gpointer user_data) +static void +add_one_tag (const GstTagList * list, const gchar * tag, gpointer user_data) { - GList *comments; - GList *it; - FlacEnc *flacenc = GST_FLACENC (user_data); - - comments = gst_tag_to_vorbis_comments (list, tag); - for (it = comments; it != NULL; it = it->next) { - FLAC__StreamMetadata_VorbisComment_Entry commment_entry; - commment_entry.length = strlen(it->data); - commment_entry.entry = it->data; - FLAC__metadata_object_vorbiscomment_insert_comment (flacenc->meta[0], - flacenc->meta[0]->data.vorbis_comment.num_comments, - commment_entry, - TRUE); - g_free (it->data); - } - g_list_free (comments); + GList *comments; + GList *it; + FlacEnc *flacenc = GST_FLACENC (user_data); + + comments = gst_tag_to_vorbis_comments (list, tag); + for (it = comments; it != NULL; it = it->next) { + FLAC__StreamMetadata_VorbisComment_Entry commment_entry; + + commment_entry.length = strlen (it->data); + commment_entry.entry = it->data; + FLAC__metadata_object_vorbiscomment_insert_comment (flacenc->meta[0], + flacenc->meta[0]->data.vorbis_comment.num_comments, + commment_entry, TRUE); + g_free (it->data); + } + g_list_free (comments); } static void -gst_flacenc_set_metadata (FlacEnc *flacenc) +gst_flacenc_set_metadata (FlacEnc * flacenc) { const GstTagList *user_tags; GstTagList *copy; @@ -498,21 +502,23 @@ gst_flacenc_set_metadata (FlacEnc *flacenc) if ((flacenc->tags == NULL) && (user_tags == NULL)) { return; } - copy = gst_tag_list_merge (user_tags, flacenc->tags, - gst_tag_setter_get_merge_mode (GST_TAG_SETTER (flacenc))); + copy = gst_tag_list_merge (user_tags, flacenc->tags, + gst_tag_setter_get_merge_mode (GST_TAG_SETTER (flacenc))); flacenc->meta = g_malloc (sizeof (FLAC__StreamMetadata **)); - flacenc->meta[0] = FLAC__metadata_object_new (FLAC__METADATA_TYPE_VORBIS_COMMENT); + flacenc->meta[0] = + FLAC__metadata_object_new (FLAC__METADATA_TYPE_VORBIS_COMMENT); gst_tag_list_foreach (copy, add_one_tag, flacenc); - if (FLAC__seekable_stream_encoder_set_metadata(flacenc->encoder, flacenc->meta, 1) != true) + if (FLAC__seekable_stream_encoder_set_metadata (flacenc->encoder, + flacenc->meta, 1) != true) g_warning ("Dude, i'm already initialized!"); gst_tag_list_free (copy); } static void -gst_flacenc_chain (GstPad *pad, GstData *_data) +gst_flacenc_chain (GstPad * pad, GstData * _data) { GstBuffer *buf = GST_BUFFER (_data); FlacEnc *flacenc; @@ -522,7 +528,7 @@ gst_flacenc_chain (GstPad *pad, GstData *_data) gulong i; FLAC__bool res; - g_return_if_fail(buf != NULL); + g_return_if_fail (buf != NULL); flacenc = GST_FLACENC (gst_pad_get_parent (pad)); @@ -531,18 +537,18 @@ gst_flacenc_chain (GstPad *pad, GstData *_data) switch (GST_EVENT_TYPE (event)) { case GST_EVENT_EOS: - FLAC__seekable_stream_encoder_finish(flacenc->encoder); + FLAC__seekable_stream_encoder_finish (flacenc->encoder); break; case GST_EVENT_TAG: if (flacenc->tags) { - gst_tag_list_insert (flacenc->tags, gst_event_tag_get_list (event), - GST_TAG_MERGE_REPLACE); + gst_tag_list_insert (flacenc->tags, gst_event_tag_get_list (event), + GST_TAG_MERGE_REPLACE); } else { g_assert_not_reached (); } break; default: - break; + break; } gst_pad_event_default (pad, event); return; @@ -550,33 +556,31 @@ gst_flacenc_chain (GstPad *pad, GstData *_data) if (!flacenc->negotiated) { GST_ELEMENT_ERROR (flacenc, CORE, NEGOTIATION, (NULL), - ("format wasn't negotiated before chain function")); + ("format wasn't negotiated before chain function")); return; } depth = flacenc->depth; insize = GST_BUFFER_SIZE (buf); - samples = insize / ((depth+7)>>3); + samples = insize / ((depth + 7) >> 3); - if (FLAC__seekable_stream_encoder_get_state (flacenc->encoder) == - FLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) - { + if (FLAC__seekable_stream_encoder_get_state (flacenc->encoder) == + FLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED) { FLAC__SeekableStreamEncoderState state; - FLAC__seekable_stream_encoder_set_write_callback (flacenc->encoder, - gst_flacenc_write_callback); - FLAC__seekable_stream_encoder_set_seek_callback (flacenc->encoder, - gst_flacenc_seek_callback); - - FLAC__seekable_stream_encoder_set_client_data (flacenc->encoder, - flacenc); - + FLAC__seekable_stream_encoder_set_write_callback (flacenc->encoder, + gst_flacenc_write_callback); + FLAC__seekable_stream_encoder_set_seek_callback (flacenc->encoder, + gst_flacenc_seek_callback); + + FLAC__seekable_stream_encoder_set_client_data (flacenc->encoder, flacenc); + gst_flacenc_set_metadata (flacenc); state = FLAC__seekable_stream_encoder_init (flacenc->encoder); if (state != FLAC__STREAM_ENCODER_OK) { GST_ELEMENT_ERROR (flacenc, LIBRARY, INIT, (NULL), - ("could not initialize encoder (wrong parameters?)")); + ("could not initialize encoder (wrong parameters?)")); return; } } @@ -584,27 +588,26 @@ gst_flacenc_chain (GstPad *pad, GstData *_data) /* we keep a pointer in the flacenc struct because we are freeing the data * after a push opreration that might never return */ data = flacenc->data = g_malloc (samples * sizeof (FLAC__int32)); - + if (depth == 8) { gint8 *indata = (gint8 *) GST_BUFFER_DATA (buf); - - for (i=0; i<samples; i++) { - data[i] = (FLAC__int32) *indata++; + + for (i = 0; i < samples; i++) { + data[i] = (FLAC__int32) * indata++; } - } - else if (depth == 16) { + } else if (depth == 16) { gint16 *indata = (gint16 *) GST_BUFFER_DATA (buf); - for (i=0; i<samples; i++) { - data[i] = (FLAC__int32) *indata++; + for (i = 0; i < samples; i++) { + data[i] = (FLAC__int32) * indata++; } } - gst_buffer_unref(buf); + gst_buffer_unref (buf); - res = FLAC__seekable_stream_encoder_process_interleaved (flacenc->encoder, - (const FLAC__int32 *) data, samples / flacenc->channels); + res = FLAC__seekable_stream_encoder_process_interleaved (flacenc->encoder, + (const FLAC__int32 *) data, samples / flacenc->channels); g_free (flacenc->data); flacenc->data = NULL; @@ -615,63 +618,63 @@ gst_flacenc_chain (GstPad *pad, GstData *_data) } static void -gst_flacenc_set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec) +gst_flacenc_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) { FlacEnc *this; - - this = (FlacEnc *)object; + + this = (FlacEnc *) object; switch (prop_id) { case ARG_QUALITY: gst_flacenc_update_quality (this, g_value_get_enum (value)); break; case ARG_STREAMABLE_SUBSET: - FLAC__seekable_stream_encoder_set_streamable_subset (this->encoder, - g_value_get_boolean (value)); + FLAC__seekable_stream_encoder_set_streamable_subset (this->encoder, + g_value_get_boolean (value)); break; case ARG_MID_SIDE_STEREO: - FLAC__seekable_stream_encoder_set_do_mid_side_stereo (this->encoder, - g_value_get_boolean (value)); + FLAC__seekable_stream_encoder_set_do_mid_side_stereo (this->encoder, + g_value_get_boolean (value)); break; case ARG_LOOSE_MID_SIDE_STEREO: - FLAC__seekable_stream_encoder_set_loose_mid_side_stereo (this->encoder, - g_value_get_boolean (value)); + FLAC__seekable_stream_encoder_set_loose_mid_side_stereo (this->encoder, + g_value_get_boolean (value)); break; case ARG_BLOCKSIZE: - FLAC__seekable_stream_encoder_set_blocksize (this->encoder, - g_value_get_uint (value)); + FLAC__seekable_stream_encoder_set_blocksize (this->encoder, + g_value_get_uint (value)); break; case ARG_MAX_LPC_ORDER: - FLAC__seekable_stream_encoder_set_max_lpc_order (this->encoder, - g_value_get_uint (value)); + FLAC__seekable_stream_encoder_set_max_lpc_order (this->encoder, + g_value_get_uint (value)); break; case ARG_QLP_COEFF_PRECISION: - FLAC__seekable_stream_encoder_set_qlp_coeff_precision (this->encoder, - g_value_get_uint (value)); + FLAC__seekable_stream_encoder_set_qlp_coeff_precision (this->encoder, + g_value_get_uint (value)); break; case ARG_QLP_COEFF_PREC_SEARCH: - FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search (this->encoder, - g_value_get_boolean (value)); + FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search (this->encoder, + g_value_get_boolean (value)); break; case ARG_ESCAPE_CODING: - FLAC__seekable_stream_encoder_set_do_escape_coding (this->encoder, - g_value_get_boolean (value)); + FLAC__seekable_stream_encoder_set_do_escape_coding (this->encoder, + g_value_get_boolean (value)); break; case ARG_EXHAUSTIVE_MODEL_SEARCH: - FLAC__seekable_stream_encoder_set_do_exhaustive_model_search (this->encoder, - g_value_get_boolean (value)); + FLAC__seekable_stream_encoder_set_do_exhaustive_model_search (this-> + encoder, g_value_get_boolean (value)); break; case ARG_MIN_RESIDUAL_PARTITION_ORDER: - FLAC__seekable_stream_encoder_set_min_residual_partition_order (this->encoder, - g_value_get_uint (value)); + FLAC__seekable_stream_encoder_set_min_residual_partition_order (this-> + encoder, g_value_get_uint (value)); break; case ARG_MAX_RESIDUAL_PARTITION_ORDER: - FLAC__seekable_stream_encoder_set_max_residual_partition_order (this->encoder, - g_value_get_uint (value)); + FLAC__seekable_stream_encoder_set_max_residual_partition_order (this-> + encoder, g_value_get_uint (value)); break; case ARG_RICE_PARAMETER_SEARCH_DIST: - FLAC__seekable_stream_encoder_set_rice_parameter_search_dist (this->encoder, - g_value_get_uint (value)); + FLAC__seekable_stream_encoder_set_rice_parameter_search_dist (this-> + encoder, g_value_get_uint (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -680,64 +683,71 @@ gst_flacenc_set_property (GObject *object, guint prop_id, } static void -gst_flacenc_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) +gst_flacenc_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) { FlacEnc *this; - - this = (FlacEnc *)object; - + + this = (FlacEnc *) object; + switch (prop_id) { case ARG_QUALITY: g_value_set_enum (value, this->quality); break; case ARG_STREAMABLE_SUBSET: - g_value_set_boolean (value, - FLAC__seekable_stream_encoder_get_streamable_subset (this->encoder)); + g_value_set_boolean (value, + FLAC__seekable_stream_encoder_get_streamable_subset (this->encoder)); break; case ARG_MID_SIDE_STEREO: - g_value_set_boolean (value, - FLAC__seekable_stream_encoder_get_do_mid_side_stereo (this->encoder)); + g_value_set_boolean (value, + FLAC__seekable_stream_encoder_get_do_mid_side_stereo (this->encoder)); break; case ARG_LOOSE_MID_SIDE_STEREO: - g_value_set_boolean (value, - FLAC__seekable_stream_encoder_get_loose_mid_side_stereo (this->encoder)); + g_value_set_boolean (value, + FLAC__seekable_stream_encoder_get_loose_mid_side_stereo (this-> + encoder)); break; case ARG_BLOCKSIZE: - g_value_set_uint (value, - FLAC__seekable_stream_encoder_get_blocksize (this->encoder)); + g_value_set_uint (value, + FLAC__seekable_stream_encoder_get_blocksize (this->encoder)); break; case ARG_MAX_LPC_ORDER: - g_value_set_uint (value, - FLAC__seekable_stream_encoder_get_max_lpc_order (this->encoder)); + g_value_set_uint (value, + FLAC__seekable_stream_encoder_get_max_lpc_order (this->encoder)); break; case ARG_QLP_COEFF_PRECISION: - g_value_set_uint (value, - FLAC__seekable_stream_encoder_get_qlp_coeff_precision (this->encoder)); + g_value_set_uint (value, + FLAC__seekable_stream_encoder_get_qlp_coeff_precision (this-> + encoder)); break; case ARG_QLP_COEFF_PREC_SEARCH: - g_value_set_boolean (value, - FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search (this->encoder)); + g_value_set_boolean (value, + FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search (this-> + encoder)); break; case ARG_ESCAPE_CODING: - g_value_set_boolean (value, - FLAC__seekable_stream_encoder_get_do_escape_coding (this->encoder)); + g_value_set_boolean (value, + FLAC__seekable_stream_encoder_get_do_escape_coding (this->encoder)); break; case ARG_EXHAUSTIVE_MODEL_SEARCH: - g_value_set_boolean (value, - FLAC__seekable_stream_encoder_get_do_exhaustive_model_search (this->encoder)); + g_value_set_boolean (value, + FLAC__seekable_stream_encoder_get_do_exhaustive_model_search (this-> + encoder)); break; case ARG_MIN_RESIDUAL_PARTITION_ORDER: - g_value_set_uint (value, - FLAC__seekable_stream_encoder_get_min_residual_partition_order (this->encoder)); + g_value_set_uint (value, + FLAC__seekable_stream_encoder_get_min_residual_partition_order (this-> + encoder)); break; case ARG_MAX_RESIDUAL_PARTITION_ORDER: - g_value_set_uint (value, - FLAC__seekable_stream_encoder_get_max_residual_partition_order (this->encoder)); + g_value_set_uint (value, + FLAC__seekable_stream_encoder_get_max_residual_partition_order (this-> + encoder)); break; case ARG_RICE_PARAMETER_SEARCH_DIST: - g_value_set_uint (value, - FLAC__seekable_stream_encoder_get_rice_parameter_search_dist (this->encoder)); + g_value_set_uint (value, + FLAC__seekable_stream_encoder_get_rice_parameter_search_dist (this-> + encoder)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -746,7 +756,7 @@ gst_flacenc_get_property (GObject *object, guint prop_id, } static GstElementStateReturn -gst_flacenc_change_state (GstElement *element) +gst_flacenc_change_state (GstElement * element) { FlacEnc *flacenc = GST_FLACENC (element); @@ -760,10 +770,10 @@ gst_flacenc_change_state (GstElement *element) case GST_STATE_PLAYING_TO_PAUSED: break; case GST_STATE_PAUSED_TO_READY: - if (FLAC__seekable_stream_encoder_get_state (flacenc->encoder) != - FLAC__STREAM_ENCODER_UNINITIALIZED) { - flacenc->stopped = TRUE; - FLAC__seekable_stream_encoder_finish (flacenc->encoder); + if (FLAC__seekable_stream_encoder_get_state (flacenc->encoder) != + FLAC__STREAM_ENCODER_UNINITIALIZED) { + flacenc->stopped = TRUE; + FLAC__seekable_stream_encoder_finish (flacenc->encoder); } flacenc->negotiated = FALSE; if (flacenc->first_buf) diff --git a/ext/flac/gstflacenc.h b/ext/flac/gstflacenc.h index 27dbb3b0..1337a6fe 100644 --- a/ext/flac/gstflacenc.h +++ b/ext/flac/gstflacenc.h @@ -27,8 +27,9 @@ #include <FLAC/all.h> #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define GST_TYPE_FLACENC flacenc_get_type() #define GST_FLACENC(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, GST_TYPE_FLACENC, FlacEnc) @@ -36,40 +37,42 @@ extern "C" { #define GST_IS_FLACENC(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, GST_TYPE_FLACENC) #define GST_IS_FLACENC_CLASS(obj) G_TYPE_CHECK_CLASS_TYPE(klass, GST_TYPE_FLACENC) -typedef struct _FlacEnc FlacEnc; -typedef struct _FlacEncClass FlacEncClass; + typedef struct _FlacEnc FlacEnc; + typedef struct _FlacEncClass FlacEncClass; -struct _FlacEnc { - GstElement element; + struct _FlacEnc + { + GstElement element; - GstPad *sinkpad,*srcpad; + GstPad *sinkpad, *srcpad; - gboolean first; - GstBuffer *first_buf; - gboolean eos; - gint channels; - gint depth; - gint sample_rate; - gboolean negotiated; - gint quality; - gboolean stopped; - FLAC__int32 *data; + gboolean first; + GstBuffer *first_buf; + gboolean eos; + gint channels; + gint depth; + gint sample_rate; + gboolean negotiated; + gint quality; + gboolean stopped; + FLAC__int32 *data; - FLAC__SeekableStreamEncoder *encoder; - FLAC__StreamMetadata **meta; + FLAC__SeekableStreamEncoder *encoder; + FLAC__StreamMetadata **meta; - GstTagList * tags; -}; + GstTagList *tags; + }; -struct _FlacEncClass { - GstElementClass parent_class; -}; + struct _FlacEncClass + { + GstElementClass parent_class; + }; -GType flacenc_get_type(void); + GType flacenc_get_type (void); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __FLACENC_H__ */ +#endif /* __FLACENC_H__ */ diff --git a/ext/flac/gstflactag.c b/ext/flac/gstflactag.c index 5d1c56c2..c931f41c 100644 --- a/ext/flac/gstflactag.c +++ b/ext/flac/gstflactag.c @@ -36,17 +36,19 @@ typedef struct _GstFlacTag GstFlacTag; typedef struct _GstFlacTagClass GstFlacTagClass; -static inline -gint min (gint a, gint b) { +static inline gint +min (gint a, gint b) +{ if (a < b) { return a; } else { return b; } } - -typedef enum { + +typedef enum +{ GST_FLAC_TAG_STATE_INIT, GST_FLAC_TAG_STATE_METADATA_BLOCKS, GST_FLAC_TAG_STATE_METADATA_NEXT_BLOCK, @@ -57,77 +59,78 @@ typedef enum { } GstFlacTagState; -struct _GstFlacTag { - GstElement element; +struct _GstFlacTag +{ + GstElement element; /* pads */ - GstPad * sinkpad; - GstPad * srcpad; + GstPad *sinkpad; + GstPad *srcpad; - GstFlacTagState state; + GstFlacTagState state; - GstBuffer * buffer; - GstBuffer * vorbiscomment; - GstTagList * tags; + GstBuffer *buffer; + GstBuffer *vorbiscomment; + GstTagList *tags; - guint metadata_bytes_remaining; - gboolean metadata_last_block; + guint metadata_bytes_remaining; + gboolean metadata_last_block; - gboolean only_output_tags; + gboolean only_output_tags; }; -struct _GstFlacTagClass { +struct _GstFlacTagClass +{ GstElementClass parent_class; }; /* elementfactory information */ -static GstElementDetails gst_flac_tag_details = GST_ELEMENT_DETAILS ( - "flac rettager", - "Tag", - "Rewrite tags in a FLAC file", - "Christope Fergeau <teuf@gnome.org>" -); +static GstElementDetails gst_flac_tag_details = +GST_ELEMENT_DETAILS ("flac rettager", + "Tag", + "Rewrite tags in a FLAC file", + "Christope Fergeau <teuf@gnome.org>"); /* signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, /* FILL ME */ }; static GstStaticPadTemplate flac_tag_src_template = -GST_STATIC_PAD_TEMPLATE ( - "src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/x-flac; application/x-gst-tags") -); + GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-flac; application/x-gst-tags") + ); static GstStaticPadTemplate flac_tag_sink_template = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/x-flac") -); +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-flac") + ); -static void gst_flac_tag_base_init (gpointer g_class); -static void gst_flac_tag_class_init (GstFlacTagClass * klass); -static void gst_flac_tag_init (GstFlacTag * tag); +static void gst_flac_tag_base_init (gpointer g_class); +static void gst_flac_tag_class_init (GstFlacTagClass * klass); +static void gst_flac_tag_init (GstFlacTag * tag); -static void gst_flac_tag_chain (GstPad * pad, - GstData * data); +static void gst_flac_tag_chain (GstPad * pad, GstData * data); -static GstElementStateReturn gst_flac_tag_change_state (GstElement * element); +static GstElementStateReturn gst_flac_tag_change_state (GstElement * element); static GstElementClass *parent_class = NULL; + /* static guint gst_flac_tag_signals[LAST_SIGNAL] = { 0 }; */ GType @@ -152,11 +155,14 @@ gst_flac_tag_get_type (void) NULL, NULL }; - - flac_tag_type = g_type_register_static(GST_TYPE_ELEMENT, "GstFlacTag", &flac_tag_info, 0); - g_type_add_interface_static (flac_tag_type, GST_TYPE_TAG_SETTER, &tag_setter_info); - + flac_tag_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstFlacTag", &flac_tag_info, + 0); + + g_type_add_interface_static (flac_tag_type, GST_TYPE_TAG_SETTER, + &tag_setter_info); + } return flac_tag_type; } @@ -170,29 +176,29 @@ gst_flac_tag_base_init (gpointer g_class) gst_element_class_set_details (element_class, &gst_flac_tag_details); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&flac_tag_sink_template)); + gst_static_pad_template_get (&flac_tag_sink_template)); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&flac_tag_src_template)); + gst_static_pad_template_get (&flac_tag_src_template)); } -static void -send_eos (GstFlacTag *tag) +static void +send_eos (GstFlacTag * tag) { gst_element_set_eos (GST_ELEMENT (tag)); gst_pad_push (tag->srcpad, GST_DATA (gst_event_new (GST_EVENT_EOS))); /* Seek to end of sink stream */ if (gst_pad_send_event (GST_PAD_PEER (tag->sinkpad), - gst_event_new_seek (GST_FORMAT_BYTES | GST_SEEK_METHOD_END | - GST_SEEK_FLAG_FLUSH, 0))) { + gst_event_new_seek (GST_FORMAT_BYTES | GST_SEEK_METHOD_END | + GST_SEEK_FLAG_FLUSH, 0))) { } else { g_warning ("Couldn't seek to eos on sinkpad\n"); } } -static gboolean -caps_nego (GstFlacTag *tag) +static gboolean +caps_nego (GstFlacTag * tag) { /* do caps nego */ GstCaps *caps; @@ -202,8 +208,8 @@ caps_nego (GstFlacTag *tag) tag->only_output_tags = FALSE; GST_LOG_OBJECT (tag, "normal operation, using audio/x-flac output"); } else { - if (gst_pad_try_set_caps (tag->srcpad, gst_caps_new_simple ( - "application/x-gst-tags", NULL)) + if (gst_pad_try_set_caps (tag->srcpad, + gst_caps_new_simple ("application/x-gst-tags", NULL)) != GST_PAD_LINK_REFUSED) { tag->only_output_tags = TRUE; GST_LOG_OBJECT (tag, "fast operation, just outputting tags"); @@ -211,36 +217,39 @@ caps_nego (GstFlacTag *tag) } else { return FALSE; } - } + } return TRUE; } static void -gst_flac_tag_class_init (GstFlacTagClass *klass) +gst_flac_tag_class_init (GstFlacTagClass * klass) { GstElementClass *gstelement_class; GObjectClass *gobject_class; - - gstelement_class = (GstElementClass*) klass; - gobject_class = (GObjectClass*) klass; - parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + gstelement_class = (GstElementClass *) klass; + gobject_class = (GObjectClass *) klass; + + parent_class = g_type_class_ref (GST_TYPE_ELEMENT); gstelement_class->change_state = gst_flac_tag_change_state; } static void -gst_flac_tag_init (GstFlacTag *tag) +gst_flac_tag_init (GstFlacTag * tag) { /* create the sink and src pads */ - tag->sinkpad = gst_pad_new_from_template( - gst_static_pad_template_get (&flac_tag_sink_template), "sink"); + tag->sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&flac_tag_sink_template), "sink"); gst_element_add_pad (GST_ELEMENT (tag), tag->sinkpad); - gst_pad_set_chain_function (tag->sinkpad, GST_DEBUG_FUNCPTR (gst_flac_tag_chain)); + gst_pad_set_chain_function (tag->sinkpad, + GST_DEBUG_FUNCPTR (gst_flac_tag_chain)); - tag->srcpad = gst_pad_new_from_template( - gst_static_pad_template_get (&flac_tag_src_template), "src"); + tag->srcpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&flac_tag_src_template), "src"); gst_element_add_pad (GST_ELEMENT (tag), tag->srcpad); tag->buffer = NULL; @@ -250,11 +259,11 @@ gst_flac_tag_init (GstFlacTag *tag) #define FLAC_MAGIC_SIZE (sizeof (FLAC_MAGIC) - 1) static void -gst_flac_tag_chain (GstPad *pad, GstData *data) +gst_flac_tag_chain (GstPad * pad, GstData * data) { GstBuffer *buffer; GstFlacTag *tag; - + if (GST_IS_EVENT (data)) { g_print ("Unhandled event\n"); return; @@ -265,6 +274,7 @@ gst_flac_tag_chain (GstPad *pad, GstData *data) if (tag->buffer) { GstBuffer *merge; + merge = gst_buffer_merge (tag->buffer, buffer); gst_buffer_unref (buffer); gst_buffer_unref (tag->buffer); @@ -284,13 +294,17 @@ gst_flac_tag_chain (GstPad *pad, GstData *data) return; } - if (strncmp (GST_BUFFER_DATA (tag->buffer), FLAC_MAGIC, FLAC_MAGIC_SIZE) == 0) { + if (strncmp (GST_BUFFER_DATA (tag->buffer), FLAC_MAGIC, + FLAC_MAGIC_SIZE) == 0) { GstBuffer *sub; + tag->state = GST_FLAC_TAG_STATE_METADATA_BLOCKS; sub = gst_buffer_create_sub (tag->buffer, 0, FLAC_MAGIC_SIZE); - + gst_pad_push (tag->srcpad, GST_DATA (sub)); - sub = gst_buffer_create_sub (tag->buffer, FLAC_MAGIC_SIZE, GST_BUFFER_SIZE (tag->buffer) - FLAC_MAGIC_SIZE); + sub = + gst_buffer_create_sub (tag->buffer, FLAC_MAGIC_SIZE, + GST_BUFFER_SIZE (tag->buffer) - FLAC_MAGIC_SIZE); gst_buffer_unref (tag->buffer); /* We do a copy because we need a writable buffer, and _create_sub * sets the buffer it uses to read-only @@ -332,10 +346,9 @@ gst_flac_tag_chain (GstPad *pad, GstData *data) } type = (GST_BUFFER_DATA (tag->buffer)[0]) & 0x7F; - size = - ((GST_BUFFER_DATA (tag->buffer)[1]) << 16) - | ((GST_BUFFER_DATA (tag->buffer)[2]) << 8) - | (GST_BUFFER_DATA (tag->buffer)[3]); + size = ((GST_BUFFER_DATA (tag->buffer)[1]) << 16) + | ((GST_BUFFER_DATA (tag->buffer)[2]) << 8) + | (GST_BUFFER_DATA (tag->buffer)[3]); /* The 4 bytes long header isn't included in the metadata size */ tag->metadata_bytes_remaining = size + 4; @@ -352,14 +365,14 @@ gst_flac_tag_chain (GstPad *pad, GstData *data) /* Reads a metadata block */ if ((tag->state == GST_FLAC_TAG_STATE_WRITING_METADATA_BLOCK) || - (tag->state == GST_FLAC_TAG_STATE_VC_METADATA_BLOCK)) { - GstBuffer *sub; + (tag->state == GST_FLAC_TAG_STATE_VC_METADATA_BLOCK)) { + GstBuffer *sub; guint bytes_to_push; g_assert (tag->metadata_bytes_remaining != 0); - bytes_to_push = min (tag->metadata_bytes_remaining, - GST_BUFFER_SIZE (tag->buffer)); + bytes_to_push = min (tag->metadata_bytes_remaining, + GST_BUFFER_SIZE (tag->buffer)); sub = gst_buffer_create_sub (tag->buffer, 0, bytes_to_push); @@ -370,6 +383,7 @@ gst_flac_tag_chain (GstPad *pad, GstData *data) tag->vorbiscomment = sub; } else { GstBuffer *merge; + merge = gst_buffer_merge (tag->vorbiscomment, sub); gst_buffer_unref (tag->vorbiscomment); gst_buffer_unref (sub); @@ -382,8 +396,8 @@ gst_flac_tag_chain (GstPad *pad, GstData *data) if (GST_BUFFER_SIZE (tag->buffer) > bytes_to_push) { GstBuffer *sub; - sub = gst_buffer_create_sub (tag->buffer, bytes_to_push, - GST_BUFFER_SIZE (tag->buffer) - bytes_to_push); + sub = gst_buffer_create_sub (tag->buffer, bytes_to_push, + GST_BUFFER_SIZE (tag->buffer) - bytes_to_push); gst_buffer_unref (tag->buffer); /* We make a copy because we need a writable buffer, and _create_sub @@ -415,10 +429,9 @@ gst_flac_tag_chain (GstPad *pad, GstData *data) if (tag->vorbiscomment != NULL) { /* We found some tags, try to parse them and notify the other elements * that we encoutered some tags - */ - tag->tags = gst_tag_list_from_vorbiscomment_buffer (tag->vorbiscomment, - GST_BUFFER_DATA (tag->vorbiscomment), - 4, NULL); + */ + tag->tags = gst_tag_list_from_vorbiscomment_buffer (tag->vorbiscomment, + GST_BUFFER_DATA (tag->vorbiscomment), 4, NULL); if (tag->tags != NULL) { gst_element_found_tags (GST_ELEMENT (tag), tag->tags); } @@ -431,7 +444,7 @@ gst_flac_tag_chain (GstPad *pad, GstData *data) return; } } - + /* Skip to next state */ if (tag->metadata_last_block == FALSE) { tag->state = GST_FLAC_TAG_STATE_METADATA_BLOCKS; @@ -461,9 +474,9 @@ gst_flac_tag_chain (GstPad *pad, GstData *data) g_assert (tag->only_output_tags == FALSE); user_tags = gst_tag_setter_get_list (GST_TAG_SETTER (tag)); - merged_tags = gst_tag_list_merge (tag->tags, user_tags, - gst_tag_setter_get_merge_mode (GST_TAG_SETTER (tag))); - + merged_tags = gst_tag_list_merge (tag->tags, user_tags, + gst_tag_setter_get_merge_mode (GST_TAG_SETTER (tag))); + if (merged_tags == NULL) { /* If we get a NULL list of tags, we must generate a padding block * which is marked as the last metadata block, otherwise we'll @@ -473,23 +486,25 @@ gst_flac_tag_chain (GstPad *pad, GstData *data) buffer = gst_buffer_new_and_alloc (12); if (buffer == NULL) { GST_ELEMENT_ERROR (tag, CORE, TOO_LAZY, (NULL), - ("Error creating 12-byte buffer for padding block")); + ("Error creating 12-byte buffer for padding block")); } memset (GST_BUFFER_DATA (buffer), 0, GST_BUFFER_SIZE (buffer)); - GST_BUFFER_DATA (buffer)[0] = 0x81; /* 0x80 = Last metadata block, - * 0x01 = padding block - */ + GST_BUFFER_DATA (buffer)[0] = 0x81; /* 0x80 = Last metadata block, + * 0x01 = padding block + */ } else { guchar header[4]; + memset (header, 0, sizeof (header)); - header[0] = 0x84; /* 0x80 = Last metadata block, - * 0x04 = vorbiscomment block - */ - buffer = gst_tag_list_to_vorbiscomment_buffer (merged_tags, header, - sizeof (header), NULL); + header[0] = 0x84; /* 0x80 = Last metadata block, + * 0x04 = vorbiscomment block + */ + buffer = gst_tag_list_to_vorbiscomment_buffer (merged_tags, header, + sizeof (header), NULL); gst_tag_list_free (merged_tags); if (buffer == NULL) { - GST_ELEMENT_ERROR (tag, CORE, TAG, (NULL), ("Error converting tag list to vorbiscomment buffer")); + GST_ELEMENT_ERROR (tag, CORE, TAG, (NULL), + ("Error converting tag list to vorbiscomment buffer")); return; } size = GST_BUFFER_SIZE (buffer) - 4; @@ -498,9 +513,10 @@ gst_flac_tag_chain (GstPad *pad, GstData *data) * while the vorbis specs allow more than that. Shouldn't * be a real world problem though */ - GST_ELEMENT_ERROR (tag, CORE, TAG, (NULL), ("Vorbis comment of size %d too long", size)); + GST_ELEMENT_ERROR (tag, CORE, TAG, (NULL), + ("Vorbis comment of size %d too long", size)); return; - } + } } /* The 4 byte metadata block header isn't accounted for in the total @@ -509,8 +525,8 @@ gst_flac_tag_chain (GstPad *pad, GstData *data) size = GST_BUFFER_SIZE (buffer) - 4; GST_BUFFER_DATA (buffer)[1] = ((size & 0xFF0000) >> 16); - GST_BUFFER_DATA (buffer)[2] = ((size & 0x00FF00) >> 8); - GST_BUFFER_DATA (buffer)[3] = (size & 0x0000FF); + GST_BUFFER_DATA (buffer)[2] = ((size & 0x00FF00) >> 8); + GST_BUFFER_DATA (buffer)[3] = (size & 0x0000FF); gst_pad_push (tag->srcpad, GST_DATA (buffer)); tag->state = GST_FLAC_TAG_STATE_AUDIO_DATA; } @@ -525,7 +541,7 @@ gst_flac_tag_chain (GstPad *pad, GstData *data) static GstElementStateReturn -gst_flac_tag_change_state (GstElement *element) +gst_flac_tag_change_state (GstElement * element) { GstFlacTag *tag; @@ -543,7 +559,7 @@ gst_flac_tag_change_state (GstElement *element) break; case GST_STATE_PAUSED_TO_READY: if (tag->buffer) { - gst_buffer_unref (tag->buffer); + gst_buffer_unref (tag->buffer); tag->buffer = NULL; } if (tag->vorbiscomment) { diff --git a/ext/gdk_pixbuf/gst_loader.c b/ext/gdk_pixbuf/gst_loader.c index b0538cac..95fd5af7 100644 --- a/ext/gdk_pixbuf/gst_loader.c +++ b/ext/gdk_pixbuf/gst_loader.c @@ -31,53 +31,58 @@ #include <fcntl.h> -typedef struct { +typedef struct +{ /* stuff gdk throws at us and we're supposed to keep */ - GdkPixbufModuleSizeFunc size_func; - GdkPixbufModulePreparedFunc prepared_func; - GdkPixbufModuleUpdatedFunc updated_func; - gpointer user_data; + GdkPixbufModuleSizeFunc size_func; + GdkPixbufModulePreparedFunc prepared_func; + GdkPixbufModuleUpdatedFunc updated_func; + gpointer user_data; /* our own stuff - we're much better at keeping fields small :p */ - GstGdkAnimation * ani; - gboolean initialized; + GstGdkAnimation *ani; + gboolean initialized; } GstLoaderContext; GST_DEBUG_CATEGORY_STATIC (gst_loader_debug); #define GST_CAT_DEFAULT gst_loader_debug static gboolean -gst_loader_init (GError **error) +gst_loader_init (GError ** error) { static gboolean inited = FALSE; - + if (inited) return TRUE; - + if (!g_thread_supported ()) { g_set_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_FAILED, - "The GStreamer loader requires threading support."); + "The GStreamer loader requires threading support."); return FALSE; } if (!gst_init_check (0, NULL)) { g_set_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_FAILED, - "GStreamer could not be initialized."); + "GStreamer could not be initialized."); return FALSE; } inited = TRUE; - GST_DEBUG_CATEGORY_INIT (gst_loader_debug, "gstloader", 0, "entry point debugging for the GStreamer gdk pixbuf loader"); + GST_DEBUG_CATEGORY_INIT (gst_loader_debug, "gstloader", 0, + "entry point debugging for the GStreamer gdk pixbuf loader"); return TRUE; } + static gpointer -gst_loader_begin_load (GdkPixbufModuleSizeFunc size_func, GdkPixbufModulePreparedFunc prepared_func, - GdkPixbufModuleUpdatedFunc updated_func, gpointer user_data, GError **error) +gst_loader_begin_load (GdkPixbufModuleSizeFunc size_func, + GdkPixbufModulePreparedFunc prepared_func, + GdkPixbufModuleUpdatedFunc updated_func, gpointer user_data, + GError ** error) { GstLoaderContext *context; - + if (!gst_loader_init (error)) return NULL; - + context = g_new (GstLoaderContext, 1); context->size_func = size_func; context->prepared_func = prepared_func; @@ -91,7 +96,8 @@ gst_loader_begin_load (GdkPixbufModuleSizeFunc size_func, GdkPixbufModulePrepare g_free (context); return NULL; } - context->ani->temp_fd = g_file_open_tmp (NULL, &context->ani->temp_location, error); + context->ani->temp_fd = + g_file_open_tmp (NULL, &context->ani->temp_location, error); if (context->ani->temp_fd == 0) { g_object_unref (context->ani); g_free (context); @@ -101,19 +107,27 @@ gst_loader_begin_load (GdkPixbufModuleSizeFunc size_func, GdkPixbufModulePrepare GST_LOG_OBJECT (context->ani, "begin loading"); return context; } + static gboolean -gst_loader_load_increment (gpointer context_pointer, const guchar *buf, guint size, GError **error) +gst_loader_load_increment (gpointer context_pointer, const guchar * buf, + guint size, GError ** error) { GdkPixbufAnimationIter *iter; GstLoaderContext *context = (GstLoaderContext *) context_pointer; GST_LOG_OBJECT (context->ani, "load increment: %u bytes", size); gst_gdk_animation_add_data (context->ani, buf, size); - if (!context->initialized && (iter = gdk_pixbuf_animation_get_iter ( - GDK_PIXBUF_ANIMATION (context->ani), NULL)) != NULL) { - int width = gdk_pixbuf_animation_get_width (GDK_PIXBUF_ANIMATION (context->ani)); - int height = gdk_pixbuf_animation_get_height (GDK_PIXBUF_ANIMATION (context->ani)); - GdkPixbuf *pixbuf = gdk_pixbuf_animation_get_static_image (GDK_PIXBUF_ANIMATION (context->ani)); + if (!context->initialized + && (iter = + gdk_pixbuf_animation_get_iter (GDK_PIXBUF_ANIMATION (context->ani), + NULL)) != NULL) { + int width = + gdk_pixbuf_animation_get_width (GDK_PIXBUF_ANIMATION (context->ani)); + int height = + gdk_pixbuf_animation_get_height (GDK_PIXBUF_ANIMATION (context->ani)); + GdkPixbuf *pixbuf = + gdk_pixbuf_animation_get_static_image (GDK_PIXBUF_ANIMATION (context-> + ani)); g_object_unref (iter); GST_LOG_OBJECT (context->ani, "initializing loader"); @@ -123,17 +137,20 @@ gst_loader_load_increment (gpointer context_pointer, const guchar *buf, guint si } if (context->prepared_func) { - GST_LOG_OBJECT (context->ani, "calling prepared_func %p", context->prepared_func); - context->prepared_func (pixbuf, GDK_PIXBUF_ANIMATION (context->ani), context->user_data); + GST_LOG_OBJECT (context->ani, "calling prepared_func %p", + context->prepared_func); + context->prepared_func (pixbuf, GDK_PIXBUF_ANIMATION (context->ani), + context->user_data); } - + context->initialized = TRUE; } - + return TRUE; } + static gboolean -gst_loader_stop_load (gpointer context_pointer, GError **error) +gst_loader_stop_load (gpointer context_pointer, GError ** error) { GstLoaderContext *context = (GstLoaderContext *) context_pointer; @@ -146,20 +163,20 @@ gst_loader_stop_load (gpointer context_pointer, GError **error) } static GdkPixbufAnimation * -gst_loader_load_animation (FILE *f, GError **error) +gst_loader_load_animation (FILE * f, GError ** error) { gchar *filename; GstGdkAnimation *ani; GdkPixbufAnimationIter *iter = NULL; - + if (!gst_loader_init (error)) return NULL; - + GST_LOG ("load_animation"); ani = gst_gdk_animation_new (error); if (!ani) return NULL; - + filename = g_strdup_printf ("/proc/self/fd/%d", fileno (f)); ani->temp_fd = open (filename, 0); if (ani->temp_fd >= 0) { @@ -170,21 +187,21 @@ gst_loader_load_animation (FILE *f, GError **error) g_free (filename); if (iter == NULL) { g_set_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE, - "could not create an image"); + "could not create an image"); g_object_unref (ani); GST_INFO ("could not create an image"); - return NULL; + return NULL; } g_object_unref (iter); GST_LOG_OBJECT (ani, "load_animation succeeded"); return GDK_PIXBUF_ANIMATION (ani); } static GdkPixbuf * -gst_loader_load (FILE *f, GError **error) +gst_loader_load (FILE * f, GError ** error) { GdkPixbufAnimation *ani; GdkPixbuf *pixbuf; - + ani = gst_loader_load_animation (f, error); if (ani == NULL) return NULL; @@ -193,8 +210,8 @@ gst_loader_load (FILE *f, GError **error) if (!pixbuf) { GST_ERROR_OBJECT (ani, "Could not get an image in _pixbuf_load"); g_object_unref (ani); - g_set_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE, - "Could not get an image from file."); + g_set_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE, + "Could not get an image from file."); return NULL; } @@ -203,8 +220,9 @@ gst_loader_load (FILE *f, GError **error) return pixbuf; } + void -fill_vtable (GdkPixbufModule *module) +fill_vtable (GdkPixbufModule * module) { module->load = gst_loader_load; module->begin_load = gst_loader_begin_load; @@ -212,33 +230,35 @@ fill_vtable (GdkPixbufModule *module) module->stop_load = gst_loader_stop_load; module->load_animation = gst_loader_load_animation; } + void -fill_info (GdkPixbufFormat *info) +fill_info (GdkPixbufFormat * info) { static GdkPixbufModulePattern signature[] = { /* AVI */ - { "RIFF AVI ", " xxxx ", 100 }, + {"RIFF AVI ", " xxxx ", 100}, /* MPEG 1 */ - { "xx\001\272", "zz ", 100 }, + {"xx\001\272", "zz ", 100}, /* MPEG 2 */ - { "xx\001\263", "zz ", 100 }, + {"xx\001\263", "zz ", 100}, /* Quicktime */ - { " wide", "xxxx ", 80 }, - { " moov", "xxxx ", 80 }, - { " mdat", "xxxx ", 80 }, - { " pnot", "xxxx ", 80 }, - { " PICT", "xxxx ", 80 }, - { " free", "xxxx ", 80 }, + {" wide", "xxxx ", 80}, + {" moov", "xxxx ", 80}, + {" mdat", "xxxx ", 80}, + {" pnot", "xxxx ", 80}, + {" PICT", "xxxx ", 80}, + {" free", "xxxx ", 80}, /* ASF */ - { "\060\046\262\165\216\146\317\021\246\331 \252 \142\316\154", " z z ", 100 }, - { NULL, NULL, 0 } + {"\060\046\262\165\216\146\317\021\246\331 \252 \142\316\154", + " z z ", 100}, + {NULL, NULL, 0} }; - + static gchar *mime_types[] = { "video/avi", "video/x-avi", "video/x-msvideo", "video/mpeg", - "video/quicktime", - "video/x-ms-asf", + "video/quicktime", + "video/x-ms-asf", NULL }; @@ -246,14 +266,14 @@ fill_info (GdkPixbufFormat *info) "avi", "mpeg", "mpe", "mpg", "mov", - "asf", "wmv", + "asf", "wmv", NULL }; - - info->name = "GStreamer"; - info->signature = signature; + + info->name = "GStreamer"; + info->signature = signature; info->description = "GStreamer supported video"; - info->mime_types = mime_types; - info->extensions = extensions; - info->flags = 0; + info->mime_types = mime_types; + info->extensions = extensions; + info->flags = 0; } diff --git a/ext/gdk_pixbuf/gstgdkanimation.c b/ext/gdk_pixbuf/gstgdkanimation.c index a0b6cb93..df58c5be 100644 --- a/ext/gdk_pixbuf/gstgdkanimation.c +++ b/ext/gdk_pixbuf/gstgdkanimation.c @@ -27,17 +27,18 @@ GST_DEBUG_CATEGORY_STATIC (gst_gdk_animation_debug); #define GST_CAT_DEFAULT gst_gdk_animation_debug -static void gst_gdk_animation_class_init (gpointer g_class, - gpointer class_data); -static void gst_gdk_animation_finalize (GObject * object); +static void gst_gdk_animation_class_init (gpointer g_class, + gpointer class_data); +static void gst_gdk_animation_finalize (GObject * object); -static gboolean gst_gdk_animation_is_static_image (GdkPixbufAnimation * animation); -static GdkPixbuf* gst_gdk_animation_get_static_image (GdkPixbufAnimation * animation); -static void gst_gdk_animation_get_size (GdkPixbufAnimation * anim, - gint * width, - gint * height); -static GdkPixbufAnimationIter* gst_gdk_animation_get_iter (GdkPixbufAnimation * anim, - const GTimeVal * start_time); +static gboolean gst_gdk_animation_is_static_image (GdkPixbufAnimation * + animation); +static GdkPixbuf *gst_gdk_animation_get_static_image (GdkPixbufAnimation * + animation); +static void gst_gdk_animation_get_size (GdkPixbufAnimation * anim, gint * width, + gint * height); +static GdkPixbufAnimationIter *gst_gdk_animation_get_iter (GdkPixbufAnimation * + anim, const GTimeVal * start_time); static gpointer parent_class; @@ -53,19 +54,20 @@ gst_gdk_animation_get_type (void) NULL, NULL, gst_gdk_animation_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ + NULL, /* class_finalize */ + NULL, /* class_data */ sizeof (GstGdkAnimation), - 0, /* n_preallocs */ + 0, /* n_preallocs */ NULL, }; - + object_type = g_type_register_static (GDK_TYPE_PIXBUF_ANIMATION, - "GstGdkAnimation", &object_info, 0); + "GstGdkAnimation", &object_info, 0); - GST_DEBUG_CATEGORY_INIT (gst_gdk_animation_debug, "gstloader_animation", 0, "GStreamer GdkPixbuf loader - GdkAnimation class"); + GST_DEBUG_CATEGORY_INIT (gst_gdk_animation_debug, "gstloader_animation", 0, + "GStreamer GdkPixbuf loader - GdkAnimation class"); } - + return object_type; } static void @@ -73,9 +75,9 @@ gst_gdk_animation_class_init (gpointer g_class, gpointer class_data) { GObjectClass *object_class = G_OBJECT_CLASS (g_class); GdkPixbufAnimationClass *anim_class = GDK_PIXBUF_ANIMATION_CLASS (g_class); - + parent_class = g_type_class_peek_parent (g_class); - + object_class->finalize = gst_gdk_animation_finalize; anim_class->is_static_image = gst_gdk_animation_is_static_image; @@ -84,7 +86,7 @@ gst_gdk_animation_class_init (gpointer g_class, gpointer class_data) anim_class->get_iter = gst_gdk_animation_get_iter; } static void -gst_gdk_animation_finalize (GObject *object) +gst_gdk_animation_finalize (GObject * object) { GstGdkAnimation *ani = GST_GDK_ANIMATION (object); @@ -99,39 +101,47 @@ gst_gdk_animation_finalize (GObject *object) g_object_unref (ani->pixbuf); ani->pixbuf = NULL; } - + G_OBJECT_CLASS (parent_class)->finalize (object); } + GstGdkAnimation * -gst_gdk_animation_new (GError **error) +gst_gdk_animation_new (GError ** error) { - GstGdkAnimation *ani = GST_GDK_ANIMATION (g_object_new (GST_TYPE_GDK_ANIMATION, NULL)); + GstGdkAnimation *ani = + GST_GDK_ANIMATION (g_object_new (GST_TYPE_GDK_ANIMATION, NULL)); return ani; } + gboolean -gst_gdk_animation_add_data (GstGdkAnimation *ani, const guint8 *data, guint size) +gst_gdk_animation_add_data (GstGdkAnimation * ani, const guint8 * data, + guint size) { return (write (ani->temp_fd, data, size) == size); } + void -gst_gdk_animation_done_adding (GstGdkAnimation *ani) +gst_gdk_animation_done_adding (GstGdkAnimation * ani) { close (ani->temp_fd); ani->temp_fd = 0; } + static gboolean -gst_gdk_animation_is_static_image (GdkPixbufAnimation *animation) +gst_gdk_animation_is_static_image (GdkPixbufAnimation * animation) { return FALSE; } static void -gst_gdk_animation_get_size (GdkPixbufAnimation *anim, gint *width, int *height) +gst_gdk_animation_get_size (GdkPixbufAnimation * anim, gint * width, + int *height) { GstGdkAnimation *ani = GST_GDK_ANIMATION (anim); - GST_LOG_OBJECT (ani, "get_size called (%p, %p) %d x %d", width, height, ani->width, ani->height); + GST_LOG_OBJECT (ani, "get_size called (%p, %p) %d x %d", width, height, + ani->width, ani->height); if (width) *width = ani->width; @@ -140,17 +150,21 @@ gst_gdk_animation_get_size (GdkPixbufAnimation *anim, gint *width, int *height) } -static void gst_gdk_animation_iter_class_init (gpointer g_class, - gpointer class_data); -static void gst_gdk_animation_iter_init (GTypeInstance * instance, - gpointer g_class); -static void gst_gdk_animation_iter_finalize (GObject * object); +static void gst_gdk_animation_iter_class_init (gpointer g_class, + gpointer class_data); +static void gst_gdk_animation_iter_init (GTypeInstance * instance, + gpointer g_class); +static void gst_gdk_animation_iter_finalize (GObject * object); -static gint gst_gdk_animation_iter_get_delay_time (GdkPixbufAnimationIter * iter); -static GdkPixbuf * gst_gdk_animation_iter_get_pixbuf (GdkPixbufAnimationIter * iter); -static gboolean gst_gdk_animation_iter_on_currently_loading_frame (GdkPixbufAnimationIter * iter); -static gboolean gst_gdk_animation_iter_advance (GdkPixbufAnimationIter * iter, - const GTimeVal * current_time); +static gint gst_gdk_animation_iter_get_delay_time (GdkPixbufAnimationIter * + iter); +static GdkPixbuf *gst_gdk_animation_iter_get_pixbuf (GdkPixbufAnimationIter * + iter); +static gboolean +gst_gdk_animation_iter_on_currently_loading_frame (GdkPixbufAnimationIter * + iter); +static gboolean gst_gdk_animation_iter_advance (GdkPixbufAnimationIter * iter, + const GTimeVal * current_time); static gpointer iter_parent_class; @@ -165,17 +179,17 @@ gst_gdk_animation_iter_get_type (void) NULL, NULL, gst_gdk_animation_iter_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ + NULL, /* class_finalize */ + NULL, /* class_data */ sizeof (GstGdkAnimationIter), - 0, /* n_preallocs */ + 0, /* n_preallocs */ gst_gdk_animation_iter_init, }; - + object_type = g_type_register_static (GDK_TYPE_PIXBUF_ANIMATION_ITER, - "GdkPixbufAniAnimIter", &object_info, 0); + "GdkPixbufAniAnimIter", &object_info, 0); } - + return object_type; } @@ -183,19 +197,21 @@ static void gst_gdk_animation_iter_class_init (gpointer g_class, gpointer class_data) { GObjectClass *object_class = G_OBJECT_CLASS (g_class); - GdkPixbufAnimationIterClass *anim_iter_class = GDK_PIXBUF_ANIMATION_ITER_CLASS (g_class); - + GdkPixbufAnimationIterClass *anim_iter_class = + GDK_PIXBUF_ANIMATION_ITER_CLASS (g_class); + iter_parent_class = g_type_class_peek_parent (g_class); - + object_class->finalize = gst_gdk_animation_iter_finalize; - + anim_iter_class->get_delay_time = gst_gdk_animation_iter_get_delay_time; anim_iter_class->get_pixbuf = gst_gdk_animation_iter_get_pixbuf; - anim_iter_class->on_currently_loading_frame = gst_gdk_animation_iter_on_currently_loading_frame; + anim_iter_class->on_currently_loading_frame = + gst_gdk_animation_iter_on_currently_loading_frame; anim_iter_class->advance = gst_gdk_animation_iter_advance; } static void -gst_gdk_animation_iter_init (GTypeInstance *instance, gpointer g_class) +gst_gdk_animation_iter_init (GTypeInstance * instance, gpointer g_class) { GstGdkAnimationIter *iter = GST_GDK_ANIMATION_ITER (instance); @@ -203,18 +219,19 @@ gst_gdk_animation_iter_init (GTypeInstance *instance, gpointer g_class) iter->eos = FALSE; } static void -gst_gdk_animation_iter_finalize (GObject *object) +gst_gdk_animation_iter_finalize (GObject * object) { GstGdkAnimationIter *iter = GST_GDK_ANIMATION_ITER (object); - + g_object_unref (iter->ani); - + if (iter->pipeline) g_object_unref (iter->pipeline); if (iter->pixbuf) g_object_unref (iter->pixbuf); while (iter->buffers) { GstBuffer *buffer = GST_BUFFER (g_queue_pop_head (iter->buffers)); + if (buffer) { GST_LOG_OBJECT (iter, "unreffing buffer %p on finalize", buffer); gst_data_unref (GST_DATA (buffer)); @@ -226,36 +243,40 @@ gst_gdk_animation_iter_finalize (GObject *object) G_OBJECT_CLASS (iter_parent_class)->finalize (object); } static void -got_handoff (GstElement *fakesink, GstBuffer *buffer, GstPad *pad, GstGdkAnimationIter *iter) +got_handoff (GstElement * fakesink, GstBuffer * buffer, GstPad * pad, + GstGdkAnimationIter * iter) { - GST_LOG_OBJECT (iter, "enqueing buffer %p (timestamp %"G_GUINT64_FORMAT")", - buffer, GST_BUFFER_TIMESTAMP (buffer)); + GST_LOG_OBJECT (iter, "enqueing buffer %p (timestamp %" G_GUINT64_FORMAT ")", + buffer, GST_BUFFER_TIMESTAMP (buffer)); gst_data_ref (GST_DATA (buffer)); g_queue_push_tail (iter->buffers, buffer); } + static gboolean -gst_gdk_animation_iter_create_pipeline (GstGdkAnimationIter *iter) +gst_gdk_animation_iter_create_pipeline (GstGdkAnimationIter * iter) { GstElement *src, *typefind, *autoplugger, *sink, *colorspace; GstCaps *caps = GST_CAPS_NEW ("pixbuf_filter32", - "video/x-raw-rgb", - "endianness", GST_PROPS_INT (G_BIG_ENDIAN), - "bpp", GST_PROPS_INT (32), - "red_mask", GST_PROPS_INT (0xFF000000), - "green_mask", GST_PROPS_INT (0x00FF0000), - "blue_mask", GST_PROPS_INT (0x0000FF00) - ); + "video/x-raw-rgb", + "endianness", GST_PROPS_INT (G_BIG_ENDIAN), + "bpp", GST_PROPS_INT (32), + "red_mask", GST_PROPS_INT (0xFF000000), + "green_mask", GST_PROPS_INT (0x00FF0000), + "blue_mask", GST_PROPS_INT (0x0000FF00) + ); + gst_caps_append (caps, GST_CAPS_NEW ("pixbuf_filter24", - "video/x-raw-rgb", - "endianness", GST_PROPS_INT (G_BIG_ENDIAN), - "bpp", GST_PROPS_INT (24), - "red_mask", GST_PROPS_INT (0xFF0000), - "green_mask", GST_PROPS_INT (0x00FF00), - "blue_mask", GST_PROPS_INT (0x0000FF) - )); + "video/x-raw-rgb", + "endianness", GST_PROPS_INT (G_BIG_ENDIAN), + "bpp", GST_PROPS_INT (24), + "red_mask", GST_PROPS_INT (0xFF0000), + "green_mask", GST_PROPS_INT (0x00FF00), + "blue_mask", GST_PROPS_INT (0x0000FF) + )); iter->pipeline = gst_element_factory_make ("pipeline", "main_pipeline"); - if (iter->pipeline == NULL) return FALSE; + if (iter->pipeline == NULL) + return FALSE; if (!(src = gst_element_factory_make ("filesrc", "source"))) goto error; @@ -265,6 +286,7 @@ gst_gdk_animation_iter_create_pipeline (GstGdkAnimationIter *iter) GST_INFO_OBJECT (iter, "using file '%s'", iter->ani->temp_location); } else { gchar *filename = g_strdup_printf ("/proc/self/fd/%d", iter->ani->temp_fd); + g_object_set (src, "location", filename, NULL); GST_INFO_OBJECT (iter, "using file '%s'", filename); g_free (filename); @@ -292,7 +314,7 @@ gst_gdk_animation_iter_create_pipeline (GstGdkAnimationIter *iter) gst_bin_add (GST_BIN (iter->pipeline), colorspace); if (!gst_element_link (autoplugger, colorspace)) goto error; - + if (!(sink = gst_element_factory_make ("fakesink", "sink"))) goto error; g_object_set (sink, "signal-handoffs", TRUE, NULL); @@ -300,39 +322,42 @@ gst_gdk_animation_iter_create_pipeline (GstGdkAnimationIter *iter) gst_bin_add (GST_BIN (iter->pipeline), sink); if (!gst_element_link_filtered (colorspace, sink, caps)) goto error; - if (gst_element_set_state (iter->pipeline, GST_STATE_PLAYING) != GST_STATE_SUCCESS) + if (gst_element_set_state (iter->pipeline, + GST_STATE_PLAYING) != GST_STATE_SUCCESS) goto error; - + return TRUE; error: g_object_unref (iter->pipeline); iter->pipeline = NULL; return FALSE; } + static gboolean -gst_gdk_animation_iter_may_advance (GstGdkAnimationIter *iter) +gst_gdk_animation_iter_may_advance (GstGdkAnimationIter * iter) { GstFormat bytes = GST_FORMAT_BYTES; gint64 offset; gint64 data_amount; - + if (iter->ani->temp_fd == 0 || iter->ani->temp_location == NULL) return TRUE; data_amount = lseek (iter->ani->temp_fd, 0, SEEK_CUR); g_assert (data_amount >= 0); - g_assert (gst_element_query (gst_bin_get_by_name (GST_BIN (iter->pipeline), "source"), - GST_QUERY_POSITION, &bytes, &offset)); + g_assert (gst_element_query (gst_bin_get_by_name (GST_BIN (iter->pipeline), + "source"), GST_QUERY_POSITION, &bytes, &offset)); if (data_amount - offset > GST_GDK_BUFFER_SIZE) return TRUE; return FALSE; } + static gboolean -gst_gdk_animation_get_more_buffers (GstGdkAnimationIter *iter) +gst_gdk_animation_get_more_buffers (GstGdkAnimationIter * iter) { GstBuffer *last = g_queue_peek_tail (iter->buffers); - + do { GST_LOG_OBJECT (iter, "iterating..."); if (!gst_gdk_animation_iter_may_advance (iter)) { @@ -348,17 +373,17 @@ gst_gdk_animation_get_more_buffers (GstGdkAnimationIter *iter) return last != g_queue_peek_tail (iter->buffers); } static void -pixbuf_destroy_notify (guchar *pixels, gpointer data) +pixbuf_destroy_notify (guchar * pixels, gpointer data) { GST_LOG ("unreffing buffer %p because pixbuf was destroyed", data); gst_data_unref (GST_DATA (data)); } static void -gst_gdk_animation_iter_create_pixbuf (GstGdkAnimationIter *iter) +gst_gdk_animation_iter_create_pixbuf (GstGdkAnimationIter * iter) { GstBuffer *buf; GstGdkAnimation *ani = iter->ani; - + buf = g_queue_pop_head (iter->buffers); g_assert (buf); if (iter->pixbuf) { @@ -368,7 +393,8 @@ gst_gdk_animation_iter_create_pixbuf (GstGdkAnimationIter *iter) if (ani->width == 0) { GstPad *pad; GstCaps *caps; - GstElement *fakesink = gst_bin_get_by_name (GST_BIN (iter->pipeline), "sink"); + GstElement *fakesink = + gst_bin_get_by_name (GST_BIN (iter->pipeline), "sink"); g_assert (fakesink); pad = gst_element_get_pad (fakesink, "sink"); g_assert (pad); @@ -376,92 +402,108 @@ gst_gdk_animation_iter_create_pixbuf (GstGdkAnimationIter *iter) g_assert (caps); g_assert (GST_CAPS_IS_FIXED (caps)); g_assert (gst_caps_has_fixed_property (caps, "bpp") && - gst_caps_has_fixed_property (caps, "width") && - gst_caps_has_fixed_property (caps, "height")); + gst_caps_has_fixed_property (caps, "width") && + gst_caps_has_fixed_property (caps, "height")); gst_caps_get_int (caps, "width", &ani->width); gst_caps_get_int (caps, "height", &ani->height); gst_caps_get_int (caps, "bpp", &ani->bpp); - GST_DEBUG_OBJECT (ani, "found format (width %d, height %d, bpp %d)", ani->width, ani->height, ani->bpp); + GST_DEBUG_OBJECT (ani, "found format (width %d, height %d, bpp %d)", + ani->width, ani->height, ani->bpp); } g_assert (GST_BUFFER_SIZE (buf) == ani->width * ani->height * ani->bpp / 8); if (ani->bpp == 32) { gint i; guint32 *data = (guint32 *) GST_BUFFER_DATA (buf); + /* ensure opacity */ for (i = 0; i < ani->width * ani->height; i++) { data[i] |= 0xFF000000; } } iter->pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buf), - GDK_COLORSPACE_RGB, ani->bpp == 32, 8, ani->width, ani->height, ani->width * ani->bpp / 8, pixbuf_destroy_notify, buf); - GST_LOG_OBJECT (iter, "created pixbuf %p from buffer %p (refcount %d)", iter->pixbuf, buf, GST_DATA_REFCOUNT_VALUE (buf)); + GDK_COLORSPACE_RGB, ani->bpp == 32, 8, ani->width, ani->height, + ani->width * ani->bpp / 8, pixbuf_destroy_notify, buf); + GST_LOG_OBJECT (iter, "created pixbuf %p from buffer %p (refcount %d)", + iter->pixbuf, buf, GST_DATA_REFCOUNT_VALUE (buf)); } -static GdkPixbufAnimationIter* -gst_gdk_animation_get_iter (GdkPixbufAnimation *anim, const GTimeVal *start_time) +static GdkPixbufAnimationIter * +gst_gdk_animation_get_iter (GdkPixbufAnimation * anim, + const GTimeVal * start_time) { GstGdkAnimation *ani = GST_GDK_ANIMATION (anim); GstGdkAnimationIter *iter; - if (ani->temp_fd != 0 && ani->temp_location != NULL && + if (ani->temp_fd != 0 && ani->temp_location != NULL && lseek (ani->temp_fd, 0, SEEK_CUR) < GST_GDK_BUFFER_SIZE) { GST_DEBUG_OBJECT (ani, "Not enough data to create iterator."); return NULL; } - + iter = g_object_new (GST_TYPE_GDK_ANIMATION_ITER, NULL); iter->start = *start_time; - + iter->ani = ani; g_object_ref (ani); if (!gst_gdk_animation_iter_create_pipeline (iter)) goto error; - + if (!gst_gdk_animation_get_more_buffers (iter)) goto error; - + gst_gdk_animation_iter_create_pixbuf (iter); - + return GDK_PIXBUF_ANIMATION_ITER (iter); error: g_object_unref (iter); return NULL; } + static gboolean -gst_gdk_animation_iter_advance (GdkPixbufAnimationIter *anim_iter, const GTimeVal *current_time) +gst_gdk_animation_iter_advance (GdkPixbufAnimationIter * anim_iter, + const GTimeVal * current_time) { GstClockTime offset; GstBuffer *buffer = NULL; GstGdkAnimationIter *iter = GST_GDK_ANIMATION_ITER (anim_iter); /* compute timestamp that next buffer must match */ - offset = ((GstClockTime) current_time->tv_sec - iter->start.tv_sec) * GST_SECOND; + offset = + ((GstClockTime) current_time->tv_sec - iter->start.tv_sec) * GST_SECOND; if (iter->start.tv_usec > current_time->tv_usec) { - offset -= ((GstClockTime) iter->start.tv_usec - current_time->tv_usec) * GST_SECOND / G_USEC_PER_SEC; + offset -= + ((GstClockTime) iter->start.tv_usec - + current_time->tv_usec) * GST_SECOND / G_USEC_PER_SEC; } else { - offset += ((GstClockTime) current_time->tv_usec - iter->start.tv_usec) * GST_SECOND / G_USEC_PER_SEC; + offset += + ((GstClockTime) current_time->tv_usec - + iter->start.tv_usec) * GST_SECOND / G_USEC_PER_SEC; } - GST_DEBUG_OBJECT (iter, "advancing to %ld:%ld (started at %ld:%ld) need offset %"G_GUINT64_FORMAT, - current_time->tv_sec, current_time->tv_usec, iter->start.tv_sec, iter->start.tv_usec, offset); - if (!iter->just_seeked && - offset - iter->last_timestamp > GST_GDK_MAX_DELAY_TO_SEEK) { - GST_INFO_OBJECT (iter, "current pipeline timestamp is too old (%"G_GUINT64_FORMAT - " vs %"G_GUINT64_FORMAT"), seeking there", iter->last_timestamp, offset); - if (gst_element_send_event (gst_bin_get_by_name (GST_BIN (iter->pipeline), "sink"), - gst_event_new_seek (GST_FORMAT_TIME | GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE, - offset))) { - iter->last_timestamp = offset; - iter->just_seeked = TRUE; - } else { - GST_WARNING_OBJECT (iter, "seek to %"G_GUINT64_FORMAT" didn't work. Iterating there...", - offset); - } + GST_DEBUG_OBJECT (iter, + "advancing to %ld:%ld (started at %ld:%ld) need offset %" + G_GUINT64_FORMAT, current_time->tv_sec, current_time->tv_usec, + iter->start.tv_sec, iter->start.tv_usec, offset); + if (!iter->just_seeked + && offset - iter->last_timestamp > GST_GDK_MAX_DELAY_TO_SEEK) { + GST_INFO_OBJECT (iter, + "current pipeline timestamp is too old (%" G_GUINT64_FORMAT " vs %" + G_GUINT64_FORMAT "), seeking there", iter->last_timestamp, offset); + if (gst_element_send_event (gst_bin_get_by_name (GST_BIN (iter->pipeline), + "sink"), + gst_event_new_seek (GST_FORMAT_TIME | GST_SEEK_METHOD_SET | + GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE, offset))) { + iter->last_timestamp = offset; + iter->just_seeked = TRUE; + } else { + GST_WARNING_OBJECT (iter, + "seek to %" G_GUINT64_FORMAT " didn't work. Iterating there...", + offset); + } } else if (iter->just_seeked) { iter->just_seeked = FALSE; } - + while (TRUE) { if (g_queue_is_empty (iter->buffers)) { if (iter->eos) @@ -474,8 +516,8 @@ gst_gdk_animation_iter_advance (GdkPixbufAnimationIter *anim_iter, const GTimeVa break; if (buffer) { GST_LOG_OBJECT (iter, "unreffing buffer %p, because timestamp too low (%" - G_GUINT64_FORMAT" vs %"G_GUINT64_FORMAT")", - buffer, GST_BUFFER_TIMESTAMP (buffer), offset); + G_GUINT64_FORMAT " vs %" G_GUINT64_FORMAT ")", + buffer, GST_BUFFER_TIMESTAMP (buffer), offset); gst_data_unref (GST_DATA (buffer)); } buffer = GST_BUFFER (g_queue_pop_head (iter->buffers)); @@ -492,39 +534,44 @@ gst_gdk_animation_iter_advance (GdkPixbufAnimationIter *anim_iter, const GTimeVa gst_gdk_animation_iter_create_pixbuf (iter); return TRUE; } + static gint -gst_gdk_animation_iter_get_delay_time (GdkPixbufAnimationIter *anim_iter) +gst_gdk_animation_iter_get_delay_time (GdkPixbufAnimationIter * anim_iter) { gint delay; GstGdkAnimationIter *iter = GST_GDK_ANIMATION_ITER (anim_iter); - + while (g_queue_is_empty (iter->buffers)) { if (iter->eos) { GST_LOG_OBJECT (iter, "returning delay of infinite, we're EOS"); return -1; } if (!gst_gdk_animation_get_more_buffers (iter)) - return -1; /* FIXME? */ + return -1; /* FIXME? */ } - delay = (GST_BUFFER_TIMESTAMP (g_queue_peek_head (iter->buffers)) - iter->last_timestamp) * - 1000 / GST_SECOND; + delay = + (GST_BUFFER_TIMESTAMP (g_queue_peek_head (iter->buffers)) - + iter->last_timestamp) * 1000 / GST_SECOND; GST_LOG_OBJECT (iter, "returning delay of %d ms", delay); return delay; } -GdkPixbuf* -gst_gdk_animation_iter_get_pixbuf (GdkPixbufAnimationIter *anim_iter) + +GdkPixbuf * +gst_gdk_animation_iter_get_pixbuf (GdkPixbufAnimationIter * anim_iter) { GstGdkAnimationIter *iter = GST_GDK_ANIMATION_ITER (anim_iter); - + GST_LOG_OBJECT (iter, "returning pixbuf %p", iter->pixbuf); return iter->pixbuf; } + static gboolean -gst_gdk_animation_iter_on_currently_loading_frame (GdkPixbufAnimationIter *anim_iter) +gst_gdk_animation_iter_on_currently_loading_frame (GdkPixbufAnimationIter * + anim_iter) { GstGdkAnimationIter *iter = GST_GDK_ANIMATION_ITER (anim_iter); - + /* EOS - last frame */ if (iter->eos && g_queue_is_empty (iter->buffers)) return TRUE; @@ -532,11 +579,11 @@ gst_gdk_animation_iter_on_currently_loading_frame (GdkPixbufAnimationIter *anim_ /* can't load more frames */ if (!gst_gdk_animation_iter_may_advance (iter)) return FALSE; - + return TRUE; } -static GdkPixbuf* -gst_gdk_animation_get_static_image (GdkPixbufAnimation *animation) +static GdkPixbuf * +gst_gdk_animation_get_static_image (GdkPixbufAnimation * animation) { GstGdkAnimation *ani = GST_GDK_ANIMATION (animation); GTimeVal tv; @@ -545,16 +592,15 @@ gst_gdk_animation_get_static_image (GdkPixbufAnimation *animation) if (!ani->pixbuf) { GST_LOG_OBJECT (ani, "trying to create pixbuf"); g_get_current_time (&tv); - iter = GST_GDK_ANIMATION_ITER ( - gdk_pixbuf_animation_get_iter (animation, &tv)); + iter = + GST_GDK_ANIMATION_ITER (gdk_pixbuf_animation_get_iter (animation, &tv)); if (iter) { guint64 offset; GstBuffer *buf; GstFormat time = GST_FORMAT_TIME; - if (!gst_element_query (gst_bin_get_by_name (GST_BIN ( - iter->pipeline), "sink"), - GST_QUERY_TOTAL, &time, &offset)) { + if (!gst_element_query (gst_bin_get_by_name (GST_BIN (iter->pipeline), + "sink"), GST_QUERY_TOTAL, &time, &offset)) { offset = 0; } if (offset > 120 * GST_SECOND) { @@ -563,15 +609,17 @@ gst_gdk_animation_get_static_image (GdkPixbufAnimation *animation) offset = offset / 2; } g_assert (time == GST_FORMAT_TIME); - GST_LOG_OBJECT (ani, "using time offset %"G_GUINT64_FORMAT" for creating static image", - offset); + GST_LOG_OBJECT (ani, + "using time offset %" G_GUINT64_FORMAT " for creating static image", + offset); while ((buf = g_queue_pop_head (iter->buffers)) != NULL) { gst_data_unref (GST_DATA (buf)); } /* now we do evil stuff, be sure to get rid of the iterator afterwards */ - if (!gst_element_send_event (gst_bin_get_by_name (GST_BIN (iter->pipeline), "sink"), - gst_event_new_seek (GST_FORMAT_TIME | GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE, offset))) { + if (!gst_element_send_event (gst_bin_get_by_name (GST_BIN (iter-> + pipeline), "sink"), + gst_event_new_seek (GST_FORMAT_TIME | GST_SEEK_METHOD_SET | + GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE, offset))) { GST_INFO_OBJECT (ani, "seeking didn't work. Using next image"); } @@ -585,7 +633,9 @@ gst_gdk_animation_get_static_image (GdkPixbufAnimation *animation) } while (FALSE); if (!g_queue_is_empty (iter->buffers)) { gst_gdk_animation_iter_create_pixbuf (iter); - ani->pixbuf = gst_gdk_animation_iter_get_pixbuf (GDK_PIXBUF_ANIMATION_ITER (iter)); + ani->pixbuf = + gst_gdk_animation_iter_get_pixbuf (GDK_PIXBUF_ANIMATION_ITER + (iter)); g_object_ref (ani->pixbuf); } else { g_assert (ani->pixbuf == NULL); diff --git a/ext/gdk_pixbuf/gstgdkanimation.h b/ext/gdk_pixbuf/gstgdkanimation.h index 183d335e..8dc0d4ef 100644 --- a/ext/gdk_pixbuf/gstgdkanimation.h +++ b/ext/gdk_pixbuf/gstgdkanimation.h @@ -27,20 +27,16 @@ #include <stdio.h> G_BEGIN_DECLS - /* how many bytes we need to have available before we dare to start a new iteration */ #define GST_GDK_BUFFER_SIZE (102400) /* how far behind we need to be before we attempt to seek */ #define GST_GDK_MAX_DELAY_TO_SEEK (GST_SECOND / 4) - - #define GST_TYPE_GDK_ANIMATION (gst_gdk_animation_get_type()) #define GST_GDK_ANIMATION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GDK_ANIMATION,GstGdkAnimation)) #define GST_GDK_ANIMATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_GDK_ANIMATION,GstGdkAnimation)) #define GST_IS_GDK_ANIMATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GDK_ANIMATION)) #define GST_IS_GDK_ANIMATION_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_GDK_ANIMATION)) - -typedef struct _GstGdkAnimation GstGdkAnimation; +typedef struct _GstGdkAnimation GstGdkAnimation; typedef struct _GstGdkAnimationClass GstGdkAnimationClass; typedef struct _GstGdkAnimationIter GstGdkAnimationIter; @@ -48,34 +44,33 @@ typedef struct _GstGdkAnimationIterClass GstGdkAnimationIterClass; struct _GstGdkAnimation { - GdkPixbufAnimation parent; + GdkPixbufAnimation parent; /* name of temporary buffer file */ - gchar * temp_location; + gchar *temp_location; /* file descriptor to temporary file or 0 if we're done writing */ - int temp_fd; + int temp_fd; /* size of image */ - gint width; - gint height; - gint bpp; + gint width; + gint height; + gint bpp; /* static image we use */ - GdkPixbuf * pixbuf; + GdkPixbuf *pixbuf; }; -struct _GstGdkAnimationClass +struct _GstGdkAnimationClass { - GdkPixbufAnimationClass parent_class; + GdkPixbufAnimationClass parent_class; }; -GType gst_gdk_animation_get_type (void); +GType gst_gdk_animation_get_type (void); -GstGdkAnimation * gst_gdk_animation_new (GError **error); +GstGdkAnimation *gst_gdk_animation_new (GError ** error); -gboolean gst_gdk_animation_add_data (GstGdkAnimation * ani, - const guint8 * data, - guint size); -void gst_gdk_animation_done_adding (GstGdkAnimation * ani); +gboolean gst_gdk_animation_add_data (GstGdkAnimation * ani, + const guint8 * data, guint size); +void gst_gdk_animation_done_adding (GstGdkAnimation * ani); #define GST_TYPE_GDK_ANIMATION_ITER (gst_gdk_animation_iter_get_type ()) @@ -86,32 +81,35 @@ void gst_gdk_animation_done_adding (GstGdkAnimation * ani); #define GST_IS_GDK_ANIMATION_ITER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_GDK_ANIMATION_ITER)) #define GST_GDK_ANIMATION_ITER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_GDK_ANIMATION_ITER, GstGdkAnimationIterClass)) -struct _GstGdkAnimationIter { - GdkPixbufAnimationIter parent; - +struct _GstGdkAnimationIter +{ + GdkPixbufAnimationIter parent; + /* our animation */ - GstGdkAnimation * ani; + GstGdkAnimation *ani; /* start timeval */ - GTimeVal start; + GTimeVal start; /* timestamp of last buffer */ - GstClockTime last_timestamp; - + GstClockTime last_timestamp; + /* pipeline we're using */ - GstElement * pipeline; - gboolean eos; - gboolean just_seeked; - + GstElement *pipeline; + gboolean eos; + gboolean just_seeked; + /* current image and the buffers containing the data */ - GdkPixbuf * pixbuf; - GQueue * buffers; + GdkPixbuf *pixbuf; + GQueue *buffers; }; -struct _GstGdkAnimationIterClass { - GdkPixbufAnimationIterClass parent_class; +struct _GstGdkAnimationIterClass +{ + GdkPixbufAnimationIterClass parent_class; }; -GType gst_gdk_animation_iter_get_type (void) G_GNUC_CONST; +GType +gst_gdk_animation_iter_get_type (void) + G_GNUC_CONST; G_END_DECLS - #endif /* __GST_GDK_ANIMATION_H__ */ diff --git a/ext/gdk_pixbuf/gstgdkpixbuf.c b/ext/gdk_pixbuf/gstgdkpixbuf.c index 99d937bd..9691782d 100644 --- a/ext/gdk_pixbuf/gstgdkpixbuf.c +++ b/ext/gdk_pixbuf/gstgdkpixbuf.c @@ -41,78 +41,73 @@ static GstElementDetails plugin_details = { }; /* Filter signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_SILENT }; static GstStaticPadTemplate gst_gdk_pixbuf_sink_template = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ( - "image/png; " - "image/jpeg; " - "image/gif; " - "image/x-icon; " - "application/x-navi-animation; " - "image/x-cmu-raster; " - "image/x-sun-raster; " - "image/x-pixmap; " - "image/tiff; " - "image/x-portable-anymap; " - "image/x-portable-bitmap; " - "image/x-portable-graymap; " - "image/x-portable-pixmap; " - "image/bmp; " - "image/x-bmp; " - "image/x-MS-bmp; " - "image/vnd.wap.wbmp; " - "image/x-bitmap; " - "image/x-tga") -); + GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("image/png; " + "image/jpeg; " + "image/gif; " + "image/x-icon; " + "application/x-navi-animation; " + "image/x-cmu-raster; " + "image/x-sun-raster; " + "image/x-pixmap; " + "image/tiff; " + "image/x-portable-anymap; " + "image/x-portable-bitmap; " + "image/x-portable-graymap; " + "image/x-portable-pixmap; " + "image/bmp; " + "image/x-bmp; " + "image/x-MS-bmp; " + "image/vnd.wap.wbmp; " "image/x-bitmap; " "image/x-tga") + ); static GstStaticPadTemplate gst_gdk_pixbuf_src_template = -GST_STATIC_PAD_TEMPLATE ( - "src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB) -); - -static void gst_gdk_pixbuf_base_init (gpointer g_class); -static void gst_gdk_pixbuf_class_init (GstGdkPixbufClass *klass); -static void gst_gdk_pixbuf_init (GstGdkPixbuf *filter); - -static void gst_gdk_pixbuf_set_property(GObject *object, guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void gst_gdk_pixbuf_get_property(GObject *object, guint prop_id, - GValue *value, - GParamSpec *pspec); - -static void gst_gdk_pixbuf_chain (GstPad *pad, GstData *_data); +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB) + ); + +static void gst_gdk_pixbuf_base_init (gpointer g_class); +static void gst_gdk_pixbuf_class_init (GstGdkPixbufClass * klass); +static void gst_gdk_pixbuf_init (GstGdkPixbuf * filter); + +static void gst_gdk_pixbuf_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_gdk_pixbuf_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); + +static void gst_gdk_pixbuf_chain (GstPad * pad, GstData * _data); + #ifdef enable_typefind -static void gst_gdk_pixbuf_type_find (GstTypeFind *tf, gpointer ignore); +static void gst_gdk_pixbuf_type_find (GstTypeFind * tf, gpointer ignore); #endif static GstElementClass *parent_class = NULL; static GstPadLinkReturn -gst_gdk_pixbuf_sink_link (GstPad *pad, const GstCaps *caps) +gst_gdk_pixbuf_sink_link (GstPad * pad, const GstCaps * caps) { GstGdkPixbuf *filter; filter = GST_GDK_PIXBUF (gst_pad_get_parent (pad)); g_return_val_if_fail (filter != NULL, GST_PAD_LINK_REFUSED); - g_return_val_if_fail (GST_IS_GDK_PIXBUF (filter), - GST_PAD_LINK_REFUSED); + g_return_val_if_fail (GST_IS_GDK_PIXBUF (filter), GST_PAD_LINK_REFUSED); filter->framerate = 1.0; gst_structure_get_double (gst_caps_get_structure (caps, 0), "framerate", @@ -126,13 +121,15 @@ gst_gdk_pixbuf_sink_link (GstPad *pad, const GstCaps *caps) * These are just the formats that gdk-pixbuf is known to support. * But maybe not -- it may have been compiled without an external * library. */ -static GstCaps *gst_gdk_pixbuf_get_capslist(void) +static GstCaps * +gst_gdk_pixbuf_get_capslist (void) { - return gst_caps_copy (gst_static_caps_get ( - &gst_gdk_pixbuf_sink_template.static_caps)); + return gst_caps_copy (gst_static_caps_get (&gst_gdk_pixbuf_sink_template. + static_caps)); } #else -static GstCaps *gst_gdk_pixbuf_get_capslist(void) +static GstCaps * +gst_gdk_pixbuf_get_capslist (void) { GSList *slist; GSList *slist0; @@ -142,24 +139,24 @@ static GstCaps *gst_gdk_pixbuf_get_capslist(void) GstCaps *capslist = NULL; capslist = gst_caps_new_empty (); - slist0 = gdk_pixbuf_get_formats(); + slist0 = gdk_pixbuf_get_formats (); - for(slist = slist0;slist;slist=g_slist_next(slist)){ + for (slist = slist0; slist; slist = g_slist_next (slist)) { pixbuf_format = slist->data; - mimetypes = gdk_pixbuf_format_get_mime_types(pixbuf_format); - for(mimetype = mimetypes; *mimetype; mimetype++){ - gst_caps_append_structure (capslist, - gst_structure_new (*mimetype,NULL)); + mimetypes = gdk_pixbuf_format_get_mime_types (pixbuf_format); + for (mimetype = mimetypes; *mimetype; mimetype++) { + gst_caps_append_structure (capslist, gst_structure_new (*mimetype, NULL)); } - g_free(mimetypes); + g_free (mimetypes); } - g_slist_free(slist0); + g_slist_free (slist0); return capslist; } #endif -static GstCaps *gst_gdk_pixbuf_sink_getcaps(GstPad *pad) +static GstCaps * +gst_gdk_pixbuf_sink_getcaps (GstPad * pad) { GstGdkPixbuf *filter; @@ -167,7 +164,7 @@ static GstCaps *gst_gdk_pixbuf_sink_getcaps(GstPad *pad) g_return_val_if_fail (filter != NULL, NULL); g_return_val_if_fail (GST_IS_GDK_PIXBUF (filter), NULL); - return gst_gdk_pixbuf_get_capslist(); + return gst_gdk_pixbuf_get_capslist (); } GType @@ -175,10 +172,8 @@ gst_gdk_pixbuf_get_type (void) { static GType plugin_type = 0; - if (!plugin_type) - { - static const GTypeInfo plugin_info = - { + if (!plugin_type) { + static const GTypeInfo plugin_info = { sizeof (GstGdkPixbufClass), gst_gdk_pixbuf_base_init, NULL, @@ -190,8 +185,7 @@ gst_gdk_pixbuf_get_type (void) (GInstanceInitFunc) gst_gdk_pixbuf_init, }; plugin_type = g_type_register_static (GST_TYPE_ELEMENT, - "GstGdkPixbuf", - &plugin_info, 0); + "GstGdkPixbuf", &plugin_info, 0); } return plugin_type; } @@ -202,42 +196,44 @@ gst_gdk_pixbuf_base_init (gpointer g_class) GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get( &gst_gdk_pixbuf_src_template)); + gst_static_pad_template_get (&gst_gdk_pixbuf_src_template)); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get( &gst_gdk_pixbuf_sink_template)); + gst_static_pad_template_get (&gst_gdk_pixbuf_sink_template)); gst_element_class_set_details (element_class, &plugin_details); } /* initialize the plugin's class */ static void -gst_gdk_pixbuf_class_init (GstGdkPixbufClass *klass) +gst_gdk_pixbuf_class_init (GstGdkPixbufClass * 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); g_object_class_install_property (gobject_class, ARG_SILENT, - g_param_spec_boolean ("silent", "Silent", "Produce verbose output ?", - FALSE, G_PARAM_READWRITE)); + g_param_spec_boolean ("silent", "Silent", "Produce verbose output ?", + FALSE, G_PARAM_READWRITE)); gobject_class->set_property = gst_gdk_pixbuf_set_property; gobject_class->get_property = gst_gdk_pixbuf_get_property; } static void -gst_gdk_pixbuf_init (GstGdkPixbuf *filter) +gst_gdk_pixbuf_init (GstGdkPixbuf * filter) { - filter->sinkpad = gst_pad_new_from_template ( - gst_static_pad_template_get( &gst_gdk_pixbuf_sink_template), "sink"); + filter->sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_gdk_pixbuf_sink_template), "sink"); gst_pad_set_link_function (filter->sinkpad, gst_gdk_pixbuf_sink_link); gst_pad_set_getcaps_function (filter->sinkpad, gst_gdk_pixbuf_sink_getcaps); - filter->srcpad = gst_pad_new_from_template ( - gst_static_pad_template_get( &gst_gdk_pixbuf_src_template), "src"); + filter->srcpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_gdk_pixbuf_src_template), "src"); gst_pad_use_explicit_caps (filter->srcpad); gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad); @@ -248,7 +244,7 @@ gst_gdk_pixbuf_init (GstGdkPixbuf *filter) } static void -gst_gdk_pixbuf_chain (GstPad *pad, GstData *_data) +gst_gdk_pixbuf_chain (GstPad * pad, GstData * _data) { GstBuffer *buf = GST_BUFFER (_data); GstGdkPixbuf *filter; @@ -270,15 +266,15 @@ gst_gdk_pixbuf_chain (GstPad *pad, GstData *_data) switch (GST_EVENT_TYPE (event)) { case GST_EVENT_EOS: - push_buffer = TRUE; - got_eos = TRUE; - break; + push_buffer = TRUE; + got_eos = TRUE; + break; case GST_EVENT_DISCONTINUOUS: - dump_buffer = TRUE; - break; + dump_buffer = TRUE; + break; default: - gst_pad_event_default (pad, event); - return; + gst_pad_event_default (pad, event); + return; } } @@ -293,41 +289,41 @@ gst_gdk_pixbuf_chain (GstPad *pad, GstData *_data) GError *error = NULL; if (!gdk_pixbuf_loader_close (filter->pixbuf_loader, &error)) { - GST_ELEMENT_ERROR (filter, LIBRARY, SHUTDOWN, (NULL), (error->message)); - g_error_free (error); - return; + GST_ELEMENT_ERROR (filter, LIBRARY, SHUTDOWN, (NULL), (error->message)); + g_error_free (error); + return; } pixbuf = gdk_pixbuf_loader_get_pixbuf (filter->pixbuf_loader); - if(filter->image_size == 0){ - GstCaps *caps; + if (filter->image_size == 0) { + GstCaps *caps; - filter->width = gdk_pixbuf_get_width(pixbuf); - filter->height = gdk_pixbuf_get_height(pixbuf); - filter->rowstride = gdk_pixbuf_get_rowstride(pixbuf); - filter->image_size = filter->rowstride * filter->height; + filter->width = gdk_pixbuf_get_width (pixbuf); + filter->height = gdk_pixbuf_get_height (pixbuf); + filter->rowstride = gdk_pixbuf_get_rowstride (pixbuf); + filter->image_size = filter->rowstride * filter->height; - caps = gst_caps_copy (gst_pad_get_pad_template_caps (filter->srcpad)); - gst_caps_set_simple (caps, - "width", G_TYPE_INT, filter->width, - "height", G_TYPE_INT, filter->height, - "framerate", G_TYPE_DOUBLE, filter->framerate, NULL); + caps = gst_caps_copy (gst_pad_get_pad_template_caps (filter->srcpad)); + gst_caps_set_simple (caps, + "width", G_TYPE_INT, filter->width, + "height", G_TYPE_INT, filter->height, + "framerate", G_TYPE_DOUBLE, filter->framerate, NULL); - gst_pad_set_explicit_caps (filter->srcpad, caps); + gst_pad_set_explicit_caps (filter->srcpad, caps); } outbuf = gst_pad_alloc_buffer (filter->srcpad, GST_BUFFER_OFFSET_NONE, - filter->image_size); - GST_BUFFER_TIMESTAMP(outbuf) = GST_BUFFER_TIMESTAMP(buf); - GST_BUFFER_DURATION(outbuf) = GST_BUFFER_DURATION(buf); - - memcpy(GST_BUFFER_DATA(outbuf), gdk_pixbuf_get_pixels(pixbuf), - filter->image_size); + filter->image_size); + GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf); + GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buf); + + memcpy (GST_BUFFER_DATA (outbuf), gdk_pixbuf_get_pixels (pixbuf), + filter->image_size); gst_pad_push (filter->srcpad, GST_DATA (outbuf)); - g_object_unref(G_OBJECT(filter->pixbuf_loader)); + g_object_unref (G_OBJECT (filter->pixbuf_loader)); filter->pixbuf_loader = NULL; dump_buffer = FALSE; } @@ -336,19 +332,19 @@ gst_gdk_pixbuf_chain (GstPad *pad, GstData *_data) if (dump_buffer) { if (filter->pixbuf_loader != NULL) { gdk_pixbuf_loader_close (filter->pixbuf_loader, NULL); - g_object_unref(G_OBJECT(filter->pixbuf_loader)); + g_object_unref (G_OBJECT (filter->pixbuf_loader)); filter->pixbuf_loader = NULL; } } if (GST_IS_BUFFER (_data)) { if (filter->pixbuf_loader == NULL) { - filter->pixbuf_loader = gdk_pixbuf_loader_new(); + filter->pixbuf_loader = gdk_pixbuf_loader_new (); filter->last_timestamp = GST_BUFFER_TIMESTAMP (buf); } - - gdk_pixbuf_loader_write(filter->pixbuf_loader, GST_BUFFER_DATA(buf), - GST_BUFFER_SIZE(buf), &error); + + gdk_pixbuf_loader_write (filter->pixbuf_loader, GST_BUFFER_DATA (buf), + GST_BUFFER_SIZE (buf), &error); gst_buffer_unref (buf); } @@ -358,28 +354,27 @@ gst_gdk_pixbuf_chain (GstPad *pad, GstData *_data) } static void -gst_gdk_pixbuf_set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec) +gst_gdk_pixbuf_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) { GstGdkPixbuf *filter; g_return_if_fail (GST_IS_GDK_PIXBUF (object)); filter = GST_GDK_PIXBUF (object); - switch (prop_id) - { - case ARG_SILENT: - //filter->silent = g_value_get_boolean (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; + switch (prop_id) { + case ARG_SILENT: + //filter->silent = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; } } static void -gst_gdk_pixbuf_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) +gst_gdk_pixbuf_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) { GstGdkPixbuf *filter; @@ -387,12 +382,12 @@ gst_gdk_pixbuf_get_property (GObject *object, guint prop_id, filter = GST_GDK_PIXBUF (object); switch (prop_id) { - case ARG_SILENT: - //g_value_set_boolean (value, filter->silent); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; + case ARG_SILENT: + //g_value_set_boolean (value, filter->silent); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; } } @@ -400,22 +395,23 @@ gst_gdk_pixbuf_get_property (GObject *object, guint prop_id, #ifdef enable_typefind static void -gst_gdk_pixbuf_type_find (GstTypeFind *tf, gpointer ignore) +gst_gdk_pixbuf_type_find (GstTypeFind * tf, gpointer ignore) { guint8 *data; GdkPixbufLoader *pixbuf_loader; GdkPixbufFormat *format; data = gst_type_find_peek (tf, 0, GST_GDK_PIXBUF_TYPE_FIND_SIZE); - if (data == NULL) return; + if (data == NULL) + return; GST_DEBUG ("creating new loader"); - pixbuf_loader = gdk_pixbuf_loader_new(); - + pixbuf_loader = gdk_pixbuf_loader_new (); + gdk_pixbuf_loader_write (pixbuf_loader, data, GST_GDK_PIXBUF_TYPE_FIND_SIZE, NULL); - + format = gdk_pixbuf_loader_get_format (pixbuf_loader); if (format != NULL) { @@ -423,8 +419,7 @@ gst_gdk_pixbuf_type_find (GstTypeFind *tf, gpointer ignore) gchar **p; gchar **mlist = gdk_pixbuf_format_get_mime_types (format); - for (p = mlist; *p; ++p) - { + for (p = mlist; *p; ++p) { GST_DEBUG ("suggesting mime type %s", *p); caps = gst_caps_new_simple (*p, NULL); gst_type_find_suggest (tf, GST_TYPE_FIND_MINIMUM, caps); @@ -449,17 +444,18 @@ gst_gdk_pixbuf_type_find (GstTypeFind *tf, gpointer ignore) * register the features */ static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { - GST_DEBUG_CATEGORY_INIT (gst_gdk_pixbuf_debug, "gdkpixbuf", 0, "gdk pixbuf loader"); + GST_DEBUG_CATEGORY_INIT (gst_gdk_pixbuf_debug, "gdkpixbuf", 0, + "gdk pixbuf loader"); - if (!gst_element_register (plugin, "gdkpixbufdec", GST_RANK_NONE, GST_TYPE_GDK_PIXBUF)) + if (!gst_element_register (plugin, "gdkpixbufdec", GST_RANK_NONE, + GST_TYPE_GDK_PIXBUF)) return FALSE; #ifdef enable_typefind gst_type_find_register (plugin, "image/*", GST_RANK_MARGINAL, - gst_gdk_pixbuf_type_find, NULL, - GST_CAPS_ANY, NULL); + gst_gdk_pixbuf_type_find, NULL, GST_CAPS_ANY, NULL); #endif /* plugin initialisation succeeded */ @@ -468,13 +464,7 @@ plugin_init (GstPlugin *plugin) /* this is the structure that gst-register looks for * so keep the name plugin_desc, or you cannot get your plug-in registered */ -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "gdkpixbuf", - "GDK Pixbuf decoder", - plugin_init, - VERSION, - "LGPL", - GST_PACKAGE, - GST_ORIGIN) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "gdkpixbuf", + "GDK Pixbuf decoder", plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN) diff --git a/ext/gdk_pixbuf/gstgdkpixbuf.h b/ext/gdk_pixbuf/gstgdkpixbuf.h index 62e11aac..f239bf72 100644 --- a/ext/gdk_pixbuf/gstgdkpixbuf.h +++ b/ext/gdk_pixbuf/gstgdkpixbuf.h @@ -26,7 +26,6 @@ #include <gst/gst.h> G_BEGIN_DECLS - /* #define's don't like whitespacey bits */ #define GST_TYPE_GDK_PIXBUF \ (gst_gdk_pixbuf_get_type()) @@ -38,8 +37,7 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GDK_PIXBUF)) #define GST_IS_GDK_PIXBUF_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_GDK_PIXBUF)) - -typedef struct _GstGdkPixbuf GstGdkPixbuf; +typedef struct _GstGdkPixbuf GstGdkPixbuf; typedef struct _GstGdkPixbufClass GstGdkPixbufClass; struct _GstGdkPixbuf @@ -48,7 +46,7 @@ struct _GstGdkPixbuf GstPad *sinkpad, *srcpad; - GstClockTime last_timestamp; + GstClockTime last_timestamp; GdkPixbufLoader *pixbuf_loader; int width; @@ -59,7 +57,7 @@ struct _GstGdkPixbuf double framerate; }; -struct _GstGdkPixbufClass +struct _GstGdkPixbufClass { GstElementClass parent_class; }; @@ -67,5 +65,4 @@ struct _GstGdkPixbufClass GType gst_gdk_pixbuf_get_type (void); G_END_DECLS - #endif /* __GST_GDK_PIXBUF_H__ */ diff --git a/ext/jpeg/gstjpeg.c b/ext/jpeg/gstjpeg.c index 1a78b222..add7435e 100644 --- a/ext/jpeg/gstjpeg.c +++ b/ext/jpeg/gstjpeg.c @@ -24,24 +24,21 @@ #include "gstjpegenc.h" static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { - if (!gst_element_register (plugin, "jpegenc", GST_RANK_NONE, GST_TYPE_JPEGENC)) + if (!gst_element_register (plugin, "jpegenc", GST_RANK_NONE, + GST_TYPE_JPEGENC)) return FALSE; - - if (!gst_element_register (plugin, "jpegdec", GST_RANK_PRIMARY, GST_TYPE_JPEGDEC)) + + if (!gst_element_register (plugin, "jpegdec", GST_RANK_PRIMARY, + GST_TYPE_JPEGDEC)) return FALSE; - + return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "jpeg", - "JPeg plugin library", - plugin_init, - VERSION, - "LGPL", - GST_PACKAGE, - GST_ORIGIN) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "jpeg", + "JPeg plugin library", + plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN) diff --git a/ext/jpeg/gstjpegdec.c b/ext/jpeg/gstjpegdec.c index 0a1bb60d..10156559 100644 --- a/ext/jpeg/gstjpegdec.c +++ b/ext/jpeg/gstjpegdec.c @@ -36,73 +36,74 @@ GstElementDetails gst_jpegdec_details = { }; /* JpegDec signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, /* FILL ME */ }; -static void gst_jpegdec_base_init (gpointer g_class); -static void gst_jpegdec_class_init (GstJpegDec *klass); -static void gst_jpegdec_init (GstJpegDec *jpegdec); +static void gst_jpegdec_base_init (gpointer g_class); +static void gst_jpegdec_class_init (GstJpegDec * klass); +static void gst_jpegdec_init (GstJpegDec * jpegdec); -static void gst_jpegdec_chain (GstPad *pad, GstData *_data); -static GstPadLinkReturn - gst_jpegdec_link (GstPad *pad, const GstCaps *caps); +static void gst_jpegdec_chain (GstPad * pad, GstData * _data); +static GstPadLinkReturn gst_jpegdec_link (GstPad * pad, const GstCaps * caps); static GstElementClass *parent_class = NULL; + /*static guint gst_jpegdec_signals[LAST_SIGNAL] = { 0 }; */ GType -gst_jpegdec_get_type(void) { +gst_jpegdec_get_type (void) +{ static GType jpegdec_type = 0; - + if (!jpegdec_type) { static const GTypeInfo jpegdec_info = { - sizeof(GstJpegDec), + sizeof (GstJpegDec), gst_jpegdec_base_init, NULL, - (GClassInitFunc)gst_jpegdec_class_init, + (GClassInitFunc) gst_jpegdec_class_init, NULL, NULL, - sizeof(GstJpegDec), + sizeof (GstJpegDec), 0, - (GInstanceInitFunc)gst_jpegdec_init, + (GInstanceInitFunc) gst_jpegdec_init, }; - jpegdec_type = g_type_register_static(GST_TYPE_ELEMENT, "GstJpegDec", &jpegdec_info, 0); + jpegdec_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstJpegDec", &jpegdec_info, + 0); } return jpegdec_type; } static GstStaticPadTemplate gst_jpegdec_src_pad_template = -GST_STATIC_PAD_TEMPLATE ( - "src", +GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV("I420")) -); + GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420")) + ); static GstStaticPadTemplate gst_jpegdec_sink_pad_template = -GST_STATIC_PAD_TEMPLATE ( - "sink", +GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS ("image/jpeg, " - "width = (int) [ 16, 4096 ], " - "height = (int) [ 16, 4096 ], " - "framerate = (double) [ 1, MAX ]" - ) -); + "width = (int) [ 16, 4096 ], " + "height = (int) [ 16, 4096 ], " "framerate = (double) [ 1, MAX ]") + ); static void gst_jpegdec_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - + gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&gst_jpegdec_src_pad_template)); gst_element_class_add_pad_template (element_class, @@ -111,13 +112,13 @@ gst_jpegdec_base_init (gpointer g_class) } static void -gst_jpegdec_class_init (GstJpegDec *klass) +gst_jpegdec_class_init (GstJpegDec * klass) { GstElementClass *gstelement_class; - gstelement_class = (GstElementClass*)klass; + gstelement_class = (GstElementClass *) klass; - parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + parent_class = g_type_class_ref (GST_TYPE_ELEMENT); } static void @@ -125,6 +126,7 @@ gst_jpegdec_init_source (j_decompress_ptr cinfo) { GST_DEBUG ("gst_jpegdec_chain: init_source"); } + static gboolean gst_jpegdec_fill_input_buffer (j_decompress_ptr cinfo) { @@ -152,21 +154,23 @@ gst_jpegdec_term_source (j_decompress_ptr cinfo) } static void -gst_jpegdec_init (GstJpegDec *jpegdec) +gst_jpegdec_init (GstJpegDec * jpegdec) { GST_DEBUG ("gst_jpegdec_init: initializing"); /* create the sink and src pads */ - jpegdec->sinkpad = gst_pad_new_from_template ( - gst_static_pad_template_get (&gst_jpegdec_sink_pad_template), "sink"); - gst_element_add_pad(GST_ELEMENT(jpegdec),jpegdec->sinkpad); - gst_pad_set_chain_function(jpegdec->sinkpad,gst_jpegdec_chain); - gst_pad_set_link_function(jpegdec->sinkpad, gst_jpegdec_link); + jpegdec->sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_jpegdec_sink_pad_template), "sink"); + gst_element_add_pad (GST_ELEMENT (jpegdec), jpegdec->sinkpad); + gst_pad_set_chain_function (jpegdec->sinkpad, gst_jpegdec_chain); + gst_pad_set_link_function (jpegdec->sinkpad, gst_jpegdec_link); - jpegdec->srcpad = gst_pad_new_from_template ( - gst_static_pad_template_get (&gst_jpegdec_src_pad_template), "src"); + jpegdec->srcpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_jpegdec_src_pad_template), "src"); gst_pad_use_explicit_caps (jpegdec->srcpad); - gst_element_add_pad(GST_ELEMENT(jpegdec),jpegdec->srcpad); + gst_element_add_pad (GST_ELEMENT (jpegdec), jpegdec->srcpad); /* initialize the jpegdec decoder state */ jpegdec->next_time = 0; @@ -181,10 +185,10 @@ gst_jpegdec_init (GstJpegDec *jpegdec) jpegdec->line[2] = NULL; /* setup jpeglib */ - memset(&jpegdec->cinfo, 0, sizeof(jpegdec->cinfo)); - memset(&jpegdec->jerr, 0, sizeof(jpegdec->jerr)); - jpegdec->cinfo.err = jpeg_std_error(&jpegdec->jerr); - jpeg_create_decompress(&jpegdec->cinfo); + memset (&jpegdec->cinfo, 0, sizeof (jpegdec->cinfo)); + memset (&jpegdec->jerr, 0, sizeof (jpegdec->jerr)); + jpegdec->cinfo.err = jpeg_std_error (&jpegdec->jerr); + jpeg_create_decompress (&jpegdec->cinfo); jpegdec->jsrc.init_source = gst_jpegdec_init_source; jpegdec->jsrc.fill_input_buffer = gst_jpegdec_fill_input_buffer; @@ -196,7 +200,7 @@ gst_jpegdec_init (GstJpegDec *jpegdec) } static GstPadLinkReturn -gst_jpegdec_link (GstPad *pad, const GstCaps *caps) +gst_jpegdec_link (GstPad * pad, const GstCaps * caps) { GstJpegDec *jpegdec = GST_JPEGDEC (gst_pad_get_parent (pad)); GstStructure *structure; @@ -205,15 +209,14 @@ gst_jpegdec_link (GstPad *pad, const GstCaps *caps) structure = gst_caps_get_structure (caps, 0); gst_structure_get_double (structure, "framerate", &jpegdec->fps); - gst_structure_get_int (structure, "width", &jpegdec->width); - gst_structure_get_int (structure, "height", &jpegdec->height); + gst_structure_get_int (structure, "width", &jpegdec->width); + gst_structure_get_int (structure, "height", &jpegdec->height); srccaps = gst_caps_new_simple ("video/x-raw-yuv", - "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I','4','2','0'), - "width", G_TYPE_INT, jpegdec->width, - "height", G_TYPE_INT, jpegdec->height, - "framerate", G_TYPE_DOUBLE, jpegdec->fps, - NULL); + "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I', '4', '2', '0'), + "width", G_TYPE_INT, jpegdec->width, + "height", G_TYPE_INT, jpegdec->height, + "framerate", G_TYPE_DOUBLE, jpegdec->fps, NULL); /* at this point, we're pretty sure that this will be the output * format, so we'll set it. */ @@ -223,18 +226,18 @@ gst_jpegdec_link (GstPad *pad, const GstCaps *caps) } /* shamelessly ripped from jpegutils.c in mjpegtools */ -static void add_huff_table (j_decompress_ptr dinfo, - JHUFF_TBL **htblptr, - const UINT8 *bits, const UINT8 *val) +static void +add_huff_table (j_decompress_ptr dinfo, + JHUFF_TBL ** htblptr, const UINT8 * bits, const UINT8 * val) /* Define a Huffman table */ { int nsymbols, len; if (*htblptr == NULL) - *htblptr = jpeg_alloc_huff_table((j_common_ptr) dinfo); + *htblptr = jpeg_alloc_huff_table ((j_common_ptr) dinfo); /* Copy the number-of-symbols-of-each-code-length counts */ - memcpy((*htblptr)->bits, bits, sizeof((*htblptr)->bits)); + memcpy ((*htblptr)->bits, bits, sizeof ((*htblptr)->bits)); /* Validate the counts. We do this here mainly so we can copy the right * number of symbols from the val[] array, without risking marching off @@ -244,119 +247,123 @@ static void add_huff_table (j_decompress_ptr dinfo, for (len = 1; len <= 16; len++) nsymbols += bits[len]; if (nsymbols < 1 || nsymbols > 256) - g_error("jpegutils.c: add_huff_table failed badly. "); + g_error ("jpegutils.c: add_huff_table failed badly. "); - memcpy((*htblptr)->huffval, val, nsymbols * sizeof(UINT8)); + memcpy ((*htblptr)->huffval, val, nsymbols * sizeof (UINT8)); } -static void std_huff_tables (j_decompress_ptr dinfo) +static void +std_huff_tables (j_decompress_ptr dinfo) /* Set up the standard Huffman tables (cf. JPEG standard section K.3) */ /* IMPORTANT: these are only valid for 8-bit data precision! */ { static const UINT8 bits_dc_luminance[17] = - { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }; + { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }; static const UINT8 val_dc_luminance[] = - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; - + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + static const UINT8 bits_dc_chrominance[17] = - { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; + { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; static const UINT8 val_dc_chrominance[] = - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; - + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + static const UINT8 bits_ac_luminance[17] = - { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d }; + { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d }; static const UINT8 val_ac_luminance[] = - { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, - 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, - 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, - 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, - 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, - 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, - 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, - 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, - 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, - 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, - 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, - 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, - 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, - 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, - 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, - 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, - 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, - 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, - 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, - 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, - 0xf9, 0xfa }; - + { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, + 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, + 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, + 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, + 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, + 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, + 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, + 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, + 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, + 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, + 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, + 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, + 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, + 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, + 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, + 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, + 0xf9, 0xfa + }; + static const UINT8 bits_ac_chrominance[17] = - { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 }; + { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 }; static const UINT8 val_ac_chrominance[] = - { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, - 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, - 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, - 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, - 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, - 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, - 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, - 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, - 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, - 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, - 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, - 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, - 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, - 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, - 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, - 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, - 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, - 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, - 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, - 0xf9, 0xfa }; - - add_huff_table(dinfo, &dinfo->dc_huff_tbl_ptrs[0], - bits_dc_luminance, val_dc_luminance); - add_huff_table(dinfo, &dinfo->ac_huff_tbl_ptrs[0], - bits_ac_luminance, val_ac_luminance); - add_huff_table(dinfo, &dinfo->dc_huff_tbl_ptrs[1], - bits_dc_chrominance, val_dc_chrominance); - add_huff_table(dinfo, &dinfo->ac_huff_tbl_ptrs[1], - bits_ac_chrominance, val_ac_chrominance); + { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, + 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, + 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, + 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, + 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, + 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, + 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, + 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, + 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, + 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, + 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, + 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, + 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, + 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, + 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, + 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, + 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, + 0xf9, 0xfa + }; + + add_huff_table (dinfo, &dinfo->dc_huff_tbl_ptrs[0], + bits_dc_luminance, val_dc_luminance); + add_huff_table (dinfo, &dinfo->ac_huff_tbl_ptrs[0], + bits_ac_luminance, val_ac_luminance); + add_huff_table (dinfo, &dinfo->dc_huff_tbl_ptrs[1], + bits_dc_chrominance, val_dc_chrominance); + add_huff_table (dinfo, &dinfo->ac_huff_tbl_ptrs[1], + bits_ac_chrominance, val_ac_chrominance); } -static void guarantee_huff_tables(j_decompress_ptr dinfo) +static void +guarantee_huff_tables (j_decompress_ptr dinfo) { - if ( (dinfo->dc_huff_tbl_ptrs[0] == NULL) && - (dinfo->dc_huff_tbl_ptrs[1] == NULL) && - (dinfo->ac_huff_tbl_ptrs[0] == NULL) && - (dinfo->ac_huff_tbl_ptrs[1] == NULL) ) { - GST_DEBUG ( - "Generating standard Huffman tables for this frame."); - std_huff_tables(dinfo); + if ((dinfo->dc_huff_tbl_ptrs[0] == NULL) && + (dinfo->dc_huff_tbl_ptrs[1] == NULL) && + (dinfo->ac_huff_tbl_ptrs[0] == NULL) && + (dinfo->ac_huff_tbl_ptrs[1] == NULL)) { + GST_DEBUG ("Generating standard Huffman tables for this frame."); + std_huff_tables (dinfo); } } static void -gst_jpegdec_chain (GstPad *pad, GstData *_data) +gst_jpegdec_chain (GstPad * pad, GstData * _data) { GstBuffer *buf = GST_BUFFER (_data); GstJpegDec *jpegdec; guchar *data, *outdata; gulong size, outsize; GstBuffer *outbuf; - /*GstMeta *meta;*/ + + /*GstMeta *meta; */ gint width, height, width2; guchar *base[3]; - gint i,j, k; + gint i, j, k; gint r_h, r_v; - g_return_if_fail(pad != NULL); - g_return_if_fail(GST_IS_PAD(pad)); - g_return_if_fail(buf != NULL); - /*g_return_if_fail(GST_IS_BUFFER(buf));*/ + g_return_if_fail (pad != NULL); + g_return_if_fail (GST_IS_PAD (pad)); + g_return_if_fail (buf != NULL); + /*g_return_if_fail(GST_IS_BUFFER(buf)); */ jpegdec = GST_JPEGDEC (GST_OBJECT_PARENT (pad)); @@ -365,24 +372,24 @@ gst_jpegdec_chain (GstPad *pad, GstData *_data) return; } - data = (guchar *)GST_BUFFER_DATA(buf); - size = GST_BUFFER_SIZE(buf); - GST_DEBUG ("gst_jpegdec_chain: got buffer of %ld bytes in '%s'",size, - GST_OBJECT_NAME (jpegdec)); + data = (guchar *) GST_BUFFER_DATA (buf); + size = GST_BUFFER_SIZE (buf); + GST_DEBUG ("gst_jpegdec_chain: got buffer of %ld bytes in '%s'", size, + GST_OBJECT_NAME (jpegdec)); jpegdec->jsrc.next_input_byte = data; jpegdec->jsrc.bytes_in_buffer = size; - - GST_DEBUG ("gst_jpegdec_chain: reading header %08lx", *(gulong *)data); - jpeg_read_header(&jpegdec->cinfo, TRUE); + + GST_DEBUG ("gst_jpegdec_chain: reading header %08lx", *(gulong *) data); + jpeg_read_header (&jpegdec->cinfo, TRUE); r_h = jpegdec->cinfo.cur_comp_info[0]->h_samp_factor; r_v = jpegdec->cinfo.cur_comp_info[0]->v_samp_factor; - /*g_print ("%d %d\n", r_h, r_v);*/ - /*g_print ("%d %d\n", jpegdec->cinfo.cur_comp_info[1]->h_samp_factor, jpegdec->cinfo.cur_comp_info[1]->v_samp_factor);*/ - /*g_print ("%d %d\n", jpegdec->cinfo.cur_comp_info[2]->h_samp_factor, jpegdec->cinfo.cur_comp_info[2]->v_samp_factor);*/ + /*g_print ("%d %d\n", r_h, r_v); */ + /*g_print ("%d %d\n", jpegdec->cinfo.cur_comp_info[1]->h_samp_factor, jpegdec->cinfo.cur_comp_info[1]->v_samp_factor); */ + /*g_print ("%d %d\n", jpegdec->cinfo.cur_comp_info[2]->h_samp_factor, jpegdec->cinfo.cur_comp_info[2]->v_samp_factor); */ jpegdec->cinfo.do_fancy_upsampling = FALSE; jpegdec->cinfo.do_block_smoothing = FALSE; @@ -390,66 +397,67 @@ gst_jpegdec_chain (GstPad *pad, GstData *_data) jpegdec->cinfo.dct_method = JDCT_IFAST; jpegdec->cinfo.raw_data_out = TRUE; GST_DEBUG ("gst_jpegdec_chain: starting decompress"); - guarantee_huff_tables(&jpegdec->cinfo); - jpeg_start_decompress(&jpegdec->cinfo); + guarantee_huff_tables (&jpegdec->cinfo); + jpeg_start_decompress (&jpegdec->cinfo); width = jpegdec->cinfo.output_width; height = jpegdec->cinfo.output_height; GST_DEBUG ("gst_jpegdec_chain: width %d, height %d", width, height); - outbuf = gst_buffer_new(); - outsize = GST_BUFFER_SIZE(outbuf) = width*height + - width*height / 2; - outdata = GST_BUFFER_DATA(outbuf) = g_malloc(outsize); - GST_BUFFER_TIMESTAMP(outbuf) = GST_BUFFER_TIMESTAMP(buf); + outbuf = gst_buffer_new (); + outsize = GST_BUFFER_SIZE (outbuf) = width * height + width * height / 2; + outdata = GST_BUFFER_DATA (outbuf) = g_malloc (outsize); + GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf); if (jpegdec->height != height || jpegdec->line[0] == NULL) { GstCaps *caps; - jpegdec->line[0] = g_realloc(jpegdec->line[0], height*sizeof(char*)); - jpegdec->line[1] = g_realloc(jpegdec->line[1], height*sizeof(char*)); - jpegdec->line[2] = g_realloc(jpegdec->line[2], height*sizeof(char*)); + jpegdec->line[0] = g_realloc (jpegdec->line[0], height * sizeof (char *)); + jpegdec->line[1] = g_realloc (jpegdec->line[1], height * sizeof (char *)); + jpegdec->line[2] = g_realloc (jpegdec->line[2], height * sizeof (char *)); jpegdec->height = height; caps = gst_caps_new_simple ("video/x-raw-yuv", - "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I','4','2','0'), - "width", G_TYPE_INT, width, - "height", G_TYPE_INT, height, - "framerate", G_TYPE_DOUBLE, jpegdec->fps, - NULL); + "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I', '4', '2', '0'), + "width", G_TYPE_INT, width, + "height", G_TYPE_INT, height, + "framerate", G_TYPE_DOUBLE, jpegdec->fps, NULL); gst_pad_set_explicit_caps (jpegdec->srcpad, caps); gst_caps_free (caps); } /* mind the swap, jpeglib outputs blue chroma first */ base[0] = outdata; - base[1] = base[0]+width*height; - base[2] = base[1]+width*height/4; + base[1] = base[0] + width * height; + base[2] = base[1] + width * height / 4; width2 = width >> 1; - GST_DEBUG ("gst_jpegdec_chain: decompressing %u", jpegdec->cinfo.rec_outbuf_height); - for (i = 0; i < height; i += r_v*DCTSIZE) { - for (j=0, k=0; j< (r_v*DCTSIZE); j += r_v, k++) { - jpegdec->line[0][j] = base[0]; base[0] += width; + GST_DEBUG ("gst_jpegdec_chain: decompressing %u", + jpegdec->cinfo.rec_outbuf_height); + for (i = 0; i < height; i += r_v * DCTSIZE) { + for (j = 0, k = 0; j < (r_v * DCTSIZE); j += r_v, k++) { + jpegdec->line[0][j] = base[0]; + base[0] += width; if (r_v == 2) { - jpegdec->line[0][j+1] = base[0]; base[0] += width; + jpegdec->line[0][j + 1] = base[0]; + base[0] += width; } - jpegdec->line[1][k] = base[1]; - jpegdec->line[2][k] = base[2]; - if (r_v == 2 || k&1) { - base[1] += width2; base[2] += width2; + jpegdec->line[1][k] = base[1]; + jpegdec->line[2][k] = base[2]; + if (r_v == 2 || k & 1) { + base[1] += width2; + base[2] += width2; } } - /*g_print ("%d\n", jpegdec->cinfo.output_scanline);*/ - jpeg_read_raw_data(&jpegdec->cinfo, jpegdec->line, r_v*DCTSIZE); + /*g_print ("%d\n", jpegdec->cinfo.output_scanline); */ + jpeg_read_raw_data (&jpegdec->cinfo, jpegdec->line, r_v * DCTSIZE); } GST_DEBUG ("gst_jpegdec_chain: decompressing finished"); - jpeg_finish_decompress(&jpegdec->cinfo); + jpeg_finish_decompress (&jpegdec->cinfo); GST_DEBUG ("gst_jpegdec_chain: sending buffer"); - gst_pad_push(jpegdec->srcpad, GST_DATA (outbuf)); + gst_pad_push (jpegdec->srcpad, GST_DATA (outbuf)); - gst_buffer_unref(buf); + gst_buffer_unref (buf); } - diff --git a/ext/jpeg/gstjpegdec.h b/ext/jpeg/gstjpegdec.h index 05187873..9a864eba 100644 --- a/ext/jpeg/gstjpegdec.h +++ b/ext/jpeg/gstjpegdec.h @@ -30,8 +30,9 @@ #include <jpeglib.h> #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define GST_TYPE_JPEGDEC \ @@ -45,46 +46,48 @@ extern "C" { #define GST_IS_JPEGDEC_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_JPEGDEC)) -typedef struct _GstJpegDec GstJpegDec; -typedef struct _GstJpegDecClass GstJpegDecClass; + typedef struct _GstJpegDec GstJpegDec; + typedef struct _GstJpegDecClass GstJpegDecClass; -struct _GstJpegDec { - GstElement element; + struct _GstJpegDec + { + GstElement element; - /* pads */ - GstPad *sinkpad,*srcpad; + /* pads */ + GstPad *sinkpad, *srcpad; - int parse_state; - /* the timestamp of the next frame */ - guint64 next_time; - /* the interval between frames */ - guint64 time_interval; + int parse_state; + /* the timestamp of the next frame */ + guint64 next_time; + /* the interval between frames */ + guint64 time_interval; - /* video state */ - gint format; - gint width; - gint height; - gdouble fps; - /* the size of the output buffer */ - gint outsize; - /* the jpeg line buffer */ - guchar **line[3]; + /* video state */ + gint format; + gint width; + gint height; + gdouble fps; + /* the size of the output buffer */ + gint outsize; + /* the jpeg line buffer */ + guchar **line[3]; - struct jpeg_decompress_struct cinfo; - struct jpeg_error_mgr jerr; - struct jpeg_source_mgr jsrc; -}; + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + struct jpeg_source_mgr jsrc; + }; -struct _GstJpegDecClass { - GstElementClass parent_class; -}; + struct _GstJpegDecClass + { + GstElementClass parent_class; + }; -GType gst_jpegdec_get_type(void); + GType gst_jpegdec_get_type (void); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __GST_JPEGDEC_H__ */ +#endif /* __GST_JPEGDEC_H__ */ diff --git a/ext/jpeg/gstjpegenc.c b/ext/jpeg/gstjpegenc.c index 7f43ea97..44941719 100644 --- a/ext/jpeg/gstjpegenc.c +++ b/ext/jpeg/gstjpegenc.c @@ -35,30 +35,34 @@ GstElementDetails gst_jpegenc_details = { }; /* JpegEnc signals and args */ -enum { +enum +{ FRAME_ENCODED, /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_QUALITY, ARG_SMOOTHING, /* FILL ME */ }; -static void gst_jpegenc_base_init (gpointer g_class); -static void gst_jpegenc_class_init (GstJpegEnc *klass); -static void gst_jpegenc_init (GstJpegEnc *jpegenc); +static void gst_jpegenc_base_init (gpointer g_class); +static void gst_jpegenc_class_init (GstJpegEnc * klass); +static void gst_jpegenc_init (GstJpegEnc * jpegenc); -static void gst_jpegenc_chain (GstPad *pad, GstData *_data); -static GstPadLinkReturn gst_jpegenc_link (GstPad *pad, const GstCaps *caps); -static GstCaps * gst_jpegenc_getcaps (GstPad *pad); +static void gst_jpegenc_chain (GstPad * pad, GstData * _data); +static GstPadLinkReturn gst_jpegenc_link (GstPad * pad, const GstCaps * caps); +static GstCaps *gst_jpegenc_getcaps (GstPad * pad); -static void gst_jpegenc_resync (GstJpegEnc *jpegenc); -static void gst_jpegenc_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); -static void gst_jpegenc_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); +static void gst_jpegenc_resync (GstJpegEnc * jpegenc); +static void gst_jpegenc_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_jpegenc_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); static GstElementClass *parent_class = NULL; static guint gst_jpegenc_signals[LAST_SIGNAL] = { 0 }; @@ -70,46 +74,44 @@ gst_jpegenc_get_type (void) if (!jpegenc_type) { static const GTypeInfo jpegenc_info = { - sizeof(GstJpegEnc), + sizeof (GstJpegEnc), gst_jpegenc_base_init, NULL, - (GClassInitFunc)gst_jpegenc_class_init, + (GClassInitFunc) gst_jpegenc_class_init, NULL, NULL, - sizeof(GstJpegEnc), + sizeof (GstJpegEnc), 0, - (GInstanceInitFunc)gst_jpegenc_init, + (GInstanceInitFunc) gst_jpegenc_init, }; - jpegenc_type = g_type_register_static(GST_TYPE_ELEMENT, "GstJpegEnc", &jpegenc_info, 0); + jpegenc_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstJpegEnc", &jpegenc_info, + 0); } return jpegenc_type; } static GstStaticPadTemplate gst_jpegenc_sink_pad_template = -GST_STATIC_PAD_TEMPLATE ( - "sink", +GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV("I420")) -); + GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420")) + ); static GstStaticPadTemplate gst_jpegenc_src_pad_template = -GST_STATIC_PAD_TEMPLATE ( - "src", +GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS ("image/jpeg, " - "width = (int) [ 16, 4096 ], " - "height = (int) [ 16, 4096 ], " - "framerate = (double) [ 1, MAX ]" - ) -); + "width = (int) [ 16, 4096 ], " + "height = (int) [ 16, 4096 ], " "framerate = (double) [ 1, MAX ]") + ); static void gst_jpegenc_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - + gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&gst_jpegenc_sink_pad_template)); gst_element_class_add_pad_template (element_class, @@ -118,29 +120,29 @@ gst_jpegenc_base_init (gpointer g_class) } static void -gst_jpegenc_class_init (GstJpegEnc *klass) +gst_jpegenc_class_init (GstJpegEnc * 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); gst_jpegenc_signals[FRAME_ENCODED] = - g_signal_new ("frame-encoded", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstJpegEncClass, frame_encoded), NULL, NULL, - g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + g_signal_new ("frame-encoded", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstJpegEncClass, frame_encoded), NULL, + NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); g_object_class_install_property (gobject_class, ARG_QUALITY, g_param_spec_int ("quality", "Quality", "Quality of encoding", - 0, 100, 85, G_PARAM_READWRITE)); + 0, 100, 85, G_PARAM_READWRITE)); #if 0 /* disabled, since it doesn't seem to work */ g_object_class_install_property (gobject_class, ARG_SMOOTHING, g_param_spec_int ("smoothing", "Smoothing", "Smoothing factor", - 0, 100, 0, G_PARAM_READWRITE)); + 0, 100, 0, G_PARAM_READWRITE)); #endif gobject_class->set_property = gst_jpegenc_set_property; @@ -160,44 +162,47 @@ gst_jpegenc_flush_destination (j_compress_ptr cinfo) return TRUE; } -static void gst_jpegenc_term_destination (j_compress_ptr cinfo) +static void +gst_jpegenc_term_destination (j_compress_ptr cinfo) { GST_DEBUG ("gst_jpegenc_chain: term_source"); } static void -gst_jpegenc_init (GstJpegEnc *jpegenc) +gst_jpegenc_init (GstJpegEnc * jpegenc) { /* create the sink and src pads */ - jpegenc->sinkpad = gst_pad_new_from_template ( - gst_static_pad_template_get (&gst_jpegenc_sink_pad_template), "sink"); - gst_pad_set_chain_function(jpegenc->sinkpad,gst_jpegenc_chain); - gst_pad_set_getcaps_function(jpegenc->sinkpad, gst_jpegenc_getcaps); - gst_pad_set_link_function(jpegenc->sinkpad, gst_jpegenc_link); - gst_element_add_pad(GST_ELEMENT(jpegenc),jpegenc->sinkpad); - - jpegenc->srcpad = gst_pad_new_from_template ( - gst_static_pad_template_get (&gst_jpegenc_src_pad_template), "src"); - gst_pad_set_getcaps_function(jpegenc->sinkpad, gst_jpegenc_getcaps); - gst_pad_set_link_function(jpegenc->sinkpad, gst_jpegenc_link); - gst_element_add_pad(GST_ELEMENT(jpegenc),jpegenc->srcpad); + jpegenc->sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_jpegenc_sink_pad_template), "sink"); + gst_pad_set_chain_function (jpegenc->sinkpad, gst_jpegenc_chain); + gst_pad_set_getcaps_function (jpegenc->sinkpad, gst_jpegenc_getcaps); + gst_pad_set_link_function (jpegenc->sinkpad, gst_jpegenc_link); + gst_element_add_pad (GST_ELEMENT (jpegenc), jpegenc->sinkpad); + + jpegenc->srcpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_jpegenc_src_pad_template), "src"); + gst_pad_set_getcaps_function (jpegenc->sinkpad, gst_jpegenc_getcaps); + gst_pad_set_link_function (jpegenc->sinkpad, gst_jpegenc_link); + gst_element_add_pad (GST_ELEMENT (jpegenc), jpegenc->srcpad); /* reset the initial video state */ jpegenc->width = -1; jpegenc->height = -1; /* setup jpeglib */ - memset(&jpegenc->cinfo, 0, sizeof(jpegenc->cinfo)); - memset(&jpegenc->jerr, 0, sizeof(jpegenc->jerr)); - jpegenc->cinfo.err = jpeg_std_error(&jpegenc->jerr); - jpeg_create_compress(&jpegenc->cinfo); + memset (&jpegenc->cinfo, 0, sizeof (jpegenc->cinfo)); + memset (&jpegenc->jerr, 0, sizeof (jpegenc->jerr)); + jpegenc->cinfo.err = jpeg_std_error (&jpegenc->jerr); + jpeg_create_compress (&jpegenc->cinfo); GST_DEBUG ("gst_jpegenc_init: setting line buffers"); jpegenc->line[0] = NULL; jpegenc->line[1] = NULL; jpegenc->line[2] = NULL; - gst_jpegenc_resync(jpegenc); + gst_jpegenc_resync (jpegenc); jpegenc->jdest.init_destination = gst_jpegenc_init_destination; jpegenc->jdest.empty_output_buffer = gst_jpegenc_flush_destination; @@ -209,7 +214,7 @@ gst_jpegenc_init (GstJpegEnc *jpegenc) } static GstCaps * -gst_jpegenc_getcaps (GstPad *pad) +gst_jpegenc_getcaps (GstPad * pad) { GstJpegEnc *jpegenc = GST_JPEGENC (gst_pad_get_parent (pad)); GstPad *otherpad; @@ -225,7 +230,7 @@ gst_jpegenc_getcaps (GstPad *pad) } else { name = "video/x-raw-yuv"; } - for (i=0;i<gst_caps_get_size (caps); i++){ + for (i = 0; i < gst_caps_get_size (caps); i++) { structure = gst_caps_get_structure (caps, i); gst_structure_set_name (structure, name); @@ -236,7 +241,7 @@ gst_jpegenc_getcaps (GstPad *pad) } static GstPadLinkReturn -gst_jpegenc_link (GstPad *pad, const GstCaps *caps) +gst_jpegenc_link (GstPad * pad, const GstCaps * caps) { GstJpegEnc *jpegenc = GST_JPEGENC (gst_pad_get_parent (pad)); GstStructure *structure; @@ -248,18 +253,17 @@ gst_jpegenc_link (GstPad *pad, const GstCaps *caps) structure = gst_caps_get_structure (caps, 0); gst_structure_get_double (structure, "framerate", &jpegenc->fps); - gst_structure_get_int (structure, "width", &jpegenc->width); - gst_structure_get_int (structure, "height", &jpegenc->height); - + gst_structure_get_int (structure, "width", &jpegenc->width); + gst_structure_get_int (structure, "height", &jpegenc->height); + othercaps = gst_caps_copy (gst_pad_get_pad_template_caps (otherpad)); gst_caps_set_simple (othercaps, - "width", G_TYPE_INT, jpegenc->width, - "height", G_TYPE_INT, jpegenc->height, - "framerate", G_TYPE_DOUBLE, jpegenc->fps, - NULL); + "width", G_TYPE_INT, jpegenc->width, + "height", G_TYPE_INT, jpegenc->height, + "framerate", G_TYPE_DOUBLE, jpegenc->fps, NULL); ret = gst_pad_try_set_caps (jpegenc->srcpad, othercaps); - gst_caps_free(othercaps); + gst_caps_free (othercaps); if (GST_PAD_LINK_SUCCESSFUL (ret)) { gst_jpegenc_resync (jpegenc); @@ -269,7 +273,7 @@ gst_jpegenc_link (GstPad *pad, const GstCaps *caps) } static void -gst_jpegenc_resync (GstJpegEnc *jpegenc) +gst_jpegenc_resync (GstJpegEnc * jpegenc) { guint size = 0; gint width, height; @@ -282,11 +286,11 @@ gst_jpegenc_resync (GstJpegEnc *jpegenc) GST_DEBUG ("gst_jpegenc_resync: wdith %d, height %d", width, height); - jpeg_set_defaults(&jpegenc->cinfo); + jpeg_set_defaults (&jpegenc->cinfo); jpegenc->cinfo.dct_method = JDCT_FASTEST; - /*jpegenc->cinfo.dct_method = JDCT_DEFAULT;*/ + /*jpegenc->cinfo.dct_method = JDCT_DEFAULT; */ /*jpegenc->cinfo.smoothing_factor = jpegenc->smoothing; */ - jpeg_set_quality(&jpegenc->cinfo, jpegenc->quality, TRUE); + jpeg_set_quality (&jpegenc->cinfo, jpegenc->quality, TRUE); #if 0 switch (jpegenc->format) { @@ -310,24 +314,27 @@ gst_jpegenc_resync (GstJpegEnc *jpegenc) jpegenc->cinfo.comp_info[2].v_samp_factor = 1; if (height != -1) { - jpegenc->line[0] = g_realloc(jpegenc->line[0], height*sizeof(char*)); - jpegenc->line[1] = g_realloc(jpegenc->line[1], height*sizeof(char*)/2); - jpegenc->line[2] = g_realloc(jpegenc->line[2], height*sizeof(char*)/2); + jpegenc->line[0] = + g_realloc (jpegenc->line[0], height * sizeof (char *)); + jpegenc->line[1] = + g_realloc (jpegenc->line[1], height * sizeof (char *) / 2); + jpegenc->line[2] = + g_realloc (jpegenc->line[2], height * sizeof (char *) / 2); } GST_DEBUG ("gst_jpegenc_resync: setting format done"); #if 0 break; default: - printf("gst_jpegenc_resync: unsupported colorspace, using RGB\n"); + printf ("gst_jpegenc_resync: unsupported colorspace, using RGB\n"); size = 3; jpegenc->cinfo.in_color_space = JCS_RGB; break; } #endif - jpegenc->bufsize = jpegenc->width*jpegenc->height*size; + jpegenc->bufsize = jpegenc->width * jpegenc->height * size; - jpeg_suppress_tables(&jpegenc->cinfo, TRUE); + jpeg_suppress_tables (&jpegenc->cinfo, TRUE); //jpeg_suppress_tables(&jpegenc->cinfo, FALSE); jpegenc->buffer = NULL; @@ -335,17 +342,18 @@ gst_jpegenc_resync (GstJpegEnc *jpegenc) } static void -gst_jpegenc_chain (GstPad *pad, GstData *_data) +gst_jpegenc_chain (GstPad * pad, GstData * _data) { GstBuffer *buf = GST_BUFFER (_data); GstJpegEnc *jpegenc; guchar *data, *outdata; gulong size, outsize; GstBuffer *outbuf; + /* GstMeta *meta; */ guint height, width, width2; guchar *base[3]; - gint i,j, k; + gint i, j, k; g_return_if_fail (pad != NULL); g_return_if_fail (GST_IS_PAD (pad)); @@ -355,53 +363,58 @@ gst_jpegenc_chain (GstPad *pad, GstData *_data) /*usleep(10000); */ jpegenc = GST_JPEGENC (GST_OBJECT_PARENT (pad)); - data = GST_BUFFER_DATA(buf); - size = GST_BUFFER_SIZE(buf); + data = GST_BUFFER_DATA (buf); + size = GST_BUFFER_SIZE (buf); - GST_DEBUG ("gst_jpegenc_chain: got buffer of %ld bytes in '%s'",size, - GST_OBJECT_NAME (jpegenc)); + GST_DEBUG ("gst_jpegenc_chain: got buffer of %ld bytes in '%s'", size, + GST_OBJECT_NAME (jpegenc)); - outbuf = gst_buffer_new(); - outsize = GST_BUFFER_SIZE(outbuf) = jpegenc->bufsize; - outdata = GST_BUFFER_DATA(outbuf) = g_malloc(outsize); - GST_BUFFER_TIMESTAMP(outbuf) = GST_BUFFER_TIMESTAMP(buf); + outbuf = gst_buffer_new (); + outsize = GST_BUFFER_SIZE (outbuf) = jpegenc->bufsize; + outdata = GST_BUFFER_DATA (outbuf) = g_malloc (outsize); + GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf); width = jpegenc->width; height = jpegenc->height; base[0] = data; - base[1] = base[0]+width*height; - base[2] = base[1]+width*height/4; + base[1] = base[0] + width * height; + base[2] = base[1] + width * height / 4; jpegenc->jdest.next_output_byte = outdata; jpegenc->jdest.free_in_buffer = outsize; jpegenc->cinfo.smoothing_factor = jpegenc->smoothing; - jpeg_set_quality(&jpegenc->cinfo, jpegenc->quality, TRUE); - jpeg_start_compress(&jpegenc->cinfo, TRUE); + jpeg_set_quality (&jpegenc->cinfo, jpegenc->quality, TRUE); + jpeg_start_compress (&jpegenc->cinfo, TRUE); - width2 = width>>1; + width2 = width >> 1; GST_DEBUG ("gst_jpegdec_chain: compressing"); - for (i = 0; i < height; i += 2*DCTSIZE) { - for (j=0, k=0; j<2*DCTSIZE;j+=2, k++) { - jpegenc->line[0][j] = base[0]; base[0] += width; - jpegenc->line[0][j+1] = base[0]; base[0] += width; - jpegenc->line[1][k] = base[1]; base[1] += width2; - jpegenc->line[2][k] = base[2]; base[2] += width2; + for (i = 0; i < height; i += 2 * DCTSIZE) { + for (j = 0, k = 0; j < 2 * DCTSIZE; j += 2, k++) { + jpegenc->line[0][j] = base[0]; + base[0] += width; + jpegenc->line[0][j + 1] = base[0]; + base[0] += width; + jpegenc->line[1][k] = base[1]; + base[1] += width2; + jpegenc->line[2][k] = base[2]; + base[2] += width2; } - jpeg_write_raw_data(&jpegenc->cinfo, jpegenc->line, 2*DCTSIZE); + jpeg_write_raw_data (&jpegenc->cinfo, jpegenc->line, 2 * DCTSIZE); } - jpeg_finish_compress(&jpegenc->cinfo); + jpeg_finish_compress (&jpegenc->cinfo); GST_DEBUG ("gst_jpegdec_chain: compressing done"); - GST_BUFFER_SIZE(outbuf) = (((outsize - jpegenc->jdest.free_in_buffer)+3)&~3); + GST_BUFFER_SIZE (outbuf) = + (((outsize - jpegenc->jdest.free_in_buffer) + 3) & ~3); - gst_pad_push(jpegenc->srcpad, GST_DATA (outbuf)); + gst_pad_push (jpegenc->srcpad, GST_DATA (outbuf)); - g_signal_emit(G_OBJECT(jpegenc),gst_jpegenc_signals[FRAME_ENCODED], 0); + g_signal_emit (G_OBJECT (jpegenc), gst_jpegenc_signals[FRAME_ENCODED], 0); - gst_buffer_unref(buf); + gst_buffer_unref (buf); } static void @@ -412,7 +425,7 @@ gst_jpegenc_set_property (GObject * object, guint prop_id, g_return_if_fail (GST_IS_JPEGENC (object)); jpegenc = GST_JPEGENC (object); - + switch (prop_id) { case ARG_QUALITY: jpegenc->quality = g_value_get_int (value); @@ -423,7 +436,7 @@ gst_jpegenc_set_property (GObject * object, guint prop_id, default: break; } -} +} static void gst_jpegenc_get_property (GObject * object, guint prop_id, GValue * value, @@ -446,4 +459,3 @@ gst_jpegenc_get_property (GObject * object, guint prop_id, GValue * value, break; } } - diff --git a/ext/jpeg/gstjpegenc.h b/ext/jpeg/gstjpegenc.h index b68b4859..beeaf6f9 100644 --- a/ext/jpeg/gstjpegenc.h +++ b/ext/jpeg/gstjpegenc.h @@ -30,8 +30,9 @@ #include <jpeglib.h> #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define GST_TYPE_JPEGENC \ @@ -45,48 +46,50 @@ extern "C" { #define GST_IS_JPEGENC_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_JPEGENC)) -typedef struct _GstJpegEnc GstJpegEnc; -typedef struct _GstJpegEncClass GstJpegEncClass; + typedef struct _GstJpegEnc GstJpegEnc; + typedef struct _GstJpegEncClass GstJpegEncClass; -struct _GstJpegEnc { - GstElement element; + struct _GstJpegEnc + { + GstElement element; - /* pads */ - GstPad *sinkpad,*srcpad; + /* pads */ + GstPad *sinkpad, *srcpad; - /* video state */ - gint format; - gint width; - gint height; - gdouble fps; - /* the video buffer */ - gint bufsize; - GstBuffer *buffer; - guint row_stride; - /* the jpeg line buffer */ - guchar **line[3]; + /* video state */ + gint format; + gint width; + gint height; + gdouble fps; + /* the video buffer */ + gint bufsize; + GstBuffer *buffer; + guint row_stride; + /* the jpeg line buffer */ + guchar **line[3]; - struct jpeg_compress_struct cinfo; - struct jpeg_error_mgr jerr; - struct jpeg_destination_mgr jdest; + struct jpeg_compress_struct cinfo; + struct jpeg_error_mgr jerr; + struct jpeg_destination_mgr jdest; - int quality; - int smoothing; -}; + int quality; + int smoothing; + }; -struct _GstJpegEncClass { - GstElementClass parent_class; + struct _GstJpegEncClass + { + GstElementClass parent_class; - /* signals */ - void (*frame_encoded) (GstElement *element); -}; + /* signals */ + void (*frame_encoded) (GstElement * element); + }; -GType gst_jpegenc_get_type(void); + GType gst_jpegenc_get_type (void); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __GST_JPEGENC_H__ */ +#endif /* __GST_JPEGENC_H__ */ diff --git a/ext/ladspa/gstladspa.c b/ext/ladspa/gstladspa.c index 020767fa..4f6c1f0c 100644 --- a/ext/ladspa/gstladspa.c +++ b/ext/ladspa/gstladspa.c @@ -28,8 +28,8 @@ #include <gst/audio/audio.h> #include "gstladspa.h" -#include <ladspa.h> /* main ladspa sdk include file */ -#include "utils.h" /* ladspa sdk utility functions */ +#include <ladspa.h> /* main ladspa sdk include file */ +#include "utils.h" /* ladspa sdk utility functions */ /* 1.0 and the 1.1 preliminary headers don't define a version, but 1.1 final does */ @@ -40,31 +40,34 @@ static GstStaticCaps ladspa_pad_caps = GST_STATIC_CAPS (GST_AUDIO_FLOAT_STANDARD_PAD_TEMPLATE_CAPS); -static void gst_ladspa_class_init (GstLADSPAClass *klass); -static void gst_ladspa_base_init (GstLADSPAClass *klass); -static void gst_ladspa_init (GstLADSPA *ladspa); +static void gst_ladspa_class_init (GstLADSPAClass * klass); +static void gst_ladspa_base_init (GstLADSPAClass * klass); +static void gst_ladspa_init (GstLADSPA * ladspa); -static void gst_ladspa_update_int (const GValue *value, gpointer data); -static GstPadLinkReturn gst_ladspa_link (GstPad *pad, const GstCaps *caps); +static void gst_ladspa_update_int (const GValue * value, gpointer data); +static GstPadLinkReturn gst_ladspa_link (GstPad * pad, const GstCaps * caps); -static void gst_ladspa_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); -static void gst_ladspa_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); +static void gst_ladspa_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_ladspa_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); -static gboolean gst_ladspa_instantiate (GstLADSPA *ladspa); -static void gst_ladspa_activate (GstLADSPA *ladspa); -static void gst_ladspa_deactivate (GstLADSPA *ladspa); +static gboolean gst_ladspa_instantiate (GstLADSPA * ladspa); +static void gst_ladspa_activate (GstLADSPA * ladspa); +static void gst_ladspa_deactivate (GstLADSPA * ladspa); -static GstElementStateReturn gst_ladspa_change_state (GstElement *element); -static void gst_ladspa_loop (GstElement *element); -static void gst_ladspa_chain (GstPad *pad,GstData *_data); -static GstData * gst_ladspa_get (GstPad *pad); +static GstElementStateReturn gst_ladspa_change_state (GstElement * element); +static void gst_ladspa_loop (GstElement * element); +static void gst_ladspa_chain (GstPad * pad, GstData * _data); +static GstData *gst_ladspa_get (GstPad * pad); static GstElementClass *parent_class = NULL; static GstPlugin *ladspa_plugin; static GHashTable *ladspa_descriptors; -enum { +enum +{ ARG_0, ARG_SAMPLERATE, ARG_BUFFERSIZE, @@ -78,38 +81,39 @@ GST_DEBUG_CATEGORY_STATIC (ladspa_debug); GST_CAT_LEVEL_LOG (ladspa_debug, GST_LEVEL_DEBUG, obj, __VA_ARGS__) static void -gst_ladspa_base_init (GstLADSPAClass *klass) +gst_ladspa_base_init (GstLADSPAClass * klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); GstPadTemplate *templ; GstElementDetails *details; LADSPA_Descriptor *desc; - gint j, sinkcount,srccount; + gint j, sinkcount, srccount; - desc = g_hash_table_lookup(ladspa_descriptors, - GINT_TO_POINTER(G_TYPE_FROM_CLASS(klass))); + desc = g_hash_table_lookup (ladspa_descriptors, + GINT_TO_POINTER (G_TYPE_FROM_CLASS (klass))); if (!desc) - desc = g_hash_table_lookup(ladspa_descriptors, GINT_TO_POINTER(0)); + desc = g_hash_table_lookup (ladspa_descriptors, GINT_TO_POINTER (0)); g_assert (desc); /* pad templates */ klass->numports = desc->PortCount; klass->numsinkpads = 0; klass->numsrcpads = 0; - for (j=0;j<desc->PortCount;j++) { - if (LADSPA_IS_PORT_AUDIO(desc->PortDescriptors[j])) { - gchar *name = g_strdup((gchar *)desc->PortNames[j]); + for (j = 0; j < desc->PortCount; j++) { + if (LADSPA_IS_PORT_AUDIO (desc->PortDescriptors[j])) { + gchar *name = g_strdup ((gchar *) desc->PortNames[j]); + g_strcanon (name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-'); /* the factories take ownership of the name */ - if (LADSPA_IS_PORT_INPUT(desc->PortDescriptors[j])) { - templ = gst_pad_template_new (name, GST_PAD_SINK, GST_PAD_ALWAYS, - gst_caps_copy (gst_static_caps_get (&ladspa_pad_caps))); - klass->numsinkpads++; + if (LADSPA_IS_PORT_INPUT (desc->PortDescriptors[j])) { + templ = gst_pad_template_new (name, GST_PAD_SINK, GST_PAD_ALWAYS, + gst_caps_copy (gst_static_caps_get (&ladspa_pad_caps))); + klass->numsinkpads++; } else { - templ = gst_pad_template_new (name, GST_PAD_SRC, GST_PAD_ALWAYS, - gst_caps_copy (gst_static_caps_get (&ladspa_pad_caps))); - klass->numsrcpads++; + templ = gst_pad_template_new (name, GST_PAD_SRC, GST_PAD_ALWAYS, + gst_caps_copy (gst_static_caps_get (&ladspa_pad_caps))); + klass->numsrcpads++; } gst_element_class_add_pad_template (element_class, templ); @@ -117,28 +121,32 @@ gst_ladspa_base_init (GstLADSPAClass *klass) } /* construct the element details struct */ - details = g_new0(GstElementDetails,1); - details->longname = g_strdup(desc->Name); + details = g_new0 (GstElementDetails, 1); + details->longname = g_strdup (desc->Name); details->description = details->longname; - details->author = g_strdup(desc->Maker); - if ((klass->numsinkpads >0) && (klass->numsrcpads >0)) details->klass = "Filter/Effect/Audio/LADSPA"; - else if((klass->numsinkpads==0) && (klass->numsrcpads >0)) details->klass = "Source/Audio/LADSPA"; - else if((klass->numsinkpads >0) && (klass->numsrcpads==0)) details->klass = "Sink/Audio/LADSPA"; - else details->klass = "Filter/Effect/Audio/LADSPA"; /* whatever this is */ + details->author = g_strdup (desc->Maker); + if ((klass->numsinkpads > 0) && (klass->numsrcpads > 0)) + details->klass = "Filter/Effect/Audio/LADSPA"; + else if ((klass->numsinkpads == 0) && (klass->numsrcpads > 0)) + details->klass = "Source/Audio/LADSPA"; + else if ((klass->numsinkpads > 0) && (klass->numsrcpads == 0)) + details->klass = "Sink/Audio/LADSPA"; + else + details->klass = "Filter/Effect/Audio/LADSPA"; /* whatever this is */ gst_element_class_set_details (element_class, details); - klass->srcpad_portnums = g_new0(gint,klass->numsrcpads); - klass->sinkpad_portnums = g_new0(gint,klass->numsinkpads); + klass->srcpad_portnums = g_new0 (gint, klass->numsrcpads); + klass->sinkpad_portnums = g_new0 (gint, klass->numsinkpads); sinkcount = 0; srccount = 0; /* walk through the ports, note the portnums for srcpads, sinkpads */ - for (j=0; j<desc->PortCount; j++) { - if (LADSPA_IS_PORT_AUDIO(desc->PortDescriptors[j])) { - if (LADSPA_IS_PORT_INPUT(desc->PortDescriptors[j])) - klass->sinkpad_portnums[sinkcount++] = j; + for (j = 0; j < desc->PortCount; j++) { + if (LADSPA_IS_PORT_AUDIO (desc->PortDescriptors[j])) { + if (LADSPA_IS_PORT_INPUT (desc->PortDescriptors[j])) + klass->sinkpad_portnums[sinkcount++] = j; else - klass->srcpad_portnums[srccount++] = j; + klass->srcpad_portnums[srccount++] = j; } } @@ -146,19 +154,19 @@ gst_ladspa_base_init (GstLADSPAClass *klass) } static void -gst_ladspa_class_init (GstLADSPAClass *klass) +gst_ladspa_class_init (GstLADSPAClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; LADSPA_Descriptor *desc; - gint i,current_portnum,controlcount; + gint i, current_portnum, controlcount; gint hintdesc; - gint argtype,argperms; + gint argtype, argperms; GParamSpec *paramspec = NULL; gchar *argname, *tempstr, *paren; - gobject_class = (GObjectClass*)klass; - gstelement_class = (GstElementClass*)klass; + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; gobject_class->set_property = gst_ladspa_set_property; gobject_class->get_property = gst_ladspa_get_property; @@ -166,78 +174,85 @@ gst_ladspa_class_init (GstLADSPAClass *klass) gstelement_class->change_state = gst_ladspa_change_state; /* look up and store the ladspa descriptor */ - desc = g_hash_table_lookup(ladspa_descriptors, - GINT_TO_POINTER(G_TYPE_FROM_CLASS(klass))); + desc = g_hash_table_lookup (ladspa_descriptors, + GINT_TO_POINTER (G_TYPE_FROM_CLASS (klass))); if (!desc) - desc = g_hash_table_lookup(ladspa_descriptors, GINT_TO_POINTER(0)); + desc = g_hash_table_lookup (ladspa_descriptors, GINT_TO_POINTER (0)); g_assert (desc); klass->numcontrols = 0; /* walk through the ports, count the input, output and control ports */ - for (i=0; i<desc->PortCount; i++) { - if (!LADSPA_IS_PORT_AUDIO(desc->PortDescriptors[i]) && - LADSPA_IS_PORT_INPUT(desc->PortDescriptors[i])) + for (i = 0; i < desc->PortCount; i++) { + if (!LADSPA_IS_PORT_AUDIO (desc->PortDescriptors[i]) && + LADSPA_IS_PORT_INPUT (desc->PortDescriptors[i])) klass->numcontrols++; } DEBUG ("ladspa element class: init %s with %d sink, %d src, %d control\n", - g_type_name (G_TYPE_FROM_CLASS (klass)), - klass->numsinkpads, klass->numsrcpads, klass->numcontrols); + g_type_name (G_TYPE_FROM_CLASS (klass)), + klass->numsinkpads, klass->numsrcpads, klass->numcontrols); - klass->control_portnums = g_new0(gint,klass->numcontrols); + klass->control_portnums = g_new0 (gint, klass->numcontrols); controlcount = 0; /* walk through the ports, note the portnums for control params */ - for (i=0; i<desc->PortCount; i++) { - if (!LADSPA_IS_PORT_AUDIO(desc->PortDescriptors[i]) && - LADSPA_IS_PORT_INPUT(desc->PortDescriptors[i])) + for (i = 0; i < desc->PortCount; i++) { + if (!LADSPA_IS_PORT_AUDIO (desc->PortDescriptors[i]) && + LADSPA_IS_PORT_INPUT (desc->PortDescriptors[i])) klass->control_portnums[controlcount++] = i; } /* now build the control info from the control ports */ - klass->control_info = g_new0(ladspa_control_info,klass->numcontrols); - - for (i=0;i<klass->numcontrols;i++) { + klass->control_info = g_new0 (ladspa_control_info, klass->numcontrols); + + for (i = 0; i < klass->numcontrols; i++) { current_portnum = klass->control_portnums[i]; - + /* short name for hint descriptor */ hintdesc = desc->PortRangeHints[current_portnum].HintDescriptor; /* get the various bits */ - if (LADSPA_IS_HINT_TOGGLED(hintdesc)) + if (LADSPA_IS_HINT_TOGGLED (hintdesc)) klass->control_info[i].toggled = TRUE; - if (LADSPA_IS_HINT_LOGARITHMIC(hintdesc)) + if (LADSPA_IS_HINT_LOGARITHMIC (hintdesc)) klass->control_info[i].logarithmic = TRUE; - if (LADSPA_IS_HINT_INTEGER(hintdesc)) + if (LADSPA_IS_HINT_INTEGER (hintdesc)) klass->control_info[i].integer = TRUE; /* figure out the argument details */ - if (klass->control_info[i].toggled) argtype = G_TYPE_BOOLEAN; - else if (klass->control_info[i].integer) argtype = G_TYPE_INT; - else argtype = G_TYPE_FLOAT; + if (klass->control_info[i].toggled) + argtype = G_TYPE_BOOLEAN; + else if (klass->control_info[i].integer) + argtype = G_TYPE_INT; + else + argtype = G_TYPE_FLOAT; /* grab the bounds */ - if (LADSPA_IS_HINT_BOUNDED_BELOW(hintdesc)) { + if (LADSPA_IS_HINT_BOUNDED_BELOW (hintdesc)) { klass->control_info[i].lower = TRUE; klass->control_info[i].lowerbound = - desc->PortRangeHints[current_portnum].LowerBound; + desc->PortRangeHints[current_portnum].LowerBound; } else { - if (argtype==G_TYPE_INT) klass->control_info[i].lowerbound = (gfloat)G_MININT; - if (argtype==G_TYPE_FLOAT) klass->control_info[i].lowerbound = -G_MAXFLOAT; + if (argtype == G_TYPE_INT) + klass->control_info[i].lowerbound = (gfloat) G_MININT; + if (argtype == G_TYPE_FLOAT) + klass->control_info[i].lowerbound = -G_MAXFLOAT; } - - if (LADSPA_IS_HINT_BOUNDED_ABOVE(hintdesc)) { + + if (LADSPA_IS_HINT_BOUNDED_ABOVE (hintdesc)) { klass->control_info[i].upper = TRUE; klass->control_info[i].upperbound = - desc->PortRangeHints[current_portnum].UpperBound; - if (LADSPA_IS_HINT_SAMPLE_RATE(hintdesc)) { - klass->control_info[i].samplerate = TRUE; - klass->control_info[i].upperbound *= 44100; /* FIXME? */ + desc->PortRangeHints[current_portnum].UpperBound; + if (LADSPA_IS_HINT_SAMPLE_RATE (hintdesc)) { + klass->control_info[i].samplerate = TRUE; + klass->control_info[i].upperbound *= 44100; /* FIXME? */ } } else { - if (argtype==G_TYPE_INT) klass->control_info[i].upperbound = (gfloat)G_MAXINT; - if (argtype==G_TYPE_FLOAT) klass->control_info[i].upperbound = G_MAXFLOAT; + if (argtype == G_TYPE_INT) + klass->control_info[i].upperbound = (gfloat) G_MAXINT; + if (argtype == G_TYPE_FLOAT) + klass->control_info[i].upperbound = G_MAXFLOAT; } /* use the lowerbound as the default value */ @@ -247,46 +262,51 @@ gst_ladspa_class_init (GstLADSPAClass *klass) /* figure out the defaults */ if (LADSPA_IS_HINT_HAS_DEFAULT (hintdesc)) { if (LADSPA_IS_HINT_DEFAULT_MINIMUM (hintdesc)) - klass->control_info[i].def = klass->control_info[i].lowerbound; + klass->control_info[i].def = klass->control_info[i].lowerbound; else if (LADSPA_IS_HINT_DEFAULT_LOW (hintdesc)) - if (LADSPA_IS_HINT_LOGARITHMIC (hintdesc)) - klass->control_info[i].def = exp (0.75*log(klass->control_info[i].lowerbound) + - 0.25*log(klass->control_info[i].upperbound)); - else - klass->control_info[i].def = (0.75*klass->control_info[i].lowerbound + - 0.25*klass->control_info[i].upperbound); + if (LADSPA_IS_HINT_LOGARITHMIC (hintdesc)) + klass->control_info[i].def = + exp (0.75 * log (klass->control_info[i].lowerbound) + + 0.25 * log (klass->control_info[i].upperbound)); + else + klass->control_info[i].def = + (0.75 * klass->control_info[i].lowerbound + + 0.25 * klass->control_info[i].upperbound); else if (LADSPA_IS_HINT_DEFAULT_MIDDLE (hintdesc)) - if (LADSPA_IS_HINT_LOGARITHMIC (hintdesc)) - klass->control_info[i].def = exp (0.5*log(klass->control_info[i].lowerbound) + - 0.5*log(klass->control_info[i].upperbound)); - else - klass->control_info[i].def = (0.5*klass->control_info[i].lowerbound + - 0.5*klass->control_info[i].upperbound); + if (LADSPA_IS_HINT_LOGARITHMIC (hintdesc)) + klass->control_info[i].def = + exp (0.5 * log (klass->control_info[i].lowerbound) + + 0.5 * log (klass->control_info[i].upperbound)); + else + klass->control_info[i].def = + (0.5 * klass->control_info[i].lowerbound + + 0.5 * klass->control_info[i].upperbound); else if (LADSPA_IS_HINT_DEFAULT_HIGH (hintdesc)) - if (LADSPA_IS_HINT_LOGARITHMIC (hintdesc)) - klass->control_info[i].def = exp (0.25*log(klass->control_info[i].lowerbound) + - 0.75*log(klass->control_info[i].upperbound)); - else - klass->control_info[i].def = (0.25*klass->control_info[i].lowerbound + - 0.75*klass->control_info[i].upperbound); + if (LADSPA_IS_HINT_LOGARITHMIC (hintdesc)) + klass->control_info[i].def = + exp (0.25 * log (klass->control_info[i].lowerbound) + + 0.75 * log (klass->control_info[i].upperbound)); + else + klass->control_info[i].def = + (0.25 * klass->control_info[i].lowerbound + + 0.75 * klass->control_info[i].upperbound); else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM (hintdesc)) - klass->control_info[i].def = klass->control_info[i].upperbound; + klass->control_info[i].def = klass->control_info[i].upperbound; else if (LADSPA_IS_HINT_DEFAULT_0 (hintdesc)) - klass->control_info[i].def = 0.0; + klass->control_info[i].def = 0.0; else if (LADSPA_IS_HINT_DEFAULT_1 (hintdesc)) - klass->control_info[i].def = 1.0; + klass->control_info[i].def = 1.0; else if (LADSPA_IS_HINT_DEFAULT_100 (hintdesc)) - klass->control_info[i].def = 100.0; + klass->control_info[i].def = 100.0; else if (LADSPA_IS_HINT_DEFAULT_440 (hintdesc)) - klass->control_info[i].def = 440.0; + klass->control_info[i].def = 440.0; } #endif /* LADSPA_IS_HINT_HAS_DEFAULT */ - klass->control_info[i].def = CLAMP(klass->control_info[i].def, - klass->control_info[i].lowerbound, - klass->control_info[i].upperbound); - - if (LADSPA_IS_PORT_INPUT(desc->PortDescriptors[current_portnum])) { + klass->control_info[i].def = CLAMP (klass->control_info[i].def, + klass->control_info[i].lowerbound, klass->control_info[i].upperbound); + + if (LADSPA_IS_PORT_INPUT (desc->PortDescriptors[current_portnum])) { argperms = G_PARAM_READWRITE; klass->control_info[i].writable = TRUE; } else { @@ -294,8 +314,8 @@ gst_ladspa_class_init (GstLADSPAClass *klass) klass->control_info[i].writable = FALSE; } - klass->control_info[i].name = g_strdup(desc->PortNames[current_portnum]); - argname = g_strdup(klass->control_info[i].name); + klass->control_info[i].name = g_strdup (desc->PortNames[current_portnum]); + argname = g_strdup (klass->control_info[i].name); /* find out if there is a (unitname) at the end of the argname and get rid of it */ paren = g_strrstr (argname, " ("); @@ -305,123 +325,120 @@ gst_ladspa_class_init (GstLADSPAClass *klass) /* this is the same thing that param_spec_* will do */ g_strcanon (argname, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-'); /* satisfy glib2 (argname[0] must be [A-Za-z]) */ - if (!((argname[0] >= 'a' && argname[0] <= 'z') || (argname[0] >= 'A' && argname[0] <= 'Z'))) { + if (!((argname[0] >= 'a' && argname[0] <= 'z') || (argname[0] >= 'A' + && argname[0] <= 'Z'))) { tempstr = argname; - argname = g_strconcat("param-", argname, NULL); + argname = g_strconcat ("param-", argname, NULL); g_free (tempstr); } - + /* check for duplicate property names */ - if (g_object_class_find_property(G_OBJECT_CLASS(klass), argname) != NULL){ - gint numarg=1; - gchar *numargname = g_strdup_printf("%s_%d",argname,numarg++); - while (g_object_class_find_property(G_OBJECT_CLASS(klass), numargname) != NULL){ - g_free(numargname); - numargname = g_strdup_printf("%s_%d",argname,numarg++); + if (g_object_class_find_property (G_OBJECT_CLASS (klass), argname) != NULL) { + gint numarg = 1; + gchar *numargname = g_strdup_printf ("%s_%d", argname, numarg++); + + while (g_object_class_find_property (G_OBJECT_CLASS (klass), + numargname) != NULL) { + g_free (numargname); + numargname = g_strdup_printf ("%s_%d", argname, numarg++); } argname = numargname; } - + klass->control_info[i].param_name = argname; - + DEBUG ("adding arg %s from %s", argname, klass->control_info[i].name); - - if (argtype==G_TYPE_BOOLEAN){ - paramspec = g_param_spec_boolean(argname,argname,argname, FALSE, argperms); - } else if (argtype==G_TYPE_INT){ - paramspec = g_param_spec_int(argname,argname,argname, - (gint)klass->control_info[i].lowerbound, - (gint)klass->control_info[i].upperbound, - (gint)klass->control_info[i].def, argperms); - } else if (klass->control_info[i].samplerate){ - paramspec = g_param_spec_float(argname,argname,argname, - 0.0, G_MAXFLOAT, - 0.0, argperms); + + if (argtype == G_TYPE_BOOLEAN) { + paramspec = + g_param_spec_boolean (argname, argname, argname, FALSE, argperms); + } else if (argtype == G_TYPE_INT) { + paramspec = g_param_spec_int (argname, argname, argname, + (gint) klass->control_info[i].lowerbound, + (gint) klass->control_info[i].upperbound, + (gint) klass->control_info[i].def, argperms); + } else if (klass->control_info[i].samplerate) { + paramspec = g_param_spec_float (argname, argname, argname, + 0.0, G_MAXFLOAT, 0.0, argperms); } else { - paramspec = g_param_spec_float(argname,argname,argname, - klass->control_info[i].lowerbound, klass->control_info[i].upperbound, - klass->control_info[i].def, argperms); + paramspec = g_param_spec_float (argname, argname, argname, + klass->control_info[i].lowerbound, klass->control_info[i].upperbound, + klass->control_info[i].def, argperms); } - + /* properties have an offset of 1 */ - g_object_class_install_property(G_OBJECT_CLASS(klass), i+1, paramspec); + g_object_class_install_property (G_OBJECT_CLASS (klass), i + 1, paramspec); } } static void -gst_ladspa_init (GstLADSPA *ladspa) +gst_ladspa_init (GstLADSPA * ladspa) { GstLADSPAClass *oclass; ladspa_control_info cinfo; GList *l; LADSPA_Descriptor *desc; - gint i,sinkcount,srccount; + gint i, sinkcount, srccount; - oclass = (GstLADSPAClass*)G_OBJECT_GET_CLASS (ladspa); + oclass = (GstLADSPAClass *) G_OBJECT_GET_CLASS (ladspa); desc = oclass->descriptor; ladspa->descriptor = oclass->descriptor; - + /* allocate the various arrays */ - ladspa->srcpads = g_new0(GstPad*,oclass->numsrcpads); - ladspa->sinkpads = g_new0(GstPad*,oclass->numsinkpads); - ladspa->controls = g_new(gfloat,oclass->numcontrols); - ladspa->dpman = gst_dpman_new ("ladspa_dpman", GST_ELEMENT(ladspa)); - + ladspa->srcpads = g_new0 (GstPad *, oclass->numsrcpads); + ladspa->sinkpads = g_new0 (GstPad *, oclass->numsinkpads); + ladspa->controls = g_new (gfloat, oclass->numcontrols); + ladspa->dpman = gst_dpman_new ("ladspa_dpman", GST_ELEMENT (ladspa)); + /* set up pads */ sinkcount = 0; srccount = 0; - for (l=GST_ELEMENT_CLASS (oclass)->padtemplates; l; l=l->next) { + for (l = GST_ELEMENT_CLASS (oclass)->padtemplates; l; l = l->next) { GstPad *pad = gst_pad_new_from_template (GST_PAD_TEMPLATE (l->data), - GST_PAD_TEMPLATE_NAME_TEMPLATE (l->data)); + GST_PAD_TEMPLATE_NAME_TEMPLATE (l->data)); + gst_pad_set_link_function (pad, gst_ladspa_link); - gst_element_add_pad ((GstElement*)ladspa, pad); + gst_element_add_pad ((GstElement *) ladspa, pad); if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) ladspa->sinkpads[sinkcount++] = pad; else ladspa->srcpads[srccount++] = pad; } - + /* set up dparams */ - for (i=0; i<oclass->numcontrols; i++) { - if (LADSPA_IS_PORT_INPUT(desc->PortDescriptors[i])) { + for (i = 0; i < oclass->numcontrols; i++) { + if (LADSPA_IS_PORT_INPUT (desc->PortDescriptors[i])) { cinfo = oclass->control_info[i]; - ladspa->controls[i]=cinfo.def; - - if (cinfo.toggled){ - gst_dpman_add_required_dparam_callback ( - ladspa->dpman, - g_param_spec_int(cinfo.param_name, cinfo.name, cinfo.name, - 0, 1, (gint)(ladspa->controls[i]), G_PARAM_READWRITE), - "int", gst_ladspa_update_int, &(ladspa->controls[i]) - ); - } - else if (cinfo.integer){ - gst_dpman_add_required_dparam_callback ( - ladspa->dpman, - g_param_spec_int(cinfo.param_name, cinfo.name, cinfo.name, - (gint)cinfo.lowerbound, (gint)cinfo.upperbound, - (gint)ladspa->controls[i], G_PARAM_READWRITE), - "int", gst_ladspa_update_int, &(ladspa->controls[i]) - ); - } - else if (cinfo.samplerate){ - gst_dpman_add_required_dparam_direct ( - ladspa->dpman, - g_param_spec_float(cinfo.param_name, cinfo.name, cinfo.name, - cinfo.lowerbound, cinfo.upperbound, - ladspa->controls[i], G_PARAM_READWRITE), - "hertz-rate-bound", &(ladspa->controls[i]) - ); - } - else { - gst_dpman_add_required_dparam_direct ( - ladspa->dpman, - g_param_spec_float(cinfo.param_name, cinfo.name, cinfo.name, - cinfo.lowerbound, cinfo.upperbound, - ladspa->controls[i], G_PARAM_READWRITE), - "float", &(ladspa->controls[i]) - ); + ladspa->controls[i] = cinfo.def; + + if (cinfo.toggled) { + gst_dpman_add_required_dparam_callback (ladspa->dpman, + g_param_spec_int (cinfo.param_name, cinfo.name, cinfo.name, + 0, 1, (gint) (ladspa->controls[i]), G_PARAM_READWRITE), + "int", gst_ladspa_update_int, &(ladspa->controls[i]) + ); + } else if (cinfo.integer) { + gst_dpman_add_required_dparam_callback (ladspa->dpman, + g_param_spec_int (cinfo.param_name, cinfo.name, cinfo.name, + (gint) cinfo.lowerbound, (gint) cinfo.upperbound, + (gint) ladspa->controls[i], G_PARAM_READWRITE), + "int", gst_ladspa_update_int, &(ladspa->controls[i]) + ); + } else if (cinfo.samplerate) { + gst_dpman_add_required_dparam_direct (ladspa->dpman, + g_param_spec_float (cinfo.param_name, cinfo.name, cinfo.name, + cinfo.lowerbound, cinfo.upperbound, + ladspa->controls[i], G_PARAM_READWRITE), + "hertz-rate-bound", &(ladspa->controls[i]) + ); + } else { + gst_dpman_add_required_dparam_direct (ladspa->dpman, + g_param_spec_float (cinfo.param_name, cinfo.name, cinfo.name, + cinfo.lowerbound, cinfo.upperbound, + ladspa->controls[i], G_PARAM_READWRITE), + "float", &(ladspa->controls[i]) + ); } } } @@ -429,58 +446,62 @@ gst_ladspa_init (GstLADSPA *ladspa) /* nonzero default needed to instantiate() some plugins */ ladspa->samplerate = 44100; - ladspa->buffer_frames = 0; /* should be set with caps */ + ladspa->buffer_frames = 0; /* should be set with caps */ ladspa->activated = FALSE; - ladspa->inplace_broken = LADSPA_IS_INPLACE_BROKEN(ladspa->descriptor->Properties); + ladspa->inplace_broken = + LADSPA_IS_INPLACE_BROKEN (ladspa->descriptor->Properties); - if (sinkcount==0 && srccount == 1) { + if (sinkcount == 0 && srccount == 1) { /* get mode (no sink pads) */ DEBUG_OBJ (ladspa, "mono get mode with 1 src pad"); gst_pad_set_get_function (ladspa->srcpads[0], gst_ladspa_get); - } else if (sinkcount==1){ + } else if (sinkcount == 1) { /* with one sink we can use the chain function */ DEBUG_OBJ (ladspa, "chain mode"); gst_pad_set_chain_function (ladspa->sinkpads[0], gst_ladspa_chain); - } else if (sinkcount > 1){ + } else if (sinkcount > 1) { /* more than one sink pad needs loop mode */ - DEBUG_OBJ (ladspa, "loop mode with %d sink pads and %d src pads", sinkcount, srccount); + DEBUG_OBJ (ladspa, "loop mode with %d sink pads and %d src pads", sinkcount, + srccount); gst_element_set_loop_function (GST_ELEMENT (ladspa), gst_ladspa_loop); - } else if (sinkcount==0 && srccount == 0) { + } else if (sinkcount == 0 && srccount == 0) { /* for example, a plugin with only control inputs and output -- just ignore * it for now */ } else { - g_warning ("%d sink pads, %d src pads not yet supported", sinkcount, srccount); + g_warning ("%d sink pads, %d src pads not yet supported", sinkcount, + srccount); } gst_ladspa_instantiate (ladspa); } static void -gst_ladspa_update_int(const GValue *value, gpointer data) +gst_ladspa_update_int (const GValue * value, gpointer data) { - gfloat *target = (gfloat*) data; - *target = (gfloat)g_value_get_int(value); + gfloat *target = (gfloat *) data; + + *target = (gfloat) g_value_get_int (value); } static GstPadLinkReturn -gst_ladspa_link (GstPad *pad, const GstCaps *caps) +gst_ladspa_link (GstPad * pad, const GstCaps * caps) { - GstElement *element = (GstElement*)GST_PAD_PARENT (pad); - GstLADSPA *ladspa = (GstLADSPA*)element; + GstElement *element = (GstElement *) GST_PAD_PARENT (pad); + GstLADSPA *ladspa = (GstLADSPA *) element; const GList *l = NULL; gint rate; GstStructure *structure; /* if this fails in some other plugin, the graph is left in an inconsistent state */ - for (l=gst_element_get_pad_list (element); l; l=l->next) - if (pad != (GstPad*)l->data) - if (gst_pad_try_set_caps ((GstPad*)l->data, caps) <= 0) - return GST_PAD_LINK_REFUSED; - + for (l = gst_element_get_pad_list (element); l; l = l->next) + if (pad != (GstPad *) l->data) + if (gst_pad_try_set_caps ((GstPad *) l->data, caps) <= 0) + return GST_PAD_LINK_REFUSED; + /* we assume that the ladspa plugin can handle any sample rate, so this check gets put last */ structure = gst_caps_get_structure (caps, 0); @@ -488,48 +509,46 @@ gst_ladspa_link (GstPad *pad, const GstCaps *caps) /* have to instantiate ladspa plugin when samplerate changes (groan) */ if (ladspa->samplerate != rate) { ladspa->samplerate = rate; - if (! gst_ladspa_instantiate(ladspa)) + if (!gst_ladspa_instantiate (ladspa)) return GST_PAD_LINK_REFUSED; } - - gst_structure_get_int (structure, "buffer-frames", &ladspa->buffer_frames); - + + gst_structure_get_int (structure, "buffer-frames", &ladspa->buffer_frames); + return GST_PAD_LINK_OK; } #if 0 static void -gst_ladspa_force_src_caps(GstLADSPA *ladspa, GstPad *pad) +gst_ladspa_force_src_caps (GstLADSPA * ladspa, GstPad * pad) { if (!ladspa->buffer_frames) { - ladspa->buffer_frames = 256; /* 5 ms at 44100 kHz (just a default...) */ + ladspa->buffer_frames = 256; /* 5 ms at 44100 kHz (just a default...) */ } DEBUG_OBJ (ladspa, "forcing caps with rate=%d, buffer-frames=%d", - ladspa->samplerate, ladspa->buffer_frames); + ladspa->samplerate, ladspa->buffer_frames); gst_pad_try_set_caps (pad, - gst_caps_new ( - "ladspa_src_caps", - "audio/x-raw-float", - gst_props_new ( - "width", G_TYPE_INT (32), - "endianness", G_TYPE_INT (G_BYTE_ORDER), - "rate", G_TYPE_INT (ladspa->samplerate), - "buffer-frames", G_TYPE_INT (ladspa->buffer_frames), - "channels", G_TYPE_INT (1), - NULL))); + gst_caps_new ("ladspa_src_caps", + "audio/x-raw-float", + gst_props_new ("width", G_TYPE_INT (32), + "endianness", G_TYPE_INT (G_BYTE_ORDER), + "rate", G_TYPE_INT (ladspa->samplerate), + "buffer-frames", G_TYPE_INT (ladspa->buffer_frames), + "channels", G_TYPE_INT (1), NULL))); } #endif static void -gst_ladspa_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +gst_ladspa_set_property (GObject * object, guint prop_id, const GValue * value, + GParamSpec * pspec) { - GstLADSPA *ladspa = (GstLADSPA*)object; + GstLADSPA *ladspa = (GstLADSPA *) object; GstLADSPAClass *oclass; ladspa_control_info *control_info; - oclass = (GstLADSPAClass*)(G_OBJECT_GET_CLASS (object)); + oclass = (GstLADSPAClass *) (G_OBJECT_GET_CLASS (object)); /* remember, properties have an offset of 1 */ prop_id--; @@ -551,14 +570,16 @@ gst_ladspa_set_property (GObject *object, guint prop_id, const GValue *value, GP else ladspa->controls[prop_id] = g_value_get_float (value); - DEBUG_OBJ (object, "set arg %s to %f", control_info->name, ladspa->controls[prop_id]); + DEBUG_OBJ (object, "set arg %s to %f", control_info->name, + ladspa->controls[prop_id]); } static void -gst_ladspa_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +gst_ladspa_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { - GstLADSPA *ladspa = (GstLADSPA*)object; - GstLADSPAClass *oclass = (GstLADSPAClass*)(G_OBJECT_GET_CLASS (object)); + GstLADSPA *ladspa = (GstLADSPA *) object; + GstLADSPAClass *oclass = (GstLADSPAClass *) (G_OBJECT_GET_CLASS (object)); ladspa_control_info *control_info; /* remember, properties have an offset of 1 */ @@ -574,62 +595,63 @@ gst_ladspa_get_property (GObject *object, guint prop_id, GValue *value, GParamSp if (control_info->toggled) g_value_set_boolean (value, ladspa->controls[prop_id] == 1.0); else if (control_info->integer) - g_value_set_int (value, (gint)ladspa->controls[prop_id]); + g_value_set_int (value, (gint) ladspa->controls[prop_id]); else g_value_set_float (value, ladspa->controls[prop_id]); - DEBUG_OBJ (object, "got arg %s as %f", control_info->name, ladspa->controls[prop_id]); + DEBUG_OBJ (object, "got arg %s as %f", control_info->name, + ladspa->controls[prop_id]); } static gboolean -gst_ladspa_instantiate (GstLADSPA *ladspa) +gst_ladspa_instantiate (GstLADSPA * ladspa) { LADSPA_Descriptor *desc; int i; - GstLADSPAClass *oclass = (GstLADSPAClass*)(G_OBJECT_GET_CLASS (ladspa)); + GstLADSPAClass *oclass = (GstLADSPAClass *) (G_OBJECT_GET_CLASS (ladspa)); gboolean was_activated; - + desc = ladspa->descriptor; - + /* check for old handle */ was_activated = ladspa->activated; - if (ladspa->handle != NULL){ - gst_ladspa_deactivate(ladspa); - desc->cleanup(ladspa->handle); + if (ladspa->handle != NULL) { + gst_ladspa_deactivate (ladspa); + desc->cleanup (ladspa->handle); } - - /* instantiate the plugin */ + + /* instantiate the plugin */ DEBUG_OBJ (ladspa, "instantiating the plugin at %d Hz", ladspa->samplerate); - - ladspa->handle = desc->instantiate(desc,ladspa->samplerate); + + ladspa->handle = desc->instantiate (desc, ladspa->samplerate); g_return_val_if_fail (ladspa->handle != NULL, FALSE); /* connect the control ports */ - for (i=0;i<oclass->numcontrols;i++) - desc->connect_port(ladspa->handle, - oclass->control_portnums[i], - &(ladspa->controls[i])); + for (i = 0; i < oclass->numcontrols; i++) + desc->connect_port (ladspa->handle, + oclass->control_portnums[i], &(ladspa->controls[i])); /* reactivate if it was activated before the reinstantiation */ if (was_activated) - gst_ladspa_activate(ladspa); + gst_ladspa_activate (ladspa); return TRUE; } static GstElementStateReturn -gst_ladspa_change_state (GstElement *element) +gst_ladspa_change_state (GstElement * element) { LADSPA_Descriptor *desc; - GstLADSPA *ladspa = (GstLADSPA*)element; + GstLADSPA *ladspa = (GstLADSPA *) element; + desc = ladspa->descriptor; switch (GST_STATE_TRANSITION (element)) { case GST_STATE_NULL_TO_READY: - gst_ladspa_activate(ladspa); + gst_ladspa_activate (ladspa); break; case GST_STATE_READY_TO_NULL: - gst_ladspa_deactivate(ladspa); + gst_ladspa_deactivate (ladspa); break; default: break; @@ -642,104 +664,109 @@ gst_ladspa_change_state (GstElement *element) } static void -gst_ladspa_activate (GstLADSPA *ladspa) +gst_ladspa_activate (GstLADSPA * ladspa) { LADSPA_Descriptor *desc; + desc = ladspa->descriptor; - + if (ladspa->activated) - gst_ladspa_deactivate(ladspa); - + gst_ladspa_deactivate (ladspa); + DEBUG_OBJ (ladspa, "activating"); /* activate the plugin (function might be null) */ if (desc->activate != NULL) - desc->activate(ladspa->handle); + desc->activate (ladspa->handle); ladspa->activated = TRUE; } static void -gst_ladspa_deactivate (GstLADSPA *ladspa) +gst_ladspa_deactivate (GstLADSPA * ladspa) { LADSPA_Descriptor *desc; + desc = ladspa->descriptor; DEBUG_OBJ (ladspa, "deactivating"); /* deactivate the plugin (function might be null) */ if (ladspa->activated && (desc->deactivate != NULL)) - desc->deactivate(ladspa->handle); + desc->deactivate (ladspa->handle); ladspa->activated = FALSE; } static void -gst_ladspa_loop (GstElement *element) +gst_ladspa_loop (GstElement * element) { - guint i, j, numsrcpads, numsinkpads; - guint num_processed, num_to_process; - gint largest_buffer; - LADSPA_Data **data_in, **data_out; - GstBuffer **buffers_in, **buffers_out; - - GstLADSPA *ladspa = (GstLADSPA *)element; - GstLADSPAClass *oclass = (GstLADSPAClass*)(G_OBJECT_GET_CLASS (ladspa)); + guint i, j, numsrcpads, numsinkpads; + guint num_processed, num_to_process; + gint largest_buffer; + LADSPA_Data **data_in, **data_out; + GstBuffer **buffers_in, **buffers_out; + + GstLADSPA *ladspa = (GstLADSPA *) element; + GstLADSPAClass *oclass = (GstLADSPAClass *) (G_OBJECT_GET_CLASS (ladspa)); LADSPA_Descriptor *desc = ladspa->descriptor; numsinkpads = oclass->numsinkpads; numsrcpads = oclass->numsrcpads; - + /* fixme: these mallocs need to die */ - data_in = g_new0(LADSPA_Data*, numsinkpads); - data_out = g_new0(LADSPA_Data*, numsrcpads); - buffers_in = g_new0(GstBuffer*, numsinkpads); - buffers_out = g_new0(GstBuffer*, numsrcpads); - + data_in = g_new0 (LADSPA_Data *, numsinkpads); + data_out = g_new0 (LADSPA_Data *, numsrcpads); + buffers_in = g_new0 (GstBuffer *, numsinkpads); + buffers_out = g_new0 (GstBuffer *, numsrcpads); + largest_buffer = -1; /* first get all the necessary data from the input ports */ - for (i=0 ; i<numsinkpads ; i++){ + for (i = 0; i < numsinkpads; i++) { get_buffer: buffers_in[i] = GST_BUFFER (gst_pad_pull (ladspa->sinkpads[i])); - + if (GST_IS_EVENT (buffers_in[i])) { /* push it out on all pads */ - gst_data_ref_by_count ((GstData*)buffers_in[i], numsrcpads); - for (j=0; j<numsrcpads; j++) - gst_pad_push (ladspa->srcpads[j], GST_DATA (buffers_in[i])); + gst_data_ref_by_count ((GstData *) buffers_in[i], numsrcpads); + for (j = 0; j < numsrcpads; j++) + gst_pad_push (ladspa->srcpads[j], GST_DATA (buffers_in[i])); if (GST_EVENT_TYPE (buffers_in[i]) == GST_EVENT_EOS) { - /* shut down */ - gst_element_set_eos (element); - return; + /* shut down */ + gst_element_set_eos (element); + return; } else { - goto get_buffer; + goto get_buffer; } } if (largest_buffer < 0) - largest_buffer = GST_BUFFER_SIZE (buffers_in[i])/sizeof(gfloat); + largest_buffer = GST_BUFFER_SIZE (buffers_in[i]) / sizeof (gfloat); else - largest_buffer = MIN (GST_BUFFER_SIZE (buffers_in[i])/sizeof(gfloat), largest_buffer); - data_in[i] = (LADSPA_Data *) GST_BUFFER_DATA(buffers_in[i]); - GST_BUFFER_TIMESTAMP(buffers_in[i]) = ladspa->timestamp; + largest_buffer = + MIN (GST_BUFFER_SIZE (buffers_in[i]) / sizeof (gfloat), + largest_buffer); + data_in[i] = (LADSPA_Data *) GST_BUFFER_DATA (buffers_in[i]); + GST_BUFFER_TIMESTAMP (buffers_in[i]) = ladspa->timestamp; } - i=0; + i = 0; if (!ladspa->inplace_broken) { - for (; i<numsrcpads && i<numsinkpads; i++) { + for (; i < numsrcpads && i < numsinkpads; i++) { /* reuse input buffers */ buffers_out[i] = buffers_in[i]; data_out[i] = data_in[i]; } } - for (; i<numsrcpads; i++) { - buffers_out[i] = gst_buffer_new_and_alloc (ladspa->buffer_frames * sizeof(gfloat)); + for (; i < numsrcpads; i++) { + buffers_out[i] = + gst_buffer_new_and_alloc (ladspa->buffer_frames * sizeof (gfloat)); GST_BUFFER_TIMESTAMP (buffers_out[i]) = ladspa->timestamp; - data_out[i] = (LADSPA_Data*)GST_BUFFER_DATA (buffers_out[i]); + data_out[i] = (LADSPA_Data *) GST_BUFFER_DATA (buffers_out[i]); } - - GST_DPMAN_PREPROCESS(ladspa->dpman, largest_buffer, ladspa->timestamp); + + GST_DPMAN_PREPROCESS (ladspa->dpman, largest_buffer, ladspa->timestamp); num_processed = 0; /* split up processing of the buffer into chunks so that dparams can @@ -747,37 +774,39 @@ gst_ladspa_loop (GstElement *element) * In many cases the buffer will be processed in one chunk anyway. */ while (GST_DPMAN_PROCESS (ladspa->dpman, num_processed)) { - num_to_process = GST_DPMAN_FRAMES_TO_PROCESS(ladspa->dpman); + num_to_process = GST_DPMAN_FRAMES_TO_PROCESS (ladspa->dpman); - for (i=0 ; i<numsinkpads ; i++) - desc->connect_port (ladspa->handle, oclass->sinkpad_portnums[i], data_in[i]); - for (i=0 ; i<numsrcpads ; i++) - desc->connect_port (ladspa->handle, oclass->srcpad_portnums[i], data_out[i]); + for (i = 0; i < numsinkpads; i++) + desc->connect_port (ladspa->handle, oclass->sinkpad_portnums[i], + data_in[i]); + for (i = 0; i < numsrcpads; i++) + desc->connect_port (ladspa->handle, oclass->srcpad_portnums[i], + data_out[i]); - desc->run(ladspa->handle, num_to_process); + desc->run (ladspa->handle, num_to_process); - for (i=0 ; i<numsinkpads ; i++) + for (i = 0; i < numsinkpads; i++) data_in[i] += num_to_process; - for (i=0 ; i<numsrcpads ; i++) + for (i = 0; i < numsrcpads; i++) data_out[i] += num_to_process; - + num_processed += num_to_process; } - - for (i=0 ; i<numsinkpads ; i++) { + + for (i = 0; i < numsinkpads; i++) { if (i >= numsrcpads || buffers_out[i] != buffers_in[i]) - gst_buffer_unref(buffers_in[i]); + gst_buffer_unref (buffers_in[i]); data_in[i] = NULL; buffers_in[i] = NULL; - } - for (i=0 ; i<numsrcpads ; i++) { + } + for (i = 0; i < numsrcpads; i++) { DEBUG_OBJ (ladspa, "pushing buffer (%p) on src pad %d", buffers_out[i], i); gst_pad_push (ladspa->srcpads[i], GST_DATA (buffers_out[i])); - + data_out[i] = NULL; buffers_out[i] = NULL; } - + ladspa->timestamp += ladspa->buffer_frames * GST_SECOND / ladspa->samplerate; /* FIXME: move these mallocs and frees to the state-change handler */ @@ -789,7 +818,7 @@ gst_ladspa_loop (GstElement *element) } static void -gst_ladspa_chain (GstPad *pad, GstData *_data) +gst_ladspa_chain (GstPad * pad, GstData * _data) { GstBuffer *buffer_in = GST_BUFFER (_data); LADSPA_Descriptor *desc; @@ -800,23 +829,23 @@ gst_ladspa_chain (GstPad *pad, GstData *_data) GstLADSPA *ladspa; GstLADSPAClass *oclass; - ladspa = (GstLADSPA*)GST_OBJECT_PARENT (pad); + ladspa = (GstLADSPA *) GST_OBJECT_PARENT (pad); oclass = (GstLADSPAClass *) (G_OBJECT_GET_CLASS (ladspa)); - data_in = (LADSPA_Data *) GST_BUFFER_DATA(buffer_in); - num_samples = GST_BUFFER_SIZE(buffer_in) / sizeof(gfloat); + data_in = (LADSPA_Data *) GST_BUFFER_DATA (buffer_in); + num_samples = GST_BUFFER_SIZE (buffer_in) / sizeof (gfloat); numsrcpads = oclass->numsrcpads; desc = ladspa->descriptor; /* we shouldn't get events here... */ g_return_if_fail (GST_IS_BUFFER (buffer_in)); - + /* FIXME: this function shouldn't need to malloc() anything */ if (numsrcpads > 0) { - buffers_out = g_new(GstBuffer*, numsrcpads); - data_out = g_new(LADSPA_Data*, numsrcpads); + buffers_out = g_new (GstBuffer *, numsrcpads); + data_out = g_new (LADSPA_Data *, numsrcpads); } - i=0; + i = 0; if (!ladspa->inplace_broken && numsrcpads) { /* reuse the first (chained) buffer */ buffers_out[i] = buffer_in; @@ -824,54 +853,56 @@ gst_ladspa_chain (GstPad *pad, GstData *_data) data_out[i] = data_in; i++; } - for (; i<numsrcpads; i++) { - buffers_out[i] = gst_buffer_new_and_alloc (GST_BUFFER_SIZE(buffer_in)); + for (; i < numsrcpads; i++) { + buffers_out[i] = gst_buffer_new_and_alloc (GST_BUFFER_SIZE (buffer_in)); DEBUG ("new %d", GST_BUFFER_SIZE (buffer_in)); GST_BUFFER_TIMESTAMP (buffers_out[i]) = ladspa->timestamp; - data_out[i] = (LADSPA_Data*)GST_BUFFER_DATA (buffers_out[i]); + data_out[i] = (LADSPA_Data *) GST_BUFFER_DATA (buffers_out[i]); } - GST_DPMAN_PREPROCESS(ladspa->dpman, num_samples, GST_BUFFER_TIMESTAMP(buffer_in)); + GST_DPMAN_PREPROCESS (ladspa->dpman, num_samples, + GST_BUFFER_TIMESTAMP (buffer_in)); num_processed = 0; /* split up processing of the buffer into chunks so that dparams can * be updated when required. * In many cases the buffer will be processed in one chunk anyway. */ - while(GST_DPMAN_PROCESS(ladspa->dpman, num_processed)) { - num_to_process = GST_DPMAN_FRAMES_TO_PROCESS(ladspa->dpman); + while (GST_DPMAN_PROCESS (ladspa->dpman, num_processed)) { + num_to_process = GST_DPMAN_FRAMES_TO_PROCESS (ladspa->dpman); + + desc->connect_port (ladspa->handle, oclass->sinkpad_portnums[0], data_in); + for (i = 0; i < numsrcpads; i++) + desc->connect_port (ladspa->handle, oclass->srcpad_portnums[i], + data_out[i]); - desc->connect_port(ladspa->handle,oclass->sinkpad_portnums[0],data_in); - for (i=0 ; i<numsrcpads ; i++) - desc->connect_port(ladspa->handle,oclass->srcpad_portnums[i],data_out[i]); + desc->run (ladspa->handle, num_to_process); - desc->run(ladspa->handle, num_to_process); - data_in += num_to_process; - for (i=0 ; i<numsrcpads ; i++) + for (i = 0; i < numsrcpads; i++) data_out[i] += num_to_process; num_processed += num_to_process; } if (!numsrcpads || buffers_out[0] != buffer_in) - gst_buffer_unref(buffer_in); + gst_buffer_unref (buffer_in); if (numsrcpads) { - for (i=0; i<numsrcpads; i++) { + for (i = 0; i < numsrcpads; i++) { DEBUG_OBJ (ladspa, "pushing buffer (%p, length %u bytes) on src pad %d", - buffers_out[i], GST_BUFFER_SIZE (buffers_out[i]), i); + buffers_out[i], GST_BUFFER_SIZE (buffers_out[i]), i); gst_pad_push (ladspa->srcpads[i], GST_DATA (buffers_out[i])); } - g_free(buffers_out); - g_free(data_out); + g_free (buffers_out); + g_free (data_out); } } static GstData * -gst_ladspa_get(GstPad *pad) -{ +gst_ladspa_get (GstPad * pad) +{ GstLADSPA *ladspa; GstLADSPAClass *oclass; GstBuffer *buf; @@ -879,120 +910,111 @@ gst_ladspa_get(GstPad *pad) LADSPA_Descriptor *desc; guint num_to_process, num_processed; - ladspa = (GstLADSPA *)gst_pad_get_parent (pad); - oclass = (GstLADSPAClass*)(G_OBJECT_GET_CLASS(ladspa)); + ladspa = (GstLADSPA *) gst_pad_get_parent (pad); + oclass = (GstLADSPAClass *) (G_OBJECT_GET_CLASS (ladspa)); desc = ladspa->descriptor; /* 4096 is arbitrary */ buf = gst_buffer_new_and_alloc (4096); - GST_BUFFER_TIMESTAMP(buf) = ladspa->timestamp; - data = (LADSPA_Data *) GST_BUFFER_DATA(buf); + GST_BUFFER_TIMESTAMP (buf) = ladspa->timestamp; + data = (LADSPA_Data *) GST_BUFFER_DATA (buf); - GST_DPMAN_PREPROCESS(ladspa->dpman, ladspa->buffer_frames, ladspa->timestamp); + GST_DPMAN_PREPROCESS (ladspa->dpman, ladspa->buffer_frames, + ladspa->timestamp); num_processed = 0; /* split up processing of the buffer into chunks so that dparams can * be updated when required. * In many cases the buffer will be processed in one chunk anyway. */ - while(GST_DPMAN_PROCESS(ladspa->dpman, num_processed)) { - num_to_process = GST_DPMAN_FRAMES_TO_PROCESS(ladspa->dpman); + while (GST_DPMAN_PROCESS (ladspa->dpman, num_processed)) { + num_to_process = GST_DPMAN_FRAMES_TO_PROCESS (ladspa->dpman); - /* update timestamp */ + /* update timestamp */ ladspa->timestamp += num_to_process * GST_SECOND / ladspa->samplerate; - desc->connect_port(ladspa->handle,oclass->srcpad_portnums[0],data); + desc->connect_port (ladspa->handle, oclass->srcpad_portnums[0], data); + + desc->run (ladspa->handle, num_to_process); - desc->run(ladspa->handle, num_to_process); - data += num_to_process; num_processed = num_to_process; } - + return GST_DATA (buf); } static void -ladspa_describe_plugin(const char *pcFullFilename, - void *pvPluginHandle, - LADSPA_Descriptor_Function pfDescriptorFunction) +ladspa_describe_plugin (const char *pcFullFilename, + void *pvPluginHandle, LADSPA_Descriptor_Function pfDescriptorFunction) { const LADSPA_Descriptor *desc; gint i; GTypeInfo typeinfo = { - sizeof(GstLADSPAClass), - (GBaseInitFunc)gst_ladspa_base_init, - NULL, - (GClassInitFunc)gst_ladspa_class_init, - NULL, - NULL, - sizeof(GstLADSPA), - 0, - (GInstanceInitFunc)gst_ladspa_init, + sizeof (GstLADSPAClass), + (GBaseInitFunc) gst_ladspa_base_init, + NULL, + (GClassInitFunc) gst_ladspa_class_init, + NULL, + NULL, + sizeof (GstLADSPA), + 0, + (GInstanceInitFunc) gst_ladspa_init, }; GType type; /* walk through all the plugins in this pluginlibrary */ i = 0; - while ((desc = pfDescriptorFunction(i++))) { + while ((desc = pfDescriptorFunction (i++))) { gchar *type_name; /* construct the type */ - type_name = g_strdup_printf("ladspa-%s",desc->Label); + type_name = g_strdup_printf ("ladspa-%s", desc->Label); g_strcanon (type_name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-+", '-'); /* if it's already registered, drop it */ - if (g_type_from_name(type_name)) { - g_free(type_name); + if (g_type_from_name (type_name)) { + g_free (type_name); continue; } /* base-init temp alloc */ - g_hash_table_insert(ladspa_descriptors, - GINT_TO_POINTER(0), - (gpointer)desc); + g_hash_table_insert (ladspa_descriptors, + GINT_TO_POINTER (0), (gpointer) desc); /* create the type now */ - type = g_type_register_static(GST_TYPE_ELEMENT, type_name, &typeinfo, 0); + type = g_type_register_static (GST_TYPE_ELEMENT, type_name, &typeinfo, 0); if (!gst_element_register (ladspa_plugin, type_name, GST_RANK_NONE, type)) continue; /* add this plugin to the hash */ - g_hash_table_insert(ladspa_descriptors, - GINT_TO_POINTER(type), - (gpointer)desc); + g_hash_table_insert (ladspa_descriptors, + GINT_TO_POINTER (type), (gpointer) desc); } g_hash_table_remove (ladspa_descriptors, GINT_TO_POINTER (0)); } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { GST_DEBUG_CATEGORY_INIT (ladspa_debug, "ladspa", - GST_DEBUG_FG_GREEN | GST_DEBUG_BG_BLACK | GST_DEBUG_BOLD, - "LADSPA"); + GST_DEBUG_FG_GREEN | GST_DEBUG_BG_BLACK | GST_DEBUG_BOLD, "LADSPA"); - ladspa_descriptors = g_hash_table_new(NULL,NULL); - parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + ladspa_descriptors = g_hash_table_new (NULL, NULL); + parent_class = g_type_class_ref (GST_TYPE_ELEMENT); ladspa_plugin = plugin; - LADSPAPluginSearch(ladspa_describe_plugin); + LADSPAPluginSearch (ladspa_describe_plugin); /* initialize dparam support library */ - gst_control_init(NULL,NULL); - + gst_control_init (NULL, NULL); + return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "ladspa", - "All LADSPA plugins", - plugin_init, - VERSION, - GST_LICENSE, - GST_PACKAGE, - GST_ORIGIN -) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "ladspa", + "All LADSPA plugins", + plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN) diff --git a/ext/ladspa/gstladspa.h b/ext/ladspa/gstladspa.h index f3556f74..b40cd145 100644 --- a/ext/ladspa/gstladspa.h +++ b/ext/ladspa/gstladspa.h @@ -31,62 +31,60 @@ #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ -typedef struct _ladspa_control_info { - gchar *name; - gchar *param_name; - gfloat lowerbound, upperbound; - gfloat def; - gboolean lower,upper,samplerate; - gboolean toggled, logarithmic, integer, writable; -} ladspa_control_info; + typedef struct _ladspa_control_info + { + gchar *name; + gchar *param_name; + gfloat lowerbound, upperbound; + gfloat def; + gboolean lower, upper, samplerate; + gboolean toggled, logarithmic, integer, writable; + } ladspa_control_info; -typedef struct _GstLADSPA GstLADSPA; -typedef struct _GstLADSPAClass GstLADSPAClass; + typedef struct _GstLADSPA GstLADSPA; + typedef struct _GstLADSPAClass GstLADSPAClass; -struct _GstLADSPA { - GstElement element; + struct _GstLADSPA + { + GstElement element; - LADSPA_Descriptor *descriptor; - LADSPA_Handle *handle; + LADSPA_Descriptor *descriptor; + LADSPA_Handle *handle; - GstDParamManager *dpman; + GstDParamManager *dpman; - gfloat *controls; - - GstPad **sinkpads, - **srcpads; + gfloat *controls; - gboolean activated; + GstPad **sinkpads, **srcpads; - gint samplerate, buffer_frames; - gint64 timestamp; - gboolean inplace_broken; -}; + gboolean activated; -struct _GstLADSPAClass { - GstElementClass parent_class; + gint samplerate, buffer_frames; + gint64 timestamp; + gboolean inplace_broken; + }; - LADSPA_Descriptor *descriptor; + struct _GstLADSPAClass + { + GstElementClass parent_class; - gint numports, - numsinkpads, - numsrcpads, - numcontrols; + LADSPA_Descriptor *descriptor; - gint *sinkpad_portnums, - *srcpad_portnums, - *control_portnums; + gint numports, numsinkpads, numsrcpads, numcontrols; - ladspa_control_info *control_info; -}; + gint *sinkpad_portnums, *srcpad_portnums, *control_portnums; + + ladspa_control_info *control_info; + }; #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __GST_LADSPA_H__ */ +#endif /* __GST_LADSPA_H__ */ diff --git a/ext/ladspa/load.c b/ext/ladspa/load.c index bf52eb1f..98337f58 100644 --- a/ext/ladspa/load.c +++ b/ext/ladspa/load.c @@ -26,18 +26,19 @@ not an absolute path (i.e. does not begin with / character), this routine will search the LADSPA_PATH for the file. */ static void * -dlopenLADSPA(const char * pcFilename, int iFlag) { +dlopenLADSPA (const char *pcFilename, int iFlag) +{ - char * pcBuffer; - const char * pcEnd; - const char * pcLADSPAPath; - const char * pcStart; + char *pcBuffer; + const char *pcEnd; + const char *pcLADSPAPath; + const char *pcStart; int iEndsInSO; int iNeedSlash; size_t iFilenameLength; - void * pvResult; + void *pvResult; - iFilenameLength = strlen(pcFilename); + iFilenameLength = strlen (pcFilename); pvResult = NULL; if (pcFilename[0] == '/') { @@ -45,12 +46,11 @@ dlopenLADSPA(const char * pcFilename, int iFlag) { /* The filename is absolute. Assume the user knows what he/she is doing and simply dlopen() it. */ - pvResult = dlopen(pcFilename, iFlag); + pvResult = dlopen (pcFilename, iFlag); if (pvResult != NULL) return pvResult; - } - else { + } else { /* If the filename is not absolute then we wish to check along the LADSPA_PATH path to see if we can find the file there. We do @@ -63,8 +63,8 @@ dlopenLADSPA(const char * pcFilename, int iFlag) { */ pcLADSPAPath = g_strdup_printf ("%s:/usr/lib/ladspa:/usr/local/lib/ladspa", - getenv("LADSPA_PATH")); - + getenv ("LADSPA_PATH")); + if (pcLADSPAPath) { pcStart = pcLADSPAPath; @@ -72,24 +72,24 @@ dlopenLADSPA(const char * pcFilename, int iFlag) { pcEnd = pcStart; while (*pcEnd != ':' && *pcEnd != '\0') pcEnd++; - - pcBuffer = malloc(iFilenameLength + 2 + (pcEnd - pcStart)); + + pcBuffer = malloc (iFilenameLength + 2 + (pcEnd - pcStart)); if (pcEnd > pcStart) - strncpy(pcBuffer, pcStart, pcEnd - pcStart); + strncpy (pcBuffer, pcStart, pcEnd - pcStart); iNeedSlash = 0; if (pcEnd > pcStart) if (*(pcEnd - 1) != '/') { iNeedSlash = 1; pcBuffer[pcEnd - pcStart] = '/'; } - strcpy(pcBuffer + iNeedSlash + (pcEnd - pcStart), pcFilename); - - pvResult = dlopen(pcBuffer, iFlag); - + strcpy (pcBuffer + iNeedSlash + (pcEnd - pcStart), pcFilename); + + pvResult = dlopen (pcBuffer, iFlag); + free (pcBuffer); if (pvResult != NULL) return pvResult; - + pcStart = pcEnd; if (*pcStart == ':') pcStart++; @@ -101,13 +101,13 @@ dlopenLADSPA(const char * pcFilename, int iFlag) { ".so". In this case, add this suffix and recurse. */ iEndsInSO = 0; if (iFilenameLength > 3) - iEndsInSO = (strcmp(pcFilename + iFilenameLength - 3, ".so") == 0); + iEndsInSO = (strcmp (pcFilename + iFilenameLength - 3, ".so") == 0); if (!iEndsInSO) { - pcBuffer = malloc(iFilenameLength + 4); - strcpy(pcBuffer, pcFilename); - strcat(pcBuffer, ".so"); - pvResult = dlopenLADSPA(pcBuffer, iFlag); - free(pcBuffer); + pcBuffer = malloc (iFilenameLength + 4); + strcpy (pcBuffer, pcFilename); + strcat (pcBuffer, ".so"); + pvResult = dlopenLADSPA (pcBuffer, iFlag); + free (pcBuffer); } if (pvResult != NULL) @@ -120,23 +120,22 @@ dlopenLADSPA(const char * pcFilename, int iFlag) { will be kept when multiple calls are made to dlopen(). We've covered the former case - now we can handle the latter by calling dlopen() again here. */ - return dlopen(pcFilename, iFlag); + return dlopen (pcFilename, iFlag); } /*****************************************************************************/ void * -loadLADSPAPluginLibrary(const char * pcPluginFilename) { +loadLADSPAPluginLibrary (const char *pcPluginFilename) +{ - void * pvPluginHandle; + void *pvPluginHandle; - pvPluginHandle = dlopenLADSPA(pcPluginFilename, RTLD_NOW); + pvPluginHandle = dlopenLADSPA (pcPluginFilename, RTLD_NOW); if (!pvPluginHandle) { - fprintf(stderr, - "Failed to load plugin \"%s\": %s\n", - pcPluginFilename, - dlerror()); - exit(1); + fprintf (stderr, + "Failed to load plugin \"%s\": %s\n", pcPluginFilename, dlerror ()); + exit (1); } return pvPluginHandle; @@ -144,49 +143,49 @@ loadLADSPAPluginLibrary(const char * pcPluginFilename) { /*****************************************************************************/ -void -unloadLADSPAPluginLibrary(void * pvLADSPAPluginLibrary) { - dlclose(pvLADSPAPluginLibrary); +void +unloadLADSPAPluginLibrary (void *pvLADSPAPluginLibrary) +{ + dlclose (pvLADSPAPluginLibrary); } /*****************************************************************************/ const LADSPA_Descriptor * -findLADSPAPluginDescriptor(void * pvLADSPAPluginLibrary, - const char * pcPluginLibraryFilename, - const char * pcPluginLabel) { +findLADSPAPluginDescriptor (void *pvLADSPAPluginLibrary, + const char *pcPluginLibraryFilename, const char *pcPluginLabel) +{ - const LADSPA_Descriptor * psDescriptor; + const LADSPA_Descriptor *psDescriptor; LADSPA_Descriptor_Function pfDescriptorFunction; unsigned long lPluginIndex; - dlerror(); - pfDescriptorFunction - = (LADSPA_Descriptor_Function)dlsym(pvLADSPAPluginLibrary, - "ladspa_descriptor"); + dlerror (); + pfDescriptorFunction + = (LADSPA_Descriptor_Function) dlsym (pvLADSPAPluginLibrary, + "ladspa_descriptor"); if (!pfDescriptorFunction) { - const char * pcError = dlerror(); + const char *pcError = dlerror (); + if (pcError) { - fprintf(stderr, - "Unable to find ladspa_descriptor() function in plugin " - "library file \"%s\": %s.\n" - "Are you sure this is a LADSPA plugin file?\n", - pcPluginLibraryFilename, - pcError); - exit(1); + fprintf (stderr, + "Unable to find ladspa_descriptor() function in plugin " + "library file \"%s\": %s.\n" + "Are you sure this is a LADSPA plugin file?\n", + pcPluginLibraryFilename, pcError); + exit (1); } } for (lPluginIndex = 0;; lPluginIndex++) { - psDescriptor = pfDescriptorFunction(lPluginIndex); + psDescriptor = pfDescriptorFunction (lPluginIndex); if (psDescriptor == NULL) { - fprintf(stderr, - "Unable to find label \"%s\" in plugin library file \"%s\".\n", - pcPluginLabel, - pcPluginLibraryFilename); - exit(1); + fprintf (stderr, + "Unable to find label \"%s\" in plugin library file \"%s\".\n", + pcPluginLabel, pcPluginLibraryFilename); + exit (1); } - if (strcmp(psDescriptor->Label, pcPluginLabel) == 0) + if (strcmp (psDescriptor->Label, pcPluginLabel) == 0) return psDescriptor; } } diff --git a/ext/ladspa/search.c b/ext/ladspa/search.c index 08b28d12..0f690275 100644 --- a/ext/ladspa/search.c +++ b/ext/ladspa/search.c @@ -27,19 +27,20 @@ /* Search just the one directory. */ static void -LADSPADirectoryPluginSearch -(const char * pcDirectory, - LADSPAPluginSearchCallbackFunction fCallbackFunction) { + LADSPADirectoryPluginSearch + (const char *pcDirectory, + LADSPAPluginSearchCallbackFunction fCallbackFunction) +{ - char * pcFilename; - DIR * psDirectory; + char *pcFilename; + DIR *psDirectory; LADSPA_Descriptor_Function fDescriptorFunction; long lDirLength; long iNeedSlash; - struct dirent * psDirectoryEntry; - void * pvPluginHandle; + struct dirent *psDirectoryEntry; + void *pvPluginHandle; - lDirLength = strlen(pcDirectory); + lDirLength = strlen (pcDirectory); if (!lDirLength) return; if (pcDirectory[lDirLength - 1] == '/') @@ -47,66 +48,63 @@ LADSPADirectoryPluginSearch else iNeedSlash = 1; - psDirectory = opendir(pcDirectory); + psDirectory = opendir (pcDirectory); if (!psDirectory) return; while (1) { - psDirectoryEntry = readdir(psDirectory); + psDirectoryEntry = readdir (psDirectory); if (!psDirectoryEntry) { - closedir(psDirectory); + closedir (psDirectory); return; } - pcFilename = malloc(lDirLength - + strlen(psDirectoryEntry->d_name) - + 1 + iNeedSlash); - strcpy(pcFilename, pcDirectory); + pcFilename = malloc (lDirLength + strlen (psDirectoryEntry->d_name) + + 1 + iNeedSlash); + strcpy (pcFilename, pcDirectory); if (iNeedSlash) - strcat(pcFilename, "/"); - strcat(pcFilename, psDirectoryEntry->d_name); - - pvPluginHandle = dlopen(pcFilename, RTLD_LAZY); + strcat (pcFilename, "/"); + strcat (pcFilename, psDirectoryEntry->d_name); + + pvPluginHandle = dlopen (pcFilename, RTLD_LAZY); if (pvPluginHandle) { /* This is a file and the file is a shared library! */ - dlerror(); + dlerror (); fDescriptorFunction - = (LADSPA_Descriptor_Function)dlsym(pvPluginHandle, - "ladspa_descriptor"); - if (dlerror() == NULL && fDescriptorFunction) { + = (LADSPA_Descriptor_Function) dlsym (pvPluginHandle, + "ladspa_descriptor"); + if (dlerror () == NULL && fDescriptorFunction) { /* We've successfully found a ladspa_descriptor function. Pass - it to the callback function. */ - fCallbackFunction(pcFilename, - pvPluginHandle, - fDescriptorFunction); - } - else { + it to the callback function. */ + fCallbackFunction (pcFilename, pvPluginHandle, fDescriptorFunction); + } else { /* It was a library, but not a LADSPA one. Unload it. */ - dlclose(pcFilename); + dlclose (pcFilename); } } - free(pcFilename); + free (pcFilename); } } /*****************************************************************************/ -void -LADSPAPluginSearch(LADSPAPluginSearchCallbackFunction fCallbackFunction) { +void +LADSPAPluginSearch (LADSPAPluginSearchCallbackFunction fCallbackFunction) +{ - char * pcBuffer; - const char * pcEnd; - const char * pcLADSPAPath; - const char * pcStart; + char *pcBuffer; + const char *pcEnd; + const char *pcLADSPAPath; + const char *pcStart; /* thomasvs: I'm sorry, but I'm going to add glib stuff here. - * I'm appending logical values for LADSPA_PATH here - */ + * I'm appending logical values for LADSPA_PATH here + */ pcLADSPAPath = g_strdup_printf ("%s:/usr/lib/ladspa:/usr/local/lib/ladspa", - getenv("LADSPA_PATH")); + getenv ("LADSPA_PATH")); if (!pcLADSPAPath) { /* fprintf(stderr, */ @@ -114,20 +112,20 @@ LADSPAPluginSearch(LADSPAPluginSearchCallbackFunction fCallbackFunction) { /* "environment variable set.\n"); */ return; } - + pcStart = pcLADSPAPath; while (*pcStart != '\0') { pcEnd = pcStart; while (*pcEnd != ':' && *pcEnd != '\0') pcEnd++; - - pcBuffer = malloc(1 + pcEnd - pcStart); + + pcBuffer = malloc (1 + pcEnd - pcStart); if (pcEnd > pcStart) - strncpy(pcBuffer, pcStart, pcEnd - pcStart); + strncpy (pcBuffer, pcStart, pcEnd - pcStart); pcBuffer[pcEnd - pcStart] = '\0'; - - LADSPADirectoryPluginSearch(pcBuffer, fCallbackFunction); - free(pcBuffer); + + LADSPADirectoryPluginSearch (pcBuffer, fCallbackFunction); + free (pcBuffer); pcStart = pcEnd; if (*pcStart == ':') diff --git a/ext/ladspa/utils.h b/ext/ladspa/utils.h index d470eb0d..7a22b50b 100644 --- a/ext/ladspa/utils.h +++ b/ext/ladspa/utils.h @@ -20,20 +20,19 @@ unloadLADSPAPluginLibrary(). Errors are handled by writing a message to stderr and calling exit(1). It is alright (although inefficient) to call this more than once for the same file. */ -void * loadLADSPAPluginLibrary(const char * pcPluginFilename); +void *loadLADSPAPluginLibrary (const char *pcPluginFilename); /* This function unloads a LADSPA plugin library. */ -void unloadLADSPAPluginLibrary(void * pvLADSPAPluginLibrary); +void unloadLADSPAPluginLibrary (void *pvLADSPAPluginLibrary); /* This function locates a LADSPA plugin within a plugin library loaded with loadLADSPAPluginLibrary(). Errors are handled by writing a message to stderr and calling exit(1). Note that the plugin library filename is only included to help provide informative error messages. */ -const LADSPA_Descriptor * -findLADSPAPluginDescriptor(void * pvLADSPAPluginLibrary, - const char * pcPluginLibraryFilename, - const char * pcPluginLabel); +const LADSPA_Descriptor *findLADSPAPluginDescriptor (void + *pvLADSPAPluginLibrary, const char *pcPluginLibraryFilename, + const char *pcPluginLabel); /*****************************************************************************/ @@ -44,16 +43,15 @@ findLADSPAPluginDescriptor(void * pvLADSPAPluginLibrary, style) and a LADSPA_DescriptorFunction (from which LADSPA_Descriptors can be acquired). */ typedef void LADSPAPluginSearchCallbackFunction -(const char * pcFullFilename, - void * pvPluginHandle, - LADSPA_Descriptor_Function fDescriptorFunction); + (const char *pcFullFilename, + void *pvPluginHandle, LADSPA_Descriptor_Function fDescriptorFunction); /* Search through the $(LADSPA_PATH) (or a default path) for any LADSPA plugin libraries. Each plugin library is tested using dlopen() and dlsym(,"ladspa_descriptor"). After loading each library, the callback function is called to process it. This function leaves items passed to the callback function open. */ -void LADSPAPluginSearch(LADSPAPluginSearchCallbackFunction fCallbackFunction); +void LADSPAPluginSearch (LADSPAPluginSearchCallbackFunction fCallbackFunction); /*****************************************************************************/ diff --git a/ext/libcaca/gstcacasink.c b/ext/libcaca/gstcacasink.c index e45677d4..4cb64e4b 100644 --- a/ext/libcaca/gstcacasink.c +++ b/ext/libcaca/gstcacasink.c @@ -36,12 +36,14 @@ static GstElementDetails gst_cacasink_details = { }; /* cacasink signals and args */ -enum { +enum +{ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_SCREEN_WIDTH, ARG_SCREEN_HEIGHT, @@ -49,33 +51,32 @@ enum { ARG_ANTIALIASING }; -static GstStaticPadTemplate sink_template = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB ";" GST_VIDEO_CAPS_RGBx ";" GST_VIDEO_CAPS_RGB_16 ";" GST_VIDEO_CAPS_RGB_15) -); +static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB ";" GST_VIDEO_CAPS_RGBx ";" + GST_VIDEO_CAPS_RGB_16 ";" GST_VIDEO_CAPS_RGB_15) + ); static void gst_cacasink_base_init (gpointer g_class); -static void gst_cacasink_class_init (GstCACASinkClass *klass); -static void gst_cacasink_init (GstCACASink *cacasink); -static void gst_cacasink_interface_init (GstImplementsInterfaceClass *klass); -static gboolean gst_cacasink_interface_supported (GstImplementsInterface *iface, - GType type); -static void gst_cacasink_navigation_init (GstNavigationInterface *iface); -static void gst_cacasink_navigation_send_event (GstNavigation *navigation, - GstStructure *structure); +static void gst_cacasink_class_init (GstCACASinkClass * klass); +static void gst_cacasink_init (GstCACASink * cacasink); +static void gst_cacasink_interface_init (GstImplementsInterfaceClass * klass); +static gboolean gst_cacasink_interface_supported (GstImplementsInterface * + iface, GType type); +static void gst_cacasink_navigation_init (GstNavigationInterface * iface); +static void gst_cacasink_navigation_send_event (GstNavigation * navigation, + GstStructure * structure); -static void gst_cacasink_chain (GstPad *pad, GstData *_data); +static void gst_cacasink_chain (GstPad * pad, GstData * _data); -static void gst_cacasink_set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec); -static void gst_cacasink_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec); -static void gst_cacasink_dispose (GObject *object); +static void gst_cacasink_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_cacasink_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); +static void gst_cacasink_dispose (GObject * object); -static GstElementStateReturn gst_cacasink_change_state (GstElement *element); +static GstElementStateReturn gst_cacasink_change_state (GstElement * element); static GstElementClass *parent_class = NULL; @@ -86,17 +87,17 @@ gst_cacasink_get_type (void) if (!cacasink_type) { static const GTypeInfo cacasink_info = { - sizeof(GstCACASinkClass), + sizeof (GstCACASinkClass), gst_cacasink_base_init, NULL, (GClassInitFunc) gst_cacasink_class_init, NULL, NULL, - sizeof(GstCACASink), + sizeof (GstCACASink), 0, (GInstanceInitFunc) gst_cacasink_init, }; - + static const GInterfaceInfo iface_info = { (GInterfaceInitFunc) gst_cacasink_interface_init, NULL, @@ -109,12 +110,14 @@ gst_cacasink_get_type (void) NULL, }; - cacasink_type = g_type_register_static (GST_TYPE_VIDEOSINK, "GstCACASink", &cacasink_info, 0); - + cacasink_type = + g_type_register_static (GST_TYPE_VIDEOSINK, "GstCACASink", + &cacasink_info, 0); + g_type_add_interface_static (cacasink_type, GST_TYPE_IMPLEMENTS_INTERFACE, - &iface_info); + &iface_info); g_type_add_interface_static (cacasink_type, GST_TYPE_NAVIGATION, - &navigation_info); + &navigation_info); } return cacasink_type; } @@ -124,18 +127,20 @@ static GType gst_cacasink_dither_get_type (void) { static GType dither_type = 0; + if (!dither_type) { GEnumValue *dithers; gint n_dithers; gint i; gchar *caca_dithernames[] = { - "NONE", "ORDERED2", "ORDERED4", "ORDERED8", "RANDOM", NULL}; + "NONE", "ORDERED2", "ORDERED4", "ORDERED8", "RANDOM", NULL + }; n_dithers = 5; - - dithers = g_new0(GEnumValue, n_dithers + 1); - for (i = 0; i < n_dithers; i++){ + dithers = g_new0 (GEnumValue, n_dithers + 1); + + for (i = 0; i < n_dithers; i++) { dithers[i].value = i; dithers[i].value_name = g_strdup (caca_dithernames[i]); dithers[i].value_nick = g_strdup (caca_dithernames[i]); @@ -155,35 +160,31 @@ gst_cacasink_base_init (gpointer g_class) GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); gst_element_class_set_details (element_class, &gst_cacasink_details); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&sink_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_template)); } static void -gst_cacasink_class_init (GstCACASinkClass *klass) +gst_cacasink_class_init (GstCACASinkClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; GstVideoSinkClass *gstvs_class; - gobject_class = (GObjectClass*)klass; - gstelement_class = (GstElementClass*)klass; - gstvs_class = (GstVideoSinkClass*) klass; + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; + gstvs_class = (GstVideoSinkClass *) klass; parent_class = g_type_class_ref (GST_TYPE_ELEMENT); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SCREEN_WIDTH, - g_param_spec_int("screen_width","screen_width","screen_width", - G_MININT,G_MAXINT,0,G_PARAM_READABLE)); /* CHECKME */ - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SCREEN_HEIGHT, - g_param_spec_int("screen_height","screen_height","screen_height", - G_MININT,G_MAXINT,0,G_PARAM_READABLE)); /* CHECKME */ - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_DITHER, - g_param_spec_enum("dither","Dither Type","Set type of Dither", - GST_TYPE_CACADITHER, 0, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SCREEN_WIDTH, g_param_spec_int ("screen_width", "screen_width", "screen_width", G_MININT, G_MAXINT, 0, G_PARAM_READABLE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SCREEN_HEIGHT, g_param_spec_int ("screen_height", "screen_height", "screen_height", G_MININT, G_MAXINT, 0, G_PARAM_READABLE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DITHER, + g_param_spec_enum ("dither", "Dither Type", "Set type of Dither", + GST_TYPE_CACADITHER, 0, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ANTIALIASING, - g_param_spec_boolean ("anti_aliasing", "Anti-Aliasing", - "Enables Anti-Aliasing", TRUE, G_PARAM_READWRITE)); + g_param_spec_boolean ("anti_aliasing", "Anti-Aliasing", + "Enables Anti-Aliasing", TRUE, G_PARAM_READWRITE)); gobject_class->set_property = gst_cacasink_set_property; gobject_class->get_property = gst_cacasink_get_property; @@ -193,13 +194,13 @@ gst_cacasink_class_init (GstCACASinkClass *klass) } static void -gst_cacasink_interface_init (GstImplementsInterfaceClass *klass) +gst_cacasink_interface_init (GstImplementsInterfaceClass * klass) { klass->supported = gst_cacasink_interface_supported; } static gboolean -gst_cacasink_interface_supported (GstImplementsInterface *iface, GType type) +gst_cacasink_interface_supported (GstImplementsInterface * iface, GType type) { g_assert (type == GST_TYPE_NAVIGATION); @@ -207,31 +208,31 @@ gst_cacasink_interface_supported (GstImplementsInterface *iface, GType type) } static void -gst_cacasink_navigation_init (GstNavigationInterface *iface) +gst_cacasink_navigation_init (GstNavigationInterface * iface) { iface->send_event = gst_cacasink_navigation_send_event; } static void -gst_cacasink_navigation_send_event (GstNavigation *navigation, - GstStructure *structure) +gst_cacasink_navigation_send_event (GstNavigation * navigation, + GstStructure * structure) { GstCACASink *cacasink = GST_CACASINK (navigation); GstEvent *event; event = gst_event_new (GST_EVENT_NAVIGATION); - /*GST_EVENT_TIMESTAMP (event) = 0;*/ + /*GST_EVENT_TIMESTAMP (event) = 0; */ event->event_data.structure.structure = structure; /* FIXME * Obviously, the pointer x,y coordinates need to be adjusted by the * window size and relation to the bounding window. */ - gst_pad_send_event (gst_pad_get_peer (GST_VIDEOSINK_PAD(cacasink)), - event); + gst_pad_send_event (gst_pad_get_peer (GST_VIDEOSINK_PAD (cacasink)), event); } + static GstPadLinkReturn -gst_cacasink_sinkconnect (GstPad *pad, const GstCaps *caps) +gst_cacasink_sinkconnect (GstPad * pad, const GstCaps * caps) { GstCACASink *cacasink; GstStructure *structure; @@ -239,67 +240,62 @@ gst_cacasink_sinkconnect (GstPad *pad, const GstCaps *caps) cacasink = GST_CACASINK (gst_pad_get_parent (pad)); /*if (!GST_CAPS_IS_FIXED (caps)) - return GST_PAD_LINK_DELAYED;*/ - + return GST_PAD_LINK_DELAYED; */ + structure = gst_caps_get_structure (caps, 0); - gst_structure_get_int (structure, "width", - &(GST_VIDEOSINK_WIDTH (cacasink))); + gst_structure_get_int (structure, "width", &(GST_VIDEOSINK_WIDTH (cacasink))); gst_structure_get_int (structure, "height", - &(GST_VIDEOSINK_HEIGHT (cacasink))); + &(GST_VIDEOSINK_HEIGHT (cacasink))); gst_structure_get_int (structure, "bpp", &cacasink->bpp); gst_structure_get_int (structure, "red_mask", &cacasink->red_mask); gst_structure_get_int (structure, "green_mask", &cacasink->green_mask); gst_structure_get_int (structure, "blue_mask", &cacasink->blue_mask); if (cacasink->bpp == 24) { - cacasink->red_mask = GUINT32_FROM_BE (cacasink->red_mask) >> 8; + cacasink->red_mask = GUINT32_FROM_BE (cacasink->red_mask) >> 8; cacasink->green_mask = GUINT32_FROM_BE (cacasink->green_mask) >> 8; - cacasink->blue_mask = GUINT32_FROM_BE (cacasink->blue_mask) >> 8; + cacasink->blue_mask = GUINT32_FROM_BE (cacasink->blue_mask) >> 8; } else if (cacasink->bpp == 32) { - cacasink->red_mask = GUINT32_FROM_BE (cacasink->red_mask); + cacasink->red_mask = GUINT32_FROM_BE (cacasink->red_mask); cacasink->green_mask = GUINT32_FROM_BE (cacasink->green_mask); - cacasink->blue_mask = GUINT32_FROM_BE (cacasink->blue_mask); + cacasink->blue_mask = GUINT32_FROM_BE (cacasink->blue_mask); } else if (cacasink->bpp == 16 || cacasink->bpp == 15) { - cacasink->red_mask = GUINT16_FROM_BE (cacasink->red_mask); + cacasink->red_mask = GUINT16_FROM_BE (cacasink->red_mask); cacasink->green_mask = GUINT16_FROM_BE (cacasink->green_mask); - cacasink->blue_mask = GUINT16_FROM_BE (cacasink->blue_mask); + cacasink->blue_mask = GUINT16_FROM_BE (cacasink->blue_mask); } if (cacasink->bitmap) { caca_free_bitmap (cacasink->bitmap); } - cacasink->bitmap = caca_create_bitmap ( - cacasink->bpp, - GST_VIDEOSINK_WIDTH (cacasink), - GST_VIDEOSINK_HEIGHT (cacasink), - GST_VIDEOSINK_WIDTH (cacasink) * cacasink->bpp/8, - cacasink->red_mask, - cacasink->green_mask, - cacasink->blue_mask, - 0); + cacasink->bitmap = caca_create_bitmap (cacasink->bpp, + GST_VIDEOSINK_WIDTH (cacasink), + GST_VIDEOSINK_HEIGHT (cacasink), + GST_VIDEOSINK_WIDTH (cacasink) * cacasink->bpp / 8, + cacasink->red_mask, cacasink->green_mask, cacasink->blue_mask, 0); if (!cacasink->bitmap) { - return GST_PAD_LINK_DELAYED; + return GST_PAD_LINK_DELAYED; } - + return GST_PAD_LINK_OK; } static void -gst_cacasink_init (GstCACASink *cacasink) +gst_cacasink_init (GstCACASink * cacasink) { - GST_VIDEOSINK_PAD (cacasink) = gst_pad_new_from_template ( - gst_static_pad_template_get (&sink_template), "sink"); + GST_VIDEOSINK_PAD (cacasink) = + gst_pad_new_from_template (gst_static_pad_template_get (&sink_template), + "sink"); gst_element_add_pad (GST_ELEMENT (cacasink), GST_VIDEOSINK_PAD (cacasink)); - gst_pad_set_chain_function (GST_VIDEOSINK_PAD (cacasink), - gst_cacasink_chain); - gst_pad_set_link_function (GST_VIDEOSINK_PAD (cacasink), - gst_cacasink_sinkconnect); + gst_pad_set_chain_function (GST_VIDEOSINK_PAD (cacasink), gst_cacasink_chain); + gst_pad_set_link_function (GST_VIDEOSINK_PAD (cacasink), + gst_cacasink_sinkconnect); cacasink->screen_width = GST_CACA_DEFAULT_SCREEN_WIDTH; cacasink->screen_height = GST_CACA_DEFAULT_SCREEN_HEIGHT; @@ -318,11 +314,11 @@ gst_cacasink_init (GstCACASink *cacasink) cacasink->dither = 0; caca_set_dithering (CACA_DITHERING_NONE); - GST_FLAG_SET(cacasink, GST_ELEMENT_THREAD_SUGGESTED); + GST_FLAG_SET (cacasink, GST_ELEMENT_THREAD_SUGGESTED); } static void -gst_cacasink_chain (GstPad *pad, GstData *_data) +gst_cacasink_chain (GstPad * pad, GstData * _data) { GstBuffer *buf = GST_BUFFER (_data); GstCACASink *cacasink; @@ -336,14 +332,15 @@ gst_cacasink_chain (GstPad *pad, GstData *_data) cacasink = GST_CACASINK (gst_pad_get_parent (pad)); if (cacasink->id && GST_CLOCK_TIME_IS_VALID (time)) { - GST_DEBUG ("videosink: clock %s wait: %" G_GUINT64_FORMAT " %u", - GST_OBJECT_NAME (GST_VIDEOSINK_CLOCK (cacasink)), - time, GST_BUFFER_SIZE (buf)); + GST_DEBUG ("videosink: clock %s wait: %" G_GUINT64_FORMAT " %u", + GST_OBJECT_NAME (GST_VIDEOSINK_CLOCK (cacasink)), + time, GST_BUFFER_SIZE (buf)); gst_element_wait (GST_ELEMENT (cacasink), GST_BUFFER_TIMESTAMP (buf)); } caca_clear (); - caca_draw_bitmap (0, 0, cacasink->screen_width-1, cacasink->screen_height-1, cacasink->bitmap, GST_BUFFER_DATA (buf)); + caca_draw_bitmap (0, 0, cacasink->screen_width - 1, + cacasink->screen_height - 1, cacasink->bitmap, GST_BUFFER_DATA (buf)); caca_refresh (); if (GST_VIDEOSINK_CLOCK (cacasink)) { @@ -353,12 +350,12 @@ gst_cacasink_chain (GstPad *pad, GstData *_data) cacasink->correction = 0; } - gst_buffer_unref(buf); + gst_buffer_unref (buf); } static void -gst_cacasink_dispose (GObject *object) +gst_cacasink_dispose (GObject * object) { GstCACASink *cacasink = GST_CACASINK (object); @@ -367,12 +364,13 @@ gst_cacasink_dispose (GObject *object) } caca_end (); - + G_OBJECT_CLASS (parent_class)->dispose (object); } static void -gst_cacasink_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +gst_cacasink_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) { GstCACASink *cacasink; @@ -382,17 +380,17 @@ gst_cacasink_set_property (GObject *object, guint prop_id, const GValue *value, cacasink = GST_CACASINK (object); switch (prop_id) { - case ARG_DITHER: { + case ARG_DITHER:{ cacasink->dither = g_value_get_enum (value); caca_set_dithering (cacasink->dither + CACA_DITHERING_NONE); break; } - case ARG_ANTIALIASING: { + case ARG_ANTIALIASING:{ cacasink->antialiasing = g_value_get_boolean (value); if (cacasink->antialiasing) { caca_set_feature (CACA_ANTIALIASING_MAX); } - + else { caca_set_feature (CACA_ANTIALIASING_MIN); } @@ -404,31 +402,32 @@ gst_cacasink_set_property (GObject *object, guint prop_id, const GValue *value, } static void -gst_cacasink_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +gst_cacasink_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { GstCACASink *cacasink; /* it's not null if we got it, but it might not be ours */ - cacasink = GST_CACASINK(object); + cacasink = GST_CACASINK (object); switch (prop_id) { - case ARG_SCREEN_WIDTH: { + case ARG_SCREEN_WIDTH:{ g_value_set_int (value, cacasink->screen_width); break; } - case ARG_SCREEN_HEIGHT: { + case ARG_SCREEN_HEIGHT:{ g_value_set_int (value, cacasink->screen_height); break; } - case ARG_DITHER: { + case ARG_DITHER:{ g_value_set_enum (value, cacasink->dither); break; } - case ARG_ANTIALIASING: { + case ARG_ANTIALIASING:{ g_value_set_boolean (value, cacasink->antialiasing); break; } - default: { + default:{ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } @@ -436,9 +435,9 @@ gst_cacasink_get_property (GObject *object, guint prop_id, GValue *value, GParam } static gboolean -gst_cacasink_open (GstCACASink *cacasink) +gst_cacasink_open (GstCACASink * cacasink) { - g_return_val_if_fail (!GST_FLAG_IS_SET (cacasink ,GST_CACASINK_OPEN), FALSE); + g_return_val_if_fail (!GST_FLAG_IS_SET (cacasink, GST_CACASINK_OPEN), FALSE); GST_FLAG_SET (cacasink, GST_CACASINK_OPEN); @@ -446,15 +445,15 @@ gst_cacasink_open (GstCACASink *cacasink) } static void -gst_cacasink_close (GstCACASink *cacasink) +gst_cacasink_close (GstCACASink * cacasink) { - g_return_if_fail (GST_FLAG_IS_SET (cacasink ,GST_CACASINK_OPEN)); + g_return_if_fail (GST_FLAG_IS_SET (cacasink, GST_CACASINK_OPEN)); GST_FLAG_UNSET (cacasink, GST_CACASINK_OPEN); } static GstElementStateReturn -gst_cacasink_change_state (GstElement *element) +gst_cacasink_change_state (GstElement * element) { g_return_val_if_fail (GST_IS_CACASINK (element), GST_STATE_FAILURE); @@ -464,7 +463,7 @@ gst_cacasink_change_state (GstElement *element) } else { if (!GST_FLAG_IS_SET (element, GST_CACASINK_OPEN)) { if (!gst_cacasink_open (GST_CACASINK (element))) - return GST_STATE_FAILURE; + return GST_STATE_FAILURE; } } @@ -475,26 +474,21 @@ gst_cacasink_change_state (GstElement *element) } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { /* Loading the library containing GstVideoSink, our parent object */ if (!gst_library_load ("gstvideo")) return FALSE; - - if (!gst_element_register (plugin, "cacasink", GST_RANK_NONE, GST_TYPE_CACASINK)) + + if (!gst_element_register (plugin, "cacasink", GST_RANK_NONE, + GST_TYPE_CACASINK)) return FALSE; return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "cacasink", - "Colored ASCII Art video sink", - plugin_init, - VERSION, - GST_LICENSE, - GST_PACKAGE, - GST_ORIGIN -) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "cacasink", + "Colored ASCII Art video sink", + plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN) diff --git a/ext/libcaca/gstcacasink.h b/ext/libcaca/gstcacasink.h index 3a6d4f23..2080c284 100644 --- a/ext/libcaca/gstcacasink.h +++ b/ext/libcaca/gstcacasink.h @@ -28,8 +28,9 @@ #include <caca.h> #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define GST_CACA_DEFAULT_SCREEN_WIDTH 80 #define GST_CACA_DEFAULT_SCREEN_HEIGHT 25 @@ -53,44 +54,47 @@ extern "C" { #define GST_IS_CACASINK_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_CACASINK)) -typedef enum { - GST_CACASINK_OPEN = GST_ELEMENT_FLAG_LAST, + typedef enum + { + GST_CACASINK_OPEN = GST_ELEMENT_FLAG_LAST, - GST_CACASINK_FLAG_LAST = GST_ELEMENT_FLAG_LAST + 2, -} GstCACASinkFlags; + GST_CACASINK_FLAG_LAST = GST_ELEMENT_FLAG_LAST + 2, + } GstCACASinkFlags; -typedef struct _GstCACASink GstCACASink; -typedef struct _GstCACASinkClass GstCACASinkClass; + typedef struct _GstCACASink GstCACASink; + typedef struct _GstCACASinkClass GstCACASinkClass; -struct _GstCACASink { - GstVideoSink videosink; + struct _GstCACASink + { + GstVideoSink videosink; - GstPad *sinkpad; + GstPad *sinkpad; - gulong format; - gint screen_width, screen_height; - guint bpp; - guint dither; - gboolean antialiasing; - guint red_mask, green_mask, blue_mask; + gulong format; + gint screen_width, screen_height; + guint bpp; + guint dither; + gboolean antialiasing; + guint red_mask, green_mask, blue_mask; - gint64 correction; - GstClockID id; + gint64 correction; + GstClockID id; - struct caca_bitmap *bitmap; -}; + struct caca_bitmap *bitmap; + }; -struct _GstCACASinkClass { - GstVideoSinkClass parent_class; + struct _GstCACASinkClass + { + GstVideoSinkClass parent_class; - /* signals */ -}; + /* signals */ + }; -GType gst_cacasink_get_type(void); + GType gst_cacasink_get_type (void); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __GST_CACASINKE_H__ */ +#endif /* __GST_CACASINKE_H__ */ diff --git a/ext/libpng/gstpng.c b/ext/libpng/gstpng.c index 38a492f4..dab8d9d9 100644 --- a/ext/libpng/gstpng.c +++ b/ext/libpng/gstpng.c @@ -34,13 +34,7 @@ plugin_init (GstPlugin * plugin) return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "png", - "PNG plugin library", - plugin_init, - VERSION, - "LGPL", - GST_PACKAGE, - GST_ORIGIN) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "png", + "PNG plugin library", plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN) diff --git a/ext/libpng/gstpngenc.c b/ext/libpng/gstpngenc.c index 393e642c..78055cce 100644 --- a/ext/libpng/gstpngenc.c +++ b/ext/libpng/gstpngenc.c @@ -47,29 +47,32 @@ enum ARG_0 }; -static void gst_pngenc_base_init (gpointer g_class); -static void gst_pngenc_class_init (GstPngEncClass *klass); -static void gst_pngenc_init (GstPngEnc *pngenc); +static void gst_pngenc_base_init (gpointer g_class); +static void gst_pngenc_class_init (GstPngEncClass * klass); +static void gst_pngenc_init (GstPngEnc * pngenc); -static void gst_pngenc_chain (GstPad *pad, GstData *_data); +static void gst_pngenc_chain (GstPad * pad, GstData * _data); GstPadTemplate *pngenc_src_template, *pngenc_sink_template; static GstElementClass *parent_class = NULL; -static void user_error_fn (png_structp png_ptr, png_const_charp error_msg) +static void +user_error_fn (png_structp png_ptr, png_const_charp error_msg) { - g_warning("%s", error_msg); + g_warning ("%s", error_msg); } -static void user_warning_fn (png_structp png_ptr, png_const_charp warning_msg) +static void +user_warning_fn (png_structp png_ptr, png_const_charp warning_msg) { - g_warning("%s", warning_msg); + g_warning ("%s", warning_msg); } -GType gst_pngenc_get_type (void) +GType +gst_pngenc_get_type (void) { static GType pngenc_type = 0; @@ -87,25 +90,24 @@ GType gst_pngenc_get_type (void) }; pngenc_type = g_type_register_static (GST_TYPE_ELEMENT, "GstPngEnc", - &pngenc_info, 0); + &pngenc_info, 0); } return pngenc_type; } -static GstCaps* +static GstCaps * png_caps_factory (void) { return gst_caps_new_simple ("video/x-png", - "width", GST_TYPE_INT_RANGE, 16, 4096, - "height", GST_TYPE_INT_RANGE, 16, 4096, - "framerate", GST_TYPE_DOUBLE_RANGE, 0.0, G_MAXDOUBLE, - NULL); + "width", GST_TYPE_INT_RANGE, 16, 4096, + "height", GST_TYPE_INT_RANGE, 16, 4096, + "framerate", GST_TYPE_DOUBLE_RANGE, 0.0, G_MAXDOUBLE, NULL); } -static GstCaps* +static GstCaps * raw_caps_factory (void) -{ +{ return gst_caps_from_string (GST_VIDEO_CAPS_RGB); } @@ -114,25 +116,23 @@ gst_pngenc_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); GstCaps *raw_caps, *png_caps; - + raw_caps = raw_caps_factory (); png_caps = png_caps_factory (); pngenc_sink_template = gst_pad_template_new ("sink", GST_PAD_SINK, - GST_PAD_ALWAYS, - raw_caps); - + GST_PAD_ALWAYS, raw_caps); + pngenc_src_template = gst_pad_template_new ("src", GST_PAD_SRC, - GST_PAD_ALWAYS, - png_caps); - + GST_PAD_ALWAYS, png_caps); + gst_element_class_add_pad_template (element_class, pngenc_sink_template); gst_element_class_add_pad_template (element_class, pngenc_src_template); gst_element_class_set_details (element_class, &gst_pngenc_details); } static void -gst_pngenc_class_init (GstPngEncClass *klass) +gst_pngenc_class_init (GstPngEncClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; @@ -145,7 +145,7 @@ gst_pngenc_class_init (GstPngEncClass *klass) static GstPadLinkReturn -gst_pngenc_sinklink (GstPad *pad, const GstCaps *caps) +gst_pngenc_sinklink (GstPad * pad, const GstCaps * caps) { GstPngEnc *pngenc; gdouble fps; @@ -161,8 +161,8 @@ gst_pngenc_sinklink (GstPad *pad, const GstCaps *caps) caps = gst_caps_new_simple ("video/x-png", "framerate", G_TYPE_DOUBLE, fps, - "width", G_TYPE_INT, pngenc->width, - "height", G_TYPE_INT, pngenc->height, NULL); + "width", G_TYPE_INT, pngenc->width, + "height", G_TYPE_INT, pngenc->height, NULL); return gst_pad_try_set_caps (pngenc->srcpad, caps); } @@ -184,9 +184,10 @@ gst_pngenc_init (GstPngEnc * pngenc) } -void user_flush_data (png_structp png_ptr) +void +user_flush_data (png_structp png_ptr) { -GstPngEnc *pngenc; + GstPngEnc *pngenc; pngenc = (GstPngEnc *) png_get_io_ptr (png_ptr); @@ -194,31 +195,31 @@ GstPngEnc *pngenc; } -void user_write_data (png_structp png_ptr, png_bytep data, png_uint_32 length) +void +user_write_data (png_structp png_ptr, png_bytep data, png_uint_32 length) { GstBuffer *buffer; GstPngEnc *pngenc; pngenc = (GstPngEnc *) png_get_io_ptr (png_ptr); - buffer = gst_buffer_new(); + buffer = gst_buffer_new (); GST_BUFFER_DATA (buffer) = g_memdup (data, length); GST_BUFFER_SIZE (buffer) = length; - if (pngenc->buffer_out) - { + if (pngenc->buffer_out) { GstBuffer *merge; + merge = gst_buffer_merge (pngenc->buffer_out, buffer); gst_buffer_unref (buffer); gst_buffer_unref (pngenc->buffer_out); pngenc->buffer_out = merge; - } - else + } else pngenc->buffer_out = buffer; } static void -gst_pngenc_chain (GstPad *pad, GstData *_data) +gst_pngenc_chain (GstPad * pad, GstData * _data) { GstBuffer *buf = GST_BUFFER (_data); GstPngEnc *pngenc; @@ -229,56 +230,50 @@ gst_pngenc_chain (GstPad *pad, GstData *_data) pngenc = GST_PNGENC (gst_pad_get_parent (pad)); pngenc->buffer_out = NULL; - if (!GST_PAD_IS_USABLE (pngenc->srcpad)) - { + if (!GST_PAD_IS_USABLE (pngenc->srcpad)) { gst_buffer_unref (buf); return; } /* initialize png struct stuff */ pngenc->png_struct_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, - (png_voidp) NULL, user_error_fn, user_warning_fn); + (png_voidp) NULL, user_error_fn, user_warning_fn); /* FIXME: better error handling */ if (pngenc->png_struct_ptr == NULL) - g_warning ("Failed to initialize png structure"); + g_warning ("Failed to initialize png structure"); pngenc->png_info_ptr = png_create_info_struct (pngenc->png_struct_ptr); - if (!pngenc->png_info_ptr) - { + if (!pngenc->png_info_ptr) { png_destroy_read_struct (&(pngenc->png_struct_ptr), (png_infopp) NULL, - (png_infopp) NULL); + (png_infopp) NULL); } /* non-0 return is from a longjmp inside of libpng */ - if (setjmp (pngenc->png_struct_ptr->jmpbuf) != 0) - { + if (setjmp (pngenc->png_struct_ptr->jmpbuf) != 0) { GST_DEBUG ("returning from longjmp"); png_destroy_write_struct (&pngenc->png_struct_ptr, &pngenc->png_info_ptr); return; } png_set_filter (pngenc->png_struct_ptr, 0, - PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE); + PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE); png_set_compression_level (pngenc->png_struct_ptr, 9); - png_set_IHDR( - pngenc->png_struct_ptr, - pngenc->png_info_ptr, - pngenc->width, - pngenc->height, - pngenc->bpp / 3, - PNG_COLOR_TYPE_RGB, - PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, - PNG_FILTER_TYPE_DEFAULT - ); + png_set_IHDR (pngenc->png_struct_ptr, + pngenc->png_info_ptr, + pngenc->width, + pngenc->height, + pngenc->bpp / 3, + PNG_COLOR_TYPE_RGB, + PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); png_set_write_fn (pngenc->png_struct_ptr, pngenc, - (png_rw_ptr) user_write_data, user_flush_data); + (png_rw_ptr) user_write_data, user_flush_data); for (row_index = 0; row_index < pngenc->height; row_index++) row_pointers[row_index] = GST_BUFFER_DATA (buf) + - (pngenc->width * row_index * pngenc->bpp / 8); + (pngenc->width * row_index * pngenc->bpp / 8); png_write_info (pngenc->png_struct_ptr, pngenc->png_info_ptr); png_write_image (pngenc->png_struct_ptr, row_pointers); diff --git a/ext/libpng/gstpngenc.h b/ext/libpng/gstpngenc.h index 59bc4ab4..1c521260 100644 --- a/ext/libpng/gstpngenc.h +++ b/ext/libpng/gstpngenc.h @@ -25,8 +25,9 @@ #include <png.h> #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define GST_TYPE_PNGENC (gst_pngenc_get_type()) @@ -35,37 +36,37 @@ extern "C" { #define GST_IS_PNGENC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PNGENC)) #define GST_IS_PNGENC_CLASS(obj)(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PNGENC)) -typedef struct _GstPngEnc GstPngEnc; -typedef struct _GstPngEncClass GstPngEncClass; + typedef struct _GstPngEnc GstPngEnc; + typedef struct _GstPngEncClass GstPngEncClass; -extern GstPadTemplate *pngenc_src_template, *pngenc_sink_template; + extern GstPadTemplate *pngenc_src_template, *pngenc_sink_template; -struct _GstPngEnc -{ - GstElement element; + struct _GstPngEnc + { + GstElement element; - GstPad *sinkpad, *srcpad; - GstBuffer *buffer_out; + GstPad *sinkpad, *srcpad; + GstBuffer *buffer_out; - png_structp png_struct_ptr; - png_infop png_info_ptr; + png_structp png_struct_ptr; + png_infop png_info_ptr; - gint width; - gint height; - gint bpp; -}; + gint width; + gint height; + gint bpp; + }; -struct _GstPngEncClass -{ - GstElementClass parent_class; -}; + struct _GstPngEncClass + { + GstElementClass parent_class; + }; -GType gst_pngenc_get_type(void); + GType gst_pngenc_get_type (void); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __GST_PNGENC_H__ */ +#endif /* __GST_PNGENC_H__ */ diff --git a/ext/mikmod/drv_gst.c b/ext/mikmod/drv_gst.c index 83d475ba..2d7b8e6e 100644 --- a/ext/mikmod/drv_gst.c +++ b/ext/mikmod/drv_gst.c @@ -10,94 +10,96 @@ static int buffer_size; static SBYTE *audiobuffer = NULL; extern int need_sync; -static BOOL mikmod_IsThere( void ) +static BOOL +mikmod_IsThere (void) { return 1; } -static BOOL mikmod_Init( void ) +static BOOL +mikmod_Init (void) { buffer_size = 32768; - if (!( audiobuffer = ( SBYTE * ) g_malloc( buffer_size ) )) + if (!(audiobuffer = (SBYTE *) g_malloc (buffer_size))) return 1; - - return VC_Init(); + + return VC_Init (); } -static void mikmod_Exit( void ) +static void +mikmod_Exit (void) { - VC_Exit(); + VC_Exit (); - if ( audiobuffer ) - { - g_free(audiobuffer); + if (audiobuffer) { + g_free (audiobuffer); audiobuffer = NULL; - } + } } -static void mikmod_Update( void ) +static void +mikmod_Update (void) { gint length; GstBuffer *outdata; - length = VC_WriteBytes((SBYTE *) audiobuffer, buffer_size); - - outdata = gst_buffer_new(); + length = VC_WriteBytes ((SBYTE *) audiobuffer, buffer_size); + + outdata = gst_buffer_new (); - GST_BUFFER_DATA( outdata ) = g_memdup( audiobuffer, length ); - GST_BUFFER_SIZE( outdata ) = length; + GST_BUFFER_DATA (outdata) = g_memdup (audiobuffer, length); + GST_BUFFER_SIZE (outdata) = length; - GST_BUFFER_TIMESTAMP( outdata ) = timestamp; + GST_BUFFER_TIMESTAMP (outdata) = timestamp; - if ( need_sync == 1 ) - { + if (need_sync == 1) { /* FIXME, send a flush event or something */ - need_sync = 0 ; + need_sync = 0; } - gst_pad_push( srcpad, GST_DATA (outdata )); - + gst_pad_push (srcpad, GST_DATA (outdata)); + } -static BOOL mikmod_Reset( void ) +static BOOL +mikmod_Reset (void) { - VC_Exit(); - return VC_Init(); + VC_Exit (); + return VC_Init (); } -MDRIVER drv_gst = -{ - NULL, - "mikmod", - "mikmod output driver v1.0", - 0, 255, +MDRIVER drv_gst = { + NULL, + "mikmod", + "mikmod output driver v1.0", + 0, 255, #if (LIBMIKMOD_VERSION > 0x030106) - "mikmod", - NULL, + "mikmod", + NULL, #endif - mikmod_IsThere, - VC_SampleLoad, - VC_SampleUnload, - VC_SampleSpace, - VC_SampleLength, - mikmod_Init, - mikmod_Exit, - mikmod_Reset, - VC_SetNumVoices, - VC_PlayStart, - VC_PlayStop, - mikmod_Update, - NULL, - VC_VoiceSetVolume, - VC_VoiceGetVolume, - VC_VoiceSetFrequency, - VC_VoiceGetFrequency, - VC_VoiceSetPanning, - VC_VoiceGetPanning, - VC_VoicePlay, - VC_VoiceStop, - VC_VoiceStopped, - VC_VoiceGetPosition, - VC_VoiceRealVolume + mikmod_IsThere, + VC_SampleLoad, + VC_SampleUnload, + VC_SampleSpace, + VC_SampleLength, + mikmod_Init, + mikmod_Exit, + mikmod_Reset, + VC_SetNumVoices, + VC_PlayStart, + VC_PlayStop, + mikmod_Update, + NULL, + VC_VoiceSetVolume, + VC_VoiceGetVolume, + VC_VoiceSetFrequency, + VC_VoiceGetFrequency, + VC_VoiceSetPanning, + VC_VoiceGetPanning, + VC_VoicePlay, + VC_VoiceStop, + VC_VoiceStopped, + VC_VoiceGetPosition, + VC_VoiceRealVolume }; diff --git a/ext/mikmod/gstmikmod.c b/ext/mikmod/gstmikmod.c index f8a6a4e8..89e057c1 100644 --- a/ext/mikmod/gstmikmod.c +++ b/ext/mikmod/gstmikmod.c @@ -34,12 +34,14 @@ GstElementDetails mikmod_details = { /* Filter signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_SONGNAME, ARG_MODTYPE, @@ -62,68 +64,67 @@ GstPad *srcpad; GstClockTime timestamp; int need_sync; -static GstStaticPadTemplate mikmod_src_factory = -GST_STATIC_PAD_TEMPLATE ( - "src", +static GstStaticPadTemplate mikmod_src_factory = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, - GST_STATIC_CAPS ( - "audio/x-raw-int, " + GST_STATIC_CAPS ("audio/x-raw-int, " "endianness = (int) BYTE_ORDER, " "signed = (boolean) TRUE, " "width = (int) 16, " "depth = (int) 16, " "rate = (int) { 8000, 11025, 22050, 44100 }, " "channels = (int) [ 1, 2 ]; " - "audio/x-raw-int, " + "audio/x-raw-int, " "signed = (boolean) FALSE, " "width = (int) 8, " "depth = (int) 8, " "rate = (int) { 8000, 11025, 22050, 44100 }, " - "channels = (int) [ 1, 2 ]" - ) -); + "channels = (int) [ 1, 2 ]") + ); static GstStaticPadTemplate mikmod_sink_factory = -GST_STATIC_PAD_TEMPLATE ( - "sink", +GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS ("audio/x-mod") -); + ); -static void gst_mikmod_base_init (gpointer g_class); -static void gst_mikmod_class_init (GstMikModClass *klass); -static void gst_mikmod_init (GstMikMod *filter); -static void gst_mikmod_set_property (GObject *object, guint id, const GValue *value, GParamSpec *pspec ); -static void gst_mikmod_get_property (GObject *object, guint id, GValue *value, GParamSpec *pspec ); -static GstPadLinkReturn gst_mikmod_srclink (GstPad *pad, const GstCaps *caps); -static GstCaps * gst_mikmod_srcfixate (GstPad *pad, const GstCaps *caps); -static void gst_mikmod_loop (GstElement *element); -static gboolean gst_mikmod_setup (GstMikMod *mikmod); -static GstElementStateReturn gst_mikmod_change_state (GstElement *element); +static void gst_mikmod_base_init (gpointer g_class); +static void gst_mikmod_class_init (GstMikModClass * klass); +static void gst_mikmod_init (GstMikMod * filter); +static void gst_mikmod_set_property (GObject * object, guint id, + const GValue * value, GParamSpec * pspec); +static void gst_mikmod_get_property (GObject * object, guint id, GValue * value, + GParamSpec * pspec); +static GstPadLinkReturn gst_mikmod_srclink (GstPad * pad, const GstCaps * caps); +static GstCaps *gst_mikmod_srcfixate (GstPad * pad, const GstCaps * caps); +static void gst_mikmod_loop (GstElement * element); +static gboolean gst_mikmod_setup (GstMikMod * mikmod); +static GstElementStateReturn gst_mikmod_change_state (GstElement * element); static GstElementClass *parent_class = NULL; GType -gst_mikmod_get_type(void) { +gst_mikmod_get_type (void) +{ static GType mikmod_type = 0; if (!mikmod_type) { static const GTypeInfo mikmod_info = { - sizeof(GstMikModClass), + sizeof (GstMikModClass), gst_mikmod_base_init, NULL, - (GClassInitFunc)gst_mikmod_class_init, + (GClassInitFunc) gst_mikmod_class_init, NULL, NULL, - sizeof(GstMikMod), + sizeof (GstMikMod), 0, - (GInstanceInitFunc)gst_mikmod_init, + (GInstanceInitFunc) gst_mikmod_init, }; - mikmod_type = g_type_register_static(GST_TYPE_ELEMENT, "GstMikmod", &mikmod_info, 0); + mikmod_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstMikmod", &mikmod_info, 0); } return mikmod_type; } @@ -141,58 +142,58 @@ gst_mikmod_base_init (gpointer g_class) } static void -gst_mikmod_class_init (GstMikModClass *klass) +gst_mikmod_class_init (GstMikModClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; - gobject_class = (GObjectClass*)klass; - gstelement_class = (GstElementClass*)klass; - - parent_class = g_type_class_ref(GST_TYPE_ELEMENT); - - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SONGNAME, - g_param_spec_string("songname","songname","songname", - NULL, G_PARAM_READABLE)); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_MODTYPE, - g_param_spec_string("modtype", "modtype", "modtype", - NULL, G_PARAM_READABLE )); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_MUSICVOLUME, - g_param_spec_int("musicvolume", "musivolume", "musicvolume", - 0, 128, 128, G_PARAM_READWRITE )); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_PANSEP, - g_param_spec_int("pansep", "pansep", "pansep", - 0, 128, 128, G_PARAM_READWRITE )); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_REVERB, - g_param_spec_int("reverb", "reverb", "reverb", - 0, 15, 0, G_PARAM_READWRITE )); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SNDFXVOLUME, - g_param_spec_int("sndfxvolume", "sndfxvolume", "sndfxvolume", - 0, 128, 128, G_PARAM_READWRITE )); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_VOLUME, - g_param_spec_int("volume", "volume", "volume", - 0, 128, 96, G_PARAM_READWRITE )); - - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_INTERP, - g_param_spec_boolean("interp", "interp", "interp", - FALSE, G_PARAM_READWRITE )); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_REVERSE, - g_param_spec_boolean("reverse", "reverse", "reverse", - FALSE, G_PARAM_READWRITE )); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SURROUND, - g_param_spec_boolean("surround", "surround", "surround", - TRUE, G_PARAM_READWRITE )); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_HQMIXER, - g_param_spec_boolean("hqmixer", "hqmixer", "hqmixer", - FALSE, G_PARAM_READWRITE )); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SOFT_MUSIC, - g_param_spec_boolean("soft_music", "soft_music", "soft_music", - TRUE, G_PARAM_READWRITE )); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SOFT_SNDFX, - g_param_spec_boolean("soft_sndfx", "soft_sndfx", "soft_sndfx", - TRUE, G_PARAM_READWRITE )); - - + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; + + parent_class = g_type_class_ref (GST_TYPE_ELEMENT); + + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SONGNAME, + g_param_spec_string ("songname", "songname", "songname", + NULL, G_PARAM_READABLE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MODTYPE, + g_param_spec_string ("modtype", "modtype", "modtype", + NULL, G_PARAM_READABLE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MUSICVOLUME, + g_param_spec_int ("musicvolume", "musivolume", "musicvolume", + 0, 128, 128, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PANSEP, + g_param_spec_int ("pansep", "pansep", "pansep", + 0, 128, 128, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_REVERB, + g_param_spec_int ("reverb", "reverb", "reverb", + 0, 15, 0, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SNDFXVOLUME, + g_param_spec_int ("sndfxvolume", "sndfxvolume", "sndfxvolume", + 0, 128, 128, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VOLUME, + g_param_spec_int ("volume", "volume", "volume", + 0, 128, 96, G_PARAM_READWRITE)); + + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_INTERP, + g_param_spec_boolean ("interp", "interp", "interp", + FALSE, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_REVERSE, + g_param_spec_boolean ("reverse", "reverse", "reverse", + FALSE, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SURROUND, + g_param_spec_boolean ("surround", "surround", "surround", + TRUE, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_HQMIXER, + g_param_spec_boolean ("hqmixer", "hqmixer", "hqmixer", + FALSE, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SOFT_MUSIC, + g_param_spec_boolean ("soft_music", "soft_music", "soft_music", + TRUE, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SOFT_SNDFX, + g_param_spec_boolean ("soft_sndfx", "soft_sndfx", "soft_sndfx", + TRUE, G_PARAM_READWRITE)); + + gobject_class->set_property = gst_mikmod_set_property; gobject_class->get_property = gst_mikmod_get_property; @@ -201,52 +202,54 @@ gst_mikmod_class_init (GstMikModClass *klass) static void -gst_mikmod_init (GstMikMod *filter) -{ - filter->sinkpad = gst_pad_new_from_template( - gst_static_pad_template_get (&mikmod_sink_factory),"sink"); - filter->srcpad = gst_pad_new_from_template( - gst_static_pad_template_get (&mikmod_src_factory),"src"); - - gst_element_add_pad(GST_ELEMENT(filter),filter->sinkpad); - gst_element_add_pad(GST_ELEMENT(filter),filter->srcpad); +gst_mikmod_init (GstMikMod * filter) +{ + filter->sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&mikmod_sink_factory), "sink"); + filter->srcpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&mikmod_src_factory), "src"); + + gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad); + gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad); gst_pad_set_link_function (filter->srcpad, gst_mikmod_srclink); gst_pad_set_fixate_function (filter->srcpad, gst_mikmod_srcfixate); - + gst_element_set_loop_function (GST_ELEMENT (filter), gst_mikmod_loop); - + filter->Buffer = NULL; - filter->stereo = TRUE; - filter->surround = TRUE; - filter->_16bit = TRUE; - filter->soft_music = TRUE; - filter->soft_sndfx = TRUE; - filter->mixfreq = 44100; - filter->reverb = 0; - filter->pansep = 128; + filter->stereo = TRUE; + filter->surround = TRUE; + filter->_16bit = TRUE; + filter->soft_music = TRUE; + filter->soft_sndfx = TRUE; + filter->mixfreq = 44100; + filter->reverb = 0; + filter->pansep = 128; filter->musicvolume = 128; - filter->volume = 96; + filter->volume = 96; filter->sndfxvolume = 128; - filter->songname = NULL; - filter->modtype = NULL; - + filter->songname = NULL; + filter->modtype = NULL; + filter->initialized = FALSE; } static GstCaps * -gst_mikmod_srcfixate (GstPad *pad, const GstCaps *caps) +gst_mikmod_srcfixate (GstPad * pad, const GstCaps * caps) { GstCaps *ret; GstStructure *structure; - + /* FIXME: select est caps here */ if (gst_caps_get_size (caps) > 1) return NULL; ret = gst_caps_copy (caps); structure = gst_caps_get_structure (ret, 0); - + if (gst_caps_structure_fixate_field_nearest_int (structure, "channels", 2)) return ret; if (gst_caps_structure_fixate_field_nearest_int (structure, "rate", 44100)) @@ -257,9 +260,9 @@ gst_mikmod_srcfixate (GstPad *pad, const GstCaps *caps) } static GstPadLinkReturn -gst_mikmod_srclink (GstPad *pad, const GstCaps *caps) +gst_mikmod_srclink (GstPad * pad, const GstCaps * caps) { - GstMikMod *filter; + GstMikMod *filter; GstStructure *structure; gint depth; gint channels; @@ -273,68 +276,69 @@ gst_mikmod_srclink (GstPad *pad, const GstCaps *caps) gst_structure_get_int (structure, "channels", &channels); filter->stereo = (channels == 2); gst_structure_get_int (structure, "rate", &filter->mixfreq); - + return gst_mikmod_setup (filter) ? GST_PAD_LINK_OK : GST_PAD_LINK_REFUSED; } static void -gst_mikmod_loop (GstElement *element) +gst_mikmod_loop (GstElement * element) { GstMikMod *mikmod; GstBuffer *buffer_in; g_return_if_fail (element != NULL); g_return_if_fail (GST_IS_MIKMOD (element)); - + mikmod = GST_MIKMOD (element); srcpad = mikmod->srcpad; mikmod->Buffer = NULL; - + if (!mikmod->initialized) { - while ((buffer_in = GST_BUFFER (gst_pad_pull( mikmod->sinkpad )))) { - if ( GST_IS_EVENT (buffer_in) ) { + while ((buffer_in = GST_BUFFER (gst_pad_pull (mikmod->sinkpad)))) { + if (GST_IS_EVENT (buffer_in)) { GstEvent *event = GST_EVENT (buffer_in); - - if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) - break; + + if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) + break; } else { - if ( mikmod->Buffer ) { - GstBuffer *merge; - merge = gst_buffer_merge( mikmod->Buffer, buffer_in ); - gst_buffer_unref( buffer_in ); - gst_buffer_unref( mikmod->Buffer ); + if (mikmod->Buffer) { + GstBuffer *merge; + + merge = gst_buffer_merge (mikmod->Buffer, buffer_in); + gst_buffer_unref (buffer_in); + gst_buffer_unref (mikmod->Buffer); mikmod->Buffer = merge; } else { mikmod->Buffer = buffer_in; } } - } - + } + if (!GST_PAD_CAPS (mikmod->srcpad)) { if (GST_PAD_LINK_SUCCESSFUL (gst_pad_renegotiate (mikmod->srcpad))) { GST_ELEMENT_ERROR (mikmod, CORE, NEGOTIATION, (NULL), (NULL)); return; } } - - MikMod_RegisterDriver(&drv_gst); - MikMod_RegisterAllLoaders(); - - MikMod_Init(""); - reader = GST_READER_new( mikmod ); - module = Player_LoadGeneric ( reader, 64, 0 ); - + + MikMod_RegisterDriver (&drv_gst); + MikMod_RegisterAllLoaders (); + + MikMod_Init (""); + reader = GST_READER_new (mikmod); + module = Player_LoadGeneric (reader, 64, 0); + gst_buffer_unref (mikmod->Buffer); - - if ( ! Player_Active() ) - Player_Start(module); - + + if (!Player_Active ()) + Player_Start (module); + mikmod->initialized = TRUE; } - if ( Player_Active() ) { - timestamp = ( module->sngtime / 1024.0 ) * GST_SECOND; - drv_gst.Update(); + if (Player_Active ()) { + timestamp = (module->sngtime / 1024.0) * GST_SECOND; + drv_gst.Update (); } else { gst_element_set_eos (GST_ELEMENT (mikmod)); gst_pad_push (mikmod->srcpad, GST_DATA (gst_event_new (GST_EVENT_EOS))); @@ -343,7 +347,7 @@ gst_mikmod_loop (GstElement *element) static gboolean -gst_mikmod_setup (GstMikMod *mikmod) +gst_mikmod_setup (GstMikMod * mikmod) { md_musicvolume = mikmod->musicvolume; md_pansep = mikmod->pansep; @@ -354,28 +358,28 @@ gst_mikmod_setup (GstMikMod *mikmod) md_mode = 0; - if ( mikmod->interp ) + if (mikmod->interp) md_mode = md_mode | DMODE_INTERP; - if ( mikmod->reverse ) + if (mikmod->reverse) md_mode = md_mode | DMODE_REVERSE; - if ( mikmod->surround ) + if (mikmod->surround) md_mode = md_mode | DMODE_SURROUND; - if ( mikmod->_16bit ) + if (mikmod->_16bit) md_mode = md_mode | DMODE_16BITS; - if ( mikmod->hqmixer ) + if (mikmod->hqmixer) md_mode = md_mode | DMODE_HQMIXER; - if ( mikmod->soft_music ) + if (mikmod->soft_music) md_mode = md_mode | DMODE_SOFT_MUSIC; - if ( mikmod->soft_sndfx ) + if (mikmod->soft_sndfx) md_mode = md_mode | DMODE_SOFT_SNDFX; - if ( mikmod->stereo ) + if (mikmod->stereo) md_mode = md_mode | DMODE_STEREO; return TRUE; @@ -383,9 +387,9 @@ gst_mikmod_setup (GstMikMod *mikmod) static GstElementStateReturn -gst_mikmod_change_state (GstElement *element) +gst_mikmod_change_state (GstElement * element) { -GstMikMod *mikmod; + GstMikMod *mikmod; g_return_val_if_fail (GST_IS_MIKMOD (element), GST_STATE_FAILURE); @@ -393,35 +397,31 @@ GstMikMod *mikmod; GST_DEBUG ("state pending %d", GST_STATE_PENDING (element)); - if (GST_STATE_PENDING (element) == GST_STATE_READY) - { - gst_mikmod_setup(mikmod); - - if ( Player_Active() ) - { - Player_TogglePause(); - Player_SetPosition( 0 ); - } - mikmod->initialized = FALSE; + if (GST_STATE_PENDING (element) == GST_STATE_READY) { + gst_mikmod_setup (mikmod); + + if (Player_Active ()) { + Player_TogglePause (); + Player_SetPosition (0); + } + mikmod->initialized = FALSE; } - - if (GST_STATE_PENDING (element) == GST_STATE_PLAYING) - { - if ( Player_Active() && Player_Paused() ) - Player_TogglePause(); - else - if ( ! Player_Active() ) - Player_Start(module); - + + if (GST_STATE_PENDING (element) == GST_STATE_PLAYING) { + if (Player_Active () && Player_Paused ()) + Player_TogglePause (); + else if (!Player_Active ()) + Player_Start (module); + } - - if (GST_STATE_PENDING (element) == GST_STATE_PAUSED) - if ( Player_Active() && ! Player_Paused() ) - Player_TogglePause(); - if (GST_STATE_PENDING (element) == GST_STATE_NULL) - MikMod_Exit(); - + if (GST_STATE_PENDING (element) == GST_STATE_PAUSED) + if (Player_Active () && !Player_Paused ()) + Player_TogglePause (); + + if (GST_STATE_PENDING (element) == GST_STATE_NULL) + MikMod_Exit (); + if (GST_ELEMENT_CLASS (parent_class)->change_state) return GST_ELEMENT_CLASS (parent_class)->change_state (element); @@ -432,13 +432,14 @@ GstMikMod *mikmod; static void -gst_mikmod_set_property (GObject *object, guint id, const GValue *value, GParamSpec *pspec ) +gst_mikmod_set_property (GObject * object, guint id, const GValue * value, + GParamSpec * pspec) { GstMikMod *filter; /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_MIKMOD(object)); - filter = GST_MIKMOD(object); + g_return_if_fail (GST_IS_MIKMOD (object)); + filter = GST_MIKMOD (object); switch (id) { case ARG_SONGNAME: @@ -488,13 +489,14 @@ gst_mikmod_set_property (GObject *object, guint id, const GValue *value, GParamS } static void -gst_mikmod_get_property (GObject *object, guint id, GValue *value, GParamSpec *pspec ) +gst_mikmod_get_property (GObject * object, guint id, GValue * value, + GParamSpec * pspec) { GstMikMod *filter; /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_MIKMOD(object)); - filter = GST_MIKMOD(object); + g_return_if_fail (GST_IS_MIKMOD (object)); + filter = GST_MIKMOD (object); switch (id) { case ARG_MUSICVOLUME: @@ -536,21 +538,17 @@ gst_mikmod_get_property (GObject *object, guint id, GValue *value, GParamSpec *p } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { - if (!gst_element_register (plugin, "mikmod", GST_RANK_SECONDARY, GST_TYPE_MIKMOD)) + if (!gst_element_register (plugin, "mikmod", GST_RANK_SECONDARY, + GST_TYPE_MIKMOD)) return FALSE; return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "mikmod", - "Mikmod plugin library", - plugin_init, - VERSION, - "GPL", - GST_PACKAGE, - GST_ORIGIN) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "mikmod", + "Mikmod plugin library", + plugin_init, VERSION, "GPL", GST_PACKAGE, GST_ORIGIN) diff --git a/ext/mikmod/gstmikmod.h b/ext/mikmod/gstmikmod.h index 208fc5b9..ce65f8e8 100644 --- a/ext/mikmod/gstmikmod.h +++ b/ext/mikmod/gstmikmod.h @@ -25,13 +25,14 @@ #include <gst/gst.h> #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define GST_TYPE_MIKMOD \ (gst_mikmod_get_type()) - + #define GST_MIKMOD(obj) \ (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MIKMOD,GstMikMod)) #define GST_MIKMOD_CLASS(klass) \ @@ -40,68 +41,70 @@ extern "C" { (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MIKMOD)) #define GST_IS_MIKMOD_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MIKMOD)) - -struct _GstMikMod { - GstElement element; - GstPad *sinkpad, *srcpad; - GstBuffer *Buffer; - - gchar *songname; - gchar *modtype; - gint musicvolume; - gint pansep; - gint reverb; - gint sndfxvolume; - gint volume; - gint mixfreq; - gint mode; - gboolean interp; - gboolean reverse; - gboolean surround; - gboolean _16bit; - gboolean hqmixer; - gboolean soft_music; - gboolean soft_sndfx; - gboolean stereo; - - gboolean initialized; -}; - -struct _GstMikModClass { - GstElementClass parent_class; -}; - -typedef struct _GstMikMod GstMikMod; -typedef struct _GstMikModClass GstMikModClass; - -extern MODULE *module; -extern MREADER *reader; -extern GstPad *srcpad; -extern GstClockTime timestamp; -extern int need_sync; - -GType gst_mikmod_get_type(void); + + struct _GstMikMod + { + GstElement element; + GstPad *sinkpad, *srcpad; + GstBuffer *Buffer; + + gchar *songname; + gchar *modtype; + gint musicvolume; + gint pansep; + gint reverb; + gint sndfxvolume; + gint volume; + gint mixfreq; + gint mode; + gboolean interp; + gboolean reverse; + gboolean surround; + gboolean _16bit; + gboolean hqmixer; + gboolean soft_music; + gboolean soft_sndfx; + gboolean stereo; + + gboolean initialized; + }; + + struct _GstMikModClass + { + GstElementClass parent_class; + }; + + typedef struct _GstMikMod GstMikMod; + typedef struct _GstMikModClass GstMikModClass; + + extern MODULE *module; + extern MREADER *reader; + extern GstPad *srcpad; + extern GstClockTime timestamp; + extern int need_sync; + + GType gst_mikmod_get_type (void); /* symbols for mikmod_reader.h */ -struct _GST_READER -{ - MREADER core; - GstMikMod *mik; - guint64 offset; - gshort eof; -}; + struct _GST_READER + { + MREADER core; + GstMikMod *mik; + guint64 offset; + gshort eof; + }; -typedef struct _GST_READER GST_READER; + typedef struct _GST_READER GST_READER; -MREADER *GST_READER_new( GstMikMod *mik ); + MREADER *GST_READER_new (GstMikMod * mik); /* symbols for drv_gst.c */ -extern MDRIVER drv_gst; + extern MDRIVER drv_gst; #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __GST_MIKMOD_H__ */ +#endif /* __GST_MIKMOD_H__ */ diff --git a/ext/mikmod/mikmod_reader.c b/ext/mikmod/mikmod_reader.c index 38b8402c..f8e83de1 100644 --- a/ext/mikmod/mikmod_reader.c +++ b/ext/mikmod/mikmod_reader.c @@ -9,57 +9,62 @@ extern int need_sync; -static BOOL GST_READER_Eof ( MREADER *reader ); -static BOOL GST_READER_Read( MREADER *reader, void *ptr, size_t size ); -static int GST_READER_Get ( MREADER *reader ); -static BOOL GST_READER_Seek( MREADER* reader,long offset,int whence ); -static long GST_READER_Tell( MREADER* reader ); +static BOOL GST_READER_Eof (MREADER * reader); +static BOOL GST_READER_Read (MREADER * reader, void *ptr, size_t size); +static int GST_READER_Get (MREADER * reader); +static BOOL GST_READER_Seek (MREADER * reader, long offset, int whence); +static long GST_READER_Tell (MREADER * reader); -static BOOL GST_READER_Eof( MREADER *reader ) +static BOOL +GST_READER_Eof (MREADER * reader) { -GST_READER *gst_reader; + GST_READER *gst_reader; - gst_reader = ( GST_READER * ) reader; + gst_reader = (GST_READER *) reader; return gst_reader->eof; } -static BOOL GST_READER_Read( MREADER *reader, void *ptr, size_t size ) +static BOOL +GST_READER_Read (MREADER * reader, void *ptr, size_t size) { -GST_READER *gst_reader; + GST_READER *gst_reader; - gst_reader = ( GST_READER * ) reader; - - memcpy( ptr, GST_BUFFER_DATA( gst_reader->mik->Buffer ) + gst_reader->offset, size); - gst_reader->offset = gst_reader->offset + size; + gst_reader = (GST_READER *) reader; + + memcpy (ptr, GST_BUFFER_DATA (gst_reader->mik->Buffer) + gst_reader->offset, + size); + gst_reader->offset = gst_reader->offset + size; return 1; } -static int GST_READER_Get ( MREADER *reader ) +static int +GST_READER_Get (MREADER * reader) { -GST_READER *gst_reader; -int res; + GST_READER *gst_reader; + int res; + + gst_reader = (GST_READER *) reader; - gst_reader = ( GST_READER * ) reader; - - res = *( GST_BUFFER_DATA( gst_reader->mik->Buffer ) + gst_reader->offset ); + res = *(GST_BUFFER_DATA (gst_reader->mik->Buffer) + gst_reader->offset); gst_reader->offset += 1; - + return res; } -static BOOL GST_READER_Seek( MREADER *reader, long offset, int whence ) +static BOOL +GST_READER_Seek (MREADER * reader, long offset, int whence) { -GST_READER *gst_reader; - - gst_reader = ( GST_READER * ) reader; + GST_READER *gst_reader; - if ( whence == SEEK_SET ) + gst_reader = (GST_READER *) reader; + + if (whence == SEEK_SET) gst_reader->offset = offset; else gst_reader->offset += offset; @@ -68,39 +73,41 @@ GST_READER *gst_reader; } -static long GST_READER_Tell( MREADER *reader ) +static long +GST_READER_Tell (MREADER * reader) { -GST_READER *gst_reader; + GST_READER *gst_reader; - gst_reader = ( GST_READER * ) reader; + gst_reader = (GST_READER *) reader; return gst_reader->offset; } -MREADER *GST_READER_new( GstMikMod *mik ) +MREADER * +GST_READER_new (GstMikMod * mik) { -GST_READER *gst_reader; - - gst_reader = ( GST_READER * ) g_malloc( sizeof( GST_READER )); + GST_READER *gst_reader; + + gst_reader = (GST_READER *) g_malloc (sizeof (GST_READER)); gst_reader->offset = 0; - gst_reader->eof = 0; - gst_reader->mik = mik; - if ( gst_reader ) - { - gst_reader->core.Eof = &GST_READER_Eof; - gst_reader->core.Read = &GST_READER_Read; - gst_reader->core.Get = &GST_READER_Get; - gst_reader->core.Seek = &GST_READER_Seek; - gst_reader->core.Tell = &GST_READER_Tell; + gst_reader->eof = 0; + gst_reader->mik = mik; + if (gst_reader) { + gst_reader->core.Eof = &GST_READER_Eof; + gst_reader->core.Read = &GST_READER_Read; + gst_reader->core.Get = &GST_READER_Get; + gst_reader->core.Seek = &GST_READER_Seek; + gst_reader->core.Tell = &GST_READER_Tell; } - return ( MREADER *)gst_reader; + return (MREADER *) gst_reader; } -void GST_READER_free ( MREADER *reader ) +void +GST_READER_free (MREADER * reader) { - if ( reader ) - g_free( reader ); + if (reader) + g_free (reader); } diff --git a/ext/mikmod/mikmod_types.c b/ext/mikmod/mikmod_types.c index f583d082..370f59cb 100644 --- a/ext/mikmod/mikmod_types.c +++ b/ext/mikmod/mikmod_types.c @@ -28,197 +28,211 @@ #define MODULEHEADERSIZE 0x438 - -gboolean MOD_CheckType( GstBuffer *buf ) + +gboolean +MOD_CheckType (GstBuffer * buf) { -gchar *data; - - data = GST_BUFFER_DATA( buf ) + MODULEHEADERSIZE; - - /* Protracker and variants */ - if (( ! memcmp( data, "M.K.", 4 )) || ( ! memcmp( data, "M!K!", 4 ))) - return TRUE; - - /* Star Tracker */ - if ((( ! memcmp( data, "FLT", 3 )) || ( ! memcmp( data, "EXO", 3 ))) && ( isdigit( data[3] ))) - return TRUE; - - /* Oktalyzer (Amiga) */ - if (! memcmp( data, "OKTA", 4 )) - return TRUE; - - /* Oktalyser (Atari) */ - if ( ! memcmp( data, "CD81", 4 )) - return TRUE; - - /* Fasttracker */ - if (( ! memcmp( data + 1, "CHN", 3 )) && ( isdigit( data[0] ))) - return TRUE; - - /* Fasttracker or Taketracker */ - if ((( ! memcmp( data + 2, "CH", 2 )) || ( ! memcmp( data + 2, "CN", 2 ))) && ( isdigit( data[0] )) && ( isdigit( data[1] ))) - return TRUE; - - return FALSE; + gchar *data; + + data = GST_BUFFER_DATA (buf) + MODULEHEADERSIZE; + + /* Protracker and variants */ + if ((!memcmp (data, "M.K.", 4)) || (!memcmp (data, "M!K!", 4))) + return TRUE; + + /* Star Tracker */ + if (((!memcmp (data, "FLT", 3)) || (!memcmp (data, "EXO", 3))) + && (isdigit (data[3]))) + return TRUE; + + /* Oktalyzer (Amiga) */ + if (!memcmp (data, "OKTA", 4)) + return TRUE; + + /* Oktalyser (Atari) */ + if (!memcmp (data, "CD81", 4)) + return TRUE; + + /* Fasttracker */ + if ((!memcmp (data + 1, "CHN", 3)) && (isdigit (data[0]))) + return TRUE; + + /* Fasttracker or Taketracker */ + if (((!memcmp (data + 2, "CH", 2)) || (!memcmp (data + 2, "CN", 2))) + && (isdigit (data[0])) && (isdigit (data[1]))) + return TRUE; + + return FALSE; } -gboolean Mod_669_CheckType( GstBuffer *buf ) +gboolean +Mod_669_CheckType (GstBuffer * buf) { -gchar *data; - - data = GST_BUFFER_DATA( buf ); - - if( ! memcmp( data, "if", 2 ) || ! memcmp( data, "JN", 2 )) - return TRUE; - - return FALSE; + gchar *data; + + data = GST_BUFFER_DATA (buf); + + if (!memcmp (data, "if", 2) || !memcmp (data, "JN", 2)) + return TRUE; + + return FALSE; } -gboolean Amf_CheckType( GstBuffer *buf ) +gboolean +Amf_CheckType (GstBuffer * buf) { -gchar *data; - - data = GST_BUFFER_DATA( buf ); - - if( memcmp( data, "AMF", 3) ) - return FALSE; - - data = GST_BUFFER_DATA( buf ) + 3; - - if (( (gint)*data >= 10 ) && ( (gint)*data <= 14 )) - return TRUE; - - return FALSE; + gchar *data; + + data = GST_BUFFER_DATA (buf); + + if (memcmp (data, "AMF", 3)) + return FALSE; + + data = GST_BUFFER_DATA (buf) + 3; + + if (((gint) * data >= 10) && ((gint) * data <= 14)) + return TRUE; + + return FALSE; } -gboolean Dsm_CheckType( GstBuffer *buf ) +gboolean +Dsm_CheckType (GstBuffer * buf) { -gchar *data; - - data = GST_BUFFER_DATA( buf ); - - if( ! memcmp( data, "RIFF", 4 ) && ! memcmp( data + 8, "DSMF", 4 )) - return TRUE; - - return FALSE; + gchar *data; + + data = GST_BUFFER_DATA (buf); + + if (!memcmp (data, "RIFF", 4) && !memcmp (data + 8, "DSMF", 4)) + return TRUE; + + return FALSE; } -gboolean Fam_CheckType( GstBuffer *buf ) +gboolean +Fam_CheckType (GstBuffer * buf) { -gchar *data; -static unsigned char FARSIG[4+3]={'F','A','R',0xfe,13,10,26}; - - data = GST_BUFFER_DATA( buf ); - - if(( memcmp( data, FARSIG, 4 )) || ( memcmp( data + 44, FARSIG + 4, 3 ))) - return FALSE; - - return 1; + gchar *data; + static unsigned char FARSIG[4 + 3] = { 'F', 'A', 'R', 0xfe, 13, 10, 26 }; + + data = GST_BUFFER_DATA (buf); + + if ((memcmp (data, FARSIG, 4)) || (memcmp (data + 44, FARSIG + 4, 3))) + return FALSE; + + return 1; } -gboolean Gdm_CheckType( GstBuffer *buf ) +gboolean +Gdm_CheckType (GstBuffer * buf) { -gchar *data; - - data = GST_BUFFER_DATA( buf ); - - if ( ! memcmp( data, "GDM\xfe", 4 ) && ! memcmp( data + 71, "GMFS", 4 )) - return TRUE; - - return FALSE; + gchar *data; + + data = GST_BUFFER_DATA (buf); + + if (!memcmp (data, "GDM\xfe", 4) && !memcmp (data + 71, "GMFS", 4)) + return TRUE; + + return FALSE; } -gboolean Imf_CheckType( GstBuffer *buf ) +gboolean +Imf_CheckType (GstBuffer * buf) { -gchar *data; - - data = GST_BUFFER_DATA( buf ) + 0x3c; - - if( ! memcmp( data, "IM10", 4)) - return TRUE; - - return FALSE; + gchar *data; + + data = GST_BUFFER_DATA (buf) + 0x3c; + + if (!memcmp (data, "IM10", 4)) + return TRUE; + + return FALSE; } -gboolean It_CheckType( GstBuffer *buf ) +gboolean +It_CheckType (GstBuffer * buf) { -gchar *data; - - data = GST_BUFFER_DATA( buf ); - - if( ! memcmp( data, "IMPM", 4 )) - return TRUE; - - return FALSE; + gchar *data; + + data = GST_BUFFER_DATA (buf); + + if (!memcmp (data, "IMPM", 4)) + return TRUE; + + return FALSE; } -gboolean M15_CheckType( GstBuffer *buf ) +gboolean +M15_CheckType (GstBuffer * buf) { - /* FIXME: M15 CheckType to do */ - return FALSE; + /* FIXME: M15 CheckType to do */ + return FALSE; } -gboolean Med_CheckType( GstBuffer *buf ) +gboolean +Med_CheckType (GstBuffer * buf) { -gchar *data; - - data = GST_BUFFER_DATA( buf ); - - if(( ! memcmp(data, "MMD0", 4 )) || ( memcmp( data, "MMD1", 4 ))) - return TRUE; - - return FALSE; + gchar *data; + + data = GST_BUFFER_DATA (buf); + + if ((!memcmp (data, "MMD0", 4)) || (memcmp (data, "MMD1", 4))) + return TRUE; + + return FALSE; } -gboolean Mtm_CheckType( GstBuffer *buf ) +gboolean +Mtm_CheckType (GstBuffer * buf) { -gchar *data; - - data = GST_BUFFER_DATA( buf ); - - if( ! memcmp( data, "MTM", 3 )) - return TRUE; - - return FALSE; + gchar *data; + + data = GST_BUFFER_DATA (buf); + + if (!memcmp (data, "MTM", 3)) + return TRUE; + + return FALSE; } -gboolean Okt_CheckType( GstBuffer *buf ) +gboolean +Okt_CheckType (GstBuffer * buf) { -gchar *data; - - data = GST_BUFFER_DATA( buf ); - - if( ! memcmp( data, "OKTSONG", 8 )) - return TRUE; - - return FALSE; + gchar *data; + + data = GST_BUFFER_DATA (buf); + + if (!memcmp (data, "OKTSONG", 8)) + return TRUE; + + return FALSE; } -gboolean S3m_CheckType( GstBuffer *buf ) +gboolean +S3m_CheckType (GstBuffer * buf) { -gchar *data; - - data = GST_BUFFER_DATA( buf ) + 0x2c; - - if( ! memcmp( data, "SCRM", 4 )) - return TRUE; - - return FALSE; + gchar *data; + + data = GST_BUFFER_DATA (buf) + 0x2c; + + if (!memcmp (data, "SCRM", 4)) + return TRUE; + + return FALSE; } -gboolean Xm_CheckType( GstBuffer *buf ) +gboolean +Xm_CheckType (GstBuffer * buf) { -gchar *data; - - data = GST_BUFFER_DATA( buf ); - - if( memcmp( data, "Extended Module: ", 17 )) - return FALSE; - - if( data[ 37 ] == 0x1a ) - return TRUE; - - return FALSE; -} + gchar *data; + data = GST_BUFFER_DATA (buf); + if (memcmp (data, "Extended Module: ", 17)) + return FALSE; + + if (data[37] == 0x1a) + return TRUE; + + return FALSE; +} diff --git a/ext/mikmod/mikmod_types.h b/ext/mikmod/mikmod_types.h index c431faf9..8559455c 100644 --- a/ext/mikmod/mikmod_types.h +++ b/ext/mikmod/mikmod_types.h @@ -20,25 +20,26 @@ #define __MIKMOD_TYPES_H__ #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ -gboolean MOD_CheckType (GstBuffer *buf); -gboolean Mod_669_CheckType (GstBuffer *buf); -gboolean Amf_CheckType (GstBuffer *buf); -gboolean Dsm_CheckType (GstBuffer *buf); -gboolean Fam_CheckType (GstBuffer *buf); -gboolean Gdm_CheckType (GstBuffer *buf); -gboolean Imf_CheckType (GstBuffer *buf); -gboolean It_CheckType (GstBuffer *buf); -gboolean M15_CheckType (GstBuffer *buf); -gboolean Mtm_CheckType (GstBuffer *buf); -gboolean Okt_CheckType (GstBuffer *buf); -gboolean S3m_CheckType (GstBuffer *buf); -gboolean Xm_CheckType (GstBuffer *buf); + gboolean MOD_CheckType (GstBuffer * buf); + gboolean Mod_669_CheckType (GstBuffer * buf); + gboolean Amf_CheckType (GstBuffer * buf); + gboolean Dsm_CheckType (GstBuffer * buf); + gboolean Fam_CheckType (GstBuffer * buf); + gboolean Gdm_CheckType (GstBuffer * buf); + gboolean Imf_CheckType (GstBuffer * buf); + gboolean It_CheckType (GstBuffer * buf); + gboolean M15_CheckType (GstBuffer * buf); + gboolean Mtm_CheckType (GstBuffer * buf); + gboolean Okt_CheckType (GstBuffer * buf); + gboolean S3m_CheckType (GstBuffer * buf); + gboolean Xm_CheckType (GstBuffer * buf); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __MIKMOD_TYPES_H__ */ +#endif /* __MIKMOD_TYPES_H__ */ diff --git a/ext/pango/gsttextoverlay.c b/ext/pango/gsttextoverlay.c index 4264e813..d0b40294 100644 --- a/ext/pango/gsttextoverlay.c +++ b/ext/pango/gsttextoverlay.c @@ -11,205 +11,196 @@ /*#include "SDL_blit.h"*/ static GstElementDetails textoverlay_details = { - "Text Overlay", - "Filter/Editor/Video", - "Adds text strings on top of a video buffer", - "Gustavo J. A. M. Carneiro <gjc@inescporto.pt>" + "Text Overlay", + "Filter/Editor/Video", + "Adds text strings on top of a video buffer", + "Gustavo J. A. M. Carneiro <gjc@inescporto.pt>" }; -enum { - ARG_0, - ARG_TEXT, - ARG_VALIGN, - ARG_HALIGN, - ARG_X0, - ARG_Y0, - ARG_FONT_DESC, +enum +{ + ARG_0, + ARG_TEXT, + ARG_VALIGN, + ARG_HALIGN, + ARG_X0, + ARG_Y0, + ARG_FONT_DESC, }; static GstStaticPadTemplate textoverlay_src_template_factory = -GST_STATIC_PAD_TEMPLATE ( - "src", +GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS ("video/x-raw-yuv, " - "format = (fourcc) I420, " - "width = (int) [ 1, MAX ], " - "height = (int) [ 1, MAX ]") -); + "format = (fourcc) I420, " + "width = (int) [ 1, MAX ], " "height = (int) [ 1, MAX ]") + ); static GstStaticPadTemplate video_sink_template_factory = -GST_STATIC_PAD_TEMPLATE ( - "video_sink", +GST_STATIC_PAD_TEMPLATE ("video_sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS ("video/x-raw-yuv, " - "format = (fourcc) I420, " - "width = (int) [ 1, MAX ], " - "height = (int) [ 1, MAX ]") -); + "format = (fourcc) I420, " + "width = (int) [ 1, MAX ], " "height = (int) [ 1, MAX ]") + ); static GstStaticPadTemplate text_sink_template_factory = -GST_STATIC_PAD_TEMPLATE ( - "text_sink", + GST_STATIC_PAD_TEMPLATE ("text_sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS ("text/x-pango-markup; text/plain") -); - -static void gst_textoverlay_base_init (gpointer g_class); -static void gst_textoverlay_class_init(GstTextOverlayClass *klass); -static void gst_textoverlay_init(GstTextOverlay *overlay); -static void gst_textoverlay_set_property(GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void gst_textoverlay_get_property(GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static GstElementStateReturn gst_textoverlay_change_state(GstElement *element); -static void gst_textoverlay_finalize(GObject *object); + ); + +static void gst_textoverlay_base_init (gpointer g_class); +static void gst_textoverlay_class_init (GstTextOverlayClass * klass); +static void gst_textoverlay_init (GstTextOverlay * overlay); +static void gst_textoverlay_set_property (GObject * object, + guint prop_id, const GValue * value, GParamSpec * pspec); +static void gst_textoverlay_get_property (GObject * object, + guint prop_id, GValue * value, GParamSpec * pspec); +static GstElementStateReturn gst_textoverlay_change_state (GstElement * + element); +static void gst_textoverlay_finalize (GObject * object); static GstElementClass *parent_class = NULL; + /*static guint gst_textoverlay_signals[LAST_SIGNAL] = { 0 }; */ GType -gst_textoverlay_get_type(void) +gst_textoverlay_get_type (void) { - static GType textoverlay_type = 0; - - if (!textoverlay_type) { - static const GTypeInfo textoverlay_info = { - sizeof(GstTextOverlayClass), - gst_textoverlay_base_init, - NULL, - (GClassInitFunc)gst_textoverlay_class_init, - NULL, - NULL, - sizeof(GstTextOverlay), - 0, - (GInstanceInitFunc)gst_textoverlay_init, - }; - textoverlay_type = g_type_register_static(GST_TYPE_ELEMENT, "GstTextOverlay", - &textoverlay_info, 0); - } - return textoverlay_type; + static GType textoverlay_type = 0; + + if (!textoverlay_type) { + static const GTypeInfo textoverlay_info = { + sizeof (GstTextOverlayClass), + gst_textoverlay_base_init, + NULL, + (GClassInitFunc) gst_textoverlay_class_init, + NULL, + NULL, + sizeof (GstTextOverlay), + 0, + (GInstanceInitFunc) gst_textoverlay_init, + }; + textoverlay_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstTextOverlay", + &textoverlay_info, 0); + } + return textoverlay_type; } static void gst_textoverlay_base_init (gpointer g_class) { - GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); + GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&textoverlay_src_template_factory)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&video_sink_template_factory)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&text_sink_template_factory)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&textoverlay_src_template_factory)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&video_sink_template_factory)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&text_sink_template_factory)); - gst_element_class_set_details (element_class, &textoverlay_details); + gst_element_class_set_details (element_class, &textoverlay_details); } static void -gst_textoverlay_class_init(GstTextOverlayClass *klass) +gst_textoverlay_class_init (GstTextOverlayClass * klass) { - GObjectClass *gobject_class; - GstElementClass *gstelement_class; - - gobject_class = (GObjectClass*)klass; - gstelement_class = (GstElementClass*)klass; - - parent_class = g_type_class_peek_parent(klass); - - gobject_class->finalize = gst_textoverlay_finalize; - gobject_class->set_property = gst_textoverlay_set_property; - gobject_class->get_property = gst_textoverlay_get_property; - - gstelement_class->change_state = gst_textoverlay_change_state; - klass->pango_context = pango_ft2_get_context(72, 72); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_TEXT, - g_param_spec_string("text", "text", - "Text to be display," - " in pango markup format.", - "", G_PARAM_WRITABLE)); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_VALIGN, - g_param_spec_string("valign", "vertical alignment", - "Vertical alignment of the text. " - "Can be either 'baseline', 'bottom', or 'top'", - "baseline", G_PARAM_WRITABLE)); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_HALIGN, - g_param_spec_string("halign", "horizontal alignment", - "Horizontal alignment of the text. " - "Can be either 'left', 'right', or 'center'", - "center", G_PARAM_WRITABLE)); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_X0, - g_param_spec_int("x0", "X position", - "Initial X position." - " Horizontal aligment takes this point" - " as reference.", - G_MININT, G_MAXINT, 0, G_PARAM_WRITABLE)); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_Y0, - g_param_spec_int("y0", "Y position", - "Initial Y position." - " Vertical aligment takes this point" - " as reference.", - G_MININT, G_MAXINT, 0, G_PARAM_WRITABLE)); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_FONT_DESC, - g_param_spec_string("font-desc", "font description", - "Pango font description of font " - "to be used for rendering. " - "See documentation of " - "pango_font_description_from_string" - " for syntax.", - "", G_PARAM_WRITABLE)); + GObjectClass *gobject_class; + GstElementClass *gstelement_class; + + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; + + parent_class = g_type_class_peek_parent (klass); + + gobject_class->finalize = gst_textoverlay_finalize; + gobject_class->set_property = gst_textoverlay_set_property; + gobject_class->get_property = gst_textoverlay_get_property; + + gstelement_class->change_state = gst_textoverlay_change_state; + klass->pango_context = pango_ft2_get_context (72, 72); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TEXT, + g_param_spec_string ("text", "text", + "Text to be display," + " in pango markup format.", "", G_PARAM_WRITABLE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_VALIGN, + g_param_spec_string ("valign", "vertical alignment", + "Vertical alignment of the text. " + "Can be either 'baseline', 'bottom', or 'top'", + "baseline", G_PARAM_WRITABLE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_HALIGN, + g_param_spec_string ("halign", "horizontal alignment", + "Horizontal alignment of the text. " + "Can be either 'left', 'right', or 'center'", + "center", G_PARAM_WRITABLE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_X0, + g_param_spec_int ("x0", "X position", + "Initial X position." + " Horizontal aligment takes this point" + " as reference.", G_MININT, G_MAXINT, 0, G_PARAM_WRITABLE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_Y0, + g_param_spec_int ("y0", "Y position", + "Initial Y position." + " Vertical aligment takes this point" + " as reference.", G_MININT, G_MAXINT, 0, G_PARAM_WRITABLE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FONT_DESC, + g_param_spec_string ("font-desc", "font description", + "Pango font description of font " + "to be used for rendering. " + "See documentation of " + "pango_font_description_from_string" + " for syntax.", "", G_PARAM_WRITABLE)); } static void -resize_bitmap(GstTextOverlay *overlay, int width, int height) +resize_bitmap (GstTextOverlay * overlay, int width, int height) { - FT_Bitmap *bitmap = &overlay->bitmap; - int pitch = (width|3) + 1; - int size = pitch*height; - - /* no need to keep reallocating; just keep the maximum size so far */ - if (size <= overlay->bitmap_buffer_size) { - bitmap->rows = height; - bitmap->width = width; - bitmap->pitch = pitch; - memset(bitmap->buffer, 0, overlay->bitmap_buffer_size); - return; - } - if (!bitmap->buffer) { - /* initialize */ - bitmap->pixel_mode = ft_pixel_mode_grays; - bitmap->num_grays = 256; - } - if (bitmap->buffer) - bitmap->buffer = g_realloc(bitmap->buffer, size); - else - bitmap->buffer = g_malloc(size); + FT_Bitmap *bitmap = &overlay->bitmap; + int pitch = (width | 3) + 1; + int size = pitch * height; + + /* no need to keep reallocating; just keep the maximum size so far */ + if (size <= overlay->bitmap_buffer_size) { bitmap->rows = height; bitmap->width = width; bitmap->pitch = pitch; - memset(bitmap->buffer, 0, size); - overlay->bitmap_buffer_size = size; + memset (bitmap->buffer, 0, overlay->bitmap_buffer_size); + return; + } + if (!bitmap->buffer) { + /* initialize */ + bitmap->pixel_mode = ft_pixel_mode_grays; + bitmap->num_grays = 256; + } + if (bitmap->buffer) + bitmap->buffer = g_realloc (bitmap->buffer, size); + else + bitmap->buffer = g_malloc (size); + bitmap->rows = height; + bitmap->width = width; + bitmap->pitch = pitch; + memset (bitmap->buffer, 0, size); + overlay->bitmap_buffer_size = size; } static void -render_text(GstTextOverlay *overlay) +render_text (GstTextOverlay * overlay) { - PangoRectangle ink_rect, logical_rect; + PangoRectangle ink_rect, logical_rect; - pango_layout_get_pixel_extents(overlay->layout, &ink_rect, &logical_rect); - resize_bitmap(overlay, ink_rect.width, ink_rect.height + ink_rect.y); - pango_ft2_render_layout(&overlay->bitmap, overlay->layout, 0, 0); - overlay->baseline_y = ink_rect.y; + pango_layout_get_pixel_extents (overlay->layout, &ink_rect, &logical_rect); + resize_bitmap (overlay, ink_rect.width, ink_rect.height + ink_rect.y); + pango_ft2_render_layout (&overlay->bitmap, overlay->layout, 0, 0); + overlay->baseline_y = ink_rect.y; } /* static GstPadLinkReturn */ @@ -220,154 +211,157 @@ render_text(GstTextOverlay *overlay) static GstPadLinkReturn -gst_textoverlay_video_sinkconnect(GstPad *pad, const GstCaps *caps) +gst_textoverlay_video_sinkconnect (GstPad * pad, const GstCaps * caps) { - GstTextOverlay *overlay; - GstStructure *structure; + GstTextOverlay *overlay; + GstStructure *structure; - overlay = GST_TEXTOVERLAY(gst_pad_get_parent(pad)); + overlay = GST_TEXTOVERLAY (gst_pad_get_parent (pad)); - structure = gst_caps_get_structure (caps, 0); - overlay->width = overlay->height = 0; - gst_structure_get_int (structure, "width", &overlay->width); - gst_structure_get_int (structure, "height", &overlay->height); + structure = gst_caps_get_structure (caps, 0); + overlay->width = overlay->height = 0; + gst_structure_get_int (structure, "width", &overlay->width); + gst_structure_get_int (structure, "height", &overlay->height); - return gst_pad_try_set_caps(overlay->srcpad, caps); + return gst_pad_try_set_caps (overlay->srcpad, caps); } static void -gst_text_overlay_blit_yuv420(GstTextOverlay *overlay, FT_Bitmap *bitmap, - guchar *pixbuf, int x0, int y0) +gst_text_overlay_blit_yuv420 (GstTextOverlay * overlay, FT_Bitmap * bitmap, + guchar * pixbuf, int x0, int y0) { - int y; /* text bitmap coordinates */ - int x1, y1; /* video buffer coordinates */ - int rowinc, bit_rowinc, uv_rowinc; - guchar *p, *bitp, *u_p; - int video_width = overlay->width, video_height = overlay->height; - int bitmap_x0 = x0 < 1? -(x0 - 1) : 1; /* 1 pixel border */ - int bitmap_y0 = y0 < 1? -(y0 - 1) : 1; /* 1 pixel border */ - int bitmap_width = bitmap->width - bitmap_x0; - int bitmap_height = bitmap->rows - bitmap_y0; - int u_plane_size; - int skip_y, skip_x; - guchar v; - - if (x0 + bitmap_x0 + bitmap_width > video_width - 1) /* 1 pixel border */ - bitmap_width -= x0 + bitmap_x0 + bitmap_width - video_width + 1; - if (y0 + bitmap_y0 + bitmap_height > video_height - 1) /* 1 pixel border */ - bitmap_height -= y0 + bitmap_y0 + bitmap_height - video_height + 1; - - rowinc = video_width - bitmap_width; - uv_rowinc = video_width / 2 - bitmap_width / 2; - bit_rowinc = bitmap->pitch - bitmap_width; - u_plane_size = (video_width / 2)*(video_height / 2); - - y1 = y0 + bitmap_y0; - x1 = x0 + bitmap_x0; - p = pixbuf + video_width*y1 + x1; - bitp = bitmap->buffer + bitmap->pitch*bitmap_y0 + bitmap_x0; - for (y = bitmap_y0; y < bitmap_height; y++){ - int n; - for(n=bitmap_width; n>0; --n){ - v = *bitp; - if (v) { - p[-1] = CLAMP(p[-1] - v, 0, 255); - p[ 1] = CLAMP(p[ 1] - v, 0, 255); - p[-video_width] = CLAMP(p[-video_width] - v, 0, 255); - p[ video_width] = CLAMP(p[ video_width] - v, 0, 255); - } - p++; - bitp++; + int y; /* text bitmap coordinates */ + int x1, y1; /* video buffer coordinates */ + int rowinc, bit_rowinc, uv_rowinc; + guchar *p, *bitp, *u_p; + int video_width = overlay->width, video_height = overlay->height; + int bitmap_x0 = x0 < 1 ? -(x0 - 1) : 1; /* 1 pixel border */ + int bitmap_y0 = y0 < 1 ? -(y0 - 1) : 1; /* 1 pixel border */ + int bitmap_width = bitmap->width - bitmap_x0; + int bitmap_height = bitmap->rows - bitmap_y0; + int u_plane_size; + int skip_y, skip_x; + guchar v; + + if (x0 + bitmap_x0 + bitmap_width > video_width - 1) /* 1 pixel border */ + bitmap_width -= x0 + bitmap_x0 + bitmap_width - video_width + 1; + if (y0 + bitmap_y0 + bitmap_height > video_height - 1) /* 1 pixel border */ + bitmap_height -= y0 + bitmap_y0 + bitmap_height - video_height + 1; + + rowinc = video_width - bitmap_width; + uv_rowinc = video_width / 2 - bitmap_width / 2; + bit_rowinc = bitmap->pitch - bitmap_width; + u_plane_size = (video_width / 2) * (video_height / 2); + + y1 = y0 + bitmap_y0; + x1 = x0 + bitmap_x0; + p = pixbuf + video_width * y1 + x1; + bitp = bitmap->buffer + bitmap->pitch * bitmap_y0 + bitmap_x0; + for (y = bitmap_y0; y < bitmap_height; y++) { + int n; + + for (n = bitmap_width; n > 0; --n) { + v = *bitp; + if (v) { + p[-1] = CLAMP (p[-1] - v, 0, 255); + p[1] = CLAMP (p[1] - v, 0, 255); + p[-video_width] = CLAMP (p[-video_width] - v, 0, 255); + p[video_width] = CLAMP (p[video_width] - v, 0, 255); } - p += rowinc; - bitp += bit_rowinc; + p++; + bitp++; } + p += rowinc; + bitp += bit_rowinc; + } + + y = bitmap_y0; + y1 = y0 + bitmap_y0; + x1 = x0 + bitmap_x0; + bitp = bitmap->buffer + bitmap->pitch * bitmap_y0 + bitmap_x0; + p = pixbuf + video_width * y1 + x1; + u_p = + pixbuf + video_width * video_height + (video_width >> 1) * (y1 >> 1) + + (x1 >> 1); + skip_y = 0; + skip_x = 0; + + for (; y < bitmap_height; y++) { + int n; - y = bitmap_y0; - y1 = y0 + bitmap_y0; x1 = x0 + bitmap_x0; - bitp = bitmap->buffer + bitmap->pitch*bitmap_y0 + bitmap_x0; - p = pixbuf + video_width*y1 + x1; - u_p = pixbuf + video_width*video_height + (video_width >> 1)*(y1 >> 1) + (x1 >> 1); - skip_y = 0; skip_x = 0; - - for ( ; y < bitmap_height; y++){ - int n; - x1 = x0 + bitmap_x0; - skip_x = 0; - for(n = bitmap_width; n>0; --n){ - v = *bitp; - if (v) { - *p = v; - if (!skip_y) { - u_p[0] = u_p[u_plane_size] = 0x80; - } - } + for (n = bitmap_width; n > 0; --n) { + v = *bitp; + if (v) { + *p = v; if (!skip_y) { - skip_x = !skip_x; - if (!skip_x) u_p++; + u_p[0] = u_p[u_plane_size] = 0x80; } - p++; - bitp++; } - /*if (!skip_x && !skip_y) u_p--; */ - p += rowinc; - bitp += bit_rowinc; - skip_y = !skip_y; - u_p += skip_y? uv_rowinc : 0; + if (!skip_y) { + skip_x = !skip_x; + if (!skip_x) + u_p++; + } + p++; + bitp++; } + /*if (!skip_x && !skip_y) u_p--; */ + p += rowinc; + bitp += bit_rowinc; + skip_y = !skip_y; + u_p += skip_y ? uv_rowinc : 0; + } } static void -gst_textoverlay_video_chain(GstPad *pad, GstData *_data) +gst_textoverlay_video_chain (GstPad * pad, GstData * _data) { - GstBuffer *buf = GST_BUFFER (_data); - GstTextOverlay *overlay; - guchar *pixbuf; - gint x0, y0; - - g_return_if_fail(pad != NULL); - g_return_if_fail(GST_IS_PAD(pad)); - g_return_if_fail(buf != NULL); - overlay = GST_TEXTOVERLAY(gst_pad_get_parent(pad)); - g_return_if_fail(overlay != NULL); - g_return_if_fail(GST_IS_TEXTOVERLAY(overlay)); - - pixbuf = GST_BUFFER_DATA(buf); - - x0 = overlay->x0; - y0 = overlay->y0; - switch (overlay->valign) - { + GstBuffer *buf = GST_BUFFER (_data); + GstTextOverlay *overlay; + guchar *pixbuf; + gint x0, y0; + + g_return_if_fail (pad != NULL); + g_return_if_fail (GST_IS_PAD (pad)); + g_return_if_fail (buf != NULL); + overlay = GST_TEXTOVERLAY (gst_pad_get_parent (pad)); + g_return_if_fail (overlay != NULL); + g_return_if_fail (GST_IS_TEXTOVERLAY (overlay)); + + pixbuf = GST_BUFFER_DATA (buf); + + x0 = overlay->x0; + y0 = overlay->y0; + switch (overlay->valign) { case GST_TEXT_OVERLAY_VALIGN_BOTTOM: - y0 += overlay->bitmap.rows; - break; + y0 += overlay->bitmap.rows; + break; case GST_TEXT_OVERLAY_VALIGN_BASELINE: - y0 -= (overlay->bitmap.rows - overlay->baseline_y); - break; + y0 -= (overlay->bitmap.rows - overlay->baseline_y); + break; case GST_TEXT_OVERLAY_VALIGN_TOP: - break; - } + break; + } - switch (overlay->halign) - { + switch (overlay->halign) { case GST_TEXT_OVERLAY_HALIGN_LEFT: - break; + break; case GST_TEXT_OVERLAY_HALIGN_RIGHT: - x0 -= overlay->bitmap.width; - break; + x0 -= overlay->bitmap.width; + break; case GST_TEXT_OVERLAY_HALIGN_CENTER: - x0 -= overlay->bitmap.width / 2; - break; - } + x0 -= overlay->bitmap.width / 2; + break; + } - if (overlay->bitmap.buffer) - gst_text_overlay_blit_yuv420(overlay, &overlay->bitmap, pixbuf, x0, y0); + if (overlay->bitmap.buffer) + gst_text_overlay_blit_yuv420 (overlay, &overlay->bitmap, pixbuf, x0, y0); - gst_pad_push(overlay->srcpad, GST_DATA (buf)); + gst_pad_push (overlay->srcpad, GST_DATA (buf)); } #define PAST_END(buffer, time) \ @@ -377,270 +371,271 @@ gst_textoverlay_video_chain(GstPad *pad, GstData *_data) < (time)) static void -gst_textoverlay_loop(GstElement *element) +gst_textoverlay_loop (GstElement * element) { - GstTextOverlay *overlay; - GstBuffer *video_frame; - guint64 now; - - g_return_if_fail(element != NULL); - g_return_if_fail(GST_IS_TEXTOVERLAY(element)); - overlay = GST_TEXTOVERLAY(element); - - video_frame = GST_BUFFER (gst_pad_pull(overlay->video_sinkpad)); - now = GST_BUFFER_TIMESTAMP(video_frame); - - /* - * This state machine has a bug that can't be resolved easily. - * (Needs a more complicated state machine.) Basically, if the - * text that came from a buffer from the sink pad is being - * displayed, and the default text is changed by set_parameter, - * we'll incorrectly display the default text. - * - * Otherwise, this is a pretty decent state machine that handles - * buffer timestamps and durations correctly. (I think) - */ - - while (overlay->next_buffer == NULL){ - GST_DEBUG("attempting to pull a buffer"); - - /* read all text buffers until we get one "in the future" */ - if(!GST_PAD_IS_USABLE(overlay->text_sinkpad)){ - break; - } - overlay->next_buffer = GST_BUFFER (gst_pad_pull(overlay->text_sinkpad)); - if (!overlay->next_buffer) - break; - - if (PAST_END(overlay->next_buffer, now)){ - gst_buffer_unref(overlay->next_buffer); - overlay->next_buffer = NULL; - } + GstTextOverlay *overlay; + GstBuffer *video_frame; + guint64 now; + + g_return_if_fail (element != NULL); + g_return_if_fail (GST_IS_TEXTOVERLAY (element)); + overlay = GST_TEXTOVERLAY (element); + + video_frame = GST_BUFFER (gst_pad_pull (overlay->video_sinkpad)); + now = GST_BUFFER_TIMESTAMP (video_frame); + + /* + * This state machine has a bug that can't be resolved easily. + * (Needs a more complicated state machine.) Basically, if the + * text that came from a buffer from the sink pad is being + * displayed, and the default text is changed by set_parameter, + * we'll incorrectly display the default text. + * + * Otherwise, this is a pretty decent state machine that handles + * buffer timestamps and durations correctly. (I think) + */ + + while (overlay->next_buffer == NULL) { + GST_DEBUG ("attempting to pull a buffer"); + + /* read all text buffers until we get one "in the future" */ + if (!GST_PAD_IS_USABLE (overlay->text_sinkpad)) { + break; } + overlay->next_buffer = GST_BUFFER (gst_pad_pull (overlay->text_sinkpad)); + if (!overlay->next_buffer) + break; - if (overlay->next_buffer && - (GST_BUFFER_TIMESTAMP(overlay->next_buffer) <= now || - GST_BUFFER_TIMESTAMP(overlay->next_buffer) == GST_CLOCK_TIME_NONE)){ - GST_DEBUG("using new buffer"); - - if (overlay->current_buffer){ - gst_buffer_unref (overlay->current_buffer); - } - overlay->current_buffer = overlay->next_buffer; + if (PAST_END (overlay->next_buffer, now)) { + gst_buffer_unref (overlay->next_buffer); overlay->next_buffer = NULL; + } + } - GST_DEBUG ( "rendering '%*s'", - GST_BUFFER_SIZE(overlay->current_buffer), - GST_BUFFER_DATA(overlay->current_buffer)); - pango_layout_set_markup(overlay->layout, - GST_BUFFER_DATA(overlay->current_buffer), - GST_BUFFER_SIZE(overlay->current_buffer)); - render_text(overlay); - overlay->need_render = FALSE; + if (overlay->next_buffer && + (GST_BUFFER_TIMESTAMP (overlay->next_buffer) <= now || + GST_BUFFER_TIMESTAMP (overlay->next_buffer) == GST_CLOCK_TIME_NONE)) { + GST_DEBUG ("using new buffer"); + + if (overlay->current_buffer) { + gst_buffer_unref (overlay->current_buffer); } + overlay->current_buffer = overlay->next_buffer; + overlay->next_buffer = NULL; - if (overlay->current_buffer && PAST_END(overlay->current_buffer, now)){ - GST_DEBUG("dropping old buffer"); + GST_DEBUG ("rendering '%*s'", + GST_BUFFER_SIZE (overlay->current_buffer), + GST_BUFFER_DATA (overlay->current_buffer)); + pango_layout_set_markup (overlay->layout, + GST_BUFFER_DATA (overlay->current_buffer), + GST_BUFFER_SIZE (overlay->current_buffer)); + render_text (overlay); + overlay->need_render = FALSE; + } - gst_buffer_unref(overlay->current_buffer); - overlay->current_buffer = NULL; + if (overlay->current_buffer && PAST_END (overlay->current_buffer, now)) { + GST_DEBUG ("dropping old buffer"); - overlay->need_render = TRUE; - } + gst_buffer_unref (overlay->current_buffer); + overlay->current_buffer = NULL; - if(overlay->need_render){ - GST_DEBUG ( "rendering '%s'", overlay->default_text); - pango_layout_set_markup(overlay->layout, - overlay->default_text, strlen(overlay->default_text)); - render_text(overlay); + overlay->need_render = TRUE; + } - overlay->need_render = FALSE; - } + if (overlay->need_render) { + GST_DEBUG ("rendering '%s'", overlay->default_text); + pango_layout_set_markup (overlay->layout, + overlay->default_text, strlen (overlay->default_text)); + render_text (overlay); + + overlay->need_render = FALSE; + } - gst_textoverlay_video_chain(overlay->srcpad, GST_DATA (video_frame)); + gst_textoverlay_video_chain (overlay->srcpad, GST_DATA (video_frame)); } static GstElementStateReturn -gst_textoverlay_change_state(GstElement *element) +gst_textoverlay_change_state (GstElement * element) { - GstTextOverlay *overlay; + GstTextOverlay *overlay; - overlay = GST_TEXTOVERLAY(element); + overlay = GST_TEXTOVERLAY (element); - switch (GST_STATE_TRANSITION(element)) - { + switch (GST_STATE_TRANSITION (element)) { case GST_STATE_PAUSED_TO_PLAYING: - break; + break; case GST_STATE_PLAYING_TO_PAUSED: - break; + break; case GST_STATE_PAUSED_TO_READY: - break; - } + break; + } - parent_class->change_state(element); + parent_class->change_state (element); - return GST_STATE_SUCCESS; + return GST_STATE_SUCCESS; } static void -gst_textoverlay_finalize(GObject *object) +gst_textoverlay_finalize (GObject * object) { - GstTextOverlay *overlay = GST_TEXTOVERLAY(object); - - if (overlay->layout) { - g_object_unref(overlay->layout); - overlay->layout = NULL; - } - if (overlay->bitmap.buffer) { - g_free(overlay->bitmap.buffer); - overlay->bitmap.buffer = NULL; - } - - G_OBJECT_CLASS(parent_class)->finalize(object); + GstTextOverlay *overlay = GST_TEXTOVERLAY (object); + + if (overlay->layout) { + g_object_unref (overlay->layout); + overlay->layout = NULL; + } + if (overlay->bitmap.buffer) { + g_free (overlay->bitmap.buffer); + overlay->bitmap.buffer = NULL; + } + + G_OBJECT_CLASS (parent_class)->finalize (object); } static void -gst_textoverlay_init(GstTextOverlay *overlay) +gst_textoverlay_init (GstTextOverlay * overlay) { - /* video sink */ - overlay->video_sinkpad = gst_pad_new_from_template( - gst_static_pad_template_get (&video_sink_template_factory), "video_sink"); + /* video sink */ + overlay->video_sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&video_sink_template_factory), "video_sink"); /* gst_pad_set_chain_function(overlay->video_sinkpad, gst_textoverlay_video_chain); */ - gst_pad_set_link_function(overlay->video_sinkpad, gst_textoverlay_video_sinkconnect); - gst_element_add_pad(GST_ELEMENT(overlay), overlay->video_sinkpad); - - /* text sink */ - overlay->text_sinkpad = gst_pad_new_from_template( - gst_static_pad_template_get (&text_sink_template_factory), "text_sink"); + gst_pad_set_link_function (overlay->video_sinkpad, + gst_textoverlay_video_sinkconnect); + gst_element_add_pad (GST_ELEMENT (overlay), overlay->video_sinkpad); + + /* text sink */ + overlay->text_sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&text_sink_template_factory), "text_sink"); /* gst_pad_set_link_function(overlay->text_sinkpad, gst_textoverlay_text_sinkconnect); */ - gst_element_add_pad(GST_ELEMENT(overlay), overlay->text_sinkpad); + gst_element_add_pad (GST_ELEMENT (overlay), overlay->text_sinkpad); - /* (video) source */ - overlay->srcpad = gst_pad_new_from_template( - gst_static_pad_template_get (&textoverlay_src_template_factory), "src"); - gst_element_add_pad(GST_ELEMENT(overlay), overlay->srcpad); + /* (video) source */ + overlay->srcpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&textoverlay_src_template_factory), "src"); + gst_element_add_pad (GST_ELEMENT (overlay), overlay->srcpad); - overlay->layout = pango_layout_new(GST_TEXTOVERLAY_GET_CLASS(overlay)->pango_context); - memset(&overlay->bitmap, 0, sizeof(overlay->bitmap)); + overlay->layout = + pango_layout_new (GST_TEXTOVERLAY_GET_CLASS (overlay)->pango_context); + memset (&overlay->bitmap, 0, sizeof (overlay->bitmap)); - overlay->halign = GST_TEXT_OVERLAY_HALIGN_CENTER; - overlay->valign = GST_TEXT_OVERLAY_VALIGN_BASELINE; - overlay->x0 = overlay->y0 = 0; + overlay->halign = GST_TEXT_OVERLAY_HALIGN_CENTER; + overlay->valign = GST_TEXT_OVERLAY_VALIGN_BASELINE; + overlay->x0 = overlay->y0 = 0; - overlay->default_text = g_strdup(""); - overlay->need_render = TRUE; + overlay->default_text = g_strdup (""); + overlay->need_render = TRUE; - gst_element_set_loop_function(GST_ELEMENT(overlay), gst_textoverlay_loop); + gst_element_set_loop_function (GST_ELEMENT (overlay), gst_textoverlay_loop); } static void -gst_textoverlay_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +gst_textoverlay_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) { - GstTextOverlay *overlay; + GstTextOverlay *overlay; - /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_TEXTOVERLAY(object)); - overlay = GST_TEXTOVERLAY(object); + /* it's not null if we got it, but it might not be ours */ + g_return_if_fail (GST_IS_TEXTOVERLAY (object)); + overlay = GST_TEXTOVERLAY (object); - switch (prop_id) - { + switch (prop_id) { case ARG_TEXT: - if(overlay->default_text){ - g_free(overlay->default_text); - } - overlay->default_text = g_strdup(g_value_get_string(value)); - overlay->need_render = TRUE; - break; + if (overlay->default_text) { + g_free (overlay->default_text); + } + overlay->default_text = g_strdup (g_value_get_string (value)); + overlay->need_render = TRUE; + break; case ARG_VALIGN: - if (strcasecmp(g_value_get_string(value), "baseline") == 0) - overlay->valign = GST_TEXT_OVERLAY_VALIGN_BASELINE; - else if (strcasecmp(g_value_get_string(value), "bottom") == 0) - overlay->valign = GST_TEXT_OVERLAY_VALIGN_BOTTOM; - else if (strcasecmp(g_value_get_string(value), "top") == 0) - overlay->valign = GST_TEXT_OVERLAY_VALIGN_TOP; - else - g_warning("Invalid 'valign' property value: %s", - g_value_get_string(value)); - break; + if (strcasecmp (g_value_get_string (value), "baseline") == 0) + overlay->valign = GST_TEXT_OVERLAY_VALIGN_BASELINE; + else if (strcasecmp (g_value_get_string (value), "bottom") == 0) + overlay->valign = GST_TEXT_OVERLAY_VALIGN_BOTTOM; + else if (strcasecmp (g_value_get_string (value), "top") == 0) + overlay->valign = GST_TEXT_OVERLAY_VALIGN_TOP; + else + g_warning ("Invalid 'valign' property value: %s", + g_value_get_string (value)); + break; case ARG_HALIGN: - if (strcasecmp(g_value_get_string(value), "left") == 0) - overlay->halign = GST_TEXT_OVERLAY_HALIGN_LEFT; - else if (strcasecmp(g_value_get_string(value), "right") == 0) - overlay->halign = GST_TEXT_OVERLAY_HALIGN_RIGHT; - else if (strcasecmp(g_value_get_string(value), "center") == 0) - overlay->halign = GST_TEXT_OVERLAY_HALIGN_CENTER; - else - g_warning("Invalid 'halign' property value: %s", - g_value_get_string(value)); - break; + if (strcasecmp (g_value_get_string (value), "left") == 0) + overlay->halign = GST_TEXT_OVERLAY_HALIGN_LEFT; + else if (strcasecmp (g_value_get_string (value), "right") == 0) + overlay->halign = GST_TEXT_OVERLAY_HALIGN_RIGHT; + else if (strcasecmp (g_value_get_string (value), "center") == 0) + overlay->halign = GST_TEXT_OVERLAY_HALIGN_CENTER; + else + g_warning ("Invalid 'halign' property value: %s", + g_value_get_string (value)); + break; case ARG_X0: - overlay->x0 = g_value_get_int(value); - break; + overlay->x0 = g_value_get_int (value); + break; case ARG_Y0: - overlay->y0 = g_value_get_int(value); - break; + overlay->y0 = g_value_get_int (value); + break; case ARG_FONT_DESC: { - PangoFontDescription *desc; - desc = pango_font_description_from_string(g_value_get_string(value)); - if (desc) { - g_message("font description set: %s", g_value_get_string(value)); - pango_layout_set_font_description(overlay->layout, desc); - pango_font_description_free(desc); - render_text(overlay); - } else - g_warning("font description parse failed: %s", g_value_get_string(value)); - break; + PangoFontDescription *desc; + + desc = pango_font_description_from_string (g_value_get_string (value)); + if (desc) { + g_message ("font description set: %s", g_value_get_string (value)); + pango_layout_set_font_description (overlay->layout, desc); + pango_font_description_free (desc); + render_text (overlay); + } else + g_warning ("font description parse failed: %s", + g_value_get_string (value)); + break; } default: - break; - } + break; + } } static void -gst_textoverlay_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +gst_textoverlay_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { - GstTextOverlay *overlay; + GstTextOverlay *overlay; - /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_TEXTOVERLAY(object)); - overlay = GST_TEXTOVERLAY(object); + /* it's not null if we got it, but it might not be ours */ + g_return_if_fail (GST_IS_TEXTOVERLAY (object)); + overlay = GST_TEXTOVERLAY (object); - switch (prop_id) { + switch (prop_id) { default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static gboolean -plugin_init(GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { - if (!gst_element_register (plugin, "textoverlay", GST_RANK_PRIMARY, GST_TYPE_TEXTOVERLAY)) - return FALSE; + if (!gst_element_register (plugin, "textoverlay", GST_RANK_PRIMARY, + GST_TYPE_TEXTOVERLAY)) + return FALSE; - /*texttestsrc_plugin_init(module, plugin);*/ - /*subparse_plugin_init(module, plugin);*/ - return TRUE; + /*texttestsrc_plugin_init(module, plugin); */ + /*subparse_plugin_init(module, plugin); */ + return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR, "textoverlay", - "Text overlay", - plugin_init, - VERSION, - "GPL", - GST_PACKAGE, - GST_ORIGIN) - + "Text overlay", plugin_init, VERSION, "GPL", GST_PACKAGE, GST_ORIGIN) diff --git a/ext/pango/gsttextoverlay.h b/ext/pango/gsttextoverlay.h index b039acac..08ad8145 100644 --- a/ext/pango/gsttextoverlay.h +++ b/ext/pango/gsttextoverlay.h @@ -6,7 +6,6 @@ #include <pango/pangoft2.h> G_BEGIN_DECLS - #define GST_TYPE_TEXTOVERLAY (gst_textoverlay_get_type()) #define GST_TEXTOVERLAY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),\ GST_TYPE_TEXTOVERLAY, GstTextOverlay)) @@ -18,56 +17,60 @@ G_BEGIN_DECLS GST_TYPE_TEXTOVERLAY)) #define GST_IS_TEXTOVERLAY_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),\ GST_TYPE_TEXTOVERLAY)) - -typedef struct _GstTextOverlay GstTextOverlay; +typedef struct _GstTextOverlay GstTextOverlay; typedef struct _GstTextOverlayClass GstTextOverlayClass; typedef enum _GstTextOverlayVAlign GstTextOverlayVAlign; typedef enum _GstTextOverlayHAlign GstTextOverlayHAlign; -enum _GstTextOverlayVAlign { - GST_TEXT_OVERLAY_VALIGN_BASELINE, - GST_TEXT_OVERLAY_VALIGN_BOTTOM, - GST_TEXT_OVERLAY_VALIGN_TOP, +enum _GstTextOverlayVAlign +{ + GST_TEXT_OVERLAY_VALIGN_BASELINE, + GST_TEXT_OVERLAY_VALIGN_BOTTOM, + GST_TEXT_OVERLAY_VALIGN_TOP, }; -enum _GstTextOverlayHAlign { - GST_TEXT_OVERLAY_HALIGN_LEFT, - GST_TEXT_OVERLAY_HALIGN_CENTER, - GST_TEXT_OVERLAY_HALIGN_RIGHT, +enum _GstTextOverlayHAlign +{ + GST_TEXT_OVERLAY_HALIGN_LEFT, + GST_TEXT_OVERLAY_HALIGN_CENTER, + GST_TEXT_OVERLAY_HALIGN_RIGHT, }; -struct _GstTextOverlay { - GstElement element; +struct _GstTextOverlay +{ + GstElement element; - GstPad *video_sinkpad; - GstPad *text_sinkpad; - GstPad *srcpad; - gint width; - gint height; - PangoLayout *layout; - FT_Bitmap bitmap; - gint bitmap_buffer_size; - gint baseline_y; - GstTextOverlayVAlign valign; - GstTextOverlayHAlign halign; - gint x0; - gint y0; - GstBuffer *current_buffer; - GstBuffer *next_buffer; - gchar *default_text; - gboolean need_render; + GstPad *video_sinkpad; + GstPad *text_sinkpad; + GstPad *srcpad; + gint width; + gint height; + PangoLayout *layout; + FT_Bitmap bitmap; + gint bitmap_buffer_size; + gint baseline_y; + GstTextOverlayVAlign valign; + GstTextOverlayHAlign halign; + gint x0; + gint y0; + GstBuffer *current_buffer; + GstBuffer *next_buffer; + gchar *default_text; + gboolean need_render; }; -struct _GstTextOverlayClass { - GstElementClass parent_class; +struct _GstTextOverlayClass +{ + GstElementClass parent_class; - PangoContext *pango_context; + PangoContext *pango_context; }; -GType gst_textoverlay_get_type(void) G_GNUC_CONST; +GType +gst_textoverlay_get_type (void) + G_GNUC_CONST; G_END_DECLS - #endif /* __GST_TEXTOVERLAY_H */ diff --git a/ext/pango/gsttimeoverlay.c b/ext/pango/gsttimeoverlay.c index 9a3b292e..9ce5c897 100644 --- a/ext/pango/gsttimeoverlay.c +++ b/ext/pango/gsttimeoverlay.c @@ -45,25 +45,30 @@ /* GstTimeoverlay signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, /* FILL ME */ }; -static void gst_timeoverlay_base_init (gpointer g_class); -static void gst_timeoverlay_class_init (gpointer g_class, gpointer class_data); -static void gst_timeoverlay_init (GTypeInstance *instance, gpointer g_class); +static void gst_timeoverlay_base_init (gpointer g_class); +static void gst_timeoverlay_class_init (gpointer g_class, gpointer class_data); +static void gst_timeoverlay_init (GTypeInstance * instance, gpointer g_class); -static void gst_timeoverlay_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); -static void gst_timeoverlay_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); +static void gst_timeoverlay_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_timeoverlay_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); -static void gst_timeoverlay_planar411(GstVideofilter *videofilter, void *dest, void *src); -static void gst_timeoverlay_setup(GstVideofilter *videofilter); +static void gst_timeoverlay_planar411 (GstVideofilter * videofilter, void *dest, + void *src); +static void gst_timeoverlay_setup (GstVideofilter * videofilter); GType gst_timeoverlay_get_type (void) @@ -72,44 +77,43 @@ gst_timeoverlay_get_type (void) if (!timeoverlay_type) { static const GTypeInfo timeoverlay_info = { - sizeof(GstTimeoverlayClass), + sizeof (GstTimeoverlayClass), gst_timeoverlay_base_init, NULL, gst_timeoverlay_class_init, NULL, NULL, - sizeof(GstTimeoverlay), + sizeof (GstTimeoverlay), 0, gst_timeoverlay_init, }; - timeoverlay_type = g_type_register_static(GST_TYPE_VIDEOFILTER, - "GstTimeoverlay", &timeoverlay_info, 0); + timeoverlay_type = g_type_register_static (GST_TYPE_VIDEOFILTER, + "GstTimeoverlay", &timeoverlay_info, 0); } return timeoverlay_type; } static GstVideofilterFormat gst_timeoverlay_formats[] = { - { "I420", 12, gst_timeoverlay_planar411, }, + {"I420", 12, gst_timeoverlay_planar411,}, }; - + static void gst_timeoverlay_base_init (gpointer g_class) { - static GstElementDetails timeoverlay_details = GST_ELEMENT_DETAILS ( - "Time Overlay", - "Filter/Editor/Video", - "Overlays the time on a video stream", - "David Schleef <ds@schleef.org>" - ); + static GstElementDetails timeoverlay_details = + GST_ELEMENT_DETAILS ("Time Overlay", + "Filter/Editor/Video", + "Overlays the time on a video stream", + "David Schleef <ds@schleef.org>"); GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class); int i; - + gst_element_class_set_details (element_class, &timeoverlay_details); - for(i=0;i<G_N_ELEMENTS(gst_timeoverlay_formats);i++){ - gst_videofilter_class_add_format(videofilter_class, + for (i = 0; i < G_N_ELEMENTS (gst_timeoverlay_formats); i++) { + gst_videofilter_class_add_format (videofilter_class, gst_timeoverlay_formats + i); } @@ -126,10 +130,10 @@ gst_timeoverlay_class_init (gpointer g_class, gpointer class_data) videofilter_class = GST_VIDEOFILTER_CLASS (g_class); #if 0 - g_object_class_install_property(gobject_class, ARG_METHOD, - g_param_spec_enum("method","method","method", - GST_TYPE_TIMEOVERLAY_METHOD, GST_TIMEOVERLAY_METHOD_1, - G_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, ARG_METHOD, + g_param_spec_enum ("method", "method", "method", + GST_TYPE_TIMEOVERLAY_METHOD, GST_TIMEOVERLAY_METHOD_1, + G_PARAM_READWRITE)); #endif gobject_class->set_property = gst_timeoverlay_set_property; @@ -139,28 +143,29 @@ gst_timeoverlay_class_init (gpointer g_class, gpointer class_data) } static void -gst_timeoverlay_init (GTypeInstance *instance, gpointer g_class) +gst_timeoverlay_init (GTypeInstance * instance, gpointer g_class) { GstTimeoverlay *timeoverlay = GST_TIMEOVERLAY (instance); GstVideofilter *videofilter; - GST_DEBUG("gst_timeoverlay_init"); + GST_DEBUG ("gst_timeoverlay_init"); - videofilter = GST_VIDEOFILTER(timeoverlay); + videofilter = GST_VIDEOFILTER (timeoverlay); /* do stuff */ } static void -gst_timeoverlay_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +gst_timeoverlay_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) { GstTimeoverlay *src; /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_TIMEOVERLAY(object)); - src = GST_TIMEOVERLAY(object); + g_return_if_fail (GST_IS_TIMEOVERLAY (object)); + src = GST_TIMEOVERLAY (object); - GST_DEBUG("gst_timeoverlay_set_property"); + GST_DEBUG ("gst_timeoverlay_set_property"); switch (prop_id) { #if 0 case ARG_METHOD: @@ -173,13 +178,14 @@ gst_timeoverlay_set_property (GObject *object, guint prop_id, const GValue *valu } static void -gst_timeoverlay_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +gst_timeoverlay_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { GstTimeoverlay *src; /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_TIMEOVERLAY(object)); - src = GST_TIMEOVERLAY(object); + g_return_if_fail (GST_IS_TIMEOVERLAY (object)); + src = GST_TIMEOVERLAY (object); switch (prop_id) { #if 0 @@ -193,35 +199,29 @@ gst_timeoverlay_get_property (GObject *object, guint prop_id, GValue *value, GPa } } -static gboolean plugin_init (GstPlugin *plugin) +static gboolean +plugin_init (GstPlugin * plugin) { - if(!gst_library_load("gstvideofilter")) + if (!gst_library_load ("gstvideofilter")) return FALSE; return gst_element_register (plugin, "timeoverlay", GST_RANK_NONE, GST_TYPE_TIMEOVERLAY); } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "timeoverlay", - "Time overlay", - plugin_init, - VERSION, - GST_LICENSE, - GST_PACKAGE, - GST_ORIGIN -) - -static void gst_timeoverlay_setup(GstVideofilter *videofilter) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "timeoverlay", + "Time overlay", plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN) + + static void gst_timeoverlay_setup (GstVideofilter * videofilter) { GstTimeoverlay *timeoverlay; PangoFontDescription *font_description; PangoContext *context; - g_return_if_fail(GST_IS_TIMEOVERLAY(videofilter)); - timeoverlay = GST_TIMEOVERLAY(videofilter); + g_return_if_fail (GST_IS_TIMEOVERLAY (videofilter)); + timeoverlay = GST_TIMEOVERLAY (videofilter); /* if any setup needs to be done, do it here */ @@ -246,7 +246,8 @@ static void gst_timeoverlay_setup(GstVideofilter *videofilter) } -static char *gst_timeoverlay_print_smpte_time(guint64 time) +static char * +gst_timeoverlay_print_smpte_time (guint64 time) { int hours; int minutes; @@ -254,21 +255,21 @@ static char *gst_timeoverlay_print_smpte_time(guint64 time) int ms; double x; - x = rint((time + 500000)*1e-6); + x = rint ((time + 500000) * 1e-6); - hours = floor(x/(60*60*1000)); - x -= hours*60*60*1000; - minutes = floor(x/(60*1000)); - x -= minutes*60*1000; - seconds = floor(x/(1000)); - x -= seconds*1000; - ms = rint(x); + hours = floor (x / (60 * 60 * 1000)); + x -= hours * 60 * 60 * 1000; + minutes = floor (x / (60 * 1000)); + x -= minutes * 60 * 1000; + seconds = floor (x / (1000)); + x -= seconds * 1000; + ms = rint (x); - return g_strdup_printf("%02d:%02d:%02d.%03d",hours,minutes,seconds,ms); + return g_strdup_printf ("%02d:%02d:%02d.%03d", hours, minutes, seconds, ms); } -static void gst_timeoverlay_planar411(GstVideofilter *videofilter, - void *dest, void *src) +static void +gst_timeoverlay_planar411 (GstVideofilter * videofilter, void *dest, void *src) { GstTimeoverlay *timeoverlay; int width; @@ -280,19 +281,21 @@ static void gst_timeoverlay_planar411(GstVideofilter *videofilter, char *string; int i; - g_return_if_fail(GST_IS_TIMEOVERLAY(videofilter)); - timeoverlay = GST_TIMEOVERLAY(videofilter); + g_return_if_fail (GST_IS_TIMEOVERLAY (videofilter)); + timeoverlay = GST_TIMEOVERLAY (videofilter); - width = gst_videofilter_get_input_width(videofilter); - height = gst_videofilter_get_input_height(videofilter); + width = gst_videofilter_get_input_width (videofilter); + height = gst_videofilter_get_input_height (videofilter); - width = gst_videofilter_get_input_width(videofilter); - height = gst_videofilter_get_input_height(videofilter); + width = gst_videofilter_get_input_width (videofilter); + height = gst_videofilter_get_input_height (videofilter); layout = pango_layout_new (timeoverlay->context); - string = gst_timeoverlay_print_smpte_time(GST_BUFFER_TIMESTAMP(videofilter->in_buf)); - pango_layout_set_text (layout, string, strlen(string)); - g_free(string); + string = + gst_timeoverlay_print_smpte_time (GST_BUFFER_TIMESTAMP (videofilter-> + in_buf)); + pango_layout_set_text (layout, string, strlen (string)); + g_free (string); pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT); pango_layout_set_width (layout, -1); @@ -303,15 +306,15 @@ static void gst_timeoverlay_planar411(GstVideofilter *videofilter, //hheight = 20; - memcpy(dest, src, videofilter->from_buf_size); + memcpy (dest, src, videofilter->from_buf_size); - for(i=0;i<b_height;i++){ - memset(dest + i*width, 0, b_width); + for (i = 0; i < b_height; i++) { + memset (dest + i * width, 0, b_width); } - for(i=0;i<b_height/2;i++){ - memset(dest + width*height + i*(width/2), 128, b_width/2); - memset(dest + width*height + (width/2)*(height/2) + i*(width/2), 128, - b_width/2); + for (i = 0; i < b_height / 2; i++) { + memset (dest + width * height + i * (width / 2), 128, b_width / 2); + memset (dest + width * height + (width / 2) * (height / 2) + + i * (width / 2), 128, b_width / 2); } bitmap.rows = b_height; bitmap.width = b_width; @@ -322,4 +325,3 @@ static void gst_timeoverlay_planar411(GstVideofilter *videofilter, pango_ft2_render_layout (&bitmap, layout, 0, 0); } - diff --git a/ext/pango/gsttimeoverlay.h b/ext/pango/gsttimeoverlay.h index 505f8f04..a591bd6a 100644 --- a/ext/pango/gsttimeoverlay.h +++ b/ext/pango/gsttimeoverlay.h @@ -29,7 +29,6 @@ G_BEGIN_DECLS - #define GST_TYPE_TIMEOVERLAY \ (gst_timeoverlay_get_type()) #define GST_TIMEOVERLAY(obj) \ @@ -40,11 +39,11 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_TIMEOVERLAY)) #define GST_IS_TIMEOVERLAY_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_TIMEOVERLAY)) - typedef struct _GstTimeoverlay GstTimeoverlay; typedef struct _GstTimeoverlayClass GstTimeoverlayClass; -struct _GstTimeoverlay { +struct _GstTimeoverlay +{ GstVideofilter videofilter; PangoFontDescription *font_description; @@ -52,13 +51,12 @@ struct _GstTimeoverlay { }; -struct _GstTimeoverlayClass { +struct _GstTimeoverlayClass +{ GstVideofilterClass parent_class; }; -GType gst_timeoverlay_get_type(void); +GType gst_timeoverlay_get_type (void); G_END_DECLS - #endif /* __GST_TIMEOVERLAY_H__ */ - diff --git a/ext/raw1394/gst1394.c b/ext/raw1394/gst1394.c index 0a5a8b7a..250a5764 100644 --- a/ext/raw1394/gst1394.c +++ b/ext/raw1394/gst1394.c @@ -27,23 +27,17 @@ #include "gstdv1394src.h" static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { - if (!gst_element_register(plugin, "dv1394src", GST_RANK_NONE, GST_TYPE_DV1394SRC)) + if (!gst_element_register (plugin, "dv1394src", GST_RANK_NONE, + GST_TYPE_DV1394SRC)) return FALSE; return TRUE; } -GST_PLUGIN_DEFINE( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "gst1394", - "Source for DV data via IEEE1394 interface", - plugin_init, - VERSION, - "LGPL", - GST_PACKAGE, - GST_ORIGIN -); - +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "gst1394", + "Source for DV data via IEEE1394 interface", + plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN); diff --git a/ext/raw1394/gstdv1394src.c b/ext/raw1394/gstdv1394src.c index a044d0f3..9509ea2c 100644 --- a/ext/raw1394/gstdv1394src.c +++ b/ext/raw1394/gstdv1394src.c @@ -31,84 +31,85 @@ #define NTSC_FRAMESIZE 120000 /* Filter signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_CONSECUTIVE, ARG_SKIP, ARG_DROP_INCOMPLETE, }; -static GstElementDetails gst_dv1394src_details = GST_ELEMENT_DETAILS ( - "Firewire (1394) DV Source", - "Source/Video", - "Source for DV video data from firewire port", - "Erik Walthinsen <omega@temple-baptist.com>\n" - "Daniel Fischer <dan@f3c.com>" -); +static GstElementDetails gst_dv1394src_details = +GST_ELEMENT_DETAILS ("Firewire (1394) DV Source", + "Source/Video", + "Source for DV video data from firewire port", + "Erik Walthinsen <omega@temple-baptist.com>\n" + "Daniel Fischer <dan@f3c.com>"); #if 0 -static GstPadTemplate* +static GstPadTemplate * gst_dv1394src_factory (void) { static GstPadTemplate *template = NULL; if (!template) { - template = gst_pad_template_new ( - "src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ( - "dv1394src", - "video/dv", - gst_props_new ( - "format", GST_PROPS_LIST ( - G_TYPE_STRING ("NTSC"), - G_TYPE_STRING ("PAL") - ), - NULL) - ), - NULL); + template = gst_pad_template_new ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("dv1394src", + "video/dv", + gst_props_new ("format", GST_PROPS_LIST (G_TYPE_STRING ("NTSC"), + G_TYPE_STRING ("PAL") + ), NULL) + ), NULL); } return template; } #endif -static void gst_dv1394src_base_init (gpointer g_class); -static void gst_dv1394src_class_init (GstDV1394SrcClass *klass); -static void gst_dv1394src_init (GstDV1394Src *filter); +static void gst_dv1394src_base_init (gpointer g_class); +static void gst_dv1394src_class_init (GstDV1394SrcClass * klass); +static void gst_dv1394src_init (GstDV1394Src * filter); -static void gst_dv1394src_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); -static void gst_dv1394src_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); +static void gst_dv1394src_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_dv1394src_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); -static GstElementStateReturn gst_dv1394src_change_state (GstElement *element); +static GstElementStateReturn gst_dv1394src_change_state (GstElement * element); -static GstData * gst_dv1394src_get (GstPad *pad); +static GstData *gst_dv1394src_get (GstPad * pad); static GstElementClass *parent_class = NULL; + /*static guint gst_filter_signals[LAST_SIGNAL] = { 0 }; */ GType -gst_dv1394src_get_type(void) { +gst_dv1394src_get_type (void) +{ static GType gst_dv1394src_type = 0; if (!gst_dv1394src_type) { static const GTypeInfo gst_dv1394src_info = { - sizeof(GstDV1394Src), + sizeof (GstDV1394Src), gst_dv1394src_base_init, NULL, - (GClassInitFunc)gst_dv1394src_class_init, + (GClassInitFunc) gst_dv1394src_class_init, NULL, NULL, - sizeof(GstDV1394Src), + sizeof (GstDV1394Src), 0, - (GInstanceInitFunc)gst_dv1394src_init, + (GInstanceInitFunc) gst_dv1394src_init, }; - gst_dv1394src_type = g_type_register_static(GST_TYPE_ELEMENT, "DV1394Src", &gst_dv1394src_info, 0); + gst_dv1394src_type = + g_type_register_static (GST_TYPE_ELEMENT, "DV1394Src", + &gst_dv1394src_info, 0); } return gst_dv1394src_type; } @@ -122,25 +123,26 @@ gst_dv1394src_base_init (gpointer g_class) } static void -gst_dv1394src_class_init (GstDV1394SrcClass *klass) +gst_dv1394src_class_init (GstDV1394SrcClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; - gobject_class = (GObjectClass*)klass; - gstelement_class = (GstElementClass*)klass; + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; - g_object_class_install_property( G_OBJECT_CLASS(klass), ARG_CONSECUTIVE, - g_param_spec_int("consecutive","consecutive frames","send n consecutive frames after skipping", - 1, G_MAXINT,1,G_PARAM_READWRITE)); - g_object_class_install_property( G_OBJECT_CLASS(klass), ARG_SKIP, - g_param_spec_int("skip","skip frames","skip n frames", - 0, G_MAXINT,1,G_PARAM_READWRITE)); - g_object_class_install_property( G_OBJECT_CLASS(klass), ARG_DROP_INCOMPLETE, - g_param_spec_boolean("drop_incomplete","drop_incomplete","drop incomplete frames", - TRUE, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CONSECUTIVE, + g_param_spec_int ("consecutive", "consecutive frames", + "send n consecutive frames after skipping", 1, G_MAXINT, 1, + G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SKIP, + g_param_spec_int ("skip", "skip frames", "skip n frames", 0, G_MAXINT, 1, + G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DROP_INCOMPLETE, + g_param_spec_boolean ("drop_incomplete", "drop_incomplete", + "drop incomplete frames", TRUE, G_PARAM_READWRITE)); - parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + parent_class = g_type_class_ref (GST_TYPE_ELEMENT); gobject_class->set_property = gst_dv1394src_set_property; gobject_class->get_property = gst_dv1394src_get_property; @@ -149,7 +151,7 @@ gst_dv1394src_class_init (GstDV1394SrcClass *klass) } static void -gst_dv1394src_init (GstDV1394Src *dv1394src) +gst_dv1394src_init (GstDV1394Src * dv1394src) { dv1394src->srcpad = gst_pad_new ("src", GST_PAD_SRC); gst_pad_set_get_function (dv1394src->srcpad, gst_dv1394src_get); @@ -158,188 +160,199 @@ gst_dv1394src_init (GstDV1394Src *dv1394src) dv1394src->card = 0; dv1394src->port = 0; dv1394src->channel = 63; - + dv1394src->consecutive = 1; dv1394src->skip = 0; dv1394src->drop_incomplete = TRUE; - + /* initialized when first header received */ - dv1394src->frameSize=0; - + dv1394src->frameSize = 0; + dv1394src->buf = NULL; dv1394src->frame = NULL; dv1394src->frameSequence = 0; } static void -gst_dv1394src_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +gst_dv1394src_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) { GstDV1394Src *filter; /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_DV1394SRC(object)); - filter = GST_DV1394SRC(object); + g_return_if_fail (GST_IS_DV1394SRC (object)); + filter = GST_DV1394SRC (object); switch (prop_id) { case ARG_SKIP: - filter->skip = g_value_get_int(value); - break; + filter->skip = g_value_get_int (value); + break; case ARG_CONSECUTIVE: - filter->consecutive = g_value_get_int(value); - break; + filter->consecutive = g_value_get_int (value); + break; case ARG_DROP_INCOMPLETE: - filter->drop_incomplete = g_value_get_boolean(value); - break; + filter->drop_incomplete = g_value_get_boolean (value); + break; default: break; } } static void -gst_dv1394src_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +gst_dv1394src_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { GstDV1394Src *filter; /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_DV1394SRC(object)); - filter = GST_DV1394SRC(object); + g_return_if_fail (GST_IS_DV1394SRC (object)); + filter = GST_DV1394SRC (object); switch (prop_id) { case ARG_SKIP: - g_value_set_int( value, filter->skip ); - break; + g_value_set_int (value, filter->skip); + break; case ARG_CONSECUTIVE: - g_value_set_int( value, filter->consecutive ); - break; + g_value_set_int (value, filter->consecutive); + break; case ARG_DROP_INCOMPLETE: - g_value_set_boolean( value, filter->drop_incomplete ); - break; + g_value_set_boolean (value, filter->drop_incomplete); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } -static -int gst_dv1394src_iso_receive(raw1394handle_t handle,int channel,size_t len,quadlet_t *data) { - GstDV1394Src *dv1394src = GST_DV1394SRC (raw1394_get_userdata(handle)); +static int +gst_dv1394src_iso_receive (raw1394handle_t handle, int channel, size_t len, + quadlet_t * data) +{ + GstDV1394Src *dv1394src = GST_DV1394SRC (raw1394_get_userdata (handle)); if (len > 16) { - /* - the following code taken from kino-0.51 (Dan Dennedy/Charles Yates) - */ - unsigned char *p = (unsigned char*) & data[3]; - int section_type = p[0] >> 5; /* section type is in bits 5 - 7 */ - int dif_sequence = p[1] >> 4; /* dif sequence number is in bits 4 - 7 */ - int dif_block = p[2]; - - /* if we are at the beginning of a frame, - we set buf=frame, and alloc a new buffer for frame - */ - - if (section_type == 0 && dif_sequence == 0) { // dif header - - if( !dv1394src->negotiated) { - // figure format (NTSC/PAL) - if( p[3] & 0x80 ) { - // PAL - dv1394src->frameSize = PAL_FRAMESIZE; - GST_DEBUG ("PAL data"); - if (gst_pad_try_set_caps (dv1394src->srcpad, - gst_caps_new_simple ("video/dv", - "format", G_TYPE_STRING, "PAL", NULL)) <= 0) { - GST_ELEMENT_ERROR (dv1394src, CORE, NEGOTIATION, (NULL), - ("Could not set source caps for PAL")); - return 0; - } - } else { - // NTSC (untested) - dv1394src->frameSize = NTSC_FRAMESIZE; - GST_DEBUG ("NTSC data [untested] - please report success/failure to <dan@f3c.com>"); - if (gst_pad_try_set_caps (dv1394src->srcpad, - gst_caps_new_simple ("video/dv", - "format", G_TYPE_STRING, "NTSC", NULL)) <= 0) { - GST_ELEMENT_ERROR (dv1394src, CORE, NEGOTIATION, (NULL), - ("Could not set source caps for NTSC")); - return 0; - } - } - dv1394src->negotiated = TRUE; - } - - // drop last frame when not complete - if( !dv1394src->drop_incomplete || dv1394src->bytesInFrame == dv1394src->frameSize ) { - dv1394src->buf = dv1394src->frame; - } else { - GST_INFO_OBJECT (GST_ELEMENT(dv1394src), "incomplete frame dropped"); - } - dv1394src->frame = NULL; - - dv1394src->frameSequence++; - - if( dv1394src->frameSequence % (dv1394src->skip+dv1394src->consecutive) < dv1394src->consecutive ) { - dv1394src->frame = gst_buffer_new_and_alloc (dv1394src->frameSize); - } - dv1394src->bytesInFrame = 0; - } - - if (dv1394src->frame != NULL) { - void *data = GST_BUFFER_DATA( dv1394src->frame ); - - - switch (section_type) { - case 0: /* 1 Header block */ - /* p[3] |= 0x80; // hack to force PAL data */ - memcpy(data + dif_sequence * 150 * 80, p, 480); - break; - - case 1: /* 2 Subcode blocks */ - memcpy(data + dif_sequence * 150 * 80 + (1 + dif_block) * 80, p, 480); - break; - - case 2: /* 3 VAUX blocks */ - memcpy(data + dif_sequence * 150 * 80 + (3 + dif_block) * 80, p, 480); - break; - - case 3: /* 9 Audio blocks interleaved with video */ - memcpy(data + dif_sequence * 150 * 80 + (6 + dif_block * 16) * 80, p, 480); - break; - - case 4: /* 135 Video blocks interleaved with audio */ - memcpy(data + dif_sequence * 150 * 80 + (7 + (dif_block / 15) + dif_block) * 80, p, 480); - break; - - default: /* we can´t handle any other data */ - break; - } - dv1394src->bytesInFrame += 480; - } + /* + the following code taken from kino-0.51 (Dan Dennedy/Charles Yates) + */ + unsigned char *p = (unsigned char *) &data[3]; + int section_type = p[0] >> 5; /* section type is in bits 5 - 7 */ + int dif_sequence = p[1] >> 4; /* dif sequence number is in bits 4 - 7 */ + int dif_block = p[2]; + + /* if we are at the beginning of a frame, + we set buf=frame, and alloc a new buffer for frame + */ + + if (section_type == 0 && dif_sequence == 0) { // dif header + + if (!dv1394src->negotiated) { + // figure format (NTSC/PAL) + if (p[3] & 0x80) { + // PAL + dv1394src->frameSize = PAL_FRAMESIZE; + GST_DEBUG ("PAL data"); + if (gst_pad_try_set_caps (dv1394src->srcpad, + gst_caps_new_simple ("video/dv", + "format", G_TYPE_STRING, "PAL", NULL)) <= 0) { + GST_ELEMENT_ERROR (dv1394src, CORE, NEGOTIATION, (NULL), + ("Could not set source caps for PAL")); + return 0; + } + } else { + // NTSC (untested) + dv1394src->frameSize = NTSC_FRAMESIZE; + GST_DEBUG + ("NTSC data [untested] - please report success/failure to <dan@f3c.com>"); + if (gst_pad_try_set_caps (dv1394src->srcpad, + gst_caps_new_simple ("video/dv", "format", G_TYPE_STRING, + "NTSC", NULL)) <= 0) { + GST_ELEMENT_ERROR (dv1394src, CORE, NEGOTIATION, (NULL), + ("Could not set source caps for NTSC")); + return 0; + } + } + dv1394src->negotiated = TRUE; + } + // drop last frame when not complete + if (!dv1394src->drop_incomplete + || dv1394src->bytesInFrame == dv1394src->frameSize) { + dv1394src->buf = dv1394src->frame; + } else { + GST_INFO_OBJECT (GST_ELEMENT (dv1394src), "incomplete frame dropped"); + } + dv1394src->frame = NULL; + + dv1394src->frameSequence++; + + if (dv1394src->frameSequence % (dv1394src->skip + + dv1394src->consecutive) < dv1394src->consecutive) { + dv1394src->frame = gst_buffer_new_and_alloc (dv1394src->frameSize); + } + dv1394src->bytesInFrame = 0; + } + + if (dv1394src->frame != NULL) { + void *data = GST_BUFFER_DATA (dv1394src->frame); + + + switch (section_type) { + case 0: /* 1 Header block */ + /* p[3] |= 0x80; // hack to force PAL data */ + memcpy (data + dif_sequence * 150 * 80, p, 480); + break; + + case 1: /* 2 Subcode blocks */ + memcpy (data + dif_sequence * 150 * 80 + (1 + dif_block) * 80, p, + 480); + break; + + case 2: /* 3 VAUX blocks */ + memcpy (data + dif_sequence * 150 * 80 + (3 + dif_block) * 80, p, + 480); + break; + + case 3: /* 9 Audio blocks interleaved with video */ + memcpy (data + dif_sequence * 150 * 80 + (6 + dif_block * 16) * 80, p, + 480); + break; + + case 4: /* 135 Video blocks interleaved with audio */ + memcpy (data + dif_sequence * 150 * 80 + (7 + (dif_block / 15) + + dif_block) * 80, p, 480); + break; + + default: /* we can´t handle any other data */ + break; + } + dv1394src->bytesInFrame += 480; + } } return 0; } -static -int gst_dv1394src_bus_reset(raw1394handle_t handle, - unsigned int generation) { - GST_INFO_OBJECT (GST_DV1394SRC(raw1394_get_userdata(handle)),"have bus reset"); +static int +gst_dv1394src_bus_reset (raw1394handle_t handle, unsigned int generation) +{ + GST_INFO_OBJECT (GST_DV1394SRC (raw1394_get_userdata (handle)), + "have bus reset"); return 0; } static GstData * -gst_dv1394src_get (GstPad *pad) +gst_dv1394src_get (GstPad * pad) { - GstDV1394Src *dv1394src = GST_DV1394SRC (GST_PAD_PARENT(pad)); + GstDV1394Src *dv1394src = GST_DV1394SRC (GST_PAD_PARENT (pad)); dv1394src->buf = NULL; while (dv1394src->buf == NULL) - raw1394_loop_iterate(dv1394src->handle); + raw1394_loop_iterate (dv1394src->handle); - return GST_DATA(dv1394src->buf); -} + return GST_DATA (dv1394src->buf); +} static GstElementStateReturn -gst_dv1394src_change_state (GstElement *element) +gst_dv1394src_change_state (GstElement * element) { GstDV1394Src *dv1394src; @@ -348,46 +361,49 @@ gst_dv1394src_change_state (GstElement *element) switch (GST_STATE_TRANSITION (element)) { case GST_STATE_NULL_TO_READY: - if ((dv1394src->handle = raw1394_new_handle()) == NULL) { - GST_INFO_OBJECT (dv1394src,"can't get raw1394 handle"); - return GST_STATE_FAILURE; + if ((dv1394src->handle = raw1394_new_handle ()) == NULL) { + GST_INFO_OBJECT (dv1394src, "can't get raw1394 handle"); + return GST_STATE_FAILURE; } - raw1394_set_userdata(dv1394src->handle,dv1394src); - dv1394src->numcards = raw1394_get_port_info(dv1394src->handle,dv1394src->pinfo,16); + raw1394_set_userdata (dv1394src->handle, dv1394src); + dv1394src->numcards = + raw1394_get_port_info (dv1394src->handle, dv1394src->pinfo, 16); if (dv1394src->numcards == 0) { - GST_INFO_OBJECT (dv1394src,"no cards available for raw1394"); - return GST_STATE_FAILURE; + GST_INFO_OBJECT (dv1394src, "no cards available for raw1394"); + return GST_STATE_FAILURE; } if (dv1394src->pinfo[dv1394src->card].nodes <= 1) { - GST_INFO_OBJECT (dv1394src,"there are no nodes on the 1394 bus"); - return GST_STATE_FAILURE; + GST_INFO_OBJECT (dv1394src, "there are no nodes on the 1394 bus"); + return GST_STATE_FAILURE; } - if (raw1394_set_port(dv1394src->handle,dv1394src->port) < 0) { - GST_INFO_OBJECT (dv1394src,"can't set 1394 port %d",dv1394src->port); - return GST_STATE_FAILURE; + if (raw1394_set_port (dv1394src->handle, dv1394src->port) < 0) { + GST_INFO_OBJECT (dv1394src, "can't set 1394 port %d", dv1394src->port); + return GST_STATE_FAILURE; } - raw1394_set_iso_handler(dv1394src->handle,dv1394src->channel,gst_dv1394src_iso_receive); - raw1394_set_bus_reset_handler(dv1394src->handle,gst_dv1394src_bus_reset); + raw1394_set_iso_handler (dv1394src->handle, dv1394src->channel, + gst_dv1394src_iso_receive); + raw1394_set_bus_reset_handler (dv1394src->handle, + gst_dv1394src_bus_reset); dv1394src->started = FALSE; GST_DEBUG ("successfully opened up 1394 connection"); break; case GST_STATE_PAUSED_TO_PLAYING: - if (raw1394_start_iso_rcv(dv1394src->handle,dv1394src->channel) < 0) { - GST_INFO_OBJECT (dv1394src,"can't start 1394 iso receive"); - return GST_STATE_FAILURE; + if (raw1394_start_iso_rcv (dv1394src->handle, dv1394src->channel) < 0) { + GST_INFO_OBJECT (dv1394src, "can't start 1394 iso receive"); + return GST_STATE_FAILURE; } break; case GST_STATE_PLAYING_TO_PAUSED: - raw1394_stop_iso_rcv(dv1394src->handle, dv1394src->channel); + raw1394_stop_iso_rcv (dv1394src->handle, dv1394src->channel); break; case GST_STATE_READY_TO_NULL: - raw1394_destroy_handle(dv1394src->handle); + raw1394_destroy_handle (dv1394src->handle); break; default: break; } - /* if we haven't failed already, give the parent class a chance to ;-) */ + /* if we haven't failed already, give the parent class a chance to ;-) */ if (GST_ELEMENT_CLASS (parent_class)->change_state) return GST_ELEMENT_CLASS (parent_class)->change_state (element); diff --git a/ext/raw1394/gstdv1394src.h b/ext/raw1394/gstdv1394src.h index 7d384fd0..2ba4ab3d 100644 --- a/ext/raw1394/gstdv1394src.h +++ b/ext/raw1394/gstdv1394src.h @@ -27,8 +27,9 @@ #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define GST_TYPE_DV1394SRC \ @@ -42,45 +43,47 @@ extern "C" { #define GST_IS_DV1394SRC_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DV1394SRC)) -typedef struct _GstDV1394Src GstDV1394Src; -typedef struct _GstDV1394SrcClass GstDV1394SrcClass; + typedef struct _GstDV1394Src GstDV1394Src; + typedef struct _GstDV1394SrcClass GstDV1394SrcClass; -struct _GstDV1394Src { - GstElement element; + struct _GstDV1394Src + { + GstElement element; - GstPad *srcpad; + GstPad *srcpad; - // consecutive=2, skip=4 will skip 4 frames, then let 2 consecutive ones thru - gint consecutive; - gint skip; - gboolean drop_incomplete; + // consecutive=2, skip=4 will skip 4 frames, then let 2 consecutive ones thru + gint consecutive; + gint skip; + gboolean drop_incomplete; - int numcards,numports; - int card,port,channel; + int numcards, numports; + int card, port, channel; - struct raw1394_portinfo pinfo[16]; - raw1394handle_t handle; + struct raw1394_portinfo pinfo[16]; + raw1394handle_t handle; - gboolean started; - GstBuffer *buf; - - GstBuffer *frame; - guint frameSize; - guint bytesInFrame; - guint frameSequence; + gboolean started; + GstBuffer *buf; - gboolean negotiated; -}; + GstBuffer *frame; + guint frameSize; + guint bytesInFrame; + guint frameSequence; -struct _GstDV1394SrcClass { - GstElementClass parent_class; -}; + gboolean negotiated; + }; -GType gst_dv1394src_get_type(void); + struct _GstDV1394SrcClass + { + GstElementClass parent_class; + }; + + GType gst_dv1394src_get_type (void); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __GST_GST1394_H__ */ +#endif /* __GST_GST1394_H__ */ diff --git a/ext/shout2/gstshout2.c b/ext/shout2/gstshout2.c index 3b07dd7d..4a1d4a1e 100644 --- a/ext/shout2/gstshout2.c +++ b/ext/shout2/gstshout2.c @@ -29,177 +29,163 @@ static GstElementDetails shout2send_details = { "An Icecast plugin", "Sink/Network", "Sends data to an icecast server", - "Wim Taymans <wim.taymans@chello.be>\n" - "Pedro Corte-Real <typo@netcabo.pt>" + "Wim Taymans <wim.taymans@chello.be>\n" "Pedro Corte-Real <typo@netcabo.pt>" }; unsigned int audio_format = 100; /* Shout2send signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, - ARG_IP, /* the ip of the server */ - ARG_PORT, /* the encoder port number on the server */ - ARG_PASSWORD, /* the encoder password on the server */ - ARG_PUBLIC, /* is this stream public? */ - ARG_NAME, /* Name of the stream */ - ARG_DESCRIPTION, /* Description of the stream */ - ARG_GENRE, /* Genre of the stream */ - - ARG_PROTOCOL, /* Protocol to connect with */ - - ARG_MOUNT, /* mountpoint of stream (icecast only) */ - ARG_URL, /* Url of stream (I'm guessing) */ + ARG_IP, /* the ip of the server */ + ARG_PORT, /* the encoder port number on the server */ + ARG_PASSWORD, /* the encoder password on the server */ + ARG_PUBLIC, /* is this stream public? */ + ARG_NAME, /* Name of the stream */ + ARG_DESCRIPTION, /* Description of the stream */ + ARG_GENRE, /* Genre of the stream */ + + ARG_PROTOCOL, /* Protocol to connect with */ + + ARG_MOUNT, /* mountpoint of stream (icecast only) */ + ARG_URL, /* Url of stream (I'm guessing) */ }; -static GstPadTemplate* +static GstPadTemplate * sink_template_factory (void) { static GstPadTemplate *template = NULL; - + if (!template) { - template = gst_pad_template_new ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - gst_caps_new ( - "shout2send_sink", - "application/ogg", - NULL), - gst_caps_new ( - "shout2send_sink", - "audio/mpeg", - gst_props_new ( - "mpegversion", GST_PROPS_INT (1), - "layer", GST_PROPS_INT_RANGE (1, 3), - NULL - )), - NULL); + template = gst_pad_template_new ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + gst_caps_new ("shout2send_sink", + "application/ogg", + NULL), + gst_caps_new ("shout2send_sink", + "audio/mpeg", + gst_props_new ("mpegversion", GST_PROPS_INT (1), + "layer", GST_PROPS_INT_RANGE (1, 3), NULL)), NULL); } return template; } -static void gst_shout2send_class_init (GstShout2sendClass *klass); -static void gst_shout2send_base_init (GstShout2sendClass *klass); -static void gst_shout2send_init (GstShout2send *shout2send); +static void gst_shout2send_class_init (GstShout2sendClass * klass); +static void gst_shout2send_base_init (GstShout2sendClass * klass); +static void gst_shout2send_init (GstShout2send * shout2send); -static void gst_shout2send_chain (GstPad *pad, GstData *_data); -static GstPadLinkReturn gst_shout2send_connect (GstPad *pad, GstCaps *caps); +static void gst_shout2send_chain (GstPad * pad, GstData * _data); +static GstPadLinkReturn gst_shout2send_connect (GstPad * pad, GstCaps * caps); -static void gst_shout2send_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); -static void gst_shout2send_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); +static void gst_shout2send_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_shout2send_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); -static GstElementStateReturn gst_shout2send_change_state (GstElement *element); +static GstElementStateReturn gst_shout2send_change_state (GstElement * element); static GstElementClass *parent_class = NULL; + /*static guint gst_shout2send_signals[LAST_SIGNAL] = { 0 }; */ #define GST_TYPE_SHOUT_PROTOCOL (gst_shout2send_protocol_get_type()) static GType -gst_shout2send_protocol_get_type (void) +gst_shout2send_protocol_get_type (void) { static GType shout2send_protocol_type = 0; static GEnumValue shout2send_protocol[] = { - { SHOUT2SEND_PROTOCOL_ICE, "1", "Ice Protocol"}, - { SHOUT2SEND_PROTOCOL_XAUDIOCAST, "2", "Xaudiocast Protocol (icecast 1.3.x)"}, - { SHOUT2SEND_PROTOCOL_ICY, "3", "Icy Protocol (ShoutCast)"}, - { SHOUT2SEND_PROTOCOL_HTTP, "4", "Http Protocol (icecast 2.x)"}, + {SHOUT2SEND_PROTOCOL_ICE, "1", "Ice Protocol"}, + {SHOUT2SEND_PROTOCOL_XAUDIOCAST, "2", + "Xaudiocast Protocol (icecast 1.3.x)"}, + {SHOUT2SEND_PROTOCOL_ICY, "3", "Icy Protocol (ShoutCast)"}, + {SHOUT2SEND_PROTOCOL_HTTP, "4", "Http Protocol (icecast 2.x)"}, {0, NULL, NULL}, }; if (!shout2send_protocol_type) { - shout2send_protocol_type = g_enum_register_static ("GstShout2SendProtocol", shout2send_protocol); + shout2send_protocol_type = + g_enum_register_static ("GstShout2SendProtocol", shout2send_protocol); } return shout2send_protocol_type; } GType -gst_shout2send_get_type(void) +gst_shout2send_get_type (void) { static GType shout2send_type = 0; if (!shout2send_type) { static const GTypeInfo shout2send_info = { - sizeof(GstShout2sendClass), - (GBaseInitFunc)gst_shout2send_base_init, + sizeof (GstShout2sendClass), + (GBaseInitFunc) gst_shout2send_base_init, NULL, - (GClassInitFunc)gst_shout2send_class_init, + (GClassInitFunc) gst_shout2send_class_init, NULL, NULL, - sizeof(GstShout2send), + sizeof (GstShout2send), 0, - (GInstanceInitFunc)gst_shout2send_init, + (GInstanceInitFunc) gst_shout2send_init, }; - shout2send_type = g_type_register_static(GST_TYPE_ELEMENT, "GstShout2send", &shout2send_info, 0); + shout2send_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstShout2send", + &shout2send_info, 0); } return shout2send_type; } static void -gst_shout2send_base_init (GstShout2sendClass *klass) +gst_shout2send_base_init (GstShout2sendClass * klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - gst_element_class_add_pad_template (element_class, sink_template_factory()); + gst_element_class_add_pad_template (element_class, sink_template_factory ()); gst_element_class_set_details (element_class, &shout2send_details); } static void -gst_shout2send_class_init (GstShout2sendClass *klass) +gst_shout2send_class_init (GstShout2sendClass * 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); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_IP, - g_param_spec_string("ip","ip","ip", - NULL, G_PARAM_READWRITE)); /* CHECKME */ - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_PORT, - g_param_spec_int("port","port","port", - 1,G_MAXUSHORT,8000,G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_IP, g_param_spec_string ("ip", "ip", "ip", NULL, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PORT, g_param_spec_int ("port", "port", "port", 1, G_MAXUSHORT, 8000, G_PARAM_READWRITE)); /* CHECKME */ - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_PASSWORD, - g_param_spec_string("password","password","password", - NULL, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PASSWORD, g_param_spec_string ("password", "password", "password", NULL, G_PARAM_READWRITE)); /* CHECKME */ /* metadata */ - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_NAME, - g_param_spec_string("name","name","name", - NULL, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NAME, g_param_spec_string ("name", "name", "name", NULL, G_PARAM_READWRITE)); /* CHECKME */ - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_DESCRIPTION, - g_param_spec_string("description","description","description", - NULL, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DESCRIPTION, g_param_spec_string ("description", "description", "description", NULL, G_PARAM_READWRITE)); /* CHECKME */ - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_GENRE, - g_param_spec_string("genre","genre","genre", - NULL, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_GENRE, g_param_spec_string ("genre", "genre", "genre", NULL, G_PARAM_READWRITE)); /* CHECKME */ g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PROTOCOL, - g_param_spec_enum ("protocol", "protocol", "Connection Protocol to use", - GST_TYPE_SHOUT_PROTOCOL, SHOUT2SEND_PROTOCOL_HTTP, G_PARAM_READWRITE)); + g_param_spec_enum ("protocol", "protocol", "Connection Protocol to use", + GST_TYPE_SHOUT_PROTOCOL, SHOUT2SEND_PROTOCOL_HTTP, + G_PARAM_READWRITE)); /* icecast only */ - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_MOUNT, - g_param_spec_string("mount","mount","mount", - NULL, G_PARAM_READWRITE)); /* CHECKME */ + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MOUNT, g_param_spec_string ("mount", "mount", "mount", NULL, G_PARAM_READWRITE)); /* CHECKME */ + + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_URL, g_param_spec_string ("url", "url", "url", NULL, G_PARAM_READWRITE)); /* CHECKME */ + - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_URL, - g_param_spec_string("url","url","url", - NULL, G_PARAM_READWRITE)); /* CHECKME */ - - gobject_class->set_property = gst_shout2send_set_property; gobject_class->get_property = gst_shout2send_get_property; @@ -207,11 +193,12 @@ gst_shout2send_class_init (GstShout2sendClass *klass) } static void -gst_shout2send_init (GstShout2send *shout2send) +gst_shout2send_init (GstShout2send * shout2send) { - shout2send->sinkpad = gst_pad_new_from_template (sink_template_factory (), "sink"); - gst_element_add_pad(GST_ELEMENT(shout2send),shout2send->sinkpad); - gst_pad_set_chain_function(shout2send->sinkpad,gst_shout2send_chain); + shout2send->sinkpad = + gst_pad_new_from_template (sink_template_factory (), "sink"); + gst_element_add_pad (GST_ELEMENT (shout2send), shout2send->sinkpad); + gst_pad_set_chain_function (shout2send->sinkpad, gst_shout2send_chain); gst_pad_set_link_function (shout2send->sinkpad, gst_shout2send_connect); @@ -227,15 +214,15 @@ gst_shout2send_init (GstShout2send *shout2send) } static void -gst_shout2send_chain (GstPad *pad, GstData *_data) +gst_shout2send_chain (GstPad * pad, GstData * _data) { GstBuffer *buf = GST_BUFFER (_data); GstShout2send *shout2send; glong ret; - g_return_if_fail(pad != NULL); - g_return_if_fail(GST_IS_PAD(pad)); - g_return_if_fail(buf != NULL); + g_return_if_fail (pad != NULL); + g_return_if_fail (GST_IS_PAD (pad)); + g_return_if_fail (buf != NULL); shout2send = GST_SHOUT2SEND (GST_OBJECT_PARENT (pad)); @@ -243,9 +230,9 @@ gst_shout2send_chain (GstPad *pad, GstData *_data) g_return_if_fail (GST_IS_SHOUT2SEND (shout2send)); ret = shout_send (shout2send->conn, GST_BUFFER_DATA (buf), - GST_BUFFER_SIZE (buf)); + GST_BUFFER_SIZE (buf)); if (ret != SHOUTERR_SUCCESS) { - g_warning ("send error: %s...\n", shout_get_error(shout2send->conn)); + g_warning ("send error: %s...\n", shout_get_error (shout2send->conn)); } shout_sync (shout2send->conn); @@ -254,147 +241,145 @@ gst_shout2send_chain (GstPad *pad, GstData *_data) } static void -gst_shout2send_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +gst_shout2send_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) { GstShout2send *shout2send; /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_SHOUT2SEND(object)); - shout2send = GST_SHOUT2SEND(object); + g_return_if_fail (GST_IS_SHOUT2SEND (object)); + shout2send = GST_SHOUT2SEND (object); switch (prop_id) { - case ARG_IP: - if (shout2send->ip) - g_free (shout2send->ip); - shout2send->ip = g_strdup (g_value_get_string (value)); - break; - - case ARG_PORT: - shout2send->port = g_value_get_int (value); - break; - - case ARG_PASSWORD: - if (shout2send->password) - g_free (shout2send->password); - shout2send->password = g_strdup (g_value_get_string (value)); - break; - - case ARG_NAME: /* Name of the stream */ - if (shout2send->name) - g_free (shout2send->name); - shout2send->name = g_strdup (g_value_get_string (value)); - break; - - case ARG_DESCRIPTION: /* Description of the stream */ - if (shout2send->description) - g_free (shout2send->description); - shout2send->description = g_strdup (g_value_get_string (value)); - break; - - case ARG_GENRE: /* Genre of the stream */ - if (shout2send->genre) - g_free (shout2send->genre); - shout2send->genre = g_strdup (g_value_get_string (value)); - break; - - case ARG_PROTOCOL: /* protocol to connect with */ - shout2send->protocol = g_value_get_enum (value); - break; - - case ARG_MOUNT: /* mountpoint of stream (icecast only) */ - if (shout2send->mount) - g_free (shout2send->mount); - shout2send->mount = g_strdup (g_value_get_string (value)); - break; - - case ARG_URL: /* Url of the stream (I'm guessing) */ - if (shout2send->url) - g_free (shout2send->url); - shout2send->url = g_strdup (g_value_get_string (value)); - break; - - default: - break; + case ARG_IP: + if (shout2send->ip) + g_free (shout2send->ip); + shout2send->ip = g_strdup (g_value_get_string (value)); + break; + + case ARG_PORT: + shout2send->port = g_value_get_int (value); + break; + + case ARG_PASSWORD: + if (shout2send->password) + g_free (shout2send->password); + shout2send->password = g_strdup (g_value_get_string (value)); + break; + + case ARG_NAME: /* Name of the stream */ + if (shout2send->name) + g_free (shout2send->name); + shout2send->name = g_strdup (g_value_get_string (value)); + break; + + case ARG_DESCRIPTION: /* Description of the stream */ + if (shout2send->description) + g_free (shout2send->description); + shout2send->description = g_strdup (g_value_get_string (value)); + break; + + case ARG_GENRE: /* Genre of the stream */ + if (shout2send->genre) + g_free (shout2send->genre); + shout2send->genre = g_strdup (g_value_get_string (value)); + break; + + case ARG_PROTOCOL: /* protocol to connect with */ + shout2send->protocol = g_value_get_enum (value); + break; + + case ARG_MOUNT: /* mountpoint of stream (icecast only) */ + if (shout2send->mount) + g_free (shout2send->mount); + shout2send->mount = g_strdup (g_value_get_string (value)); + break; + + case ARG_URL: /* Url of the stream (I'm guessing) */ + if (shout2send->url) + g_free (shout2send->url); + shout2send->url = g_strdup (g_value_get_string (value)); + break; + + default: + break; } } static void -gst_shout2send_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +gst_shout2send_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { GstShout2send *shout2send; /* it's not null if we got it, but it might not be ours */ - g_return_if_fail(GST_IS_SHOUT2SEND(object)); - shout2send = GST_SHOUT2SEND(object); + g_return_if_fail (GST_IS_SHOUT2SEND (object)); + shout2send = GST_SHOUT2SEND (object); switch (prop_id) { - - case ARG_IP: - g_value_set_string (value, shout2send->ip); - break; - case ARG_PORT: - g_value_set_int (value, shout2send->port); - break; - case ARG_PASSWORD: - g_value_set_string (value, shout2send->password); - break; - - case ARG_NAME: /* Name of the stream */ - g_value_set_string (value, shout2send->name); - break; - - case ARG_DESCRIPTION: /* Description of the stream */ - g_value_set_string (value, shout2send->description); - break; - - case ARG_GENRE: /* Genre of the stream */ - g_value_set_string (value, shout2send->genre); - break; - - case ARG_PROTOCOL: /* protocol to connect with */ - g_value_set_enum (value, shout2send->protocol); - break; - - case ARG_MOUNT: /* mountpoint of stream (icecast only) */ - g_value_set_string (value, shout2send->mount); - break; - - case ARG_URL: /* Url of stream (I'm guessing) */ - g_value_set_string (value, shout2send->url); - break; - - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; + + case ARG_IP: + g_value_set_string (value, shout2send->ip); + break; + case ARG_PORT: + g_value_set_int (value, shout2send->port); + break; + case ARG_PASSWORD: + g_value_set_string (value, shout2send->password); + break; + + case ARG_NAME: /* Name of the stream */ + g_value_set_string (value, shout2send->name); + break; + + case ARG_DESCRIPTION: /* Description of the stream */ + g_value_set_string (value, shout2send->description); + break; + + case ARG_GENRE: /* Genre of the stream */ + g_value_set_string (value, shout2send->genre); + break; + + case ARG_PROTOCOL: /* protocol to connect with */ + g_value_set_enum (value, shout2send->protocol); + break; + + case ARG_MOUNT: /* mountpoint of stream (icecast only) */ + g_value_set_string (value, shout2send->mount); + break; + + case ARG_URL: /* Url of stream (I'm guessing) */ + g_value_set_string (value, shout2send->url); + break; + + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; } } static GstPadLinkReturn -gst_shout2send_connect (GstPad *pad, GstCaps *caps) - +gst_shout2send_connect (GstPad * pad, GstCaps * caps) { - - if (!strcmp(gst_caps_get_mime (caps), "audio/mpeg")) - { - audio_format = SHOUT_FORMAT_MP3; - return GST_PAD_LINK_OK; - } - - if (!strcmp(gst_caps_get_mime (caps), "application/ogg")) - { - audio_format = SHOUT_FORMAT_VORBIS; - return GST_PAD_LINK_OK; - } - else { + + if (!strcmp (gst_caps_get_mime (caps), "audio/mpeg")) { + audio_format = SHOUT_FORMAT_MP3; + return GST_PAD_LINK_OK; + } + + if (!strcmp (gst_caps_get_mime (caps), "application/ogg")) { + audio_format = SHOUT_FORMAT_VORBIS; + return GST_PAD_LINK_OK; + } else { return GST_PAD_LINK_REFUSED; } - + } static GstElementStateReturn -gst_shout2send_change_state (GstElement *element) +gst_shout2send_change_state (GstElement * element) { GstShout2send *shout2send; @@ -405,144 +390,147 @@ gst_shout2send_change_state (GstElement *element) g_return_val_if_fail (GST_IS_SHOUT2SEND (element), GST_STATE_FAILURE); - shout2send = GST_SHOUT2SEND(element); + shout2send = GST_SHOUT2SEND (element); GST_DEBUG ("state pending %d", GST_STATE_PENDING (element)); /* if going down into NULL state, close the file if it's open */ switch (GST_STATE_TRANSITION (element)) { - case GST_STATE_NULL_TO_READY: - shout2send->conn = shout_new(); - - switch (shout2send->protocol) { - case SHOUT2SEND_PROTOCOL_ICE: - proto = SHOUT_PROTOCOL_ICE; - break; - case SHOUT2SEND_PROTOCOL_XAUDIOCAST: - proto = SHOUT_PROTOCOL_XAUDIOCAST; - break; - case SHOUT2SEND_PROTOCOL_ICY: - proto = SHOUT_PROTOCOL_ICY; - break; - case SHOUT2SEND_PROTOCOL_HTTP: - proto = SHOUT_PROTOCOL_HTTP; - break; - } - - if (shout_set_protocol(shout2send->conn, proto) != SHOUTERR_SUCCESS) - { - g_error ("Error setting protocol: %s\n", shout_get_error(shout2send->conn)); - } - - /* --- FIXME: shout requires an ip, and fails if it is given a host. */ - /* may want to put convert_to_ip(shout2send->ip) here */ - - - if (shout_set_host(shout2send->conn, shout2send->ip) != SHOUTERR_SUCCESS) - { - g_error ("Error setting host: %s\n", shout_get_error(shout2send->conn)); - } - /* --- */ - - if (shout_set_port(shout2send->conn, shout2send->port) != SHOUTERR_SUCCESS) - { - g_error ("Error setting port: %s\n", shout_get_error(shout2send->conn)); - } - - if(shout_set_password(shout2send->conn, shout2send->password) != SHOUTERR_SUCCESS) - { - g_error ("Error setting password: %s\n", shout_get_error(shout2send->conn)); - } - - if (shout_set_name(shout2send->conn, shout2send->name) != SHOUTERR_SUCCESS) - { - g_error ("Error setting name: %s\n", shout_get_error(shout2send->conn)); - } - - if (shout_set_description(shout2send->conn, shout2send->description) != SHOUTERR_SUCCESS) - { - g_error ("Error setting name: %s\n", shout_get_error(shout2send->conn)); - } - - if (shout_set_genre(shout2send->conn, shout2send->genre) != SHOUTERR_SUCCESS) - { - g_error ("Error setting name: %s\n", shout_get_error(shout2send->conn)); - } - - if (shout_set_mount(shout2send->conn, shout2send->mount) != SHOUTERR_SUCCESS) - { - g_error ("Error setting mount point: %s\n", shout_get_error(shout2send->conn)); - } - - if (shout_set_user(shout2send->conn, "source") != SHOUTERR_SUCCESS) - { - g_error ("Error setting user: %s\n", shout_get_error(shout2send->conn)); - } - - gst_version(&major,&minor,µ); - - version_string = g_strdup_printf("GStreamer %d.%d.%d", major,minor,micro); - - if (shout_set_agent(shout2send->conn, version_string) != SHOUTERR_SUCCESS) - { - g_error ("Error setting agent: %s\n", shout_get_error(shout2send->conn)); - } - - g_free (version_string); - - - - break; - case GST_STATE_READY_TO_PAUSED: - - /* This sets the format acording to the capabilities of what - we are being given as input. */ - - if (shout_set_format(shout2send->conn, audio_format) != SHOUTERR_SUCCESS) - { - g_error ("Error setting connection format: %s\n", shout_get_error(shout2send->conn)); - } - - if (shout_open (shout2send->conn) == SHOUTERR_SUCCESS) { - g_print ("connected to server...\n"); - } - else { - g_warning ("Couldn't connect to server: %s", shout_get_error(shout2send->conn)); + case GST_STATE_NULL_TO_READY: + shout2send->conn = shout_new (); + + switch (shout2send->protocol) { + case SHOUT2SEND_PROTOCOL_ICE: + proto = SHOUT_PROTOCOL_ICE; + break; + case SHOUT2SEND_PROTOCOL_XAUDIOCAST: + proto = SHOUT_PROTOCOL_XAUDIOCAST; + break; + case SHOUT2SEND_PROTOCOL_ICY: + proto = SHOUT_PROTOCOL_ICY; + break; + case SHOUT2SEND_PROTOCOL_HTTP: + proto = SHOUT_PROTOCOL_HTTP; + break; + } + + if (shout_set_protocol (shout2send->conn, proto) != SHOUTERR_SUCCESS) { + g_error ("Error setting protocol: %s\n", + shout_get_error (shout2send->conn)); + } + + /* --- FIXME: shout requires an ip, and fails if it is given a host. */ + /* may want to put convert_to_ip(shout2send->ip) here */ + + + if (shout_set_host (shout2send->conn, shout2send->ip) != SHOUTERR_SUCCESS) { + g_error ("Error setting host: %s\n", + shout_get_error (shout2send->conn)); + } + /* --- */ + + if (shout_set_port (shout2send->conn, + shout2send->port) != SHOUTERR_SUCCESS) { + g_error ("Error setting port: %s\n", + shout_get_error (shout2send->conn)); + } + + if (shout_set_password (shout2send->conn, + shout2send->password) != SHOUTERR_SUCCESS) { + g_error ("Error setting password: %s\n", + shout_get_error (shout2send->conn)); + } + + if (shout_set_name (shout2send->conn, + shout2send->name) != SHOUTERR_SUCCESS) { + g_error ("Error setting name: %s\n", + shout_get_error (shout2send->conn)); + } + + if (shout_set_description (shout2send->conn, + shout2send->description) != SHOUTERR_SUCCESS) { + g_error ("Error setting name: %s\n", + shout_get_error (shout2send->conn)); + } + + if (shout_set_genre (shout2send->conn, + shout2send->genre) != SHOUTERR_SUCCESS) { + g_error ("Error setting name: %s\n", + shout_get_error (shout2send->conn)); + } + + if (shout_set_mount (shout2send->conn, + shout2send->mount) != SHOUTERR_SUCCESS) { + g_error ("Error setting mount point: %s\n", + shout_get_error (shout2send->conn)); + } + + if (shout_set_user (shout2send->conn, "source") != SHOUTERR_SUCCESS) { + g_error ("Error setting user: %s\n", + shout_get_error (shout2send->conn)); + } + + gst_version (&major, &minor, µ); + + version_string = + g_strdup_printf ("GStreamer %d.%d.%d", major, minor, micro); + + if (shout_set_agent (shout2send->conn, + version_string) != SHOUTERR_SUCCESS) { + g_error ("Error setting agent: %s\n", + shout_get_error (shout2send->conn)); + } + + g_free (version_string); + + + + break; + case GST_STATE_READY_TO_PAUSED: + + /* This sets the format acording to the capabilities of what + we are being given as input. */ + + if (shout_set_format (shout2send->conn, audio_format) != SHOUTERR_SUCCESS) { + g_error ("Error setting connection format: %s\n", + shout_get_error (shout2send->conn)); + } + + if (shout_open (shout2send->conn) == SHOUTERR_SUCCESS) { + g_print ("connected to server...\n"); + } else { + g_warning ("Couldn't connect to server: %s", + shout_get_error (shout2send->conn)); + shout_close (shout2send->conn); + shout_free (shout2send->conn); + return GST_STATE_FAILURE; + } + break; + case GST_STATE_PAUSED_TO_READY: shout_close (shout2send->conn); shout_free (shout2send->conn); - return GST_STATE_FAILURE; - } - break; - case GST_STATE_PAUSED_TO_READY: - shout_close (shout2send->conn); - shout_free (shout2send->conn); - break; - default: - break; + break; + default: + break; } - + /* if we haven't failed already, give the parent class a chance to ;-) */ if (GST_ELEMENT_CLASS (parent_class)->change_state) return GST_ELEMENT_CLASS (parent_class)->change_state (element); - + return GST_STATE_SUCCESS; } static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { return gst_element_register (plugin, "shout2send", GST_RANK_NONE, - GST_TYPE_SHOUT2SEND); + GST_TYPE_SHOUT2SEND); } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "shout2send", - "Sends data to an icecast server using libshout2", - plugin_init, - VERSION, - "LGPL", - "libshout2", - "http://www.icecast.org/download.html" -) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "shout2send", + "Sends data to an icecast server using libshout2", + plugin_init, + VERSION, "LGPL", "libshout2", "http://www.icecast.org/download.html") diff --git a/ext/shout2/gstshout2.h b/ext/shout2/gstshout2.h index 70631298..62ff44b9 100644 --- a/ext/shout2/gstshout2.h +++ b/ext/shout2/gstshout2.h @@ -25,47 +25,51 @@ #include <shout/shout.h> #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ /* Protocol type enum */ -typedef enum { - SHOUT2SEND_PROTOCOL_ICE = 1, - SHOUT2SEND_PROTOCOL_XAUDIOCAST, - SHOUT2SEND_PROTOCOL_ICY, - SHOUT2SEND_PROTOCOL_HTTP -} GstShout2SendProtocol; + typedef enum + { + SHOUT2SEND_PROTOCOL_ICE = 1, + SHOUT2SEND_PROTOCOL_XAUDIOCAST, + SHOUT2SEND_PROTOCOL_ICY, + SHOUT2SEND_PROTOCOL_HTTP + } GstShout2SendProtocol; /* Definition of structure storing data for this element. */ -typedef struct _GstShout2send GstShout2send; -struct _GstShout2send { - GstElement element; + typedef struct _GstShout2send GstShout2send; + struct _GstShout2send + { + GstElement element; - GstPad *sinkpad,*srcpad; + GstPad *sinkpad, *srcpad; - GstShout2SendProtocol protocol; + GstShout2SendProtocol protocol; - shout_t *conn; + shout_t *conn; - gchar *ip; - guint port; - gchar *password; - gchar *name; - gchar *description; - gchar *genre; - gchar *mount; - gchar *url; + gchar *ip; + guint port; + gchar *password; + gchar *name; + gchar *description; + gchar *genre; + gchar *mount; + gchar *url; -}; + }; /* Standard definition defining a class for this element. */ -typedef struct _GstShout2sendClass GstShout2sendClass; -struct _GstShout2sendClass { - GstElementClass parent_class; -}; + typedef struct _GstShout2sendClass GstShout2sendClass; + struct _GstShout2sendClass + { + GstElementClass parent_class; + }; /* Standard macros for defining types for this element. */ #define GST_TYPE_SHOUT2SEND \ @@ -80,12 +84,12 @@ struct _GstShout2sendClass { (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SHOUT2SEND)) /* Standard function returning type information. */ -GType gst_shout2send_get_type(void); + GType gst_shout2send_get_type (void); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __GST_SHOUT2SEND_H__ */ +#endif /* __GST_SHOUT2SEND_H__ */ diff --git a/ext/speex/gstspeex.c b/ext/speex/gstspeex.c index df2f230c..0b0de0bf 100644 --- a/ext/speex/gstspeex.c +++ b/ext/speex/gstspeex.c @@ -24,24 +24,21 @@ #include "gstspeexenc.h" static gboolean -plugin_init (GstPlugin *plugin) +plugin_init (GstPlugin * plugin) { - if (!gst_element_register (plugin, "speexenc", GST_RANK_NONE, GST_TYPE_SPEEXENC)) + if (!gst_element_register (plugin, "speexenc", GST_RANK_NONE, + GST_TYPE_SPEEXENC)) return FALSE; - if (!gst_element_register (plugin, "speexdec", GST_RANK_PRIMARY, GST_TYPE_SPEEXDEC)) + if (!gst_element_register (plugin, "speexdec", GST_RANK_PRIMARY, + GST_TYPE_SPEEXDEC)) return FALSE; - + return TRUE; } -GST_PLUGIN_DEFINE ( - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "speex", - "Speex plugin library", - plugin_init, - VERSION, - "LGPL", - GST_PACKAGE, - GST_ORIGIN) +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "speex", + "Speex plugin library", + plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN) diff --git a/ext/speex/gstspeexdec.c b/ext/speex/gstspeexdec.c index a5ab788e..364ae669 100644 --- a/ext/speex/gstspeexdec.c +++ b/ext/speex/gstspeexdec.c @@ -36,72 +36,72 @@ GstElementDetails gst_speexdec_details = { }; /* SpeexDec signals and args */ -enum { +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, /* FILL ME */ }; -static void gst_speexdec_base_init (gpointer g_class); -static void gst_speexdec_class_init (GstSpeexDec *klass); -static void gst_speexdec_init (GstSpeexDec *speexdec); +static void gst_speexdec_base_init (gpointer g_class); +static void gst_speexdec_class_init (GstSpeexDec * klass); +static void gst_speexdec_init (GstSpeexDec * speexdec); -static void gst_speexdec_chain (GstPad *pad, GstData *_data); -static GstPadLinkReturn gst_speexdec_sinkconnect (GstPad *pad, const GstCaps *caps); +static void gst_speexdec_chain (GstPad * pad, GstData * _data); +static GstPadLinkReturn gst_speexdec_sinkconnect (GstPad * pad, + const GstCaps * caps); static GstElementClass *parent_class = NULL; + /*static guint gst_speexdec_signals[LAST_SIGNAL] = { 0 }; */ GType -gst_speexdec_get_type(void) { +gst_speexdec_get_type (void) +{ static GType speexdec_type = 0; if (!speexdec_type) { static const GTypeInfo speexdec_info = { - sizeof(GstSpeexDecClass), + sizeof (GstSpeexDecClass), gst_speexdec_base_init, NULL, - (GClassInitFunc)gst_speexdec_class_init, + (GClassInitFunc) gst_speexdec_class_init, NULL, NULL, - sizeof(GstSpeexDec), + sizeof (GstSpeexDec), 0, - (GInstanceInitFunc)gst_speexdec_init, + (GInstanceInitFunc) gst_speexdec_init, }; - speexdec_type = g_type_register_static(GST_TYPE_ELEMENT, "GstSpeexDec", &speexdec_info, 0); + speexdec_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstSpeexDec", &speexdec_info, + 0); } return speexdec_type; } static GstStaticPadTemplate speex_sink_template = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/x-speex, " - "rate = (int) [ 1000, 48000 ], " - "channels = (int) 1" - ) -); - -static GstStaticPadTemplate speex_src_template = -GST_STATIC_PAD_TEMPLATE ( - "src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/x-raw-int, " - "endianness = (int) BYTE_ORDER, " - "signed = (boolean) true, " - "width = (int) 16, " - "depth = (int) 16, " - "rate = (int) [ 1000, 48000 ], " - "channels = (int) 1" - ) -); +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-speex, " + "rate = (int) [ 1000, 48000 ], " "channels = (int) 1") + ); + +static GstStaticPadTemplate speex_src_template = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-raw-int, " + "endianness = (int) BYTE_ORDER, " + "signed = (boolean) true, " + "width = (int) 16, " + "depth = (int) 16, " + "rate = (int) [ 1000, 48000 ], " "channels = (int) 1") + ); static void gst_speexdec_base_init (gpointer g_class) @@ -109,30 +109,31 @@ gst_speexdec_base_init (gpointer g_class) GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&speex_src_template)); + gst_static_pad_template_get (&speex_src_template)); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&speex_sink_template)); + gst_static_pad_template_get (&speex_sink_template)); gst_element_class_set_details (element_class, &gst_speexdec_details); } static void -gst_speexdec_class_init (GstSpeexDec *klass) +gst_speexdec_class_init (GstSpeexDec * klass) { GstElementClass *gstelement_class; - gstelement_class = (GstElementClass*)klass; + gstelement_class = (GstElementClass *) klass; - parent_class = g_type_class_ref(GST_TYPE_ELEMENT); + parent_class = g_type_class_ref (GST_TYPE_ELEMENT); } static void -gst_speexdec_init (GstSpeexDec *speexdec) +gst_speexdec_init (GstSpeexDec * speexdec) { GST_DEBUG ("gst_speexdec_init: initializing"); /* create the sink and src pads */ - speexdec->sinkpad = gst_pad_new_from_template (speexdec_sink_template, "sink"); + speexdec->sinkpad = + gst_pad_new_from_template (speexdec_sink_template, "sink"); gst_element_add_pad (GST_ELEMENT (speexdec), speexdec->sinkpad); gst_pad_set_chain_function (speexdec->sinkpad, gst_speexdec_chain); gst_pad_set_link_function (speexdec->sinkpad, gst_speexdec_sinkconnect); @@ -144,43 +145,40 @@ gst_speexdec_init (GstSpeexDec *speexdec) } static GstPadLinkReturn -gst_speexdec_sinkconnect (GstPad *pad, const GstCaps *caps) +gst_speexdec_sinkconnect (GstPad * pad, const GstCaps * caps) { GstSpeexDec *speexdec; gint rate; GstStructure *structure; - + speexdec = GST_SPEEXDEC (gst_pad_get_parent (pad)); structure = gst_caps_get_structure (caps, 0); - gst_structure_get_int (structure, "rate", &rate); - - if (gst_pad_set_explicit_caps (speexdec->srcpad, - gst_caps_new_simple ("audio/x-raw-int", - "endianness", G_TYPE_INT, G_BYTE_ORDER, - "signed", G_TYPE_BOOLEAN, TRUE, - "width", G_TYPE_INT, 16, - "depth", G_TYPE_INT, 16, - "rate", G_TYPE_INT, rate, - "channels", G_TYPE_INT, 1, - NULL))) - { + gst_structure_get_int (structure, "rate", &rate); + + if (gst_pad_set_explicit_caps (speexdec->srcpad, + gst_caps_new_simple ("audio/x-raw-int", + "endianness", G_TYPE_INT, G_BYTE_ORDER, + "signed", G_TYPE_BOOLEAN, TRUE, + "width", G_TYPE_INT, 16, + "depth", G_TYPE_INT, 16, + "rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, 1, NULL))) { return GST_PAD_LINK_OK; } return GST_PAD_LINK_REFUSED; } static void -gst_speexdec_chain (GstPad *pad, GstData *_data) +gst_speexdec_chain (GstPad * pad, GstData * _data) { GstBuffer *buf = GST_BUFFER (_data); GstSpeexDec *speexdec; gchar *data; guint size; - g_return_if_fail(pad != NULL); - g_return_if_fail(GST_IS_PAD(pad)); - g_return_if_fail(buf != NULL); + g_return_if_fail (pad != NULL); + g_return_if_fail (GST_IS_PAD (pad)); + g_return_if_fail (buf != NULL); /*g_return_if_fail(GST_IS_BUFFER(buf)); */ speexdec = GST_SPEEXDEC (gst_pad_get_parent (pad)); @@ -188,6 +186,5 @@ gst_speexdec_chain (GstPad *pad, GstData *_data) data = GST_BUFFER_DATA (buf); size = GST_BUFFER_SIZE (buf); - gst_buffer_unref(buf); + gst_buffer_unref (buf); } - diff --git a/ext/speex/gstspeexdec.h b/ext/speex/gstspeexdec.h index c679dc18..6723742c 100644 --- a/ext/speex/gstspeexdec.h +++ b/ext/speex/gstspeexdec.h @@ -26,8 +26,9 @@ #include <speex.h> #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define GST_TYPE_SPEEXDEC \ @@ -41,26 +42,28 @@ extern "C" { #define GST_IS_SPEEXDEC_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SPEEXDEC)) -typedef struct _GstSpeexDec GstSpeexDec; -typedef struct _GstSpeexDecClass GstSpeexDecClass; + typedef struct _GstSpeexDec GstSpeexDec; + typedef struct _GstSpeexDecClass GstSpeexDecClass; -struct _GstSpeexDec { - GstElement element; + struct _GstSpeexDec + { + GstElement element; - /* pads */ - GstPad *sinkpad,*srcpad; -}; + /* pads */ + GstPad *sinkpad, *srcpad; + }; -struct _GstSpeexDecClass { - GstElementClass parent_class; -}; + struct _GstSpeexDecClass + { + GstElementClass parent_class; + }; -GType gst_speexdec_get_type(void); + GType gst_speexdec_get_type (void); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __GST_SPEEXDEC_H__ */ +#endif /* __GST_SPEEXDEC_H__ */ diff --git a/ext/speex/gstspeexenc.c b/ext/speex/gstspeexenc.c index 1db431d3..d1b4ae39 100644 --- a/ext/speex/gstspeexenc.c +++ b/ext/speex/gstspeexenc.c @@ -36,23 +36,26 @@ GstElementDetails gst_speexenc_details = { }; /* SpeexEnc signals and args */ -enum { +enum +{ FRAME_ENCODED, /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, /* FILL ME */ }; -static void gst_speexenc_base_init (gpointer g_class); -static void gst_speexenc_class_init (GstSpeexEnc *klass); -static void gst_speexenc_init (GstSpeexEnc *speexenc); +static void gst_speexenc_base_init (gpointer g_class); +static void gst_speexenc_class_init (GstSpeexEnc * klass); +static void gst_speexenc_init (GstSpeexEnc * speexenc); -static void gst_speexenc_chain (GstPad *pad,GstData *_data); -static GstPadLinkReturn gst_speexenc_sinkconnect (GstPad *pad, const GstCaps *caps); +static void gst_speexenc_chain (GstPad * pad, GstData * _data); +static GstPadLinkReturn gst_speexenc_sinkconnect (GstPad * pad, + const GstCaps * caps); static GstElementClass *parent_class = NULL; static guint gst_speexenc_signals[LAST_SIGNAL] = { 0 }; @@ -74,42 +77,37 @@ gst_speexenc_get_type (void) 0, (GInstanceInitFunc) gst_speexenc_init, }; - speexenc_type = g_type_register_static (GST_TYPE_ELEMENT, "GstSpeexEnc", &speexenc_info, 0); + speexenc_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstSpeexEnc", &speexenc_info, + 0); } return speexenc_type; } static GstStaticPadTemplate speex_sink_template = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/x-raw-int, " - "endianness = (int) BYTE_ORDER, " - "signed = (boolean) true, " - "width = (int) 16, " - "depth = (int) 16, " - "rate = (int) [ 1000, 48000 ], " - "channels = (int) 1" - ) -); - -static GstStaticPadTemplate speex_src_template = -GST_STATIC_PAD_TEMPLATE ( - "src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/x-speex, " - "rate = (int) [ 1000, 48000 ], " - "channels = (int) 1" - ) -); +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-raw-int, " + "endianness = (int) BYTE_ORDER, " + "signed = (boolean) true, " + "width = (int) 16, " + "depth = (int) 16, " + "rate = (int) [ 1000, 48000 ], " "channels = (int) 1") + ); + +static GstStaticPadTemplate speex_src_template = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-speex, " + "rate = (int) [ 1000, 48000 ], " "channels = (int) 1") + ); static void gst_speexenc_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - + gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&speex_sink_template)); gst_element_class_add_pad_template (element_class, @@ -119,28 +117,29 @@ gst_speexenc_base_init (gpointer g_class) } static void -gst_speexenc_class_init (GstSpeexEnc *klass) +gst_speexenc_class_init (GstSpeexEnc * 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); gst_speexenc_signals[FRAME_ENCODED] = - g_signal_new ("frame-encoded", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstSpeexEncClass, frame_encoded), NULL, NULL, - g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + g_signal_new ("frame-encoded", G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstSpeexEncClass, frame_encoded), + NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); } static void -gst_speexenc_init (GstSpeexEnc *speexenc) +gst_speexenc_init (GstSpeexEnc * speexenc) { /* create the sink and src pads */ - speexenc->sinkpad = gst_pad_new_from_template (speexenc_sink_template, "sink"); + speexenc->sinkpad = + gst_pad_new_from_template (speexenc_sink_template, "sink"); gst_element_add_pad (GST_ELEMENT (speexenc), speexenc->sinkpad); gst_pad_set_chain_function (speexenc->sinkpad, gst_speexenc_chain); gst_pad_set_link_function (speexenc->sinkpad, gst_speexenc_sinkconnect); @@ -148,7 +147,7 @@ gst_speexenc_init (GstSpeexEnc *speexenc) speexenc->srcpad = gst_pad_new_from_template (speexenc_src_template, "src"); gst_element_add_pad (GST_ELEMENT (speexenc), speexenc->srcpad); - speex_bits_init(&speexenc->bits); + speex_bits_init (&speexenc->bits); speexenc->mode = &speex_nb_mode; speexenc->bufsize = 0; speexenc->packet_count = 0; @@ -156,7 +155,7 @@ gst_speexenc_init (GstSpeexEnc *speexenc) } static GstPadLinkReturn -gst_speexenc_sinkconnect (GstPad *pad, const GstCaps *caps) +gst_speexenc_sinkconnect (GstPad * pad, const GstCaps * caps) { GstSpeexEnc *speexenc; GstStructure *structure; @@ -166,16 +165,15 @@ gst_speexenc_sinkconnect (GstPad *pad, const GstCaps *caps) structure = gst_caps_get_structure (caps, 0); gst_structure_get_int (structure, "rate", &speexenc->rate); if (gst_pad_try_set_caps (speexenc->srcpad, - gst_caps_new_simple ("audio/x-speex", - "rate", G_TYPE_INT, speexenc->rate, - "channels", G_TYPE_INT, 1, - NULL))) - { - speex_init_header(&speexenc->header, speexenc->rate, 1, speexenc->mode); + gst_caps_new_simple ("audio/x-speex", + "rate", G_TYPE_INT, speexenc->rate, + "channels", G_TYPE_INT, 1, NULL))) { + speex_init_header (&speexenc->header, speexenc->rate, 1, speexenc->mode); speexenc->header.frames_per_packet = speexenc->n_packets; - speexenc->state = speex_encoder_init(speexenc->mode); - speex_encoder_ctl(speexenc->state, SPEEX_GET_FRAME_SIZE, &speexenc->frame_size); + speexenc->state = speex_encoder_init (speexenc->mode); + speex_encoder_ctl (speexenc->state, SPEEX_GET_FRAME_SIZE, + &speexenc->frame_size); return GST_PAD_LINK_OK; } @@ -184,7 +182,7 @@ gst_speexenc_sinkconnect (GstPad *pad, const GstCaps *caps) } static void -gst_speexenc_chain (GstPad *pad, GstData *_data) +gst_speexenc_chain (GstPad * pad, GstData * _data) { GstBuffer *buf = GST_BUFFER (_data); GstSpeexEnc *speexenc; @@ -201,22 +199,20 @@ gst_speexenc_chain (GstPad *pad, GstData *_data) g_return_if_fail (buf != NULL); speexenc = GST_SPEEXENC (GST_OBJECT_PARENT (pad)); - + if (!GST_PAD_CAPS (speexenc->srcpad)) { if (!gst_pad_try_set_caps (speexenc->srcpad, - gst_caps_new_simple ("audio/x-speex", - "rate", G_TYPE_INT, speexenc->rate, - "channels", G_TYPE_INT, 1, - NULL))) - { + gst_caps_new_simple ("audio/x-speex", + "rate", G_TYPE_INT, speexenc->rate, + "channels", G_TYPE_INT, 1, NULL))) { GST_ELEMENT_ERROR (speexenc, CORE, NEGOTIATION, (NULL), (NULL)); return; } } if (speexenc->packet_count == 0) { - header_data = speex_header_to_packet(&speexenc->header, &size); + header_data = speex_header_to_packet (&speexenc->header, &size); outbuf = gst_buffer_new (); GST_BUFFER_DATA (outbuf) = header_data; @@ -231,7 +227,8 @@ gst_speexenc_chain (GstPad *pad, GstData *_data) frame_size = speexenc->frame_size; if (speexenc->bufsize && (speexenc->bufsize + size >= frame_size)) { - memcpy (speexenc->buffer + speexenc->bufsize, data, (frame_size - speexenc->bufsize) * sizeof (gint16)); + memcpy (speexenc->buffer + speexenc->bufsize, data, + (frame_size - speexenc->bufsize) * sizeof (gint16)); for (i = 0; i < frame_size; i++) input[i] = speexenc->buffer[i]; @@ -243,10 +240,10 @@ gst_speexenc_chain (GstPad *pad, GstData *_data) GstBuffer *outbuf; outbuf = gst_buffer_new_and_alloc (frame_size * speexenc->n_packets); - GST_BUFFER_SIZE (outbuf) = speex_bits_write(&speexenc->bits, - GST_BUFFER_DATA (outbuf), GST_BUFFER_SIZE (outbuf)); + GST_BUFFER_SIZE (outbuf) = speex_bits_write (&speexenc->bits, + GST_BUFFER_DATA (outbuf), GST_BUFFER_SIZE (outbuf)); GST_BUFFER_TIMESTAMP (outbuf) = speexenc->next_ts; - speex_bits_reset(&speexenc->bits); + speex_bits_reset (&speexenc->bits); gst_pad_push (speexenc->srcpad, GST_DATA (outbuf)); speexenc->next_ts += frame_size * GST_SECOND / speexenc->rate; @@ -269,10 +266,10 @@ gst_speexenc_chain (GstPad *pad, GstData *_data) GstBuffer *outbuf; outbuf = gst_buffer_new_and_alloc (frame_size * speexenc->n_packets); - GST_BUFFER_SIZE (outbuf) = speex_bits_write(&speexenc->bits, - GST_BUFFER_DATA (outbuf), GST_BUFFER_SIZE (outbuf)); + GST_BUFFER_SIZE (outbuf) = speex_bits_write (&speexenc->bits, + GST_BUFFER_DATA (outbuf), GST_BUFFER_SIZE (outbuf)); GST_BUFFER_TIMESTAMP (outbuf) = speexenc->next_ts; - speex_bits_reset(&speexenc->bits); + speex_bits_reset (&speexenc->bits); gst_pad_push (speexenc->srcpad, GST_DATA (outbuf)); speexenc->next_ts += frame_size * GST_SECOND / speexenc->rate; @@ -286,6 +283,6 @@ gst_speexenc_chain (GstPad *pad, GstData *_data) memcpy (speexenc->buffer + speexenc->bufsize, data, size * sizeof (gint16)); speexenc->bufsize += size; } - - gst_buffer_unref(buf); + + gst_buffer_unref (buf); } diff --git a/ext/speex/gstspeexenc.h b/ext/speex/gstspeexenc.h index 4677f6a1..4da1e787 100644 --- a/ext/speex/gstspeexenc.h +++ b/ext/speex/gstspeexenc.h @@ -28,8 +28,9 @@ #include <speex_header.h> #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif /* __cplusplus */ #define GST_TYPE_SPEEXENC \ @@ -43,44 +44,45 @@ extern "C" { #define GST_IS_SPEEXENC_CLASS(obj) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SPEEXENC)) -typedef struct _GstSpeexEnc GstSpeexEnc; -typedef struct _GstSpeexEncClass GstSpeexEncClass; + typedef struct _GstSpeexEnc GstSpeexEnc; + typedef struct _GstSpeexEncClass GstSpeexEncClass; -struct _GstSpeexEnc { - GstElement element; + struct _GstSpeexEnc + { + GstElement element; - /* pads */ - GstPad *sinkpad, - *srcpad; + /* pads */ + GstPad *sinkpad, *srcpad; - gint packet_count; - gint n_packets; + gint packet_count; + gint n_packets; - SpeexBits bits; - SpeexHeader header; - SpeexMode *mode; - void *state; - gint frame_size; - gint16 buffer[2000]; - gint bufsize; - guint64 next_ts; + SpeexBits bits; + SpeexHeader header; + SpeexMode *mode; + void *state; + gint frame_size; + gint16 buffer[2000]; + gint bufsize; + guint64 next_ts; - gint rate; -}; + gint rate; + }; -struct _GstSpeexEncClass { - GstElementClass parent_class; + struct _GstSpeexEncClass + { + GstElementClass parent_class; - /* signals */ - void (*frame_encoded) (GstElement *element); -}; + /* signals */ + void (*frame_encoded) (GstElement * element); + }; -GType gst_speexenc_get_type(void); + GType gst_speexenc_get_type (void); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif /* __cplusplus */ -#endif /* __GST_SPEEXENC_H__ */ +#endif /* __GST_SPEEXENC_H__ */ |