* qatar/master: (44 commits) replacement Indeo 3 decoder gsm demuxer: do not allocate packet twice. flvenc: use first packet delay as global delay. ac3enc: doxygen update. imc: return error codes instead of 0 for error conditions. imc: return meaningful error codes instead of -1 imc: do not set channel layout for stereo imc: validate channel count imc: check for ff_fft_init() failure imc: check output buffer size before decoding imc: use DSPContext.bswap16_buf() to byte-swap packet data rtsp: add allowed_media_types option libgsm: add flush function to reset the decoder state when seeking libgsm: simplify decoding by using a loop gsm: log error message when packet is too small libgsmdec: do not needlessly set *data_size to 0 gsmdec: do not needlessly set *data_size to 0 gsmdec: add flush function to reset the decoder state when seeking libgsmdec: check output buffer size before decoding gsmdec: log error message when output buffer is too small. ... Conflicts: Changelog ffplay.c libavcodec/indeo3.c libavcodec/mjpeg_parser.c libavcodec/vp3.c libavformat/cutils.c libavformat/id3v2.c libavutil/parseutils.c Merged-by: Michael Niedermayer <michaelni@gmx.at>tags/n0.9
| @@ -71,6 +71,7 @@ easier to use. The changes are: | |||
| - Pulseaudio input device | |||
| - Prores encoder | |||
| - Video Decoder Acceleration (VDA) HWAccel module. | |||
| - replacement Indeo 3 decoder | |||
| version 0.8: | |||
| @@ -61,9 +61,9 @@ static av_cold int aac_parse_init(AVCodecParserContext *s1) | |||
| AVCodecParser ff_aac_parser = { | |||
| { CODEC_ID_AAC }, | |||
| sizeof(AACAC3ParseContext), | |||
| aac_parse_init, | |||
| ff_aac_ac3_parse, | |||
| ff_parse_close, | |||
| .codec_ids = { CODEC_ID_AAC }, | |||
| .priv_data_size = sizeof(AACAC3ParseContext), | |||
| .parser_init = aac_parse_init, | |||
| .parser_parse = ff_aac_ac3_parse, | |||
| .parser_close = ff_parse_close, | |||
| }; | |||
| @@ -174,9 +174,9 @@ static av_cold int ac3_parse_init(AVCodecParserContext *s1) | |||
| AVCodecParser ff_ac3_parser = { | |||
| { CODEC_ID_AC3, CODEC_ID_EAC3 }, | |||
| sizeof(AACAC3ParseContext), | |||
| ac3_parse_init, | |||
| ff_aac_ac3_parse, | |||
| ff_parse_close, | |||
| .codec_ids = { CODEC_ID_AC3, CODEC_ID_EAC3 }, | |||
| .priv_data_size = sizeof(AACAC3ParseContext), | |||
| .parser_init = ac3_parse_init, | |||
| .parser_parse = ff_aac_ac3_parse, | |||
| .parser_close = ff_parse_close, | |||
| }; | |||
| @@ -176,6 +176,8 @@ static const int8_t ac3_coupling_start_tab[6][3][19] = { | |||
| /** | |||
| * Adjust the frame size to make the average bit rate match the target bit rate. | |||
| * This is only needed for 11025, 22050, and 44100 sample rates or any E-AC-3. | |||
| * | |||
| * @param s AC-3 encoder private context | |||
| */ | |||
| void ff_ac3_adjust_frame_size(AC3EncodeContext *s) | |||
| { | |||
| @@ -190,6 +192,11 @@ void ff_ac3_adjust_frame_size(AC3EncodeContext *s) | |||
| } | |||
| /** | |||
| * Set the initial coupling strategy parameters prior to coupling analysis. | |||
| * | |||
| * @param s AC-3 encoder private context | |||
| */ | |||
| void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s) | |||
| { | |||
| int blk, ch; | |||
| @@ -258,6 +265,8 @@ void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s) | |||
| /** | |||
| * Apply stereo rematrixing to coefficients based on rematrixing flags. | |||
| * | |||
| * @param s AC-3 encoder private context | |||
| */ | |||
| void ff_ac3_apply_rematrixing(AC3EncodeContext *s) | |||
| { | |||
| @@ -290,7 +299,7 @@ void ff_ac3_apply_rematrixing(AC3EncodeContext *s) | |||
| } | |||
| /** | |||
| /* | |||
| * Initialize exponent tables. | |||
| */ | |||
| static av_cold void exponent_init(AC3EncodeContext *s) | |||
| @@ -312,7 +321,7 @@ static av_cold void exponent_init(AC3EncodeContext *s) | |||
| } | |||
| /** | |||
| /* | |||
| * Extract exponents from the MDCT coefficients. | |||
| */ | |||
| static void extract_exponents(AC3EncodeContext *s) | |||
| @@ -341,7 +350,7 @@ static const uint8_t exp_strategy_reuse_tab[4][6] = { | |||
| { EXP_D45, EXP_D25, EXP_D25, EXP_D15, EXP_D15, EXP_D15 } | |||
| }; | |||
| /** | |||
| /* | |||
| * Calculate exponent strategies for all channels. | |||
| * Array arrangement is reversed to simplify the per-channel calculation. | |||
| */ | |||
| @@ -405,6 +414,11 @@ static void compute_exp_strategy(AC3EncodeContext *s) | |||
| /** | |||
| * Update the exponents so that they are the ones the decoder will decode. | |||
| * | |||
| * @param[in,out] exp array of exponents for 1 block in 1 channel | |||
| * @param nb_exps number of exponents in active bandwidth | |||
| * @param exp_strategy exponent strategy for the block | |||
| * @param cpl indicates if the block is in the coupling channel | |||
| */ | |||
| static void encode_exponents_blk_ch(uint8_t *exp, int nb_exps, int exp_strategy, | |||
| int cpl) | |||
| @@ -473,7 +487,7 @@ static void encode_exponents_blk_ch(uint8_t *exp, int nb_exps, int exp_strategy, | |||
| } | |||
| /** | |||
| /* | |||
| * Encode exponents from original extracted form to what the decoder will see. | |||
| * This copies and groups exponents based on exponent strategy and reduces | |||
| * deltas between adjacent exponent groups so that they can be differentially | |||
| @@ -526,7 +540,7 @@ static void encode_exponents(AC3EncodeContext *s) | |||
| } | |||
| /** | |||
| /* | |||
| * Count exponent bits based on bandwidth, coupling, and exponent strategies. | |||
| */ | |||
| static int count_exponent_bits(AC3EncodeContext *s) | |||
| @@ -558,6 +572,8 @@ static int count_exponent_bits(AC3EncodeContext *s) | |||
| * Group exponents. | |||
| * 3 delta-encoded exponents are in each 7-bit group. The number of groups | |||
| * varies depending on exponent strategy and bandwidth. | |||
| * | |||
| * @param s AC-3 encoder private context | |||
| */ | |||
| void ff_ac3_group_exponents(AC3EncodeContext *s) | |||
| { | |||
| @@ -614,6 +630,8 @@ void ff_ac3_group_exponents(AC3EncodeContext *s) | |||
| * Calculate final exponents from the supplied MDCT coefficients and exponent shift. | |||
| * Extract exponents from MDCT coefficients, calculate exponent strategies, | |||
| * and encode final exponents. | |||
| * | |||
| * @param s AC-3 encoder private context | |||
| */ | |||
| void ff_ac3_process_exponents(AC3EncodeContext *s) | |||
| { | |||
| @@ -627,7 +645,7 @@ void ff_ac3_process_exponents(AC3EncodeContext *s) | |||
| } | |||
| /** | |||
| /* | |||
| * Count frame bits that are based solely on fixed parameters. | |||
| * This only has to be run once when the encoder is initialized. | |||
| */ | |||
| @@ -733,7 +751,7 @@ static void count_frame_bits_fixed(AC3EncodeContext *s) | |||
| } | |||
| /** | |||
| /* | |||
| * Initialize bit allocation. | |||
| * Set default parameter codes and calculate parameter values. | |||
| */ | |||
| @@ -768,7 +786,7 @@ static void bit_alloc_init(AC3EncodeContext *s) | |||
| } | |||
| /** | |||
| /* | |||
| * Count the bits used to encode the frame, minus exponents and mantissas. | |||
| * Bits based on fixed parameters have already been counted, so now we just | |||
| * have to add the bits based on parameters that change during encoding. | |||
| @@ -915,7 +933,7 @@ static void count_frame_bits(AC3EncodeContext *s) | |||
| } | |||
| /** | |||
| /* | |||
| * Calculate masking curve based on the final exponents. | |||
| * Also calculate the power spectral densities to use in future calculations. | |||
| */ | |||
| @@ -945,7 +963,7 @@ static void bit_alloc_masking(AC3EncodeContext *s) | |||
| } | |||
| /** | |||
| /* | |||
| * Ensure that bap for each block and channel point to the current bap_buffer. | |||
| * They may have been switched during the bit allocation search. | |||
| */ | |||
| @@ -971,6 +989,8 @@ static void reset_block_bap(AC3EncodeContext *s) | |||
| * Initialize mantissa counts. | |||
| * These are set so that they are padded to the next whole group size when bits | |||
| * are counted in compute_mantissa_size. | |||
| * | |||
| * @param[in,out] mant_cnt running counts for each bap value for each block | |||
| */ | |||
| static void count_mantissa_bits_init(uint16_t mant_cnt[AC3_MAX_BLOCKS][16]) | |||
| { | |||
| @@ -987,6 +1007,12 @@ static void count_mantissa_bits_init(uint16_t mant_cnt[AC3_MAX_BLOCKS][16]) | |||
| /** | |||
| * Update mantissa bit counts for all blocks in 1 channel in a given bandwidth | |||
| * range. | |||
| * | |||
| * @param s AC-3 encoder private context | |||
| * @param ch channel index | |||
| * @param[in,out] mant_cnt running counts for each bap value for each block | |||
| * @param start starting coefficient bin | |||
| * @param end ending coefficient bin | |||
| */ | |||
| static void count_mantissa_bits_update_ch(AC3EncodeContext *s, int ch, | |||
| uint16_t mant_cnt[AC3_MAX_BLOCKS][16], | |||
| @@ -1005,7 +1031,7 @@ static void count_mantissa_bits_update_ch(AC3EncodeContext *s, int ch, | |||
| } | |||
| /** | |||
| /* | |||
| * Count the number of mantissa bits in the frame based on the bap values. | |||
| */ | |||
| static int count_mantissa_bits(AC3EncodeContext *s) | |||
| @@ -1028,6 +1054,9 @@ static int count_mantissa_bits(AC3EncodeContext *s) | |||
| * Run the bit allocation with a given SNR offset. | |||
| * This calculates the bit allocation pointers that will be used to determine | |||
| * the quantization of each mantissa. | |||
| * | |||
| * @param s AC-3 encoder private context | |||
| * @param snr_offset SNR offset, 0 to 1023 | |||
| * @return the number of bits needed for mantissas if the given SNR offset is | |||
| * is used. | |||
| */ | |||
| @@ -1058,7 +1087,7 @@ static int bit_alloc(AC3EncodeContext *s, int snr_offset) | |||
| } | |||
| /** | |||
| /* | |||
| * Constant bitrate bit allocation search. | |||
| * Find the largest SNR offset that will allow data to fit in the frame. | |||
| */ | |||
| @@ -1107,7 +1136,7 @@ static int cbr_bit_allocation(AC3EncodeContext *s) | |||
| } | |||
| /** | |||
| /* | |||
| * Perform bit allocation search. | |||
| * Finds the SNR offset value that maximizes quality and fits in the specified | |||
| * frame size. Output is the SNR offset and a set of bit allocation pointers | |||
| @@ -1127,6 +1156,11 @@ int ff_ac3_compute_bit_allocation(AC3EncodeContext *s) | |||
| /** | |||
| * Symmetric quantization on 'levels' levels. | |||
| * | |||
| * @param c unquantized coefficient | |||
| * @param e exponent | |||
| * @param levels number of quantization levels | |||
| * @return quantized coefficient | |||
| */ | |||
| static inline int sym_quant(int c, int e, int levels) | |||
| { | |||
| @@ -1138,6 +1172,11 @@ static inline int sym_quant(int c, int e, int levels) | |||
| /** | |||
| * Asymmetric quantization on 2^qbits levels. | |||
| * | |||
| * @param c unquantized coefficient | |||
| * @param e exponent | |||
| * @param qbits number of quantization bits | |||
| * @return quantized coefficient | |||
| */ | |||
| static inline int asym_quant(int c, int e, int qbits) | |||
| { | |||
| @@ -1154,6 +1193,14 @@ static inline int asym_quant(int c, int e, int qbits) | |||
| /** | |||
| * Quantize a set of mantissas for a single channel in a single block. | |||
| * | |||
| * @param s Mantissa count context | |||
| * @param fixed_coef unquantized fixed-point coefficients | |||
| * @param exp exponents | |||
| * @param bap bit allocation pointer indices | |||
| * @param[out] qmant quantized coefficients | |||
| * @param start_freq starting coefficient bin | |||
| * @param end_freq ending coefficient bin | |||
| */ | |||
| static void quantize_mantissas_blk_ch(AC3Mant *s, int32_t *fixed_coef, | |||
| uint8_t *exp, uint8_t *bap, | |||
| @@ -1246,6 +1293,8 @@ static void quantize_mantissas_blk_ch(AC3Mant *s, int32_t *fixed_coef, | |||
| /** | |||
| * Quantize mantissas using coefficients, exponents, and bit allocation pointers. | |||
| * | |||
| * @param s AC-3 encoder private context | |||
| */ | |||
| void ff_ac3_quantize_mantissas(AC3EncodeContext *s) | |||
| { | |||
| @@ -1273,7 +1322,7 @@ void ff_ac3_quantize_mantissas(AC3EncodeContext *s) | |||
| } | |||
| /** | |||
| /* | |||
| * Write the AC-3 frame header to the output bitstream. | |||
| */ | |||
| static void ac3_output_frame_header(AC3EncodeContext *s) | |||
| @@ -1329,7 +1378,7 @@ static void ac3_output_frame_header(AC3EncodeContext *s) | |||
| } | |||
| /** | |||
| /* | |||
| * Write one audio block to the output bitstream. | |||
| */ | |||
| static void output_audio_block(AC3EncodeContext *s, int blk) | |||
| @@ -1557,7 +1606,7 @@ static unsigned int pow_poly(unsigned int a, unsigned int n, unsigned int poly) | |||
| } | |||
| /** | |||
| /* | |||
| * Fill the end of the frame with 0's and compute the two CRCs. | |||
| */ | |||
| static void output_frame_end(AC3EncodeContext *s) | |||
| @@ -1605,6 +1654,9 @@ static void output_frame_end(AC3EncodeContext *s) | |||
| /** | |||
| * Write the frame to the output bitstream. | |||
| * | |||
| * @param s AC-3 encoder private context | |||
| * @param frame output data buffer | |||
| */ | |||
| void ff_ac3_output_frame(AC3EncodeContext *s, unsigned char *frame) | |||
| { | |||
| @@ -1775,6 +1827,8 @@ static void validate_mix_level(void *log_ctx, const char *opt_name, | |||
| /** | |||
| * Validate metadata options as set by AVOption system. | |||
| * These values can optionally be changed per-frame. | |||
| * | |||
| * @param s AC-3 encoder private context | |||
| */ | |||
| int ff_ac3_validate_metadata(AC3EncodeContext *s) | |||
| { | |||
| @@ -1957,6 +2011,8 @@ int ff_ac3_validate_metadata(AC3EncodeContext *s) | |||
| /** | |||
| * Finalize encoding and free any memory allocated by the encoder. | |||
| * | |||
| * @param avctx Codec context | |||
| */ | |||
| av_cold int ff_ac3_encode_close(AVCodecContext *avctx) | |||
| { | |||
| @@ -2000,7 +2056,7 @@ av_cold int ff_ac3_encode_close(AVCodecContext *avctx) | |||
| } | |||
| /** | |||
| /* | |||
| * Set channel information during initialization. | |||
| */ | |||
| static av_cold int set_channel_info(AC3EncodeContext *s, int channels, | |||
| @@ -2170,7 +2226,7 @@ static av_cold int validate_options(AC3EncodeContext *s) | |||
| } | |||
| /** | |||
| /* | |||
| * Set bandwidth for all channels. | |||
| * The user can optionally supply a cutoff frequency. Otherwise an appropriate | |||
| * default value will be used. | |||
| @@ -2348,9 +2404,6 @@ alloc_fail: | |||
| } | |||
| /** | |||
| * Initialize the encoder. | |||
| */ | |||
| av_cold int ff_ac3_encode_init(AVCodecContext *avctx) | |||
| { | |||
| AC3EncodeContext *s = avctx->priv_data; | |||
| @@ -41,6 +41,8 @@ static const AVClass ac3enc_class = { "Fixed-Point AC-3 Encoder", av_default_ite | |||
| /** | |||
| * Finalize MDCT and free allocated memory. | |||
| * | |||
| * @param s AC-3 encoder private context | |||
| */ | |||
| av_cold void AC3_NAME(mdct_end)(AC3EncodeContext *s) | |||
| { | |||
| @@ -50,7 +52,9 @@ av_cold void AC3_NAME(mdct_end)(AC3EncodeContext *s) | |||
| /** | |||
| * Initialize MDCT tables. | |||
| * @param nbits log2(MDCT size) | |||
| * | |||
| * @param s AC-3 encoder private context | |||
| * @return 0 on success, negative error code on failure | |||
| */ | |||
| av_cold int AC3_NAME(mdct_init)(AC3EncodeContext *s) | |||
| { | |||
| @@ -60,7 +64,7 @@ av_cold int AC3_NAME(mdct_init)(AC3EncodeContext *s) | |||
| } | |||
| /** | |||
| /* | |||
| * Apply KBD window to input samples prior to MDCT. | |||
| */ | |||
| static void apply_window(DSPContext *dsp, int16_t *output, const int16_t *input, | |||
| @@ -70,11 +74,9 @@ static void apply_window(DSPContext *dsp, int16_t *output, const int16_t *input, | |||
| } | |||
| /** | |||
| /* | |||
| * Normalize the input samples to use the maximum available precision. | |||
| * This assumes signed 16-bit input samples. | |||
| * | |||
| * @return exponent shift | |||
| */ | |||
| static int normalize_samples(AC3EncodeContext *s) | |||
| { | |||
| @@ -87,7 +89,7 @@ static int normalize_samples(AC3EncodeContext *s) | |||
| } | |||
| /** | |||
| /* | |||
| * Scale MDCT coefficients to 25-bit signed fixed-point. | |||
| */ | |||
| static void scale_coefficients(AC3EncodeContext *s) | |||
| @@ -110,7 +112,7 @@ static void sum_square_butterfly(AC3EncodeContext *s, int64_t sum[4], | |||
| s->ac3dsp.sum_square_butterfly_int32(sum, coef0, coef1, len); | |||
| } | |||
| /** | |||
| /* | |||
| * Clip MDCT coefficients to allowable range. | |||
| */ | |||
| static void clip_coefficients(DSPContext *dsp, int32_t *coef, unsigned int len) | |||
| @@ -119,7 +121,7 @@ static void clip_coefficients(DSPContext *dsp, int32_t *coef, unsigned int len) | |||
| } | |||
| /** | |||
| /* | |||
| * Calculate a single coupling coordinate. | |||
| */ | |||
| static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl) | |||
| @@ -44,6 +44,8 @@ static const AVClass ac3enc_class = { "AC-3 Encoder", av_default_item_name, | |||
| /** | |||
| * Finalize MDCT and free allocated memory. | |||
| * | |||
| * @param s AC-3 encoder private context | |||
| */ | |||
| av_cold void ff_ac3_float_mdct_end(AC3EncodeContext *s) | |||
| { | |||
| @@ -54,7 +56,9 @@ av_cold void ff_ac3_float_mdct_end(AC3EncodeContext *s) | |||
| /** | |||
| * Initialize MDCT tables. | |||
| * @param nbits log2(MDCT size) | |||
| * | |||
| * @param s AC-3 encoder private context | |||
| * @return 0 on success, negative error code on failure | |||
| */ | |||
| av_cold int ff_ac3_float_mdct_init(AC3EncodeContext *s) | |||
| { | |||
| @@ -78,7 +82,7 @@ av_cold int ff_ac3_float_mdct_init(AC3EncodeContext *s) | |||
| } | |||
| /** | |||
| /* | |||
| * Apply KBD window to input samples prior to MDCT. | |||
| */ | |||
| static void apply_window(DSPContext *dsp, float *output, const float *input, | |||
| @@ -88,7 +92,7 @@ static void apply_window(DSPContext *dsp, float *output, const float *input, | |||
| } | |||
| /** | |||
| /* | |||
| * Normalize the input samples. | |||
| * Not needed for the floating-point encoder. | |||
| */ | |||
| @@ -98,7 +102,7 @@ static int normalize_samples(AC3EncodeContext *s) | |||
| } | |||
| /** | |||
| /* | |||
| * Scale MDCT coefficients from float to 24-bit fixed-point. | |||
| */ | |||
| static void scale_coefficients(AC3EncodeContext *s) | |||
| @@ -117,7 +121,7 @@ static void sum_square_butterfly(AC3EncodeContext *s, float sum[4], | |||
| s->ac3dsp.sum_square_butterfly_float(sum, coef0, coef1, len); | |||
| } | |||
| /** | |||
| /* | |||
| * Clip MDCT coefficients to allowable range. | |||
| */ | |||
| static void clip_coefficients(DSPContext *dsp, float *coef, unsigned int len) | |||
| @@ -126,7 +130,7 @@ static void clip_coefficients(DSPContext *dsp, float *coef, unsigned int len) | |||
| } | |||
| /** | |||
| /* | |||
| * Calculate a single coupling coordinate. | |||
| */ | |||
| static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl) | |||
| @@ -67,7 +67,7 @@ alloc_fail: | |||
| } | |||
| /** | |||
| /* | |||
| * Deinterleave input samples. | |||
| * Channels are reordered from Libav's default order to AC-3 order. | |||
| */ | |||
| @@ -96,7 +96,7 @@ static void deinterleave_input_samples(AC3EncodeContext *s, | |||
| } | |||
| /** | |||
| /* | |||
| * Apply the MDCT to input samples to generate frequency coefficients. | |||
| * This applies the KBD window and normalizes the input to reduce precision | |||
| * loss due to fixed-point calculations. | |||
| @@ -123,7 +123,7 @@ static void apply_mdct(AC3EncodeContext *s) | |||
| } | |||
| /** | |||
| /* | |||
| * Calculate coupling channel and coupling coordinates. | |||
| */ | |||
| static void apply_channel_coupling(AC3EncodeContext *s) | |||
| @@ -331,7 +331,7 @@ static void apply_channel_coupling(AC3EncodeContext *s) | |||
| } | |||
| /** | |||
| /* | |||
| * Determine rematrixing flags for each block and band. | |||
| */ | |||
| static void compute_rematrixing_strategy(AC3EncodeContext *s) | |||
| @@ -386,9 +386,6 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s) | |||
| } | |||
| /** | |||
| * Encode a single AC-3 frame. | |||
| */ | |||
| int AC3_NAME(encode_frame)(AVCodecContext *avctx, unsigned char *frame, | |||
| int buf_size, void *data) | |||
| { | |||
| @@ -98,10 +98,9 @@ static int cavsvideo_parse(AVCodecParserContext *s, | |||
| } | |||
| AVCodecParser ff_cavsvideo_parser = { | |||
| { CODEC_ID_CAVS }, | |||
| sizeof(ParseContext1), | |||
| NULL, | |||
| cavsvideo_parse, | |||
| ff_parse1_close, | |||
| ff_mpeg4video_split, | |||
| .codec_ids = { CODEC_ID_CAVS }, | |||
| .priv_data_size = sizeof(ParseContext1), | |||
| .parser_parse = cavsvideo_parse, | |||
| .parser_close = ff_parse1_close, | |||
| .split = ff_mpeg4video_split, | |||
| }; | |||
| @@ -124,9 +124,9 @@ static int dca_parse(AVCodecParserContext * s, | |||
| } | |||
| AVCodecParser ff_dca_parser = { | |||
| {CODEC_ID_DTS}, | |||
| sizeof(DCAParseContext), | |||
| dca_parse_init, | |||
| dca_parse, | |||
| ff_parse_close, | |||
| .codec_ids = { CODEC_ID_DTS }, | |||
| .priv_data_size = sizeof(DCAParseContext), | |||
| .parser_init = dca_parse_init, | |||
| .parser_parse = dca_parse, | |||
| .parser_close = ff_parse_close, | |||
| }; | |||
| @@ -248,9 +248,8 @@ static void dirac_parse_close(AVCodecParserContext *s) | |||
| } | |||
| AVCodecParser ff_dirac_parser = { | |||
| { CODEC_ID_DIRAC }, | |||
| sizeof(DiracParseContext), | |||
| NULL, | |||
| dirac_parse, | |||
| dirac_parse_close, | |||
| .codec_ids = { CODEC_ID_DIRAC }, | |||
| .priv_data_size = sizeof(DiracParseContext), | |||
| .parser_parse = dirac_parse, | |||
| .parser_close = dirac_parse_close, | |||
| }; | |||
| @@ -87,9 +87,8 @@ static int dnxhd_parse(AVCodecParserContext *s, | |||
| } | |||
| AVCodecParser ff_dnxhd_parser = { | |||
| { CODEC_ID_DNXHD }, | |||
| sizeof(ParseContext), | |||
| NULL, | |||
| dnxhd_parse, | |||
| ff_parse_close, | |||
| .codec_ids = { CODEC_ID_DNXHD }, | |||
| .priv_data_size = sizeof(ParseContext), | |||
| .parser_parse = dnxhd_parse, | |||
| .parser_close = ff_parse_close, | |||
| }; | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * DVB subtitle encoding for ffmpeg | |||
| * DVB subtitle encoding | |||
| * Copyright (c) 2005 Fabrice Bellard | |||
| * | |||
| * This file is part of FFmpeg. | |||
| @@ -172,9 +172,9 @@ static av_cold void dvbsub_parse_close(AVCodecParserContext *s) | |||
| } | |||
| AVCodecParser ff_dvbsub_parser = { | |||
| { CODEC_ID_DVB_SUBTITLE }, | |||
| sizeof(DVBSubParseContext), | |||
| dvbsub_parse_init, | |||
| dvbsub_parse, | |||
| dvbsub_parse_close, | |||
| .codec_ids = { CODEC_ID_DVB_SUBTITLE }, | |||
| .priv_data_size = sizeof(DVBSubParseContext), | |||
| .parser_init = dvbsub_parse_init, | |||
| .parser_parse = dvbsub_parse, | |||
| .parser_close = dvbsub_parse_close, | |||
| }; | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * DVB subtitle decoding for ffmpeg | |||
| * DVB subtitle decoding | |||
| * Copyright (c) 2005 Ian Caulfield | |||
| * | |||
| * This file is part of FFmpeg. | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * DVD subtitle decoding for ffmpeg | |||
| * DVD subtitle decoding | |||
| * Copyright (c) 2005 Fabrice Bellard | |||
| * | |||
| * This file is part of FFmpeg. | |||
| @@ -77,9 +77,9 @@ static av_cold void dvdsub_parse_close(AVCodecParserContext *s) | |||
| } | |||
| AVCodecParser ff_dvdsub_parser = { | |||
| { CODEC_ID_DVD_SUBTITLE }, | |||
| sizeof(DVDSubParseContext), | |||
| dvdsub_parse_init, | |||
| dvdsub_parse, | |||
| dvdsub_parse_close, | |||
| .codec_ids = { CODEC_ID_DVD_SUBTITLE }, | |||
| .priv_data_size = sizeof(DVDSubParseContext), | |||
| .parser_init = dvdsub_parse_init, | |||
| .parser_parse = dvdsub_parse, | |||
| .parser_close = dvdsub_parse_close, | |||
| }; | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * DVD subtitle decoding for ffmpeg | |||
| * DVD subtitle decoding | |||
| * Copyright (c) 2005 Fabrice Bellard | |||
| * | |||
| * This file is part of FFmpeg. | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * DVD subtitle encoding for ffmpeg | |||
| * DVD subtitle encoding | |||
| * Copyright (c) 2005 Wolfram Gloger | |||
| * | |||
| * This file is part of FFmpeg. | |||
| @@ -674,9 +674,9 @@ static void flac_parse_close(AVCodecParserContext *c) | |||
| } | |||
| AVCodecParser ff_flac_parser = { | |||
| { CODEC_ID_FLAC }, | |||
| sizeof(FLACParseContext), | |||
| flac_parse_init, | |||
| flac_parse, | |||
| flac_parse_close, | |||
| .codec_ids = { CODEC_ID_FLAC }, | |||
| .priv_data_size = sizeof(FLACParseContext), | |||
| .parser_init = flac_parse_init, | |||
| .parser_parse = flac_parse, | |||
| .parser_close = flac_parse_close, | |||
| }; | |||
| @@ -22,7 +22,10 @@ | |||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |||
| */ | |||
| #include <limits.h> | |||
| #include "libavutil/avassert.h" | |||
| #include "libavutil/opt.h" | |||
| #include "avcodec.h" | |||
| #include "internal.h" | |||
| #include "get_bits.h" | |||
| #include "put_bits.h" | |||
| @@ -71,6 +74,7 @@ typedef struct G726Tables { | |||
| } G726Tables; | |||
| typedef struct G726Context { | |||
| AVClass *class; | |||
| G726Tables tbls; /**< static tables needed for computation */ | |||
| Float11 sr[2]; /**< prev. reconstructed samples */ | |||
| @@ -266,11 +270,11 @@ static int16_t g726_decode(G726Context* c, int I) | |||
| return av_clip(re_signal << 2, -0xffff, 0xffff); | |||
| } | |||
| static av_cold int g726_reset(G726Context* c, int index) | |||
| static av_cold int g726_reset(G726Context *c) | |||
| { | |||
| int i; | |||
| c->tbls = G726Tables_pool[index]; | |||
| c->tbls = G726Tables_pool[c->code_size - 2]; | |||
| for (i=0; i<2; i++) { | |||
| c->sr[i].mant = 1<<5; | |||
| c->pk[i] = 1; | |||
| @@ -295,65 +299,59 @@ static int16_t g726_encode(G726Context* c, int16_t sig) | |||
| g726_decode(c, i); | |||
| return i; | |||
| } | |||
| #endif | |||
| /* Interfacing to the libavcodec */ | |||
| static av_cold int g726_init(AVCodecContext * avctx) | |||
| static av_cold int g726_encode_init(AVCodecContext *avctx) | |||
| { | |||
| G726Context* c = avctx->priv_data; | |||
| unsigned int index; | |||
| if (avctx->sample_rate <= 0) { | |||
| av_log(avctx, AV_LOG_ERROR, "Samplerate is invalid\n"); | |||
| return -1; | |||
| if (avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL && | |||
| avctx->sample_rate != 8000) { | |||
| av_log(avctx, AV_LOG_ERROR, "Sample rates other than 8kHz are not " | |||
| "allowed when the compliance level is higher than unofficial. " | |||
| "Resample or reduce the compliance level.\n"); | |||
| return AVERROR(EINVAL); | |||
| } | |||
| av_assert0(avctx->sample_rate > 0); | |||
| index = (avctx->bit_rate + avctx->sample_rate/2) / avctx->sample_rate - 2; | |||
| if (avctx->bit_rate % avctx->sample_rate && avctx->codec->encode) { | |||
| av_log(avctx, AV_LOG_ERROR, "Bitrate - Samplerate combination is invalid\n"); | |||
| return -1; | |||
| } | |||
| if(avctx->channels != 1){ | |||
| av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n"); | |||
| return -1; | |||
| } | |||
| if(index>3){ | |||
| av_log(avctx, AV_LOG_ERROR, "Unsupported number of bits %d\n", index+2); | |||
| return -1; | |||
| return AVERROR(EINVAL); | |||
| } | |||
| g726_reset(c, index); | |||
| c->code_size = index+2; | |||
| if (avctx->bit_rate) | |||
| c->code_size = (avctx->bit_rate + avctx->sample_rate/2) / avctx->sample_rate; | |||
| c->code_size = av_clip(c->code_size, 2, 5); | |||
| avctx->bit_rate = c->code_size * avctx->sample_rate; | |||
| avctx->bits_per_coded_sample = c->code_size; | |||
| g726_reset(c); | |||
| avctx->coded_frame = avcodec_alloc_frame(); | |||
| if (!avctx->coded_frame) | |||
| return AVERROR(ENOMEM); | |||
| avctx->coded_frame->key_frame = 1; | |||
| if (avctx->codec->decode) | |||
| avctx->sample_fmt = AV_SAMPLE_FMT_S16; | |||
| /* select a frame size that will end on a byte boundary and have a size of | |||
| approximately 1024 bytes */ | |||
| if (avctx->codec->encode) | |||
| avctx->frame_size = ((int[]){ 4096, 2736, 2048, 1640 })[index]; | |||
| avctx->frame_size = ((int[]){ 4096, 2736, 2048, 1640 })[c->code_size - 2]; | |||
| return 0; | |||
| } | |||
| static av_cold int g726_close(AVCodecContext *avctx) | |||
| static av_cold int g726_encode_close(AVCodecContext *avctx) | |||
| { | |||
| av_freep(&avctx->coded_frame); | |||
| return 0; | |||
| } | |||
| #if CONFIG_ADPCM_G726_ENCODER | |||
| static int g726_encode_frame(AVCodecContext *avctx, | |||
| uint8_t *dst, int buf_size, void *data) | |||
| { | |||
| G726Context *c = avctx->priv_data; | |||
| const short *samples = data; | |||
| const int16_t *samples = data; | |||
| PutBitContext pb; | |||
| int i; | |||
| @@ -366,8 +364,72 @@ static int g726_encode_frame(AVCodecContext *avctx, | |||
| return put_bits_count(&pb)>>3; | |||
| } | |||
| #define OFFSET(x) offsetof(G726Context, x) | |||
| #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM | |||
| static const AVOption options[] = { | |||
| { "code_size", "Bits per code", OFFSET(code_size), AV_OPT_TYPE_INT, { 4 }, 2, 5, AE }, | |||
| { NULL }, | |||
| }; | |||
| static const AVClass class = { | |||
| .class_name = "g726", | |||
| .item_name = av_default_item_name, | |||
| .option = options, | |||
| .version = LIBAVUTIL_VERSION_INT, | |||
| }; | |||
| static const AVCodecDefault defaults[] = { | |||
| { "b", "0" }, | |||
| { NULL }, | |||
| }; | |||
| AVCodec ff_adpcm_g726_encoder = { | |||
| .name = "g726", | |||
| .type = AVMEDIA_TYPE_AUDIO, | |||
| .id = CODEC_ID_ADPCM_G726, | |||
| .priv_data_size = sizeof(G726Context), | |||
| .init = g726_encode_init, | |||
| .encode = g726_encode_frame, | |||
| .close = g726_encode_close, | |||
| .capabilities = CODEC_CAP_SMALL_LAST_FRAME, | |||
| .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, | |||
| .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), | |||
| .priv_class = &class, | |||
| .defaults = defaults, | |||
| }; | |||
| #endif | |||
| #if CONFIG_ADPCM_G726_DECODER | |||
| static av_cold int g726_decode_init(AVCodecContext *avctx) | |||
| { | |||
| G726Context* c = avctx->priv_data; | |||
| if (avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT && | |||
| avctx->sample_rate != 8000) { | |||
| av_log(avctx, AV_LOG_ERROR, "Only 8kHz sample rate is allowed when " | |||
| "the compliance level is strict. Reduce the compliance level " | |||
| "if you wish to decode the stream anyway.\n"); | |||
| return AVERROR(EINVAL); | |||
| } | |||
| if(avctx->channels != 1){ | |||
| av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n"); | |||
| return AVERROR(EINVAL); | |||
| } | |||
| c->code_size = avctx->bits_per_coded_sample; | |||
| if (c->code_size < 2 || c->code_size > 5) { | |||
| av_log(avctx, AV_LOG_ERROR, "Invalid number of bits %d\n", c->code_size); | |||
| return AVERROR(EINVAL); | |||
| } | |||
| g726_reset(c); | |||
| avctx->sample_fmt = AV_SAMPLE_FMT_S16; | |||
| return 0; | |||
| } | |||
| static int g726_decode_frame(AVCodecContext *avctx, | |||
| void *data, int *data_size, | |||
| AVPacket *avpkt) | |||
| @@ -375,43 +437,43 @@ static int g726_decode_frame(AVCodecContext *avctx, | |||
| const uint8_t *buf = avpkt->data; | |||
| int buf_size = avpkt->size; | |||
| G726Context *c = avctx->priv_data; | |||
| short *samples = data; | |||
| int16_t *samples = data; | |||
| GetBitContext gb; | |||
| int out_samples, out_size; | |||
| out_samples = buf_size * 8 / c->code_size; | |||
| out_size = out_samples * av_get_bytes_per_sample(avctx->sample_fmt); | |||
| if (*data_size < out_size) { | |||
| av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n"); | |||
| return AVERROR(EINVAL); | |||
| } | |||
| init_get_bits(&gb, buf, buf_size * 8); | |||
| while (get_bits_count(&gb) + c->code_size <= buf_size*8) | |||
| while (out_samples--) | |||
| *samples++ = g726_decode(c, get_bits(&gb, c->code_size)); | |||
| if(buf_size*8 != get_bits_count(&gb)) | |||
| if (get_bits_left(&gb) > 0) | |||
| av_log(avctx, AV_LOG_ERROR, "Frame invalidly split, missing parser?\n"); | |||
| *data_size = (uint8_t*)samples - (uint8_t*)data; | |||
| *data_size = out_size; | |||
| return buf_size; | |||
| } | |||
| #if CONFIG_ADPCM_G726_ENCODER | |||
| AVCodec ff_adpcm_g726_encoder = { | |||
| .name = "g726", | |||
| .type = AVMEDIA_TYPE_AUDIO, | |||
| .id = CODEC_ID_ADPCM_G726, | |||
| .priv_data_size = sizeof(G726Context), | |||
| .init = g726_init, | |||
| .encode = g726_encode_frame, | |||
| .close = g726_close, | |||
| .capabilities = CODEC_CAP_SMALL_LAST_FRAME, | |||
| .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, | |||
| .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), | |||
| }; | |||
| #endif | |||
| static void g726_decode_flush(AVCodecContext *avctx) | |||
| { | |||
| G726Context *c = avctx->priv_data; | |||
| g726_reset(c); | |||
| } | |||
| AVCodec ff_adpcm_g726_decoder = { | |||
| .name = "g726", | |||
| .type = AVMEDIA_TYPE_AUDIO, | |||
| .id = CODEC_ID_ADPCM_G726, | |||
| .priv_data_size = sizeof(G726Context), | |||
| .init = g726_init, | |||
| .close = g726_close, | |||
| .init = g726_decode_init, | |||
| .decode = g726_decode_frame, | |||
| .flush = g726_decode_flush, | |||
| .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), | |||
| }; | |||
| #endif | |||
| @@ -58,13 +58,18 @@ static int gsm_decode_frame(AVCodecContext *avctx, void *data, | |||
| const uint8_t *buf = avpkt->data; | |||
| int buf_size = avpkt->size; | |||
| int16_t *samples = data; | |||
| int frame_bytes = 2 * avctx->frame_size; | |||
| int frame_bytes = avctx->frame_size * | |||
| av_get_bytes_per_sample(avctx->sample_fmt); | |||
| if (*data_size < frame_bytes) | |||
| return -1; | |||
| *data_size = 0; | |||
| if(buf_size < avctx->block_align) | |||
| if (*data_size < frame_bytes) { | |||
| av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n"); | |||
| return AVERROR(EINVAL); | |||
| } | |||
| if (buf_size < avctx->block_align) { | |||
| av_log(avctx, AV_LOG_ERROR, "Packet is too small\n"); | |||
| return AVERROR_INVALIDDATA; | |||
| } | |||
| switch (avctx->codec_id) { | |||
| case CODEC_ID_GSM: | |||
| @@ -84,6 +89,12 @@ static int gsm_decode_frame(AVCodecContext *avctx, void *data, | |||
| return avctx->block_align; | |||
| } | |||
| static void gsm_flush(AVCodecContext *avctx) | |||
| { | |||
| GSMContext *s = avctx->priv_data; | |||
| memset(s, 0, sizeof(*s)); | |||
| } | |||
| AVCodec ff_gsm_decoder = { | |||
| .name = "gsm", | |||
| .type = AVMEDIA_TYPE_AUDIO, | |||
| @@ -91,6 +102,7 @@ AVCodec ff_gsm_decoder = { | |||
| .priv_data_size = sizeof(GSMContext), | |||
| .init = gsm_init, | |||
| .decode = gsm_decode_frame, | |||
| .flush = gsm_flush, | |||
| .long_name = NULL_IF_CONFIG_SMALL("GSM"), | |||
| }; | |||
| @@ -101,5 +113,6 @@ AVCodec ff_gsm_ms_decoder = { | |||
| .priv_data_size = sizeof(GSMContext), | |||
| .init = gsm_init, | |||
| .decode = gsm_decode_frame, | |||
| .flush = gsm_flush, | |||
| .long_name = NULL_IF_CONFIG_SMALL("GSM Microsoft variant"), | |||
| }; | |||
| @@ -86,9 +86,8 @@ static int h261_parse(AVCodecParserContext *s, | |||
| } | |||
| AVCodecParser ff_h261_parser = { | |||
| { CODEC_ID_H261 }, | |||
| sizeof(ParseContext), | |||
| NULL, | |||
| h261_parse, | |||
| ff_parse_close, | |||
| .codec_ids = { CODEC_ID_H261 }, | |||
| .priv_data_size = sizeof(ParseContext), | |||
| .parser_parse = h261_parse, | |||
| .parser_close = ff_parse_close, | |||
| }; | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * H263/MPEG4 backend for ffmpeg encoder and decoder | |||
| * H263/MPEG4 backend for encoder and decoder | |||
| * Copyright (c) 2000,2001 Fabrice Bellard | |||
| * H263+ support. | |||
| * Copyright (c) 2001 Juan J. Sierralta P | |||
| @@ -88,9 +88,8 @@ static int h263_parse(AVCodecParserContext *s, | |||
| } | |||
| AVCodecParser ff_h263_parser = { | |||
| { CODEC_ID_H263 }, | |||
| sizeof(ParseContext), | |||
| NULL, | |||
| h263_parse, | |||
| ff_parse_close, | |||
| .codec_ids = { CODEC_ID_H263 }, | |||
| .priv_data_size = sizeof(ParseContext), | |||
| .parser_parse = h263_parse, | |||
| .parser_close = ff_parse_close, | |||
| }; | |||
| @@ -375,10 +375,10 @@ static int init(AVCodecParserContext *s) | |||
| } | |||
| AVCodecParser ff_h264_parser = { | |||
| { CODEC_ID_H264 }, | |||
| sizeof(H264Context), | |||
| init, | |||
| h264_parse, | |||
| close, | |||
| h264_split, | |||
| .codec_ids = { CODEC_ID_H264 }, | |||
| .priv_data_size = sizeof(H264Context), | |||
| .parser_init = init, | |||
| .parser_parse = h264_parse, | |||
| .parser_close = close, | |||
| .split = h264_split, | |||
| }; | |||
| @@ -36,7 +36,7 @@ | |||
| * a little more compression by exploiting the fact that adjacent pixels | |||
| * tend to be similar. | |||
| * | |||
| * Note that this decoder could use ffmpeg's optimized VLC facilities | |||
| * Note that this decoder could use libavcodec's optimized VLC facilities | |||
| * rather than naive, tree-based Huffman decoding. However, there are 256 | |||
| * Huffman tables. Plus, the VLC bit coding order is right -> left instead | |||
| * or left -> right, so all of the bits would have to be reversed. Further, | |||
| @@ -104,10 +104,15 @@ static VLC_TYPE vlc_tables[VLC_TABLES_SIZE][2]; | |||
| static av_cold int imc_decode_init(AVCodecContext * avctx) | |||
| { | |||
| int i, j; | |||
| int i, j, ret; | |||
| IMCContext *q = avctx->priv_data; | |||
| double r1, r2; | |||
| if (avctx->channels != 1) { | |||
| av_log_ask_for_sample(avctx, "Number of channels is not supported\n"); | |||
| return AVERROR_PATCHWELCOME; | |||
| } | |||
| q->decoder_reset = 1; | |||
| for(i = 0; i < BANDS; i++) | |||
| @@ -156,10 +161,13 @@ static av_cold int imc_decode_init(AVCodecContext * avctx) | |||
| } | |||
| q->one_div_log2 = 1/log(2); | |||
| ff_fft_init(&q->fft, 7, 1); | |||
| if ((ret = ff_fft_init(&q->fft, 7, 1))) { | |||
| av_log(avctx, AV_LOG_INFO, "FFT init failed\n"); | |||
| return ret; | |||
| } | |||
| dsputil_init(&q->dsp, avctx); | |||
| avctx->sample_fmt = AV_SAMPLE_FMT_FLT; | |||
| avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO; | |||
| avctx->channel_layout = AV_CH_LAYOUT_MONO; | |||
| return 0; | |||
| } | |||
| @@ -336,7 +344,7 @@ static int bit_allocation (IMCContext* q, int stream_format_code, int freebits, | |||
| indx = 2; | |||
| if (indx == -1) | |||
| return -1; | |||
| return AVERROR_INVALIDDATA; | |||
| q->flcoeffs4[i] = q->flcoeffs4[i] + xTab[(indx*2 + (q->flcoeffs1[i] < highest)) * 2 + flag]; | |||
| } | |||
| @@ -595,7 +603,7 @@ static int inverse_quant_coeff (IMCContext* q, int stream_format_code) { | |||
| middle_value = max_size >> 1; | |||
| if (q->codewords[j] >= max_size || q->codewords[j] < 0) | |||
| return -1; | |||
| return AVERROR_INVALIDDATA; | |||
| if (cw_len >= 4){ | |||
| quantizer = imc_quantizer2[(stream_format_code & 2) >> 1]; | |||
| @@ -628,7 +636,7 @@ static int imc_get_coeffs (IMCContext* q) { | |||
| if (get_bits_count(&q->gb) + cw_len > 512){ | |||
| //av_log(NULL,0,"Band %i coeff %i cw_len %i\n",i,j,cw_len); | |||
| return -1; | |||
| return AVERROR_INVALIDDATA; | |||
| } | |||
| if(cw_len && (!q->bandFlagsBuf[i] || !q->skipFlags[j])) | |||
| @@ -651,18 +659,24 @@ static int imc_decode_frame(AVCodecContext * avctx, | |||
| IMCContext *q = avctx->priv_data; | |||
| int stream_format_code; | |||
| int imc_hdr, i, j; | |||
| int imc_hdr, i, j, out_size, ret; | |||
| int flag; | |||
| int bits, summer; | |||
| int counter, bitscount; | |||
| uint16_t buf16[IMC_BLOCK_SIZE / 2]; | |||
| LOCAL_ALIGNED_16(uint16_t, buf16, [IMC_BLOCK_SIZE / 2]); | |||
| if (buf_size < IMC_BLOCK_SIZE) { | |||
| av_log(avctx, AV_LOG_ERROR, "imc frame too small!\n"); | |||
| return -1; | |||
| return AVERROR_INVALIDDATA; | |||
| } | |||
| for(i = 0; i < IMC_BLOCK_SIZE / 2; i++) | |||
| buf16[i] = av_bswap16(((const uint16_t*)buf)[i]); | |||
| out_size = COEFFS * av_get_bytes_per_sample(avctx->sample_fmt); | |||
| if (*data_size < out_size) { | |||
| av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n"); | |||
| return AVERROR(EINVAL); | |||
| } | |||
| q->dsp.bswap16_buf(buf16, (const uint16_t*)buf, IMC_BLOCK_SIZE / 2); | |||
| q->out_samples = data; | |||
| init_get_bits(&q->gb, (const uint8_t*)buf16, IMC_BLOCK_SIZE * 8); | |||
| @@ -672,13 +686,13 @@ static int imc_decode_frame(AVCodecContext * avctx, | |||
| if (imc_hdr != IMC_FRAME_ID) { | |||
| av_log(avctx, AV_LOG_ERROR, "imc frame header check failed!\n"); | |||
| av_log(avctx, AV_LOG_ERROR, "got %x instead of 0x21.\n", imc_hdr); | |||
| return -1; | |||
| return AVERROR_INVALIDDATA; | |||
| } | |||
| stream_format_code = get_bits(&q->gb, 3); | |||
| if(stream_format_code & 1){ | |||
| av_log(avctx, AV_LOG_ERROR, "Stream code format %X is not supported\n", stream_format_code); | |||
| return -1; | |||
| return AVERROR_INVALIDDATA; | |||
| } | |||
| // av_log(avctx, AV_LOG_DEBUG, "stream_format_code = %d\n", stream_format_code); | |||
| @@ -738,10 +752,11 @@ static int imc_decode_frame(AVCodecContext * avctx, | |||
| } | |||
| } | |||
| if(bit_allocation (q, stream_format_code, 512 - bitscount - get_bits_count(&q->gb), flag) < 0) { | |||
| if((ret = bit_allocation (q, stream_format_code, | |||
| 512 - bitscount - get_bits_count(&q->gb), flag)) < 0) { | |||
| av_log(avctx, AV_LOG_ERROR, "Bit allocations failed\n"); | |||
| q->decoder_reset = 1; | |||
| return -1; | |||
| return ret; | |||
| } | |||
| for(i = 0; i < BANDS; i++) { | |||
| @@ -795,20 +810,20 @@ static int imc_decode_frame(AVCodecContext * avctx, | |||
| if(imc_get_coeffs(q) < 0) { | |||
| av_log(avctx, AV_LOG_ERROR, "Read coefficients failed\n"); | |||
| q->decoder_reset = 1; | |||
| return 0; | |||
| return AVERROR_INVALIDDATA; | |||
| } | |||
| if(inverse_quant_coeff(q, stream_format_code) < 0) { | |||
| av_log(avctx, AV_LOG_ERROR, "Inverse quantization of coefficients failed\n"); | |||
| q->decoder_reset = 1; | |||
| return 0; | |||
| return AVERROR_INVALIDDATA; | |||
| } | |||
| memset(q->skipFlags, 0, sizeof(q->skipFlags)); | |||
| imc_imdct256(q); | |||
| *data_size = COEFFS * sizeof(float); | |||
| *data_size = out_size; | |||
| return IMC_BLOCK_SIZE; | |||
| } | |||
| @@ -106,9 +106,8 @@ static int latm_parse(AVCodecParserContext *s1, AVCodecContext *avctx, | |||
| } | |||
| AVCodecParser ff_aac_latm_parser = { | |||
| { CODEC_ID_AAC_LATM }, | |||
| sizeof(LATMParseContext), | |||
| NULL, | |||
| latm_parse, | |||
| ff_parse_close | |||
| .codec_ids = { CODEC_ID_AAC_LATM }, | |||
| .priv_data_size = sizeof(LATMParseContext), | |||
| .parser_parse = latm_parse, | |||
| .parser_close = ff_parse_close | |||
| }; | |||
| @@ -166,23 +166,39 @@ static av_cold int libgsm_decode_close(AVCodecContext *avctx) { | |||
| static int libgsm_decode_frame(AVCodecContext *avctx, | |||
| void *data, int *data_size, | |||
| AVPacket *avpkt) { | |||
| int i, ret; | |||
| struct gsm_state *s = avctx->priv_data; | |||
| uint8_t *buf = avpkt->data; | |||
| int buf_size = avpkt->size; | |||
| *data_size = 0; /* In case of error */ | |||
| if(buf_size < avctx->block_align) return -1; | |||
| switch(avctx->codec_id) { | |||
| case CODEC_ID_GSM: | |||
| if(gsm_decode(avctx->priv_data,buf,data)) return -1; | |||
| *data_size = GSM_FRAME_SIZE*sizeof(int16_t); | |||
| break; | |||
| case CODEC_ID_GSM_MS: | |||
| if(gsm_decode(avctx->priv_data,buf,data) || | |||
| gsm_decode(avctx->priv_data,buf+33,((int16_t*)data)+GSM_FRAME_SIZE)) return -1; | |||
| *data_size = GSM_FRAME_SIZE*sizeof(int16_t)*2; | |||
| int16_t *samples = data; | |||
| int out_size = avctx->frame_size * av_get_bytes_per_sample(avctx->sample_fmt); | |||
| if (*data_size < out_size) { | |||
| av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n"); | |||
| return AVERROR(EINVAL); | |||
| } | |||
| if (buf_size < avctx->block_align) { | |||
| av_log(avctx, AV_LOG_ERROR, "Packet is too small\n"); | |||
| return AVERROR_INVALIDDATA; | |||
| } | |||
| for (i = 0; i < avctx->frame_size / GSM_FRAME_SIZE; i++) { | |||
| if ((ret = gsm_decode(s, buf, samples)) < 0) | |||
| return -1; | |||
| buf += GSM_BLOCK_SIZE; | |||
| samples += GSM_FRAME_SIZE; | |||
| } | |||
| *data_size = out_size; | |||
| return avctx->block_align; | |||
| } | |||
| static void libgsm_flush(AVCodecContext *avctx) { | |||
| gsm_destroy(avctx->priv_data); | |||
| avctx->priv_data = gsm_create(); | |||
| } | |||
| AVCodec ff_libgsm_decoder = { | |||
| .name = "libgsm", | |||
| .type = AVMEDIA_TYPE_AUDIO, | |||
| @@ -190,6 +206,7 @@ AVCodec ff_libgsm_decoder = { | |||
| .init = libgsm_decode_init, | |||
| .close = libgsm_decode_close, | |||
| .decode = libgsm_decode_frame, | |||
| .flush = libgsm_flush, | |||
| .long_name = NULL_IF_CONFIG_SMALL("libgsm GSM"), | |||
| }; | |||
| @@ -200,5 +217,6 @@ AVCodec ff_libgsm_ms_decoder = { | |||
| .init = libgsm_decode_init, | |||
| .close = libgsm_decode_close, | |||
| .decode = libgsm_decode_frame, | |||
| .flush = libgsm_flush, | |||
| .long_name = NULL_IF_CONFIG_SMALL("libgsm GSM Microsoft variant"), | |||
| }; | |||
| @@ -241,7 +241,7 @@ static av_cold int encode_init(AVCodecContext* avc_context) | |||
| header, comment, and tables. | |||
| Each one is prefixed with a 16bit size, then they | |||
| are concatenated together into ffmpeg's extradata. | |||
| are concatenated together into libavcodec's extradata. | |||
| */ | |||
| offset = 0; | |||
| @@ -27,7 +27,7 @@ | |||
| #include "avcodec.h" | |||
| /* | |||
| * Adapted to ffmpeg by Francois Revol <revol@free.fr> | |||
| * Adapted to libavcodec by Francois Revol <revol@free.fr> | |||
| * (removed 68k REG stuff, changed types, added some statics and consts, | |||
| * libavcodec api, context stuff, interlaced stereo out). | |||
| */ | |||
| @@ -127,9 +127,8 @@ static int jpeg_parse(AVCodecParserContext *s, | |||
| AVCodecParser ff_mjpeg_parser = { | |||
| { CODEC_ID_MJPEG }, | |||
| sizeof(MJPEGParserContext), | |||
| NULL, | |||
| jpeg_parse, | |||
| ff_parse_close, | |||
| .codec_ids = { CODEC_ID_MJPEG }, | |||
| .priv_data_size = sizeof(MJPEGParserContext), | |||
| .parser_parse = jpeg_parse, | |||
| .parser_close = ff_parse_close, | |||
| }; | |||
| @@ -345,9 +345,9 @@ lost_sync: | |||
| } | |||
| AVCodecParser ff_mlp_parser = { | |||
| { CODEC_ID_MLP, CODEC_ID_TRUEHD }, | |||
| sizeof(MLPParseContext), | |||
| mlp_init, | |||
| mlp_parse, | |||
| ff_parse_close, | |||
| .codec_ids = { CODEC_ID_MLP, CODEC_ID_TRUEHD }, | |||
| .priv_data_size = sizeof(MLPParseContext), | |||
| .parser_init = mlp_init, | |||
| .parser_parse = mlp_parse, | |||
| .parser_close = ff_parse_close, | |||
| }; | |||
| @@ -131,10 +131,10 @@ static int mpeg4video_parse(AVCodecParserContext *s, | |||
| AVCodecParser ff_mpeg4video_parser = { | |||
| { CODEC_ID_MPEG4 }, | |||
| sizeof(ParseContext1), | |||
| mpeg4video_parse_init, | |||
| mpeg4video_parse, | |||
| ff_parse1_close, | |||
| ff_mpeg4video_split, | |||
| .codec_ids = { CODEC_ID_MPEG4 }, | |||
| .priv_data_size = sizeof(ParseContext1), | |||
| .parser_init = mpeg4video_parse_init, | |||
| .parser_parse = mpeg4video_parse, | |||
| .parser_close = ff_parse1_close, | |||
| .split = ff_mpeg4video_split, | |||
| }; | |||
| @@ -1878,7 +1878,7 @@ static int decode_user_data(MpegEncContext *s, GetBitContext *gb){ | |||
| } | |||
| } | |||
| /* ffmpeg detection */ | |||
| /* libavcodec detection */ | |||
| e=sscanf(buf, "FFmpe%*[^b]b%d", &build)+3; | |||
| if(e!=4) | |||
| e=sscanf(buf, "FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build); | |||
| @@ -101,9 +101,8 @@ static int mpegaudio_parse(AVCodecParserContext *s1, | |||
| AVCodecParser ff_mpegaudio_parser = { | |||
| { CODEC_ID_MP1, CODEC_ID_MP2, CODEC_ID_MP3 }, | |||
| sizeof(MpegAudioParseContext), | |||
| NULL, | |||
| mpegaudio_parse, | |||
| ff_parse_close, | |||
| .codec_ids = { CODEC_ID_MP1, CODEC_ID_MP2, CODEC_ID_MP3 }, | |||
| .priv_data_size = sizeof(MpegAudioParseContext), | |||
| .parser_parse = mpegaudio_parse, | |||
| .parser_close = ff_parse_close, | |||
| }; | |||
| @@ -177,10 +177,9 @@ static int mpegvideo_split(AVCodecContext *avctx, | |||
| } | |||
| AVCodecParser ff_mpegvideo_parser = { | |||
| { CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO }, | |||
| sizeof(ParseContext1), | |||
| NULL, | |||
| mpegvideo_parse, | |||
| ff_parse1_close, | |||
| mpegvideo_split, | |||
| .codec_ids = { CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO }, | |||
| .priv_data_size = sizeof(ParseContext1), | |||
| .parser_parse = mpegvideo_parse, | |||
| .parser_close = ff_parse1_close, | |||
| .split = mpegvideo_split, | |||
| }; | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * MSMPEG4 backend for ffmpeg encoder and decoder | |||
| * MSMPEG4 backend for encoder and decoder | |||
| * Copyright (c) 2001 Fabrice Bellard | |||
| * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> | |||
| * | |||
| @@ -24,7 +24,7 @@ | |||
| /** | |||
| * @file | |||
| * MSMPEG4 backend for ffmpeg encoder and decoder. | |||
| * MSMPEG4 backend for encoder and decoder | |||
| */ | |||
| #include "avcodec.h" | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * MSMPEG4 backend for ffmpeg encoder and decoder | |||
| * MSMPEG4 backend for encoder and decoder | |||
| * copyright (c) 2007 Aurelien Jacobs <aurel@gnuage.org> | |||
| * | |||
| * This file is part of FFmpeg. | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * MSMPEG4 backend for ffmpeg encoder and decoder | |||
| * MSMPEG4 backend for encoder and decoder | |||
| * copyright (c) 2001 Fabrice Bellard | |||
| * copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> | |||
| * | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * MSMPEG4 backend for ffmpeg encoder and decoder | |||
| * MSMPEG4 backend for encoder and decoder | |||
| * copyright (c) 2001 Fabrice Bellard | |||
| * copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> | |||
| * | |||
| @@ -84,9 +84,9 @@ retry: | |||
| } | |||
| AVCodecParser ff_pnm_parser = { | |||
| { CODEC_ID_PGM, CODEC_ID_PGMYUV, CODEC_ID_PPM, CODEC_ID_PBM, CODEC_ID_PAM}, | |||
| sizeof(ParseContext), | |||
| NULL, | |||
| pnm_parse, | |||
| ff_parse_close, | |||
| .codec_ids = { CODEC_ID_PGM, CODEC_ID_PGMYUV, CODEC_ID_PPM, | |||
| CODEC_ID_PBM, CODEC_ID_PAM }, | |||
| .priv_data_size = sizeof(ParseContext), | |||
| .parser_parse = pnm_parse, | |||
| .parser_close = ff_parse_close, | |||
| }; | |||
| @@ -30,8 +30,8 @@ | |||
| * Note that this decoder reads big endian RGB555 pixel values from the | |||
| * bytestream, arranges them in the host's endian order, and outputs | |||
| * them to the final rendered map in the same host endian order. This is | |||
| * intended behavior as the ffmpeg documentation states that RGB555 pixels | |||
| * shall be stored in native CPU endianness. | |||
| * intended behavior as the libavcodec documentation states that RGB555 | |||
| * pixels shall be stored in native CPU endianness. | |||
| */ | |||
| #include <stdio.h> | |||
| @@ -78,18 +78,16 @@ static int rv34_parse(AVCodecParserContext *s, | |||
| #ifdef CONFIG_RV30_PARSER | |||
| AVCodecParser ff_rv30_parser = { | |||
| { CODEC_ID_RV30 }, | |||
| sizeof(RV34ParseContext), | |||
| NULL, | |||
| rv34_parse, | |||
| .codec_ids = { CODEC_ID_RV30 }, | |||
| .priv_data_size = sizeof(RV34ParseContext), | |||
| .parser_parse = rv34_parse, | |||
| }; | |||
| #endif | |||
| #ifdef CONFIG_RV40_PARSER | |||
| AVCodecParser ff_rv40_parser = { | |||
| { CODEC_ID_RV40 }, | |||
| sizeof(RV34ParseContext), | |||
| NULL, | |||
| rv34_parse, | |||
| .codec_ids = { CODEC_ID_RV40 }, | |||
| .priv_data_size = sizeof(RV34ParseContext), | |||
| .parser_parse = rv34_parse, | |||
| }; | |||
| #endif | |||
| @@ -19,7 +19,7 @@ | |||
| */ | |||
| /* The *no_round* functions have been added by James A. Morrison, 2003,2004. | |||
| The vis code from libmpeg2 was adapted for ffmpeg by James A. Morrison. | |||
| The vis code from libmpeg2 was adapted for libavcodec by James A. Morrison. | |||
| */ | |||
| #include "config.h" | |||
| @@ -2,9 +2,9 @@ | |||
| * Duck Truemotion v1 Decoding Tables | |||
| * | |||
| * Data in this file was originally part of VpVision from On2 which is | |||
| * distributed under the GNU GPL. It is redistributed with ffmpeg under the | |||
| * GNU LGPL using the common understanding that data tables necessary for | |||
| * decoding algorithms are not necessarily licensable. | |||
| * distributed under the GNU GPL. It is redistributed with libavcodec under | |||
| * the GNU LGPL using the common understanding that data tables necessary | |||
| * for decoding algorithms are not necessarily copyrightable. | |||
| * | |||
| * This file is part of FFmpeg. | |||
| * | |||
| @@ -185,10 +185,9 @@ static int vc1_split(AVCodecContext *avctx, | |||
| } | |||
| AVCodecParser ff_vc1_parser = { | |||
| { CODEC_ID_VC1 }, | |||
| sizeof(VC1ParseContext), | |||
| NULL, | |||
| vc1_parse, | |||
| ff_parse1_close, | |||
| vc1_split, | |||
| .codec_ids = { CODEC_ID_VC1 }, | |||
| .priv_data_size = sizeof(VC1ParseContext), | |||
| .parser_parse = vc1_parse, | |||
| .parser_close = ff_parse1_close, | |||
| .split = vc1_split, | |||
| }; | |||
| @@ -1588,9 +1588,6 @@ static av_cold int allocate_tables(AVCodecContext *avctx) | |||
| return 0; | |||
| } | |||
| /* | |||
| * This is the ffmpeg/libavcodec API init function. | |||
| */ | |||
| static av_cold int vp3_decode_init(AVCodecContext *avctx) | |||
| { | |||
| Vp3DecodeContext *s = avctx->priv_data; | |||
| @@ -1842,9 +1839,6 @@ static int vp3_update_thread_context(AVCodecContext *dst, const AVCodecContext * | |||
| return 0; | |||
| } | |||
| /* | |||
| * This is the ffmpeg/libavcodec API frame decode function. | |||
| */ | |||
| static int vp3_decode_frame(AVCodecContext *avctx, | |||
| void *data, int *data_size, | |||
| AVPacket *avpkt) | |||
| @@ -2002,9 +1996,6 @@ error: | |||
| static void vp3_decode_flush(AVCodecContext *avctx); | |||
| /* | |||
| * This is the ffmpeg/libavcodec API module cleanup function. | |||
| */ | |||
| static av_cold int vp3_decode_end(AVCodecContext *avctx) | |||
| { | |||
| Vp3DecodeContext *s = avctx->priv_data; | |||
| @@ -36,9 +36,7 @@ static int parse(AVCodecParserContext *s, | |||
| } | |||
| AVCodecParser ff_vp3_parser = { | |||
| { CODEC_ID_THEORA, CODEC_ID_VP3, | |||
| CODEC_ID_VP6, CODEC_ID_VP6F, CODEC_ID_VP6A }, | |||
| 0, | |||
| NULL, | |||
| parse, | |||
| .codec_ids = { CODEC_ID_THEORA, CODEC_ID_VP3, CODEC_ID_VP6, | |||
| CODEC_ID_VP6F, CODEC_ID_VP6A }, | |||
| .parser_parse = parse, | |||
| }; | |||
| @@ -33,8 +33,6 @@ static int parse(AVCodecParserContext *s, | |||
| } | |||
| AVCodecParser ff_vp8_parser = { | |||
| { CODEC_ID_VP8 }, | |||
| 0, | |||
| NULL, | |||
| parse, | |||
| .codec_ids = { CODEC_ID_VP8 }, | |||
| .parser_parse = parse, | |||
| }; | |||
| @@ -22,7 +22,7 @@ | |||
| /** | |||
| * @file | |||
| * drawtext filter, based on the original FFmpeg vhook/drawtext.c | |||
| * drawtext filter, based on the original vhook/drawtext.c | |||
| * filter by Gustavo Sverzut Barbieri | |||
| */ | |||
| @@ -24,7 +24,7 @@ | |||
| * Misc test sources. | |||
| * | |||
| * testsrc is based on the test pattern generator demuxer by Nicolas George: | |||
| * http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2007-October/037845.html | |||
| * http://lists.ffmpeg.org/pipermail/ffmpeg-devel/2007-October/037845.html | |||
| * | |||
| * rgbtestsrc is ported from MPlayer libmpcodecs/vf_rgbtest.c by | |||
| * Michael Niedermayer. | |||
| @@ -93,7 +93,7 @@ OBJS-$(CONFIG_FOURXM_DEMUXER) += 4xm.o | |||
| OBJS-$(CONFIG_FRAMECRC_MUXER) += framecrcenc.o | |||
| OBJS-$(CONFIG_FRAMEMD5_MUXER) += md5enc.o | |||
| OBJS-$(CONFIG_GIF_MUXER) += gif.o | |||
| OBJS-$(CONFIG_GSM_DEMUXER) += rawdec.o | |||
| OBJS-$(CONFIG_GSM_DEMUXER) += gsmdec.o | |||
| OBJS-$(CONFIG_GXF_DEMUXER) += gxf.o | |||
| OBJS-$(CONFIG_GXF_MUXER) += gxfenc.o audiointerleave.o | |||
| OBJS-$(CONFIG_G722_DEMUXER) += rawdec.o | |||
| @@ -358,7 +358,7 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size) | |||
| /* Extract palette from extradata if bpp <= 8 */ | |||
| /* This code assumes that extradata contains only palette */ | |||
| /* This is true for all paletted codecs implemented in ffmpeg */ | |||
| /* This is true for all paletted codecs implemented in libavcodec */ | |||
| if (st->codec->extradata_size && (st->codec->bits_per_coded_sample <= 8)) { | |||
| int av_unused i; | |||
| #if HAVE_BIGENDIAN | |||
| @@ -35,7 +35,7 @@ | |||
| /* if we don't know the size in advance */ | |||
| #define AU_UNKNOWN_SIZE ((uint32_t)(~0)) | |||
| /* The ffmpeg codecs we support, and the IDs they have in the file */ | |||
| /* The libavcodec codecs we support, and the IDs they have in the file */ | |||
| static const AVCodecTag codec_au_tags[] = { | |||
| { CODEC_ID_PCM_MULAW, 1 }, | |||
| { CODEC_ID_PCM_S8, 2 }, | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * Unbuffered io for ffmpeg system | |||
| * unbuffered I/O | |||
| * Copyright (c) 2001 Fabrice Bellard | |||
| * | |||
| * This file is part of FFmpeg. | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * Buffered I/O for ffmpeg system | |||
| * buffered I/O | |||
| * Copyright (c) 2000,2001 Fabrice Bellard | |||
| * | |||
| * This file is part of FFmpeg. | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * AVISynth support for ffmpeg system | |||
| * AVISynth support | |||
| * Copyright (c) 2006 DivX, Inc. | |||
| * | |||
| * This file is part of FFmpeg. | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * Various simple utilities for ffmpeg system | |||
| * various simple utilities for libavformat | |||
| * Copyright (c) 2000, 2001, 2002 Fabrice Bellard | |||
| * | |||
| * This file is part of FFmpeg. | |||
| @@ -96,7 +96,7 @@ static const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t) | |||
| /* | |||
| * There's a couple of assumptions being made here: | |||
| * 1. By default we silence erroneous (0x8000/16bit 0x800/12bit) audio samples. | |||
| * We can pass them upwards when ffmpeg will be ready to deal with them. | |||
| * We can pass them upwards when libavcodec will be ready to deal with them. | |||
| * 2. We don't do software emphasis. | |||
| * 3. Audio is always returned as 16bit linear samples: 12bit nonlinear samples | |||
| * are converted into 16bit linear ones. | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * Buffered file io for ffmpeg system | |||
| * buffered file I/O | |||
| * Copyright (c) 2001 Fabrice Bellard | |||
| * | |||
| * This file is part of FFmpeg. | |||
| @@ -60,10 +60,10 @@ typedef struct FLVContext { | |||
| int64_t duration_offset; | |||
| int64_t filesize_offset; | |||
| int64_t duration; | |||
| int64_t delay; ///< first dts delay (needed for AVC & Speex) | |||
| } FLVContext; | |||
| typedef struct FLVStreamContext { | |||
| int delay; ///< first dts delay for each stream (needed for AVC & Speex) | |||
| int64_t last_ts; ///< last timestamp for each stream | |||
| } FLVStreamContext; | |||
| @@ -210,6 +210,8 @@ static int flv_write_header(AVFormatContext *s) | |||
| s->streams[i]->priv_data = sc; | |||
| sc->last_ts = -1; | |||
| } | |||
| flv->delay = AV_NOPTS_VALUE; | |||
| avio_write(pb, "FLV", 3); | |||
| avio_w8(pb,1); | |||
| avio_w8(pb, FLV_HEADER_FLAG_HASAUDIO * !!audio_enc | |||
| @@ -444,10 +446,15 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) | |||
| av_log(s, AV_LOG_ERROR, "malformated aac bitstream, use -absf aac_adtstoasc\n"); | |||
| return -1; | |||
| } | |||
| if (!sc->delay && pkt->dts < 0) | |||
| sc->delay = -pkt->dts; | |||
| if (flv->delay == AV_NOPTS_VALUE) | |||
| flv->delay = -pkt->dts; | |||
| if (pkt->dts < -flv->delay) { | |||
| av_log(s, AV_LOG_WARNING, "Packets are not in the proper order with " | |||
| "respect to DTS\n"); | |||
| return AVERROR(EINVAL); | |||
| } | |||
| ts = pkt->dts + sc->delay; // add delay to force positive dts | |||
| ts = pkt->dts + flv->delay; // add delay to force positive dts | |||
| /* check Speex packet duration */ | |||
| if (enc->codec_id == CODEC_ID_SPEEX && ts - sc->last_ts > 160) { | |||
| @@ -481,7 +488,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) | |||
| avio_write(pb, data ? data : pkt->data, size); | |||
| avio_wb32(pb,size+flags_size+11); // previous tag size | |||
| flv->duration = FFMAX(flv->duration, pkt->pts + sc->delay + pkt->duration); | |||
| flv->duration = FFMAX(flv->duration, pkt->pts + flv->delay + pkt->duration); | |||
| avio_flush(pb); | |||
| @@ -0,0 +1,132 @@ | |||
| /* | |||
| * RAW GSM demuxer | |||
| * Copyright (c) 2011 Justin Ruggles | |||
| * | |||
| * This file is part of Libav. | |||
| * | |||
| * Libav 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. | |||
| * | |||
| * Libav 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 Libav; if not, write to the Free Software | |||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |||
| */ | |||
| #include "libavutil/mathematics.h" | |||
| #include "libavutil/opt.h" | |||
| #include "avformat.h" | |||
| #define GSM_BLOCK_SIZE 33 | |||
| #define GSM_BLOCK_SAMPLES 160 | |||
| #define GSM_SAMPLE_RATE 8000 | |||
| typedef struct { | |||
| AVClass *class; | |||
| int sample_rate; | |||
| } GSMDemuxerContext; | |||
| static int gsm_read_packet(AVFormatContext *s, AVPacket *pkt) | |||
| { | |||
| int ret, size; | |||
| size = GSM_BLOCK_SIZE * 32; | |||
| pkt->pos = avio_tell(s->pb); | |||
| pkt->stream_index = 0; | |||
| ret = av_get_packet(s->pb, pkt, size); | |||
| if (ret < GSM_BLOCK_SIZE) { | |||
| av_free_packet(pkt); | |||
| return ret < 0 ? ret : AVERROR(EIO); | |||
| } | |||
| pkt->size = ret; | |||
| pkt->duration = ret / GSM_BLOCK_SIZE; | |||
| pkt->pts = pkt->pos / GSM_BLOCK_SIZE; | |||
| return 0; | |||
| } | |||
| static int gsm_read_header(AVFormatContext *s, AVFormatParameters *ap) | |||
| { | |||
| GSMDemuxerContext *c = s->priv_data; | |||
| AVStream *st = avformat_new_stream(s, NULL); | |||
| if (!st) | |||
| return AVERROR(ENOMEM); | |||
| st->codec->codec_type = AVMEDIA_TYPE_AUDIO; | |||
| st->codec->codec_id = s->iformat->value; | |||
| st->codec->channels = 1; | |||
| st->codec->sample_rate = c->sample_rate; | |||
| st->codec->block_align = GSM_BLOCK_SIZE; | |||
| st->codec->bit_rate = GSM_BLOCK_SIZE * 8 * c->sample_rate / GSM_BLOCK_SAMPLES; | |||
| av_set_pts_info(st, 64, GSM_BLOCK_SAMPLES, GSM_SAMPLE_RATE); | |||
| return 0; | |||
| } | |||
| static int gsm_read_seek2(AVFormatContext *s, int stream_index, int64_t min_ts, | |||
| int64_t ts, int64_t max_ts, int flags) | |||
| { | |||
| GSMDemuxerContext *c = s->priv_data; | |||
| /* convert timestamps to file positions */ | |||
| if (!(flags & AVSEEK_FLAG_BYTE)) { | |||
| if (stream_index < 0) { | |||
| AVRational bitrate_q = { GSM_BLOCK_SAMPLES, c->sample_rate * GSM_BLOCK_SIZE }; | |||
| ts = av_rescale_q(ts, AV_TIME_BASE_Q, bitrate_q); | |||
| min_ts = av_rescale_q(min_ts, AV_TIME_BASE_Q, bitrate_q); | |||
| max_ts = av_rescale_q(max_ts, AV_TIME_BASE_Q, bitrate_q); | |||
| } else { | |||
| ts *= GSM_BLOCK_SIZE; | |||
| min_ts *= GSM_BLOCK_SIZE; | |||
| max_ts *= GSM_BLOCK_SIZE; | |||
| } | |||
| } | |||
| /* round to nearest block boundary */ | |||
| ts = (ts + GSM_BLOCK_SIZE / 2) / GSM_BLOCK_SIZE * GSM_BLOCK_SIZE; | |||
| ts = FFMAX(0, ts); | |||
| /* handle min/max */ | |||
| while (ts < min_ts) | |||
| ts += GSM_BLOCK_SIZE; | |||
| while (ts > max_ts) | |||
| ts -= GSM_BLOCK_SIZE; | |||
| if (ts < min_ts || ts > max_ts) | |||
| return -1; | |||
| return avio_seek(s->pb, ts, SEEK_SET); | |||
| } | |||
| static const AVOption options[] = { | |||
| { "sample_rate", "", offsetof(GSMDemuxerContext, sample_rate), | |||
| AV_OPT_TYPE_INT, {.dbl = GSM_SAMPLE_RATE}, 1, INT_MAX / GSM_BLOCK_SIZE, | |||
| AV_OPT_FLAG_DECODING_PARAM }, | |||
| { NULL }, | |||
| }; | |||
| static const AVClass class = { | |||
| .class_name = "gsm demuxer", | |||
| .item_name = av_default_item_name, | |||
| .option = options, | |||
| .version = LIBAVUTIL_VERSION_INT, | |||
| }; | |||
| AVInputFormat ff_gsm_demuxer = { | |||
| .name = "gsm", | |||
| .long_name = NULL_IF_CONFIG_SMALL("raw GSM"), | |||
| .priv_data_size = sizeof(GSMDemuxerContext), | |||
| .read_header = gsm_read_header, | |||
| .read_packet = gsm_read_packet, | |||
| .read_seek2 = gsm_read_seek2, | |||
| .extensions = "gsm", | |||
| .value = CODEC_ID_GSM, | |||
| .priv_class = &class, | |||
| }; | |||
| @@ -392,7 +392,7 @@ typedef struct ID3v2EMFunc { | |||
| const char *tag3; | |||
| const char *tag4; | |||
| void (*read)(AVFormatContext*, AVIOContext*, int, char*, ID3v2ExtraMeta **); | |||
| void (*free)(void *); | |||
| void (*free)(void *obj); | |||
| } ID3v2EMFunc; | |||
| static const ID3v2EMFunc id3v2_extra_meta_funcs[] = { | |||
| @@ -1475,7 +1475,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len | |||
| if (pid < 0) | |||
| break; | |||
| /* now create ffmpeg stream */ | |||
| /* now create stream */ | |||
| if (ts->pids[pid] && ts->pids[pid]->type == MPEGTS_PES) { | |||
| pes = ts->pids[pid]->u.pes_filter.opaque; | |||
| if (!pes->st) { | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * Various utilities for ffmpeg system | |||
| * various OS-feature replacement utilities | |||
| * Copyright (c) 2000, 2001, 2002 Fabrice Bellard | |||
| * copyright (c) 2002 Francois Revol | |||
| * | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * various utilities for ffmpeg system | |||
| * various OS-feature replacement utilities | |||
| * copyright (c) 2000, 2001, 2002 Fabrice Bellard | |||
| * | |||
| * This file is part of FFmpeg. | |||
| @@ -193,18 +193,6 @@ AVInputFormat ff_g722_demuxer = { | |||
| }; | |||
| #endif | |||
| #if CONFIG_GSM_DEMUXER | |||
| AVInputFormat ff_gsm_demuxer = { | |||
| .name = "gsm", | |||
| .long_name = NULL_IF_CONFIG_SMALL("raw GSM"), | |||
| .read_header = ff_raw_audio_read_header, | |||
| .read_packet = ff_raw_read_partial_packet, | |||
| .flags= AVFMT_GENERIC_INDEX, | |||
| .extensions = "gsm", | |||
| .value = CODEC_ID_GSM, | |||
| }; | |||
| #endif | |||
| #if CONFIG_LATM_DEMUXER | |||
| AVInputFormat ff_latm_demuxer = { | |||
| .name = "latm", | |||
| @@ -400,11 +400,13 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc) | |||
| avio_wl32(pb, enc->sample_rate); | |||
| if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3 || enc->codec_id == CODEC_ID_GSM_MS) { | |||
| bps = 0; | |||
| } else if (enc->codec_id == CODEC_ID_ADPCM_G726) { | |||
| bps = 4; | |||
| } else { | |||
| if (!(bps = av_get_bits_per_sample(enc->codec_id))) | |||
| bps = 16; // default to 16 | |||
| if (!(bps = av_get_bits_per_sample(enc->codec_id))) { | |||
| if (enc->bits_per_coded_sample) | |||
| bps = enc->bits_per_coded_sample; | |||
| else | |||
| bps = 16; // default to 16 | |||
| } | |||
| } | |||
| if(bps != enc->bits_per_coded_sample && enc->bits_per_coded_sample){ | |||
| av_log(enc, AV_LOG_WARNING, "requested bits_per_coded_sample (%d) and actually stored (%d) differ\n", enc->bits_per_coded_sample, bps); | |||
| @@ -415,12 +417,10 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc) | |||
| //blkalign = 144 * enc->bit_rate/enc->sample_rate; | |||
| } else if (enc->codec_id == CODEC_ID_AC3) { | |||
| blkalign = 3840; //maximum bytes per frame | |||
| } else if (enc->codec_id == CODEC_ID_ADPCM_G726) { // | |||
| blkalign = 1; | |||
| } else if (enc->block_align != 0) { /* specified by the codec */ | |||
| blkalign = enc->block_align; | |||
| } else | |||
| blkalign = enc->channels*bps >> 3; | |||
| blkalign = bps * enc->channels / av_gcd(8, bps); | |||
| if (enc->codec_id == CODEC_ID_PCM_U8 || | |||
| enc->codec_id == CODEC_ID_PCM_S24LE || | |||
| enc->codec_id == CODEC_ID_PCM_S32LE || | |||
| @@ -572,6 +572,9 @@ int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size) | |||
| codec->channels = 0; | |||
| codec->sample_rate = 0; | |||
| } | |||
| /* override bits_per_coded_sample for G.726 */ | |||
| if (codec->codec_id == CODEC_ID_ADPCM_G726) | |||
| codec->bits_per_coded_sample = codec->bit_rate / codec->sample_rate; | |||
| return 0; | |||
| } | |||
| @@ -26,7 +26,7 @@ | |||
| #define RSO_HEADER_SIZE 8 | |||
| /* The ffmpeg codecs we support, and the IDs they have in the file */ | |||
| /* The libavcodec codecs we support, and the IDs they have in the file */ | |||
| extern const AVCodecTag ff_codec_rso_tags[]; | |||
| #endif /* AVFORMAT_RSO_H */ | |||
| @@ -65,6 +65,12 @@ | |||
| { name, longname, OFFSET(rtsp_flags), AV_OPT_TYPE_FLAGS, {0}, INT_MIN, INT_MAX, DEC, "rtsp_flags" }, \ | |||
| { "filter_src", "Only receive packets from the negotiated peer IP", 0, AV_OPT_TYPE_CONST, {RTSP_FLAG_FILTER_SRC}, 0, 0, DEC, "rtsp_flags" } | |||
| #define RTSP_MEDIATYPE_OPTS(name, longname) \ | |||
| { name, longname, OFFSET(media_type_mask), AV_OPT_TYPE_FLAGS, { (1 << (AVMEDIA_TYPE_DATA+1)) - 1 }, INT_MIN, INT_MAX, DEC, "allowed_media_types" }, \ | |||
| { "video", "Video", 0, AV_OPT_TYPE_CONST, {1 << AVMEDIA_TYPE_VIDEO}, 0, 0, DEC, "allowed_media_types" }, \ | |||
| { "audio", "Audio", 0, AV_OPT_TYPE_CONST, {1 << AVMEDIA_TYPE_AUDIO}, 0, 0, DEC, "allowed_media_types" }, \ | |||
| { "data", "Data", 0, AV_OPT_TYPE_CONST, {1 << AVMEDIA_TYPE_DATA}, 0, 0, DEC, "allowed_media_types" } | |||
| const AVOption ff_rtsp_options[] = { | |||
| { "initial_pause", "Don't start playing the stream immediately", OFFSET(initial_pause), AV_OPT_TYPE_INT, {0}, 0, 1, DEC }, | |||
| FF_RTP_FLAG_OPTS(RTSPState, rtp_muxer_flags), | |||
| @@ -74,11 +80,13 @@ const AVOption ff_rtsp_options[] = { | |||
| { "udp_multicast", "UDP multicast", 0, AV_OPT_TYPE_CONST, {1 << RTSP_LOWER_TRANSPORT_UDP_MULTICAST}, 0, 0, DEC, "rtsp_transport" }, | |||
| { "http", "HTTP tunneling", 0, AV_OPT_TYPE_CONST, {(1 << RTSP_LOWER_TRANSPORT_HTTP)}, 0, 0, DEC, "rtsp_transport" }, | |||
| RTSP_FLAG_OPTS("rtsp_flags", "RTSP flags"), | |||
| RTSP_MEDIATYPE_OPTS("allowed_media_types", "Media types to accept from the server"), | |||
| { NULL }, | |||
| }; | |||
| static const AVOption sdp_options[] = { | |||
| RTSP_FLAG_OPTS("sdp_flags", "SDP flags"), | |||
| RTSP_MEDIATYPE_OPTS("allowed_media_types", "Media types to accept from the server"), | |||
| { NULL }, | |||
| }; | |||
| @@ -325,6 +333,7 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, | |||
| case 'm': | |||
| /* new stream */ | |||
| s1->skip_media = 0; | |||
| codec_type = AVMEDIA_TYPE_UNKNOWN; | |||
| get_word(st_type, sizeof(st_type), &p); | |||
| if (!strcmp(st_type, "audio")) { | |||
| codec_type = AVMEDIA_TYPE_AUDIO; | |||
| @@ -332,7 +341,8 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, | |||
| codec_type = AVMEDIA_TYPE_VIDEO; | |||
| } else if (!strcmp(st_type, "application")) { | |||
| codec_type = AVMEDIA_TYPE_DATA; | |||
| } else { | |||
| } | |||
| if (codec_type == AVMEDIA_TYPE_UNKNOWN || !(rt->media_type_mask & (1 << codec_type))) { | |||
| s1->skip_media = 1; | |||
| return; | |||
| } | |||
| @@ -354,6 +354,11 @@ typedef struct RTSPState { | |||
| * Various option flags for the RTSP muxer/demuxer. | |||
| */ | |||
| int rtsp_flags; | |||
| /** | |||
| * Mask of all requested media types | |||
| */ | |||
| int media_type_mask; | |||
| } RTSPState; | |||
| #define RTSP_FLAG_FILTER_SRC 0x1 /**< Filter incoming UDP packets - | |||
| @@ -52,17 +52,17 @@ static void colored_fputs(int level, const char *str){ | |||
| #if defined(_WIN32) && !defined(__MINGW32CE__) | |||
| CONSOLE_SCREEN_BUFFER_INFO con_info; | |||
| con = GetStdHandle(STD_ERROR_HANDLE); | |||
| use_color = (con != INVALID_HANDLE_VALUE) && !getenv("NO_COLOR") && !getenv("FFMPEG_FORCE_NOCOLOR"); | |||
| use_color = (con != INVALID_HANDLE_VALUE) && !getenv("NO_COLOR") && !getenv("AV_LOG_FORCE_NOCOLOR"); | |||
| if (use_color) { | |||
| GetConsoleScreenBufferInfo(con, &con_info); | |||
| attr_orig = con_info.wAttributes; | |||
| background = attr_orig & 0xF0; | |||
| } | |||
| #elif HAVE_ISATTY | |||
| use_color= !getenv("NO_COLOR") && !getenv("FFMPEG_FORCE_NOCOLOR") && | |||
| (getenv("TERM") && isatty(2) || getenv("FFMPEG_FORCE_COLOR")); | |||
| use_color= !getenv("NO_COLOR") && !getenv("AV_LOG_FORCE_NOCOLOR") && | |||
| (getenv("TERM") && isatty(2) || getenv("AV_LOG_FORCE_COLOR")); | |||
| #else | |||
| use_color= getenv("FFMPEG_FORCE_COLOR") && !getenv("NO_COLOR") && !getenv("FFMPEG_FORCE_NOCOLOR"); | |||
| use_color= getenv("AV_LOG_FORCE_COLOR") && !getenv("NO_COLOR") && !getenv("AV_LOG_FORCE_NOCOLOR"); | |||
| #endif | |||
| } | |||
| @@ -411,9 +411,7 @@ static int date_get_num(const char **pp, | |||
| * function call, or NULL in case the function fails to match all of | |||
| * the fmt string and therefore an error occurred | |||
| */ | |||
| static | |||
| const char *small_strptime(const char *p, const char *fmt, | |||
| struct tm *dt) | |||
| static const char *small_strptime(const char *p, const char *fmt, struct tm *dt) | |||
| { | |||
| int c, val; | |||