mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 12:11:13 +00:00
adding flac
Original commit message from CVS: adding flac
This commit is contained in:
parent
1dcf747efc
commit
56f271163b
9 changed files with 554 additions and 26 deletions
3
TODO
3
TODO
|
@ -22,3 +22,6 @@
|
||||||
|
|
||||||
* riff: do we need those cflags ?
|
* riff: do we need those cflags ?
|
||||||
|
|
||||||
|
* festival should have checks and stuff and added properly
|
||||||
|
|
||||||
|
* fix ffmpeg
|
||||||
|
|
28
configure.ac
28
configure.ac
|
@ -457,9 +457,10 @@ GST_CHECK_FEATURE(ESD, [esound plugins], esdsrc esdsink, [
|
||||||
dnl *** FLAC ***
|
dnl *** FLAC ***
|
||||||
dnl thomas : checking for compile with main instead of actual function,
|
dnl thomas : checking for compile with main instead of actual function,
|
||||||
dnl since that made autoconf break (for version 2.13)
|
dnl since that made autoconf break (for version 2.13)
|
||||||
translit(dnm, m, l) AM_CONDITIONAL(USE_LIBFLAC, true)
|
translit(dnm, m, l) AM_CONDITIONAL(USE_FLAC, true)
|
||||||
GST_CHECK_FEATURE(FLACLIB, [FLAC lossless audio], flacenc flacdec, [
|
GST_CHECK_FEATURE(FLAC, [FLAC lossless audio], flacenc flacdec, [
|
||||||
GST_CHECK_LIBHEADER(FLACLIB, FLAC, main, -lm, FLAC/all.h, LIBFLAC_LIBS="-lFLAC")
|
GST_CHECK_LIBHEADER(FLAC, FLAC, main, -lm, FLAC/all.h, FLAC_LIBS="-lFLAC")
|
||||||
|
AC_SUBST(FLAC_LIBS)
|
||||||
])
|
])
|
||||||
|
|
||||||
dnl *** Gnome VFS ***
|
dnl *** Gnome VFS ***
|
||||||
|
@ -478,10 +479,10 @@ GST_CHECK_LIBHEADER(LIBGSM, gsm, gsm_create, , gsm/gsm.h, LIBGSM_LIBS="-lgsm")
|
||||||
])
|
])
|
||||||
|
|
||||||
dnl *** Hermes ***
|
dnl *** Hermes ***
|
||||||
translit(dnm, m, l) AM_CONDITIONAL(USE_LIBHERMES, true)
|
translit(dnm, m, l) AM_CONDITIONAL(USE_HERMES, true)
|
||||||
GST_CHECK_FEATURE(LIBHERMES, [Hermes library], colorspace, [
|
GST_CHECK_FEATURE(HERMES, [Hermes library], colorspace, [
|
||||||
GST_CHECK_LIBHEADER(LIBHERMES, Hermes, Hermes_ConverterInstance, , Hermes/Hermes.h, LIBHERMES_LIBS="-lHermes")
|
GST_CHECK_LIBHEADER(HERMES, Hermes, Hermes_ConverterInstance, , Hermes/Hermes.h, HERMES_LIBS="-lHermes")
|
||||||
], AC_SUBST(LIBHERMES_LIBS))
|
], AC_SUBST(HERMES_LIBS))
|
||||||
|
|
||||||
dnl *** lame ***
|
dnl *** lame ***
|
||||||
translit(dnm, m, l) AM_CONDITIONAL(USE_LAME, true)
|
translit(dnm, m, l) AM_CONDITIONAL(USE_LAME, true)
|
||||||
|
@ -871,10 +872,6 @@ if test "x$HAVE_A52DEC" = xyes; then
|
||||||
AC_DEFINE(HAVE_A52DEC)
|
AC_DEFINE(HAVE_A52DEC)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test "x$HAVE_FLACLIB" = xyes; then
|
|
||||||
AC_DEFINE(HAVE_FLACLIB)
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test "x$HAVE_LIBGSM" = xyes; then
|
if test "x$HAVE_LIBGSM" = xyes; then
|
||||||
AC_DEFINE(HAVE_LIBGSM)
|
AC_DEFINE(HAVE_LIBGSM)
|
||||||
fi
|
fi
|
||||||
|
@ -916,14 +913,6 @@ AM_CONDITIONAL(HAVE_XSLTPROC, $HAVE_XSLTPROC)
|
||||||
AM_CONDITIONAL(HAVE_FIG2DEV_PNG, $HAVE_FIG2DEV_PNG)
|
AM_CONDITIONAL(HAVE_FIG2DEV_PNG, $HAVE_FIG2DEV_PNG)
|
||||||
AM_CONDITIONAL(HAVE_FIG2DEV_PDF, $HAVE_FIG2DEV_PDF)
|
AM_CONDITIONAL(HAVE_FIG2DEV_PDF, $HAVE_FIG2DEV_PDF)
|
||||||
AM_CONDITIONAL(HAVE_LIBSHOUT, test "x$HAVE_LIBSHOUT" = "xyes")
|
AM_CONDITIONAL(HAVE_LIBSHOUT, test "x$HAVE_LIBSHOUT" = "xyes")
|
||||||
AM_CONDITIONAL(HAVE_A52DEC, test "x$HAVE_A52DEC" = "xyes")
|
|
||||||
AM_CONDITIONAL(HAVE_AVIFILE, test "x$HAVE_AVIFILE" = "xyes")
|
|
||||||
dnl thomas : the next line gives errors, this is how it is in CVS
|
|
||||||
dnl AM_CONDITIONAL(HAVE_FLAC, test "x$HAVE_FLAC" = "xyes")
|
|
||||||
dnl thomas : the next line gives errors as well, I commented it
|
|
||||||
dnl AM_CONDITIONAL(HAVE_LAC, test "x$HAVE_FAC" = "xyes")
|
|
||||||
dnl thomas: the next line doesn't give errors
|
|
||||||
AM_CONDITIONAL(HAVE_FLACLIB, test "x$HAVE_FLACLIB" = "xyes")
|
|
||||||
AM_CONDITIONAL(HAVE_LIBRTP, test "x$HAVE_LIBRTP" = "xyes")
|
AM_CONDITIONAL(HAVE_LIBRTP, test "x$HAVE_LIBRTP" = "xyes")
|
||||||
AM_CONDITIONAL(HAVE_ARTS, test "x$HAVE_ARTS" = "xyes")
|
AM_CONDITIONAL(HAVE_ARTS, test "x$HAVE_ARTS" = "xyes")
|
||||||
AM_CONDITIONAL(HAVE_XMMS, test "x$HAVE_XMMS" = "xyes")
|
AM_CONDITIONAL(HAVE_XMMS, test "x$HAVE_XMMS" = "xyes")
|
||||||
|
@ -1086,6 +1075,7 @@ ext/avifile/Makefile
|
||||||
ext/cdparanoia/Makefile
|
ext/cdparanoia/Makefile
|
||||||
ext/dvdread/Makefile
|
ext/dvdread/Makefile
|
||||||
ext/esd/Makefile
|
ext/esd/Makefile
|
||||||
|
ext/flac/Makefile
|
||||||
ext/lame/Makefile
|
ext/lame/Makefile
|
||||||
ext/mad/Makefile
|
ext/mad/Makefile
|
||||||
ext/mpeg2dec/Makefile
|
ext/mpeg2dec/Makefile
|
||||||
|
|
|
@ -46,10 +46,16 @@ else
|
||||||
ESD_DIR=
|
ESD_DIR=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if USE_FESTIVAL
|
## if USE_FESTIVAL
|
||||||
FESTIVAL_DIR=festival
|
## FESTIVAL_DIR=festival
|
||||||
else
|
## else
|
||||||
FESTIVAL_DIR=
|
FESTIVAL_DIR=
|
||||||
|
## endif
|
||||||
|
|
||||||
|
if USE_FLAC
|
||||||
|
FLAC_DIR=flac
|
||||||
|
else
|
||||||
|
FLAC_DIR=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if USE_LAME
|
if USE_LAME
|
||||||
|
@ -84,8 +90,9 @@ endif
|
||||||
|
|
||||||
SUBDIRS=$(A52_DIR) $(AALIB_DIR) $(ALSA_DIR) $(AUDIOFILE_DIR) \
|
SUBDIRS=$(A52_DIR) $(AALIB_DIR) $(ALSA_DIR) $(AUDIOFILE_DIR) \
|
||||||
$(AVIFILE_DIR) $(CDPARANOIA_DIR) $(DVDREAD_DIR) $(ESD_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)
|
$(SDL_DIR) $(VORBIS_DIR)
|
||||||
|
|
||||||
DIST_SUBDIRS=a52 aalib alsa avifile audiofile cdparanoia dvdread esd \
|
DIST_SUBDIRS=a52 aalib alsa avifile audiofile cdparanoia dvdread esd \
|
||||||
festival lame mad mpeg2dec sdl vorbis
|
festival flac lame mad mpeg2dec sdl vorbis
|
||||||
|
|
|
@ -7,4 +7,4 @@ libgstflac_la_SOURCES = gstflac.c gstflacenc.c gstflacdec.c
|
||||||
noinst_HEADERS = gstflacenc.h gstflacdec.h
|
noinst_HEADERS = gstflacenc.h gstflacdec.h
|
||||||
|
|
||||||
libgstflac_la_CFLAGS = $(GST_CFLAGS)
|
libgstflac_la_CFLAGS = $(GST_CFLAGS)
|
||||||
libgstflac_la_LIBADD = $(GST_LIBS)
|
libgstflac_la_LIBADD = $(GST_LIBS) $(FLAC_LIBS)
|
||||||
|
|
141
ext/flac/gstflac.c
Normal file
141
ext/flac/gstflac.c
Normal file
|
@ -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
|
||||||
|
};
|
250
ext/flac/gstflacdec.c
Normal file
250
ext/flac/gstflacdec.c
Normal file
|
@ -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));
|
||||||
|
}
|
||||||
|
|
70
ext/flac/gstflacdec.h
Normal file
70
ext/flac/gstflacdec.h
Normal file
|
@ -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__ */
|
|
@ -21,7 +21,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <gst/gstarch.h>
|
|
||||||
#include <gstflacenc.h>
|
#include <gstflacenc.h>
|
||||||
|
|
||||||
extern GstPadTemplate *enc_src_template, *enc_sink_template;
|
extern GstPadTemplate *enc_src_template, *enc_sink_template;
|
||||||
|
|
68
ext/flac/gstflacenc.h
Normal file
68
ext/flac/gstflacenc.h
Normal file
|
@ -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__ */
|
Loading…
Reference in a new issue