summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libmad/stream.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/libmad/stream.c')
-rw-r--r--lib/rbcodec/codecs/libmad/stream.c165
1 files changed, 165 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libmad/stream.c b/lib/rbcodec/codecs/libmad/stream.c
new file mode 100644
index 0000000000..6c8bbcf850
--- /dev/null
+++ b/lib/rbcodec/codecs/libmad/stream.c
@@ -0,0 +1,165 @@
1/*
2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
4 *
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.
9 *
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.
14 *
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
18 *
19 * $Id$
20 */
21
22# ifdef HAVE_CONFIG_H
23# include "config.h"
24# endif
25
26# include "global.h"
27
28# include "bit.h"
29# include "stream.h"
30
31/*
32 * NAME: stream->init()
33 * DESCRIPTION: initialize stream struct
34 */
35void mad_stream_init(struct mad_stream *stream)
36{
37 stream->buffer = 0;
38 stream->bufend = 0;
39 /* rockbox: not used
40 stream->skiplen = 0; */
41
42 stream->sync = 0;
43 stream->freerate = 0;
44
45 stream->this_frame = 0;
46 stream->next_frame = 0;
47 mad_bit_init(&stream->ptr, 0);
48
49 mad_bit_init(&stream->anc_ptr, 0);
50 stream->anc_bitlen = 0;
51
52/* rockbox: comment this to avoid allocation in following code. main_data is
53 * linked to an array in ../mpa.c before calling this.
54 stream->main_data = 0;
55*/
56 stream->md_len = 0;
57
58 stream->options = 0;
59 stream->error = MAD_ERROR_NONE;
60}
61
62/*
63 * NAME: stream->finish()
64 * DESCRIPTION: deallocate any dynamic memory associated with stream
65 */
66/* rockbox: not used
67void mad_stream_finish(struct mad_stream *stream)
68{
69 if (stream->main_data) {
70 free(stream->main_data);
71 stream->main_data = 0;
72 }
73
74 mad_bit_finish(&stream->anc_ptr);
75 mad_bit_finish(&stream->ptr);
76} */
77
78/*
79 * NAME: stream->buffer()
80 * DESCRIPTION: set stream buffer pointers
81 */
82void mad_stream_buffer(struct mad_stream *stream,
83 unsigned char const *buffer, unsigned long length)
84{
85 stream->buffer = buffer;
86 stream->bufend = buffer + length;
87
88 stream->this_frame = buffer;
89 stream->next_frame = buffer;
90
91 stream->sync = 1;
92
93 mad_bit_init(&stream->ptr, buffer);
94}
95
96/*
97 * NAME: stream->skip()
98 * DESCRIPTION: arrange to skip bytes before the next frame
99 */
100/* rockbox: not used
101void mad_stream_skip(struct mad_stream *stream, unsigned long length)
102{
103 stream->skiplen += length;
104} */
105
106/*
107 * NAME: stream->sync()
108 * DESCRIPTION: locate the next stream sync word
109 */
110int mad_stream_sync(struct mad_stream *stream)
111{
112 register unsigned char const *ptr, *end;
113
114 ptr = mad_bit_nextbyte(&stream->ptr);
115 end = stream->bufend;
116
117 while (ptr < end - 1 &&
118 !(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0))
119 ++ptr;
120
121 if (end - ptr < MAD_BUFFER_GUARD)
122 return -1;
123
124 mad_bit_init(&stream->ptr, ptr);
125
126 return 0;
127}
128
129/*
130 * NAME: stream->errorstr()
131 * DESCRIPTION: return a string description of the current error condition
132 */
133char const *mad_stream_errorstr(struct mad_stream const *stream)
134{
135 switch (stream->error) {
136 case MAD_ERROR_NONE: return "no error";
137
138 case MAD_ERROR_BUFLEN: return "input buffer too small (or EOF)";
139 case MAD_ERROR_BUFPTR: return "invalid (null) buffer pointer";
140
141 case MAD_ERROR_NOMEM: return "not enough memory";
142
143 case MAD_ERROR_LOSTSYNC: return "lost synchronization";
144 case MAD_ERROR_BADLAYER: return "reserved header layer value";
145 case MAD_ERROR_BADBITRATE: return "forbidden bitrate value";
146 case MAD_ERROR_BADSAMPLERATE: return "reserved sample frequency value";
147 case MAD_ERROR_BADEMPHASIS: return "reserved emphasis value";
148
149 case MAD_ERROR_BADCRC: return "CRC check failed";
150 case MAD_ERROR_BADBITALLOC: return "forbidden bit allocation value";
151 case MAD_ERROR_BADSCALEFACTOR: return "bad scalefactor index";
152 case MAD_ERROR_BADMODE: return "bad bitrate/mode combination";
153 case MAD_ERROR_BADFRAMELEN: return "bad frame length";
154 case MAD_ERROR_BADBIGVALUES: return "bad big_values count";
155 case MAD_ERROR_BADBLOCKTYPE: return "reserved block_type";
156 case MAD_ERROR_BADSCFSI: return "bad scalefactor selection info";
157 case MAD_ERROR_BADDATAPTR: return "bad main_data_begin pointer";
158 case MAD_ERROR_BADPART3LEN: return "bad audio data length";
159 case MAD_ERROR_BADHUFFTABLE: return "bad Huffman table select";
160 case MAD_ERROR_BADHUFFDATA: return "Huffman data overrun";
161 case MAD_ERROR_BADSTEREO: return "incompatible block_type for JS";
162 }
163
164 return 0;
165}