11 printf("BUG in %s (%s: line %i): ", __FUNCTION__, __FILE__, __LINE__); \
18 /* Theses determine what infos the packet comes with */
19 #define TARKIN_PACK_EXAMPLE 1
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? */
38 #define TARKIN_INTERNAL_FORMAT TARKIN_FYUV
43 TARKIN_SIGNATURE_NOT_FOUND
,
45 TARKIN_INVALID_COLOR_FORMAT
,
52 TARKIN_NOT_IMPLEMENTED
62 uint32_t frames_per_buf
;
63 uint32_t bitstream_len
; /* for all color components, bytes */
64 TarkinColorFormat format
;
65 } TarkinVideoLayerDesc
;
69 TarkinVideoLayerDesc desc
;
70 uint32_t n_comp
; /* number of color components */
71 Wavelet3DBuf
**waveletbuf
;
73 uint32_t current_frame_in_buf
;
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
);
83 } TarkinTime
; /* Let's say the unit is 1 second */
85 typedef struct TarkinInfo
{
88 TarkinVideoLayer
*layer
;
89 TarkinTime inter
; /* numerator == O if per-frame time info. */
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
100 implies a VBR stream that averages the nominal bitrate. No hard
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.
106 the coder does not care to speculate.
110 long bitrate_nominal
;
115 /* This is used for encoding */
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
{
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
;
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
);
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
;
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
,
186 TarkinError (*free_frame
)(void *tarkinstream
, void *ptr
),
187 TarkinError (*packet_out
)(void *tarkinstream
, ogg_packet
*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
199 extern int TarkinCommentheader_out(TarkinComment
*vc
, ogg_packet
*op
);
200 extern TarkinError
tarkin_analysis_headerout(TarkinStream
*s
,
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 */
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
,
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
);