Debian Codegraph @

external/mp3/mad_stream.c

raw symbols SCIP
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: stream.c,v 1.12 2004/02/05 09:02:39 rob Exp $
20 */
21
22 /*# ifdef HAVE_CONFIG_H*/
23 # include "mad_config.h"cxx . . $ `<file>/external/mp3/mad_config.h`/
24 /*# endif*/
25
26 # include "mad_global.h"cxx . . $ `<file>/external/mp3/mad_global.h`/
27
28 # include <stdlib.h>
29
30 # include "mad_bit.h"cxx . . $ `<file>/external/mp3/mad_bit.h`/
31 # include "mad_stream.h"cxx . . $ `<file>/external/mp3/mad_stream.h`/
32
33 /*
34 * NAME: stream->init()
35 * DESCRIPTION: initialize stream struct
36 */
37 void mad_stream_initcxx . . $ mad_stream_init(16649f0d052e40ae).(struct mad_streamcxx . . $ mad_stream# *stream)
38 {
39 stream->buffercxx . . $ mad_stream#buffer. = 0;
40 stream->bufendcxx . . $ mad_stream#bufend. = 0;
41 stream->skiplencxx . . $ mad_stream#skiplen. = 0;
42
43 stream->synccxx . . $ mad_stream#sync. = 0;
44 stream->freeratecxx . . $ mad_stream#freerate. = 0;
45
46 stream->this_framecxx . . $ mad_stream#this_frame. = 0;
47 stream->next_framecxx . . $ mad_stream#next_frame. = 0;
48 mad_bit_initcxx . . $ mad_bit_init(e5fd0ed86f676da4).(&stream->ptrcxx . . $ mad_stream#ptr., 0);
49
50 mad_bit_initcxx . . $ mad_bit_init(e5fd0ed86f676da4).(&stream->anc_ptrcxx . . $ mad_stream#anc_ptr., 0);
51 stream->anc_bitlencxx . . $ mad_stream#anc_bitlen. = 0;
52
53 stream->main_datacxx . . $ mad_stream#main_data. = 0;
54 stream->md_lencxx . . $ mad_stream#md_len. = 0;
55
56 stream->optionscxx . . $ mad_stream#options. = 0;
57 stream->errorcxx . . $ mad_stream#error. = MAD_ERROR_NONEcxx . . $ MAD_ERROR_NONE.;
58
59 stream->this_offsetcxx . . $ mad_stream#this_offset. = 0; /* Erez Volk */
60 }
61
62 /*
63 * NAME: stream->finish()
64 * DESCRIPTION: deallocate any dynamic memory associated with stream
65 */
66 void mad_stream_finishcxx . . $ mad_stream_finish(16649f0d052e40ae).(struct mad_streamcxx . . $ mad_stream# *stream)
67 {
68 if (stream->main_datacxx . . $ mad_stream#main_data.) {
69 freecxx . . $ free(5d22bdacc48458e8).(stream->main_datacxx . . $ mad_stream#main_data.);
70 stream->main_datacxx . . $ mad_stream#main_data. = 0;
71 }
72
73 mad_bit_finishcxx . . $ `external/mp3/mad_bit.h:33:10`!(&stream->anc_ptr);
74 mad_bit_finishcxx . . $ `external/mp3/mad_bit.h:33:10`!(&stream->ptr);
75 }
76
77 /*
78 * NAME: stream->buffer()
79 * DESCRIPTION: set stream buffer pointers
80 */
81 void mad_stream_buffercxx . . $ mad_stream_buffer(77a564b974a2c81b).(struct mad_streamcxx . . $ mad_stream# *stream,
82 unsigned char const *buffer, unsigned long length)
83 {
84 stream->buffercxx . . $ mad_stream#buffer. = buffer;
85 stream->bufendcxx . . $ mad_stream#bufend. = buffer + length;
86
87 stream->this_framecxx . . $ mad_stream#this_frame. = buffer;
88 stream->next_framecxx . . $ mad_stream#next_frame. = buffer;
89
90 stream->synccxx . . $ mad_stream#sync. = 1;
91
92 mad_bit_initcxx . . $ mad_bit_init(e5fd0ed86f676da4).(&stream->ptrcxx . . $ mad_stream#ptr., buffer);
93 }
94
95 /*
96 * NAME: stream->buffer_offset()
97 * DESCRIPTION: set stream buffer pointers and offset
98 * Erez Volk
99 */
100 void mad_stream_buffer_offsetcxx . . $ mad_stream_buffer_offset(2a4dee137988d553).(struct mad_streamcxx . . $ mad_stream# *stream,
101 unsigned char const *buffer, unsigned long length,
102 unsigned long offset)
103 {
104 mad_stream_buffercxx . . $ mad_stream_buffer(77a564b974a2c81b).(stream, buffer, length);
105 stream->this_offsetcxx . . $ mad_stream#this_offset. = offset;
106 }
107
108 /*
109 * NAME: stream->skip()
110 * DESCRIPTION: arrange to skip bytes before the next frame
111 */
112 void mad_stream_skipcxx . . $ mad_stream_skip(a830e26bdf9f87a6).(struct mad_streamcxx . . $ mad_stream# *stream, unsigned long length)
113 {
114 stream->skiplencxx . . $ mad_stream#skiplen. += length;
115 }
116
117 /*
118 * NAME: stream->sync()
119 * DESCRIPTION: locate the next stream sync word
120 */
121 int mad_stream_synccxx . . $ mad_stream_sync(b074ad635480770e).(struct mad_streamcxx . . $ mad_stream# *stream)
122 {
123 register unsigned char const *ptr, *end;
124
125 ptr = mad_bit_nextbytecxx . . $ mad_bit_nextbyte(8b44ec6325e5bd63).(&stream->ptrcxx . . $ mad_stream#ptr.);
126 end = stream->bufendcxx . . $ mad_stream#bufend.;
127
128 while (ptr < end - 1 &&
129 !(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) {
130 ++ptr;
131 }
132
133 if (end - ptr < MAD_BUFFER_GUARDcxx . . $ `external/mp3/mad_stream.h:27:10`!)
134 return -1;
135
136 mad_bit_initcxx . . $ mad_bit_init(e5fd0ed86f676da4).(&stream->ptrcxx . . $ mad_stream#ptr., ptr);
137
138 return 0;
139 }
140
141 /*
142 * NAME: stream->errorstr()
143 * DESCRIPTION: return a string description of the current error condition
144 */
145 char const *mad_stream_errorstrcxx . . $ mad_stream_errorstr(2140f2fa09604b4).(struct mad_streamcxx . . $ mad_stream# const *stream)
146 {
147 switch (stream->errorcxx . . $ mad_stream#error.) {
148 case MAD_ERROR_NONEcxx . . $ MAD_ERROR_NONE.: return "no error";
149
150 case MAD_ERROR_BUFLENcxx . . $ MAD_ERROR_BUFLEN.: return "input buffer too small (or EOF)";
151 case MAD_ERROR_BUFPTRcxx . . $ MAD_ERROR_BUFPTR.: return "invalid (null) buffer pointer";
152
153 case MAD_ERROR_NOMEMcxx . . $ MAD_ERROR_NOMEM.: return "not enough memory";
154
155 case MAD_ERROR_LOSTSYNCcxx . . $ MAD_ERROR_LOSTSYNC.: return "lost synchronization";
156 case MAD_ERROR_BADLAYERcxx . . $ MAD_ERROR_BADLAYER.: return "reserved header layer value";
157 case MAD_ERROR_BADBITRATEcxx . . $ MAD_ERROR_BADBITRATE.: return "forbidden bitrate value";
158 case MAD_ERROR_BADSAMPLERATEcxx . . $ MAD_ERROR_BADSAMPLERATE.: return "reserved sample frequency value";
159 case MAD_ERROR_BADEMPHASIScxx . . $ MAD_ERROR_BADEMPHASIS.: return "reserved emphasis value";
160
161 case MAD_ERROR_BADCRCcxx . . $ MAD_ERROR_BADCRC.: return "CRC check failed";
162 case MAD_ERROR_BADBITALLOCcxx . . $ MAD_ERROR_BADBITALLOC.: return "forbidden bit allocation value";
163 case MAD_ERROR_BADSCALEFACTORcxx . . $ MAD_ERROR_BADSCALEFACTOR.: return "bad scalefactor index";
164 case MAD_ERROR_BADMODEcxx . . $ MAD_ERROR_BADMODE.: return "bad bitrate/mode combination";
165 case MAD_ERROR_BADFRAMELENcxx . . $ MAD_ERROR_BADFRAMELEN.: return "bad frame length";
166 case MAD_ERROR_BADBIGVALUEScxx . . $ MAD_ERROR_BADBIGVALUES.: return "bad big_values count";
167 case MAD_ERROR_BADBLOCKTYPEcxx . . $ MAD_ERROR_BADBLOCKTYPE.: return "reserved block_type";
168 case MAD_ERROR_BADSCFSIcxx . . $ MAD_ERROR_BADSCFSI.: return "bad scalefactor selection info";
169 case MAD_ERROR_BADDATAPTRcxx . . $ MAD_ERROR_BADDATAPTR.: return "bad main_data_begin pointer";
170 case MAD_ERROR_BADPART3LENcxx . . $ MAD_ERROR_BADPART3LEN.: return "bad audio data length";
171 case MAD_ERROR_BADHUFFTABLEcxx . . $ MAD_ERROR_BADHUFFTABLE.: return "bad Huffman table select";
172 case MAD_ERROR_BADHUFFDATAcxx . . $ MAD_ERROR_BADHUFFDATA.: return "Huffman data overrun";
173 case MAD_ERROR_BADSTEREOcxx . . $ MAD_ERROR_BADSTEREO.: return "incompatible block_type for JS";
174 }
175
176 return 0;
177 }