annotate ac3dec.c @ 6479:3e7384f85f1d libavformat

tcp: Check both wfds and efds when waiting for the result from connect On windows, a connection failure doesn't trigger wfds as it does on unix. This fixes issue 2237, based on code by yeyingxian.
author mstorsjo
date Tue, 21 Sep 2010 20:17:34 +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 /*
6440
8beba113f242 move ac3/eac3 demuxer to its own file
aurel
parents: 6439
diff changeset
2 * RAW AC-3 and E-AC-3 demuxer
8beba113f242 move ac3/eac3 demuxer to its own file
aurel
parents: 6439
diff changeset
3 * Copyright (c) 2007 Justin Ruggles <justin.ruggles@gmail.com>
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 "libavutil/crc.h"
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 3274
diff changeset
23 #include "libavcodec/ac3_parser.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 #include "avformat.h"
6448
4775a49a6045 split raw.c into rawdec.c and rawenc.c
aurel
parents: 6440
diff changeset
25 #include "rawdec.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26
3864
b31edc09d556 simplify ac3_probe() and eac3_probe(). patch by Aurelien Jacobs.
jbr
parents: 3863
diff changeset
27 static int ac3_eac3_probe(AVProbeData *p, enum CodecID expected_codec_id)
1768
7598146fe1cc add read_probe function to raw ac3 demuxer
jbr
parents: 1756
diff changeset
28 {
2224
fbaec5e545d2 kill uninitialised variable warning in ac3_probe()
mru
parents: 2210
diff changeset
29 int max_frames, first_frames = 0, frames;
1931
69c6eb14fdfc improve ac3_probe by counting consecutive frames
jbr
parents: 1773
diff changeset
30 uint8_t *buf, *buf2, *end;
69c6eb14fdfc improve ac3_probe by counting consecutive frames
jbr
parents: 1773
diff changeset
31 AC3HeaderInfo hdr;
3238
db733a434b2c change ff_ac3_parse_header() to take a GetBitContext instead of const char*
bwolowiec
parents: 3237
diff changeset
32 GetBitContext gbc;
3864
b31edc09d556 simplify ac3_probe() and eac3_probe(). patch by Aurelien Jacobs.
jbr
parents: 3863
diff changeset
33 enum CodecID codec_id = CODEC_ID_AC3;
1768
7598146fe1cc add read_probe function to raw ac3 demuxer
jbr
parents: 1756
diff changeset
34
1931
69c6eb14fdfc improve ac3_probe by counting consecutive frames
jbr
parents: 1773
diff changeset
35 max_frames = 0;
69c6eb14fdfc improve ac3_probe by counting consecutive frames
jbr
parents: 1773
diff changeset
36 buf = p->buf;
2304
763527841a80 additional tweaks to AC3 probe function. give a higher score to a single frame
jbr
parents: 2303
diff changeset
37 end = buf + p->buf_size;
1931
69c6eb14fdfc improve ac3_probe by counting consecutive frames
jbr
parents: 1773
diff changeset
38
69c6eb14fdfc improve ac3_probe by counting consecutive frames
jbr
parents: 1773
diff changeset
39 for(; buf < end; buf++) {
69c6eb14fdfc improve ac3_probe by counting consecutive frames
jbr
parents: 1773
diff changeset
40 buf2 = buf;
69c6eb14fdfc improve ac3_probe by counting consecutive frames
jbr
parents: 1773
diff changeset
41
69c6eb14fdfc improve ac3_probe by counting consecutive frames
jbr
parents: 1773
diff changeset
42 for(frames = 0; buf2 < end; frames++) {
3238
db733a434b2c change ff_ac3_parse_header() to take a GetBitContext instead of const char*
bwolowiec
parents: 3237
diff changeset
43 init_get_bits(&gbc, buf2, 54);
db733a434b2c change ff_ac3_parse_header() to take a GetBitContext instead of const char*
bwolowiec
parents: 3237
diff changeset
44 if(ff_ac3_parse_header(&gbc, &hdr) < 0)
1931
69c6eb14fdfc improve ac3_probe by counting consecutive frames
jbr
parents: 1773
diff changeset
45 break;
3237
4fa7ec10b57e Compute AC3 frame CRC for stronger raw AC3 format probing.
andoma
parents: 3235
diff changeset
46 if(buf2 + hdr.frame_size > end ||
4fa7ec10b57e Compute AC3 frame CRC for stronger raw AC3 format probing.
andoma
parents: 3235
diff changeset
47 av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2))
4fa7ec10b57e Compute AC3 frame CRC for stronger raw AC3 format probing.
andoma
parents: 3235
diff changeset
48 break;
3862
c11ff84634b2 create a separate codec_id for E-AC-3
jbr
parents: 3757
diff changeset
49 if (hdr.bitstream_id > 10)
3864
b31edc09d556 simplify ac3_probe() and eac3_probe(). patch by Aurelien Jacobs.
jbr
parents: 3863
diff changeset
50 codec_id = CODEC_ID_EAC3;
1931
69c6eb14fdfc improve ac3_probe by counting consecutive frames
jbr
parents: 1773
diff changeset
51 buf2 += hdr.frame_size;
69c6eb14fdfc improve ac3_probe by counting consecutive frames
jbr
parents: 1773
diff changeset
52 }
69c6eb14fdfc improve ac3_probe by counting consecutive frames
jbr
parents: 1773
diff changeset
53 max_frames = FFMAX(max_frames, frames);
69c6eb14fdfc improve ac3_probe by counting consecutive frames
jbr
parents: 1773
diff changeset
54 if(buf == p->buf)
69c6eb14fdfc improve ac3_probe by counting consecutive frames
jbr
parents: 1773
diff changeset
55 first_frames = frames;
1768
7598146fe1cc add read_probe function to raw ac3 demuxer
jbr
parents: 1756
diff changeset
56 }
3864
b31edc09d556 simplify ac3_probe() and eac3_probe(). patch by Aurelien Jacobs.
jbr
parents: 3863
diff changeset
57 if(codec_id != expected_codec_id) return 0;
5238
c872818a8e1f Sync AC3 probe values with MP3 probe values, they have to avoid similar issues.
reimar
parents: 5191
diff changeset
58 // keep this in sync with mp3 probe, both need to avoid
c872818a8e1f Sync AC3 probe values with MP3 probe values, they have to avoid similar issues.
reimar
parents: 5191
diff changeset
59 // issues with MPEG-files!
c872818a8e1f Sync AC3 probe values with MP3 probe values, they have to avoid similar issues.
reimar
parents: 5191
diff changeset
60 if (first_frames>=4) return AVPROBE_SCORE_MAX/2+1;
c872818a8e1f Sync AC3 probe values with MP3 probe values, they have to avoid similar issues.
reimar
parents: 5191
diff changeset
61 else if(max_frames>500)return AVPROBE_SCORE_MAX/2;
c872818a8e1f Sync AC3 probe values with MP3 probe values, they have to avoid similar issues.
reimar
parents: 5191
diff changeset
62 else if(max_frames>=4) return AVPROBE_SCORE_MAX/4;
1931
69c6eb14fdfc improve ac3_probe by counting consecutive frames
jbr
parents: 1773
diff changeset
63 else if(max_frames>=1) return 1;
69c6eb14fdfc improve ac3_probe by counting consecutive frames
jbr
parents: 1773
diff changeset
64 else return 0;
1768
7598146fe1cc add read_probe function to raw ac3 demuxer
jbr
parents: 1756
diff changeset
65 }
7598146fe1cc add read_probe function to raw ac3 demuxer
jbr
parents: 1756
diff changeset
66
4206
c3102b189cb6 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 4103
diff changeset
67 #if CONFIG_AC3_DEMUXER
3862
c11ff84634b2 create a separate codec_id for E-AC-3
jbr
parents: 3757
diff changeset
68 static int ac3_probe(AVProbeData *p)
c11ff84634b2 create a separate codec_id for E-AC-3
jbr
parents: 3757
diff changeset
69 {
3864
b31edc09d556 simplify ac3_probe() and eac3_probe(). patch by Aurelien Jacobs.
jbr
parents: 3863
diff changeset
70 return ac3_eac3_probe(p, CODEC_ID_AC3);
3862
c11ff84634b2 create a separate codec_id for E-AC-3
jbr
parents: 3757
diff changeset
71 }
c11ff84634b2 create a separate codec_id for E-AC-3
jbr
parents: 3757
diff changeset
72
1167
d89d7ef290da give AVInput/OutputFormat structs consistent names
mru
parents: 1121
diff changeset
73 AVInputFormat ac3_demuxer = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 "ac3",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3405
diff changeset
75 NULL_IF_CONFIG_SMALL("raw AC-3"),
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 0,
1768
7598146fe1cc add read_probe function to raw ac3 demuxer
jbr
parents: 1756
diff changeset
77 ac3_probe,
6429
3e32902d7025 move DTS demuxer to its own file
aurel
parents: 6428
diff changeset
78 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
79 ff_raw_read_partial_packet,
1756
5d72afc6c8aa better generic index building and seeking code
michael
parents: 1463
diff changeset
80 .flags= AVFMT_GENERIC_INDEX,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 .extensions = "ac3",
3268
319c36da904b set demuxers .value and use common audio_read_header function
bcoudurier
parents: 3238
diff changeset
82 .value = CODEC_ID_AC3,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 };
2022
4f62a7d9381a Make the declaration of AVInputFormat ac3_demuxer conditional
diego
parents: 2021
diff changeset
84 #endif
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85
6440
8beba113f242 move ac3/eac3 demuxer to its own file
aurel
parents: 6439
diff changeset
86 #if CONFIG_EAC3_DEMUXER
8beba113f242 move ac3/eac3 demuxer to its own file
aurel
parents: 6439
diff changeset
87 static int eac3_probe(AVProbeData *p)
8beba113f242 move ac3/eac3 demuxer to its own file
aurel
parents: 6439
diff changeset
88 {
8beba113f242 move ac3/eac3 demuxer to its own file
aurel
parents: 6439
diff changeset
89 return ac3_eac3_probe(p, CODEC_ID_EAC3);
8beba113f242 move ac3/eac3 demuxer to its own file
aurel
parents: 6439
diff changeset
90 }
3272
07038dc492ab Import Dirac demuxer/muxer from SoC branch; written by Marco Gerards,
lu_zero
parents: 3269
diff changeset
91
3862
c11ff84634b2 create a separate codec_id for E-AC-3
jbr
parents: 3757
diff changeset
92 AVInputFormat eac3_demuxer = {
c11ff84634b2 create a separate codec_id for E-AC-3
jbr
parents: 3757
diff changeset
93 "eac3",
c11ff84634b2 create a separate codec_id for E-AC-3
jbr
parents: 3757
diff changeset
94 NULL_IF_CONFIG_SMALL("raw E-AC-3"),
c11ff84634b2 create a separate codec_id for E-AC-3
jbr
parents: 3757
diff changeset
95 0,
c11ff84634b2 create a separate codec_id for E-AC-3
jbr
parents: 3757
diff changeset
96 eac3_probe,
6429
3e32902d7025 move DTS demuxer to its own file
aurel
parents: 6428
diff changeset
97 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
98 ff_raw_read_partial_packet,
3862
c11ff84634b2 create a separate codec_id for E-AC-3
jbr
parents: 3757
diff changeset
99 .flags= AVFMT_GENERIC_INDEX,
c11ff84634b2 create a separate codec_id for E-AC-3
jbr
parents: 3757
diff changeset
100 .extensions = "eac3",
c11ff84634b2 create a separate codec_id for E-AC-3
jbr
parents: 3757
diff changeset
101 .value = CODEC_ID_EAC3,
c11ff84634b2 create a separate codec_id for E-AC-3
jbr
parents: 3757
diff changeset
102 };
c11ff84634b2 create a separate codec_id for E-AC-3
jbr
parents: 3757
diff changeset
103 #endif