• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /************************************************************************
2  * Copyright (C) 2002-2009, Xiph.org Foundation
3  * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following disclaimer
14  * in the documentation and/or other materials provided with the
15  * distribution.
16  *     * Neither the names of the Xiph.org Foundation nor Pinknoise
17  * Productions Ltd nor the names of its contributors may be used to
18  * endorse or promote products derived from this software without
19  * specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  ************************************************************************
33 
34  function: subsumed libogg includes
35 
36  ************************************************************************/
37 #ifndef _OGG_H
38 #define _OGG_H
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 #include "os_types.h"
45 
46 #ifndef ONLY_C
47 #define ARM_LITTLE_ENDIAN
48 #endif
49 
50 typedef struct ogg_buffer_state{
51   struct ogg_buffer    *unused_buffers;
52   struct ogg_reference *unused_references;
53   int                   outstanding;
54   int                   shutdown;
55 } ogg_buffer_state;
56 
57 typedef struct ogg_buffer {
58   unsigned char      *data;
59   long                size;
60   int                 refcount;
61 
62   union {
63     ogg_buffer_state  *owner;
64     struct ogg_buffer *next;
65   } ptr;
66 } ogg_buffer;
67 
68 typedef struct ogg_reference {
69   ogg_buffer    *buffer;
70   long           begin;
71   long           length;
72 
73   struct ogg_reference *next;
74 } ogg_reference;
75 
76 typedef struct oggpack_buffer {
77 #ifdef ARM_LITTLE_ENDIAN
78   int            bitsLeftInSegment;
79   ogg_uint32_t  *ptr;
80   long           bitsLeftInWord;
81 #else
82   int            headbit;
83   unsigned char *headptr;
84   long           headend;
85 #endif /* ARM_LITTLE_ENDIAN */
86   /* memory management */
87   ogg_reference *head;
88   ogg_reference *tail;
89 
90   /* render the byte/bit counter API constant time */
91   long              count; /* doesn't count the tail */
92 } oggpack_buffer;
93 
94 typedef struct oggbyte_buffer {
95   ogg_reference *baseref;
96 
97   ogg_reference *ref;
98   unsigned char *ptr;
99   long           pos;
100   long           end;
101 } oggbyte_buffer;
102 
103 typedef struct ogg_sync_state {
104   /* decode memory management pool */
105   ogg_buffer_state *bufferpool;
106 
107   /* stream buffers */
108   ogg_reference    *fifo_head;
109   ogg_reference    *fifo_tail;
110   long              fifo_fill;
111 
112   /* stream sync management */
113   int               unsynced;
114   int               headerbytes;
115   int               bodybytes;
116 
117 } ogg_sync_state;
118 
119 typedef struct ogg_stream_state {
120   ogg_reference *header_head;
121   ogg_reference *header_tail;
122   ogg_reference *body_head;
123   ogg_reference *body_tail;
124 
125   int            e_o_s;    /* set when we have buffered the last
126                               packet in the logical bitstream */
127   int            b_o_s;    /* set after we've written the initial page
128                               of a logical bitstream */
129   long           serialno;
130   long           pageno;
131   ogg_int64_t    packetno; /* sequence number for decode; the framing
132                               knows where there's a hole in the data,
133                               but we need coupling so that the codec
134                               (which is in a seperate abstraction
135                               layer) also knows about the gap */
136   ogg_int64_t    granulepos;
137 
138   int            lacing_fill;
139   ogg_uint32_t   body_fill;
140 
141   /* decode-side state data */
142   int            holeflag;
143   int            spanflag;
144   int            clearflag;
145   int            laceptr;
146   ogg_uint32_t   body_fill_next;
147 
148 } ogg_stream_state;
149 
150 typedef struct {
151   ogg_reference *packet;
152   long           bytes;
153   long           b_o_s;
154   long           e_o_s;
155   ogg_int64_t    granulepos;
156   ogg_int64_t    packetno;     /* sequence number for decode; the framing
157                                   knows where there's a hole in the data,
158                                   but we need coupling so that the codec
159                                   (which is in a seperate abstraction
160                                   layer) also knows about the gap */
161 } ogg_packet;
162 
163 typedef struct {
164   ogg_reference *header;
165   int            header_len;
166   ogg_reference *body;
167   long           body_len;
168 } ogg_page;
169 
170 /* Ogg BITSTREAM PRIMITIVES: bitstream ************************/
171 
172 extern void  oggpack_readinit(oggpack_buffer *b,ogg_reference *r);
173 extern long  oggpack_look(oggpack_buffer *b,int bits);
174 extern void  oggpack_adv(oggpack_buffer *b,int bits);
175 extern long  oggpack_read(oggpack_buffer *b,int bits);
176 extern long  oggpack_bytes(oggpack_buffer *b);
177 extern long  oggpack_bits(oggpack_buffer *b);
178 extern int   oggpack_eop(oggpack_buffer *b);
179 
180 // Quick hack
181 #define oggpack_bytesleft(B)  (((B)->bitsLeftInSegment+7)/8)
182 
183 /* Ogg BITSTREAM PRIMITIVES: decoding **************************/
184 
185 extern void     ogg_sync_init(ogg_sync_state *oy);
186 extern ogg_sync_state *ogg_sync_create(void);
187 extern int      ogg_sync_clear(ogg_sync_state *oy);
188 extern int      ogg_sync_destroy(ogg_sync_state *oy);
189 extern int      ogg_sync_reset(ogg_sync_state *oy);
190 
191 extern unsigned char *ogg_sync_bufferin(ogg_sync_state *oy, long size);
192 extern int      ogg_sync_wrote(ogg_sync_state *oy, long bytes);
193 extern long     ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
194 extern int      ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
195 extern int      ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
196 extern int      ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
197 extern int      ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
198 
199 /* Ogg BITSTREAM PRIMITIVES: general ***************************/
200 
201 extern void     ogg_stream_init(ogg_stream_state *os, int serialno);
202 extern ogg_stream_state *ogg_stream_create(int serialno);
203 extern int      ogg_stream_destroy(ogg_stream_state *os);
204 extern int      ogg_stream_clear(ogg_stream_state *os);
205 extern int      ogg_stream_reset(ogg_stream_state *os);
206 extern int      ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
207 extern int      ogg_stream_eos(ogg_stream_state *os);
208 
209 extern int      ogg_page_checksum_set(ogg_page *og);
210 
211 extern int      ogg_page_version(ogg_page *og);
212 extern int      ogg_page_continued(ogg_page *og);
213 extern int      ogg_page_bos(ogg_page *og);
214 extern int      ogg_page_eos(ogg_page *og);
215 extern ogg_int64_t  ogg_page_granulepos(ogg_page *og);
216 extern ogg_uint32_t ogg_page_serialno(ogg_page *og);
217 extern ogg_uint32_t ogg_page_pageno(ogg_page *og);
218 extern int      ogg_page_packets(ogg_page *og);
219 extern int      ogg_page_getbuffer(ogg_page *og, unsigned char **buffer);
220 
221 extern int      ogg_packet_release(ogg_packet *op);
222 extern int      ogg_page_release(ogg_page *og);
223 
224 extern void     ogg_page_dup(ogg_page *d, ogg_page *s);
225 
226 /* Ogg BITSTREAM PRIMITIVES: return codes ***************************/
227 
228 #define  OGG_SUCCESS   0
229 
230 #define  OGG_HOLE     -10
231 #define  OGG_SPAN     -11
232 #define  OGG_EVERSION -12
233 #define  OGG_ESERIAL  -13
234 #define  OGG_EINVAL   -14
235 #define  OGG_EEOS     -15
236 
237 
238 #ifdef __cplusplus
239 }
240 #endif
241 
242 #endif  /* _OGG_H */
243