|
Packit Service |
102f81 |
/* -*- c-basic-offset: 8; -*- */
|
|
Packit Service |
102f81 |
/* speex.c: Ogg Speex data handlers for libshout
|
|
Packit Service |
102f81 |
*
|
|
Packit Service |
102f81 |
* Copyright (C) 2005 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 |
#include <speex/speex.h>
|
|
Packit Service |
102f81 |
#include <speex/speex_header.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 |
SpeexHeader *sh;
|
|
Packit Service |
102f81 |
} speex_data_t;
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
/* -- local prototypes -- */
|
|
Packit Service |
102f81 |
static int read_speex_page(ogg_codec_t *codec, ogg_page *page);
|
|
Packit Service |
102f81 |
static void free_speex_data(void *codec_data);
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
/* -- speex functions -- */
|
|
Packit Service |
102f81 |
int _shout_open_speex(ogg_codec_t *codec, ogg_page *page)
|
|
Packit Service |
102f81 |
{
|
|
Packit Service |
102f81 |
speex_data_t *speex_data = calloc(1, sizeof(speex_data_t));
|
|
Packit Service |
102f81 |
ogg_packet packet;
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
if (!speex_data)
|
|
Packit Service |
102f81 |
return SHOUTERR_MALLOC;
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
ogg_stream_packetout(&codec->os, &packet);
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
if (!(speex_data->sh = speex_packet_to_header(packet.packet,packet.bytes))) {
|
|
Packit Service |
102f81 |
free_speex_data(speex_data);
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
return SHOUTERR_UNSUPPORTED;
|
|
Packit Service |
102f81 |
}
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
codec->codec_data = speex_data;
|
|
Packit Service |
102f81 |
codec->read_page = read_speex_page;
|
|
Packit Service |
102f81 |
codec->free_data = free_speex_data;
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
return SHOUTERR_SUCCESS;
|
|
Packit Service |
102f81 |
}
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
static int read_speex_page(ogg_codec_t *codec, ogg_page *page)
|
|
Packit Service |
102f81 |
{
|
|
Packit Service |
102f81 |
ogg_packet packet;
|
|
Packit Service |
102f81 |
speex_data_t *speex_data = codec->codec_data;
|
|
Packit Service |
102f81 |
uint64_t samples = 0;
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
while (ogg_stream_packetout (&codec->os, &packet) > 0)
|
|
Packit Service |
102f81 |
samples += speex_data->sh->frames_per_packet * speex_data->sh->frame_size;
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
codec->senttime += ((samples * 1000000) / speex_data->sh->rate);
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
return SHOUTERR_SUCCESS;
|
|
Packit Service |
102f81 |
}
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
static void free_speex_data(void *codec_data)
|
|
Packit Service |
102f81 |
{
|
|
Packit Service |
102f81 |
speex_data_t *speex_data = (speex_data_t *)codec_data;
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
if (speex_data->sh)
|
|
Packit Service |
102f81 |
free(speex_data->sh);
|
|
Packit Service |
102f81 |
|
|
Packit Service |
102f81 |
free(speex_data);
|
|
Packit Service |
102f81 |
}
|