summaryrefslogtreecommitdiffstats
path: root/ext
diff options
context:
space:
mode:
authorThomas Vander Stichele <thomas@apestaart.org>2001-12-23 14:15:30 +0000
committerThomas Vander Stichele <thomas@apestaart.org>2001-12-23 14:15:30 +0000
commit56f271163b03535bec01c8978818ca8c41e25968 (patch)
tree2b3886b67c9e3c2d3c69c6ead92f78288d2f2837 /ext
parent1dcf747efcb12e79118bf64e96c0f6c75ae425d9 (diff)
adding flac
Original commit message from CVS: adding flac
Diffstat (limited to 'ext')
-rw-r--r--ext/Makefile.am17
-rw-r--r--ext/flac/Makefile.am2
-rw-r--r--ext/flac/gstflac.c141
-rw-r--r--ext/flac/gstflacdec.c250
-rw-r--r--ext/flac/gstflacdec.h70
-rw-r--r--ext/flac/gstflacenc.c1
-rw-r--r--ext/flac/gstflacenc.h68
7 files changed, 542 insertions, 7 deletions
diff --git a/ext/Makefile.am b/ext/Makefile.am
index c53ea1bd..83000f83 100644
--- a/ext/Makefile.am
+++ b/ext/Makefile.am
@@ -46,10 +46,16 @@ else
ESD_DIR=
endif
-if USE_FESTIVAL
-FESTIVAL_DIR=festival
-else
+## if USE_FESTIVAL
+## FESTIVAL_DIR=festival
+## else
FESTIVAL_DIR=
+## endif
+
+if USE_FLAC
+FLAC_DIR=flac
+else
+FLAC_DIR=
endif
if USE_LAME
@@ -84,8 +90,9 @@ endif
SUBDIRS=$(A52_DIR) $(AALIB_DIR) $(ALSA_DIR) $(AUDIOFILE_DIR) \
$(AVIFILE_DIR) $(CDPARANOIA_DIR) $(DVDREAD_DIR) $(ESD_DIR) \
- $(FESTIVAL_DIR) $(LAME_DIR) $(MAD_DIR) $(MPEG2DEC_DIR) \
+ $(FESTIVAL_DIR) $(FLAC_DIR) \
+ $(LAME_DIR) $(MAD_DIR) $(MPEG2DEC_DIR) \
$(SDL_DIR) $(VORBIS_DIR)
DIST_SUBDIRS=a52 aalib alsa avifile audiofile cdparanoia dvdread esd \
- festival lame mad mpeg2dec sdl vorbis
+ festival flac lame mad mpeg2dec sdl vorbis
diff --git a/ext/flac/Makefile.am b/ext/flac/Makefile.am
index 11a17473..6efc3538 100644
--- a/ext/flac/Makefile.am
+++ b/ext/flac/Makefile.am
@@ -7,4 +7,4 @@ libgstflac_la_SOURCES = gstflac.c gstflacenc.c gstflacdec.c
noinst_HEADERS = gstflacenc.h gstflacdec.h
libgstflac_la_CFLAGS = $(GST_CFLAGS)
-libgstflac_la_LIBADD = $(GST_LIBS)
+libgstflac_la_LIBADD = $(GST_LIBS) $(FLAC_LIBS)
diff --git a/ext/flac/gstflac.c b/ext/flac/gstflac.c
new file mode 100644
index 00000000..ff4f3577
--- /dev/null
+++ b/ext/flac/gstflac.c
@@ -0,0 +1,141 @@
+/* Gnome-Streamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+
+#include "gstflacenc.h"
+#include "gstflacdec.h"
+
+extern GstElementDetails flacenc_details;
+extern GstElementDetails flacdec_details;
+
+static GstCaps* flac_typefind (GstBuffer *buf, gpointer private);
+
+GstPadTemplate *dec_src_template, *dec_sink_template;
+GstPadTemplate *enc_src_template, *enc_sink_template;
+
+static GstCaps*
+flac_caps_factory (void)
+{
+ return
+ gst_caps_new (
+ "flac_flac",
+ "audio/x-flac",
+ NULL);
+}
+
+static GstCaps*
+raw_caps_factory (void)
+{
+ return
+ gst_caps_new (
+ "flac_raw",
+ "audio/raw",
+ gst_props_new (
+ "format", GST_PROPS_STRING ("int"),
+ "law", GST_PROPS_INT (0),
+ "endianness", GST_PROPS_INT (G_BYTE_ORDER),
+ "signed", GST_PROPS_BOOLEAN (TRUE),
+ "width", GST_PROPS_INT (16),
+ "depth", GST_PROPS_INT (16),
+ "rate", GST_PROPS_INT_RANGE (11025, 48000),
+ "channels", GST_PROPS_INT_RANGE (1, 2),
+ NULL));
+}
+
+static GstTypeDefinition flacdefinition = {
+ "flac_audio/x-flac",
+ "audio/x-flac",
+ ".flac",
+ flac_typefind,
+};
+
+static GstCaps*
+flac_typefind (GstBuffer *buf, gpointer private)
+{
+ gulong head = GULONG_FROM_BE (*((gulong *)GST_BUFFER_DATA (buf)));
+
+ if (head != 0x664C6143)
+ return NULL;
+
+ return gst_caps_new ("flac_typefind", "audio/x-flac", NULL);
+}
+
+
+static gboolean
+plugin_init (GModule *module, GstPlugin *plugin)
+{
+ GstElementFactory *enc, *dec;
+ GstTypeFactory *type;
+ GstCaps *raw_caps, *flac_caps;
+
+ gst_plugin_set_longname (plugin, "The FLAC Lossless compressor Codec");
+
+ /* create an elementfactory for the flacenc element */
+ enc = gst_elementfactory_new ("flacenc", GST_TYPE_FLACENC,
+ &flacenc_details);
+ g_return_val_if_fail (enc != NULL, FALSE);
+
+ raw_caps = raw_caps_factory ();
+ flac_caps = flac_caps_factory ();
+
+ /* register sink pads */
+ enc_sink_template = gst_padtemplate_new ("sink", GST_PAD_SINK,
+ GST_PAD_ALWAYS,
+ raw_caps, NULL);
+ gst_elementfactory_add_padtemplate (enc, enc_sink_template);
+
+ /* register src pads */
+ enc_src_template = gst_padtemplate_new ("src", GST_PAD_SRC,
+ GST_PAD_ALWAYS,
+ flac_caps, NULL);
+ gst_elementfactory_add_padtemplate (enc, enc_src_template);
+
+ gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (enc));
+
+ /* create an elementfactory for the flacdec element */
+ dec = gst_elementfactory_new("flacdec",GST_TYPE_FLACDEC,
+ &flacdec_details);
+ g_return_val_if_fail(dec != NULL, FALSE);
+
+ /* register sink pads */
+ dec_sink_template = gst_padtemplate_new ("sink", GST_PAD_SINK,
+ GST_PAD_ALWAYS,
+ flac_caps, NULL);
+ gst_elementfactory_add_padtemplate (dec, dec_sink_template);
+
+ /* register src pads */
+ dec_src_template = gst_padtemplate_new ("src", GST_PAD_SRC,
+ GST_PAD_ALWAYS,
+ raw_caps, NULL);
+ gst_elementfactory_add_padtemplate (dec, dec_src_template);
+
+ gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (dec));
+
+ type = gst_typefactory_new (&flacdefinition);
+ gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type));
+
+ return TRUE;
+}
+
+GstPluginDesc plugin_desc = {
+ GST_VERSION_MAJOR,
+ GST_VERSION_MINOR,
+ "flac",
+ plugin_init
+};
diff --git a/ext/flac/gstflacdec.c b/ext/flac/gstflacdec.c
new file mode 100644
index 00000000..67291482
--- /dev/null
+++ b/ext/flac/gstflacdec.c
@@ -0,0 +1,250 @@
+/* GStreamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <string.h>
+#include <sys/soundcard.h>
+
+//#define DEBUG_ENABLED
+#include "gstflacdec.h"
+
+
+extern GstPadTemplate *dec_src_template, *dec_sink_template;
+
+/* elementfactory information */
+GstElementDetails flacdec_details = {
+ "FLAC decoder",
+ "Filter/Audio/Decoder",
+ "Decodes FLAC lossless audio streams",
+ VERSION,
+ "Wim Taymans <wim.taymans@chello.be>",
+ "(C) 2001",
+};
+
+/* FlacDec signals and args */
+enum {
+ /* FILL ME */
+ LAST_SIGNAL
+};
+
+enum {
+ ARG_0,
+};
+
+static void gst_flacdec_class_init (FlacDecClass *klass);
+static void gst_flacdec_init (FlacDec *flacdec);
+
+static void gst_flacdec_loop (GstElement *element);
+
+static void gst_flacdec_metadata_callback (const FLAC__StreamDecoder *decoder,
+ const FLAC__StreamMetaData *metadata,
+ void *client_data);
+static void gst_flacdec_error_callback (const FLAC__StreamDecoder *decoder,
+ FLAC__StreamDecoderErrorStatus status,
+ void *client_data);
+
+static FLAC__StreamDecoderReadStatus gst_flacdec_read (const FLAC__StreamDecoder *decoder,
+ FLAC__byte buffer[], unsigned *bytes, void *client_data);
+static FLAC__StreamDecoderWriteStatus gst_flacdec_write (const FLAC__StreamDecoder *decoder,
+ const FLAC__Frame *frame, const FLAC__int32 *buffer[],
+ void *client_data);
+
+static GstElementClass *parent_class = NULL;
+//static guint gst_flacdec_signals[LAST_SIGNAL] = { 0 };
+
+GType
+flacdec_get_type(void) {
+ static GType flacdec_type = 0;
+
+ if (!flacdec_type) {
+ static const GTypeInfo flacdec_info = {
+ sizeof(FlacDecClass),
+ NULL,
+ NULL,
+ (GClassInitFunc)gst_flacdec_class_init,
+ NULL,
+ NULL,
+ sizeof(FlacDec),
+ 0,
+ (GInstanceInitFunc)gst_flacdec_init,
+ };
+ flacdec_type = g_type_register_static (GST_TYPE_ELEMENT, "FlacDec", &flacdec_info, 0);
+ }
+ return flacdec_type;
+}
+
+static void
+gst_flacdec_class_init (FlacDecClass *klass)
+{
+ GstElementClass *gstelement_class;
+
+ gstelement_class = (GstElementClass*)klass;
+
+ parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
+}
+
+static void
+gst_flacdec_init (FlacDec *flacdec)
+{
+ flacdec->sinkpad = gst_pad_new_from_template (dec_sink_template, "sink");
+ gst_element_add_pad (GST_ELEMENT (flacdec), flacdec->sinkpad);
+
+ gst_element_set_loop_function (GST_ELEMENT (flacdec), gst_flacdec_loop);
+ flacdec->srcpad = gst_pad_new_from_template (dec_src_template, "src");
+ gst_element_add_pad (GST_ELEMENT (flacdec), flacdec->srcpad);
+
+ flacdec->decoder = FLAC__stream_decoder_new ();
+ flacdec->offset_left = 0;
+ flacdec->data_left = NULL;
+
+ FLAC__stream_decoder_set_read_callback (flacdec->decoder, gst_flacdec_read);
+ FLAC__stream_decoder_set_write_callback (flacdec->decoder, gst_flacdec_write);
+ FLAC__stream_decoder_set_metadata_callback (flacdec->decoder, gst_flacdec_metadata_callback);
+ FLAC__stream_decoder_set_error_callback (flacdec->decoder, gst_flacdec_error_callback);
+ FLAC__stream_decoder_set_client_data (flacdec->decoder, flacdec);
+
+ FLAC__stream_decoder_init (flacdec->decoder);
+}
+
+static void
+gst_flacdec_metadata_callback (const FLAC__StreamDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data)
+{
+}
+
+static void
+gst_flacdec_error_callback (const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
+{
+}
+
+static FLAC__StreamDecoderReadStatus
+gst_flacdec_read (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
+{
+ FlacDec *flacdec;
+ GstBuffer *inbuf = NULL;
+ gint insize;
+ guchar *indata;
+
+ flacdec = GST_FLACDEC (client_data);
+
+ if (flacdec->data_left == NULL) {
+ inbuf = gst_pad_pull (flacdec->sinkpad);
+ insize = GST_BUFFER_SIZE (inbuf);
+ indata = GST_BUFFER_DATA (inbuf);
+ }
+ else {
+ inbuf = flacdec->data_left;
+ insize = GST_BUFFER_SIZE (inbuf) - flacdec->offset_left;
+ indata = GST_BUFFER_DATA (inbuf) + flacdec->offset_left;
+ }
+
+ if (*bytes < insize) {
+ // we have more than we can handle
+ flacdec->data_left = inbuf;
+ flacdec->offset_left += *bytes;
+ inbuf = NULL;
+ }
+ else {
+ flacdec->data_left = NULL;
+ flacdec->offset_left = 0;
+ *bytes = insize;
+ }
+ memcpy (buffer, indata, *bytes);
+
+ if (inbuf)
+ gst_buffer_unref (inbuf);
+
+ return FLAC__STREAM_DECODER_READ_CONTINUE;
+}
+
+static FLAC__StreamDecoderWriteStatus
+gst_flacdec_write (const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 *buffer[], void *client_data)
+{
+ FlacDec *flacdec;
+ GstBuffer *outbuf;
+ guint depth = frame->header.bits_per_sample;
+ guint channels = frame->header.channels;
+ guint samples = frame->header.blocksize;
+ guint j, i;
+
+ flacdec = GST_FLACDEC (client_data);
+
+ if (!GST_PAD_CAPS (flacdec->srcpad)) {
+ gst_pad_set_caps (flacdec->srcpad,
+ GST_CAPS_NEW (
+ "flac_caps",
+ "audio/raw",
+ "format", GST_PROPS_STRING ("int"),
+ "law", GST_PROPS_INT (0),
+ "endianness", GST_PROPS_INT (G_BYTE_ORDER),
+ "signed", GST_PROPS_BOOLEAN (TRUE),
+ "width", GST_PROPS_INT (depth),
+ "depth", GST_PROPS_INT (depth),
+ "rate", GST_PROPS_INT (frame->header.sample_rate),
+ "channels", GST_PROPS_INT (channels)
+ ));
+ }
+
+ outbuf = gst_buffer_new ();
+ GST_BUFFER_SIZE (outbuf) = samples * channels * ((depth+7)>>3);
+ GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf));
+
+ 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];
+ }
+ }
+ }
+ 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 {
+ g_warning ("flacdec: invalid depth %d found\n", depth);
+ return FLAC__STREAM_DECODER_WRITE_ABORT;
+ }
+
+ gst_pad_push (flacdec->srcpad, outbuf);
+
+ return FLAC__STREAM_DECODER_WRITE_CONTINUE;
+}
+
+static void
+gst_flacdec_loop (GstElement *element)
+{
+ FlacDec *flacdec;
+
+ flacdec = GST_FLACDEC (element);
+
+ if (FLAC__stream_decoder_get_state (flacdec->decoder) == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA) {
+ FLAC__stream_decoder_process_metadata (flacdec->decoder);
+ }
+
+ do {
+ FLAC__stream_decoder_process_one_frame (flacdec->decoder);
+ }
+ while (!GST_ELEMENT_IS_COTHREAD_STOPPING (element));
+}
+
diff --git a/ext/flac/gstflacdec.h b/ext/flac/gstflacdec.h
new file mode 100644
index 00000000..ed0cb43f
--- /dev/null
+++ b/ext/flac/gstflacdec.h
@@ -0,0 +1,70 @@
+/* Gnome-Streamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+
+#ifndef __FLACDEC_H__
+#define __FLACDEC_H__
+
+
+#include <config.h>
+#include <gst/gst.h>
+
+#include <FLAC/all.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+#define GST_TYPE_FLACDEC flacdec_get_type()
+#define GST_FLACDEC(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, GST_TYPE_FLACDEC, FlacDec)
+#define GST_FLACDEC_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, GST_TYPE_FLACDEC, FlacDec)
+#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;
+
+struct _FlacDec {
+ GstElement element;
+
+ GstPad *sinkpad,*srcpad;
+
+ FLAC__StreamDecoder *decoder;
+
+ gint offset_left;
+ GstBuffer *data_left;
+
+ gboolean eos;
+ guint state;
+};
+
+struct _FlacDecClass {
+ GstElementClass parent_class;
+};
+
+GType flacdec_get_type(void);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+
+#endif /* __FLACDEC_H__ */
diff --git a/ext/flac/gstflacenc.c b/ext/flac/gstflacenc.c
index de532f3a..8167f776 100644
--- a/ext/flac/gstflacenc.c
+++ b/ext/flac/gstflacenc.c
@@ -21,7 +21,6 @@
#include <stdlib.h>
#include <string.h>
-#include <gst/gstarch.h>
#include <gstflacenc.h>
extern GstPadTemplate *enc_src_template, *enc_sink_template;
diff --git a/ext/flac/gstflacenc.h b/ext/flac/gstflacenc.h
new file mode 100644
index 00000000..1fe5e900
--- /dev/null
+++ b/ext/flac/gstflacenc.h
@@ -0,0 +1,68 @@
+/* GStreamer
+ * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+
+#ifndef __FLACENC_H__
+#define __FLACENC_H__
+
+
+#include <config.h>
+#include <gst/gst.h>
+
+#include <FLAC/all.h>
+
+#ifdef __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)
+#define GST_FLACENC_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, GST_TYPE_FLACENC, FlacEnc)
+#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;
+
+struct _FlacEnc {
+ GstElement element;
+
+ GstPad *sinkpad,*srcpad;
+
+ gboolean eos;
+ gint channels;
+ gint depth;
+ gint sample_rate;
+
+ FLAC__StreamEncoder *encoder;
+};
+
+struct _FlacEncClass {
+ GstElementClass parent_class;
+};
+
+GType flacenc_get_type(void);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+
+#endif /* __FLACENC_H__ */