probetest.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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, "Failure of %s probing code with score=%d type=%d p=%X size=%d\n",
  38. fmt->name, score, type, p, size);
  39. failures++;
  40. }
  41. }
  42. i++;
  43. }
  44. }
  45. int main(void)
  46. {
  47. unsigned int p, i, type, size, retry;
  48. AVProbeData pd;
  49. AVLFG state;
  50. PutBitContext pb;
  51. avcodec_register_all();
  52. av_register_all();
  53. av_lfg_init(&state, 0xdeadbeef);
  54. pd.buf = NULL;
  55. for (size = 1; size < 65537; size *= 2) {
  56. pd.buf_size = size;
  57. pd.buf = av_realloc(pd.buf, size + AVPROBE_PADDING_SIZE);
  58. pd.filename = "";
  59. fprintf(stderr, "testing size=%d\n", size);
  60. for (retry = 0; retry < 4097; retry += FFMAX(size, 32)) {
  61. for (type = 0; type < 4; type++) {
  62. for (p = 0; p < 4096; p++) {
  63. unsigned hist = 0;
  64. init_put_bits(&pb, pd.buf, size);
  65. switch (type) {
  66. case 0:
  67. for (i = 0; i < size * 8; i++) {
  68. put_bits(&pb, 1, (av_lfg_get(&state) & 0xFFFFFFFF) > p << 20);
  69. }
  70. break;
  71. case 1:
  72. for (i = 0; i < size * 8; i++) {
  73. unsigned int p2 = hist ? p & 0x3F : (p >> 6);
  74. unsigned int v = (av_lfg_get(&state) & 0xFFFFFFFF) > p2 << 26;
  75. put_bits(&pb, 1, v);
  76. hist = v;
  77. }
  78. break;
  79. case 2:
  80. for (i = 0; i < size * 8; i++) {
  81. unsigned int p2 = (p >> (hist*3)) & 7;
  82. unsigned int v = (av_lfg_get(&state) & 0xFFFFFFFF) > p2 << 29;
  83. put_bits(&pb, 1, v);
  84. hist = (2*hist + v) & 3;
  85. }
  86. break;
  87. case 3:
  88. for (i = 0; i < size; i++) {
  89. int c = 0;
  90. while (p & 63) {
  91. c = (av_lfg_get(&state) & 0xFFFFFFFF) >> 24;
  92. if (c >= 'a' && c <= 'z' && (p & 1)) break;
  93. else if(c >= 'A' && c <= 'Z' && (p & 2)) break;
  94. else if(c >= '0' && c <= '9' && (p & 4)) break;
  95. else if(c == ' ' && (p & 8)) break;
  96. else if(c == 0 && (p & 16)) break;
  97. else if(c == 1 && (p & 32)) break;
  98. }
  99. pd.buf[i] = c;
  100. }
  101. }
  102. flush_put_bits(&pb);
  103. probe(&pd, type, p, size);
  104. }
  105. }
  106. }
  107. }
  108. return failures;
  109. }