annotate dtsdec.c @ 6491:b7f807b4cd88 libavformat tip

In mov demuxer, check that nb_streams is valid before using it in read_dac3
author bcoudurier
date Tue, 28 Sep 2010 00:33:21 +0000
parents 4775a49a6045
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 868
diff changeset
1 /*
6429
3e32902d7025 move DTS demuxer to its own file
aurel
parents: 6428
diff changeset
2 * RAW DTS demuxer
3e32902d7025 move DTS demuxer to its own file
aurel
parents: 6428
diff changeset
3 * Copyright (c) 2008 Benjamin Larsson
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1245
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1245
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1245
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1245
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1245
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1245
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 887
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 */
3286
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 3274
diff changeset
21
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 3274
diff changeset
22 #include "libavcodec/bytestream.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 #include "avformat.h"
6448
4775a49a6045 split raw.c into rawdec.c and rawenc.c
aurel
parents: 6429
diff changeset
24 #include "rawdec.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25
3274
194be504f61d dts probe
banan
parents: 3272
diff changeset
26 #define DCA_MARKER_14B_BE 0x1FFFE800
194be504f61d dts probe
banan
parents: 3272
diff changeset
27 #define DCA_MARKER_14B_LE 0xFF1F00E8
194be504f61d dts probe
banan
parents: 3272
diff changeset
28 #define DCA_MARKER_RAW_BE 0x7FFE8001
194be504f61d dts probe
banan
parents: 3272
diff changeset
29 #define DCA_MARKER_RAW_LE 0xFE7F0180
6429
3e32902d7025 move DTS demuxer to its own file
aurel
parents: 6428
diff changeset
30
3274
194be504f61d dts probe
banan
parents: 3272
diff changeset
31 static int dts_probe(AVProbeData *p)
194be504f61d dts probe
banan
parents: 3272
diff changeset
32 {
194be504f61d dts probe
banan
parents: 3272
diff changeset
33 const uint8_t *buf, *bufp;
194be504f61d dts probe
banan
parents: 3272
diff changeset
34 uint32_t state = -1;
5182
34ec401808a8 Make DTS probe more robust against false positives (as e.g. probetest shows).
reimar
parents: 5179
diff changeset
35 int markers[3] = {0};
34ec401808a8 Make DTS probe more robust against false positives (as e.g. probetest shows).
reimar
parents: 5179
diff changeset
36 int sum, max;
3274
194be504f61d dts probe
banan
parents: 3272
diff changeset
37
194be504f61d dts probe
banan
parents: 3272
diff changeset
38 buf = p->buf;
194be504f61d dts probe
banan
parents: 3272
diff changeset
39
194be504f61d dts probe
banan
parents: 3272
diff changeset
40 for(; buf < (p->buf+p->buf_size)-2; buf+=2) {
194be504f61d dts probe
banan
parents: 3272
diff changeset
41 bufp = buf;
194be504f61d dts probe
banan
parents: 3272
diff changeset
42 state = (state << 16) | bytestream_get_be16(&bufp);
194be504f61d dts probe
banan
parents: 3272
diff changeset
43
3725
900a232fc55e cosmetics: misc spelling fixes
diego
parents: 3613
diff changeset
44 /* regular bitstream */
3274
194be504f61d dts probe
banan
parents: 3272
diff changeset
45 if (state == DCA_MARKER_RAW_BE || state == DCA_MARKER_RAW_LE)
5182
34ec401808a8 Make DTS probe more robust against false positives (as e.g. probetest shows).
reimar
parents: 5179
diff changeset
46 markers[0]++;
3274
194be504f61d dts probe
banan
parents: 3272
diff changeset
47
3725
900a232fc55e cosmetics: misc spelling fixes
diego
parents: 3613
diff changeset
48 /* 14 bits big-endian bitstream */
3274
194be504f61d dts probe
banan
parents: 3272
diff changeset
49 if (state == DCA_MARKER_14B_BE)
194be504f61d dts probe
banan
parents: 3272
diff changeset
50 if ((bytestream_get_be16(&bufp) & 0xFFF0) == 0x07F0)
5182
34ec401808a8 Make DTS probe more robust against false positives (as e.g. probetest shows).
reimar
parents: 5179
diff changeset
51 markers[1]++;
3274
194be504f61d dts probe
banan
parents: 3272
diff changeset
52
3725
900a232fc55e cosmetics: misc spelling fixes
diego
parents: 3613
diff changeset
53 /* 14 bits little-endian bitstream */
3274
194be504f61d dts probe
banan
parents: 3272
diff changeset
54 if (state == DCA_MARKER_14B_LE)
194be504f61d dts probe
banan
parents: 3272
diff changeset
55 if ((bytestream_get_be16(&bufp) & 0xF0FF) == 0xF007)
5182
34ec401808a8 Make DTS probe more robust against false positives (as e.g. probetest shows).
reimar
parents: 5179
diff changeset
56 markers[2]++;
3274
194be504f61d dts probe
banan
parents: 3272
diff changeset
57 }
5182
34ec401808a8 Make DTS probe more robust against false positives (as e.g. probetest shows).
reimar
parents: 5179
diff changeset
58 sum = markers[0] + markers[1] + markers[2];
34ec401808a8 Make DTS probe more robust against false positives (as e.g. probetest shows).
reimar
parents: 5179
diff changeset
59 max = markers[1] > markers[0];
34ec401808a8 Make DTS probe more robust against false positives (as e.g. probetest shows).
reimar
parents: 5179
diff changeset
60 max = markers[2] > markers[max] ? 2 : max;
34ec401808a8 Make DTS probe more robust against false positives (as e.g. probetest shows).
reimar
parents: 5179
diff changeset
61 if (markers[max] > 3 && p->buf_size / markers[max] < 32*1024 &&
34ec401808a8 Make DTS probe more robust against false positives (as e.g. probetest shows).
reimar
parents: 5179
diff changeset
62 markers[max] * 4 > sum * 3)
34ec401808a8 Make DTS probe more robust against false positives (as e.g. probetest shows).
reimar
parents: 5179
diff changeset
63 return AVPROBE_SCORE_MAX/2+1;
3274
194be504f61d dts probe
banan
parents: 3272
diff changeset
64
194be504f61d dts probe
banan
parents: 3272
diff changeset
65 return 0;
194be504f61d dts probe
banan
parents: 3272
diff changeset
66 }
194be504f61d dts probe
banan
parents: 3272
diff changeset
67
1167
d89d7ef290da give AVInput/OutputFormat structs consistent names
mru
parents: 1121
diff changeset
68 AVInputFormat dts_demuxer = {
496
112057e05179 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents: 483
diff changeset
69 "dts",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3405
diff changeset
70 NULL_IF_CONFIG_SMALL("raw DTS"),
496
112057e05179 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents: 483
diff changeset
71 0,
3274
194be504f61d dts probe
banan
parents: 3272
diff changeset
72 dts_probe,
6429
3e32902d7025 move DTS demuxer to its own file
aurel
parents: 6428
diff changeset
73 ff_raw_audio_read_header,
4610
41542d2edcf4 Separate the raw FLAC demuxer from raw.c and put in a new file,
jbr
parents: 4577
diff changeset
74 ff_raw_read_partial_packet,
1756
5d72afc6c8aa better generic index building and seeking code
michael
parents: 1463
diff changeset
75 .flags= AVFMT_GENERIC_INDEX,
496
112057e05179 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents: 483
diff changeset
76 .extensions = "dts",
3268
319c36da904b set demuxers .value and use common audio_read_header function
bcoudurier
parents: 3238
diff changeset
77 .value = CODEC_ID_DTS,
496
112057e05179 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents: 483
diff changeset
78 };