Chris@0: /* Chris@0: * libmad - MPEG audio decoder library Chris@0: * Copyright (C) 2000-2004 Underbit Technologies, Inc. Chris@0: * Chris@0: * This program is free software; you can redistribute it and/or modify Chris@0: * it under the terms of the GNU General Public License as published by Chris@0: * the Free Software Foundation; either version 2 of the License, or Chris@0: * (at your option) any later version. Chris@0: * Chris@0: * This program is distributed in the hope that it will be useful, Chris@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: * GNU General Public License for more details. Chris@0: * Chris@0: * You should have received a copy of the GNU General Public License Chris@0: * along with this program; if not, write to the Free Software Chris@0: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Chris@0: * Chris@0: * $Id: stream.h,v 1.20 2004/02/05 09:02:39 rob Exp $ Chris@0: */ Chris@0: Chris@0: # ifndef LIBMAD_STREAM_H Chris@0: # define LIBMAD_STREAM_H Chris@0: Chris@0: # include "bit.h" Chris@0: Chris@0: # define MAD_BUFFER_GUARD 8 Chris@0: # define MAD_BUFFER_MDLEN (511 + 2048 + MAD_BUFFER_GUARD) Chris@0: Chris@0: enum mad_error { Chris@0: MAD_ERROR_NONE = 0x0000, /* no error */ Chris@0: Chris@0: MAD_ERROR_BUFLEN = 0x0001, /* input buffer too small (or EOF) */ Chris@0: MAD_ERROR_BUFPTR = 0x0002, /* invalid (null) buffer pointer */ Chris@0: Chris@0: MAD_ERROR_NOMEM = 0x0031, /* not enough memory */ Chris@0: Chris@0: MAD_ERROR_LOSTSYNC = 0x0101, /* lost synchronization */ Chris@0: MAD_ERROR_BADLAYER = 0x0102, /* reserved header layer value */ Chris@0: MAD_ERROR_BADBITRATE = 0x0103, /* forbidden bitrate value */ Chris@0: MAD_ERROR_BADSAMPLERATE = 0x0104, /* reserved sample frequency value */ Chris@0: MAD_ERROR_BADEMPHASIS = 0x0105, /* reserved emphasis value */ Chris@0: Chris@0: MAD_ERROR_BADCRC = 0x0201, /* CRC check failed */ Chris@0: MAD_ERROR_BADBITALLOC = 0x0211, /* forbidden bit allocation value */ Chris@0: MAD_ERROR_BADSCALEFACTOR = 0x0221, /* bad scalefactor index */ Chris@0: MAD_ERROR_BADMODE = 0x0222, /* bad bitrate/mode combination */ Chris@0: MAD_ERROR_BADFRAMELEN = 0x0231, /* bad frame length */ Chris@0: MAD_ERROR_BADBIGVALUES = 0x0232, /* bad big_values count */ Chris@0: MAD_ERROR_BADBLOCKTYPE = 0x0233, /* reserved block_type */ Chris@0: MAD_ERROR_BADSCFSI = 0x0234, /* bad scalefactor selection info */ Chris@0: MAD_ERROR_BADDATAPTR = 0x0235, /* bad main_data_begin pointer */ Chris@0: MAD_ERROR_BADPART3LEN = 0x0236, /* bad audio data length */ Chris@0: MAD_ERROR_BADHUFFTABLE = 0x0237, /* bad Huffman table select */ Chris@0: MAD_ERROR_BADHUFFDATA = 0x0238, /* Huffman data overrun */ Chris@0: MAD_ERROR_BADSTEREO = 0x0239 /* incompatible block_type for JS */ Chris@0: }; Chris@0: Chris@0: # define MAD_RECOVERABLE(error) ((error) & 0xff00) Chris@0: Chris@0: struct mad_stream { Chris@0: unsigned char const *buffer; /* input bitstream buffer */ Chris@0: unsigned char const *bufend; /* end of buffer */ Chris@0: unsigned long skiplen; /* bytes to skip before next frame */ Chris@0: Chris@0: int sync; /* stream sync found */ Chris@0: unsigned long freerate; /* free bitrate (fixed) */ Chris@0: Chris@0: unsigned char const *this_frame; /* start of current frame */ Chris@0: unsigned char const *next_frame; /* start of next frame */ Chris@0: struct mad_bitptr ptr; /* current processing bit pointer */ Chris@0: Chris@0: struct mad_bitptr anc_ptr; /* ancillary bits pointer */ Chris@0: unsigned int anc_bitlen; /* number of ancillary bits */ Chris@0: Chris@0: unsigned char (*main_data)[MAD_BUFFER_MDLEN]; Chris@0: /* Layer III main_data() */ Chris@0: unsigned int md_len; /* bytes in main_data */ Chris@0: Chris@0: int options; /* decoding options (see below) */ Chris@0: enum mad_error error; /* error code (see above) */ Chris@0: }; Chris@0: Chris@0: enum { Chris@0: MAD_OPTION_IGNORECRC = 0x0001, /* ignore CRC errors */ Chris@0: MAD_OPTION_HALFSAMPLERATE = 0x0002 /* generate PCM at 1/2 sample rate */ Chris@0: # if 0 /* not yet implemented */ Chris@0: MAD_OPTION_LEFTCHANNEL = 0x0010, /* decode left channel only */ Chris@0: MAD_OPTION_RIGHTCHANNEL = 0x0020, /* decode right channel only */ Chris@0: MAD_OPTION_SINGLECHANNEL = 0x0030 /* combine channels */ Chris@0: # endif Chris@0: }; Chris@0: Chris@0: void mad_stream_init(struct mad_stream *); Chris@0: void mad_stream_finish(struct mad_stream *); Chris@0: Chris@0: # define mad_stream_options(stream, opts) \ Chris@0: ((void) ((stream)->options = (opts))) Chris@0: Chris@0: void mad_stream_buffer(struct mad_stream *, Chris@0: unsigned char const *, unsigned long); Chris@0: void mad_stream_skip(struct mad_stream *, unsigned long); Chris@0: Chris@0: int mad_stream_sync(struct mad_stream *); Chris@0: Chris@0: char const *mad_stream_errorstr(struct mad_stream const *); Chris@0: Chris@0: # endif