tools/probetest.c
Go to the documentation of this file.
00001 /*
00002  * copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at>
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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]; //this must be larger than the number of formats
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(void)
00053 {
00054     unsigned int p, i, type, size, retry;
00055     AVProbeData pd;
00056     AVLFG state;
00057     PutBitContext pb;
00058 
00059     avcodec_register_all();
00060     av_register_all();
00061 
00062     av_lfg_init(&state, 0xdeadbeef);
00063 
00064     pd.buf = NULL;
00065     for (size = 1; size < 65537; size *= 2) {
00066         pd.buf_size = size;
00067         pd.buf      = av_realloc(pd.buf, size + AVPROBE_PADDING_SIZE);
00068         pd.filename = "";
00069 
00070         fprintf(stderr, "testing size=%d\n", size);
00071 
00072         for (retry = 0; retry < 4097; retry += FFMAX(size, 32)) {
00073             for (type = 0; type < 4; type++) {
00074                 for (p = 0; p < 4096; p++) {
00075                     unsigned hist = 0;
00076                     init_put_bits(&pb, pd.buf, size);
00077                     switch (type) {
00078                     case 0:
00079                         for (i = 0; i < size * 8; i++)
00080                             put_bits(&pb, 1, (av_lfg_get(&state) & 0xFFFFFFFF) > p << 20);
00081                         break;
00082                     case 1:
00083                         for (i = 0; i < size * 8; i++) {
00084                             unsigned int p2 = hist ? p & 0x3F : (p >> 6);
00085                             unsigned int v  = (av_lfg_get(&state) & 0xFFFFFFFF) > p2 << 26;
00086                             put_bits(&pb, 1, v);
00087                             hist = v;
00088                         }
00089                         break;
00090                     case 2:
00091                         for (i = 0; i < size * 8; i++) {
00092                             unsigned int p2 = (p >> (hist * 3)) & 7;
00093                             unsigned int v  = (av_lfg_get(&state) & 0xFFFFFFFF) > p2 << 29;
00094                             put_bits(&pb, 1, v);
00095                             hist = (2 * hist + v) & 3;
00096                         }
00097                         break;
00098                     case 3:
00099                         for (i = 0; i < size; i++) {
00100                             int c = 0;
00101                             while (p & 63) {
00102                                 c = (av_lfg_get(&state) & 0xFFFFFFFF) >> 24;
00103                                 if (c >= 'a' && c <= 'z' && (p & 1))
00104                                     break;
00105                                 else if (c >= 'A' && c <= 'Z' && (p & 2))
00106                                     break;
00107                                 else if (c >= '0' && c <= '9' && (p & 4))
00108                                     break;
00109                                 else if (c == ' ' && (p & 8))
00110                                     break;
00111                                 else if (c == 0 && (p & 16))
00112                                     break;
00113                                 else if (c == 1 && (p & 32))
00114                                     break;
00115                             }
00116                             pd.buf[i] = c;
00117                         }
00118                     }
00119                     flush_put_bits(&pb);
00120                     probe(&pd, type, p, size);
00121                 }
00122             }
00123         }
00124     }
00125     return failures;
00126 }