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