Chris@3: /******************************************************************** Chris@3: * * Chris@3: * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * Chris@3: * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * Chris@3: * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * Chris@3: * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * Chris@3: * * Chris@3: * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 * Chris@3: * by the Xiph.Org Foundation http://www.xiph.org/ * Chris@3: * * Chris@3: ******************************************************************** Chris@3: Chris@3: function: vorbis encode-engine setup Chris@3: last mod: $Id: vorbisenc.h 17021 2010-03-24 09:29:41Z xiphmont $ Chris@3: Chris@3: ********************************************************************/ Chris@3: Chris@3: /** \file Chris@3: * Libvorbisenc is a convenient API for setting up an encoding Chris@3: * environment using libvorbis. Libvorbisenc encapsulates the Chris@3: * actions needed to set up the encoder properly. Chris@3: */ Chris@3: Chris@3: #ifndef _OV_ENC_H_ Chris@3: #define _OV_ENC_H_ Chris@3: Chris@3: #ifdef __cplusplus Chris@3: extern "C" Chris@3: { Chris@3: #endif /* __cplusplus */ Chris@3: Chris@3: #include "codec.h" Chris@3: Chris@3: /** Chris@3: * This is the primary function within libvorbisenc for setting up managed Chris@3: * bitrate modes. Chris@3: * Chris@3: * Before this function is called, the \ref vorbis_info Chris@3: * struct should be initialized by using vorbis_info_init() from the libvorbis Chris@3: * API. After encoding, vorbis_info_clear() should be called. Chris@3: * Chris@3: * The max_bitrate, nominal_bitrate, and min_bitrate settings are used to set Chris@3: * constraints for the encoded file. This function uses these settings to Chris@3: * select the appropriate encoding mode and set it up. Chris@3: * Chris@3: * \param vi Pointer to an initialized \ref vorbis_info struct. Chris@3: * \param channels The number of channels to be encoded. Chris@3: * \param rate The sampling rate of the source audio. Chris@3: * \param max_bitrate Desired maximum bitrate (limit). -1 indicates unset. Chris@3: * \param nominal_bitrate Desired average, or central, bitrate. -1 indicates unset. Chris@3: * \param min_bitrate Desired minimum bitrate. -1 indicates unset. Chris@3: * Chris@3: * \return Zero for success, and negative values for failure. Chris@3: * Chris@3: * \retval 0 Success. Chris@3: * \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption. Chris@3: * \retval OV_EINVAL Invalid setup request, eg, out of range argument. Chris@3: * \retval OV_EIMPL Unimplemented mode; unable to comply with bitrate request. Chris@3: */ Chris@3: extern int vorbis_encode_init(vorbis_info *vi, Chris@3: long channels, Chris@3: long rate, Chris@3: Chris@3: long max_bitrate, Chris@3: long nominal_bitrate, Chris@3: long min_bitrate); Chris@3: Chris@3: /** Chris@3: * This function performs step-one of a three-step bitrate-managed encode Chris@3: * setup. It functions similarly to the one-step setup performed by \ref Chris@3: * vorbis_encode_init but allows an application to make further encode setup Chris@3: * tweaks using \ref vorbis_encode_ctl before finally calling \ref Chris@3: * vorbis_encode_setup_init to complete the setup process. Chris@3: * Chris@3: * Before this function is called, the \ref vorbis_info struct should be Chris@3: * initialized by using vorbis_info_init() from the libvorbis API. After Chris@3: * encoding, vorbis_info_clear() should be called. Chris@3: * Chris@3: * The max_bitrate, nominal_bitrate, and min_bitrate settings are used to set Chris@3: * constraints for the encoded file. This function uses these settings to Chris@3: * select the appropriate encoding mode and set it up. Chris@3: * Chris@3: * \param vi Pointer to an initialized vorbis_info struct. Chris@3: * \param channels The number of channels to be encoded. Chris@3: * \param rate The sampling rate of the source audio. Chris@3: * \param max_bitrate Desired maximum bitrate (limit). -1 indicates unset. Chris@3: * \param nominal_bitrate Desired average, or central, bitrate. -1 indicates unset. Chris@3: * \param min_bitrate Desired minimum bitrate. -1 indicates unset. Chris@3: * Chris@3: * \return Zero for success, and negative for failure. Chris@3: * Chris@3: * \retval 0 Success Chris@3: * \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption. Chris@3: * \retval OV_EINVAL Invalid setup request, eg, out of range argument. Chris@3: * \retval OV_EIMPL Unimplemented mode; unable to comply with bitrate request. Chris@3: */ Chris@3: extern int vorbis_encode_setup_managed(vorbis_info *vi, Chris@3: long channels, Chris@3: long rate, Chris@3: Chris@3: long max_bitrate, Chris@3: long nominal_bitrate, Chris@3: long min_bitrate); Chris@3: Chris@3: /** Chris@3: * This function performs step-one of a three-step variable bitrate Chris@3: * (quality-based) encode setup. It functions similarly to the one-step setup Chris@3: * performed by \ref vorbis_encode_init_vbr() but allows an application to Chris@3: * make further encode setup tweaks using \ref vorbis_encode_ctl() before Chris@3: * finally calling \ref vorbis_encode_setup_init to complete the setup Chris@3: * process. Chris@3: * Chris@3: * Before this function is called, the \ref vorbis_info struct should be Chris@3: * initialized by using \ref vorbis_info_init() from the libvorbis API. After Chris@3: * encoding, vorbis_info_clear() should be called. Chris@3: * Chris@3: * \param vi Pointer to an initialized vorbis_info struct. Chris@3: * \param channels The number of channels to be encoded. Chris@3: * \param rate The sampling rate of the source audio. Chris@3: * \param quality Desired quality level, currently from -0.1 to 1.0 (lo to hi). Chris@3: * Chris@3: * \return Zero for success, and negative values for failure. Chris@3: * Chris@3: * \retval 0 Success Chris@3: * \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption. Chris@3: * \retval OV_EINVAL Invalid setup request, eg, out of range argument. Chris@3: * \retval OV_EIMPL Unimplemented mode; unable to comply with quality level request. Chris@3: */ Chris@3: extern int vorbis_encode_setup_vbr(vorbis_info *vi, Chris@3: long channels, Chris@3: long rate, Chris@3: Chris@3: float quality Chris@3: ); Chris@3: Chris@3: /** Chris@3: * This is the primary function within libvorbisenc for setting up variable Chris@3: * bitrate ("quality" based) modes. Chris@3: * Chris@3: * Chris@3: * Before this function is called, the vorbis_info struct should be Chris@3: * initialized by using vorbis_info_init() from the libvorbis API. After Chris@3: * encoding, vorbis_info_clear() should be called. Chris@3: * Chris@3: * \param vi Pointer to an initialized vorbis_info struct. Chris@3: * \param channels The number of channels to be encoded. Chris@3: * \param rate The sampling rate of the source audio. Chris@3: * \param base_quality Desired quality level, currently from -0.1 to 1.0 (lo to hi). Chris@3: * Chris@3: * Chris@3: * \return Zero for success, or a negative number for failure. Chris@3: * Chris@3: * \retval 0 Success Chris@3: * \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption. Chris@3: * \retval OV_EINVAL Invalid setup request, eg, out of range argument. Chris@3: * \retval OV_EIMPL Unimplemented mode; unable to comply with quality level request. Chris@3: */ Chris@3: extern int vorbis_encode_init_vbr(vorbis_info *vi, Chris@3: long channels, Chris@3: long rate, Chris@3: Chris@3: float base_quality Chris@3: ); Chris@3: Chris@3: /** Chris@3: * This function performs the last stage of three-step encoding setup, as Chris@3: * described in the API overview under managed bitrate modes. Chris@3: * Chris@3: * Before this function is called, the \ref vorbis_info struct should be Chris@3: * initialized by using vorbis_info_init() from the libvorbis API, one of Chris@3: * \ref vorbis_encode_setup_managed() or \ref vorbis_encode_setup_vbr() called to Chris@3: * initialize the high-level encoding setup, and \ref vorbis_encode_ctl() Chris@3: * called if necessary to make encoding setup changes. Chris@3: * vorbis_encode_setup_init() finalizes the highlevel encoding structure into Chris@3: * a complete encoding setup after which the application may make no further Chris@3: * setup changes. Chris@3: * Chris@3: * After encoding, vorbis_info_clear() should be called. Chris@3: * Chris@3: * \param vi Pointer to an initialized \ref vorbis_info struct. Chris@3: * Chris@3: * \return Zero for success, and negative values for failure. Chris@3: * Chris@3: * \retval 0 Success. Chris@3: * \retval OV_EFAULT Internal logic fault; indicates a bug or heap/stack corruption. Chris@3: * Chris@3: * \retval OV_EINVAL Attempt to use vorbis_encode_setup_init() without first Chris@3: * calling one of vorbis_encode_setup_managed() or vorbis_encode_setup_vbr() to Chris@3: * initialize the high-level encoding setup Chris@3: * Chris@3: */ Chris@3: extern int vorbis_encode_setup_init(vorbis_info *vi); Chris@3: Chris@3: /** Chris@3: * This function implements a generic interface to miscellaneous encoder Chris@3: * settings similar to the classic UNIX 'ioctl()' system call. Applications Chris@3: * may use vorbis_encode_ctl() to query or set bitrate management or quality Chris@3: * mode details by using one of several \e request arguments detailed below. Chris@3: * vorbis_encode_ctl() must be called after one of Chris@3: * vorbis_encode_setup_managed() or vorbis_encode_setup_vbr(). When used Chris@3: * to modify settings, \ref vorbis_encode_ctl() must be called before \ref Chris@3: * vorbis_encode_setup_init(). Chris@3: * Chris@3: * \param vi Pointer to an initialized vorbis_info struct. Chris@3: * Chris@3: * \param number Specifies the desired action; See \ref encctlcodes "the list Chris@3: * of available requests". Chris@3: * Chris@3: * \param arg void * pointing to a data structure matching the request Chris@3: * argument. Chris@3: * Chris@3: * \retval 0 Success. Any further return information (such as the result of a Chris@3: * query) is placed into the storage pointed to by *arg. Chris@3: * Chris@3: * \retval OV_EINVAL Invalid argument, or an attempt to modify a setting after Chris@3: * calling vorbis_encode_setup_init(). Chris@3: * Chris@3: * \retval OV_EIMPL Unimplemented or unknown request Chris@3: */ Chris@3: extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg); Chris@3: Chris@3: /** Chris@3: * \deprecated This is a deprecated interface. Please use vorbis_encode_ctl() Chris@3: * with the \ref ovectl_ratemanage2_arg struct and \ref Chris@3: * OV_ECTL_RATEMANAGE2_GET and \ref OV_ECTL_RATEMANAGE2_SET calls in new code. Chris@3: * Chris@3: * The \ref ovectl_ratemanage_arg structure is used with vorbis_encode_ctl() Chris@3: * and the \ref OV_ECTL_RATEMANAGE_GET, \ref OV_ECTL_RATEMANAGE_SET, \ref Chris@3: * OV_ECTL_RATEMANAGE_AVG, \ref OV_ECTL_RATEMANAGE_HARD calls in order to Chris@3: * query and modify specifics of the encoder's bitrate management Chris@3: * configuration. Chris@3: */ Chris@3: struct ovectl_ratemanage_arg { Chris@3: int management_active; /**< nonzero if bitrate management is active*/ Chris@3: /** hard lower limit (in kilobits per second) below which the stream bitrate Chris@3: will never be allowed for any given bitrate_hard_window seconds of time.*/ Chris@3: long bitrate_hard_min; Chris@3: /** hard upper limit (in kilobits per second) above which the stream bitrate Chris@3: will never be allowed for any given bitrate_hard_window seconds of time.*/ Chris@3: long bitrate_hard_max; Chris@3: /** the window period (in seconds) used to regulate the hard bitrate minimum Chris@3: and maximum*/ Chris@3: double bitrate_hard_window; Chris@3: /** soft lower limit (in kilobits per second) below which the average bitrate Chris@3: tracker will start nudging the bitrate higher.*/ Chris@3: long bitrate_av_lo; Chris@3: /** soft upper limit (in kilobits per second) above which the average bitrate Chris@3: tracker will start nudging the bitrate lower.*/ Chris@3: long bitrate_av_hi; Chris@3: /** the window period (in seconds) used to regulate the average bitrate Chris@3: minimum and maximum.*/ Chris@3: double bitrate_av_window; Chris@3: /** Regulates the relative centering of the average and hard windows; in Chris@3: libvorbis 1.0 and 1.0.1, the hard window regulation overlapped but Chris@3: followed the average window regulation. In libvorbis 1.1 a bit-reservoir Chris@3: interface replaces the old windowing interface; the older windowing Chris@3: interface is simulated and this field has no effect.*/ Chris@3: double bitrate_av_window_center; Chris@3: }; Chris@3: Chris@3: /** Chris@3: * \name struct ovectl_ratemanage2_arg Chris@3: * Chris@3: * The ovectl_ratemanage2_arg structure is used with vorbis_encode_ctl() and Chris@3: * the OV_ECTL_RATEMANAGE2_GET and OV_ECTL_RATEMANAGE2_SET calls in order to Chris@3: * query and modify specifics of the encoder's bitrate management Chris@3: * configuration. Chris@3: * Chris@3: */ Chris@3: struct ovectl_ratemanage2_arg { Chris@3: int management_active; /**< nonzero if bitrate management is active */ Chris@3: /** Lower allowed bitrate limit in kilobits per second */ Chris@3: long bitrate_limit_min_kbps; Chris@3: /** Upper allowed bitrate limit in kilobits per second */ Chris@3: long bitrate_limit_max_kbps; Chris@3: long bitrate_limit_reservoir_bits; /**struct ovectl_ratemanage2_arg * Chris@3: * Chris@3: * Used to query the current encoder bitrate management setting. Also used to Chris@3: * initialize fields of an ovectl_ratemanage2_arg structure for use with Chris@3: * \ref OV_ECTL_RATEMANAGE2_SET. Chris@3: */ Chris@3: #define OV_ECTL_RATEMANAGE2_GET 0x14 Chris@3: Chris@3: /** Chris@3: * Set the current encoder bitrate management settings. Chris@3: * Chris@3: * Argument: struct ovectl_ratemanage2_arg * Chris@3: * Chris@3: * Used to set the current encoder bitrate management settings to the values Chris@3: * listed in the ovectl_ratemanage2_arg. Passing a NULL pointer will disable Chris@3: * bitrate management. Chris@3: */ Chris@3: #define OV_ECTL_RATEMANAGE2_SET 0x15 Chris@3: Chris@3: /** Chris@3: * Returns the current encoder hard-lowpass setting (kHz) in the double Chris@3: * pointed to by arg. Chris@3: * Chris@3: * Argument: double * Chris@3: */ Chris@3: #define OV_ECTL_LOWPASS_GET 0x20 Chris@3: Chris@3: /** Chris@3: * Sets the encoder hard-lowpass to the value (kHz) pointed to by arg. Valid Chris@3: * lowpass settings range from 2 to 99. Chris@3: * Chris@3: * Argument: double * Chris@3: */ Chris@3: #define OV_ECTL_LOWPASS_SET 0x21 Chris@3: Chris@3: /** Chris@3: * Returns the current encoder impulse block setting in the double pointed Chris@3: * to by arg. Chris@3: * Chris@3: * Argument: double * Chris@3: */ Chris@3: #define OV_ECTL_IBLOCK_GET 0x30 Chris@3: Chris@3: /** Chris@3: * Sets the impulse block bias to the the value pointed to by arg. Chris@3: * Chris@3: * Argument: double * Chris@3: * Chris@3: * Valid range is -15.0 to 0.0 [default]. A negative impulse block bias will Chris@3: * direct to encoder to use more bits when incoding short blocks that contain Chris@3: * strong impulses, thus improving the accuracy of impulse encoding. Chris@3: */ Chris@3: #define OV_ECTL_IBLOCK_SET 0x31 Chris@3: Chris@3: /** Chris@3: * Returns the current encoder coupling setting in the int pointed Chris@3: * to by arg. Chris@3: * Chris@3: * Argument: int * Chris@3: */ Chris@3: #define OV_ECTL_COUPLING_GET 0x40 Chris@3: Chris@3: /** Chris@3: * Enables/disables channel coupling in multichannel encoding according to arg. Chris@3: * Chris@3: * Argument: int * Chris@3: * Chris@3: * Zero disables channel coupling for multichannel inputs, nonzer enables Chris@3: * channel coupling. Setting has no effect on monophonic encoding or Chris@3: * multichannel counts that do not offer coupling. At present, coupling is Chris@3: * available for stereo and 5.1 encoding. Chris@3: */ Chris@3: #define OV_ECTL_COUPLING_SET 0x41 Chris@3: Chris@3: /* deprecated rate management supported only for compatibility */ Chris@3: Chris@3: /** Chris@3: * Old interface to querying bitrate management settings. Chris@3: * Chris@3: * Deprecated after move to bit-reservoir style management in 1.1 rendered Chris@3: * this interface partially obsolete. Chris@3: Chris@3: * \deprecated Please use \ref OV_ECTL_RATEMANAGE2_GET instead. Chris@3: * Chris@3: * Argument: struct ovectl_ratemanage_arg * Chris@3: */ Chris@3: #define OV_ECTL_RATEMANAGE_GET 0x10 Chris@3: /** Chris@3: * Old interface to modifying bitrate management settings. Chris@3: * Chris@3: * deprecated after move to bit-reservoir style management in 1.1 rendered Chris@3: * this interface partially obsolete. Chris@3: * Chris@3: * \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead. Chris@3: * Chris@3: * Argument: struct ovectl_ratemanage_arg * Chris@3: */ Chris@3: #define OV_ECTL_RATEMANAGE_SET 0x11 Chris@3: /** Chris@3: * Old interface to setting average-bitrate encoding mode. Chris@3: * Chris@3: * Deprecated after move to bit-reservoir style management in 1.1 rendered Chris@3: * this interface partially obsolete. Chris@3: * Chris@3: * \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead. Chris@3: * Chris@3: * Argument: struct ovectl_ratemanage_arg * Chris@3: */ Chris@3: #define OV_ECTL_RATEMANAGE_AVG 0x12 Chris@3: /** Chris@3: * Old interface to setting bounded-bitrate encoding modes. Chris@3: * Chris@3: * deprecated after move to bit-reservoir style management in 1.1 rendered Chris@3: * this interface partially obsolete. Chris@3: * Chris@3: * \deprecated Please use \ref OV_ECTL_RATEMANAGE2_SET instead. Chris@3: * Chris@3: * Argument: struct ovectl_ratemanage_arg * Chris@3: */ Chris@3: #define OV_ECTL_RATEMANAGE_HARD 0x13 Chris@3: Chris@3: /*@}*/ Chris@3: Chris@3: Chris@3: Chris@3: #ifdef __cplusplus Chris@3: } Chris@3: #endif /* __cplusplus */ Chris@3: Chris@3: #endif