From 29b42c66f70ec7f8bcac87cb3cb35ec13dc0c71e Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Tue, 19 Jul 2011 10:20:56 +0100 Subject: [PATCH 1/9] dsputil: fix ff_check_alignment() The change to LOCAL_ALIGNED means the declared object must be an array and the subsequent test should not use the & operator. Noticed by Uoti Urpala. Signed-off-by: Mans Rullgard --- libavcodec/dsputil.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/dsputil.c b/libavcodec/dsputil.c index f24985ce4c..a3e8d6cd95 100644 --- a/libavcodec/dsputil.c +++ b/libavcodec/dsputil.c @@ -2823,9 +2823,9 @@ av_cold void dsputil_static_init(void) int ff_check_alignment(void){ static int did_fail=0; - LOCAL_ALIGNED_16(int, aligned); + LOCAL_ALIGNED_16(int, aligned, [4]); - if((intptr_t)&aligned & 15){ + if((intptr_t)aligned & 15){ if(!did_fail){ #if HAVE_MMX || HAVE_ALTIVEC av_log(NULL, AV_LOG_ERROR, From 31b69928e5fd3d40dda4091ae7db340c582113af Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Tue, 12 Jul 2011 16:44:22 -0400 Subject: [PATCH 2/9] cosmetics: rename eac3dec_data.c/h to eac3_data.c/h since the tables will also be used in the E-AC-3 encoder. --- libavcodec/Makefile | 2 +- libavcodec/{eac3dec_data.c => eac3_data.c} | 4 ++-- libavcodec/{eac3dec_data.h => eac3_data.h} | 8 ++++---- libavcodec/eac3dec.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) rename libavcodec/{eac3dec_data.c => eac3_data.c} (99%) rename libavcodec/{eac3dec_data.h => eac3_data.h} (90%) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index fb603f864d..2c52c8d453 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -122,7 +122,7 @@ OBJS-$(CONFIG_DVDSUB_ENCODER) += dvdsubenc.o OBJS-$(CONFIG_DVVIDEO_DECODER) += dv.o dvdata.o OBJS-$(CONFIG_DVVIDEO_ENCODER) += dv.o dvdata.o OBJS-$(CONFIG_DXA_DECODER) += dxa.o -OBJS-$(CONFIG_EAC3_DECODER) += eac3dec.o eac3dec_data.o +OBJS-$(CONFIG_EAC3_DECODER) += eac3dec.o eac3_data.o OBJS-$(CONFIG_EAC3_ENCODER) += eac3enc.o ac3enc.o ac3enc_float.o \ ac3tab.o ac3.o kbdwin.o OBJS-$(CONFIG_EACMV_DECODER) += eacmv.o diff --git a/libavcodec/eac3dec_data.c b/libavcodec/eac3_data.c similarity index 99% rename from libavcodec/eac3dec_data.c rename to libavcodec/eac3_data.c index 4cea26fcb3..b0416f3ce7 100644 --- a/libavcodec/eac3dec_data.c +++ b/libavcodec/eac3_data.c @@ -1,5 +1,5 @@ /* - * E-AC-3 decoder tables + * E-AC-3 tables * Copyright (c) 2007 Bartlomiej Wolowiec * * This file is part of Libav. @@ -24,7 +24,7 @@ * Tables taken directly from the E-AC-3 spec. */ -#include "eac3dec_data.h" +#include "eac3_data.h" #include "ac3.h" const uint8_t ff_eac3_bits_vs_hebap[20] = { diff --git a/libavcodec/eac3dec_data.h b/libavcodec/eac3_data.h similarity index 90% rename from libavcodec/eac3dec_data.h rename to libavcodec/eac3_data.h index 91892a30d6..4d88ce0a53 100644 --- a/libavcodec/eac3dec_data.h +++ b/libavcodec/eac3_data.h @@ -1,5 +1,5 @@ /* - * E-AC-3 decoder tables + * E-AC-3 tables * Copyright (c) 2007 Bartlomiej Wolowiec * * This file is part of Libav. @@ -19,8 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVCODEC_EAC3DEC_DATA_H -#define AVCODEC_EAC3DEC_DATA_H +#ifndef AVCODEC_EAC3_DATA_H +#define AVCODEC_EAC3_DATA_H #include @@ -33,4 +33,4 @@ extern const int16_t (* const ff_eac3_mantissa_vq[8])[6]; extern const uint8_t ff_eac3_frm_expstr[32][6]; extern const float ff_eac3_spx_atten_tab[32][3]; -#endif /* AVCODEC_EAC3DEC_DATA_H */ +#endif /* AVCODEC_EAC3_DATA_H */ diff --git a/libavcodec/eac3dec.c b/libavcodec/eac3dec.c index 54007686dd..212f6b4e38 100644 --- a/libavcodec/eac3dec.c +++ b/libavcodec/eac3dec.c @@ -51,7 +51,7 @@ #include "ac3_parser.h" #include "ac3dec.h" #include "ac3dec_data.h" -#include "eac3dec_data.h" +#include "eac3_data.h" /** gain adaptive quantization mode */ typedef enum { From 08a747afb98c11da48b89339c2f1c5fdc56ced7e Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 13 Jul 2011 12:20:29 -0400 Subject: [PATCH 3/9] eac3enc: use frame exponent strategy when applicable. This checks if the set of selected exponent strategies for all blocks in a channel are in the frame exponent strategy table, and if so, writes the table index instead of each strategy. This saves up to 7 bits per channel per frame, so the overall effect on quality is small. --- libavcodec/Makefile | 2 +- libavcodec/ac3enc.c | 41 ++++++++++++++++++++++++----- libavcodec/ac3enc.h | 2 ++ libavcodec/eac3enc.c | 61 +++++++++++++++++++++++++++++++++++++++++--- libavcodec/eac3enc.h | 10 ++++++++ 5 files changed, 106 insertions(+), 10 deletions(-) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 2c52c8d453..26800b3851 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -124,7 +124,7 @@ OBJS-$(CONFIG_DVVIDEO_ENCODER) += dv.o dvdata.o OBJS-$(CONFIG_DXA_DECODER) += dxa.o OBJS-$(CONFIG_EAC3_DECODER) += eac3dec.o eac3_data.o OBJS-$(CONFIG_EAC3_ENCODER) += eac3enc.o ac3enc.o ac3enc_float.o \ - ac3tab.o ac3.o kbdwin.o + ac3tab.o ac3.o kbdwin.o eac3_data.o OBJS-$(CONFIG_EACMV_DECODER) += eacmv.o OBJS-$(CONFIG_EAMAD_DECODER) += eamad.o eaidct.o mpeg12.o \ mpeg12data.o mpegvideo.o \ diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index fb4d33441e..e7a5b1611e 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -194,6 +194,7 @@ void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s) { int blk, ch; int got_cpl_snr; + int num_cpl_blocks; /* set coupling use flags for each block/channel */ /* TODO: turn coupling on/off and adjust start band based on bit usage */ @@ -206,12 +207,14 @@ void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s) /* enable coupling for each block if at least 2 channels have coupling enabled for that block */ got_cpl_snr = 0; + num_cpl_blocks = 0; for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { AC3Block *block = &s->blocks[blk]; block->num_cpl_channels = 0; for (ch = 1; ch <= s->fbw_channels; ch++) block->num_cpl_channels += block->channel_in_cpl[ch]; block->cpl_in_use = block->num_cpl_channels > 1; + num_cpl_blocks += block->cpl_in_use; if (!block->cpl_in_use) { block->num_cpl_channels = 0; for (ch = 1; ch <= s->fbw_channels; ch++) @@ -237,6 +240,8 @@ void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s) block->new_snr_offsets = 0; } } + if (!num_cpl_blocks) + s->cpl_on = 0; /* set bandwidth for each channel */ for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { @@ -301,6 +306,9 @@ static av_cold void exponent_init(AC3EncodeContext *s) } /* LFE */ exponent_group_tab[0][0][7] = 2; + + if (CONFIG_EAC3_ENCODER && s->eac3) + ff_eac3_exponent_init(); } @@ -342,8 +350,15 @@ static void compute_exp_strategy(AC3EncodeContext *s) exp_strategy[0] = EXP_NEW; exp += AC3_MAX_COEFS; for (blk = 1; blk < AC3_MAX_BLOCKS; blk++, exp += AC3_MAX_COEFS) { - if ((ch == CPL_CH && (!s->blocks[blk].cpl_in_use || !s->blocks[blk-1].cpl_in_use)) || - (ch > CPL_CH && (s->blocks[blk].channel_in_cpl[ch] != s->blocks[blk-1].channel_in_cpl[ch]))) { + if (ch == CPL_CH) { + if (!s->blocks[blk-1].cpl_in_use) { + exp_strategy[blk] = EXP_NEW; + continue; + } else if (!s->blocks[blk].cpl_in_use) { + exp_strategy[blk] = EXP_REUSE; + continue; + } + } else if (s->blocks[blk].channel_in_cpl[ch] != s->blocks[blk-1].channel_in_cpl[ch]) { exp_strategy[blk] = EXP_NEW; continue; } @@ -377,6 +392,10 @@ static void compute_exp_strategy(AC3EncodeContext *s) for (blk = 1; blk < AC3_MAX_BLOCKS; blk++) s->exp_strategy[ch][blk] = EXP_REUSE; } + + /* for E-AC-3, determine frame exponent strategy */ + if (CONFIG_EAC3_ENCODER && s->eac3) + ff_eac3_get_frame_exp_strategy(s); } @@ -611,8 +630,12 @@ static void count_frame_bits_fixed(AC3EncodeContext *s) frame_bits += 2; frame_bits += 10; /* exponent strategy */ - for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) - frame_bits += 2 * s->fbw_channels + s->lfe_on; + if (s->use_frame_exp_strategy) + frame_bits += 5 * s->fbw_channels; + else + frame_bits += AC3_MAX_BLOCKS * 2 * s->fbw_channels; + if (s->lfe_on) + frame_bits += AC3_MAX_BLOCKS; /* converter exponent strategy */ frame_bits += s->fbw_channels * 5; /* snr offsets */ @@ -735,8 +758,14 @@ static void count_frame_bits(AC3EncodeContext *s) } } /* coupling exponent strategy */ - for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) - frame_bits += 2 * s->blocks[blk].cpl_in_use; + if (s->cpl_on) { + if (s->use_frame_exp_strategy) { + frame_bits += 5 * s->cpl_on; + } else { + for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) + frame_bits += 2 * s->blocks[blk].cpl_in_use; + } + } } else { if (opt->audio_production_info) frame_bits += 7; diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h index 6caf4d80c4..a4a8fd4325 100644 --- a/libavcodec/ac3enc.h +++ b/libavcodec/ac3enc.h @@ -217,6 +217,8 @@ typedef struct AC3EncodeContext { uint8_t *cpl_coord_mant_buffer; uint8_t exp_strategy[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< exponent strategies + uint8_t frame_exp_strategy[AC3_MAX_CHANNELS]; ///< frame exp strategy index + int use_frame_exp_strategy; ///< indicates use of frame exp strategy uint8_t exp_ref_block[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< reference blocks for EXP_REUSE uint8_t *ref_bap [AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< bit allocation pointers (bap) int ref_bap_set; ///< indicates if ref_bap pointers have been set diff --git a/libavcodec/eac3enc.c b/libavcodec/eac3enc.c index 0433db49d7..153428fdfb 100644 --- a/libavcodec/eac3enc.c +++ b/libavcodec/eac3enc.c @@ -27,6 +27,7 @@ #define CONFIG_AC3ENC_FLOAT 1 #include "ac3enc.h" #include "eac3enc.h" +#include "eac3_data.h" #define AC3ENC_TYPE AC3ENC_TYPE_EAC3 @@ -35,6 +36,51 @@ static const AVClass eac3enc_class = { "E-AC-3 Encoder", av_default_item_name, eac3_options, LIBAVUTIL_VERSION_INT }; +/** + * LUT for finding a matching frame exponent strategy index from a set of + * exponent strategies for a single channel across all 6 blocks. + */ +static int8_t eac3_frame_expstr_index_tab[3][4][4][4][4][4]; + + +void ff_eac3_exponent_init(void) +{ + int i; + + memset(eac3_frame_expstr_index_tab, -1, sizeof(eac3_frame_expstr_index_tab)); + for (i = 0; i < 32; i++) { + eac3_frame_expstr_index_tab[ff_eac3_frm_expstr[i][0]-1] + [ff_eac3_frm_expstr[i][1]] + [ff_eac3_frm_expstr[i][2]] + [ff_eac3_frm_expstr[i][3]] + [ff_eac3_frm_expstr[i][4]] + [ff_eac3_frm_expstr[i][5]] = i; + } +} + + +void ff_eac3_get_frame_exp_strategy(AC3EncodeContext *s) +{ + int ch; + + s->use_frame_exp_strategy = 1; + for (ch = !s->cpl_on; ch <= s->fbw_channels; ch++) { + int expstr = eac3_frame_expstr_index_tab[s->exp_strategy[ch][0]-1] + [s->exp_strategy[ch][1]] + [s->exp_strategy[ch][2]] + [s->exp_strategy[ch][3]] + [s->exp_strategy[ch][4]] + [s->exp_strategy[ch][5]]; + if (expstr < 0) { + s->use_frame_exp_strategy = 0; + break; + } + s->frame_exp_strategy[ch] = expstr; + } +} + + + void ff_eac3_set_cpl_states(AC3EncodeContext *s) { int ch, blk; @@ -98,7 +144,7 @@ void ff_eac3_output_frame_header(AC3EncodeContext *s) put_bits(&s->pb, 1, 0); /* no additional bit stream info */ /* frame header */ - put_bits(&s->pb, 1, 1); /* exponent strategy syntax = each block */ + put_bits(&s->pb, 1, !s->use_frame_exp_strategy);/* exponent strategy syntax */ put_bits(&s->pb, 1, 0); /* aht enabled = no */ put_bits(&s->pb, 2, 0); /* snr offset strategy = 1 */ put_bits(&s->pb, 1, 0); /* transient pre-noise processing enabled = no */ @@ -120,16 +166,25 @@ void ff_eac3_output_frame_header(AC3EncodeContext *s) } } /* exponent strategy */ + if (s->use_frame_exp_strategy) { + for (ch = !s->cpl_on; ch <= s->fbw_channels; ch++) + put_bits(&s->pb, 5, s->frame_exp_strategy[ch]); + } else { for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) for (ch = !s->blocks[blk].cpl_in_use; ch <= s->fbw_channels; ch++) put_bits(&s->pb, 2, s->exp_strategy[ch][blk]); + } if (s->lfe_on) { for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) put_bits(&s->pb, 1, s->exp_strategy[s->lfe_channel][blk]); } /* E-AC-3 to AC-3 converter exponent strategy (unfortunately not optional...) */ - for (ch = 1; ch <= s->fbw_channels; ch++) - put_bits(&s->pb, 5, 0); + for (ch = 1; ch <= s->fbw_channels; ch++) { + if (s->use_frame_exp_strategy) + put_bits(&s->pb, 5, s->frame_exp_strategy[ch]); + else + put_bits(&s->pb, 5, 0); + } /* snr offsets */ put_bits(&s->pb, 6, s->coarse_snr_offset); put_bits(&s->pb, 4, s->fine_snr_offset[1]); diff --git a/libavcodec/eac3enc.h b/libavcodec/eac3enc.h index eacb8cf164..a92a24c2fa 100644 --- a/libavcodec/eac3enc.h +++ b/libavcodec/eac3enc.h @@ -29,6 +29,16 @@ #include "ac3enc.h" +/** + * Initialize E-AC-3 exponent tables. + */ +void ff_eac3_exponent_init(void); + +/** + * Determine frame exponent strategy use and indices. + */ +void ff_eac3_get_frame_exp_strategy(AC3EncodeContext *s); + /** * Set coupling states. * This determines whether certain flags must be written to the bitstream or From 953302656aaaeb1bc737b59fae2d5a11b75d9f7d Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 13 Jul 2011 12:49:15 -0400 Subject: [PATCH 4/9] cosmetics: indentation --- libavcodec/eac3enc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/eac3enc.c b/libavcodec/eac3enc.c index 153428fdfb..09fa80fcb9 100644 --- a/libavcodec/eac3enc.c +++ b/libavcodec/eac3enc.c @@ -170,9 +170,9 @@ void ff_eac3_output_frame_header(AC3EncodeContext *s) for (ch = !s->cpl_on; ch <= s->fbw_channels; ch++) put_bits(&s->pb, 5, s->frame_exp_strategy[ch]); } else { - for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) - for (ch = !s->blocks[blk].cpl_in_use; ch <= s->fbw_channels; ch++) - put_bits(&s->pb, 2, s->exp_strategy[ch][blk]); + for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) + for (ch = !s->blocks[blk].cpl_in_use; ch <= s->fbw_channels; ch++) + put_bits(&s->pb, 2, s->exp_strategy[ch][blk]); } if (s->lfe_on) { for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) From 69619a13c3fef940cba545cf0a283ff22771dd71 Mon Sep 17 00:00:00 2001 From: Chris Evans Date: Tue, 19 Jul 2011 17:51:48 -0700 Subject: [PATCH 5/9] matroskadec: fix integer underflow if header length < probe length. This fixes a crash with specifically crafted files. Signed-off-by: Ronald S. Bultje --- libavformat/matroskadec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 852760cc4d..037997742c 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -903,6 +903,8 @@ static int matroska_probe(AVProbeData *p) * Not fully fool-proof, but good enough. */ for (i = 0; i < FF_ARRAY_ELEMS(matroska_doctypes); i++) { int probelen = strlen(matroska_doctypes[i]); + if (total < probelen) + continue; for (n = 4+size; n <= 4+size+total-probelen; n++) if (!memcmp(p->buf+n, matroska_doctypes[i], probelen)) return AVPROBE_SCORE_MAX; From e23a05ab0605693aa715b95120bc0132079ded06 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Wed, 20 Jul 2011 09:55:48 +0100 Subject: [PATCH 6/9] Fix incorrect max_lowres values Signed-off-by: Mans Rullgard --- libavcodec/cdgraphics.c | 1 - libavcodec/kgv1dec.c | 1 - libavcodec/pngdec.c | 1 - libavcodec/pnmdec.c | 5 ----- libavcodec/sp5xdec.c | 2 +- 5 files changed, 1 insertion(+), 9 deletions(-) diff --git a/libavcodec/cdgraphics.c b/libavcodec/cdgraphics.c index 9e3f19a5f7..6493709aaf 100644 --- a/libavcodec/cdgraphics.c +++ b/libavcodec/cdgraphics.c @@ -377,6 +377,5 @@ AVCodec ff_cdgraphics_decoder = { cdg_decode_end, cdg_decode_frame, CODEC_CAP_DR1, - .max_lowres = 5, .long_name = NULL_IF_CONFIG_SMALL("CD Graphics video"), }; diff --git a/libavcodec/kgv1dec.c b/libavcodec/kgv1dec.c index 57684340af..88c54bf817 100644 --- a/libavcodec/kgv1dec.c +++ b/libavcodec/kgv1dec.c @@ -173,6 +173,5 @@ AVCodec ff_kgv1_decoder = { NULL, decode_end, decode_frame, - .max_lowres = 1, .long_name = NULL_IF_CONFIG_SMALL("Kega Game Video"), }; diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index 7477f6746b..1268c9e781 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -667,6 +667,5 @@ AVCodec ff_png_decoder = { decode_frame, CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/, NULL, - .max_lowres = 5, .long_name = NULL_IF_CONFIG_SMALL("PNG image"), }; diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c index b9f20c0569..988ea0c267 100644 --- a/libavcodec/pnmdec.c +++ b/libavcodec/pnmdec.c @@ -199,7 +199,6 @@ AVCodec ff_pgm_decoder = { pnm_decode_frame, CODEC_CAP_DR1, .pix_fmts = (const enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, PIX_FMT_NONE}, - .max_lowres = 5, .long_name = NULL_IF_CONFIG_SMALL("PGM (Portable GrayMap) image"), }; #endif @@ -216,7 +215,6 @@ AVCodec ff_pgmyuv_decoder = { pnm_decode_frame, CODEC_CAP_DR1, .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, - .max_lowres = 5, .long_name = NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"), }; #endif @@ -233,7 +231,6 @@ AVCodec ff_ppm_decoder = { pnm_decode_frame, CODEC_CAP_DR1, .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB48BE, PIX_FMT_NONE}, - .max_lowres = 5, .long_name = NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"), }; #endif @@ -250,7 +247,6 @@ AVCodec ff_pbm_decoder = { pnm_decode_frame, CODEC_CAP_DR1, .pix_fmts = (const enum PixelFormat[]){PIX_FMT_MONOWHITE, PIX_FMT_NONE}, - .max_lowres = 5, .long_name = NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"), }; #endif @@ -267,7 +263,6 @@ AVCodec ff_pam_decoder = { pnm_decode_frame, CODEC_CAP_DR1, .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_GRAY8, PIX_FMT_MONOWHITE, PIX_FMT_NONE}, - .max_lowres = 5, .long_name = NULL_IF_CONFIG_SMALL("PAM (Portable AnyMap) image"), }; #endif diff --git a/libavcodec/sp5xdec.c b/libavcodec/sp5xdec.c index 6726c18ca9..ae25733530 100644 --- a/libavcodec/sp5xdec.c +++ b/libavcodec/sp5xdec.c @@ -104,7 +104,7 @@ AVCodec ff_sp5x_decoder = { sp5x_decode_frame, CODEC_CAP_DR1, NULL, - .max_lowres = 5, + .max_lowres = 3, .long_name = NULL_IF_CONFIG_SMALL("Sunplus JPEG (SP5X)"), }; From 1b4a17094ebdc605a9414d4d98653a1bfb0ea0a4 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Sun, 17 Jul 2011 13:09:04 +0200 Subject: [PATCH 7/9] h264: remove some disabled code --- libavcodec/h264.c | 149 ---------------------------------------------- 1 file changed, 149 deletions(-) diff --git a/libavcodec/h264.c b/libavcodec/h264.c index cbeeb07425..5adce242ce 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -3459,52 +3459,6 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){ } } } - -#if 0 - for(;s->mb_y < s->mb_height; s->mb_y++){ - for(;s->mb_x < s->mb_width; s->mb_x++){ - int ret= decode_mb(h); - - ff_h264_hl_decode_mb(h); - - if(ret<0){ - av_log(s->avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y); - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); - - return -1; - } - - if(++s->mb_x >= s->mb_width){ - s->mb_x=0; - if(++s->mb_y >= s->mb_height){ - if(get_bits_count(s->gb) == s->gb.size_in_bits){ - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); - - return 0; - }else{ - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); - - return -1; - } - } - } - - if(get_bits_count(s->?gb) >= s->gb?.size_in_bits){ - if(get_bits_count(s->gb) == s->gb.size_in_bits){ - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); - - return 0; - }else{ - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); - - return -1; - } - } - } - s->mb_x=0; - ff_draw_horiz_band(s, 16*s->mb_y, 16); - } -#endif } /** @@ -3971,109 +3925,6 @@ int main(void){ STOP_TIMER("get_se_golomb"); } -#if 0 - printf("testing 4x4 (I)DCT\n"); - - DCTELEM block[16]; - uint8_t src[16], ref[16]; - uint64_t error= 0, max_error=0; - - for(i=0; ih264dsp.h264_idct_add(ref, block, 4); -/* for(j=0; j<16; j++){ - printf("%d ", ref[j]); - } - printf("\n");*/ - - for(j=0; j<16; j++){ - int diff= FFABS(src[j] - ref[j]); - - error+= diff*diff; - max_error= FFMAX(max_error, diff); - } - } - printf("error=%f max_error=%d\n", ((float)error)/COUNT/16, (int)max_error ); - printf("testing quantizer\n"); - for(qp=0; qp<52; qp++){ - for(i=0; i<16; i++) - src1_block[i]= src2_block[i]= random()%255; - - } - printf("Testing NAL layer\n"); - - uint8_t bitstream[COUNT]; - uint8_t nal[COUNT*2]; - H264Context h; - memset(&h, 0, sizeof(H264Context)); - - for(i=0; i Date: Sun, 17 Jul 2011 20:43:15 +0100 Subject: [PATCH 8/9] Remove snow/dwt test program This test program so full of programming errors it is impossible to make sense of it. Signed-off-by: Mans Rullgard --- libavcodec/Makefile | 2 +- libavcodec/snow.c | 121 -------------------------------------------- 2 files changed, 1 insertion(+), 122 deletions(-) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 26800b3851..f23ade2734 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -667,7 +667,7 @@ SKIPHEADERS-$(CONFIG_XVMC) += xvmc.h EXAMPLES = api -TESTPROGS = cabac dct fft fft-fixed h264 iirfilter rangecoder snow +TESTPROGS = cabac dct fft fft-fixed h264 iirfilter rangecoder TESTPROGS-$(HAVE_MMX) += motion TESTOBJS = dctref.o diff --git a/libavcodec/snow.c b/libavcodec/snow.c index e1f6c57352..3162e5cf98 100644 --- a/libavcodec/snow.c +++ b/libavcodec/snow.c @@ -3689,124 +3689,3 @@ AVCodec ff_snow_encoder = { .long_name = NULL_IF_CONFIG_SMALL("Snow"), }; #endif - - -#ifdef TEST -#undef malloc -#undef free -#undef printf - -#include "libavutil/lfg.h" -#include "libavutil/mathematics.h" - -int main(void){ - int width=256; - int height=256; - int buffer[2][width*height]; - SnowContext s; - int i; - AVLFG prng; - s.spatial_decomposition_count=6; - s.spatial_decomposition_type=1; - - av_lfg_init(&prng, 1); - - printf("testing 5/3 DWT\n"); - for(i=0; i20) printf("fsck: %6d %12d %7d\n",i, buffer[0][i], buffer[1][i]); - - { - int level, orientation, x, y; - int64_t errors[8][4]; - int64_t g=0; - - memset(errors, 0, sizeof(errors)); - s.spatial_decomposition_count=3; - s.spatial_decomposition_type=0; - for(level=0; level> (s.spatial_decomposition_count-level); - int h= height >> (s.spatial_decomposition_count-level); - int stride= width << (s.spatial_decomposition_count-level); - DWTELEM *buf= buffer[0]; - int64_t error=0; - - if(orientation&1) buf+=w; - if(orientation>1) buf+=stride>>1; - - memset(buffer[0], 0, sizeof(int)*width*height); - buf[w/2 + h/2*stride]= 256*256; - ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count); - for(y=0; y> (s.spatial_decomposition_count-level); - //int h= height >> (s.spatial_decomposition_count-level); - int stride= width << (s.spatial_decomposition_count-level); - DWTELEM *buf= buffer[0]; - int64_t error=0; - - buf+=w; - buf+=stride>>1; - - memset(buffer[0], 0, sizeof(int)*width*height); - for(y=0; y Date: Wed, 20 Jul 2011 09:46:18 +0100 Subject: [PATCH 9/9] Remove h264_lowres_idct_put/add functions Use of these has been broken ever since the h264 idct was changed to always use transposed inputs. Furthermore, they were only ever used if some *other* non-default idct was requested. Signed-off-by: Mans Rullgard --- libavcodec/dsputil.c | 25 ++-------------- libavcodec/dsputil.h | 2 -- libavcodec/h264idct_template.c | 53 ++++++++++++++-------------------- 3 files changed, 23 insertions(+), 57 deletions(-) diff --git a/libavcodec/dsputil.c b/libavcodec/dsputil.c index a3e8d6cd95..e2cf708940 100644 --- a/libavcodec/dsputil.c +++ b/libavcodec/dsputil.c @@ -2863,29 +2863,8 @@ av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx) #endif //CONFIG_ENCODERS if(avctx->lowres==1){ - if(avctx->idct_algo==FF_IDCT_INT || avctx->idct_algo==FF_IDCT_AUTO || !CONFIG_H264_DECODER){ - c->idct_put= ff_jref_idct4_put; - c->idct_add= ff_jref_idct4_add; - }else{ - if (avctx->codec_id != CODEC_ID_H264) { - c->idct_put= ff_h264_lowres_idct_put_8_c; - c->idct_add= ff_h264_lowres_idct_add_8_c; - } else { - switch (avctx->bits_per_raw_sample) { - case 9: - c->idct_put= ff_h264_lowres_idct_put_9_c; - c->idct_add= ff_h264_lowres_idct_add_9_c; - break; - case 10: - c->idct_put= ff_h264_lowres_idct_put_10_c; - c->idct_add= ff_h264_lowres_idct_add_10_c; - break; - default: - c->idct_put= ff_h264_lowres_idct_put_8_c; - c->idct_add= ff_h264_lowres_idct_add_8_c; - } - } - } + c->idct_put= ff_jref_idct4_put; + c->idct_add= ff_jref_idct4_add; c->idct = j_rev_dct4; c->idct_permutation_type= FF_NO_IDCT_PERM; }else if(avctx->lowres==2){ diff --git a/libavcodec/dsputil.h b/libavcodec/dsputil.h index 5a97b442ad..8cd3af60ca 100644 --- a/libavcodec/dsputil.h +++ b/libavcodec/dsputil.h @@ -58,8 +58,6 @@ void ff_h264_idct8_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride) void ff_h264_idct_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\ void ff_h264_idct8_dc_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\ void ff_h264_idct_dc_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\ -void ff_h264_lowres_idct_add_ ## depth ## _c(uint8_t *dst, int stride, DCTELEM *block);\ -void ff_h264_lowres_idct_put_ ## depth ## _c(uint8_t *dst, int stride, DCTELEM *block);\ void ff_h264_idct_add16_ ## depth ## _c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\ void ff_h264_idct_add16intra_ ## depth ## _c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\ void ff_h264_idct8_add4_ ## depth ## _c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\ diff --git a/libavcodec/h264idct_template.c b/libavcodec/h264idct_template.c index 55c1d3a4d8..ba5571576d 100644 --- a/libavcodec/h264idct_template.c +++ b/libavcodec/h264idct_template.c @@ -46,52 +46,41 @@ static const uint8_t scan8[16*3]={ }; #endif -static av_always_inline void FUNCC(idct_internal)(uint8_t *_dst, DCTELEM *_block, int stride, int block_stride, int shift, int add){ +void FUNCC(ff_h264_idct_add)(uint8_t *_dst, DCTELEM *_block, int stride) +{ int i; INIT_CLIP pixel *dst = (pixel*)_dst; dctcoef *block = (dctcoef*)_block; stride /= sizeof(pixel); - block[0] += 1<<(shift-1); + block[0] += 1 << 5; for(i=0; i<4; i++){ - const int z0= block[i + block_stride*0] + block[i + block_stride*2]; - const int z1= block[i + block_stride*0] - block[i + block_stride*2]; - const int z2= (block[i + block_stride*1]>>1) - block[i + block_stride*3]; - const int z3= block[i + block_stride*1] + (block[i + block_stride*3]>>1); + const int z0= block[i + 4*0] + block[i + 4*2]; + const int z1= block[i + 4*0] - block[i + 4*2]; + const int z2= (block[i + 4*1]>>1) - block[i + 4*3]; + const int z3= block[i + 4*1] + (block[i + 4*3]>>1); - block[i + block_stride*0]= z0 + z3; - block[i + block_stride*1]= z1 + z2; - block[i + block_stride*2]= z1 - z2; - block[i + block_stride*3]= z0 - z3; + block[i + 4*0]= z0 + z3; + block[i + 4*1]= z1 + z2; + block[i + 4*2]= z1 - z2; + block[i + 4*3]= z0 - z3; } for(i=0; i<4; i++){ - const int z0= block[0 + block_stride*i] + block[2 + block_stride*i]; - const int z1= block[0 + block_stride*i] - block[2 + block_stride*i]; - const int z2= (block[1 + block_stride*i]>>1) - block[3 + block_stride*i]; - const int z3= block[1 + block_stride*i] + (block[3 + block_stride*i]>>1); + const int z0= block[0 + 4*i] + block[2 + 4*i]; + const int z1= block[0 + 4*i] - block[2 + 4*i]; + const int z2= (block[1 + 4*i]>>1) - block[3 + 4*i]; + const int z3= block[1 + 4*i] + (block[3 + 4*i]>>1); - dst[i + 0*stride]= CLIP(add*dst[i + 0*stride] + ((z0 + z3) >> shift)); - dst[i + 1*stride]= CLIP(add*dst[i + 1*stride] + ((z1 + z2) >> shift)); - dst[i + 2*stride]= CLIP(add*dst[i + 2*stride] + ((z1 - z2) >> shift)); - dst[i + 3*stride]= CLIP(add*dst[i + 3*stride] + ((z0 - z3) >> shift)); + dst[i + 0*stride]= CLIP(dst[i + 0*stride] + ((z0 + z3) >> 6)); + dst[i + 1*stride]= CLIP(dst[i + 1*stride] + ((z1 + z2) >> 6)); + dst[i + 2*stride]= CLIP(dst[i + 2*stride] + ((z1 - z2) >> 6)); + dst[i + 3*stride]= CLIP(dst[i + 3*stride] + ((z0 - z3) >> 6)); } } -void FUNCC(ff_h264_idct_add)(uint8_t *dst, DCTELEM *block, int stride){ - FUNCC(idct_internal)(dst, block, stride, 4, 6, 1); -} - -void FUNCC(ff_h264_lowres_idct_add)(uint8_t *dst, int stride, DCTELEM *block){ - FUNCC(idct_internal)(dst, block, stride, 8, 3, 1); -} - -void FUNCC(ff_h264_lowres_idct_put)(uint8_t *dst, int stride, DCTELEM *block){ - FUNCC(idct_internal)(dst, block, stride, 8, 3, 0); -} - void FUNCC(ff_h264_idct8_add)(uint8_t *_dst, DCTELEM *_block, int stride){ int i; INIT_CLIP @@ -200,7 +189,7 @@ void FUNCC(ff_h264_idct_add16)(uint8_t *dst, const int *block_offset, DCTELEM *b int nnz = nnzc[ scan8[i] ]; if(nnz){ if(nnz==1 && ((dctcoef*)block)[i*16]) FUNCC(ff_h264_idct_dc_add)(dst + block_offset[i], block + i*16*sizeof(pixel), stride); - else FUNCC(idct_internal )(dst + block_offset[i], block + i*16*sizeof(pixel), stride, 4, 6, 1); + else FUNCC(ff_h264_idct_add )(dst + block_offset[i], block + i*16*sizeof(pixel), stride); } } } @@ -208,7 +197,7 @@ void FUNCC(ff_h264_idct_add16)(uint8_t *dst, const int *block_offset, DCTELEM *b void FUNCC(ff_h264_idct_add16intra)(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){ int i; for(i=0; i<16; i++){ - if(nnzc[ scan8[i] ]) FUNCC(idct_internal )(dst + block_offset[i], block + i*16*sizeof(pixel), stride, 4, 6, 1); + if(nnzc[ scan8[i] ]) FUNCC(ff_h264_idct_add )(dst + block_offset[i], block + i*16*sizeof(pixel), stride); else if(((dctcoef*)block)[i*16]) FUNCC(ff_h264_idct_dc_add)(dst + block_offset[i], block + i*16*sizeof(pixel), stride); } }