stream.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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.h,v 1.20 2004/02/05 09:02:39 rob Exp $
  20. */
  21. # ifndef LIBMAD_STREAM_H
  22. # define LIBMAD_STREAM_H
  23. # include "bit.h"
  24. # define MAD_BUFFER_GUARD 8
  25. # define MAD_BUFFER_MDLEN (511 + 2048 + MAD_BUFFER_GUARD)
  26. enum mad_error {
  27. MAD_ERROR_NONE = 0x0000, /* no error */
  28. MAD_ERROR_BUFLEN = 0x0001, /* input buffer too small (or EOF) */
  29. MAD_ERROR_BUFPTR = 0x0002, /* invalid (null) buffer pointer */
  30. MAD_ERROR_NOMEM = 0x0031, /* not enough memory */
  31. MAD_ERROR_LOSTSYNC = 0x0101, /* lost synchronization */
  32. MAD_ERROR_BADLAYER = 0x0102, /* reserved header layer value */
  33. MAD_ERROR_BADBITRATE = 0x0103, /* forbidden bitrate value */
  34. MAD_ERROR_BADSAMPLERATE = 0x0104, /* reserved sample frequency value */
  35. MAD_ERROR_BADEMPHASIS = 0x0105, /* reserved emphasis value */
  36. MAD_ERROR_BADCRC = 0x0201, /* CRC check failed */
  37. MAD_ERROR_BADBITALLOC = 0x0211, /* forbidden bit allocation value */
  38. MAD_ERROR_BADSCALEFACTOR = 0x0221, /* bad scalefactor index */
  39. MAD_ERROR_BADMODE = 0x0222, /* bad bitrate/mode combination */
  40. MAD_ERROR_BADFRAMELEN = 0x0231, /* bad frame length */
  41. MAD_ERROR_BADBIGVALUES = 0x0232, /* bad big_values count */
  42. MAD_ERROR_BADBLOCKTYPE = 0x0233, /* reserved block_type */
  43. MAD_ERROR_BADSCFSI = 0x0234, /* bad scalefactor selection info */
  44. MAD_ERROR_BADDATAPTR = 0x0235, /* bad main_data_begin pointer */
  45. MAD_ERROR_BADPART3LEN = 0x0236, /* bad audio data length */
  46. MAD_ERROR_BADHUFFTABLE = 0x0237, /* bad Huffman table select */
  47. MAD_ERROR_BADHUFFDATA = 0x0238, /* Huffman data overrun */
  48. MAD_ERROR_BADSTEREO = 0x0239 /* incompatible block_type for JS */
  49. };
  50. # define MAD_RECOVERABLE(error) ((error) & 0xff00)
  51. struct mad_stream {
  52. unsigned char const *buffer; /* input bitstream buffer */
  53. unsigned char const *bufend; /* end of buffer */
  54. unsigned long skiplen; /* bytes to skip before next frame */
  55. int sync; /* stream sync found */
  56. unsigned long freerate; /* free bitrate (fixed) */
  57. unsigned char const *this_frame; /* start of current frame */
  58. unsigned char const *next_frame; /* start of next frame */
  59. struct mad_bitptr ptr; /* current processing bit pointer */
  60. struct mad_bitptr anc_ptr; /* ancillary bits pointer */
  61. unsigned int anc_bitlen; /* number of ancillary bits */
  62. unsigned char (*main_data)[MAD_BUFFER_MDLEN];
  63. /* Layer III main_data() */
  64. unsigned int md_len; /* bytes in main_data */
  65. int options; /* decoding options (see below) */
  66. enum mad_error error; /* error code (see above) */
  67. };
  68. enum {
  69. MAD_OPTION_IGNORECRC = 0x0001, /* ignore CRC errors */
  70. MAD_OPTION_HALFSAMPLERATE = 0x0002 /* generate PCM at 1/2 sample rate */
  71. # if 0 /* not yet implemented */
  72. MAD_OPTION_LEFTCHANNEL = 0x0010, /* decode left channel only */
  73. MAD_OPTION_RIGHTCHANNEL = 0x0020, /* decode right channel only */
  74. MAD_OPTION_SINGLECHANNEL = 0x0030 /* combine channels */
  75. # endif
  76. };
  77. void mad_stream_init(struct mad_stream *);
  78. void mad_stream_finish(struct mad_stream *);
  79. # define mad_stream_options(stream, opts) \
  80. ((void) ((stream)->options = (opts)))
  81. void mad_stream_buffer(struct mad_stream *,
  82. unsigned char const *, unsigned long);
  83. void mad_stream_skip(struct mad_stream *, unsigned long);
  84. int mad_stream_sync(struct mad_stream *);
  85. char const *mad_stream_errorstr(struct mad_stream const *);
  86. # endif