Mercurial > audlegacy-plugins
changeset 817:b3b7a4e480b2 trunk
[svn] - make this compile again
author | nenolod |
---|---|
date | Mon, 12 Mar 2007 13:14:40 -0700 |
parents | 87b58fcb96c8 |
children | 07107d476f32 |
files | ChangeLog src/ffmpeg/libavcodec/dsputil.c src/ffmpeg/libavcodec/dsputil.h src/ffmpeg/libavcodec/parser.c |
diffstat | 4 files changed, 273 insertions(+), 1035 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Mon Mar 12 13:11:29 2007 -0700 +++ b/ChangeLog Mon Mar 12 13:14:40 2007 -0700 @@ -1,3 +1,22 @@ +2007-03-12 20:11:29 +0000 William Pitcock <nenolod@sacredspiral.co.uk> + revision [1732] + - remove more video stuff, remove vorbis + + trunk/src/ffmpeg/libavcodec/Makefile | 14 + trunk/src/ffmpeg/libavcodec/error_resilience.c | 1030 ----------- + trunk/src/ffmpeg/libavcodec/eval.c | 1 + trunk/src/ffmpeg/libavcodec/parser.c | 2 + trunk/src/ffmpeg/libavcodec/pnm.c | 598 ------ + trunk/src/ffmpeg/libavcodec/qdrw.c | 160 - + trunk/src/ffmpeg/libavcodec/ratecontrol.c | 937 ---------- + trunk/src/ffmpeg/libavcodec/utils.c | 91 - + trunk/src/ffmpeg/libavcodec/vorbis.c | 1814 --------------------- + trunk/src/ffmpeg/libavcodec/vorbis.h | 43 + trunk/src/ffmpeg/libavcodec/vorbis_data.c | 2155 ------------------------- + trunk/src/ffmpeg/libavcodec/vorbis_enc.c | 1087 ------------ + 12 files changed, 6 insertions(+), 7926 deletions(-) + + 2007-03-12 20:06:30 +0000 William Pitcock <nenolod@sacredspiral.co.uk> revision [1730] - bork bork bork
--- a/src/ffmpeg/libavcodec/dsputil.c Mon Mar 12 13:11:29 2007 -0700 +++ b/src/ffmpeg/libavcodec/dsputil.c Mon Mar 12 13:14:40 2007 -0700 @@ -57,7 +57,7 @@ }; /* not permutated inverse zigzag_direct + 1 for MMX quantizer */ -uint16_t __align8 inv_zigzag_direct16[64]; +uint16_t inv_zigzag_direct16[64]; const uint8_t ff_alternate_horizontal_scan[64] = { 0, 1, 2, 3, 8, 9, 16, 17,
--- a/src/ffmpeg/libavcodec/dsputil.h Mon Mar 12 13:11:29 2007 -0700 +++ b/src/ffmpeg/libavcodec/dsputil.h Mon Mar 12 13:14:40 2007 -0700 @@ -3,19 +3,21 @@ * Copyright (c) 2000, 2001, 2002 Fabrice Bellard. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** @@ -35,6 +37,7 @@ //#define DEBUG /* dct code */ typedef short DCTELEM; +typedef int DWTELEM; void fdct_ifast (DCTELEM *data); void fdct_ifast248 (DCTELEM *data); @@ -42,11 +45,25 @@ void ff_fdct248_islow (DCTELEM *data); void j_rev_dct (DCTELEM *data); +void j_rev_dct4 (DCTELEM *data); +void j_rev_dct2 (DCTELEM *data); +void j_rev_dct1 (DCTELEM *data); void ff_fdct_mmx(DCTELEM *block); void ff_fdct_mmx2(DCTELEM *block); void ff_fdct_sse2(DCTELEM *block); +void ff_h264_idct8_add_c(uint8_t *dst, DCTELEM *block, int stride); +void ff_h264_idct_add_c(uint8_t *dst, DCTELEM *block, int stride); +void ff_h264_idct8_dc_add_c(uint8_t *dst, DCTELEM *block, int stride); +void ff_h264_idct_dc_add_c(uint8_t *dst, DCTELEM *block, int stride); +void ff_h264_lowres_idct_add_c(uint8_t *dst, int stride, DCTELEM *block); +void ff_h264_lowres_idct_put_c(uint8_t *dst, int stride, DCTELEM *block); + +void ff_vector_fmul_add_add_c(float *dst, const float *src0, const float *src1, + const float *src2, int src3, int blocksize, int step); +void ff_float_to_int16_c(int16_t *dst, const float *src, int len); + /* encoding scans */ extern const uint8_t ff_alternate_horizontal_scan[64]; extern const uint8_t ff_alternate_vertical_scan[64]; @@ -54,12 +71,25 @@ extern const uint8_t ff_zigzag248_direct[64]; /* pixel operations */ -#define MAX_NEG_CROP 384 +#define MAX_NEG_CROP 1024 /* temporary */ extern uint32_t squareTbl[512]; extern uint8_t cropTbl[256 + 2 * MAX_NEG_CROP]; +/* VP3 DSP functions */ +void ff_vp3_idct_c(DCTELEM *block/* align 16*/); +void ff_vp3_idct_put_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); +void ff_vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); + +/* 1/2^n downscaling functions from imgconvert.c */ +void ff_img_copy_plane(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); +void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); +void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); +void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); + +void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy, + int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height); /* minimum alignment rules ;) if u notice errors in the align stuff, need more alignment for some asm code for some cpu @@ -86,6 +116,8 @@ typedef void (*tpel_mc_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int w, int h); typedef void (*qpel_mc_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride); typedef void (*h264_chroma_mc_func)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x, int y); +typedef void (*h264_weight_func)(uint8_t *block, int stride, int log2_denom, int weight, int offset); +typedef void (*h264_biweight_func)(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset); #define DEF_OLD_QPEL(name)\ void ff_put_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\ @@ -117,6 +149,9 @@ typedef int (*me_cmp_func)(void /*MpegEncContext*/ *s, uint8_t *blk1/*align width (8 or 16)*/, uint8_t *blk2/*align 1*/, int line_size, int h)/* __attribute__ ((const))*/; +// for snow slices +typedef struct slice_buffer_s slice_buffer; + /** * DSPContext. */ @@ -125,7 +160,10 @@ void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size); void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride); void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); + void (*put_signed_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); + void (*add_pixels8)(uint8_t *pixels, DCTELEM *block, int line_size); + void (*add_pixels4)(uint8_t *pixels, DCTELEM *block, int line_size); /** * translational global motion compensation. */ @@ -134,12 +172,12 @@ * global motion compensation. */ void (*gmc )(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int ox, int oy, - int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height); + int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height); void (*clear_blocks)(DCTELEM *blocks/*align 16*/); int (*pix_sum)(uint8_t * pix, int line_size); int (*pix_norm1)(uint8_t * pix, int line_size); // 16x16 8x8 4x4 2x2 16x8 8x4 4x2 8x16 4x8 2x4 - + me_cmp_func sad[5]; /* identical to pix_absAxA except additional void * */ me_cmp_func sse[5]; me_cmp_func hadamard8_diff[5]; @@ -149,16 +187,22 @@ me_cmp_func rd[5]; me_cmp_func vsad[5]; me_cmp_func vsse[5]; + me_cmp_func nsse[5]; + me_cmp_func w53[5]; + me_cmp_func w97[5]; + me_cmp_func dct_max[5]; + me_cmp_func dct264_sad[5]; me_cmp_func me_pre_cmp[5]; me_cmp_func me_cmp[5]; me_cmp_func me_sub_cmp[5]; me_cmp_func mb_cmp[5]; me_cmp_func ildct_cmp[5]; //only width 16 used + me_cmp_func frame_skip_cmp[5]; //only width 8 used /** * Halfpel motion compensation with rounding (a+b+1)>>1. - * this is an array[4][4] of motion compensation funcions for 4 + * this is an array[4][4] of motion compensation funcions for 4 * horizontal blocksizes (8,16) and the 4 halfpel positions<br> * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ] * @param block destination where the result is stored @@ -170,7 +214,7 @@ /** * Halfpel motion compensation with rounding (a+b+1)>>1. - * This is an array[4][4] of motion compensation functions for 4 + * This is an array[4][4] of motion compensation functions for 4 * horizontal blocksizes (8,16) and the 4 halfpel positions<br> * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ] * @param block destination into which the result is averaged (a+b+1)>>1 @@ -182,7 +226,7 @@ /** * Halfpel motion compensation with no rounding (a+b)>>1. - * this is an array[2][4] of motion compensation funcions for 2 + * this is an array[2][4] of motion compensation funcions for 2 * horizontal blocksizes (8,16) and the 4 halfpel positions<br> * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ] * @param block destination where the result is stored @@ -190,11 +234,11 @@ * @param line_size number of bytes in a horizontal line of block * @param h height */ - op_pixels_func put_no_rnd_pixels_tab[2][4]; + op_pixels_func put_no_rnd_pixels_tab[4][4]; /** * Halfpel motion compensation with no rounding (a+b)>>1. - * this is an array[2][4] of motion compensation funcions for 2 + * this is an array[2][4] of motion compensation funcions for 2 * horizontal blocksizes (8,16) and the 4 halfpel positions<br> * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ] * @param block destination into which the result is averaged (a+b)>>1 @@ -202,8 +246,10 @@ * @param line_size number of bytes in a horizontal line of block * @param h height */ - op_pixels_func avg_no_rnd_pixels_tab[2][4]; - + op_pixels_func avg_no_rnd_pixels_tab[4][4]; + + void (*put_no_rnd_pixels_l2[2])(uint8_t *block/*align width (8 or 16)*/, const uint8_t *a/*align 1*/, const uint8_t *b/*align 1*/, int line_size, int h); + /** * Thirdpel motion compensation with rounding (a+b+1)>>1. * this is an array[12] of motion compensation funcions for the 9 thirdpel positions<br> @@ -221,18 +267,35 @@ qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16]; qpel_mc_func avg_no_rnd_qpel_pixels_tab[2][16]; qpel_mc_func put_mspel_pixels_tab[8]; - + /** * h264 Chram MC */ h264_chroma_mc_func put_h264_chroma_pixels_tab[3]; + /* This is really one func used in VC-1 decoding */ + h264_chroma_mc_func put_no_rnd_h264_chroma_pixels_tab[3]; h264_chroma_mc_func avg_h264_chroma_pixels_tab[3]; - qpel_mc_func put_h264_qpel_pixels_tab[3][16]; - qpel_mc_func avg_h264_qpel_pixels_tab[3][16]; - + qpel_mc_func put_h264_qpel_pixels_tab[4][16]; + qpel_mc_func avg_h264_qpel_pixels_tab[4][16]; + + qpel_mc_func put_2tap_qpel_pixels_tab[4][16]; + qpel_mc_func avg_2tap_qpel_pixels_tab[4][16]; + + h264_weight_func weight_h264_pixels_tab[10]; + h264_biweight_func biweight_h264_pixels_tab[10]; + + /* AVS specific */ + qpel_mc_func put_cavs_qpel_pixels_tab[2][16]; + qpel_mc_func avg_cavs_qpel_pixels_tab[2][16]; + void (*cavs_filter_lv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2); + void (*cavs_filter_lh)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2); + void (*cavs_filter_cv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2); + void (*cavs_filter_ch)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2); + void (*cavs_idct8_add)(uint8_t *dst, DCTELEM *block, int stride); + me_cmp_func pix_abs[2][4]; - + /* huffyuv specific */ void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w); void (*diff_bytes)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 1*/,int w); @@ -242,30 +305,54 @@ */ void (*sub_hfyu_median_prediction)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top); void (*bswap_buf)(uint32_t *dst, uint32_t *src, int w); - + + void (*h264_v_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0); + void (*h264_h_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0); + void (*h264_v_loop_filter_chroma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0); + void (*h264_h_loop_filter_chroma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0); + void (*h264_v_loop_filter_chroma_intra)(uint8_t *pix, int stride, int alpha, int beta); + void (*h264_h_loop_filter_chroma_intra)(uint8_t *pix, int stride, int alpha, int beta); + // h264_loop_filter_strength: simd only. the C version is inlined in h264.c + void (*h264_loop_filter_strength)(int16_t bS[2][4][4], uint8_t nnz[40], int8_t ref[2][40], int16_t mv[2][40][2], + int bidir, int edges, int step, int mask_mv0, int mask_mv1); + void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale); void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale); + void (*h261_loop_filter)(uint8_t *src, int stride); + + /* assume len is a multiple of 4, and arrays are 16-byte aligned */ + void (*vorbis_inverse_coupling)(float *mag, float *ang, int blocksize); + /* assume len is a multiple of 8, and arrays are 16-byte aligned */ + void (*vector_fmul)(float *dst, const float *src, int len); + void (*vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len); + /* assume len is a multiple of 8, and src arrays are 16-byte aligned */ + void (*vector_fmul_add_add)(float *dst, const float *src0, const float *src1, const float *src2, int src3, int len, int step); + + /* C version: convert floats from the range [384.0,386.0] to ints in [-32768,32767] + * simd versions: convert floats from [-32768.0,32767.0] without rescaling and arrays are 16byte aligned */ + void (*float_to_int16)(int16_t *dst, const float *src, int len); + /* (I)DCT */ void (*fdct)(DCTELEM *block/* align 16*/); void (*fdct248)(DCTELEM *block/* align 16*/); - + /* IDCT really*/ void (*idct)(DCTELEM *block/* align 16*/); - + /** * block -> idct -> clip to unsigned 8 bit -> dest. * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...) * @param line_size size in bytes of a horizotal line of dest */ void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); - + /** * block -> idct -> add dest -> clip to unsigned 8 bit -> dest. * @param line_size size in bytes of a horizotal line of dest */ void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); - + /** * idct input permutation. * several optimized IDCTs need a permutated input (relative to the normal order of the reference @@ -284,12 +371,38 @@ #define FF_LIBMPEG2_IDCT_PERM 2 #define FF_SIMPLE_IDCT_PERM 3 #define FF_TRANSPOSE_IDCT_PERM 4 +#define FF_PARTTRANS_IDCT_PERM 5 int (*try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale); void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale); #define BASIS_SHIFT 16 #define RECON_SHIFT 6 + void (*h264_idct_add)(uint8_t *dst, DCTELEM *block, int stride); + void (*h264_idct8_add)(uint8_t *dst, DCTELEM *block, int stride); + void (*h264_idct_dc_add)(uint8_t *dst, DCTELEM *block, int stride); + void (*h264_idct8_dc_add)(uint8_t *dst, DCTELEM *block, int stride); + + /* snow wavelet */ + void (*vertical_compose97i)(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width); + void (*horizontal_compose97i)(DWTELEM *b, int width); + void (*inner_add_yblock)(uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8); + + void (*prefetch)(void *mem, int stride, int h); + + void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); + + /* vc1 functions */ + void (*vc1_inv_trans_8x8)(DCTELEM *b); + void (*vc1_inv_trans_8x4)(DCTELEM *b, int n); + void (*vc1_inv_trans_4x8)(DCTELEM *b, int n); + void (*vc1_inv_trans_4x4)(DCTELEM *b, int n); + void (*vc1_v_overlap)(uint8_t* src, int stride, int rnd); + void (*vc1_h_overlap)(uint8_t* src, int stride, int rnd); + /* put 8x8 block with bicubic interpolation and quarterpel precision + * last argument is actually round value instead of height + */ + op_pixels_func put_vc1_mspel_pixels_tab[16]; } DSPContext; void dsputil_static_init(void); @@ -303,7 +416,7 @@ void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type); -#define BYTE_VEC32(c) ((c)*0x01010101UL) +#define BYTE_VEC32(c) ((c)*0x01010101UL) static inline uint32_t rnd_avg32(uint32_t a, uint32_t b) { @@ -315,6 +428,30 @@ return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1); } +static inline int get_penalty_factor(int lambda, int lambda2, int type){ + switch(type&0xFF){ + default: + case FF_CMP_SAD: + return lambda>>FF_LAMBDA_SHIFT; + case FF_CMP_DCT: + return (3*lambda)>>(FF_LAMBDA_SHIFT+1); + case FF_CMP_W53: + return (4*lambda)>>(FF_LAMBDA_SHIFT); + case FF_CMP_W97: + return (2*lambda)>>(FF_LAMBDA_SHIFT); + case FF_CMP_SATD: + case FF_CMP_DCT264: + return (2*lambda)>>FF_LAMBDA_SHIFT; + case FF_CMP_RD: + case FF_CMP_PSNR: + case FF_CMP_SSE: + case FF_CMP_NSSE: + return lambda2>>FF_LAMBDA_SHIFT; + case FF_CMP_BIT: + return 1; + } +} + /** * Empty mmx state. * this must be called between any dsp function and float/double code. @@ -326,6 +463,12 @@ one or more MultiMedia extension */ int mm_support(void); +#ifdef __GNUC__ + #define DECLARE_ALIGNED_16(t,v) t v __attribute__ ((aligned (16))) +#else + #define DECLARE_ALIGNED_16(t,v) __declspec(align(16)) t v +#endif + #if defined(HAVE_MMX) #undef emms_c @@ -335,11 +478,14 @@ #define MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */ #define MM_SSE 0x0008 /* SSE functions */ #define MM_SSE2 0x0010 /* PIV SSE2 functions */ +#define MM_3DNOWEXT 0x0020 /* AMD 3DNowExt */ +#define MM_SSE3 0x0040 /* Prescott SSE3 functions */ extern int mm_flags; void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size); void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size); +void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size); static inline void emms(void) { @@ -353,7 +499,13 @@ emms();\ } -#define __align8 __attribute__ ((aligned (8))) +#ifdef __GNUC__ + #define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8))) +#else + #define DECLARE_ALIGNED_8(t,v) __declspec(align(8)) t v +#endif + +#define STRIDE_ALIGN 8 void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx); void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx); @@ -361,21 +513,35 @@ #elif defined(ARCH_ARMV4L) /* This is to use 4 bytes read to the IDCT pointers for some 'zero' - line ptimizations */ -#define __align8 __attribute__ ((aligned (4))) + line optimizations */ +#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (4))) +#define STRIDE_ALIGN 4 + +#define MM_IWMMXT 0x0100 /* XScale IWMMXT */ + +extern int mm_flags; void dsputil_init_armv4l(DSPContext* c, AVCodecContext *avctx); #elif defined(HAVE_MLIB) /* SPARC/VIS IDCT needs 8-byte aligned DCT blocks */ -#define __align8 __attribute__ ((aligned (8))) +#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8))) +#define STRIDE_ALIGN 8 void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx); +#elif defined(ARCH_SPARC) + +/* SPARC/VIS IDCT needs 8-byte aligned DCT blocks */ +#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8))) +#define STRIDE_ALIGN 8 +void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx); + #elif defined(ARCH_ALPHA) -#define __align8 __attribute__ ((aligned (8))) +#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8))) +#define STRIDE_ALIGN 8 void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx); @@ -391,25 +557,36 @@ #undef pixel #endif -#define __align8 __attribute__ ((aligned (16))) +#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (16))) +#define STRIDE_ALIGN 16 void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx); #elif defined(HAVE_MMI) -#define __align8 __attribute__ ((aligned (16))) +#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (16))) +#define STRIDE_ALIGN 16 void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx); #elif defined(ARCH_SH4) -#define __align8 __attribute__ ((aligned (8))) +#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8))) +#define STRIDE_ALIGN 8 void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx); +#elif defined(ARCH_BFIN) + +#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8))) +#define STRIDE_ALIGN 8 + +void dsputil_init_bfin(DSPContext* c, AVCodecContext *avctx); + #else -#define __align8 +#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8))) +#define STRIDE_ALIGN 8 #endif @@ -423,6 +600,7 @@ #define LD32(a) (((const struct unaligned_32 *) (a))->l) #define LD64(a) (((const struct unaligned_64 *) (a))->l) +#define ST16(a, b) (((struct unaligned_16 *) (a))->l) = (b) #define ST32(a, b) (((struct unaligned_32 *) (a))->l) = (b) #else /* __GNUC__ */ @@ -431,6 +609,7 @@ #define LD32(a) (*((uint32_t*)(a))) #define LD64(a) (*((uint64_t*)(a))) +#define ST16(a, b) *((uint16_t*)(a)) = (b) #define ST32(a, b) *((uint32_t*)(a)) = (b) #endif /* !__GNUC__ */ @@ -446,6 +625,8 @@ FFTSample type */ typedef float FFTSample; +struct MDCTContext; + typedef struct FFTComplex { FFTSample re, im; } FFTComplex; @@ -457,19 +638,23 @@ FFTComplex *exptab; FFTComplex *exptab1; /* only used by SSE code */ void (*fft_calc)(struct FFTContext *s, FFTComplex *z); + void (*imdct_calc)(struct MDCTContext *s, FFTSample *output, + const FFTSample *input, FFTSample *tmp); } FFTContext; -int fft_inits(FFTContext *s, int nbits, int inverse); -void fft_permute(FFTContext *s, FFTComplex *z); -void fft_calc_c(FFTContext *s, FFTComplex *z); -void fft_calc_sse(FFTContext *s, FFTComplex *z); -void fft_calc_altivec(FFTContext *s, FFTComplex *z); +int ff_fft_init(FFTContext *s, int nbits, int inverse); +void ff_fft_permute(FFTContext *s, FFTComplex *z); +void ff_fft_calc_c(FFTContext *s, FFTComplex *z); +void ff_fft_calc_sse(FFTContext *s, FFTComplex *z); +void ff_fft_calc_3dn(FFTContext *s, FFTComplex *z); +void ff_fft_calc_3dn2(FFTContext *s, FFTComplex *z); +void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z); -static inline void fft_calc(FFTContext *s, FFTComplex *z) +static inline void ff_fft_calc(FFTContext *s, FFTComplex *z) { s->fft_calc(s, z); } -void fft_end(FFTContext *s); +void ff_fft_end(FFTContext *s); /* MDCT computation */ @@ -485,6 +670,10 @@ int ff_mdct_init(MDCTContext *s, int nbits, int inverse); void ff_imdct_calc(MDCTContext *s, FFTSample *output, const FFTSample *input, FFTSample *tmp); +void ff_imdct_calc_3dn2(MDCTContext *s, FFTSample *output, + const FFTSample *input, FFTSample *tmp); +void ff_imdct_calc_sse(MDCTContext *s, FFTSample *output, + const FFTSample *input, FFTSample *tmp); void ff_mdct_calc(MDCTContext *s, FFTSample *out, const FFTSample *input, FFTSample *tmp); void ff_mdct_end(MDCTContext *s);
--- a/src/ffmpeg/libavcodec/parser.c Mon Mar 12 13:11:29 2007 -0700 +++ b/src/ffmpeg/libavcodec/parser.c Mon Mar 12 13:14:40 2007 -0700 @@ -3,23 +3,22 @@ * 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 + * This library 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. + * version 2 of the License, or (at your option) any later version. * - * FFmpeg is distributed in the hope that it will be useful, + * This library 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 + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avcodec.h" +#include "utils.h" AVCodecParser *av_first_parser = NULL; @@ -35,15 +34,10 @@ AVCodecParser *parser; int ret; - if(codec_id == CODEC_ID_NONE) - return NULL; - for(parser = av_first_parser; parser != NULL; parser = parser->next) { if (parser->codec_ids[0] == codec_id || parser->codec_ids[1] == codec_id || - parser->codec_ids[2] == codec_id || - parser->codec_ids[3] == codec_id || - parser->codec_ids[4] == codec_id) + parser->codec_ids[2] == codec_id) goto found; } return NULL; @@ -54,53 +48,31 @@ s->parser = parser; s->priv_data = av_mallocz(parser->priv_data_size); if (!s->priv_data) { - av_free(s); + free(s); return NULL; } if (parser->parser_init) { ret = parser->parser_init(s); if (ret != 0) { - av_free(s->priv_data); - av_free(s); + free(s->priv_data); + free(s); return NULL; } } - s->fetch_timestamp=1; return s; } -/** - * - * @param buf input - * @param buf_size input length, to signal EOF, this should be 0 (so that the last frame can be output) - * @param pts input presentation timestamp - * @param dts input decoding timestamp - * @param poutbuf will contain a pointer to the first byte of the output frame - * @param poutbuf_size will contain the length of the output frame - * @return the number of bytes of the input bitstream used - * - * Example: - * @code - * while(in_len){ - * len = av_parser_parse(myparser, AVCodecContext, &data, &size, - * in_data, in_len, - * pts, dts); - * in_data += len; - * in_len -= len; - * - * decode_frame(data, size); - * } - * @endcode - */ -int av_parser_parse(AVCodecParserContext *s, +/* NOTE: buf_size == 0 is used to signal EOF so that the last frame + can be returned if necessary */ +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 index, i, k; uint8_t dummy_buf[FF_INPUT_BUFFER_PADDING_SIZE]; - + if (buf_size == 0) { /* padding is always necessary even if EOF, so we add it here */ memset(dummy_buf, 0, sizeof(dummy_buf)); @@ -114,25 +86,21 @@ s->cur_frame_dts[k] = dts; /* fill first PTS/DTS */ - if (s->fetch_timestamp){ - s->fetch_timestamp=0; + if (s->cur_offset == 0) { s->last_pts = pts; s->last_dts = dts; - s->cur_frame_pts[k] = - s->cur_frame_dts[k] = AV_NOPTS_VALUE; } } /* WARNING: the returned index can be negative */ index = s->parser->parser_parse(s, avctx, poutbuf, poutbuf_size, buf, buf_size); -//av_log(NULL, AV_LOG_DEBUG, "parser: in:%lld, %lld, out:%lld, %lld, in:%d out:%d id:%d\n", pts, dts, s->last_pts, s->last_dts, buf_size, *poutbuf_size, avctx->codec_id); /* update the file pointer */ if (*poutbuf_size) { /* fill the data for the current frame */ s->frame_offset = s->last_frame_offset; s->pts = s->last_pts; s->dts = s->last_dts; - + /* offset of the next frame */ s->last_frame_offset = s->cur_offset + index; /* find the packet in which the new frame starts. It @@ -147,15 +115,8 @@ break; k = (k - 1) & (AV_PARSER_PTS_NB - 1); } - s->last_pts = s->cur_frame_pts[k]; s->last_dts = s->cur_frame_dts[k]; - - /* some parsers tell us the packet size even before seeing the first byte of the next packet, - so the next pts/dts is in the next chunk */ - if(index == buf_size){ - s->fetch_timestamp=1; - } } if (index < 0) index = 0; @@ -163,943 +124,12 @@ return index; } -/** - * - * @return 0 if the output buffer is a subset of the input, 1 if it is allocated and must be freed - * @deprecated use AVBitstreamFilter - */ -int av_parser_change(AVCodecParserContext *s, - AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size, int keyframe){ - - if(s && s->parser->split){ - if((avctx->flags & CODEC_FLAG_GLOBAL_HEADER) || (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)){ - int i= s->parser->split(avctx, buf, buf_size); - buf += i; - buf_size -= i; - } - } - - /* cast to avoid warning about discarding qualifiers */ - *poutbuf= (uint8_t *) buf; - *poutbuf_size= buf_size; - if(avctx->extradata){ - if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)) - /*||(s->pict_type != I_TYPE && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_NOKEY))*/ - /*||(? && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_BEGIN)*/){ - int size= buf_size + avctx->extradata_size; - *poutbuf_size= size; - *poutbuf= av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); - - memcpy(*poutbuf, avctx->extradata, avctx->extradata_size); - memcpy((*poutbuf) + avctx->extradata_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); - return 1; - } - } - - return 0; -} - void av_parser_close(AVCodecParserContext *s) { - if (s->parser->parser_close) - s->parser->parser_close(s); - av_free(s->priv_data); - av_free(s); -} - -/*****************************************************/ - -//#define END_NOT_FOUND (-100) - -#define PICTURE_START_CODE 0x00000100 -#define SEQ_START_CODE 0x000001b3 -#define EXT_START_CODE 0x000001b5 -#define SLICE_MIN_START_CODE 0x00000101 -#define SLICE_MAX_START_CODE 0x000001af - -typedef struct ParseContext1{ - ParseContext pc; -/* XXX/FIXME PC1 vs. PC */ - /* MPEG2 specific */ - int frame_rate; - int progressive_sequence; - int width, height; - - /* XXX: suppress that, needed by MPEG4 */ - MpegEncContext *enc; - int first_picture; -} ParseContext1; - -/** - * combines the (truncated) bitstream to a complete frame - * @returns -1 if no complete frame could be created - */ -int ff_combine_frame(ParseContext *pc, int next, uint8_t **buf, int *buf_size) -{ -#if 0 - if(pc->overread){ - printf("overread %d, state:%X next:%d index:%d o_index:%d\n", pc->overread, pc->state, next, pc->index, pc->overread_index); - printf("%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]); - } -#endif - - /* copy overreaded bytes from last frame into buffer */ - for(; pc->overread>0; pc->overread--){ - pc->buffer[pc->index++]= pc->buffer[pc->overread_index++]; - } - - /* flush remaining if EOF */ - if(!*buf_size && next == END_NOT_FOUND){ - next= 0; - } - - pc->last_index= pc->index; - - /* copy into buffer end return */ - if(next == END_NOT_FOUND){ - pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, (*buf_size) + pc->index + FF_INPUT_BUFFER_PADDING_SIZE); - - memcpy(&pc->buffer[pc->index], *buf, *buf_size); - pc->index += *buf_size; - return -1; - } - - *buf_size= - pc->overread_index= pc->index + next; - - /* append to buffer */ - if(pc->index){ - pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, next + pc->index + FF_INPUT_BUFFER_PADDING_SIZE); - - memcpy(&pc->buffer[pc->index], *buf, next + FF_INPUT_BUFFER_PADDING_SIZE ); - pc->index = 0; - *buf= pc->buffer; - } - - /* store overread bytes */ - for(;next < 0; next++){ - pc->state = (pc->state<<8) | pc->buffer[pc->last_index + next]; - pc->overread++; - } - -#if 0 - if(pc->overread){ - printf("overread %d, state:%X next:%d index:%d o_index:%d\n", pc->overread, pc->state, next, pc->index, pc->overread_index); - printf("%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]); - } -#endif - - return 0; -} - -/* XXX: merge with libavcodec ? */ -#define MPEG1_FRAME_RATE_BASE 1001 - -static const int frame_rate_tab[16] = { - 0, - 24000, - 24024, - 25025, - 30000, - 30030, - 50050, - 60000, - 60060, - // Xing's 15fps: (9) - 15015, - // libmpeg3's "Unofficial economy rates": (10-13) - 5005, - 10010, - 12012, - 15015, - // random, just to avoid segfault !never encode these - 25025, - 25025, -}; - -#ifdef CONFIG_MPEGVIDEO_PARSER -//FIXME move into mpeg12.c -static void mpegvideo_extract_headers(AVCodecParserContext *s, - AVCodecContext *avctx, - const uint8_t *buf, int buf_size) -{ - ParseContext1 *pc = s->priv_data; - const uint8_t *buf_end; - uint32_t start_code; - int frame_rate_index, ext_type, bytes_left; - int frame_rate_ext_n, frame_rate_ext_d; - int picture_structure, top_field_first, repeat_first_field, progressive_frame; - int horiz_size_ext, vert_size_ext, bit_rate_ext; -//FIXME replace the crap with get_bits() - s->repeat_pict = 0; - buf_end = buf + buf_size; - while (buf < buf_end) { - start_code= -1; - buf= ff_find_start_code(buf, buf_end, &start_code); - bytes_left = buf_end - buf; - switch(start_code) { - case PICTURE_START_CODE: - if (bytes_left >= 2) { - s->pict_type = (buf[1] >> 3) & 7; - } - break; - case SEQ_START_CODE: - if (bytes_left >= 7) { - pc->width = (buf[0] << 4) | (buf[1] >> 4); - pc->height = ((buf[1] & 0x0f) << 8) | buf[2]; - avcodec_set_dimensions(avctx, pc->width, pc->height); - frame_rate_index = buf[3] & 0xf; - pc->frame_rate = avctx->time_base.den = frame_rate_tab[frame_rate_index]; - avctx->time_base.num = MPEG1_FRAME_RATE_BASE; - avctx->bit_rate = ((buf[4]<<10) | (buf[5]<<2) | (buf[6]>>6))*400; - avctx->codec_id = CODEC_ID_MPEG1VIDEO; - avctx->sub_id = 1; - } - break; - case EXT_START_CODE: - if (bytes_left >= 1) { - ext_type = (buf[0] >> 4); - switch(ext_type) { - case 0x1: /* sequence extension */ - if (bytes_left >= 6) { - horiz_size_ext = ((buf[1] & 1) << 1) | (buf[2] >> 7); - vert_size_ext = (buf[2] >> 5) & 3; - bit_rate_ext = ((buf[2] & 0x1F)<<7) | (buf[3]>>1); - frame_rate_ext_n = (buf[5] >> 5) & 3; - frame_rate_ext_d = (buf[5] & 0x1f); - pc->progressive_sequence = buf[1] & (1 << 3); - avctx->has_b_frames= !(buf[5] >> 7); - - pc->width |=(horiz_size_ext << 12); - pc->height |=( vert_size_ext << 12); - avctx->bit_rate += (bit_rate_ext << 18) * 400; - avcodec_set_dimensions(avctx, pc->width, pc->height); - avctx->time_base.den = pc->frame_rate * (frame_rate_ext_n + 1); - avctx->time_base.num = MPEG1_FRAME_RATE_BASE * (frame_rate_ext_d + 1); - avctx->codec_id = CODEC_ID_MPEG2VIDEO; - avctx->sub_id = 2; /* forces MPEG2 */ - } - break; - case 0x8: /* picture coding extension */ - if (bytes_left >= 5) { - picture_structure = buf[2]&3; - top_field_first = buf[3] & (1 << 7); - repeat_first_field = buf[3] & (1 << 1); - progressive_frame = buf[4] & (1 << 7); - - /* check if we must repeat the frame */ - if (repeat_first_field) { - if (pc->progressive_sequence) { - if (top_field_first) - s->repeat_pict = 4; - else - s->repeat_pict = 2; - } else if (progressive_frame) { - s->repeat_pict = 1; - } - } - - /* the packet only represents half a frame - XXX,FIXME maybe find a different solution */ - if(picture_structure != 3) - s->repeat_pict = -1; - } - break; - } - } - break; - case -1: - goto the_end; - default: - /* we stop parsing when we encounter a slice. It ensures - that this function takes a negligible amount of time */ - if (start_code >= SLICE_MIN_START_CODE && - start_code <= SLICE_MAX_START_CODE) - goto the_end; - break; - } - } - the_end: ; -} - -static int mpegvideo_parse(AVCodecParserContext *s, - AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size) -{ - ParseContext1 *pc1 = s->priv_data; - ParseContext *pc= &pc1->pc; - int next; - - if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ - next= buf_size; - }else{ - next= ff_mpeg1_find_frame_end(pc, buf, buf_size); - - if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) { - *poutbuf = NULL; - *poutbuf_size = 0; - return buf_size; - } - - } - /* we have a full frame : we just parse the first few MPEG headers - to have the full timing information. The time take by this - function should be negligible for uncorrupted streams */ - mpegvideo_extract_headers(s, avctx, buf, buf_size); -#if 0 - printf("pict_type=%d frame_rate=%0.3f repeat_pict=%d\n", - s->pict_type, (double)avctx->time_base.den / avctx->time_base.num, s->repeat_pict); -#endif - - *poutbuf = (uint8_t *)buf; - *poutbuf_size = buf_size; - return next; -} - -static int mpegvideo_split(AVCodecContext *avctx, - const uint8_t *buf, int buf_size) -{ - int i; - uint32_t state= -1; - - for(i=0; i<buf_size; i++){ - state= (state<<8) | buf[i]; - if(state != 0x1B3 && state != 0x1B5 && state < 0x200 && state >= 0x100) - return i-3; - } - return 0; -} -#endif /* CONFIG_MPEGVIDEO_PARSER */ - -void ff_parse_close(AVCodecParserContext *s) -{ - ParseContext *pc = s->priv_data; - - av_free(pc->buffer); -} - -static void parse1_close(AVCodecParserContext *s) -{ - ParseContext1 *pc1 = s->priv_data; - - av_free(pc1->pc.buffer); - av_free(pc1->enc); -} - -/*************************/ - -#ifdef CONFIG_MPEG4VIDEO_PARSER -/* used by parser */ -/* XXX: make it use less memory */ -static int av_mpeg4_decode_header(AVCodecParserContext *s1, - AVCodecContext *avctx, - const uint8_t *buf, int buf_size) -{ - ParseContext1 *pc = s1->priv_data; - MpegEncContext *s = pc->enc; - GetBitContext gb1, *gb = &gb1; - int ret; - - s->avctx = avctx; - s->current_picture_ptr = &s->current_picture; - - if (avctx->extradata_size && pc->first_picture){ - init_get_bits(gb, avctx->extradata, avctx->extradata_size*8); - ret = ff_mpeg4_decode_picture_header(s, gb); - } - - init_get_bits(gb, buf, 8 * buf_size); - ret = ff_mpeg4_decode_picture_header(s, gb); - if (s->width) { - avcodec_set_dimensions(avctx, s->width, s->height); - } - s1->pict_type= s->pict_type; - pc->first_picture = 0; - return ret; -} - -static int mpeg4video_parse_init(AVCodecParserContext *s) -{ - ParseContext1 *pc = s->priv_data; - - pc->enc = av_mallocz(sizeof(MpegEncContext)); - if (!pc->enc) - return -1; - pc->first_picture = 1; - return 0; -} - -static int mpeg4video_parse(AVCodecParserContext *s, - AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size) -{ - ParseContext *pc = s->priv_data; - int next; - - if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ - next= buf_size; - }else{ - next= ff_mpeg4_find_frame_end(pc, buf, buf_size); - - if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) { - *poutbuf = NULL; - *poutbuf_size = 0; - return buf_size; - } - } - av_mpeg4_decode_header(s, avctx, buf, buf_size); - - *poutbuf = (uint8_t *)buf; - *poutbuf_size = buf_size; - return next; -} -#endif - -#ifdef CONFIG_CAVSVIDEO_PARSER -static int cavsvideo_parse(AVCodecParserContext *s, - AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size) -{ - ParseContext *pc = s->priv_data; - int next; - - if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ - next= buf_size; - }else{ - next= ff_cavs_find_frame_end(pc, buf, buf_size); - - if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) { - *poutbuf = NULL; - *poutbuf_size = 0; - return buf_size; - } - } - *poutbuf = (uint8_t *)buf; - *poutbuf_size = buf_size; - return next; -} -#endif /* CONFIG_CAVSVIDEO_PARSER */ - -static int mpeg4video_split(AVCodecContext *avctx, - const uint8_t *buf, int buf_size) -{ - int i; - uint32_t state= -1; - - for(i=0; i<buf_size; i++){ - state= (state<<8) | buf[i]; - if(state == 0x1B3 || state == 0x1B6) - return i-3; - } - return 0; -} - -/*************************/ - -#ifdef CONFIG_MPEGAUDIO_PARSER -typedef struct MpegAudioParseContext { - uint8_t inbuf[MPA_MAX_CODED_FRAME_SIZE]; /* input buffer */ - uint8_t *inbuf_ptr; - int frame_size; - int free_format_frame_size; - int free_format_next_header; - uint32_t header; - int header_count; -} MpegAudioParseContext; - -#define MPA_HEADER_SIZE 4 - -/* header + layer + bitrate + freq + lsf/mpeg25 */ -#undef SAME_HEADER_MASK /* mpegaudio.h defines different version */ -#define SAME_HEADER_MASK \ - (0xffe00000 | (3 << 17) | (3 << 10) | (3 << 19)) - -static int mpegaudio_parse_init(AVCodecParserContext *s1) -{ - MpegAudioParseContext *s = s1->priv_data; - s->inbuf_ptr = s->inbuf; - return 0; + if (s->parser->parser_close) + s->parser->parser_close(s); + + free(s->priv_data); + free(s); } -static int mpegaudio_parse(AVCodecParserContext *s1, - AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size) -{ - MpegAudioParseContext *s = s1->priv_data; - int len, ret, sr; - uint32_t header; - const uint8_t *buf_ptr; - - *poutbuf = NULL; - *poutbuf_size = 0; - buf_ptr = buf; - while (buf_size > 0) { - len = s->inbuf_ptr - s->inbuf; - if (s->frame_size == 0) { - /* special case for next header for first frame in free - format case (XXX: find a simpler method) */ - if (s->free_format_next_header != 0) { - s->inbuf[0] = s->free_format_next_header >> 24; - s->inbuf[1] = s->free_format_next_header >> 16; - s->inbuf[2] = s->free_format_next_header >> 8; - s->inbuf[3] = s->free_format_next_header; - s->inbuf_ptr = s->inbuf + 4; - s->free_format_next_header = 0; - goto got_header; - } - /* no header seen : find one. We need at least MPA_HEADER_SIZE - bytes to parse it */ - len = FFMIN(MPA_HEADER_SIZE - len, buf_size); - if (len > 0) { - memcpy(s->inbuf_ptr, buf_ptr, len); - buf_ptr += len; - buf_size -= len; - s->inbuf_ptr += len; - } - if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) { - got_header: - sr= avctx->sample_rate; - header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | - (s->inbuf[2] << 8) | s->inbuf[3]; - - ret = mpa_decode_header(avctx, header); - if (ret < 0) { - s->header_count= -2; - /* no sync found : move by one byte (inefficient, but simple!) */ - memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); - s->inbuf_ptr--; - dprintf("skip %x\n", header); - /* reset free format frame size to give a chance - to get a new bitrate */ - s->free_format_frame_size = 0; - } else { - if((header&SAME_HEADER_MASK) != (s->header&SAME_HEADER_MASK) && s->header) - s->header_count= -3; - s->header= header; - s->header_count++; - s->frame_size = ret; - -#if 0 - /* free format: prepare to compute frame size */ - if (decode_header(s, header) == 1) { - s->frame_size = -1; - } -#endif - } - if(s->header_count <= 0) - avctx->sample_rate= sr; //FIXME ugly - } - } else -#if 0 - if (s->frame_size == -1) { - /* free format : find next sync to compute frame size */ - len = MPA_MAX_CODED_FRAME_SIZE - len; - if (len > buf_size) - len = buf_size; - if (len == 0) { - /* frame too long: resync */ - s->frame_size = 0; - memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); - s->inbuf_ptr--; - } else { - uint8_t *p, *pend; - uint32_t header1; - int padding; - - memcpy(s->inbuf_ptr, buf_ptr, len); - /* check for header */ - p = s->inbuf_ptr - 3; - pend = s->inbuf_ptr + len - 4; - while (p <= pend) { - header = (p[0] << 24) | (p[1] << 16) | - (p[2] << 8) | p[3]; - header1 = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | - (s->inbuf[2] << 8) | s->inbuf[3]; - /* check with high probability that we have a - valid header */ - if ((header & SAME_HEADER_MASK) == - (header1 & SAME_HEADER_MASK)) { - /* header found: update pointers */ - len = (p + 4) - s->inbuf_ptr; - buf_ptr += len; - buf_size -= len; - s->inbuf_ptr = p; - /* compute frame size */ - s->free_format_next_header = header; - s->free_format_frame_size = s->inbuf_ptr - s->inbuf; - padding = (header1 >> 9) & 1; - if (s->layer == 1) - s->free_format_frame_size -= padding * 4; - else - s->free_format_frame_size -= padding; - dprintf("free frame size=%d padding=%d\n", - s->free_format_frame_size, padding); - decode_header(s, header1); - goto next_data; - } - p++; - } - /* not found: simply increase pointers */ - buf_ptr += len; - s->inbuf_ptr += len; - buf_size -= len; - } - } else -#endif - if (len < s->frame_size) { - if (s->frame_size > MPA_MAX_CODED_FRAME_SIZE) - s->frame_size = MPA_MAX_CODED_FRAME_SIZE; - len = FFMIN(s->frame_size - len, buf_size); - memcpy(s->inbuf_ptr, buf_ptr, len); - buf_ptr += len; - s->inbuf_ptr += len; - buf_size -= len; - } - - if(s->frame_size > 0 && buf_ptr - buf == s->inbuf_ptr - s->inbuf - && buf_size + buf_ptr - buf >= s->frame_size){ - if(s->header_count > 0){ - *poutbuf = buf; - *poutbuf_size = s->frame_size; - } - buf_ptr = buf + s->frame_size; - s->inbuf_ptr = s->inbuf; - s->frame_size = 0; - break; - } - - // next_data: - if (s->frame_size > 0 && - (s->inbuf_ptr - s->inbuf) >= s->frame_size) { - if(s->header_count > 0){ - *poutbuf = s->inbuf; - *poutbuf_size = s->inbuf_ptr - s->inbuf; - } - s->inbuf_ptr = s->inbuf; - s->frame_size = 0; - break; - } - } - return buf_ptr - buf; -} -#endif /* CONFIG_MPEGAUDIO_PARSER */ - -#if defined(CONFIG_AC3_PARSER) || defined(CONFIG_AAC_PARSER) -/* also used for ADTS AAC */ -typedef struct AC3ParseContext { - uint8_t *inbuf_ptr; - int frame_size; - int header_size; - int (*sync)(const uint8_t *buf, int *channels, int *sample_rate, - int *bit_rate, int *samples); - uint8_t inbuf[8192]; /* input buffer */ -} AC3ParseContext; - -#define AC3_HEADER_SIZE 7 -#define AAC_HEADER_SIZE 7 - -#ifdef CONFIG_AC3_PARSER -static const int ac3_sample_rates[4] = { - 48000, 44100, 32000, 0 -}; - -static const int ac3_frame_sizes[64][3] = { - { 64, 69, 96 }, - { 64, 70, 96 }, - { 80, 87, 120 }, - { 80, 88, 120 }, - { 96, 104, 144 }, - { 96, 105, 144 }, - { 112, 121, 168 }, - { 112, 122, 168 }, - { 128, 139, 192 }, - { 128, 140, 192 }, - { 160, 174, 240 }, - { 160, 175, 240 }, - { 192, 208, 288 }, - { 192, 209, 288 }, - { 224, 243, 336 }, - { 224, 244, 336 }, - { 256, 278, 384 }, - { 256, 279, 384 }, - { 320, 348, 480 }, - { 320, 349, 480 }, - { 384, 417, 576 }, - { 384, 418, 576 }, - { 448, 487, 672 }, - { 448, 488, 672 }, - { 512, 557, 768 }, - { 512, 558, 768 }, - { 640, 696, 960 }, - { 640, 697, 960 }, - { 768, 835, 1152 }, - { 768, 836, 1152 }, - { 896, 975, 1344 }, - { 896, 976, 1344 }, - { 1024, 1114, 1536 }, - { 1024, 1115, 1536 }, - { 1152, 1253, 1728 }, - { 1152, 1254, 1728 }, - { 1280, 1393, 1920 }, - { 1280, 1394, 1920 }, -}; - -static const int ac3_bitrates[64] = { - 32, 32, 40, 40, 48, 48, 56, 56, 64, 64, 80, 80, 96, 96, 112, 112, - 128, 128, 160, 160, 192, 192, 224, 224, 256, 256, 320, 320, 384, - 384, 448, 448, 512, 512, 576, 576, 640, 640, -}; - -static const int ac3_channels[8] = { - 2, 1, 2, 3, 3, 4, 4, 5 -}; -#endif /* CONFIG_AC3_PARSER */ - -#ifdef CONFIG_AAC_PARSER -static const int aac_sample_rates[16] = { - 96000, 88200, 64000, 48000, 44100, 32000, - 24000, 22050, 16000, 12000, 11025, 8000, 7350 -}; - -static const int aac_channels[8] = { - 0, 1, 2, 3, 4, 5, 6, 8 -}; -#endif - -#ifdef CONFIG_AC3_PARSER -static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate, - int *bit_rate, int *samples) -{ - unsigned int fscod, frmsizecod, acmod, bsid, lfeon; - GetBitContext bits; - - init_get_bits(&bits, buf, AC3_HEADER_SIZE * 8); - - if(get_bits(&bits, 16) != 0x0b77) - return 0; - - skip_bits(&bits, 16); /* crc */ - fscod = get_bits(&bits, 2); - frmsizecod = get_bits(&bits, 6); - - if(!ac3_sample_rates[fscod]) - return 0; - - bsid = get_bits(&bits, 5); - if(bsid > 8) - return 0; - skip_bits(&bits, 3); /* bsmod */ - acmod = get_bits(&bits, 3); - if(acmod & 1 && acmod != 1) - skip_bits(&bits, 2); /* cmixlev */ - if(acmod & 4) - skip_bits(&bits, 2); /* surmixlev */ - if(acmod & 2) - skip_bits(&bits, 2); /* dsurmod */ - lfeon = get_bits1(&bits); - - *sample_rate = ac3_sample_rates[fscod]; - *bit_rate = ac3_bitrates[frmsizecod] * 1000; - *channels = ac3_channels[acmod] + lfeon; - *samples = 6 * 256; - - return ac3_frame_sizes[frmsizecod][fscod] * 2; -} -#endif /* CONFIG_AC3_PARSER */ - -#ifdef CONFIG_AAC_PARSER -static int aac_sync(const uint8_t *buf, int *channels, int *sample_rate, - int *bit_rate, int *samples) -{ - GetBitContext bits; - int size, rdb, ch, sr; - - init_get_bits(&bits, buf, AAC_HEADER_SIZE * 8); - - if(get_bits(&bits, 12) != 0xfff) - return 0; - - skip_bits1(&bits); /* id */ - skip_bits(&bits, 2); /* layer */ - skip_bits1(&bits); /* protection_absent */ - skip_bits(&bits, 2); /* profile_objecttype */ - sr = get_bits(&bits, 4); /* sample_frequency_index */ - if(!aac_sample_rates[sr]) - return 0; - skip_bits1(&bits); /* private_bit */ - ch = get_bits(&bits, 3); /* channel_configuration */ - if(!aac_channels[ch]) - return 0; - skip_bits1(&bits); /* original/copy */ - skip_bits1(&bits); /* home */ - - /* adts_variable_header */ - skip_bits1(&bits); /* copyright_identification_bit */ - skip_bits1(&bits); /* copyright_identification_start */ - size = get_bits(&bits, 13); /* aac_frame_length */ - skip_bits(&bits, 11); /* adts_buffer_fullness */ - rdb = get_bits(&bits, 2); /* number_of_raw_data_blocks_in_frame */ - - *channels = aac_channels[ch]; - *sample_rate = aac_sample_rates[sr]; - *samples = (rdb + 1) * 1024; - *bit_rate = size * 8 * *sample_rate / *samples; - - return size; -} -#endif /* CONFIG_AAC_PARSER */ - -#ifdef CONFIG_AC3_PARSER -static int ac3_parse_init(AVCodecParserContext *s1) -{ - AC3ParseContext *s = s1->priv_data; - s->inbuf_ptr = s->inbuf; - s->header_size = AC3_HEADER_SIZE; - s->sync = ac3_sync; - return 0; -} -#endif - -#ifdef CONFIG_AAC_PARSER -static int aac_parse_init(AVCodecParserContext *s1) -{ - AC3ParseContext *s = s1->priv_data; - s->inbuf_ptr = s->inbuf; - s->header_size = AAC_HEADER_SIZE; - s->sync = aac_sync; - return 0; -} -#endif - -/* also used for ADTS AAC */ -static int ac3_parse(AVCodecParserContext *s1, - AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size) -{ - AC3ParseContext *s = s1->priv_data; - const uint8_t *buf_ptr; - int len, sample_rate, bit_rate, channels, samples; - - *poutbuf = NULL; - *poutbuf_size = 0; - - buf_ptr = buf; - while (buf_size > 0) { - len = s->inbuf_ptr - s->inbuf; - if (s->frame_size == 0) { - /* no header seen : find one. We need at least s->header_size - bytes to parse it */ - len = FFMIN(s->header_size - len, buf_size); - - memcpy(s->inbuf_ptr, buf_ptr, len); - buf_ptr += len; - s->inbuf_ptr += len; - buf_size -= len; - if ((s->inbuf_ptr - s->inbuf) == s->header_size) { - len = s->sync(s->inbuf, &channels, &sample_rate, &bit_rate, - &samples); - if (len == 0) { - /* no sync found : move by one byte (inefficient, but simple!) */ - memmove(s->inbuf, s->inbuf + 1, s->header_size - 1); - s->inbuf_ptr--; - } else { - s->frame_size = len; - /* update codec info */ - avctx->sample_rate = sample_rate; - /* set channels,except if the user explicitly requests 1 or 2 channels, XXX/FIXME this is a bit ugly */ - if(avctx->codec_id == CODEC_ID_AC3){ - if(avctx->channels!=1 && avctx->channels!=2){ - avctx->channels = channels; - } - } else { - avctx->channels = channels; - } - avctx->bit_rate = bit_rate; - avctx->frame_size = samples; - } - } - } else { - len = FFMIN(s->frame_size - len, buf_size); - - memcpy(s->inbuf_ptr, buf_ptr, len); - buf_ptr += len; - s->inbuf_ptr += len; - buf_size -= len; - - if(s->inbuf_ptr - s->inbuf == s->frame_size){ - *poutbuf = s->inbuf; - *poutbuf_size = s->frame_size; - s->inbuf_ptr = s->inbuf; - s->frame_size = 0; - break; - } - } - } - return buf_ptr - buf; -} -#endif /* CONFIG_AC3_PARSER || CONFIG_AAC_PARSER */ - -#ifdef CONFIG_MPEGVIDEO_PARSER -AVCodecParser mpegvideo_parser = { - { CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO }, - sizeof(ParseContext1), - NULL, - mpegvideo_parse, - parse1_close, - mpegvideo_split, -}; -#endif -#ifdef CONFIG_MPEG4VIDEO_PARSER -AVCodecParser mpeg4video_parser = { - { CODEC_ID_MPEG4 }, - sizeof(ParseContext1), - mpeg4video_parse_init, - mpeg4video_parse, - parse1_close, - mpeg4video_split, -}; -#endif -#ifdef CONFIG_CAVSVIDEO_PARSER -AVCodecParser cavsvideo_parser = { - { CODEC_ID_CAVS }, - sizeof(ParseContext1), - NULL, - cavsvideo_parse, - parse1_close, - mpeg4video_split, -}; -#endif -#ifdef CONFIG_MPEGAUDIO_PARSER -AVCodecParser mpegaudio_parser = { - { CODEC_ID_MP2, CODEC_ID_MP3 }, - sizeof(MpegAudioParseContext), - mpegaudio_parse_init, - mpegaudio_parse, - NULL, -}; -#endif -#ifdef CONFIG_AC3_PARSER -AVCodecParser ac3_parser = { - { CODEC_ID_AC3 }, - sizeof(AC3ParseContext), - ac3_parse_init, - ac3_parse, - NULL, -}; -#endif -#ifdef CONFIG_AAC_PARSER -AVCodecParser aac_parser = { - { CODEC_ID_AAC }, - sizeof(AC3ParseContext), - aac_parse_init, - ac3_parse, - NULL, -}; -#endif