1 /********************************************************************
3 * THIS FILE IS PART OF THE Ogg Reference Library SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE Ogg Reference Library SOURCE CODE IS (C) COPYRIGHT 1994-2004 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
11 ********************************************************************
13 function: internal/hidden data representation structures
16 ********************************************************************/
28 struct ogg2_buffer_state
{
29 ogg2_buffer
*unused_buffers
;
30 ogg2_reference
*unused_references
;
43 ogg2_buffer_state
*owner
;
48 struct ogg2_reference
{
49 struct ogg2_buffer
*buffer
;
53 struct ogg2_reference
*next
;
54 #ifdef OGG2BUFFER_DEBUG
59 struct ogg2pack_buffer
{
61 unsigned char *headptr
;
64 /* memory management */
68 /* render the byte/bit counter API constant time */
69 long count
; /* doesn't count the tail */
70 ogg2_buffer_state
*owner
; /* useful on encode side */
73 typedef struct ogg2byte_buffer
{
74 ogg2_reference
*baseref
;
81 ogg2_buffer_state
*owner
; /* if it's to be extensible; encode side */
82 int external
; /* did baseref come from outside? */
85 struct ogg2_sync_state
{
86 /* decode memory management pool */
87 ogg2_buffer_state
*bufferpool
;
90 ogg2_reference
*fifo_head
;
91 ogg2_reference
*fifo_tail
;
94 /* stream sync management */
101 struct ogg2_stream_state
{
102 /* encode memory management pool */
103 ogg2_buffer_state
*bufferpool
;
105 ogg2_reference
*header_head
;
106 ogg2_reference
*header_tail
;
107 ogg2_reference
*body_head
;
108 ogg2_reference
*body_tail
;
110 int e_o_s
; /* set when we have buffered the last
111 packet in the logical bitstream */
112 int b_o_s
; /* set after we've written the initial page
113 of a logical bitstream */
116 ogg_int64_t packetno
; /* sequence number for decode; the framing
117 knows where there's a hole in the data,
118 but we need coupling so that the codec
119 (which is in a seperate abstraction
120 layer) also knows about the gap */
121 ogg_int64_t granulepos
;
122 int discont
; /* 0 = continuous, 1 = discontinuous */
125 ogg_uint32_t body_fill
;
127 /* encode-side header build */
128 unsigned int watermark
;
129 ogg2byte_buffer header_build
;
133 /* decode-side state data */
138 ogg_uint32_t body_fill_next
;
142 extern ogg2_buffer_state
*ogg2_buffer_create(void);
143 extern void ogg2_buffer_destroy(ogg2_buffer_state
*bs
);
144 extern ogg2_reference
*ogg2_buffer_alloc(ogg2_buffer_state
*bs
,long bytes
);
145 extern void ogg2_buffer_realloc(ogg2_reference
*or,long bytes
);
146 extern ogg2_reference
*ogg2_buffer_sub(ogg2_reference
*or,long begin
,long length
);
147 extern ogg2_reference
*ogg2_buffer_dup(ogg2_reference
*or);
148 extern ogg2_reference
*ogg2_buffer_extend(ogg2_reference
*or,long bytes
);
149 extern void ogg2_buffer_mark(ogg2_reference
*or);
150 extern void ogg2_buffer_release(ogg2_reference
*or);
151 extern void ogg2_buffer_release_one(ogg2_reference
*or);
152 extern ogg2_reference
*ogg2_buffer_pretruncate(ogg2_reference
*or,long pos
);
153 extern void ogg2_buffer_posttruncate(ogg2_reference
*or,long pos
);
154 extern ogg2_reference
*ogg2_buffer_cat(ogg2_reference
*tail
, ogg2_reference
*head
);
155 extern ogg2_reference
*ogg2_buffer_walk(ogg2_reference
*or);
156 extern long ogg2_buffer_length(ogg2_reference
*or);
157 extern ogg2_reference
*ogg2_buffer_split(ogg2_reference
**tail
,
158 ogg2_reference
**head
,long pos
);
159 extern void ogg2_buffer_outstanding(ogg2_buffer_state
*bs
);
161 extern int ogg2byte_init(ogg2byte_buffer
*b
,ogg2_reference
*or,
162 ogg2_buffer_state
*bs
);
163 extern void ogg2byte_clear(ogg2byte_buffer
*b
);
164 extern ogg2_reference
*ogg2byte_return_and_reset(ogg2byte_buffer
*b
);
165 extern void ogg2byte_set1(ogg2byte_buffer
*b
,unsigned char val
,
167 extern void ogg2byte_set2(ogg2byte_buffer
*b
,int val
,int pos
);
168 extern void ogg2byte_set4(ogg2byte_buffer
*b
,ogg_uint32_t val
,int pos
);
169 extern void ogg2byte_set8(ogg2byte_buffer
*b
,ogg_int64_t val
,int pos
);
170 extern unsigned char ogg2byte_read1(ogg2byte_buffer
*b
,int pos
);
171 extern int ogg2byte_read2(ogg2byte_buffer
*b
,int pos
);
172 extern ogg_uint32_t
ogg2byte_read4(ogg2byte_buffer
*b
,int pos
);
173 extern ogg_int64_t
ogg2byte_read8(ogg2byte_buffer
*b
,int pos
);
174 extern int ogg2_page_checksum_set(ogg2_page
*og
);
177 #define OGG2PACK_CHUNKSIZE 3
178 #define OGG2PACK_MINCHUNKSIZE 1
180 #define OGG2PACK_CHUNKSIZE 128
181 #define OGG2PACK_MINCHUNKSIZE 16