Commit eab60398 authored by brendan's avatar brendan
Browse files

Move theora codec support into separate file (cleaner, if by cleaner you mean

"fewer #ifdefs", not "less autoconf")

svn path=/icecast/trunk/libshout/; revision=7183
parent 0c317929
......@@ -114,9 +114,10 @@ XIPH_PATH_VORBIS
VORBIS_LIBS="$VORBIS_LDFLAGS $VORBIS_LIBS"
XIPH_CFLAGS="$XIPH_CFLAGS $VORBIS_CFLAGS"
XIPH_PATH_THEORA(,[AC_MSG_WARN([Theora library not found, disabling])])
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])
AM_CONDITIONAL(HAVE_THEORA, test -n "$THEORA_LIBS")
dnl pkgconfig/shout-config.
dnl If pkgconfig is found, use it and disable shout-config, otherwise do the
......
......@@ -6,13 +6,19 @@ if HAVE_THREAD
MAYBE_THREAD = thread
MAYBE_THREAD_LIB = thread/libicethread.la
endif
if HAVE_THEORA
MAYBE_THEORA = theora.c
endif
SUBDIRS = avl net timing httpp $(MAYBE_THREAD)
lib_LTLIBRARIES = libshout.la
libshout_la_LDFLAGS = -version-info 3:0:0
EXTRA_DIST = theora.c
noinst_HEADERS = shout_ogg.h shout_private.h util.h
libshout_la_SOURCES = shout.c util.c ogg.c vorbis.c mp3.c
libshout_la_SOURCES = shout.c util.c ogg.c vorbis.c mp3.c $(MAYBE_THEORA)
AM_CFLAGS = @XIPH_CFLAGS@
libshout_la_LIBADD = net/libicenet.la timing/libicetiming.la avl/libiceavl.la\
......
......@@ -27,9 +27,6 @@
#include <string.h>
#include <ogg/ogg.h>
#ifdef HAVE_THEORA
#include <theora/theora.h>
#endif
#include <shout/shout.h>
#include "shout_private.h"
......@@ -42,15 +39,6 @@ typedef struct {
char bos;
} ogg_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);
......@@ -59,13 +47,6 @@ static void free_codec(ogg_codec_t *codec);
static void free_codecs(ogg_data_t *ogg_data);
static int send_page(shout_t *self, ogg_page *page);
#ifdef HAVE_THEORA
/* theora handler */
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);
static codec_open_t codecs[] = {
open_vorbis,
......@@ -214,97 +195,3 @@ static int send_page(shout_t *self, ogg_page *page)
return SHOUTERR_SUCCESS;
}
#ifdef HAVE_THEORA
/* theora handler */
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;
double per_frame, duration, new_time;
ogg_int64_t granulepos, iframe, pframe;
uint64_t frames;
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;
}
per_frame = (double)theora_data->ti.fps_denominator / theora_data->ti.fps_numerator * 1000000;
granulepos = ogg_page_granulepos(page);
if (granulepos > 0) {
iframe = granulepos >> theora_data->granule_shift;
pframe = granulepos - (iframe << theora_data->granule_shift);
frames = iframe + pframe;
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
/* -*- c-basic-offset: 8; -*- */
/* theora.c: Ogg Theora data handlers for libshout
* $Id$
*
* Copyright (C) 2004 the Icecast team <team@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 <theora/theora.h>
#include "shout_private.h"
#include "shout_ogg.h"
/* -- local data structures -- */
typedef struct {
theora_info ti;
theora_comment tc;
uint32_t granule_shift;
double prev_time;
} theora_data_t;
/* -- local prototypes -- */
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);
/* -- theora functions -- */
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;
double per_frame, duration, new_time;
ogg_int64_t granulepos, iframe, pframe;
uint64_t frames;
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;
}
per_frame = (double)theora_data->ti.fps_denominator / theora_data->ti.fps_numerator * 1000000;
granulepos = ogg_page_granulepos(page);
if (granulepos > 0) {
iframe = granulepos >> theora_data->granule_shift;
pframe = granulepos - (iframe << theora_data->granule_shift);
frames = iframe + pframe;
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;
}
/* -*- 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 $
* $Id$
*
* Copyright (C) 2002-2004 the Icecast team <team@icecast.org>
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment