theoraenc.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  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. /**\file
  16. * The <tt>libtheoraenc</tt> C encoding API.*/
  17. #if !defined(_O_THEORA_THEORAENC_H_)
  18. # define _O_THEORA_THEORAENC_H_ (1)
  19. # include <stddef.h>
  20. # include <ogg/ogg.h>
  21. # include "codec.h"
  22. #if defined(__cplusplus)
  23. extern "C" {
  24. #endif
  25. /**\name th_encode_ctl() codes
  26. * \anchor encctlcodes
  27. * These are the available request codes for th_encode_ctl().
  28. * By convention, these are even, to distinguish them from the
  29. * \ref decctlcodes "decoder control codes".
  30. * Keep any experimental or vendor-specific values above \c 0x8000.*/
  31. /*@{*/
  32. /**Sets the Huffman tables to use.
  33. * The tables are copied, not stored by reference, so they can be freed after
  34. * this call.
  35. * <tt>NULL</tt> may be specified to revert to the default tables.
  36. *
  37. * \param[in] _buf <tt>#th_huff_code[#TH_NHUFFMAN_TABLES][#TH_NDCT_TOKENS]</tt>
  38. * \retval TH_EFAULT \a _enc_ctx is <tt>NULL</tt>.
  39. * \retval TH_EINVAL Encoding has already begun or one or more of the given
  40. * tables is not full or prefix-free, \a _buf is
  41. * <tt>NULL</tt> and \a _buf_sz is not zero, or \a _buf is
  42. * non-<tt>NULL</tt> and \a _buf_sz is not
  43. * <tt>sizeof(#th_huff_code)*#TH_NHUFFMAN_TABLES*#TH_NDCT_TOKENS</tt>.
  44. * \retval TH_EIMPL Not supported by this implementation.*/
  45. #define TH_ENCCTL_SET_HUFFMAN_CODES (0)
  46. /**Sets the quantization parameters to use.
  47. * The parameters are copied, not stored by reference, so they can be freed
  48. * after this call.
  49. * <tt>NULL</tt> may be specified to revert to the default parameters.
  50. *
  51. * \param[in] _buf #th_quant_info
  52. * \retval TH_EFAULT \a _enc_ctx is <tt>NULL</tt>.
  53. * \retval TH_EINVAL Encoding has already begun, \a _buf is
  54. * <tt>NULL</tt> and \a _buf_sz is not zero,
  55. * or \a _buf is non-<tt>NULL</tt> and
  56. * \a _buf_sz is not <tt>sizeof(#th_quant_info)</tt>.
  57. * \retval TH_EIMPL Not supported by this implementation.*/
  58. #define TH_ENCCTL_SET_QUANT_PARAMS (2)
  59. /**Sets the maximum distance between key frames.
  60. * This can be changed during an encode, but will be bounded by
  61. * <tt>1<<th_info#keyframe_granule_shift</tt>.
  62. * If it is set before encoding begins, th_info#keyframe_granule_shift will
  63. * be enlarged appropriately.
  64. *
  65. * \param[in] _buf <tt>ogg_uint32_t</tt>: The maximum distance between key
  66. * frames.
  67. * \param[out] _buf <tt>ogg_uint32_t</tt>: The actual maximum distance set.
  68. * \retval TH_EFAULT \a _enc_ctx or \a _buf is <tt>NULL</tt>.
  69. * \retval TH_EINVAL \a _buf_sz is not <tt>sizeof(ogg_uint32_t)</tt>.
  70. * \retval TH_EIMPL Not supported by this implementation.*/
  71. #define TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE (4)
  72. /**Disables any encoder features that would prevent lossless transcoding back
  73. * to VP3.
  74. * This primarily means disabling block-adaptive quantization and always coding
  75. * all four luma blocks in a macro block when 4MV is used.
  76. * It also includes using the VP3 quantization tables and Huffman codes; if you
  77. * set them explicitly after calling this function, the resulting stream will
  78. * not be VP3-compatible.
  79. * If you enable VP3-compatibility when encoding 4:2:2 or 4:4:4 source
  80. * material, or when using a picture region smaller than the full frame (e.g.
  81. * a non-multiple-of-16 width or height), then non-VP3 bitstream features will
  82. * still be disabled, but the stream will still not be VP3-compatible, as VP3
  83. * was not capable of encoding such formats.
  84. * If you call this after encoding has already begun, then the quantization
  85. * tables and codebooks cannot be changed, but the frame-level features will
  86. * be enabled or disabled as requested.
  87. *
  88. * \param[in] _buf <tt>int</tt>: a non-zero value to enable VP3 compatibility,
  89. * or 0 to disable it (the default).
  90. * \param[out] _buf <tt>int</tt>: 1 if all bitstream features required for
  91. * VP3-compatibility could be set, and 0 otherwise.
  92. * The latter will be returned if the pixel format is not
  93. * 4:2:0, the picture region is smaller than the full frame,
  94. * or if encoding has begun, preventing the quantization
  95. * tables and codebooks from being set.
  96. * \retval TH_EFAULT \a _enc_ctx or \a _buf is <tt>NULL</tt>.
  97. * \retval TH_EINVAL \a _buf_sz is not <tt>sizeof(int)</tt>.
  98. * \retval TH_EIMPL Not supported by this implementation.*/
  99. #define TH_ENCCTL_SET_VP3_COMPATIBLE (10)
  100. /**Gets the maximum speed level.
  101. * Higher speed levels favor quicker encoding over better quality per bit.
  102. * Depending on the encoding mode, and the internal algorithms used, quality
  103. * may actually improve, but in this case bitrate will also likely increase.
  104. * In any case, overall rate/distortion performance will probably decrease.
  105. * The maximum value, and the meaning of each value, may change depending on
  106. * the current encoding mode (VBR vs. constant quality, etc.).
  107. *
  108. * \param[out] _buf <tt>int</tt>: The maximum encoding speed level.
  109. * \retval TH_EFAULT \a _enc_ctx or \a _buf is <tt>NULL</tt>.
  110. * \retval TH_EINVAL \a _buf_sz is not <tt>sizeof(int)</tt>.
  111. * \retval TH_EIMPL Not supported by this implementation in the current
  112. * encoding mode.*/
  113. #define TH_ENCCTL_GET_SPLEVEL_MAX (12)
  114. /**Sets the speed level.
  115. * The current speed level may be retrieved using #TH_ENCCTL_GET_SPLEVEL.
  116. *
  117. * \param[in] _buf <tt>int</tt>: The new encoding speed level.
  118. * 0 is slowest, larger values use less CPU.
  119. * \retval TH_EFAULT \a _enc_ctx or \a _buf is <tt>NULL</tt>.
  120. * \retval TH_EINVAL \a _buf_sz is not <tt>sizeof(int)</tt>, or the
  121. * encoding speed level is out of bounds.
  122. * The maximum encoding speed level may be
  123. * implementation- and encoding mode-specific, and can be
  124. * obtained via #TH_ENCCTL_GET_SPLEVEL_MAX.
  125. * \retval TH_EIMPL Not supported by this implementation in the current
  126. * encoding mode.*/
  127. #define TH_ENCCTL_SET_SPLEVEL (14)
  128. /**Gets the current speed level.
  129. * The default speed level may vary according to encoder implementation, but if
  130. * this control code is not supported (it returns #TH_EIMPL), the default may
  131. * be assumed to be the slowest available speed (0).
  132. * The maximum encoding speed level may be implementation- and encoding
  133. * mode-specific, and can be obtained via #TH_ENCCTL_GET_SPLEVEL_MAX.
  134. *
  135. * \param[out] _buf <tt>int</tt>: The current encoding speed level.
  136. * 0 is slowest, larger values use less CPU.
  137. * \retval TH_EFAULT \a _enc_ctx or \a _buf is <tt>NULL</tt>.
  138. * \retval TH_EINVAL \a _buf_sz is not <tt>sizeof(int)</tt>.
  139. * \retval TH_EIMPL Not supported by this implementation in the current
  140. * encoding mode.*/
  141. #define TH_ENCCTL_GET_SPLEVEL (16)
  142. /**Sets the number of duplicates of the next frame to produce.
  143. * Although libtheora can encode duplicate frames very cheaply, it costs some
  144. * amount of CPU to detect them, and a run of duplicates cannot span a
  145. * keyframe boundary.
  146. * This control code tells the encoder to produce the specified number of extra
  147. * duplicates of the next frame.
  148. * This allows the encoder to make smarter keyframe placement decisions and
  149. * rate control decisions, and reduces CPU usage as well, when compared to
  150. * just submitting the same frame for encoding multiple times.
  151. * This setting only applies to the next frame submitted for encoding.
  152. * You MUST call th_encode_packetout() repeatedly until it returns 0, or the
  153. * extra duplicate frames will be lost.
  154. *
  155. * \param[in] _buf <tt>int</tt>: The number of duplicates to produce.
  156. * If this is negative or zero, no duplicates will be produced.
  157. * \retval TH_EFAULT \a _enc_ctx or \a _buf is <tt>NULL</tt>.
  158. * \retval TH_EINVAL \a _buf_sz is not <tt>sizeof(int)</tt>, or the
  159. * number of duplicates is greater than or equal to the
  160. * maximum keyframe interval.
  161. * In the latter case, NO duplicate frames will be produced.
  162. * You must ensure that the maximum keyframe interval is set
  163. * larger than the maximum number of duplicates you will
  164. * ever wish to insert prior to encoding.
  165. * \retval TH_EIMPL Not supported by this implementation in the current
  166. * encoding mode.*/
  167. #define TH_ENCCTL_SET_DUP_COUNT (18)
  168. /**Modifies the default bitrate management behavior.
  169. * Use to allow or disallow frame dropping, and to enable or disable capping
  170. * bit reservoir overflows and underflows.
  171. * See \ref encctlcodes "the list of available flags".
  172. * The flags are set by default to
  173. * <tt>#TH_RATECTL_DROP_FRAMES|#TH_RATECTL_CAP_OVERFLOW</tt>.
  174. *
  175. * \param[in] _buf <tt>int</tt>: Any combination of
  176. * \ref ratectlflags "the available flags":
  177. * - #TH_RATECTL_DROP_FRAMES: Enable frame dropping.
  178. * - #TH_RATECTL_CAP_OVERFLOW: Don't bank excess bits for later
  179. * use.
  180. * - #TH_RATECTL_CAP_UNDERFLOW: Don't try to make up shortfalls
  181. * later.
  182. * \retval TH_EFAULT \a _enc_ctx or \a _buf is <tt>NULL</tt>.
  183. * \retval TH_EINVAL \a _buf_sz is not <tt>sizeof(int)</tt> or rate control
  184. * is not enabled.
  185. * \retval TH_EIMPL Not supported by this implementation in the current
  186. * encoding mode.*/
  187. #define TH_ENCCTL_SET_RATE_FLAGS (20)
  188. /**Sets the size of the bitrate management bit reservoir as a function
  189. * of number of frames.
  190. * The reservoir size affects how quickly bitrate management reacts to
  191. * instantaneous changes in the video complexity.
  192. * Larger reservoirs react more slowly, and provide better overall quality, but
  193. * require more buffering by a client, adding more latency to live streams.
  194. * By default, libtheora sets the reservoir to the maximum distance between
  195. * keyframes, subject to a minimum and maximum limit.
  196. * This call may be used to increase or decrease the reservoir, increasing or
  197. * decreasing the allowed temporary variance in bitrate.
  198. * An implementation may impose some limits on the size of a reservoir it can
  199. * handle, in which case the actual reservoir size may not be exactly what was
  200. * requested.
  201. * The actual value set will be returned.
  202. *
  203. * \param[in] _buf <tt>int</tt>: Requested size of the reservoir measured in
  204. * frames.
  205. * \param[out] _buf <tt>int</tt>: The actual size of the reservoir set.
  206. * \retval TH_EFAULT \a _enc_ctx or \a _buf is <tt>NULL</tt>.
  207. * \retval TH_EINVAL \a _buf_sz is not <tt>sizeof(int)</tt>, or rate control
  208. * is not enabled. The buffer has an implementation
  209. * defined minimum and maximum size and the value in _buf
  210. * will be adjusted to match the actual value set.
  211. * \retval TH_EIMPL Not supported by this implementation in the current
  212. * encoding mode.*/
  213. #define TH_ENCCTL_SET_RATE_BUFFER (22)
  214. /**Enable pass 1 of two-pass encoding mode and retrieve the first pass metrics.
  215. * Pass 1 mode must be enabled before the first frame is encoded, and a target
  216. * bitrate must have already been specified to the encoder.
  217. * Although this does not have to be the exact rate that will be used in the
  218. * second pass, closer values may produce better results.
  219. * The first call returns the size of the two-pass header data, along with some
  220. * placeholder content, and sets the encoder into pass 1 mode implicitly.
  221. * This call sets the encoder to pass 1 mode implicitly.
  222. * Then, a subsequent call must be made after each call to
  223. * th_encode_ycbcr_in() to retrieve the metrics for that frame.
  224. * An additional, final call must be made to retrieve the summary data,
  225. * containing such information as the total number of frames, etc.
  226. * This must be stored in place of the placeholder data that was returned
  227. * in the first call, before the frame metrics data.
  228. * All of this data must be presented back to the encoder during pass 2 using
  229. * #TH_ENCCTL_2PASS_IN.
  230. *
  231. * \param[out] <tt>char *</tt>_buf: Returns a pointer to internal storage
  232. * containing the two pass metrics data.
  233. * This storage is only valid until the next call, or until the
  234. * encoder context is freed, and must be copied by the
  235. * application.
  236. * \retval >=0 The number of bytes of metric data available in the
  237. * returned buffer.
  238. * \retval TH_EFAULT \a _enc_ctx or \a _buf is <tt>NULL</tt>.
  239. * \retval TH_EINVAL \a _buf_sz is not <tt>sizeof(char *)</tt>, no target
  240. * bitrate has been set, or the first call was made after
  241. * the first frame was submitted for encoding.
  242. * \retval TH_EIMPL Not supported by this implementation.*/
  243. #define TH_ENCCTL_2PASS_OUT (24)
  244. /**Submits two-pass encoding metric data collected the first encoding pass to
  245. * the second pass.
  246. * The first call must be made before the first frame is encoded, and a target
  247. * bitrate must have already been specified to the encoder.
  248. * It sets the encoder to pass 2 mode implicitly; this cannot be disabled.
  249. * The encoder may require reading data from some or all of the frames in
  250. * advance, depending on, e.g., the reservoir size used in the second pass.
  251. * You must call this function repeatedly before each frame to provide data
  252. * until either a) it fails to consume all of the data presented or b) all of
  253. * the pass 1 data has been consumed.
  254. * In the first case, you must save the remaining data to be presented after
  255. * the next frame.
  256. * You can call this function with a NULL argument to get an upper bound on
  257. * the number of bytes that will be required before the next frame.
  258. *
  259. * When pass 2 is first enabled, the default bit reservoir is set to the entire
  260. * file; this gives maximum flexibility but can lead to very high peak rates.
  261. * You can subsequently set it to another value with #TH_ENCCTL_SET_RATE_BUFFER
  262. * (e.g., to set it to the keyframe interval for non-live streaming), however,
  263. * you may then need to provide more data before the next frame.
  264. *
  265. * \param[in] _buf <tt>char[]</tt>: A buffer containing the data returned by
  266. * #TH_ENCCTL_2PASS_OUT in pass 1.
  267. * You may pass <tt>NULL</tt> for \a _buf to return an upper
  268. * bound on the number of additional bytes needed before the
  269. * next frame.
  270. * The summary data returned at the end of pass 1 must be at
  271. * the head of the buffer on the first call with a
  272. * non-<tt>NULL</tt> \a _buf, and the placeholder data
  273. * returned at the start of pass 1 should be omitted.
  274. * After each call you should advance this buffer by the number
  275. * of bytes consumed.
  276. * \retval >0 The number of bytes of metric data required/consumed.
  277. * \retval 0 No more data is required before the next frame.
  278. * \retval TH_EFAULT \a _enc_ctx is <tt>NULL</tt>.
  279. * \retval TH_EINVAL No target bitrate has been set, or the first call was
  280. * made after the first frame was submitted for
  281. * encoding.
  282. * \retval TH_ENOTFORMAT The data did not appear to be pass 1 from a compatible
  283. * implementation of this library.
  284. * \retval TH_EBADHEADER The data was invalid; this may be returned when
  285. * attempting to read an aborted pass 1 file that still
  286. * has the placeholder data in place of the summary
  287. * data.
  288. * \retval TH_EIMPL Not supported by this implementation.*/
  289. #define TH_ENCCTL_2PASS_IN (26)
  290. /**Sets the current encoding quality.
  291. * This is only valid so long as no bitrate has been specified, either through
  292. * the #th_info struct used to initialize the encoder or through
  293. * #TH_ENCCTL_SET_BITRATE (this restriction may be relaxed in a future
  294. * version).
  295. * If it is set before the headers are emitted, the target quality encoded in
  296. * them will be updated.
  297. *
  298. * \param[in] _buf <tt>int</tt>: The new target quality, in the range 0...63,
  299. * inclusive.
  300. * \retval 0 Success.
  301. * \retval TH_EFAULT \a _enc_ctx or \a _buf is <tt>NULL</tt>.
  302. * \retval TH_EINVAL A target bitrate has already been specified, or the
  303. * quality index was not in the range 0...63.
  304. * \retval TH_EIMPL Not supported by this implementation.*/
  305. #define TH_ENCCTL_SET_QUALITY (28)
  306. /**Sets the current encoding bitrate.
  307. * Once a bitrate is set, the encoder must use a rate-controlled mode for all
  308. * future frames (this restriction may be relaxed in a future version).
  309. * If it is set before the headers are emitted, the target bitrate encoded in
  310. * them will be updated.
  311. * Due to the buffer delay, the exact bitrate of each section of the encode is
  312. * not guaranteed.
  313. * The encoder may have already used more bits than allowed for the frames it
  314. * has encoded, expecting to make them up in future frames, or it may have
  315. * used fewer, holding the excess in reserve.
  316. * The exact transition between the two bitrates is not well-defined by this
  317. * API, but may be affected by flags set with #TH_ENCCTL_SET_RATE_FLAGS.
  318. * After a number of frames equal to the buffer delay, one may expect further
  319. * output to average at the target bitrate.
  320. *
  321. * \param[in] _buf <tt>long</tt>: The new target bitrate, in bits per second.
  322. * \retval 0 Success.
  323. * \retval TH_EFAULT \a _enc_ctx or \a _buf is <tt>NULL</tt>.
  324. * \retval TH_EINVAL The target bitrate was not positive.
  325. * \retval TH_EIMPL Not supported by this implementation.*/
  326. #define TH_ENCCTL_SET_BITRATE (30)
  327. /*@}*/
  328. /**\name TH_ENCCTL_SET_RATE_FLAGS flags
  329. * \anchor ratectlflags
  330. * These are the flags available for use with #TH_ENCCTL_SET_RATE_FLAGS.*/
  331. /*@{*/
  332. /**Drop frames to keep within bitrate buffer constraints.
  333. * This can have a severe impact on quality, but is the only way to ensure that
  334. * bitrate targets are met at low rates during sudden bursts of activity.*/
  335. #define TH_RATECTL_DROP_FRAMES (0x1)
  336. /**Ignore bitrate buffer overflows.
  337. * If the encoder uses so few bits that the reservoir of available bits
  338. * overflows, ignore the excess.
  339. * The encoder will not try to use these extra bits in future frames.
  340. * At high rates this may cause the result to be undersized, but allows a
  341. * client to play the stream using a finite buffer; it should normally be
  342. * enabled.*/
  343. #define TH_RATECTL_CAP_OVERFLOW (0x2)
  344. /**Ignore bitrate buffer underflows.
  345. * If the encoder uses so many bits that the reservoir of available bits
  346. * underflows, ignore the deficit.
  347. * The encoder will not try to make up these extra bits in future frames.
  348. * At low rates this may cause the result to be oversized; it should normally
  349. * be disabled.*/
  350. #define TH_RATECTL_CAP_UNDERFLOW (0x4)
  351. /*@}*/
  352. /**The quantization parameters used by VP3.*/
  353. extern const th_quant_info TH_VP31_QUANT_INFO;
  354. /**The Huffman tables used by VP3.*/
  355. extern const th_huff_code
  356. TH_VP31_HUFF_CODES[TH_NHUFFMAN_TABLES][TH_NDCT_TOKENS];
  357. /**\name Encoder state
  358. The following data structure is opaque, and its contents are not publicly
  359. defined by this API.
  360. Referring to its internals directly is unsupported, and may break without
  361. warning.*/
  362. /*@{*/
  363. /**The encoder context.*/
  364. typedef struct th_enc_ctx th_enc_ctx;
  365. /*@}*/
  366. /**\defgroup encfuncs Functions for Encoding*/
  367. /*@{*/
  368. /**\name Functions for encoding
  369. * You must link to <tt>libtheoraenc</tt> and <tt>libtheoradec</tt>
  370. * if you use any of the functions in this section.
  371. *
  372. * The functions are listed in the order they are used in a typical encode.
  373. * The basic steps are:
  374. * - Fill in a #th_info structure with details on the format of the video you
  375. * wish to encode.
  376. * - Allocate a #th_enc_ctx handle with th_encode_alloc().
  377. * - Perform any additional encoder configuration required with
  378. * th_encode_ctl().
  379. * - Repeatedly call th_encode_flushheader() to retrieve all the header
  380. * packets.
  381. * - For each uncompressed frame:
  382. * - Submit the uncompressed frame via th_encode_ycbcr_in()
  383. * - Repeatedly call th_encode_packetout() to retrieve any video data packets
  384. * that are ready.
  385. * - Call th_encode_free() to release all encoder memory.*/
  386. /*@{*/
  387. /**Allocates an encoder instance.
  388. * \param _info A #th_info struct filled with the desired encoding parameters.
  389. * \return The initialized #th_enc_ctx handle.
  390. * \retval NULL If the encoding parameters were invalid.*/
  391. extern th_enc_ctx *th_encode_alloc(const th_info *_info);
  392. /**Encoder control function.
  393. * This is used to provide advanced control the encoding process.
  394. * \param _enc A #th_enc_ctx handle.
  395. * \param _req The control code to process.
  396. * See \ref encctlcodes "the list of available control codes"
  397. * for details.
  398. * \param _buf The parameters for this control code.
  399. * \param _buf_sz The size of the parameter buffer.*/
  400. extern int th_encode_ctl(th_enc_ctx *_enc,int _req,void *_buf,size_t _buf_sz);
  401. /**Outputs the next header packet.
  402. * This should be called repeatedly after encoder initialization until it
  403. * returns 0 in order to get all of the header packets, in order, before
  404. * encoding actual video data.
  405. * \param _enc A #th_enc_ctx handle.
  406. * \param _comments The metadata to place in the comment header, when it is
  407. * encoded.
  408. * \param _op An <tt>ogg_packet</tt> structure to fill.
  409. * All of the elements of this structure will be set,
  410. * including a pointer to the header data.
  411. * The memory for the header data is owned by
  412. * <tt>libtheoraenc</tt>, and may be invalidated when the
  413. * next encoder function is called.
  414. * \return A positive value indicates that a header packet was successfully
  415. * produced.
  416. * \retval 0 No packet was produced, and no more header packets remain.
  417. * \retval TH_EFAULT \a _enc, \a _comments, or \a _op was <tt>NULL</tt>.*/
  418. extern int th_encode_flushheader(th_enc_ctx *_enc,
  419. th_comment *_comments,ogg_packet *_op);
  420. /**Submits an uncompressed frame to the encoder.
  421. * \param _enc A #th_enc_ctx handle.
  422. * \param _ycbcr A buffer of Y'CbCr data to encode.
  423. * \retval 0 Success.
  424. * \retval TH_EFAULT \a _enc or \a _ycbcr is <tt>NULL</tt>.
  425. * \retval TH_EINVAL The buffer size does not match the frame size the encoder
  426. * was initialized with, or encoding has already
  427. * completed.*/
  428. extern int th_encode_ycbcr_in(th_enc_ctx *_enc,th_ycbcr_buffer _ycbcr);
  429. /**Retrieves encoded video data packets.
  430. * This should be called repeatedly after each frame is submitted to flush any
  431. * encoded packets, until it returns 0.
  432. * The encoder will not buffer these packets as subsequent frames are
  433. * compressed, so a failure to do so will result in lost video data.
  434. * \note Currently the encoder operates in a one-frame-in, one-packet-out
  435. * manner.
  436. * However, this may be changed in the future.
  437. * \param _enc A #th_enc_ctx handle.
  438. * \param _last Set this flag to a non-zero value if no more uncompressed
  439. * frames will be submitted.
  440. * This ensures that a proper EOS flag is set on the last packet.
  441. * \param _op An <tt>ogg_packet</tt> structure to fill.
  442. * All of the elements of this structure will be set, including a
  443. * pointer to the video data.
  444. * The memory for the video data is owned by
  445. * <tt>libtheoraenc</tt>, and may be invalidated when the next
  446. * encoder function is called.
  447. * \return A positive value indicates that a video data packet was successfully
  448. * produced.
  449. * \retval 0 No packet was produced, and no more encoded video data
  450. * remains.
  451. * \retval TH_EFAULT \a _enc or \a _op was <tt>NULL</tt>.*/
  452. extern int th_encode_packetout(th_enc_ctx *_enc,int _last,ogg_packet *_op);
  453. /**Frees an allocated encoder instance.
  454. * \param _enc A #th_enc_ctx handle.*/
  455. extern void th_encode_free(th_enc_ctx *_enc);
  456. /*@}*/
  457. /*@}*/
  458. #if defined(__cplusplus)
  459. }
  460. #endif
  461. #endif