v210enc.c 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (c) 2015 Henrik Gramner
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (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
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #include <string.h>
  21. #include "checkasm.h"
  22. #include "libavcodec/v210enc_init.h"
  23. #include "libavutil/common.h"
  24. #include "libavutil/internal.h"
  25. #include "libavutil/intreadwrite.h"
  26. #include "libavutil/mem_internal.h"
  27. #define BUF_SIZE 512
  28. #define randomize_buffers(mask) \
  29. do { \
  30. int i, size = sizeof(*y0); \
  31. for (i = 0; i < BUF_SIZE; i += 4 / size) { \
  32. uint32_t r = rnd() & mask; \
  33. AV_WN32A(y0 + i, r); \
  34. AV_WN32A(y1 + i, r); \
  35. } \
  36. for (i = 0; i < BUF_SIZE / 2; i += 4 / size) { \
  37. uint32_t r = rnd() & mask; \
  38. AV_WN32A(u0 + i, r); \
  39. AV_WN32A(u1 + i, r); \
  40. r = rnd() & mask; \
  41. AV_WN32A(v0 + i, r); \
  42. AV_WN32A(v1 + i, r); \
  43. } \
  44. for (i = 0; i < width * 8 / 3; i += 4) { \
  45. uint32_t r = rnd(); \
  46. AV_WN32A(dst0 + i, r); \
  47. AV_WN32A(dst1 + i, r); \
  48. } \
  49. } while (0)
  50. #define check_pack_line(type, mask) \
  51. do { \
  52. LOCAL_ALIGNED_16(type, y0, [BUF_SIZE]); \
  53. LOCAL_ALIGNED_16(type, y1, [BUF_SIZE]); \
  54. LOCAL_ALIGNED_16(type, u0, [BUF_SIZE / 2]); \
  55. LOCAL_ALIGNED_16(type, u1, [BUF_SIZE / 2]); \
  56. LOCAL_ALIGNED_16(type, v0, [BUF_SIZE / 2]); \
  57. LOCAL_ALIGNED_16(type, v1, [BUF_SIZE / 2]); \
  58. LOCAL_ALIGNED_16(uint8_t, dst0, [BUF_SIZE * 8 / 3]); \
  59. LOCAL_ALIGNED_16(uint8_t, dst1, [BUF_SIZE * 8 / 3]); \
  60. \
  61. declare_func(void, const type * y, const type * u, const type * v, \
  62. uint8_t * dst, ptrdiff_t width); \
  63. ptrdiff_t width, step = 12 / sizeof(type); \
  64. \
  65. for (width = step; width < BUF_SIZE - 15; width += step) { \
  66. int y_offset = rnd() & 15; \
  67. int uv_offset = y_offset / 2; \
  68. randomize_buffers(mask); \
  69. call_ref(y0 + y_offset, u0 + uv_offset, v0 + uv_offset, dst0, width); \
  70. call_new(y1 + y_offset, u1 + uv_offset, v1 + uv_offset, dst1, width); \
  71. if (memcmp(y0, y1, BUF_SIZE * sizeof(type)) \
  72. || memcmp(u0, u1, BUF_SIZE * sizeof(type) / 2) \
  73. || memcmp(v0, v1, BUF_SIZE * sizeof(type) / 2) \
  74. || memcmp(dst0, dst1, width * 8 / 3)) \
  75. fail(); \
  76. bench_new(y1 + y_offset, u1 + uv_offset, v1 + uv_offset, dst1, width); \
  77. } \
  78. } while (0)
  79. void checkasm_check_v210enc(void)
  80. {
  81. V210EncContext h;
  82. ff_v210enc_init(&h);
  83. if (check_func(h.pack_line_8, "v210_planar_pack_8"))
  84. check_pack_line(uint8_t, 0xffffffff);
  85. if (check_func(h.pack_line_10, "v210_planar_pack_10"))
  86. check_pack_line(uint16_t, 0x03ff03ff);
  87. report("planar_pack");
  88. }