theora.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  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.17 2003/12/06 18:06:19 arc Exp $
  14. ********************************************************************/
  15. #ifndef _O_THEORA_H_
  16. #define _O_THEORA_H_
  17. #ifdef __cplusplus
  18. extern "C"
  19. {
  20. #endif /* __cplusplus */
  21. #include <stddef.h> /* for size_t */
  22. #include <ogg/ogg.h>
  23. /** \file
  24. * The libtheora pre-1.0 legacy C API.
  25. *
  26. * \ingroup oldfuncs
  27. *
  28. * \section intro Introduction
  29. *
  30. * This is the documentation for the libtheora legacy C API, declared in
  31. * the theora.h header, which describes the old interface used before
  32. * the 1.0 release. This API was widely deployed for several years and
  33. * remains supported, but for new code we recommend the cleaner API
  34. * declared in theoradec.h and theoraenc.h.
  35. *
  36. * libtheora is the reference implementation for
  37. * <a href="http://www.theora.org/">Theora</a>, a free video codec.
  38. * Theora is derived from On2's VP3 codec with improved integration with
  39. * Ogg multimedia formats by <a href="http://www.xiph.org/">Xiph.Org</a>.
  40. *
  41. * \section overview Overview
  42. *
  43. * This library will both decode and encode theora packets to/from raw YUV
  44. * frames. In either case, the packets will most likely either come from or
  45. * need to be embedded in an Ogg stream. Use
  46. * <a href="http://xiph.org/ogg/">libogg</a> or
  47. * <a href="http://www.annodex.net/software/liboggz/index.html">liboggz</a>
  48. * to extract/package these packets.
  49. *
  50. * \section decoding Decoding Process
  51. *
  52. * Decoding can be separated into the following steps:
  53. * -# initialise theora_info and theora_comment structures using
  54. * theora_info_init() and theora_comment_init():
  55. \verbatim
  56. theora_info info;
  57. theora_comment comment;
  58. theora_info_init(&info);
  59. theora_comment_init(&comment);
  60. \endverbatim
  61. * -# retrieve header packets from Ogg stream (there should be 3) and decode
  62. * into theora_info and theora_comment structures using
  63. * theora_decode_header(). See \ref identification for more information on
  64. * identifying which packets are theora packets.
  65. \verbatim
  66. int i;
  67. for (i = 0; i < 3; i++)
  68. {
  69. (get a theora packet "op" from the Ogg stream)
  70. theora_decode_header(&info, &comment, op);
  71. }
  72. \endverbatim
  73. * -# initialise the decoder based on the information retrieved into the
  74. * theora_info struct by theora_decode_header(). You will need a
  75. * theora_state struct.
  76. \verbatim
  77. theora_state state;
  78. theora_decode_init(&state, &info);
  79. \endverbatim
  80. * -# pass in packets and retrieve decoded frames! See the yuv_buffer
  81. * documentation for information on how to retrieve raw YUV data.
  82. \verbatim
  83. yuf_buffer buffer;
  84. while (last packet was not e_o_s) {
  85. (get a theora packet "op" from the Ogg stream)
  86. theora_decode_packetin(&state, op);
  87. theora_decode_YUVout(&state, &buffer);
  88. }
  89. \endverbatim
  90. *
  91. *
  92. * \subsection identification Identifying Theora Packets
  93. *
  94. * All streams inside an Ogg file have a unique serial_no attached to the
  95. * stream. Typically, you will want to
  96. * - retrieve the serial_no for each b_o_s (beginning of stream) page
  97. * encountered within the Ogg file;
  98. * - test the first (only) packet on that page to determine if it is a theora
  99. * packet;
  100. * - once you have found a theora b_o_s page then use the retrieved serial_no
  101. * to identify future packets belonging to the same theora stream.
  102. *
  103. * Note that you \e cannot use theora_packet_isheader() to determine if a
  104. * packet is a theora packet or not, as this function does not perform any
  105. * checking beyond whether a header bit is present. Instead, use the
  106. * theora_decode_header() function and check the return value; or examine the
  107. * header bytes at the beginning of the Ogg page.
  108. */
  109. /** \defgroup oldfuncs Legacy pre-1.0 C API */
  110. /* @{ */
  111. /**
  112. * A YUV buffer for passing uncompressed frames to and from the codec.
  113. * This holds a Y'CbCr frame in planar format. The CbCr planes can be
  114. * subsampled and have their own separate dimensions and row stride
  115. * offsets. Note that the strides may be negative in some
  116. * configurations. For theora the width and height of the largest plane
  117. * must be a multiple of 16. The actual meaningful picture size and
  118. * offset are stored in the theora_info structure; frames returned by
  119. * the decoder may need to be cropped for display.
  120. *
  121. * All samples are 8 bits. Within each plane samples are ordered by
  122. * row from the top of the frame to the bottom. Within each row samples
  123. * are ordered from left to right.
  124. *
  125. * During decode, the yuv_buffer struct is allocated by the user, but all
  126. * fields (including luma and chroma pointers) are filled by the library.
  127. * These pointers address library-internal memory and their contents should
  128. * not be modified.
  129. *
  130. * Conversely, during encode the user allocates the struct and fills out all
  131. * fields. The user also manages the data addressed by the luma and chroma
  132. * pointers. See the encoder_example.c and dump_video.c example files in
  133. * theora/examples/ for more information.
  134. */
  135. typedef struct {
  136. int y_width; /**< Width of the Y' luminance plane */
  137. int y_height; /**< Height of the luminance plane */
  138. int y_stride; /**< Offset in bytes between successive rows */
  139. int uv_width; /**< Width of the Cb and Cr chroma planes */
  140. int uv_height; /**< Height of the chroma planes */
  141. int uv_stride; /**< Offset between successive chroma rows */
  142. unsigned char *y; /**< Pointer to start of luminance data */
  143. unsigned char *u; /**< Pointer to start of Cb data */
  144. unsigned char *v; /**< Pointer to start of Cr data */
  145. } yuv_buffer;
  146. /**
  147. * A Colorspace.
  148. */
  149. typedef enum {
  150. OC_CS_UNSPECIFIED, /**< The colorspace is unknown or unspecified */
  151. OC_CS_ITU_REC_470M, /**< This is the best option for 'NTSC' content */
  152. OC_CS_ITU_REC_470BG, /**< This is the best option for 'PAL' content */
  153. OC_CS_NSPACES /**< This marks the end of the defined colorspaces */
  154. } theora_colorspace;
  155. /**
  156. * A Chroma subsampling
  157. *
  158. * These enumerate the available chroma subsampling options supported
  159. * by the theora format. See Section 4.4 of the specification for
  160. * exact definitions.
  161. */
  162. typedef enum {
  163. OC_PF_420, /**< Chroma subsampling by 2 in each direction (4:2:0) */
  164. OC_PF_RSVD, /**< Reserved value */
  165. OC_PF_422, /**< Horizonatal chroma subsampling by 2 (4:2:2) */
  166. OC_PF_444, /**< No chroma subsampling at all (4:4:4) */
  167. } theora_pixelformat;
  168. /**
  169. * Theora bitstream info.
  170. * Contains the basic playback parameters for a stream,
  171. * corresponding to the initial 'info' header packet.
  172. *
  173. * Encoded theora frames must be a multiple of 16 in width and height.
  174. * To handle other frame sizes, a crop rectangle is specified in
  175. * frame_height and frame_width, offset_x and * offset_y. The offset
  176. * and size should still be a multiple of 2 to avoid chroma sampling
  177. * shifts. Offset values in this structure are measured from the
  178. * upper left of the image.
  179. *
  180. * Frame rate, in frames per second, is stored as a rational
  181. * fraction. Aspect ratio is also stored as a rational fraction, and
  182. * refers to the aspect ratio of the frame pixels, not of the
  183. * overall frame itself.
  184. *
  185. * See <a href="http://svn.xiph.org/trunk/theora/examples/encoder_example.c">
  186. * examples/encoder_example.c</a> for usage examples of the
  187. * other paramters and good default settings for the encoder parameters.
  188. */
  189. typedef struct {
  190. ogg_uint32_t width; /**< encoded frame width */
  191. ogg_uint32_t height; /**< encoded frame height */
  192. ogg_uint32_t frame_width; /**< display frame width */
  193. ogg_uint32_t frame_height; /**< display frame height */
  194. ogg_uint32_t offset_x; /**< horizontal offset of the displayed frame */
  195. ogg_uint32_t offset_y; /**< vertical offset of the displayed frame */
  196. ogg_uint32_t fps_numerator; /**< frame rate numerator **/
  197. ogg_uint32_t fps_denominator; /**< frame rate denominator **/
  198. ogg_uint32_t aspect_numerator; /**< pixel aspect ratio numerator */
  199. ogg_uint32_t aspect_denominator; /**< pixel aspect ratio denominator */
  200. theora_colorspace colorspace; /**< colorspace */
  201. int target_bitrate; /**< nominal bitrate in bits per second */
  202. int quality; /**< Nominal quality setting, 0-63 */
  203. int quick_p; /**< Quick encode/decode */
  204. /* decode only */
  205. unsigned char version_major;
  206. unsigned char version_minor;
  207. unsigned char version_subminor;
  208. void *codec_setup;
  209. /* encode only */
  210. int dropframes_p;
  211. int keyframe_auto_p;
  212. ogg_uint32_t keyframe_frequency;
  213. ogg_uint32_t keyframe_frequency_force; /* also used for decode init to
  214. get granpos shift correct */
  215. ogg_uint32_t keyframe_data_target_bitrate;
  216. ogg_int32_t keyframe_auto_threshold;
  217. ogg_uint32_t keyframe_mindistance;
  218. ogg_int32_t noise_sensitivity;
  219. ogg_int32_t sharpness;
  220. theora_pixelformat pixelformat; /**< chroma subsampling mode to expect */
  221. } theora_info;
  222. /** Codec internal state and context.
  223. */
  224. typedef struct {
  225. theora_info *i;
  226. ogg_int64_t granulepos;
  227. void *internal_encode;
  228. void *internal_decode;
  229. } theora_state;
  230. /**
  231. * Comment header metadata.
  232. *
  233. * This structure holds the in-stream metadata corresponding to
  234. * the 'comment' header packet.
  235. *
  236. * Meta data is stored as a series of (tag, value) pairs, in
  237. * length-encoded string vectors. The first occurence of the
  238. * '=' character delimits the tag and value. A particular tag
  239. * may occur more than once. The character set encoding for
  240. * the strings is always UTF-8, but the tag names are limited
  241. * to case-insensitive ASCII. See the spec for details.
  242. *
  243. * In filling in this structure, theora_decode_header() will
  244. * null-terminate the user_comment strings for safety. However,
  245. * the bitstream format itself treats them as 8-bit clean,
  246. * and so the length array should be treated as authoritative
  247. * for their length.
  248. */
  249. typedef struct theora_comment {
  250. char **user_comments; /**< An array of comment string vectors */
  251. int *comment_lengths; /**< An array of corresponding string vector lengths in bytes */
  252. int comments; /**< The total number of comment string vectors */
  253. char *vendor; /**< The vendor string identifying the encoder, null terminated */
  254. } theora_comment;
  255. /**\name theora_control() codes */
  256. /* \anchor decctlcodes_old
  257. * These are the available request codes for theora_control()
  258. * when called with a decoder instance.
  259. * By convention decoder control codes are odd, to distinguish
  260. * them from \ref encctlcodes_old "encoder control codes" which
  261. * are even.
  262. *
  263. * Note that since the 1.0 release, both the legacy and the final
  264. * implementation accept all the same control codes, but only the
  265. * final API declares the newer codes.
  266. *
  267. * Keep any experimental or vendor-specific values above \c 0x8000.*/
  268. /*@{*/
  269. /**Get the maximum post-processing level.
  270. * The decoder supports a post-processing filter that can improve
  271. * the appearance of the decoded images. This returns the highest
  272. * level setting for this post-processor, corresponding to maximum
  273. * improvement and computational expense.
  274. */
  275. #define TH_DECCTL_GET_PPLEVEL_MAX (1)
  276. /**Set the post-processing level.
  277. * Sets the level of post-processing to use when decoding the
  278. * compressed stream. This must be a value between zero (off)
  279. * and the maximum returned by TH_DECCTL_GET_PPLEVEL_MAX.
  280. */
  281. #define TH_DECCTL_SET_PPLEVEL (3)
  282. /**Sets the maximum distance between key frames.
  283. * This can be changed during an encode, but will be bounded by
  284. * <tt>1<<th_info#keyframe_granule_shift</tt>.
  285. * If it is set before encoding begins, th_info#keyframe_granule_shift will
  286. * be enlarged appropriately.
  287. *
  288. * \param[in] buf <tt>ogg_uint32_t</tt>: The maximum distance between key
  289. * frames.
  290. * \param[out] buf <tt>ogg_uint32_t</tt>: The actual maximum distance set.
  291. * \retval OC_FAULT \a theora_state or \a buf is <tt>NULL</tt>.
  292. * \retval OC_EINVAL \a buf_sz is not <tt>sizeof(ogg_uint32_t)</tt>.
  293. * \retval OC_IMPL Not supported by this implementation.*/
  294. #define TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE (4)
  295. /**Set the granule position.
  296. * Call this after a seek, to update the internal granulepos
  297. * in the decoder, to insure that subsequent frames are marked
  298. * properly. If you track timestamps yourself and do not use
  299. * the granule postion returned by the decoder, then you do
  300. * not need to use this control.
  301. */
  302. #define TH_DECCTL_SET_GRANPOS (5)
  303. /**\anchor encctlcodes_old */
  304. /**Sets the quantization parameters to use.
  305. * The parameters are copied, not stored by reference, so they can be freed
  306. * after this call.
  307. * <tt>NULL</tt> may be specified to revert to the default parameters.
  308. *
  309. * \param[in] buf #th_quant_info
  310. * \retval OC_FAULT \a theora_state is <tt>NULL</tt>.
  311. * \retval OC_EINVAL Encoding has already begun, the quantization parameters
  312. * are not acceptable to this version of the encoder,
  313. * \a buf is <tt>NULL</tt> and \a buf_sz is not zero,
  314. * or \a buf is non-<tt>NULL</tt> and \a buf_sz is
  315. * not <tt>sizeof(#th_quant_info)</tt>.
  316. * \retval OC_IMPL Not supported by this implementation.*/
  317. #define TH_ENCCTL_SET_QUANT_PARAMS (2)
  318. /**Disables any encoder features that would prevent lossless transcoding back
  319. * to VP3.
  320. * This primarily means disabling block-level QI values and not using 4MV mode
  321. * when any of the luma blocks in a macro block are not coded.
  322. * It also includes using the VP3 quantization tables and Huffman codes; if you
  323. * set them explicitly after calling this function, the resulting stream will
  324. * not be VP3-compatible.
  325. * If you enable VP3-compatibility when encoding 4:2:2 or 4:4:4 source
  326. * material, or when using a picture region smaller than the full frame (e.g.
  327. * a non-multiple-of-16 width or height), then non-VP3 bitstream features will
  328. * still be disabled, but the stream will still not be VP3-compatible, as VP3
  329. * was not capable of encoding such formats.
  330. * If you call this after encoding has already begun, then the quantization
  331. * tables and codebooks cannot be changed, but the frame-level features will
  332. * be enabled or disabled as requested.
  333. *
  334. * \param[in] buf <tt>int</tt>: a non-zero value to enable VP3 compatibility,
  335. * or 0 to disable it (the default).
  336. * \param[out] buf <tt>int</tt>: 1 if all bitstream features required for
  337. * VP3-compatibility could be set, and 0 otherwise.
  338. * The latter will be returned if the pixel format is not
  339. * 4:2:0, the picture region is smaller than the full frame,
  340. * or if encoding has begun, preventing the quantization
  341. * tables and codebooks from being set.
  342. * \retval OC_FAULT \a theora_state or \a buf is <tt>NULL</tt>.
  343. * \retval OC_EINVAL \a buf_sz is not <tt>sizeof(int)</tt>.
  344. * \retval OC_IMPL Not supported by this implementation.*/
  345. #define TH_ENCCTL_SET_VP3_COMPATIBLE (10)
  346. /**Gets the maximum speed level.
  347. * Higher speed levels favor quicker encoding over better quality per bit.
  348. * Depending on the encoding mode, and the internal algorithms used, quality
  349. * may actually improve, but in this case bitrate will also likely increase.
  350. * In any case, overall rate/distortion performance will probably decrease.
  351. * The maximum value, and the meaning of each value, may change depending on
  352. * the current encoding mode (VBR vs. CQI, etc.).
  353. *
  354. * \param[out] buf int: The maximum encoding speed level.
  355. * \retval OC_FAULT \a theora_state or \a buf is <tt>NULL</tt>.
  356. * \retval OC_EINVAL \a buf_sz is not <tt>sizeof(int)</tt>.
  357. * \retval OC_IMPL Not supported by this implementation in the current
  358. * encoding mode.*/
  359. #define TH_ENCCTL_GET_SPLEVEL_MAX (12)
  360. /**Sets the speed level.
  361. * By default a speed value of 1 is used.
  362. *
  363. * \param[in] buf int: The new encoding speed level.
  364. * 0 is slowest, larger values use less CPU.
  365. * \retval OC_FAULT \a theora_state or \a buf is <tt>NULL</tt>.
  366. * \retval OC_EINVAL \a buf_sz is not <tt>sizeof(int)</tt>, or the
  367. * encoding speed level is out of bounds.
  368. * The maximum encoding speed level may be
  369. * implementation- and encoding mode-specific, and can be
  370. * obtained via #TH_ENCCTL_GET_SPLEVEL_MAX.
  371. * \retval OC_IMPL Not supported by this implementation in the current
  372. * encoding mode.*/
  373. #define TH_ENCCTL_SET_SPLEVEL (14)
  374. /*@}*/
  375. #define OC_FAULT -1 /**< General failure */
  376. #define OC_EINVAL -10 /**< Library encountered invalid internal data */
  377. #define OC_DISABLED -11 /**< Requested action is disabled */
  378. #define OC_BADHEADER -20 /**< Header packet was corrupt/invalid */
  379. #define OC_NOTFORMAT -21 /**< Packet is not a theora packet */
  380. #define OC_VERSION -22 /**< Bitstream version is not handled */
  381. #define OC_IMPL -23 /**< Feature or action not implemented */
  382. #define OC_BADPACKET -24 /**< Packet is corrupt */
  383. #define OC_NEWPACKET -25 /**< Packet is an (ignorable) unhandled extension */
  384. #define OC_DUPFRAME 1 /**< Packet is a dropped frame */
  385. /**
  386. * Retrieve a human-readable string to identify the encoder vendor and version.
  387. * \returns A version string.
  388. */
  389. extern const char *theora_version_string(void);
  390. /**
  391. * Retrieve a 32-bit version number.
  392. * This number is composed of a 16-bit major version, 8-bit minor version
  393. * and 8 bit sub-version, composed as follows:
  394. <pre>
  395. (VERSION_MAJOR<<16) + (VERSION_MINOR<<8) + (VERSION_SUB)
  396. </pre>
  397. * \returns The version number.
  398. */
  399. extern ogg_uint32_t theora_version_number(void);
  400. /**
  401. * Initialize the theora encoder.
  402. * \param th The theora_state handle to initialize for encoding.
  403. * \param ti A theora_info struct filled with the desired encoding parameters.
  404. * \retval 0 Success
  405. */
  406. extern int theora_encode_init(theora_state *th, theora_info *ti);
  407. /**
  408. * Submit a YUV buffer to the theora encoder.
  409. * \param t A theora_state handle previously initialized for encoding.
  410. * \param yuv A buffer of YUV data to encode. Note that both the yuv_buffer
  411. * struct and the luma/chroma buffers within should be allocated by
  412. * the user.
  413. * \retval OC_EINVAL Encoder is not ready, or is finished.
  414. * \retval -1 The size of the given frame differs from those previously input
  415. * \retval 0 Success
  416. */
  417. extern int theora_encode_YUVin(theora_state *t, yuv_buffer *yuv);
  418. /**
  419. * Request the next packet of encoded video.
  420. * The encoded data is placed in a user-provided ogg_packet structure.
  421. * \param t A theora_state handle previously initialized for encoding.
  422. * \param last_p whether this is the last packet the encoder should produce.
  423. * \param op An ogg_packet structure to fill. libtheora will set all
  424. * elements of this structure, including a pointer to encoded
  425. * data. The memory for the encoded data is owned by libtheora.
  426. * \retval 0 No internal storage exists OR no packet is ready
  427. * \retval -1 The encoding process has completed
  428. * \retval 1 Success
  429. */
  430. extern int theora_encode_packetout( theora_state *t, int last_p,
  431. ogg_packet *op);
  432. /**
  433. * Request a packet containing the initial header.
  434. * A pointer to the header data is placed in a user-provided ogg_packet
  435. * structure.
  436. * \param t A theora_state handle previously initialized for encoding.
  437. * \param op An ogg_packet structure to fill. libtheora will set all
  438. * elements of this structure, including a pointer to the header
  439. * data. The memory for the header data is owned by libtheora.
  440. * \retval 0 Success
  441. */
  442. extern int theora_encode_header(theora_state *t, ogg_packet *op);
  443. /**
  444. * Request a comment header packet from provided metadata.
  445. * A pointer to the comment data is placed in a user-provided ogg_packet
  446. * structure.
  447. * \param tc A theora_comment structure filled with the desired metadata
  448. * \param op An ogg_packet structure to fill. libtheora will set all
  449. * elements of this structure, including a pointer to the encoded
  450. * comment data. The memory for the comment data is owned by
  451. * libtheora.
  452. * \retval 0 Success
  453. */
  454. extern int theora_encode_comment(theora_comment *tc, ogg_packet *op);
  455. /**
  456. * Request a packet containing the codebook tables for the stream.
  457. * A pointer to the codebook data is placed in a user-provided ogg_packet
  458. * structure.
  459. * \param t A theora_state handle previously initialized for encoding.
  460. * \param op An ogg_packet structure to fill. libtheora will set all
  461. * elements of this structure, including a pointer to the codebook
  462. * data. The memory for the header data is owned by libtheora.
  463. * \retval 0 Success
  464. */
  465. extern int theora_encode_tables(theora_state *t, ogg_packet *op);
  466. /**
  467. * Decode an Ogg packet, with the expectation that the packet contains
  468. * an initial header, comment data or codebook tables.
  469. *
  470. * \param ci A theora_info structure to fill. This must have been previously
  471. * initialized with theora_info_init(). If \a op contains an initial
  472. * header, theora_decode_header() will fill \a ci with the
  473. * parsed header values. If \a op contains codebook tables,
  474. * theora_decode_header() will parse these and attach an internal
  475. * representation to \a ci->codec_setup.
  476. * \param cc A theora_comment structure to fill. If \a op contains comment
  477. * data, theora_decode_header() will fill \a cc with the parsed
  478. * comments.
  479. * \param op An ogg_packet structure which you expect contains an initial
  480. * header, comment data or codebook tables.
  481. *
  482. * \retval OC_BADHEADER \a op is NULL; OR the first byte of \a op->packet
  483. * has the signature of an initial packet, but op is
  484. * not a b_o_s packet; OR this packet has the signature
  485. * of an initial header packet, but an initial header
  486. * packet has already been seen; OR this packet has the
  487. * signature of a comment packet, but the initial header
  488. * has not yet been seen; OR this packet has the signature
  489. * of a comment packet, but contains invalid data; OR
  490. * this packet has the signature of codebook tables,
  491. * but the initial header or comments have not yet
  492. * been seen; OR this packet has the signature of codebook
  493. * tables, but contains invalid data;
  494. * OR the stream being decoded has a compatible version
  495. * but this packet does not have the signature of a
  496. * theora initial header, comments, or codebook packet
  497. * \retval OC_VERSION The packet data of \a op is an initial header with
  498. * a version which is incompatible with this version of
  499. * libtheora.
  500. * \retval OC_NEWPACKET the stream being decoded has an incompatible (future)
  501. * version and contains an unknown signature.
  502. * \retval 0 Success
  503. *
  504. * \note The normal usage is that theora_decode_header() be called on the
  505. * first three packets of a theora logical bitstream in succession.
  506. */
  507. extern int theora_decode_header(theora_info *ci, theora_comment *cc,
  508. ogg_packet *op);
  509. /**
  510. * Initialize a theora_state handle for decoding.
  511. * \param th The theora_state handle to initialize.
  512. * \param c A theora_info struct filled with the desired decoding parameters.
  513. * This is of course usually obtained from a previous call to
  514. * theora_decode_header().
  515. * \retval 0 Success
  516. */
  517. extern int theora_decode_init(theora_state *th, theora_info *c);
  518. /**
  519. * Input a packet containing encoded data into the theora decoder.
  520. * \param th A theora_state handle previously initialized for decoding.
  521. * \param op An ogg_packet containing encoded theora data.
  522. * \retval 0 Success
  523. * \retval OC_BADPACKET \a op does not contain encoded video data
  524. */
  525. extern int theora_decode_packetin(theora_state *th,ogg_packet *op);
  526. /**
  527. * Output the next available frame of decoded YUV data.
  528. * \param th A theora_state handle previously initialized for decoding.
  529. * \param yuv A yuv_buffer in which libtheora should place the decoded data.
  530. * Note that the buffer struct itself is allocated by the user, but
  531. * that the luma and chroma pointers will be filled in by the
  532. * library. Also note that these luma and chroma regions should be
  533. * considered read-only by the user.
  534. * \retval 0 Success
  535. */
  536. extern int theora_decode_YUVout(theora_state *th,yuv_buffer *yuv);
  537. /**
  538. * Report whether a theora packet is a header or not
  539. * This function does no verification beyond checking the header
  540. * flag bit so it should not be used for bitstream identification;
  541. * use theora_decode_header() for that.
  542. *
  543. * \param op An ogg_packet containing encoded theora data.
  544. * \retval 1 The packet is a header packet
  545. * \retval 0 The packet is not a header packet (and so contains frame data)
  546. *
  547. * Thus function was added in the 1.0alpha4 release.
  548. */
  549. extern int theora_packet_isheader(ogg_packet *op);
  550. /**
  551. * Report whether a theora packet is a keyframe or not
  552. *
  553. * \param op An ogg_packet containing encoded theora data.
  554. * \retval 1 The packet contains a keyframe image
  555. * \retval 0 The packet is contains an interframe delta
  556. * \retval -1 The packet is not an image data packet at all
  557. *
  558. * Thus function was added in the 1.0alpha4 release.
  559. */
  560. extern int theora_packet_iskeyframe(ogg_packet *op);
  561. /**
  562. * Report the granulepos shift radix
  563. *
  564. * When embedded in Ogg, Theora uses a two-part granulepos,
  565. * splitting the 64-bit field into two pieces. The more-significant
  566. * section represents the frame count at the last keyframe,
  567. * and the less-significant section represents the count of
  568. * frames since the last keyframe. In this way the overall
  569. * field is still non-decreasing with time, but usefully encodes
  570. * a pointer to the last keyframe, which is necessary for
  571. * correctly restarting decode after a seek.
  572. *
  573. * This function reports the number of bits used to represent
  574. * the distance to the last keyframe, and thus how the granulepos
  575. * field must be shifted or masked to obtain the two parts.
  576. *
  577. * Since libtheora returns compressed data in an ogg_packet
  578. * structure, this may be generally useful even if the Theora
  579. * packets are not being used in an Ogg container.
  580. *
  581. * \param ti A previously initialized theora_info struct
  582. * \returns The bit shift dividing the two granulepos fields
  583. *
  584. * This function was added in the 1.0alpha5 release.
  585. */
  586. int theora_granule_shift(theora_info *ti);
  587. /**
  588. * Convert a granulepos to an absolute frame index, starting at 0.
  589. * The granulepos is interpreted in the context of a given theora_state handle.
  590. *
  591. * Note that while the granulepos encodes the frame count (i.e. starting
  592. * from 1) this call returns the frame index, starting from zero. Thus
  593. * One can calculate the presentation time by multiplying the index by
  594. * the rate.
  595. *
  596. * \param th A previously initialized theora_state handle (encode or decode)
  597. * \param granulepos The granulepos to convert.
  598. * \returns The frame index corresponding to \a granulepos.
  599. * \retval -1 The given granulepos is undefined (i.e. negative)
  600. *
  601. * Thus function was added in the 1.0alpha4 release.
  602. */
  603. extern ogg_int64_t theora_granule_frame(theora_state *th,ogg_int64_t granulepos);
  604. /**
  605. * Convert a granulepos to absolute time in seconds. The granulepos is
  606. * interpreted in the context of a given theora_state handle, and gives
  607. * the end time of a frame's presentation as used in Ogg mux ordering.
  608. *
  609. * \param th A previously initialized theora_state handle (encode or decode)
  610. * \param granulepos The granulepos to convert.
  611. * \returns The absolute time in seconds corresponding to \a granulepos.
  612. * This is the "end time" for the frame, or the latest time it should
  613. * be displayed.
  614. * It is not the presentation time.
  615. * \retval -1. The given granulepos is undefined (i.e. negative), or
  616. * \retval -1. The function has been disabled because floating
  617. * point support is not available.
  618. */
  619. extern double theora_granule_time(theora_state *th,ogg_int64_t granulepos);
  620. /**
  621. * Initialize a theora_info structure. All values within the given theora_info
  622. * structure are initialized, and space is allocated within libtheora for
  623. * internal codec setup data.
  624. * \param c A theora_info struct to initialize.
  625. */
  626. extern void theora_info_init(theora_info *c);
  627. /**
  628. * Clear a theora_info structure. All values within the given theora_info
  629. * structure are cleared, and associated internal codec setup data is freed.
  630. * \param c A theora_info struct to initialize.
  631. */
  632. extern void theora_info_clear(theora_info *c);
  633. /**
  634. * Free all internal data associated with a theora_state handle.
  635. * \param t A theora_state handle.
  636. */
  637. extern void theora_clear(theora_state *t);
  638. /**
  639. * Initialize an allocated theora_comment structure
  640. * \param tc An allocated theora_comment structure
  641. **/
  642. extern void theora_comment_init(theora_comment *tc);
  643. /**
  644. * Add a comment to an initialized theora_comment structure
  645. * \param tc A previously initialized theora comment structure
  646. * \param comment A null-terminated string encoding the comment in the form
  647. * "TAG=the value"
  648. *
  649. * Neither theora_comment_add() nor theora_comment_add_tag() support
  650. * comments containing null values, although the bitstream format
  651. * supports this. To add such comments you will need to manipulate
  652. * the theora_comment structure directly.
  653. **/
  654. extern void theora_comment_add(theora_comment *tc, char *comment);
  655. /**
  656. * Add a comment to an initialized theora_comment structure.
  657. * \param tc A previously initialized theora comment structure
  658. * \param tag A null-terminated string containing the tag
  659. * associated with the comment.
  660. * \param value The corresponding value as a null-terminated string
  661. *
  662. * Neither theora_comment_add() nor theora_comment_add_tag() support
  663. * comments containing null values, although the bitstream format
  664. * supports this. To add such comments you will need to manipulate
  665. * the theora_comment structure directly.
  666. **/
  667. extern void theora_comment_add_tag(theora_comment *tc,
  668. char *tag, char *value);
  669. /**
  670. * Look up a comment value by tag.
  671. * \param tc Tn initialized theora_comment structure
  672. * \param tag The tag to look up
  673. * \param count The instance of the tag. The same tag can appear multiple
  674. * times, each with a distinct and ordered value, so an index
  675. * is required to retrieve them all.
  676. * \returns A pointer to the queried tag's value
  677. * \retval NULL No matching tag is found
  678. *
  679. * \note Use theora_comment_query_count() to get the legal range for the
  680. * count parameter.
  681. **/
  682. extern char *theora_comment_query(theora_comment *tc, char *tag, int count);
  683. /** Look up the number of instances of a tag.
  684. * \param tc An initialized theora_comment structure
  685. * \param tag The tag to look up
  686. * \returns The number on instances of a particular tag.
  687. *
  688. * Call this first when querying for a specific tag and then interate
  689. * over the number of instances with separate calls to
  690. * theora_comment_query() to retrieve all instances in order.
  691. **/
  692. extern int theora_comment_query_count(theora_comment *tc, char *tag);
  693. /**
  694. * Clear an allocated theora_comment struct so that it can be freed.
  695. * \param tc An allocated theora_comment structure.
  696. **/
  697. extern void theora_comment_clear(theora_comment *tc);
  698. /**Encoder control function.
  699. * This is used to provide advanced control the encoding process.
  700. * \param th A #theora_state handle.
  701. * \param req The control code to process.
  702. * See \ref encctlcodes_old "the list of available
  703. * control codes" for details.
  704. * \param buf The parameters for this control code.
  705. * \param buf_sz The size of the parameter buffer.*/
  706. extern int theora_control(theora_state *th,int req,void *buf,size_t buf_sz);
  707. /* @} */ /* end oldfuncs doxygen group */
  708. #ifdef __cplusplus
  709. }
  710. #endif /* __cplusplus */
  711. #endif /* _O_THEORA_H_ */