2005-02-15 18:29:42 +00:00
|
|
|
/*
|
|
|
|
* libmad - MPEG audio decoder library
|
|
|
|
* Copyright (C) 2000-2004 Underbit Technologies, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
# ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# include "global.h"
|
|
|
|
|
|
|
|
# include "bit.h"
|
|
|
|
# include "stream.h"
|
|
|
|
|
|
|
|
/*
|
2010-02-22 21:02:57 +00:00
|
|
|
* NAME: stream->init()
|
2010-02-22 19:44:05 +00:00
|
|
|
* DESCRIPTION: initialize stream struct
|
2005-02-15 18:29:42 +00:00
|
|
|
*/
|
|
|
|
void mad_stream_init(struct mad_stream *stream)
|
|
|
|
{
|
|
|
|
stream->buffer = 0;
|
|
|
|
stream->bufend = 0;
|
2011-06-24 14:48:25 +00:00
|
|
|
/* rockbox: not used
|
|
|
|
stream->skiplen = 0; */
|
2005-02-15 18:29:42 +00:00
|
|
|
|
|
|
|
stream->sync = 0;
|
|
|
|
stream->freerate = 0;
|
|
|
|
|
|
|
|
stream->this_frame = 0;
|
|
|
|
stream->next_frame = 0;
|
|
|
|
mad_bit_init(&stream->ptr, 0);
|
|
|
|
|
|
|
|
mad_bit_init(&stream->anc_ptr, 0);
|
|
|
|
stream->anc_bitlen = 0;
|
|
|
|
|
2010-06-27 18:11:07 +00:00
|
|
|
/* rockbox: comment this to avoid allocation in following code. main_data is
|
2011-06-26 01:32:25 +00:00
|
|
|
* linked to an array in ../mpa.c before calling this.
|
2005-02-15 18:29:42 +00:00
|
|
|
stream->main_data = 0;
|
2010-06-27 18:11:07 +00:00
|
|
|
*/
|
2005-02-15 18:29:42 +00:00
|
|
|
stream->md_len = 0;
|
|
|
|
|
|
|
|
stream->options = 0;
|
|
|
|
stream->error = MAD_ERROR_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-02-22 21:02:57 +00:00
|
|
|
* NAME: stream->finish()
|
2010-02-22 19:44:05 +00:00
|
|
|
* DESCRIPTION: deallocate any dynamic memory associated with stream
|
2005-02-15 18:29:42 +00:00
|
|
|
*/
|
2011-06-24 14:48:25 +00:00
|
|
|
/* rockbox: not used
|
2005-02-15 18:29:42 +00:00
|
|
|
void mad_stream_finish(struct mad_stream *stream)
|
|
|
|
{
|
|
|
|
if (stream->main_data) {
|
|
|
|
free(stream->main_data);
|
|
|
|
stream->main_data = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mad_bit_finish(&stream->anc_ptr);
|
|
|
|
mad_bit_finish(&stream->ptr);
|
2011-06-24 14:48:25 +00:00
|
|
|
} */
|
2005-02-15 18:29:42 +00:00
|
|
|
|
|
|
|
/*
|
2010-02-22 21:02:57 +00:00
|
|
|
* NAME: stream->buffer()
|
2010-02-22 19:44:05 +00:00
|
|
|
* DESCRIPTION: set stream buffer pointers
|
2005-02-15 18:29:42 +00:00
|
|
|
*/
|
|
|
|
void mad_stream_buffer(struct mad_stream *stream,
|
2010-02-22 21:02:57 +00:00
|
|
|
unsigned char const *buffer, unsigned long length)
|
2005-02-15 18:29:42 +00:00
|
|
|
{
|
|
|
|
stream->buffer = buffer;
|
|
|
|
stream->bufend = buffer + length;
|
|
|
|
|
|
|
|
stream->this_frame = buffer;
|
|
|
|
stream->next_frame = buffer;
|
|
|
|
|
|
|
|
stream->sync = 1;
|
|
|
|
|
|
|
|
mad_bit_init(&stream->ptr, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-02-22 21:02:57 +00:00
|
|
|
* NAME: stream->skip()
|
2010-02-22 19:44:05 +00:00
|
|
|
* DESCRIPTION: arrange to skip bytes before the next frame
|
2005-02-15 18:29:42 +00:00
|
|
|
*/
|
2011-06-24 14:48:25 +00:00
|
|
|
/* rockbox: not used
|
2005-02-15 18:29:42 +00:00
|
|
|
void mad_stream_skip(struct mad_stream *stream, unsigned long length)
|
|
|
|
{
|
|
|
|
stream->skiplen += length;
|
2011-06-24 14:48:25 +00:00
|
|
|
} */
|
2005-02-15 18:29:42 +00:00
|
|
|
|
|
|
|
/*
|
2010-02-22 21:02:57 +00:00
|
|
|
* NAME: stream->sync()
|
2010-02-22 19:44:05 +00:00
|
|
|
* DESCRIPTION: locate the next stream sync word
|
2005-02-15 18:29:42 +00:00
|
|
|
*/
|
|
|
|
int mad_stream_sync(struct mad_stream *stream)
|
|
|
|
{
|
|
|
|
register unsigned char const *ptr, *end;
|
|
|
|
|
|
|
|
ptr = mad_bit_nextbyte(&stream->ptr);
|
|
|
|
end = stream->bufend;
|
|
|
|
|
|
|
|
while (ptr < end - 1 &&
|
2010-02-22 21:02:57 +00:00
|
|
|
!(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0))
|
2005-02-15 18:29:42 +00:00
|
|
|
++ptr;
|
|
|
|
|
|
|
|
if (end - ptr < MAD_BUFFER_GUARD)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
mad_bit_init(&stream->ptr, ptr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-02-22 21:02:57 +00:00
|
|
|
* NAME: stream->errorstr()
|
2010-02-22 19:44:05 +00:00
|
|
|
* DESCRIPTION: return a string description of the current error condition
|
2005-02-15 18:29:42 +00:00
|
|
|
*/
|
|
|
|
char const *mad_stream_errorstr(struct mad_stream const *stream)
|
|
|
|
{
|
|
|
|
switch (stream->error) {
|
2010-02-22 21:02:57 +00:00
|
|
|
case MAD_ERROR_NONE: return "no error";
|
2005-02-15 18:29:42 +00:00
|
|
|
|
2010-02-22 21:02:57 +00:00
|
|
|
case MAD_ERROR_BUFLEN: return "input buffer too small (or EOF)";
|
|
|
|
case MAD_ERROR_BUFPTR: return "invalid (null) buffer pointer";
|
2005-02-15 18:29:42 +00:00
|
|
|
|
2010-02-22 21:02:57 +00:00
|
|
|
case MAD_ERROR_NOMEM: return "not enough memory";
|
2005-02-15 18:29:42 +00:00
|
|
|
|
2010-02-22 21:02:57 +00:00
|
|
|
case MAD_ERROR_LOSTSYNC: return "lost synchronization";
|
|
|
|
case MAD_ERROR_BADLAYER: return "reserved header layer value";
|
2010-02-22 19:44:05 +00:00
|
|
|
case MAD_ERROR_BADBITRATE: return "forbidden bitrate value";
|
|
|
|
case MAD_ERROR_BADSAMPLERATE: return "reserved sample frequency value";
|
|
|
|
case MAD_ERROR_BADEMPHASIS: return "reserved emphasis value";
|
2005-02-15 18:29:42 +00:00
|
|
|
|
2010-02-22 21:02:57 +00:00
|
|
|
case MAD_ERROR_BADCRC: return "CRC check failed";
|
2010-02-22 19:44:05 +00:00
|
|
|
case MAD_ERROR_BADBITALLOC: return "forbidden bit allocation value";
|
2005-02-15 18:29:42 +00:00
|
|
|
case MAD_ERROR_BADSCALEFACTOR: return "bad scalefactor index";
|
2010-02-22 21:02:57 +00:00
|
|
|
case MAD_ERROR_BADMODE: return "bad bitrate/mode combination";
|
2010-02-22 19:44:05 +00:00
|
|
|
case MAD_ERROR_BADFRAMELEN: return "bad frame length";
|
|
|
|
case MAD_ERROR_BADBIGVALUES: return "bad big_values count";
|
|
|
|
case MAD_ERROR_BADBLOCKTYPE: return "reserved block_type";
|
2010-02-22 21:02:57 +00:00
|
|
|
case MAD_ERROR_BADSCFSI: return "bad scalefactor selection info";
|
2010-02-22 19:44:05 +00:00
|
|
|
case MAD_ERROR_BADDATAPTR: return "bad main_data_begin pointer";
|
|
|
|
case MAD_ERROR_BADPART3LEN: return "bad audio data length";
|
|
|
|
case MAD_ERROR_BADHUFFTABLE: return "bad Huffman table select";
|
|
|
|
case MAD_ERROR_BADHUFFDATA: return "Huffman data overrun";
|
2010-02-22 21:02:57 +00:00
|
|
|
case MAD_ERROR_BADSTEREO: return "incompatible block_type for JS";
|
2005-02-15 18:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|