|
Packit Service |
102f81 |
/* -*- c-basic-offset: 8; -*- */
|
|
Packit Service |
102f81 |
/* vorbis.c: Ogg Vorbis data handlers for libshout
|
|
Packit Service |
102f81 |
* $Id: vorbis.c 10686 2006-01-03 18:47:54Z brendan $
|
|
Packit Service |
102f81 |
*
|
|
Packit Service |
102f81 |
* Copyright (C) 2002-2004 the Icecast team <team@icecast.org>
|
|
Packit Service |
102f81 |
*
|
|
Packit Service |
102f81 |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
102f81 |
* modify it under the terms of the GNU Library General Public
|
|
Packit Service |
102f81 |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
102f81 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit Service |
102f81 |
*
|
|
Packit Service |
102f81 |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
102f81 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
102f81 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
102f81 |
* Library General Public License for more details.
|
|
Packit Service |
102f81 |
*
|
|
Packit Service |
102f81 |
* You should have received a copy of the GNU Library General Public
|
|
Packit Service |
102f81 |
* License along with this library; if not, write to the Free
|
|
Packit Service |
102f81 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
Packit Service |
102f81 |
*/
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
#ifdef HAVE_CONFIG_H
|
|
Packit Service |
102f81 |
# include <config.h>
|
|
Packit Service |
102f81 |
#endif
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
#ifdef HAVE_INTTYPES_H
|
|
Packit Service |
102f81 |
#include <inttypes.h>
|
|
Packit Service |
102f81 |
#endif
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
#include <vorbis/codec.h>
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
#include "shout_private.h"
|
|
Packit Service |
102f81 |
#include "shout_ogg.h"
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
/* -- local data structures -- */
|
|
Packit Service |
102f81 |
typedef struct {
|
|
Packit Service |
102f81 |
vorbis_info vi;
|
|
Packit Service |
102f81 |
vorbis_comment vc;
|
|
Packit Service |
102f81 |
int prevW;
|
|
Packit Service |
102f81 |
} vorbis_data_t;
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
/* -- local prototypes -- */
|
|
Packit Service |
102f81 |
static int read_vorbis_page(ogg_codec_t *codec, ogg_page *page);
|
|
Packit Service |
102f81 |
static void free_vorbis_data(void *codec_data);
|
|
Packit Service |
102f81 |
static int vorbis_blocksize(vorbis_data_t *vd, ogg_packet *p);
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
/* -- vorbis functions -- */
|
|
Packit Service |
102f81 |
int _shout_open_vorbis(ogg_codec_t *codec, ogg_page *page)
|
|
Packit Service |
102f81 |
{
|
|
Packit Service |
102f81 |
vorbis_data_t *vorbis_data = calloc(1, sizeof(vorbis_data_t));
|
|
Packit Service |
102f81 |
ogg_packet packet;
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
if (!vorbis_data)
|
|
Packit Service |
102f81 |
return SHOUTERR_MALLOC;
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
vorbis_info_init(&vorbis_data->vi);
|
|
Packit Service |
102f81 |
vorbis_comment_init(&vorbis_data->vc);
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
ogg_stream_packetout(&codec->os, &packet);
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
if (vorbis_synthesis_headerin(&vorbis_data->vi, &vorbis_data->vc, &packet) < 0) {
|
|
Packit Service |
102f81 |
free_vorbis_data(vorbis_data);
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
return SHOUTERR_UNSUPPORTED;
|
|
Packit Service |
102f81 |
}
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
codec->codec_data = vorbis_data;
|
|
Packit Service |
102f81 |
codec->read_page = read_vorbis_page;
|
|
Packit Service |
102f81 |
codec->free_data = free_vorbis_data;
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
return SHOUTERR_SUCCESS;
|
|
Packit Service |
102f81 |
}
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
static int read_vorbis_page(ogg_codec_t *codec, ogg_page *page)
|
|
Packit Service |
102f81 |
{
|
|
Packit Service |
102f81 |
ogg_packet packet;
|
|
Packit Service |
102f81 |
vorbis_data_t *vorbis_data = codec->codec_data;
|
|
Packit Service |
102f81 |
uint64_t samples = 0;
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
if (codec->headers < 3) {
|
|
Packit Service |
102f81 |
while (ogg_stream_packetout (&codec->os, &packet) > 0) {
|
|
Packit Service |
102f81 |
if (vorbis_synthesis_headerin(&vorbis_data->vi, &vorbis_data->vc, &packet) < 0)
|
|
Packit Service |
102f81 |
return SHOUTERR_INSANE;
|
|
Packit Service |
102f81 |
codec->headers++;
|
|
Packit Service |
102f81 |
}
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
return SHOUTERR_SUCCESS;
|
|
Packit Service |
102f81 |
}
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
while (ogg_stream_packetout (&codec->os, &packet) > 0)
|
|
Packit Service |
102f81 |
samples += vorbis_blocksize(vorbis_data, &packet);
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
codec->senttime += ((samples * 1000000) / vorbis_data->vi.rate);
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
return SHOUTERR_SUCCESS;
|
|
Packit Service |
102f81 |
}
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
static void free_vorbis_data(void *codec_data)
|
|
Packit Service |
102f81 |
{
|
|
Packit Service |
102f81 |
vorbis_data_t *vorbis_data = (vorbis_data_t *)codec_data;
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
vorbis_info_clear(&vorbis_data->vi);
|
|
Packit Service |
102f81 |
vorbis_comment_clear(&vorbis_data->vc);
|
|
Packit Service |
102f81 |
free(vorbis_data);
|
|
Packit Service |
102f81 |
}
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
static int vorbis_blocksize(vorbis_data_t *vd, ogg_packet *p)
|
|
Packit Service |
102f81 |
{
|
|
Packit Service |
102f81 |
int this = vorbis_packet_blocksize(&vd->vi, p);
|
|
Packit Service |
102f81 |
int ret = (this + vd->prevW)/4;
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
if(!vd->prevW) {
|
|
Packit Service |
102f81 |
vd->prevW = this;
|
|
Packit Service |
102f81 |
return 0;
|
|
Packit Service |
102f81 |
}
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
vd->prevW = this;
|
|
Packit Service |
102f81 |
return ret;
|
|
Packit Service |
102f81 |
}
|