00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdlib.h>
00022
00023 #include "libavformat/avformat.h"
00024 #include "libavcodec/put_bits.h"
00025 #include "libavutil/lfg.h"
00026
00027 static int score_array[1000];
00028 static int failures = 0;
00029
00030 static void probe(AVProbeData *pd, int type, int p, int size)
00031 {
00032 int i = 0;
00033 AVInputFormat *fmt = NULL;
00034
00035 while ((fmt = av_iformat_next(fmt))) {
00036 if (fmt->flags & AVFMT_NOFILE)
00037 continue;
00038 if (fmt->read_probe) {
00039 int score = fmt->read_probe(pd);
00040 if (score > score_array[i] && score > AVPROBE_SCORE_MAX / 4) {
00041 score_array[i] = score;
00042 fprintf(stderr,
00043 "Failure of %s probing code with score=%d type=%d p=%X size=%d\n",
00044 fmt->name, score, type, p, size);
00045 failures++;
00046 }
00047 }
00048 i++;
00049 }
00050 }
00051
00052 int main(int argc, char **argv)
00053 {
00054 unsigned int p, i, type, size, retry;
00055 AVProbeData pd;
00056 AVLFG state;
00057 PutBitContext pb;
00058 int retry_count= 4097;
00059 int max_size = 65537;
00060
00061 if(argc >= 2)
00062 retry_count = atoi(argv[1]);
00063 if(argc >= 3)
00064 max_size = atoi(argv[2]);
00065
00066 avcodec_register_all();
00067 av_register_all();
00068
00069 av_lfg_init(&state, 0xdeadbeef);
00070
00071 pd.buf = NULL;
00072 for (size = 1; size < max_size; size *= 2) {
00073 pd.buf_size = size;
00074 pd.buf = av_realloc(pd.buf, size + AVPROBE_PADDING_SIZE);
00075 pd.filename = "";
00076
00077 fprintf(stderr, "testing size=%d\n", size);
00078
00079 for (retry = 0; retry < retry_count; retry += FFMAX(size, 32)) {
00080 for (type = 0; type < 4; type++) {
00081 for (p = 0; p < 4096; p++) {
00082 unsigned hist = 0;
00083 init_put_bits(&pb, pd.buf, size);
00084 switch (type) {
00085 case 0:
00086 for (i = 0; i < size * 8; i++)
00087 put_bits(&pb, 1, (av_lfg_get(&state) & 0xFFFFFFFF) > p << 20);
00088 break;
00089 case 1:
00090 for (i = 0; i < size * 8; i++) {
00091 unsigned int p2 = hist ? p & 0x3F : (p >> 6);
00092 unsigned int v = (av_lfg_get(&state) & 0xFFFFFFFF) > p2 << 26;
00093 put_bits(&pb, 1, v);
00094 hist = v;
00095 }
00096 break;
00097 case 2:
00098 for (i = 0; i < size * 8; i++) {
00099 unsigned int p2 = (p >> (hist * 3)) & 7;
00100 unsigned int v = (av_lfg_get(&state) & 0xFFFFFFFF) > p2 << 29;
00101 put_bits(&pb, 1, v);
00102 hist = (2 * hist + v) & 3;
00103 }
00104 break;
00105 case 3:
00106 for (i = 0; i < size; i++) {
00107 int c = 0;
00108 while (p & 63) {
00109 c = (av_lfg_get(&state) & 0xFFFFFFFF) >> 24;
00110 if (c >= 'a' && c <= 'z' && (p & 1))
00111 break;
00112 else if (c >= 'A' && c <= 'Z' && (p & 2))
00113 break;
00114 else if (c >= '0' && c <= '9' && (p & 4))
00115 break;
00116 else if (c == ' ' && (p & 8))
00117 break;
00118 else if (c == 0 && (p & 16))
00119 break;
00120 else if (c == 1 && (p & 32))
00121 break;
00122 }
00123 pd.buf[i] = c;
00124 }
00125 }
00126 flush_put_bits(&pb);
00127 probe(&pd, type, p, size);
00128 }
00129 }
00130 }
00131 }
00132 return failures;
00133 }