summaryrefslogtreecommitdiff
path: root/apps/codecs/libtremor/ogg.h
diff options
context:
space:
mode:
authorNils Wallménius <nils@rockbox.org>2010-12-06 14:36:52 +0000
committerNils Wallménius <nils@rockbox.org>2010-12-06 14:36:52 +0000
commit67efbc13870ee87ce3df442f7c396c13481921ec (patch)
treeeaf63d36c5bf2d41a6b3bb2addecb4d3c05f7eef /apps/codecs/libtremor/ogg.h
parent1f64b7fb1fa5058e3b7871078055156eac0c511d (diff)
downloadrockbox-67efbc13870ee87ce3df442f7c396c13481921ec.tar.gz
rockbox-67efbc13870ee87ce3df442f7c396c13481921ec.zip
libtremor:
Merge in upstream revision 17375. This removes tremor's internal ogg code and now uses libogg instead so a bunch of changes are just adjusting to the new api. Also brings in improvements to vorbisfile which fixes FS#10484. Disabled a lot of unused code in the libogg files and moved some small functions into the ogg.h header so they can be inlined. Some small tweaks to fix warnings. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28742 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libtremor/ogg.h')
-rw-r--r--apps/codecs/libtremor/ogg.h387
1 files changed, 192 insertions, 195 deletions
diff --git a/apps/codecs/libtremor/ogg.h b/apps/codecs/libtremor/ogg.h
index 15ca46b3cd..da072184b4 100644
--- a/apps/codecs/libtremor/ogg.h
+++ b/apps/codecs/libtremor/ogg.h
@@ -1,17 +1,17 @@
1/******************************************************************** 1/********************************************************************
2 * * 2 * *
3 * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * 3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4 * *
5 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
6 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
7 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * * 7 * *
9 * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 * 8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
10 * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * 9 * by the Xiph.Org Foundation http://www.xiph.org/ *
11 * * 10 * *
12 ******************************************************************** 11 ********************************************************************
13 12
14 function: subsumed libogg includes 13 function: toplevel libogg include
14 last mod: $Id$
15 15
16 ********************************************************************/ 16 ********************************************************************/
17#ifndef _OGG_H 17#ifndef _OGG_H
@@ -21,241 +21,238 @@
21extern "C" { 21extern "C" {
22#endif 22#endif
23 23
24#include <stddef.h>
24#include "os_types.h" 25#include "os_types.h"
25 26
26typedef struct ogg_buffer_state{ 27extern const unsigned long mask[] ICONST_ATTR;
27 struct ogg_buffer *unused_buffers;
28 struct ogg_reference *unused_references;
29 int outstanding;
30 int shutdown;
31} ogg_buffer_state;
32
33typedef 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
44typedef struct ogg_reference {
45 ogg_buffer *buffer;
46 long begin;
47 long length;
48
49 struct ogg_reference *next;
50} ogg_reference;
51
52typedef 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 28
65typedef struct oggbyte_buffer { 29typedef struct {
66 ogg_reference *baseref; 30 void *iov_base;
31 size_t iov_len;
32} ogg_iovec_t;
33
34typedef struct {
35 long endbyte;
36 int endbit;
67 37
68 ogg_reference *ref; 38 unsigned char *buffer;
69 unsigned char *ptr; 39 unsigned char *ptr;
70 long pos; 40 long storage;
71 long end; 41} oggpack_buffer;
72} oggbyte_buffer;
73 42
74typedef struct ogg_sync_state { 43/* ogg_page is used to encapsulate the data in one Ogg bitstream page *****/
75 /* decode memory management pool */
76 ogg_buffer_state *bufferpool;
77 44
78 /* stream buffers */ 45typedef struct {
79 ogg_reference *fifo_head; 46 unsigned char *header;
80 ogg_reference *fifo_tail; 47 long header_len;
81 long fifo_fill; 48 unsigned char *body;
49 long body_len;
50} ogg_page;
82 51
83 /* stream sync management */ 52/* ogg_stream_state contains the current encode/decode state of a logical
84 int unsynced; 53 Ogg bitstream **********************************************************/
85 int headerbytes;
86 int bodybytes;
87 54
88} ogg_sync_state; 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;
89 87
90typedef 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; 88} ogg_stream_state;
120 89
90/* ogg_packet is used to encapsulate the data and metadata belonging
91 to a single raw Ogg/Vorbis packet *************************************/
92
121typedef struct { 93typedef struct {
122 ogg_reference *packet; 94 unsigned char *packet;
123 long bytes; 95 long bytes;
124 long b_o_s; 96 long b_o_s;
125 long e_o_s; 97 long e_o_s;
126 ogg_int64_t granulepos; 98
127 ogg_int64_t packetno; /* sequence number for decode; the framing 99 ogg_int64_t granulepos;
128 knows where there's a hole in the data, 100
129 but we need coupling so that the codec 101 ogg_int64_t packetno; /* sequence number for decode; the framing
130 (which is in a seperate abstraction 102 knows where there's a hole in the data,
131 layer) also knows about the gap */ 103 but we need coupling so that the codec
104 (which is in a separate abstraction
105 layer) also knows about the gap */
132} ogg_packet; 106} ogg_packet;
133 107
134typedef struct { 108typedef struct {
135 ogg_reference *header; 109 unsigned char *data;
136 int header_len; 110 int storage;
137 ogg_reference *body; 111 int fill;
138 long body_len; 112 int returned;
139} ogg_page; 113
114 int unsynced;
115 int headerbytes;
116 int bodybytes;
117} ogg_sync_state;
140 118
141/* Ogg BITSTREAM PRIMITIVES: bitstream ************************/ 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/* extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits); */
130
131//extern long oggpack_look(oggpack_buffer *b,int bits);
132static inline long oggpack_look(oggpack_buffer *b,int bits){
133 unsigned long ret;
134 unsigned long m;
135
136 if(bits<0 || bits>32) return -1;
137 m=mask[bits];
138 bits+=b->endbit;
139
140 if(b->endbyte >= b->storage-4){
141 /* not the main path */
142 if(b->endbyte > b->storage-((bits+7)>>3)) return -1;
143 /* special case to avoid reading b->ptr[0], which might be past the end of
144 the buffer; also skips some useless accounting */
145 else if(!bits)return(0L);
146 }
142 147
143extern void oggpack_readinit(oggpack_buffer *b,ogg_reference *r); 148 ret=b->ptr[0]>>b->endbit;
144extern long oggpack_look_full(oggpack_buffer *b,int bits); 149 if(bits>8){
145extern long oggpack_read(oggpack_buffer *b,register int bits); 150 ret|=b->ptr[1]<<(8-b->endbit);
146 151 if(bits>16){
147/* Inline a few, often called functions */ 152 ret|=b->ptr[2]<<(16-b->endbit);
148 153 if(bits>24){
149/* mark read process as having run off the end */ 154 ret|=b->ptr[3]<<(24-b->endbit);
150static inline void _adv_halt(oggpack_buffer *b){ 155 if(bits>32 && b->endbit)
151 b->headptr=b->head->buffer->data+b->head->begin+b->head->length; 156 ret|=b->ptr[4]<<(32-b->endbit);
152 b->headend=-1; 157 }
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. */
160static 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 } 158 }
176 } 159 }
160 return(m&ret);
177} 161}
178 162
179/* limited to 32 at a time */ 163extern long oggpack_look1(oggpack_buffer *b);
164
165//extern void oggpack_adv(oggpack_buffer *b,int bits);
180static inline void oggpack_adv(oggpack_buffer *b,int bits){ 166static inline void oggpack_adv(oggpack_buffer *b,int bits){
181 bits+=b->headbit; 167 bits+=b->endbit;
182 b->headbit=bits&7;
183 b->headptr+=bits/8;
184 if((b->headend-=((unsigned)bits)/8)<1)_span(b);
185}
186 168
187static inline long oggpack_look(oggpack_buffer *b, int bits){ 169 if(b->endbyte > b->storage-((bits+7)>>3)) goto overflow;
188 if(bits+b->headbit < b->headend<<3){ 170
189 extern const unsigned long oggpack_mask[]; 171 b->ptr+=bits/8;
190 unsigned long m=oggpack_mask[bits]; 172 b->endbyte+=bits/8;
191 unsigned long ret=-1; 173 b->endbit=bits&7;
192 174 return;
193 bits+=b->headbit; 175
194 ret=b->headptr[0]>>b->headbit; 176 overflow:
195 if(bits>8){ 177 b->ptr=NULL;
196 ret|=b->headptr[1]<<(8-b->headbit); 178 b->endbyte=b->storage;
197 if(bits>16){ 179 b->endbit=1;
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} 180}
211 181
182extern void oggpack_adv1(oggpack_buffer *b);
183extern long oggpack_read(oggpack_buffer *b,int bits);
184extern long oggpack_read1(oggpack_buffer *b);
185#if 0
186extern long oggpack_bytes(oggpack_buffer *b);
187extern long oggpack_bits(oggpack_buffer *b);
188extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
189
190extern void oggpackB_writeinit(oggpack_buffer *b);
191extern int oggpackB_writecheck(oggpack_buffer *b);
192extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
193extern void oggpackB_writealign(oggpack_buffer *b);
194extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
195extern void oggpackB_reset(oggpack_buffer *b);
196extern void oggpackB_writeclear(oggpack_buffer *b);
197extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
198extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
199extern long oggpackB_look(oggpack_buffer *b,int bits);
200extern long oggpackB_look1(oggpack_buffer *b);
201extern void oggpackB_adv(oggpack_buffer *b,int bits);
202extern void oggpackB_adv1(oggpack_buffer *b);
203extern long oggpackB_read(oggpack_buffer *b,int bits);
204extern long oggpackB_read1(oggpack_buffer *b);
205extern long oggpackB_bytes(oggpack_buffer *b);
206extern long oggpackB_bits(oggpack_buffer *b);
207extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
208# endif
209/* Ogg BITSTREAM PRIMITIVES: encoding **************************/
210#if 0
211extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
212extern int ogg_stream_iovecin(ogg_stream_state *os, ogg_iovec_t *iov,
213 int count, long e_o_s, ogg_int64_t granulepos);
214extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
215extern int ogg_stream_pageout_fill(ogg_stream_state *os, ogg_page *og, int nfill);
216extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
217#endif
212/* Ogg BITSTREAM PRIMITIVES: decoding **************************/ 218/* Ogg BITSTREAM PRIMITIVES: decoding **************************/
213 219
214extern ogg_sync_state *ogg_sync_create(void); 220extern int ogg_sync_init(ogg_sync_state *oy);
215extern int ogg_sync_destroy(ogg_sync_state *oy); 221extern int ogg_sync_clear(ogg_sync_state *oy);
216extern int ogg_sync_reset(ogg_sync_state *oy); 222extern int ogg_sync_reset(ogg_sync_state *oy);
223extern int ogg_sync_destroy(ogg_sync_state *oy);
224extern int ogg_sync_check(ogg_sync_state *oy);
217 225
218extern unsigned char *ogg_sync_bufferin(ogg_sync_state *oy, long size); 226extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
219extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes); 227extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
220extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og); 228extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
229extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
221extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og); 230extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
222extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op); 231extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
223extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op); 232extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
224 233
225/* Ogg BITSTREAM PRIMITIVES: general ***************************/ 234/* Ogg BITSTREAM PRIMITIVES: general ***************************/
226 235
227extern ogg_stream_state *ogg_stream_create(int serialno); 236extern int ogg_stream_init(ogg_stream_state *os,int serialno);
228extern int ogg_stream_destroy(ogg_stream_state *os); 237extern int ogg_stream_clear(ogg_stream_state *os);
229extern int ogg_stream_reset(ogg_stream_state *os); 238extern int ogg_stream_reset(ogg_stream_state *os);
230extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno); 239extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
240extern int ogg_stream_destroy(ogg_stream_state *os);
241extern int ogg_stream_check(ogg_stream_state *os);
231extern int ogg_stream_eos(ogg_stream_state *os); 242extern int ogg_stream_eos(ogg_stream_state *os);
232 243
233extern int ogg_page_checksum_set(ogg_page *og); 244extern void ogg_page_checksum_set(ogg_page *og);
234
235extern int ogg_page_version(ogg_page *og);
236extern int ogg_page_continued(ogg_page *og);
237extern int ogg_page_bos(ogg_page *og);
238extern int ogg_page_eos(ogg_page *og);
239extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
240extern ogg_uint32_t ogg_page_serialno(ogg_page *og);
241extern ogg_uint32_t ogg_page_pageno(ogg_page *og);
242extern int ogg_page_getbuffer(ogg_page *og, unsigned char **buffer);
243
244extern int ogg_packet_release(ogg_packet *op);
245extern int ogg_page_release(ogg_page *og);
246
247extern void ogg_page_dup(ogg_page *d, ogg_page *s);
248
249/* Ogg BITSTREAM PRIMITIVES: return codes ***************************/
250 245
251#define OGG_SUCCESS 0 246extern int ogg_page_version(const ogg_page *og);
247extern int ogg_page_continued(const ogg_page *og);
248extern int ogg_page_bos(const ogg_page *og);
249extern int ogg_page_eos(const ogg_page *og);
250extern ogg_int64_t ogg_page_granulepos(const ogg_page *og);
251extern ogg_uint32_t ogg_page_serialno(const ogg_page *og);
252extern long ogg_page_pageno(const ogg_page *og);
253extern int ogg_page_packets(const ogg_page *og);
252 254
253#define OGG_HOLE -10 255extern void ogg_packet_clear(ogg_packet *op);
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 256
260 257
261#ifdef __cplusplus 258#ifdef __cplusplus