probetest.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  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.
  10. *
  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.
  15. *
  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
  19. */
  20. #include <stdlib.h>
  21. #include "libavformat/avformat.h"
  22. #include "libavcodec/put_bits.h"
  23. #include "libavutil/lfg.h"
  24. static int score_array[1000]; //this must be larger than the number of formats
  25. static int failures = 0;
  26. static void probe(AVProbeData *pd, int type, int p, int size)
  27. {
  28. int i = 0;
  29. AVInputFormat *fmt = NULL;
  30. while ((fmt = av_iformat_next(fmt))) {
  31. if (fmt->flags & AVFMT_NOFILE)
  32. continue;
  33. if (fmt->read_probe) {
  34. int score = fmt->read_probe(pd);
  35. if (score > score_array[i] && score > AVPROBE_SCORE_MAX / 4) {
  36. score_array[i] = score;
  37. fprintf(stderr,
  38. "Failure of %s probing code with score=%d type=%d p=%X size=%d\n",
  39. fmt->name, score, type, p, size);
  40. failures++;
  41. }
  42. }
  43. i++;
  44. }
  45. }
  46. int main(int argc, char **argv)
  47. {
  48. unsigned int p, i, type, size, retry;
  49. AVProbeData pd;
  50. AVLFG state;
  51. PutBitContext pb;
  52. int retry_count= 4097;
  53. int max_size = 65537;
  54. if(argc >= 2)
  55. retry_count = atoi(argv[1]);
  56. if(argc >= 3)
  57. max_size = atoi(argv[2]);
  58. avcodec_register_all();
  59. av_register_all();
  60. av_lfg_init(&state, 0xdeadbeef);
  61. pd.buf = NULL;
  62. for (size = 1; size < max_size; size *= 2) {
  63. pd.buf_size = size;
  64. pd.buf = av_realloc(pd.buf, size + AVPROBE_PADDING_SIZE);
  65. pd.filename = "";
  66. fprintf(stderr, "testing size=%d\n", size);
  67. for (retry = 0; retry < retry_count; retry += FFMAX(size, 32)) {
  68. for (type = 0; type < 4; type++) {
  69. for (p = 0; p < 4096; p++) {
  70. unsigned hist = 0;
  71. init_put_bits(&pb, pd.buf, size);
  72. switch (type) {
  73. case 0:
  74. for (i = 0; i < size * 8; i++)
  75. put_bits(&pb, 1, (av_lfg_get(&state) & 0xFFFFFFFF) > p << 20);
  76. break;
  77. case 1:
  78. for (i = 0; i < size * 8; i++) {
  79. unsigned int p2 = hist ? p & 0x3F : (p >> 6);
  80. unsigned int v = (av_lfg_get(&state) & 0xFFFFFFFF) > p2 << 26;
  81. put_bits(&pb, 1, v);
  82. hist = v;
  83. }
  84. break;
  85. case 2:
  86. for (i = 0; i < size * 8; i++) {
  87. unsigned int p2 = (p >> (hist * 3)) & 7;
  88. unsigned int v = (av_lfg_get(&state) & 0xFFFFFFFF) > p2 << 29;
  89. put_bits(&pb, 1, v);
  90. hist = (2 * hist + v) & 3;
  91. }
  92. break;
  93. case 3:
  94. for (i = 0; i < size; i++) {
  95. int c = 0;
  96. while (p & 63) {
  97. c = (av_lfg_get(&state) & 0xFFFFFFFF) >> 24;
  98. if (c >= 'a' && c <= 'z' && (p & 1))
  99. break;
  100. else if (c >= 'A' && c <= 'Z' && (p & 2))
  101. break;
  102. else if (c >= '0' && c <= '9' && (p & 4))
  103. break;
  104. else if (c == ' ' && (p & 8))
  105. break;
  106. else if (c == 0 && (p & 16))
  107. break;
  108. else if (c == 1 && (p & 32))
  109. break;
  110. }
  111. pd.buf[i] = c;
  112. }
  113. }
  114. flush_put_bits(&pb);
  115. probe(&pd, type, p, size);
  116. }
  117. }
  118. }
  119. }
  120. return failures;
  121. }