From 7a778ee4b7ec09a1f5b2185c9cceee3910dfbdf2 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Sun, 14 Mar 2004 22:34:33 +0000 Subject: gst-indent Original commit message from CVS: gst-indent --- ext/audiofile/gstafparse.c | 414 ++++++++++++++++++++++----------------------- 1 file changed, 206 insertions(+), 208 deletions(-) (limited to 'ext/audiofile/gstafparse.c') diff --git a/ext/audiofile/gstafparse.c b/ext/audiofile/gstafparse.c index 179dd849..00c9fd81 100644 --- a/ext/audiofile/gstafparse.c +++ b/ext/audiofile/gstafparse.c @@ -39,65 +39,64 @@ static GstElementDetails afparse_details = { /* AFParse signals and args */ -enum { +enum +{ /* FILL ME */ SIGNAL_HANDOFF, LAST_SIGNAL }; -enum { +enum +{ ARG_0, }; /* added a src factory function to force audio/raw MIME type */ static GstStaticPadTemplate afparse_src_factory = -GST_STATIC_PAD_TEMPLATE ( - "src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ( - "audio/x-raw-int, " - "rate = (int) [ 1, MAX ], " - "channels = (int) [ 1, MAX ], " - "endianness = (int) BYTE_ORDER, " - "width = (int) { 8, 16 }, " - "depth = (int) { 8, 16 }, " - "signed = (boolean) { true, false }, " - "buffer-frames = (int) [ 1, MAX ]" - ) -); +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-raw-int, " + "rate = (int) [ 1, MAX ], " + "channels = (int) [ 1, MAX ], " + "endianness = (int) BYTE_ORDER, " + "width = (int) { 8, 16 }, " + "depth = (int) { 8, 16 }, " + "signed = (boolean) { true, false }, " + "buffer-frames = (int) [ 1, MAX ]") + ); static GstStaticPadTemplate afparse_sink_factory = -GST_STATIC_PAD_TEMPLATE ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ( - "audio/x-aiff; " - "audio/x-wav; " - "audio/x-au" - ) -); + GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("audio/x-aiff; " "audio/x-wav; " "audio/x-au") + ); static void gst_afparse_base_init (gpointer g_class); -static void gst_afparse_class_init(GstAFParseClass *klass); -static void gst_afparse_init (GstAFParse *afparse); - -static gboolean gst_afparse_open_file(GstAFParse *afparse); -static void gst_afparse_close_file(GstAFParse *afparse); - -static void gst_afparse_loop(GstElement *element); -static void gst_afparse_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); -static void gst_afparse_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); -static ssize_t gst_afparse_vf_read (AFvirtualfile *vfile, void *data, size_t nbytes); -static long gst_afparse_vf_length (AFvirtualfile *vfile); -static ssize_t gst_afparse_vf_write (AFvirtualfile *vfile, const void *data, size_t nbytes); -static void gst_afparse_vf_destroy(AFvirtualfile *vfile); -static long gst_afparse_vf_seek (AFvirtualfile *vfile, long offset, int is_relative); -static long gst_afparse_vf_tell (AFvirtualfile *vfile); +static void gst_afparse_class_init (GstAFParseClass * klass); +static void gst_afparse_init (GstAFParse * afparse); + +static gboolean gst_afparse_open_file (GstAFParse * afparse); +static void gst_afparse_close_file (GstAFParse * afparse); + +static void gst_afparse_loop (GstElement * element); +static void gst_afparse_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_afparse_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); +static ssize_t gst_afparse_vf_read (AFvirtualfile * vfile, void *data, + size_t nbytes); +static long gst_afparse_vf_length (AFvirtualfile * vfile); +static ssize_t gst_afparse_vf_write (AFvirtualfile * vfile, const void *data, + size_t nbytes); +static void gst_afparse_vf_destroy (AFvirtualfile * vfile); +static long gst_afparse_vf_seek (AFvirtualfile * vfile, long offset, + int is_relative); +static long gst_afparse_vf_tell (AFvirtualfile * vfile); GType -gst_afparse_get_type (void) +gst_afparse_get_type (void) { static GType afparse_type = 0; @@ -113,7 +112,9 @@ gst_afparse_get_type (void) 0, (GInstanceInitFunc) gst_afparse_init, }; - afparse_type = g_type_register_static (GST_TYPE_ELEMENT, "GstAFParse", &afparse_info, 0); + afparse_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstAFParse", &afparse_info, + 0); } return afparse_type; } @@ -132,34 +133,36 @@ gst_afparse_base_init (gpointer g_class) } static void -gst_afparse_class_init (GstAFParseClass *klass) +gst_afparse_class_init (GstAFParseClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; - gobject_class = (GObjectClass*)klass; - gstelement_class = (GstElementClass*)klass; + gobject_class = (GObjectClass *) klass; + gstelement_class = (GstElementClass *) klass; gobject_class->set_property = gst_afparse_set_property; gobject_class->get_property = gst_afparse_get_property; } -static void -gst_afparse_init (GstAFParse *afparse) +static void +gst_afparse_init (GstAFParse * afparse) { - afparse->srcpad = gst_pad_new_from_template ( - gst_element_get_pad_template (GST_ELEMENT (afparse), "src"), "src"); + afparse->srcpad = + gst_pad_new_from_template (gst_element_get_pad_template (GST_ELEMENT + (afparse), "src"), "src"); gst_pad_use_explicit_caps (afparse->srcpad); gst_element_add_pad (GST_ELEMENT (afparse), afparse->srcpad); - afparse->sinkpad = gst_pad_new_from_template ( - gst_element_get_pad_template (GST_ELEMENT (afparse), "sink"), "sink"); + afparse->sinkpad = + gst_pad_new_from_template (gst_element_get_pad_template (GST_ELEMENT + (afparse), "sink"), "sink"); gst_element_add_pad (GST_ELEMENT (afparse), afparse->sinkpad); gst_element_set_loop_function (GST_ELEMENT (afparse), gst_afparse_loop); - afparse->vfile = af_virtual_file_new(); + afparse->vfile = af_virtual_file_new (); afparse->vfile->closure = NULL; afparse->vfile->read = gst_afparse_vf_read; afparse->vfile->length = gst_afparse_vf_length; @@ -184,7 +187,7 @@ gst_afparse_init (GstAFParse *afparse) } static void -gst_afparse_loop(GstElement *element) +gst_afparse_loop (GstElement * element) { GstAFParse *afparse; GstBuffer *buf; @@ -194,14 +197,14 @@ gst_afparse_loop(GstElement *element) GstByteStream *bs; int s_format, v_format, s_width, v_width; - afparse = GST_AFPARSE(element); + afparse = GST_AFPARSE (element); afparse->vfile->closure = bs = gst_bytestream_new (afparse->sinkpad); /* just stop if we cannot open the file */ - if (!gst_afparse_open_file (afparse)){ + if (!gst_afparse_open_file (afparse)) { gst_bytestream_destroy ((GstByteStream *) afparse->vfile->closure); - gst_pad_push (afparse->srcpad, GST_DATA(gst_event_new (GST_EVENT_EOS))); + gst_pad_push (afparse->srcpad, GST_DATA (gst_event_new (GST_EVENT_EOS))); gst_element_set_eos (GST_ELEMENT (afparse)); return; } @@ -209,91 +212,91 @@ gst_afparse_loop(GstElement *element) /* if audiofile changes the data in any way, we have to access * the audio data via afReadFrames. Otherwise we can just access * the data directly. */ - afGetSampleFormat(afparse->file, AF_DEFAULT_TRACK, &s_format, &s_width); - afGetVirtualSampleFormat(afparse->file, AF_DEFAULT_TRACK, &v_format, &v_width); - if (afGetCompression != AF_COMPRESSION_NONE || - afGetByteOrder(afparse->file, AF_DEFAULT_TRACK) != afGetVirtualByteOrder(afparse->file, AF_DEFAULT_TRACK) || - s_format != v_format || - s_width != v_width) { + afGetSampleFormat (afparse->file, AF_DEFAULT_TRACK, &s_format, &s_width); + afGetVirtualSampleFormat (afparse->file, AF_DEFAULT_TRACK, &v_format, + &v_width); + if (afGetCompression != AF_COMPRESSION_NONE + || afGetByteOrder (afparse->file, + AF_DEFAULT_TRACK) != afGetVirtualByteOrder (afparse->file, + AF_DEFAULT_TRACK) || s_format != v_format || s_width != v_width) { bypass_afread = FALSE; } - if (bypass_afread){ - GST_DEBUG("will bypass afReadFrames\n"); + if (bypass_afread) { + GST_DEBUG ("will bypass afReadFrames\n"); } - + frames_to_bytes = afparse->channels * afparse->width / 8; frames_per_read = afparse->frames_per_read; bytes_per_read = frames_per_read * frames_to_bytes; - - afSeekFrame(afparse->file, AF_DEFAULT_TRACK, 0); - if (bypass_afread){ - GstEvent *event = NULL; - guint32 waiting; - guint32 got_bytes; + afSeekFrame (afparse->file, AF_DEFAULT_TRACK, 0); + + if (bypass_afread) { + GstEvent *event = NULL; + guint32 waiting; + guint32 got_bytes; do { got_bytes = gst_bytestream_read (bs, &buf, bytes_per_read); if (got_bytes == 0) { - /* we need to check for an event. */ - gst_bytestream_get_status (bs, &waiting, &event); - if (event && GST_EVENT_TYPE(event) == GST_EVENT_EOS) { - gst_pad_push (afparse->srcpad, - GST_DATA (gst_event_new (GST_EVENT_EOS))); - gst_element_set_eos (GST_ELEMENT (afparse)); - break; - } - } - else { - GST_BUFFER_TIMESTAMP(buf) = afparse->timestamp; - gst_pad_push (afparse->srcpad, GST_DATA (buf)); - if (got_bytes != bytes_per_read){ + /* we need to check for an event. */ + gst_bytestream_get_status (bs, &waiting, &event); + if (event && GST_EVENT_TYPE (event) == GST_EVENT_EOS) { + gst_pad_push (afparse->srcpad, + GST_DATA (gst_event_new (GST_EVENT_EOS))); + gst_element_set_eos (GST_ELEMENT (afparse)); + break; + } + } else { + GST_BUFFER_TIMESTAMP (buf) = afparse->timestamp; + gst_pad_push (afparse->srcpad, GST_DATA (buf)); + if (got_bytes != bytes_per_read) { /* this shouldn't happen very often */ /* FIXME calculate the timestamps based on the fewer bytes received */ - } - else { - afparse->timestamp += frames_per_read * 1E9 / afparse->rate; + } else { + afparse->timestamp += frames_per_read * 1E9 / afparse->rate; } } } while (TRUE); - } - else { + } else { do { buf = gst_buffer_new_and_alloc (bytes_per_read); - GST_BUFFER_TIMESTAMP(buf) = afparse->timestamp; - data = GST_BUFFER_DATA(buf); - numframes = afReadFrames (afparse->file, AF_DEFAULT_TRACK, data, frames_per_read); + GST_BUFFER_TIMESTAMP (buf) = afparse->timestamp; + data = GST_BUFFER_DATA (buf); + numframes = + afReadFrames (afparse->file, AF_DEFAULT_TRACK, data, frames_per_read); /* events are handled in gst_afparse_vf_read so if there are no * frames it must be EOS */ - if (numframes < 1){ - gst_buffer_unref(buf); + if (numframes < 1) { + gst_buffer_unref (buf); - gst_pad_push (afparse->srcpad, GST_DATA(gst_event_new (GST_EVENT_EOS))); - gst_element_set_eos (GST_ELEMENT (afparse)); - break; + gst_pad_push (afparse->srcpad, + GST_DATA (gst_event_new (GST_EVENT_EOS))); + gst_element_set_eos (GST_ELEMENT (afparse)); + break; } - GST_BUFFER_SIZE(buf) = numframes * frames_to_bytes; + GST_BUFFER_SIZE (buf) = numframes * frames_to_bytes; gst_pad_push (afparse->srcpad, GST_DATA (buf)); afparse->timestamp += numframes * 1E9 / afparse->rate; } while (TRUE); } gst_afparse_close_file (afparse); - - gst_bytestream_destroy ((GstByteStream*) afparse->vfile->closure); + + gst_bytestream_destroy ((GstByteStream *) afparse->vfile->closure); } static void -gst_afparse_set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec) +gst_afparse_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) { GstAFParse *afparse; @@ -306,16 +309,16 @@ gst_afparse_set_property (GObject *object, guint prop_id, } } -static void -gst_afparse_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) +static void +gst_afparse_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) { GstAFParse *afparse; - + g_return_if_fail (GST_IS_AFPARSE (object)); - + afparse = GST_AFPARSE (object); - + switch (prop_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -324,13 +327,14 @@ gst_afparse_get_property (GObject *object, guint prop_id, } gboolean -gst_afparse_plugin_init (GstPlugin *plugin) +gst_afparse_plugin_init (GstPlugin * plugin) { - /* load audio support library */ + /* load audio support library */ if (!gst_library_load ("gstaudio")) return FALSE; - if (!gst_element_register (plugin, "afparse", GST_RANK_NONE, GST_TYPE_AFPARSE)) + if (!gst_element_register (plugin, "afparse", GST_RANK_NONE, + GST_TYPE_AFPARSE)) return FALSE; return TRUE; @@ -338,60 +342,56 @@ gst_afparse_plugin_init (GstPlugin *plugin) /* this is where we open the audiofile */ static gboolean -gst_afparse_open_file (GstAFParse *afparse) +gst_afparse_open_file (GstAFParse * afparse) { g_return_val_if_fail (!GST_FLAG_IS_SET (afparse, GST_AFPARSE_OPEN), FALSE); /* open the file */ - GST_DEBUG("opening vfile %p\n", afparse->vfile); + GST_DEBUG ("opening vfile %p\n", afparse->vfile); afparse->file = afOpenVirtualFile (afparse->vfile, "r", AF_NULL_FILESETUP); - if (afparse->file == AF_NULL_FILEHANDLE) - { + if (afparse->file == AF_NULL_FILEHANDLE) { /* this should never happen */ g_warning ("ERROR: gstafparse: Could not open virtual file for reading\n"); return FALSE; } - GST_DEBUG("vfile opened\n"); + GST_DEBUG ("vfile opened\n"); /* get the audiofile audio parameters */ { int sampleFormat, sampleWidth; + afparse->channels = afGetChannels (afparse->file, AF_DEFAULT_TRACK); - afGetSampleFormat (afparse->file, AF_DEFAULT_TRACK, - &sampleFormat, &sampleWidth); - switch (sampleFormat) - { + afGetSampleFormat (afparse->file, AF_DEFAULT_TRACK, + &sampleFormat, &sampleWidth); + switch (sampleFormat) { case AF_SAMPFMT_TWOSCOMP: - afparse->is_signed = TRUE; - break; + afparse->is_signed = TRUE; + break; case AF_SAMPFMT_UNSIGNED: - afparse->is_signed = FALSE; - break; + afparse->is_signed = FALSE; + break; case AF_SAMPFMT_FLOAT: case AF_SAMPFMT_DOUBLE: - GST_DEBUG ("ERROR: float data not supported yet !\n"); + GST_DEBUG ("ERROR: float data not supported yet !\n"); } afparse->rate = (guint) afGetRate (afparse->file, AF_DEFAULT_TRACK); afparse->width = sampleWidth; - GST_DEBUG ( - "input file: %d channels, %d width, %d rate, signed %s\n", - afparse->channels, afparse->width, afparse->rate, - afparse->is_signed ? "yes" : "no"); + GST_DEBUG ("input file: %d channels, %d width, %d rate, signed %s\n", + afparse->channels, afparse->width, afparse->rate, + afparse->is_signed ? "yes" : "no"); } - + /* set caps on src */ - /*FIXME: add all the possible formats, especially float ! */ - gst_pad_set_explicit_caps (afparse->srcpad, - gst_caps_new_simple ( - "audio/x-raw-int", - "endianness", G_TYPE_INT, G_BYTE_ORDER, - "signed", G_TYPE_BOOLEAN, afparse->is_signed, - "width", G_TYPE_INT, afparse->width, - "depth", G_TYPE_INT, afparse->width, - "rate", G_TYPE_INT, afparse->rate, - "channels", G_TYPE_INT, afparse->channels, - NULL)); + /*FIXME: add all the possible formats, especially float ! */ + gst_pad_set_explicit_caps (afparse->srcpad, + gst_caps_new_simple ("audio/x-raw-int", + "endianness", G_TYPE_INT, G_BYTE_ORDER, + "signed", G_TYPE_BOOLEAN, afparse->is_signed, + "width", G_TYPE_INT, afparse->width, + "depth", G_TYPE_INT, afparse->width, + "rate", G_TYPE_INT, afparse->rate, + "channels", G_TYPE_INT, afparse->channels, NULL)); GST_FLAG_SET (afparse, GST_AFPARSE_OPEN); @@ -399,126 +399,124 @@ gst_afparse_open_file (GstAFParse *afparse) } static void -gst_afparse_close_file (GstAFParse *afparse) +gst_afparse_close_file (GstAFParse * afparse) { g_return_if_fail (GST_FLAG_IS_SET (afparse, GST_AFPARSE_OPEN)); - if (afCloseFile (afparse->file) != 0) - { + if (afCloseFile (afparse->file) != 0) { g_warning ("afparse: oops, error closing !\n"); - } - else { + } else { GST_FLAG_UNSET (afparse, GST_AFPARSE_OPEN); } } -static ssize_t -gst_afparse_vf_read (AFvirtualfile *vfile, void *data, size_t nbytes) +static ssize_t +gst_afparse_vf_read (AFvirtualfile * vfile, void *data, size_t nbytes) { - GstByteStream *bs = (GstByteStream*)vfile->closure; - guint8 *bytes = NULL; - GstEvent *event = NULL; - guint32 waiting; - guint32 got_bytes; - /*gchar *debug_str;*/ - - got_bytes = gst_bytestream_peek_bytes(bs, &bytes, nbytes); - - while (got_bytes != nbytes){ + GstByteStream *bs = (GstByteStream *) vfile->closure; + guint8 *bytes = NULL; + GstEvent *event = NULL; + guint32 waiting; + guint32 got_bytes; + + /*gchar *debug_str; */ + + got_bytes = gst_bytestream_peek_bytes (bs, &bytes, nbytes); + + while (got_bytes != nbytes) { /* handle events */ gst_bytestream_get_status (bs, &waiting, &event); /* FIXME this event handling isn't right yet */ - if (!event){ - /*g_print("no event found with %u bytes\n", got_bytes);*/ + if (!event) { + /*g_print("no event found with %u bytes\n", got_bytes); */ return 0; } - switch (GST_EVENT_TYPE(event)) { + switch (GST_EVENT_TYPE (event)) { case GST_EVENT_EOS: - return 0; + return 0; case GST_EVENT_FLUSH: - GST_DEBUG("flush"); - break; + GST_DEBUG ("flush"); + break; case GST_EVENT_DISCONTINUOUS: - GST_DEBUG("seek done"); - got_bytes = gst_bytestream_peek_bytes(bs, &bytes, nbytes); - break; + GST_DEBUG ("seek done"); + got_bytes = gst_bytestream_peek_bytes (bs, &bytes, nbytes); + break; default: - g_warning("unknown event %d", GST_EVENT_TYPE(event)); - got_bytes = gst_bytestream_peek_bytes(bs, &bytes, nbytes); + g_warning ("unknown event %d", GST_EVENT_TYPE (event)); + got_bytes = gst_bytestream_peek_bytes (bs, &bytes, nbytes); } } - - memcpy(data, bytes, got_bytes); - gst_bytestream_flush_fast(bs, got_bytes); + + memcpy (data, bytes, got_bytes); + gst_bytestream_flush_fast (bs, got_bytes); /* debug_str = g_strndup((gchar*)bytes, got_bytes); - g_print("read %u bytes: %s\n", got_bytes, debug_str); - */ + g_print("read %u bytes: %s\n", got_bytes, debug_str); + */ return got_bytes; } -static long -gst_afparse_vf_seek (AFvirtualfile *vfile, long offset, int is_relative) +static long +gst_afparse_vf_seek (AFvirtualfile * vfile, long offset, int is_relative) { - GstByteStream *bs = (GstByteStream*)vfile->closure; + GstByteStream *bs = (GstByteStream *) vfile->closure; GstSeekType method; - guint64 current_offset = gst_bytestream_tell(bs); + guint64 current_offset = gst_bytestream_tell (bs); - if (!is_relative){ - if ((guint64)offset == current_offset) { + if (!is_relative) { + if ((guint64) offset == current_offset) { /* this seems to happen before every read - bad audiofile */ return offset; } method = GST_SEEK_METHOD_SET; + } else { + if (offset == 0) + return current_offset; + method = GST_SEEK_METHOD_CUR; } - else { - if (offset == 0) return current_offset; - method = GST_SEEK_METHOD_CUR; - } - - if (gst_bytestream_seek(bs, (gint64)offset, method)){ - GST_DEBUG("doing seek to %d", (gint)offset); + + if (gst_bytestream_seek (bs, (gint64) offset, method)) { + GST_DEBUG ("doing seek to %d", (gint) offset); return offset; } return 0; } -static long -gst_afparse_vf_length (AFvirtualfile *vfile) +static long +gst_afparse_vf_length (AFvirtualfile * vfile) { - GstByteStream *bs = (GstByteStream*)vfile->closure; + GstByteStream *bs = (GstByteStream *) vfile->closure; guint64 length; - length = gst_bytestream_length(bs); - GST_DEBUG("doing length: %" G_GUINT64_FORMAT, length); + length = gst_bytestream_length (bs); + GST_DEBUG ("doing length: %" G_GUINT64_FORMAT, length); return length; } -static ssize_t -gst_afparse_vf_write (AFvirtualfile *vfile, const void *data, size_t nbytes) +static ssize_t +gst_afparse_vf_write (AFvirtualfile * vfile, const void *data, size_t nbytes) { - /* GstByteStream *bs = (GstByteStream*)vfile->closure;*/ - g_warning("shouldn't write to a readonly pad"); + /* GstByteStream *bs = (GstByteStream*)vfile->closure; */ + g_warning ("shouldn't write to a readonly pad"); return 0; } -static void -gst_afparse_vf_destroy(AFvirtualfile *vfile) +static void +gst_afparse_vf_destroy (AFvirtualfile * vfile) { - /* GstByteStream *bs = (GstByteStream*)vfile->closure;*/ + /* GstByteStream *bs = (GstByteStream*)vfile->closure; */ - GST_DEBUG("doing destroy"); + GST_DEBUG ("doing destroy"); } -static long -gst_afparse_vf_tell (AFvirtualfile *vfile) +static long +gst_afparse_vf_tell (AFvirtualfile * vfile) { - GstByteStream *bs = (GstByteStream*)vfile->closure; + GstByteStream *bs = (GstByteStream *) vfile->closure; guint64 offset; - offset = gst_bytestream_tell(bs); - GST_DEBUG("doing tell: %" G_GUINT64_FORMAT, offset); + offset = gst_bytestream_tell (bs); + GST_DEBUG ("doing tell: %" G_GUINT64_FORMAT, offset); return offset; } - -- cgit v1.2.1