ogg.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
  4. * *
  5. * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
  6. * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  7. * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  8. * *
  9. * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 *
  10. * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
  11. * *
  12. ********************************************************************
  13. function: subsumed libogg includes
  14. ********************************************************************/
  15. #ifndef _OGG_H
  16. #define _OGG_H
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #include "os_types.h"
  21. #ifndef ONLY_C
  22. #define ARM_LITTLE_ENDIAN
  23. #endif
  24. typedef struct ogg_buffer_state{
  25. struct ogg_buffer *unused_buffers;
  26. struct ogg_reference *unused_references;
  27. int outstanding;
  28. int shutdown;
  29. } ogg_buffer_state;
  30. typedef struct ogg_buffer {
  31. unsigned char *data;
  32. long size;
  33. int refcount;
  34. union {
  35. ogg_buffer_state *owner;
  36. struct ogg_buffer *next;
  37. } ptr;
  38. } ogg_buffer;
  39. typedef struct ogg_reference {
  40. ogg_buffer *buffer;
  41. long begin;
  42. long length;
  43. struct ogg_reference *next;
  44. } ogg_reference;
  45. typedef struct oggpack_buffer {
  46. #ifdef ARM_LITTLE_ENDIAN
  47. int bitsLeftInSegment;
  48. ogg_uint32_t *ptr;
  49. long bitsLeftInWord;
  50. #else
  51. int headbit;
  52. unsigned char *headptr;
  53. long headend;
  54. #endif /* ARM_LITTLE_ENDIAN */
  55. /* memory management */
  56. ogg_reference *head;
  57. ogg_reference *tail;
  58. /* render the byte/bit counter API constant time */
  59. long count; /* doesn't count the tail */
  60. } oggpack_buffer;
  61. typedef struct oggbyte_buffer {
  62. ogg_reference *baseref;
  63. ogg_reference *ref;
  64. unsigned char *ptr;
  65. long pos;
  66. long end;
  67. } oggbyte_buffer;
  68. typedef struct ogg_sync_state {
  69. /* decode memory management pool */
  70. ogg_buffer_state *bufferpool;
  71. /* stream buffers */
  72. ogg_reference *fifo_head;
  73. ogg_reference *fifo_tail;
  74. long fifo_fill;
  75. /* stream sync management */
  76. int unsynced;
  77. int headerbytes;
  78. int bodybytes;
  79. } ogg_sync_state;
  80. typedef struct ogg_stream_state {
  81. ogg_reference *header_head;
  82. ogg_reference *header_tail;
  83. ogg_reference *body_head;
  84. ogg_reference *body_tail;
  85. int e_o_s; /* set when we have buffered the last
  86. packet in the logical bitstream */
  87. int b_o_s; /* set after we've written the initial page
  88. of a logical bitstream */
  89. long serialno;
  90. long pageno;
  91. ogg_int64_t packetno; /* sequence number for decode; the framing
  92. knows where there's a hole in the data,
  93. but we need coupling so that the codec
  94. (which is in a seperate abstraction
  95. layer) also knows about the gap */
  96. ogg_int64_t granulepos;
  97. int lacing_fill;
  98. ogg_uint32_t body_fill;
  99. /* decode-side state data */
  100. int holeflag;
  101. int spanflag;
  102. int clearflag;
  103. int laceptr;
  104. ogg_uint32_t body_fill_next;
  105. } ogg_stream_state;
  106. typedef struct {
  107. ogg_reference *packet;
  108. long bytes;
  109. long b_o_s;
  110. long e_o_s;
  111. ogg_int64_t granulepos;
  112. ogg_int64_t packetno; /* sequence number for decode; the framing
  113. knows where there's a hole in the data,
  114. but we need coupling so that the codec
  115. (which is in a seperate abstraction
  116. layer) also knows about the gap */
  117. } ogg_packet;
  118. typedef struct {
  119. ogg_reference *header;
  120. int header_len;
  121. ogg_reference *body;
  122. long body_len;
  123. } ogg_page;
  124. /* Ogg BITSTREAM PRIMITIVES: bitstream ************************/
  125. extern void oggpack_readinit(oggpack_buffer *b,ogg_reference *r);
  126. extern long oggpack_look(oggpack_buffer *b,int bits);
  127. extern void oggpack_adv(oggpack_buffer *b,int bits);
  128. extern long oggpack_read(oggpack_buffer *b,int bits);
  129. extern long oggpack_bytes(oggpack_buffer *b);
  130. extern long oggpack_bits(oggpack_buffer *b);
  131. extern int oggpack_eop(oggpack_buffer *b);
  132. /* Ogg BITSTREAM PRIMITIVES: decoding **************************/
  133. extern ogg_sync_state *ogg_sync_create(void);
  134. extern int ogg_sync_destroy(ogg_sync_state *oy);
  135. extern int ogg_sync_reset(ogg_sync_state *oy);
  136. extern unsigned char *ogg_sync_bufferin(ogg_sync_state *oy, long size);
  137. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  138. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  139. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  140. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  141. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  142. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  143. /* Ogg BITSTREAM PRIMITIVES: general ***************************/
  144. extern ogg_stream_state *ogg_stream_create(int serialno);
  145. extern int ogg_stream_destroy(ogg_stream_state *os);
  146. extern int ogg_stream_reset(ogg_stream_state *os);
  147. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  148. extern int ogg_stream_eos(ogg_stream_state *os);
  149. extern int ogg_page_checksum_set(ogg_page *og);
  150. extern int ogg_page_version(ogg_page *og);
  151. extern int ogg_page_continued(ogg_page *og);
  152. extern int ogg_page_bos(ogg_page *og);
  153. extern int ogg_page_eos(ogg_page *og);
  154. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  155. extern ogg_uint32_t ogg_page_serialno(ogg_page *og);
  156. extern ogg_uint32_t ogg_page_pageno(ogg_page *og);
  157. extern int ogg_page_packets(ogg_page *og);
  158. extern int ogg_page_getbuffer(ogg_page *og, unsigned char **buffer);
  159. extern int ogg_packet_release(ogg_packet *op);
  160. extern int ogg_page_release(ogg_page *og);
  161. extern void ogg_page_dup(ogg_page *d, ogg_page *s);
  162. /* Ogg BITSTREAM PRIMITIVES: return codes ***************************/
  163. #define OGG_SUCCESS 0
  164. #define OGG_HOLE -10
  165. #define OGG_SPAN -11
  166. #define OGG_EVERSION -12
  167. #define OGG_ESERIAL -13
  168. #define OGG_EINVAL -14
  169. #define OGG_EEOS -15
  170. #ifdef __cplusplus
  171. }
  172. #endif
  173. #endif /* _OGG_H */