blob: 7f35bd4f0f8a8e9a809e2d07873d3e62653e0b5d [file] [log] [blame]
Gloria Wang37fe1582010-03-12 14:53:20 -08001/************************************************************************
Gloria Wang2da723a2010-03-18 15:56:16 -07002 * Copyright (C) 2002-2009, Xiph.org Foundation
3 * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
Gloria Wang37fe1582010-03-12 14:53:20 -08004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
Gloria Wang2da723a2010-03-18 15:56:16 -07007 * modification, are permitted provided that the following conditions
8 * are met:
Gloria Wang37fe1582010-03-12 14:53:20 -08009 *
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.
Gloria Wang2da723a2010-03-18 15:56:16 -070016 * * 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.
Gloria Wang37fe1582010-03-12 14:53:20 -080020 *
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 ************************************************************************
Gloria Wang79130732010-02-08 14:41:04 -080033
34 function: subsumed libogg includes
35
Gloria Wang37fe1582010-03-12 14:53:20 -080036 ************************************************************************/
Gloria Wang79130732010-02-08 14:41:04 -080037#ifndef _OGG_H
38#define _OGG_H
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44#include "os_types.h"
45
46#ifndef ONLY_C
47#define ARM_LITTLE_ENDIAN
48#endif
49
50typedef 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
57typedef 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
68typedef struct ogg_reference {
69 ogg_buffer *buffer;
70 long begin;
71 long length;
72
73 struct ogg_reference *next;
74} ogg_reference;
75
76typedef 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
94typedef 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
103typedef 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
119typedef 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
150typedef 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
163typedef 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
172extern void oggpack_readinit(oggpack_buffer *b,ogg_reference *r);
173extern long oggpack_look(oggpack_buffer *b,int bits);
174extern void oggpack_adv(oggpack_buffer *b,int bits);
175extern long oggpack_read(oggpack_buffer *b,int bits);
176extern long oggpack_bytes(oggpack_buffer *b);
177extern long oggpack_bits(oggpack_buffer *b);
178extern 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
185extern void ogg_sync_init(ogg_sync_state *oy);
186extern ogg_sync_state *ogg_sync_create(void);
187extern int ogg_sync_clear(ogg_sync_state *oy);
188extern int ogg_sync_destroy(ogg_sync_state *oy);
189extern int ogg_sync_reset(ogg_sync_state *oy);
190
191extern unsigned char *ogg_sync_bufferin(ogg_sync_state *oy, long size);
192extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
193extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
194extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
195extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
196extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
197extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
198
199/* Ogg BITSTREAM PRIMITIVES: general ***************************/
200
201extern void ogg_stream_init(ogg_stream_state *os, int serialno);
202extern ogg_stream_state *ogg_stream_create(int serialno);
203extern int ogg_stream_destroy(ogg_stream_state *os);
204extern int ogg_stream_clear(ogg_stream_state *os);
205extern int ogg_stream_reset(ogg_stream_state *os);
206extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
207extern int ogg_stream_eos(ogg_stream_state *os);
208
209extern int ogg_page_checksum_set(ogg_page *og);
210
211extern int ogg_page_version(ogg_page *og);
212extern int ogg_page_continued(ogg_page *og);
213extern int ogg_page_bos(ogg_page *og);
214extern int ogg_page_eos(ogg_page *og);
215extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
216extern ogg_uint32_t ogg_page_serialno(ogg_page *og);
217extern ogg_uint32_t ogg_page_pageno(ogg_page *og);
218extern int ogg_page_packets(ogg_page *og);
219extern int ogg_page_getbuffer(ogg_page *og, unsigned char **buffer);
220
221extern int ogg_packet_release(ogg_packet *op);
222extern int ogg_page_release(ogg_page *og);
223
224extern 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 */