media/libtheora/include/theora/theoraenc.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial