[xiph-commits] r7181 - icecast/trunk/libshout/src

brendan at dactyl.lonelymoon.com brendan
Mon Jul 19 19:52:33 PDT 2004


Author: brendan
Date: Mon Jul 19 19:52:33 2004
New Revision: 7181

Added:
icecast/trunk/libshout/src/shout_ogg.h
icecast/trunk/libshout/src/vorbis.c
Modified:
icecast/trunk/libshout/src/Makefile.am
icecast/trunk/libshout/src/ogg.c
Log:
Move vorbis codec handler into separate file. Theora will be moved shortly.


Modified: icecast/trunk/libshout/src/Makefile.am
===================================================================
--- icecast/trunk/libshout/src/Makefile.am	2004-07-20 02:50:54 UTC (rev 7180)
+++ icecast/trunk/libshout/src/Makefile.am	2004-07-20 02:52:32 UTC (rev 7181)
@@ -11,8 +11,8 @@
lib_LTLIBRARIES = libshout.la
libshout_la_LDFLAGS = -version-info 3:0:0

-noinst_HEADERS = shout_private.h util.h
-libshout_la_SOURCES = shout.c util.c ogg.c mp3.c
+noinst_HEADERS = shout_ogg.h shout_private.h util.h
+libshout_la_SOURCES = shout.c util.c ogg.c vorbis.c mp3.c
AM_CFLAGS = @XIPH_CFLAGS@

libshout_la_LIBADD = net/libicenet.la timing/libicetiming.la avl/libiceavl.la\

Modified: icecast/trunk/libshout/src/ogg.c
===================================================================
--- icecast/trunk/libshout/src/ogg.c	2004-07-20 02:50:54 UTC (rev 7180)
+++ icecast/trunk/libshout/src/ogg.c	2004-07-20 02:52:32 UTC (rev 7181)
@@ -1,5 +1,5 @@
/* -*- c-basic-offset: 8; -*- */
-/* vorbis.c: Ogg Vorbis data handlers for libshout
+/* ogg.c: Generic ogg data handler
* $Id$
*
*  Copyright (C) 2002-2004 the Icecast team <team at icecast.org>
@@ -27,40 +27,21 @@
#include <string.h>

#include <ogg/ogg.h>
-#include <vorbis/codec.h>
#ifdef HAVE_THEORA
#include <theora/theora.h>
#endif

#include <shout/shout.h>
#include "shout_private.h"
+#include "shout_ogg.h"

/* -- local datatypes -- */
-typedef struct _ogg_codec_tag {
-	ogg_stream_state os;
-
-	unsigned int headers;
-	uint64_t senttime;
-
-	void *codec_data;
-	int (*read_page)(struct _ogg_codec_tag *codec, ogg_page *page);
-	void (*free_data)(void *codec_data);
-
-	struct _ogg_codec_tag *next;
-} ogg_codec_t;
-
typedef struct {
ogg_sync_state oy;
ogg_codec_t *codecs;
char bos;
} ogg_data_t;

-typedef struct {
-	vorbis_info vi;
-	vorbis_comment vc;
-	int prevW;
-} vorbis_data_t;
-
#ifdef HAVE_THEORA
typedef struct {
theora_info ti;
@@ -78,15 +59,8 @@
static void free_codecs(ogg_data_t *ogg_data);
static int send_page(shout_t *self, ogg_page *page);

-/* vorbis handler */
-static int open_vorbis(ogg_codec_t *codec, ogg_page *page);
-static int read_vorbis_page(ogg_codec_t *codec, ogg_page *page);
-static void free_vorbis_data(void *codec_data);
-static int vorbis_blocksize(vorbis_data_t *vd, ogg_packet *p);
-
#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);
@@ -241,83 +215,10 @@
return SHOUTERR_SUCCESS;
}

-/* -- vorbis functions -- */
-static int open_vorbis(ogg_codec_t *codec, ogg_page *page)
-{
-	vorbis_data_t *vorbis_data = calloc(1, sizeof(vorbis_data_t));
-	ogg_packet packet;

-	if (!vorbis_data)
-		return SHOUTERR_MALLOC;
-
-	vorbis_info_init(&vorbis_data->vi);
-	vorbis_comment_init(&vorbis_data->vc);
-
-	ogg_stream_packetout(&codec->os, &packet);
-
-	if (vorbis_synthesis_headerin(&vorbis_data->vi, &vorbis_data->vc, &packet) < 0) {
-		free_vorbis_data(vorbis_data);
-
-		return SHOUTERR_UNSUPPORTED;
-	}
-
-	codec->codec_data = vorbis_data;
-	codec->read_page = read_vorbis_page;
-	codec->free_data = free_vorbis_data;
-
-	return SHOUTERR_SUCCESS;
-}
-
-static int read_vorbis_page(ogg_codec_t *codec, ogg_page *page)
-{
-	ogg_packet packet;
-	vorbis_data_t *vorbis_data = codec->codec_data;
-	uint64_t samples = 0;
-
-	if (codec->headers < 3) {
-		while (ogg_stream_packetout (&codec->os, &packet) > 0) {
-			if (vorbis_synthesis_headerin(&vorbis_data->vi, &vorbis_data->vc, &packet) < 0)
-				return SHOUTERR_INSANE;
-			codec->headers++;
-		}
-
-		return SHOUTERR_SUCCESS;
-	}
-
-	while (ogg_stream_packetout (&codec->os, &packet) > 0)
-		samples += vorbis_blocksize(vorbis_data, &packet);
-
-	codec->senttime += ((samples * 1000000) / vorbis_data->vi.rate);
-
-	return SHOUTERR_SUCCESS;
-}
-
-static void free_vorbis_data(void *codec_data)
-{
-	vorbis_data_t *vorbis_data = (vorbis_data_t *)codec_data;
-
-	vorbis_info_clear(&vorbis_data->vi);
-	vorbis_comment_clear(&vorbis_data->vc);
-	free(vorbis_data);
-}
-
-static int vorbis_blocksize(vorbis_data_t *vd, ogg_packet *p)
-{
-	int this = vorbis_packet_blocksize(&vd->vi, p);
-	int ret = (this + vd->prevW)/4;
-
-	if(!vd->prevW) {
-		vd->prevW = this;
-		return 0;
-	}
-
-	vd->prevW = this;
-	return ret;
-}
-
#ifdef HAVE_THEORA
/* theora handler */
-static int open_theora(ogg_codec_t *codec, ogg_page *page)
+int open_theora(ogg_codec_t *codec, ogg_page *page)
{
ogg_packet packet;


Added: icecast/trunk/libshout/src/shout_ogg.h
===================================================================
--- icecast/trunk/libshout/src/shout_ogg.h	2004-07-20 02:50:54 UTC (rev 7180)
+++ icecast/trunk/libshout/src/shout_ogg.h	2004-07-20 02:52:32 UTC (rev 7181)
@@ -0,0 +1,52 @@
+/* -*- c-basic-offset: 8; -*- */
+/* shout_ogg.h: Internal shout interface to Ogg codec handlers
+ * $Id$
+ *
+ *  Copyright (C) 2004 the Icecast team <team at icecast.org>
+ *
+ *  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
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef __LIBSHOUT_SHOUT_OGG_H__
+#define __LIBSHOUT_SHOUT_OGG_H__
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+
+#include <ogg/ogg.h>
+
+typedef struct _ogg_codec_tag {
+	ogg_stream_state os;
+
+	unsigned int headers;
+	uint64_t senttime;
+
+	void *codec_data;
+	int (*read_page)(struct _ogg_codec_tag *codec, ogg_page *page);
+	void (*free_data)(void *codec_data);
+
+	struct _ogg_codec_tag *next;
+} ogg_codec_t;
+
+/* codec hooks */
+int open_vorbis(ogg_codec_t *codec, ogg_page *page);
+#ifdef HAVE_THEORA
+int open_theora(ogg_codec_t *codec, ogg_page *page);
+#endif
+
+#endif

Added: icecast/trunk/libshout/src/vorbis.c
===================================================================
--- icecast/trunk/libshout/src/vorbis.c	2004-07-20 02:50:54 UTC (rev 7180)
+++ icecast/trunk/libshout/src/vorbis.c	2004-07-20 02:52:32 UTC (rev 7181)
@@ -0,0 +1,115 @@
+/* -*- c-basic-offset: 8; -*- */
+/* vorbis.c: Ogg Vorbis data handlers for libshout
+ * $Id: vorbis.c,v 1.1 2004/07/20 02:49:54 brendan Exp $
+ *
+ *  Copyright (C) 2002-2004 the Icecast team <team at icecast.org>
+ *
+ *  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
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <vorbis/codec.h>
+
+#include "shout_private.h"
+#include "shout_ogg.h"
+
+/* -- local data structures -- */
+typedef struct {
+	vorbis_info vi;
+	vorbis_comment vc;
+	int prevW;
+} vorbis_data_t;
+
+/* -- local prototypes -- */
+static int read_vorbis_page(ogg_codec_t *codec, ogg_page *page);
+static void free_vorbis_data(void *codec_data);
+static int vorbis_blocksize(vorbis_data_t *vd, ogg_packet *p);
+
+/* -- vorbis functions -- */
+int open_vorbis(ogg_codec_t *codec, ogg_page *page)
+{
+	vorbis_data_t *vorbis_data = calloc(1, sizeof(vorbis_data_t));
+	ogg_packet packet;
+
+	if (!vorbis_data)
+		return SHOUTERR_MALLOC;
+
+	vorbis_info_init(&vorbis_data->vi);
+	vorbis_comment_init(&vorbis_data->vc);
+
+	ogg_stream_packetout(&codec->os, &packet);
+
+	if (vorbis_synthesis_headerin(&vorbis_data->vi, &vorbis_data->vc, &packet) < 0) {
+		free_vorbis_data(vorbis_data);
+
+		return SHOUTERR_UNSUPPORTED;
+	}
+
+	codec->codec_data = vorbis_data;
+	codec->read_page = read_vorbis_page;
+	codec->free_data = free_vorbis_data;
+
+	return SHOUTERR_SUCCESS;
+}
+
+static int read_vorbis_page(ogg_codec_t *codec, ogg_page *page)
+{
+	ogg_packet packet;
+	vorbis_data_t *vorbis_data = codec->codec_data;
+	uint64_t samples = 0;
+
+	if (codec->headers < 3) {
+		while (ogg_stream_packetout (&codec->os, &packet) > 0) {
+			if (vorbis_synthesis_headerin(&vorbis_data->vi, &vorbis_data->vc, &packet) < 0)
+				return SHOUTERR_INSANE;
+			codec->headers++;
+		}
+
+		return SHOUTERR_SUCCESS;
+	}
+
+	while (ogg_stream_packetout (&codec->os, &packet) > 0)
+		samples += vorbis_blocksize(vorbis_data, &packet);
+
+	codec->senttime += ((samples * 1000000) / vorbis_data->vi.rate);
+
+	return SHOUTERR_SUCCESS;
+}
+
+static void free_vorbis_data(void *codec_data)
+{
+	vorbis_data_t *vorbis_data = (vorbis_data_t *)codec_data;
+
+	vorbis_info_clear(&vorbis_data->vi);
+	vorbis_comment_clear(&vorbis_data->vc);
+	free(vorbis_data);
+}
+
+static int vorbis_blocksize(vorbis_data_t *vd, ogg_packet *p)
+{
+	int this = vorbis_packet_blocksize(&vd->vi, p);
+	int ret = (this + vd->prevW)/4;
+
+	if(!vd->prevW) {
+		vd->prevW = this;
+		return 0;
+	}
+
+	vd->prevW = this;
+	return ret;
+}



More information about the commits mailing list