1 | /******************************************************************** |
2 | * * |
3 | * THIS FILE IS PART OF THE OggTheora 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 Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 * |
9 | * by the Xiph.Org Foundation http://www.xiph.org/ * |
10 | * * |
11 | ******************************************************************** |
12 | |
13 | function: |
14 | last mod: $Id: theora.h,v 1.8 2004/03/15 22:17:32 derf Exp $ |
15 | |
16 | ********************************************************************/ |
17 | |
18 | /**\mainpage |
19 | * |
20 | * \section intro Introduction |
21 | * |
22 | * This is the documentation for the <tt>libtheora</tt> C API. |
23 | * |
24 | * The \c libtheora package is the current reference |
25 | * implementation for <a href="http://www.theora.org/">Theora</a>, a free, |
26 | * patent-unencumbered video codec. |
27 | * Theora is derived from On2's VP3 codec with additional features and |
28 | * integration with Ogg multimedia formats by |
29 | * <a href="http://www.xiph.org/">the Xiph.Org Foundation</a>. |
30 | * Complete documentation of the format itself is available in |
31 | * <a href="http://www.theora.org/doc/Theora.pdf">the Theora |
32 | * specification</a>. |
33 | * |
34 | * \section Organization |
35 | * |
36 | * The functions documented here are divided between two |
37 | * separate libraries: |
38 | * - \c libtheoraenc contains the encoder interface, |
39 | * described in \ref encfuncs. |
40 | * - \c libtheoradec contains the decoder interface, |
41 | * described in \ref decfuncs, \n |
42 | * and additional \ref basefuncs. |
43 | * |
44 | * New code should link to \c libtheoradec. If using encoder |
45 | * features, it must also link to \c libtheoraenc. |
46 | * |
47 | * During initial development, prior to the 1.0 release, |
48 | * \c libtheora exported a different \ref oldfuncs which |
49 | * combined both encode and decode functions. |
50 | * In general, legacy API symbols can be indentified |
51 | * by their \c theora_ or \c OC_ namespace prefixes. |
52 | * The current API uses \c th_ or \c TH_ instead. |
53 | * |
54 | * While deprecated, \c libtheoraenc and \c libtheoradec |
55 | * together export the legacy api as well at the one documented above. |
56 | * Likewise, the legacy \c libtheora included with this package |
57 | * exports the new 1.x API. Older code and build scripts can therefore |
58 | * but updated independently to the current scheme. |
59 | */ |
60 | |
61 | /**\file |
62 | * The shared <tt>libtheoradec</tt> and <tt>libtheoraenc</tt> C API. |
63 | * You don't need to include this directly.*/ |
64 | |
65 | #if !defined(_O_THEORA_CODEC_H_) |
66 | # define _O_THEORA_CODEC_H_ (1) |
67 | # include <ogg/ogg.h> |
68 | |
69 | #if defined(__cplusplus) |
70 | extern "C" { |
71 | #endif |
72 | |
73 | |
74 | |
75 | /**\name Return codes*/ |
76 | /*@{*/ |
77 | /**An invalid pointer was provided.*/ |
78 | #define TH_EFAULT (-1) |
79 | /**An invalid argument was provided.*/ |
80 | #define TH_EINVAL (-10) |
81 | /**The contents of the header were incomplete, invalid, or unexpected.*/ |
82 | #define (-20) |
83 | /**The header does not belong to a Theora stream.*/ |
84 | #define TH_ENOTFORMAT (-21) |
85 | /**The bitstream version is too high.*/ |
86 | #define TH_EVERSION (-22) |
87 | /**The specified function is not implemented.*/ |
88 | #define TH_EIMPL (-23) |
89 | /**There were errors in the video data packet.*/ |
90 | #define TH_EBADPACKET (-24) |
91 | /**The decoded packet represented a dropped frame. |
92 | The player can continue to display the current frame, as the contents of the |
93 | decoded frame buffer have not changed.*/ |
94 | #define TH_DUPFRAME (1) |
95 | /*@}*/ |
96 | |
97 | /**The currently defined color space tags. |
98 | * See <a href="http://www.theora.org/doc/Theora.pdf">the Theora |
99 | * specification</a>, Chapter 4, for exact details on the meaning |
100 | * of each of these color spaces.*/ |
101 | typedef enum{ |
102 | /**The color space was not specified at the encoder. |
103 | It may be conveyed by an external means.*/ |
104 | TH_CS_UNSPECIFIED, |
105 | /**A color space designed for NTSC content.*/ |
106 | TH_CS_ITU_REC_470M, |
107 | /**A color space designed for PAL/SECAM content.*/ |
108 | TH_CS_ITU_REC_470BG, |
109 | /**The total number of currently defined color spaces.*/ |
110 | TH_CS_NSPACES |
111 | }th_colorspace; |
112 | |
113 | /**The currently defined pixel format tags. |
114 | * See <a href="http://www.theora.org/doc/Theora.pdf">the Theora |
115 | * specification</a>, Section 4.4, for details on the precise sample |
116 | * locations.*/ |
117 | typedef enum{ |
118 | /**Chroma decimation by 2 in both the X and Y directions (4:2:0). |
119 | The Cb and Cr chroma planes are half the width and half the |
120 | height of the luma plane.*/ |
121 | TH_PF_420, |
122 | /**Currently reserved.*/ |
123 | TH_PF_RSVD, |
124 | /**Chroma decimation by 2 in the X direction (4:2:2). |
125 | The Cb and Cr chroma planes are half the width of the luma plane, but full |
126 | height.*/ |
127 | TH_PF_422, |
128 | /**No chroma decimation (4:4:4). |
129 | The Cb and Cr chroma planes are full width and full height.*/ |
130 | TH_PF_444, |
131 | /**The total number of currently defined pixel formats.*/ |
132 | TH_PF_NFORMATS |
133 | }th_pixel_fmt; |
134 | |
135 | |
136 | |
137 | /**A buffer for a single color plane in an uncompressed image. |
138 | * This contains the image data in a left-to-right, top-down format. |
139 | * Each row of pixels is stored contiguously in memory, but successive |
140 | * rows need not be. |
141 | * Use \a stride to compute the offset of the next row. |
142 | * The encoder accepts both positive \a stride values (top-down in memory) |
143 | * and negative (bottom-up in memory). |
144 | * The decoder currently always generates images with positive strides.*/ |
145 | typedef struct{ |
146 | /**The width of this plane.*/ |
147 | int width; |
148 | /**The height of this plane.*/ |
149 | int height; |
150 | /**The offset in bytes between successive rows.*/ |
151 | int stride; |
152 | /**A pointer to the beginning of the first row.*/ |
153 | unsigned char *data; |
154 | }th_img_plane; |
155 | |
156 | /**A complete image buffer for an uncompressed frame. |
157 | * The chroma planes may be decimated by a factor of two in either |
158 | * direction, as indicated by th_info#pixel_fmt. |
159 | * The width and height of the Y' plane must be multiples of 16. |
160 | * They may need to be cropped for display, using the rectangle |
161 | * specified by th_info#pic_x, th_info#pic_y, th_info#pic_width, |
162 | * and th_info#pic_height. |
163 | * All samples are 8 bits. |
164 | * \note The term YUV often used to describe a colorspace is ambiguous. |
165 | * The exact parameters of the RGB to YUV conversion process aside, in |
166 | * many contexts the U and V channels actually have opposite meanings. |
167 | * To avoid this confusion, we are explicit: the name of the color |
168 | * channels are Y'CbCr, and they appear in that order, always. |
169 | * The prime symbol denotes that the Y channel is non-linear. |
170 | * Cb and Cr stand for "Chroma blue" and "Chroma red", respectively.*/ |
171 | typedef th_img_plane th_ycbcr_buffer[3]; |
172 | |
173 | /**Theora bitstream information. |
174 | * This contains the basic playback parameters for a stream, and corresponds to |
175 | * the initial 'info' header packet. |
176 | * To initialize an encoder, the application fills in this structure and |
177 | * passes it to th_encode_alloc(). |
178 | * A default encoding mode is chosen based on the values of the #quality and |
179 | * #target_bitrate fields. |
180 | * On decode, it is filled in by th_decode_headerin(), and then passed to |
181 | * th_decode_alloc(). |
182 | * |
183 | * Encoded Theora frames must be a multiple of 16 in size; |
184 | * this is what the #frame_width and #frame_height members represent. |
185 | * To handle arbitrary picture sizes, a crop rectangle is specified in the |
186 | * #pic_x, #pic_y, #pic_width and #pic_height members. |
187 | * |
188 | * All frame buffers contain pointers to the full, padded frame. |
189 | * However, the current encoder <em>will not</em> reference pixels outside of |
190 | * the cropped picture region, and the application does not need to fill them |
191 | * in. |
192 | * The decoder <em>will</em> allocate storage for a full frame, but the |
193 | * application <em>should not</em> rely on the padding containing sensible |
194 | * data. |
195 | * |
196 | * It is also generally recommended that the offsets and sizes should still be |
197 | * multiples of 2 to avoid chroma sampling shifts when chroma is sub-sampled. |
198 | * See <a href="http://www.theora.org/doc/Theora.pdf">the Theora |
199 | * specification</a>, Section 4.4, for more details. |
200 | * |
201 | * Frame rate, in frames per second, is stored as a rational fraction, as is |
202 | * the pixel aspect ratio. |
203 | * Note that this refers to the aspect ratio of the individual pixels, not of |
204 | * the overall frame itself. |
205 | * The frame aspect ratio can be computed from pixel aspect ratio using the |
206 | * image dimensions.*/ |
207 | typedef struct{ |
208 | /**\name Theora version |
209 | * Bitstream version information.*/ |
210 | /*@{*/ |
211 | unsigned char version_major; |
212 | unsigned char version_minor; |
213 | unsigned char version_subminor; |
214 | /*@}*/ |
215 | /**The encoded frame width. |
216 | * This must be a multiple of 16, and less than 1048576.*/ |
217 | ogg_uint32_t frame_width; |
218 | /**The encoded frame height. |
219 | * This must be a multiple of 16, and less than 1048576.*/ |
220 | ogg_uint32_t frame_height; |
221 | /**The displayed picture width. |
222 | * This must be no larger than width.*/ |
223 | ogg_uint32_t pic_width; |
224 | /**The displayed picture height. |
225 | * This must be no larger than height.*/ |
226 | ogg_uint32_t pic_height; |
227 | /**The X offset of the displayed picture. |
228 | * This must be no larger than #frame_width-#pic_width or 255, whichever is |
229 | * smaller.*/ |
230 | ogg_uint32_t pic_x; |
231 | /**The Y offset of the displayed picture. |
232 | * This must be no larger than #frame_height-#pic_height, and |
233 | * #frame_height-#pic_height-#pic_y must be no larger than 255. |
234 | * This slightly funny restriction is due to the fact that the offset is |
235 | * specified from the top of the image for consistency with the standard |
236 | * graphics left-handed coordinate system used throughout this API, while |
237 | * it is stored in the encoded stream as an offset from the bottom.*/ |
238 | ogg_uint32_t pic_y; |
239 | /**\name Frame rate |
240 | * The frame rate, as a fraction. |
241 | * If either is 0, the frame rate is undefined.*/ |
242 | /*@{*/ |
243 | ogg_uint32_t fps_numerator; |
244 | ogg_uint32_t fps_denominator; |
245 | /*@}*/ |
246 | /**\name Aspect ratio |
247 | * The aspect ratio of the pixels. |
248 | * If either value is zero, the aspect ratio is undefined. |
249 | * If not specified by any external means, 1:1 should be assumed. |
250 | * The aspect ratio of the full picture can be computed as |
251 | * \code |
252 | * aspect_numerator*pic_width/(aspect_denominator*pic_height). |
253 | * \endcode */ |
254 | /*@{*/ |
255 | ogg_uint32_t aspect_numerator; |
256 | ogg_uint32_t aspect_denominator; |
257 | /*@}*/ |
258 | /**The color space.*/ |
259 | th_colorspace colorspace; |
260 | /**The pixel format.*/ |
261 | th_pixel_fmt pixel_fmt; |
262 | /**The target bit-rate in bits per second. |
263 | If initializing an encoder with this struct, set this field to a non-zero |
264 | value to activate CBR encoding by default.*/ |
265 | int target_bitrate; |
266 | /**The target quality level. |
267 | Valid values range from 0 to 63, inclusive, with higher values giving |
268 | higher quality. |
269 | If initializing an encoder with this struct, and #target_bitrate is set |
270 | to zero, VBR encoding at this quality will be activated by default.*/ |
271 | /*Currently this is set so that a qi of 0 corresponds to distortions of 24 |
272 | times the JND, and each increase by 16 halves that value. |
273 | This gives us fine discrimination at low qualities, yet effective rate |
274 | control at high qualities. |
275 | The qi value 63 is special, however. |
276 | For this, the highest quality, we use one half of a JND for our threshold. |
277 | Due to the lower bounds placed on allowable quantizers in Theora, we will |
278 | not actually be able to achieve quality this good, but this should |
279 | provide as close to visually lossless quality as Theora is capable of. |
280 | We could lift the quantizer restrictions without breaking VP3.1 |
281 | compatibility, but this would result in quantized coefficients that are |
282 | too large for the current bitstream to be able to store. |
283 | We'd have to redesign the token syntax to store these large coefficients, |
284 | which would make transcoding complex.*/ |
285 | int quality; |
286 | /**The amount to shift to extract the last keyframe number from the granule |
287 | * position. |
288 | * This can be at most 31. |
289 | * th_info_init() will set this to a default value (currently <tt>6</tt>, |
290 | * which is good for streaming applications), but you can set it to 0 to |
291 | * make every frame a keyframe. |
292 | * The maximum distance between key frames is |
293 | * <tt>1<<#keyframe_granule_shift</tt>. |
294 | * The keyframe frequency can be more finely controlled with |
295 | * #TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE, which can also be adjusted |
296 | * during encoding (for example, to force the next frame to be a keyframe), |
297 | * but it cannot be set larger than the amount permitted by this field after |
298 | * the headers have been output.*/ |
299 | int keyframe_granule_shift; |
300 | }th_info; |
301 | |
302 | /**The comment information. |
303 | * |
304 | * This structure holds the in-stream metadata corresponding to |
305 | * the 'comment' header packet. |
306 | * The comment header is meant to be used much like someone jotting a quick |
307 | * note on the label of a video. |
308 | * It should be a short, to the point text note that can be more than a couple |
309 | * words, but not more than a short paragraph. |
310 | * |
311 | * The metadata is stored as a series of (tag, value) pairs, in |
312 | * length-encoded string vectors. |
313 | * The first occurrence of the '=' character delimits the tag and value. |
314 | * A particular tag may occur more than once, and order is significant. |
315 | * The character set encoding for the strings is always UTF-8, but the tag |
316 | * names are limited to ASCII, and treated as case-insensitive. |
317 | * See <a href="http://www.theora.org/doc/Theora.pdf">the Theora |
318 | * specification</a>, Section 6.3.3 for details. |
319 | * |
320 | * In filling in this structure, th_decode_headerin() will null-terminate |
321 | * the user_comment strings for safety. |
322 | * However, the bitstream format itself treats them as 8-bit clean vectors, |
323 | * possibly containing null characters, so the length array should be |
324 | * treated as their authoritative length. |
325 | */ |
326 | typedef struct { |
327 | /**The array of comment string vectors.*/ |
328 | char **; |
329 | /**An array of the corresponding length of each vector, in bytes.*/ |
330 | int *; |
331 | /**The total number of comment strings.*/ |
332 | int ; |
333 | /**The null-terminated vendor string. |
334 | This identifies the software used to encode the stream.*/ |
335 | char *; |
336 | }; |
337 | |
338 | |
339 | |
340 | /**A single base matrix.*/ |
341 | typedef unsigned char th_quant_base[64]; |
342 | |
343 | /**A set of \a qi ranges.*/ |
344 | typedef struct{ |
345 | /**The number of ranges in the set.*/ |
346 | int nranges; |
347 | /**The size of each of the #nranges ranges. |
348 | These must sum to 63.*/ |
349 | const int *sizes; |
350 | /**#nranges <tt>+1</tt> base matrices. |
351 | Matrices \a i and <tt>i+1</tt> form the endpoints of range \a i.*/ |
352 | const th_quant_base *base_matrices; |
353 | }th_quant_ranges; |
354 | |
355 | /**A complete set of quantization parameters. |
356 | The quantizer for each coefficient is calculated as: |
357 | \code |
358 | Q=MAX(MIN(qmin[qti][ci!=0],scale[ci!=0][qi]*base[qti][pli][qi][ci]/100), |
359 | 1024). |
360 | \endcode |
361 | |
362 | \a qti is the quantization type index: 0 for intra, 1 for inter. |
363 | <tt>ci!=0</tt> is 0 for the DC coefficient and 1 for AC coefficients. |
364 | \a qi is the quality index, ranging between 0 (low quality) and 63 (high |
365 | quality). |
366 | \a pli is the color plane index: 0 for Y', 1 for Cb, 2 for Cr. |
367 | \a ci is the DCT coefficient index. |
368 | Coefficient indices correspond to the normal 2D DCT block |
369 | ordering--row-major with low frequencies first--\em not zig-zag order. |
370 | |
371 | Minimum quantizers are constant, and are given by: |
372 | \code |
373 | qmin[2][2]={{4,2},{8,4}}. |
374 | \endcode |
375 | |
376 | Parameters that can be stored in the bitstream are as follows: |
377 | - The two scale matrices ac_scale and dc_scale. |
378 | \code |
379 | scale[2][64]={dc_scale,ac_scale}. |
380 | \endcode |
381 | - The base matrices for each \a qi, \a qti and \a pli (up to 384 in all). |
382 | In order to avoid storing a full 384 base matrices, only a sparse set of |
383 | matrices are stored, and the rest are linearly interpolated. |
384 | This is done as follows. |
385 | For each \a qti and \a pli, a series of \a n \a qi ranges is defined. |
386 | The size of each \a qi range can vary arbitrarily, but they must sum to |
387 | 63. |
388 | Then, <tt>n+1</tt> matrices are specified, one for each endpoint of the |
389 | ranges. |
390 | For interpolation purposes, each range's endpoints are the first \a qi |
391 | value it contains and one past the last \a qi value it contains. |
392 | Fractional values are rounded to the nearest integer, with ties rounded |
393 | away from zero. |
394 | |
395 | Base matrices are stored by reference, so if the same matrices are used |
396 | multiple times, they will only appear once in the bitstream. |
397 | The bitstream is also capable of omitting an entire set of ranges and |
398 | its associated matrices if they are the same as either the previous |
399 | set (indexed in row-major order) or if the inter set is the same as the |
400 | intra set. |
401 | |
402 | - Loop filter limit values. |
403 | The same limits are used for the loop filter in all color planes, despite |
404 | potentially differing levels of quantization in each. |
405 | |
406 | For the current encoder, <tt>scale[ci!=0][qi]</tt> must be no greater |
407 | than <tt>scale[ci!=0][qi-1]</tt> and <tt>base[qti][pli][qi][ci]</tt> must |
408 | be no greater than <tt>base[qti][pli][qi-1][ci]</tt>. |
409 | These two conditions ensure that the actual quantizer for a given \a qti, |
410 | \a pli, and \a ci does not increase as \a qi increases. |
411 | This is not required by the decoder.*/ |
412 | typedef struct{ |
413 | /**The DC scaling factors.*/ |
414 | ogg_uint16_t dc_scale[64]; |
415 | /**The AC scaling factors.*/ |
416 | ogg_uint16_t ac_scale[64]; |
417 | /**The loop filter limit values.*/ |
418 | unsigned char loop_filter_limits[64]; |
419 | /**The \a qi ranges for each \a ci and \a pli.*/ |
420 | th_quant_ranges qi_ranges[2][3]; |
421 | }th_quant_info; |
422 | |
423 | |
424 | |
425 | /**The number of Huffman tables used by Theora.*/ |
426 | #define TH_NHUFFMAN_TABLES (80) |
427 | /**The number of DCT token values in each table.*/ |
428 | #define TH_NDCT_TOKENS (32) |
429 | |
430 | /**A Huffman code for a Theora DCT token. |
431 | * Each set of Huffman codes in a given table must form a complete, prefix-free |
432 | * code. |
433 | * There is no requirement that all the tokens in a table have a valid code, |
434 | * but the current encoder is not optimized to take advantage of this. |
435 | * If each of the five grouops of 16 tables does not contain at least one table |
436 | * with a code for every token, then the encoder may fail to encode certain |
437 | * frames. |
438 | * The complete table in the first group of 16 does not have to be in the same |
439 | * place as the complete table in the other groups, but the complete tables in |
440 | * the remaining four groups must all be in the same place.*/ |
441 | typedef struct{ |
442 | /**The bit pattern for the code, with the LSbit of the pattern aligned in |
443 | * the LSbit of the word.*/ |
444 | ogg_uint32_t pattern; |
445 | /**The number of bits in the code. |
446 | * This must be between 0 and 32, inclusive.*/ |
447 | int nbits; |
448 | }th_huff_code; |
449 | |
450 | |
451 | |
452 | /**\defgroup basefuncs Functions Shared by Encode and Decode*/ |
453 | /*@{*/ |
454 | /**\name Basic shared functions |
455 | * These functions return information about the library itself, |
456 | * or provide high-level information about codec state |
457 | * and packet type. |
458 | * |
459 | * You must link to \c libtheoradec if you use any of the |
460 | * functions in this section.*/ |
461 | /*@{*/ |
462 | /**Retrieves a human-readable string to identify the library vendor and |
463 | * version. |
464 | * \return the version string.*/ |
465 | extern const char *th_version_string(void); |
466 | /**Retrieves the library version number. |
467 | * This is the highest bitstream version that the encoder library will produce, |
468 | * or that the decoder library can decode. |
469 | * This number is composed of a 16-bit major version, 8-bit minor version |
470 | * and 8 bit sub-version, composed as follows: |
471 | * \code |
472 | * (VERSION_MAJOR<<16)+(VERSION_MINOR<<8)+(VERSION_SUBMINOR) |
473 | * \endcode |
474 | * \return the version number.*/ |
475 | extern ogg_uint32_t th_version_number(void); |
476 | /**Converts a granule position to an absolute frame index, starting at |
477 | * <tt>0</tt>. |
478 | * The granule position is interpreted in the context of a given |
479 | * #th_enc_ctx or #th_dec_ctx handle (either will suffice). |
480 | * \param _encdec A previously allocated #th_enc_ctx or #th_dec_ctx |
481 | * handle. |
482 | * \param _granpos The granule position to convert. |
483 | * \returns The absolute frame index corresponding to \a _granpos. |
484 | * \retval -1 The given granule position was invalid (i.e. negative).*/ |
485 | extern ogg_int64_t th_granule_frame(void *_encdec,ogg_int64_t _granpos); |
486 | /**Converts a granule position to an absolute time in seconds. |
487 | * The granule position is interpreted in the context of a given |
488 | * #th_enc_ctx or #th_dec_ctx handle (either will suffice). |
489 | * \param _encdec A previously allocated #th_enc_ctx or #th_dec_ctx |
490 | * handle. |
491 | * \param _granpos The granule position to convert. |
492 | * \return The absolute time in seconds corresponding to \a _granpos. |
493 | * This is the "end time" for the frame, or the latest time it should |
494 | * be displayed. |
495 | * It is not the presentation time. |
496 | * \retval -1 The given granule position was invalid (i.e. negative).*/ |
497 | extern double th_granule_time(void *_encdec,ogg_int64_t _granpos); |
498 | /**Determines whether a Theora packet is a header or not. |
499 | * This function does no verification beyond checking the packet type bit, so |
500 | * it should not be used for bitstream identification; use |
501 | * th_decode_headerin() for that. |
502 | * As per the Theora specification, an empty (0-byte) packet is treated as a |
503 | * data packet (a delta frame with no coded blocks). |
504 | * \param _op An <tt>ogg_packet</tt> containing encoded Theora data. |
505 | * \retval 1 The packet is a header packet |
506 | * \retval 0 The packet is a video data packet.*/ |
507 | extern int (ogg_packet *_op); |
508 | /**Determines whether a theora packet is a key frame or not. |
509 | * This function does no verification beyond checking the packet type and |
510 | * key frame bits, so it should not be used for bitstream identification; use |
511 | * th_decode_headerin() for that. |
512 | * As per the Theora specification, an empty (0-byte) packet is treated as a |
513 | * delta frame (with no coded blocks). |
514 | * \param _op An <tt>ogg_packet</tt> containing encoded Theora data. |
515 | * \retval 1 The packet contains a key frame. |
516 | * \retval 0 The packet contains a delta frame. |
517 | * \retval -1 The packet is not a video data packet.*/ |
518 | extern int th_packet_iskeyframe(ogg_packet *_op); |
519 | /*@}*/ |
520 | |
521 | |
522 | /**\name Functions for manipulating header data |
523 | * These functions manipulate the #th_info and #th_comment structures |
524 | * which describe video parameters and key-value metadata, respectively. |
525 | * |
526 | * You must link to \c libtheoradec if you use any of the |
527 | * functions in this section.*/ |
528 | /*@{*/ |
529 | /**Initializes a th_info structure. |
530 | * This should be called on a freshly allocated #th_info structure before |
531 | * attempting to use it. |
532 | * \param _info The #th_info struct to initialize.*/ |
533 | extern void th_info_init(th_info *_info); |
534 | /**Clears a #th_info structure. |
535 | * This should be called on a #th_info structure after it is no longer |
536 | * needed. |
537 | * \param _info The #th_info struct to clear.*/ |
538 | extern void th_info_clear(th_info *_info); |
539 | |
540 | /**Initialize a #th_comment structure. |
541 | * This should be called on a freshly allocated #th_comment structure |
542 | * before attempting to use it. |
543 | * \param _tc The #th_comment struct to initialize.*/ |
544 | extern void (th_comment *_tc); |
545 | /**Add a comment to an initialized #th_comment structure. |
546 | * \note Neither th_comment_add() nor th_comment_add_tag() support |
547 | * comments containing null values, although the bitstream format does |
548 | * support them. |
549 | * To add such comments you will need to manipulate the #th_comment |
550 | * structure directly. |
551 | * \param _tc The #th_comment struct to add the comment to. |
552 | * \param _comment Must be a null-terminated UTF-8 string containing the |
553 | * comment in "TAG=the value" form.*/ |
554 | extern void (th_comment *_tc,const char *); |
555 | /**Add a comment to an initialized #th_comment structure. |
556 | * \note Neither th_comment_add() nor th_comment_add_tag() support |
557 | * comments containing null values, although the bitstream format does |
558 | * support them. |
559 | * To add such comments you will need to manipulate the #th_comment |
560 | * structure directly. |
561 | * \param _tc The #th_comment struct to add the comment to. |
562 | * \param _tag A null-terminated string containing the tag associated with |
563 | * the comment. |
564 | * \param _val The corresponding value as a null-terminated string.*/ |
565 | extern void (th_comment *_tc,const char *_tag, |
566 | const char *_val); |
567 | /**Look up a comment value by its tag. |
568 | * \param _tc An initialized #th_comment structure. |
569 | * \param _tag The tag to look up. |
570 | * \param _count The instance of the tag. |
571 | * The same tag can appear multiple times, each with a distinct |
572 | * value, so an index is required to retrieve them all. |
573 | * The order in which these values appear is significant and |
574 | * should be preserved. |
575 | * Use th_comment_query_count() to get the legal range for |
576 | * the \a _count parameter. |
577 | * \return A pointer to the queried tag's value. |
578 | * This points directly to data in the #th_comment structure. |
579 | * It should not be modified or freed by the application, and |
580 | * modifications to the structure may invalidate the pointer. |
581 | * \retval NULL If no matching tag is found.*/ |
582 | extern char *(th_comment *_tc,const char *_tag,int _count); |
583 | /**Look up the number of instances of a tag. |
584 | * Call this first when querying for a specific tag and then iterate over the |
585 | * number of instances with separate calls to th_comment_query() to |
586 | * retrieve all the values for that tag in order. |
587 | * \param _tc An initialized #th_comment structure. |
588 | * \param _tag The tag to look up. |
589 | * \return The number of instances of this particular tag.*/ |
590 | extern int (th_comment *_tc,const char *_tag); |
591 | /**Clears a #th_comment structure. |
592 | * This should be called on a #th_comment structure after it is no longer |
593 | * needed. |
594 | * It will free all memory used by the structure members. |
595 | * \param _tc The #th_comment struct to clear.*/ |
596 | extern void (th_comment *_tc); |
597 | /*@}*/ |
598 | /*@}*/ |
599 | |
600 | |
601 | |
602 | #if defined(__cplusplus) |
603 | } |
604 | #endif |
605 | |
606 | #endif |
607 | |