summaryrefslogtreecommitdiff
path: root/ext/wavpack
diff options
context:
space:
mode:
authorjk7744.park <jk7744.park@samsung.com>2015-02-01 13:44:31 +0900
committerjk7744.park <jk7744.park@samsung.com>2015-02-01 13:44:31 +0900
commit73ea2d7db1c622705a034dc3aa73b02693bc9aad (patch)
tree8ec6ded7aa6ffd57bc2b0c1a44d70dc1d46d4be3 /ext/wavpack
parent9e1f49bdfcf5a218296206db6db790187c114084 (diff)
downloadgst-plugins-good0.10-tizen_2.3.tar.gz
gst-plugins-good0.10-tizen_2.3.tar.bz2
gst-plugins-good0.10-tizen_2.3.zip
Diffstat (limited to 'ext/wavpack')
-rw-r--r--ext/wavpack/Makefile.am24
-rw-r--r--ext/wavpack/Makefile.in868
-rw-r--r--ext/wavpack/gstwavpack.c56
-rw-r--r--ext/wavpack/gstwavpackcommon.c282
-rw-r--r--ext/wavpack/gstwavpackcommon.h75
-rw-r--r--ext/wavpack/gstwavpackdec.c512
-rw-r--r--ext/wavpack/gstwavpackdec.h80
-rw-r--r--ext/wavpack/gstwavpackenc.c1049
-rw-r--r--ext/wavpack/gstwavpackenc.h104
-rw-r--r--ext/wavpack/gstwavpackparse.c1344
-rw-r--r--ext/wavpack/gstwavpackparse.h97
-rw-r--r--ext/wavpack/gstwavpackstreamreader.c124
-rw-r--r--ext/wavpack/gstwavpackstreamreader.h36
13 files changed, 4651 insertions, 0 deletions
diff --git a/ext/wavpack/Makefile.am b/ext/wavpack/Makefile.am
new file mode 100644
index 0000000..70d2431
--- /dev/null
+++ b/ext/wavpack/Makefile.am
@@ -0,0 +1,24 @@
+plugin_LTLIBRARIES = libgstwavpack.la
+
+libgstwavpack_la_SOURCES = \
+ gstwavpack.c \
+ gstwavpackcommon.c \
+ gstwavpackparse.c \
+ gstwavpackdec.c \
+ gstwavpackenc.c \
+ gstwavpackstreamreader.c
+
+libgstwavpack_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) \
+ $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(WAVPACK_CFLAGS)
+libgstwavpack_la_LIBADD = $(GST_PLUGINS_BASE_LIBS) -lgstaudio-$(GST_MAJORMINOR) \
+ $(GST_BASE_LIBS) $(GST_LIBS) $(WAVPACK_LIBS)
+libgstwavpack_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
+libgstwavpack_la_LIBTOOLFLAGS = --tag=disable-static
+
+noinst_HEADERS = \
+ gstwavpackparse.h \
+ gstwavpackdec.h \
+ gstwavpackenc.h \
+ gstwavpackcommon.h \
+ gstwavpackstreamreader.h
+
diff --git a/ext/wavpack/Makefile.in b/ext/wavpack/Makefile.in
new file mode 100644
index 0000000..4eb1dd1
--- /dev/null
+++ b/ext/wavpack/Makefile.in
@@ -0,0 +1,868 @@
+# Makefile.in generated by automake 1.11.3 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = ext/wavpack
+DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
+ $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/common/m4/as-ac-expand.m4 \
+ $(top_srcdir)/common/m4/as-auto-alt.m4 \
+ $(top_srcdir)/common/m4/as-compiler-flag.m4 \
+ $(top_srcdir)/common/m4/as-gcc-inline-assembly.m4 \
+ $(top_srcdir)/common/m4/as-objc.m4 \
+ $(top_srcdir)/common/m4/as-python.m4 \
+ $(top_srcdir)/common/m4/as-scrub-include.m4 \
+ $(top_srcdir)/common/m4/as-version.m4 \
+ $(top_srcdir)/common/m4/ax_create_stdint_h.m4 \
+ $(top_srcdir)/common/m4/gst-arch.m4 \
+ $(top_srcdir)/common/m4/gst-args.m4 \
+ $(top_srcdir)/common/m4/gst-check.m4 \
+ $(top_srcdir)/common/m4/gst-default.m4 \
+ $(top_srcdir)/common/m4/gst-dowhile.m4 \
+ $(top_srcdir)/common/m4/gst-error.m4 \
+ $(top_srcdir)/common/m4/gst-feature.m4 \
+ $(top_srcdir)/common/m4/gst-gettext.m4 \
+ $(top_srcdir)/common/m4/gst-glib2.m4 \
+ $(top_srcdir)/common/m4/gst-package-release-datetime.m4 \
+ $(top_srcdir)/common/m4/gst-platform.m4 \
+ $(top_srcdir)/common/m4/gst-plugin-docs.m4 \
+ $(top_srcdir)/common/m4/gst-plugindir.m4 \
+ $(top_srcdir)/common/m4/gst-x11.m4 \
+ $(top_srcdir)/common/m4/gst.m4 \
+ $(top_srcdir)/common/m4/gtk-doc.m4 \
+ $(top_srcdir)/common/m4/orc.m4 $(top_srcdir)/common/m4/pkg.m4 \
+ $(top_srcdir)/m4/aalib.m4 $(top_srcdir)/m4/esd.m4 \
+ $(top_srcdir)/m4/gconf-2.m4 $(top_srcdir)/m4/gettext.m4 \
+ $(top_srcdir)/m4/gst-fionread.m4 $(top_srcdir)/m4/iconv.m4 \
+ $(top_srcdir)/m4/intlmacosx.m4 $(top_srcdir)/m4/lib-ld.m4 \
+ $(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \
+ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
+ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
+ $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \
+ $(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \
+ $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+ *) f=$$p;; \
+ esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+ for p in $$list; do echo "$$p $$p"; done | \
+ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+ if (++n[$$2] == $(am__install_max)) \
+ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+ END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__uninstall_files_from_dir = { \
+ test -z "$$files" \
+ || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+ $(am__cd) "$$dir" && rm -f $$files; }; \
+ }
+am__installdirs = "$(DESTDIR)$(plugindir)"
+LTLIBRARIES = $(plugin_LTLIBRARIES)
+am__DEPENDENCIES_1 =
+libgstwavpack_la_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+ $(am__DEPENDENCIES_1)
+am_libgstwavpack_la_OBJECTS = libgstwavpack_la-gstwavpack.lo \
+ libgstwavpack_la-gstwavpackcommon.lo \
+ libgstwavpack_la-gstwavpackparse.lo \
+ libgstwavpack_la-gstwavpackdec.lo \
+ libgstwavpack_la-gstwavpackenc.lo \
+ libgstwavpack_la-gstwavpackstreamreader.lo
+libgstwavpack_la_OBJECTS = $(am_libgstwavpack_la_OBJECTS)
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+libgstwavpack_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+ $(libgstwavpack_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link \
+ $(CCLD) $(libgstwavpack_la_CFLAGS) $(CFLAGS) \
+ $(libgstwavpack_la_LDFLAGS) $(LDFLAGS) -o $@
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo " CC " $@;
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+CCLD = $(CC)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo " CCLD " $@;
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo " GEN " $@;
+SOURCES = $(libgstwavpack_la_SOURCES)
+DIST_SOURCES = $(libgstwavpack_la_SOURCES)
+HEADERS = $(noinst_HEADERS)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+AALIB_CFLAGS = @AALIB_CFLAGS@
+AALIB_CONFIG = @AALIB_CONFIG@
+AALIB_LIBS = @AALIB_LIBS@
+ACLOCAL = @ACLOCAL@
+ACLOCAL_AMFLAGS = @ACLOCAL_AMFLAGS@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+ANNODEX_CFLAGS = @ANNODEX_CFLAGS@
+ANNODEX_LIBS = @ANNODEX_LIBS@
+AR = @AR@
+AS = @AS@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+BZ2_LIBS = @BZ2_LIBS@
+CAIRO_CFLAGS = @CAIRO_CFLAGS@
+CAIRO_GOBJECT_CFLAGS = @CAIRO_GOBJECT_CFLAGS@
+CAIRO_GOBJECT_LIBS = @CAIRO_GOBJECT_LIBS@
+CAIRO_LIBS = @CAIRO_LIBS@
+CC = @CC@
+CCAS = @CCAS@
+CCASDEPMODE = @CCASDEPMODE@
+CCASFLAGS = @CCASFLAGS@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFAULT_AUDIOSINK = @DEFAULT_AUDIOSINK@
+DEFAULT_AUDIOSRC = @DEFAULT_AUDIOSRC@
+DEFAULT_VIDEOSINK = @DEFAULT_VIDEOSINK@
+DEFAULT_VIDEOSRC = @DEFAULT_VIDEOSRC@
+DEFAULT_VISUALIZER = @DEFAULT_VISUALIZER@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DEPRECATED_CFLAGS = @DEPRECATED_CFLAGS@
+DIRECTSOUND_CFLAGS = @DIRECTSOUND_CFLAGS@
+DIRECTSOUND_LDFLAGS = @DIRECTSOUND_LDFLAGS@
+DIRECTSOUND_LIBS = @DIRECTSOUND_LIBS@
+DLLTOOL = @DLLTOOL@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+DV1394_CFLAGS = @DV1394_CFLAGS@
+DV1394_LIBS = @DV1394_LIBS@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+ERROR_CFLAGS = @ERROR_CFLAGS@
+ERROR_CXXFLAGS = @ERROR_CXXFLAGS@
+ESD_CFLAGS = @ESD_CFLAGS@
+ESD_CONFIG = @ESD_CONFIG@
+ESD_LIBS = @ESD_LIBS@
+EXEEXT = @EXEEXT@
+FFLAGS = @FFLAGS@
+FGREP = @FGREP@
+FLAC_CFLAGS = @FLAC_CFLAGS@
+FLAC_LIBS = @FLAC_LIBS@
+GCONFTOOL = @GCONFTOOL@
+GCONF_CFLAGS = @GCONF_CFLAGS@
+GCONF_LIBS = @GCONF_LIBS@
+GCONF_SCHEMA_CONFIG_SOURCE = @GCONF_SCHEMA_CONFIG_SOURCE@
+GCONF_SCHEMA_FILE_DIR = @GCONF_SCHEMA_FILE_DIR@
+GCOV = @GCOV@
+GCOV_CFLAGS = @GCOV_CFLAGS@
+GCOV_LIBS = @GCOV_LIBS@
+GDK_PIXBUF_CFLAGS = @GDK_PIXBUF_CFLAGS@
+GDK_PIXBUF_LIBS = @GDK_PIXBUF_LIBS@
+GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@
+GETTEXT_PACKAGE = @GETTEXT_PACKAGE@
+GIO_CFLAGS = @GIO_CFLAGS@
+GIO_LIBS = @GIO_LIBS@
+GLIB_CFLAGS = @GLIB_CFLAGS@
+GLIB_EXTRA_CFLAGS = @GLIB_EXTRA_CFLAGS@
+GLIB_LIBS = @GLIB_LIBS@
+GLIB_PREFIX = @GLIB_PREFIX@
+GLIB_REQ = @GLIB_REQ@
+GMSGFMT = @GMSGFMT@
+GMSGFMT_015 = @GMSGFMT_015@
+GREP = @GREP@
+GSTPB_PLUGINS_DIR = @GSTPB_PLUGINS_DIR@
+GSTPB_PREFIX = @GSTPB_PREFIX@
+GST_ALL_LDFLAGS = @GST_ALL_LDFLAGS@
+GST_BASE_CFLAGS = @GST_BASE_CFLAGS@
+GST_BASE_LIBS = @GST_BASE_LIBS@
+GST_CFLAGS = @GST_CFLAGS@
+GST_CHECK_CFLAGS = @GST_CHECK_CFLAGS@
+GST_CHECK_LIBS = @GST_CHECK_LIBS@
+GST_CONTROLLER_CFLAGS = @GST_CONTROLLER_CFLAGS@
+GST_CONTROLLER_LIBS = @GST_CONTROLLER_LIBS@
+GST_CXXFLAGS = @GST_CXXFLAGS@
+GST_GDP_CFLAGS = @GST_GDP_CFLAGS@
+GST_GDP_LIBS = @GST_GDP_LIBS@
+GST_LEVEL_DEFAULT = @GST_LEVEL_DEFAULT@
+GST_LIBS = @GST_LIBS@
+GST_LICENSE = @GST_LICENSE@
+GST_LT_LDFLAGS = @GST_LT_LDFLAGS@
+GST_MAJORMINOR = @GST_MAJORMINOR@
+GST_OPTION_CFLAGS = @GST_OPTION_CFLAGS@
+GST_OPTION_CXXFLAGS = @GST_OPTION_CXXFLAGS@
+GST_PACKAGE_NAME = @GST_PACKAGE_NAME@
+GST_PACKAGE_ORIGIN = @GST_PACKAGE_ORIGIN@
+GST_PLUGINS_ALL = @GST_PLUGINS_ALL@
+GST_PLUGINS_BASE_CFLAGS = @GST_PLUGINS_BASE_CFLAGS@
+GST_PLUGINS_BASE_DIR = @GST_PLUGINS_BASE_DIR@
+GST_PLUGINS_BASE_LIBS = @GST_PLUGINS_BASE_LIBS@
+GST_PLUGINS_DIR = @GST_PLUGINS_DIR@
+GST_PLUGINS_SELECTED = @GST_PLUGINS_SELECTED@
+GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@
+GST_PREFIX = @GST_PREFIX@
+GST_TOOLS_DIR = @GST_TOOLS_DIR@
+GTKDOC_CHECK = @GTKDOC_CHECK@
+GTK_CFLAGS = @GTK_CFLAGS@
+GTK_LIBS = @GTK_LIBS@
+GTK_X11_CFLAGS = @GTK_X11_CFLAGS@
+GTK_X11_LIBS = @GTK_X11_LIBS@
+GUDEV_CFLAGS = @GUDEV_CFLAGS@
+GUDEV_LIBS = @GUDEV_LIBS@
+HAL_CFLAGS = @HAL_CFLAGS@
+HAL_LIBS = @HAL_LIBS@
+HAVE_AVC1394 = @HAVE_AVC1394@
+HAVE_BZ2 = @HAVE_BZ2@
+HAVE_CXX = @HAVE_CXX@
+HAVE_DIRECTSOUND = @HAVE_DIRECTSOUND@
+HAVE_GCONFTOOL = @HAVE_GCONFTOOL@
+HAVE_ROM1394 = @HAVE_ROM1394@
+HAVE_SPEEX = @HAVE_SPEEX@
+HAVE_X = @HAVE_X@
+HAVE_XSHM = @HAVE_XSHM@
+HAVE_ZLIB = @HAVE_ZLIB@
+HTML_DIR = @HTML_DIR@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+INTLLIBS = @INTLLIBS@
+INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@
+JACK_0_120_1_CFLAGS = @JACK_0_120_1_CFLAGS@
+JACK_0_120_1_LIBS = @JACK_0_120_1_LIBS@
+JACK_1_9_7_CFLAGS = @JACK_1_9_7_CFLAGS@
+JACK_1_9_7_LIBS = @JACK_1_9_7_LIBS@
+JACK_CFLAGS = @JACK_CFLAGS@
+JACK_LIBS = @JACK_LIBS@
+JPEG_LIBS = @JPEG_LIBS@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBCACA_CFLAGS = @LIBCACA_CFLAGS@
+LIBCACA_LIBS = @LIBCACA_LIBS@
+LIBDV_CFLAGS = @LIBDV_CFLAGS@
+LIBDV_LIBS = @LIBDV_LIBS@
+LIBICONV = @LIBICONV@
+LIBIEC61883_CFLAGS = @LIBIEC61883_CFLAGS@
+LIBIEC61883_LIBS = @LIBIEC61883_LIBS@
+LIBINTL = @LIBINTL@
+LIBM = @LIBM@
+LIBOBJS = @LIBOBJS@
+LIBPNG_CFLAGS = @LIBPNG_CFLAGS@
+LIBPNG_LIBS = @LIBPNG_LIBS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIBV4L2_CFLAGS = @LIBV4L2_CFLAGS@
+LIBV4L2_LIBS = @LIBV4L2_LIBS@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LOCALEDIR = @LOCALEDIR@
+LTLIBICONV = @LTLIBICONV@
+LTLIBINTL = @LTLIBINTL@
+LTLIBOBJS = @LTLIBOBJS@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MKDIR_P = @MKDIR_P@
+MSGFMT = @MSGFMT@
+MSGFMT_015 = @MSGFMT_015@
+MSGMERGE = @MSGMERGE@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJC = @OBJC@
+OBJCDEPMODE = @OBJCDEPMODE@
+OBJC_LDFLAGS = @OBJC_LDFLAGS@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+ORCC = @ORCC@
+ORCC_FLAGS = @ORCC_FLAGS@
+ORC_CFLAGS = @ORC_CFLAGS@
+ORC_LIBS = @ORC_LIBS@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PACKAGE_VERSION_MAJOR = @PACKAGE_VERSION_MAJOR@
+PACKAGE_VERSION_MICRO = @PACKAGE_VERSION_MICRO@
+PACKAGE_VERSION_MINOR = @PACKAGE_VERSION_MINOR@
+PACKAGE_VERSION_NANO = @PACKAGE_VERSION_NANO@
+PACKAGE_VERSION_RELEASE = @PACKAGE_VERSION_RELEASE@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+PLUGINDIR = @PLUGINDIR@
+POSUB = @POSUB@
+PROFILE_CFLAGS = @PROFILE_CFLAGS@
+PULSE_0_9_20_CFLAGS = @PULSE_0_9_20_CFLAGS@
+PULSE_0_9_20_LIBS = @PULSE_0_9_20_LIBS@
+PULSE_1_0_CFLAGS = @PULSE_1_0_CFLAGS@
+PULSE_1_0_LIBS = @PULSE_1_0_LIBS@
+PULSE_CFLAGS = @PULSE_CFLAGS@
+PULSE_LIBS = @PULSE_LIBS@
+PYTHON = @PYTHON@
+PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@
+PYTHON_PLATFORM = @PYTHON_PLATFORM@
+PYTHON_PREFIX = @PYTHON_PREFIX@
+PYTHON_VERSION = @PYTHON_VERSION@
+RANLIB = @RANLIB@
+RAW1394_CFLAGS = @RAW1394_CFLAGS@
+RAW1394_LIBS = @RAW1394_LIBS@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SHOUT2_CFLAGS = @SHOUT2_CFLAGS@
+SHOUT2_LIBS = @SHOUT2_LIBS@
+SOUP_CFLAGS = @SOUP_CFLAGS@
+SOUP_LIBS = @SOUP_LIBS@
+SPEEX_CFLAGS = @SPEEX_CFLAGS@
+SPEEX_LIBS = @SPEEX_LIBS@
+STRIP = @STRIP@
+TAGLIB_CFLAGS = @TAGLIB_CFLAGS@
+TAGLIB_CXXFLAGS = @TAGLIB_CXXFLAGS@
+TAGLIB_LIBS = @TAGLIB_LIBS@
+USE_NLS = @USE_NLS@
+VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
+VALGRIND_LIBS = @VALGRIND_LIBS@
+VALGRIND_PATH = @VALGRIND_PATH@
+VERSION = @VERSION@
+WARNING_CFLAGS = @WARNING_CFLAGS@
+WARNING_CXXFLAGS = @WARNING_CXXFLAGS@
+WAVPACK_CFLAGS = @WAVPACK_CFLAGS@
+WAVPACK_LIBS = @WAVPACK_LIBS@
+WIN32_LIBS = @WIN32_LIBS@
+XDAMAGE_CFLAGS = @XDAMAGE_CFLAGS@
+XDAMAGE_LIBS = @XDAMAGE_LIBS@
+XFIXES_CFLAGS = @XFIXES_CFLAGS@
+XFIXES_LIBS = @XFIXES_LIBS@
+XGETTEXT = @XGETTEXT@
+XGETTEXT_015 = @XGETTEXT_015@
+XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@
+XMKMF = @XMKMF@
+XSHM_LIBS = @XSHM_LIBS@
+XVIDEO_LIBS = @XVIDEO_LIBS@
+X_CFLAGS = @X_CFLAGS@
+X_EXTRA_LIBS = @X_EXTRA_LIBS@
+X_LIBS = @X_LIBS@
+X_PRE_LIBS = @X_PRE_LIBS@
+ZLIB_LIBS = @ZLIB_LIBS@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+ac_ct_OBJC = @ac_ct_OBJC@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+pkgpyexecdir = @pkgpyexecdir@
+pkgpythondir = @pkgpythondir@
+plugindir = @plugindir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+pyexecdir = @pyexecdir@
+pythondir = @pythondir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+plugin_LTLIBRARIES = libgstwavpack.la
+libgstwavpack_la_SOURCES = \
+ gstwavpack.c \
+ gstwavpackcommon.c \
+ gstwavpackparse.c \
+ gstwavpackdec.c \
+ gstwavpackenc.c \
+ gstwavpackstreamreader.c
+
+libgstwavpack_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) \
+ $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(WAVPACK_CFLAGS)
+
+libgstwavpack_la_LIBADD = $(GST_PLUGINS_BASE_LIBS) -lgstaudio-$(GST_MAJORMINOR) \
+ $(GST_BASE_LIBS) $(GST_LIBS) $(WAVPACK_LIBS)
+
+libgstwavpack_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
+libgstwavpack_la_LIBTOOLFLAGS = --tag=disable-static
+noinst_HEADERS = \
+ gstwavpackparse.h \
+ gstwavpackdec.h \
+ gstwavpackenc.h \
+ gstwavpackcommon.h \
+ gstwavpackstreamreader.h
+
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu ext/wavpack/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --gnu ext/wavpack/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+install-pluginLTLIBRARIES: $(plugin_LTLIBRARIES)
+ @$(NORMAL_INSTALL)
+ test -z "$(plugindir)" || $(MKDIR_P) "$(DESTDIR)$(plugindir)"
+ @list='$(plugin_LTLIBRARIES)'; test -n "$(plugindir)" || list=; \
+ list2=; for p in $$list; do \
+ if test -f $$p; then \
+ list2="$$list2 $$p"; \
+ else :; fi; \
+ done; \
+ test -z "$$list2" || { \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(plugindir)'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(plugindir)"; \
+ }
+
+uninstall-pluginLTLIBRARIES:
+ @$(NORMAL_UNINSTALL)
+ @list='$(plugin_LTLIBRARIES)'; test -n "$(plugindir)" || list=; \
+ for p in $$list; do \
+ $(am__strip_dir) \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(plugindir)/$$f'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(plugindir)/$$f"; \
+ done
+
+clean-pluginLTLIBRARIES:
+ -test -z "$(plugin_LTLIBRARIES)" || rm -f $(plugin_LTLIBRARIES)
+ @list='$(plugin_LTLIBRARIES)'; for p in $$list; do \
+ dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+ test "$$dir" != "$$p" || dir=.; \
+ echo "rm -f \"$${dir}/so_locations\""; \
+ rm -f "$${dir}/so_locations"; \
+ done
+libgstwavpack.la: $(libgstwavpack_la_OBJECTS) $(libgstwavpack_la_DEPENDENCIES) $(EXTRA_libgstwavpack_la_DEPENDENCIES)
+ $(AM_V_CCLD)$(libgstwavpack_la_LINK) -rpath $(plugindir) $(libgstwavpack_la_OBJECTS) $(libgstwavpack_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgstwavpack_la-gstwavpack.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgstwavpack_la-gstwavpackcommon.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgstwavpack_la-gstwavpackdec.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgstwavpack_la-gstwavpackenc.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgstwavpack_la-gstwavpackparse.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgstwavpack_la-gstwavpackstreamreader.Plo@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
+
+libgstwavpack_la-gstwavpack.lo: gstwavpack.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(libgstwavpack_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgstwavpack_la_CFLAGS) $(CFLAGS) -MT libgstwavpack_la-gstwavpack.lo -MD -MP -MF $(DEPDIR)/libgstwavpack_la-gstwavpack.Tpo -c -o libgstwavpack_la-gstwavpack.lo `test -f 'gstwavpack.c' || echo '$(srcdir)/'`gstwavpack.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libgstwavpack_la-gstwavpack.Tpo $(DEPDIR)/libgstwavpack_la-gstwavpack.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='gstwavpack.c' object='libgstwavpack_la-gstwavpack.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(libgstwavpack_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgstwavpack_la_CFLAGS) $(CFLAGS) -c -o libgstwavpack_la-gstwavpack.lo `test -f 'gstwavpack.c' || echo '$(srcdir)/'`gstwavpack.c
+
+libgstwavpack_la-gstwavpackcommon.lo: gstwavpackcommon.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(libgstwavpack_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgstwavpack_la_CFLAGS) $(CFLAGS) -MT libgstwavpack_la-gstwavpackcommon.lo -MD -MP -MF $(DEPDIR)/libgstwavpack_la-gstwavpackcommon.Tpo -c -o libgstwavpack_la-gstwavpackcommon.lo `test -f 'gstwavpackcommon.c' || echo '$(srcdir)/'`gstwavpackcommon.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libgstwavpack_la-gstwavpackcommon.Tpo $(DEPDIR)/libgstwavpack_la-gstwavpackcommon.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='gstwavpackcommon.c' object='libgstwavpack_la-gstwavpackcommon.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(libgstwavpack_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgstwavpack_la_CFLAGS) $(CFLAGS) -c -o libgstwavpack_la-gstwavpackcommon.lo `test -f 'gstwavpackcommon.c' || echo '$(srcdir)/'`gstwavpackcommon.c
+
+libgstwavpack_la-gstwavpackparse.lo: gstwavpackparse.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(libgstwavpack_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgstwavpack_la_CFLAGS) $(CFLAGS) -MT libgstwavpack_la-gstwavpackparse.lo -MD -MP -MF $(DEPDIR)/libgstwavpack_la-gstwavpackparse.Tpo -c -o libgstwavpack_la-gstwavpackparse.lo `test -f 'gstwavpackparse.c' || echo '$(srcdir)/'`gstwavpackparse.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libgstwavpack_la-gstwavpackparse.Tpo $(DEPDIR)/libgstwavpack_la-gstwavpackparse.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='gstwavpackparse.c' object='libgstwavpack_la-gstwavpackparse.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(libgstwavpack_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgstwavpack_la_CFLAGS) $(CFLAGS) -c -o libgstwavpack_la-gstwavpackparse.lo `test -f 'gstwavpackparse.c' || echo '$(srcdir)/'`gstwavpackparse.c
+
+libgstwavpack_la-gstwavpackdec.lo: gstwavpackdec.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(libgstwavpack_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgstwavpack_la_CFLAGS) $(CFLAGS) -MT libgstwavpack_la-gstwavpackdec.lo -MD -MP -MF $(DEPDIR)/libgstwavpack_la-gstwavpackdec.Tpo -c -o libgstwavpack_la-gstwavpackdec.lo `test -f 'gstwavpackdec.c' || echo '$(srcdir)/'`gstwavpackdec.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libgstwavpack_la-gstwavpackdec.Tpo $(DEPDIR)/libgstwavpack_la-gstwavpackdec.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='gstwavpackdec.c' object='libgstwavpack_la-gstwavpackdec.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(libgstwavpack_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgstwavpack_la_CFLAGS) $(CFLAGS) -c -o libgstwavpack_la-gstwavpackdec.lo `test -f 'gstwavpackdec.c' || echo '$(srcdir)/'`gstwavpackdec.c
+
+libgstwavpack_la-gstwavpackenc.lo: gstwavpackenc.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(libgstwavpack_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgstwavpack_la_CFLAGS) $(CFLAGS) -MT libgstwavpack_la-gstwavpackenc.lo -MD -MP -MF $(DEPDIR)/libgstwavpack_la-gstwavpackenc.Tpo -c -o libgstwavpack_la-gstwavpackenc.lo `test -f 'gstwavpackenc.c' || echo '$(srcdir)/'`gstwavpackenc.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libgstwavpack_la-gstwavpackenc.Tpo $(DEPDIR)/libgstwavpack_la-gstwavpackenc.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='gstwavpackenc.c' object='libgstwavpack_la-gstwavpackenc.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(libgstwavpack_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgstwavpack_la_CFLAGS) $(CFLAGS) -c -o libgstwavpack_la-gstwavpackenc.lo `test -f 'gstwavpackenc.c' || echo '$(srcdir)/'`gstwavpackenc.c
+
+libgstwavpack_la-gstwavpackstreamreader.lo: gstwavpackstreamreader.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(libgstwavpack_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgstwavpack_la_CFLAGS) $(CFLAGS) -MT libgstwavpack_la-gstwavpackstreamreader.lo -MD -MP -MF $(DEPDIR)/libgstwavpack_la-gstwavpackstreamreader.Tpo -c -o libgstwavpack_la-gstwavpackstreamreader.lo `test -f 'gstwavpackstreamreader.c' || echo '$(srcdir)/'`gstwavpackstreamreader.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libgstwavpack_la-gstwavpackstreamreader.Tpo $(DEPDIR)/libgstwavpack_la-gstwavpackstreamreader.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='gstwavpackstreamreader.c' object='libgstwavpack_la-gstwavpackstreamreader.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(libgstwavpack_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgstwavpack_la_CFLAGS) $(CFLAGS) -c -o libgstwavpack_la-gstwavpackstreamreader.lo `test -f 'gstwavpackstreamreader.c' || echo '$(srcdir)/'`gstwavpackstreamreader.c
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ set x; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
+ fi
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ test -z "$(CTAGS_ARGS)$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+ else \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LTLIBRARIES) $(HEADERS)
+installdirs:
+ for dir in "$(DESTDIR)$(plugindir)"; do \
+ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+ done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ if test -z '$(STRIP)'; then \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ install; \
+ else \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+ fi
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libtool clean-pluginLTLIBRARIES \
+ mostlyclean-am
+
+distclean: distclean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am: install-pluginLTLIBRARIES
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-pluginLTLIBRARIES
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+ clean-libtool clean-pluginLTLIBRARIES ctags distclean \
+ distclean-compile distclean-generic distclean-libtool \
+ distclean-tags distdir dvi dvi-am html html-am info info-am \
+ install install-am install-data install-data-am install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am install-man \
+ install-pdf install-pdf-am install-pluginLTLIBRARIES \
+ install-ps install-ps-am install-strip installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags uninstall uninstall-am uninstall-pluginLTLIBRARIES
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/ext/wavpack/gstwavpack.c b/ext/wavpack/gstwavpack.c
new file mode 100644
index 0000000..b01f443
--- /dev/null
+++ b/ext/wavpack/gstwavpack.c
@@ -0,0 +1,56 @@
+/* GStreamer wavpack plugin
+ * (c) 2004 Arwed v. Merkatz <v.merkatz@gmx.net>
+ *
+ * gstwavpack.c: plugin loader
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gst/gst-i18n-plugin.h>
+
+#include "gstwavpackparse.h"
+#include "gstwavpackdec.h"
+#include "gstwavpackenc.h"
+
+/* debug category for common code */
+GST_DEBUG_CATEGORY (wavpack_debug);
+
+static gboolean
+plugin_init (GstPlugin * plugin)
+{
+ GST_DEBUG_CATEGORY_INIT (wavpack_debug, "wavpack", 0, "Wavpack elements");
+
+#ifdef ENABLE_NLS
+ GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE,
+ LOCALEDIR);
+ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+#endif
+
+ return (gst_wavpack_parse_plugin_init (plugin)
+ && gst_wavpack_dec_plugin_init (plugin)
+ && gst_wavpack_enc_plugin_init (plugin));
+}
+
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
+ GST_VERSION_MINOR,
+ "wavpack",
+ "Wavpack lossless/lossy audio format handling",
+ plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
diff --git a/ext/wavpack/gstwavpackcommon.c b/ext/wavpack/gstwavpackcommon.c
new file mode 100644
index 0000000..252b64c
--- /dev/null
+++ b/ext/wavpack/gstwavpackcommon.c
@@ -0,0 +1,282 @@
+/* GStreamer Wavpack plugin
+ * Copyright (c) 2005 Arwed v. Merkatz <v.merkatz@gmx.net>
+ * Copyright (c) 1998 - 2005 Conifer Software
+ * Copyright (c) 2006 Sebastian Dröge <slomo@circular-chaos.org>
+ *
+ * gstwavpackcommon.c: common helper functions
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "gstwavpackcommon.h"
+#include <string.h>
+
+#include <gst/gst.h>
+#include <gst/audio/multichannel.h>
+
+GST_DEBUG_CATEGORY_EXTERN (wavpack_debug);
+#define GST_CAT_DEFAULT wavpack_debug
+
+gboolean
+gst_wavpack_read_header (WavpackHeader * header, guint8 * buf)
+{
+ g_memmove (header, buf, sizeof (WavpackHeader));
+
+#ifndef WAVPACK_OLD_API
+ WavpackLittleEndianToNative (header, (char *) WavpackHeaderFormat);
+#else
+ little_endian_to_native (header, WavpackHeaderFormat);
+#endif
+
+ return (memcmp (header->ckID, "wvpk", 4) == 0);
+}
+
+/* inspired by the original one in wavpack */
+gboolean
+gst_wavpack_read_metadata (GstWavpackMetadata * wpmd, guint8 * header_data,
+ guint8 ** p_data)
+{
+ WavpackHeader hdr;
+ guint8 *end;
+
+ gst_wavpack_read_header (&hdr, header_data);
+ end = header_data + hdr.ckSize + 8;
+
+ if (end - *p_data < 2)
+ return FALSE;
+
+ wpmd->id = GST_READ_UINT8 (*p_data);
+ wpmd->byte_length = 2 * (guint) GST_READ_UINT8 (*p_data + 1);
+
+ *p_data += 2;
+
+ if ((wpmd->id & ID_LARGE) == ID_LARGE) {
+ guint extra;
+
+ wpmd->id &= ~ID_LARGE;
+
+ if (end - *p_data < 2)
+ return FALSE;
+
+ extra = GST_READ_UINT16_LE (*p_data);
+ wpmd->byte_length += (extra << 9);
+ *p_data += 2;
+ }
+
+ if ((wpmd->id & ID_ODD_SIZE) == ID_ODD_SIZE) {
+ wpmd->id &= ~ID_ODD_SIZE;
+ --wpmd->byte_length;
+ }
+
+ if (wpmd->byte_length > 0) {
+ if (end - *p_data < wpmd->byte_length + (wpmd->byte_length & 1)) {
+ wpmd->data = NULL;
+ return FALSE;
+ }
+
+ wpmd->data = *p_data;
+ *p_data += wpmd->byte_length + (wpmd->byte_length & 1);
+ } else {
+ wpmd->data = NULL;
+ }
+
+ return TRUE;
+}
+
+gint
+gst_wavpack_get_default_channel_mask (gint nchannels)
+{
+ gint channel_mask = 0;
+
+ /* Set the default channel mask for the given number of channels.
+ * It's the same as for WAVE_FORMAT_EXTENDED:
+ * http://www.microsoft.com/whdc/device/audio/multichaud.mspx
+ */
+ switch (nchannels) {
+ case 11:
+ channel_mask |= 0x00400;
+ channel_mask |= 0x00200;
+ case 9:
+ channel_mask |= 0x00100;
+ case 8:
+ channel_mask |= 0x00080;
+ channel_mask |= 0x00040;
+ case 6:
+ channel_mask |= 0x00020;
+ channel_mask |= 0x00010;
+ case 4:
+ channel_mask |= 0x00008;
+ case 3:
+ channel_mask |= 0x00004;
+ case 2:
+ channel_mask |= 0x00002;
+ channel_mask |= 0x00001;
+ break;
+ case 1:
+ /* For mono use front center */
+ channel_mask |= 0x00004;
+ break;
+ }
+
+ return channel_mask;
+}
+
+static const struct
+{
+ const guint32 ms_mask;
+ const GstAudioChannelPosition gst_pos;
+} layout_mapping[] = {
+ {
+ 0x00001, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, {
+ 0x00002, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}, {
+ 0x00004, GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER}, {
+ 0x00008, GST_AUDIO_CHANNEL_POSITION_LFE}, {
+ 0x00010, GST_AUDIO_CHANNEL_POSITION_REAR_LEFT}, {
+ 0x00020, GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT}, {
+ 0x00040, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER}, {
+ 0x00080, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER}, {
+ 0x00100, GST_AUDIO_CHANNEL_POSITION_REAR_CENTER}, {
+ 0x00200, GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT}, {
+ 0x00400, GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT}, {
+ 0x00800, GST_AUDIO_CHANNEL_POSITION_INVALID}, /* TOP_CENTER */
+ {
+ 0x01000, GST_AUDIO_CHANNEL_POSITION_INVALID}, /* TOP_FRONT_LEFT */
+ {
+ 0x02000, GST_AUDIO_CHANNEL_POSITION_INVALID}, /* TOP_FRONT_CENTER */
+ {
+ 0x04000, GST_AUDIO_CHANNEL_POSITION_INVALID}, /* TOP_FRONT_RIGHT */
+ {
+ 0x08000, GST_AUDIO_CHANNEL_POSITION_INVALID}, /* TOP_BACK_LEFT */
+ {
+ 0x10000, GST_AUDIO_CHANNEL_POSITION_INVALID}, /* TOP_BACK_CENTER */
+ {
+ 0x20000, GST_AUDIO_CHANNEL_POSITION_INVALID} /* TOP_BACK_RIGHT */
+};
+
+#define MAX_CHANNEL_POSITIONS G_N_ELEMENTS (layout_mapping)
+
+gboolean
+gst_wavpack_set_channel_layout (GstCaps * caps, gint layout)
+{
+ GstAudioChannelPosition pos[MAX_CHANNEL_POSITIONS];
+ GstStructure *s;
+ gint num_channels, i, p;
+
+ s = gst_caps_get_structure (caps, 0);
+ if (!gst_structure_get_int (s, "channels", &num_channels))
+ g_return_val_if_reached (FALSE);
+
+ if (num_channels == 1 && layout == 0x00004) {
+ pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_MONO;
+ gst_audio_set_channel_positions (s, pos);
+ return TRUE;
+ }
+
+ p = 0;
+ for (i = 0; i < MAX_CHANNEL_POSITIONS; ++i) {
+ if ((layout & layout_mapping[i].ms_mask) != 0) {
+ if (p >= num_channels) {
+ GST_WARNING ("More bits set in the channel layout map than there "
+ "are channels! Broken file");
+ return FALSE;
+ }
+ if (layout_mapping[i].gst_pos == GST_AUDIO_CHANNEL_POSITION_INVALID) {
+ GST_WARNING ("Unsupported channel position (mask 0x%08x) in channel "
+ "layout map - ignoring those channels", layout_mapping[i].ms_mask);
+ /* what to do? just ignore it and let downstream deal with a channel
+ * layout that has INVALID positions in it for now ... */
+ }
+ pos[p] = layout_mapping[i].gst_pos;
+ ++p;
+ }
+ }
+
+ if (p != num_channels) {
+ GST_WARNING ("Only %d bits set in the channel layout map, but there are "
+ "supposed to be %d channels! Broken file", p, num_channels);
+ return FALSE;
+ }
+
+ gst_audio_set_channel_positions (s, pos);
+ return TRUE;
+}
+
+GstAudioChannelPosition *
+gst_wavpack_get_default_channel_positions (gint nchannels)
+{
+ GstAudioChannelPosition *pos = g_new (GstAudioChannelPosition, nchannels);
+ gint i;
+
+ if (nchannels == 1) {
+ pos[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER;
+ return pos;
+ }
+
+ for (i = 0; i < nchannels; i++)
+ pos[i] = layout_mapping[i].gst_pos;
+
+ return pos;
+}
+
+gint
+gst_wavpack_get_channel_mask_from_positions (GstAudioChannelPosition * pos,
+ gint nchannels)
+{
+ gint channel_mask = 0;
+ gint i, j;
+
+ if (nchannels == 1 && pos[0] == GST_AUDIO_CHANNEL_POSITION_FRONT_MONO) {
+ channel_mask = 0x00000004;
+ return channel_mask;
+ }
+
+ /* FIXME: not exactly efficient but otherwise we need an inverse
+ * mapping table too */
+ for (i = 0; i < nchannels; i++) {
+ for (j = 0; j < MAX_CHANNEL_POSITIONS; j++) {
+ if (pos[i] == layout_mapping[j].gst_pos) {
+ channel_mask |= layout_mapping[j].ms_mask;
+ break;
+ }
+ }
+ }
+
+ return channel_mask;
+}
+
+gboolean
+gst_wavpack_set_channel_mapping (GstAudioChannelPosition * pos, gint nchannels,
+ gint8 * channel_mapping)
+{
+ gint i, j;
+ gboolean ret = TRUE;
+
+ for (i = 0; i < nchannels; i++) {
+ for (j = 0; j < MAX_CHANNEL_POSITIONS; j++) {
+ if (pos[i] == layout_mapping[j].gst_pos) {
+ channel_mapping[i] = j;
+ ret &= (i == j);
+ break;
+ }
+ }
+ }
+
+ return !ret;
+}
diff --git a/ext/wavpack/gstwavpackcommon.h b/ext/wavpack/gstwavpackcommon.h
new file mode 100644
index 0000000..6a9e516
--- /dev/null
+++ b/ext/wavpack/gstwavpackcommon.h
@@ -0,0 +1,75 @@
+/* GStreamer Wavpack plugin
+ * Copyright (c) 2005 Arwed v. Merkatz <v.merkatz@gmx.net>
+ * Copyright (c) 2006 Sebastian Dröge <slomo@circular-chaos.org>
+ *
+ * gstwavpackcommon.h: common helper functions
+ *
+ * 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 __GST_WAVPACK_COMMON_H__
+#define __GST_WAVPACK_COMMON_H__
+
+#include <gst/gst.h>
+#include <gst/audio/multichannel.h>
+#include <wavpack/wavpack.h>
+
+typedef struct
+{
+ guint32 byte_length;
+ guint8 *data;
+ guint8 id;
+} GstWavpackMetadata;
+
+#define ID_UNIQUE 0x3f
+#define ID_OPTIONAL_DATA 0x20
+#define ID_ODD_SIZE 0x40
+#define ID_LARGE 0x80
+
+#define ID_DUMMY 0x0
+#define ID_ENCODER_INFO 0x1
+#define ID_DECORR_TERMS 0x2
+#define ID_DECORR_WEIGHTS 0x3
+#define ID_DECORR_SAMPLES 0x4
+#define ID_ENTROPY_VARS 0x5
+#define ID_HYBRID_PROFILE 0x6
+#define ID_SHAPING_WEIGHTS 0x7
+#define ID_FLOAT_INFO 0x8
+#define ID_INT32_INFO 0x9
+#define ID_WV_BITSTREAM 0xa
+#define ID_WVC_BITSTREAM 0xb
+#define ID_WVX_BITSTREAM 0xc
+#define ID_CHANNEL_INFO 0xd
+
+#define ID_RIFF_HEADER (ID_OPTIONAL_DATA | 0x1)
+#define ID_RIFF_TRAILER (ID_OPTIONAL_DATA | 0x2)
+#define ID_REPLAY_GAIN (ID_OPTIONAL_DATA | 0x3)
+#define ID_CUESHEET (ID_OPTIONAL_DATA | 0x4)
+#define ID_CONFIG_BLOCK (ID_OPTIONAL_DATA | 0x5)
+#define ID_MD5_CHECKSUM (ID_OPTIONAL_DATA | 0x6)
+#define ID_SAMPLE_RATE (ID_OPTIONAL_DATA | 0x7)
+
+
+gboolean gst_wavpack_read_header (WavpackHeader * header, guint8 * buf);
+gboolean gst_wavpack_read_metadata (GstWavpackMetadata * meta,
+ guint8 * header_data, guint8 ** p_data);
+gint gst_wavpack_get_default_channel_mask (gint nchannels);
+gboolean gst_wavpack_set_channel_layout (GstCaps * caps, gint layout);
+GstAudioChannelPosition *gst_wavpack_get_default_channel_positions (gint nchannels);
+gint gst_wavpack_get_channel_mask_from_positions (GstAudioChannelPosition *pos, gint nchannels);
+gboolean gst_wavpack_set_channel_mapping (GstAudioChannelPosition *pos, gint nchannels, gint8 *channel_mapping);
+
+#endif
diff --git a/ext/wavpack/gstwavpackdec.c b/ext/wavpack/gstwavpackdec.c
new file mode 100644
index 0000000..4ba242d
--- /dev/null
+++ b/ext/wavpack/gstwavpackdec.c
@@ -0,0 +1,512 @@
+/* GStreamer Wavpack plugin
+ * Copyright (c) 2005 Arwed v. Merkatz <v.merkatz@gmx.net>
+ * Copyright (c) 2006 Edward Hervey <bilboed@gmail.com>
+ * Copyright (c) 2006 Sebastian Dröge <slomo@circular-chaos.org>
+ *
+ * gstwavpackdec.c: raw Wavpack bitstream decoder
+ *
+ * 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.
+ */
+
+/**
+ * SECTION:element-wavpackdec
+ *
+ * WavpackDec decodes framed (for example by the WavpackParse element)
+ * Wavpack streams and decodes them to raw audio.
+ * <ulink url="http://www.wavpack.com/">Wavpack</ulink> is an open-source
+ * audio codec that features both lossless and lossy encoding.
+ *
+ * <refsect2>
+ * <title>Example launch line</title>
+ * |[
+ * gst-launch filesrc location=test.wv ! wavpackparse ! wavpackdec ! audioconvert ! audioresample ! autoaudiosink
+ * ]| This pipeline decodes the Wavpack file test.wv into raw audio buffers and
+ * tries to play it back using an automatically found audio sink.
+ * </refsect2>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gst/gst.h>
+#include <gst/audio/audio.h>
+#include <gst/audio/multichannel.h>
+
+#include <math.h>
+#include <string.h>
+
+#include <wavpack/wavpack.h>
+#include "gstwavpackdec.h"
+#include "gstwavpackcommon.h"
+#include "gstwavpackstreamreader.h"
+
+
+#define WAVPACK_DEC_MAX_ERRORS 16
+
+GST_DEBUG_CATEGORY_STATIC (gst_wavpack_dec_debug);
+#define GST_CAT_DEFAULT gst_wavpack_dec_debug
+
+static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
+ GST_PAD_SINK,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("audio/x-wavpack, "
+ "width = (int) [ 1, 32 ], "
+ "channels = (int) [ 1, 8 ], "
+ "rate = (int) [ 6000, 192000 ], " "framed = (boolean) true")
+ );
+
+static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
+ GST_PAD_SRC,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("audio/x-raw-int, "
+ "width = (int) 32, "
+ "depth = (int) [ 1, 32 ], "
+ "channels = (int) [ 1, 8 ], "
+ "rate = (int) [ 6000, 192000 ], "
+ "endianness = (int) BYTE_ORDER, " "signed = (boolean) true")
+ );
+
+static GstFlowReturn gst_wavpack_dec_chain (GstPad * pad, GstBuffer * buffer);
+static gboolean gst_wavpack_dec_sink_set_caps (GstPad * pad, GstCaps * caps);
+static gboolean gst_wavpack_dec_sink_event (GstPad * pad, GstEvent * event);
+static void gst_wavpack_dec_finalize (GObject * object);
+static GstStateChangeReturn gst_wavpack_dec_change_state (GstElement * element,
+ GstStateChange transition);
+static void gst_wavpack_dec_post_tags (GstWavpackDec * dec);
+
+GST_BOILERPLATE (GstWavpackDec, gst_wavpack_dec, GstElement, GST_TYPE_ELEMENT);
+
+static void
+gst_wavpack_dec_base_init (gpointer klass)
+{
+ GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
+
+ gst_element_class_add_static_pad_template (element_class, &src_factory);
+ gst_element_class_add_static_pad_template (element_class, &sink_factory);
+ gst_element_class_set_details_simple (element_class, "Wavpack audio decoder",
+ "Codec/Decoder/Audio",
+ "Decodes Wavpack audio data",
+ "Arwed v. Merkatz <v.merkatz@gmx.net>, "
+ "Sebastian Dröge <slomo@circular-chaos.org>");
+}
+
+static void
+gst_wavpack_dec_class_init (GstWavpackDecClass * klass)
+{
+ GObjectClass *gobject_class = (GObjectClass *) klass;
+ GstElementClass *gstelement_class = (GstElementClass *) klass;
+
+ gstelement_class->change_state =
+ GST_DEBUG_FUNCPTR (gst_wavpack_dec_change_state);
+ gobject_class->finalize = gst_wavpack_dec_finalize;
+}
+
+static void
+gst_wavpack_dec_reset (GstWavpackDec * dec)
+{
+ dec->wv_id.buffer = NULL;
+ dec->wv_id.position = dec->wv_id.length = 0;
+
+ dec->error_count = 0;
+
+ dec->channels = 0;
+ dec->channel_mask = 0;
+ dec->sample_rate = 0;
+ dec->depth = 0;
+
+ gst_segment_init (&dec->segment, GST_FORMAT_TIME);
+ dec->next_block_index = 0;
+}
+
+static void
+gst_wavpack_dec_init (GstWavpackDec * dec, GstWavpackDecClass * gklass)
+{
+ dec->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
+ gst_pad_set_chain_function (dec->sinkpad,
+ GST_DEBUG_FUNCPTR (gst_wavpack_dec_chain));
+ gst_pad_set_setcaps_function (dec->sinkpad,
+ GST_DEBUG_FUNCPTR (gst_wavpack_dec_sink_set_caps));
+ gst_pad_set_event_function (dec->sinkpad,
+ GST_DEBUG_FUNCPTR (gst_wavpack_dec_sink_event));
+ gst_element_add_pad (GST_ELEMENT (dec), dec->sinkpad);
+
+ dec->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
+ gst_pad_use_fixed_caps (dec->srcpad);
+ gst_element_add_pad (GST_ELEMENT (dec), dec->srcpad);
+
+ dec->context = NULL;
+ dec->stream_reader = gst_wavpack_stream_reader_new ();
+
+ gst_wavpack_dec_reset (dec);
+}
+
+static void
+gst_wavpack_dec_finalize (GObject * object)
+{
+ GstWavpackDec *dec = GST_WAVPACK_DEC (object);
+
+ g_free (dec->stream_reader);
+ dec->stream_reader = NULL;
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static gboolean
+gst_wavpack_dec_sink_set_caps (GstPad * pad, GstCaps * caps)
+{
+ GstWavpackDec *dec = GST_WAVPACK_DEC (gst_pad_get_parent (pad));
+ GstStructure *structure = gst_caps_get_structure (caps, 0);
+
+ /* Check if we can set the caps here already */
+ if (gst_structure_get_int (structure, "channels", &dec->channels) &&
+ gst_structure_get_int (structure, "rate", &dec->sample_rate) &&
+ gst_structure_get_int (structure, "width", &dec->depth)) {
+ GstCaps *caps;
+ GstAudioChannelPosition *pos;
+
+ caps = gst_caps_new_simple ("audio/x-raw-int",
+ "rate", G_TYPE_INT, dec->sample_rate,
+ "channels", G_TYPE_INT, dec->channels,
+ "depth", G_TYPE_INT, dec->depth,
+ "width", G_TYPE_INT, 32,
+ "endianness", G_TYPE_INT, G_BYTE_ORDER,
+ "signed", G_TYPE_BOOLEAN, TRUE, NULL);
+
+ /* If we already have the channel layout set from upstream
+ * take this */
+ if (gst_structure_has_field (structure, "channel-positions")) {
+ pos = gst_audio_get_channel_positions (structure);
+ if (pos != NULL && dec->channels > 2) {
+ GstStructure *new_str = gst_caps_get_structure (caps, 0);
+
+ gst_audio_set_channel_positions (new_str, pos);
+ dec->channel_mask =
+ gst_wavpack_get_channel_mask_from_positions (pos, dec->channels);
+ }
+
+ if (pos != NULL)
+ g_free (pos);
+ }
+
+ GST_DEBUG_OBJECT (dec, "setting caps %" GST_PTR_FORMAT, caps);
+
+ /* should always succeed */
+ gst_pad_set_caps (dec->srcpad, caps);
+ gst_caps_unref (caps);
+
+ /* send GST_TAG_AUDIO_CODEC and GST_TAG_BITRATE tags before something
+ * is decoded or after the format has changed */
+ gst_wavpack_dec_post_tags (dec);
+ }
+
+ gst_object_unref (dec);
+
+ return TRUE;
+}
+
+static void
+gst_wavpack_dec_post_tags (GstWavpackDec * dec)
+{
+ GstTagList *list;
+ GstFormat format_time = GST_FORMAT_TIME, format_bytes = GST_FORMAT_BYTES;
+ gint64 duration, size;
+
+ list = gst_tag_list_new ();
+
+ gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
+ GST_TAG_AUDIO_CODEC, "Wavpack", NULL);
+
+ /* try to estimate the average bitrate */
+ if (gst_pad_query_peer_duration (dec->sinkpad, &format_bytes, &size) &&
+ gst_pad_query_peer_duration (dec->sinkpad, &format_time, &duration) &&
+ size > 0 && duration > 0) {
+ guint64 bitrate;
+
+ bitrate = gst_util_uint64_scale (size, 8 * GST_SECOND, duration);
+ gst_tag_list_add (list, GST_TAG_MERGE_REPLACE, GST_TAG_BITRATE,
+ (guint) bitrate, NULL);
+ }
+
+ gst_element_post_message (GST_ELEMENT (dec),
+ gst_message_new_tag (GST_OBJECT (dec), list));
+}
+
+static GstFlowReturn
+gst_wavpack_dec_chain (GstPad * pad, GstBuffer * buf)
+{
+ GstWavpackDec *dec;
+ GstBuffer *outbuf = NULL;
+ GstFlowReturn ret = GST_FLOW_OK;
+ WavpackHeader wph;
+ int32_t decoded, unpacked_size;
+ gboolean format_changed;
+
+ dec = GST_WAVPACK_DEC (GST_PAD_PARENT (pad));
+
+ /* check input, we only accept framed input with complete chunks */
+ if (GST_BUFFER_SIZE (buf) < sizeof (WavpackHeader))
+ goto input_not_framed;
+
+ if (!gst_wavpack_read_header (&wph, GST_BUFFER_DATA (buf)))
+ goto invalid_header;
+
+ if (GST_BUFFER_SIZE (buf) < wph.ckSize + 4 * 1 + 4)
+ goto input_not_framed;
+
+ if (!(wph.flags & INITIAL_BLOCK))
+ goto input_not_framed;
+
+ dec->wv_id.buffer = GST_BUFFER_DATA (buf);
+ dec->wv_id.length = GST_BUFFER_SIZE (buf);
+ dec->wv_id.position = 0;
+
+ /* create a new wavpack context if there is none yet but if there
+ * was already one (i.e. caps were set on the srcpad) check whether
+ * the new one has the same caps */
+ if (!dec->context) {
+ gchar error_msg[80];
+
+ dec->context = WavpackOpenFileInputEx (dec->stream_reader,
+ &dec->wv_id, NULL, error_msg, OPEN_STREAMING, 0);
+
+ if (!dec->context) {
+ GST_WARNING ("Couldn't decode buffer: %s", error_msg);
+ dec->error_count++;
+ if (dec->error_count <= WAVPACK_DEC_MAX_ERRORS) {
+ goto out; /* just return OK for now */
+ } else {
+ goto decode_error;
+ }
+ }
+ }
+
+ g_assert (dec->context != NULL);
+
+ dec->error_count = 0;
+
+ format_changed =
+ (dec->sample_rate != WavpackGetSampleRate (dec->context)) ||
+ (dec->channels != WavpackGetNumChannels (dec->context)) ||
+ (dec->depth != WavpackGetBitsPerSample (dec->context)) ||
+#ifdef WAVPACK_OLD_API
+ (dec->channel_mask != dec->context->config.channel_mask);
+#else
+ (dec->channel_mask != WavpackGetChannelMask (dec->context));
+#endif
+
+ if (!GST_PAD_CAPS (dec->srcpad) || format_changed) {
+ GstCaps *caps;
+ gint channel_mask;
+
+ dec->sample_rate = WavpackGetSampleRate (dec->context);
+ dec->channels = WavpackGetNumChannels (dec->context);
+ dec->depth = WavpackGetBitsPerSample (dec->context);
+
+ caps = gst_caps_new_simple ("audio/x-raw-int",
+ "rate", G_TYPE_INT, dec->sample_rate,
+ "channels", G_TYPE_INT, dec->channels,
+ "depth", G_TYPE_INT, dec->depth,
+ "width", G_TYPE_INT, 32,
+ "endianness", G_TYPE_INT, G_BYTE_ORDER,
+ "signed", G_TYPE_BOOLEAN, TRUE, NULL);
+
+#ifdef WAVPACK_OLD_API
+ channel_mask = dec->context->config.channel_mask;
+#else
+ channel_mask = WavpackGetChannelMask (dec->context);
+#endif
+ if (channel_mask == 0)
+ channel_mask = gst_wavpack_get_default_channel_mask (dec->channels);
+
+ dec->channel_mask = channel_mask;
+
+ /* Only set the channel layout for more than two channels
+ * otherwise things break unfortunately */
+ if (channel_mask != 0 && dec->channels > 2)
+ if (!gst_wavpack_set_channel_layout (caps, channel_mask))
+ GST_WARNING_OBJECT (dec, "Failed to set channel layout");
+
+ GST_DEBUG_OBJECT (dec, "setting caps %" GST_PTR_FORMAT, caps);
+
+ /* should always succeed */
+ gst_pad_set_caps (dec->srcpad, caps);
+ gst_caps_unref (caps);
+
+ /* send GST_TAG_AUDIO_CODEC and GST_TAG_BITRATE tags before something
+ * is decoded or after the format has changed */
+ gst_wavpack_dec_post_tags (dec);
+ }
+
+ /* alloc output buffer */
+ unpacked_size = 4 * wph.block_samples * dec->channels;
+ ret = gst_pad_alloc_buffer (dec->srcpad, GST_BUFFER_OFFSET (buf),
+ unpacked_size, GST_PAD_CAPS (dec->srcpad), &outbuf);
+
+ if (ret != GST_FLOW_OK)
+ goto out;
+
+ gst_buffer_copy_metadata (outbuf, buf, GST_BUFFER_COPY_TIMESTAMPS);
+
+ /* If we got a DISCONT buffer forward the flag. Nothing else
+ * has to be done as libwavpack doesn't store state between
+ * Wavpack blocks */
+ if (GST_BUFFER_IS_DISCONT (buf) || dec->next_block_index != wph.block_index)
+ GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
+
+ dec->next_block_index = wph.block_index + wph.block_samples;
+
+ /* decode */
+ decoded = WavpackUnpackSamples (dec->context,
+ (int32_t *) GST_BUFFER_DATA (outbuf), wph.block_samples);
+ if (decoded != wph.block_samples)
+ goto decode_error;
+
+ if ((outbuf = gst_audio_buffer_clip (outbuf, &dec->segment,
+ dec->sample_rate, 4 * dec->channels))) {
+ GST_LOG_OBJECT (dec, "pushing buffer with time %" GST_TIME_FORMAT,
+ GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)));
+ ret = gst_pad_push (dec->srcpad, outbuf);
+ }
+
+out:
+
+ if (G_UNLIKELY (ret != GST_FLOW_OK)) {
+ GST_DEBUG_OBJECT (dec, "flow: %s", gst_flow_get_name (ret));
+ }
+
+ gst_buffer_unref (buf);
+
+ return ret;
+
+/* ERRORS */
+input_not_framed:
+ {
+ GST_ELEMENT_ERROR (dec, STREAM, DECODE, (NULL), ("Expected framed input"));
+ gst_buffer_unref (buf);
+ return GST_FLOW_ERROR;
+ }
+invalid_header:
+ {
+ GST_ELEMENT_ERROR (dec, STREAM, DECODE, (NULL), ("Invalid wavpack header"));
+ gst_buffer_unref (buf);
+ return GST_FLOW_ERROR;
+ }
+decode_error:
+ {
+ const gchar *reason = "unknown";
+
+ if (dec->context) {
+#ifdef WAVPACK_OLD_API
+ reason = dec->context->error_message;
+#else
+ reason = WavpackGetErrorMessage (dec->context);
+#endif
+ } else {
+ reason = "couldn't create decoder context";
+ }
+ GST_ELEMENT_ERROR (dec, STREAM, DECODE, (NULL),
+ ("Failed to decode wavpack stream: %s", reason));
+ if (outbuf)
+ gst_buffer_unref (outbuf);
+ gst_buffer_unref (buf);
+ return GST_FLOW_ERROR;
+ }
+}
+
+static gboolean
+gst_wavpack_dec_sink_event (GstPad * pad, GstEvent * event)
+{
+ GstWavpackDec *dec = GST_WAVPACK_DEC (gst_pad_get_parent (pad));
+
+ GST_LOG_OBJECT (dec, "Received %s event", GST_EVENT_TYPE_NAME (event));
+ switch (GST_EVENT_TYPE (event)) {
+ case GST_EVENT_NEWSEGMENT:{
+ GstFormat fmt;
+ gboolean is_update;
+ gint64 start, end, base;
+ gdouble rate;
+
+ gst_event_parse_new_segment (event, &is_update, &rate, &fmt, &start,
+ &end, &base);
+ if (fmt == GST_FORMAT_TIME) {
+ GST_DEBUG ("Got NEWSEGMENT event in GST_FORMAT_TIME, passing on (%"
+ GST_TIME_FORMAT " - %" GST_TIME_FORMAT ")", GST_TIME_ARGS (start),
+ GST_TIME_ARGS (end));
+ gst_segment_set_newsegment (&dec->segment, is_update, rate, fmt,
+ start, end, base);
+ } else {
+ gst_segment_init (&dec->segment, GST_FORMAT_TIME);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+
+ gst_object_unref (dec);
+ return gst_pad_event_default (pad, event);
+}
+
+static GstStateChangeReturn
+gst_wavpack_dec_change_state (GstElement * element, GstStateChange transition)
+{
+ GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
+ GstWavpackDec *dec = GST_WAVPACK_DEC (element);
+
+ switch (transition) {
+ case GST_STATE_CHANGE_NULL_TO_READY:
+ break;
+ case GST_STATE_CHANGE_READY_TO_PAUSED:
+ break;
+ case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
+ break;
+ default:
+ break;
+ }
+
+ ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
+
+ switch (transition) {
+ case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
+ break;
+ case GST_STATE_CHANGE_PAUSED_TO_READY:
+ if (dec->context) {
+ WavpackCloseFile (dec->context);
+ dec->context = NULL;
+ }
+
+ gst_wavpack_dec_reset (dec);
+ break;
+ case GST_STATE_CHANGE_READY_TO_NULL:
+ break;
+ default:
+ break;
+ }
+
+ return ret;
+}
+
+gboolean
+gst_wavpack_dec_plugin_init (GstPlugin * plugin)
+{
+ if (!gst_element_register (plugin, "wavpackdec",
+ GST_RANK_PRIMARY, GST_TYPE_WAVPACK_DEC))
+ return FALSE;
+ GST_DEBUG_CATEGORY_INIT (gst_wavpack_dec_debug, "wavpack_dec", 0,
+ "Wavpack decoder");
+ return TRUE;
+}
diff --git a/ext/wavpack/gstwavpackdec.h b/ext/wavpack/gstwavpackdec.h
new file mode 100644
index 0000000..eb6e4c3
--- /dev/null
+++ b/ext/wavpack/gstwavpackdec.h
@@ -0,0 +1,80 @@
+/* GStreamer Wavpack plugin
+ * Copyright (c) 2004 Arwed v. Merkatz <v.merkatz@gmx.net>
+ * Copyright (c) 2006 Sebastian Dröge <slomo@circular-chaos.org>
+ *
+ * gstwavpackdec.h: raw Wavpack bitstream decoder
+ *
+ * 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 __GST_WAVPACK_DEC_H__
+#define __GST_WAVPACK_DEC_H__
+
+#include <gst/gst.h>
+
+#include <wavpack/wavpack.h>
+
+#include "gstwavpackstreamreader.h"
+
+G_BEGIN_DECLS
+#define GST_TYPE_WAVPACK_DEC \
+ (gst_wavpack_dec_get_type())
+#define GST_WAVPACK_DEC(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_WAVPACK_DEC,GstWavpackDec))
+#define GST_WAVPACK_DEC_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_WAVPACK_DEC,GstWavpackDecClass))
+#define GST_IS_WAVPACK_DEC(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_WAVPACK_DEC))
+#define GST_IS_WAVPACK_DEC_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_WAVPACK_DEC))
+typedef struct _GstWavpackDec GstWavpackDec;
+typedef struct _GstWavpackDecClass GstWavpackDecClass;
+
+struct _GstWavpackDec
+{
+ GstElement element;
+
+ /*< private > */
+ GstPad *sinkpad;
+ GstPad *srcpad;
+
+ WavpackContext *context;
+ WavpackStreamReader *stream_reader;
+
+ read_id wv_id;
+
+ GstSegment segment; /* used for clipping, TIME format */
+ guint32 next_block_index;
+
+ gint sample_rate;
+ gint depth;
+ gint channels;
+ gint channel_mask;
+
+ gint error_count;
+};
+
+struct _GstWavpackDecClass
+{
+ GstElementClass parent;
+};
+
+GType gst_wavpack_dec_get_type (void);
+
+gboolean gst_wavpack_dec_plugin_init (GstPlugin * plugin);
+
+G_END_DECLS
+#endif /* __GST_WAVPACK_DEC_H__ */
diff --git a/ext/wavpack/gstwavpackenc.c b/ext/wavpack/gstwavpackenc.c
new file mode 100644
index 0000000..a22dd23
--- /dev/null
+++ b/ext/wavpack/gstwavpackenc.c
@@ -0,0 +1,1049 @@
+/* GStreamer Wavpack encoder plugin
+ * Copyright (c) 2006 Sebastian Dröge <slomo@circular-chaos.org>
+ *
+ * gstwavpackdec.c: Wavpack audio encoder
+ *
+ * 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.
+ */
+
+/**
+ * SECTION:element-wavpackenc
+ *
+ * WavpackEnc encodes raw audio into a framed Wavpack stream.
+ * <ulink url="http://www.wavpack.com/">Wavpack</ulink> is an open-source
+ * audio codec that features both lossless and lossy encoding.
+ *
+ * <refsect2>
+ * <title>Example launch line</title>
+ * |[
+ * gst-launch audiotestsrc num-buffers=500 ! audioconvert ! wavpackenc ! filesink location=sinewave.wv
+ * ]| This pipeline encodes audio from audiotestsrc into a Wavpack file. The audioconvert element is needed
+ * as the Wavpack encoder only accepts input with 32 bit width (and every depth between 1 and 32 bits).
+ * |[
+ * gst-launch cdda://1 ! audioconvert ! wavpackenc ! filesink location=track1.wv
+ * ]| This pipeline encodes audio from an audio CD into a Wavpack file using
+ * lossless encoding (the file output will be fairly large).
+ * |[
+ * gst-launch cdda://1 ! audioconvert ! wavpackenc bitrate=128000 ! filesink location=track1.wv
+ * ]| This pipeline encodes audio from an audio CD into a Wavpack file using
+ * lossy encoding at a certain bitrate (the file will be fairly small).
+ * </refsect2>
+ */
+
+/*
+ * TODO: - add 32 bit float mode. CONFIG_FLOAT_DATA
+ */
+
+#include <string.h>
+#include <gst/gst.h>
+#include <glib/gprintf.h>
+
+#include <wavpack/wavpack.h>
+#include "gstwavpackenc.h"
+#include "gstwavpackcommon.h"
+
+static GstFlowReturn gst_wavpack_enc_chain (GstPad * pad, GstBuffer * buffer);
+static gboolean gst_wavpack_enc_sink_set_caps (GstPad * pad, GstCaps * caps);
+static int gst_wavpack_enc_push_block (void *id, void *data, int32_t count);
+static gboolean gst_wavpack_enc_sink_event (GstPad * pad, GstEvent * event);
+static GstStateChangeReturn gst_wavpack_enc_change_state (GstElement * element,
+ GstStateChange transition);
+static void gst_wavpack_enc_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec);
+static void gst_wavpack_enc_get_property (GObject * object, guint prop_id,
+ GValue * value, GParamSpec * pspec);
+
+enum
+{
+ ARG_0,
+ ARG_MODE,
+ ARG_BITRATE,
+ ARG_BITSPERSAMPLE,
+ ARG_CORRECTION_MODE,
+ ARG_MD5,
+ ARG_EXTRA_PROCESSING,
+ ARG_JOINT_STEREO_MODE
+};
+
+GST_DEBUG_CATEGORY_STATIC (gst_wavpack_enc_debug);
+#define GST_CAT_DEFAULT gst_wavpack_enc_debug
+
+static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
+ GST_PAD_SINK,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("audio/x-raw-int, "
+ "width = (int) 32, "
+ "depth = (int) [ 1, 32], "
+ "endianness = (int) BYTE_ORDER, "
+ "channels = (int) [ 1, 8 ], "
+ "rate = (int) [ 6000, 192000 ]," "signed = (boolean) TRUE")
+ );
+
+static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
+ GST_PAD_SRC,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("audio/x-wavpack, "
+ "width = (int) [ 1, 32 ], "
+ "channels = (int) [ 1, 2 ], "
+ "rate = (int) [ 6000, 192000 ], " "framed = (boolean) TRUE")
+ );
+
+static GstStaticPadTemplate wvcsrc_factory = GST_STATIC_PAD_TEMPLATE ("wvcsrc",
+ GST_PAD_SRC,
+ GST_PAD_SOMETIMES,
+ GST_STATIC_CAPS ("audio/x-wavpack-correction, " "framed = (boolean) TRUE")
+ );
+
+enum
+{
+ GST_WAVPACK_ENC_MODE_VERY_FAST = 0,
+ GST_WAVPACK_ENC_MODE_FAST,
+ GST_WAVPACK_ENC_MODE_DEFAULT,
+ GST_WAVPACK_ENC_MODE_HIGH,
+ GST_WAVPACK_ENC_MODE_VERY_HIGH
+};
+
+#define GST_TYPE_WAVPACK_ENC_MODE (gst_wavpack_enc_mode_get_type ())
+static GType
+gst_wavpack_enc_mode_get_type (void)
+{
+ static GType qtype = 0;
+
+ if (qtype == 0) {
+ static const GEnumValue values[] = {
+#if 0
+ /* Very Fast Compression is not supported yet, but will be supported
+ * in future wavpack versions */
+ {GST_WAVPACK_ENC_MODE_VERY_FAST, "Very Fast Compression", "veryfast"},
+#endif
+ {GST_WAVPACK_ENC_MODE_FAST, "Fast Compression", "fast"},
+ {GST_WAVPACK_ENC_MODE_DEFAULT, "Normal Compression", "normal"},
+ {GST_WAVPACK_ENC_MODE_HIGH, "High Compression", "high"},
+#ifndef WAVPACK_OLD_API
+ {GST_WAVPACK_ENC_MODE_VERY_HIGH, "Very High Compression", "veryhigh"},
+#endif
+ {0, NULL, NULL}
+ };
+
+ qtype = g_enum_register_static ("GstWavpackEncMode", values);
+ }
+ return qtype;
+}
+
+enum
+{
+ GST_WAVPACK_CORRECTION_MODE_OFF = 0,
+ GST_WAVPACK_CORRECTION_MODE_ON,
+ GST_WAVPACK_CORRECTION_MODE_OPTIMIZED
+};
+
+#define GST_TYPE_WAVPACK_ENC_CORRECTION_MODE (gst_wavpack_enc_correction_mode_get_type ())
+static GType
+gst_wavpack_enc_correction_mode_get_type (void)
+{
+ static GType qtype = 0;
+
+ if (qtype == 0) {
+ static const GEnumValue values[] = {
+ {GST_WAVPACK_CORRECTION_MODE_OFF, "Create no correction file", "off"},
+ {GST_WAVPACK_CORRECTION_MODE_ON, "Create correction file", "on"},
+ {GST_WAVPACK_CORRECTION_MODE_OPTIMIZED,
+ "Create optimized correction file", "optimized"},
+ {0, NULL, NULL}
+ };
+
+ qtype = g_enum_register_static ("GstWavpackEncCorrectionMode", values);
+ }
+ return qtype;
+}
+
+enum
+{
+ GST_WAVPACK_JS_MODE_AUTO = 0,
+ GST_WAVPACK_JS_MODE_LEFT_RIGHT,
+ GST_WAVPACK_JS_MODE_MID_SIDE
+};
+
+#define GST_TYPE_WAVPACK_ENC_JOINT_STEREO_MODE (gst_wavpack_enc_joint_stereo_mode_get_type ())
+static GType
+gst_wavpack_enc_joint_stereo_mode_get_type (void)
+{
+ static GType qtype = 0;
+
+ if (qtype == 0) {
+ static const GEnumValue values[] = {
+ {GST_WAVPACK_JS_MODE_AUTO, "auto", "auto"},
+ {GST_WAVPACK_JS_MODE_LEFT_RIGHT, "left/right", "leftright"},
+ {GST_WAVPACK_JS_MODE_MID_SIDE, "mid/side", "midside"},
+ {0, NULL, NULL}
+ };
+
+ qtype = g_enum_register_static ("GstWavpackEncJSMode", values);
+ }
+ return qtype;
+}
+
+static void
+_do_init (GType object_type)
+{
+ const GInterfaceInfo preset_interface_info = {
+ NULL, /* interface_init */
+ NULL, /* interface_finalize */
+ NULL /* interface_data */
+ };
+
+ g_type_add_interface_static (object_type, GST_TYPE_PRESET,
+ &preset_interface_info);
+}
+
+GST_BOILERPLATE_FULL (GstWavpackEnc, gst_wavpack_enc, GstElement,
+ GST_TYPE_ELEMENT, _do_init);
+
+static void
+gst_wavpack_enc_base_init (gpointer klass)
+{
+ GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
+
+ /* add pad templates */
+ gst_element_class_add_static_pad_template (element_class, &sink_factory);
+ gst_element_class_add_static_pad_template (element_class, &src_factory);
+ gst_element_class_add_static_pad_template (element_class,
+ &wvcsrc_factory);
+
+ /* set element details */
+ gst_element_class_set_details_simple (element_class, "Wavpack audio encoder",
+ "Codec/Encoder/Audio",
+ "Encodes audio with the Wavpack lossless/lossy audio codec",
+ "Sebastian Dröge <slomo@circular-chaos.org>");
+}
+
+
+static void
+gst_wavpack_enc_class_init (GstWavpackEncClass * klass)
+{
+ GObjectClass *gobject_class = (GObjectClass *) klass;
+ GstElementClass *gstelement_class = (GstElementClass *) klass;
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ /* set state change handler */
+ gstelement_class->change_state =
+ GST_DEBUG_FUNCPTR (gst_wavpack_enc_change_state);
+
+ /* set property handlers */
+ gobject_class->set_property = gst_wavpack_enc_set_property;
+ gobject_class->get_property = gst_wavpack_enc_get_property;
+
+ /* install all properties */
+ g_object_class_install_property (gobject_class, ARG_MODE,
+ g_param_spec_enum ("mode", "Encoding mode",
+ "Speed versus compression tradeoff.",
+ GST_TYPE_WAVPACK_ENC_MODE, GST_WAVPACK_ENC_MODE_DEFAULT,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (gobject_class, ARG_BITRATE,
+ g_param_spec_uint ("bitrate", "Bitrate",
+ "Try to encode with this average bitrate (bits/sec). "
+ "This enables lossy encoding, values smaller than 24000 disable it again.",
+ 0, 9600000, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (gobject_class, ARG_BITSPERSAMPLE,
+ g_param_spec_double ("bits-per-sample", "Bits per sample",
+ "Try to encode with this amount of bits per sample. "
+ "This enables lossy encoding, values smaller than 2.0 disable it again.",
+ 0.0, 24.0, 0.0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (gobject_class, ARG_CORRECTION_MODE,
+ g_param_spec_enum ("correction-mode", "Correction stream mode",
+ "Use this mode for the correction stream. Only works in lossy mode!",
+ GST_TYPE_WAVPACK_ENC_CORRECTION_MODE, GST_WAVPACK_CORRECTION_MODE_OFF,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (gobject_class, ARG_MD5,
+ g_param_spec_boolean ("md5", "MD5",
+ "Store MD5 hash of raw samples within the file.", FALSE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (gobject_class, ARG_EXTRA_PROCESSING,
+ g_param_spec_uint ("extra-processing", "Extra processing",
+ "Use better but slower filters for better compression/quality.",
+ 0, 6, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (gobject_class, ARG_JOINT_STEREO_MODE,
+ g_param_spec_enum ("joint-stereo-mode", "Joint-Stereo mode",
+ "Use this joint-stereo mode.", GST_TYPE_WAVPACK_ENC_JOINT_STEREO_MODE,
+ GST_WAVPACK_JS_MODE_AUTO,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+}
+
+static void
+gst_wavpack_enc_reset (GstWavpackEnc * enc)
+{
+ /* close and free everything stream related if we already did something */
+ if (enc->wp_context) {
+ WavpackCloseFile (enc->wp_context);
+ enc->wp_context = NULL;
+ }
+ if (enc->wp_config) {
+ g_free (enc->wp_config);
+ enc->wp_config = NULL;
+ }
+ if (enc->first_block) {
+ g_free (enc->first_block);
+ enc->first_block = NULL;
+ }
+ enc->first_block_size = 0;
+ if (enc->md5_context) {
+ g_checksum_free (enc->md5_context);
+ enc->md5_context = NULL;
+ }
+
+ if (enc->pending_buffer) {
+ gst_buffer_unref (enc->pending_buffer);
+ enc->pending_buffer = NULL;
+ enc->pending_offset = 0;
+ }
+
+ /* reset the last returns to GST_FLOW_OK. This is only set to something else
+ * while WavpackPackSamples() or more specific gst_wavpack_enc_push_block()
+ * so not valid anymore */
+ enc->srcpad_last_return = enc->wvcsrcpad_last_return = GST_FLOW_OK;
+
+ /* reset stream information */
+ enc->samplerate = 0;
+ enc->depth = 0;
+ enc->channels = 0;
+ enc->channel_mask = 0;
+ enc->need_channel_remap = FALSE;
+
+ enc->timestamp_offset = GST_CLOCK_TIME_NONE;
+ enc->next_ts = GST_CLOCK_TIME_NONE;
+}
+
+static void
+gst_wavpack_enc_init (GstWavpackEnc * enc, GstWavpackEncClass * gclass)
+{
+ enc->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
+ gst_pad_set_setcaps_function (enc->sinkpad,
+ GST_DEBUG_FUNCPTR (gst_wavpack_enc_sink_set_caps));
+ gst_pad_set_chain_function (enc->sinkpad,
+ GST_DEBUG_FUNCPTR (gst_wavpack_enc_chain));
+ gst_pad_set_event_function (enc->sinkpad,
+ GST_DEBUG_FUNCPTR (gst_wavpack_enc_sink_event));
+ gst_element_add_pad (GST_ELEMENT (enc), enc->sinkpad);
+
+ /* setup src pad */
+ enc->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
+ gst_element_add_pad (GST_ELEMENT (enc), enc->srcpad);
+
+ /* initialize object attributes */
+ enc->wp_config = NULL;
+ enc->wp_context = NULL;
+ enc->first_block = NULL;
+ enc->md5_context = NULL;
+ gst_wavpack_enc_reset (enc);
+
+ enc->wv_id.correction = FALSE;
+ enc->wv_id.wavpack_enc = enc;
+ enc->wv_id.passthrough = FALSE;
+ enc->wvc_id.correction = TRUE;
+ enc->wvc_id.wavpack_enc = enc;
+ enc->wvc_id.passthrough = FALSE;
+
+ /* set default values of params */
+ enc->mode = GST_WAVPACK_ENC_MODE_DEFAULT;
+ enc->bitrate = 0;
+ enc->bps = 0.0;
+ enc->correction_mode = GST_WAVPACK_CORRECTION_MODE_OFF;
+ enc->md5 = FALSE;
+ enc->extra_processing = 0;
+ enc->joint_stereo_mode = GST_WAVPACK_JS_MODE_AUTO;
+}
+
+static gboolean
+gst_wavpack_enc_sink_set_caps (GstPad * pad, GstCaps * caps)
+{
+ GstWavpackEnc *enc = GST_WAVPACK_ENC (gst_pad_get_parent (pad));
+ GstStructure *structure = gst_caps_get_structure (caps, 0);
+ GstAudioChannelPosition *pos;
+
+ if (!gst_structure_get_int (structure, "channels", &enc->channels) ||
+ !gst_structure_get_int (structure, "rate", &enc->samplerate) ||
+ !gst_structure_get_int (structure, "depth", &enc->depth)) {
+ GST_ELEMENT_ERROR (enc, LIBRARY, INIT, (NULL),
+ ("got invalid caps: %" GST_PTR_FORMAT, caps));
+ gst_object_unref (enc);
+ return FALSE;
+ }
+
+ pos = gst_audio_get_channel_positions (structure);
+ /* If one channel is NONE they'll be all undefined */
+ if (pos != NULL && pos[0] == GST_AUDIO_CHANNEL_POSITION_NONE) {
+ g_free (pos);
+ pos = NULL;
+ }
+
+ if (pos == NULL) {
+ GST_ELEMENT_ERROR (enc, STREAM, FORMAT, (NULL),
+ ("input has no valid channel layout"));
+
+ gst_object_unref (enc);
+ return FALSE;
+ }
+
+ enc->channel_mask =
+ gst_wavpack_get_channel_mask_from_positions (pos, enc->channels);
+ enc->need_channel_remap =
+ gst_wavpack_set_channel_mapping (pos, enc->channels,
+ enc->channel_mapping);
+ g_free (pos);
+
+ /* set fixed src pad caps now that we know what we will get */
+ caps = gst_caps_new_simple ("audio/x-wavpack",
+ "channels", G_TYPE_INT, enc->channels,
+ "rate", G_TYPE_INT, enc->samplerate,
+ "width", G_TYPE_INT, enc->depth, "framed", G_TYPE_BOOLEAN, TRUE, NULL);
+
+ if (!gst_wavpack_set_channel_layout (caps, enc->channel_mask))
+ GST_WARNING_OBJECT (enc, "setting channel layout failed");
+
+ if (!gst_pad_set_caps (enc->srcpad, caps)) {
+ GST_ELEMENT_ERROR (enc, LIBRARY, INIT, (NULL),
+ ("setting caps failed: %" GST_PTR_FORMAT, caps));
+ gst_caps_unref (caps);
+ gst_object_unref (enc);
+ return FALSE;
+ }
+ gst_pad_use_fixed_caps (enc->srcpad);
+
+ gst_caps_unref (caps);
+ gst_object_unref (enc);
+ return TRUE;
+}
+
+static void
+gst_wavpack_enc_set_wp_config (GstWavpackEnc * enc)
+{
+ enc->wp_config = g_new0 (WavpackConfig, 1);
+ /* set general stream informations in the WavpackConfig */
+ enc->wp_config->bytes_per_sample = GST_ROUND_UP_8 (enc->depth) / 8;
+ enc->wp_config->bits_per_sample = enc->depth;
+ enc->wp_config->num_channels = enc->channels;
+ enc->wp_config->channel_mask = enc->channel_mask;
+ enc->wp_config->sample_rate = enc->samplerate;
+
+ /*
+ * Set parameters in WavpackConfig
+ */
+
+ /* Encoding mode */
+ switch (enc->mode) {
+#if 0
+ case GST_WAVPACK_ENC_MODE_VERY_FAST:
+ enc->wp_config->flags |= CONFIG_VERY_FAST_FLAG;
+ enc->wp_config->flags |= CONFIG_FAST_FLAG;
+ break;
+#endif
+ case GST_WAVPACK_ENC_MODE_FAST:
+ enc->wp_config->flags |= CONFIG_FAST_FLAG;
+ break;
+ case GST_WAVPACK_ENC_MODE_DEFAULT:
+ break;
+ case GST_WAVPACK_ENC_MODE_HIGH:
+ enc->wp_config->flags |= CONFIG_HIGH_FLAG;
+ break;
+#ifndef WAVPACK_OLD_API
+ case GST_WAVPACK_ENC_MODE_VERY_HIGH:
+ enc->wp_config->flags |= CONFIG_HIGH_FLAG;
+ enc->wp_config->flags |= CONFIG_VERY_HIGH_FLAG;
+ break;
+#endif
+ }
+
+ /* Bitrate, enables lossy mode */
+ if (enc->bitrate) {
+ enc->wp_config->flags |= CONFIG_HYBRID_FLAG;
+ enc->wp_config->flags |= CONFIG_BITRATE_KBPS;
+ enc->wp_config->bitrate = enc->bitrate / 1000.0;
+ } else if (enc->bps) {
+ enc->wp_config->flags |= CONFIG_HYBRID_FLAG;
+ enc->wp_config->bitrate = enc->bps;
+ }
+
+ /* Correction Mode, only in lossy mode */
+ if (enc->wp_config->flags & CONFIG_HYBRID_FLAG) {
+ if (enc->correction_mode > GST_WAVPACK_CORRECTION_MODE_OFF) {
+ GstCaps *caps = gst_caps_new_simple ("audio/x-wavpack-correction",
+ "framed", G_TYPE_BOOLEAN, TRUE, NULL);
+
+ enc->wvcsrcpad =
+ gst_pad_new_from_static_template (&wvcsrc_factory, "wvcsrc");
+
+ /* try to add correction src pad, don't set correction mode on failure */
+ GST_DEBUG_OBJECT (enc, "Adding correction pad with caps %"
+ GST_PTR_FORMAT, caps);
+ if (!gst_pad_set_caps (enc->wvcsrcpad, caps)) {
+ enc->correction_mode = 0;
+ GST_WARNING_OBJECT (enc, "setting correction caps failed");
+ } else {
+ gst_pad_use_fixed_caps (enc->wvcsrcpad);
+ gst_pad_set_active (enc->wvcsrcpad, TRUE);
+ gst_element_add_pad (GST_ELEMENT (enc), enc->wvcsrcpad);
+ enc->wp_config->flags |= CONFIG_CREATE_WVC;
+ if (enc->correction_mode == GST_WAVPACK_CORRECTION_MODE_OPTIMIZED) {
+ enc->wp_config->flags |= CONFIG_OPTIMIZE_WVC;
+ }
+ }
+ gst_caps_unref (caps);
+ }
+ } else {
+ if (enc->correction_mode > GST_WAVPACK_CORRECTION_MODE_OFF) {
+ enc->correction_mode = 0;
+ GST_WARNING_OBJECT (enc, "setting correction mode only has "
+ "any effect if a bitrate is provided.");
+ }
+ }
+ gst_element_no_more_pads (GST_ELEMENT (enc));
+
+ /* MD5, setup MD5 context */
+ if ((enc->md5) && !(enc->md5_context)) {
+ enc->wp_config->flags |= CONFIG_MD5_CHECKSUM;
+ enc->md5_context = g_checksum_new (G_CHECKSUM_MD5);
+ }
+
+ /* Extra encode processing */
+ if (enc->extra_processing) {
+ enc->wp_config->flags |= CONFIG_EXTRA_MODE;
+ enc->wp_config->xmode = enc->extra_processing;
+ }
+
+ /* Joint stereo mode */
+ switch (enc->joint_stereo_mode) {
+ case GST_WAVPACK_JS_MODE_AUTO:
+ break;
+ case GST_WAVPACK_JS_MODE_LEFT_RIGHT:
+ enc->wp_config->flags |= CONFIG_JOINT_OVERRIDE;
+ enc->wp_config->flags &= ~CONFIG_JOINT_STEREO;
+ break;
+ case GST_WAVPACK_JS_MODE_MID_SIDE:
+ enc->wp_config->flags |= (CONFIG_JOINT_OVERRIDE | CONFIG_JOINT_STEREO);
+ break;
+ }
+}
+
+static int
+gst_wavpack_enc_push_block (void *id, void *data, int32_t count)
+{
+ GstWavpackEncWriteID *wid = (GstWavpackEncWriteID *) id;
+ GstWavpackEnc *enc = GST_WAVPACK_ENC (wid->wavpack_enc);
+ GstFlowReturn *flow;
+ GstBuffer *buffer;
+ GstPad *pad;
+ guchar *block = (guchar *) data;
+
+ pad = (wid->correction) ? enc->wvcsrcpad : enc->srcpad;
+ flow =
+ (wid->correction) ? &enc->wvcsrcpad_last_return : &enc->
+ srcpad_last_return;
+
+ *flow = gst_pad_alloc_buffer_and_set_caps (pad, GST_BUFFER_OFFSET_NONE,
+ count, GST_PAD_CAPS (pad), &buffer);
+
+ if (*flow != GST_FLOW_OK) {
+ GST_WARNING_OBJECT (enc, "flow on %s:%s = %s",
+ GST_DEBUG_PAD_NAME (pad), gst_flow_get_name (*flow));
+ return FALSE;
+ }
+
+ g_memmove (GST_BUFFER_DATA (buffer), block, count);
+
+ if (count > sizeof (WavpackHeader) && memcmp (block, "wvpk", 4) == 0) {
+ /* if it's a Wavpack block set buffer timestamp and duration, etc */
+ WavpackHeader wph;
+
+ GST_LOG_OBJECT (enc, "got %d bytes of encoded wavpack %sdata",
+ count, (wid->correction) ? "correction " : "");
+
+ gst_wavpack_read_header (&wph, block);
+
+ /* Only set when pushing the first buffer again, in that case
+ * we don't want to delay the buffer or push newsegment events
+ */
+ if (!wid->passthrough) {
+ /* Only push complete blocks */
+ if (enc->pending_buffer == NULL) {
+ enc->pending_buffer = buffer;
+ enc->pending_offset = wph.block_index;
+ } else if (enc->pending_offset == wph.block_index) {
+ enc->pending_buffer = gst_buffer_join (enc->pending_buffer, buffer);
+ } else {
+ GST_ERROR ("Got incomplete block, dropping");
+ gst_buffer_unref (enc->pending_buffer);
+ enc->pending_buffer = buffer;
+ enc->pending_offset = wph.block_index;
+ }
+
+ if (!(wph.flags & FINAL_BLOCK))
+ return TRUE;
+
+ buffer = enc->pending_buffer;
+ enc->pending_buffer = NULL;
+ enc->pending_offset = 0;
+
+ /* if it's the first wavpack block, send a NEW_SEGMENT event */
+ if (wph.block_index == 0) {
+ gst_pad_push_event (pad,
+ gst_event_new_new_segment (FALSE,
+ 1.0, GST_FORMAT_TIME, 0, GST_BUFFER_OFFSET_NONE, 0));
+
+ /* save header for later reference, so we can re-send it later on
+ * EOS with fixed up values for total sample count etc. */
+ if (enc->first_block == NULL && !wid->correction) {
+ enc->first_block =
+ g_memdup (GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer));
+ enc->first_block_size = GST_BUFFER_SIZE (buffer);
+ }
+ }
+ }
+
+ /* set buffer timestamp, duration, offset, offset_end from
+ * the wavpack header */
+ GST_BUFFER_TIMESTAMP (buffer) = enc->timestamp_offset +
+ gst_util_uint64_scale_int (GST_SECOND, wph.block_index,
+ enc->samplerate);
+ GST_BUFFER_DURATION (buffer) =
+ gst_util_uint64_scale_int (GST_SECOND, wph.block_samples,
+ enc->samplerate);
+ GST_BUFFER_OFFSET (buffer) = wph.block_index;
+ GST_BUFFER_OFFSET_END (buffer) = wph.block_index + wph.block_samples;
+ } else {
+ /* if it's something else set no timestamp and duration on the buffer */
+ GST_DEBUG_OBJECT (enc, "got %d bytes of unknown data", count);
+
+ GST_BUFFER_TIMESTAMP (buffer) = GST_CLOCK_TIME_NONE;
+ GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE;
+ }
+
+ /* push the buffer and forward errors */
+ GST_DEBUG_OBJECT (enc, "pushing buffer with %d bytes",
+ GST_BUFFER_SIZE (buffer));
+ *flow = gst_pad_push (pad, buffer);
+
+ if (*flow != GST_FLOW_OK) {
+ GST_WARNING_OBJECT (enc, "flow on %s:%s = %s",
+ GST_DEBUG_PAD_NAME (pad), gst_flow_get_name (*flow));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void
+gst_wavpack_enc_fix_channel_order (GstWavpackEnc * enc, gint32 * data,
+ gint nsamples)
+{
+ gint i, j;
+ gint32 tmp[8];
+
+ for (i = 0; i < nsamples / enc->channels; i++) {
+ for (j = 0; j < enc->channels; j++) {
+ tmp[enc->channel_mapping[j]] = data[j];
+ }
+ for (j = 0; j < enc->channels; j++) {
+ data[j] = tmp[j];
+ }
+ data += enc->channels;
+ }
+}
+
+static GstFlowReturn
+gst_wavpack_enc_chain (GstPad * pad, GstBuffer * buf)
+{
+ GstWavpackEnc *enc = GST_WAVPACK_ENC (gst_pad_get_parent (pad));
+ uint32_t sample_count = GST_BUFFER_SIZE (buf) / 4;
+ GstFlowReturn ret;
+
+ /* reset the last returns to GST_FLOW_OK. This is only set to something else
+ * while WavpackPackSamples() or more specific gst_wavpack_enc_push_block()
+ * so not valid anymore */
+ enc->srcpad_last_return = enc->wvcsrcpad_last_return = GST_FLOW_OK;
+
+ GST_DEBUG ("got %u raw samples", sample_count);
+
+ /* check if we already have a valid WavpackContext, otherwise make one */
+ if (!enc->wp_context) {
+ /* create raw context */
+ enc->wp_context =
+ WavpackOpenFileOutput (gst_wavpack_enc_push_block, &enc->wv_id,
+ (enc->correction_mode > 0) ? &enc->wvc_id : NULL);
+ if (!enc->wp_context) {
+ GST_ELEMENT_ERROR (enc, LIBRARY, INIT, (NULL),
+ ("error creating Wavpack context"));
+ gst_object_unref (enc);
+ gst_buffer_unref (buf);
+ return GST_FLOW_ERROR;
+ }
+
+ /* set the WavpackConfig according to our parameters */
+ gst_wavpack_enc_set_wp_config (enc);
+
+ /* set the configuration to the context now that we know everything
+ * and initialize the encoder */
+ if (!WavpackSetConfiguration (enc->wp_context,
+ enc->wp_config, (uint32_t) (-1))
+ || !WavpackPackInit (enc->wp_context)) {
+ GST_ELEMENT_ERROR (enc, LIBRARY, SETTINGS, (NULL),
+ ("error setting up wavpack encoding context"));
+ WavpackCloseFile (enc->wp_context);
+ gst_object_unref (enc);
+ gst_buffer_unref (buf);
+ return GST_FLOW_ERROR;
+ }
+ GST_DEBUG ("setup of encoding context successfull");
+ }
+
+ /* Save the timestamp of the first buffer. This will be later
+ * used as offset for all following buffers */
+ if (enc->timestamp_offset == GST_CLOCK_TIME_NONE) {
+ if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
+ enc->timestamp_offset = GST_BUFFER_TIMESTAMP (buf);
+ enc->next_ts = GST_BUFFER_TIMESTAMP (buf);
+ } else {
+ enc->timestamp_offset = 0;
+ enc->next_ts = 0;
+ }
+ }
+
+ /* Check if we have a continous stream, if not drop some samples or the buffer or
+ * insert some silence samples */
+ if (enc->next_ts != GST_CLOCK_TIME_NONE &&
+ GST_BUFFER_TIMESTAMP (buf) < enc->next_ts) {
+ guint64 diff = enc->next_ts - GST_BUFFER_TIMESTAMP (buf);
+ guint64 diff_bytes;
+
+ GST_WARNING_OBJECT (enc, "Buffer is older than previous "
+ "timestamp + duration (%" GST_TIME_FORMAT "< %" GST_TIME_FORMAT
+ "), cannot handle. Clipping buffer.",
+ GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
+ GST_TIME_ARGS (enc->next_ts));
+
+ diff_bytes =
+ GST_CLOCK_TIME_TO_FRAMES (diff, enc->samplerate) * enc->channels * 2;
+ if (diff_bytes >= GST_BUFFER_SIZE (buf)) {
+ gst_buffer_unref (buf);
+ return GST_FLOW_OK;
+ }
+ buf = gst_buffer_make_metadata_writable (buf);
+ GST_BUFFER_DATA (buf) += diff_bytes;
+ GST_BUFFER_SIZE (buf) -= diff_bytes;
+
+ GST_BUFFER_TIMESTAMP (buf) += diff;
+ if (GST_BUFFER_DURATION_IS_VALID (buf))
+ GST_BUFFER_DURATION (buf) -= diff;
+ }
+
+ /* Allow a diff of at most 5 ms */
+ if (enc->next_ts != GST_CLOCK_TIME_NONE
+ && GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
+ if (GST_BUFFER_TIMESTAMP (buf) != enc->next_ts &&
+ GST_BUFFER_TIMESTAMP (buf) - enc->next_ts > 5 * GST_MSECOND) {
+ GST_WARNING_OBJECT (enc,
+ "Discontinuity detected: %" G_GUINT64_FORMAT " > %" G_GUINT64_FORMAT,
+ GST_BUFFER_TIMESTAMP (buf) - enc->next_ts, 5 * GST_MSECOND);
+
+ WavpackFlushSamples (enc->wp_context);
+ enc->timestamp_offset += (GST_BUFFER_TIMESTAMP (buf) - enc->next_ts);
+ }
+ }
+
+ if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)
+ && GST_BUFFER_DURATION_IS_VALID (buf))
+ enc->next_ts = GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf);
+ else
+ enc->next_ts = GST_CLOCK_TIME_NONE;
+
+ if (enc->need_channel_remap) {
+ buf = gst_buffer_make_writable (buf);
+ gst_wavpack_enc_fix_channel_order (enc, (gint32 *) GST_BUFFER_DATA (buf),
+ sample_count);
+ }
+
+ /* if we want to append the MD5 sum to the stream update it here
+ * with the current raw samples */
+ if (enc->md5) {
+ g_checksum_update (enc->md5_context, GST_BUFFER_DATA (buf),
+ GST_BUFFER_SIZE (buf));
+ }
+
+ /* encode and handle return values from encoding */
+ if (WavpackPackSamples (enc->wp_context, (int32_t *) GST_BUFFER_DATA (buf),
+ sample_count / enc->channels)) {
+ GST_DEBUG ("encoding samples successful");
+ ret = GST_FLOW_OK;
+ } else {
+ if ((enc->srcpad_last_return == GST_FLOW_RESEND) ||
+ (enc->wvcsrcpad_last_return == GST_FLOW_RESEND)) {
+ ret = GST_FLOW_RESEND;
+ } else if ((enc->srcpad_last_return == GST_FLOW_OK) ||
+ (enc->wvcsrcpad_last_return == GST_FLOW_OK)) {
+ ret = GST_FLOW_OK;
+ } else if ((enc->srcpad_last_return == GST_FLOW_NOT_LINKED) &&
+ (enc->wvcsrcpad_last_return == GST_FLOW_NOT_LINKED)) {
+ ret = GST_FLOW_NOT_LINKED;
+ } else if ((enc->srcpad_last_return == GST_FLOW_WRONG_STATE) &&
+ (enc->wvcsrcpad_last_return == GST_FLOW_WRONG_STATE)) {
+ ret = GST_FLOW_WRONG_STATE;
+ } else {
+ GST_ELEMENT_ERROR (enc, LIBRARY, ENCODE, (NULL),
+ ("encoding samples failed"));
+ ret = GST_FLOW_ERROR;
+ }
+ }
+
+ gst_buffer_unref (buf);
+ gst_object_unref (enc);
+ return ret;
+}
+
+static void
+gst_wavpack_enc_rewrite_first_block (GstWavpackEnc * enc)
+{
+ GstEvent *event = gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES,
+ 0, GST_BUFFER_OFFSET_NONE, 0);
+ gboolean ret;
+
+ g_return_if_fail (enc);
+ g_return_if_fail (enc->first_block);
+
+ /* update the sample count in the first block */
+ WavpackUpdateNumSamples (enc->wp_context, enc->first_block);
+
+ /* try to seek to the beginning of the output */
+ ret = gst_pad_push_event (enc->srcpad, event);
+ if (ret) {
+ /* try to rewrite the first block */
+ GST_DEBUG_OBJECT (enc, "rewriting first block ...");
+ enc->wv_id.passthrough = TRUE;
+ ret = gst_wavpack_enc_push_block (&enc->wv_id,
+ enc->first_block, enc->first_block_size);
+ enc->wv_id.passthrough = FALSE;
+ } else {
+ GST_WARNING_OBJECT (enc, "rewriting of first block failed. "
+ "Seeking to first block failed!");
+ }
+}
+
+static gboolean
+gst_wavpack_enc_sink_event (GstPad * pad, GstEvent * event)
+{
+ GstWavpackEnc *enc = GST_WAVPACK_ENC (gst_pad_get_parent (pad));
+ gboolean ret = TRUE;
+
+ GST_DEBUG ("Received %s event on sinkpad", GST_EVENT_TYPE_NAME (event));
+
+ switch (GST_EVENT_TYPE (event)) {
+ case GST_EVENT_EOS:
+ /* Encode all remaining samples and flush them to the src pads */
+ WavpackFlushSamples (enc->wp_context);
+
+ /* Drop all remaining data, this is no complete block otherwise
+ * it would've been pushed already */
+ if (enc->pending_buffer) {
+ gst_buffer_unref (enc->pending_buffer);
+ enc->pending_buffer = NULL;
+ enc->pending_offset = 0;
+ }
+
+ /* write the MD5 sum if we have to write one */
+ if ((enc->md5) && (enc->md5_context)) {
+ guint8 md5_digest[16];
+ gsize digest_len = sizeof (md5_digest);
+
+ g_checksum_get_digest (enc->md5_context, md5_digest, &digest_len);
+ if (digest_len == sizeof (md5_digest))
+ WavpackStoreMD5Sum (enc->wp_context, md5_digest);
+ else
+ GST_WARNING_OBJECT (enc, "Calculating MD5 digest failed");
+ }
+
+ /* Try to rewrite the first frame with the correct sample number */
+ if (enc->first_block)
+ gst_wavpack_enc_rewrite_first_block (enc);
+
+ /* close the context if not already happened */
+ if (enc->wp_context) {
+ WavpackCloseFile (enc->wp_context);
+ enc->wp_context = NULL;
+ }
+
+ ret = gst_pad_event_default (pad, event);
+ break;
+ case GST_EVENT_NEWSEGMENT:
+ if (enc->wp_context) {
+ GST_WARNING_OBJECT (enc, "got NEWSEGMENT after encoding "
+ "already started");
+ }
+ /* drop NEWSEGMENT events, we create our own when pushing
+ * the first buffer to the pads */
+ gst_event_unref (event);
+ ret = TRUE;
+ break;
+ default:
+ ret = gst_pad_event_default (pad, event);
+ break;
+ }
+
+ gst_object_unref (enc);
+ return ret;
+}
+
+static GstStateChangeReturn
+gst_wavpack_enc_change_state (GstElement * element, GstStateChange transition)
+{
+ GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
+ GstWavpackEnc *enc = GST_WAVPACK_ENC (element);
+
+ switch (transition) {
+ case GST_STATE_CHANGE_NULL_TO_READY:
+ /* set the last returned GstFlowReturns of the two pads to GST_FLOW_OK
+ * as they're only set to something else in WavpackPackSamples() or more
+ * specific gst_wavpack_enc_push_block() and nothing happened there yet */
+ enc->srcpad_last_return = enc->wvcsrcpad_last_return = GST_FLOW_OK;
+ break;
+ case GST_STATE_CHANGE_READY_TO_PAUSED:
+ break;
+ case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
+ default:
+ break;
+ }
+
+ ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
+
+ switch (transition) {
+ case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
+ break;
+ case GST_STATE_CHANGE_PAUSED_TO_READY:
+ gst_wavpack_enc_reset (enc);
+ break;
+ case GST_STATE_CHANGE_READY_TO_NULL:
+ break;
+ default:
+ break;
+ }
+
+ return ret;
+}
+
+static void
+gst_wavpack_enc_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec)
+{
+ GstWavpackEnc *enc = GST_WAVPACK_ENC (object);
+
+ switch (prop_id) {
+ case ARG_MODE:
+ enc->mode = g_value_get_enum (value);
+ break;
+ case ARG_BITRATE:{
+ guint val = g_value_get_uint (value);
+
+ if ((val >= 24000) && (val <= 9600000)) {
+ enc->bitrate = val;
+ enc->bps = 0.0;
+ } else {
+ enc->bitrate = 0;
+ enc->bps = 0.0;
+ }
+ break;
+ }
+ case ARG_BITSPERSAMPLE:{
+ gdouble val = g_value_get_double (value);
+
+ if ((val >= 2.0) && (val <= 24.0)) {
+ enc->bps = val;
+ enc->bitrate = 0;
+ } else {
+ enc->bps = 0.0;
+ enc->bitrate = 0;
+ }
+ break;
+ }
+ case ARG_CORRECTION_MODE:
+ enc->correction_mode = g_value_get_enum (value);
+ break;
+ case ARG_MD5:
+ enc->md5 = g_value_get_boolean (value);
+ break;
+ case ARG_EXTRA_PROCESSING:
+ enc->extra_processing = g_value_get_uint (value);
+ break;
+ case ARG_JOINT_STEREO_MODE:
+ enc->joint_stereo_mode = g_value_get_enum (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gst_wavpack_enc_get_property (GObject * object, guint prop_id, GValue * value,
+ GParamSpec * pspec)
+{
+ GstWavpackEnc *enc = GST_WAVPACK_ENC (object);
+
+ switch (prop_id) {
+ case ARG_MODE:
+ g_value_set_enum (value, enc->mode);
+ break;
+ case ARG_BITRATE:
+ if (enc->bps == 0.0) {
+ g_value_set_uint (value, enc->bitrate);
+ } else {
+ g_value_set_uint (value, 0);
+ }
+ break;
+ case ARG_BITSPERSAMPLE:
+ if (enc->bitrate == 0) {
+ g_value_set_double (value, enc->bps);
+ } else {
+ g_value_set_double (value, 0.0);
+ }
+ break;
+ case ARG_CORRECTION_MODE:
+ g_value_set_enum (value, enc->correction_mode);
+ break;
+ case ARG_MD5:
+ g_value_set_boolean (value, enc->md5);
+ break;
+ case ARG_EXTRA_PROCESSING:
+ g_value_set_uint (value, enc->extra_processing);
+ break;
+ case ARG_JOINT_STEREO_MODE:
+ g_value_set_enum (value, enc->joint_stereo_mode);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+gboolean
+gst_wavpack_enc_plugin_init (GstPlugin * plugin)
+{
+ if (!gst_element_register (plugin, "wavpackenc",
+ GST_RANK_NONE, GST_TYPE_WAVPACK_ENC))
+ return FALSE;
+
+ GST_DEBUG_CATEGORY_INIT (gst_wavpack_enc_debug, "wavpack_enc", 0,
+ "Wavpack encoder");
+
+ return TRUE;
+}
diff --git a/ext/wavpack/gstwavpackenc.h b/ext/wavpack/gstwavpackenc.h
new file mode 100644
index 0000000..d2df844
--- /dev/null
+++ b/ext/wavpack/gstwavpackenc.h
@@ -0,0 +1,104 @@
+/* GStreamer Wavpack encoder plugin
+ * Copyright (c) 2006 Sebastian Dröge <slomo@circular-chaos.org>
+ *
+ * gstwavpackenc.h: Wavpack audio encoder
+ *
+ * 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 __GST_WAVPACK_ENC_H__
+#define __GST_WAVPACK_ENC_H__
+
+#include <gst/gst.h>
+
+#include <wavpack/wavpack.h>
+
+G_BEGIN_DECLS
+#define GST_TYPE_WAVPACK_ENC \
+ (gst_wavpack_enc_get_type())
+#define GST_WAVPACK_ENC(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_WAVPACK_ENC,GstWavpackEnc))
+#define GST_WAVPACK_ENC_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_WAVPACK_ENC,GstWavpackEnc))
+#define GST_IS_WAVPACK_ENC(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_WAVPACK_ENC))
+#define GST_IS_WAVPACK_ENC_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_WAVPACK_ENC))
+typedef struct _GstWavpackEnc GstWavpackEnc;
+typedef struct _GstWavpackEncClass GstWavpackEncClass;
+
+typedef struct
+{
+ gboolean correction;
+ GstWavpackEnc *wavpack_enc;
+ gboolean passthrough;
+} GstWavpackEncWriteID;
+
+
+struct _GstWavpackEnc
+{
+ GstElement element;
+
+ /*< private > */
+ GstPad *sinkpad, *srcpad;
+ GstPad *wvcsrcpad;
+
+ GstFlowReturn srcpad_last_return;
+ GstFlowReturn wvcsrcpad_last_return;
+
+ WavpackConfig *wp_config;
+ WavpackContext *wp_context;
+
+ gint samplerate;
+ gint channels;
+ gint channel_mask;
+ gint8 channel_mapping[8];
+ gboolean need_channel_remap;
+ gint depth;
+
+ GstWavpackEncWriteID wv_id;
+ GstWavpackEncWriteID wvc_id;
+
+ guint mode;
+ guint bitrate;
+ gdouble bps;
+ guint correction_mode;
+ gboolean md5;
+ GChecksum *md5_context;
+ guint extra_processing;
+ guint joint_stereo_mode;
+
+ void *first_block;
+ int32_t first_block_size;
+
+ GstBuffer *pending_buffer;
+ gint32 pending_offset;
+
+ GstClockTime timestamp_offset;
+ GstClockTime next_ts;
+};
+
+struct _GstWavpackEncClass
+{
+ GstElementClass parent;
+};
+
+GType gst_wavpack_enc_get_type (void);
+
+gboolean gst_wavpack_enc_plugin_init (GstPlugin * plugin);
+
+G_END_DECLS
+#endif /* __GST_WAVPACK_ENC_H__ */
diff --git a/ext/wavpack/gstwavpackparse.c b/ext/wavpack/gstwavpackparse.c
new file mode 100644
index 0000000..e1ff785
--- /dev/null
+++ b/ext/wavpack/gstwavpackparse.c
@@ -0,0 +1,1344 @@
+/* GStreamer wavpack plugin
+ * Copyright (c) 2005 Arwed v. Merkatz <v.merkatz@gmx.net>
+ * Copyright (c) 2006 Tim-Philipp Müller <tim centricular net>
+ * Copyright (c) 2006 Sebastian Dröge <slomo@circular-chaos.org>
+ *
+ * gstwavpackparse.c: wavpack file parser
+ *
+ * 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.
+ */
+
+/**
+ * SECTION:element-wavpackparse
+ *
+ * WavpackParse takes raw, unframed Wavpack streams and splits them into
+ * single Wavpack chunks with information like bit depth and the position
+ * in the stream.
+ * <ulink url="http://www.wavpack.com/">Wavpack</ulink> is an open-source
+ * audio codec that features both lossless and lossy encoding.
+ *
+ * <refsect2>
+ * <title>Example launch line</title>
+ * |[
+ * gst-launch filesrc location=test.wv ! wavpackparse ! wavpackdec ! fakesink
+ * ]| This pipeline decodes the Wavpack file test.wv into raw audio buffers.
+ * </refsect2>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* FIXME 0.11: suppress warnings for deprecated API such as GStaticRecMutex
+ * with newer GLib versions (>= 2.31.0) */
+#define GLIB_DISABLE_DEPRECATION_WARNINGS
+
+#include <gst/gst.h>
+#include <gst/gst-i18n-plugin.h>
+
+#include <math.h>
+#include <string.h>
+
+#include <wavpack/wavpack.h>
+#include "gstwavpackparse.h"
+#include "gstwavpackstreamreader.h"
+#include "gstwavpackcommon.h"
+
+GST_DEBUG_CATEGORY_STATIC (gst_wavpack_parse_debug);
+#define GST_CAT_DEFAULT gst_wavpack_parse_debug
+
+static inline GstWavpackParseIndexEntry *
+gst_wavpack_parse_index_entry_new (void)
+{
+ return g_slice_new (GstWavpackParseIndexEntry);
+}
+
+static inline void
+gst_wavpack_parse_index_entry_free (GstWavpackParseIndexEntry * entry)
+{
+ g_slice_free (GstWavpackParseIndexEntry, entry);
+}
+
+static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
+ GST_PAD_SINK,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("audio/x-wavpack, "
+ "framed = (boolean) false; "
+ "audio/x-wavpack-correction, " "framed = (boolean) false")
+ );
+
+static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
+ GST_PAD_SRC,
+ GST_PAD_SOMETIMES,
+ GST_STATIC_CAPS ("audio/x-wavpack, "
+ "width = (int) [ 1, 32 ], "
+ "channels = (int) [ 1, 8 ], "
+ "rate = (int) [ 6000, 192000 ], " "framed = (boolean) true")
+ );
+
+static GstStaticPadTemplate wvc_src_factory = GST_STATIC_PAD_TEMPLATE ("wvcsrc",
+ GST_PAD_SRC,
+ GST_PAD_SOMETIMES,
+ GST_STATIC_CAPS ("audio/x-wavpack-correction, " "framed = (boolean) true")
+ );
+
+static gboolean gst_wavpack_parse_sink_activate (GstPad * sinkpad);
+
+static gboolean
+gst_wavpack_parse_sink_activate_pull (GstPad * sinkpad, gboolean active);
+
+static void gst_wavpack_parse_loop (GstElement * element);
+
+static GstStateChangeReturn gst_wavpack_parse_change_state (GstElement *
+ element, GstStateChange transition);
+static void gst_wavpack_parse_reset (GstWavpackParse * parse);
+
+static gint64 gst_wavpack_parse_get_upstream_length (GstWavpackParse * wvparse);
+
+static GstBuffer *gst_wavpack_parse_pull_buffer (GstWavpackParse * wvparse,
+ gint64 offset, guint size, GstFlowReturn * flow);
+static GstFlowReturn gst_wavpack_parse_chain (GstPad * pad, GstBuffer * buf);
+
+GST_BOILERPLATE (GstWavpackParse, gst_wavpack_parse, GstElement,
+ GST_TYPE_ELEMENT);
+
+static void
+gst_wavpack_parse_base_init (gpointer klass)
+{
+ GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
+
+ gst_element_class_add_static_pad_template (element_class, &src_factory);
+ gst_element_class_add_static_pad_template (element_class,
+ &wvc_src_factory);
+ gst_element_class_add_static_pad_template (element_class, &sink_factory);
+
+ gst_element_class_set_details_simple (element_class, "Wavpack parser",
+ "Codec/Demuxer/Audio",
+ "Parses Wavpack files",
+ "Arwed v. Merkatz <v.merkatz@gmx.net>, "
+ "Sebastian Dröge <slomo@circular-chaos.org>");
+}
+
+static void
+gst_wavpack_parse_finalize (GObject * object)
+{
+ gst_wavpack_parse_reset (GST_WAVPACK_PARSE (object));
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+gst_wavpack_parse_class_init (GstWavpackParseClass * klass)
+{
+ GObjectClass *gobject_class;
+
+ GstElementClass *gstelement_class;
+
+ gobject_class = (GObjectClass *) klass;
+ gstelement_class = (GstElementClass *) klass;
+
+ gobject_class->finalize = gst_wavpack_parse_finalize;
+ gstelement_class->change_state =
+ GST_DEBUG_FUNCPTR (gst_wavpack_parse_change_state);
+}
+
+static GstWavpackParseIndexEntry *
+gst_wavpack_parse_index_get_last_entry (GstWavpackParse * wvparse)
+{
+ g_assert (wvparse->entries != NULL);
+
+ return wvparse->entries->data;
+}
+
+static GstWavpackParseIndexEntry *
+gst_wavpack_parse_index_get_entry_from_sample (GstWavpackParse * wvparse,
+ gint64 sample_offset)
+{
+ gint i;
+
+ GSList *node;
+
+ if (wvparse->entries == NULL)
+ return NULL;
+
+ for (node = wvparse->entries, i = 0; node; node = node->next, i++) {
+ GstWavpackParseIndexEntry *entry;
+
+ entry = node->data;
+
+ GST_LOG_OBJECT (wvparse, "Index entry %03u: sample %" G_GINT64_FORMAT " @"
+ " byte %" G_GINT64_FORMAT, i, entry->sample_offset, entry->byte_offset);
+
+ if (entry->sample_offset <= sample_offset &&
+ sample_offset < entry->sample_offset_end) {
+ GST_LOG_OBJECT (wvparse, "found match");
+ return entry;
+ }
+
+ /* as the list is sorted and we first look at the latest entry
+ * we can abort searching for an entry if the sample we want is
+ * after the latest one */
+ if (sample_offset >= entry->sample_offset_end)
+ break;
+ }
+ GST_LOG_OBJECT (wvparse, "no match in index");
+ return NULL;
+}
+
+static void
+gst_wavpack_parse_index_append_entry (GstWavpackParse * wvparse,
+ gint64 byte_offset, gint64 sample_offset, gint64 num_samples)
+{
+ GstWavpackParseIndexEntry *entry;
+
+ /* do we have this one already? */
+ if (wvparse->entries) {
+ entry = gst_wavpack_parse_index_get_last_entry (wvparse);
+ if (entry->byte_offset >= byte_offset
+ || entry->sample_offset >= sample_offset)
+ return;
+ }
+
+ GST_LOG_OBJECT (wvparse, "Adding index entry %8" G_GINT64_FORMAT " - %"
+ GST_TIME_FORMAT " @ offset 0x%08" G_GINT64_MODIFIER "x", sample_offset,
+ GST_TIME_ARGS (gst_util_uint64_scale_int (sample_offset,
+ GST_SECOND, wvparse->samplerate)), byte_offset);
+
+ entry = gst_wavpack_parse_index_entry_new ();
+ entry->byte_offset = byte_offset;
+ entry->sample_offset = sample_offset;
+ entry->sample_offset_end = sample_offset + num_samples;
+ wvparse->entries = g_slist_prepend (wvparse->entries, entry);
+}
+
+static void
+gst_wavpack_parse_reset (GstWavpackParse * parse)
+{
+ parse->total_samples = G_GINT64_CONSTANT (-1);
+ parse->samplerate = 0;
+ parse->channels = 0;
+
+ gst_segment_init (&parse->segment, GST_FORMAT_UNDEFINED);
+ parse->next_block_index = 0;
+
+ parse->current_offset = 0;
+ parse->need_newsegment = TRUE;
+ parse->discont = TRUE;
+ parse->upstream_length = -1;
+
+ if (parse->entries) {
+ g_slist_foreach (parse->entries, (GFunc) gst_wavpack_parse_index_entry_free,
+ NULL);
+ g_slist_free (parse->entries);
+ parse->entries = NULL;
+ }
+
+ if (parse->adapter) {
+ gst_adapter_clear (parse->adapter);
+ g_object_unref (parse->adapter);
+ parse->adapter = NULL;
+ }
+
+ if (parse->srcpad != NULL) {
+ gboolean res;
+
+ GST_DEBUG_OBJECT (parse, "Removing src pad");
+ res = gst_element_remove_pad (GST_ELEMENT (parse), parse->srcpad);
+ g_return_if_fail (res != FALSE);
+ gst_object_unref (parse->srcpad);
+ parse->srcpad = NULL;
+ }
+
+ g_list_foreach (parse->queued_events, (GFunc) gst_mini_object_unref, NULL);
+ g_list_free (parse->queued_events);
+ parse->queued_events = NULL;
+
+ if (parse->pending_buffer)
+ gst_buffer_unref (parse->pending_buffer);
+
+ parse->pending_buffer = NULL;
+}
+
+static const GstQueryType *
+gst_wavpack_parse_get_src_query_types (GstPad * pad)
+{
+ static const GstQueryType types[] = {
+ GST_QUERY_POSITION,
+ GST_QUERY_DURATION,
+ GST_QUERY_SEEKING,
+ 0
+ };
+
+ return types;
+}
+
+static gboolean
+gst_wavpack_parse_src_query (GstPad * pad, GstQuery * query)
+{
+ GstWavpackParse *parse = GST_WAVPACK_PARSE (gst_pad_get_parent (pad));
+
+ GstFormat format;
+
+ gboolean ret = FALSE;
+
+ switch (GST_QUERY_TYPE (query)) {
+ case GST_QUERY_POSITION:{
+ gint64 cur;
+
+ guint rate;
+
+ GST_OBJECT_LOCK (parse);
+ cur = parse->segment.last_stop;
+ rate = parse->samplerate;
+ GST_OBJECT_UNLOCK (parse);
+
+ if (rate == 0) {
+ GST_DEBUG_OBJECT (parse, "haven't read header yet");
+ break;
+ }
+
+ gst_query_parse_position (query, &format, NULL);
+
+ switch (format) {
+ case GST_FORMAT_TIME:
+ cur = gst_util_uint64_scale_int (cur, GST_SECOND, rate);
+ gst_query_set_position (query, GST_FORMAT_TIME, cur);
+ ret = TRUE;
+ break;
+ case GST_FORMAT_DEFAULT:
+ gst_query_set_position (query, GST_FORMAT_DEFAULT, cur);
+ ret = TRUE;
+ break;
+ default:
+ GST_DEBUG_OBJECT (parse, "cannot handle position query in "
+ "%s format. Forwarding upstream.", gst_format_get_name (format));
+ ret = gst_pad_query_default (pad, query);
+ break;
+ }
+ break;
+ }
+ case GST_QUERY_DURATION:{
+ gint64 len;
+
+ guint rate;
+
+ GST_OBJECT_LOCK (parse);
+ rate = parse->samplerate;
+ len = parse->total_samples;
+ GST_OBJECT_UNLOCK (parse);
+
+ if (rate == 0) {
+ GST_DEBUG_OBJECT (parse, "haven't read header yet");
+ break;
+ }
+
+ gst_query_parse_duration (query, &format, NULL);
+
+ switch (format) {
+ case GST_FORMAT_TIME:
+ if (len != G_GINT64_CONSTANT (-1))
+ len = gst_util_uint64_scale_int (len, GST_SECOND, rate);
+ gst_query_set_duration (query, GST_FORMAT_TIME, len);
+ ret = TRUE;
+ break;
+ case GST_FORMAT_DEFAULT:
+ gst_query_set_duration (query, GST_FORMAT_DEFAULT, len);
+ ret = TRUE;
+ break;
+ default:
+ GST_DEBUG_OBJECT (parse, "cannot handle duration query in "
+ "%s format. Forwarding upstream.", gst_format_get_name (format));
+ ret = gst_pad_query_default (pad, query);
+ break;
+ }
+ break;
+ }
+ case GST_QUERY_SEEKING:{
+ gst_query_parse_seeking (query, &format, NULL, NULL, NULL);
+ if (format == GST_FORMAT_TIME || format == GST_FORMAT_DEFAULT) {
+ gboolean seekable;
+
+ gint64 duration = -1;
+
+ /* only fails if we didn't read the headers yet and can't say
+ * anything about our seeking capabilities */
+ if (!gst_pad_query_duration (pad, &format, &duration))
+ break;
+
+ /* can't seek in streaming mode yet */
+ GST_OBJECT_LOCK (parse);
+ seekable = (parse->adapter == NULL);
+ GST_OBJECT_UNLOCK (parse);
+
+ gst_query_set_seeking (query, format, seekable, 0, duration);
+ ret = TRUE;
+ }
+ break;
+ }
+ default:{
+ ret = gst_pad_query_default (pad, query);
+ break;
+ }
+ }
+
+ gst_object_unref (parse);
+ return ret;
+
+}
+
+/* returns TRUE on success, with byte_offset set to the offset of the
+ * wavpack chunk containing the sample requested. start_sample will be
+ * set to the first sample in the chunk starting at byte_offset.
+ * Scanning from the last known header offset to the wanted position
+ * when seeking forward isn't very clever, but seems fast enough in
+ * practice and has the nice side effect of populating our index
+ * table */
+static gboolean
+gst_wavpack_parse_scan_to_find_sample (GstWavpackParse * parse,
+ gint64 sample, gint64 * byte_offset, gint64 * start_sample)
+{
+ GstWavpackParseIndexEntry *entry;
+
+ GstFlowReturn ret;
+
+ gint64 off = 0;
+
+ /* first, check if we have to scan at all */
+ entry = gst_wavpack_parse_index_get_entry_from_sample (parse, sample);
+ if (entry) {
+ *byte_offset = entry->byte_offset;
+ *start_sample = entry->sample_offset;
+ GST_LOG_OBJECT (parse, "Found index entry: sample %" G_GINT64_FORMAT
+ " @ offset %" G_GINT64_FORMAT, entry->sample_offset,
+ entry->byte_offset);
+ return TRUE;
+ }
+
+ GST_LOG_OBJECT (parse, "No matching entry in index, scanning file ...");
+
+ /* if we have an index, we can start scanning from the last known offset
+ * in there, after all we know our wanted sample is not in the index */
+ if (parse->entries) {
+ GstWavpackParseIndexEntry *entry;
+
+ entry = gst_wavpack_parse_index_get_last_entry (parse);
+ off = entry->byte_offset;
+ }
+
+ /* now scan forward until we find the chunk we're looking for or hit EOS */
+ do {
+ WavpackHeader header;
+
+ GstBuffer *buf;
+
+ buf = gst_wavpack_parse_pull_buffer (parse, off, sizeof (WavpackHeader),
+ &ret);
+
+ if (buf == NULL)
+ break;
+
+ gst_wavpack_read_header (&header, GST_BUFFER_DATA (buf));
+ gst_buffer_unref (buf);
+
+ if (header.flags & INITIAL_BLOCK)
+ gst_wavpack_parse_index_append_entry (parse, off, header.block_index,
+ header.block_samples);
+ else
+ continue;
+
+ if (header.block_index <= sample &&
+ sample < (header.block_index + header.block_samples)) {
+ *byte_offset = off;
+ *start_sample = header.block_index;
+ return TRUE;
+ }
+
+ off += header.ckSize + 8;
+ } while (1);
+
+ GST_DEBUG_OBJECT (parse, "scan failed: %s (off=0x%08" G_GINT64_MODIFIER "x)",
+ gst_flow_get_name (ret), off);
+
+ return FALSE;
+}
+
+static gboolean
+gst_wavpack_parse_send_newsegment (GstWavpackParse * wvparse, gboolean update)
+{
+ GstSegment *s = &wvparse->segment;
+
+ gboolean ret;
+
+ gint64 stop_time = -1;
+
+ gint64 start_time = 0;
+
+ gint64 cur_pos_time;
+
+ gint64 diff;
+
+ /* segment is in DEFAULT format, but we want to send a TIME newsegment */
+ start_time = gst_util_uint64_scale_int (s->start, GST_SECOND,
+ wvparse->samplerate);
+
+ if (s->stop != -1) {
+ stop_time = gst_util_uint64_scale_int (s->stop, GST_SECOND,
+ wvparse->samplerate);
+ }
+
+ GST_DEBUG_OBJECT (wvparse, "sending newsegment from %" GST_TIME_FORMAT
+ " to %" GST_TIME_FORMAT, GST_TIME_ARGS (start_time),
+ GST_TIME_ARGS (stop_time));
+
+ /* after a seek, s->last_stop will point to a chunk boundary, ie. from
+ * which sample we will start sending data again, while s->start will
+ * point to the sample we actually want to seek to and want to start
+ * playing right after the seek. Adjust clock-time for the difference
+ * so we start playing from start_time */
+ cur_pos_time = gst_util_uint64_scale_int (s->last_stop, GST_SECOND,
+ wvparse->samplerate);
+ diff = start_time - cur_pos_time;
+
+ ret = gst_pad_push_event (wvparse->srcpad,
+ gst_event_new_new_segment (update, s->rate, GST_FORMAT_TIME,
+ start_time, stop_time, start_time - diff));
+
+ return ret;
+}
+
+static gboolean
+gst_wavpack_parse_handle_seek_event (GstWavpackParse * wvparse,
+ GstEvent * event)
+{
+ GstSeekFlags seek_flags;
+
+ GstSeekType start_type;
+
+ GstSeekType stop_type;
+
+ GstSegment segment;
+
+ GstFormat format;
+
+ gboolean only_update;
+
+ gboolean flush, ret;
+
+ gdouble speed;
+
+ gint64 stop;
+
+ gint64 start; /* sample we want to seek to */
+
+ gint64 byte_offset; /* byte offset the chunk we seek to starts at */
+
+ gint64 chunk_start; /* first sample in chunk we seek to */
+
+ guint rate;
+
+ gint64 last_stop;
+
+ if (wvparse->adapter) {
+ GST_DEBUG_OBJECT (wvparse, "seeking in streaming mode not implemented yet");
+ return FALSE;
+ }
+
+ gst_event_parse_seek (event, &speed, &format, &seek_flags, &start_type,
+ &start, &stop_type, &stop);
+
+ if (format != GST_FORMAT_DEFAULT && format != GST_FORMAT_TIME) {
+ GST_DEBUG ("seeking is only supported in TIME or DEFAULT format");
+ return FALSE;
+ }
+
+ if (speed < 0.0) {
+ GST_DEBUG ("only forward playback supported, rate %f not allowed", speed);
+ return FALSE;
+ }
+
+ GST_OBJECT_LOCK (wvparse);
+
+ rate = wvparse->samplerate;
+ if (rate == 0) {
+ GST_OBJECT_UNLOCK (wvparse);
+ GST_DEBUG ("haven't read header yet");
+ return FALSE;
+ }
+
+ /* figure out the last position we need to play. If it's configured (stop !=
+ * -1), use that, else we play until the total duration of the file */
+ if (stop == -1)
+ stop = wvparse->segment.duration;
+
+ /* convert from time to samples if necessary */
+ if (format == GST_FORMAT_TIME) {
+ if (start_type != GST_SEEK_TYPE_NONE)
+ start = gst_util_uint64_scale_int (start, rate, GST_SECOND);
+ if (stop_type != GST_SEEK_TYPE_NONE)
+ stop = gst_util_uint64_scale_int (stop, rate, GST_SECOND);
+ }
+
+ if (start < 0) {
+ GST_OBJECT_UNLOCK (wvparse);
+ GST_DEBUG_OBJECT (wvparse, "Invalid start sample %" G_GINT64_FORMAT, start);
+ return FALSE;
+ }
+
+ flush = ((seek_flags & GST_SEEK_FLAG_FLUSH) != 0);
+
+ /* operate on segment copy until we know the seek worked */
+ segment = wvparse->segment;
+
+ gst_segment_set_seek (&segment, speed, GST_FORMAT_DEFAULT,
+ seek_flags, start_type, start, stop_type, stop, &only_update);
+
+#if 0
+ if (only_update) {
+ wvparse->segment = segment;
+ gst_wavpack_parse_send_newsegment (wvparse, TRUE);
+ goto done;
+ }
+#endif
+
+ gst_pad_push_event (wvparse->sinkpad, gst_event_new_flush_start ());
+
+ if (flush) {
+ gst_pad_push_event (wvparse->srcpad, gst_event_new_flush_start ());
+ } else {
+ gst_pad_pause_task (wvparse->sinkpad);
+ }
+
+ GST_PAD_STREAM_LOCK (wvparse->sinkpad);
+
+ /* Save current position */
+ last_stop = wvparse->segment.last_stop;
+
+ gst_pad_push_event (wvparse->sinkpad, gst_event_new_flush_stop ());
+
+ if (flush) {
+ gst_pad_push_event (wvparse->srcpad, gst_event_new_flush_stop ());
+ }
+
+ GST_DEBUG_OBJECT (wvparse, "Performing seek to %" GST_TIME_FORMAT " sample %"
+ G_GINT64_FORMAT, GST_TIME_ARGS (segment.start * GST_SECOND / rate),
+ start);
+
+ ret = gst_wavpack_parse_scan_to_find_sample (wvparse, segment.start,
+ &byte_offset, &chunk_start);
+
+ if (ret) {
+ GST_DEBUG_OBJECT (wvparse, "new offset: %" G_GINT64_FORMAT, byte_offset);
+ wvparse->current_offset = byte_offset;
+ /* we want to send a newsegment event with the actual seek position
+ * as start, even though our first buffer might start before the
+ * configured segment. We leave it up to the decoder or sink to crop
+ * the output buffers accordingly */
+ wvparse->segment = segment;
+ wvparse->segment.last_stop = chunk_start;
+ wvparse->need_newsegment = TRUE;
+ wvparse->discont = (last_stop != chunk_start) ? TRUE : FALSE;
+
+ /* if we're doing a segment seek, post a SEGMENT_START message */
+ if (wvparse->segment.flags & GST_SEEK_FLAG_SEGMENT) {
+ gst_element_post_message (GST_ELEMENT_CAST (wvparse),
+ gst_message_new_segment_start (GST_OBJECT_CAST (wvparse),
+ wvparse->segment.format, wvparse->segment.last_stop));
+ }
+ } else {
+ GST_DEBUG_OBJECT (wvparse, "seek failed: don't know where to seek to");
+ }
+
+ GST_PAD_STREAM_UNLOCK (wvparse->sinkpad);
+ GST_OBJECT_UNLOCK (wvparse);
+
+ gst_pad_start_task (wvparse->sinkpad,
+ (GstTaskFunction) gst_wavpack_parse_loop, wvparse);
+
+ return ret;
+}
+
+static gboolean
+gst_wavpack_parse_sink_event (GstPad * pad, GstEvent * event)
+{
+ GstWavpackParse *parse;
+
+ gboolean ret = TRUE;
+
+ parse = GST_WAVPACK_PARSE (gst_pad_get_parent (pad));
+
+ switch (GST_EVENT_TYPE (event)) {
+ case GST_EVENT_FLUSH_STOP:{
+ if (parse->adapter) {
+ gst_adapter_clear (parse->adapter);
+ }
+ if (parse->pending_buffer) {
+ gst_buffer_unref (parse->pending_buffer);
+ parse->pending_buffer = NULL;
+ parse->pending_offset = 0;
+ }
+ ret = gst_pad_push_event (parse->srcpad, event);
+ break;
+ }
+ case GST_EVENT_NEWSEGMENT:{
+ parse->need_newsegment = TRUE;
+ gst_event_unref (event);
+ ret = TRUE;
+ break;
+ }
+ case GST_EVENT_EOS:{
+ if (parse->adapter) {
+ /* remove all bytes that are left in the adapter after EOS. They can't
+ * be a complete Wavpack block and we can't do anything with them */
+ gst_adapter_clear (parse->adapter);
+ }
+ if (parse->pending_buffer) {
+ gst_buffer_unref (parse->pending_buffer);
+ parse->pending_buffer = NULL;
+ parse->pending_offset = 0;
+ }
+ ret = gst_pad_push_event (parse->srcpad, event);
+ break;
+ }
+ default:{
+ /* stream lock is recursive, should be fine for all events */
+ GST_PAD_STREAM_LOCK (pad);
+ if (parse->srcpad == NULL) {
+ parse->queued_events = g_list_append (parse->queued_events, event);
+ } else {
+ ret = gst_pad_push_event (parse->srcpad, event);
+ }
+ GST_PAD_STREAM_UNLOCK (pad);
+ }
+ }
+
+
+ gst_object_unref (parse);
+ return ret;
+}
+
+static gboolean
+gst_wavpack_parse_src_event (GstPad * pad, GstEvent * event)
+{
+ GstWavpackParse *parse;
+
+ gboolean ret;
+
+ parse = GST_WAVPACK_PARSE (gst_pad_get_parent (pad));
+
+ switch (GST_EVENT_TYPE (event)) {
+ case GST_EVENT_SEEK:
+ ret = gst_wavpack_parse_handle_seek_event (parse, event);
+ break;
+ default:
+ ret = gst_pad_event_default (pad, event);
+ break;
+ }
+
+ gst_object_unref (parse);
+ return ret;
+}
+
+static void
+gst_wavpack_parse_init (GstWavpackParse * parse, GstWavpackParseClass * gclass)
+{
+ GstElementClass *klass = GST_ELEMENT_GET_CLASS (parse);
+
+ GstPadTemplate *tmpl;
+
+ tmpl = gst_element_class_get_pad_template (klass, "sink");
+ parse->sinkpad = gst_pad_new_from_template (tmpl, "sink");
+
+ gst_pad_set_activate_function (parse->sinkpad,
+ GST_DEBUG_FUNCPTR (gst_wavpack_parse_sink_activate));
+ gst_pad_set_activatepull_function (parse->sinkpad,
+ GST_DEBUG_FUNCPTR (gst_wavpack_parse_sink_activate_pull));
+ gst_pad_set_event_function (parse->sinkpad,
+ GST_DEBUG_FUNCPTR (gst_wavpack_parse_sink_event));
+ gst_pad_set_chain_function (parse->sinkpad,
+ GST_DEBUG_FUNCPTR (gst_wavpack_parse_chain));
+
+ gst_element_add_pad (GST_ELEMENT (parse), parse->sinkpad);
+
+ parse->srcpad = NULL;
+ gst_wavpack_parse_reset (parse);
+}
+
+static gint64
+gst_wavpack_parse_get_upstream_length (GstWavpackParse * parse)
+{
+ gint64 length = -1;
+
+ GstFormat format = GST_FORMAT_BYTES;
+
+ if (!gst_pad_query_peer_duration (parse->sinkpad, &format, &length)) {
+ length = -1;
+ } else {
+ GST_DEBUG ("upstream length: %" G_GINT64_FORMAT, length);
+ }
+ return length;
+}
+
+static GstBuffer *
+gst_wavpack_parse_pull_buffer (GstWavpackParse * wvparse, gint64 offset,
+ guint size, GstFlowReturn * flow)
+{
+ GstFlowReturn flow_ret;
+
+ GstBuffer *buf = NULL;
+
+ if (offset + size > wvparse->upstream_length) {
+ wvparse->upstream_length = gst_wavpack_parse_get_upstream_length (wvparse);
+ if (offset + size > wvparse->upstream_length) {
+ GST_DEBUG_OBJECT (wvparse, "EOS: %" G_GINT64_FORMAT " + %u > %"
+ G_GINT64_FORMAT, offset, size, wvparse->upstream_length);
+ flow_ret = GST_FLOW_UNEXPECTED;
+ goto done;
+ }
+ }
+
+ flow_ret = gst_pad_pull_range (wvparse->sinkpad, offset, size, &buf);
+
+ if (flow_ret != GST_FLOW_OK) {
+ GST_DEBUG_OBJECT (wvparse, "pull_range (%" G_GINT64_FORMAT ", %u) "
+ "failed, flow: %s", offset, size, gst_flow_get_name (flow_ret));
+ buf = NULL;
+ goto done;
+ }
+
+ if (GST_BUFFER_SIZE (buf) < size) {
+ GST_DEBUG_OBJECT (wvparse, "Short read at offset %" G_GINT64_FORMAT
+ ", got only %u of %u bytes", offset, GST_BUFFER_SIZE (buf), size);
+ gst_buffer_unref (buf);
+ buf = NULL;
+ flow_ret = GST_FLOW_UNEXPECTED;
+ }
+
+done:
+ if (flow)
+ *flow = flow_ret;
+ return buf;
+}
+
+static gboolean
+gst_wavpack_parse_create_src_pad (GstWavpackParse * wvparse, GstBuffer * buf,
+ WavpackHeader * header)
+{
+ GstWavpackMetadata meta;
+
+ GstCaps *caps = NULL;
+
+ guchar *bufptr;
+
+ g_assert (wvparse->srcpad == NULL);
+
+ bufptr = GST_BUFFER_DATA (buf) + sizeof (WavpackHeader);
+
+ while (gst_wavpack_read_metadata (&meta, GST_BUFFER_DATA (buf), &bufptr)) {
+ switch (meta.id) {
+ case ID_WVC_BITSTREAM:{
+ caps = gst_caps_new_simple ("audio/x-wavpack-correction",
+ "framed", G_TYPE_BOOLEAN, TRUE, NULL);
+ wvparse->srcpad =
+ gst_pad_new_from_template (gst_element_class_get_pad_template
+ (GST_ELEMENT_GET_CLASS (wvparse), "wvcsrc"), "wvcsrc");
+ break;
+ }
+ case ID_WV_BITSTREAM:
+ case ID_WVX_BITSTREAM:{
+ WavpackStreamReader *stream_reader = gst_wavpack_stream_reader_new ();
+
+ WavpackContext *wpc;
+
+ gchar error_msg[80];
+
+ read_id rid;
+
+ gint channel_mask;
+
+ rid.buffer = GST_BUFFER_DATA (buf);
+ rid.length = GST_BUFFER_SIZE (buf);
+ rid.position = 0;
+
+ wpc =
+ WavpackOpenFileInputEx (stream_reader, &rid, NULL, error_msg, 0, 0);
+
+ if (!wpc)
+ return FALSE;
+
+ wvparse->samplerate = WavpackGetSampleRate (wpc);
+ wvparse->channels = WavpackGetNumChannels (wpc);
+ wvparse->total_samples =
+ (header->total_samples ==
+ 0xffffffff) ? G_GINT64_CONSTANT (-1) : header->total_samples;
+
+ caps = gst_caps_new_simple ("audio/x-wavpack",
+ "width", G_TYPE_INT, WavpackGetBitsPerSample (wpc),
+ "channels", G_TYPE_INT, wvparse->channels,
+ "rate", G_TYPE_INT, wvparse->samplerate,
+ "framed", G_TYPE_BOOLEAN, TRUE, NULL);
+#ifdef WAVPACK_OLD_API
+ channel_mask = wpc->config.channel_mask;
+#else
+ channel_mask = WavpackGetChannelMask (wpc);
+#endif
+ if (channel_mask == 0)
+ channel_mask =
+ gst_wavpack_get_default_channel_mask (wvparse->channels);
+
+ if (channel_mask != 0) {
+ if (!gst_wavpack_set_channel_layout (caps, channel_mask)) {
+ GST_WARNING_OBJECT (wvparse, "Failed to set channel layout");
+ gst_caps_unref (caps);
+ caps = NULL;
+ WavpackCloseFile (wpc);
+ g_free (stream_reader);
+ break;
+ }
+ }
+
+ wvparse->srcpad =
+ gst_pad_new_from_template (gst_element_class_get_pad_template
+ (GST_ELEMENT_GET_CLASS (wvparse), "src"), "src");
+ WavpackCloseFile (wpc);
+ g_free (stream_reader);
+ break;
+ }
+ default:{
+ GST_LOG_OBJECT (wvparse, "unhandled ID: 0x%02x", meta.id);
+ break;
+ }
+ }
+ if (caps != NULL)
+ break;
+ }
+
+ if (caps == NULL || wvparse->srcpad == NULL)
+ return FALSE;
+
+ GST_DEBUG_OBJECT (wvparse, "Added src pad with caps %" GST_PTR_FORMAT, caps);
+
+ gst_pad_set_query_function (wvparse->srcpad,
+ GST_DEBUG_FUNCPTR (gst_wavpack_parse_src_query));
+ gst_pad_set_query_type_function (wvparse->srcpad,
+ GST_DEBUG_FUNCPTR (gst_wavpack_parse_get_src_query_types));
+ gst_pad_set_event_function (wvparse->srcpad,
+ GST_DEBUG_FUNCPTR (gst_wavpack_parse_src_event));
+
+ gst_pad_set_caps (wvparse->srcpad, caps);
+ gst_caps_unref (caps);
+ gst_pad_use_fixed_caps (wvparse->srcpad);
+
+ gst_object_ref (wvparse->srcpad);
+ gst_pad_set_active (wvparse->srcpad, TRUE);
+ gst_element_add_pad (GST_ELEMENT (wvparse), wvparse->srcpad);
+ gst_element_no_more_pads (GST_ELEMENT (wvparse));
+
+ return TRUE;
+}
+
+static GstFlowReturn
+gst_wavpack_parse_push_buffer (GstWavpackParse * wvparse, GstBuffer * buf,
+ WavpackHeader * header)
+{
+ GstFlowReturn ret;
+ wvparse->current_offset += header->ckSize + 8;
+
+ wvparse->segment.last_stop = header->block_index;
+
+ if (wvparse->need_newsegment) {
+ if (gst_wavpack_parse_send_newsegment (wvparse, FALSE))
+ wvparse->need_newsegment = FALSE;
+ }
+
+ /* send any queued events */
+ if (wvparse->queued_events) {
+ GList *l;
+
+ for (l = wvparse->queued_events; l != NULL; l = l->next) {
+ gst_pad_push_event (wvparse->srcpad, GST_EVENT (l->data));
+ }
+ g_list_free (wvparse->queued_events);
+ wvparse->queued_events = NULL;
+ }
+
+ if (wvparse->pending_buffer == NULL) {
+ wvparse->pending_buffer = buf;
+ wvparse->pending_offset = header->block_index;
+ } else if (wvparse->pending_offset == header->block_index) {
+ wvparse->pending_buffer = gst_buffer_join (wvparse->pending_buffer, buf);
+ } else {
+ GST_ERROR ("Got incomplete block, dropping");
+ gst_buffer_unref (wvparse->pending_buffer);
+ wvparse->pending_buffer = buf;
+ wvparse->pending_offset = header->block_index;
+ }
+
+ if (!(header->flags & FINAL_BLOCK))
+ return GST_FLOW_OK;
+
+ buf = wvparse->pending_buffer;
+ wvparse->pending_buffer = NULL;
+
+ GST_BUFFER_TIMESTAMP (buf) = gst_util_uint64_scale_int (header->block_index,
+ GST_SECOND, wvparse->samplerate);
+ GST_BUFFER_DURATION (buf) = gst_util_uint64_scale_int (header->block_samples,
+ GST_SECOND, wvparse->samplerate);
+ GST_BUFFER_OFFSET (buf) = header->block_index;
+ GST_BUFFER_OFFSET_END (buf) = header->block_index + header->block_samples;
+
+ if (wvparse->discont || wvparse->next_block_index != header->block_index) {
+ GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
+ wvparse->discont = FALSE;
+ }
+
+ wvparse->next_block_index = header->block_index + header->block_samples;
+
+ gst_buffer_set_caps (buf, GST_PAD_CAPS (wvparse->srcpad));
+
+ GST_LOG_OBJECT (wvparse, "Pushing buffer with time %" GST_TIME_FORMAT,
+ GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
+
+ ret = gst_pad_push (wvparse->srcpad, buf);
+
+ wvparse->segment.last_stop = wvparse->next_block_index;
+
+ return ret;
+}
+
+static guint8 *
+gst_wavpack_parse_find_marker (guint8 * buf, guint size)
+{
+ int i;
+
+ guint8 *ret = NULL;
+
+ if (G_UNLIKELY (size < 4))
+ return NULL;
+
+ for (i = 0; i < size - 4; i++) {
+ if (memcmp (buf + i, "wvpk", 4) == 0) {
+ ret = buf + i;
+ break;
+ }
+ }
+ return ret;
+}
+
+static GstFlowReturn
+gst_wavpack_parse_resync_loop (GstWavpackParse * parse, WavpackHeader * header)
+{
+ GstFlowReturn flow_ret = GST_FLOW_UNEXPECTED;
+
+ GstBuffer *buf = NULL;
+
+ /* loop until we have a frame header or reach the end of the stream */
+ while (1) {
+ guint8 *data, *marker;
+
+ guint len, size;
+
+ if (buf) {
+ gst_buffer_unref (buf);
+ buf = NULL;
+ }
+
+ if (parse->upstream_length == 0 ||
+ parse->upstream_length <= parse->current_offset) {
+ parse->upstream_length = gst_wavpack_parse_get_upstream_length (parse);
+ if (parse->upstream_length == 0 ||
+ parse->upstream_length <= parse->current_offset) {
+ break;
+ }
+ }
+
+ len = MIN (parse->upstream_length - parse->current_offset, 2048);
+
+ GST_LOG_OBJECT (parse, "offset: %" G_GINT64_FORMAT, parse->current_offset);
+
+ buf = gst_wavpack_parse_pull_buffer (parse, parse->current_offset,
+ len, &flow_ret);
+
+ /* whatever the problem is, there's nothing more for us to do for now */
+ if (flow_ret != GST_FLOW_OK)
+ break;
+
+ data = GST_BUFFER_DATA (buf);
+ size = GST_BUFFER_SIZE (buf);
+
+ /* not enough data for a header? */
+ if (size < sizeof (WavpackHeader))
+ break;
+
+ /* got a header right where we are at now? */
+ if (gst_wavpack_read_header (header, data))
+ break;
+
+ /* nope, let's see if we can find one */
+ marker = gst_wavpack_parse_find_marker (data + 1, size - 1);
+
+ if (marker) {
+ parse->current_offset += marker - data;
+ /* do one more loop iteration to make sure we pull enough
+ * data for a full header, we'll bail out then */
+ } else {
+ parse->current_offset += len - 4;
+ }
+ }
+
+ if (buf)
+ gst_buffer_unref (buf);
+
+ return flow_ret;
+}
+
+static void
+gst_wavpack_parse_loop (GstElement * element)
+{
+ GstWavpackParse *parse = GST_WAVPACK_PARSE (element);
+
+ GstFlowReturn flow_ret;
+ WavpackHeader header = { {0,}, 0, };
+ GstBuffer *buf = NULL;
+
+ flow_ret = gst_wavpack_parse_resync_loop (parse, &header);
+
+ if (flow_ret != GST_FLOW_OK)
+ goto pause;
+
+ GST_LOG_OBJECT (parse, "Read header at offset %" G_GINT64_FORMAT
+ ": chunk size = %u+8", parse->current_offset, header.ckSize);
+
+ buf = gst_wavpack_parse_pull_buffer (parse, parse->current_offset,
+ header.ckSize + 8, &flow_ret);
+
+ if (flow_ret != GST_FLOW_OK)
+ goto pause;
+
+ if (parse->srcpad == NULL) {
+ if (!gst_wavpack_parse_create_src_pad (parse, buf, &header)) {
+ GST_ERROR_OBJECT (parse, "Failed to create src pad");
+ flow_ret = GST_FLOW_ERROR;
+ goto pause;
+ }
+ }
+ if (header.flags & INITIAL_BLOCK)
+ gst_wavpack_parse_index_append_entry (parse, parse->current_offset,
+ header.block_index, header.block_samples);
+
+ flow_ret = gst_wavpack_parse_push_buffer (parse, buf, &header);
+ if (flow_ret != GST_FLOW_OK)
+ goto pause;
+
+ return;
+
+pause:
+ {
+ const gchar *reason = gst_flow_get_name (flow_ret);
+
+ GST_LOG_OBJECT (parse, "pausing task, reason %s", reason);
+ gst_pad_pause_task (parse->sinkpad);
+
+ if (flow_ret == GST_FLOW_UNEXPECTED && parse->srcpad) {
+ if (parse->segment.flags & GST_SEEK_FLAG_SEGMENT) {
+ GstClockTime stop;
+
+ GST_LOG_OBJECT (parse, "Sending segment done");
+
+ if ((stop = parse->segment.stop) == -1)
+ stop = parse->segment.duration;
+
+ gst_element_post_message (GST_ELEMENT_CAST (parse),
+ gst_message_new_segment_done (GST_OBJECT_CAST (parse),
+ parse->segment.format, stop));
+ } else {
+ GST_LOG_OBJECT (parse, "Sending EOS, at end of stream");
+ gst_pad_push_event (parse->srcpad, gst_event_new_eos ());
+ }
+ } else if (flow_ret == GST_FLOW_NOT_LINKED
+ || flow_ret < GST_FLOW_UNEXPECTED) {
+ GST_ELEMENT_ERROR (parse, STREAM, FAILED,
+ (_("Internal data stream error.")), ("stream stopped, reason %s",
+ reason));
+ if (parse->srcpad)
+ gst_pad_push_event (parse->srcpad, gst_event_new_eos ());
+ }
+ return;
+ }
+}
+
+static gboolean
+gst_wavpack_parse_resync_adapter (GstAdapter * adapter)
+{
+ const guint8 *buf, *marker;
+
+ guint avail = gst_adapter_available (adapter);
+
+ if (avail < 4)
+ return FALSE;
+
+ /* if the marker is at the beginning don't do the expensive search */
+ buf = gst_adapter_peek (adapter, 4);
+ if (memcmp (buf, "wvpk", 4) == 0)
+ return TRUE;
+
+ if (avail == 4)
+ return FALSE;
+
+ /* search for the marker in the complete content of the adapter */
+ buf = gst_adapter_peek (adapter, avail);
+ if (buf && (marker = gst_wavpack_parse_find_marker ((guint8 *) buf, avail))) {
+ gst_adapter_flush (adapter, marker - buf);
+ return TRUE;
+ }
+
+ /* flush everything except the last 4 bytes. they could contain
+ * the start of a new marker */
+ gst_adapter_flush (adapter, avail - 4);
+
+ return FALSE;
+}
+
+static GstFlowReturn
+gst_wavpack_parse_chain (GstPad * pad, GstBuffer * buf)
+{
+ GstWavpackParse *wvparse = GST_WAVPACK_PARSE (GST_PAD_PARENT (pad));
+
+ GstFlowReturn ret = GST_FLOW_OK;
+
+ WavpackHeader wph;
+
+ const guint8 *tmp_buf;
+
+ if (!wvparse->adapter) {
+ wvparse->adapter = gst_adapter_new ();
+ }
+
+ if (GST_BUFFER_IS_DISCONT (buf)) {
+ gst_adapter_clear (wvparse->adapter);
+ wvparse->discont = TRUE;
+ }
+
+ gst_adapter_push (wvparse->adapter, buf);
+
+ if (gst_adapter_available (wvparse->adapter) < sizeof (WavpackHeader))
+ return ret;
+
+ if (!gst_wavpack_parse_resync_adapter (wvparse->adapter))
+ return ret;
+
+ tmp_buf = gst_adapter_peek (wvparse->adapter, sizeof (WavpackHeader));
+ gst_wavpack_read_header (&wph, (guint8 *) tmp_buf);
+
+ while (gst_adapter_available (wvparse->adapter) >= wph.ckSize + 4 * 1 + 4) {
+ GstBuffer *outbuf =
+ gst_adapter_take_buffer (wvparse->adapter, wph.ckSize + 4 * 1 + 4);
+
+ if (!outbuf)
+ return GST_FLOW_ERROR;
+
+ if (wvparse->srcpad == NULL) {
+ if (!gst_wavpack_parse_create_src_pad (wvparse, outbuf, &wph)) {
+ GST_ERROR_OBJECT (wvparse, "Failed to create src pad");
+ ret = GST_FLOW_ERROR;
+ break;
+ }
+ }
+
+ ret = gst_wavpack_parse_push_buffer (wvparse, outbuf, &wph);
+
+ if (ret != GST_FLOW_OK)
+ break;
+
+ if (gst_adapter_available (wvparse->adapter) >= sizeof (WavpackHeader)) {
+ tmp_buf = gst_adapter_peek (wvparse->adapter, sizeof (WavpackHeader));
+
+ if (!gst_wavpack_parse_resync_adapter (wvparse->adapter))
+ break;
+
+ gst_wavpack_read_header (&wph, (guint8 *) tmp_buf);
+ }
+ }
+
+ return ret;
+}
+
+static GstStateChangeReturn
+gst_wavpack_parse_change_state (GstElement * element, GstStateChange transition)
+{
+ GstWavpackParse *wvparse = GST_WAVPACK_PARSE (element);
+
+ GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
+
+ switch (transition) {
+ case GST_STATE_CHANGE_READY_TO_PAUSED:
+ gst_segment_init (&wvparse->segment, GST_FORMAT_DEFAULT);
+ wvparse->segment.last_stop = 0;
+ default:
+ break;
+ }
+
+ if (GST_ELEMENT_CLASS (parent_class)->change_state)
+ ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
+
+ switch (transition) {
+ case GST_STATE_CHANGE_PAUSED_TO_READY:
+ gst_wavpack_parse_reset (wvparse);
+ break;
+ default:
+ break;
+ }
+
+ return ret;
+}
+
+static gboolean
+gst_wavpack_parse_sink_activate (GstPad * sinkpad)
+{
+ if (gst_pad_check_pull_range (sinkpad)) {
+ return gst_pad_activate_pull (sinkpad, TRUE);
+ } else {
+ return gst_pad_activate_push (sinkpad, TRUE);
+ }
+}
+
+static gboolean
+gst_wavpack_parse_sink_activate_pull (GstPad * sinkpad, gboolean active)
+{
+ gboolean result;
+
+ if (active) {
+ result = gst_pad_start_task (sinkpad,
+ (GstTaskFunction) gst_wavpack_parse_loop, GST_PAD_PARENT (sinkpad));
+ } else {
+ result = gst_pad_stop_task (sinkpad);
+ }
+
+ return result;
+}
+
+gboolean
+gst_wavpack_parse_plugin_init (GstPlugin * plugin)
+{
+ if (!gst_element_register (plugin, "wavpackparse",
+ GST_RANK_PRIMARY, GST_TYPE_WAVPACK_PARSE)) {
+ return FALSE;
+ }
+
+ GST_DEBUG_CATEGORY_INIT (gst_wavpack_parse_debug, "wavpack_parse", 0,
+ "Wavpack file parser");
+
+ return TRUE;
+}
diff --git a/ext/wavpack/gstwavpackparse.h b/ext/wavpack/gstwavpackparse.h
new file mode 100644
index 0000000..60504a7
--- /dev/null
+++ b/ext/wavpack/gstwavpackparse.h
@@ -0,0 +1,97 @@
+/* GStreamer wavpack plugin
+ * (c) 2005 Arwed v. Merkatz <v.merkatz@gmx.net>
+ *
+ * gstwavpackparse.h: wavpack file parser
+ *
+ * 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 __GST_WAVPACK_PARSE_H__
+#define __GST_WAVPACK_PARSE_H__
+
+#include <gst/gst.h>
+#include <gst/base/gstadapter.h>
+
+G_BEGIN_DECLS
+#define GST_TYPE_WAVPACK_PARSE \
+ (gst_wavpack_parse_get_type())
+#define GST_WAVPACK_PARSE(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_WAVPACK_PARSE,GstWavpackParse))
+#define GST_WAVPACK_PARSE_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_WAVPACK_PARSE,GstWavpackParseClass))
+#define GST_IS_WAVPACK_PARSE(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_WAVPACK_PARSE))
+#define GST_IS_WAVPACK_PARSE_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_WAVPACK_PARSE))
+typedef struct _GstWavpackParse GstWavpackParse;
+typedef struct _GstWavpackParseClass GstWavpackParseClass;
+typedef struct _GstWavpackParseIndexEntry GstWavpackParseIndexEntry;
+
+struct _GstWavpackParseIndexEntry
+{
+ gint64 byte_offset; /* byte offset of this chunk */
+ gint64 sample_offset; /* first sample in this chunk */
+ gint64 sample_offset_end; /* first sample in next chunk */
+};
+
+struct _GstWavpackParse
+{
+ GstElement element;
+
+ /*< private > */
+ GstPad *sinkpad;
+ GstPad *srcpad;
+
+ guint samplerate;
+ guint channels;
+ gint64 total_samples;
+
+ gboolean need_newsegment;
+ gboolean discont;
+
+ gint64 current_offset; /* byte offset on sink pad */
+ gint64 upstream_length; /* length of file in bytes */
+
+ GstSegment segment; /* the currently configured segment, in
+ * samples/audio frames (DEFAULT format) */
+
+ GstBuffer *pending_buffer;
+ gint32 pending_offset;
+ guint32 next_block_index;
+
+ GstAdapter *adapter; /* when operating chain-based, otherwise NULL */
+
+ /* List of GstWavpackParseIndexEntry structs, mapping known
+ * sample offsets to byte offsets. Is kept increasing without
+ * gaps (ie. append only and consecutive entries must always
+ * map to consecutive chunks in the file). */
+ GSList *entries;
+
+ /* Queued events (e.g. tag events we receive before we create the src pad) */
+ GList *queued_events; /* STREAM_LOCK */
+};
+
+struct _GstWavpackParseClass
+{
+ GstElementClass parent;
+};
+
+GType gst_wavpack_parse_get_type (void);
+
+gboolean gst_wavpack_parse_plugin_init (GstPlugin * plugin);
+
+G_END_DECLS
+#endif /* __GST_WAVPACK_PARSE_H__ */
diff --git a/ext/wavpack/gstwavpackstreamreader.c b/ext/wavpack/gstwavpackstreamreader.c
new file mode 100644
index 0000000..074a2e7
--- /dev/null
+++ b/ext/wavpack/gstwavpackstreamreader.c
@@ -0,0 +1,124 @@
+/* GStreamer Wavpack plugin
+ * Copyright (c) 2006 Sebastian Dröge <slomo@circular-chaos.org>
+ *
+ * gstwavpackstreamreader.c: stream reader used for decoding
+ *
+ * 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 <math.h>
+#include <gst/gst.h>
+
+#include "gstwavpackstreamreader.h"
+
+GST_DEBUG_CATEGORY_EXTERN (wavpack_debug);
+#define GST_CAT_DEFAULT wavpack_debug
+
+static int32_t
+gst_wavpack_stream_reader_read_bytes (void *id, void *data, int32_t bcount)
+{
+ read_id *rid = (read_id *) id;
+ uint32_t left = rid->length - rid->position;
+ uint32_t to_read = MIN (left, bcount);
+
+ GST_DEBUG ("Trying to read %d of %d bytes from position %d", bcount,
+ rid->length, rid->position);
+
+ if (to_read > 0) {
+ g_memmove (data, rid->buffer + rid->position, to_read);
+ rid->position += to_read;
+ return to_read;
+ } else {
+ GST_WARNING ("Couldn't read %d bytes", bcount);
+ return 0;
+ }
+}
+
+static uint32_t
+gst_wavpack_stream_reader_get_pos (void *id)
+{
+ GST_DEBUG ("Returning position %d", ((read_id *) id)->position);
+ return ((read_id *) id)->position;
+}
+
+static int
+gst_wavpack_stream_reader_set_pos_abs (void *id, uint32_t pos)
+{
+ GST_WARNING ("Should not be called: tried to set absolute position to %d",
+ pos);
+ return -1;
+}
+
+static int
+gst_wavpack_stream_reader_set_pos_rel (void *id, int32_t delta, int mode)
+{
+ GST_WARNING ("Should not be called: tried to set relative position to %d"
+ " with mode %d", delta, mode);
+ return -1;
+}
+
+static int
+gst_wavpack_stream_reader_push_back_byte (void *id, int c)
+{
+ read_id *rid = (read_id *) id;
+
+ GST_DEBUG ("Pushing back one byte: 0x%x", c);
+
+ rid->position -= 1;
+ if (rid->position < 0)
+ rid->position = 0;
+ return rid->position;
+}
+
+static uint32_t
+gst_wavpack_stream_reader_get_length (void *id)
+{
+ GST_DEBUG ("Returning length %d", ((read_id *) id)->length);
+
+ return ((read_id *) id)->length;
+}
+
+static int
+gst_wavpack_stream_reader_can_seek (void *id)
+{
+ GST_DEBUG ("Can't seek");
+ return FALSE;
+}
+
+static int32_t
+gst_wavpack_stream_reader_write_bytes (void *id, void *data, int32_t bcount)
+{
+ GST_WARNING ("Should not be called, tried to write %d bytes", bcount);
+ return 0;
+}
+
+WavpackStreamReader *
+gst_wavpack_stream_reader_new (void)
+{
+ WavpackStreamReader *stream_reader =
+ (WavpackStreamReader *) g_malloc0 (sizeof (WavpackStreamReader));
+ stream_reader->read_bytes = gst_wavpack_stream_reader_read_bytes;
+ stream_reader->get_pos = gst_wavpack_stream_reader_get_pos;
+ stream_reader->set_pos_abs = gst_wavpack_stream_reader_set_pos_abs;
+ stream_reader->set_pos_rel = gst_wavpack_stream_reader_set_pos_rel;
+ stream_reader->push_back_byte = gst_wavpack_stream_reader_push_back_byte;
+ stream_reader->get_length = gst_wavpack_stream_reader_get_length;
+ stream_reader->can_seek = gst_wavpack_stream_reader_can_seek;
+ stream_reader->write_bytes = gst_wavpack_stream_reader_write_bytes;
+
+ return stream_reader;
+}
diff --git a/ext/wavpack/gstwavpackstreamreader.h b/ext/wavpack/gstwavpackstreamreader.h
new file mode 100644
index 0000000..713b4c1
--- /dev/null
+++ b/ext/wavpack/gstwavpackstreamreader.h
@@ -0,0 +1,36 @@
+/* GStreamer Wavpack plugin
+ * Copyright (c) 2006 Sebastian Dröge <slomo@circular-chaos.org>
+ *
+ * gstwavpackstreamreader.h: stream reader used for decoding
+ *
+ * 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 __GST_WAVPACK_STREAM_READER_H__
+#define __GST_WAVPACK_STREAM_READER_H__
+
+#include <wavpack/wavpack.h>
+
+typedef struct
+{
+ guint8 *buffer;
+ uint32_t length;
+ uint32_t position;
+} read_id;
+
+WavpackStreamReader *gst_wavpack_stream_reader_new (void);
+
+#endif