AM_CONDITIONAL(HAVE_VORBIS, false)
define([CHECK_MODULE_OGG],
[
- AC_LMS_CHECK_PKG(VORBIS, vorbis, [], [OGG=false])
+ AC_CHECK_HEADERS(tremor/ivorbiscodec.h tremor/ivorbisfile.h, HAVE_IVORBIS_HEADERS=yes, HAVE_IVORBIS_HEADERS=no)
+ if test "x$HAVE_IVORBIS_HEADERS" = "xyes"; then
+ AC_CHECK_LIB(vorbisidec, ogg_sync_bufferin, HAVE_IVORBIS_LIBS=yes, HAVE_IVORBIS_LIBS=no)
+ fi
+
+ AM_CONDITIONAL(USE_TREMOR, test "x$HAVE_IVORBIS_LIBS" = "xyes")
+ if test "x$HAVE_IVORBIS_LIBS" = "xyes"; then
+ AC_DEFINE(USE_TREMOR, 1, Define if libvorbisidec (aka tremor) support is enabled)
+ VORBIS_LIBS="-lvorbisidec"
+ AC_SUBST(VORBIS_LIBS)
+ else
+ AC_LMS_CHECK_PKG(VORBIS, vorbis, [], [OGG=false])
+ fi
])
AM_CONDITIONAL(HAVE_MP4V2, false)
pkgdir = $(pluginsdir)
pkg_LTLIBRARIES = ogg.la
ogg_la_SOURCES = ogg.c
+
+if USE_TREMOR
+ogg_la_SOURCES += lms_ogg_tremor.c
+else
+ogg_la_SOURCES += lms_ogg_vorbis.c
+endif
+
ogg_la_DEPENDENCIES = $(top_builddir)/config.h
ogg_la_LIBADD = $(top_builddir)/src/lib/liblightmediascanner.la @VORBIS_LIBS@
ogg_la_LDFLAGS = -module -avoid-version
+
+noinst_HEADERS= lms_ogg_private.h
--- /dev/null
+/**
+ * Copyright (C) 2007-2008 by INdT
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * @author Eduardo Lima (Etrunko) <eduardo.lima@indt.org.br>
+ *
+ */
+
+#ifndef _LMS_OGG_PRIVATE_H_
+#define _LMS_OGG_PRIVATE_H_ 1
+
+#ifdef USE_TREMOR
+ #include <tremor/ivorbiscodec.h>
+ #include <tremor/ivorbisfile.h>
+#else
+ #include <vorbis/codec.h>
+ #include <vorbis/vorbisfile.h>
+#endif
+
+#ifdef USE_TREMOR
+ typedef unsigned char * lms_ogg_buffer_t;
+#else
+ typedef char * lms_ogg_buffer_t;
+#endif
+
+extern inline ogg_sync_state *lms_create_ogg_sync(void);
+extern inline void lms_destroy_ogg_sync(ogg_sync_state *osync);
+
+extern inline ogg_stream_state *lms_create_ogg_stream(int serial);
+extern inline void lms_destroy_ogg_stream(ogg_stream_state *ostream);
+
+extern inline lms_ogg_buffer_t lms_get_ogg_sync_buffer(ogg_sync_state * osync, long size);
+
+#endif /* _LMS_OGG_PRIVATE_H_ */
--- /dev/null
+/**
+ * Copyright (C) 2007-2008 by INdT
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * @author Eduardo Lima (Etrunko) <eduardo.lima@indt.org.br>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <tremor/ogg.h>
+
+#include "lms_ogg_private.h"
+
+ogg_sync_state *lms_create_ogg_sync(void)
+{
+ return ogg_sync_create();
+}
+
+void lms_destroy_ogg_sync(ogg_sync_state *osync)
+{
+ ogg_sync_destroy(osync);
+}
+
+ogg_stream_state *lms_create_ogg_stream(int serial)
+{
+ return ogg_stream_create(serial);
+}
+
+void lms_destroy_ogg_stream(ogg_stream_state *ostream)
+{
+ ogg_stream_destroy(ostream);
+}
+
+lms_ogg_buffer_t lms_get_ogg_sync_buffer(ogg_sync_state *osync, long size)
+{
+ return ogg_sync_bufferin(osync, size);
+}
--- /dev/null
+/**
+ * Copyright (C) 2007-2008 by INdT
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * @author Eduardo Lima (Etrunko) <eduardo.lima@indt.org.br>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <ogg/ogg.h>
+
+#include "lms_ogg_private.h"
+
+ogg_sync_state *lms_create_ogg_sync(void)
+{
+ ogg_sync_state *osync = (ogg_sync_state *) malloc(sizeof(ogg_sync_state));
+ ogg_sync_init(osync);
+
+ return osync;
+}
+
+void lms_destroy_ogg_sync(ogg_sync_state *osync)
+{
+ ogg_sync_clear(osync);
+ free(osync);
+}
+
+ogg_stream_state *lms_create_ogg_stream(int serial)
+{
+ ogg_stream_state * ostream = (ogg_stream_state *) malloc(sizeof(ogg_stream_state));
+ ogg_stream_init(ostream, serial);
+
+ return ostream;
+}
+
+void lms_destroy_ogg_stream(ogg_stream_state *ostream)
+{
+ ogg_stream_clear(ostream);
+ free(ostream);
+}
+
+lms_ogg_buffer_t lms_get_ogg_sync_buffer(ogg_sync_state *osync, long size)
+{
+ return ogg_sync_buffer(osync, size);
+}
#include <lightmediascanner_db.h>
#include <stdlib.h>
#include <string.h>
-#include <vorbis/codec.h>
-#include <vorbis/vorbisfile.h>
+
+#include "lms_ogg_private.h"
static long int
_id3_tag_size(FILE *file)
static int
_get_vorbis_comment(FILE *file, vorbis_comment *vc)
{
- char *buffer;
- int bytes, i, chunks = 0;
+ lms_ogg_buffer_t buffer = NULL;
+ int bytes = 0, i = 0, chunks = 0;
ogg_packet header;
ogg_page og;
- ogg_sync_state osync;
- ogg_stream_state os;
+ ogg_sync_state *osync = NULL;
+ ogg_stream_state *os = NULL;
vorbis_info vi;
- int serial;
+ int serial = 0;
+#ifndef CHUNKSIZE
int CHUNKSIZE = 4096;
+#endif
int nheaders = 0;
+ int ret = -1;
+
+ /* Initialize stuff */
+ memset(&header, 0, sizeof(ogg_packet));
+ memset(&og, 0, sizeof(ogg_page));
+ vorbis_info_init(&vi);
- ogg_sync_init(&osync);
+ osync = lms_create_ogg_sync();
while (1) {
- buffer = ogg_sync_buffer(&osync, CHUNKSIZE);
+ buffer = lms_get_ogg_sync_buffer(osync, CHUNKSIZE);
bytes = fread(buffer, 1, CHUNKSIZE, file);
- ogg_sync_wrote(&osync, bytes);
+ ogg_sync_wrote(osync, bytes);
- if (ogg_sync_pageout(&osync, &og) == 1)
+ if (ogg_sync_pageout(osync, &og) == 1)
break;
if (chunks++ >= 10)
- return -1;
+ goto end;
}
serial = ogg_page_serialno(&og);
+ os = lms_create_ogg_stream(serial);
- ogg_stream_init(&os, serial);
- vorbis_info_init(&vi);
vorbis_comment_init(vc);
- if (ogg_stream_pagein(&os, &og) < 0)
- return -1;
- if (ogg_stream_packetout(&os, &header) != 1)
- return -1;
- if (vorbis_synthesis_headerin(&vi, vc, &header) != 0)
- return -1;
+ if (ogg_stream_pagein(os, &og) < 0 ||
+ ogg_stream_packetout(os, &header) != 1 ||
+ vorbis_synthesis_headerin(&vi, vc, &header) != 0)
+ goto end;
i = 1;
nheaders = 3;
while (i < nheaders) {
while (i < nheaders) {
- int result = ogg_sync_pageout(&osync, &og);
+ int result = ogg_sync_pageout(osync, &og);
if (result == 0)
break;
else if (result == 1) {
- ogg_stream_pagein(&os, &og);
+ ogg_stream_pagein(os, &og);
while (i < nheaders) {
- result = ogg_stream_packetout(&os, &header);
+ result = ogg_stream_packetout(os, &header);
if (result == 0)
break;
if (result == -1)
- return -1;
+ goto end;
vorbis_synthesis_headerin(&vi, vc, &header);
i++;
}
}
- buffer = ogg_sync_buffer(&osync, CHUNKSIZE);
+ buffer = lms_get_ogg_sync_buffer(osync, CHUNKSIZE);
bytes = fread(buffer, 1, CHUNKSIZE, file);
if (bytes == 0 && i < 2)
- return -1;
+ goto end;
- ogg_sync_wrote(&osync, bytes);
+ ogg_sync_wrote(osync, bytes);
}
- ogg_stream_clear(&os);
- ogg_sync_clear(&osync);
+ ret = 0;
+
+end:
vorbis_info_clear(&vi);
- return 0;
+ if (os)
+ lms_destroy_ogg_stream(os);
+
+ if (osync)
+ lms_destroy_ogg_sync(osync);
+
+ return ret;
}
static int