annotate tremor/ogg.h @ 14471:6cdd5669e930

Here is an updated draft with the bits discussed previously merged: - short startcode removed - QT/Microsoft codec_specific_data removed, reverted to a neutral format - meta packet removed, merged in the info packet. - stream class simplified, added metadata stream patch by (Luca Barbato <lu_zero gentoo org>)
author michael
date Wed, 12 Jan 2005 11:54:30 +0000
parents 8631a3803289
children e891ff7a7b6c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
1 /********************************************************************
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
2 * *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
3 * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
4 * *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
5 * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
6 * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
7 * ALL REDISTRIBUTION RIGHTS RESERVED. *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
8 * *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
9 ********************************************************************
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
10
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
11 function: subsumed libogg includes
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
12
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
13 ********************************************************************/
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
14 #ifndef _OGG_H
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
15 #define _OGG_H
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
16
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
17 #ifdef __cplusplus
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
18 extern "C" {
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
19 #endif
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
20
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
21 #include "os_types.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
22
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
23 typedef struct {
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
24 long endbyte;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
25 int endbit;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
26
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
27 unsigned char *buffer;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
28 unsigned char *ptr;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
29 long storage;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
30 } oggpack_buffer;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
31
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
32 /* ogg_page is used to encapsulate the data in one Ogg bitstream page *****/
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
33
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
34 typedef struct {
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
35 unsigned char *header;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
36 long header_len;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
37 unsigned char *body;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
38 long body_len;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
39 } ogg_page;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
40
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
41 /* ogg_stream_state contains the current encode/decode state of a logical
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
42 Ogg bitstream **********************************************************/
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
43
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
44 typedef struct {
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
45 unsigned char *body_data; /* bytes from packet bodies */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
46 long body_storage; /* storage elements allocated */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
47 long body_fill; /* elements stored; fill mark */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
48 long body_returned; /* elements of fill returned */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
49
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
50
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
51 int *lacing_vals; /* The values that will go to the segment table */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
52 ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
53 this way, but it is simple coupled to the
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
54 lacing fifo */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
55 long lacing_storage;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
56 long lacing_fill;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
57 long lacing_packet;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
58 long lacing_returned;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
59
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
60 unsigned char header[282]; /* working space for header encode */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
61 int header_fill;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
62
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
63 int e_o_s; /* set when we have buffered the last packet in the
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
64 logical bitstream */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
65 int b_o_s; /* set after we've written the initial page
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
66 of a logical bitstream */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
67 long serialno;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
68 long pageno;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
69 ogg_int64_t packetno; /* sequence number for decode; the framing
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
70 knows where there's a hole in the data,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
71 but we need coupling so that the codec
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
72 (which is in a seperate abstraction
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
73 layer) also knows about the gap */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
74 ogg_int64_t granulepos;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
75
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
76 } ogg_stream_state;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
77
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
78 /* ogg_packet is used to encapsulate the data and metadata belonging
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
79 to a single raw Ogg/Vorbis packet *************************************/
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
80
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
81 typedef struct {
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
82 unsigned char *packet;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
83 long bytes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
84 long b_o_s;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
85 long e_o_s;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
86
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
87 ogg_int64_t granulepos;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
88
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
89 ogg_int64_t packetno; /* sequence number for decode; the framing
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
90 knows where there's a hole in the data,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
91 but we need coupling so that the codec
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
92 (which is in a seperate abstraction
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
93 layer) also knows about the gap */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
94 } ogg_packet;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
95
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
96 typedef struct {
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
97 unsigned char *data;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
98 int storage;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
99 int fill;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
100 int returned;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
101
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
102 int unsynced;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
103 int headerbytes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
104 int bodybytes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
105 } ogg_sync_state;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
106
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
107 /* Ogg BITSTREAM PRIMITIVES: bitstream ************************/
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
108
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
109 extern void oggpack_writeinit(oggpack_buffer *b);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
110 extern void oggpack_reset(oggpack_buffer *b);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
111 extern void oggpack_writeclear(oggpack_buffer *b);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
112 extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
113 extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
114 extern long oggpack_look(oggpack_buffer *b,int bits);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
115 extern long oggpack_look_huff(oggpack_buffer *b,int bits);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
116 extern long oggpack_look1(oggpack_buffer *b);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
117 extern void oggpack_adv(oggpack_buffer *b,int bits);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
118 extern int oggpack_adv_huff(oggpack_buffer *b,int bits);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
119 extern void oggpack_adv1(oggpack_buffer *b);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
120 extern long oggpack_read(oggpack_buffer *b,int bits);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
121 extern long oggpack_read1(oggpack_buffer *b);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
122 extern long oggpack_bytes(oggpack_buffer *b);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
123 extern long oggpack_bits(oggpack_buffer *b);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
124 extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
125
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
126 /* Ogg BITSTREAM PRIMITIVES: decoding **************************/
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
127
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
128 extern int ogg_sync_init(ogg_sync_state *oy);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
129 extern int ogg_sync_clear(ogg_sync_state *oy);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
130 extern int ogg_sync_reset(ogg_sync_state *oy);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
131 extern int ogg_sync_destroy(ogg_sync_state *oy);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
132
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
133 extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
134 extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
135 extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
136 extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
137 extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
138 extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
139 extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
140
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
141 /* Ogg BITSTREAM PRIMITIVES: general ***************************/
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
142
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
143 extern int ogg_stream_init(ogg_stream_state *os,int serialno);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
144 extern int ogg_stream_clear(ogg_stream_state *os);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
145 extern int ogg_stream_reset(ogg_stream_state *os);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
146 extern int ogg_stream_destroy(ogg_stream_state *os);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
147 extern int ogg_stream_eos(ogg_stream_state *os);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
148
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
149 extern void ogg_page_checksum_set(ogg_page *og);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
150
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
151 extern int ogg_page_version(ogg_page *og);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
152 extern int ogg_page_continued(ogg_page *og);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
153 extern int ogg_page_bos(ogg_page *og);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
154 extern int ogg_page_eos(ogg_page *og);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
155 extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
156 extern int ogg_page_serialno(ogg_page *og);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
157 extern long ogg_page_pageno(ogg_page *og);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
158 extern int ogg_page_packets(ogg_page *og);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
159
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
160 extern void ogg_packet_clear(ogg_packet *op);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
161
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
162
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
163 #ifdef __cplusplus
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
164 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
165 #endif
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
166
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
167 #endif /* _OGG_H */