summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libtremor/ogg.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/libtremor/ogg.h')
-rw-r--r--lib/rbcodec/codecs/libtremor/ogg.h282
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
21extern "C" {
22#endif
23
24#include <stddef.h>
25#include "os_types.h"
26
27extern const unsigned long mask[] ICONST_ATTR;
28
29typedef struct {
30 void *iov_base;
31 size_t iov_len;
32} ogg_iovec_t;
33
34typedef 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
45typedef 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
55typedef 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
93typedef 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
108typedef 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/*
121extern void oggpack_writeinit(oggpack_buffer *b);
122extern int oggpack_writecheck(oggpack_buffer *b);
123extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
124extern void oggpack_writealign(oggpack_buffer *b);
125extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
126extern void oggpack_reset(oggpack_buffer *b);
127extern void oggpack_writeclear(oggpack_buffer *b); */
128extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
129/*
130extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
131extern long oggpack_look(oggpack_buffer *b,int bits);
132*/
133
134static 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/*
165extern long oggpack_look1(oggpack_buffer *b);
166extern void oggpack_adv(oggpack_buffer *b,int bits);
167*/
168
169static 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/*
186extern void oggpack_adv1(oggpack_buffer *b);
187*/
188extern long oggpack_read(oggpack_buffer *b,int bits);
189/*
190extern long oggpack_read1(oggpack_buffer *b);
191extern long oggpack_bytes(oggpack_buffer *b);
192*/
193static inline long oggpack_bytes(oggpack_buffer *b){
194 return(b->endbyte+(b->endbit+7)/8);
195}
196#if 0
197extern long oggpack_bits(oggpack_buffer *b);
198extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
199
200extern void oggpackB_writeinit(oggpack_buffer *b);
201extern int oggpackB_writecheck(oggpack_buffer *b);
202extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
203extern void oggpackB_writealign(oggpack_buffer *b);
204extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
205extern void oggpackB_reset(oggpack_buffer *b);
206extern void oggpackB_writeclear(oggpack_buffer *b);
207extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
208extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
209extern long oggpackB_look(oggpack_buffer *b,int bits);
210extern long oggpackB_look1(oggpack_buffer *b);
211extern void oggpackB_adv(oggpack_buffer *b,int bits);
212extern void oggpackB_adv1(oggpack_buffer *b);
213extern long oggpackB_read(oggpack_buffer *b,int bits);
214extern long oggpackB_read1(oggpack_buffer *b);
215extern long oggpackB_bytes(oggpack_buffer *b);
216extern long oggpackB_bits(oggpack_buffer *b);
217extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
218# endif
219/* Ogg BITSTREAM PRIMITIVES: encoding **************************/
220#if 0
221extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
222extern int ogg_stream_iovecin(ogg_stream_state *os, ogg_iovec_t *iov,
223 int count, long e_o_s, ogg_int64_t granulepos);
224extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
225extern int ogg_stream_pageout_fill(ogg_stream_state *os, ogg_page *og, int nfill);
226extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
227#endif
228/* Ogg BITSTREAM PRIMITIVES: decoding **************************/
229
230extern int _os_body_expand(ogg_stream_state *os,int needed);
231
232extern int ogg_sync_init(ogg_sync_state *oy);
233extern int ogg_sync_clear(ogg_sync_state *oy);
234extern int ogg_sync_reset(ogg_sync_state *oy);
235/*
236extern int ogg_sync_destroy(ogg_sync_state *oy);
237extern int ogg_sync_check(ogg_sync_state *oy);
238*/
239
240extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
241extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
242extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
243/*
244extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
245*/
246extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og, bool copy_body);
247extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
248extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
249
250/* Ogg BITSTREAM PRIMITIVES: general ***************************/
251
252extern int ogg_stream_init(ogg_stream_state *os,int serialno);
253extern int ogg_stream_clear(ogg_stream_state *os);
254extern int ogg_stream_reset(ogg_stream_state *os);
255extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
256/*
257extern int ogg_stream_destroy(ogg_stream_state *os);
258extern int ogg_stream_check(ogg_stream_state *os);
259*/
260extern int ogg_stream_eos(ogg_stream_state *os);
261
262/*
263extern void ogg_page_checksum_set(ogg_page *og);
264extern int ogg_page_version(const ogg_page *og);
265*/
266extern int ogg_page_continued(const ogg_page *og);
267extern int ogg_page_bos(const ogg_page *og);
268extern int ogg_page_eos(const ogg_page *og);
269extern ogg_int64_t ogg_page_granulepos(const ogg_page *og);
270extern ogg_uint32_t ogg_page_serialno(const ogg_page *og);
271/*
272extern long ogg_page_pageno(const ogg_page *og);
273extern int ogg_page_packets(const ogg_page *og);
274
275extern void ogg_packet_clear(ogg_packet *op);
276*/
277
278#ifdef __cplusplus
279}
280#endif
281
282#endif /* _OGG_H */