diff options
author | Björn Stenberg <bjorn@haxx.se> | 2008-11-05 13:30:58 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2008-11-05 13:30:58 +0000 |
commit | 45bd7e024603ba47207e5cc64c61e4116e8f1261 (patch) | |
tree | cf789bb0ce99eb8b153c5445c535ef5c4e4ead62 /apps/codecs/libtremor/ogg.h | |
parent | 7ec9ceeaaabb75adaa790b41eba6dec020232fa6 (diff) | |
download | rockbox-45bd7e024603ba47207e5cc64c61e4116e8f1261.tar.gz rockbox-45bd7e024603ba47207e5cc64c61e4116e8f1261.zip |
Codec lib directories renamed, except for demac.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19018 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libtremor/ogg.h')
-rw-r--r-- | apps/codecs/libtremor/ogg.h | 265 |
1 files changed, 265 insertions, 0 deletions
diff --git a/apps/codecs/libtremor/ogg.h b/apps/codecs/libtremor/ogg.h new file mode 100644 index 0000000000..7e2785f117 --- /dev/null +++ b/apps/codecs/libtremor/ogg.h | |||
@@ -0,0 +1,265 @@ | |||
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 | |||
14 | function: subsumed libogg includes | ||
15 | |||
16 | ********************************************************************/ | ||
17 | #ifndef _OGG_H | ||
18 | #define _OGG_H | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" { | ||
22 | #endif | ||
23 | |||
24 | #include "os_types.h" | ||
25 | |||
26 | typedef struct ogg_buffer_state{ | ||
27 | struct ogg_buffer *unused_buffers; | ||
28 | struct ogg_reference *unused_references; | ||
29 | int outstanding; | ||
30 | int shutdown; | ||
31 | } ogg_buffer_state; | ||
32 | |||
33 | typedef struct ogg_buffer { | ||
34 | unsigned char *data; | ||
35 | long size; | ||
36 | int refcount; | ||
37 | |||
38 | union { | ||
39 | ogg_buffer_state *owner; | ||
40 | struct ogg_buffer *next; | ||
41 | } ptr; | ||
42 | } ogg_buffer; | ||
43 | |||
44 | typedef struct ogg_reference { | ||
45 | ogg_buffer *buffer; | ||
46 | long begin; | ||
47 | long length; | ||
48 | |||
49 | struct ogg_reference *next; | ||
50 | } ogg_reference; | ||
51 | |||
52 | typedef struct oggpack_buffer { | ||
53 | int headbit; | ||
54 | unsigned char *headptr; | ||
55 | long headend; | ||
56 | |||
57 | /* memory management */ | ||
58 | ogg_reference *head; | ||
59 | ogg_reference *tail; | ||
60 | |||
61 | /* render the byte/bit counter API constant time */ | ||
62 | long count; /* doesn't count the tail */ | ||
63 | } oggpack_buffer; | ||
64 | |||
65 | typedef struct oggbyte_buffer { | ||
66 | ogg_reference *baseref; | ||
67 | |||
68 | ogg_reference *ref; | ||
69 | unsigned char *ptr; | ||
70 | long pos; | ||
71 | long end; | ||
72 | } oggbyte_buffer; | ||
73 | |||
74 | typedef struct ogg_sync_state { | ||
75 | /* decode memory management pool */ | ||
76 | ogg_buffer_state *bufferpool; | ||
77 | |||
78 | /* stream buffers */ | ||
79 | ogg_reference *fifo_head; | ||
80 | ogg_reference *fifo_tail; | ||
81 | long fifo_fill; | ||
82 | |||
83 | /* stream sync management */ | ||
84 | int unsynced; | ||
85 | int headerbytes; | ||
86 | int bodybytes; | ||
87 | |||
88 | } ogg_sync_state; | ||
89 | |||
90 | typedef struct ogg_stream_state { | ||
91 | ogg_reference *header_head; | ||
92 | ogg_reference *header_tail; | ||
93 | ogg_reference *body_head; | ||
94 | ogg_reference *body_tail; | ||
95 | |||
96 | int e_o_s; /* set when we have buffered the last | ||
97 | packet in the logical bitstream */ | ||
98 | int b_o_s; /* set after we've written the initial page | ||
99 | of a logical bitstream */ | ||
100 | long serialno; | ||
101 | long pageno; | ||
102 | ogg_int64_t packetno; /* sequence number for decode; the framing | ||
103 | knows where there's a hole in the data, | ||
104 | but we need coupling so that the codec | ||
105 | (which is in a seperate abstraction | ||
106 | layer) also knows about the gap */ | ||
107 | ogg_int64_t granulepos; | ||
108 | |||
109 | int lacing_fill; | ||
110 | ogg_uint32_t body_fill; | ||
111 | |||
112 | /* decode-side state data */ | ||
113 | int holeflag; | ||
114 | int spanflag; | ||
115 | int clearflag; | ||
116 | int laceptr; | ||
117 | ogg_uint32_t body_fill_next; | ||
118 | |||
119 | } ogg_stream_state; | ||
120 | |||
121 | typedef struct { | ||
122 | ogg_reference *packet; | ||
123 | long bytes; | ||
124 | long b_o_s; | ||
125 | long e_o_s; | ||
126 | ogg_int64_t granulepos; | ||
127 | ogg_int64_t packetno; /* sequence number for decode; the framing | ||
128 | knows where there's a hole in the data, | ||
129 | but we need coupling so that the codec | ||
130 | (which is in a seperate abstraction | ||
131 | layer) also knows about the gap */ | ||
132 | } ogg_packet; | ||
133 | |||
134 | typedef struct { | ||
135 | ogg_reference *header; | ||
136 | int header_len; | ||
137 | ogg_reference *body; | ||
138 | long body_len; | ||
139 | } ogg_page; | ||
140 | |||
141 | /* Ogg BITSTREAM PRIMITIVES: bitstream ************************/ | ||
142 | |||
143 | extern void oggpack_readinit(oggpack_buffer *b,ogg_reference *r); | ||
144 | extern long oggpack_look_full(oggpack_buffer *b,int bits); | ||
145 | extern long oggpack_read(oggpack_buffer *b,int bits); | ||
146 | |||
147 | /* Inline a few, often called functions */ | ||
148 | |||
149 | /* mark read process as having run off the end */ | ||
150 | static inline void _adv_halt(oggpack_buffer *b){ | ||
151 | b->headptr=b->head->buffer->data+b->head->begin+b->head->length; | ||
152 | b->headend=-1; | ||
153 | b->headbit=0; | ||
154 | } | ||
155 | |||
156 | /* spans forward, skipping as many bytes as headend is negative; if | ||
157 | headend is zero, simply finds next byte. If we're up to the end | ||
158 | of the buffer, leaves headend at zero. If we've read past the end, | ||
159 | halt the decode process. */ | ||
160 | static inline void _span(oggpack_buffer *b){ | ||
161 | while(b->headend<1){ | ||
162 | if(b->head->next){ | ||
163 | b->count+=b->head->length; | ||
164 | b->head=b->head->next; | ||
165 | b->headptr=b->head->buffer->data+b->head->begin-b->headend; | ||
166 | b->headend+=b->head->length; | ||
167 | }else{ | ||
168 | /* we've either met the end of decode, or gone past it. halt | ||
169 | only if we're past */ | ||
170 | if(b->headend<0 || b->headbit) | ||
171 | /* read has fallen off the end */ | ||
172 | _adv_halt(b); | ||
173 | |||
174 | break; | ||
175 | } | ||
176 | } | ||
177 | } | ||
178 | |||
179 | /* limited to 32 at a time */ | ||
180 | static inline void oggpack_adv(oggpack_buffer *b,int bits){ | ||
181 | bits+=b->headbit; | ||
182 | b->headbit=bits&7; | ||
183 | b->headptr+=bits/8; | ||
184 | if((b->headend-=((unsigned)bits)/8)<1)_span(b); | ||
185 | } | ||
186 | |||
187 | static inline long oggpack_look(oggpack_buffer *b, int bits){ | ||
188 | if(bits+b->headbit < b->headend<<3){ | ||
189 | extern const unsigned long oggpack_mask[]; | ||
190 | unsigned long m=oggpack_mask[bits]; | ||
191 | unsigned long ret=-1; | ||
192 | |||
193 | bits+=b->headbit; | ||
194 | ret=b->headptr[0]>>b->headbit; | ||
195 | if(bits>8){ | ||
196 | ret|=b->headptr[1]<<(8-b->headbit); | ||
197 | if(bits>16){ | ||
198 | ret|=b->headptr[2]<<(16-b->headbit); | ||
199 | if(bits>24){ | ||
200 | ret|=b->headptr[3]<<(24-b->headbit); | ||
201 | if(bits>32 && b->headbit) | ||
202 | ret|=b->headptr[4]<<(32-b->headbit); | ||
203 | } | ||
204 | } | ||
205 | } | ||
206 | return ret&m; | ||
207 | }else{ | ||
208 | return oggpack_look_full(b, bits); | ||
209 | } | ||
210 | } | ||
211 | |||
212 | /* Ogg BITSTREAM PRIMITIVES: decoding **************************/ | ||
213 | |||
214 | extern ogg_sync_state *ogg_sync_create(void); | ||
215 | extern int ogg_sync_destroy(ogg_sync_state *oy); | ||
216 | extern int ogg_sync_reset(ogg_sync_state *oy); | ||
217 | |||
218 | extern unsigned char *ogg_sync_bufferin(ogg_sync_state *oy, long size); | ||
219 | extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes); | ||
220 | extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og); | ||
221 | extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og); | ||
222 | extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op); | ||
223 | extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op); | ||
224 | |||
225 | /* Ogg BITSTREAM PRIMITIVES: general ***************************/ | ||
226 | |||
227 | extern ogg_stream_state *ogg_stream_create(int serialno); | ||
228 | extern int ogg_stream_destroy(ogg_stream_state *os); | ||
229 | extern int ogg_stream_reset(ogg_stream_state *os); | ||
230 | extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno); | ||
231 | extern int ogg_stream_eos(ogg_stream_state *os); | ||
232 | |||
233 | extern int ogg_page_checksum_set(ogg_page *og); | ||
234 | |||
235 | extern int ogg_page_version(ogg_page *og); | ||
236 | extern int ogg_page_continued(ogg_page *og); | ||
237 | extern int ogg_page_bos(ogg_page *og); | ||
238 | extern int ogg_page_eos(ogg_page *og); | ||
239 | extern ogg_int64_t ogg_page_granulepos(ogg_page *og); | ||
240 | extern ogg_uint32_t ogg_page_serialno(ogg_page *og); | ||
241 | extern ogg_uint32_t ogg_page_pageno(ogg_page *og); | ||
242 | extern int ogg_page_getbuffer(ogg_page *og, unsigned char **buffer); | ||
243 | |||
244 | extern int ogg_packet_release(ogg_packet *op); | ||
245 | extern int ogg_page_release(ogg_page *og); | ||
246 | |||
247 | extern void ogg_page_dup(ogg_page *d, ogg_page *s); | ||
248 | |||
249 | /* Ogg BITSTREAM PRIMITIVES: return codes ***************************/ | ||
250 | |||
251 | #define OGG_SUCCESS 0 | ||
252 | |||
253 | #define OGG_HOLE -10 | ||
254 | #define OGG_SPAN -11 | ||
255 | #define OGG_EVERSION -12 | ||
256 | #define OGG_ESERIAL -13 | ||
257 | #define OGG_EINVAL -14 | ||
258 | #define OGG_EEOS -15 | ||
259 | |||
260 | |||
261 | #ifdef __cplusplus | ||
262 | } | ||
263 | #endif | ||
264 | |||
265 | #endif /* _OGG_H */ | ||