cannam@85
|
1 /*
|
cannam@85
|
2 * libmad - MPEG audio decoder library
|
cannam@85
|
3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
|
cannam@85
|
4 *
|
cannam@85
|
5 * This program is free software; you can redistribute it and/or modify
|
cannam@85
|
6 * it under the terms of the GNU General Public License as published by
|
cannam@85
|
7 * the Free Software Foundation; either version 2 of the License, or
|
cannam@85
|
8 * (at your option) any later version.
|
cannam@85
|
9 *
|
cannam@85
|
10 * This program is distributed in the hope that it will be useful,
|
cannam@85
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
cannam@85
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
cannam@85
|
13 * GNU General Public License for more details.
|
cannam@85
|
14 *
|
cannam@85
|
15 * You should have received a copy of the GNU General Public License
|
cannam@85
|
16 * along with this program; if not, write to the Free Software
|
cannam@85
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
cannam@85
|
18 *
|
cannam@85
|
19 * $Id: stream.h,v 1.20 2004/02/05 09:02:39 rob Exp $
|
cannam@85
|
20 */
|
cannam@85
|
21
|
cannam@85
|
22 # ifndef LIBMAD_STREAM_H
|
cannam@85
|
23 # define LIBMAD_STREAM_H
|
cannam@85
|
24
|
cannam@85
|
25 # include "bit.h"
|
cannam@85
|
26
|
cannam@85
|
27 # define MAD_BUFFER_GUARD 8
|
cannam@85
|
28 # define MAD_BUFFER_MDLEN (511 + 2048 + MAD_BUFFER_GUARD)
|
cannam@85
|
29
|
cannam@85
|
30 enum mad_error {
|
cannam@85
|
31 MAD_ERROR_NONE = 0x0000, /* no error */
|
cannam@85
|
32
|
cannam@85
|
33 MAD_ERROR_BUFLEN = 0x0001, /* input buffer too small (or EOF) */
|
cannam@85
|
34 MAD_ERROR_BUFPTR = 0x0002, /* invalid (null) buffer pointer */
|
cannam@85
|
35
|
cannam@85
|
36 MAD_ERROR_NOMEM = 0x0031, /* not enough memory */
|
cannam@85
|
37
|
cannam@85
|
38 MAD_ERROR_LOSTSYNC = 0x0101, /* lost synchronization */
|
cannam@85
|
39 MAD_ERROR_BADLAYER = 0x0102, /* reserved header layer value */
|
cannam@85
|
40 MAD_ERROR_BADBITRATE = 0x0103, /* forbidden bitrate value */
|
cannam@85
|
41 MAD_ERROR_BADSAMPLERATE = 0x0104, /* reserved sample frequency value */
|
cannam@85
|
42 MAD_ERROR_BADEMPHASIS = 0x0105, /* reserved emphasis value */
|
cannam@85
|
43
|
cannam@85
|
44 MAD_ERROR_BADCRC = 0x0201, /* CRC check failed */
|
cannam@85
|
45 MAD_ERROR_BADBITALLOC = 0x0211, /* forbidden bit allocation value */
|
cannam@85
|
46 MAD_ERROR_BADSCALEFACTOR = 0x0221, /* bad scalefactor index */
|
cannam@85
|
47 MAD_ERROR_BADMODE = 0x0222, /* bad bitrate/mode combination */
|
cannam@85
|
48 MAD_ERROR_BADFRAMELEN = 0x0231, /* bad frame length */
|
cannam@85
|
49 MAD_ERROR_BADBIGVALUES = 0x0232, /* bad big_values count */
|
cannam@85
|
50 MAD_ERROR_BADBLOCKTYPE = 0x0233, /* reserved block_type */
|
cannam@85
|
51 MAD_ERROR_BADSCFSI = 0x0234, /* bad scalefactor selection info */
|
cannam@85
|
52 MAD_ERROR_BADDATAPTR = 0x0235, /* bad main_data_begin pointer */
|
cannam@85
|
53 MAD_ERROR_BADPART3LEN = 0x0236, /* bad audio data length */
|
cannam@85
|
54 MAD_ERROR_BADHUFFTABLE = 0x0237, /* bad Huffman table select */
|
cannam@85
|
55 MAD_ERROR_BADHUFFDATA = 0x0238, /* Huffman data overrun */
|
cannam@85
|
56 MAD_ERROR_BADSTEREO = 0x0239 /* incompatible block_type for JS */
|
cannam@85
|
57 };
|
cannam@85
|
58
|
cannam@85
|
59 # define MAD_RECOVERABLE(error) ((error) & 0xff00)
|
cannam@85
|
60
|
cannam@85
|
61 struct mad_stream {
|
cannam@85
|
62 unsigned char const *buffer; /* input bitstream buffer */
|
cannam@85
|
63 unsigned char const *bufend; /* end of buffer */
|
cannam@85
|
64 unsigned long skiplen; /* bytes to skip before next frame */
|
cannam@85
|
65
|
cannam@85
|
66 int sync; /* stream sync found */
|
cannam@85
|
67 unsigned long freerate; /* free bitrate (fixed) */
|
cannam@85
|
68
|
cannam@85
|
69 unsigned char const *this_frame; /* start of current frame */
|
cannam@85
|
70 unsigned char const *next_frame; /* start of next frame */
|
cannam@85
|
71 struct mad_bitptr ptr; /* current processing bit pointer */
|
cannam@85
|
72
|
cannam@85
|
73 struct mad_bitptr anc_ptr; /* ancillary bits pointer */
|
cannam@85
|
74 unsigned int anc_bitlen; /* number of ancillary bits */
|
cannam@85
|
75
|
cannam@85
|
76 unsigned char (*main_data)[MAD_BUFFER_MDLEN];
|
cannam@85
|
77 /* Layer III main_data() */
|
cannam@85
|
78 unsigned int md_len; /* bytes in main_data */
|
cannam@85
|
79
|
cannam@85
|
80 int options; /* decoding options (see below) */
|
cannam@85
|
81 enum mad_error error; /* error code (see above) */
|
cannam@85
|
82 };
|
cannam@85
|
83
|
cannam@85
|
84 enum {
|
cannam@85
|
85 MAD_OPTION_IGNORECRC = 0x0001, /* ignore CRC errors */
|
cannam@85
|
86 MAD_OPTION_HALFSAMPLERATE = 0x0002 /* generate PCM at 1/2 sample rate */
|
cannam@85
|
87 # if 0 /* not yet implemented */
|
cannam@85
|
88 MAD_OPTION_LEFTCHANNEL = 0x0010, /* decode left channel only */
|
cannam@85
|
89 MAD_OPTION_RIGHTCHANNEL = 0x0020, /* decode right channel only */
|
cannam@85
|
90 MAD_OPTION_SINGLECHANNEL = 0x0030 /* combine channels */
|
cannam@85
|
91 # endif
|
cannam@85
|
92 };
|
cannam@85
|
93
|
cannam@85
|
94 void mad_stream_init(struct mad_stream *);
|
cannam@85
|
95 void mad_stream_finish(struct mad_stream *);
|
cannam@85
|
96
|
cannam@85
|
97 # define mad_stream_options(stream, opts) \
|
cannam@85
|
98 ((void) ((stream)->options = (opts)))
|
cannam@85
|
99
|
cannam@85
|
100 void mad_stream_buffer(struct mad_stream *,
|
cannam@85
|
101 unsigned char const *, unsigned long);
|
cannam@85
|
102 void mad_stream_skip(struct mad_stream *, unsigned long);
|
cannam@85
|
103
|
cannam@85
|
104 int mad_stream_sync(struct mad_stream *);
|
cannam@85
|
105
|
cannam@85
|
106 char const *mad_stream_errorstr(struct mad_stream const *);
|
cannam@85
|
107
|
cannam@85
|
108 # endif
|