Browse code

Merge commit 'e0f8be6413b6a8d334d6052e610af32935c310af'

* commit 'e0f8be6413b6a8d334d6052e610af32935c310af':
avformat: Add AVPROBE_SCORE_EXTENSION define and use where appropriate

Conflicts:
libavformat/ac3dec.c
libavformat/avformat.h
libavformat/avs.c
libavformat/m4vdec.c
libavformat/mov.c
libavformat/mp3dec.c
libavformat/mpeg.c
libavformat/mpegvideodec.c
libavformat/psxstr.c
libavformat/pva.c
libavformat/utils.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2013/05/05 19:29:56
Showing 36 changed files
... ...
@@ -55,9 +55,9 @@ static int adts_aac_probe(AVProbeData *p)
55 55
         if(buf == buf0)
56 56
             first_frames= frames;
57 57
     }
58
-    if   (first_frames>=3) return AVPROBE_SCORE_MAX/2+1;
59
-    else if(max_frames>500)return AVPROBE_SCORE_MAX/2;
60
-    else if(max_frames>=3) return AVPROBE_SCORE_MAX/4;
58
+    if   (first_frames>=3) return AVPROBE_SCORE_EXTENSION + 1;
59
+    else if(max_frames>500)return AVPROBE_SCORE_EXTENSION;
60
+    else if(max_frames>=3) return AVPROBE_SCORE_EXTENSION / 2;
61 61
     else if(max_frames>=1) return 1;
62 62
     else                   return 0;
63 63
 }
... ...
@@ -79,9 +79,9 @@ static int ac3_eac3_probe(AVProbeData *p, enum AVCodecID expected_codec_id)
79 79
     if(codec_id != expected_codec_id) return 0;
80 80
     // keep this in sync with mp3 probe, both need to avoid
81 81
     // issues with MPEG-files!
82
-    if   (first_frames>=4) return AVPROBE_SCORE_MAX/2+1;
83
-    else if(max_frames>200)return AVPROBE_SCORE_MAX/2;
84
-    else if(max_frames>=4) return AVPROBE_SCORE_MAX/4;
82
+    if   (first_frames>=4) return AVPROBE_SCORE_EXTENSION + 1;
83
+    else if(max_frames>200)return AVPROBE_SCORE_EXTENSION;
84
+    else if(max_frames>=4) return AVPROBE_SCORE_EXTENSION/2;
85 85
     else if(max_frames>=1) return 1;
86 86
     else                   return 0;
87 87
 }
... ...
@@ -337,8 +337,10 @@ typedef struct AVProbeData {
337 337
     int buf_size;       /**< Size of buf except extra allocated bytes */
338 338
 } AVProbeData;
339 339
 
340
-#define AVPROBE_SCORE_MAX 100               ///< maximum score, half of that is used for file-extension-based detection
341 340
 #define AVPROBE_SCORE_RETRY (AVPROBE_SCORE_MAX/4)
341
+#define AVPROBE_SCORE_EXTENSION  50 ///< score for file extension
342
+#define AVPROBE_SCORE_MAX       100 ///< maximum score
343
+
342 344
 #define AVPROBE_PADDING_SIZE 32             ///< extra allocated bytes at the end of the probe buffer
343 345
 
344 346
 /// Demuxer will use avio_open, no opened file should be provided by the caller.
... ...
@@ -830,7 +830,7 @@ static int avi_read_header(AVFormatContext *s)
830 830
 static int read_gab2_sub(AVStream *st, AVPacket *pkt) {
831 831
     if (pkt->data && !strcmp(pkt->data, "GAB2") && AV_RL16(pkt->data+5) == 2) {
832 832
         uint8_t desc[256];
833
-        int score = AVPROBE_SCORE_MAX / 2, ret;
833
+        int score = AVPROBE_SCORE_EXTENSION, ret;
834 834
         AVIStream *ast = st->priv_data;
835 835
         AVInputFormat *sub_demuxer;
836 836
         AVRational time_base;
... ...
@@ -50,7 +50,7 @@ static int avs_probe(AVProbeData * p)
50 50
 
51 51
     d = p->buf;
52 52
     if (d[0] == 'w' && d[1] == 'W' && d[2] == 0x10 && d[3] == 0)
53
-        return 55;
53
+        return AVPROBE_SCORE_EXTENSION+5;
54 54
 
55 55
     return 0;
56 56
 }
... ...
@@ -61,7 +61,7 @@ static int cavsvideo_probe(AVProbeData *p)
61 61
         }
62 62
     }
63 63
     if(seq && seq*9<=pic*10)
64
-        return AVPROBE_SCORE_MAX/2;
64
+        return AVPROBE_SCORE_EXTENSION;
65 65
     return 0;
66 66
 }
67 67
 
... ...
@@ -60,7 +60,7 @@ static int dts_probe(AVProbeData *p)
60 60
     max = markers[2] > markers[max] ? 2 : max;
61 61
     if (markers[max] > 3 && p->buf_size / markers[max] < 32*1024 &&
62 62
         markers[max] * 4 > sum * 3)
63
-        return AVPROBE_SCORE_MAX/2+1;
63
+        return AVPROBE_SCORE_EXTENSION + 1;
64 64
 
65 65
     return 0;
66 66
 }
... ...
@@ -280,7 +280,7 @@ static int flac_probe(AVProbeData *p)
280 280
 {
281 281
     if (p->buf_size < 4 || memcmp(p->buf, "fLaC", 4))
282 282
         return 0;
283
-    return AVPROBE_SCORE_MAX/2;
283
+    return AVPROBE_SCORE_EXTENSION;
284 284
 }
285 285
 
286 286
 AVInputFormat ff_flac_demuxer = {
... ...
@@ -56,9 +56,9 @@ static int h261_probe(AVProbeData *p)
56 56
         }
57 57
     }
58 58
     if(valid_psc > 2*invalid_psc + 6){
59
-        return 50;
59
+        return AVPROBE_SCORE_EXTENSION;
60 60
     }else if(valid_psc > 2*invalid_psc + 2)
61
-        return 25;
61
+        return AVPROBE_SCORE_EXTENSION / 2;
62 62
     return 0;
63 63
 }
64 64
 
... ...
@@ -56,9 +56,9 @@ static int h263_probe(AVProbeData *p)
56 56
         }
57 57
     }
58 58
     if(valid_psc > 2*invalid_psc + 2*res_change + 3){
59
-        return 50;
59
+        return AVPROBE_SCORE_EXTENSION;
60 60
     }else if(valid_psc > 2*invalid_psc)
61
-        return 25;
61
+        return AVPROBE_SCORE_EXTENSION / 2;
62 62
     return 0;
63 63
 }
64 64
 
... ...
@@ -63,7 +63,7 @@ static int h264_probe(AVProbeData *p)
63 63
         }
64 64
     }
65 65
     if(sps && pps && (idr||sli>3) && res<(sps+pps+idr))
66
-        return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
66
+        return AVPROBE_SCORE_EXTENSION + 1; // 1 more than .mpg
67 67
     return 0;
68 68
 }
69 69
 
... ...
@@ -137,7 +137,7 @@ static int idcin_probe(AVProbeData *p)
137 137
         return 0;
138 138
 
139 139
     /* return half certainty since this check is a bit sketchy */
140
-    return AVPROBE_SCORE_MAX / 2;
140
+    return AVPROBE_SCORE_EXTENSION;
141 141
 }
142 142
 
143 143
 static int idcin_read_header(AVFormatContext *s)
... ...
@@ -185,7 +185,7 @@ static int img_read_probe(AVProbeData *p)
185 185
         else if (av_match_ext(p->filename, "raw") || av_match_ext(p->filename, "gif"))
186 186
             return 5;
187 187
         else
188
-            return AVPROBE_SCORE_MAX / 2;
188
+            return AVPROBE_SCORE_EXTENSION;
189 189
     }
190 190
     return 0;
191 191
 }
... ...
@@ -45,7 +45,7 @@ static int mpeg4video_probe(AVProbeData *probe_packet)
45 45
     }
46 46
 
47 47
     if (VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res==0)
48
-        return VOP+VO > 3 ? AVPROBE_SCORE_MAX/2 : AVPROBE_SCORE_MAX/4;
48
+        return VOP+VO > 3 ? AVPROBE_SCORE_EXTENSION : AVPROBE_SCORE_EXTENSION/2;
49 49
     return 0;
50 50
 }
51 51
 
... ...
@@ -1060,7 +1060,7 @@ static int matroska_probe(AVProbeData *p)
1060 1060
     }
1061 1061
 
1062 1062
     // probably valid EBML header but no recognized doctype
1063
-    return AVPROBE_SCORE_MAX/2;
1063
+    return AVPROBE_SCORE_EXTENSION;
1064 1064
 }
1065 1065
 
1066 1066
 static MatroskaTrack *matroska_find_track_by_num(MatroskaDemuxContext *matroska,
... ...
@@ -79,7 +79,7 @@ static int probe(AVProbeData *p)
79 79
         return 0;
80 80
 
81 81
     /* only return half certainty since this check is a bit sketchy */
82
-    return AVPROBE_SCORE_MAX / 2;
82
+    return AVPROBE_SCORE_EXTENSION;
83 83
 }
84 84
 
85 85
 static int read_header(AVFormatContext *s)
... ...
@@ -2887,7 +2887,7 @@ static int mov_probe(AVProbeData *p)
2887 2887
                 (AV_RB32(p->buf+offset) != 1 ||
2888 2888
                  offset + 12 > (unsigned int)p->buf_size ||
2889 2889
                  AV_RB64(p->buf+offset + 8) == 0)) {
2890
-                score = FFMAX(score, AVPROBE_SCORE_MAX - 50);
2890
+                score = FFMAX(score, AVPROBE_SCORE_EXTENSION);
2891 2891
             } else {
2892 2892
                 score = AVPROBE_SCORE_MAX;
2893 2893
             }
... ...
@@ -2907,7 +2907,7 @@ static int mov_probe(AVProbeData *p)
2907 2907
         case MKTAG('u','u','i','d'):
2908 2908
         case MKTAG('p','r','f','l'):
2909 2909
             /* if we only find those cause probedata is too small at least rate them */
2910
-            score  = FFMAX(score, AVPROBE_SCORE_MAX - 50);
2910
+            score  = FFMAX(score, AVPROBE_SCORE_EXTENSION);
2911 2911
             offset = FFMAX(4, AV_RB32(p->buf+offset)) + offset;
2912 2912
             break;
2913 2913
         default:
... ...
@@ -76,11 +76,11 @@ static int mp3_read_probe(AVProbeData *p)
76 76
     }
77 77
     // keep this in sync with ac3 probe, both need to avoid
78 78
     // issues with MPEG-files!
79
-    if   (first_frames>=4) return AVPROBE_SCORE_MAX/2+1;
80
-    else if(max_frames>200)return AVPROBE_SCORE_MAX/2;
81
-    else if(max_frames>=4) return AVPROBE_SCORE_MAX/4;
79
+    if   (first_frames>=4) return AVPROBE_SCORE_EXTENSION + 1;
80
+    else if(max_frames>200)return AVPROBE_SCORE_EXTENSION;
81
+    else if(max_frames>=4) return AVPROBE_SCORE_EXTENSION / 2;
82 82
     else if(ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC) && 2*ff_id3v2_tag_len(buf0) >= p->buf_size)
83
-                           return AVPROBE_SCORE_MAX/8;
83
+                           return AVPROBE_SCORE_EXTENSION / 4;
84 84
     else if(max_frames>=1) return 1;
85 85
     else                   return 0;
86 86
 //mpegps_mp3_unrecognized_format.mpg has max_frames=3
... ...
@@ -92,7 +92,7 @@ static int mpc8_probe(AVProbeData *p)
92 92
         if (size < 2)
93 93
             return 0;
94 94
         if (bs + size - 2 >= bs_end)
95
-            return AVPROBE_SCORE_MAX / 4 - 1; //seems to be valid MPC but no header yet
95
+            return AVPROBE_SCORE_EXTENSION - 1; // seems to be valid MPC but no header yet
96 96
         if (header_found) {
97 97
             if (size < 11 || size > 28)
98 98
                 return 0;
... ...
@@ -89,14 +89,14 @@ static int mpegps_probe(AVProbeData *p)
89 89
     }
90 90
 
91 91
     if(vid+audio > invalid+1)     /* invalid VDR files nd short PES streams */
92
-        score= AVPROBE_SCORE_MAX/4;
92
+        score = AVPROBE_SCORE_EXTENSION / 2;
93 93
 
94 94
     if(sys>invalid && sys*9 <= pspack*10)
95
-        return (audio > 12 || vid > 3 || pspack > 2) ? AVPROBE_SCORE_MAX/2+2 : AVPROBE_SCORE_MAX/4; // +1 for .mpg
95
+        return (audio > 12 || vid > 3 || pspack > 2) ? AVPROBE_SCORE_EXTENSION + 2 : AVPROBE_SCORE_EXTENSION / 2; // 1 more than .mpg
96 96
     if(pspack > invalid && (priv1+vid+audio)*10 >= pspack*9)
97
-        return pspack > 2 ? AVPROBE_SCORE_MAX/2+2 : AVPROBE_SCORE_MAX/4; // +1 for .mpg
97
+        return pspack > 2 ? AVPROBE_SCORE_EXTENSION + 2 : AVPROBE_SCORE_EXTENSION / 2; // 1 more than .mpg
98 98
     if((!!vid ^ !!audio) && (audio > 4 || vid > 1) && !sys && !pspack && p->buf_size>2048 && vid + audio > invalid) /* PES stream */
99
-        return (audio > 12 || vid > 3 + 2*invalid) ? AVPROBE_SCORE_MAX/2+2 : AVPROBE_SCORE_MAX/4;
99
+        return (audio > 12 || vid > 3 + 2*invalid) ? AVPROBE_SCORE_EXTENSION + 2 : AVPROBE_SCORE_EXTENSION / 2;
100 100
 
101 101
     //02-Penguin.flac has sys:0 priv1:0 pspack:0 vid:0 audio:1
102 102
     //mp3_misidentified_2.mp3 has sys:0 priv1:0 pspack:0 vid:0 audio:6
... ...
@@ -63,8 +63,8 @@ static int mpegvideo_probe(AVProbeData *p)
63 63
         }
64 64
     }
65 65
     if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !apes && !res && slice > sicle) {
66
-        if(vpes) return AVPROBE_SCORE_MAX/8;
67
-        else     return pic>1 ? AVPROBE_SCORE_MAX/2+1 : AVPROBE_SCORE_MAX/4; // +1 for .mpg
66
+        if(vpes) return AVPROBE_SCORE_EXTENSION / 4;
67
+        else     return pic>1 ? AVPROBE_SCORE_EXTENSION + 1 : AVPROBE_SCORE_EXTENSION / 2; // +1 for .mpg
68 68
     }
69 69
     return 0;
70 70
 }
... ...
@@ -64,13 +64,13 @@ static int mtv_probe(AVProbeData *p)
64 64
     if(!AV_RL16(&p->buf[52]) || !AV_RL16(&p->buf[54]))
65 65
     {
66 66
         if(!!AV_RL16(&p->buf[56]))
67
-            return AVPROBE_SCORE_MAX/2;
67
+            return AVPROBE_SCORE_EXTENSION;
68 68
         else
69 69
             return 0;
70 70
     }
71 71
 
72 72
     if(p->buf[51] != 16)
73
-        return AVPROBE_SCORE_MAX/4; // But we are going to assume 16bpp anyway ..
73
+        return AVPROBE_SCORE_EXTENSION / 2; // But we are going to assume 16bpp anyway ..
74 74
 
75 75
     return AVPROBE_SCORE_MAX;
76 76
 }
... ...
@@ -786,7 +786,7 @@ static int nsv_probe(AVProbeData *p)
786 786
     }
787 787
     /* so we'll have more luck on extension... */
788 788
     if (av_match_ext(p->filename, "nsv"))
789
-        return AVPROBE_SCORE_MAX/2;
789
+        return AVPROBE_SCORE_EXTENSION;
790 790
     /* FIXME: add mime-type check */
791 791
     return score;
792 792
 }
... ...
@@ -433,7 +433,7 @@ static int oma_read_probe(AVProbeData *p)
433 433
     /* This check cannot overflow as tag_len has at most 28 bits */
434 434
     if (p->buf_size < tag_len + 5)
435 435
         /* EA3 header comes late, might be outside of the probe buffer */
436
-        return AVPROBE_SCORE_MAX / 2;
436
+        return AVPROBE_SCORE_EXTENSION;
437 437
 
438 438
     buf += tag_len;
439 439
 
... ...
@@ -126,7 +126,7 @@ static int str_probe(AVProbeData *p)
126 126
     }
127 127
     /* MPEG files (like those ripped from VCDs) can also look like this;
128 128
      * only return half certainty */
129
-    if(vid+aud > 3)  return 50;
129
+    if(vid+aud > 3)  return AVPROBE_SCORE_EXTENSION;
130 130
     else if(vid+aud) return 1;
131 131
     else             return 0;
132 132
 }
... ...
@@ -49,7 +49,7 @@ static int pva_probe(AVProbeData * pd) {
49 49
 
50 50
     if (pd->buf_size >= len + 8 &&
51 51
         pva_check(buf + len) >= 0)
52
-        return AVPROBE_SCORE_MAX / 2;
52
+        return AVPROBE_SCORE_EXTENSION;
53 53
 
54 54
     return AVPROBE_SCORE_MAX / 4;
55 55
 }
... ...
@@ -2030,7 +2030,7 @@ static int sdp_probe(AVProbeData *p1)
2030 2030
     while (p < p_end && *p != '\0') {
2031 2031
         if (p + sizeof("c=IN IP") - 1 < p_end &&
2032 2032
             av_strstart(p, "c=IN IP", NULL))
2033
-            return AVPROBE_SCORE_MAX / 2;
2033
+            return AVPROBE_SCORE_EXTENSION;
2034 2034
 
2035 2035
         while (p < p_end - 1 && *p != '\n') p++;
2036 2036
         if (++p >= p_end)
... ...
@@ -77,7 +77,7 @@ static int vmd_probe(AVProbeData *p)
77 77
         return 0;
78 78
 
79 79
     /* only return half certainty since this check is a bit sketchy */
80
-    return AVPROBE_SCORE_MAX / 2;
80
+    return AVPROBE_SCORE_EXTENSION;
81 81
 }
82 82
 
83 83
 static int vmd_read_header(AVFormatContext *s)
... ...
@@ -154,10 +154,10 @@ int ff_spdif_probe(const uint8_t *p_buf, int buf_size, enum AVCodecID *codec)
154 154
 
155 155
     if (sync_codes >= 6)
156 156
         /* good amount of sync codes but with unexpected offsets */
157
-        return AVPROBE_SCORE_MAX / 2;
157
+        return AVPROBE_SCORE_EXTENSION;
158 158
 
159 159
     /* some sync codes were found */
160
-    return AVPROBE_SCORE_MAX / 8;
160
+    return AVPROBE_SCORE_EXTENSION / 4;
161 161
 }
162 162
 
163 163
 static int spdif_read_header(AVFormatContext *s)
... ...
@@ -33,7 +33,7 @@ typedef struct TAKDemuxContext {
33 33
 static int tak_probe(AVProbeData *p)
34 34
 {
35 35
     if (!memcmp(p->buf, "tBaK", 4))
36
-        return AVPROBE_SCORE_MAX / 2;
36
+        return AVPROBE_SCORE_EXTENSION;
37 37
     return 0;
38 38
 }
39 39
 
... ...
@@ -36,7 +36,7 @@ static int tta_probe(AVProbeData *p)
36 36
     const uint8_t *d = p->buf;
37 37
 
38 38
     if (d[0] == 'T' && d[1] == 'T' && d[2] == 'A' && d[3] == '1')
39
-        return 80;
39
+        return AVPROBE_SCORE_EXTENSION + 30;
40 40
     return 0;
41 41
 }
42 42
 
... ...
@@ -376,10 +376,10 @@ AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score
376 376
         if (fmt1->read_probe) {
377 377
             score = fmt1->read_probe(&lpd);
378 378
             if(fmt1->extensions && av_match_ext(lpd.filename, fmt1->extensions))
379
-                score = FFMAX(score, nodat ? AVPROBE_SCORE_MAX/4-1 : 1);
379
+                score = FFMAX(score, nodat ? AVPROBE_SCORE_EXTENSION / 2 - 1 : 1);
380 380
         } else if (fmt1->extensions) {
381 381
             if (av_match_ext(lpd.filename, fmt1->extensions)) {
382
-                score = 50;
382
+                score = AVPROBE_SCORE_EXTENSION;
383 383
             }
384 384
         }
385 385
         if (score > score_max) {
... ...
@@ -389,7 +389,7 @@ AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score
389 389
             fmt = NULL;
390 390
     }
391 391
     if(nodat)
392
-        score_max = FFMIN(AVPROBE_SCORE_MAX/4-1, score_max);
392
+        score_max = FFMIN(AVPROBE_SCORE_EXTENSION / 2 - 1, score_max);
393 393
     *score_ret= score_max;
394 394
 
395 395
     return fmt;
... ...
@@ -39,7 +39,7 @@ static int vc1t_probe(AVProbeData *p)
39 39
     if (p->buf[3] != 0xC5 || AV_RL32(&p->buf[4]) != 4 || AV_RL32(&p->buf[20]) != 0xC)
40 40
         return 0;
41 41
 
42
-    return AVPROBE_SCORE_MAX/2;
42
+    return AVPROBE_SCORE_EXTENSION;
43 43
 }
44 44
 
45 45
 static int vc1t_read_header(AVFormatContext *s)
... ...
@@ -43,7 +43,7 @@ static int vqf_probe(AVProbeData *probe_packet)
43 43
     if (!memcmp(probe_packet->buf + 4, "00052200", 8))
44 44
         return AVPROBE_SCORE_MAX;
45 45
 
46
-    return AVPROBE_SCORE_MAX/2;
46
+    return AVPROBE_SCORE_EXTENSION;
47 47
 }
48 48
 
49 49
 static void add_metadata(AVFormatContext *s, uint32_t tag,
... ...
@@ -77,7 +77,7 @@ static int wsaud_probe(AVProbeData *p)
77 77
         return 0;
78 78
 
79 79
     /* return 1/2 certainty since this file check is a little sketchy */
80
-    return AVPROBE_SCORE_MAX / 2;
80
+    return AVPROBE_SCORE_EXTENSION;
81 81
 }
82 82
 
83 83
 static int wsaud_read_header(AVFormatContext *s)
... ...
@@ -59,7 +59,7 @@ static int xa_probe(AVProbeData *p)
59 59
     if (!channels || channels > 8 || !srate || srate > 192000 ||
60 60
         bits_per_sample < 4 || bits_per_sample > 32)
61 61
         return 0;
62
-    return AVPROBE_SCORE_MAX/2;
62
+    return AVPROBE_SCORE_EXTENSION;
63 63
 }
64 64
 
65 65
 static int xa_read_header(AVFormatContext *s)