Revision dda3f0ef

View differences:

libavcodec/Makefile
55 55
                                          mpeg4audio.o
56 56
OBJS-$(CONFIG_AASC_DECODER)            += aasc.o msrledec.o
57 57
OBJS-$(CONFIG_AC3_DECODER)             += ac3dec.o ac3dec_data.o ac3.o
58
OBJS-$(CONFIG_AC3_ENCODER)             += ac3enc_float.o ac3tab.o ac3.o
59
OBJS-$(CONFIG_AC3_FIXED_ENCODER)       += ac3enc_fixed.o ac3tab.o ac3.o
58
OBJS-$(CONFIG_AC3_ENCODER)             += ac3enc_float.o ac3tab.o ac3.o \
59
                                          ac3dsp.o
60
OBJS-$(CONFIG_AC3_FIXED_ENCODER)       += ac3enc_fixed.o ac3tab.o ac3.o \
61
                                          ac3dsp.o
60 62
OBJS-$(CONFIG_ALAC_DECODER)            += alac.o
61 63
OBJS-$(CONFIG_ALAC_ENCODER)            += alacenc.o
62 64
OBJS-$(CONFIG_ALS_DECODER)             += alsdec.o bgmc.o mpeg4audio.o
libavcodec/ac3dsp.c
1
/*
2
 * AC-3 DSP utils
3
 * Copyright (c) 2011 Justin Ruggles
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with FFmpeg; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21

  
22
#include "avcodec.h"
23
#include "ac3dsp.h"
24

  
25
static void ac3_exponent_min_c(uint8_t *exp, int num_reuse_blocks, int nb_coefs)
26
{
27
    int blk, i;
28

  
29
    if (!num_reuse_blocks)
30
        return;
31

  
32
    for (i = 0; i < nb_coefs; i++) {
33
        uint8_t min_exp = *exp;
34
        uint8_t *exp1 = exp + 256;
35
        for (blk = 0; blk < num_reuse_blocks; blk++) {
36
            uint8_t next_exp = *exp1;
37
            if (next_exp < min_exp)
38
                min_exp = next_exp;
39
            exp1 += 256;
40
        }
41
        *exp++ = min_exp;
42
    }
43
}
44

  
45
av_cold void ff_ac3dsp_init(AC3DSPContext *c)
46
{
47
    c->ac3_exponent_min = ac3_exponent_min_c;
48

  
49
    if (HAVE_MMX)
50
        ff_ac3dsp_init_x86(c);
51
}
libavcodec/ac3dsp.h
1
/*
2
 * AC-3 DSP utils
3
 * Copyright (c) 2011 Justin Ruggles
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with FFmpeg; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21

  
22
#ifndef AVCODEC_AC3DSP_H
23
#define AVCODEC_AC3DSP_H
24

  
25
#include <stdint.h>
26

  
27
typedef struct AC3DSPContext {
28
    /**
29
     * Set each encoded exponent in a block to the minimum of itself and the
30
     * exponents in the same frequency bin of up to 5 following blocks.
31
     * @param exp   pointer to the start of the current block of exponents.
32
     *              constraints: align 16
33
     * @param num_reuse_blocks  number of blocks that will reuse exponents from the current block.
34
     *                          constraints: range 0 to 5
35
     * @param nb_coefs  number of frequency coefficients.
36
     */
37
    void (*ac3_exponent_min)(uint8_t *exp, int num_reuse_blocks, int nb_coefs);
38
} AC3DSPContext;
39

  
40
void ff_ac3dsp_init    (AC3DSPContext *c);
41
void ff_ac3dsp_init_x86(AC3DSPContext *c);
42

  
43
#endif /* AVCODEC_AC3DSP_H */
libavcodec/ac3enc.c
33 33
#include "avcodec.h"
34 34
#include "put_bits.h"
35 35
#include "dsputil.h"
36
#include "ac3dsp.h"
36 37
#include "ac3.h"
37 38
#include "audioconvert.h"
38 39

  
......
86 87
typedef struct AC3EncodeContext {
87 88
    PutBitContext pb;                       ///< bitstream writer context
88 89
    DSPContext dsp;
90
    AC3DSPContext ac3dsp;                   ///< AC-3 optimized functions
89 91
    AC3MDCTContext mdct;                    ///< MDCT context
90 92

  
91 93
    AC3Block blocks[AC3_MAX_BLOCKS];        ///< per-block info
......
458 460
            exp_strategy[blk] = EXP_REUSE;
459 461
        exp += AC3_MAX_COEFS;
460 462
    }
461
    emms_c();
462 463

  
463 464
    /* now select the encoding strategy type : if exponents are often
464 465
       recoded, we use a coarse encoding */
......
499 500

  
500 501

  
501 502
/**
502
 * Set each encoded exponent in a block to the minimum of itself and the
503
 * exponents in the same frequency bin of up to 5 following blocks.
504
 */
505
static void exponent_min(uint8_t *exp, int num_reuse_blocks, int nb_coefs)
506
{
507
    int blk, i;
508

  
509
    if (!num_reuse_blocks)
510
        return;
511

  
512
    for (i = 0; i < nb_coefs; i++) {
513
        uint8_t min_exp = *exp;
514
        uint8_t *exp1 = exp + AC3_MAX_COEFS;
515
        for (blk = 0; blk < num_reuse_blocks; blk++) {
516
            uint8_t next_exp = *exp1;
517
            if (next_exp < min_exp)
518
                min_exp = next_exp;
519
            exp1 += AC3_MAX_COEFS;
520
        }
521
        *exp++ = min_exp;
522
    }
523
}
524

  
525

  
526
/**
527 503
 * Update the exponents so that they are the ones the decoder will decode.
528 504
 */
529 505
static void encode_exponents_blk_ch(uint8_t *exp, int nb_exps, int exp_strategy)
......
616 592
            num_reuse_blocks = blk1 - blk - 1;
617 593

  
618 594
            /* for the EXP_REUSE case we select the min of the exponents */
619
            exponent_min(exp, num_reuse_blocks, nb_coefs);
595
            s->ac3dsp.ac3_exponent_min(exp, num_reuse_blocks, nb_coefs);
620 596

  
621 597
            encode_exponents_blk_ch(exp, nb_coefs, exp_strategy[blk]);
622 598

  
......
704 680
    encode_exponents(s);
705 681

  
706 682
    group_exponents(s);
683

  
684
    emms_c();
707 685
}
708 686

  
709 687

  
......
1856 1834
    avctx->coded_frame= avcodec_alloc_frame();
1857 1835

  
1858 1836
    dsputil_init(&s->dsp, avctx);
1837
    ff_ac3dsp_init(&s->ac3dsp);
1859 1838

  
1860 1839
    return 0;
1861 1840
init_fail:
libavcodec/x86/Makefile
17 17

  
18 18
YASM-OBJS-$(CONFIG_VC1_DECODER)        += x86/vc1dsp_yasm.o
19 19

  
20
MMX-OBJS-$(CONFIG_AC3_ENCODER)         += x86/ac3dsp_mmx.o
21
MMX-OBJS-$(CONFIG_AC3_FIXED_ENCODER)   += x86/ac3dsp_mmx.o
22
YASM-OBJS-$(CONFIG_AC3_ENCODER)        += x86/ac3dsp.o
23
YASM-OBJS-$(CONFIG_AC3_FIXED_ENCODER)  += x86/ac3dsp.o
20 24
MMX-OBJS-$(CONFIG_CAVS_DECODER)        += x86/cavsdsp_mmx.o
21 25
MMX-OBJS-$(CONFIG_MP1FLOAT_DECODER)    += x86/mpegaudiodec_mmx.o
22 26
MMX-OBJS-$(CONFIG_MP2FLOAT_DECODER)    += x86/mpegaudiodec_mmx.o
libavcodec/x86/ac3dsp.asm
1
;*****************************************************************************
2
;* x86-optimized AC-3 DSP utils
3
;* Copyright (c) 2011 Justin Ruggles
4
;*
5
;* This file is part of FFmpeg.
6
;*
7
;* FFmpeg is free software; you can redistribute it and/or
8
;* modify it under the terms of the GNU Lesser General Public
9
;* License as published by the Free Software Foundation; either
10
;* version 2.1 of the License, or (at your option) any later version.
11
;*
12
;* FFmpeg is distributed in the hope that it will be useful,
13
;* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
;* Lesser General Public License for more details.
16
;*
17
;* You should have received a copy of the GNU Lesser General Public
18
;* License along with FFmpeg; if not, write to the Free Software
19
;* 51, Inc., Foundation Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
;******************************************************************************
21

  
22
%include "x86inc.asm"
23
%include "x86util.asm"
24

  
25
SECTION .text
26

  
27
;-----------------------------------------------------------------------------
28
; void ff_ac3_exponent_min(uint8_t *exp, int num_reuse_blocks, int nb_coefs)
29
;-----------------------------------------------------------------------------
30

  
31
%macro AC3_EXPONENT_MIN 1
32
cglobal ac3_exponent_min_%1, 3,4,2, exp, reuse_blks, expn, offset
33
    shl  reuse_blksq, 8
34
    jz .end
35
    LOOP_ALIGN
36
.nextexp:
37
    mov      offsetq, reuse_blksq
38
    mova          m0, [expq+offsetq]
39
    sub      offsetq, 256
40
    LOOP_ALIGN
41
.nextblk:
42
    PMINUB        m0, [expq+offsetq], m1
43
    sub      offsetq, 256
44
    jae .nextblk
45
    mova      [expq], m0
46
    add         expq, mmsize
47
    sub        expnq, mmsize
48
    jg .nextexp
49
.end:
50
    REP_RET
51
%endmacro
52

  
53
%define PMINUB PMINUB_MMX
54
%define LOOP_ALIGN
55
INIT_MMX
56
AC3_EXPONENT_MIN mmx
57
%ifdef HAVE_MMX2
58
%define PMINUB PMINUB_MMXEXT
59
%define LOOP_ALIGN ALIGN 16
60
AC3_EXPONENT_MIN mmxext
61
%endif
62
%ifdef HAVE_SSE
63
INIT_XMM
64
AC3_EXPONENT_MIN sse2
65
%endif
66
%undef PMINUB
67
%undef LOOP_ALIGN
libavcodec/x86/ac3dsp_mmx.c
1
/*
2
 * x86-optimized AC-3 DSP utils
3
 * Copyright (c) 2011 Justin Ruggles
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with FFmpeg; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21

  
22
#include "libavutil/x86_cpu.h"
23
#include "dsputil_mmx.h"
24
#include "libavcodec/ac3dsp.h"
25

  
26
extern void ff_ac3_exponent_min_mmx   (uint8_t *exp, int num_reuse_blocks, int nb_coefs);
27
extern void ff_ac3_exponent_min_mmxext(uint8_t *exp, int num_reuse_blocks, int nb_coefs);
28
extern void ff_ac3_exponent_min_sse2  (uint8_t *exp, int num_reuse_blocks, int nb_coefs);
29

  
30
av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c)
31
{
32
    int mm_flags = av_get_cpu_flags();
33

  
34
#if HAVE_YASM
35
    if (mm_flags & AV_CPU_FLAG_MMX) {
36
        c->ac3_exponent_min = ff_ac3_exponent_min_mmx;
37
    }
38
    if (mm_flags & AV_CPU_FLAG_MMX2 && HAVE_MMX2) {
39
        c->ac3_exponent_min = ff_ac3_exponent_min_mmxext;
40
    }
41
    if (mm_flags & AV_CPU_FLAG_SSE2 && HAVE_SSE) {
42
        c->ac3_exponent_min = ff_ac3_exponent_min_sse2;
43
    }
44
#endif
45
}
libavcodec/x86/x86util.asm
434 434
    movh     [%7], %3
435 435
    movh  [%7+%8], %4
436 436
%endmacro
437

  
438
%macro PMINUB_MMX 3 ; dst, src, tmp
439
    mova     %3, %1
440
    psubusb  %3, %2
441
    psubb    %1, %3
442
%endmacro
443

  
444
%macro PMINUB_MMXEXT 3 ; dst, src, ignored
445
    pminub   %1, %2
446
%endmacro

Also available in: Unified diff