msm_vidc_buffer.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <media/msm_media_info.h>
  6. #include "msm_vidc_buffer.h"
  7. #include "msm_vidc_inst.h"
  8. #include "msm_vidc_core.h"
  9. #include "msm_vidc_driver.h"
  10. #include "msm_vidc_debug.h"
  11. #include "msm_vidc_internal.h"
  12. #define MIN_INPUT_BUFFERS 4
  13. #define MIN_ENC_OUTPUT_BUFFERS 4
  14. u32 msm_vidc_input_min_count(struct msm_vidc_inst *inst)
  15. {
  16. u32 input_min_count = 0;
  17. //struct v4l2_ctrl *max_layer = NULL;
  18. if (!inst) {
  19. d_vpr_e("%s: invalid params\n", __func__);
  20. return 0;
  21. }
  22. if (!is_decode_session(inst) && !is_encode_session(inst))
  23. return 0;
  24. input_min_count = MIN_INPUT_BUFFERS;
  25. if (is_thumbnail_session(inst))
  26. input_min_count = 1;
  27. //if (is_grid_session(inst))
  28. // input_min_count = 2;
  29. //if (is_hier_b_session(inst)) {
  30. //max_layer = get_ctrl(inst,
  31. // V4L2_CID_MPEG_VIDC_VIDEO_HEVC_MAX_HIER_CODING_LAYER);
  32. //input_min_count = (1 << (max_layer->val - 1)) + 2;
  33. //}
  34. return input_min_count;
  35. }
  36. u32 msm_vidc_output_min_count(struct msm_vidc_inst *inst)
  37. {
  38. u32 output_min_count;
  39. if (!inst) {
  40. d_vpr_e("%s: invalid params\n", __func__);
  41. return 0;
  42. }
  43. if (!is_decode_session(inst) && !is_encode_session(inst))
  44. return 0;
  45. if (is_thumbnail_session(inst))
  46. return inst->codec == MSM_VIDC_VP9 ? 8 : 1;
  47. if (is_decode_session(inst)) {
  48. switch (inst->codec) {
  49. case MSM_VIDC_H264:
  50. case MSM_VIDC_HEVC:
  51. output_min_count = 4;
  52. break;
  53. case MSM_VIDC_VP9:
  54. output_min_count = 9;
  55. break;
  56. case MSM_VIDC_MPEG2:
  57. output_min_count = 6;
  58. break;
  59. default:
  60. output_min_count = 4;
  61. }
  62. } else {
  63. output_min_count = MIN_ENC_OUTPUT_BUFFERS;
  64. }
  65. //if (is_vpp_delay_allowed(inst)) {
  66. // output_min_count =
  67. // max(output_min_count, (u32)MAX_BSE_VPP_DELAY);
  68. // output_min_count =
  69. // max(output_min_count, (u32)(msm_vidc_vpp_delay & 0x1F));
  70. //}
  71. return output_min_count;
  72. }
  73. u32 msm_vidc_input_extra_count(struct msm_vidc_inst *inst)
  74. {
  75. u32 extra_input_count = 0;
  76. struct msm_vidc_core *core;
  77. if (!inst || !inst->core) {
  78. d_vpr_e("%s: invalid params %pK\n", __func__, inst);
  79. return 0;
  80. }
  81. core = inst->core;
  82. if (is_thumbnail_session(inst))
  83. return extra_input_count;
  84. if (is_decode_session(inst)) {
  85. /* add dcvs buffers */
  86. /* add batching buffers */
  87. extra_input_count = 6;
  88. } else if (is_encode_session(inst)) {
  89. /* add dcvs buffers */
  90. extra_input_count = 4;
  91. }
  92. return extra_input_count;
  93. }
  94. u32 msm_vidc_output_extra_count(struct msm_vidc_inst *inst)
  95. {
  96. u32 extra_output_count = 0;
  97. struct msm_vidc_core *core;
  98. if (!inst || !inst->core) {
  99. d_vpr_e("%s: invalid params %pK\n", __func__, inst);
  100. return 0;
  101. }
  102. core = inst->core;
  103. if (is_thumbnail_session(inst))
  104. return 0;
  105. if (is_decode_session(inst)) {
  106. /* add dcvs buffers */
  107. /* add batching buffers */
  108. extra_output_count = 6;
  109. } else if (is_encode_session(inst)) {
  110. /* add heif buffers */
  111. //extra_output_count = 8
  112. }
  113. return extra_output_count;
  114. }
  115. u32 msm_vidc_decoder_input_size(struct msm_vidc_inst *inst)
  116. {
  117. u32 size = ALIGN(15 * 1024 * 1024, SZ_4K);
  118. size = 4; // TODO
  119. return size;
  120. }
  121. u32 msm_vidc_decoder_output_size(struct msm_vidc_inst *inst)
  122. {
  123. u32 size;
  124. u32 format;
  125. struct v4l2_format *f;
  126. f = &inst->fmts[OUTPUT_PORT];
  127. format = v4l2_colorformat_to_media(f->fmt.pix_mp.pixelformat, __func__);
  128. size = VENUS_BUFFER_SIZE(format, f->fmt.pix_mp.width,
  129. f->fmt.pix_mp.height);
  130. return size;
  131. }
  132. u32 msm_vidc_decoder_input_meta_size(struct msm_vidc_inst *inst)
  133. {
  134. return ALIGN(16 * 1024, SZ_4K);
  135. }
  136. u32 msm_vidc_decoder_output_meta_size(struct msm_vidc_inst *inst)
  137. {
  138. return ALIGN(16 * 1024, SZ_4K);
  139. }
  140. u32 msm_vidc_encoder_input_size(struct msm_vidc_inst *inst)
  141. {
  142. u32 size;
  143. u32 format;
  144. struct v4l2_format *f;
  145. f = &inst->fmts[INPUT_PORT];
  146. format = v4l2_colorformat_to_media(f->fmt.pix_mp.pixelformat, __func__);
  147. size = VENUS_BUFFER_SIZE(format, f->fmt.pix_mp.width,
  148. f->fmt.pix_mp.height);
  149. return size;
  150. }
  151. u32 msm_vidc_encoder_output_size(struct msm_vidc_inst *inst)
  152. {
  153. u32 frame_size;
  154. u32 mbs_per_frame;
  155. u32 width, height;
  156. struct v4l2_format *f;
  157. f = &inst->fmts[OUTPUT_PORT];
  158. /*
  159. * Encoder output size calculation: 32 Align width/height
  160. * For resolution < 720p : YUVsize * 4
  161. * For resolution > 720p & <= 4K : YUVsize / 2
  162. * For resolution > 4k : YUVsize / 4
  163. * Initially frame_size = YUVsize * 2;
  164. */
  165. /* if (is_grid_session(inst)) {
  166. f->fmt.pix_mp.width = f->fmt.pix_mp.height = HEIC_GRID_DIMENSION;
  167. } */
  168. width = ALIGN(f->fmt.pix_mp.width, BUFFER_ALIGNMENT_SIZE(32));
  169. height = ALIGN(f->fmt.pix_mp.height, BUFFER_ALIGNMENT_SIZE(32));
  170. mbs_per_frame = NUM_MBS_PER_FRAME(width, height);
  171. frame_size = (width * height * 3);
  172. if (mbs_per_frame < NUM_MBS_720P)
  173. frame_size = frame_size << 1;
  174. else if (mbs_per_frame <= NUM_MBS_4k)
  175. frame_size = frame_size >> 2;
  176. else
  177. frame_size = frame_size >> 3;
  178. /*if ((inst->rc_type == RATE_CONTROL_OFF) ||
  179. (inst->rc_type == V4L2_MPEG_VIDEO_BITRATE_MODE_CQ))
  180. frame_size = frame_size << 1;
  181. if (inst->rc_type == RATE_CONTROL_LOSSLESS)
  182. frame_size = (width * height * 9) >> 2; */
  183. /* multiply by 10/8 (1.25) to get size for 10 bit case */
  184. if (f->fmt.pix_mp.pixelformat == V4L2_PIX_FMT_HEVC)
  185. frame_size = frame_size + (frame_size >> 2);
  186. return ALIGN(frame_size, SZ_4K);
  187. }
  188. u32 msm_vidc_encoder_input_meta_size(struct msm_vidc_inst *inst)
  189. {
  190. return ALIGN(1 * 1024 * 1024, SZ_4K);
  191. }
  192. u32 msm_vidc_encoder_output_meta_size(struct msm_vidc_inst *inst)
  193. {
  194. return ALIGN(16 * 1024, SZ_4K);
  195. }