Mercurial > libavformat.hg
comparison westwood.c @ 3232:12f41a1f8afc libavformat
Tighten up the Westwood AUD detection. Probability of random detections
used to be on the order of 2^8. It is now on the order of 2^45.
author | melanson |
---|---|
date | Fri, 18 Apr 2008 17:29:58 +0000 |
parents | d52c718e83f9 |
children | 7a0230981402 |
comparison
equal
deleted
inserted
replaced
3231:956fc24819df | 3232:12f41a1f8afc |
---|---|
88 int field; | 88 int field; |
89 | 89 |
90 /* Probabilistic content detection strategy: There is no file signature | 90 /* Probabilistic content detection strategy: There is no file signature |
91 * so perform sanity checks on various header parameters: | 91 * so perform sanity checks on various header parameters: |
92 * 8000 <= sample rate (16 bits) <= 48000 ==> 40001 acceptable numbers | 92 * 8000 <= sample rate (16 bits) <= 48000 ==> 40001 acceptable numbers |
93 * flags <= 0x03 (2 LSBs are used) ==> 4 acceptable numbers | |
93 * compression type (8 bits) = 1 or 99 ==> 2 acceptable numbers | 94 * compression type (8 bits) = 1 or 99 ==> 2 acceptable numbers |
94 * There is a total of 24 bits. The number space contains 2^24 = | 95 * first audio chunk signature (32 bits) ==> 1 acceptable number |
95 * 16777216 numbers. There are 40001 * 2 = 80002 acceptable combinations | 96 * The number space contains 2^64 numbers. There are 40001 * 4 * 2 * 1 = |
96 * of numbers. There is a 80002/16777216 = 0.48% chance of a false | 97 * 320008 acceptable number combinations. |
97 * positive. | |
98 */ | 98 */ |
99 | 99 |
100 if (p->buf_size < AUD_HEADER_SIZE) | 100 if (p->buf_size < AUD_HEADER_SIZE + AUD_CHUNK_PREAMBLE_SIZE) |
101 return 0; | 101 return 0; |
102 | 102 |
103 /* check sample rate */ | 103 /* check sample rate */ |
104 field = AV_RL16(&p->buf[0]); | 104 field = AV_RL16(&p->buf[0]); |
105 if ((field < 8000) || (field > 48000)) | 105 if ((field < 8000) || (field > 48000)) |
106 return 0; | 106 return 0; |
107 | 107 |
108 /* enforce the rule that the top 6 bits of this flags field are reserved (0); | |
109 * this might not be true, but enforce it until deemed unnecessary */ | |
110 if (p->buf[10] & 0xFC) | |
111 return 0; | |
112 | |
108 /* note: only check for WS IMA (type 99) right now since there is no | 113 /* note: only check for WS IMA (type 99) right now since there is no |
109 * support for type 1 */ | 114 * support for type 1 */ |
110 if (p->buf[11] != 99) | 115 if (p->buf[11] != 99) |
116 return 0; | |
117 | |
118 /* read ahead to the first audio chunk and validate the first header signature */ | |
119 if (AV_RL32(&p->buf[16]) != AUD_CHUNK_SIGNATURE) | |
111 return 0; | 120 return 0; |
112 | 121 |
113 /* return 1/2 certainty since this file check is a little sketchy */ | 122 /* return 1/2 certainty since this file check is a little sketchy */ |
114 return AVPROBE_SCORE_MAX / 2; | 123 return AVPROBE_SCORE_MAX / 2; |
115 } | 124 } |