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.

168 lines
3.9KB

  1. /*
  2. * (c) 2001 Fabrice Bellard
  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. /**
  21. * @file libavcodec/motion-test.c
  22. * motion test.
  23. */
  24. #include <stdlib.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include <sys/time.h>
  28. #include <unistd.h>
  29. #include "config.h"
  30. #include "dsputil.h"
  31. #include "libavutil/lfg.h"
  32. #undef exit
  33. #undef printf
  34. #define WIDTH 64
  35. #define HEIGHT 64
  36. uint8_t img1[WIDTH * HEIGHT];
  37. uint8_t img2[WIDTH * HEIGHT];
  38. static void fill_random(uint8_t *tab, int size)
  39. {
  40. int i;
  41. AVLFG prng;
  42. av_lfg_init(&prng, 1);
  43. for(i=0;i<size;i++) {
  44. #if 1
  45. tab[i] = av_lfg_get(&prng) % 256;
  46. #else
  47. tab[i] = i;
  48. #endif
  49. }
  50. }
  51. static void help(void)
  52. {
  53. printf("motion-test [-h]\n"
  54. "test motion implementations\n");
  55. exit(1);
  56. }
  57. static int64_t gettime(void)
  58. {
  59. struct timeval tv;
  60. gettimeofday(&tv,NULL);
  61. return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
  62. }
  63. #define NB_ITS 500
  64. int dummy;
  65. static void test_motion(const char *name,
  66. me_cmp_func test_func, me_cmp_func ref_func)
  67. {
  68. int x, y, d1, d2, it;
  69. uint8_t *ptr;
  70. int64_t ti;
  71. printf("testing '%s'\n", name);
  72. /* test correctness */
  73. for(it=0;it<20;it++) {
  74. fill_random(img1, WIDTH * HEIGHT);
  75. fill_random(img2, WIDTH * HEIGHT);
  76. for(y=0;y<HEIGHT-17;y++) {
  77. for(x=0;x<WIDTH-17;x++) {
  78. ptr = img2 + y * WIDTH + x;
  79. d1 = test_func(NULL, img1, ptr, WIDTH, 1);
  80. d2 = ref_func(NULL, img1, ptr, WIDTH, 1);
  81. if (d1 != d2) {
  82. printf("error: mmx=%d c=%d\n", d1, d2);
  83. }
  84. }
  85. }
  86. }
  87. emms_c();
  88. /* speed test */
  89. ti = gettime();
  90. d1 = 0;
  91. for(it=0;it<NB_ITS;it++) {
  92. for(y=0;y<HEIGHT-17;y++) {
  93. for(x=0;x<WIDTH-17;x++) {
  94. ptr = img2 + y * WIDTH + x;
  95. d1 += test_func(NULL, img1, ptr, WIDTH, 1);
  96. }
  97. }
  98. }
  99. emms_c();
  100. dummy = d1; /* avoid optimization */
  101. ti = gettime() - ti;
  102. printf(" %0.0f kop/s\n",
  103. (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) /
  104. (double)(ti / 1000.0));
  105. }
  106. int main(int argc, char **argv)
  107. {
  108. AVCodecContext *ctx;
  109. int c;
  110. DSPContext cctx, mmxctx;
  111. int flags[2] = { FF_MM_MMX, FF_MM_MMX2 };
  112. int flags_size = HAVE_MMX2 ? 2 : 1;
  113. for(;;) {
  114. c = getopt(argc, argv, "h");
  115. if (c == -1)
  116. break;
  117. switch(c) {
  118. case 'h':
  119. help();
  120. break;
  121. }
  122. }
  123. printf("ffmpeg motion test\n");
  124. ctx = avcodec_alloc_context();
  125. ctx->dsp_mask = FF_MM_FORCE;
  126. dsputil_init(&cctx, ctx);
  127. for (c = 0; c < flags_size; c++) {
  128. int x;
  129. ctx->dsp_mask = FF_MM_FORCE | flags[c];
  130. dsputil_init(&mmxctx, ctx);
  131. for (x = 0; x < 2; x++) {
  132. printf("%s for %dx%d pixels\n", c ? "mmx2" : "mmx",
  133. x ? 8 : 16, x ? 8 : 16);
  134. test_motion("mmx", mmxctx.pix_abs[x][0], cctx.pix_abs[x][0]);
  135. test_motion("mmx_x2", mmxctx.pix_abs[x][1], cctx.pix_abs[x][1]);
  136. test_motion("mmx_y2", mmxctx.pix_abs[x][2], cctx.pix_abs[x][2]);
  137. test_motion("mmx_xy2", mmxctx.pix_abs[x][3], cctx.pix_abs[x][3]);
  138. }
  139. }
  140. av_free(ctx);
  141. return 0;
  142. }