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.

152 lines
6.0KB

  1. /*
  2. * Copyright (c) 2018 Yingming Fan <yingmingfan@gmail.com>
  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 "libavutil/intreadwrite.h"
  22. #include "libavutil/mem_internal.h"
  23. #include "libavcodec/avcodec.h"
  24. #include "libavcodec/hevcdsp.h"
  25. #include "checkasm.h"
  26. static const uint32_t pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff };
  27. static const uint32_t sao_size[5] = {8, 16, 32, 48, 64};
  28. #define SIZEOF_PIXEL ((bit_depth + 7) / 8)
  29. #define PIXEL_STRIDE (2*MAX_PB_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) //same with sao_edge src_stride
  30. #define BUF_SIZE (PIXEL_STRIDE * (64+2) * 2) //+2 for top and bottom row, *2 for high bit depth
  31. #define OFFSET_THRESH (1 << (bit_depth - 5))
  32. #define OFFSET_LENGTH 5
  33. #define randomize_buffers(buf0, buf1, size) \
  34. do { \
  35. uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
  36. int k; \
  37. for (k = 0; k < size; k += 4) { \
  38. uint32_t r = rnd() & mask; \
  39. AV_WN32A(buf0 + k, r); \
  40. AV_WN32A(buf1 + k, r); \
  41. } \
  42. } while (0)
  43. #define randomize_buffers2(buf, size) \
  44. do { \
  45. uint32_t max_offset = OFFSET_THRESH; \
  46. int k; \
  47. if (bit_depth == 8) { \
  48. for (k = 0; k < size; k++) { \
  49. uint8_t r = rnd() % max_offset; \
  50. buf[k] = r; \
  51. } \
  52. } else { \
  53. for (k = 0; k < size; k++) { \
  54. uint16_t r = rnd() % max_offset; \
  55. buf[k] = r; \
  56. } \
  57. } \
  58. } while (0)
  59. static void check_sao_band(HEVCDSPContext h, int bit_depth)
  60. {
  61. int i;
  62. LOCAL_ALIGNED_32(uint8_t, dst0, [BUF_SIZE]);
  63. LOCAL_ALIGNED_32(uint8_t, dst1, [BUF_SIZE]);
  64. LOCAL_ALIGNED_32(uint8_t, src0, [BUF_SIZE]);
  65. LOCAL_ALIGNED_32(uint8_t, src1, [BUF_SIZE]);
  66. int16_t offset_val[OFFSET_LENGTH];
  67. int left_class = rnd()%32;
  68. for (i = 0; i <= 4; i++) {
  69. int block_size = sao_size[i];
  70. ptrdiff_t stride = PIXEL_STRIDE*SIZEOF_PIXEL;
  71. declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, uint8_t *src, ptrdiff_t dst_stride, ptrdiff_t src_stride,
  72. int16_t *sao_offset_val, int sao_left_class, int width, int height);
  73. randomize_buffers(src0, src1, BUF_SIZE);
  74. randomize_buffers2(offset_val, OFFSET_LENGTH);
  75. memset(dst0, 0, BUF_SIZE);
  76. memset(dst1, 0, BUF_SIZE);
  77. if (check_func(h.sao_band_filter[i], "hevc_sao_band_%dx%d_%d", block_size, block_size, bit_depth)) {
  78. call_ref(dst0, src0, stride, stride, offset_val, left_class, block_size, block_size);
  79. call_new(dst1, src1, stride, stride, offset_val, left_class, block_size, block_size);
  80. if (memcmp(dst0, dst1, BUF_SIZE))
  81. fail();
  82. bench_new(dst1, src1, stride, stride, offset_val, left_class, block_size, block_size);
  83. }
  84. }
  85. }
  86. static void check_sao_edge(HEVCDSPContext h, int bit_depth)
  87. {
  88. int i;
  89. LOCAL_ALIGNED_32(uint8_t, dst0, [BUF_SIZE]);
  90. LOCAL_ALIGNED_32(uint8_t, dst1, [BUF_SIZE]);
  91. LOCAL_ALIGNED_32(uint8_t, src0, [BUF_SIZE]);
  92. LOCAL_ALIGNED_32(uint8_t, src1, [BUF_SIZE]);
  93. int16_t offset_val[OFFSET_LENGTH];
  94. int eo = rnd()%4;
  95. for (i = 0; i <= 4; i++) {
  96. int block_size = sao_size[i];
  97. ptrdiff_t stride = PIXEL_STRIDE*SIZEOF_PIXEL;
  98. int offset = (AV_INPUT_BUFFER_PADDING_SIZE + PIXEL_STRIDE)*SIZEOF_PIXEL;
  99. declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, uint8_t *src, ptrdiff_t stride_dst,
  100. int16_t *sao_offset_val, int eo, int width, int height);
  101. randomize_buffers(src0, src1, BUF_SIZE);
  102. randomize_buffers2(offset_val, OFFSET_LENGTH);
  103. memset(dst0, 0, BUF_SIZE);
  104. memset(dst1, 0, BUF_SIZE);
  105. if (check_func(h.sao_edge_filter[i], "hevc_sao_edge_%dx%d_%d", block_size, block_size, bit_depth)) {
  106. call_ref(dst0, src0 + offset, stride, offset_val, eo, block_size, block_size);
  107. call_new(dst1, src1 + offset, stride, offset_val, eo, block_size, block_size);
  108. if (memcmp(dst0, dst1, BUF_SIZE))
  109. fail();
  110. bench_new(dst1, src1 + offset, stride, offset_val, eo, block_size, block_size);
  111. }
  112. }
  113. }
  114. void checkasm_check_hevc_sao(void)
  115. {
  116. int bit_depth;
  117. for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
  118. HEVCDSPContext h;
  119. ff_hevc_dsp_init(&h, bit_depth);
  120. check_sao_band(h, bit_depth);
  121. }
  122. report("sao_band");
  123. for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
  124. HEVCDSPContext h;
  125. ff_hevc_dsp_init(&h, bit_depth);
  126. check_sao_edge(h, bit_depth);
  127. }
  128. report("sao_edge");
  129. }