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