Update of /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25800/libavcodec Modified Files: Makefile.am avcodec.h cabac.c common.h dsputil.c dsputil.h dv.c dvdata.h error_resilience.c h263.c h263dec.c h264.c h264data.h imgresample.c mjpeg.c motion_est.c motion_est_template.c mpeg12.c mpegaudiodec.c mpegvideo.c mpegvideo.h msmpeg4.c rv10.c smc.c svq1.c truemotion1.c utils.c vmdav.c vp3.c wmadec.c wmv2.c Log Message: ffmpeg sync Index: Makefile.am =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/Makefile.am,v retrieving revision 1.55 retrieving revision 1.56 diff -u -r1.55 -r1.56 --- Makefile.am 17 Mar 2004 20:24:16 -0000 1.55 +++ Makefile.am 25 Apr 2004 18:58:17 -0000 1.56 @@ -1,6 +1,6 @@ include $(top_srcdir)/misc/Makefile.common -SUBDIRS = armv4l i386 mlib alpha ppc libpostproc +SUBDIRS = armv4l i386 mlib alpha ppc sparc libpostproc ## some files here are #included by others... go figure. EXTRA_DIST = fdctref.c motion_est_template.c svq3.c wmv2.c \ @@ -80,6 +80,7 @@ $(top_builddir)/src/libffmpeg/libavcodec/i386/libavcodec_mmx.la \ $(top_builddir)/src/libffmpeg/libavcodec/mlib/libavcodec_mlib.la \ $(top_builddir)/src/libffmpeg/libavcodec/ppc/libavcodec_ppc.la \ + $(top_builddir)/src/libffmpeg/libavcodec/sparc/libavcodec_sparc.la \ -avoid-version -module Index: avcodec.h =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/avcodec.h,v retrieving revision 1.32 retrieving revision 1.33 diff -u -r1.32 -r1.33 --- avcodec.h 14 Mar 2004 21:14:08 -0000 1.32 +++ avcodec.h 25 Apr 2004 18:58:17 -0000 1.33 @@ -24,7 +24,7 @@ #define FFMPEG_VERSION_INT 0x000408 #define FFMPEG_VERSION "0.4.8" -#define LIBAVCODEC_BUILD 4707 +#define LIBAVCODEC_BUILD 4710 #define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT #define LIBAVCODEC_VERSION FFMPEG_VERSION @@ -449,7 +449,7 @@ \ /**\ * Motion vector table\ - * - encoding: unused\ + * - encoding: set by user\ * - decoding: set by lavc\ */\ int16_t (*motion_val[2])[2];\ @@ -457,7 +457,7 @@ /**\ * Macroblock type table\ * mb_type_base + mb_width + 2\ - * - encoding: unused\ + * - encoding: set by user\ * - decoding: set by lavc\ */\ uint32_t *mb_type;\ @@ -545,13 +545,20 @@ * - decoding: set by lavc\ */\ short *dct_coeff;\ +\ + /**\ + * Motion referece frame index\ + * - encoding: set by user\ + * - decoding: set by lavc\ + */\ + int8_t *ref_index[2]; #define FF_QSCALE_TYPE_MPEG1 0 #define FF_QSCALE_TYPE_MPEG2 1 #define FF_BUFFER_TYPE_INTERNAL 1 #define FF_BUFFER_TYPE_USER 2 ///< Direct rendering buffers (image is (de)allocated by user) -#define FF_BUFFER_TYPE_SHARED 4 ///< buffer from somewher else, dont dealloc image (data/base) +#define FF_BUFFER_TYPE_SHARED 4 ///< buffer from somewher else, dont dealloc image (data/base), all other tables are not shared #define FF_BUFFER_TYPE_COPY 8 ///< just a (modified) copy of some other buffer, dont dealloc anything @@ -847,6 +854,7 @@ #define FF_BUG_QPEL_CHROMA2 256 #define FF_BUG_DIRECT_BLOCKSIZE 512 #define FF_BUG_EDGE 1024 +#define FF_BUG_HPEL_CHROMA 2048 //#define FF_BUG_FAKE_SCALABILITY 16 //autodetection should work 100% /** @@ -1567,6 +1575,22 @@ * - decoding: set by execute() */ void *thread_opaque; + + /** + * Motion estimation threshold. under which no motion estimation is + * performed, but instead the user specified motion vectors are used + * + * - encoding: set by user + * - decoding: unused + */ + int me_threshold; + + /** + * Macroblock threshold. under which the user specified macroblock types will be used + * - encoding: set by user + * - decoding: unused + */ + int mb_threshold; } AVCodecContext; @@ -1676,6 +1700,7 @@ extern AVCodec flv_encoder; extern AVCodec rv10_encoder; extern AVCodec rv20_encoder; +extern AVCodec dvvideo_encoder; extern AVCodec mjpeg_encoder; extern AVCodec ljpeg_encoder; extern AVCodec mpeg4_encoder; @@ -1826,7 +1851,10 @@ ImgReSampleContext *img_resample_full_init(int owidth, int oheight, int iwidth, int iheight, int topBand, int bottomBand, - int leftBand, int rightBand); + int leftBand, int rightBand, + int padtop, int padbottom, + int padleft, int padright); + void img_resample(ImgReSampleContext *s, AVPicture *output, const AVPicture *input); @@ -1901,6 +1929,7 @@ void avcodec_get_context_defaults(AVCodecContext *s); AVCodecContext *avcodec_alloc_context(void); +void avcodec_get_frame_defaults(AVFrame *pic); AVFrame *avcodec_alloc_frame(void); int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic); @@ -2102,8 +2131,7 @@ /* for static data only */ /* call av_free_static to release all staticaly allocated tables */ void av_free_static(void); -void *__av_mallocz_static(void** location, unsigned int size); -#define av_mallocz_static(p, s) __av_mallocz_static((void **)(p), s) +void *av_mallocz_static(unsigned int size); /* add by bero : in adx.c */ int is_adx(const unsigned char *buf,size_t bufsize); @@ -2115,6 +2143,7 @@ #include <stdarg.h> +#define AV_LOG_QUIET -1 #define AV_LOG_ERROR 0 #define AV_LOG_INFO 1 #define AV_LOG_DEBUG 2 Index: cabac.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/cabac.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- cabac.c 27 Oct 2003 15:24:38 -0000 1.1 +++ cabac.c 25 Apr 2004 18:58:30 -0000 1.2 @@ -113,7 +113,7 @@ c->mps_state[2*i+0]= 2*mps_state[i]; c->mps_state[2*i+1]= 2*mps_state[i]+1; - if(lps_state[i]){ + if( i ){ c->lps_state[2*i+0]= 2*lps_state[i]; c->lps_state[2*i+1]= 2*lps_state[i]+1; }else{ Index: common.h =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/common.h,v retrieving revision 1.35 retrieving revision 1.36 diff -u -r1.35 -r1.36 --- common.h 17 Mar 2004 20:24:16 -0000 1.35 +++ common.h 25 Apr 2004 18:58:30 -0000 1.36 @@ -6,6 +6,11 @@ #ifndef COMMON_H #define COMMON_H +// xine: disable DEBUG for ffmpeg (too noisy) +#ifdef DEBUG +#undef DEBUG +#endif + #if defined(WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) # define CONFIG_WIN32 #endif @@ -131,7 +136,7 @@ /* windows */ -# ifndef __MINGW32__ +# if !defined(__MINGW32__) && !defined(__CYGWIN__) # define int64_t_C(c) (c ## i64) # define uint64_t_C(c) (c ## i64) @@ -204,40 +209,30 @@ /* debug stuff */ -# ifndef DEBUG -# ifndef NDEBUG +# if !defined(DEBUG) && !defined(NDEBUG) # define NDEBUG -# endif # endif # include <assert.h> /* dprintf macros */ -# if defined(CONFIG_WIN32) && !defined(__MINGW32__) +# if defined(CONFIG_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) inline void dprintf(const char* fmt,...) {} # else -#if __GNUC__ -#ifdef DEBUG -#define dprintf(fmt,args...) printf(fmt, ## args) -#else -#define dprintf(fmt,args...) -#endif -#else -#ifdef DEBUG -#define dprintf(...) printf(__VA_ARGS__) -#else -#define dprintf(...) -#endif -#endif +# ifdef DEBUG +# define dprintf(fmt,...) av_log(NULL, AV_LOG_DEBUG, fmt, __VA_ARGS__) +# else +# define dprintf(fmt,...) +# endif # endif /* !CONFIG_WIN32 */ # define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0) //rounded divison & shift -#define RSHIFT(a,b) ((a) > 0 ? ((a) + (1<<((b)-1)))>>(b) : ((a) + (1<<((b)-1))-1)>>(b)) +#define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b)) /* assume b>0 */ #define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b)) #define ABS(a) ((a) >= 0 ? (a) : (-(a))) @@ -291,6 +286,7 @@ typedef void (*WriteDataFunc)(void *, uint8_t *, int); +/* buf and buf_end must be present and used by every alternative writer. */ typedef struct PutBitContext { #ifdef ALT_BITSTREAM_WRITER uint8_t *buf, *buf_end; @@ -327,11 +323,6 @@ #endif } -static inline int put_bits_left(PutBitContext* s) -{ - return (s->buf_end - s->buf) * 8 - put_bits_count(s); -} - /* pad the end of the output stream with zeros */ static inline void flush_put_bits(PutBitContext *s) { @@ -354,7 +345,7 @@ void put_string(PutBitContext * pbc, char *s, int put_zero); /* bit input */ - +/* buffer, buffer_end and size_in_bits must be present and used by every reader */ typedef struct GetBitContext { const uint8_t *buffer, *buffer_end; #ifdef ALT_BITSTREAM_READER @@ -386,7 +377,7 @@ uint8_t run; } RL_VLC_ELEM; -#ifdef ARCH_SPARC64 +#ifdef ARCH_SPARC #define UNALIGNED_STORES_ARE_BAD #endif @@ -437,7 +428,7 @@ bit_buf<<=bit_left; bit_buf |= value >> (n - bit_left); #ifdef UNALIGNED_STORES_ARE_BAD - if (3 & (int) s->buf_ptr) { + if (3 & (intptr_t) s->buf_ptr) { s->buf_ptr[0] = bit_buf >> 24; s->buf_ptr[1] = bit_buf >> 16; s->buf_ptr[2] = bit_buf >> 8; @@ -924,11 +915,6 @@ #endif } -static inline int get_bits_left(GetBitContext *s) -{ - return s->size_in_bits - get_bits_count(s); -} - int check_marker(GetBitContext *s, const char *msg); void align_get_bits(GetBitContext *s); int init_vlc(VLC *vlc, int nb_bits, int nb_codes, @@ -1080,7 +1066,7 @@ #define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__) #define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__) -#define tprintf printf +#define tprintf(...) av_log(NULL, AV_LOG_DEBUG, __VA_ARGS__) #else //TRACE #define tprintf(...) {} @@ -1182,6 +1168,12 @@ return a; } +static inline int clip_uint8(int a) +{ + if (a&(~255)) return (-a)>>31; + else return a; +} + /* math */ extern const uint8_t ff_sqrt_tab[128]; @@ -1290,6 +1282,9 @@ #define malloc please_use_av_malloc #define free please_use_av_free #define realloc please_use_av_realloc +#define time time_is_forbidden_due_to_security_issues +#define rand rand_is_forbidden_due_to_state_trashing +#define srand srand_is_forbidden_due_to_state_trashing #if !(defined(LIBAVFORMAT_BUILD) || defined(_FRAMEHOOK_H)) #define printf please_use_av_log #define fprintf please_use_av_log Index: dsputil.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/dsputil.c,v retrieving revision 1.34 retrieving revision 1.35 diff -u -r1.34 -r1.35 --- dsputil.c 14 Mar 2004 21:14:08 -0000 1.34 +++ dsputil.c 25 Apr 2004 18:58:31 -0000 1.35 @@ -3286,6 +3286,9 @@ #ifdef HAVE_MLIB dsputil_init_mlib(c, avctx); #endif +#ifdef ARCH_SPARC + dsputil_init_vis(c,avctx); +#endif #ifdef ARCH_ALPHA dsputil_init_alpha(c, avctx); #endif Index: dsputil.h =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/dsputil.h,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- dsputil.h 14 Mar 2004 21:14:08 -0000 1.27 +++ dsputil.h 25 Apr 2004 18:58:36 -0000 1.28 @@ -76,6 +76,12 @@ void vp3_idct_add_mmx(int16_t *input_data, int16_t *dequant_matrix, int coeff_count, uint8_t *dest, int stride); +void vp3_dsp_init_sse2(void); +void vp3_idct_put_sse2(int16_t *input_data, int16_t *dequant_matrix, + int coeff_count, uint8_t *dest, int stride); +void vp3_idct_add_sse2(int16_t *input_data, int16_t *dequant_matrix, + int coeff_count, uint8_t *dest, int stride); + /* minimum alignment rules ;) if u notice errors in the align stuff, need more alignment for some asm code for some cpu @@ -378,6 +384,8 @@ one or more MultiMedia extension */ int mm_support(void); +#define __align16 __attribute__ ((aligned (16))) + #if defined(HAVE_MMX) #undef emms_c @@ -413,7 +421,7 @@ #elif defined(ARCH_ARMV4L) /* This is to use 4 bytes read to the IDCT pointers for some 'zero' - line ptimizations */ + line optimizations */ #define __align8 __attribute__ ((aligned (4))) void dsputil_init_armv4l(DSPContext* c, AVCodecContext *avctx); @@ -425,6 +433,12 @@ void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx); +#elif defined(ARCH_SPARC) + +/* SPARC/VIS IDCT needs 8-byte aligned DCT blocks */ +#define __align8 __attribute__ ((aligned (8))) +void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx); + #elif defined(ARCH_ALPHA) #define __align8 __attribute__ ((aligned (8))) Index: dv.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/dv.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- dv.c 14 Mar 2004 21:14:08 -0000 1.13 +++ dv.c 25 Apr 2004 18:58:37 -0000 1.14 @@ -1,6 +1,7 @@ /* * DV decoder * Copyright (c) 2002 Fabrice Bellard. + * Copyright (c) 2004 Roman Shaposhnik. * * DV encoder * Copyright (c) 2003 Roman Shaposhnik. @@ -33,20 +34,18 @@ #include "simple_idct.h" #include "dvdata.h" -typedef struct DVVideoDecodeContext { +typedef struct DVVideoContext { const DVprofile* sys; AVFrame picture; + uint8_t *buf; uint8_t dv_zigzag[2][64]; - uint8_t dv_idct_shift[2][22][64]; + uint8_t dv_idct_shift[2][2][22][64]; void (*get_pixels)(DCTELEM *block, const uint8_t *pixels, int line_size); void (*fdct[2])(DCTELEM *block); void (*idct_put[2])(uint8_t *dest, int line_size, DCTELEM *block); - - GetBitContext gb; - DCTELEM block[5*6][64] __align8; -} DVVideoDecodeContext; +} DVVideoContext; #define TEX_VLC_BITS 9 @@ -58,15 +57,18 @@ #define DV_VLC_MAP_LEV_SIZE 512 #endif +/* MultiThreading */ +static uint8_t** dv_anchor; + /* XXX: also include quantization */ -static RL_VLC_ELEM *dv_rl_vlc[1]; +static RL_VLC_ELEM *dv_rl_vlc; /* VLC encoding lookup table */ static struct dv_vlc_pair { uint32_t vlc; uint8_t size; } (*dv_vlc_map)[DV_VLC_MAP_LEV_SIZE] = NULL; -static void dv_build_unquantize_tables(DVVideoDecodeContext *s, uint8_t* perm) +static void dv_build_unquantize_tables(DVVideoContext *s, uint8_t* perm) { int i, q, j; @@ -76,29 +78,34 @@ for(i = 1; i < 64; i++) { /* 88 table */ j = perm[i]; - s->dv_idct_shift[0][q][j] = + s->dv_idct_shift[0][0][q][j] = dv_quant_shifts[q][dv_88_areas[i]] + 1; + s->dv_idct_shift[1][0][q][j] = s->dv_idct_shift[0][0][q][j] + 1; } /* 248DCT */ for(i = 1; i < 64; i++) { /* 248 table */ - s->dv_idct_shift[1][q][i] = + s->dv_idct_shift[0][1][q][i] = dv_quant_shifts[q][dv_248_areas[i]] + 1; + s->dv_idct_shift[1][1][q][i] = s->dv_idct_shift[0][1][q][i] + 1; } } } static int dvvideo_init(AVCodecContext *avctx) { - DVVideoDecodeContext *s = avctx->priv_data; + DVVideoContext *s = avctx->priv_data; DSPContext dsp; static int done=0; int i, j; if (!done) { - int i; VLC dv_vlc; + uint16_t new_dv_vlc_bits[NB_DV_VLC*2]; + uint8_t new_dv_vlc_len[NB_DV_VLC*2]; + uint8_t new_dv_vlc_run[NB_DV_VLC*2]; + int16_t new_dv_vlc_level[NB_DV_VLC*2]; done = 1; @@ -106,13 +113,42 @@ if (!dv_vlc_map) return -ENOMEM; + /* dv_anchor lets each thread know its Id */ + dv_anchor = av_malloc(12*27*sizeof(void*)); + if (!dv_anchor) { + av_free(dv_vlc_map); + return -ENOMEM; + } + for (i=0; i<12*27; i++) + dv_anchor[i] = (void*)(size_t)i; + + /* it's faster to include sign bit in a generic VLC parsing scheme */ + for (i=0, j=0; i<NB_DV_VLC; i++, j++) { + new_dv_vlc_bits[j] = dv_vlc_bits[i]; + new_dv_vlc_len[j] = dv_vlc_len[i]; + new_dv_vlc_run[j] = dv_vlc_run[i]; + new_dv_vlc_level[j] = dv_vlc_level[i]; + + if (dv_vlc_level[i]) { + new_dv_vlc_bits[j] <<= 1; + new_dv_vlc_len[j]++; + + j++; + new_dv_vlc_bits[j] = (dv_vlc_bits[i] << 1) | 1; + new_dv_vlc_len[j] = dv_vlc_len[i] + 1; + new_dv_vlc_run[j] = dv_vlc_run[i]; + new_dv_vlc_level[j] = -dv_vlc_level[i]; + } + } + /* NOTE: as a trick, we use the fact the no codes are unused to accelerate the parsing of partial codes */ - init_vlc(&dv_vlc, TEX_VLC_BITS, NB_DV_VLC, - dv_vlc_len, 1, 1, dv_vlc_bits, 2, 2); + init_vlc(&dv_vlc, TEX_VLC_BITS, j, + new_dv_vlc_len, 1, 1, new_dv_vlc_bits, 2, 2); - dv_rl_vlc[0] = av_malloc(dv_vlc.table_size * sizeof(RL_VLC_ELEM)); - if (!dv_rl_vlc[0]) { + dv_rl_vlc = av_malloc(dv_vlc.table_size * sizeof(RL_VLC_ELEM)); + if (!dv_rl_vlc) { + av_free(dv_anchor); av_free(dv_vlc_map); return -ENOMEM; } @@ -124,18 +160,15 @@ if(len<0){ //more bits needed run= 0; level= code; - } else if (code == (NB_DV_VLC - 1)) { - /* EOB */ - run = 0; - level = 256; } else { - run= dv_vlc_run[code] + 1; - level= dv_vlc_level[code]; + run= new_dv_vlc_run[code] + 1; + level= new_dv_vlc_level[code]; } - dv_rl_vlc[0][i].len = len; - dv_rl_vlc[0][i].level = level; - dv_rl_vlc[0][i].run = run; + dv_rl_vlc[i].len = len; + dv_rl_vlc[i].level = level; + dv_rl_vlc[i].run = run; } + free_vlc(&dv_vlc); for (i = 0; i < NB_DV_VLC - 1; i++) { if (dv_vlc_run[i] >= DV_VLC_MAP_RUN_SIZE || dv_vlc_level[i] >= DV_VLC_MAP_LEV_SIZE) @@ -202,13 +235,19 @@ return 0; } +static int dvvideo_end(AVCodecContext *avctx) +{ + avcodec_default_free_buffers(avctx); + return 0; +} + // #define VLC_DEBUG +// #define printf(...) av_log(NULL, AV_LOG_ERROR, __VA_ARGS__) typedef struct BlockInfo { const uint8_t *shift_table; const uint8_t *scan_table; uint8_t pos; /* position in block */ - uint8_t eob_reached; /* true if EOB has been reached */ uint8_t dct_mode; uint8_t partial_bit_count; uint16_t partial_bit_buffer; @@ -228,141 +267,88 @@ #warning only works with ALT_BITSTREAM_READER #endif +static inline int get_bits_left(GetBitContext *s) +{ + return s->size_in_bits - get_bits_count(s); +} + +static inline int get_bits_size(GetBitContext *s) +{ + return s->size_in_bits; +} + +static inline int put_bits_left(PutBitContext* s) +{ + return (s->buf_end - s->buf) * 8 - put_bits_count(s); +} + /* decode ac coefs */ -static void dv_decode_ac(DVVideoDecodeContext *s, - BlockInfo *mb, DCTELEM *block, int last_index) +static void dv_decode_ac(GetBitContext *gb, BlockInfo *mb, DCTELEM *block) { - int last_re_index; - int shift_offset = mb->shift_offset; + int last_index = get_bits_size(gb); const uint8_t *scan_table = mb->scan_table; const uint8_t *shift_table = mb->shift_table; int pos = mb->pos; - int level, pos1, sign, run; - int partial_bit_count; -#ifndef ALT_BITSTREAM_READER //FIXME - int re_index=0; - int re1_index=0; -#endif - OPEN_READER(re, &s->gb); + int partial_bit_count = mb->partial_bit_count; + int level, pos1, run, vlc_len, index; + + OPEN_READER(re, gb); + UPDATE_CACHE(re, gb); -#ifdef VLC_DEBUG - printf("start\n"); -#endif - /* if we must parse a partial vlc, we do it here */ - partial_bit_count = mb->partial_bit_count; if (partial_bit_count > 0) { - uint8_t buf[4]; - uint32_t v; - int l, l1; - GetBitContext gb1; - - /* build the dummy bit buffer */ - l = 16 - partial_bit_count; - UPDATE_CACHE(re, &s->gb); -#ifdef VLC_DEBUG - printf("show=%04x\n", SHOW_UBITS(re, &s->gb, 16)); -#endif - v = (mb->partial_bit_buffer << l) | SHOW_UBITS(re, &s->gb, l); - buf[0] = v >> 8; - buf[1] = v; -#ifdef VLC_DEBUG - printf("v=%04x cnt=%d %04x\n", - v, partial_bit_count, (mb->partial_bit_buffer << l)); -#endif - /* try to read the codeword */ - init_get_bits(&gb1, buf, 4*8); - { - OPEN_READER(re1, &gb1); - UPDATE_CACHE(re1, &gb1); - GET_RL_VLC(level, run, re1, &gb1, dv_rl_vlc[0], - TEX_VLC_BITS, 2); - l = re1_index; - CLOSE_READER(re1, &gb1); - } -#ifdef VLC_DEBUG - printf("****run=%d level=%d size=%d\n", run, level, l); -#endif - /* compute codeword length */ - l1 = (level != 256 && level != 0); - /* if too long, we cannot parse */ - l -= partial_bit_count; - if ((re_index + l + l1) > last_index) - return; - /* skip read bits */ - last_re_index = 0; /* avoid warning */ - re_index += l; - /* by definition, if we can read the vlc, all partial bits - will be read (otherwise we could have read the vlc before) */ - mb->partial_bit_count = 0; - UPDATE_CACHE(re, &s->gb); - goto handle_vlc; + re_cache = ((unsigned)re_cache >> partial_bit_count) | + (mb->partial_bit_buffer << (sizeof(re_cache)*8 - partial_bit_count)); + re_index -= partial_bit_count; + mb->partial_bit_count = 0; } /* get the AC coefficients until last_index is reached */ for(;;) { - UPDATE_CACHE(re, &s->gb); #ifdef VLC_DEBUG - printf("%2d: bits=%04x index=%d\n", - pos, SHOW_UBITS(re, &s->gb, 16), re_index); + printf("%2d: bits=%04x index=%d\n", pos, SHOW_UBITS(re, gb, 16), re_index); #endif - last_re_index = re_index; - GET_RL_VLC(level, run, re, &s->gb, dv_rl_vlc[0], - TEX_VLC_BITS, 2); - handle_vlc: + /* our own optimized GET_RL_VLC */ + index = NEG_USR32(re_cache, TEX_VLC_BITS); + vlc_len = dv_rl_vlc[index].len; + if (vlc_len < 0) { + index = NEG_USR32((unsigned)re_cache << TEX_VLC_BITS, -vlc_len) + dv_rl_vlc[index].level; + vlc_len = TEX_VLC_BITS - vlc_len; + } + level = dv_rl_vlc[index].level; + run = dv_rl_vlc[index].run; + + /* gotta check if we're still within gb boundaries */ + if (re_index + vlc_len > last_index) { + /* should be < 16 bits otherwise a codeword could have been parsed */ + mb->partial_bit_count = last_index - re_index; + mb->partial_bit_buffer = NEG_USR32(re_cache, mb->partial_bit_count); + re_index = last_index; + break; + } + re_index += vlc_len; + #ifdef VLC_DEBUG - printf("run=%d level=%d\n", run, level); + printf("run=%d level=%d\n", run, level); #endif - if (level == 256) { - if (re_index > last_index) { - cannot_read: - /* put position before read code */ - re_index = last_re_index; - mb->eob_reached = 0; - break; - } - /* EOB */ - mb->eob_reached = 1; - break; - } else if (level != 0) { - if ((re_index + 1) > last_index) - goto cannot_read; - sign = SHOW_SBITS(re, &s->gb, 1); - level = (level ^ sign) - sign; - LAST_SKIP_BITS(re, &s->gb, 1); - pos += run; - /* error */ - if (pos >= 64) { - goto read_error; - } + pos += run; + if (pos >= 64) + break; + + if (level) { pos1 = scan_table[pos]; - level = level << (shift_table[pos1] + shift_offset); - block[pos1] = level; - // printf("run=%d level=%d shift=%d\n", run, level, shift_table[pos1]); - } else { - if (re_index > last_index) - goto cannot_read; - /* level is zero: means run without coding. No - sign is coded */ - pos += run; - /* error */ - if (pos >= 64) { - read_error: -#if defined(VLC_DEBUG) || 1 - av_log(NULL, AV_LOG_ERROR, "error pos=%d\n", pos); -#endif - /* for errors, we consider the eob is reached */ - mb->eob_reached = 1; - break; - } - } + block[pos1] = level << shift_table[pos1]; + } + + UPDATE_CACHE(re, gb); } - CLOSE_READER(re, &s->gb); + CLOSE_READER(re, gb); mb->pos = pos; } -static inline void bit_copy(PutBitContext *pb, GetBitContext *gb, int bits_left) +static inline void bit_copy(PutBitContext *pb, GetBitContext *gb) { + int bits_left = get_bits_left(gb); while (bits_left >= 16) { put_bits(pb, 16, get_bits(gb, 16)); bits_left -= 16; @@ -373,60 +359,56 @@ } /* mb_x and mb_y are in units of 8 pixels */ -static inline void dv_decode_video_segment(DVVideoDecodeContext *s, +static inline void dv_decode_video_segment(DVVideoContext *s, uint8_t *buf_ptr1, const uint16_t *mb_pos_ptr) { int quant, dc, dct_mode, class1, j; int mb_index, mb_x, mb_y, v, last_index; DCTELEM *block, *block1; - int c_offset, bits_left; + int c_offset; uint8_t *y_ptr; - BlockInfo mb_data[5 * 6], *mb, *mb1; void (*idct_put)(uint8_t *dest, int line_size, DCTELEM *block); uint8_t *buf_ptr; PutBitContext pb, vs_pb; + GetBitContext gb; + BlockInfo mb_data[5 * 6], *mb, *mb1; + DCTELEM sblock[5*6][64] __align8; uint8_t mb_bit_buffer[80 + 4]; /* allow some slack */ - int mb_bit_count; uint8_t vs_bit_buffer[5 * 80 + 4]; /* allow some slack */ - int vs_bit_count; - - memset(s->block, 0, sizeof(s->block)); + + memset(sblock, 0, sizeof(sblock)); /* pass 1 : read DC and AC coefficients in blocks */ buf_ptr = buf_ptr1; - block1 = &s->block[0][0]; + block1 = &sblock[0][0]; mb1 = mb_data; init_put_bits(&vs_pb, vs_bit_buffer, 5 * 80); - vs_bit_count = 0; - for(mb_index = 0; mb_index < 5; mb_index++) { + for(mb_index = 0; mb_index < 5; mb_index++, mb1 += 6, block1 += 6 * 64) { /* skip header */ quant = buf_ptr[3] & 0x0f; buf_ptr += 4; init_put_bits(&pb, mb_bit_buffer, 80); - mb_bit_count = 0; mb = mb1; block = block1; for(j = 0;j < 6; j++) { - /* NOTE: size is not important here */ - init_get_bits(&s->gb, buf_ptr, 14*8); + last_index = block_sizes[j]; + init_get_bits(&gb, buf_ptr, last_index); /* get the dc */ - dc = get_bits(&s->gb, 9); + dc = get_bits(&gb, 9); dc = (dc << (32 - 9)) >> (32 - 9); - dct_mode = get_bits1(&s->gb); + dct_mode = get_bits1(&gb); mb->dct_mode = dct_mode; mb->scan_table = s->dv_zigzag[dct_mode]; - class1 = get_bits(&s->gb, 2); - mb->shift_offset = (class1 == 3); - mb->shift_table = s->dv_idct_shift[dct_mode] + class1 = get_bits(&gb, 2); + mb->shift_table = s->dv_idct_shift[class1 == 3][dct_mode] [quant + dv_quant_offset[class1]]; dc = dc << 2; /* convert to unsigned because 128 is not added in the standard IDCT */ dc += 1024; block[0] = dc; - last_index = block_sizes[j]; buf_ptr += last_index >> 3; mb->pos = 0; mb->partial_bit_count = 0; @@ -434,88 +416,64 @@ #ifdef VLC_DEBUG printf("MB block: %d, %d ", mb_index, j); #endif - dv_decode_ac(s, mb, block, last_index); + dv_decode_ac(&gb, mb, block); /* write the remaining bits in a new buffer only if the block is finished */ - bits_left = last_index - get_bits_count(&s->gb); - if (mb->eob_reached) { - mb->partial_bit_count = 0; - mb_bit_count += bits_left; - bit_copy(&pb, &s->gb, bits_left); - } else { - /* should be < 16 bits otherwise a codeword could have - been parsed */ - mb->partial_bit_count = bits_left; - mb->partial_bit_buffer = get_bits(&s->gb, bits_left); - } + if (mb->pos >= 64) + bit_copy(&pb, &gb); + block += 64; mb++; } - flush_put_bits(&pb); - /* pass 2 : we can do it just after */ #ifdef VLC_DEBUG - printf("***pass 2 size=%d MB#=%d\n", mb_bit_count, mb_index); + printf("***pass 2 size=%d MB#=%d\n", put_bits_count(&pb), mb_index); #endif block = block1; mb = mb1; - init_get_bits(&s->gb, mb_bit_buffer, 80*8); - for(j = 0;j < 6; j++) { - if (!mb->eob_reached && get_bits_count(&s->gb) < mb_bit_count) { - dv_decode_ac(s, mb, block, mb_bit_count); + init_get_bits(&gb, mb_bit_buffer, put_bits_count(&pb)); + flush_put_bits(&pb); + for(j = 0;j < 6; j++, block += 64, mb++) { + if (mb->pos < 64 && get_bits_left(&gb) > 0) { + dv_decode_ac(&gb, mb, block); /* if still not finished, no need to parse other blocks */ - if (!mb->eob_reached) { - /* we could not parse the current AC coefficient, - so we add the remaining bytes */ - bits_left = mb_bit_count - get_bits_count(&s->gb); - if (bits_left > 0) { - mb->partial_bit_count += bits_left; - mb->partial_bit_buffer = - (mb->partial_bit_buffer << bits_left) | - get_bits(&s->gb, bits_left); - } - goto next_mb; - } + if (mb->pos < 64) + break; } - block += 64; - mb++; } /* all blocks are finished, so the extra bytes can be used at the video segment level */ - bits_left = mb_bit_count - get_bits_count(&s->gb); - vs_bit_count += bits_left; - bit_copy(&vs_pb, &s->gb, bits_left); - next_mb: - mb1 += 6; - block1 += 6 * 64; + if (j >= 6) + bit_copy(&vs_pb, &gb); } /* we need a pass other the whole video segment */ - flush_put_bits(&vs_pb); - #ifdef VLC_DEBUG - printf("***pass 3 size=%d\n", vs_bit_count); + printf("***pass 3 size=%d\n", put_bits_count(&vs_pb)); #endif - block = &s->block[0][0]; + block = &sblock[0][0]; mb = mb_data; - init_get_bits(&s->gb, vs_bit_buffer, 5 * 80*8); + init_get_bits(&gb, vs_bit_buffer, put_bits_count(&vs_pb)); + flush_put_bits(&vs_pb); for(mb_index = 0; mb_index < 5; mb_index++) { for(j = 0;j < 6; j++) { - if (!mb->eob_reached) { + if (mb->pos < 64) { #ifdef VLC_DEBUG printf("start %d:%d\n", mb_index, j); #endif - dv_decode_ac(s, mb, block, vs_bit_count); + dv_decode_ac(&gb, mb, block); } + if (mb->pos >= 64 && mb->pos < 127) + av_log(NULL, AV_LOG_ERROR, "AC EOB marker is absent pos=%d\n", mb->pos); block += 64; mb++; } } /* compute idct and place blocks */ - block = &s->block[0][0]; + block = &sblock[0][0]; mb = mb_data; for(mb_index = 0; mb_index < 5; mb_index++) { v = *mb_pos_ptr++; @@ -790,7 +748,7 @@ * horrible and the weighting is missing. But it's missing from the * decoding step also -- so at least we're on the same page with decoder ;-) */ -static inline void dv_encode_video_segment(DVVideoDecodeContext *s, +static inline void dv_encode_video_segment(DVVideoContext *s, uint8_t *dif, const uint16_t *mb_pos_ptr) { @@ -801,6 +759,7 @@ uint8_t* ptr; int do_edge_wrap; DCTELEM block[64] __align8; + DCTELEM sblock[5*6][64] __align8; EncBlockInfo enc_blks[5*6]; PutBitContext pbs[5*6]; PutBitContext* pb; @@ -854,7 +813,7 @@ } enc_blk->dct_mode = dv_guess_dct_mode(block); - enc_blk->mb = &s->block[mb_index*6+j][0]; + enc_blk->mb = &sblock[mb_index*6+j][0]; enc_blk->area_q[0] = enc_blk->area_q[1] = enc_blk->area_q[2] = enc_blk->area_q[3] = 0; enc_blk->partial_bit_count = 0; enc_blk->partial_bit_buffer = 0; @@ -906,15 +865,31 @@ flush_put_bits(&pbs[j]); } +static int dv_decode_mt(AVCodecContext *avctx, void* sl) +{ + DVVideoContext *s = avctx->priv_data; + int slice = (size_t)sl; + dv_decode_video_segment(s, &s->buf[((slice/27)*6+(slice/3)+slice*5+7)*80], + &s->sys->video_place[slice*5]); + return 0; +} + +static int dv_encode_mt(AVCodecContext *avctx, void* sl) +{ + DVVideoContext *s = avctx->priv_data; + int slice = (size_t)sl; + dv_encode_video_segment(s, &s->buf[((slice/27)*6+(slice/3)+slice*5+7)*80], + &s->sys->video_place[slice*5]); + return 0; +} + /* NOTE: exactly one frame must be given (120000 bytes for NTSC, 144000 bytes for PAL) */ static int dvvideo_decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) { - DVVideoDecodeContext *s = avctx->priv_data; - int ds, vs; - const uint16_t *mb_pos_ptr; + DVVideoContext *s = avctx->priv_data; *data_size=0; /* special case for last picture */ @@ -925,7 +900,6 @@ if (!s->sys || buf_size < s->sys->frame_size) return -1; /* NOTE: we only accept several full frames */ - if(s->picture.data[0]) avctx->release_buffer(avctx, &s->picture); @@ -940,24 +914,10 @@ s->picture.interlaced_frame = 1; s->picture.top_field_first = 0; - /* for each DIF segment */ - mb_pos_ptr = s->sys->video_place; - for (ds = 0; ds < s->sys->difseg_size; ds++) { - buf += 6 * 80; /* skip DIF segment header */ - - for(vs = 0; vs < 27; vs++) { - if ((vs % 3) == 0) - buf += 80; /* skip audio block */ - -#ifdef VLC_DEBUG - printf("********************* %d, %d **********************\n", ds, vs); -#endif - dv_decode_video_segment(s, buf, mb_pos_ptr); - buf += 5 * 80; - mb_pos_ptr += 5; - } - } - + s->buf = buf; + avctx->execute(avctx, dv_decode_mt, (void**)&dv_anchor[0], NULL, + s->sys->difseg_size * 27); + emms_c(); /* return image */ @@ -970,9 +930,7 @@ static int dvvideo_encode_frame(AVCodecContext *c, uint8_t *buf, int buf_size, void *data) { - DVVideoDecodeContext *s = c->priv_data; - const uint16_t *mb_pos_ptr; - int ds, vs; + DVVideoContext *s = c->priv_data; s->sys = dv_codec_profile(c); if (!s->sys) @@ -981,41 +939,34 @@ c->pix_fmt = s->sys->pix_fmt; s->picture = *((AVFrame *)data); - /* for each DIF segment */ - mb_pos_ptr = s->sys->video_place; - for (ds = 0; ds < s->sys->difseg_size; ds++) { - buf += 6 * 80; /* skip DIF segment header */ - - for(vs = 0; vs < 27; vs++) { - if ((vs % 3) == 0) - buf += 80; /* skip audio block */ - -#ifdef VLC_DEBUG - printf("********************* %d, %d **********************\n", ds, vs); -#endif - dv_encode_video_segment(s, buf, mb_pos_ptr); - buf += 5 * 80; - mb_pos_ptr += 5; - } - } + s->buf = buf; + c->execute(c, dv_encode_mt, (void**)&dv_anchor[0], NULL, + s->sys->difseg_size * 27); emms_c(); return s->sys->frame_size; } -static int dvvideo_end(AVCodecContext *avctx) -{ - avcodec_default_free_buffers(avctx); - return 0; -} +AVCodec dvvideo_encoder = { + "dvvideo", + CODEC_TYPE_VIDEO, + CODEC_ID_DVVIDEO, + sizeof(DVVideoContext), + dvvideo_init, + dvvideo_encode_frame, + dvvideo_end, + NULL, + CODEC_CAP_DR1, + NULL +}; AVCodec dvvideo_decoder = { "dvvideo", CODEC_TYPE_VIDEO, CODEC_ID_DVVIDEO, - sizeof(DVVideoDecodeContext), + sizeof(DVVideoContext), dvvideo_init, - dvvideo_encode_frame, + NULL, dvvideo_end, dvvideo_decode_frame, CODEC_CAP_DR1, Index: dvdata.h =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/dvdata.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- dvdata.h 1 Feb 2004 05:31:16 -0000 1.6 +++ dvdata.h 25 Apr 2004 18:58:39 -0000 1.7 @@ -218,7 +218,7 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, +127, }; static const uint8_t dv_vlc_level[409] = { Index: error_resilience.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/error_resilience.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- error_resilience.c 14 Mar 2004 21:14:08 -0000 1.11 +++ error_resilience.c 25 Apr 2004 18:58:39 -0000 1.12 @@ -45,7 +45,7 @@ { int dc, dcu, dcv, y, i; for(i=0; i<4; i++){ - dc= s->dc_val[0][mb_x*2+1 + (i&1) + (mb_y*2+1 + (i>>1))*(s->mb_width*2+2)]; + dc= s->dc_val[0][mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*s->b8_stride]; if(dc<0) dc=0; else if(dc>2040) dc=2040; for(y=0; y<8; y++){ @@ -55,8 +55,8 @@ } } } - dcu = s->dc_val[1][mb_x+1 + (mb_y+1)*(s->mb_width+2)]; - dcv = s->dc_val[2][mb_x+1 + (mb_y+1)*(s->mb_width+2)]; + dcu = s->dc_val[1][mb_x + mb_y*s->mb_stride]; + dcv = s->dc_val[2][mb_x + mb_y*s->mb_stride]; if (dcu<0 ) dcu=0; else if(dcu>2040) dcu=2040; if (dcv<0 ) dcv=0; @@ -209,8 +209,8 @@ int left_damage = left_status&(DC_ERROR|AC_ERROR|MV_ERROR); int right_damage= right_status&(DC_ERROR|AC_ERROR|MV_ERROR); int offset= b_x*8 + b_y*stride*8; - int16_t *left_mv= s->current_picture.motion_val[0][s->block_wrap[0]*((b_y<<(1-is_luma)) + 1) + ( b_x <<(1-is_luma))]; - int16_t *right_mv= s->current_picture.motion_val[0][s->block_wrap[0]*((b_y<<(1-is_luma)) + 1) + ((b_x+1)<<(1-is_luma))]; + int16_t *left_mv= s->current_picture.motion_val[0][s->b8_stride*(b_y<<(1-is_luma)) + ( b_x <<(1-is_luma))]; + int16_t *right_mv= s->current_picture.motion_val[0][s->b8_stride*(b_y<<(1-is_luma)) + ((b_x+1)<<(1-is_luma))]; if(!(left_damage||right_damage)) continue; // both undamaged @@ -269,8 +269,8 @@ int top_damage = top_status&(DC_ERROR|AC_ERROR|MV_ERROR); int bottom_damage= bottom_status&(DC_ERROR|AC_ERROR|MV_ERROR); int offset= b_x*8 + b_y*stride*8; - int16_t *top_mv= s->current_picture.motion_val[0][s->block_wrap[0]*(( b_y <<(1-is_luma)) + 1) + (b_x<<(1-is_luma))]; - int16_t *bottom_mv= s->current_picture.motion_val[0][s->block_wrap[0]*(((b_y+1)<<(1-is_luma)) + 1) + (b_x<<(1-is_luma))]; + int16_t *top_mv= s->current_picture.motion_val[0][s->b8_stride*( b_y <<(1-is_luma)) + (b_x<<(1-is_luma))]; + int16_t *bottom_mv= s->current_picture.motion_val[0][s->b8_stride*((b_y+1)<<(1-is_luma)) + (b_x<<(1-is_luma))]; if(!(top_damage||bottom_damage)) continue; // both undamaged @@ -378,8 +378,8 @@ int j; int best_score=256*256*256*64; int best_pred=0; - const int mot_stride= mb_width*2+2; - const int mot_index= mb_x*2 + 1 + (mb_y*2+1)*mot_stride; + const int mot_stride= s->b8_stride; + const int mot_index= mb_x*2 + mb_y*2*mot_stride; int prev_x= s->current_picture.motion_val[0][mot_index][0]; int prev_y= s->current_picture.motion_val[0][mot_index][1]; @@ -672,14 +672,15 @@ av_log(s->avctx, AV_LOG_INFO, "concealing errors\n"); if(s->current_picture.motion_val[0] == NULL){ - int size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); + int size = s->b8_stride * 2 * s->mb_height; Picture *pic= s->current_picture_ptr; av_log(s->avctx, AV_LOG_ERROR, "Warning MVs not available\n"); for(i=0; i<2; i++){ - pic->motion_val_base[i]= av_mallocz((size+1) * 2 * sizeof(uint16_t)); //FIXME size - pic->motion_val[i]= pic->motion_val_base[i]+1; + pic->ref_index[i]= av_mallocz(size * sizeof(uint8_t)); + pic->motion_val_base[i]= av_mallocz((size+2) * 2 * sizeof(uint16_t)); + pic->motion_val[i]= pic->motion_val_base[i]+2; } pic->motion_subsample_log2= 3; s->current_picture= *s->current_picture_ptr; @@ -845,17 +846,17 @@ s->mb_intra=0; s->mb_skiped=0; if(IS_8X8(mb_type)){ - int mb_index= mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0]; + int mb_index= mb_x*2 + mb_y*2*s->b8_stride; int j; s->mv_type = MV_TYPE_8X8; for(j=0; j<4; j++){ - s->mv[0][j][0] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->block_wrap[0] ][0]; - s->mv[0][j][1] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->block_wrap[0] ][1]; + s->mv[0][j][0] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->b8_stride ][0]; + s->mv[0][j][1] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->b8_stride ][1]; } }else{ s->mv_type = MV_TYPE_16X16; - s->mv[0][0][0] = s->current_picture.motion_val[0][ mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0] ][0]; - s->mv[0][0][1] = s->current_picture.motion_val[0][ mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0] ][1]; + s->mv[0][0][0] = s->current_picture.motion_val[0][ mb_x*2 + mb_y*2*s->b8_stride ][0]; + s->mv[0][0][1] = s->current_picture.motion_val[0][ mb_x*2 + mb_y*2*s->b8_stride ][1]; } s->dsp.clear_blocks(s->block[0]); @@ -870,7 +871,7 @@ if(s->pict_type==B_TYPE){ for(mb_y=0; mb_y<s->mb_height; mb_y++){ for(mb_x=0; mb_x<s->mb_width; mb_x++){ - int xy= mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0]; + int xy= mb_x*2 + mb_y*2*s->b8_stride; const int mb_xy= mb_x + mb_y * s->mb_stride; const int mb_type= s->current_picture.mb_type[mb_xy]; error= s->error_status_table[mb_xy]; @@ -930,7 +931,7 @@ dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize; dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize; - dc_ptr= &s->dc_val[0][mb_x*2+1 + (mb_y*2+1)*(s->mb_width*2+2)]; + dc_ptr= &s->dc_val[0][mb_x*2 + mb_y*2*s->b8_stride]; for(n=0; n<4; n++){ dc=0; for(y=0; y<8; y++){ @@ -939,7 +940,7 @@ dc+= dest_y[x + (n&1)*8 + (y + (n>>1)*8)*s->linesize]; } } - dc_ptr[(n&1) + (n>>1)*(s->mb_width*2+2)]= (dc+4)>>3; + dc_ptr[(n&1) + (n>>1)*s->b8_stride]= (dc+4)>>3; } dcu=dcv=0; @@ -950,18 +951,18 @@ dcv+=dest_cr[x + y*(s->uvlinesize)]; } } - s->dc_val[1][mb_x+1 + (mb_y+1)*(s->mb_width+2)]= (dcu+4)>>3; - s->dc_val[2][mb_x+1 + (mb_y+1)*(s->mb_width+2)]= (dcv+4)>>3; + s->dc_val[1][mb_x + mb_y*s->mb_stride]= (dcu+4)>>3; + s->dc_val[2][mb_x + mb_y*s->mb_stride]= (dcv+4)>>3; } } #if 1 /* guess DC for damaged blocks */ - guess_dc(s, s->dc_val[0] + s->mb_width*2+3, s->mb_width*2, s->mb_height*2, s->mb_width*2+2, 1); - guess_dc(s, s->dc_val[1] + s->mb_width +3, s->mb_width , s->mb_height , s->mb_width +2, 0); - guess_dc(s, s->dc_val[2] + s->mb_width +3, s->mb_width , s->mb_height , s->mb_width +2, 0); + guess_dc(s, s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride, 1); + guess_dc(s, s->dc_val[1], s->mb_width , s->mb_height , s->mb_stride, 0); + guess_dc(s, s->dc_val[2], s->mb_width , s->mb_height , s->mb_stride, 0); #endif /* filter luma DC */ - filter181(s->dc_val[0] + s->mb_width*2+3, s->mb_width*2, s->mb_height*2, s->mb_width*2+2); + filter181(s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride); #if 1 /* render DC only intra */ Index: h263.c =================================================================== RCS file: /cvsroot/xine/xine-lib/src/libffmpeg/libavcodec/h263.c,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- h263.c 14 Mar 2004 21:14:08 -0000 1.36 +++ h263.c 25 Apr 2004 18:58:48 -0000 1.37 @@ -75,7 +75,7 @@ static void mpeg4_encode_visual_object_header(MpegEncContext * s); static void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_number); #endif //CONFIG_ENCODERS -static void mpeg4_decode_sprite_trajectory(MpegEncContext * s); +static void mpeg4_decode_sprite_trajectory(MpegEncContext * s, GetBitContext *gb); static inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, uint16_t **dc_val_ptr, int *dir_ptr); #ifdef CONFIG_ENCODERS @@ -577,12 +577,13 @@ } else if(IS_INTERLACED(colocated_mb_type)){ s->mv_type = MV_TYPE_FIELD; for(i=0; i<2; i++){ + int field_select= s->next_picture.ref_index[0][s->block_index[2*i]]; if(s->top_field_first){ - time_pp= s->pp_field_time - s->p_field_select_table[i][mb_index] + i; - time_pb= s->pb_field_time - s->p_field_select_table[i][mb_index] + i; + time_pp= s->pp_field_time - field_select + i; + time_pb= s->pb_field_time - field_select + i; }else{ - time_pp= s->pp_field_time + s->p_field_select_table[i][mb_index] - i; - time_pb= s->pb_field_time + s->p_field_select_table[i][mb_index] - i; + time_pp= s->pp_field_time + field_select - i; + time_pb= s->pb_field_time + field_select - i; } s->mv[0][i][0] = s->p_field_mv_table[i][0][mb_index][0]*time_pb/time_pp + mx; s->mv[0][i][1] = s->p_field_mv_table[i][0][mb_index][1]*time_pb/time_pp + my; @@ -610,7 +611,7 @@ void ff_h263_update_motion_val(MpegEncContext * s){ const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; //FIXME a lot of thet is only needed for !low_delay - const int wrap = s->block_wrap[0]; + const int wrap = s->b8_stride; const int xy = s->block_index[0]; s->current_picture.mbskip_table[mb_xy]= s->mb_skiped; @@ -631,10 +632,13 @@ for(i=0; i<2; i++){ s->p_field_mv_table[i][0][mb_xy][0]= s->mv[0][i][0]; s->p_field_mv_table[i][0][mb_xy][1]= s->mv[0][i][1]; - s->p_field_select_table[i][mb_xy]= s->field_select[0][i]; } + s->current_picture.ref_index[0][xy ]= + s->current_picture.ref_index[0][xy + 1]= s->field_select[0][0]; + s->current_picture.ref_index[0][xy + wrap ]= + s->current_picture.ref_index[0][xy + wrap + 1]= s->field_select[0][1]; } - + /* no update if 8X8 because it has been done during parsing */ s->current_picture.motion_val[0][xy][0] = motion_x; s->current_picture.motion_val[0][xy][1] = motion_y; @@ -985,7 +989,7 @@ } /* motion vectors: 16x16 mode */ - h263_pred_motion(s, 0, &pred_x, &pred_y); + h263_pred_motion(s, 0, 0, &pred_x, &pred_y); h263_encode_motion(s, motion_x - pred_x, s->f_code); h263_encode_motion(s, motion_y - pred_y, s->f_code); @@ -1009,7 +1013,7 @@ } /* motion vectors: 16x8 interlaced mode */ - h263_pred_motion(s, 0, &pred_x, &pred_y); + h263_pred_motion(s, 0, 0, &pred_x, &pred_y); pred_y /=2; put_bits(&s->pb, 1, s->field_select[0][0]); @@ -1037,7 +1041,7 @@ for(i=0; i<4; i++){ /* motion vectors: 8x8 mode*/ - h263_pred_motion(s, i, &pred_x, &pred_y); + h263_pred_motion(s, i, 0, &pred_x, &pred_y); h263_encode_motion(s, s->current_picture.motion_val[0][ s->block_index[i] ][0] - pred_x, s->f_code); h263_encode_motion(s, s->current_picture.motion_val[0][ s->block_index[i] ][1] - pred_y, s->f_code); @@ -1185,7 +1189,7 @@ } /* motion vectors: 16x16 mode */ - h263_pred_motion(s, 0, &pred_x, &pred_y); + h263_pred_motion(s, 0, 0, &pred_x, &pred_y); if (!s->umvplus) { h263_encode_motion(s, motion_x - pred_x, 1); @@ -1212,7 +1216,7 @@ for(i=0; i<4; i++){ /* motion vectors: 8x8 mode*/ - h263_pred_motion(s, i, &pred_x, &pred_y); + h263_pred_motion(s, i, 0, &pred_x, &pred_y); motion_x= s->current_picture.motion_val[0][ s->block_index[i] ][0]; motion_y= s->current_picture.motion_val[0][ s->block_index[i] ][1]; @@ -1435,16 +1439,16 @@ /* find prediction */ if (n < 4) { - x = 2 * s->mb_x + 1 + (n & 1); - y = 2 * s->mb_y + 1 + ((n & 2) >> 1); - wrap = s->mb_width * 2 + 2; + x = 2 * s->mb_x + (n & 1); + y = 2 * s->mb_y + ((n & 2) >> 1); + wrap = s->b8_stride; dc_val = s->dc_val[0]; ac_val = s->ac_val[0][0]; scale = s->y_dc_scale; } else { - x = s->mb_x + 1; - y = s->mb_y + 1; - wrap = s->mb_width + 2; + x = s->mb_x; + y = s->mb_y; + wrap = s->mb_stride; dc_val = s->dc_val[n - 4 + 1]; ac_val = s->ac_val[n - 4 + 1][0]; scale = s->c_dc_scale; @@ -1456,8 +1460,10 @@ c = dc_val[(x) + (y - 1) * wrap]; /* No prediction outside GOB boundary */ - if (s->first_slice_line && ((n < 2) || (n > 3))) - c = 1024; + if(s->first_slice_line && n!=3){ + if(n!=2) c= 1024; + if(n!=1 && s->mb_x == s->resync_mb_x) a= 1024; + } pred_dc = 1024; /* just DC prediction */ if (a != 1024 && c != 1024) @@ -1480,16 +1486,16 @@ /* find prediction */ if (n < 4) { - x = 2 * s->mb_x + 1 + (n & 1); - y = 2 * s->mb_y + 1 + (n>> 1); - wrap = s->mb_width * 2 + 2; + x = 2 * s->mb_x + (n & 1); + y = 2 * s->mb_y + (n>> 1); + wrap = s->b8_stride; dc_val = s->dc_val[0]; ac_val = s->ac_val[0][0]; scale = s->y_dc_scale; } else { - x = s->mb_x + 1; - y = s->mb_y + 1; - wrap = s->mb_width + 2; + x = s->mb_x; + y = s->mb_y; + wrap = s->mb_stride; dc_val = s->dc_val[n - 4 + 1]; ac_val = s->ac_val[n - 4 + 1][0]; scale = s->c_dc_scale; @@ -1560,78 +1566,15 @@ ac_val1[8 + i] = block[s->dsp.idct_permutation[i ]]; } -int16_t *h263_pred_motion(MpegEncContext * s, int block, +int16_t *h263_pred_motion(MpegEncContext * s, int block, int dir, int *px, int *py) { - int xy, wrap; - int16_t *A, *B, *C, *mot_val; - static const int off[4]= {2, 1, 1, -1}; - - wrap = s->block_wrap[0]; - xy = s->block_index[block]; - - mot_val = s->current_picture.motion_val[0][xy]; - - A = s->current_picture.motion_val[0][xy - 1]; - /* special case for first (slice) line */ - if (s->first_slice_line && block<3) { - // we cant just change some MVs to simulate that as we need them for the B frames (and ME) - // and if we ever support non rectangular objects than we need to do a few ifs here anyway :( - if(block==0){ //most common case - if(s->mb_x == s->resync_mb_x){ //rare - *px= *py = 0; - }else if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare - C = s->current_picture.motion_val[0][xy + off[block] - wrap]; - if(s->mb_x==0){ - *px = C[0]; - *py = C[1]; - }else{ - *px = mid_pred(A[0], 0, C[0]); - *py = mid_pred(A[1], 0, C[1]); - } - }else{ - *px = A[0]; - *py = A[1]; - } - }else if(block==1){ - if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare - C = s->current_picture.motion_val[0][xy + off[block] - wrap]; - *px = mid_pred(A[0], 0, C[0]); - *py = mid_pred(A[1], 0, C[1]); - }else{ - *px = A[0]; - *py = A[1]; - } - }else{ /* block==2*/ - B = s->current_picture.motion_val[0][xy - wrap]; - C = s->current_picture.motion_val[0][xy + off[block] - wrap]; - if(s->mb_x == s->resync_mb_x) //rare - A[0]=A[1]=0; - - *px = mid_pred(A[0], B[0], C[0]); - *py = mid_pred(A[1], B[1], C[1]); - } - } else { - B = s->current_picture.motion_val[0][xy - wrap]; - C = s->current_picture.motion_val[0][xy + off[block] - wrap]; - *px = mid_pred(A[0], B[0], C[0]); - *py = mid_pred(A[1], B[1], C[1]); - } - return mot_val; -} - -// identical to above but with s->current_picture->motion_val, the above one will be removed, and this renamed to it -int16_t *h263_pred_motion2(MpegEncContext * s, int block, int dir, - int *px, int *py) -{ - int xy, wrap; + int wrap; int16_t *A, *B, *C, (*mot_val)[2]; static const int off[4]= {2, 1, 1, -1}; wrap = s->b8_stride; - xy = 2*(s->mb_x + s->mb_y * wrap); - - mot_val = s->current_picture.motion_val[dir] + xy; + mot_val = s->current_picture.motion_val[dir] + s->block_index[block]; A = mot_val[ - 1]; /* special case for first (slice) line */ @@ -1785,7 +1728,7 @@ else{ int val, bit_size, range, code; - bit_size = s->f_code - 1; + bit_size = f_code - 1; range = 1 << bit_size; val=mv; @@ -2386,6 +2329,7 @@ time_div= s->time/s->time_increment_resolution; time_mod= s->time%s->time_increment_resolution; time_incr= time_div - s->last_time_base; + assert(time_incr >= 0); while(time_incr--) put_bits(&s->pb, 1, 1); @@ -2994,13 +2938,12 @@ uint8_t *start= pbBufPtr(&s->pb); uint8_t *end= s->pb.buf_end; int size= end - start; - int pb_size = size/3; - int pb2_size= size/3; - int tex_size= size - pb_size - pb2_size; + int pb_size = (((int)start + size/3)&(~3)) - (int)start; + int tex_size= (size - 2*pb_size)&(~3); set_put_bits_buffer_size(&s->pb, pb_size); init_put_bits(&s->tex_pb, start + pb_size , tex_size); - init_put_bits(&s->pb2 , start + pb_size + tex_size, pb2_size); + init_put_bits(&s->pb2 , start + pb_size + tex_size, pb_size); } void ff_mpeg4_merge_partitions(MpegEncContext *s) @@ -3165,7 +3108,7 @@ skip_bits(&s->gb, 3); /* intra dc vlc threshold */ //FIXME dont just ignore everything if(s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ - mpeg4_decode_sprite_trajectory(s); + mpeg4_decode_sprite_trajectory(s, &s->gb); av_log(s->avctx, AV_LOG_ERROR, "untested\n"); } @@ -3196,10 +3139,10 @@ { int c_wrap, c_xy, l_wrap, l_xy; - l_wrap= s->block_wrap[0]; - l_xy= s->mb_y*l_wrap*2 + s->mb_x*2; - c_wrap= s->block_wrap[4]; - c_xy= s->mb_y*c_wrap + s->mb_x; + l_wrap= s->b8_stride; + l_xy= (2*s->mb_y-1)*l_wrap + s->mb_x*2 - 1; + c_wrap= s->mb_stride; + c_xy= (s->mb_y-1)*c_wrap + s->mb_x - 1; #if 0 /* clean DC */ @@ -3372,7 +3315,7 @@ }else{ /* P/S_TYPE */ int mx, my, pred_x, pred_y, bits; int16_t * const mot_val= s->current_picture.motion_val[0][s->block_index[0]]; - const int stride= s->block_wrap[0]*2; + const int stride= s->b8_stride*2; try_again: bits= show_bits(&s->gb, 17); @@ -3430,7 +3373,7 @@ if ((cbpc & 16) == 0) { /* 16x16 motion prediction */ - h263_pred_motion(s, 0, &pred_x, &pred_y); + h263_pred_motion(s, 0, 0, &pred_x, &pred_y); if(!s->mcsel){ mx = h263_decode_motion(s, pred_x, s->f_code); if (mx >= 0xffff) @@ -3454,7 +3397,7 @@ int i; s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0; for(i=0;i<4;i++) { - int16_t *mot_val= h263_pred_motion(s, i, &pred_x, &pred_y); + int16_t *mot_val= h263_pred_motion(s, i, 0, &pred_x, &pred_y); mx = h263_decode_motion(s, pred_x, s->f_code); if (mx >= 0xffff) return -1; @@ -3708,7 +3651,7 @@ int cbpc, i, pred_x, pred_y, mx, my; int16_t *mot_val; const int xy= s->mb_x + 1 + s->mb_y * s->mb_stride; - const int stride= s->block_wrap[0]*2; + const int stride= s->b8_stride*2; for(i=0; i<4; i++) s->block_index[i]+= 2; @@ -3748,7 +3691,7 @@ if ((cbpc & 16) == 0) { s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0; /* 16x16 motion prediction */ - mot_val= h263_pred_motion(s, 0, &pred_x, &pred_y); + mot_val= h263_pred_motion(s, 0, 0, &pred_x, &pred_y); if (s->umvplus) mx = h263p_decode_umotion(s, pred_x); else @@ -3766,7 +3709,7 @@ } else { s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0; for(i=0;i<4;i++) { - mot_val = h263_pred_motion(s, i, &pred_x, &pred_y); + mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y); if (s->umvplus) mx = h263p_decode_umotion(s, pred_x); else @@ -3858,7 +3801,7 @@ s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0; /* 16x16 motion prediction */ s->mv_type = MV_TYPE_16X16; - h263_pred_motion(s, 0, &pred_x, &pred_y); + h263_pred_motion(s, 0, 0, &pred_x, &pred_y); if (s->umvplus) mx = h263p_decode_umotion(s, pred_x); else @@ -3883,7 +3826,7 @@ s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0; s->mv_type = MV_TYPE_8X8; for(i=0;i<... [truncated message content] |