Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
4.4 KiB

  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. # ifdef HAVE_CONFIG_H
  22. # include "config.h"
  23. # endif
  24. # include "global.h"
  25. # include <stdlib.h>
  26. # include "bit.h"
  27. # include "stream.h"
  28. /*
  29. * NAME: stream->init()
  30. * DESCRIPTION: initialize stream struct
  31. */
  32. void mad_stream_init(struct mad_stream *stream)
  33. {
  34. stream->buffer = 0;
  35. stream->bufend = 0;
  36. stream->skiplen = 0;
  37. stream->sync = 0;
  38. stream->freerate = 0;
  39. stream->this_frame = 0;
  40. stream->next_frame = 0;
  41. mad_bit_init(&stream->ptr, 0);
  42. mad_bit_init(&stream->anc_ptr, 0);
  43. stream->anc_bitlen = 0;
  44. stream->main_data = 0;
  45. stream->md_len = 0;
  46. stream->options = 0;
  47. stream->error = MAD_ERROR_NONE;
  48. }
  49. /*
  50. * NAME: stream->finish()
  51. * DESCRIPTION: deallocate any dynamic memory associated with stream
  52. */
  53. void mad_stream_finish(struct mad_stream *stream)
  54. {
  55. if (stream->main_data) {
  56. free(stream->main_data);
  57. stream->main_data = 0;
  58. }
  59. mad_bit_finish(&stream->anc_ptr);
  60. mad_bit_finish(&stream->ptr);
  61. }
  62. /*
  63. * NAME: stream->buffer()
  64. * DESCRIPTION: set stream buffer pointers
  65. */
  66. void mad_stream_buffer(struct mad_stream *stream,
  67. unsigned char const *buffer, unsigned long length)
  68. {
  69. stream->buffer = buffer;
  70. stream->bufend = buffer + length;
  71. stream->this_frame = buffer;
  72. stream->next_frame = buffer;
  73. stream->sync = 1;
  74. mad_bit_init(&stream->ptr, buffer);
  75. }
  76. /*
  77. * NAME: stream->skip()
  78. * DESCRIPTION: arrange to skip bytes before the next frame
  79. */
  80. void mad_stream_skip(struct mad_stream *stream, unsigned long length)
  81. {
  82. stream->skiplen += length;
  83. }
  84. /*
  85. * NAME: stream->sync()
  86. * DESCRIPTION: locate the next stream sync word
  87. */
  88. int mad_stream_sync(struct mad_stream *stream)
  89. {
  90. register unsigned char const *ptr, *end;
  91. ptr = mad_bit_nextbyte(&stream->ptr);
  92. end = stream->bufend;
  93. while (ptr < end - 1 &&
  94. !(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0))
  95. ++ptr;
  96. if (end - ptr < MAD_BUFFER_GUARD)
  97. return -1;
  98. mad_bit_init(&stream->ptr, ptr);
  99. return 0;
  100. }
  101. /*
  102. * NAME: stream->errorstr()
  103. * DESCRIPTION: return a string description of the current error condition
  104. */
  105. char const *mad_stream_errorstr(struct mad_stream const *stream)
  106. {
  107. switch (stream->error) {
  108. case MAD_ERROR_NONE: return "no error";
  109. case MAD_ERROR_BUFLEN: return "input buffer too small (or EOF)";
  110. case MAD_ERROR_BUFPTR: return "invalid (null) buffer pointer";
  111. case MAD_ERROR_NOMEM: return "not enough memory";
  112. case MAD_ERROR_LOSTSYNC: return "lost synchronization";
  113. case MAD_ERROR_BADLAYER: return "reserved header layer value";
  114. case MAD_ERROR_BADBITRATE: return "forbidden bitrate value";
  115. case MAD_ERROR_BADSAMPLERATE: return "reserved sample frequency value";
  116. case MAD_ERROR_BADEMPHASIS: return "reserved emphasis value";
  117. case MAD_ERROR_BADCRC: return "CRC check failed";
  118. case MAD_ERROR_BADBITALLOC: return "forbidden bit allocation value";
  119. case MAD_ERROR_BADSCALEFACTOR: return "bad scalefactor index";
  120. case MAD_ERROR_BADMODE: return "bad bitrate/mode combination";
  121. case MAD_ERROR_BADFRAMELEN: return "bad frame length";
  122. case MAD_ERROR_BADBIGVALUES: return "bad big_values count";
  123. case MAD_ERROR_BADBLOCKTYPE: return "reserved block_type";
  124. case MAD_ERROR_BADSCFSI: return "bad scalefactor selection info";
  125. case MAD_ERROR_BADDATAPTR: return "bad main_data_begin pointer";
  126. case MAD_ERROR_BADPART3LEN: return "bad audio data length";
  127. case MAD_ERROR_BADHUFFTABLE: return "bad Huffman table select";
  128. case MAD_ERROR_BADHUFFDATA: return "Huffman data overrun";
  129. case MAD_ERROR_BADSTEREO: return "incompatible block_type for JS";
  130. }
  131. return 0;
  132. }