Fix up configure and buildzip/wpsbuild.pl a bit
[kugel-rb.git] / apps / codecs / libmad / stream.c
blobb0c5ad36fdba3178a55d4fa9b947afbc2c261918
1 /*
2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * $Id$
22 # ifdef HAVE_CONFIG_H
23 # include "config.h"
24 # endif
26 # include "global.h"
28 # include "bit.h"
29 # include "stream.h"
32 * NAME: stream->init()
33 * DESCRIPTION: initialize stream struct
35 void mad_stream_init(struct mad_stream *stream)
37 stream->buffer = 0;
38 stream->bufend = 0;
39 stream->skiplen = 0;
41 stream->sync = 0;
42 stream->freerate = 0;
44 stream->this_frame = 0;
45 stream->next_frame = 0;
46 mad_bit_init(&stream->ptr, 0);
48 mad_bit_init(&stream->anc_ptr, 0);
49 stream->anc_bitlen = 0;
51 /* rockbox: comment this to avoid allocation in following code. main_data is
52 * linked to an array in rockbox' apps/codecs/mpa.c before calling this.
53 stream->main_data = 0;
55 stream->md_len = 0;
57 stream->options = 0;
58 stream->error = MAD_ERROR_NONE;
62 * NAME: stream->finish()
63 * DESCRIPTION: deallocate any dynamic memory associated with stream
65 void mad_stream_finish(struct mad_stream *stream)
67 if (stream->main_data) {
68 free(stream->main_data);
69 stream->main_data = 0;
72 mad_bit_finish(&stream->anc_ptr);
73 mad_bit_finish(&stream->ptr);
77 * NAME: stream->buffer()
78 * DESCRIPTION: set stream buffer pointers
80 void mad_stream_buffer(struct mad_stream *stream,
81 unsigned char const *buffer, unsigned long length)
83 stream->buffer = buffer;
84 stream->bufend = buffer + length;
86 stream->this_frame = buffer;
87 stream->next_frame = buffer;
89 stream->sync = 1;
91 mad_bit_init(&stream->ptr, buffer);
95 * NAME: stream->skip()
96 * DESCRIPTION: arrange to skip bytes before the next frame
98 void mad_stream_skip(struct mad_stream *stream, unsigned long length)
100 stream->skiplen += length;
104 * NAME: stream->sync()
105 * DESCRIPTION: locate the next stream sync word
107 int mad_stream_sync(struct mad_stream *stream)
109 register unsigned char const *ptr, *end;
111 ptr = mad_bit_nextbyte(&stream->ptr);
112 end = stream->bufend;
114 while (ptr < end - 1 &&
115 !(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0))
116 ++ptr;
118 if (end - ptr < MAD_BUFFER_GUARD)
119 return -1;
121 mad_bit_init(&stream->ptr, ptr);
123 return 0;
127 * NAME: stream->errorstr()
128 * DESCRIPTION: return a string description of the current error condition
130 char const *mad_stream_errorstr(struct mad_stream const *stream)
132 switch (stream->error) {
133 case MAD_ERROR_NONE: return "no error";
135 case MAD_ERROR_BUFLEN: return "input buffer too small (or EOF)";
136 case MAD_ERROR_BUFPTR: return "invalid (null) buffer pointer";
138 case MAD_ERROR_NOMEM: return "not enough memory";
140 case MAD_ERROR_LOSTSYNC: return "lost synchronization";
141 case MAD_ERROR_BADLAYER: return "reserved header layer value";
142 case MAD_ERROR_BADBITRATE: return "forbidden bitrate value";
143 case MAD_ERROR_BADSAMPLERATE: return "reserved sample frequency value";
144 case MAD_ERROR_BADEMPHASIS: return "reserved emphasis value";
146 case MAD_ERROR_BADCRC: return "CRC check failed";
147 case MAD_ERROR_BADBITALLOC: return "forbidden bit allocation value";
148 case MAD_ERROR_BADSCALEFACTOR: return "bad scalefactor index";
149 case MAD_ERROR_BADMODE: return "bad bitrate/mode combination";
150 case MAD_ERROR_BADFRAMELEN: return "bad frame length";
151 case MAD_ERROR_BADBIGVALUES: return "bad big_values count";
152 case MAD_ERROR_BADBLOCKTYPE: return "reserved block_type";
153 case MAD_ERROR_BADSCFSI: return "bad scalefactor selection info";
154 case MAD_ERROR_BADDATAPTR: return "bad main_data_begin pointer";
155 case MAD_ERROR_BADPART3LEN: return "bad audio data length";
156 case MAD_ERROR_BADHUFFTABLE: return "bad Huffman table select";
157 case MAD_ERROR_BADHUFFDATA: return "Huffman data overrun";
158 case MAD_ERROR_BADSTEREO: return "incompatible block_type for JS";
161 return 0;