You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
4.2KB

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