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: ogg.h 18044 2011-08-01 17:55:20Z gmaxwell $
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 <ogg/os_types.h>
26
27typedef struct {
28 void *iov_base;
29 size_t iov_len;
30} ogg_iovec_t;
31
32typedef struct {
33 long endbyte;
34 int endbit;
35
36 unsigned char *buffer;
37 unsigned char *ptr;
38 long storage;
39} oggpack_buffer;
40
41/* ogg_page is used to encapsulate the data in one Ogg bitstream page *****/
42
43typedef struct {
44 unsigned char *header;
45 long header_len;
46 unsigned char *body;
47 long body_len;
48} ogg_page;
49
50/* ogg_stream_state contains the current encode/decode state of a logical
51 Ogg bitstream **********************************************************/
52
53typedef struct {
54 unsigned char *body_data; /* bytes from packet bodies */
55 long body_storage; /* storage elements allocated */
56 long body_fill; /* elements stored; fill mark */
57 long body_returned; /* elements of fill returned */
58
59
60 int *lacing_vals; /* The values that will go to the segment table */
61 ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
62 this way, but it is simple coupled to the
63 lacing fifo */
64 long lacing_storage;
65 long lacing_fill;
66 long lacing_packet;
67 long lacing_returned;
68
69 unsigned char header[282]; /* working space for header encode */
70 int header_fill;
71
72 int e_o_s; /* set when we have buffered the last packet in the
73 logical bitstream */
74 int b_o_s; /* set after we've written the initial page
75 of a logical bitstream */
76 long serialno;
77 long pageno;
78 ogg_int64_t packetno; /* sequence number for decode; the framing
79 knows where there's a hole in the data,
80 but we need coupling so that the codec
81 (which is in a separate abstraction
82 layer) also knows about the gap */
83 ogg_int64_t granulepos;
84
85} ogg_stream_state;
86
87/* ogg_packet is used to encapsulate the data and metadata belonging
88 to a single raw Ogg/Vorbis packet *************************************/
89
90typedef struct {
91 unsigned char *packet;
92 long bytes;
93 long b_o_s;
94 long e_o_s;
95
96 ogg_int64_t granulepos;
97
98 ogg_int64_t packetno; /* sequence number for decode; the framing
99 knows where there's a hole in the data,
100 but we need coupling so that the codec
101 (which is in a separate abstraction
102 layer) also knows about the gap */
103} ogg_packet;
104
105typedef struct {
106 unsigned char *data;
107 int storage;
108 int fill;
109 int returned;
110
111 int unsynced;
112 int headerbytes;
113 int bodybytes;
114} ogg_sync_state;
115
116/* Ogg BITSTREAM PRIMITIVES: bitstream ************************/
117
118extern void oggpack_writeinit(oggpack_buffer *b);
119extern int oggpack_writecheck(oggpack_buffer *b);
120extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
121extern void oggpack_writealign(oggpack_buffer *b);
122extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
123extern void oggpack_reset(oggpack_buffer *b);
124extern void oggpack_writeclear(oggpack_buffer *b);
125extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
126extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
127extern long oggpack_look(oggpack_buffer *b,int bits);
128extern long oggpack_look1(oggpack_buffer *b);
129extern void oggpack_adv(oggpack_buffer *b,int bits);
130extern void oggpack_adv1(oggpack_buffer *b);
131extern long oggpack_read(oggpack_buffer *b,int bits);
132extern long oggpack_read1(oggpack_buffer *b);
133extern long oggpack_bytes(oggpack_buffer *b);
134extern long oggpack_bits(oggpack_buffer *b);
135extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
136
137extern void oggpackB_writeinit(oggpack_buffer *b);
138extern int oggpackB_writecheck(oggpack_buffer *b);
139extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
140extern void oggpackB_writealign(oggpack_buffer *b);
141extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
142extern void oggpackB_reset(oggpack_buffer *b);
143extern void oggpackB_writeclear(oggpack_buffer *b);
144extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
145extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
146extern long oggpackB_look(oggpack_buffer *b,int bits);
147extern long oggpackB_look1(oggpack_buffer *b);
148extern void oggpackB_adv(oggpack_buffer *b,int bits);
149extern void oggpackB_adv1(oggpack_buffer *b);
150extern long oggpackB_read(oggpack_buffer *b,int bits);
151extern long oggpackB_read1(oggpack_buffer *b);
152extern long oggpackB_bytes(oggpack_buffer *b);
153extern long oggpackB_bits(oggpack_buffer *b);
154extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
155
156/* Ogg BITSTREAM PRIMITIVES: encoding **************************/
157
158extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
159extern int ogg_stream_iovecin(ogg_stream_state *os, ogg_iovec_t *iov,
160 int count, long e_o_s, ogg_int64_t granulepos);
161extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
162extern int ogg_stream_pageout_fill(ogg_stream_state *os, ogg_page *og, int nfill);
163extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
164extern int ogg_stream_flush_fill(ogg_stream_state *os, ogg_page *og, int nfill);
165
166/* Ogg BITSTREAM PRIMITIVES: decoding **************************/
167
168extern int ogg_sync_init(ogg_sync_state *oy);
169extern int ogg_sync_clear(ogg_sync_state *oy);
170extern int ogg_sync_reset(ogg_sync_state *oy);
171extern int ogg_sync_destroy(ogg_sync_state *oy);
172extern int ogg_sync_check(ogg_sync_state *oy);
173
174extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
175extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
176extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
177extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
178extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
179extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
180extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
181
182/* Ogg BITSTREAM PRIMITIVES: general ***************************/
183
184extern int ogg_stream_init(ogg_stream_state *os,int serialno);
185extern int ogg_stream_clear(ogg_stream_state *os);
186extern int ogg_stream_reset(ogg_stream_state *os);
187extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
188extern int ogg_stream_destroy(ogg_stream_state *os);
189extern int ogg_stream_check(ogg_stream_state *os);
190extern int ogg_stream_eos(ogg_stream_state *os);
191
192extern void ogg_page_checksum_set(ogg_page *og);
193
194extern int ogg_page_version(const ogg_page *og);
195extern int ogg_page_continued(const ogg_page *og);
196extern int ogg_page_bos(const ogg_page *og);
197extern int ogg_page_eos(const ogg_page *og);
198extern ogg_int64_t ogg_page_granulepos(const ogg_page *og);
199extern int ogg_page_serialno(const ogg_page *og);
200extern long ogg_page_pageno(const ogg_page *og);
201extern int ogg_page_packets(const ogg_page *og);
202
203extern void ogg_packet_clear(ogg_packet *op);
204
205
206#ifdef __cplusplus
207}
208#endif
209
210#endif /* _OGG_H */
211