diff options
author | Sean Bartell <wingedtachikoma@gmail.com> | 2011-06-25 21:32:25 -0400 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2012-04-25 22:13:20 +0200 |
commit | f40bfc9267b13b54e6379dfe7539447662879d24 (patch) | |
tree | 9b20069d5e62809ff434061ad730096836f916f2 /lib/rbcodec/codecs/libtremor/ogg.h | |
parent | a0009907de7a0107d49040d8a180f140e2eff299 (diff) | |
download | rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.tar.gz rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.zip |
Add codecs to librbcodec.
Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97
Reviewed-on: http://gerrit.rockbox.org/137
Reviewed-by: Nils Wallménius <nils@rockbox.org>
Tested-by: Nils Wallménius <nils@rockbox.org>
Diffstat (limited to 'lib/rbcodec/codecs/libtremor/ogg.h')
-rw-r--r-- | lib/rbcodec/codecs/libtremor/ogg.h | 282 |
1 files changed, 282 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libtremor/ogg.h b/lib/rbcodec/codecs/libtremor/ogg.h new file mode 100644 index 0000000000..d3af919b85 --- /dev/null +++ b/lib/rbcodec/codecs/libtremor/ogg.h | |||
@@ -0,0 +1,282 @@ | |||
1 | /******************************************************************** | ||
2 | * * | ||
3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC 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. * | ||
7 | * * | ||
8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 * | ||
9 | * by the Xiph.Org Foundation http://www.xiph.org/ * | ||
10 | * * | ||
11 | ******************************************************************** | ||
12 | |||
13 | function: toplevel libogg include | ||
14 | last mod: $Id$ | ||
15 | |||
16 | ********************************************************************/ | ||
17 | #ifndef _OGG_H | ||
18 | #define _OGG_H | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" { | ||
22 | #endif | ||
23 | |||
24 | #include <stddef.h> | ||
25 | #include "os_types.h" | ||
26 | |||
27 | extern const unsigned long mask[] ICONST_ATTR; | ||
28 | |||
29 | typedef struct { | ||
30 | void *iov_base; | ||
31 | size_t iov_len; | ||
32 | } ogg_iovec_t; | ||
33 | |||
34 | typedef struct { | ||
35 | long endbyte; | ||
36 | int endbit; | ||
37 | |||
38 | unsigned char *buffer; | ||
39 | unsigned char *ptr; | ||
40 | long storage; | ||
41 | } oggpack_buffer; | ||
42 | |||
43 | /* ogg_page is used to encapsulate the data in one Ogg bitstream page *****/ | ||
44 | |||
45 | typedef struct { | ||
46 | unsigned char *header; | ||
47 | long header_len; | ||
48 | unsigned char *body; | ||
49 | long body_len; | ||
50 | } ogg_page; | ||
51 | |||
52 | /* ogg_stream_state contains the current encode/decode state of a logical | ||
53 | Ogg bitstream **********************************************************/ | ||
54 | |||
55 | typedef struct { | ||
56 | unsigned char *body_data; /* bytes from packet bodies */ | ||
57 | long body_storage; /* storage elements allocated */ | ||
58 | long body_fill; /* elements stored; fill mark */ | ||
59 | long body_returned; /* elements of fill returned */ | ||
60 | |||
61 | |||
62 | int *lacing_vals; /* The values that will go to the segment table */ | ||
63 | ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact | ||
64 | this way, but it is simple coupled to the | ||
65 | lacing fifo */ | ||
66 | long lacing_storage; | ||
67 | long lacing_fill; | ||
68 | long lacing_packet; | ||
69 | long lacing_returned; | ||
70 | |||
71 | #if 0 | ||
72 | unsigned char header[282]; /* working space for header encode */ | ||
73 | int header_fill; | ||
74 | #endif | ||
75 | int e_o_s; /* set when we have buffered the last packet in the | ||
76 | logical bitstream */ | ||
77 | int b_o_s; /* set after we've written the initial page | ||
78 | of a logical bitstream */ | ||
79 | ogg_uint32_t serialno; | ||
80 | long pageno; | ||
81 | ogg_int64_t packetno; /* sequence number for decode; the framing | ||
82 | knows where there's a hole in the data, | ||
83 | but we need coupling so that the codec | ||
84 | (which is in a separate abstraction | ||
85 | layer) also knows about the gap */ | ||
86 | ogg_int64_t granulepos; | ||
87 | |||
88 | } ogg_stream_state; | ||
89 | |||
90 | /* ogg_packet is used to encapsulate the data and metadata belonging | ||
91 | to a single raw Ogg/Vorbis packet *************************************/ | ||
92 | |||
93 | typedef struct { | ||
94 | unsigned char *packet; | ||
95 | long bytes; | ||
96 | long b_o_s; | ||
97 | long e_o_s; | ||
98 | |||
99 | ogg_int64_t granulepos; | ||
100 | |||
101 | ogg_int64_t packetno; /* sequence number for decode; the framing | ||
102 | knows where there's a hole in the data, | ||
103 | but we need coupling so that the codec | ||
104 | (which is in a separate abstraction | ||
105 | layer) also knows about the gap */ | ||
106 | } ogg_packet; | ||
107 | |||
108 | typedef struct { | ||
109 | unsigned char *data; | ||
110 | int storage; | ||
111 | int fill; | ||
112 | int returned; | ||
113 | |||
114 | int unsynced; | ||
115 | int headerbytes; | ||
116 | int bodybytes; | ||
117 | } ogg_sync_state; | ||
118 | |||
119 | /* Ogg BITSTREAM PRIMITIVES: bitstream ************************/ | ||
120 | /* | ||
121 | extern void oggpack_writeinit(oggpack_buffer *b); | ||
122 | extern int oggpack_writecheck(oggpack_buffer *b); | ||
123 | extern void oggpack_writetrunc(oggpack_buffer *b,long bits); | ||
124 | extern void oggpack_writealign(oggpack_buffer *b); | ||
125 | extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits); | ||
126 | extern void oggpack_reset(oggpack_buffer *b); | ||
127 | extern void oggpack_writeclear(oggpack_buffer *b); */ | ||
128 | extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes); | ||
129 | /* | ||
130 | extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits); | ||
131 | extern long oggpack_look(oggpack_buffer *b,int bits); | ||
132 | */ | ||
133 | |||
134 | static inline long oggpack_look(oggpack_buffer *b,int bits){ | ||
135 | unsigned long ret; | ||
136 | unsigned long m; | ||
137 | |||
138 | if(bits<0 || bits>32) return -1; | ||
139 | m=mask[bits]; | ||
140 | bits+=b->endbit; | ||
141 | |||
142 | if(b->endbyte >= b->storage-4){ | ||
143 | /* not the main path */ | ||
144 | if(b->endbyte > b->storage-((bits+7)>>3)) return -1; | ||
145 | /* special case to avoid reading b->ptr[0], which might be past the end of | ||
146 | the buffer; also skips some useless accounting */ | ||
147 | else if(!bits)return(0L); | ||
148 | } | ||
149 | |||
150 | ret=b->ptr[0]>>b->endbit; | ||
151 | if(bits>8){ | ||
152 | ret|=b->ptr[1]<<(8-b->endbit); | ||
153 | if(bits>16){ | ||
154 | ret|=b->ptr[2]<<(16-b->endbit); | ||
155 | if(bits>24){ | ||
156 | ret|=b->ptr[3]<<(24-b->endbit); | ||
157 | if(bits>32 && b->endbit) | ||
158 | ret|=b->ptr[4]<<(32-b->endbit); | ||
159 | } | ||
160 | } | ||
161 | } | ||
162 | return(m&ret); | ||
163 | } | ||
164 | /* | ||
165 | extern long oggpack_look1(oggpack_buffer *b); | ||
166 | extern void oggpack_adv(oggpack_buffer *b,int bits); | ||
167 | */ | ||
168 | |||
169 | static inline void oggpack_adv(oggpack_buffer *b, unsigned int bits){ | ||
170 | bits+=b->endbit; | ||
171 | |||
172 | if(b->endbyte > b->storage-(int)((bits+7)>>3)) goto overflow; | ||
173 | |||
174 | b->ptr+=bits/8; | ||
175 | b->endbyte+=bits/8; | ||
176 | b->endbit=bits&7; | ||
177 | return; | ||
178 | |||
179 | overflow: | ||
180 | b->ptr=NULL; | ||
181 | b->endbyte=b->storage; | ||
182 | b->endbit=1; | ||
183 | } | ||
184 | |||
185 | /* | ||
186 | extern void oggpack_adv1(oggpack_buffer *b); | ||
187 | */ | ||
188 | extern long oggpack_read(oggpack_buffer *b,int bits); | ||
189 | /* | ||
190 | extern long oggpack_read1(oggpack_buffer *b); | ||
191 | extern long oggpack_bytes(oggpack_buffer *b); | ||
192 | */ | ||
193 | static inline long oggpack_bytes(oggpack_buffer *b){ | ||
194 | return(b->endbyte+(b->endbit+7)/8); | ||
195 | } | ||
196 | #if 0 | ||
197 | extern long oggpack_bits(oggpack_buffer *b); | ||
198 | extern unsigned char *oggpack_get_buffer(oggpack_buffer *b); | ||
199 | |||
200 | extern void oggpackB_writeinit(oggpack_buffer *b); | ||
201 | extern int oggpackB_writecheck(oggpack_buffer *b); | ||
202 | extern void oggpackB_writetrunc(oggpack_buffer *b,long bits); | ||
203 | extern void oggpackB_writealign(oggpack_buffer *b); | ||
204 | extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits); | ||
205 | extern void oggpackB_reset(oggpack_buffer *b); | ||
206 | extern void oggpackB_writeclear(oggpack_buffer *b); | ||
207 | extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes); | ||
208 | extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits); | ||
209 | extern long oggpackB_look(oggpack_buffer *b,int bits); | ||
210 | extern long oggpackB_look1(oggpack_buffer *b); | ||
211 | extern void oggpackB_adv(oggpack_buffer *b,int bits); | ||
212 | extern void oggpackB_adv1(oggpack_buffer *b); | ||
213 | extern long oggpackB_read(oggpack_buffer *b,int bits); | ||
214 | extern long oggpackB_read1(oggpack_buffer *b); | ||
215 | extern long oggpackB_bytes(oggpack_buffer *b); | ||
216 | extern long oggpackB_bits(oggpack_buffer *b); | ||
217 | extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b); | ||
218 | # endif | ||
219 | /* Ogg BITSTREAM PRIMITIVES: encoding **************************/ | ||
220 | #if 0 | ||
221 | extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op); | ||
222 | extern int ogg_stream_iovecin(ogg_stream_state *os, ogg_iovec_t *iov, | ||
223 | int count, long e_o_s, ogg_int64_t granulepos); | ||
224 | extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og); | ||
225 | extern int ogg_stream_pageout_fill(ogg_stream_state *os, ogg_page *og, int nfill); | ||
226 | extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og); | ||
227 | #endif | ||
228 | /* Ogg BITSTREAM PRIMITIVES: decoding **************************/ | ||
229 | |||
230 | extern int _os_body_expand(ogg_stream_state *os,int needed); | ||
231 | |||
232 | extern int ogg_sync_init(ogg_sync_state *oy); | ||
233 | extern int ogg_sync_clear(ogg_sync_state *oy); | ||
234 | extern int ogg_sync_reset(ogg_sync_state *oy); | ||
235 | /* | ||
236 | extern int ogg_sync_destroy(ogg_sync_state *oy); | ||
237 | extern int ogg_sync_check(ogg_sync_state *oy); | ||
238 | */ | ||
239 | |||
240 | extern char *ogg_sync_buffer(ogg_sync_state *oy, long size); | ||
241 | extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes); | ||
242 | extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og); | ||
243 | /* | ||
244 | extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og); | ||
245 | */ | ||
246 | extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og, bool copy_body); | ||
247 | extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op); | ||
248 | extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op); | ||
249 | |||
250 | /* Ogg BITSTREAM PRIMITIVES: general ***************************/ | ||
251 | |||
252 | extern int ogg_stream_init(ogg_stream_state *os,int serialno); | ||
253 | extern int ogg_stream_clear(ogg_stream_state *os); | ||
254 | extern int ogg_stream_reset(ogg_stream_state *os); | ||
255 | extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno); | ||
256 | /* | ||
257 | extern int ogg_stream_destroy(ogg_stream_state *os); | ||
258 | extern int ogg_stream_check(ogg_stream_state *os); | ||
259 | */ | ||
260 | extern int ogg_stream_eos(ogg_stream_state *os); | ||
261 | |||
262 | /* | ||
263 | extern void ogg_page_checksum_set(ogg_page *og); | ||
264 | extern int ogg_page_version(const ogg_page *og); | ||
265 | */ | ||
266 | extern int ogg_page_continued(const ogg_page *og); | ||
267 | extern int ogg_page_bos(const ogg_page *og); | ||
268 | extern int ogg_page_eos(const ogg_page *og); | ||
269 | extern ogg_int64_t ogg_page_granulepos(const ogg_page *og); | ||
270 | extern ogg_uint32_t ogg_page_serialno(const ogg_page *og); | ||
271 | /* | ||
272 | extern long ogg_page_pageno(const ogg_page *og); | ||
273 | extern int ogg_page_packets(const ogg_page *og); | ||
274 | |||
275 | extern void ogg_packet_clear(ogg_packet *op); | ||
276 | */ | ||
277 | |||
278 | #ifdef __cplusplus | ||
279 | } | ||
280 | #endif | ||
281 | |||
282 | #endif /* _OGG_H */ | ||