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