diff --git a/src/add-ons/media/plugins/avcodec/libavcodec/aac.h b/src/add-ons/media/plugins/avcodec/libavcodec/aac.h new file mode 100644 index 0000000000..83171e2c29 --- /dev/null +++ b/src/add-ons/media/plugins/avcodec/libavcodec/aac.h @@ -0,0 +1,275 @@ +/* + * AAC definitions and structures + * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org ) + * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com ) + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file aac.h + * AAC definitions and structures + * @author Oded Shimon ( ods15 ods15 dyndns org ) + * @author Maxim Gavrilov ( maxim.gavrilov gmail com ) + */ + +#ifndef FFMPEG_AAC_H +#define FFMPEG_AAC_H + +#include "avcodec.h" +#include "dsputil.h" +#include "mpeg4audio.h" + +#include + +#define AAC_INIT_VLC_STATIC(num, size) \ + INIT_VLC_STATIC(&vlc_spectral[num], 6, ff_aac_spectral_sizes[num], \ + ff_aac_spectral_bits[num], sizeof( ff_aac_spectral_bits[num][0]), sizeof( ff_aac_spectral_bits[num][0]), \ + ff_aac_spectral_codes[num], sizeof(ff_aac_spectral_codes[num][0]), sizeof(ff_aac_spectral_codes[num][0]), \ + size); + +#define MAX_CHANNELS 64 +#define MAX_ELEM_ID 16 + +#define TNS_MAX_ORDER 20 +#define PNS_MEAN_ENERGY 3719550720.0f // sqrt(3.0) * 1<<31 + +enum AudioObjectType { + AOT_NULL, + // Support? Name + AOT_AAC_MAIN, ///< Y Main + AOT_AAC_LC, ///< Y Low Complexity + AOT_AAC_SSR, ///< N (code in SoC repo) Scalable Sample Rate + AOT_AAC_LTP, ///< N (code in SoC repo) Long Term Prediction + AOT_SBR, ///< N (in progress) Spectral Band Replication + AOT_AAC_SCALABLE, ///< N Scalable + AOT_TWINVQ, ///< N Twin Vector Quantizer + AOT_CELP, ///< N Code Excited Linear Prediction + AOT_HVXC, ///< N Harmonic Vector eXcitation Coding + AOT_TTSI = 12, ///< N Text-To-Speech Interface + AOT_MAINSYNTH, ///< N Main Synthesis + AOT_WAVESYNTH, ///< N Wavetable Synthesis + AOT_MIDI, ///< N General MIDI + AOT_SAFX, ///< N Algorithmic Synthesis and Audio Effects + AOT_ER_AAC_LC, ///< N Error Resilient Low Complexity + AOT_ER_AAC_LTP = 19, ///< N Error Resilient Long Term Prediction + AOT_ER_AAC_SCALABLE, ///< N Error Resilient Scalable + AOT_ER_TWINVQ, ///< N Error Resilient Twin Vector Quantizer + AOT_ER_BSAC, ///< N Error Resilient Bit-Sliced Arithmetic Coding + AOT_ER_AAC_LD, ///< N Error Resilient Low Delay + AOT_ER_CELP, ///< N Error Resilient Code Excited Linear Prediction + AOT_ER_HVXC, ///< N Error Resilient Harmonic Vector eXcitation Coding + AOT_ER_HILN, ///< N Error Resilient Harmonic and Individual Lines plus Noise + AOT_ER_PARAM, ///< N Error Resilient Parametric + AOT_SSC, ///< N SinuSoidal Coding +}; + +enum RawDataBlockType { + TYPE_SCE, + TYPE_CPE, + TYPE_CCE, + TYPE_LFE, + TYPE_DSE, + TYPE_PCE, + TYPE_FIL, + TYPE_END, +}; + +enum ExtensionPayloadID { + EXT_FILL, + EXT_FILL_DATA, + EXT_DATA_ELEMENT, + EXT_DYNAMIC_RANGE = 0xb, + EXT_SBR_DATA = 0xd, + EXT_SBR_DATA_CRC = 0xe, +}; + +enum WindowSequence { + ONLY_LONG_SEQUENCE, + LONG_START_SEQUENCE, + EIGHT_SHORT_SEQUENCE, + LONG_STOP_SEQUENCE, +}; + +enum BandType { + ZERO_BT = 0, ///< Scalefactors and spectral data are all zero. + FIRST_PAIR_BT = 5, ///< This and later band types encode two values (rather than four) with one code word. + ESC_BT = 11, ///< Spectral data are coded with an escape sequence. + NOISE_BT = 13, ///< Spectral data are scaled white noise not coded in the bitstream. + INTENSITY_BT2 = 14, ///< Scalefactor data are intensity stereo positions. + INTENSITY_BT = 15, ///< Scalefactor data are intensity stereo positions. +}; + +#define IS_CODEBOOK_UNSIGNED(x) ((x - 1) & 10) + +enum ChannelPosition { + AAC_CHANNEL_FRONT = 1, + AAC_CHANNEL_SIDE = 2, + AAC_CHANNEL_BACK = 3, + AAC_CHANNEL_LFE = 4, + AAC_CHANNEL_CC = 5, +}; + +/** + * The point during decoding at which channel coupling is applied. + */ +enum CouplingPoint { + BEFORE_TNS, + BETWEEN_TNS_AND_IMDCT, + AFTER_IMDCT = 3, +}; + +/** + * Individual Channel Stream + */ +typedef struct { + uint8_t max_sfb; ///< number of scalefactor bands per group + enum WindowSequence window_sequence[2]; + uint8_t use_kb_window[2]; ///< If set, use Kaiser-Bessel window, otherwise use a sinus window. + int num_window_groups; + uint8_t group_len[8]; + const uint16_t *swb_offset; ///< table of offsets to the lowest spectral coefficient of a scalefactor band, sfb, for a particular window + int num_swb; ///< number of scalefactor window bands + int num_windows; + int tns_max_bands; +} IndividualChannelStream; + +/** + * Temporal Noise Shaping + */ +typedef struct { + int present; + int n_filt[8]; + int length[8][4]; + int direction[8][4]; + int order[8][4]; + float coef[8][4][TNS_MAX_ORDER]; +} TemporalNoiseShaping; + +/** + * Dynamic Range Control - decoded from the bitstream but not processed further. + */ +typedef struct { + int pce_instance_tag; ///< Indicates with which program the DRC info is associated. + int dyn_rng_sgn[17]; ///< DRC sign information; 0 - positive, 1 - negative + int dyn_rng_ctl[17]; ///< DRC magnitude information + int exclude_mask[MAX_CHANNELS]; ///< Channels to be excluded from DRC processing. + int band_incr; ///< Number of DRC bands greater than 1 having DRC info. + int interpolation_scheme; ///< Indicates the interpolation scheme used in the SBR QMF domain. + int band_top[17]; ///< Indicates the top of the i-th DRC band in units of 4 spectral lines. + int prog_ref_level; /**< A reference level for the long-term program audio level for all + * channels combined. + */ +} DynamicRangeControl; + +typedef struct { + int num_pulse; + int pos[4]; + int amp[4]; +} Pulse; + +/** + * coupling parameters + */ +typedef struct { + enum CouplingPoint coupling_point; ///< The point during decoding at which coupling is applied. + int num_coupled; ///< number of target elements + enum RawDataBlockType type[8]; ///< Type of channel element to be coupled - SCE or CPE. + int id_select[8]; ///< element id + int ch_select[8]; /**< [0] shared list of gains; [1] list of gains for left channel; + * [2] list of gains for right channel; [3] lists of gains for both channels + */ + float gain[16][120]; +} ChannelCoupling; + +/** + * Single Channel Element - used for both SCE and LFE elements. + */ +typedef struct { + IndividualChannelStream ics; + TemporalNoiseShaping tns; + enum BandType band_type[120]; ///< band types + int band_type_run_end[120]; ///< band type run end points + float sf[120]; ///< scalefactors + DECLARE_ALIGNED_16(float, coeffs[1024]); ///< coefficients for IMDCT + DECLARE_ALIGNED_16(float, saved[512]); ///< overlap + DECLARE_ALIGNED_16(float, ret[1024]); ///< PCM output +} SingleChannelElement; + +/** + * channel element - generic struct for SCE/CPE/CCE/LFE + */ +typedef struct { + // CPE specific + uint8_t ms_mask[120]; ///< Set if mid/side stereo is used for each scalefactor window band + // shared + SingleChannelElement ch[2]; + // CCE specific + ChannelCoupling coup; +} ChannelElement; + +/** + * main AAC context + */ +typedef struct { + AVCodecContext * avccontext; + + MPEG4AudioConfig m4ac; + + int is_saved; ///< Set if elements have stored overlap from previous frame. + DynamicRangeControl che_drc; + + /** + * @defgroup elements + * @{ + */ + enum ChannelPosition che_pos[4][MAX_ELEM_ID]; /**< channel element channel mapping with the + * first index as the first 4 raw data block types + */ + ChannelElement * che[4][MAX_ELEM_ID]; + /** @} */ + + /** + * @defgroup temporary aligned temporary buffers (We do not want to have these on the stack.) + * @{ + */ + DECLARE_ALIGNED_16(float, buf_mdct[1024]); + /** @} */ + + /** + * @defgroup tables Computed / set up during initialization. + * @{ + */ + MDCTContext mdct; + MDCTContext mdct_small; + DSPContext dsp; + int random_state; + /** @} */ + + /** + * @defgroup output Members used for output interleaving. + * @{ + */ + float *output_data[MAX_CHANNELS]; ///< Points to each element's 'ret' buffer (PCM output). + float add_bias; ///< offset for dsp.float_to_int16 + float sf_scale; ///< Pre-scale for correct IMDCT and dsp.float_to_int16. + int sf_offset; ///< offset into pow2sf_tab as appropriate for dsp.float_to_int16 + /** @} */ + +} AACContext; + +#endif /* FFMPEG_AAC_H */ diff --git a/src/add-ons/media/plugins/avcodec/libavcodec/aac_ac3_parser.h b/src/add-ons/media/plugins/avcodec/libavcodec/aac_ac3_parser.h new file mode 100644 index 0000000000..36ea0e0671 --- /dev/null +++ b/src/add-ons/media/plugins/avcodec/libavcodec/aac_ac3_parser.h @@ -0,0 +1,53 @@ +/* + * Common AAC and AC-3 parser prototypes + * Copyright (c) 2003 Fabrice Bellard. + * Copyright (c) 2003 Michael Niedermayer. + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_AAC_AC3_PARSER_H +#define FFMPEG_AAC_AC3_PARSER_H + +#include +#include "avcodec.h" +#include "parser.h" + +typedef struct AACAC3ParseContext { + ParseContext pc; + int frame_size; + int header_size; + int (*sync)(uint64_t state, struct AACAC3ParseContext *hdr_info, + int *need_next_header, int *new_frame_start); + + int channels; + int sample_rate; + int bit_rate; + int samples; + + int remaining_size; + uint64_t state; + + int need_next_header; +} AACAC3ParseContext; + +int ff_aac_ac3_parse(AVCodecParserContext *s1, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size); + +#endif /* FFMPEG_AAC_AC3_PARSER_H */ diff --git a/src/add-ons/media/plugins/avcodec/libavcodec/aacdectab.h b/src/add-ons/media/plugins/avcodec/libavcodec/aacdectab.h new file mode 100644 index 0000000000..3c27c384a8 --- /dev/null +++ b/src/add-ons/media/plugins/avcodec/libavcodec/aacdectab.h @@ -0,0 +1,209 @@ +/* + * AAC decoder data + * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org ) + * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com ) + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file aacdectab.h + * AAC decoder data + * @author Oded Shimon ( ods15 ods15 dyndns org ) + * @author Maxim Gavrilov ( maxim.gavrilov gmail com ) + */ + +#ifndef FFMPEG_AACDECTAB_H +#define FFMPEG_AACDECTAB_H + +#include "aac.h" + +#include + +/* @name swb_offsets + * Sample offset into the window indicating the beginning of a scalefactor + * window band + * + * scalefactor window band - term for scalefactor bands within a window, + * given in Table 4.110 to Table 4.128. + * + * scalefactor band - a set of spectral coefficients which are scaled by one + * scalefactor. In case of EIGHT_SHORT_SEQUENCE and grouping a scalefactor band + * may contain several scalefactor window bands of corresponding frequency. For + * all other window_sequences scalefactor bands and scalefactor window bands are + * identical. + * @{ + */ + +static const uint16_t swb_offset_1024_96[] = { + 0, 4, 8, 12, 16, 20, 24, 28, + 32, 36, 40, 44, 48, 52, 56, 64, + 72, 80, 88, 96, 108, 120, 132, 144, + 156, 172, 188, 212, 240, 276, 320, 384, + 448, 512, 576, 640, 704, 768, 832, 896, + 960, 1024 +}; + +static const uint16_t swb_offset_128_96[] = { + 0, 4, 8, 12, 16, 20, 24, 32, 40, 48, 64, 92, 128 +}; + +static const uint16_t swb_offset_1024_64[] = { + 0, 4, 8, 12, 16, 20, 24, 28, + 32, 36, 40, 44, 48, 52, 56, 64, + 72, 80, 88, 100, 112, 124, 140, 156, + 172, 192, 216, 240, 268, 304, 344, 384, + 424, 464, 504, 544, 584, 624, 664, 704, + 744, 784, 824, 864, 904, 944, 984, 1024 +}; + +static const uint16_t swb_offset_1024_48[] = { + 0, 4, 8, 12, 16, 20, 24, 28, + 32, 36, 40, 48, 56, 64, 72, 80, + 88, 96, 108, 120, 132, 144, 160, 176, + 196, 216, 240, 264, 292, 320, 352, 384, + 416, 448, 480, 512, 544, 576, 608, 640, + 672, 704, 736, 768, 800, 832, 864, 896, + 928, 1024 +}; + +static const uint16_t swb_offset_128_48[] = { + 0, 4, 8, 12, 16, 20, 28, 36, + 44, 56, 68, 80, 96, 112, 128 +}; + +static const uint16_t swb_offset_1024_32[] = { + 0, 4, 8, 12, 16, 20, 24, 28, + 32, 36, 40, 48, 56, 64, 72, 80, + 88, 96, 108, 120, 132, 144, 160, 176, + 196, 216, 240, 264, 292, 320, 352, 384, + 416, 448, 480, 512, 544, 576, 608, 640, + 672, 704, 736, 768, 800, 832, 864, 896, + 928, 960, 992, 1024 +}; + +static const uint16_t swb_offset_1024_24[] = { + 0, 4, 8, 12, 16, 20, 24, 28, + 32, 36, 40, 44, 52, 60, 68, 76, + 84, 92, 100, 108, 116, 124, 136, 148, + 160, 172, 188, 204, 220, 240, 260, 284, + 308, 336, 364, 396, 432, 468, 508, 552, + 600, 652, 704, 768, 832, 896, 960, 1024 +}; + +static const uint16_t swb_offset_128_24[] = { + 0, 4, 8, 12, 16, 20, 24, 28, + 36, 44, 52, 64, 76, 92, 108, 128 +}; + +static const uint16_t swb_offset_1024_16[] = { + 0, 8, 16, 24, 32, 40, 48, 56, + 64, 72, 80, 88, 100, 112, 124, 136, + 148, 160, 172, 184, 196, 212, 228, 244, + 260, 280, 300, 320, 344, 368, 396, 424, + 456, 492, 532, 572, 616, 664, 716, 772, + 832, 896, 960, 1024 +}; + +static const uint16_t swb_offset_128_16[] = { + 0, 4, 8, 12, 16, 20, 24, 28, + 32, 40, 48, 60, 72, 88, 108, 128 +}; + +static const uint16_t swb_offset_1024_8[] = { + 0, 12, 24, 36, 48, 60, 72, 84, + 96, 108, 120, 132, 144, 156, 172, 188, + 204, 220, 236, 252, 268, 288, 308, 328, + 348, 372, 396, 420, 448, 476, 508, 544, + 580, 620, 664, 712, 764, 820, 880, 944, + 1024 +}; + +static const uint16_t swb_offset_128_8[] = { + 0, 4, 8, 12, 16, 20, 24, 28, + 36, 44, 52, 60, 72, 88, 108, 128 +}; + +static const uint16_t *swb_offset_1024[] = { + swb_offset_1024_96, swb_offset_1024_96, swb_offset_1024_64, + swb_offset_1024_48, swb_offset_1024_48, swb_offset_1024_32, + swb_offset_1024_24, swb_offset_1024_24, swb_offset_1024_16, + swb_offset_1024_16, swb_offset_1024_16, swb_offset_1024_8 +}; + +static const uint16_t *swb_offset_128[] = { + /* The last entry on the following row is swb_offset_128_64 but is a + duplicate of swb_offset_128_96. */ + swb_offset_128_96, swb_offset_128_96, swb_offset_128_96, + swb_offset_128_48, swb_offset_128_48, swb_offset_128_48, + swb_offset_128_24, swb_offset_128_24, swb_offset_128_16, + swb_offset_128_16, swb_offset_128_16, swb_offset_128_8 +}; + +// @} + +/* @name tns_max_bands + * The maximum number of scalefactor bands on which TNS can operate for the long + * and short transforms respectively. The index to these tables is related to + * the sample rate of the audio. + * @{ + */ +static const uint8_t tns_max_bands_1024[] = { + 31, 31, 34, 40, 42, 51, 46, 46, 42, 42, 42, 39 +}; + +static const uint8_t tns_max_bands_128[] = { + 9, 9, 10, 14, 14, 14, 14, 14, 14, 14, 14, 14 +}; +// @} + +/* @name tns_tmp2_map + * Tables of the tmp2[] arrays of LPC coefficients used for TNS. + * The suffix _M_N[] indicate the values of coef_compress and coef_res + * respectively. + * @{ + */ +static const float tns_tmp2_map_1_3[4] = { + 0.00000000, 0.43388373, -0.64278758, -0.34202015, +}; + +static const float tns_tmp2_map_0_3[8] = { + 0.00000000, 0.43388373, 0.78183150, 0.97492790, + -0.98480773, -0.86602539, -0.64278758, -0.34202015, +}; + +static const float tns_tmp2_map_1_4[8] = { + 0.00000000, 0.20791170, 0.40673664, 0.58778524, + -0.67369562, -0.52643216, -0.36124167, -0.18374951, +}; + +static const float tns_tmp2_map_0_4[16] = { + 0.00000000, 0.20791170, 0.40673664, 0.58778524, + 0.74314481, 0.86602539, 0.95105654, 0.99452192, + -0.99573416, -0.96182561, -0.89516330, -0.79801720, + -0.67369562, -0.52643216, -0.36124167, -0.18374951, +}; + +static const float *tns_tmp2_map[4] = { + tns_tmp2_map_0_3, + tns_tmp2_map_0_4, + tns_tmp2_map_1_3, + tns_tmp2_map_1_4 +}; +// @} + +#endif /* FFMPEG_AACDECTAB_H */ diff --git a/src/add-ons/media/plugins/avcodec/libavcodec/aacpsy.h b/src/add-ons/media/plugins/avcodec/libavcodec/aacpsy.h new file mode 100644 index 0000000000..d0dbb078e9 --- /dev/null +++ b/src/add-ons/media/plugins/avcodec/libavcodec/aacpsy.h @@ -0,0 +1,50 @@ +/* + * AAC encoder psychoacoustic model + * Copyright (C) 2008 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_AACPSY_H +#define FFMPEG_AACPSY_H + +#include "avcodec.h" +#include "aac.h" +#include "lowpass.h" + +enum AACPsyModelType{ + AAC_PSY_TEST, ///< a sample model to exercise encoder + AAC_PSY_3GPP, ///< model following recommendations from 3GPP TS 26.403 + + AAC_NB_PSY_MODELS ///< total number of psychoacoustic models, since it's not a part of the ABI new models can be added freely +}; + +/** + * context used by psychoacoustic model + */ +typedef struct AACPsyContext { + AVCodecContext *avctx; ///< encoder context +}AACPsyContext; + +/** + * Cleanup model context at the end. + * + * @param ctx model context + */ +void ff_aac_psy_end(AACPsyContext *ctx); + +#endif /* FFMPEG_AACPSY_H */ diff --git a/src/add-ons/media/plugins/avcodec/libavcodec/aactab.h b/src/add-ons/media/plugins/avcodec/libavcodec/aactab.h new file mode 100644 index 0000000000..55b33d2ab5 --- /dev/null +++ b/src/add-ons/media/plugins/avcodec/libavcodec/aactab.h @@ -0,0 +1,72 @@ +/* + * AAC data declarations + * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org ) + * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com ) + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file aactab.h + * AAC data declarations + * @author Oded Shimon ( ods15 ods15 dyndns org ) + * @author Maxim Gavrilov ( maxim.gavrilov gmail com ) + */ + +#ifndef FFMPEG_AACTAB_H +#define FFMPEG_AACTAB_H + +#include "mem.h" +#include "aac.h" + +#include + +/* NOTE: + * Tables in this file are used by the AAC decoder and will be used by the AAC + * encoder. + */ + +/* @name window coefficients + * @{ + */ +DECLARE_ALIGNED(16, extern float, ff_aac_kbd_long_1024[1024]); +DECLARE_ALIGNED(16, extern float, ff_aac_kbd_short_128[128]); +// @} + +/* @name number of scalefactor window bands for long and short transform windows respectively + * @{ + */ +extern const uint8_t ff_aac_num_swb_1024[]; +extern const uint8_t ff_aac_num_swb_128 []; +// @} + +extern const uint32_t ff_aac_scalefactor_code[121]; +extern const uint8_t ff_aac_scalefactor_bits[121]; + +extern const uint16_t *ff_aac_spectral_codes[11]; +extern const uint8_t *ff_aac_spectral_bits [11]; +extern const uint16_t ff_aac_spectral_sizes[11]; + +extern const float *ff_aac_codebook_vectors[]; + +#ifdef CONFIG_HARDCODED_TABLES +extern const float ff_aac_pow2sf_tab[316]; +#else +extern float ff_aac_pow2sf_tab[316]; +#endif /* CONFIG_HARDCODED_TABLES */ + +#endif /* FFMPEG_AACTAB_H */ diff --git a/src/add-ons/media/plugins/avcodec/libavcodec/ac3.h b/src/add-ons/media/plugins/avcodec/libavcodec/ac3.h index 1e8a5ba2db..3b18a15a7c 100644 --- a/src/add-ons/media/plugins/avcodec/libavcodec/ac3.h +++ b/src/add-ons/media/plugins/avcodec/libavcodec/ac3.h @@ -1,31 +1,38 @@ /* - * Common code between AC3 encoder and decoder + * Common code between the AC-3 encoder and decoder * Copyright (c) 2000, 2001, 2002 Fabrice Bellard. * - * This library is free software; you can redistribute it and/or + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. + * version 2.1 of the License, or (at your option) any later version. * - * This library is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * @file ac3.h - * Common code between AC3 encoder and decoder. + * Common code between the AC-3 encoder and decoder. */ +#ifndef FFMPEG_AC3_H +#define FFMPEG_AC3_H + +#include "ac3tab.h" + #define AC3_MAX_CODED_FRAME_SIZE 3840 /* in bytes */ #define AC3_MAX_CHANNELS 6 /* including LFE channel */ -#define NB_BLOCKS 6 /* number of PCM blocks inside an AC3 frame */ +#define NB_BLOCKS 6 /* number of PCM blocks inside an AC-3 frame */ #define AC3_FRAME_SIZE (NB_BLOCKS * 256) /* exponent encoding strategy */ @@ -36,26 +43,143 @@ #define EXP_D25 2 #define EXP_D45 3 +/** Delta bit allocation strategy */ +typedef enum { + DBA_REUSE = 0, + DBA_NEW, + DBA_NONE, + DBA_RESERVED +} AC3DeltaStrategy; + +/** Channel mode (audio coding mode) */ +typedef enum { + AC3_CHMODE_DUALMONO = 0, + AC3_CHMODE_MONO, + AC3_CHMODE_STEREO, + AC3_CHMODE_3F, + AC3_CHMODE_2F1R, + AC3_CHMODE_3F1R, + AC3_CHMODE_2F2R, + AC3_CHMODE_3F2R +} AC3ChannelMode; + typedef struct AC3BitAllocParameters { - int fscod; /* frequency */ - int halfratecod; - int sgain, sdecay, fdecay, dbknee, floor; - int cplfleak, cplsleak; + int sr_code; + int sr_shift; + int slow_gain, slow_decay, fast_decay, db_per_bit, floor; + int cpl_fast_leak, cpl_slow_leak; } AC3BitAllocParameters; -extern const uint16_t ac3_freqs[3]; -extern const uint16_t ac3_bitratetab[19]; -extern const int16_t ac3_window[256]; -extern const uint8_t sdecaytab[4]; -extern const uint8_t fdecaytab[4]; -extern const uint16_t sgaintab[4]; -extern const uint16_t dbkneetab[4]; -extern const uint16_t floortab[8]; -extern const uint16_t fgaintab[8]; +/** + * @struct AC3HeaderInfo + * Coded AC-3 header values up to the lfeon element, plus derived values. + */ +typedef struct { + /** @defgroup coded Coded elements + * @{ + */ + uint16_t sync_word; + uint16_t crc1; + uint8_t sr_code; + uint8_t bitstream_id; + uint8_t channel_mode; + uint8_t lfe_on; + uint8_t frame_type; + int substreamid; ///< substream identification + int center_mix_level; ///< Center mix level index + int surround_mix_level; ///< Surround mix level index + uint16_t channel_map; + int num_blocks; ///< number of audio blocks + /** @} */ + + /** @defgroup derived Derived values + * @{ + */ + uint8_t sr_shift; + uint16_t sample_rate; + uint32_t bit_rate; + uint8_t channels; + uint16_t frame_size; + /** @} */ +} AC3HeaderInfo; + +typedef enum { + EAC3_FRAME_TYPE_INDEPENDENT = 0, + EAC3_FRAME_TYPE_DEPENDENT, + EAC3_FRAME_TYPE_AC3_CONVERT, + EAC3_FRAME_TYPE_RESERVED +} EAC3FrameType; void ac3_common_init(void); + +/** + * Calculates the log power-spectral density of the input signal. + * This gives a rough estimate of signal power in the frequency domain by using + * the spectral envelope (exponents). The psd is also separately grouped + * into critical bands for use in the calculating the masking curve. + * 128 units in psd = -6 dB. The dbknee parameter in AC3BitAllocParameters + * determines the reference level. + * + * @param[in] exp frequency coefficient exponents + * @param[in] start starting bin location + * @param[in] end ending bin location + * @param[out] psd signal power for each frequency bin + * @param[out] band_psd signal power for each critical band + */ +void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd, + int16_t *band_psd); + +/** + * Calculates the masking curve. + * First, the excitation is calculated using parameters in \p s and the signal + * power in each critical band. The excitation is compared with a predefined + * hearing threshold table to produce the masking curve. If delta bit + * allocation information is provided, it is used for adjusting the masking + * curve, usually to give a closer match to a better psychoacoustic model. + * + * @param[in] s adjustable bit allocation parameters + * @param[in] band_psd signal power for each critical band + * @param[in] start starting bin location + * @param[in] end ending bin location + * @param[in] fast_gain fast gain (estimated signal-to-mask ratio) + * @param[in] is_lfe whether or not the channel being processed is the LFE + * @param[in] dba_mode delta bit allocation mode (none, reuse, or new) + * @param[in] dba_nsegs number of delta segments + * @param[in] dba_offsets location offsets for each segment + * @param[in] dba_lengths length of each segment + * @param[in] dba_values delta bit allocation for each segment + * @param[out] mask calculated masking curve + */ +void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, + int start, int end, int fast_gain, int is_lfe, + int dba_mode, int dba_nsegs, uint8_t *dba_offsets, + uint8_t *dba_lengths, uint8_t *dba_values, + int16_t *mask); + +/** + * Calculates bit allocation pointers. + * The SNR is the difference between the masking curve and the signal. AC-3 + * uses this value for each frequency bin to allocate bits. The \p snroffset + * parameter is a global adjustment to the SNR for all bins. + * + * @param[in] mask masking curve + * @param[in] psd signal power for each frequency bin + * @param[in] start starting bin location + * @param[in] end ending bin location + * @param[in] snr_offset SNR adjustment + * @param[in] floor noise floor + * @param[in] bap_tab look-up table for bit allocation pointers + * @param[out] bap bit allocation pointers + */ +void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end, + int snr_offset, int floor, + const uint8_t *bap_tab, uint8_t *bap); + void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap, int8_t *exp, int start, int end, - int snroffset, int fgain, int is_lfe, - int deltbae,int deltnseg, - uint8_t *deltoffst, uint8_t *deltlen, uint8_t *deltba); + int snr_offset, int fast_gain, int is_lfe, + int dba_mode, int dba_nsegs, + uint8_t *dba_offsets, uint8_t *dba_lengths, + uint8_t *dba_values); + +#endif /* FFMPEG_AC3_H */ diff --git a/src/add-ons/media/plugins/avcodec/libavcodec/ac3_parser.h b/src/add-ons/media/plugins/avcodec/libavcodec/ac3_parser.h new file mode 100644 index 0000000000..e49492558a --- /dev/null +++ b/src/add-ons/media/plugins/avcodec/libavcodec/ac3_parser.h @@ -0,0 +1,61 @@ +/* + * AC-3 parser prototypes + * Copyright (c) 2003 Fabrice Bellard. + * Copyright (c) 2003 Michael Niedermayer. + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_AC3_PARSER_H +#define FFMPEG_AC3_PARSER_H + +#include "ac3.h" +#include "bitstream.h" + +typedef enum { + AC3_PARSE_ERROR_SYNC = -1, + AC3_PARSE_ERROR_BSID = -2, + AC3_PARSE_ERROR_SAMPLE_RATE = -3, + AC3_PARSE_ERROR_FRAME_SIZE = -4, + AC3_PARSE_ERROR_FRAME_TYPE = -5, + AC3_PARSE_ERROR_CRC = -6, +} AC3ParseError; + +/** + * Parses AC-3 frame header. + * Parses the header up to the lfeon element, which is the first 52 or 54 bits + * depending on the audio coding mode. + * @param gbc[in] BitContext containing the first 54 bits of the frame. + * @param hdr[out] Pointer to struct where header info is written. + * @return Returns 0 on success, -1 if there is a sync word mismatch, + * -2 if the bsid (version) element is invalid, -3 if the fscod (sample rate) + * element is invalid, or -4 if the frmsizecod (bit rate) element is invalid. + */ +int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr); + +/** + * Parses AC-3 frame header and sets channel_map + * Parses the header up to the lfeon (channel_map in E-AC-3) + * element, which is the first 52, 54 or 104 bits depending + * on the audio coding mode. + * @param gbc[in] BitContext containing the first 54 bits of the frame. + * @param hdr[out] Pointer to struct where header info is written. + * @return value returned by ff_ac3_parse_header + */ +int ff_ac3_parse_header_full(GetBitContext *gbc, AC3HeaderInfo *hdr); + +#endif /* FFMPEG_AC3_PARSER_H */ diff --git a/src/add-ons/media/plugins/avcodec/libavcodec/ac3dec.h b/src/add-ons/media/plugins/avcodec/libavcodec/ac3dec.h new file mode 100644 index 0000000000..328c46ff1a --- /dev/null +++ b/src/add-ons/media/plugins/avcodec/libavcodec/ac3dec.h @@ -0,0 +1,171 @@ +/* + * Common code between the AC-3 and E-AC-3 decoders + * Copyright (c) 2007 Bartlomiej Wolowiec + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file ac3.h + * Common code between the AC-3 and E-AC-3 decoders. + */ + +#ifndef FFMPEG_AC3DEC_H +#define FFMPEG_AC3DEC_H + +#include "lfg.h" +#include "ac3.h" +#include "bitstream.h" +#include "dsputil.h" + +/* override ac3.h to include coupling channel */ +#undef AC3_MAX_CHANNELS +#define AC3_MAX_CHANNELS 7 +#define CPL_CH 0 + +#define AC3_OUTPUT_LFEON 8 + +#define AC3_MAX_COEFS 256 +#define AC3_BLOCK_SIZE 256 +#define MAX_BLOCKS 6 + +typedef struct { + AVCodecContext *avctx; ///< parent context + GetBitContext gbc; ///< bitstream reader + uint8_t *input_buffer; ///< temp buffer to prevent overread + +///@defgroup bsi bit stream information +///@{ + int frame_type; ///< frame type (strmtyp) + int substreamid; ///< substream identification + int frame_size; ///< current frame size, in bytes + int bit_rate; ///< stream bit rate, in bits-per-second + int sample_rate; ///< sample frequency, in Hz + int num_blocks; ///< number of audio blocks + int channel_mode; ///< channel mode (acmod) + int lfe_on; ///< lfe channel in use + int channel_map; ///< custom channel map + int center_mix_level; ///< Center mix level index + int surround_mix_level; ///< Surround mix level index + int eac3; ///< indicates if current frame is E-AC-3 +///@} + +///@defgroup audfrm frame syntax parameters + int snr_offset_strategy; ///< SNR offset strategy (snroffststr) + int block_switch_syntax; ///< block switch syntax enabled (blkswe) + int dither_flag_syntax; ///< dither flag syntax enabled (dithflage) + int bit_allocation_syntax; ///< bit allocation model syntax enabled (bamode) + int fast_gain_syntax; ///< fast gain codes enabled (frmfgaincode) + int dba_syntax; ///< delta bit allocation syntax enabled (dbaflde) + int skip_syntax; ///< skip field syntax enabled (skipflde) + ///@} + +///@defgroup cpl standard coupling + int cpl_in_use[MAX_BLOCKS]; ///< coupling in use (cplinu) + int cpl_strategy_exists[MAX_BLOCKS]; ///< coupling strategy exists (cplstre) + int channel_in_cpl[AC3_MAX_CHANNELS]; ///< channel in coupling (chincpl) + int phase_flags_in_use; ///< phase flags in use (phsflginu) + int phase_flags[18]; ///< phase flags (phsflg) + int num_cpl_subbands; ///< number of coupling sub bands (ncplsubnd) + int num_cpl_bands; ///< number of coupling bands (ncplbnd) + int cpl_band_struct[18]; ///< coupling band structure (cplbndstrc) + int firstchincpl; ///< first channel in coupling + int first_cpl_coords[AC3_MAX_CHANNELS]; ///< first coupling coordinates states (firstcplcos) + int cpl_coords[AC3_MAX_CHANNELS][18]; ///< coupling coordinates (cplco) +///@} + +///@defgroup aht adaptive hybrid transform + int channel_uses_aht[AC3_MAX_CHANNELS]; ///< channel AHT in use (chahtinu) + int pre_mantissa[AC3_MAX_CHANNELS][AC3_MAX_COEFS][MAX_BLOCKS]; ///< pre-IDCT mantissas +///@} + +///@defgroup channel channel + int fbw_channels; ///< number of full-bandwidth channels + int channels; ///< number of total channels + int lfe_ch; ///< index of LFE channel + float downmix_coeffs[AC3_MAX_CHANNELS][2]; ///< stereo downmix coefficients + int downmixed; ///< indicates if coeffs are currently downmixed + int output_mode; ///< output channel configuration + int out_channels; ///< number of output channels +///@} + +///@defgroup dynrng dynamic range + float dynamic_range[2]; ///< dynamic range +///@} + +///@defgroup bandwidth bandwidth + int start_freq[AC3_MAX_CHANNELS]; ///< start frequency bin (strtmant) + int end_freq[AC3_MAX_CHANNELS]; ///< end frequency bin (endmant) +///@} + +///@defgroup rematrixing rematrixing + int num_rematrixing_bands; ///< number of rematrixing bands (nrematbnd) + int rematrixing_flags[4]; ///< rematrixing flags (rematflg) +///@} + +///@defgroup exponents exponents + int num_exp_groups[AC3_MAX_CHANNELS]; ///< Number of exponent groups (nexpgrp) + int8_t dexps[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< decoded exponents + int exp_strategy[MAX_BLOCKS][AC3_MAX_CHANNELS]; ///< exponent strategies (expstr) +///@} + +///@defgroup bitalloc bit allocation + AC3BitAllocParameters bit_alloc_params; ///< bit allocation parameters + int first_cpl_leak; ///< first coupling leak state (firstcplleak) + int snr_offset[AC3_MAX_CHANNELS]; ///< signal-to-noise ratio offsets (snroffst) + int fast_gain[AC3_MAX_CHANNELS]; ///< fast gain values/SMR's (fgain) + uint8_t bap[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< bit allocation pointers + int16_t psd[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< scaled exponents + int16_t band_psd[AC3_MAX_CHANNELS][50]; ///< interpolated exponents + int16_t mask[AC3_MAX_CHANNELS][50]; ///< masking curve values + int dba_mode[AC3_MAX_CHANNELS]; ///< delta bit allocation mode + int dba_nsegs[AC3_MAX_CHANNELS]; ///< number of delta segments + uint8_t dba_offsets[AC3_MAX_CHANNELS][8]; ///< delta segment offsets + uint8_t dba_lengths[AC3_MAX_CHANNELS][8]; ///< delta segment lengths + uint8_t dba_values[AC3_MAX_CHANNELS][8]; ///< delta values for each segment +///@} + +///@defgroup dithering zero-mantissa dithering + int dither_all; ///< true if all channels are dithered + int dither_flag[AC3_MAX_CHANNELS]; ///< dither flags (dithflg) + AVLFG dith_state; ///< for dither generation +///@} + +///@defgroup imdct IMDCT + int block_switch[AC3_MAX_CHANNELS]; ///< block switch flags (blksw) + MDCTContext imdct_512; ///< for 512 sample IMDCT + MDCTContext imdct_256; ///< for 256 sample IMDCT +///@} + +///@defgroup opt optimization + DSPContext dsp; ///< for optimization + float add_bias; ///< offset for float_to_int16 conversion + float mul_bias; ///< scaling for float_to_int16 conversion +///@} + + DECLARE_ALIGNED_16(int, fixed_coeffs[AC3_MAX_CHANNELS][AC3_MAX_COEFS]); ///> fixed-point transform coefficients + +///@defgroup arrays aligned arrays + DECLARE_ALIGNED_16(float, transform_coeffs[AC3_MAX_CHANNELS][AC3_MAX_COEFS]); ///< transform coefficients + DECLARE_ALIGNED_16(float, delay[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]); ///< delay - added to the next block + DECLARE_ALIGNED_16(float, window[AC3_BLOCK_SIZE]); ///< window coefficients + DECLARE_ALIGNED_16(float, tmp_output[AC3_BLOCK_SIZE]); ///< temporary storage for output before windowing + DECLARE_ALIGNED_16(float, output[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]); ///< output after imdct transform and windowing +///@} +} AC3DecodeContext; + +#endif /* FFMPEG_AC3DEC_H */ diff --git a/src/add-ons/media/plugins/avcodec/libavcodec/ac3dec_data.h b/src/add-ons/media/plugins/avcodec/libavcodec/ac3dec_data.h new file mode 100644 index 0000000000..57cb255a7e --- /dev/null +++ b/src/add-ons/media/plugins/avcodec/libavcodec/ac3dec_data.h @@ -0,0 +1,40 @@ +/* + * AC-3 and E-AC-3 decoder tables + * Copyright (c) 2007 Bartlomiej Wolowiec + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_AC3DEC_DATA_H +#define FFMPEG_AC3DEC_DATA_H + +#include "common.h" + +extern const uint8_t ff_ac3_ungroup_3_in_5_bits_tab[32][3]; +extern const uint8_t ff_eac3_hebap_tab[64]; +extern const uint8_t ff_eac3_bits_vs_hebap[20]; +extern const int16_t ff_eac3_gaq_remap_1[12]; +extern const int16_t ff_eac3_gaq_remap_2_4_a[9][2]; +extern const int8_t ff_eac3_gaq_remap_2_4_b[9][2]; + +extern const int16_t (*ff_eac3_vq_hebap[8])[6]; +extern const uint8_t ff_eac3_frm_expstr[32][6]; +extern const uint8_t ff_eac3_default_cpl_band_struct[18]; + +extern const uint8_t ff_ac3_rematrix_band_tab[5]; + +#endif /* FFMPEG_AC3DEC_DATA_H */ diff --git a/src/add-ons/media/plugins/avcodec/libavcodec/ac3tab.h b/src/add-ons/media/plugins/avcodec/libavcodec/ac3tab.h index 5d404b5390..b99789c590 100644 --- a/src/add-ons/media/plugins/avcodec/libavcodec/ac3tab.h +++ b/src/add-ons/media/plugins/avcodec/libavcodec/ac3tab.h @@ -1,186 +1,59 @@ -/** - * @file ac3tab.h - * tables taken directly from AC3 spec. +/* + * AC-3 tables + * Copyright (c) 2000, 2001, 2002 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* possible frequencies */ -const uint16_t ac3_freqs[3] = { 48000, 44100, 32000 }; +#ifndef FFMPEG_AC3TAB_H +#define FFMPEG_AC3TAB_H -/* possible bitrates */ -const uint16_t ac3_bitratetab[19] = { - 32, 40, 48, 56, 64, 80, 96, 112, 128, - 160, 192, 224, 256, 320, 384, 448, 512, 576, 640 +#include "common.h" + +extern const uint16_t ff_ac3_frame_size_tab[38][3]; +extern const uint8_t ff_ac3_channels_tab[8]; +extern const uint16_t ff_ac3_sample_rate_tab[3]; +extern const uint16_t ff_ac3_bitrate_tab[19]; +extern const int16_t ff_ac3_window[256]; +extern const uint8_t ff_ac3_log_add_tab[260]; +extern const uint16_t ff_ac3_hearing_threshold_tab[50][3]; +extern const uint8_t ff_ac3_bap_tab[64]; +extern const uint8_t ff_ac3_slow_decay_tab[4]; +extern const uint8_t ff_ac3_fast_decay_tab[4]; +extern const uint16_t ff_ac3_slow_gain_tab[4]; +extern const uint16_t ff_ac3_db_per_bit_tab[4]; +extern const int16_t ff_ac3_floor_tab[8]; +extern const uint16_t ff_ac3_fast_gain_tab[8]; +extern const uint8_t ff_ac3_critical_band_size_tab[50]; +extern const uint16_t ff_eac3_default_chmap[8]; + +/** Custom channel map locations bitmask + * Other channels described in documentation: + * Lc/Rc pair, Lrs/Rrs pair, Ts, Lsd/Rsd pair, + * Lw/Rw pair, Lvh/Rvh pair, Cvh, Reserved, LFE2 + */ +enum CustomChannelMapLocation{ + AC3_CHMAP_L= 1<<(15-0), + AC3_CHMAP_C= 1<<(15-1), + AC3_CHMAP_R= 1<<(15-2), + AC3_CHMAP_L_SUR= 1<<(15-3), + AC3_CHMAP_R_SUR = 1<<(15-4), + AC3_CHMAP_C_SUR= 1<<(15-7), + AC3_CHMAP_LFE = 1<<(15-15) }; -/* AC3 MDCT window */ - -/* MDCT window */ -const int16_t ac3_window[256] = { - 4, 7, 12, 16, 21, 28, 34, 42, - 51, 61, 72, 84, 97, 111, 127, 145, - 164, 184, 207, 231, 257, 285, 315, 347, - 382, 419, 458, 500, 544, 591, 641, 694, - 750, 810, 872, 937, 1007, 1079, 1155, 1235, - 1318, 1406, 1497, 1593, 1692, 1796, 1903, 2016, - 2132, 2253, 2379, 2509, 2644, 2783, 2927, 3076, - 3230, 3389, 3552, 3721, 3894, 4072, 4255, 4444, - 4637, 4835, 5038, 5246, 5459, 5677, 5899, 6127, - 6359, 6596, 6837, 7083, 7334, 7589, 7848, 8112, - 8380, 8652, 8927, 9207, 9491, 9778,10069,10363, -10660,10960,11264,11570,11879,12190,12504,12820, -13138,13458,13780,14103,14427,14753,15079,15407, -15735,16063,16392,16720,17049,17377,17705,18032, -18358,18683,19007,19330,19651,19970,20287,20602, -20914,21225,21532,21837,22139,22438,22733,23025, -23314,23599,23880,24157,24430,24699,24964,25225, -25481,25732,25979,26221,26459,26691,26919,27142, -27359,27572,27780,27983,28180,28373,28560,28742, -28919,29091,29258,29420,29577,29729,29876,30018, -30155,30288,30415,30538,30657,30771,30880,30985, -31086,31182,31274,31363,31447,31528,31605,31678, -31747,31814,31877,31936,31993,32046,32097,32145, -32190,32232,32272,32310,32345,32378,32409,32438, -32465,32490,32513,32535,32556,32574,32592,32608, -32623,32636,32649,32661,32671,32681,32690,32698, -32705,32712,32718,32724,32729,32733,32737,32741, -32744,32747,32750,32752,32754,32756,32757,32759, -32760,32761,32762,32763,32764,32764,32765,32765, -32766,32766,32766,32766,32767,32767,32767,32767, -32767,32767,32767,32767,32767,32767,32767,32767, -32767,32767,32767,32767,32767,32767,32767,32767, -}; - -static uint8_t masktab[253]; - -static const uint8_t latab[260]= { -0x0040,0x003f,0x003e,0x003d,0x003c,0x003b,0x003a,0x0039,0x0038,0x0037, -0x0036,0x0035,0x0034,0x0034,0x0033,0x0032,0x0031,0x0030,0x002f,0x002f, -0x002e,0x002d,0x002c,0x002c,0x002b,0x002a,0x0029,0x0029,0x0028,0x0027, -0x0026,0x0026,0x0025,0x0024,0x0024,0x0023,0x0023,0x0022,0x0021,0x0021, -0x0020,0x0020,0x001f,0x001e,0x001e,0x001d,0x001d,0x001c,0x001c,0x001b, -0x001b,0x001a,0x001a,0x0019,0x0019,0x0018,0x0018,0x0017,0x0017,0x0016, -0x0016,0x0015,0x0015,0x0015,0x0014,0x0014,0x0013,0x0013,0x0013,0x0012, -0x0012,0x0012,0x0011,0x0011,0x0011,0x0010,0x0010,0x0010,0x000f,0x000f, -0x000f,0x000e,0x000e,0x000e,0x000d,0x000d,0x000d,0x000d,0x000c,0x000c, -0x000c,0x000c,0x000b,0x000b,0x000b,0x000b,0x000a,0x000a,0x000a,0x000a, -0x000a,0x0009,0x0009,0x0009,0x0009,0x0009,0x0008,0x0008,0x0008,0x0008, -0x0008,0x0008,0x0007,0x0007,0x0007,0x0007,0x0007,0x0007,0x0006,0x0006, -0x0006,0x0006,0x0006,0x0006,0x0006,0x0006,0x0005,0x0005,0x0005,0x0005, -0x0005,0x0005,0x0005,0x0005,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004, -0x0004,0x0004,0x0004,0x0004,0x0004,0x0003,0x0003,0x0003,0x0003,0x0003, -0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0002, -0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002, -0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0001,0x0001, -0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001, -0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001, -0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001, -0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, -0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, -0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, -0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, -0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, -}; - -static const uint16_t hth[50][3]= { -{ 0x04d0,0x04f0,0x0580 }, -{ 0x04d0,0x04f0,0x0580 }, -{ 0x0440,0x0460,0x04b0 }, -{ 0x0400,0x0410,0x0450 }, -{ 0x03e0,0x03e0,0x0420 }, -{ 0x03c0,0x03d0,0x03f0 }, -{ 0x03b0,0x03c0,0x03e0 }, -{ 0x03b0,0x03b0,0x03d0 }, -{ 0x03a0,0x03b0,0x03c0 }, -{ 0x03a0,0x03a0,0x03b0 }, -{ 0x03a0,0x03a0,0x03b0 }, -{ 0x03a0,0x03a0,0x03b0 }, -{ 0x03a0,0x03a0,0x03a0 }, -{ 0x0390,0x03a0,0x03a0 }, -{ 0x0390,0x0390,0x03a0 }, -{ 0x0390,0x0390,0x03a0 }, -{ 0x0380,0x0390,0x03a0 }, -{ 0x0380,0x0380,0x03a0 }, -{ 0x0370,0x0380,0x03a0 }, -{ 0x0370,0x0380,0x03a0 }, -{ 0x0360,0x0370,0x0390 }, -{ 0x0360,0x0370,0x0390 }, -{ 0x0350,0x0360,0x0390 }, -{ 0x0350,0x0360,0x0390 }, -{ 0x0340,0x0350,0x0380 }, -{ 0x0340,0x0350,0x0380 }, -{ 0x0330,0x0340,0x0380 }, -{ 0x0320,0x0340,0x0370 }, -{ 0x0310,0x0320,0x0360 }, -{ 0x0300,0x0310,0x0350 }, -{ 0x02f0,0x0300,0x0340 }, -{ 0x02f0,0x02f0,0x0330 }, -{ 0x02f0,0x02f0,0x0320 }, -{ 0x02f0,0x02f0,0x0310 }, -{ 0x0300,0x02f0,0x0300 }, -{ 0x0310,0x0300,0x02f0 }, -{ 0x0340,0x0320,0x02f0 }, -{ 0x0390,0x0350,0x02f0 }, -{ 0x03e0,0x0390,0x0300 }, -{ 0x0420,0x03e0,0x0310 }, -{ 0x0460,0x0420,0x0330 }, -{ 0x0490,0x0450,0x0350 }, -{ 0x04a0,0x04a0,0x03c0 }, -{ 0x0460,0x0490,0x0410 }, -{ 0x0440,0x0460,0x0470 }, -{ 0x0440,0x0440,0x04a0 }, -{ 0x0520,0x0480,0x0460 }, -{ 0x0800,0x0630,0x0440 }, -{ 0x0840,0x0840,0x0450 }, -{ 0x0840,0x0840,0x04e0 }, -}; - -static const uint8_t baptab[64]= { - 0, 1, 1, 1, 1, 1, 2, 2, 3, 3, - 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, - 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, - 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, - 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, - 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, - 15, 15, 15, 15, -}; - -const uint8_t sdecaytab[4]={ - 0x0f, 0x11, 0x13, 0x15, -}; - -const uint8_t fdecaytab[4]={ - 0x3f, 0x53, 0x67, 0x7b, -}; - -const uint16_t sgaintab[4]= { - 0x540, 0x4d8, 0x478, 0x410, -}; - -const uint16_t dbkneetab[4]= { - 0x000, 0x700, 0x900, 0xb00, -}; - -const uint16_t floortab[8]= { - 0x2f0, 0x2b0, 0x270, 0x230, 0x1f0, 0x170, 0x0f0, 0xf800, -}; - -const uint16_t fgaintab[8]= { - 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x400, -}; - -static const uint8_t bndsz[50]={ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, - 3, 6, 6, 6, 6, 6, 6, 12, 12, 12, 12, 24, 24, 24, 24, 24 -}; - -static uint8_t bndtab[51]; - -/* fft & mdct sin cos tables */ -static int16_t costab[64]; -static int16_t sintab[64]; -static int16_t fft_rev[512]; -static int16_t xcos1[128]; -static int16_t xsin1[128]; - -static uint16_t crc_table[256]; +#endif /* FFMPEG_AC3TAB_H */ diff --git a/src/add-ons/media/plugins/avcodec/libavcodec/acelp_filters.h b/src/add-ons/media/plugins/avcodec/libavcodec/acelp_filters.h new file mode 100644 index 0000000000..6b0679ff70 --- /dev/null +++ b/src/add-ons/media/plugins/avcodec/libavcodec/acelp_filters.h @@ -0,0 +1,137 @@ +/* + * various filters for ACELP-based codecs + * + * Copyright (c) 2008 Vladimir Voroshilov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_ACELP_FILTERS_H +#define FFMPEG_ACELP_FILTERS_H + +#include + +/** + * low-pass Finite Impulse Response filter coefficients. + * + * Hamming windowed sinc filter with cutoff freq 3/40 of the sampling freq, + * the coefficients are scaled by 2^15. + * This array only contains the right half of the filter. + * This filter is likely identical to the one used in G.729, though this + * could not be determined from the original comments with certainity. + */ +extern const int16_t ff_acelp_interp_filter[61]; + +/** + * Generic FIR interpolation routine. + * @param out [out] buffer for interpolated data + * @param in input data + * @param filter_coeffs interpolation filter coefficients (0.15) + * @param precision sub sample factor, that is the precision of the position + * @param frac_pos fractional part of position [0..precision-1] + * @param filter_length filter length + * @param length length of output + * + * filter_coeffs contains coefficients of the right half of the symmetric + * interpolation filter. filter_coeffs[0] should the central (unpaired) coefficient. + * See ff_acelp_interp_filter for an example. + * + */ +void ff_acelp_interpolate( + int16_t* out, + const int16_t* in, + const int16_t* filter_coeffs, + int precision, + int frac_pos, + int filter_length, + int length); + +/** + * Circularly convolve fixed vector with a phase dispersion impulse + * response filter (D.6.2 of G.729 and 6.1.5 of AMR). + * @param fc_out vector with filter applied + * @param fc_in source vector + * @param filter phase filter coefficients + * + * fc_out[n] = sum(i,0,len-1){ fc_in[i] * filter[(len + n - i)%len] } + * + * \note fc_in and fc_out should not overlap! + */ +void ff_acelp_convolve_circ( + int16_t* fc_out, + const int16_t* fc_in, + const int16_t* filter, + int len); + +/** + * LP synthesis filter. + * @param out [out] pointer to output buffer + * @param filter_coeffs filter coefficients (-0x8000 <= (3.12) < 0x8000) + * @param in input signal + * @param buffer_length amount of data to process + * @param filter_length filter length (10 for 10th order LP filter) + * @param stop_on_overflow 1 - return immediately if overflow occurs + * 0 - ignore overflows + * @param rounder the amount to add for rounding (usually 0x800 or 0xfff) + * + * @return 1 if overflow occurred, 0 - otherwise + * + * @note Output buffer must contain 10 samples of past + * speech data before pointer. + * + * Routine applies 1/A(z) filter to given speech data. + */ +int ff_acelp_lp_synthesis_filter( + int16_t *out, + const int16_t* filter_coeffs, + const int16_t* in, + int buffer_length, + int filter_length, + int stop_on_overflow, + int rounder); + + +/** + * high-pass filtering and upscaling (4.2.5 of G.729). + * @param out [out] output buffer for filtered speech data + * @param hpf_f [in/out] past filtered data from previous (2 items long) + * frames (-0x20000000 <= (14.13) < 0x20000000) + * @param in speech data to process + * @param length input data size + * + * out[i] = 0.93980581 * in[i] - 1.8795834 * in[i-1] + 0.93980581 * in[i-2] + + * 1.9330735 * out[i-1] - 0.93589199 * out[i-2] + * + * The filter has a cut-off frequency of 1/80 of the sampling freq + * + * @note Two items before the top of the out buffer must contain two items from the + * tail of the previous subframe. + * + * @remark It is safe to pass the same array in in and out parameters. + * + * @remark AMR uses mostly the same filter (cut-off frequency 60Hz, same formula, + * but constants differs in 5th sign after comma). Fortunately in + * fixed-point all coefficients are the same as in G.729. Thus this + * routine can be used for the fixed-point AMR decoder, too. + */ +void ff_acelp_high_pass_filter( + int16_t* out, + int hpf_f[2], + const int16_t* in, + int length); + +#endif /* FFMPEG_ACELP_FILTERS_H */ diff --git a/src/add-ons/media/plugins/avcodec/libavcodec/acelp_math.h b/src/add-ons/media/plugins/avcodec/libavcodec/acelp_math.h new file mode 100644 index 0000000000..769fcf6b1b --- /dev/null +++ b/src/add-ons/media/plugins/avcodec/libavcodec/acelp_math.h @@ -0,0 +1,86 @@ +/* + * Various fixed-point math operations + * + * Copyright (c) 2008 Vladimir Voroshilov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_ACELP_MATH_H +#define FFMPEG_ACELP_MATH_H + +#include + +/** + * fixed-point implementation of cosine in [0; PI) domain. + * @param arg fixed-point cosine argument, 0 <= arg < 0x4000 + * + * @return value of (1<<15) * cos(arg * PI / (1<<14)), -0x8000 <= result <= 0x7fff + */ +int16_t ff_cos(uint16_t arg); + +/** + * fixed-point implementation of exp2(x) in [0; 1] domain. + * @param power argument to exp2, 0 <= power <= 0x7fff + * + * @return value of (1<<20) * exp2(power / (1<<15)) + * 0x8000c <= result <= 0xfffea + */ +int ff_exp2(uint16_t power); + +/** + * Calculates log2(x). + * @param value function argument, 0 < value <= 7fff ffff + * + * @return value of (1<<15) * log2(value) + */ +int ff_log2(uint32_t value); + +/** + * returns the dot product. + * @param a input data array + * @param b input data array + * @param length number of elements + * @param shift right shift by this value will be done after multiplication + * + * @return dot product = sum of elementwise products + */ +static int dot_product(const int16_t* a, const int16_t* b, int length, int shift) +{ + int sum = 0; + int i; + + for(i=0; i> shift; + + return sum; +} + +/** + * Shift value left or right depending on sign of offset parameter. + * @param value value to shift + * @param offset shift offset + * + * @return value << offset, if offset>=0; value >> -offset - otherwise + */ +static inline int bidir_sal(int value, int offset) +{ + if(offset < 0) return value >> -offset; + else return value << offset; +} + +#endif /* FFMPEG_ACELP_MATH_H */ diff --git a/src/add-ons/media/plugins/avcodec/libavcodec/acelp_pitch_delay.h b/src/add-ons/media/plugins/avcodec/libavcodec/acelp_pitch_delay.h new file mode 100644 index 0000000000..b5b9add7f2 --- /dev/null +++ b/src/add-ons/media/plugins/avcodec/libavcodec/acelp_pitch_delay.h @@ -0,0 +1,220 @@ +/* + * gain code, gain pitch and pitch delay decoding + * + * Copyright (c) 2008 Vladimir Voroshilov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_ACELP_PITCH_DELAY_H +#define FFMPEG_ACELP_PITCH_DELAY_H + +#include + +#define PITCH_DELAY_MIN 20 +#define PITCH_DELAY_MAX 143 + +/** + * \brief Decode pitch delay of the first subframe encoded by 8 bits with 1/3 + * resolution. + * \param ac_index adaptive codebook index (8 bits) + * + * \return pitch delay in 1/3 units + * + * Pitch delay is coded: + * with 1/3 resolution, 19 < pitch_delay < 85 + * integers only, 85 <= pitch_delay <= 143 + */ +int ff_acelp_decode_8bit_to_1st_delay3(int ac_index); + +/** + * \brief Decode pitch delay of the second subframe encoded by 5 or 6 bits + * with 1/3 precision. + * \param ac_index adaptive codebook index (5 or 6 bits) + * \param pitch_delay_min lower bound (integer) of pitch delay interval + * for second subframe + * + * \return pitch delay in 1/3 units + * + * Pitch delay is coded: + * with 1/3 resolution, -6 < pitch_delay - int(prev_pitch_delay) < 5 + * + * \remark The routine is used in G.729 @8k, AMR @10.2k, AMR @7.95k, + * AMR @7.4k for the second subframe. + */ +int ff_acelp_decode_5_6_bit_to_2nd_delay3( + int ac_index, + int pitch_delay_min); + +/** + * \brief Decode pitch delay with 1/3 precision. + * \param ac_index adaptive codebook index (4 bits) + * \param pitch_delay_min lower bound (integer) of pitch delay interval for + * second subframe + * + * \return pitch delay in 1/3 units + * + * Pitch delay is coded: + * integers only, -6 < pitch_delay - int(prev_pitch_delay) <= -2 + * with 1/3 resolution, -2 < pitch_delay - int(prev_pitch_delay) < 1 + * integers only, 1 <= pitch_delay - int(prev_pitch_delay) < 5 + * + * \remark The routine is used in G.729 @6.4k, AMR @6.7k, AMR @5.9k, + * AMR @5.15k, AMR @4.75k for the second subframe. + */ +int ff_acelp_decode_4bit_to_2nd_delay3( + int ac_index, + int pitch_delay_min); + +/** + * \brief Decode pitch delay of the first subframe encoded by 9 bits + * with 1/6 precision. + * \param ac_index adaptive codebook index (9 bits) + * \param pitch_delay_min lower bound (integer) of pitch delay interval for + * second subframe + * + * \return pitch delay in 1/6 units + * + * Pitch delay is coded: + * with 1/6 resolution, 17 < pitch_delay < 95 + * integers only, 95 <= pitch_delay <= 143 + * + * \remark The routine is used in AMR @12.2k for the first and third subframes. + */ +int ff_acelp_decode_9bit_to_1st_delay6(int ac_index); + +/** + * \brief Decode pitch delay of the second subframe encoded by 6 bits + * with 1/6 precision. + * \param ac_index adaptive codebook index (6 bits) + * \param pitch_delay_min lower bound (integer) of pitch delay interval for + * second subframe + * + * \return pitch delay in 1/6 units + * + * Pitch delay is coded: + * with 1/6 resolution, -6 < pitch_delay - int(prev_pitch_delay) < 5 + * + * \remark The routine is used in AMR @12.2k for the second and fourth subframes. + */ +int ff_acelp_decode_6bit_to_2nd_delay6( + int ac_index, + int pitch_delay_min); + +/** + * \brief Update past quantized energies + * \param quant_energy [in/out] past quantized energies (5.10) + * \param gain_corr_factor gain correction factor + * \param log2_ma_pred_order log2() of MA prediction order + * \param erasure frame erasure flag + * + * If frame erasure flag is not equal to zero, memory is updated with + * averaged energy, attenuated by 4dB: + * max(avg(quant_energy[i])-4, -14), i=0,ma_pred_order + * + * In normal mode memory is updated with + * Er - Ep = 20 * log10(gain_corr_factor) + * + * \remark The routine is used in G.729 and AMR (all modes). + */ +void ff_acelp_update_past_gain( + int16_t* quant_energy, + int gain_corr_factor, + int log2_ma_pred_order, + int erasure); + +/** + * \brief Decode the adaptive codebook gain and add + * correction (4.1.5 and 3.9.1 of G.729). + * \param gain_corr_factor gain correction factor (2.13) + * \param fc_v fixed-codebook vector (2.13) + * \param mr_energy mean innovation energy and fixed-point correction (7.13) + * \param quant_energy [in/out] past quantized energies (5.10) + * \param subframe_size length of subframe + * \param ma_pred_order MA prediction order + * + * \return quantized fixed-codebook gain (14.1) + * + * The routine implements equations 69, 66 and 71 of the G.729 specification (3.9.1) + * + * Em - mean innovation energy (dB, constant, depends on decoding algorithm) + * Ep - mean-removed predicted energy (dB) + * Er - mean-removed innovation energy (dB) + * Ei - mean energy of the fixed-codebook contribution (dB) + * N - subframe_size + * M - MA (Moving Average) prediction order + * gc - fixed-codebook gain + * gc_p - predicted fixed-codebook gain + * + * Fixed codebook gain is computed using predicted gain gc_p and + * correction factor gain_corr_factor as shown below: + * + * gc = gc_p * gain_corr_factor + * + * The predicted fixed codebook gain gc_p is found by predicting + * the energy of the fixed-codebook contribution from the energy + * of previous fixed-codebook contributions. + * + * mean = 1/N * sum(i,0,N){ fc_v[i] * fc_v[i] } + * + * Ei = 10log(mean) + * + * Er = 10log(1/N * gc^2 * mean) - Em = 20log(gc) + Ei - Em + * + * Replacing Er with Ep and gc with gc_p we will receive: + * + * Ep = 10log(1/N * gc_p^2 * mean) - Em = 20log(gc_p) + Ei - Em + * + * and from above: + * + * gc_p = 10^((Ep - Ei + Em) / 20) + * + * Ep is predicted using past energies and prediction coefficients: + * + * Ep = sum(i,0,M){ ma_prediction_coeff[i] * quant_energy[i] } + * + * gc_p in fixed-point arithmetic is calculated as following: + * + * mean = 1/N * sum(i,0,N){ (fc_v[i] / 2^13) * (fc_v[i] / 2^13) } = + * = 1/N * sum(i,0,N) { fc_v[i] * fc_v[i] } / 2^26 + * + * Ei = 10log(mean) = -10log(N) - 10log(2^26) + + * + 10log(sum(i,0,N) { fc_v[i] * fc_v[i] }) + * + * Ep - Ei + Em = Ep + Em + 10log(N) + 10log(2^26) - + * - 10log(sum(i,0,N) { fc_v[i] * fc_v[i] }) = + * = Ep + mr_energy - 10log(sum(i,0,N) { fc_v[i] * fc_v[i] }) + * + * gc_p = 10 ^ ((Ep - Ei + Em) / 20) = + * = 2 ^ (3.3219 * (Ep - Ei + Em) / 20) = 2 ^ (0.166 * (Ep - Ei + Em)) + * + * where + * + * mr_energy = Em + 10log(N) + 10log(2^26) + * + * \remark The routine is used in G.729 and AMR (all modes). + */ +int16_t ff_acelp_decode_gain_code( + int gain_corr_factor, + const int16_t* fc_v, + int mr_energy, + const int16_t* quant_energy, + const int16_t* ma_prediction_coeff, + int subframe_size, + int max_pred_order); + +#endif /* FFMPEG_ACELP_PITCH_DELAY_H */ diff --git a/src/add-ons/media/plugins/avcodec/libavcodec/acelp_vectors.h b/src/add-ons/media/plugins/avcodec/libavcodec/acelp_vectors.h new file mode 100644 index 0000000000..ae6c0b23c3 --- /dev/null +++ b/src/add-ons/media/plugins/avcodec/libavcodec/acelp_vectors.h @@ -0,0 +1,153 @@ +/* + * adaptive and fixed codebook vector operations for ACELP-based codecs + * + * Copyright (c) 2008 Vladimir Voroshilov + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_ACELP_VECTORS_H +#define FFMPEG_ACELP_VECTORS_H + +#include + +/** + * Track|Pulse| Positions + * ------------------------------------------------------------------------- + * 1 | 0 | 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75 + * ------------------------------------------------------------------------- + * 2 | 1 | 1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76 + * ------------------------------------------------------------------------- + * 3 | 2 | 2, 7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57, 62, 67, 72, 77 + * ------------------------------------------------------------------------- + * + * Table contains only first the pulse indexes. + * + * Used in G.729 @8k, G.729 @4.4k, AMR @7.95k, AMR @7.40k + */ +extern const uint8_t ff_fc_4pulses_8bits_tracks_13[16]; + +/** + * Track|Pulse| Positions + * ------------------------------------------------------------------------- + * 4 | 3 | 3, 8, 13, 18, 23, 28, 33, 38, 43, 48, 53, 58, 63, 68, 73, 78 + * | | 4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59, 64, 69, 74, 79 + * ------------------------------------------------------------------------- + * + * @remark Track in the table should be read top-to-bottom, left-to-right. + * + * Used in G.729 @8k, G.729 @4.4k, AMR @7.95k, AMR @7.40k + */ +extern const uint8_t ff_fc_4pulses_8bits_track_4[32]; + +/** + * Track|Pulse| Positions + * ----------------------------------------- + * 1 | 0 | 1, 6, 11, 16, 21, 26, 31, 36 + * | | 3, 8, 13, 18, 23, 28, 33, 38 + * ----------------------------------------- + * + * @remark Track in the table should be read top-to-bottom, left-to-right. + * + * @note (EE) Reference G.729D code also uses gray decoding for each + * pulse index before looking up the value in the table. + * + * Used in G.729 @6.4k (with gray coding), AMR @5.9k (without gray coding) + */ +extern const uint8_t ff_fc_2pulses_9bits_track1[16]; +extern const uint8_t ff_fc_2pulses_9bits_track1_gray[16]; + +/** + * Track|Pulse| Positions + * ----------------------------------------- + * 2 | 1 | 0, 7, 14, 20, 27, 34, 1, 21 + * | | 2, 9, 15, 22, 29, 35, 6, 26 + * | | 4,10, 17, 24, 30, 37, 11, 31 + * | | 5,12, 19, 25, 32, 39, 16, 36 + * ----------------------------------------- + * + * @remark Track in the table should be read top-to-bottom, left-to-right. + * + * @note (EE.1) This table (from the reference code) does not comply with + * the specification. + * The specification contains the following table: + * + * Track|Pulse| Positions + * ----------------------------------------- + * 2 | 1 | 0, 5, 10, 15, 20, 25, 30, 35 + * | | 1, 6, 11, 16, 21, 26, 31, 36 + * | | 2, 7, 12, 17, 22, 27, 32, 37 + * | | 4, 9, 14, 19, 24, 29, 34, 39 + * + * ----------------------------------------- + * + * @note (EE.2) Reference G.729D code also uses gray decoding for each + * pulse index before looking up the value in the table. + * + * Used in G.729 @6.4k (with gray coding) + */ +extern const uint8_t ff_fc_2pulses_9bits_track2_gray[32]; + +/** + * Decode fixed-codebook vector (3.8 and D.5.8 of G.729, 5.7.1 of AMR). + * @param fc_v [out] decoded fixed codebook vector (2.13) + * @param tab1 table used for first pulse_count pulses + * @param tab2 table used for last pulse + * @param pulse_indexes fixed codebook indexes + * @param pulse_signs signs of the excitation pulses (0 bit value + * means negative sign) + * @param bits number of bits per one pulse index + * @param pulse_count number of pulses decoded using first table + * @param bits length of one pulse index in bits + * + * Used in G.729 @8k, G.729 @4.4k, G.729 @6.4k, AMR @7.95k, AMR @7.40k + */ +void ff_acelp_fc_pulse_per_track( + int16_t* fc_v, + const uint8_t *tab1, + const uint8_t *tab2, + int pulse_indexes, + int pulse_signs, + int pulse_count, + int bits); + +/** + * weighted sum of two vectors with rounding. + * @param out [out] result of addition + * @param in_a first vector + * @param in_b second vector + * @param weight_coeff_a first vector weight coefficient + * @param weight_coeff_a second vector weight coefficient + * @param rounder this value will be added to the sum of the two vectors + * @param shift result will be shifted to right by this value + * @param length vectors length + * + * @note It is safe to pass the same buffer for out and in_a or in_b. + * + * out[i] = (in_a[i]*weight_a + in_b[i]*weight_b + rounder) >> shift + */ +void ff_acelp_weighted_vector_sum( + int16_t* out, + const int16_t *in_a, + const int16_t *in_b, + int16_t weight_coeff_a, + int16_t weight_coeff_b, + int16_t rounder, + int shift, + int length); + +#endif /* FFMPEG_ACELP_VECTORS_H */ diff --git a/src/add-ons/media/plugins/avcodec/libavcodec/adx.h b/src/add-ons/media/plugins/avcodec/libavcodec/adx.h new file mode 100644 index 0000000000..16180372ac --- /dev/null +++ b/src/add-ons/media/plugins/avcodec/libavcodec/adx.h @@ -0,0 +1,49 @@ +/* + * ADX ADPCM codecs + * Copyright (c) 2001,2003 BERO + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file adx.h + * SEGA CRI adx codecs. + * + * Reference documents: + * http://ku-www.ss.titech.ac.jp/~yatsushi/adx.html + * adx2wav & wav2adx http://www.geocities.co.jp/Playtown/2004/ + */ + +#ifndef FFMPEG_ADX_H +#define FFMPEG_ADX_H + +typedef struct { + int s1,s2; +} PREV; + +typedef struct { + PREV prev[2]; + int header_parsed; + unsigned char dec_temp[18*2]; + int in_temp; +} ADXContext; + +#define BASEVOL 0x4000 +#define SCALE1 0x7298 +#define SCALE2 0x3350 + +#endif /* FFMPEG_ADX_H */ diff --git a/src/add-ons/media/plugins/avcodec/libavcodec/atrac3data.h b/src/add-ons/media/plugins/avcodec/libavcodec/atrac3data.h new file mode 100644 index 0000000000..555a3a20d6 --- /dev/null +++ b/src/add-ons/media/plugins/avcodec/libavcodec/atrac3data.h @@ -0,0 +1,140 @@ +/* + * Atrac 3 compatible decoder data + * Copyright (c) 2006-2007 Maxim Poliakovski + * Copyright (c) 2006-2007 Benjamin Larsson + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file atrac3data.h + * Atrac 3 AKA RealAudio 8 compatible decoder data + */ + +#ifndef FFMPEG_ATRAC3DATA_H +#define FFMPEG_ATRAC3DATA_H + +#include + +/* VLC tables */ + +static const uint8_t huffcode1[9] = { + 0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F, +}; + +static const uint8_t huffbits1[9] = { + 1,3,3,4,4,5,5,5,5, +}; + +static const uint8_t huffcode2[5] = { + 0x0,0x4,0x5,0x6,0x7, +}; + +static const uint8_t huffbits2[5] = { + 1,3,3,3,3, +}; + +static const uint8_t huffcode3[7] = { +0x0,0x4,0x5,0xC,0xD,0xE,0xF, +}; + +static const uint8_t huffbits3[7] = { + 1,3,3,4,4,4,4, +}; + +static const uint8_t huffcode4[9] = { + 0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F, +}; + +static const uint8_t huffbits4[9] = { + 1,3,3,4,4,5,5,5,5, +}; + +static const uint8_t huffcode5[15] = { + 0x0,0x2,0x3,0x8,0x9,0xA,0xB,0x1C,0x1D,0x3C,0x3D,0x3E,0x3F,0xC,0xD, +}; + +static const uint8_t huffbits5[15] = { + 2,3,3,4,4,4,4,5,5,6,6,6,6,4,4 +}; + +static const uint8_t huffcode6[31] = { + 0x0,0x2,0x3,0x4,0x5,0x6,0x7,0x14,0x15,0x16,0x17,0x18,0x19,0x34,0x35, + 0x36,0x37,0x38,0x39,0x3A,0x3B,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,0x8,0x9, +}; + +static const uint8_t huffbits6[31] = { + 3,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,4,4 +}; + +static const uint8_t huffcode7[63] = { + 0x0,0x8,0x9,0xA,0xB,0xC,0xD,0xE,0xF,0x10,0x11,0x24,0x25,0x26,0x27,0x28, + 0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x68,0x69,0x6A,0x6B,0x6C, + 0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,0x74,0x75,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2, + 0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,0x2,0x3, +}; + +static const uint8_t huffbits7[63] = { + 3,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,4,4 +}; + +static const uint8_t huff_tab_sizes[7] = { + 9, 5, 7, 9, 15, 31, 63, +}; + +static const uint8_t* const huff_codes[7] = { + huffcode1,huffcode2,huffcode3,huffcode4,huffcode5,huffcode6,huffcode7, +}; + +static const uint8_t* const huff_bits[7] = { + huffbits1,huffbits2,huffbits3,huffbits4,huffbits5,huffbits6,huffbits7, +}; + +/* selector tables */ + +static const uint8_t CLCLengthTab[8] = {0, 4, 3, 3, 4, 4, 5, 6}; +static const int8_t seTab_0[4] = {0, 1, -2, -1}; +static const int8_t decTable1[18] = {0,0, 0,1, 0,-1, 1,0, -1,0, 1,1, 1,-1, -1,1, -1,-1}; + + +/* tables for the scalefactor decoding */ + +static const float iMaxQuant[8] = { + 0.0, 1.0/1.5, 1.0/2.5, 1.0/3.5, 1.0/4.5, 1.0/7.5, 1.0/15.5, 1.0/31.5 +}; + +static const uint16_t subbandTab[33] = { + 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, + 256, 288, 320, 352, 384, 416, 448, 480, 512, 576, 640, 704, 768, 896, 1024 +}; + +/* transform data */ + +static const float qmf_48tap_half[24] = { + -0.00001461907, -0.00009205479, -0.000056157569, 0.00030117269, + 0.0002422519,-0.00085293897, -0.0005205574, 0.0020340169, + 0.00078333891, -0.0042153862, -0.00075614988, 0.0078402944, + -0.000061169922, -0.01344162, 0.0024626821, 0.021736089, + -0.007801671, -0.034090221, 0.01880949, 0.054326009, + -0.043596379, -0.099384367, 0.13207909, 0.46424159 +}; + +/* joint stereo related tables */ +static const float matrixCoeffs[8] = {0.0, 2.0, 2.0, 2.0, 0.0, 0.0, 1.0, 1.0}; + +#endif /* FFMPEG_ATRAC3DATA_H */ diff --git a/src/add-ons/media/plugins/avcodec/libavcodec/audioconvert.h b/src/add-ons/media/plugins/avcodec/libavcodec/audioconvert.h new file mode 100644 index 0000000000..e10849bd3a --- /dev/null +++ b/src/add-ons/media/plugins/avcodec/libavcodec/audioconvert.h @@ -0,0 +1,91 @@ +/* + * audio conversion + * Copyright (c) 2006 Michael Niedermayer + * Copyright (c) 2008 Peter Ross + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_AUDIOCONVERT_H +#define FFMPEG_AUDIOCONVERT_H + +/** + * @file audioconvert.h + * Audio format conversion routines + */ + + +#include "avcodec.h" + + +/** + * Generate string corresponding to the sample format with + * number sample_fmt, or a header if sample_fmt is negative. + * + * @param[in] buf the buffer where to write the string + * @param[in] buf_size the size of buf + * @param[in] sample_fmt the number of the sample format to print the corresponding info string, or + * a negative value to print the corresponding header. + * Meaningful values for obtaining a sample format info vary from 0 to SAMPLE_FMT_NB -1. + */ +void avcodec_sample_fmt_string(char *buf, int buf_size, int sample_fmt); + +/** + * @return NULL on error + */ +const char *avcodec_get_sample_fmt_name(int sample_fmt); + +/** + * @return SAMPLE_FMT_NONE on error + */ +enum SampleFormat avcodec_get_sample_fmt(const char* name); + +struct AVAudioConvert; +typedef struct AVAudioConvert AVAudioConvert; + +/** + * Create an audio sample format converter context + * @param out_fmt Output sample format + * @param out_channels Number of output channels + * @param in_fmt Input sample format + * @param in_channels Number of input channels + * @param[in] matrix Channel mixing matrix (of dimension in_channel*out_channels). Set to NULL to ignore. + * @param flags See FF_MM_xx + * @return NULL on error + */ +AVAudioConvert *av_audio_convert_alloc(enum SampleFormat out_fmt, int out_channels, + enum SampleFormat in_fmt, int in_channels, + const float *matrix, int flags); + +/** + * Free audio sample format converter context + */ +void av_audio_convert_free(AVAudioConvert *ctx); + +/** + * Convert between audio sample formats + * @param[in] out array of output buffers for each channel. set to NULL to ignore processing of the given channel. + * @param[in] out_stride distance between consecutive input samples (measured in bytes) + * @param[in] in array of input buffers for each channel + * @param[in] in_stride distance between consecutive output samples (measured in bytes) + * @param len length of audio frame size (measured in samples) + */ +int av_audio_convert(AVAudioConvert *ctx, + void * const out[6], const int out_stride[6], + const void * const in[6], const int in_stride[6], int len); + +#endif /* FFMPEG_AUDIOCONVERT_H */ diff --git a/src/add-ons/media/plugins/avcodec/libavcodec/avcodec.h b/src/add-ons/media/plugins/avcodec/libavcodec/avcodec.h index 4f2b87e87c..9caa0a2064 100644 --- a/src/add-ons/media/plugins/avcodec/libavcodec/avcodec.h +++ b/src/add-ons/media/plugins/avcodec/libavcodec/avcodec.h @@ -1,47 +1,80 @@ -#ifndef AVCODEC_H -#define AVCODEC_H +/* + * copyright (c) 2001 Fabrice Bellard + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_AVCODEC_H +#define FFMPEG_AVCODEC_H /** * @file avcodec.h - * external api header. + * external API header */ -#ifdef __cplusplus -extern "C" { -#endif +#include "avutil.h" -#include "common.h" -#include "rational.h" -#include /* size_t */ +#define LIBAVCODEC_VERSION_MAJOR 51 +#define LIBAVCODEC_VERSION_MINOR 69 +#define LIBAVCODEC_VERSION_MICRO 0 -#define FFMPEG_VERSION_INT 0x000408 -#define FFMPEG_VERSION "0.4.8" -#define LIBAVCODEC_BUILD 4699 +#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ + LIBAVCODEC_VERSION_MINOR, \ + LIBAVCODEC_VERSION_MICRO) +#define LIBAVCODEC_VERSION AV_VERSION(LIBAVCODEC_VERSION_MAJOR, \ + LIBAVCODEC_VERSION_MINOR, \ + LIBAVCODEC_VERSION_MICRO) +#define LIBAVCODEC_BUILD LIBAVCODEC_VERSION_INT -#define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT -#define LIBAVCODEC_VERSION FFMPEG_VERSION +#define LIBAVCODEC_IDENT "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION) -#define AV_STRINGIFY(s) AV_TOSTRING(s) -#define AV_TOSTRING(s) #s -#define LIBAVCODEC_IDENT "FFmpeg" LIBAVCODEC_VERSION "b" AV_STRINGIFY(LIBAVCODEC_BUILD) +#define AV_NOPTS_VALUE INT64_C(0x8000000000000000) +#define AV_TIME_BASE 1000000 +#define AV_TIME_BASE_Q (AVRational){1, AV_TIME_BASE} +/** + * Identifies the syntax and semantics of the bitstream. + * The principle is roughly: + * Two decoders with the same ID can decode the same streams. + * Two encoders with the same ID can encode compatible streams. + * There may be slight deviations from the principle due to implementation + * details. + * + * If you add a codec ID to this list, add it so that + * 1. no value of a existing codec ID changes (that would break ABI), + * 2. it is as close as possible to similar codecs. + */ enum CodecID { - CODEC_ID_NONE, + CODEC_ID_NONE, + + /* video codecs */ CODEC_ID_MPEG1VIDEO, - CODEC_ID_MPEG2VIDEO, /* prefered ID for MPEG Video 1 or 2 decoding */ + CODEC_ID_MPEG2VIDEO, ///< preferred ID for MPEG-1/2 video decoding CODEC_ID_MPEG2VIDEO_XVMC, + CODEC_ID_H261, CODEC_ID_H263, CODEC_ID_RV10, CODEC_ID_RV20, - CODEC_ID_MP2, - CODEC_ID_MP3, /* prefered ID for MPEG Audio layer 1, 2 or3 decoding */ - CODEC_ID_VORBIS, - CODEC_ID_AC3, CODEC_ID_MJPEG, CODEC_ID_MJPEGB, CODEC_ID_LJPEG, CODEC_ID_SP5X, + CODEC_ID_JPEGLS, CODEC_ID_MPEG4, CODEC_ID_RAWVIDEO, CODEC_ID_MSMPEG4V1, @@ -55,19 +88,12 @@ enum CodecID { CODEC_ID_SVQ1, CODEC_ID_SVQ3, CODEC_ID_DVVIDEO, - CODEC_ID_DVAUDIO, - CODEC_ID_WMAV1, - CODEC_ID_WMAV2, - CODEC_ID_MACE3, - CODEC_ID_MACE6, CODEC_ID_HUFFYUV, CODEC_ID_CYUV, CODEC_ID_H264, CODEC_ID_INDEO3, CODEC_ID_VP3, CODEC_ID_THEORA, - CODEC_ID_AAC, - CODEC_ID_MPEG4AAC, CODEC_ID_ASV1, CODEC_ID_ASV2, CODEC_ID_FFV1, @@ -90,12 +116,82 @@ enum CodecID { CODEC_ID_FLIC, CODEC_ID_TRUEMOTION1, CODEC_ID_VMDVIDEO, - CODEC_ID_VMDAUDIO, CODEC_ID_MSZH, CODEC_ID_ZLIB, + CODEC_ID_QTRLE, + CODEC_ID_SNOW, + CODEC_ID_TSCC, + CODEC_ID_ULTI, + CODEC_ID_QDRAW, + CODEC_ID_VIXL, + CODEC_ID_QPEG, + CODEC_ID_XVID, + CODEC_ID_PNG, + CODEC_ID_PPM, + CODEC_ID_PBM, + CODEC_ID_PGM, + CODEC_ID_PGMYUV, + CODEC_ID_PAM, + CODEC_ID_FFVHUFF, + CODEC_ID_RV30, + CODEC_ID_RV40, + CODEC_ID_VC1, + CODEC_ID_WMV3, + CODEC_ID_LOCO, + CODEC_ID_WNV1, + CODEC_ID_AASC, + CODEC_ID_INDEO2, + CODEC_ID_FRAPS, + CODEC_ID_TRUEMOTION2, + CODEC_ID_BMP, + CODEC_ID_CSCD, + CODEC_ID_MMVIDEO, + CODEC_ID_ZMBV, + CODEC_ID_AVS, + CODEC_ID_SMACKVIDEO, + CODEC_ID_NUV, + CODEC_ID_KMVC, + CODEC_ID_FLASHSV, + CODEC_ID_CAVS, + CODEC_ID_JPEG2000, + CODEC_ID_VMNC, + CODEC_ID_VP5, + CODEC_ID_VP6, + CODEC_ID_VP6F, + CODEC_ID_TARGA, + CODEC_ID_DSICINVIDEO, + CODEC_ID_TIERTEXSEQVIDEO, + CODEC_ID_TIFF, + CODEC_ID_GIF, + CODEC_ID_FFH264, + CODEC_ID_DXA, + CODEC_ID_DNXHD, + CODEC_ID_THP, + CODEC_ID_SGI, + CODEC_ID_C93, + CODEC_ID_BETHSOFTVID, + CODEC_ID_PTX, + CODEC_ID_TXD, + CODEC_ID_VP6A, + CODEC_ID_AMV, + CODEC_ID_VB, + CODEC_ID_PCX, + CODEC_ID_SUNRAST, + CODEC_ID_INDEO4, + CODEC_ID_INDEO5, + CODEC_ID_MIMIC, + CODEC_ID_RL2, + CODEC_ID_8SVX_EXP, + CODEC_ID_8SVX_FIB, + CODEC_ID_ESCAPE124, + CODEC_ID_DIRAC, + CODEC_ID_BFI, + CODEC_ID_CMV, + CODEC_ID_MOTIONPIXELS, + CODEC_ID_TGV, - /* various pcm "codecs" */ - CODEC_ID_PCM_S16LE, + /* various PCM "codecs" */ + CODEC_ID_PCM_S16LE= 0x10000, CODEC_ID_PCM_S16BE, CODEC_ID_PCM_U16LE, CODEC_ID_PCM_U16BE, @@ -103,202 +199,323 @@ enum CodecID { CODEC_ID_PCM_U8, CODEC_ID_PCM_MULAW, CODEC_ID_PCM_ALAW, + CODEC_ID_PCM_S32LE, + CODEC_ID_PCM_S32BE, + CODEC_ID_PCM_U32LE, + CODEC_ID_PCM_U32BE, + CODEC_ID_PCM_S24LE, + CODEC_ID_PCM_S24BE, + CODEC_ID_PCM_U24LE, + CODEC_ID_PCM_U24BE, + CODEC_ID_PCM_S24DAUD, + CODEC_ID_PCM_ZORK, + CODEC_ID_PCM_S16LE_PLANAR, + CODEC_ID_PCM_DVD, + CODEC_ID_PCM_F32BE, + CODEC_ID_PCM_F32LE, + CODEC_ID_PCM_F64BE, + CODEC_ID_PCM_F64LE, - /* various adpcm codecs */ - CODEC_ID_ADPCM_IMA_QT, + /* various ADPCM codecs */ + CODEC_ID_ADPCM_IMA_QT= 0x11000, CODEC_ID_ADPCM_IMA_WAV, CODEC_ID_ADPCM_IMA_DK3, CODEC_ID_ADPCM_IMA_DK4, CODEC_ID_ADPCM_IMA_WS, + CODEC_ID_ADPCM_IMA_SMJPEG, CODEC_ID_ADPCM_MS, CODEC_ID_ADPCM_4XM, CODEC_ID_ADPCM_XA, CODEC_ID_ADPCM_ADX, + CODEC_ID_ADPCM_EA, + CODEC_ID_ADPCM_G726, + CODEC_ID_ADPCM_CT, + CODEC_ID_ADPCM_SWF, + CODEC_ID_ADPCM_YAMAHA, + CODEC_ID_ADPCM_SBPRO_4, + CODEC_ID_ADPCM_SBPRO_3, + CODEC_ID_ADPCM_SBPRO_2, + CODEC_ID_ADPCM_THP, + CODEC_ID_ADPCM_IMA_AMV, + CODEC_ID_ADPCM_EA_R1, + CODEC_ID_ADPCM_EA_R3, + CODEC_ID_ADPCM_EA_R2, + CODEC_ID_ADPCM_IMA_EA_SEAD, + CODEC_ID_ADPCM_IMA_EA_EACS, + CODEC_ID_ADPCM_EA_XAS, + CODEC_ID_ADPCM_EA_MAXIS_XA, - /* AMR */ - CODEC_ID_AMR_NB, + /* AMR */ + CODEC_ID_AMR_NB= 0x12000, CODEC_ID_AMR_WB, /* RealAudio codecs*/ - CODEC_ID_RA_144, + CODEC_ID_RA_144= 0x13000, CODEC_ID_RA_288, /* various DPCM codecs */ - CODEC_ID_ROQ_DPCM, + CODEC_ID_ROQ_DPCM= 0x14000, CODEC_ID_INTERPLAY_DPCM, CODEC_ID_XAN_DPCM, - - CODEC_ID_MPEG2TS, /* _FAKE_ codec to indicate a raw MPEG2 transport - stream (only used by libavformat) */ + CODEC_ID_SOL_DPCM, + + /* audio codecs */ + CODEC_ID_MP2= 0x15000, + CODEC_ID_MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3 + CODEC_ID_AAC, +#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) + CODEC_ID_MPEG4AAC, +#endif + CODEC_ID_AC3, + CODEC_ID_DTS, + CODEC_ID_VORBIS, + CODEC_ID_DVAUDIO, + CODEC_ID_WMAV1, + CODEC_ID_WMAV2, + CODEC_ID_MACE3, + CODEC_ID_MACE6, + CODEC_ID_VMDAUDIO, + CODEC_ID_SONIC, + CODEC_ID_SONIC_LS, + CODEC_ID_FLAC, + CODEC_ID_MP3ADU, + CODEC_ID_MP3ON4, + CODEC_ID_SHORTEN, + CODEC_ID_ALAC, + CODEC_ID_WESTWOOD_SND1, + CODEC_ID_GSM, ///< as in Berlin toast format + CODEC_ID_QDM2, + CODEC_ID_COOK, + CODEC_ID_TRUESPEECH, + CODEC_ID_TTA, + CODEC_ID_SMACKAUDIO, + CODEC_ID_QCELP, + CODEC_ID_WAVPACK, + CODEC_ID_DSICINAUDIO, + CODEC_ID_IMC, + CODEC_ID_MUSEPACK7, + CODEC_ID_MLP, + CODEC_ID_GSM_MS, /* as found in WAV */ + CODEC_ID_ATRAC3, + CODEC_ID_VOXWARE, + CODEC_ID_APE, + CODEC_ID_NELLYMOSER, + CODEC_ID_MUSEPACK8, + CODEC_ID_SPEEX, + CODEC_ID_WMAVOICE, + CODEC_ID_WMAPRO, + CODEC_ID_WMALOSSLESS, + CODEC_ID_ATRAC3P, + + /* subtitle codecs */ + CODEC_ID_DVD_SUBTITLE= 0x17000, + CODEC_ID_DVB_SUBTITLE, + CODEC_ID_TEXT, ///< raw UTF-8 text + CODEC_ID_XSUB, + CODEC_ID_SSA, + CODEC_ID_MOV_TEXT, + + /* other specific kind of codecs (generally used for attachments) */ + CODEC_ID_TTF= 0x18000, + + CODEC_ID_PROBE= 0x19000, ///< codec_id is not known (like CODEC_ID_NONE) but lavf should attempt to identify it + + CODEC_ID_MPEG2TS= 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS + * stream (only used by libavformat) */ }; -/* CODEC_ID_MP3LAME is absolete */ +#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) +/* CODEC_ID_MP3LAME is obsolete */ #define CODEC_ID_MP3LAME CODEC_ID_MP3 +#define CODEC_ID_MPEG4AAC CODEC_ID_AAC +#endif enum CodecType { CODEC_TYPE_UNKNOWN = -1, CODEC_TYPE_VIDEO, CODEC_TYPE_AUDIO, CODEC_TYPE_DATA, + CODEC_TYPE_SUBTITLE, + CODEC_TYPE_ATTACHMENT, + CODEC_TYPE_NB }; /** - * Pixel format. Notes: - * - * PIX_FMT_RGBA32 is handled in an endian-specific manner. A RGBA - * color is put together as: - * (A << 24) | (R << 16) | (G << 8) | B - * This is stored as BGRA on little endian CPU architectures and ARGB on - * big endian CPUs. - * - * When the pixel format is palettized RGB (PIX_FMT_PAL8), the palettized - * image data is stored in AVFrame.data[0]. The palette is transported in - * AVFrame.data[1] and, is 1024 bytes long (256 4-byte entries) and is - * formatted the same as in PIX_FMT_RGBA32 described above (i.e., it is - * also endian-specific). Note also that the individual RGB palette - * components stored in AVFrame.data[1] should be in the range 0..255. - * This is important as many custom PAL8 video codecs that were designed - * to run on the IBM VGA graphics adapter use 6-bit palette components. + * Currently unused, may be used if 24/32 bits samples are ever supported. + * all in native-endian format */ -enum PixelFormat { - PIX_FMT_YUV420P, ///< Planar YUV 4:2:0 (1 Cr & Cb sample per 2x2 Y samples) - PIX_FMT_YUV422, - PIX_FMT_RGB24, ///< Packed pixel, 3 bytes per pixel, RGBRGB... - PIX_FMT_BGR24, ///< Packed pixel, 3 bytes per pixel, BGRBGR... - PIX_FMT_YUV422P, ///< Planar YUV 4:2:2 (1 Cr & Cb sample per 2x1 Y samples) - PIX_FMT_YUV444P, ///< Planar YUV 4:4:4 (1 Cr & Cb sample per 1x1 Y samples) - PIX_FMT_RGBA32, ///< Packed pixel, 4 bytes per pixel, BGRABGRA..., stored in cpu endianness - PIX_FMT_YUV410P, ///< Planar YUV 4:1:0 (1 Cr & Cb sample per 4x4 Y samples) - PIX_FMT_YUV411P, ///< Planar YUV 4:1:1 (1 Cr & Cb sample per 4x1 Y samples) - PIX_FMT_RGB565, ///< always stored in cpu endianness - PIX_FMT_RGB555, ///< always stored in cpu endianness, most significant bit to 1 - PIX_FMT_GRAY8, - PIX_FMT_MONOWHITE, ///< 0 is white - PIX_FMT_MONOBLACK, ///< 0 is black - PIX_FMT_PAL8, ///< 8 bit with RGBA palette - PIX_FMT_YUVJ420P, ///< Planar YUV 4:2:0 full scale (jpeg) - PIX_FMT_YUVJ422P, ///< Planar YUV 4:2:2 full scale (jpeg) - PIX_FMT_YUVJ444P, ///< Planar YUV 4:4:4 full scale (jpeg) - PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing(xvmc_render.h) - PIX_FMT_XVMC_MPEG2_IDCT, - PIX_FMT_NB, -}; - -/* currently unused, may be used if 24/32 bits samples ever supported */ enum SampleFormat { - SAMPLE_FMT_S16 = 0, ///< signed 16 bits + SAMPLE_FMT_NONE = -1, + SAMPLE_FMT_U8, ///< unsigned 8 bits + SAMPLE_FMT_S16, ///< signed 16 bits + SAMPLE_FMT_S24, ///< signed 24 bits @deprecated Deprecated in favor of SAMPLE_FMT_S32 + SAMPLE_FMT_S32, ///< signed 32 bits + SAMPLE_FMT_FLT, ///< float + SAMPLE_FMT_DBL, ///< double + SAMPLE_FMT_NB ///< Number of sample formats. DO NOT USE if dynamically linking to libavcodec }; /* in bytes */ -#define AVCODEC_MAX_AUDIO_FRAME_SIZE 131072 +#define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio /** * Required number of additionally allocated bytes at the end of the input bitstream for decoding. - * this is mainly needed because some optimized bitstream readers read - * 32 or 64 bit at once and could read over the end
- * Note, if the first 23 bits of the additional bytes are not 0 then damaged - * MPEG bitstreams could cause overread and segfault + * This is mainly needed because some optimized bitstream readers read + * 32 or 64 bit at once and could read over the end.
+ * Note: If the first 23 bits of the additional bytes are not 0, then damaged + * MPEG bitstreams could cause overread and segfault. */ #define FF_INPUT_BUFFER_PADDING_SIZE 8 -/* motion estimation type, EPZS by default */ +/** + * minimum encoding buffer size + * Used to avoid some checks during header writing. + */ +#define FF_MIN_BUFFER_SIZE 16384 + +/** + * motion estimation type. + */ enum Motion_Est_ID { - ME_ZERO = 1, + ME_ZERO = 1, ///< no search, that is use 0,0 vector whenever one is needed ME_FULL, ME_LOG, ME_PHODS, - ME_EPZS, - ME_X1 + ME_EPZS, ///< enhanced predictive zonal search + ME_X1, ///< reserved for experiments + ME_HEX, ///< hexagon based search + ME_UMH, ///< uneven multi-hexagon search + ME_ITER, ///< iterative search + ME_TESA, ///< transformed exhaustive search algorithm +}; + +enum AVDiscard{ + /* We leave some space between them for extensions (drop some + * keyframes for intra-only or drop just some bidir frames). */ + AVDISCARD_NONE =-16, ///< discard nothing + AVDISCARD_DEFAULT= 0, ///< discard useless packets like 0 size packets in avi + AVDISCARD_NONREF = 8, ///< discard all non reference + AVDISCARD_BIDIR = 16, ///< discard all bidirectional frames + AVDISCARD_NONKEY = 32, ///< discard all frames except keyframes + AVDISCARD_ALL = 48, ///< discard all }; typedef struct RcOverride{ int start_frame; int end_frame; - int qscale; // if this is 0 then quality_factor will be used instead + int qscale; // If this is 0 then quality_factor will be used instead. float quality_factor; } RcOverride; -/* only for ME compatiblity with old apps */ -extern int motion_estimation_method; - -/* ME algos sorted by quality */ -//FIXME remove IMHO -static const __attribute__((unused)) int Motion_Est_QTab[] = - { ME_ZERO, ME_PHODS, ME_LOG, ME_X1, ME_EPZS, ME_FULL }; - - -#define FF_MAX_B_FRAMES 8 +#define FF_MAX_B_FRAMES 16 /* encoding support - these flags can be passed in AVCodecContext.flags before initing - Note: note not everything is supported yet + These flags can be passed in AVCodecContext.flags before initialization. + Note: Not everything is supported yet. */ -#define CODEC_FLAG_QSCALE 0x0002 ///< use fixed qscale -#define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed / Advanced prediction for H263 -#define CODEC_FLAG_QPEL 0x0010 ///< use qpel MC -#define CODEC_FLAG_GMC 0x0020 ///< use GMC -#define CODEC_FLAG_MV0 0x0040 ///< always try a MB with MV=<0,0> -#define CODEC_FLAG_PART 0x0080 ///< use data partitioning -/* parent program gurantees that the input for b-frame containing streams is not written to - for at least s->max_b_frames+1 frames, if this is not set than the input will be copied */ +#define CODEC_FLAG_QSCALE 0x0002 ///< Use fixed qscale. +#define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed / advanced prediction for H.263. +#define CODEC_FLAG_QPEL 0x0010 ///< Use qpel MC. +#define CODEC_FLAG_GMC 0x0020 ///< Use GMC. +#define CODEC_FLAG_MV0 0x0040 ///< Always try a MB with MV=<0,0>. +#define CODEC_FLAG_PART 0x0080 ///< Use data partitioning. +/** + * The parent program guarantees that the input for B-frames containing + * streams is not written to for at least s->max_b_frames+1 frames, if + * this is not set the input will be copied. + */ #define CODEC_FLAG_INPUT_PRESERVED 0x0100 -#define CODEC_FLAG_PASS1 0x0200 ///< use internal 2pass ratecontrol in first pass mode -#define CODEC_FLAG_PASS2 0x0400 ///< use internal 2pass ratecontrol in second pass mode -#define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< use external huffman table (for mjpeg) -#define CODEC_FLAG_GRAY 0x2000 ///< only decode/encode grayscale -#define CODEC_FLAG_EMU_EDGE 0x4000///< dont draw edges -#define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding -#define CODEC_FLAG_TRUNCATED 0x00010000 /** input bitstream might be truncated at a random location instead - of only at frame boundaries */ -#define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< normalize adaptive quantization -#define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< use interlaced dct -#define CODEC_FLAG_LOW_DELAY 0x00080000 ///< force low delay -#define CODEC_FLAG_ALT_SCAN 0x00100000 ///< use alternate scan -#define CODEC_FLAG_TRELLIS_QUANT 0x00200000 ///< use trellis quantization -#define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< place global headers in extradata instead of every keyframe -#define CODEC_FLAG_BITEXACT 0x00800000 ///< use only bitexact stuff (except (i)dct) +#define CODEC_FLAG_PASS1 0x0200 ///< Use internal 2pass ratecontrol in first pass mode. +#define CODEC_FLAG_PASS2 0x0400 ///< Use internal 2pass ratecontrol in second pass mode. +#define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< Use external Huffman table (for MJPEG). +#define CODEC_FLAG_GRAY 0x2000 ///< Only decode/encode grayscale. +#define CODEC_FLAG_EMU_EDGE 0x4000 ///< Don't draw edges. +#define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding. +#define CODEC_FLAG_TRUNCATED 0x00010000 /** Input bitstream might be truncated at a random + location instead of only at frame boundaries. */ +#define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< Normalize adaptive quantization. +#define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< Use interlaced DCT. +#define CODEC_FLAG_LOW_DELAY 0x00080000 ///< Force low delay. +#define CODEC_FLAG_ALT_SCAN 0x00100000 ///< Use alternate scan. +#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) +#define CODEC_FLAG_TRELLIS_QUANT 0x00200000 ///< Use trellis quantization. +#endif +#define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< Place global headers in extradata instead of every keyframe. +#define CODEC_FLAG_BITEXACT 0x00800000 ///< Use only bitexact stuff (except (I)DCT). /* Fx : Flag for h263+ extra options */ -#define CODEC_FLAG_H263P_AIC 0x01000000 ///< H263 Advanced intra coding / MPEG4 AC prediction (remove this) -#define CODEC_FLAG_AC_PRED 0x01000000 ///< H263 Advanced intra coding / MPEG4 AC prediction -#define CODEC_FLAG_H263P_UMV 0x02000000 ///< Unlimited motion vector -#define CODEC_FLAG_CBP_RD 0x04000000 ///< use rate distortion optimization for cbp -#define CODEC_FLAG_QP_RD 0x08000000 ///< use rate distortion optimization for qp selectioon -#define CODEC_FLAG_H263P_AIV 0x00000008 ///< H263 Alternative inter vlc +#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) +#define CODEC_FLAG_H263P_AIC 0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction (remove this) +#endif +#define CODEC_FLAG_AC_PRED 0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction +#define CODEC_FLAG_H263P_UMV 0x02000000 ///< unlimited motion vector +#define CODEC_FLAG_CBP_RD 0x04000000 ///< Use rate distortion optimization for cbp. +#define CODEC_FLAG_QP_RD 0x08000000 ///< Use rate distortion optimization for qp selectioon. +#define CODEC_FLAG_H263P_AIV 0x00000008 ///< H.263 alternative inter VLC #define CODEC_FLAG_OBMC 0x00000001 ///< OBMC #define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter #define CODEC_FLAG_H263P_SLICE_STRUCT 0x10000000 #define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation -#define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< will reserve space for SVCD scan offset user data +#define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< Will reserve space for SVCD scan offset user data. #define CODEC_FLAG_CLOSED_GOP 0x80000000 +#define CODEC_FLAG2_FAST 0x00000001 ///< Allow non spec compliant speedup tricks. +#define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< Strictly enforce GOP size. +#define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< Skip bitstream encoding. +#define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< Place global headers at every keyframe instead of in extradata. +#define CODEC_FLAG2_BPYRAMID 0x00000010 ///< H.264 allow B-frames to be used as references. +#define CODEC_FLAG2_WPRED 0x00000020 ///< H.264 weighted biprediction for B-frames +#define CODEC_FLAG2_MIXED_REFS 0x00000040 ///< H.264 one reference per partition, as opposed to one reference per macroblock +#define CODEC_FLAG2_8X8DCT 0x00000080 ///< H.264 high profile 8x8 transform +#define CODEC_FLAG2_FASTPSKIP 0x00000100 ///< H.264 fast pskip +#define CODEC_FLAG2_AUD 0x00000200 ///< H.264 access unit delimiters +#define CODEC_FLAG2_BRDO 0x00000400 ///< B-frame rate-distortion optimization +#define CODEC_FLAG2_INTRA_VLC 0x00000800 ///< Use MPEG-2 intra VLC table. +#define CODEC_FLAG2_MEMC_ONLY 0x00001000 ///< Only do ME/MC (I frames -> ref, P frame -> ME+MC). +#define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format. +#define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skipping +#define CODEC_FLAG2_CHUNKS 0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries. +#define CODEC_FLAG2_NON_LINEAR_QUANT 0x00010000 ///< Use MPEG-2 nonlinear quantizer. +#define CODEC_FLAG2_BIT_RESERVOIR 0x00020000 ///< Use a bit reservoir when encoding if possible + /* Unsupported options : - * Syntax Arithmetic coding (SAC) - * Reference Picture Selection - * Independant Segment Decoding */ + * Syntax Arithmetic coding (SAC) + * Reference Picture Selection + * Independent Segment Decoding */ /* /Fx */ /* codec capabilities */ -#define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< decoder can use draw_horiz_band callback +#define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< Decoder can use draw_horiz_band callback. /** * Codec uses get_buffer() for allocating buffers. * direct rendering method 1 */ #define CODEC_CAP_DR1 0x0002 -/* if 'parse_only' field is true, then avcodec_parse_frame() can be - used */ +/* If 'parse_only' field is true, then avcodec_parse_frame() can be used. */ #define CODEC_CAP_PARSE_ONLY 0x0004 #define CODEC_CAP_TRUNCATED 0x0008 +/* Codec can export data for HW decoding (XvMC). */ +#define CODEC_CAP_HWACCEL 0x0010 +/** + * Codec has a nonzero delay and needs to be fed with NULL at the end to get the delayed data. + * If this is not set, the codec is guaranteed to never be fed with NULL data. + */ +#define CODEC_CAP_DELAY 0x0020 +/** + * Codec can be fed a final frame with a smaller size. + * This can be used to prevent truncation of the last audio samples. + */ +#define CODEC_CAP_SMALL_LAST_FRAME 0x0040 -//the following defines might change, so dont expect compatibility if u use them +//The following defines may change, don't expect compatibility if you use them. #define MB_TYPE_INTRA4x4 0x0001 -#define MB_TYPE_INTRA16x16 0x0002 //FIXME h264 specific -#define MB_TYPE_INTRA_PCM 0x0004 //FIXME h264 specific +#define MB_TYPE_INTRA16x16 0x0002 //FIXME H.264-specific +#define MB_TYPE_INTRA_PCM 0x0004 //FIXME H.264-specific #define MB_TYPE_16x16 0x0008 #define MB_TYPE_16x8 0x0010 #define MB_TYPE_8x16 0x0020 #define MB_TYPE_8x8 0x0040 #define MB_TYPE_INTERLACED 0x0080 -#define MB_TYPE_DIRECT2 0x0100 //FIXME +#define MB_TYPE_DIRECT2 0x0100 //FIXME #define MB_TYPE_ACPRED 0x0200 #define MB_TYPE_GMC 0x0400 #define MB_TYPE_SKIP 0x0800 @@ -315,28 +532,29 @@ static const __attribute__((unused)) int Motion_Est_QTab[] = /** * Pan Scan area. - * this specifies the area which should be displayed. Note there may be multiple such areas for one frame + * This specifies the area which should be displayed. + * Note there may be multiple such areas for one frame. */ typedef struct AVPanScan{ /** - * id. - * - encoding: set by user. - * - decoding: set by lavc + * id + * - encoding: Set by user. + * - decoding: Set by libavcodec. */ int id; /** * width and height in 1/16 pel - * - encoding: set by user. - * - decoding: set by lavc + * - encoding: Set by user. + * - decoding: Set by libavcodec. */ int width; int height; /** - * position of the top left corner in 1/16 pel for up to 3 fields/frames. - * - encoding: set by user. - * - decoding: set by lavc + * position of the top left corner in 1/16 pel for up to 3 fields/frames + * - encoding: Set by user. + * - decoding: Set by libavcodec. */ int16_t position[3][2]; }AVPanScan; @@ -344,146 +562,156 @@ typedef struct AVPanScan{ #define FF_COMMON_FRAME \ /**\ * pointer to the picture planes.\ - * this might be different from the first allocated byte\ + * This might be different from the first allocated byte\ * - encoding: \ * - decoding: \ */\ uint8_t *data[4];\ int linesize[4];\ /**\ - * pointer to the first allocated byte of the picture. can be used in get_buffer/release_buffer\ - * this isnt used by lavc unless the default get/release_buffer() is used\ + * pointer to the first allocated byte of the picture. Can be used in get_buffer/release_buffer.\ + * This isn't used by libavcodec unless the default get/release_buffer() is used.\ * - encoding: \ * - decoding: \ */\ uint8_t *base[4];\ /**\ * 1 -> keyframe, 0-> not\ - * - encoding: set by lavc\ - * - decoding: set by lavc\ + * - encoding: Set by libavcodec.\ + * - decoding: Set by libavcodec.\ */\ int key_frame;\ \ /**\ - * picture type of the frame, see ?_TYPE below.\ - * - encoding: set by lavc for coded_picture (and set by user for input)\ - * - decoding: set by lavc\ + * Picture type of the frame, see ?_TYPE below.\ + * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\ + * - decoding: Set by libavcodec.\ */\ int pict_type;\ \ /**\ - * presentation timestamp in micro seconds (time when frame should be shown to user)\ - * if 0 then the frame_rate will be used as reference\ - * - encoding: MUST be set by user\ - * - decoding: set by lavc\ + * presentation timestamp in time_base units (time when frame should be shown to user)\ + * If AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed.\ + * - encoding: MUST be set by user.\ + * - decoding: Set by libavcodec.\ */\ int64_t pts;\ \ /**\ - * picture number in bitstream order.\ + * picture number in bitstream order\ * - encoding: set by\ - * - decoding: set by lavc\ + * - decoding: Set by libavcodec.\ */\ int coded_picture_number;\ /**\ - * picture number in display order.\ + * picture number in display order\ * - encoding: set by\ - * - decoding: set by lavc\ + * - decoding: Set by libavcodec.\ */\ int display_picture_number;\ \ /**\ * quality (between 1 (good) and FF_LAMBDA_MAX (bad)) \ - * - encoding: set by lavc for coded_picture (and set by user for input)\ - * - decoding: set by lavc\ + * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\ + * - decoding: Set by libavcodec.\ */\ int quality; \ \ /**\ * buffer age (1->was last buffer and dint change, 2->..., ...).\ - * set to INT_MAX if the buffer has not been used yet \ + * Set to INT_MAX if the buffer has not been used yet.\ * - encoding: unused\ - * - decoding: MUST be set by get_buffer()\ + * - decoding: MUST be set by get_buffer().\ */\ int age;\ \ /**\ * is this picture used as reference\ + * The values for this are the same as the MpegEncContext.picture_structure\ + * variable, that is 1->top field, 2->bottom field, 3->frame/both fields.\ * - encoding: unused\ - * - decoding: set by lavc (before get_buffer() call))\ + * - decoding: Set by libavcodec. (before get_buffer() call)).\ */\ int reference;\ \ /**\ * QP table\ * - encoding: unused\ - * - decoding: set by lavc\ + * - decoding: Set by libavcodec.\ */\ int8_t *qscale_table;\ /**\ * QP store stride\ * - encoding: unused\ - * - decoding: set by lavc\ + * - decoding: Set by libavcodec.\ */\ int qstride;\ \ /**\ - * mbskip_table[mb]>=1 if MB didnt change\ + * mbskip_table[mb]>=1 if MB didn't change\ * stride= mb_width = (width+15)>>4\ * - encoding: unused\ - * - decoding: set by lavc\ + * - decoding: Set by libavcodec.\ */\ uint8_t *mbskip_table;\ \ /**\ - * Motion vector table\ - * - encoding: unused\ - * - decoding: set by lavc\ + * motion vector table\ + * @code\ + * example:\ + * int mv_sample_log2= 4 - motion_subsample_log2;\ + * int mb_width= (width+15)>>4;\ + * int mv_stride= (mb_width << mv_sample_log2) + 1;\ + * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y];\ + * @endcode\ + * - encoding: Set by user.\ + * - decoding: Set by libavcodec.\ */\ int16_t (*motion_val[2])[2];\ \ /**\ - * Macroblock type table\ + * macroblock type table\ * mb_type_base + mb_width + 2\ - * - encoding: unused\ - * - decoding: set by lavc\ + * - encoding: Set by user.\ + * - decoding: Set by libavcodec.\ */\ uint32_t *mb_type;\ \ /**\ - * Macroblock size: (0->16x16, 1->8x8, 2-> 4x4, 3-> 2x2)\ + * log2 of the size of the block which a single vector in motion_val represents: \ + * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)\ * - encoding: unused\ - * - decoding: set by lavc\ + * - decoding: Set by libavcodec.\ */\ uint8_t motion_subsample_log2;\ \ /**\ * for some private data of the user\ * - encoding: unused\ - * - decoding: set by user\ + * - decoding: Set by user.\ */\ void *opaque;\ \ /**\ * error\ - * - encoding: set by lavc if flags&CODEC_FLAG_PSNR\ + * - encoding: Set by libavcodec. if flags&CODEC_FLAG_PSNR.\ * - decoding: unused\ */\ uint64_t error[4];\ \ /**\ - * type of the buffer (to keep track of who has to dealloc data[*])\ - * - encoding: set by the one who allocs it\ - * - decoding: set by the one who allocs it\ - * Note: user allocated (direct rendering) & internal buffers can not coexist currently\ + * type of the buffer (to keep track of who has to deallocate data[*])\ + * - encoding: Set by the one who allocates it.\ + * - decoding: Set by the one who allocates it.\ + * Note: User allocated (direct rendering) & internal buffers cannot coexist currently.\ */\ int type;\ \ /**\ - * when decoding, this signal how much the picture must be delayed.\ + * When decoding, this signals how much the picture must be delayed.\ * extra_delay = repeat_pict / (2*fps)\ * - encoding: unused\ - * - decoding: set by lavc\ + * - decoding: Set by libavcodec.\ */\ int repeat_pict;\ \ @@ -494,62 +722,93 @@ typedef struct AVPanScan{ \ /**\ * The content of the picture is interlaced.\ - * - encoding: set by user\ - * - decoding: set by lavc (default 0)\ + * - encoding: Set by user.\ + * - decoding: Set by libavcodec. (default 0)\ */\ int interlaced_frame;\ \ /**\ - * if the content is interlaced, is top field displayed first.\ - * - encoding: set by user\ - * - decoding: set by lavc\ + * If the content is interlaced, is top field displayed first.\ + * - encoding: Set by user.\ + * - decoding: Set by libavcodec.\ */\ int top_field_first;\ \ /**\ * Pan scan.\ - * - encoding: set by user\ - * - decoding: set by lavc\ + * - encoding: Set by user.\ + * - decoding: Set by libavcodec.\ */\ AVPanScan *pan_scan;\ \ /**\ - * tell user application that palette has changed from previous frame.\ + * Tell user application that palette has changed from previous frame.\ * - encoding: ??? (no palette-enabled encoder yet)\ - * - decoding: set by lavc (default 0)\ + * - decoding: Set by libavcodec. (default 0).\ */\ int palette_has_changed;\ \ /**\ - * Codec suggestion on buffer type if != 0\ + * codec suggestion on buffer type if != 0\ * - encoding: unused\ - * - decoding: set by lavc (before get_buffer() call))\ + * - decoding: Set by libavcodec. (before get_buffer() call)).\ */\ int buffer_hints;\ +\ + /**\ + * DCT coefficients\ + * - encoding: unused\ + * - decoding: Set by libavcodec.\ + */\ + short *dct_coeff;\ +\ + /**\ + * motion referece frame index\ + * - encoding: Set by user.\ + * - decoding: Set by libavcodec.\ + */\ + int8_t *ref_index[2];\ +\ + /**\ + * reordered opaque 64bit number (generally a PTS) from AVCodecContext.reordered_opaque\ + * output in AVFrame.reordered_opaque\ + * - encoding: unused\ + * - decoding: Read by user.\ + */\ + int64_t reordered_opaque;\ -#define FF_QSCALE_TYPE_MPEG1 0 -#define FF_QSCALE_TYPE_MPEG2 1 + +#define FF_QSCALE_TYPE_MPEG1 0 +#define FF_QSCALE_TYPE_MPEG2 1 +#define FF_QSCALE_TYPE_H264 2 #define FF_BUFFER_TYPE_INTERNAL 1 -#define FF_BUFFER_TYPE_USER 2 ///< Direct rendering buffers (image is (de)allocated by user) -#define FF_BUFFER_TYPE_SHARED 4 ///< buffer from somewher else, dont dealloc image (data/base) -#define FF_BUFFER_TYPE_COPY 8 ///< just a (modified) copy of some other buffer, dont dealloc anything +#define FF_BUFFER_TYPE_USER 2 ///< direct rendering buffers (image is (de)allocated by user) +#define FF_BUFFER_TYPE_SHARED 4 ///< Buffer from somewhere else; don't deallocate image (data/base), all other tables are not shared. +#define FF_BUFFER_TYPE_COPY 8 ///< Just a (modified) copy of some other buffer, don't deallocate anything. -#define FF_I_TYPE 1 // Intra -#define FF_P_TYPE 2 // Predicted -#define FF_B_TYPE 3 // Bi-dir predicted -#define FF_S_TYPE 4 // S(GMC)-VOP MPEG4 -#define FF_SI_TYPE 5 -#define FF_SP_TYPE 6 +#define FF_I_TYPE 1 ///< Intra +#define FF_P_TYPE 2 ///< Predicted +#define FF_B_TYPE 3 ///< Bi-dir predicted +#define FF_S_TYPE 4 ///< S(GMC)-VOP MPEG4 +#define FF_SI_TYPE 5 ///< Switching Intra +#define FF_SP_TYPE 6 ///< Switching Predicted +#define FF_BI_TYPE 7 -#define FF_BUFFER_HINTS_VALID 0x01 // Buffer hints value is meaningful (if 0 ignore) -#define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer -#define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer content -#define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer (update) +#define FF_BUFFER_HINTS_VALID 0x01 // Buffer hints value is meaningful (if 0 ignore). +#define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer. +#define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer content. +#define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer (update). /** * Audio Video Frame. + * New fields can be added to the end of FF_COMMON_FRAME with minor version + * bumps. + * Removal, reordering and changes to existing fields require a major + * version bump. No fields should be added into AVFrame before or after + * FF_COMMON_FRAME! + * sizeof(AVFrame) must not be used outside libav*. */ typedef struct AVFrame { FF_COMMON_FRAME @@ -558,112 +817,124 @@ typedef struct AVFrame { #define DEFAULT_FRAME_RATE_BASE 1001000 /** - * main external api structure. + * main external API structure. + * New fields can be added to the end with minor version bumps. + * Removal, reordering and changes to existing fields require a major + * version bump. + * sizeof(AVCodecContext) must not be used outside libav*. */ typedef struct AVCodecContext { /** - * the average bitrate. - * - encoding: set by user. unused for constant quantizer encoding - * - decoding: set by lavc. 0 or some bitrate if this info is available in the stream + * information on struct for av_log + * - set by avcodec_alloc_context + */ + const AVClass *av_class; + /** + * the average bitrate + * - encoding: Set by user; unused for constant quantizer encoding. + * - decoding: Set by libavcodec. 0 or some bitrate if this info is available in the stream. */ int bit_rate; /** * number of bits the bitstream is allowed to diverge from the reference. * the reference can be CBR (for CBR pass1) or VBR (for pass2) - * - encoding: set by user. unused for constant quantizer encoding + * - encoding: Set by user; unused for constant quantizer encoding. * - decoding: unused */ - int bit_rate_tolerance; + int bit_rate_tolerance; /** * CODEC_FLAG_*. - * - encoding: set by user. - * - decoding: set by user. + * - encoding: Set by user. + * - decoding: Set by user. */ int flags; /** - * some codecs needs additionnal format info. It is stored here - * - encoding: set by user. - * - decoding: set by lavc. (FIXME is this ok?) + * Some codecs need additional format info. It is stored here. + * If any muxer uses this then ALL demuxers/parsers AND encoders for the + * specific codec MUST set it correctly otherwise stream copy breaks. + * In general use of this field by muxers is not recommanded. + * - encoding: Set by libavcodec. + * - decoding: Set by libavcodec. (FIXME: Is this OK?) */ int sub_id; /** - * motion estimation algorithm used for video coding. + * Motion estimation algorithm used for video coding. + * 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex), + * 8 (umh), 9 (iter), 10 (tesa) [7, 8, 10 are x264 specific, 9 is snow specific] * - encoding: MUST be set by user. * - decoding: unused */ int me_method; /** - * some codecs need / can use extra-data like huffman tables. - * mjpeg: huffman tables + * some codecs need / can use extradata like Huffman tables. + * mjpeg: Huffman tables * rv10: additional flags * mpeg4: global headers (they can be in the bitstream or here) - * - encoding: set/allocated/freed by lavc. - * - decoding: set/allocated/freed by user. + * The allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger + * than extradata_size to avoid prolems if it is read with the bitstream reader. + * The bytewise contents of extradata must not depend on the architecture or CPU endianness. + * - encoding: Set/allocated/freed by libavcodec. + * - decoding: Set/allocated/freed by user. */ - void *extradata; + uint8_t *extradata; int extradata_size; - + + /** + * This is the fundamental unit of time (in seconds) in terms + * of which frame timestamps are represented. For fixed-fps content, + * timebase should be 1/framerate and timestamp increments should be + * identically 1. + * - encoding: MUST be set by user. + * - decoding: Set by libavcodec. + */ + AVRational time_base; + /* video only */ /** - * frames per sec multiplied by frame_rate_base. - * for variable fps this is the precission, so if the timestamps - * can be specified in msec precssion then this is 1000*frame_rate_base - * - encoding: MUST be set by user - * - decoding: set by lavc. 0 or the frame_rate if available - */ - int frame_rate; - - /** - * width / height. - * - encoding: MUST be set by user. - * - decoding: set by user if known, codec should override / dynamically change if needed + * picture width / height. + * - encoding: MUST be set by user. + * - decoding: Set by libavcodec. + * Note: For compatibility it is possible to set this instead of + * coded_width/height before decoding. */ int width, height; - -#define FF_ASPECT_SQUARE 1 -#define FF_ASPECT_4_3_625 2 -#define FF_ASPECT_4_3_525 3 -#define FF_ASPECT_16_9_625 4 -#define FF_ASPECT_16_9_525 5 + #define FF_ASPECT_EXTENDED 15 /** - * the number of pictures in a group of pitures, or 0 for intra_only. - * - encoding: set by user. + * the number of pictures in a group of pictures, or 0 for intra_only + * - encoding: Set by user. * - decoding: unused */ int gop_size; /** - * pixel format, see PIX_FMT_xxx. - * - encoding: FIXME: used by ffmpeg to decide whether an pix_fmt - * conversion is in order. This only works for - * codecs with one supported pix_fmt, we should - * do something for a generic case as well. - * - decoding: set by lavc. + * Pixel format, see PIX_FMT_xxx. + * - encoding: Set by user. + * - decoding: Set by libavcodec. */ enum PixelFormat pix_fmt; - + /** - * Frame rate emulation. If not zero lower layer (i.e. format handler) + * Frame rate emulation. If not zero, the lower layer (i.e. format handler) * has to read frames at native frame rate. - * - encoding: set by user. - * - decoding: unused. + * - encoding: Set by user. + * - decoding: unused */ int rate_emu; - + /** - * if non NULL, 'draw_horiz_band' is called by the libavcodec - * decoder to draw an horizontal band. It improve cache usage. Not + * If non NULL, 'draw_horiz_band' is called by the libavcodec + * decoder to draw a horizontal band. It improves cache usage. Not * all codecs can do that. You must check the codec capabilities - * before + * beforehand. * - encoding: unused - * - decoding: set by user. + * - decoding: Set by user. * @param height the height of the slice * @param y the y position of the slice * @param type 1->top field, 2->bottom field, 3->frame @@ -674,94 +945,112 @@ typedef struct AVCodecContext { int y, int type, int height); /* audio only */ - int sample_rate; ///< samples per sec - int channels; - int sample_fmt; ///< sample format, currenly unused + int sample_rate; ///< samples per second + int channels; ///< number of audio channels - /* the following data should not be initialized */ - int frame_size; ///< in samples, initialized when calling 'init' - int frame_number; ///< audio or video frame number - int real_pict_num; ///< returns the real picture number of previous encoded frame - /** - * number of frames the decoded output will be delayed relative to + * audio sample format + * - encoding: Set by user. + * - decoding: Set by libavcodec. + */ + enum SampleFormat sample_fmt; ///< sample format, currently unused + + /* The following data should not be initialized. */ + /** + * Samples per packet, initialized when calling 'init'. + */ + int frame_size; + int frame_number; ///< audio or video frame number + int real_pict_num; ///< Returns the real picture number of previous encoded frame. + + /** + * Number of frames the decoded output will be delayed relative to * the encoded input. - * - encoding: set by lavc. + * - encoding: Set by libavcodec. * - decoding: unused */ int delay; - + /* - encoding parameters */ float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0) - float qblur; ///< amount of qscale smoothing over time (0.0-1.0) - + float qblur; ///< amount of qscale smoothing over time (0.0-1.0) + /** - * minimum quantizer. - * - encoding: set by user. + * minimum quantizer + * - encoding: Set by user. * - decoding: unused */ int qmin; /** - * maximum quantizer. - * - encoding: set by user. + * maximum quantizer + * - encoding: Set by user. * - decoding: unused */ int qmax; /** - * maximum quantizer difference etween frames. - * - encoding: set by user. + * maximum quantizer difference between frames + * - encoding: Set by user. * - decoding: unused */ int max_qdiff; /** - * maximum number of b frames between non b frames. - * note: the output will be delayed by max_b_frames+1 relative to the input - * - encoding: set by user. + * maximum number of B-frames between non-B-frames + * Note: The output will be delayed by max_b_frames+1 relative to the input. + * - encoding: Set by user. * - decoding: unused */ int max_b_frames; /** - * qscale factor between ip and b frames. - * - encoding: set by user. + * qscale factor between IP and B-frames + * If > 0 then the last P-frame quantizer will be used (q= lastp_q*factor+offset). + * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset). + * - encoding: Set by user. * - decoding: unused */ float b_quant_factor; - + /** obsolete FIXME remove */ int rc_strategy; +#define FF_RC_STRATEGY_XVID 1 + int b_frame_strategy; /** - * hurry up amount. + * hurry up amount * - encoding: unused - * - decoding: set by user. 1-> skip b frames, 2-> skip idct/dequant too, 5-> skip everything except header + * - decoding: Set by user. 1-> Skip B-frames, 2-> Skip IDCT/dequant too, 5-> Skip everything except header + * @deprecated Deprecated in favor of skip_idct and skip_frame. */ int hurry_up; - + struct AVCodec *codec; - + void *priv_data; +#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) /* unused, FIXME remove*/ int rtp_mode; - - int rtp_payload_size; /* The size of the RTP payload, the coder will */ - /* do it's best to deliver a chunk with size */ - /* below rtp_payload_size, the chunk will start */ - /* with a start code on some codecs like H.263 */ - /* This doesn't take account of any particular */ - /* headers inside the transmited RTP payload */ +#endif - - /* The RTP callcack: This function is called */ - /* every time the encoder as a packet to send */ - /* Depends on the encoder if the data starts */ - /* with a Start Code (it should) H.263 does */ - void (*rtp_callback)(void *data, int size, int packet_number); + int rtp_payload_size; /* The size of the RTP payload: the coder will */ + /* do its best to deliver a chunk with size */ + /* below rtp_payload_size, the chunk will start */ + /* with a start code on some codecs like H.263. */ + /* This doesn't take account of any particular */ + /* headers inside the transmitted RTP payload. */ + + + /* The RTP callback: This function is called */ + /* every time the encoder has a packet to send. */ + /* It depends on the encoder if the data starts */ + /* with a Start Code (it should). H.263 does. */ + /* mb_nb contains the number of macroblocks */ + /* encoded in the RTP payload. */ + void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb); /* statistics, used for 2-pass encoding */ int mv_bits; @@ -772,37 +1061,44 @@ typedef struct AVCodecContext { int p_count; int skip_count; int misc_bits; - + /** - * number of bits used for the previously encoded frame. - * - encoding: set by lavc + * number of bits used for the previously encoded frame + * - encoding: Set by libavcodec. * - decoding: unused */ int frame_bits; /** - * private data of the user, can be used to carry app specific stuff. - * - encoding: set by user - * - decoding: set by user + * Private data of the user, can be used to carry app specific stuff. + * - encoding: Set by user. + * - decoding: Set by user. */ void *opaque; char codec_name[32]; enum CodecType codec_type; /* see CODEC_TYPE_xxx */ enum CodecID codec_id; /* see CODEC_ID_xxx */ - + /** * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A'). - * this is used to workaround some encoder bugs - * - encoding: set by user, if not then the default based on codec_id will be used - * - decoding: set by user, will be converted to upper case by lavc during init + * This is used to work around some encoder bugs. + * A demuxer should set this to what is stored in the field used to identify the codec. + * If there are multiple such fields in a container then the demuxer should choose the one + * which maximizes the information about the used codec. + * If the codec tag field in a container is larger then 32 bits then the demuxer should + * remap the longer ID to 32 bits with a table or other structure. Alternatively a new + * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated + * first. + * - encoding: Set by user, if not then the default based on codec_id will be used. + * - decoding: Set by user, will be converted to uppercase by libavcodec during init. */ unsigned int codec_tag; - + /** - * workaround bugs in encoders which sometimes cannot be detected automatically. - * - encoding: unused - * - decoding: set by user + * Work around bugs in encoders which sometimes cannot be detected automatically. + * - encoding: Set by user + * - decoding: Set by user */ int workaround_bugs; #define FF_BUG_AUTODETECT 1 ///< autodetection @@ -810,183 +1106,202 @@ typedef struct AVCodecContext { #define FF_BUG_XVID_ILACE 4 #define FF_BUG_UMP4 8 #define FF_BUG_NO_PADDING 16 -#define FF_BUG_AC_VLC 0 ///< will be removed, libavcodec can now handle these non compliant files by default +#define FF_BUG_AMV 32 +#define FF_BUG_AC_VLC 0 ///< Will be removed, libavcodec can now handle these non-compliant files by default. #define FF_BUG_QPEL_CHROMA 64 #define FF_BUG_STD_QPEL 128 #define FF_BUG_QPEL_CHROMA2 256 #define FF_BUG_DIRECT_BLOCKSIZE 512 #define FF_BUG_EDGE 1024 -//#define FF_BUG_FAKE_SCALABILITY 16 //autodetection should work 100% - +#define FF_BUG_HPEL_CHROMA 2048 +#define FF_BUG_DC_CLIP 4096 +#define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders. +//#define FF_BUG_FAKE_SCALABILITY 16 //Autodetection should work 100%. + /** - * luma single coeff elimination threshold. - * - encoding: set by user + * luma single coefficient elimination threshold + * - encoding: Set by user. * - decoding: unused */ int luma_elim_threshold; - + /** - * chroma single coeff elimination threshold. - * - encoding: set by user + * chroma single coeff elimination threshold + * - encoding: Set by user. * - decoding: unused */ int chroma_elim_threshold; - + /** - * strictly follow the std (MPEG4, ...). - * - encoding: set by user - * - decoding: unused + * strictly follow the standard (MPEG4, ...). + * - encoding: Set by user. + * - decoding: Set by user. + * Setting this to STRICT or higher means the encoder and decoder will + * generally do stupid things. While setting it to inofficial or lower + * will mean the encoder might use things that are not supported by all + * spec compliant decoders. Decoders make no difference between normal, + * inofficial and experimental, that is they always try to decode things + * when they can unless they are explicitly asked to behave stupid + * (=strictly conform to the specs) */ int strict_std_compliance; - +#define FF_COMPLIANCE_VERY_STRICT 2 ///< Strictly conform to a older more strict version of the spec or reference software. +#define FF_COMPLIANCE_STRICT 1 ///< Strictly conform to all the things in the spec no matter what consequences. +#define FF_COMPLIANCE_NORMAL 0 +#define FF_COMPLIANCE_INOFFICIAL -1 ///< Allow inofficial extensions. +#define FF_COMPLIANCE_EXPERIMENTAL -2 ///< Allow nonstandardized experimental things. + /** - * qscale offset between ip and b frames. - * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset) - * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset) - * - encoding: set by user. + * qscale offset between IP and B-frames + * - encoding: Set by user. * - decoding: unused */ float b_quant_offset; - + /** - * error resilience higher values will detect more errors but may missdetect - * some more or less valid parts as errors. + * Error resilience; higher values will detect more errors but may + * misdetect some more or less valid parts as errors. * - encoding: unused - * - decoding: set by user + * - decoding: Set by user. */ int error_resilience; -#define FF_ER_CAREFULL 1 +#define FF_ER_CAREFUL 1 #define FF_ER_COMPLIANT 2 #define FF_ER_AGGRESSIVE 3 #define FF_ER_VERY_AGGRESSIVE 4 - + /** - * called at the beginning of each frame to get a buffer for it. - * if pic.reference is set then the frame will be read later by lavc - * width and height should be rounded up to the next multiple of 16 + * Called at the beginning of each frame to get a buffer for it. + * If pic.reference is set then the frame will be read later by libavcodec. + * avcodec_align_dimensions() should be used to find the required width and + * height, as they normally need to be rounded up to the next multiple of 16. * - encoding: unused - * - decoding: set by lavc, user can override + * - decoding: Set by libavcodec., user can override. */ int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic); - + /** - * called to release buffers which where allocated with get_buffer. - * a released buffer can be reused in get_buffer() - * pic.data[*] must be set to NULL + * Called to release buffers which were allocated with get_buffer. + * A released buffer can be reused in get_buffer(). + * pic.data[*] must be set to NULL. * - encoding: unused - * - decoding: set by lavc, user can override + * - decoding: Set by libavcodec., user can override. */ void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic); /** - * is 1 if the decoded stream contains b frames, 0 otherwise. - * - encoding: unused - * - decoding: set by lavc + * If 1 the stream has a 1 frame delay during decoding. + * - encoding: Set by libavcodec. + * - decoding: Set by libavcodec. */ int has_b_frames; - - int block_align; ///< used by some WAV based audio codecs - - int parse_only; /* - decoding only: if true, only parsing is done + + /** + * number of bytes per packet if constant and known or 0 + * Used by some WAV based audio codecs. + */ + int block_align; + + int parse_only; /* - decoding only: If true, only parsing is done (function avcodec_parse_frame()). The frame data is returned. Only MPEG codecs support this now. */ - + /** - * 0-> h263 quant 1-> mpeg quant. - * - encoding: set by user. + * 0-> h263 quant 1-> mpeg quant + * - encoding: Set by user. * - decoding: unused */ int mpeg_quant; - + /** - * pass1 encoding statistics output buffer. - * - encoding: set by lavc + * pass1 encoding statistics output buffer + * - encoding: Set by libavcodec. * - decoding: unused */ char *stats_out; - + /** - * pass2 encoding statistics input buffer. - * concatenated stuff from stats_out of pass1 should be placed here - * - encoding: allocated/set/freed by user + * pass2 encoding statistics input buffer + * Concatenated stuff from stats_out of pass1 should be placed here. + * - encoding: Allocated/set/freed by user. * - decoding: unused */ char *stats_in; - + /** - * ratecontrol qmin qmax limiting method. - * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax - * - encoding: set by user. + * ratecontrol qmin qmax limiting method + * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax. + * - encoding: Set by user. * - decoding: unused */ float rc_qsquish; float rc_qmod_amp; int rc_qmod_freq; - + /** - * ratecontrol override, see RcOverride. - * - encoding: allocated/set/freed by user. + * ratecontrol override, see RcOverride + * - encoding: Allocated/set/freed by user. * - decoding: unused */ RcOverride *rc_override; int rc_override_count; - + /** - * rate control equation. - * - encoding: set by user + * rate control equation + * - encoding: Set by user * - decoding: unused */ - char *rc_eq; - + const char *rc_eq; + /** - * maximum bitrate. - * - encoding: set by user. + * maximum bitrate + * - encoding: Set by user. * - decoding: unused */ int rc_max_rate; - + /** - * minimum bitrate. - * - encoding: set by user. + * minimum bitrate + * - encoding: Set by user. * - decoding: unused */ int rc_min_rate; - + /** - * decoder bitstream buffer size. - * - encoding: set by user. + * decoder bitstream buffer size + * - encoding: Set by user. * - decoding: unused */ int rc_buffer_size; float rc_buffer_aggressivity; /** - * qscale factor between p and i frames. - * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset) - * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset) - * - encoding: set by user. + * qscale factor between P and I-frames + * If > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset). + * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset). + * - encoding: Set by user. * - decoding: unused */ float i_quant_factor; - + /** - * qscale offset between p and i frames. - * - encoding: set by user. + * qscale offset between P and I-frames + * - encoding: Set by user. * - decoding: unused */ float i_quant_offset; - + /** - * initial complexity for pass1 ratecontrol. - * - encoding: set by user. + * initial complexity for pass1 ratecontrol + * - encoding: Set by user. * - decoding: unused */ float rc_initial_cplx; /** - * dct algorithm, see FF_DCT_* below. - * - encoding: set by user + * DCT algorithm, see FF_DCT_* below + * - encoding: Set by user. * - decoding: unused */ int dct_algo; @@ -997,81 +1312,93 @@ typedef struct AVCodecContext { #define FF_DCT_MLIB 4 #define FF_DCT_ALTIVEC 5 #define FF_DCT_FAAN 6 - + /** - * luminance masking (0-> disabled). - * - encoding: set by user + * luminance masking (0-> disabled) + * - encoding: Set by user. * - decoding: unused */ float lumi_masking; - + /** - * temporary complexity masking (0-> disabled). - * - encoding: set by user + * temporary complexity masking (0-> disabled) + * - encoding: Set by user. * - decoding: unused */ float temporal_cplx_masking; - + /** - * spatial complexity masking (0-> disabled). - * - encoding: set by user + * spatial complexity masking (0-> disabled) + * - encoding: Set by user. * - decoding: unused */ float spatial_cplx_masking; - + /** - * p block masking (0-> disabled). - * - encoding: set by user + * p block masking (0-> disabled) + * - encoding: Set by user. * - decoding: unused */ float p_masking; /** - * darkness masking (0-> disabled). - * - encoding: set by user + * darkness masking (0-> disabled) + * - encoding: Set by user. * - decoding: unused */ float dark_masking; - - + + +#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) /* for binary compatibility */ int unused; - - /** - * idct algorithm, see FF_IDCT_* below. - * - encoding: set by user - * - decoding: set by user - */ - int idct_algo; -#define FF_IDCT_AUTO 0 -#define FF_IDCT_INT 1 -#define FF_IDCT_SIMPLE 2 -#define FF_IDCT_SIMPLEMMX 3 -#define FF_IDCT_LIBMPEG2MMX 4 -#define FF_IDCT_PS2 5 -#define FF_IDCT_MLIB 6 -#define FF_IDCT_ARM 7 -#define FF_IDCT_ALTIVEC 8 -#define FF_IDCT_SH4 9 -#define FF_IDCT_SIMPLEARM 10 +#endif /** - * slice count. - * - encoding: set by lavc - * - decoding: set by user (or 0) + * IDCT algorithm, see FF_IDCT_* below. + * - encoding: Set by user. + * - decoding: Set by user. + */ + int idct_algo; +#define FF_IDCT_AUTO 0 +#define FF_IDCT_INT 1 +#define FF_IDCT_SIMPLE 2 +#define FF_IDCT_SIMPLEMMX 3 +#define FF_IDCT_LIBMPEG2MMX 4 +#define FF_IDCT_PS2 5 +#define FF_IDCT_MLIB 6 +#define FF_IDCT_ARM 7 +#define FF_IDCT_ALTIVEC 8 +#define FF_IDCT_SH4 9 +#define FF_IDCT_SIMPLEARM 10 +#define FF_IDCT_H264 11 +#define FF_IDCT_VP3 12 +#define FF_IDCT_IPP 13 +#define FF_IDCT_XVIDMMX 14 +#define FF_IDCT_CAVS 15 +#define FF_IDCT_SIMPLEARMV5TE 16 +#define FF_IDCT_SIMPLEARMV6 17 +#define FF_IDCT_SIMPLEVIS 18 +#define FF_IDCT_WMV2 19 +#define FF_IDCT_FAAN 20 + + /** + * slice count + * - encoding: Set by libavcodec. + * - decoding: Set by user (or 0). */ int slice_count; /** - * slice offsets in the frame in bytes. - * - encoding: set/allocated by lavc - * - decoding: set/allocated by user (or NULL) + * slice offsets in the frame in bytes + * - encoding: Set/allocated by libavcodec. + * - decoding: Set/allocated by user (or NULL). */ int *slice_offset; /** - * error concealment flags. + * error concealment flags * - encoding: unused - * - decoding: set by user + * - decoding: Set by user. */ int error_concealment; #define FF_EC_GUESS_MVS 1 @@ -1081,79 +1408,82 @@ typedef struct AVCodecContext { * dsp_mask could be add used to disable unwanted CPU features * CPU features (i.e. MMX, SSE. ...) * - * with FORCE flag you may instead enable given CPU features - * (Dangerous: usable in case of misdetection, improper usage however will - * result into program crash) + * With the FORCE flag you may instead enable given CPU features. + * (Dangerous: Usable in case of misdetection, improper usage however will + * result into program crash.) */ unsigned dsp_mask; -#define FF_MM_FORCE 0x80000000 /* force usage of selected flags (OR) */ +#define FF_MM_FORCE 0x80000000 /* Force usage of selected flags (OR) */ /* lower 16 bits - CPU features */ -#ifdef HAVE_MMX -#define FF_MM_MMX 0x0001 /* standard MMX */ -#define FF_MM_3DNOW 0x0004 /* AMD 3DNOW */ -#define FF_MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */ -#define FF_MM_SSE 0x0008 /* SSE functions */ -#define FF_MM_SSE2 0x0010 /* PIV SSE2 functions */ -#endif /* HAVE_MMX */ +#define FF_MM_MMX 0x0001 ///< standard MMX +#define FF_MM_3DNOW 0x0004 ///< AMD 3DNOW +#define FF_MM_MMXEXT 0x0002 ///< SSE integer functions or AMD MMX ext +#define FF_MM_SSE 0x0008 ///< SSE functions +#define FF_MM_SSE2 0x0010 ///< PIV SSE2 functions +#define FF_MM_3DNOWEXT 0x0020 ///< AMD 3DNowExt +#define FF_MM_SSE3 0x0040 ///< Prescott SSE3 functions +#define FF_MM_SSSE3 0x0080 ///< Conroe SSSE3 functions +#define FF_MM_IWMMXT 0x0100 ///< XScale IWMMXT /** * bits per sample/pixel from the demuxer (needed for huffyuv). - * - encoding: set by lavc - * - decoding: set by user + * - encoding: Set by libavcodec. + * - decoding: Set by user. */ int bits_per_sample; - + /** - * prediction method (needed for huffyuv). - * - encoding: set by user + * prediction method (needed for huffyuv) + * - encoding: Set by user. * - decoding: unused */ int prediction_method; #define FF_PRED_LEFT 0 #define FF_PRED_PLANE 1 #define FF_PRED_MEDIAN 2 - + /** - * sample aspect ratio (0 if unknown). - * numerator and denominator must be relative prime and smaller then 256 for some video standards - * - encoding: set by user. - * - decoding: set by lavc. + * sample aspect ratio (0 if unknown) + * Numerator and denominator must be relatively prime and smaller than 256 for some video standards. + * - encoding: Set by user. + * - decoding: Set by libavcodec. */ AVRational sample_aspect_ratio; /** - * the picture in the bitstream. - * - encoding: set by lavc - * - decoding: set by lavc + * the picture in the bitstream + * - encoding: Set by libavcodec. + * - decoding: Set by libavcodec. */ AVFrame *coded_frame; /** - * debug. - * - encoding: set by user. - * - decoding: set by user. + * debug + * - encoding: Set by user. + * - decoding: Set by user. */ int debug; -#define FF_DEBUG_PICT_INFO 1 -#define FF_DEBUG_RC 2 -#define FF_DEBUG_BITSTREAM 4 -#define FF_DEBUG_MB_TYPE 8 -#define FF_DEBUG_QP 16 -#define FF_DEBUG_MV 32 -//#define FF_DEBUG_VIS_MV 0x00000040 -#define FF_DEBUG_SKIP 0x00000080 -#define FF_DEBUG_STARTCODE 0x00000100 -#define FF_DEBUG_PTS 0x00000200 -#define FF_DEBUG_ER 0x00000400 -#define FF_DEBUG_MMCO 0x00000800 -#define FF_DEBUG_BUGS 0x00001000 -#define FF_DEBUG_VIS_QP 0x00002000 +#define FF_DEBUG_PICT_INFO 1 +#define FF_DEBUG_RC 2 +#define FF_DEBUG_BITSTREAM 4 +#define FF_DEBUG_MB_TYPE 8 +#define FF_DEBUG_QP 16 +#define FF_DEBUG_MV 32 +#define FF_DEBUG_DCT_COEFF 0x00000040 +#define FF_DEBUG_SKIP 0x00000080 +#define FF_DEBUG_STARTCODE 0x00000100 +#define FF_DEBUG_PTS 0x00000200 +#define FF_DEBUG_ER 0x00000400 +#define FF_DEBUG_MMCO 0x00000800 +#define FF_DEBUG_BUGS 0x00001000 +#define FF_DEBUG_VIS_QP 0x00002000 #define FF_DEBUG_VIS_MB_TYPE 0x00004000 - +#define FF_DEBUG_BUFFERS 0x00008000 + /** - * debug. - * - encoding: set by user. - * - decoding: set by user. + * debug + * - encoding: Set by user. + * - decoding: Set by user. */ int debug_mv; #define FF_DEBUG_VIS_MV_P_FOR 0x00000001 //visualize forward predicted MVs of P frames @@ -1161,122 +1491,127 @@ typedef struct AVCodecContext { #define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames /** - * error. - * - encoding: set by lavc if flags&CODEC_FLAG_PSNR + * error + * - encoding: Set by libavcodec if flags&CODEC_FLAG_PSNR. * - decoding: unused */ uint64_t error[4]; - + /** - * minimum MB quantizer. - * - encoding: set by user. + * minimum MB quantizer + * - encoding: unused * - decoding: unused */ int mb_qmin; /** - * maximum MB quantizer. - * - encoding: set by user. + * maximum MB quantizer + * - encoding: unused * - decoding: unused */ int mb_qmax; - + /** - * motion estimation compare function. - * - encoding: set by user. + * motion estimation comparison function + * - encoding: Set by user. * - decoding: unused */ int me_cmp; /** - * subpixel motion estimation compare function. - * - encoding: set by user. + * subpixel motion estimation comparison function + * - encoding: Set by user. * - decoding: unused */ int me_sub_cmp; /** - * macroblock compare function (not supported yet). - * - encoding: set by user. + * macroblock comparison function (not supported yet) + * - encoding: Set by user. * - decoding: unused */ int mb_cmp; /** - * interlaced dct compare function - * - encoding: set by user. + * interlaced DCT comparison function + * - encoding: Set by user. * - decoding: unused */ int ildct_cmp; -#define FF_CMP_SAD 0 -#define FF_CMP_SSE 1 -#define FF_CMP_SATD 2 -#define FF_CMP_DCT 3 -#define FF_CMP_PSNR 4 -#define FF_CMP_BIT 5 -#define FF_CMP_RD 6 -#define FF_CMP_ZERO 7 -#define FF_CMP_VSAD 8 -#define FF_CMP_VSSE 9 +#define FF_CMP_SAD 0 +#define FF_CMP_SSE 1 +#define FF_CMP_SATD 2 +#define FF_CMP_DCT 3 +#define FF_CMP_PSNR 4 +#define FF_CMP_BIT 5 +#define FF_CMP_RD 6 +#define FF_CMP_ZERO 7 +#define FF_CMP_VSAD 8 +#define FF_CMP_VSSE 9 +#define FF_CMP_NSSE 10 +#define FF_CMP_W53 11 +#define FF_CMP_W97 12 +#define FF_CMP_DCTMAX 13 +#define FF_CMP_DCT264 14 #define FF_CMP_CHROMA 256 - + /** - * ME diamond size & shape. - * - encoding: set by user. + * ME diamond size & shape + * - encoding: Set by user. * - decoding: unused */ int dia_size; /** - * amount of previous MV predictors (2a+1 x 2a+1 square). - * - encoding: set by user. + * amount of previous MV predictors (2a+1 x 2a+1 square) + * - encoding: Set by user. * - decoding: unused */ int last_predictor_count; /** - * pre pass for motion estimation. - * - encoding: set by user. + * prepass for motion estimation + * - encoding: Set by user. * - decoding: unused */ int pre_me; /** - * motion estimation pre pass compare function. - * - encoding: set by user. + * motion estimation prepass comparison function + * - encoding: Set by user. * - decoding: unused */ int me_pre_cmp; /** - * ME pre pass diamond size & shape. - * - encoding: set by user. + * ME prepass diamond size & shape + * - encoding: Set by user. * - decoding: unused */ int pre_dia_size; /** - * subpel ME quality. - * - encoding: set by user. + * subpel ME quality + * - encoding: Set by user. * - decoding: unused */ int me_subpel_quality; /** - * callback to negotiate the pixelFormat. + * callback to negotiate the pixelFormat * @param fmt is the list of formats which are supported by the codec, - * its terminated by -1 as 0 is a valid format, the formats are ordered by quality - * the first is allways the native one - * @return the choosen format + * it is terminated by -1 as 0 is a valid format, the formats are ordered by quality. + * The first is always the native one. + * @return the chosen format * - encoding: unused - * - decoding: set by user, if not set then the native format will always be choosen + * - decoding: Set by user, if not set the native format will be chosen. */ - enum PixelFormat (*get_format)(struct AVCodecContext *s, enum PixelFormat * fmt); + enum PixelFormat (*get_format)(struct AVCodecContext *s, const enum PixelFormat * fmt); /** - * DTG active format information (additionnal aspect ratio - * information only used in DVB MPEG2 transport streams). 0 if - * not set. - * - * - encoding: unused. - * - decoding: set by decoder + * DTG active format information (additional aspect ratio + * information only used in DVB MPEG-2 transport streams) + * 0 if not set. + * + * - encoding: unused + * - decoding: Set by decoder. */ int dtg_active_format; #define FF_DTG_AFD_SAME 8 @@ -1288,55 +1623,46 @@ typedef struct AVCodecContext { #define FF_DTG_AFD_SP_4_3 15 /** - * Maximum motion estimation search range in subpel units. - * if 0 then no limit - * - * - encoding: set by user. - * - decoding: unused. + * maximum motion estimation search range in subpel units + * If 0 then no limit. + * + * - encoding: Set by user. + * - decoding: unused */ int me_range; /** - * frame_rate_base. - * for variable fps this is 1 - * - encoding: set by user. - * - decoding: set by lavc. - * @todo move this after frame_rate - */ - - int frame_rate_base; - /** - * intra quantizer bias. - * - encoding: set by user. + * intra quantizer bias + * - encoding: Set by user. * - decoding: unused */ int intra_quant_bias; #define FF_DEFAULT_QUANT_BIAS 999999 - + /** - * inter quantizer bias. - * - encoding: set by user. + * inter quantizer bias + * - encoding: Set by user. * - decoding: unused */ int inter_quant_bias; /** - * color table ID. - * - encoding: unused. - * - decoding: which clrtable should be used for 8bit RGB images - * table have to be stored somewhere FIXME + * color table ID + * - encoding: unused + * - decoding: Which clrtable should be used for 8bit RGB images. + * Tables have to be stored somewhere. FIXME */ int color_table_id; - + /** - * internal_buffer count. - * Dont touch, used by lavc default_get_buffer() + * internal_buffer count + * Don't touch, used by libavcodec default_get_buffer(). */ int internal_buffer_count; - + /** - * internal_buffers. - * Dont touch, used by lavc default_get_buffer() + * internal_buffers + * Don't touch, used by libavcodec default_get_buffer(). */ void *internal_buffer; @@ -1347,33 +1673,44 @@ typedef struct AVCodecContext { #define FF_QUALITY_SCALE FF_LAMBDA_SCALE //FIXME maybe remove /** - * global quality for codecs which cannot change it per frame. - * this should be proportional to MPEG1/2/4 qscale. - * - encoding: set by user. + * Global quality for codecs which cannot change it per frame. + * This should be proportional to MPEG-1/2/4 qscale. + * - encoding: Set by user. * - decoding: unused */ int global_quality; - -#define FF_CODER_TYPE_VLC 0 -#define FF_CODER_TYPE_AC 1 + +#define FF_CODER_TYPE_VLC 0 +#define FF_CODER_TYPE_AC 1 +#define FF_CODER_TYPE_RAW 2 +#define FF_CODER_TYPE_RLE 3 +#define FF_CODER_TYPE_DEFLATE 4 /** * coder type - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int coder_type; /** * context model - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int context_model; - +#if 0 + /** + * + * - encoding: unused + * - decoding: Set by user. + */ + uint8_t * (*realloc)(struct AVCodecContext *s, uint8_t *buf, int buf_size); +#endif + /** * slice flags * - encoding: unused - * - decoding: set by user. + * - decoding: Set by user. */ int slice_flags; #define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display @@ -1386,155 +1723,571 @@ typedef struct AVCodecContext { * - decoding: set by decoder */ int xvmc_acceleration; - + /** * macroblock decision mode - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int mb_decision; #define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp #define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits -#define FF_MB_DECISION_RD 2 ///< rate distoration +#define FF_MB_DECISION_RD 2 ///< rate distortion /** * custom intra quantization matrix - * - encoding: set by user, can be NULL - * - decoding: set by lavc + * - encoding: Set by user, can be NULL. + * - decoding: Set by libavcodec. */ uint16_t *intra_matrix; /** * custom inter quantization matrix - * - encoding: set by user, can be NULL - * - decoding: set by lavc + * - encoding: Set by user, can be NULL. + * - decoding: Set by libavcodec. */ uint16_t *inter_matrix; - + /** * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A'). - * this is used to workaround some encoder bugs + * This is used to work around some encoder bugs. * - encoding: unused - * - decoding: set by user, will be converted to upper case by lavc during init + * - decoding: Set by user, will be converted to uppercase by libavcodec during init. */ unsigned int stream_codec_tag; /** - * scene change detection threshold. - * 0 is default, larger means fewer detected scene changes - * - encoding: set by user. + * scene change detection threshold + * 0 is default, larger means fewer detected scene changes. + * - encoding: Set by user. * - decoding: unused */ int scenechange_threshold; /** - * minimum lagrange multipler - * - encoding: set by user. + * minimum Lagrange multipler + * - encoding: Set by user. * - decoding: unused */ int lmin; /** - * maximum lagrange multipler - * - encoding: set by user. + * maximum Lagrange multipler + * - encoding: Set by user. * - decoding: unused */ int lmax; /** - * Palette control structure + * palette control structure * - encoding: ??? (no palette-enabled encoder yet) - * - decoding: set by user. + * - decoding: Set by user. */ struct AVPaletteControl *palctrl; /** * noise reduction strength - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int noise_reduction; - + /** - * called at the beginning of a frame to get cr buffer for it. - * buffer type (size, hints) must be the same. lavc won't check it. - * lavc will pass previous buffer in pic, function should return + * Called at the beginning of a frame to get cr buffer for it. + * Buffer type (size, hints) must be the same. libavcodec won't check it. + * libavcodec will pass previous buffer in pic, function should return * same buffer or new buffer with old frame "painted" into it. - * if pic.data[0] == NULL must behave like get_buffer(). + * If pic.data[0] == NULL must behave like get_buffer(). * - encoding: unused - * - decoding: set by lavc, user can override + * - decoding: Set by libavcodec., user can override */ int (*reget_buffer)(struct AVCodecContext *c, AVFrame *pic); /** - * number of bits which should be loaded into the rc buffer before decoding starts - * - encoding: set by user. + * Number of bits which should be loaded into the rc buffer before decoding starts. + * - encoding: Set by user. * - decoding: unused */ int rc_initial_buffer_occupancy; /** * - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int inter_threshold; /** - * CODEC_FLAG2_*. - * - encoding: set by user. - * - decoding: set by user. + * CODEC_FLAG2_* + * - encoding: Set by user. + * - decoding: Set by user. */ int flags2; /** - * simulates errors in the bitstream to test error concealment. - * - encoding: set by user. - * - decoding: unused. + * Simulates errors in the bitstream to test error concealment. + * - encoding: Set by user. + * - decoding: unused */ int error_rate; - + /** * MP3 antialias algorithm, see FF_AA_* below. * - encoding: unused - * - decoding: set by user + * - decoding: Set by user. */ int antialias_algo; #define FF_AA_AUTO 0 #define FF_AA_FASTINT 1 //not implemented yet #define FF_AA_INT 2 #define FF_AA_FLOAT 3 + /** + * quantizer noise shaping + * - encoding: Set by user. + * - decoding: unused + */ + int quantizer_noise_shaping; + + /** + * thread count + * is used to decide how many independent tasks should be passed to execute() + * - encoding: Set by user. + * - decoding: Set by user. + */ + int thread_count; + + /** + * The codec may call this to execute several independent things. + * It will return only after finishing all tasks. + * The user may replace this with some multithreaded implementation, + * the default implementation will execute the parts serially. + * @param count the number of things to execute + * - encoding: Set by libavcodec, user can override. + * - decoding: Set by libavcodec, user can override. + */ + int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void **arg2, int *ret, int count); + + /** + * thread opaque + * Can be used by execute() to store some per AVCodecContext stuff. + * - encoding: set by execute() + * - decoding: set by execute() + */ + void *thread_opaque; + + /** + * Motion estimation threshold below which no motion estimation is + * performed, but instead the user specified motion vectors are used. + * + * - encoding: Set by user. + * - decoding: unused + */ + int me_threshold; + + /** + * Macroblock threshold below which the user specified macroblock types will be used. + * - encoding: Set by user. + * - decoding: unused + */ + int mb_threshold; + + /** + * precision of the intra DC coefficient - 8 + * - encoding: Set by user. + * - decoding: unused + */ + int intra_dc_precision; + + /** + * noise vs. sse weight for the nsse comparsion function + * - encoding: Set by user. + * - decoding: unused + */ + int nsse_weight; + + /** + * Number of macroblock rows at the top which are skipped. + * - encoding: unused + * - decoding: Set by user. + */ + int skip_top; + + /** + * Number of macroblock rows at the bottom which are skipped. + * - encoding: unused + * - decoding: Set by user. + */ + int skip_bottom; + + /** + * profile + * - encoding: Set by user. + * - decoding: Set by libavcodec. + */ + int profile; +#define FF_PROFILE_UNKNOWN -99 +#define FF_PROFILE_AAC_MAIN 0 +#define FF_PROFILE_AAC_LOW 1 +#define FF_PROFILE_AAC_SSR 2 +#define FF_PROFILE_AAC_LTP 3 + + /** + * level + * - encoding: Set by user. + * - decoding: Set by libavcodec. + */ + int level; +#define FF_LEVEL_UNKNOWN -99 + + /** + * low resolution decoding, 1-> 1/2 size, 2->1/4 size + * - encoding: unused + * - decoding: Set by user. + */ + int lowres; + + /** + * Bitstream width / height, may be different from width/height if lowres + * or other things are used. + * - encoding: unused + * - decoding: Set by user before init if known. Codec should override / dynamically change if needed. + */ + int coded_width, coded_height; + + /** + * frame skip threshold + * - encoding: Set by user. + * - decoding: unused + */ + int frame_skip_threshold; + + /** + * frame skip factor + * - encoding: Set by user. + * - decoding: unused + */ + int frame_skip_factor; + + /** + * frame skip exponent + * - encoding: Set by user. + * - decoding: unused + */ + int frame_skip_exp; + + /** + * frame skip comparison function + * - encoding: Set by user. + * - decoding: unused + */ + int frame_skip_cmp; + + /** + * Border processing masking, raises the quantizer for mbs on the borders + * of the picture. + * - encoding: Set by user. + * - decoding: unused + */ + float border_masking; + + /** + * minimum MB lagrange multipler + * - encoding: Set by user. + * - decoding: unused + */ + int mb_lmin; + + /** + * maximum MB lagrange multipler + * - encoding: Set by user. + * - decoding: unused + */ + int mb_lmax; + + /** + * + * - encoding: Set by user. + * - decoding: unused + */ + int me_penalty_compensation; + + /** + * + * - encoding: unused + * - decoding: Set by user. + */ + enum AVDiscard skip_loop_filter; + + /** + * + * - encoding: unused + * - decoding: Set by user. + */ + enum AVDiscard skip_idct; + + /** + * + * - encoding: unused + * - decoding: Set by user. + */ + enum AVDiscard skip_frame; + + /** + * + * - encoding: Set by user. + * - decoding: unused + */ + int bidir_refine; + + /** + * + * - encoding: Set by user. + * - decoding: unused + */ + int brd_scale; + + /** + * constant rate factor - quality-based VBR - values ~correspond to qps + * - encoding: Set by user. + * - decoding: unused + */ + float crf; + + /** + * constant quantization parameter rate control method + * - encoding: Set by user. + * - decoding: unused + */ + int cqp; + + /** + * minimum GOP size + * - encoding: Set by user. + * - decoding: unused + */ + int keyint_min; + + /** + * number of reference frames + * - encoding: Set by user. + * - decoding: unused + */ + int refs; + + /** + * chroma qp offset from luma + * - encoding: Set by user. + * - decoding: unused + */ + int chromaoffset; + + /** + * Influences how often B-frames are used. + * - encoding: Set by user. + * - decoding: unused + */ + int bframebias; + + /** + * trellis RD quantization + * - encoding: Set by user. + * - decoding: unused + */ + int trellis; + + /** + * Reduce fluctuations in qp (before curve compression). + * - encoding: Set by user. + * - decoding: unused + */ + float complexityblur; + + /** + * in-loop deblocking filter alphac0 parameter + * alpha is in the range -6...6 + * - encoding: Set by user. + * - decoding: unused + */ + int deblockalpha; + + /** + * in-loop deblocking filter beta parameter + * beta is in the range -6...6 + * - encoding: Set by user. + * - decoding: unused + */ + int deblockbeta; + + /** + * macroblock subpartition sizes to consider - p8x8, p4x4, b8x8, i8x8, i4x4 + * - encoding: Set by user. + * - decoding: unused + */ + int partitions; +#define X264_PART_I4X4 0x001 /* Analyze i4x4 */ +#define X264_PART_I8X8 0x002 /* Analyze i8x8 (requires 8x8 transform) */ +#define X264_PART_P8X8 0x010 /* Analyze p16x8, p8x16 and p8x8 */ +#define X264_PART_P4X4 0x020 /* Analyze p8x4, p4x8, p4x4 */ +#define X264_PART_B8X8 0x100 /* Analyze b16x8, b8x16 and b8x8 */ + + /** + * direct MV prediction mode - 0 (none), 1 (spatial), 2 (temporal) + * - encoding: Set by user. + * - decoding: unused + */ + int directpred; + + /** + * Audio cutoff bandwidth (0 means "automatic") + * - encoding: Set by user. + * - decoding: unused + */ + int cutoff; + + /** + * Multiplied by qscale for each frame and added to scene_change_score. + * - encoding: Set by user. + * - decoding: unused + */ + int scenechange_factor; + + /** + * + * Note: Value depends upon the compare function used for fullpel ME. + * - encoding: Set by user. + * - decoding: unused + */ + int mv0_threshold; + + /** + * Adjusts sensitivity of b_frame_strategy 1. + * - encoding: Set by user. + * - decoding: unused + */ + int b_sensitivity; + + /** + * - encoding: Set by user. + * - decoding: unused + */ + int compression_level; +#define FF_COMPRESSION_DEFAULT -1 + + /** + * Sets whether to use LPC mode - used by FLAC encoder. + * - encoding: Set by user. + * - decoding: unused + */ + int use_lpc; + + /** + * LPC coefficient precision - used by FLAC encoder + * - encoding: Set by user. + * - decoding: unused + */ + int lpc_coeff_precision; + + /** + * - encoding: Set by user. + * - decoding: unused + */ + int min_prediction_order; + + /** + * - encoding: Set by user. + * - decoding: unused + */ + int max_prediction_order; + + /** + * search method for selecting prediction order + * - encoding: Set by user. + * - decoding: unused + */ + int prediction_order_method; + + /** + * - encoding: Set by user. + * - decoding: unused + */ + int min_partition_order; + + /** + * - encoding: Set by user. + * - decoding: unused + */ + int max_partition_order; + + /** + * GOP timecode frame start number, in non drop frame format + * - encoding: Set by user. + * - decoding: unused + */ + int64_t timecode_frame_start; + + /** + * Decoder should decode to this many channels if it can (0 for default) + * - encoding: unused + * - decoding: Set by user. + */ + int request_channels; + + /** + * Percentage of dynamic range compression to be applied by the decoder. + * The default value is 1.0, corresponding to full compression. + * - encoding: unused + * - decoding: Set by user. + */ + float drc_scale; + + /** + * opaque 64bit number (generally a PTS) that will be reordered and + * output in AVFrame.reordered_opaque + * - encoding: unused + * - decoding: Set by user. + */ + int64_t reordered_opaque; } AVCodecContext; - -struct AVOption; - -/** - * Parse option(s) and sets fields in passed structure - * @param strct structure where the parsed results will be written - * @param list list with AVOptions - * @param opts string with options for parsing - */ -int avoption_parse(void* strct, const struct AVOption* list, const char* opts); - - /** * AVCodec. */ typedef struct AVCodec { + /** + * Name of the codec implementation. + * The name is globally unique among encoders and among decoders (but an + * encoder and a decoder can share the same name). + * This is the primary way to find a codec from the user perspective. + */ const char *name; enum CodecType type; - int id; + enum CodecID id; int priv_data_size; int (*init)(AVCodecContext *); int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data); int (*close)(AVCodecContext *); int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, - uint8_t *buf, int buf_size); + const uint8_t *buf, int buf_size); + /** + * Codec capabilities. + * see CODEC_CAP_* + */ int capabilities; - const struct AVOption *options; struct AVCodec *next; + /** + * Flush buffers. + * Will be called when seeking + */ void (*flush)(AVCodecContext *); + const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0} + const enum PixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1 + /** + * Descriptive name for the codec, meant to be more human readable than \p name. + * You \e should use the NULL_IF_CONFIG_SMALL() macro to define it. + */ + const char *long_name; + const int *supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0 + const enum SampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1 } AVCodec; /** @@ -1550,485 +2303,764 @@ typedef struct AVPicture { * AVPaletteControl * This structure defines a method for communicating palette changes * between and demuxer and a decoder. + * + * @deprecated Use AVPacket to send palette changes instead. + * This is totally broken. */ #define AVPALETTE_SIZE 1024 #define AVPALETTE_COUNT 256 typedef struct AVPaletteControl { - /* demuxer sets this to 1 to indicate the palette has changed; - * decoder resets to 0 */ + /* Demuxer sets this to 1 to indicate the palette has changed; + * decoder resets to 0. */ int palette_changed; /* 4-byte ARGB palette entries, stored in native byte order; note that * the individual palette components should be on a 8-bit scale; if - * the palette data comes from a IBM VGA native format, the component - * data is probably 6 bits in size and needs to be scaled */ + * the palette data comes from an IBM VGA native format, the component + * data is probably 6 bits in size and needs to be scaled. */ unsigned int palette[AVPALETTE_COUNT]; -} AVPaletteControl; +} AVPaletteControl attribute_deprecated; -extern AVCodec ac3_encoder; -extern AVCodec mp2_encoder; -extern AVCodec mp3lame_encoder; -extern AVCodec oggvorbis_encoder; -extern AVCodec faac_encoder; -extern AVCodec mpeg1video_encoder; -extern AVCodec mpeg2video_encoder; -extern AVCodec h263_encoder; -extern AVCodec h263p_encoder; -extern AVCodec flv_encoder; -extern AVCodec rv10_encoder; -extern AVCodec rv20_encoder; -extern AVCodec mjpeg_encoder; -extern AVCodec ljpeg_encoder; -extern AVCodec mpeg4_encoder; -extern AVCodec msmpeg4v1_encoder; -extern AVCodec msmpeg4v2_encoder; -extern AVCodec msmpeg4v3_encoder; -extern AVCodec wmv1_encoder; -extern AVCodec wmv2_encoder; -extern AVCodec huffyuv_encoder; -extern AVCodec h264_encoder; -extern AVCodec asv1_encoder; -extern AVCodec asv2_encoder; -extern AVCodec vcr1_encoder; -extern AVCodec ffv1_encoder; -extern AVCodec mdec_encoder; -extern AVCodec zlib_encoder; +typedef struct AVSubtitleRect { + uint16_t x; + uint16_t y; + uint16_t w; + uint16_t h; + uint16_t nb_colors; + int linesize; + uint32_t *rgba_palette; + uint8_t *bitmap; +} AVSubtitleRect; -extern AVCodec h263_decoder; -extern AVCodec mpeg4_decoder; -extern AVCodec msmpeg4v1_decoder; -extern AVCodec msmpeg4v2_decoder; -extern AVCodec msmpeg4v3_decoder; -extern AVCodec wmv1_decoder; -extern AVCodec wmv2_decoder; -extern AVCodec mpeg1video_decoder; -extern AVCodec mpeg2video_decoder; -extern AVCodec mpegvideo_decoder; -extern AVCodec mpeg_xvmc_decoder; -extern AVCodec h263i_decoder; -extern AVCodec flv_decoder; -extern AVCodec rv10_decoder; -extern AVCodec rv20_decoder; -extern AVCodec svq1_decoder; -extern AVCodec svq3_decoder; -extern AVCodec dvvideo_decoder; -extern AVCodec wmav1_decoder; -extern AVCodec wmav2_decoder; -extern AVCodec mjpeg_decoder; -extern AVCodec mjpegb_decoder; -extern AVCodec sp5x_decoder; -extern AVCodec mp2_decoder; -extern AVCodec mp3_decoder; -extern AVCodec mace3_decoder; -extern AVCodec mace6_decoder; -extern AVCodec huffyuv_decoder; -extern AVCodec oggvorbis_decoder; -extern AVCodec cyuv_decoder; -extern AVCodec h264_decoder; -extern AVCodec indeo3_decoder; -extern AVCodec vp3_decoder; -extern AVCodec theora_decoder; -extern AVCodec amr_nb_decoder; -extern AVCodec amr_nb_encoder; -extern AVCodec amr_wb_encoder; -extern AVCodec amr_wb_decoder; -extern AVCodec aac_decoder; -extern AVCodec mpeg4aac_decoder; -extern AVCodec asv1_decoder; -extern AVCodec asv2_decoder; -extern AVCodec vcr1_decoder; -extern AVCodec cljr_decoder; -extern AVCodec ffv1_decoder; -extern AVCodec fourxm_decoder; -extern AVCodec mdec_decoder; -extern AVCodec roq_decoder; -extern AVCodec interplay_video_decoder; -extern AVCodec xan_wc3_decoder; -extern AVCodec rpza_decoder; -extern AVCodec cinepak_decoder; -extern AVCodec msrle_decoder; -extern AVCodec msvideo1_decoder; -extern AVCodec vqa_decoder; -extern AVCodec idcin_decoder; -extern AVCodec eightbps_decoder; -extern AVCodec smc_decoder; -extern AVCodec flic_decoder; -extern AVCodec vmdvideo_decoder; -extern AVCodec vmdaudio_decoder; -extern AVCodec truemotion1_decoder; -extern AVCodec mszh_decoder; -extern AVCodec zlib_decoder; -extern AVCodec ra_144_decoder; -extern AVCodec ra_288_decoder; -extern AVCodec roq_dpcm_decoder; -extern AVCodec interplay_dpcm_decoder; -extern AVCodec xan_dpcm_decoder; +typedef struct AVSubtitle { + uint16_t format; /* 0 = graphics */ + uint32_t start_display_time; /* relative to packet pts, in ms */ + uint32_t end_display_time; /* relative to packet pts, in ms */ + uint32_t num_rects; + AVSubtitleRect *rects; +} AVSubtitle; -/* pcm codecs */ -#define PCM_CODEC(id, name) \ -extern AVCodec name ## _decoder; \ -extern AVCodec name ## _encoder - -PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le); -PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be); -PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le); -PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be); -PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8); -PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8); -PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw); -PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw); - -/* adpcm codecs */ - -PCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt); -PCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav); -PCM_CODEC(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3); -PCM_CODEC(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4); -PCM_CODEC(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws); -PCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms); -PCM_CODEC(CODEC_ID_ADPCM_4XM, adpcm_4xm); -PCM_CODEC(CODEC_ID_ADPCM_XA, adpcm_xa); -PCM_CODEC(CODEC_ID_ADPCM_ADX, adpcm_adx); - -#undef PCM_CODEC - -/* dummy raw video codec */ -extern AVCodec rawvideo_encoder; -extern AVCodec rawvideo_decoder; - -/* the following codecs use external GPL libs */ -extern AVCodec ac3_decoder; /* resample.c */ struct ReSampleContext; +struct AVResampleContext; typedef struct ReSampleContext ReSampleContext; -ReSampleContext *audio_resample_init(int output_channels, int input_channels, +ReSampleContext *audio_resample_init(int output_channels, int input_channels, int output_rate, int input_rate); int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples); void audio_resample_close(ReSampleContext *s); +struct AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_length, int log2_phase_count, int linear, double cutoff); +int av_resample(struct AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx); +void av_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance); +void av_resample_close(struct AVResampleContext *c); + +#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) /* YUV420 format is assumed ! */ -struct ImgReSampleContext; +/** + * @deprecated Use the software scaler (swscale) instead. + */ +typedef struct ImgReSampleContext ImgReSampleContext attribute_deprecated; -typedef struct ImgReSampleContext ImgReSampleContext; - -ImgReSampleContext *img_resample_init(int output_width, int output_height, +/** + * @deprecated Use the software scaler (swscale) instead. + */ +attribute_deprecated ImgReSampleContext *img_resample_init(int output_width, int output_height, int input_width, int input_height); -ImgReSampleContext *img_resample_full_init(int owidth, int oheight, +/** + * @deprecated Use the software scaler (swscale) instead. + */ +attribute_deprecated ImgReSampleContext *img_resample_full_init(int owidth, int oheight, int iwidth, int iheight, int topBand, int bottomBand, - int leftBand, int rightBand); + int leftBand, int rightBand, + int padtop, int padbottom, + int padleft, int padright); -void img_resample(ImgReSampleContext *s, +/** + * @deprecated Use the software scaler (swscale) instead. + */ +attribute_deprecated void img_resample(struct ImgReSampleContext *s, AVPicture *output, const AVPicture *input); -void img_resample_close(ImgReSampleContext *s); +/** + * @deprecated Use the software scaler (swscale) instead. + */ +attribute_deprecated void img_resample_close(struct ImgReSampleContext *s); + +#endif /** * Allocate memory for a picture. Call avpicture_free to free it. * - * @param picture the picture to be filled in. - * @param pix_fmt the format of the picture. - * @param width the width of the picture. - * @param height the height of the picture. - * @return 0 if successful, -1 if not. + * @param picture the picture to be filled in + * @param pix_fmt the format of the picture + * @param width the width of the picture + * @param height the height of the picture + * @return zero if successful, a negative value if not */ int avpicture_alloc(AVPicture *picture, int pix_fmt, int width, int height); -/* Free a picture previously allocated by avpicture_alloc. */ +/** + * Free a picture previously allocated by avpicture_alloc(). + * + * @param picture the AVPicture to be freed + */ void avpicture_free(AVPicture *picture); +/** + * Fill in the AVPicture fields. + * The fields of the given AVPicture are filled in by using the 'ptr' address + * which points to the image data buffer. Depending on the specified picture + * format, one or multiple image data pointers and line sizes will be set. + * If a planar format is specified, several pointers will be set pointing to + * the different picture planes and the line sizes of the different planes + * will be stored in the lines_sizes array. + * + * @param picture AVPicture whose fields are to be filled in + * @param ptr Buffer which will contain or contains the actual image data + * @param pix_fmt The format in which the picture data is stored. + * @param width the width of the image in pixels + * @param height the height of the image in pixels + * @return size of the image data in bytes + */ int avpicture_fill(AVPicture *picture, uint8_t *ptr, int pix_fmt, int width, int height); int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height, unsigned char *dest, int dest_size); + +/** + * Calculate the size in bytes that a picture of the given width and height + * would occupy if stored in the given picture format. + * + * @param pix_fmt the given picture format + * @param width the width of the image + * @param height the height of the image + * @return Image data size in bytes + */ int avpicture_get_size(int pix_fmt, int width, int height); void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift); const char *avcodec_get_pix_fmt_name(int pix_fmt); +void avcodec_set_dimensions(AVCodecContext *s, int width, int height); enum PixelFormat avcodec_get_pix_fmt(const char* name); +unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat p); -#define FF_LOSS_RESOLUTION 0x0001 /* loss due to resolution change */ -#define FF_LOSS_DEPTH 0x0002 /* loss due to color depth change */ -#define FF_LOSS_COLORSPACE 0x0004 /* loss due to color space conversion */ -#define FF_LOSS_ALPHA 0x0008 /* loss of alpha bits */ -#define FF_LOSS_COLORQUANT 0x0010 /* loss due to color quantization */ -#define FF_LOSS_CHROMA 0x0020 /* loss of chroma (e.g. rgb to gray conversion) */ +#define FF_LOSS_RESOLUTION 0x0001 /**< loss due to resolution change */ +#define FF_LOSS_DEPTH 0x0002 /**< loss due to color depth change */ +#define FF_LOSS_COLORSPACE 0x0004 /**< loss due to color space conversion */ +#define FF_LOSS_ALPHA 0x0008 /**< loss of alpha bits */ +#define FF_LOSS_COLORQUANT 0x0010 /**< loss due to color quantization */ +#define FF_LOSS_CHROMA 0x0020 /**< loss of chroma (e.g. RGB to gray conversion) */ +/** + * Computes what kind of losses will occur when converting from one specific + * pixel format to another. + * When converting from one pixel format to another, information loss may occur. + * For example, when converting from RGB24 to GRAY, the color information will + * be lost. Similarly, other losses occur when converting from some formats to + * other formats. These losses can involve loss of chroma, but also loss of + * resolution, loss of color depth, loss due to the color space conversion, loss + * of the alpha bits or loss due to color quantization. + * avcodec_get_fix_fmt_loss() informs you about the various types of losses + * which will occur when converting from one pixel format to another. + * + * @param[in] dst_pix_fmt destination pixel format + * @param[in] src_pix_fmt source pixel format + * @param[in] has_alpha Whether the source pixel format alpha channel is used. + * @return Combination of flags informing you what kind of losses will occur. + */ int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt, int has_alpha); + +/** + * Finds the best pixel format to convert to given a certain source pixel + * format. When converting from one pixel format to another, information loss + * may occur. For example, when converting from RGB24 to GRAY, the color + * information will be lost. Similarly, other losses occur when converting from + * some formats to other formats. avcodec_find_best_pix_fmt() searches which of + * the given pixel formats should be used to suffer the least amount of loss. + * The pixel formats from which it chooses one, are determined by the + * \p pix_fmt_mask parameter. + * + * @code + * src_pix_fmt = PIX_FMT_YUV420P; + * pix_fmt_mask = (1 << PIX_FMT_YUV422P) || (1 << PIX_FMT_RGB24); + * dst_pix_fmt = avcodec_find_best_pix_fmt(pix_fmt_mask, src_pix_fmt, alpha, &loss); + * @endcode + * + * @param[in] pix_fmt_mask bitmask determining which pixel format to choose from + * @param[in] src_pix_fmt source pixel format + * @param[in] has_alpha Whether the source pixel format alpha channel is used. + * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur. + * @return The best pixel format to convert to or -1 if none was found. + */ int avcodec_find_best_pix_fmt(int pix_fmt_mask, int src_pix_fmt, int has_alpha, int *loss_ptr); + +/** + * Print in buf the string corresponding to the pixel format with + * number pix_fmt, or an header if pix_fmt is negative. + * + * @param[in] buf the buffer where to write the string + * @param[in] buf_size the size of buf + * @param[in] pix_fmt the number of the pixel format to print the corresponding info string, or + * a negative value to print the corresponding header. + * Meaningful values for obtaining a pixel format info vary from 0 to PIX_FMT_NB -1. + */ +void avcodec_pix_fmt_string (char *buf, int buf_size, int pix_fmt); + #define FF_ALPHA_TRANSP 0x0001 /* image has some totally transparent pixels */ #define FF_ALPHA_SEMI_TRANSP 0x0002 /* image has some transparent pixels */ -int img_get_alpha_info(const AVPicture *src, - int pix_fmt, int width, int height); -/* convert among pixel formats */ -int img_convert(AVPicture *dst, int dst_pix_fmt, - const AVPicture *src, int pix_fmt, +/** + * Tell if an image really has transparent alpha values. + * @return ored mask of FF_ALPHA_xxx constants + */ +int img_get_alpha_info(const AVPicture *src, + int pix_fmt, int width, int height); + +#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) +/** + * convert among pixel formats + * @deprecated Use the software scaler (swscale) instead. + */ +attribute_deprecated int img_convert(AVPicture *dst, int dst_pix_fmt, + const AVPicture *src, int pix_fmt, int width, int height); +#endif /* deinterlace a picture */ +/* deinterlace - if not supported return -1 */ int avpicture_deinterlace(AVPicture *dst, const AVPicture *src, int pix_fmt, int width, int height); /* external high level API */ +#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) extern AVCodec *first_avcodec; +#endif +AVCodec *av_codec_next(AVCodec *c); -/* returns LIBAVCODEC_VERSION_INT constant */ +/** + * Returns the LIBAVCODEC_VERSION_INT constant. + */ unsigned avcodec_version(void); + +#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) /* returns LIBAVCODEC_BUILD constant */ -unsigned avcodec_build(void); +attribute_deprecated unsigned avcodec_build(void); +#endif + +/** + * Initializes libavcodec. + * + * @warning This function \e must be called before any other libavcodec + * function. + */ void avcodec_init(void); void register_avcodec(AVCodec *format); + +/** + * Finds a registered encoder with a matching codec ID. + * + * @param id CodecID of the requested encoder + * @return An encoder if one was found, NULL otherwise. + */ AVCodec *avcodec_find_encoder(enum CodecID id); + +/** + * Finds a registered encoder with the specified name. + * + * @param name name of the requested encoder + * @return An encoder if one was found, NULL otherwise. + */ AVCodec *avcodec_find_encoder_by_name(const char *name); + +/** + * Finds a registered decoder with a matching codec ID. + * + * @param id CodecID of the requested decoder + * @return A decoder if one was found, NULL otherwise. + */ AVCodec *avcodec_find_decoder(enum CodecID id); + +/** + * Finds a registered decoder with the specified name. + * + * @param name name of the requested decoder + * @return A decoder if one was found, NULL otherwise. + */ AVCodec *avcodec_find_decoder_by_name(const char *name); void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode); +/** + * Sets the fields of the given AVCodecContext to default values. + * + * @param s The AVCodecContext of which the fields should be set to default values. + */ void avcodec_get_context_defaults(AVCodecContext *s); + +/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API! + * we WILL change its arguments and name a few times! */ +void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType); + +/** + * Allocates an AVCodecContext and sets its fields to default values. The + * resulting struct can be deallocated by simply calling av_free(). + * + * @return An AVCodecContext filled with default values or NULL on failure. + * @see avcodec_get_context_defaults + */ AVCodecContext *avcodec_alloc_context(void); + +/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API! + * we WILL change its arguments and name a few times! */ +AVCodecContext *avcodec_alloc_context2(enum CodecType); + +/** + * Sets the fields of the given AVFrame to default values. + * + * @param pic The AVFrame of which the fields should be set to default values. + */ +void avcodec_get_frame_defaults(AVFrame *pic); + +/** + * Allocates an AVFrame and sets its fields to default values. The resulting + * struct can be deallocated by simply calling av_free(). + * + * @return An AVFrame filled with default values or NULL on failure. + * @see avcodec_get_frame_defaults + */ AVFrame *avcodec_alloc_frame(void); int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic); void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic); -void avcodec_default_free_buffers(AVCodecContext *s); +int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic); +void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height); /** - * opens / inits the AVCodecContext. - * not thread save! + * Checks if the given dimension of a picture is valid, meaning that all + * bytes of the picture can be addressed with a signed int. + * + * @param[in] w Width of the picture. + * @param[in] h Height of the picture. + * @return Zero if valid, a negative value if invalid. + */ +int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h); +enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt); + +int avcodec_thread_init(AVCodecContext *s, int thread_count); +void avcodec_thread_free(AVCodecContext *s); +int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count); +int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count); +//FIXME func typedef + +/** + * Initializes the AVCodecContext to use the given AVCodec. Prior to using this + * function the context has to be allocated. + * + * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(), + * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for + * retrieving a codec. + * + * @warning This function is not thread safe! + * + * @code + * avcodec_register_all(); + * codec = avcodec_find_decoder(CODEC_ID_H264); + * if (!codec) + * exit(1); + * + * context = avcodec_alloc_context(); + * + * if (avcodec_open(context, codec) < 0) + * exit(1); + * @endcode + * + * @param avctx The context which will be set up to use the given codec. + * @param codec The codec to use within the context. + * @return zero on success, a negative value on error + * @see avcodec_alloc_context, avcodec_find_decoder, avcodec_find_encoder */ int avcodec_open(AVCodecContext *avctx, AVCodec *codec); -int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples, +/** + * @deprecated Use avcodec_decode_audio2() instead. + */ +attribute_deprecated int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples, int *frame_size_ptr, - uint8_t *buf, int buf_size); -int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, + const uint8_t *buf, int buf_size); + +/** + * Decodes an audio frame from \p buf into \p samples. + * The avcodec_decode_audio2() function decodes an audio frame from the input + * buffer \p buf of size \p buf_size. To decode it, it makes use of the + * audio codec which was coupled with \p avctx using avcodec_open(). The + * resulting decoded frame is stored in output buffer \p samples. If no frame + * could be decompressed, \p frame_size_ptr is zero. Otherwise, it is the + * decompressed frame size in \e bytes. + * + * @warning You \e must set \p frame_size_ptr to the allocated size of the + * output buffer before calling avcodec_decode_audio2(). + * + * @warning The input buffer must be \c FF_INPUT_BUFFER_PADDING_SIZE larger than + * the actual read bytes because some optimized bitstream readers read 32 or 64 + * bits at once and could read over the end. + * + * @warning The end of the input buffer \p buf should be set to 0 to ensure that + * no overreading happens for damaged MPEG streams. + * + * @note You might have to align the input buffer \p buf and output buffer \p + * samples. The alignment requirements depend on the CPU: On some CPUs it isn't + * necessary at all, on others it won't work at all if not aligned and on others + * it will work but it will have an impact on performance. In practice, the + * bitstream should have 4 byte alignment at minimum and all sample data should + * be 16 byte aligned unless the CPU doesn't need it (AltiVec and SSE do). If + * the linesize is not a multiple of 16 then there's no sense in aligning the + * start of the buffer to 16. + * + * @param avctx the codec context + * @param[out] samples the output buffer + * @param[in,out] frame_size_ptr the output buffer size in bytes + * @param[in] buf the input buffer + * @param[in] buf_size the input buffer size in bytes + * @return On error a negative value is returned, otherwise the number of bytes + * used or zero if no frame could be decompressed. + */ +int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples, + int *frame_size_ptr, + const uint8_t *buf, int buf_size); + +/** + * Decodes a video frame from \p buf into \p picture. + * The avcodec_decode_video() function decodes a video frame from the input + * buffer \p buf of size \p buf_size. To decode it, it makes use of the + * video codec which was coupled with \p avctx using avcodec_open(). The + * resulting decoded frame is stored in \p picture. + * + * @warning The input buffer must be \c FF_INPUT_BUFFER_PADDING_SIZE larger than + * the actual read bytes because some optimized bitstream readers read 32 or 64 + * bits at once and could read over the end. + * + * @warning The end of the input buffer \p buf should be set to 0 to ensure that + * no overreading happens for damaged MPEG streams. + * + * @note You might have to align the input buffer \p buf and output buffer \p + * samples. The alignment requirements depend on the CPU: on some CPUs it isn't + * necessary at all, on others it won't work at all if not aligned and on others + * it will work but it will have an impact on performance. In practice, the + * bitstream should have 4 byte alignment at minimum and all sample data should + * be 16 byte aligned unless the CPU doesn't need it (AltiVec and SSE do). If + * the linesize is not a multiple of 16 then there's no sense in aligning the + * start of the buffer to 16. + * + * @param avctx the codec context + * @param[out] picture The AVFrame in which the decoded video frame will be stored. + * @param[in] buf the input buffer + * @param[in] buf_size the size of the input buffer in bytes + * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero. + * @return On error a negative value is returned, otherwise the number of bytes + * used or zero if no frame could be decompressed. + */ +int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, - uint8_t *buf, int buf_size); -int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata, + const uint8_t *buf, int buf_size); + +/* Decode a subtitle message. Return -1 if error, otherwise return the + * number of bytes used. If no subtitle could be decompressed, + * got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. */ +int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub, + int *got_sub_ptr, + const uint8_t *buf, int buf_size); +int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata, int *data_size_ptr, uint8_t *buf, int buf_size); -int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, + +/** + * Encodes an audio frame from \p samples into \p buf. + * The avcodec_encode_audio() function encodes an audio frame from the input + * buffer \p samples. To encode it, it makes use of the audio codec which was + * coupled with \p avctx using avcodec_open(). The resulting encoded frame is + * stored in output buffer \p buf. + * + * @note The output buffer should be at least \c FF_MIN_BUFFER_SIZE bytes large. + * + * @param avctx the codec context + * @param[out] buf the output buffer + * @param[in] buf_size the output buffer size + * @param[in] samples the input buffer containing the samples + * The number of samples read from this buffer is frame_size*channels, + * both of which are defined in \p avctx. + * For PCM audio the number of samples read from \p samples is equal to + * \p buf_size * input_sample_size / output_sample_size. + * @return On error a negative value is returned, on success zero or the number + * of bytes used to encode the data read from the input buffer. + */ +int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, const short *samples); -int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, + +/** + * Encodes a video frame from \p pict into \p buf. + * The avcodec_encode_video() function encodes a video frame from the input + * \p pict. To encode it, it makes use of the video codec which was coupled with + * \p avctx using avcodec_open(). The resulting encoded bytes representing the + * frame are stored in the output buffer \p buf. The input picture should be + * stored using a specific format, namely \c avctx.pix_fmt. + * + * @param avctx the codec context + * @param[out] buf the output buffer for the bitstream of encoded frame + * @param[in] buf_size the size of the output buffer in bytes + * @param[in] pict the input picture to encode + * @return On error a negative value is returned, on success zero or the number + * of bytes used from the input buffer. + */ +int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVFrame *pict); +int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, + const AVSubtitle *sub); int avcodec_close(AVCodecContext *avctx); void avcodec_register_all(void); +/** + * Flush buffers, should be called when seeking or when switching to a different stream. + */ void avcodec_flush_buffers(AVCodecContext *avctx); -/* misc usefull functions */ +void avcodec_default_free_buffers(AVCodecContext *s); + +/* misc useful functions */ /** - * returns a single letter to describe the picture type + * Returns a single letter to describe the given picture type \p pict_type. + * + * @param[in] pict_type the picture type + * @return A single character representing the picture type. */ char av_get_pict_type_char(int pict_type); /** - * reduce a fraction. - * this is usefull for framerate calculations - * @param max the maximum allowed for dst_nom & dst_den - * @return 1 if exact, 0 otherwise - */ -int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max); - -/** - * rescale a 64bit integer. - * a simple a*b/c isnt possible as it can overflow - */ -int64_t av_rescale(int64_t a, int b, int c); - - -/** - * Interface for 0.5.0 version + * Returns codec bits per sample. * - * do not even think about it's usage for this moment + * @param[in] codec_id the codec + * @return Number of bits per sample or zero if unknown for the given codec. */ - -typedef struct { - /// compressed size used from given memory buffer - int size; - /// I/P/B frame type - int frame_type; -} avc_enc_result_t; +int av_get_bits_per_sample(enum CodecID codec_id); /** - * Commands - * order can't be changed - once it was defined - */ -typedef enum { - // general commands - AVC_OPEN_BY_NAME = 0xACA000, - AVC_OPEN_BY_CODEC_ID, - AVC_OPEN_BY_FOURCC, - AVC_CLOSE, - - AVC_FLUSH, - // pin - struct { uint8_t* src, uint_t src_size } - // pout - struct { AVPicture* img, consumed_bytes, - AVC_DECODE, - // pin - struct { AVPicture* img, uint8_t* dest, uint_t dest_size } - // pout - uint_t used_from_dest_size - AVC_ENCODE, - - // query/get video commands - AVC_GET_VERSION = 0xACB000, - AVC_GET_WIDTH, - AVC_GET_HEIGHT, - AVC_GET_DELAY, - AVC_GET_QUANT_TABLE, - // ... - - // query/get audio commands - AVC_GET_FRAME_SIZE = 0xABC000, - - // maybe define some simple structure which - // might be passed to the user - but they can't - // contain any codec specific parts and these - // calls are usualy necessary only few times - - // set video commands - AVC_SET_WIDTH = 0xACD000, - AVC_SET_HEIGHT, - - // set video encoding commands - AVC_SET_FRAME_RATE = 0xACD800, - AVC_SET_QUALITY, - AVC_SET_HURRY_UP, - - // set audio commands - AVC_SET_SAMPLE_RATE = 0xACE000, - AVC_SET_CHANNELS, - -} avc_cmd_t; - -/** - * \param handle allocated private structure by libavcodec - * for initialization pass NULL - will be returned pout - * user is supposed to know nothing about its structure - * \param cmd type of operation to be performed - * \param pint input parameter - * \param pout output parameter + * Returns sample format bits per sample. * - * \returns command status - eventually for query command it might return - * integer resulting value + * @param[in] sample_fmt the sample format + * @return Number of bits per sample or zero if unknown for the given sample format. */ -int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout); +int av_get_bits_per_sample_format(enum SampleFormat sample_fmt); /* frame parsing */ typedef struct AVCodecParserContext { void *priv_data; struct AVCodecParser *parser; int64_t frame_offset; /* offset of the current frame */ - int64_t cur_offset; /* current offset + int64_t cur_offset; /* current offset (incremented by each av_parser_parse()) */ - int64_t last_frame_offset; /* offset of the last frame */ + int64_t next_frame_offset; /* offset of the next frame */ /* video info */ - int pict_type; /* XXX: put it back in AVCodecContext */ - int repeat_pict; /* XXX: put it back in AVCodecContext */ + int pict_type; /* XXX: Put it back in AVCodecContext. */ + int repeat_pict; /* XXX: Put it back in AVCodecContext. */ int64_t pts; /* pts of the current frame */ int64_t dts; /* dts of the current frame */ /* private data */ int64_t last_pts; int64_t last_dts; + int fetch_timestamp; #define AV_PARSER_PTS_NB 4 int cur_frame_start_index; int64_t cur_frame_offset[AV_PARSER_PTS_NB]; int64_t cur_frame_pts[AV_PARSER_PTS_NB]; int64_t cur_frame_dts[AV_PARSER_PTS_NB]; + + int flags; +#define PARSER_FLAG_COMPLETE_FRAMES 0x0001 + + int64_t offset; ///< byte offset from starting packet start + int64_t cur_frame_end[AV_PARSER_PTS_NB]; } AVCodecParserContext; typedef struct AVCodecParser { - int codec_ids[3]; /* several codec IDs are permitted */ + int codec_ids[5]; /* several codec IDs are permitted */ int priv_data_size; int (*parser_init)(AVCodecParserContext *s); - int (*parser_parse)(AVCodecParserContext *s, + int (*parser_parse)(AVCodecParserContext *s, AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, + const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size); void (*parser_close)(AVCodecParserContext *s); + int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size); struct AVCodecParser *next; } AVCodecParser; +#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) extern AVCodecParser *av_first_parser; +#endif +AVCodecParser *av_parser_next(AVCodecParser *c); void av_register_codec_parser(AVCodecParser *parser); AVCodecParserContext *av_parser_init(int codec_id); -int av_parser_parse(AVCodecParserContext *s, +int av_parser_parse(AVCodecParserContext *s, AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, + uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int64_t pts, int64_t dts); +int av_parser_change(AVCodecParserContext *s, + AVCodecContext *avctx, + uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size, int keyframe); void av_parser_close(AVCodecParserContext *s); -extern AVCodecParser mpegvideo_parser; -extern AVCodecParser mpeg4video_parser; -extern AVCodecParser h263_parser; -extern AVCodecParser h264_parser; -extern AVCodecParser mpegaudio_parser; -extern AVCodecParser ac3_parser; + +typedef struct AVBitStreamFilterContext { + void *priv_data; + struct AVBitStreamFilter *filter; + AVCodecParserContext *parser; + struct AVBitStreamFilterContext *next; +} AVBitStreamFilterContext; + + +typedef struct AVBitStreamFilter { + const char *name; + int priv_data_size; + int (*filter)(AVBitStreamFilterContext *bsfc, + AVCodecContext *avctx, const char *args, + uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size, int keyframe); + void (*close)(AVBitStreamFilterContext *bsfc); + struct AVBitStreamFilter *next; +} AVBitStreamFilter; + +void av_register_bitstream_filter(AVBitStreamFilter *bsf); +AVBitStreamFilterContext *av_bitstream_filter_init(const char *name); +int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc, + AVCodecContext *avctx, const char *args, + uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size, int keyframe); +void av_bitstream_filter_close(AVBitStreamFilterContext *bsf); + +AVBitStreamFilter *av_bitstream_filter_next(AVBitStreamFilter *f); /* memory */ -void *av_malloc(unsigned int size); -void *av_mallocz(unsigned int size); -void *av_realloc(void *ptr, unsigned int size); -void av_free(void *ptr); -char *av_strdup(const char *s); -void __av_freep(void **ptr); -#define av_freep(p) __av_freep((void **)(p)) + +/** + * Reallocates the given block if it is not large enough, otherwise it + * does nothing. + * + * @see av_realloc + */ void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size); -/* for static data only */ -/* call av_free_static to release all staticaly allocated tables */ -void av_free_static(void); -void *__av_mallocz_static(void** location, unsigned int size); -#define av_mallocz_static(p, s) __av_mallocz_static((void **)(p), s) -/* add by bero : in adx.c */ -int is_adx(const unsigned char *buf,size_t bufsize); - -void img_copy(AVPicture *dst, const AVPicture *src, +/** + * Copy image 'src' to 'dst'. + */ +void av_picture_copy(AVPicture *dst, const AVPicture *src, int pix_fmt, int width, int height); -/* av_log API */ +/** + * Crop image top and left side. + */ +int av_picture_crop(AVPicture *dst, const AVPicture *src, + int pix_fmt, int top_band, int left_band); -#include +/** + * Pad image. + */ +int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, int pix_fmt, + int padtop, int padbottom, int padleft, int padright, int *color); -#define AV_LOG_ERROR 0 -#define AV_LOG_INFO 1 -#define AV_LOG_DEBUG 2 +#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) +/** + * @deprecated Use the software scaler (swscale) instead. + */ +attribute_deprecated void img_copy(AVPicture *dst, const AVPicture *src, + int pix_fmt, int width, int height); -extern void av_log(AVCodecContext*, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4))); -extern void av_vlog(AVCodecContext*, int level, const char *fmt, va_list); -extern int av_log_get_level(void); -extern void av_log_set_level(int); -extern void av_log_set_callback(void (*)(AVCodecContext*, int, const char*, va_list)); +/** + * @deprecated Use the software scaler (swscale) instead. + */ +attribute_deprecated int img_crop(AVPicture *dst, const AVPicture *src, + int pix_fmt, int top_band, int left_band); -#undef AV_LOG_TRAP_PRINTF -#ifdef AV_LOG_TRAP_PRINTF -#define printf DO NOT USE -#define fprintf DO NOT USE -#undef stderr -#define stderr DO NOT USE +/** + * @deprecated Use the software scaler (swscale) instead. + */ +attribute_deprecated int img_pad(AVPicture *dst, const AVPicture *src, int height, int width, int pix_fmt, + int padtop, int padbottom, int padleft, int padright, int *color); #endif -#ifdef __cplusplus -} -#endif +extern unsigned int av_xiphlacing(unsigned char *s, unsigned int v); -#endif /* AVCODEC_H */ +/** + * Parses \p str and put in \p width_ptr and \p height_ptr the detected values. + * + * @return 0 in case of a successful parsing, a negative value otherwise + * @param[in] str the string to parse: it has to be a string in the format + * x or a valid video frame size abbreviation. + * @param[in,out] width_ptr pointer to the variable which will contain the detected + * frame width value + * @param[in,out] height_ptr pointer to the variable which will contain the detected + * frame height value + */ +int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str); + +/** + * Parses \p str and put in \p frame_rate the detected values. + * + * @return 0 in case of a successful parsing, a negative value otherwise + * @param[in] str the string to parse: it has to be a string in the format + * /, a float number or a valid video rate abbreviation + * @param[in,out] frame_rate pointer to the AVRational which will contain the detected + * frame rate + */ +int av_parse_video_frame_rate(AVRational *frame_rate, const char *str); + +/** + * Logs a generic warning message about a missing feature. + * @param[in] avc a pointer to an arbitrary struct of which the first field is + * a pointer to an AVClass struct + * @param[in] feature string containing the name of the missing feature + * @param[in] want_sample indicates if samples are wanted which exhibit this feature. + * If \p want_sample is non-zero, additional verbage will be added to the log + * message which tells the user how to report samples to the development + * mailing list. + */ +void av_log_missing_feature(void *avc, const char *feature, int want_sample); + +/* error handling */ +#if EINVAL > 0 +#define AVERROR(e) (-(e)) /**< Returns a negative error code from a POSIX error code, to return from library functions. */ +#define AVUNERROR(e) (-(e)) /**< Returns a POSIX error code from a library function error return value. */ +#else +/* Some platforms have E* and errno already negated. */ +#define AVERROR(e) (e) +#define AVUNERROR(e) (e) +#endif +#define AVERROR_UNKNOWN AVERROR(EINVAL) /**< unknown error */ +#define AVERROR_IO AVERROR(EIO) /**< I/O error */ +#define AVERROR_NUMEXPECTED AVERROR(EDOM) /**< Number syntax expected in filename. */ +#define AVERROR_INVALIDDATA AVERROR(EINVAL) /**< invalid data found */ +#define AVERROR_NOMEM AVERROR(ENOMEM) /**< not enough memory */ +#define AVERROR_NOFMT AVERROR(EILSEQ) /**< unknown format */ +#define AVERROR_NOTSUPP AVERROR(ENOSYS) /**< Operation not supported. */ +#define AVERROR_NOENT AVERROR(ENOENT) /**< No such file or directory. */ +#define AVERROR_PATCHWELCOME -MKTAG('P','A','W','E') /**< Not yet implemented in FFmpeg. Patches welcome. */ + +#endif /* FFMPEG_AVCODEC_H */