codec.h 25 KB

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