[xiph-commits] r7057 - in icecast/trunk/libshout: . src

brendan at dactyl.lonelymoon.com brendan
Thu Jul 8 14:46:17 PDT 2004


Author: brendan
Date: Thu Jul  8 14:46:17 2004
New Revision: 7057

Modified:
icecast/trunk/libshout/configure.in
icecast/trunk/libshout/src/Makefile.am
icecast/trunk/libshout/src/ogg.c
Log:
Added Karl's Theora support, plus just enough autoconf to compile with Theora.
It probably doesn't work right in general.


Modified: icecast/trunk/libshout/configure.in
===================================================================
--- icecast/trunk/libshout/configure.in	2004-07-08 20:54:12 UTC (rev 7056)
+++ icecast/trunk/libshout/configure.in	2004-07-08 21:46:15 UTC (rev 7057)
@@ -1,5 +1,5 @@
# Process this file with autoconf to produce a configure script.
-# $Id: configure.in,v 1.67 2004/01/30 00:17:26 oddsock Exp $
+# $Id$

m4_define(libshout_major, 2)
m4_define(libshout_minor, 0)
@@ -114,6 +114,10 @@
VORBIS_LIBS="$VORBIS_LDFLAGS $VORBIS_LIBS"
XIPH_CFLAGS="$XIPH_CFLAGS $VORBIS_CFLAGS"

+XIPH_PATH_THEORA(,[AC_MSG_WARN([Theora library not found, disabling])])
+XIPH_VAR_APPEND([XIPH_CPPFLAGS],[$THEORA_CFLAGS])
+XIPH_VAR_PREPEND([XIPH_LIBS],[$THEORA LDFLAGS $THEORA_LIBS])
+
dnl pkgconfig/shout-config.
dnl If pkgconfig is found, use it and disable shout-config, otherwise do the
dnl opposite, unless the user overrides.

Modified: icecast/trunk/libshout/src/Makefile.am
===================================================================
--- icecast/trunk/libshout/src/Makefile.am	2004-07-08 20:54:12 UTC (rev 7056)
+++ icecast/trunk/libshout/src/Makefile.am	2004-07-08 21:46:15 UTC (rev 7057)
@@ -16,7 +16,7 @@
AM_CFLAGS = @XIPH_CFLAGS@

libshout_la_LIBADD = net/libicenet.la timing/libicetiming.la avl/libiceavl.la\
-		httpp/libicehttpp.la $(MAYBE_THREAD_LIB) $(VORBIS_LIBS)
+		httpp/libicehttpp.la $(MAYBE_THREAD_LIB) $(THEORA_LIBS) $(VORBIS_LIBS)

INCLUDES = -I$(top_builddir)/include


Modified: icecast/trunk/libshout/src/ogg.c
===================================================================
--- icecast/trunk/libshout/src/ogg.c	2004-07-08 20:54:12 UTC (rev 7056)
+++ icecast/trunk/libshout/src/ogg.c	2004-07-08 21:46:15 UTC (rev 7057)
@@ -61,6 +61,15 @@
int prevW;
} vorbis_data_t;

+#ifdef HAVE_THEORA
+typedef struct {
+	theora_info ti;
+	theora_comment tc;
+	uint32_t granule_shift;
+	double prev_time;
+} theora_data_t;
+#endif
+
/* -- static prototypes -- */
static int send_ogg(shout_t *self, const unsigned char *data, size_t len);
static void close_ogg(shout_t *self);
@@ -78,6 +87,9 @@
#ifdef HAVE_THEORA
/* theora handler */
static int open_theora(ogg_codec_t *codec, ogg_page *page);
+static int read_theora_page(ogg_codec_t *codec, ogg_page *page);
+static void free_theora_data(void *codec_data);
+static int theora_ilog(unsigned int v);
#endif

typedef int (*codec_open_t)(ogg_codec_t *codec, ogg_page *page);
@@ -303,3 +315,93 @@
vd->prevW = this;
return ret;
}
+
+#ifdef HAVE_THEORA
+/* theora handler */
+static int open_theora(ogg_codec_t *codec, ogg_page *page)
+{
+	ogg_packet packet;
+
+	theora_data_t *theora_data = calloc(1, sizeof(theora_data_t));
+	if (! theora_data)
+		return SHOUTERR_MALLOC;
+
+	theora_info_init(&theora_data->ti);
+	theora_comment_init(&theora_data->tc);
+
+	ogg_stream_packetout(&codec->os, &packet);
+
+	if (theora_decode_header(&theora_data->ti, &theora_data->tc, &packet) < 0) {
+		free_theora_data(theora_data);
+
+		return SHOUTERR_UNSUPPORTED;
+	}
+
+	codec->codec_data = theora_data;
+	codec->read_page = read_theora_page;
+	codec->free_data = free_theora_data;
+	codec->headers = 1;
+
+	return SHOUTERR_SUCCESS;
+}
+
+static int read_theora_page(ogg_codec_t *codec, ogg_page *page)
+{
+	theora_data_t *theora_data = codec->codec_data;
+	ogg_packet packet;
+
+	if (ogg_page_granulepos(page) == 0)
+	{
+		while (ogg_stream_packetout(&codec->os, &packet) > 0) {
+			if (theora_decode_header(&theora_data->ti, &theora_data->tc, &packet) < 0)
+				return SHOUTERR_INSANE;
+			codec->headers++;
+		}
+		if (codec->headers == 3) {
+			theora_data->prev_time = 0;
+			theora_data->granule_shift = theora_ilog(theora_data->ti.keyframe_frequency_force - 1);
+		}
+
+		return SHOUTERR_SUCCESS;
+	}
+
+	double per_frame = (double)theora_data->ti.fps_denominator / theora_data->ti.fps_numerator * 1000000;
+	double duration;
+	ogg_int64_t granulepos = ogg_page_granulepos(page);
+
+	if (granulepos > 0) {
+		ogg_int64_t iframe = granulepos >> theora_data->granule_shift;
+		ogg_int64_t pframe = granulepos - (iframe << theora_data->granule_shift);
+		uint64_t frames = iframe + pframe;
+		double new_time = (frames  * per_frame);
+
+		duration = new_time - theora_data->prev_time;
+		theora_data->prev_time = new_time;
+
+		codec->senttime += (uint64_t)(duration + 0.5);
+	}
+
+	return SHOUTERR_SUCCESS;
+}
+
+static void free_theora_data(void *codec_data)
+{
+	theora_data_t *theora_data = (theora_data_t *)codec_data;
+
+	theora_info_clear(&theora_data->ti);
+	theora_comment_clear(&theora_data->tc);
+	free(theora_data);
+}
+
+static int theora_ilog(unsigned int v)
+{
+	int ret = 0;
+	while (v) {
+		ret++;
+		v >>= 1;
+	}
+
+	return ret;
+}
+
+#endif HAVE_THEORA



More information about the commits mailing list