diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2011-03-15 16:18:40 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-03-15 16:48:42 +0100 |
commit | 6947b0c42e0649f0c8355442d1732d642e467902 (patch) | |
tree | bffb2d72049108372cbe46273998f3790dc860f0 /libavcodec | |
parent | 27293b840ccae95ddb1f4d8af519e7962b0e373d (diff) | |
parent | c76374c6db5f486672f9df223f43e4892bd655c9 (diff) | |
download | ffmpeg-6947b0c42e0649f0c8355442d1732d642e467902.tar.gz |
Merge remote-tracking branch 'newdev/master'
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/ac3dsp.c | 37 | ||||
-rw-r--r-- | libavcodec/ac3dsp.h | 22 | ||||
-rw-r--r-- | libavcodec/ac3enc.c | 25 | ||||
-rw-r--r-- | libavcodec/ac3enc_fixed.c | 52 | ||||
-rw-r--r-- | libavcodec/ac3enc_fixed.h | 2 | ||||
-rw-r--r-- | libavcodec/ac3enc_float.h | 2 | ||||
-rw-r--r-- | libavcodec/h264_mp4toannexb_bsf.c | 5 | ||||
-rw-r--r-- | libavcodec/vp8.c | 2 | ||||
-rw-r--r-- | libavcodec/x86/ac3dsp.asm | 45 | ||||
-rw-r--r-- | libavcodec/x86/ac3dsp_mmx.c | 12 |
10 files changed, 158 insertions, 46 deletions
diff --git a/libavcodec/ac3dsp.c b/libavcodec/ac3dsp.c index da3a123e9b..4d9db9be50 100644 --- a/libavcodec/ac3dsp.c +++ b/libavcodec/ac3dsp.c @@ -50,10 +50,47 @@ static int ac3_max_msb_abs_int16_c(const int16_t *src, int len) return v; } +static void ac3_lshift_int16_c(int16_t *src, unsigned int len, + unsigned int shift) +{ + uint32_t *src32 = (uint32_t *)src; + const uint32_t mask = ~(((1 << shift) - 1) << 16); + int i; + len >>= 1; + for (i = 0; i < len; i += 8) { + src32[i ] = (src32[i ] << shift) & mask; + src32[i+1] = (src32[i+1] << shift) & mask; + src32[i+2] = (src32[i+2] << shift) & mask; + src32[i+3] = (src32[i+3] << shift) & mask; + src32[i+4] = (src32[i+4] << shift) & mask; + src32[i+5] = (src32[i+5] << shift) & mask; + src32[i+6] = (src32[i+6] << shift) & mask; + src32[i+7] = (src32[i+7] << shift) & mask; + } +} + +static void ac3_rshift_int32_c(int32_t *src, unsigned int len, + unsigned int shift) +{ + do { + *src++ >>= shift; + *src++ >>= shift; + *src++ >>= shift; + *src++ >>= shift; + *src++ >>= shift; + *src++ >>= shift; + *src++ >>= shift; + *src++ >>= shift; + len -= 8; + } while (len > 0); +} + av_cold void ff_ac3dsp_init(AC3DSPContext *c) { c->ac3_exponent_min = ac3_exponent_min_c; c->ac3_max_msb_abs_int16 = ac3_max_msb_abs_int16_c; + c->ac3_lshift_int16 = ac3_lshift_int16_c; + c->ac3_rshift_int32 = ac3_rshift_int32_c; if (HAVE_MMX) ff_ac3dsp_init_x86(c); diff --git a/libavcodec/ac3dsp.h b/libavcodec/ac3dsp.h index a4f141f2f5..31a0af375d 100644 --- a/libavcodec/ac3dsp.h +++ b/libavcodec/ac3dsp.h @@ -46,6 +46,28 @@ typedef struct AC3DSPContext { * @return a value with the same MSB as max(abs(src[])) */ int (*ac3_max_msb_abs_int16)(const int16_t *src, int len); + + /** + * Left-shift each value in an array of int16_t by a specified amount. + * @param src input array + * constraints: align 16 + * @param len number of values in the array + * constraints: multiple of 32 greater than 0 + * @param shift left shift amount + * constraints: range [0,15] + */ + void (*ac3_lshift_int16)(int16_t *src, unsigned int len, unsigned int shift); + + /** + * Right-shift each value in an array of int32_t by a specified amount. + * @param src input array + * constraints: align 16 + * @param len number of values in the array + * constraints: multiple of 16 greater than 0 + * @param shift right shift amount + * constraints: range [0,31] + */ + void (*ac3_rshift_int32)(int32_t *src, unsigned int len, unsigned int shift); } AC3DSPContext; void ff_ac3dsp_init (AC3DSPContext *c); diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index baa9597977..4c01fe3cbd 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -78,7 +78,7 @@ typedef struct AC3Block { int16_t **band_psd; ///< psd per critical band int16_t **mask; ///< masking curve uint16_t **qmant; ///< quantized mantissas - int8_t exp_shift[AC3_MAX_CHANNELS]; ///< exponent shift values + uint8_t coeff_shift[AC3_MAX_CHANNELS]; ///< fixed-point coefficient shift values uint8_t new_rematrixing_strategy; ///< send new rematrixing flags in this block uint8_t rematrixing_flags[4]; ///< rematrixing flags } AC3Block; @@ -269,7 +269,7 @@ static void apply_mdct(AC3EncodeContext *s) apply_window(&s->dsp, s->windowed_samples, input_samples, s->mdct.window, AC3_WINDOW_SIZE); - block->exp_shift[ch] = normalize_samples(s); + block->coeff_shift[ch] = normalize_samples(s); mdct512(&s->mdct, block->mdct_coef[ch], s->windowed_samples); } @@ -328,10 +328,10 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s) CoefType rt = block->mdct_coef[1][i]; CoefType md = lt + rt; CoefType sd = lt - rt; - sum[0] += lt * lt; - sum[1] += rt * rt; - sum[2] += md * md; - sum[3] += sd * sd; + MAC_COEF(sum[0], lt, lt); + MAC_COEF(sum[1], rt, rt); + MAC_COEF(sum[2], md, md); + MAC_COEF(sum[3], sd, sd); } /* compare sums to determine if rematrixing will be used for this band */ @@ -416,14 +416,13 @@ static void extract_exponents(AC3EncodeContext *s) AC3Block *block = &s->blocks[blk]; uint8_t *exp = block->exp[ch]; int32_t *coef = block->fixed_coef[ch]; - int exp_shift = block->exp_shift[ch]; for (i = 0; i < AC3_MAX_COEFS; i++) { int e; int v = abs(coef[i]); if (v == 0) e = 24; else { - e = 23 - av_log2(v) + exp_shift; + e = 23 - av_log2(v); if (e >= 24) { e = 24; coef[i] = 0; @@ -1139,7 +1138,7 @@ static inline int asym_quant(int c, int e, int qbits) * Quantize a set of mantissas for a single channel in a single block. */ static void quantize_mantissas_blk_ch(AC3EncodeContext *s, int32_t *fixed_coef, - int8_t exp_shift, uint8_t *exp, + uint8_t *exp, uint8_t *bap, uint16_t *qmant, int n) { int i; @@ -1147,7 +1146,7 @@ static void quantize_mantissas_blk_ch(AC3EncodeContext *s, int32_t *fixed_coef, for (i = 0; i < n; i++) { int v; int c = fixed_coef[i]; - int e = exp[i] - exp_shift; + int e = exp[i]; int b = bap[i]; switch (b) { case 0: @@ -1243,7 +1242,7 @@ static void quantize_mantissas(AC3EncodeContext *s) s->qmant1_ptr = s->qmant2_ptr = s->qmant4_ptr = NULL; for (ch = 0; ch < s->channels; ch++) { - quantize_mantissas_blk_ch(s, block->fixed_coef[ch], block->exp_shift[ch], + quantize_mantissas_blk_ch(s, block->fixed_coef[ch], block->exp[ch], block->bap[ch], block->qmant[ch], s->nb_coefs[ch]); } @@ -1507,10 +1506,10 @@ static int ac3_encode_frame(AVCodecContext *avctx, unsigned char *frame, apply_mdct(s); - compute_rematrixing_strategy(s); - scale_coefficients(s); + compute_rematrixing_strategy(s); + apply_rematrixing(s); process_exponents(s); diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c index 3de00ee484..d1bb429ccc 100644 --- a/libavcodec/ac3enc_fixed.c +++ b/libavcodec/ac3enc_fixed.c @@ -131,10 +131,10 @@ mdct_alloc_fail: /** Complex multiply */ -#define CMUL(pre, pim, are, aim, bre, bim) \ +#define CMUL(pre, pim, are, aim, bre, bim, rshift) \ { \ - pre = (MUL16(are, bre) - MUL16(aim, bim)) >> 15; \ - pim = (MUL16(are, bim) + MUL16(bre, aim)) >> 15; \ + pre = (MUL16(are, bre) - MUL16(aim, bim)) >> rshift; \ + pim = (MUL16(are, bim) + MUL16(bre, aim)) >> rshift; \ } @@ -195,7 +195,7 @@ static void fft(AC3MDCTContext *mdct, IComplex *z, int ln) p++; q++; for(l = nblocks; l < np2; l += nblocks) { - CMUL(tmp_re, tmp_im, mdct->costab[l], -mdct->sintab[l], q->re, q->im); + CMUL(tmp_re, tmp_im, mdct->costab[l], -mdct->sintab[l], q->re, q->im, 15); BF(p->re, p->im, q->re, q->im, p->re, p->im, tmp_re, tmp_im); p++; @@ -234,7 +234,7 @@ static void mdct512(AC3MDCTContext *mdct, int32_t *out, int16_t *in) for (i = 0; i < n4; i++) { re = ((int)rot[ 2*i] - (int)rot[ n-1-2*i]) >> 1; im = -((int)rot[n2+2*i] - (int)rot[n2-1-2*i]) >> 1; - CMUL(x[i].re, x[i].im, re, im, -mdct->xcos1[i], mdct->xsin1[i]); + CMUL(x[i].re, x[i].im, re, im, -mdct->xcos1[i], mdct->xsin1[i], 15); } fft(mdct, x, mdct->nbits - 2); @@ -243,7 +243,7 @@ static void mdct512(AC3MDCTContext *mdct, int32_t *out, int16_t *in) for (i = 0; i < n4; i++) { re = x[i].re; im = x[i].im; - CMUL(out[n2-1-2*i], out[2*i], re, im, mdct->xsin1[i], mdct->xcos1[i]); + CMUL(out[n2-1-2*i], out[2*i], re, im, mdct->xsin1[i], mdct->xcos1[i], 0); } } @@ -278,45 +278,35 @@ static int log2_tab(AC3EncodeContext *s, int16_t *src, int len) /** - * Left-shift each value in an array by a specified amount. - * @param tab input array - * @param n number of values in the array - * @param lshift left shift amount - */ -static void lshift_tab(int16_t *tab, int n, unsigned int lshift) -{ - int i; - - if (lshift > 0) { - for (i = 0; i < n; i++) - tab[i] <<= lshift; - } -} - - -/** * Normalize the input samples to use the maximum available precision. - * This assumes signed 16-bit input samples. Exponents are reduced by 9 to - * match the 24-bit internal precision for MDCT coefficients. + * This assumes signed 16-bit input samples. * * @return exponent shift */ static int normalize_samples(AC3EncodeContext *s) { int v = 14 - log2_tab(s, s->windowed_samples, AC3_WINDOW_SIZE); - lshift_tab(s->windowed_samples, AC3_WINDOW_SIZE, v); - return v - 9; + if (v > 0) + s->ac3dsp.ac3_lshift_int16(s->windowed_samples, AC3_WINDOW_SIZE, v); + /* +6 to right-shift from 31-bit to 25-bit */ + return v + 6; } /** - * Scale MDCT coefficients from float to fixed-point. + * Scale MDCT coefficients to 25-bit signed fixed-point. */ static void scale_coefficients(AC3EncodeContext *s) { - /* scaling/conversion is obviously not needed for the fixed-point encoder - since the coefficients are already fixed-point. */ - return; + int blk, ch; + + for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { + AC3Block *block = &s->blocks[blk]; + for (ch = 0; ch < s->channels; ch++) { + s->ac3dsp.ac3_rshift_int32(block->mdct_coef[ch], AC3_MAX_COEFS, + block->coeff_shift[ch]); + } + } } diff --git a/libavcodec/ac3enc_fixed.h b/libavcodec/ac3enc_fixed.h index 12c8ace4aa..bad2306321 100644 --- a/libavcodec/ac3enc_fixed.h +++ b/libavcodec/ac3enc_fixed.h @@ -36,6 +36,8 @@ typedef int16_t SampleType; typedef int32_t CoefType; typedef int64_t CoefSumType; +#define MAC_COEF(d,a,b) MAC64(d,a,b) + /** * Compex number. diff --git a/libavcodec/ac3enc_float.h b/libavcodec/ac3enc_float.h index 1726ca045f..a4702bb51a 100644 --- a/libavcodec/ac3enc_float.h +++ b/libavcodec/ac3enc_float.h @@ -36,6 +36,8 @@ typedef float SampleType; typedef float CoefType; typedef float CoefSumType; +#define MAC_COEF(d,a,b) ((d)+=(a)*(b)) + typedef struct AC3MDCTContext { const float *window; ///< MDCT window function diff --git a/libavcodec/h264_mp4toannexb_bsf.c b/libavcodec/h264_mp4toannexb_bsf.c index df49b34810..3754f2aee7 100644 --- a/libavcodec/h264_mp4toannexb_bsf.c +++ b/libavcodec/h264_mp4toannexb_bsf.c @@ -116,8 +116,11 @@ static int h264_mp4toannexb_filter(AVBitStreamFilterContext *bsfc, memcpy(out+total_size-unit_size, extradata+2, unit_size); extradata += 2+unit_size; - if (!unit_nb && !sps_done++) + if (!unit_nb && !sps_done++) { unit_nb = *extradata++; /* number of pps unit(s) */ + if (unit_nb) + pps_seen = 1; + } } if(out) diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c index 42f401d2b1..c067f4cf2f 100644 --- a/libavcodec/vp8.c +++ b/libavcodec/vp8.c @@ -695,7 +695,7 @@ skip_eob: static av_always_inline int decode_block_coeffs(VP56RangeCoder *c, DCTELEM block[16], - uint8_t probs[8][3][NUM_DCT_TOKENS-1], + uint8_t probs[16][3][NUM_DCT_TOKENS-1], int i, int zero_nhood, int16_t qmul[2]) { uint8_t *token_prob = probs[i][zero_nhood]; diff --git a/libavcodec/x86/ac3dsp.asm b/libavcodec/x86/ac3dsp.asm index b1eeca9cd2..e281791b1e 100644 --- a/libavcodec/x86/ac3dsp.asm +++ b/libavcodec/x86/ac3dsp.asm @@ -133,3 +133,48 @@ INIT_XMM AC3_MAX_MSB_ABS_INT16 sse2, min_max %define ABS2 ABS2_SSSE3 AC3_MAX_MSB_ABS_INT16 ssse3, or_abs + +;----------------------------------------------------------------------------- +; macro used for ff_ac3_lshift_int16() and ff_ac3_rshift_int32() +;----------------------------------------------------------------------------- + +%macro AC3_SHIFT 4 ; l/r, 16/32, shift instruction, instruction set +cglobal ac3_%1shift_int%2_%4, 3,3,5, src, len, shift + movd m0, shiftd +.loop: + mova m1, [srcq ] + mova m2, [srcq+mmsize ] + mova m3, [srcq+mmsize*2] + mova m4, [srcq+mmsize*3] + %3 m1, m0 + %3 m2, m0 + %3 m3, m0 + %3 m4, m0 + mova [srcq ], m1 + mova [srcq+mmsize ], m2 + mova [srcq+mmsize*2], m3 + mova [srcq+mmsize*3], m4 + add srcq, mmsize*4 + sub lend, mmsize*32/%2 + ja .loop +.end: + REP_RET +%endmacro + +;----------------------------------------------------------------------------- +; void ff_ac3_lshift_int16(int16_t *src, unsigned int len, unsigned int shift) +;----------------------------------------------------------------------------- + +INIT_MMX +AC3_SHIFT l, 16, psllw, mmx +INIT_XMM +AC3_SHIFT l, 16, psllw, sse2 + +;----------------------------------------------------------------------------- +; void ff_ac3_rshift_int32(int32_t *src, unsigned int len, unsigned int shift) +;----------------------------------------------------------------------------- + +INIT_MMX +AC3_SHIFT r, 32, psrad, mmx +INIT_XMM +AC3_SHIFT r, 32, psrad, sse2 diff --git a/libavcodec/x86/ac3dsp_mmx.c b/libavcodec/x86/ac3dsp_mmx.c index d8af59ce8d..835b10696d 100644 --- a/libavcodec/x86/ac3dsp_mmx.c +++ b/libavcodec/x86/ac3dsp_mmx.c @@ -32,6 +32,12 @@ extern int ff_ac3_max_msb_abs_int16_mmxext(const int16_t *src, int len); extern int ff_ac3_max_msb_abs_int16_sse2 (const int16_t *src, int len); extern int ff_ac3_max_msb_abs_int16_ssse3 (const int16_t *src, int len); +extern void ff_ac3_lshift_int16_mmx (int16_t *src, unsigned int len, unsigned int shift); +extern void ff_ac3_lshift_int16_sse2(int16_t *src, unsigned int len, unsigned int shift); + +extern void ff_ac3_rshift_int32_mmx (int32_t *src, unsigned int len, unsigned int shift); +extern void ff_ac3_rshift_int32_sse2(int32_t *src, unsigned int len, unsigned int shift); + av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c) { int mm_flags = av_get_cpu_flags(); @@ -40,6 +46,8 @@ av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c) if (mm_flags & AV_CPU_FLAG_MMX) { c->ac3_exponent_min = ff_ac3_exponent_min_mmx; c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_mmx; + c->ac3_lshift_int16 = ff_ac3_lshift_int16_mmx; + c->ac3_rshift_int32 = ff_ac3_rshift_int32_mmx; } if (mm_flags & AV_CPU_FLAG_MMX2 && HAVE_MMX2) { c->ac3_exponent_min = ff_ac3_exponent_min_mmxext; @@ -48,6 +56,10 @@ av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c) if (mm_flags & AV_CPU_FLAG_SSE2 && HAVE_SSE) { c->ac3_exponent_min = ff_ac3_exponent_min_sse2; c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_sse2; + if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) { + c->ac3_lshift_int16 = ff_ac3_lshift_int16_sse2; + c->ac3_rshift_int32 = ff_ac3_rshift_int32_sse2; + } } if (mm_flags & AV_CPU_FLAG_SSSE3 && HAVE_SSSE3) { c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_ssse3; |