Recognizes if input is ogg or not.
[xiph/unicode.git] / w3d / tarkin.h
blob1b6e291f41e62cb87979a45a6e1a6154e7a5eb3a
1 #ifndef __TARKIN_H
2 #define __TARKIN_H
4 #include <stdio.h>
5 #include "wavelet.h"
6 #include <ogg/ogg.h>
9 /*#define BUG(x...) \
10 do { \
11 printf("BUG in %s (%s: line %i): ", __FUNCTION__, __FILE__, __LINE__); \
12 printf(#x); \
13 printf("\n"); \
14 exit (-1); \
15 } while (0);*/
18 /* Theses determine what infos the packet comes with */
19 #define TARKIN_PACK_EXAMPLE 1
21 typedef struct {
22 uint8_t *data;
23 uint32_t data_len;
24 uint32_t storage;
25 } TarkinPacket;
28 typedef enum {
29 TARKIN_GRAYSCALE,
30 TARKIN_RGB24, /* tight packed RGB */
31 TARKIN_RGB32, /* 32bit, no alphachannel */
32 TARKIN_RGBA, /* dito w/ alphachannel */
33 TARKIN_YUV2, /* 16 bits YUV */
34 TARKIN_YUV12, /* 12 bits YUV */
35 TARKIN_FYUV, /* Tarkin's Fast YUV-like? */
36 } TarkinColorFormat;
38 #define TARKIN_INTERNAL_FORMAT TARKIN_FYUV
40 typedef enum {
41 TARKIN_OK = 0,
42 TARKIN_IO_ERROR,
43 TARKIN_SIGNATURE_NOT_FOUND,
44 TARKIN_INVALID_LAYER,
45 TARKIN_INVALID_COLOR_FORMAT,
46 TARKIN_VERSION,
47 TARKIN_BAD_HEADER,
48 TARKIN_NOT_TARKIN,
49 TARKIN_FAULT,
50 TARKIN_UNUSED,
51 TARKIN_NEED_MORE,
52 TARKIN_NOT_IMPLEMENTED
53 } TarkinError;
57 typedef struct {
58 uint32_t width;
59 uint32_t height;
60 uint32_t a_moments;
61 uint32_t s_moments;
62 uint32_t frames_per_buf;
63 uint32_t bitstream_len; /* for all color components, bytes */
64 TarkinColorFormat format;
65 } TarkinVideoLayerDesc;
68 typedef struct {
69 TarkinVideoLayerDesc desc;
70 uint32_t n_comp; /* number of color components */
71 Wavelet3DBuf **waveletbuf;
72 TarkinPacket *packet;
73 uint32_t current_frame_in_buf;
74 uint32_t frameno;
76 void (*color_fwd_xform) (uint8_t *rgba, Wavelet3DBuf *yuva [], uint32_t count);
77 void (*color_inv_xform) (Wavelet3DBuf *yuva [], uint8_t *rgba, uint32_t count);
78 } TarkinVideoLayer;
80 typedef struct {
81 uint32_t numerator;
82 uint32_t denominator;
83 } TarkinTime; /* Let's say the unit is 1 second */
85 typedef struct TarkinInfo {
86 int version;
87 int n_layers;
88 TarkinVideoLayer *layer;
89 TarkinTime inter; /* numerator == O if per-frame time info. */
90 int frames_per_block;
91 int comp_per_block; /* AKA "packets per block" for now */
92 uint32_t max_bitstream_len;
94 /* The below bitrate declarations are *hints*.
95 Combinations of the three values carry the following implications:
97 all three set to the same value:
98 implies a fixed rate bitstream
99 only nominal set:
100 implies a VBR stream that averages the nominal bitrate. No hard
101 upper/lower limit
102 upper and or lower set:
103 implies a VBR bitstream that obeys the bitrate limits. nominal
104 may also be set to give a nominal rate.
105 none set:
106 the coder does not care to speculate.
109 long bitrate_upper;
110 long bitrate_nominal;
111 long bitrate_lower;
112 long bitrate_window;
113 } TarkinInfo;
115 /* This is used for encoding */
116 typedef struct {
117 unsigned char *header;
118 unsigned char *header1;
119 unsigned char *header2;
120 } tarkin_header_store;
125 /* Some of the fields in TarkinStream are redundent with TarkinInfo ones
126 * and will probably get deleted, namely n_layers and frames_per_buf */
127 typedef struct TarkinStream {
128 uint32_t n_layers;
129 TarkinVideoLayer *layer;
130 uint32_t current_frame;
131 uint32_t current_frame_in_buf;
132 ogg_int64_t packetno;
133 uint32_t frames_per_buf;
134 uint32_t max_bitstream_len;
135 TarkinInfo *ti;
136 tarkin_header_store headers;
137 /* These callbacks are only used for encoding */
138 TarkinError (*free_frame)(void *tarkinstream, void *ptr);
139 /* These thing allows not to buffer but it needs global var in caller. */
140 TarkinError (*packet_out)(void *tarkinstream, ogg_packet *ptr);
141 void * user_ptr;
142 } TarkinStream;
145 typedef struct TarkinComment{
146 /* unlimited user comment fields. libtarkin writes 'libtarkin'
147 whatever vendor is set to in encode */
148 char **user_comments;
149 int *comment_lengths;
150 int comments;
151 char *vendor;
153 } TarkinComment;
155 /* Tarkin PRIMITIVES: general ***************************************/
157 /* The Tarkin header is in three packets, the initial small packet in
158 the first page that identifies basic parameters, that is a TarkinInfo
159 structure, a second packet with bitstream comments and a third packet
160 that holds the layers description structures. */
163 /* Theses are the very same than Vorbis versions, they could be shared. */
164 extern TarkinStream* tarkin_stream_new ();
165 extern void tarkin_stream_destroy (TarkinStream *s);
166 extern void tarkin_info_init(TarkinInfo *vi);
167 extern void tarkin_info_clear(TarkinInfo *vi);
168 extern void tarkin_comment_init(TarkinComment *vc);
169 extern void tarkin_comment_add(TarkinComment *vc, char *comment);
170 extern void tarkin_comment_add_tag(TarkinComment *vc,
171 char *tag, char *contents);
172 extern char *tarkin_comment_query(TarkinComment *vc, char *tag, int count);
173 extern int tarkin_comment_query_count(TarkinComment *vc, char *tag);
174 extern void tarkin_comment_clear(TarkinComment *vc);
176 /* Tarkin PRIMITIVES: analysis layer ****************************/
177 /* Tarkin encoding is done this way : you init it passing a fresh
178 * TarkinStream and a fresh TarkinInfo which has at least the rate_num
179 * field renseigned. You also pass it two callback functions: free_frame()
180 * is called when the lib doesn't need a frame anymore, and packet_out
181 * is called when a packet is ready. The pointers given as arguments to
182 * these callback functions are of course only valid at the function call
183 * time. The user_ptr is stored in s and can be used by packet_out(). */
184 extern int tarkin_analysis_init(TarkinStream *s,
185 TarkinInfo *ti,
186 TarkinError (*free_frame)(void *tarkinstream, void *ptr),
187 TarkinError (*packet_out)(void *tarkinstream, ogg_packet *ptr),
188 void *user_ptr
190 /* Then you need to add at least a layer in your stream, passing a
191 * TarkinVideoLayerDesc renseigned at least on the width, height and
192 * format parameters. */
193 extern int tarkin_analysis_add_layer(TarkinStream *s,
194 TarkinVideoLayerDesc *tvld);
195 /* At that point you are ready to get headers out the lib by calling
196 * tarkin_analysis_headerout() passing it a renseigned TarkinComment
197 * structure. It does fill your 3 ogg_packet headers, which are valid
198 * till next call */
199 extern int TarkinCommentheader_out(TarkinComment *vc, ogg_packet *op);
200 extern TarkinError tarkin_analysis_headerout(TarkinStream *s,
201 TarkinComment *vc,
202 ogg_packet *op,
203 ogg_packet *op_comm,
204 ogg_packet *op_code);
205 /* You are now ready to pass in frames to the codec, however don't free
206 * them before the codec told you so. It'll tell you when packets are
207 * ready to be taken out. When you have no more frame, simply pass NULL.
208 * If you encode multiple layers you have to do it synchronously, putting
209 * one frame from each layer at a time. */
210 extern uint32_t tarkin_analysis_framein(TarkinStream *s,
211 uint8_t *frame, /* NULL for EOS */
212 uint32_t layer,
213 TarkinTime *date);
215 /* Tarkin PRIMITIVES: synthesis layer *******************************/
216 /* For decoding, you needs first to give the three first packet of the
217 * stream to tarkin_synthesis_headerin() which will fill for you blank
218 * TarkinInfo and TarkinComment. */
219 extern TarkinError tarkin_synthesis_headerin(TarkinInfo *vi,TarkinComment *vc,
220 ogg_packet *op);
221 /* Then you can init your stream with your TarkinInfo struct. */
222 extern TarkinError tarkin_synthesis_init(TarkinStream *s,TarkinInfo *ti);
223 /* All subsequent packets are to this be passed to tarkin_synthesis_packetin*/
224 extern TarkinError tarkin_synthesis_packetin(TarkinStream *s, ogg_packet *op);
225 /* and then tarkin_synthesis_frameout gives you ptr on next frame, or NULL. It
226 * also fills for you date. */
227 extern TarkinError tarkin_synthesis_frameout(TarkinStream *s,
228 uint8_t **frame, uint32_t layer_id, TarkinTime *date);
229 /* When you're done with a frame, tell it to the codec with this. */
230 extern int tarkin_synthesis_freeframe(TarkinStream *s, uint8_t *frame);
233 #endif