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