2 * copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "libavformat/avformat.h"
24 #include "libavcodec/put_bits.h"
25 #include "libavutil/lfg.h"
26 #include "libavutil/timer.h"
28 #define MAX_FORMATS 1000 //this must be larger than the number of formats
29 static int score_array
[MAX_FORMATS
];
30 static int64_t time_array
[MAX_FORMATS
];
31 static int failures
= 0;
34 #define AV_READ_TIME(x) 0
37 static void probe(AVProbeData
*pd
, int type
, int p
, int size
)
40 AVInputFormat
*fmt
= NULL
;
42 while ((fmt
= av_iformat_next(fmt
))) {
43 if (fmt
->flags
& AVFMT_NOFILE
)
45 if (fmt
->read_probe
) {
47 int64_t start
= AV_READ_TIME();
48 score
= fmt
->read_probe(pd
);
49 time_array
[i
] += AV_READ_TIME() - start
;
50 if (score
> score_array
[i
] && score
> AVPROBE_SCORE_MAX
/ 4) {
51 score_array
[i
] = score
;
53 "Failure of %s probing code with score=%d type=%d p=%X size=%d\n",
54 fmt
->name
, score
, type
, p
, size
);
62 static void print_times(void)
65 AVInputFormat
*fmt
= NULL
;
67 while ((fmt
= av_iformat_next(fmt
))) {
68 if (fmt
->flags
& AVFMT_NOFILE
)
70 if (time_array
[i
] > 1000000) {
71 fprintf(stderr
, "%12"PRIu64
" cycles, %12s\n",
72 time_array
[i
], fmt
->name
);
78 int main(int argc
, char **argv
)
80 unsigned int p
, i
, type
, size
, retry
;
81 AVProbeData pd
= { 0 };
84 int retry_count
= 4097;
88 retry_count
= atoi(argv
[1]);
90 max_size
= atoi(argv
[2]);
92 if (max_size
> 1000000000U/8) {
93 fprintf(stderr
, "max_size out of bounds\n");
97 if (retry_count
> 1000000000U) {
98 fprintf(stderr
, "retry_count out of bounds\n");
102 avcodec_register_all();
105 av_lfg_init(&state
, 0xdeadbeef);
108 for (size
= 1; size
< max_size
; size
*= 2) {
110 pd
.buf
= av_realloc(pd
.buf
, size
+ AVPROBE_PADDING_SIZE
);
114 fprintf(stderr
, "out of memory\n");
118 memset(pd
.buf
, 0, size
+ AVPROBE_PADDING_SIZE
);
120 fprintf(stderr
, "testing size=%d\n", size
);
122 for (retry
= 0; retry
< retry_count
; retry
+= FFMAX(size
, 32)) {
123 for (type
= 0; type
< 4; type
++) {
124 for (p
= 0; p
< 4096; p
++) {
126 init_put_bits(&pb
, pd
.buf
, size
);
129 for (i
= 0; i
< size
* 8; i
++)
130 put_bits(&pb
, 1, (av_lfg_get(&state
) & 0xFFFFFFFF) > p
<< 20);
133 for (i
= 0; i
< size
* 8; i
++) {
134 unsigned int p2
= hist
? p
& 0x3F : (p
>> 6);
135 unsigned int v
= (av_lfg_get(&state
) & 0xFFFFFFFF) > p2
<< 26;
141 for (i
= 0; i
< size
* 8; i
++) {
142 unsigned int p2
= (p
>> (hist
* 3)) & 7;
143 unsigned int v
= (av_lfg_get(&state
) & 0xFFFFFFFF) > p2
<< 29;
145 hist
= (2 * hist
+ v
) & 3;
149 for (i
= 0; i
< size
; i
++) {
152 c
= (av_lfg_get(&state
) & 0xFFFFFFFF) >> 24;
153 if (c
>= 'a' && c
<= 'z' && (p
& 1))
155 else if (c
>= 'A' && c
<= 'Z' && (p
& 2))
157 else if (c
>= '0' && c
<= '9' && (p
& 4))
159 else if (c
== ' ' && (p
& 8))
161 else if (c
== 0 && (p
& 16))
163 else if (c
== 1 && (p
& 32))
170 probe(&pd
, type
, p
, size
);