media/libvorbis/include/vorbis/vorbisenc.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /********************************************************************
     2  *                                                                  *
     3  * THIS FILE IS PART OF THE OggVorbis 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 OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
     9  * by the Xiph.Org Foundation http://www.xiph.org/                  *
    10  *                                                                  *
    11  ********************************************************************
    13  function: vorbis encode-engine setup
    14  last mod: $Id: vorbisenc.h 17021 2010-03-24 09:29:41Z xiphmont $
    16  ********************************************************************/
    18 /** \file
    19  * Libvorbisenc is a convenient API for setting up an encoding
    20  * environment using libvorbis. Libvorbisenc encapsulates the
    21  * actions needed to set up the encoder properly.
    22  */
    24 #ifndef _OV_ENC_H_
    25 #define _OV_ENC_H_
    27 #ifdef __cplusplus
    28 extern "C"
    29 {
    30 #endif /* __cplusplus */
    32 #include "codec.h"
    34 /**
    35  * This is the primary function within libvorbisenc for setting up managed
    36  * bitrate modes.
    37  *
    38  * Before this function is called, the \ref vorbis_info
    39  * struct should be initialized by using vorbis_info_init() from the libvorbis
    40  * API.  After encoding, vorbis_info_clear() should be called.
    41  *
    42  * The max_bitrate, nominal_bitrate, and min_bitrate settings are used to set
    43  * constraints for the encoded file.  This function uses these settings to
    44  * select the appropriate encoding mode and set it up.
    45  *
    46  * \param vi               Pointer to an initialized \ref vorbis_info struct.
    47  * \param channels         The number of channels to be encoded.
    48  * \param rate             The sampling rate of the source audio.
    49  * \param max_bitrate      Desired maximum bitrate (limit). -1 indicates unset.
    50  * \param nominal_bitrate  Desired average, or central, bitrate. -1 indicates unset.
    51  * \param min_bitrate      Desired minimum bitrate. -1 indicates unset.
    52  *
    53  * \return Zero for success, and negative values for failure.
    54  *
    55  * \retval 0          Success.
    56  * \retval OV_EFAULT  Internal logic fault; indicates a bug or heap/stack corruption.
    57  * \retval OV_EINVAL  Invalid setup request, eg, out of range argument.
    58  * \retval OV_EIMPL   Unimplemented mode; unable to comply with bitrate request.
    59  */
    60 extern int vorbis_encode_init(vorbis_info *vi,
    61                               long channels,
    62                               long rate,
    64                               long max_bitrate,
    65                               long nominal_bitrate,
    66                               long min_bitrate);
    68 /**
    69  * This function performs step-one of a three-step bitrate-managed encode
    70  * setup.  It functions similarly to the one-step setup performed by \ref
    71  * vorbis_encode_init but allows an application to make further encode setup
    72  * tweaks using \ref vorbis_encode_ctl before finally calling \ref
    73  * vorbis_encode_setup_init to complete the setup process.
    74  *
    75  * Before this function is called, the \ref vorbis_info struct should be
    76  * initialized by using vorbis_info_init() from the libvorbis API.  After
    77  * encoding, vorbis_info_clear() should be called.
    78  *
    79  * The max_bitrate, nominal_bitrate, and min_bitrate settings are used to set
    80  * constraints for the encoded file.  This function uses these settings to
    81  * select the appropriate encoding mode and set it up.
    82  *
    83  * \param vi                Pointer to an initialized vorbis_info struct.
    84  * \param channels          The number of channels to be encoded.
    85  * \param rate              The sampling rate of the source audio.
    86  * \param max_bitrate       Desired maximum bitrate (limit). -1 indicates unset.
    87  * \param nominal_bitrate   Desired average, or central, bitrate. -1 indicates unset.
    88  * \param min_bitrate       Desired minimum bitrate. -1 indicates unset.
    89  *
    90  * \return Zero for success, and negative for failure.
    91  *
    92  * \retval 0           Success
    93  * \retval OV_EFAULT   Internal logic fault; indicates a bug or heap/stack corruption.
    94  * \retval OV_EINVAL   Invalid setup request, eg, out of range argument.
    95  * \retval OV_EIMPL    Unimplemented mode; unable to comply with bitrate request.
    96  */
    97 extern int vorbis_encode_setup_managed(vorbis_info *vi,
    98                                        long channels,
    99                                        long rate,
   101                                        long max_bitrate,
   102                                        long nominal_bitrate,
   103                                        long min_bitrate);
   105 /**
   106  * This function performs step-one of a three-step variable bitrate
   107  * (quality-based) encode setup.  It functions similarly to the one-step setup
   108  * performed by \ref vorbis_encode_init_vbr() but allows an application to
   109  * make further encode setup tweaks using \ref vorbis_encode_ctl() before
   110  * finally calling \ref vorbis_encode_setup_init to complete the setup
   111  * process.
   112  *
   113  * Before this function is called, the \ref vorbis_info struct should be
   114  * initialized by using \ref vorbis_info_init() from the libvorbis API.  After
   115  * encoding, vorbis_info_clear() should be called.
   116  *
   117  * \param vi        Pointer to an initialized vorbis_info struct.
   118  * \param channels  The number of channels to be encoded.
   119  * \param rate      The sampling rate of the source audio.
   120  * \param quality   Desired quality level, currently from -0.1 to 1.0 (lo to hi).
   121  *
   122  * \return Zero for success, and negative values for failure.
   123  *
   124  * \retval  0          Success
   125  * \retval  OV_EFAULT  Internal logic fault; indicates a bug or heap/stack corruption.
   126  * \retval  OV_EINVAL  Invalid setup request, eg, out of range argument.
   127  * \retval  OV_EIMPL   Unimplemented mode; unable to comply with quality level request.
   128  */
   129 extern int vorbis_encode_setup_vbr(vorbis_info *vi,
   130                                   long channels,
   131                                   long rate,
   133                                   float quality
   134                                   );
   136 /**
   137  * This is the primary function within libvorbisenc for setting up variable
   138  * bitrate ("quality" based) modes.
   139  *
   140  *
   141  * Before this function is called, the vorbis_info struct should be
   142  * initialized by using vorbis_info_init() from the libvorbis API. After
   143  * encoding, vorbis_info_clear() should be called.
   144  *
   145  * \param vi           Pointer to an initialized vorbis_info struct.
   146  * \param channels     The number of channels to be encoded.
   147  * \param rate         The sampling rate of the source audio.
   148  * \param base_quality Desired quality level, currently from -0.1 to 1.0 (lo to hi).
   149  *
   150  *
   151  * \return Zero for success, or a negative number for failure.
   152  *
   153  * \retval 0           Success
   154  * \retval OV_EFAULT   Internal logic fault; indicates a bug or heap/stack corruption.
   155  * \retval OV_EINVAL   Invalid setup request, eg, out of range argument.
   156  * \retval OV_EIMPL    Unimplemented mode; unable to comply with quality level request.
   157  */
   158 extern int vorbis_encode_init_vbr(vorbis_info *vi,
   159                                   long channels,
   160                                   long rate,
   162                                   float base_quality
   163                                   );
   165 /**
   166  * This function performs the last stage of three-step encoding setup, as
   167  * described in the API overview under managed bitrate modes.
   168  *
   169  * Before this function is called, the \ref vorbis_info struct should be
   170  * initialized by using vorbis_info_init() from the libvorbis API, one of
   171  * \ref vorbis_encode_setup_managed() or \ref vorbis_encode_setup_vbr() called to
   172  * initialize the high-level encoding setup, and \ref vorbis_encode_ctl()
   173  * called if necessary to make encoding setup changes.
   174  * vorbis_encode_setup_init() finalizes the highlevel encoding structure into
   175  * a complete encoding setup after which the application may make no further
   176  * setup changes.
   177  *
   178  * After encoding, vorbis_info_clear() should be called.
   179  *
   180  * \param vi Pointer to an initialized \ref vorbis_info struct.
   181  *
   182  * \return Zero for success, and negative values for failure.
   183  *
   184  * \retval  0           Success.
   185  * \retval  OV_EFAULT  Internal logic fault; indicates a bug or heap/stack corruption.
   186  *
   187  * \retval OV_EINVAL   Attempt to use vorbis_encode_setup_init() without first
   188  * calling one of vorbis_encode_setup_managed() or vorbis_encode_setup_vbr() to
   189  * initialize the high-level encoding setup
   190  *
   191  */
   192 extern int vorbis_encode_setup_init(vorbis_info *vi);
   194 /**
   195  * This function implements a generic interface to miscellaneous encoder
   196  * settings similar to the classic UNIX 'ioctl()' system call.  Applications
   197  * may use vorbis_encode_ctl() to query or set bitrate management or quality
   198  * mode details by using one of several \e request arguments detailed below.
   199  * vorbis_encode_ctl() must be called after one of
   200  * vorbis_encode_setup_managed() or vorbis_encode_setup_vbr().  When used
   201  * to modify settings, \ref vorbis_encode_ctl() must be called before \ref
   202  * vorbis_encode_setup_init().
   203  *
   204  * \param vi      Pointer to an initialized vorbis_info struct.
   205  *
   206  * \param number Specifies the desired action; See \ref encctlcodes "the list
   207  * of available requests".
   208  *
   209  * \param arg void * pointing to a data structure matching the request
   210  * argument.
   211  *
   212  * \retval 0          Success. Any further return information (such as the result of a
   213  * query) is placed into the storage pointed to by *arg.
   214  *
   215  * \retval OV_EINVAL  Invalid argument, or an attempt to modify a setting after
   216  * calling vorbis_encode_setup_init().
   217  *
   218  * \retval OV_EIMPL   Unimplemented or unknown request
   219  */
   220 extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
   222 /**
   223  * \deprecated This is a deprecated interface. Please use vorbis_encode_ctl()
   224  * with the \ref ovectl_ratemanage2_arg struct and \ref
   225  * OV_ECTL_RATEMANAGE2_GET and \ref OV_ECTL_RATEMANAGE2_SET calls in new code.
   226  *
   227  * The \ref ovectl_ratemanage_arg structure is used with vorbis_encode_ctl()
   228  * and the \ref OV_ECTL_RATEMANAGE_GET, \ref OV_ECTL_RATEMANAGE_SET, \ref
   229  * OV_ECTL_RATEMANAGE_AVG, \ref OV_ECTL_RATEMANAGE_HARD calls in order to
   230  * query and modify specifics of the encoder's bitrate management
   231  * configuration.
   232 */
   233 struct ovectl_ratemanage_arg {
   234   int    management_active; /**< nonzero if bitrate management is active*/
   235 /** hard lower limit (in kilobits per second) below which the stream bitrate
   236     will never be allowed for any given bitrate_hard_window seconds of time.*/
   237   long   bitrate_hard_min;
   238 /** hard upper limit (in kilobits per second) above which the stream bitrate
   239     will never be allowed for any given bitrate_hard_window seconds of time.*/
   240   long   bitrate_hard_max;
   241 /** the window period (in seconds) used to regulate the hard bitrate minimum
   242     and maximum*/
   243   double bitrate_hard_window;
   244 /** soft lower limit (in kilobits per second) below which the average bitrate
   245     tracker will start nudging the bitrate higher.*/
   246   long   bitrate_av_lo;
   247 /** soft upper limit (in kilobits per second) above which the average bitrate
   248     tracker will start nudging the bitrate lower.*/
   249   long   bitrate_av_hi;
   250 /** the window period (in seconds) used to regulate the average bitrate
   251     minimum and maximum.*/
   252   double bitrate_av_window;
   253 /** Regulates the relative centering of the average and hard windows; in
   254     libvorbis 1.0 and 1.0.1, the hard window regulation overlapped but
   255     followed the average window regulation. In libvorbis 1.1 a bit-reservoir
   256     interface replaces the old windowing interface; the older windowing
   257     interface is simulated and this field has no effect.*/
   258   double bitrate_av_window_center;
   259 };
   261 /**
   262  * \name struct ovectl_ratemanage2_arg
   263  *
   264  * The ovectl_ratemanage2_arg structure is used with vorbis_encode_ctl() and
   265  * the OV_ECTL_RATEMANAGE2_GET and OV_ECTL_RATEMANAGE2_SET calls in order to
   266  * query and modify specifics of the encoder's bitrate management
   267  * configuration.
   268  *
   269 */
   270 struct ovectl_ratemanage2_arg {
   271   int    management_active; /**< nonzero if bitrate management is active */
   272 /** Lower allowed bitrate limit in kilobits per second */
   273   long   bitrate_limit_min_kbps;
   274 /** Upper allowed bitrate limit in kilobits per second */
   275   long   bitrate_limit_max_kbps;
   276   long   bitrate_limit_reservoir_bits; /**<Size of the bitrate reservoir in bits */
   277 /** Regulates the bitrate reservoir's preferred fill level in a range from 0.0
   278  * to 1.0; 0.0 tries to bank bits to buffer against future bitrate spikes, 1.0
   279  * buffers against future sudden drops in instantaneous bitrate. Default is
   280  * 0.1
   281  */
   282   double bitrate_limit_reservoir_bias;
   283 /** Average bitrate setting in kilobits per second */
   284   long   bitrate_average_kbps;
   285 /** Slew rate limit setting for average bitrate adjustment; sets the minimum
   286  *  time in seconds the bitrate tracker may swing from one extreme to the
   287  *  other when boosting or damping average bitrate.
   288  */
   289   double bitrate_average_damping;
   290 };
   293 /**
   294  * \name vorbis_encode_ctl() codes
   295  *
   296  * \anchor encctlcodes
   297  *
   298  * These values are passed as the \c number parameter of vorbis_encode_ctl().
   299  * The type of the referent of that function's \c arg pointer depends on these
   300  * codes.
   301  */
   302 /*@{*/
   304 /**
   305  * Query the current encoder bitrate management setting.
   306  *
   307  *Argument: <tt>struct ovectl_ratemanage2_arg *</tt>
   308  *
   309  * Used to query the current encoder bitrate management setting. Also used to
   310  * initialize fields of an ovectl_ratemanage2_arg structure for use with
   311  * \ref OV_ECTL_RATEMANAGE2_SET.
   312  */
   313 #define OV_ECTL_RATEMANAGE2_GET      0x14
   315 /**
   316  * Set the current encoder bitrate management settings.
   317  *
   318  * Argument: <tt>struct ovectl_ratemanage2_arg *</tt>
   319  *
   320  * Used to set the current encoder bitrate management settings to the values
   321  * listed in the ovectl_ratemanage2_arg. Passing a NULL pointer will disable
   322  * bitrate management.
   323 */
   324 #define OV_ECTL_RATEMANAGE2_SET      0x15
   326 /**
   327  * Returns the current encoder hard-lowpass setting (kHz) in the double
   328  * pointed to by arg.
   329  *
   330  * Argument: <tt>double *</tt>
   331 */
   332 #define OV_ECTL_LOWPASS_GET          0x20
   334 /**
   335  *  Sets the encoder hard-lowpass to the value (kHz) pointed to by arg. Valid
   336  *  lowpass settings range from 2 to 99.
   337  *
   338  * Argument: <tt>double *</tt>
   339 */
   340 #define OV_ECTL_LOWPASS_SET          0x21
   342 /**
   343  *  Returns the current encoder impulse block setting in the double pointed
   344  *  to by arg.
   345  *
   346  * Argument: <tt>double *</tt>
   347 */
   348 #define OV_ECTL_IBLOCK_GET           0x30
   350 /**
   351  *  Sets the impulse block bias to the the value pointed to by arg.
   352  *
   353  * Argument: <tt>double *</tt>
   354  *
   355  *  Valid range is -15.0 to 0.0 [default]. A negative impulse block bias will
   356  *  direct to encoder to use more bits when incoding short blocks that contain
   357  *  strong impulses, thus improving the accuracy of impulse encoding.
   358  */
   359 #define OV_ECTL_IBLOCK_SET           0x31
   361 /**
   362  *  Returns the current encoder coupling setting in the int pointed
   363  *  to by arg.
   364  *
   365  * Argument: <tt>int *</tt>
   366 */
   367 #define OV_ECTL_COUPLING_GET         0x40
   369 /**
   370  *  Enables/disables channel coupling in multichannel encoding according to arg.
   371  *
   372  * Argument: <tt>int *</tt>
   373  *
   374  *  Zero disables channel coupling for multichannel inputs, nonzer enables
   375  *  channel coupling.  Setting has no effect on monophonic encoding or
   376  *  multichannel counts that do not offer coupling.  At present, coupling is
   377  *  available for stereo and 5.1 encoding.
   378  */
   379 #define OV_ECTL_COUPLING_SET         0x41
   381   /* deprecated rate management supported only for compatibility */
   383 /**
   384  * Old interface to querying bitrate management settings.
   385  *
   386  * Deprecated after move to bit-reservoir style management in 1.1 rendered
   387  * this interface partially obsolete.
   389  * \deprecated Please use \ref OV_ECTL_RATEMANAGE2_GET instead.
   390  *
   391  * Argument: <tt>struct ovectl_ratemanage_arg *</tt>
   392  */
   393 #define OV_ECTL_RATEMANAGE_GET       0x10
   394 /**
   395  * Old interface to modifying bitrate management settings.
   396  *
   397  *  deprecated after move to bit-reservoir style management in 1.1 rendered
   398  *  this interface partially obsolete.
   399  *
   400  * \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead.
   401  *
   402  * Argument: <tt>struct ovectl_ratemanage_arg *</tt>
   403  */
   404 #define OV_ECTL_RATEMANAGE_SET       0x11
   405 /**
   406  * Old interface to setting average-bitrate encoding mode.
   407  *
   408  * Deprecated after move to bit-reservoir style management in 1.1 rendered
   409  * this interface partially obsolete.
   410  *
   411  *  \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead.
   412  *
   413  * Argument: <tt>struct ovectl_ratemanage_arg *</tt>
   414  */
   415 #define OV_ECTL_RATEMANAGE_AVG       0x12
   416 /**
   417  * Old interface to setting bounded-bitrate encoding modes.
   418  *
   419  * deprecated after move to bit-reservoir style management in 1.1 rendered
   420  * this interface partially obsolete.
   421  *
   422  *  \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead.
   423  *
   424  * Argument: <tt>struct ovectl_ratemanage_arg *</tt>
   425  */
   426 #define OV_ECTL_RATEMANAGE_HARD      0x13
   428 /*@}*/
   432 #ifdef __cplusplus
   433 }
   434 #endif /* __cplusplus */
   436 #endif

mercurial