probetest.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. if (max_size > 1000000000U/8) {
  59. fprintf(stderr, "max_size out of bounds\n");
  60. return 1;
  61. }
  62. if (retry_count > 1000000000U) {
  63. fprintf(stderr, "retry_count out of bounds\n");
  64. return 1;
  65. }
  66. avcodec_register_all();
  67. av_register_all();
  68. av_lfg_init(&state, 0xdeadbeef);
  69. pd.buf = NULL;
  70. for (size = 1; size < max_size; size *= 2) {
  71. pd.buf_size = size;
  72. pd.buf = av_realloc(pd.buf, size + AVPROBE_PADDING_SIZE);
  73. pd.filename = "";
  74. memset(pd.buf, 0, size + AVPROBE_PADDING_SIZE);
  75. fprintf(stderr, "testing size=%d\n", size);
  76. for (retry = 0; retry < retry_count; retry += FFMAX(size, 32)) {
  77. for (type = 0; type < 4; type++) {
  78. for (p = 0; p < 4096; p++) {
  79. unsigned hist = 0;
  80. init_put_bits(&pb, pd.buf, size);
  81. switch (type) {
  82. case 0:
  83. for (i = 0; i < size * 8; i++)
  84. put_bits(&pb, 1, (av_lfg_get(&state) & 0xFFFFFFFF) > p << 20);
  85. break;
  86. case 1:
  87. for (i = 0; i < size * 8; i++) {
  88. unsigned int p2 = hist ? p & 0x3F : (p >> 6);
  89. unsigned int v = (av_lfg_get(&state) & 0xFFFFFFFF) > p2 << 26;
  90. put_bits(&pb, 1, v);
  91. hist = v;
  92. }
  93. break;
  94. case 2:
  95. for (i = 0; i < size * 8; i++) {
  96. unsigned int p2 = (p >> (hist * 3)) & 7;
  97. unsigned int v = (av_lfg_get(&state) & 0xFFFFFFFF) > p2 << 29;
  98. put_bits(&pb, 1, v);
  99. hist = (2 * hist + v) & 3;
  100. }
  101. break;
  102. case 3:
  103. for (i = 0; i < size; i++) {
  104. int c = 0;
  105. while (p & 63) {
  106. c = (av_lfg_get(&state) & 0xFFFFFFFF) >> 24;
  107. if (c >= 'a' && c <= 'z' && (p & 1))
  108. break;
  109. else if (c >= 'A' && c <= 'Z' && (p & 2))
  110. break;
  111. else if (c >= '0' && c <= '9' && (p & 4))
  112. break;
  113. else if (c == ' ' && (p & 8))
  114. break;
  115. else if (c == 0 && (p & 16))
  116. break;
  117. else if (c == 1 && (p & 32))
  118. break;
  119. }
  120. pd.buf[i] = c;
  121. }
  122. }
  123. flush_put_bits(&pb);
  124. probe(&pd, type, p, size);
  125. }
  126. }
  127. }
  128. }
  129. return failures;
  130. }