Revision a7a85899

View differences:

libavcodec/mpegaudio.h
18 18
#define MPA_DUAL    2
19 19
#define MPA_MONO    3
20 20

  
21
/* header + layer + bitrate + freq + lsf/mpeg25 */
22
#define SAME_HEADER_MASK \
23
   (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
24

  
21 25
int l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
22 26
int mpa_decode_header(AVCodecContext *avctx, uint32_t head);
23 27

  
......
29 33
extern const int quant_steps[17];
30 34
extern const int quant_bits[17];
31 35
extern const int32_t mpa_enwindow[257];
36

  
37
/* fast header check for resync */
38
static inline int ff_mpa_check_header(uint32_t header){
39
    /* header */
40
    if ((header & 0xffe00000) != 0xffe00000)
41
        return -1;
42
    /* layer check */
43
    if ((header & (3<<17)) == 0)
44
        return -1;
45
    /* bit rate */
46
    if ((header & (0xf<<12)) == 0xf<<12)
47
        return -1;
48
    /* frequency */
49
    if ((header & (3<<10)) == 3<<10)
50
        return -1;
51
    return 0;
52
}
libavcodec/mpegaudiodec.c
99 99
#endif
100 100
    void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g);
101 101
    int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3
102
    unsigned int dither_state;
102 103
} MPADecodeContext;
103 104

  
104 105
/* layer 3 "granule" */
......
749 750

  
750 751
#if FRAC_BITS <= 15
751 752

  
752
static inline int round_sample(int sum)
753
static inline int round_sample(int *sum)
753 754
{
754 755
    int sum1;
755
    sum1 = (sum + (1 << (OUT_SHIFT - 1))) >> OUT_SHIFT;
756
    sum1 = (*sum) >> OUT_SHIFT;
757
    *sum &= (1<<OUT_SHIFT)-1;
756 758
    if (sum1 < -32768)
757 759
        sum1 = -32768;
758 760
    else if (sum1 > 32767)
......
782 784

  
783 785
#else
784 786

  
785
static inline int round_sample(int64_t sum) 
787
static inline int round_sample(int64_t *sum) 
786 788
{
787 789
    int sum1;
788
    sum1 = (int)((sum + (int64_t_C(1) << (OUT_SHIFT - 1))) >> OUT_SHIFT);
790
    sum1 = (int)((*sum) >> OUT_SHIFT);
791
    *sum &= (1<<OUT_SHIFT)-1;
789 792
    if (sum1 < -32768)
790 793
        sum1 = -32768;
791 794
    else if (sum1 > 32767)
......
900 903
    w = window;
901 904
    w2 = window + 31;
902 905

  
903
    sum = 0;
906
    sum = s1->dither_state;
904 907
    p = synth_buf + 16;
905 908
    SUM8(sum, +=, w, p);
906 909
    p = synth_buf + 48;
907 910
    SUM8(sum, -=, w + 32, p);
908
    *samples = round_sample(sum);
911
    *samples = round_sample(&sum);
909 912
    samples += incr;
910 913
    w++;
911 914

  
912 915
    /* we calculate two samples at the same time to avoid one memory
913 916
       access per two sample */
914 917
    for(j=1;j<16;j++) {
915
        sum = 0;
916 918
        sum2 = 0;
917 919
        p = synth_buf + 16 + j;
918 920
        SUM8P2(sum, +=, sum2, -=, w, w2, p);
919 921
        p = synth_buf + 48 - j;
920 922
        SUM8P2(sum, -=, sum2, -=, w + 32, w2 + 32, p);
921 923

  
922
        *samples = round_sample(sum);
924
        *samples = round_sample(&sum);
923 925
        samples += incr;
924
        *samples2 = round_sample(sum2);
926
        sum += sum2;
927
        *samples2 = round_sample(&sum);
925 928
        samples2 -= incr;
926 929
        w++;
927 930
        w2--;
928 931
    }
929 932
    
930 933
    p = synth_buf + 32;
931
    sum = 0;
932 934
    SUM8(sum, -=, w + 32, p);
933
    *samples = round_sample(sum);
935
    *samples = round_sample(&sum);
936
    s1->dither_state= sum;
934 937

  
935 938
    offset = (offset - 32) & 511;
936 939
    *synth_buf_offset = offset;
......
1115 1118
    out[8 - 4] = t1;
1116 1119
}
1117 1120

  
1118
/* fast header check for resync */
1119
static int check_header(uint32_t header)
1120
{
1121
    /* header */
1122
    if ((header & 0xffe00000) != 0xffe00000)
1123
	return -1;
1124
    /* layer check */
1125
    if (((header >> 17) & 3) == 0)
1126
	return -1;
1127
    /* bit rate */
1128
    if (((header >> 12) & 0xf) == 0xf)
1129
	return -1;
1130
    /* frequency */
1131
    if (((header >> 10) & 3) == 3)
1132
	return -1;
1133
    return 0;
1134
}
1135

  
1136
/* header + layer + bitrate + freq + lsf/mpeg25 */
1137
#define SAME_HEADER_MASK \
1138
   (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
1139

  
1140 1121
/* header decoding. MUST check the header before because no
1141 1122
   consistency check is done there. Return 1 if free format found and
1142 1123
   that the frame size must be computed externally */
......
1244 1225
    MPADecodeContext s1, *s = &s1;
1245 1226
    memset( s, 0, sizeof(MPADecodeContext) );
1246 1227

  
1247
    if (check_header(head) != 0)
1228
    if (ff_mpa_check_header(head) != 0)
1248 1229
        return -1;
1249 1230

  
1250 1231
    if (decode_header(s, head) != 0) {
......
2566 2547
		header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
2567 2548
		    (s->inbuf[2] << 8) | s->inbuf[3];
2568 2549

  
2569
		if (check_header(header) < 0) {
2550
		if (ff_mpa_check_header(header) < 0) {
2570 2551
		    /* no sync found : move by one byte (inefficient, but simple!) */
2571 2552
		    memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
2572 2553
		    s->inbuf_ptr--;
......
2712 2693
    header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
2713 2694
              (s->inbuf[2] << 8) | s->inbuf[3] | 0xffe00000;
2714 2695

  
2715
    if (check_header(header) < 0) { // Bad header, discard frame
2696
    if (ff_mpa_check_header(header) < 0) { // Bad header, discard frame
2716 2697
        *data_size = 0;
2717 2698
        return buf_size;
2718 2699
    }
tests/ffmpeg.regression.ref
125 125
stddev: 10.99 PSNR:27.30 bytes:7602176
126 126
21f8ff9f1daacd9133683bb4ea0f50a4 *./data/a-mp2.mp2
127 127
95712 ./data/a-mp2.mp2
128
91ab1b253cd360037d3fca67b795aba8 *./data/out.wav
129
stddev:117.02 PSNR: 6.75 bytes:1054720
128
6956f2c5185c4edbae648c614992a14b *./data/out.wav
129
stddev:117.02 PSNR: 6.76 bytes:1054720
130 130
d056da679e6d6682812fffb28a7f0db6 *./data/a-ac3.rm
131 131
97983 ./data/a-ac3.rm
132 132
2d081e0e1f2e9bd4514e9ac8ec41884c *./data/a-g726.wav
tests/libav.regression.ref
1 1
ffmpeg regression test
2 2
8517e7c83227074b8d632477fda310d5 *./data/b-libav.avi
3 3
342282 ./data/b-libav.avi
4
./data/b-libav.avi CRC=001a3415
4
./data/b-libav.avi CRC=ccab3a27
5 5
c83444a0e8ef47b6af1d868d1bb21696 *./data/b-libav.asf
6 6
342967 ./data/b-libav.asf
7
./data/b-libav.asf CRC=750f18c7
7
./data/b-libav.asf CRC=41af1ed9
8 8
5240a23a9264bc6062d6739c70825ace *./data/b-libav.rm
9 9
360251 ./data/b-libav.rm
10 10
90784a1b9589095f20fc6bcc0cc23cc4 *./data/b-libav.mpg
11 11
387072 ./data/b-libav.mpg
12
./data/b-libav.mpg CRC=16c74225
12
./data/b-libav.mpg CRC=8b644837
13 13
57a8dfc7926802bb337a9d8918de94a8 *./data/b-libav.swf
14 14
41816 ./data/b-libav.swf
15 15
./data/b-libav.swf CRC=2b273fea
16 16
2b06388316770915293edcbcc693beef *./data/b-libav.ffm
17 17
389120 ./data/b-libav.ffm
18
./data/b-libav.ffm CRC=f765cbdd
18
./data/b-libav.ffm CRC=688bd1eb
19 19
794934a02582f8dfc85d1856514cf37c *./data/b-libav.flv
20 20
339325 ./data/b-libav.flv
21 21
./data/b-libav.flv CRC=7b9076f8
......
24 24
./data/b-libav.mov CRC=da87a90d
25 25
fea20ced22451312dd463110e594eda6 *./data/b-libav.nut
26 26
332415 ./data/b-libav.nut
27
./data/b-libav.nut CRC=001a3415
27
./data/b-libav.nut CRC=ccab3a27
28 28
29a2c312bbc5b187491183a918556475 *./data/b-libav.dv
29 29
3600000 ./data/b-libav.dv
30 30
./data/b-libav.dv CRC=37b096b4
tests/rotozoom.regression.ref
125 125
stddev:  3.43 PSNR:37.39 bytes:7602176
126 126
21f8ff9f1daacd9133683bb4ea0f50a4 *./data/a-mp2.mp2
127 127
95712 ./data/a-mp2.mp2
128
91ab1b253cd360037d3fca67b795aba8 *./data/out.wav
129
stddev:117.02 PSNR: 6.75 bytes:1054720
128
6956f2c5185c4edbae648c614992a14b *./data/out.wav
129
stddev:117.02 PSNR: 6.76 bytes:1054720
130 130
d056da679e6d6682812fffb28a7f0db6 *./data/a-ac3.rm
131 131
97983 ./data/a-ac3.rm
132 132
2d081e0e1f2e9bd4514e9ac8ec41884c *./data/a-g726.wav

Also available in: Unified diff