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.

244 lines
14KB

  1. /*
  2. * HEVC video decoder
  3. *
  4. * Copyright (C) 2012 - 2013 Guillaume Martres
  5. * Copyright (C) 2013 - 2014 Pierre-Edouard Lepere
  6. *
  7. *
  8. * This file is part of FFmpeg.
  9. *
  10. * FFmpeg is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * FFmpeg is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with FFmpeg; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #include "hevcdsp.h"
  25. static const int8_t transform[32][32] = {
  26. { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  27. 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 },
  28. { 90, 90, 88, 85, 82, 78, 73, 67, 61, 54, 46, 38, 31, 22, 13, 4,
  29. -4, -13, -22, -31, -38, -46, -54, -61, -67, -73, -78, -82, -85, -88, -90, -90 },
  30. { 90, 87, 80, 70, 57, 43, 25, 9, -9, -25, -43, -57, -70, -80, -87, -90,
  31. -90, -87, -80, -70, -57, -43, -25, -9, 9, 25, 43, 57, 70, 80, 87, 90 },
  32. { 90, 82, 67, 46, 22, -4, -31, -54, -73, -85, -90, -88, -78, -61, -38, -13,
  33. 13, 38, 61, 78, 88, 90, 85, 73, 54, 31, 4, -22, -46, -67, -82, -90 },
  34. { 89, 75, 50, 18, -18, -50, -75, -89, -89, -75, -50, -18, 18, 50, 75, 89,
  35. 89, 75, 50, 18, -18, -50, -75, -89, -89, -75, -50, -18, 18, 50, 75, 89 },
  36. { 88, 67, 31, -13, -54, -82, -90, -78, -46, -4, 38, 73, 90, 85, 61, 22,
  37. -22, -61, -85, -90, -73, -38, 4, 46, 78, 90, 82, 54, 13, -31, -67, -88 },
  38. { 87, 57, 9, -43, -80, -90, -70, -25, 25, 70, 90, 80, 43, -9, -57, -87,
  39. -87, -57, -9, 43, 80, 90, 70, 25, -25, -70, -90, -80, -43, 9, 57, 87 },
  40. { 85, 46, -13, -67, -90, -73, -22, 38, 82, 88, 54, -4, -61, -90, -78, -31,
  41. 31, 78, 90, 61, 4, -54, -88, -82, -38, 22, 73, 90, 67, 13, -46, -85 },
  42. { 83, 36, -36, -83, -83, -36, 36, 83, 83, 36, -36, -83, -83, -36, 36, 83,
  43. 83, 36, -36, -83, -83, -36, 36, 83, 83, 36, -36, -83, -83, -36, 36, 83 },
  44. { 82, 22, -54, -90, -61, 13, 78, 85, 31, -46, -90, -67, 4, 73, 88, 38,
  45. -38, -88, -73, -4, 67, 90, 46, -31, -85, -78, -13, 61, 90, 54, -22, -82 },
  46. { 80, 9, -70, -87, -25, 57, 90, 43, -43, -90, -57, 25, 87, 70, -9, -80,
  47. -80, -9, 70, 87, 25, -57, -90, -43, 43, 90, 57, -25, -87, -70, 9, 80 },
  48. { 78, -4, -82, -73, 13, 85, 67, -22, -88, -61, 31, 90, 54, -38, -90, -46,
  49. 46, 90, 38, -54, -90, -31, 61, 88, 22, -67, -85, -13, 73, 82, 4, -78 },
  50. { 75, -18, -89, -50, 50, 89, 18, -75, -75, 18, 89, 50, -50, -89, -18, 75,
  51. 75, -18, -89, -50, 50, 89, 18, -75, -75, 18, 89, 50, -50, -89, -18, 75 },
  52. { 73, -31, -90, -22, 78, 67, -38, -90, -13, 82, 61, -46, -88, -4, 85, 54,
  53. -54, -85, 4, 88, 46, -61, -82, 13, 90, 38, -67, -78, 22, 90, 31, -73 },
  54. { 70, -43, -87, 9, 90, 25, -80, -57, 57, 80, -25, -90, -9, 87, 43, -70,
  55. -70, 43, 87, -9, -90, -25, 80, 57, -57, -80, 25, 90, 9, -87, -43, 70 },
  56. { 67, -54, -78, 38, 85, -22, -90, 4, 90, 13, -88, -31, 82, 46, -73, -61,
  57. 61, 73, -46, -82, 31, 88, -13, -90, -4, 90, 22, -85, -38, 78, 54, -67 },
  58. { 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64,
  59. 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64, 64, -64, -64, 64 },
  60. { 61, -73, -46, 82, 31, -88, -13, 90, -4, -90, 22, 85, -38, -78, 54, 67,
  61. -67, -54, 78, 38, -85, -22, 90, 4, -90, 13, 88, -31, -82, 46, 73, -61 },
  62. { 57, -80, -25, 90, -9, -87, 43, 70, -70, -43, 87, 9, -90, 25, 80, -57,
  63. -57, 80, 25, -90, 9, 87, -43, -70, 70, 43, -87, -9, 90, -25, -80, 57 },
  64. { 54, -85, -4, 88, -46, -61, 82, 13, -90, 38, 67, -78, -22, 90, -31, -73,
  65. 73, 31, -90, 22, 78, -67, -38, 90, -13, -82, 61, 46, -88, 4, 85, -54 },
  66. { 50, -89, 18, 75, -75, -18, 89, -50, -50, 89, -18, -75, 75, 18, -89, 50,
  67. 50, -89, 18, 75, -75, -18, 89, -50, -50, 89, -18, -75, 75, 18, -89, 50 },
  68. { 46, -90, 38, 54, -90, 31, 61, -88, 22, 67, -85, 13, 73, -82, 4, 78,
  69. -78, -4, 82, -73, -13, 85, -67, -22, 88, -61, -31, 90, -54, -38, 90, -46 },
  70. { 43, -90, 57, 25, -87, 70, 9, -80, 80, -9, -70, 87, -25, -57, 90, -43,
  71. -43, 90, -57, -25, 87, -70, -9, 80, -80, 9, 70, -87, 25, 57, -90, 43 },
  72. { 38, -88, 73, -4, -67, 90, -46, -31, 85, -78, 13, 61, -90, 54, 22, -82,
  73. 82, -22, -54, 90, -61, -13, 78, -85, 31, 46, -90, 67, 4, -73, 88, -38 },
  74. { 36, -83, 83, -36, -36, 83, -83, 36, 36, -83, 83, -36, -36, 83, -83, 36,
  75. 36, -83, 83, -36, -36, 83, -83, 36, 36, -83, 83, -36, -36, 83, -83, 36 },
  76. { 31, -78, 90, -61, 4, 54, -88, 82, -38, -22, 73, -90, 67, -13, -46, 85,
  77. -85, 46, 13, -67, 90, -73, 22, 38, -82, 88, -54, -4, 61, -90, 78, -31 },
  78. { 25, -70, 90, -80, 43, 9, -57, 87, -87, 57, -9, -43, 80, -90, 70, -25,
  79. -25, 70, -90, 80, -43, -9, 57, -87, 87, -57, 9, 43, -80, 90, -70, 25 },
  80. { 22, -61, 85, -90, 73, -38, -4, 46, -78, 90, -82, 54, -13, -31, 67, -88,
  81. 88, -67, 31, 13, -54, 82, -90, 78, -46, 4, 38, -73, 90, -85, 61, -22 },
  82. { 18, -50, 75, -89, 89, -75, 50, -18, -18, 50, -75, 89, -89, 75, -50, 18,
  83. 18, -50, 75, -89, 89, -75, 50, -18, -18, 50, -75, 89, -89, 75, -50, 18 },
  84. { 13, -38, 61, -78, 88, -90, 85, -73, 54, -31, 4, 22, -46, 67, -82, 90,
  85. -90, 82, -67, 46, -22, -4, 31, -54, 73, -85, 90, -88, 78, -61, 38, -13 },
  86. { 9, -25, 43, -57, 70, -80, 87, -90, 90, -87, 80, -70, 57, -43, 25, -9,
  87. -9, 25, -43, 57, -70, 80, -87, 90, -90, 87, -80, 70, -57, 43, -25, 9 },
  88. { 4, -13, 22, -31, 38, -46, 54, -61, 67, -73, 78, -82, 85, -88, 90, -90,
  89. 90, -90, 88, -85, 82, -78, 73, -67, 61, -54, 46, -38, 31, -22, 13, -4 },
  90. };
  91. DECLARE_ALIGNED(16, const int8_t, ff_hevc_epel_filters[7][4]) = {
  92. { -2, 58, 10, -2},
  93. { -4, 54, 16, -2},
  94. { -6, 46, 28, -4},
  95. { -4, 36, 36, -4},
  96. { -4, 28, 46, -6},
  97. { -2, 16, 54, -4},
  98. { -2, 10, 58, -2},
  99. };
  100. DECLARE_ALIGNED(16, const int8_t, ff_hevc_qpel_filters[3][16]) = {
  101. { -1, 4,-10, 58, 17, -5, 1, 0, -1, 4,-10, 58, 17, -5, 1, 0},
  102. { -1, 4,-11, 40, 40,-11, 4, -1, -1, 4,-11, 40, 40,-11, 4, -1},
  103. { 0, 1, -5, 17, 58,-10, 4, -1, 0, 1, -5, 17, 58,-10, 4, -1}
  104. };
  105. #define BIT_DEPTH 8
  106. #include "hevcdsp_template.c"
  107. #undef BIT_DEPTH
  108. #define BIT_DEPTH 9
  109. #include "hevcdsp_template.c"
  110. #undef BIT_DEPTH
  111. #define BIT_DEPTH 10
  112. #include "hevcdsp_template.c"
  113. #undef BIT_DEPTH
  114. void ff_hevc_dsp_init(HEVCDSPContext *hevcdsp, int bit_depth)
  115. {
  116. #undef FUNC
  117. #define FUNC(a, depth) a ## _ ## depth
  118. #undef PEL_FUNC
  119. #define PEL_FUNC(dst1, idx1, idx2, a, depth) \
  120. for(i = 0 ; i < 10 ; i++) \
  121. { \
  122. hevcdsp->dst1[i][idx1][idx2] = a ## _ ## depth; \
  123. }
  124. #undef EPEL_FUNCS
  125. #define EPEL_FUNCS(depth) \
  126. PEL_FUNC(put_hevc_epel, 0, 0, put_hevc_pel_pixels, depth); \
  127. PEL_FUNC(put_hevc_epel, 0, 1, put_hevc_epel_h, depth); \
  128. PEL_FUNC(put_hevc_epel, 1, 0, put_hevc_epel_v, depth); \
  129. PEL_FUNC(put_hevc_epel, 1, 1, put_hevc_epel_hv, depth)
  130. #undef EPEL_UNI_FUNCS
  131. #define EPEL_UNI_FUNCS(depth) \
  132. PEL_FUNC(put_hevc_epel_uni, 0, 0, put_hevc_pel_uni_pixels, depth); \
  133. PEL_FUNC(put_hevc_epel_uni, 0, 1, put_hevc_epel_uni_h, depth); \
  134. PEL_FUNC(put_hevc_epel_uni, 1, 0, put_hevc_epel_uni_v, depth); \
  135. PEL_FUNC(put_hevc_epel_uni, 1, 1, put_hevc_epel_uni_hv, depth); \
  136. PEL_FUNC(put_hevc_epel_uni_w, 0, 0, put_hevc_pel_uni_w_pixels, depth); \
  137. PEL_FUNC(put_hevc_epel_uni_w, 0, 1, put_hevc_epel_uni_w_h, depth); \
  138. PEL_FUNC(put_hevc_epel_uni_w, 1, 0, put_hevc_epel_uni_w_v, depth); \
  139. PEL_FUNC(put_hevc_epel_uni_w, 1, 1, put_hevc_epel_uni_w_hv, depth)
  140. #undef EPEL_BI_FUNCS
  141. #define EPEL_BI_FUNCS(depth) \
  142. PEL_FUNC(put_hevc_epel_bi, 0, 0, put_hevc_pel_bi_pixels, depth); \
  143. PEL_FUNC(put_hevc_epel_bi, 0, 1, put_hevc_epel_bi_h, depth); \
  144. PEL_FUNC(put_hevc_epel_bi, 1, 0, put_hevc_epel_bi_v, depth); \
  145. PEL_FUNC(put_hevc_epel_bi, 1, 1, put_hevc_epel_bi_hv, depth); \
  146. PEL_FUNC(put_hevc_epel_bi_w, 0, 0, put_hevc_pel_bi_w_pixels, depth); \
  147. PEL_FUNC(put_hevc_epel_bi_w, 0, 1, put_hevc_epel_bi_w_h, depth); \
  148. PEL_FUNC(put_hevc_epel_bi_w, 1, 0, put_hevc_epel_bi_w_v, depth); \
  149. PEL_FUNC(put_hevc_epel_bi_w, 1, 1, put_hevc_epel_bi_w_hv, depth)
  150. #undef QPEL_FUNCS
  151. #define QPEL_FUNCS(depth) \
  152. PEL_FUNC(put_hevc_qpel, 0, 0, put_hevc_pel_pixels, depth); \
  153. PEL_FUNC(put_hevc_qpel, 0, 1, put_hevc_qpel_h, depth); \
  154. PEL_FUNC(put_hevc_qpel, 1, 0, put_hevc_qpel_v, depth); \
  155. PEL_FUNC(put_hevc_qpel, 1, 1, put_hevc_qpel_hv, depth)
  156. #undef QPEL_UNI_FUNCS
  157. #define QPEL_UNI_FUNCS(depth) \
  158. PEL_FUNC(put_hevc_qpel_uni, 0, 0, put_hevc_pel_uni_pixels, depth); \
  159. PEL_FUNC(put_hevc_qpel_uni, 0, 1, put_hevc_qpel_uni_h, depth); \
  160. PEL_FUNC(put_hevc_qpel_uni, 1, 0, put_hevc_qpel_uni_v, depth); \
  161. PEL_FUNC(put_hevc_qpel_uni, 1, 1, put_hevc_qpel_uni_hv, depth); \
  162. PEL_FUNC(put_hevc_qpel_uni_w, 0, 0, put_hevc_pel_uni_w_pixels, depth); \
  163. PEL_FUNC(put_hevc_qpel_uni_w, 0, 1, put_hevc_qpel_uni_w_h, depth); \
  164. PEL_FUNC(put_hevc_qpel_uni_w, 1, 0, put_hevc_qpel_uni_w_v, depth); \
  165. PEL_FUNC(put_hevc_qpel_uni_w, 1, 1, put_hevc_qpel_uni_w_hv, depth)
  166. #undef QPEL_BI_FUNCS
  167. #define QPEL_BI_FUNCS(depth) \
  168. PEL_FUNC(put_hevc_qpel_bi, 0, 0, put_hevc_pel_bi_pixels, depth); \
  169. PEL_FUNC(put_hevc_qpel_bi, 0, 1, put_hevc_qpel_bi_h, depth); \
  170. PEL_FUNC(put_hevc_qpel_bi, 1, 0, put_hevc_qpel_bi_v, depth); \
  171. PEL_FUNC(put_hevc_qpel_bi, 1, 1, put_hevc_qpel_bi_hv, depth); \
  172. PEL_FUNC(put_hevc_qpel_bi_w, 0, 0, put_hevc_pel_bi_w_pixels, depth); \
  173. PEL_FUNC(put_hevc_qpel_bi_w, 0, 1, put_hevc_qpel_bi_w_h, depth); \
  174. PEL_FUNC(put_hevc_qpel_bi_w, 1, 0, put_hevc_qpel_bi_w_v, depth); \
  175. PEL_FUNC(put_hevc_qpel_bi_w, 1, 1, put_hevc_qpel_bi_w_hv, depth)
  176. #define HEVC_DSP(depth) \
  177. hevcdsp->put_pcm = FUNC(put_pcm, depth); \
  178. hevcdsp->transquant_bypass[0] = FUNC(transquant_bypass4x4, depth); \
  179. hevcdsp->transquant_bypass[1] = FUNC(transquant_bypass8x8, depth); \
  180. hevcdsp->transquant_bypass[2] = FUNC(transquant_bypass16x16, depth); \
  181. hevcdsp->transquant_bypass[3] = FUNC(transquant_bypass32x32, depth); \
  182. hevcdsp->transform_skip = FUNC(transform_skip, depth); \
  183. hevcdsp->transform_4x4_luma_add = FUNC(transform_4x4_luma_add, depth); \
  184. hevcdsp->transform_add[0] = FUNC(transform_4x4_add, depth); \
  185. hevcdsp->transform_add[1] = FUNC(transform_8x8_add, depth); \
  186. hevcdsp->transform_add[2] = FUNC(transform_16x16_add, depth); \
  187. hevcdsp->transform_add[3] = FUNC(transform_32x32_add, depth); \
  188. \
  189. hevcdsp->transform_dc_add[0] = FUNC(transform_4x4_dc_add, depth); \
  190. hevcdsp->transform_dc_add[1] = FUNC(transform_8x8_dc_add, depth); \
  191. hevcdsp->transform_dc_add[2] = FUNC(transform_16x16_dc_add, depth); \
  192. hevcdsp->transform_dc_add[3] = FUNC(transform_32x32_dc_add, depth); \
  193. \
  194. hevcdsp->sao_band_filter = FUNC(sao_band_filter_0, depth); \
  195. hevcdsp->sao_edge_filter[0] = FUNC(sao_edge_filter_0, depth); \
  196. hevcdsp->sao_edge_filter[1] = FUNC(sao_edge_filter_1, depth); \
  197. \
  198. QPEL_FUNCS(depth); \
  199. QPEL_UNI_FUNCS(depth); \
  200. QPEL_BI_FUNCS(depth); \
  201. EPEL_FUNCS(depth); \
  202. EPEL_UNI_FUNCS(depth); \
  203. EPEL_BI_FUNCS(depth); \
  204. \
  205. hevcdsp->hevc_h_loop_filter_luma = FUNC(hevc_h_loop_filter_luma, depth); \
  206. hevcdsp->hevc_v_loop_filter_luma = FUNC(hevc_v_loop_filter_luma, depth); \
  207. hevcdsp->hevc_h_loop_filter_chroma = FUNC(hevc_h_loop_filter_chroma, depth); \
  208. hevcdsp->hevc_v_loop_filter_chroma = FUNC(hevc_v_loop_filter_chroma, depth); \
  209. hevcdsp->hevc_h_loop_filter_luma_c = FUNC(hevc_h_loop_filter_luma, depth); \
  210. hevcdsp->hevc_v_loop_filter_luma_c = FUNC(hevc_v_loop_filter_luma, depth); \
  211. hevcdsp->hevc_h_loop_filter_chroma_c = FUNC(hevc_h_loop_filter_chroma, depth); \
  212. hevcdsp->hevc_v_loop_filter_chroma_c = FUNC(hevc_v_loop_filter_chroma, depth)
  213. int i = 0;
  214. switch (bit_depth) {
  215. case 9:
  216. HEVC_DSP(9);
  217. break;
  218. case 10:
  219. HEVC_DSP(10);
  220. break;
  221. default:
  222. HEVC_DSP(8);
  223. break;
  224. }
  225. if (ARCH_X86) ff_hevcdsp_init_x86(hevcdsp, bit_depth);
  226. }