ogg.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /************************************************************************
  2. * Copyright (C) 2002-2009, Xiph.org Foundation
  3. * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following disclaimer
  14. * in the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the names of the Xiph.org Foundation nor Pinknoise
  17. * Productions Ltd nor the names of its contributors may be used to
  18. * endorse or promote products derived from this software without
  19. * specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ************************************************************************
  33. function: subsumed libogg includes
  34. ************************************************************************/
  35. #ifndef _OGG_H
  36. #define _OGG_H
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. #include "os_types.h"
  41. #ifndef ONLY_C
  42. #define ARM_LITTLE_ENDIAN
  43. #endif
  44. typedef struct ogg_buffer_state{
  45. struct ogg_buffer *unused_buffers;
  46. struct ogg_reference *unused_references;
  47. int outstanding;
  48. int shutdown;
  49. } ogg_buffer_state;
  50. typedef struct ogg_buffer {
  51. unsigned char *data;
  52. long size;
  53. int refcount;
  54. union {
  55. ogg_buffer_state *owner;
  56. struct ogg_buffer *next;
  57. } ptr;
  58. } ogg_buffer;
  59. typedef struct ogg_reference {
  60. ogg_buffer *buffer;
  61. long begin;
  62. long length;
  63. struct ogg_reference *next;
  64. } ogg_reference;
  65. typedef struct oggpack_buffer {
  66. #ifdef ARM_LITTLE_ENDIAN
  67. int bitsLeftInSegment;
  68. ogg_uint32_t *ptr;
  69. long bitsLeftInWord;
  70. #else
  71. int headbit;
  72. unsigned char *headptr;
  73. long headend;
  74. #endif /* ARM_LITTLE_ENDIAN */
  75. /* memory management */
  76. ogg_reference *head;
  77. ogg_reference *tail;
  78. /* render the byte/bit counter API constant time */
  79. long count; /* doesn't count the tail */
  80. } oggpack_buffer;
  81. typedef struct oggbyte_buffer {
  82. ogg_reference *baseref;
  83. ogg_reference *ref;
  84. unsigned char *ptr;
  85. long pos;
  86. long end;
  87. } oggbyte_buffer;
  88. typedef struct ogg_sync_state {
  89. /* decode memory management pool */
  90. ogg_buffer_state *bufferpool;
  91. /* stream buffers */
  92. ogg_reference *fifo_head;
  93. ogg_reference *fifo_tail;
  94. long fifo_fill;
  95. /* stream sync management */
  96. int unsynced;
  97. int headerbytes;
  98. int bodybytes;
  99. } ogg_sync_state;
  100. typedef struct ogg_stream_state {
  101. ogg_reference *header_head;
  102. ogg_reference *header_tail;
  103. ogg_reference *body_head;
  104. ogg_reference *body_tail;
  105. int e_o_s; /* set when we have buffered the last
  106. packet in the logical bitstream */
  107. int b_o_s; /* set after we've written the initial page
  108. of a logical bitstream */
  109. long serialno;
  110. long pageno;
  111. ogg_int64_t packetno; /* sequence number for decode; the framing
  112. knows where there's a hole in the data,
  113. but we need coupling so that the codec
  114. (which is in a seperate abstraction
  115. layer) also knows about the gap */
  116. ogg_int64_t granulepos;
  117. int lacing_fill;
  118. ogg_uint32_t body_fill;
  119. /* decode-side state data */
  120. int holeflag;
  121. int spanflag;
  122. int clearflag;
  123. int laceptr;
  124. ogg_uint32_t body_fill_next;
  125. } ogg_stream_state;
  126. typedef struct {
  127. ogg_reference *packet;
  128. long bytes;
  129. long b_o_s;
  130. long e_o_s;
  131. ogg_int64_t granulepos;
  132. ogg_int64_t packetno; /* sequence number for decode; the framing
  133. knows where there's a hole in the data,
  134. but we need coupling so that the codec
  135. (which is in a seperate abstraction
  136. layer) also knows about the gap */
  137. } ogg_packet;
  138. typedef struct {
  139. ogg_reference *header;
  140. int header_len;
  141. ogg_reference *body;
  142. long body_len;
  143. } ogg_page;
  144. /* Ogg BITSTREAM PRIMITIVES: bitstream ************************/
  145. extern void oggpack_readinit(oggpack_buffer *b,ogg_reference *r);
  146. extern long oggpack_look(oggpack_buffer *b,int bits);
  147. extern void oggpack_adv(oggpack_buffer *b,int bits);
  148. extern long oggpack_read(oggpack_buffer *b,int bits);
  149. extern long oggpack_bytes(oggpack_buffer *b);
  150. extern long oggpack_bits(oggpack_buffer *b);
  151. extern int oggpack_eop(oggpack_buffer *b);
  152. // Quick hack
  153. #define oggpack_bytesleft(B) (((B)->bitsLeftInSegment+7)/8)
  154. /* Ogg BITSTREAM PRIMITIVES: decoding **************************/
  155. extern void ogg_sync_init(ogg_sync_state *oy);
  156. extern ogg_sync_state *ogg_sync_create(void);
  157. extern int ogg_sync_clear(ogg_sync_state *oy);
  158. extern int ogg_sync_destroy(ogg_sync_state *oy);
  159. extern int ogg_sync_reset(ogg_sync_state *oy);
  160. extern unsigned char *ogg_sync_bufferin(ogg_sync_state *oy, long size);
  161. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  162. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  163. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  164. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  165. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  166. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  167. /* Ogg BITSTREAM PRIMITIVES: general ***************************/
  168. extern void ogg_stream_init(ogg_stream_state *os, int serialno);
  169. extern ogg_stream_state *ogg_stream_create(int serialno);
  170. extern int ogg_stream_destroy(ogg_stream_state *os);
  171. extern int ogg_stream_clear(ogg_stream_state *os);
  172. extern int ogg_stream_reset(ogg_stream_state *os);
  173. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  174. extern int ogg_stream_eos(ogg_stream_state *os);
  175. extern int ogg_page_checksum_set(ogg_page *og);
  176. extern int ogg_page_version(ogg_page *og);
  177. extern int ogg_page_continued(ogg_page *og);
  178. extern int ogg_page_bos(ogg_page *og);
  179. extern int ogg_page_eos(ogg_page *og);
  180. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  181. extern ogg_uint32_t ogg_page_serialno(ogg_page *og);
  182. extern ogg_uint32_t ogg_page_pageno(ogg_page *og);
  183. extern int ogg_page_packets(ogg_page *og);
  184. extern int ogg_page_getbuffer(ogg_page *og, unsigned char **buffer);
  185. extern int ogg_packet_release(ogg_packet *op);
  186. extern int ogg_page_release(ogg_page *og);
  187. extern void ogg_page_dup(ogg_page *d, ogg_page *s);
  188. /* Ogg BITSTREAM PRIMITIVES: return codes ***************************/
  189. #define OGG_SUCCESS 0
  190. #define OGG_HOLE -10
  191. #define OGG_SPAN -11
  192. #define OGG_EVERSION -12
  193. #define OGG_ESERIAL -13
  194. #define OGG_EINVAL -14
  195. #define OGG_EEOS -15
  196. #ifdef __cplusplus
  197. }
  198. #endif
  199. #endif /* _OGG_H */