mpegvideoencdsp.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "libavutil/intreadwrite.h"
  19. #include "libavutil/mem.h"
  20. #include "libavutil/mem_internal.h"
  21. #include "libavcodec/mpegvideoencdsp.h"
  22. #include "checkasm.h"
  23. #define randomize_buffers(buf, size) \
  24. do { \
  25. for (int j = 0; j < size; j += 4) \
  26. AV_WN32(buf + j, rnd()); \
  27. } while (0)
  28. static void check_pix_sum(MpegvideoEncDSPContext *c)
  29. {
  30. LOCAL_ALIGNED_16(uint8_t, src, [16 * 16]);
  31. declare_func(int, const uint8_t *pix, ptrdiff_t line_size);
  32. randomize_buffers(src, 16 * 16);
  33. for (int n = 0; n < 2; n++) {
  34. const char *negstride_str = n ? "_negstride" : "";
  35. if (check_func(c->pix_sum, "pix_sum%s", negstride_str)) {
  36. int sum0, sum1;
  37. const uint8_t *pix = src + (n ? (15 * 16) : 0);
  38. ptrdiff_t line_size = 16 * (n ? -1 : 1);
  39. sum0 = call_ref(pix, line_size);
  40. sum1 = call_new(pix, line_size);
  41. if (sum0 != sum1)
  42. fail();
  43. bench_new(pix, line_size);
  44. }
  45. }
  46. }
  47. static void check_pix_norm1(MpegvideoEncDSPContext *c)
  48. {
  49. LOCAL_ALIGNED_16(uint8_t, src, [16 * 16]);
  50. declare_func(int, const uint8_t *pix, ptrdiff_t line_size);
  51. randomize_buffers(src, 16 * 16);
  52. for (int n = 0; n < 2; n++) {
  53. const char *negstride_str = n ? "_negstride" : "";
  54. if (check_func(c->pix_norm1, "pix_norm1%s", negstride_str)) {
  55. int sum0, sum1;
  56. const uint8_t *pix = src + (n ? (15 * 16) : 0);
  57. ptrdiff_t line_size = 16 * (n ? -1 : 1);
  58. sum0 = call_ref(pix, line_size);
  59. sum1 = call_new(pix, line_size);
  60. if (sum0 != sum1)
  61. fail();
  62. bench_new(pix, line_size);
  63. }
  64. }
  65. }
  66. #define NUM_LINES 4
  67. #define MAX_LINE_SIZE 1920
  68. #define EDGE_WIDTH 16
  69. #define LINESIZE (EDGE_WIDTH + MAX_LINE_SIZE + EDGE_WIDTH)
  70. #define BUFSIZE ((EDGE_WIDTH + NUM_LINES + EDGE_WIDTH) * LINESIZE)
  71. static void check_draw_edges(MpegvideoEncDSPContext *c)
  72. {
  73. static const int input_sizes[] = {8, 128, 1080, MAX_LINE_SIZE, -MAX_LINE_SIZE};
  74. LOCAL_ALIGNED_16(uint8_t, buf0, [BUFSIZE]);
  75. LOCAL_ALIGNED_16(uint8_t, buf1, [BUFSIZE]);
  76. declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *buf, ptrdiff_t wrap, int width, int height,
  77. int w, int h, int sides);
  78. for (int isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); isi++) {
  79. int input_size = input_sizes[isi];
  80. int negstride = input_size < 0;
  81. const char *negstride_str = negstride ? "_negstride" : "";
  82. int width = FFABS(input_size);
  83. ptrdiff_t linesize = EDGE_WIDTH + width + EDGE_WIDTH;
  84. /* calculate height based on specified width to use the entire buffer. */
  85. int height = (BUFSIZE / linesize) - (2 * EDGE_WIDTH);
  86. uint8_t *dst0 = buf0 + EDGE_WIDTH * linesize + EDGE_WIDTH;
  87. uint8_t *dst1 = buf1 + EDGE_WIDTH * linesize + EDGE_WIDTH;
  88. if (negstride) {
  89. dst0 += (height - 1) * linesize;
  90. dst1 += (height - 1) * linesize;
  91. linesize *= -1;
  92. }
  93. for (int shift = 0; shift < 3; shift++) {
  94. int edge = EDGE_WIDTH >> shift;
  95. if (check_func(c->draw_edges, "draw_edges_%d_%d_%d%s", width, height, edge, negstride_str)) {
  96. randomize_buffers(buf0, BUFSIZE);
  97. memcpy(buf1, buf0, BUFSIZE);
  98. call_ref(dst0, linesize, width, height, edge, edge, EDGE_BOTTOM | EDGE_TOP);
  99. call_new(dst1, linesize, width, height, edge, edge, EDGE_BOTTOM | EDGE_TOP);
  100. if (memcmp(buf0, buf1, BUFSIZE))
  101. fail();
  102. bench_new(dst1, linesize, width, height, edge, edge, EDGE_BOTTOM | EDGE_TOP);
  103. }
  104. }
  105. }
  106. }
  107. #undef NUM_LINES
  108. #undef MAX_LINE_SIZE
  109. #undef EDGE_WIDTH
  110. #undef LINESIZE
  111. #undef BUFSIZE
  112. void checkasm_check_mpegvideoencdsp(void)
  113. {
  114. AVCodecContext avctx = {
  115. .bits_per_raw_sample = 8,
  116. };
  117. MpegvideoEncDSPContext c = { 0 };
  118. ff_mpegvideoencdsp_init(&c, &avctx);
  119. check_pix_sum(&c);
  120. report("pix_sum");
  121. check_pix_norm1(&c);
  122. report("pix_norm1");
  123. check_draw_edges(&c);
  124. report("draw_edges");
  125. }