msm_venc.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <media/v4l2_vidc_extensions.h>
  6. #include <media/msm_media_info.h>
  7. #include "msm_venc.h"
  8. #include "msm_vidc_core.h"
  9. #include "msm_vidc_inst.h"
  10. #include "msm_vidc_driver.h"
  11. #include "msm_vidc_internal.h"
  12. #include "msm_vidc_platform.h"
  13. #include "msm_vidc_control.h"
  14. #include "msm_vidc_debug.h"
  15. #include "venus_hfi.h"
  16. #include "hfi_packet.h"
  17. u32 msm_venc_input_set_prop[] = {
  18. HFI_PROP_COLOR_FORMAT,
  19. HFI_PROP_RAW_RESOLUTION,
  20. HFI_PROP_LINEAR_ALIGNMENT_FACTOR,
  21. HFI_PROP_BUFFER_HOST_MAX_COUNT,
  22. };
  23. u32 msm_venc_output_set_prop[] = {
  24. HFI_PROP_BITSTREAM_RESOLUTION,
  25. HFI_PROP_CROP_OFFSETS,
  26. HFI_PROP_BUFFER_HOST_MAX_COUNT,
  27. };
  28. u32 msm_venc_input_subscribe_for_properties[] = {
  29. HFI_PROP_NO_OUTPUT,
  30. };
  31. u32 msm_venc_deliver_as_metadata[] = {
  32. HFI_PROP_BUFFER_TAG,
  33. HFI_PROP_SEI_MASTERING_DISPLAY_COLOUR,
  34. HFI_PROP_SEI_CONTENT_LIGHT_LEVEL,
  35. HFI_PROP_SEI_HDR10PLUS_USERDATA,
  36. HFI_PROP_EVA_STAT_INFO,
  37. };
  38. u32 msm_venc_subscribe_for_metadata[] = {
  39. HFI_PROP_BUFFER_TAG,
  40. HFI_PROP_METADATA_SEQ_HEADER_NAL,
  41. HFI_PROP_TIMESTAMP,
  42. HFI_PROP_LTR_MARK_USE_DETAILS,
  43. HFI_PROP_SUBFRAME_OUTPUT,
  44. HFI_PROP_ENC_QP_METADATA,
  45. };
  46. u32 msm_venc_output_subscribe_for_properties[] = {
  47. HFI_PROP_PICTURE_TYPE,
  48. HFI_PROP_BUFFER_MARK,
  49. };
  50. static int msm_venc_codec_change(struct msm_vidc_inst *inst, u32 v4l2_codec)
  51. {
  52. int rc = 0;
  53. if (inst->codec && inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat == v4l2_codec)
  54. return 0;
  55. s_vpr_h(inst->sid, "%s: codec changed from %#x to %#x\n",
  56. __func__, inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat, v4l2_codec);
  57. inst->codec = v4l2_codec_to_driver(v4l2_codec, __func__);
  58. rc = msm_vidc_get_inst_capability(inst);
  59. if (rc)
  60. goto exit;
  61. rc = msm_vidc_ctrl_deinit(inst);
  62. if (rc)
  63. goto exit;
  64. rc = msm_vidc_ctrl_init(inst);
  65. if (rc)
  66. goto exit;
  67. exit:
  68. return rc;
  69. }
  70. /* todo: add logs for each property once finalised */
  71. static int msm_venc_set_colorformat(struct msm_vidc_inst *inst,
  72. enum msm_vidc_port_type port)
  73. {
  74. int rc = 0;
  75. u32 pixelformat;
  76. enum msm_vidc_colorformat_type colorformat;
  77. u32 hfi_colorformat;
  78. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  79. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  80. return -EINVAL;
  81. }
  82. pixelformat = inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat;
  83. if (pixelformat != V4L2_PIX_FMT_VIDC_NV12C &&
  84. pixelformat != V4L2_PIX_FMT_VIDC_TP10C) {
  85. s_vpr_e(inst->sid, "%s: invalid pixelformat %#x\n",
  86. __func__, pixelformat);
  87. return -EINVAL;
  88. }
  89. colorformat = v4l2_colorformat_to_driver(pixelformat, __func__);
  90. hfi_colorformat = get_hfi_colorformat(inst, colorformat);
  91. rc = venus_hfi_session_property(inst,
  92. HFI_PROP_COLOR_FORMAT,
  93. HFI_HOST_FLAGS_NONE,
  94. get_hfi_port(inst, port),
  95. HFI_PAYLOAD_U32_ENUM,
  96. &hfi_colorformat,
  97. sizeof(u32));
  98. if (rc)
  99. return rc;
  100. return 0;
  101. }
  102. /* TODO: Enable when NV12 support is required */
  103. static int msm_venc_set_linear_alignment_factor(struct msm_vidc_inst *inst,
  104. enum msm_vidc_port_type port)
  105. {
  106. /* int rc = 0;
  107. u32 pixelformat;
  108. u32 alignment_factor[2];
  109. if (port != INPUT_PORT) {
  110. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  111. return -EINVAL;
  112. }
  113. pixelformat = inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat;
  114. if (pixelformat == V4L2_PIX_FMT_VIDC_NV12C ||
  115. pixelformat == V4L2_PIX_FMT_VIDC_TP10C ||
  116. pixelformat == V4L2_PIX_FMT_VIDC_ARGB32C) {
  117. s_vpr_e(inst->sid,
  118. "%s: not a linear color fmt, property is not set\n",
  119. __func__);
  120. return 0;
  121. }
  122. if (pixelformat == V4L2_PIX_FMT_ARGB32) {
  123. alignment_factor[0] =
  124. (rgb_stride_alignment(pixelformat, __func__) << 16) |
  125. rgb_scanline_alignment(pixelformat, __func__);
  126. alignment_factor[1] = 0;
  127. } else {
  128. alignment_factor[0] =
  129. (y_stride_alignment(pixelformat, __func__) << 16) |
  130. y_scanline_alignment(pixelformat, __func__);
  131. alignment_factor[1] =
  132. (uv_stride_alignment(pixelformat, __func__) << 16) |
  133. uv_scanline_alignment(pixelformat, __func__);
  134. }
  135. s_vpr_h(inst->sid, "%s: payload[0]: %u payload[1]: %u\n", __func__,
  136. alignment_factor[0], alignment_factor[1]);
  137. rc = venus_hfi_session_property(inst,
  138. HFI_PROP_LINEAR_ALIGNMENT_FACTOR,
  139. HFI_HOST_FLAGS_NONE,
  140. get_hfi_port(inst, port),
  141. HFI_PAYLOAD_64_PACKED,
  142. &alignment_factor,
  143. sizeof(u64));
  144. if (rc)
  145. return rc;
  146. */
  147. return 0;
  148. }
  149. static int msm_venc_set_raw_resolution(struct msm_vidc_inst *inst,
  150. enum msm_vidc_port_type port)
  151. {
  152. int rc = 0;
  153. u32 resolution;
  154. if (port != INPUT_PORT) {
  155. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  156. return -EINVAL;
  157. }
  158. resolution = inst->fmts[port].fmt.pix_mp.width << 16 |
  159. inst->fmts[port].fmt.pix_mp.height;
  160. s_vpr_h(inst->sid, "%s: width: %d height: %d\n", __func__,
  161. inst->fmts[port].fmt.pix_mp.width,
  162. inst->fmts[port].fmt.pix_mp.height);
  163. rc = venus_hfi_session_property(inst,
  164. HFI_PROP_RAW_RESOLUTION,
  165. HFI_HOST_FLAGS_NONE,
  166. get_hfi_port(inst, port),
  167. HFI_PAYLOAD_32_PACKED,
  168. &resolution,
  169. sizeof(u32));
  170. if (rc)
  171. return rc;
  172. return 0;
  173. }
  174. static int msm_venc_set_bitstream_resolution(struct msm_vidc_inst *inst,
  175. enum msm_vidc_port_type port)
  176. {
  177. int rc = 0;
  178. u32 resolution;
  179. if (port != OUTPUT_PORT) {
  180. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  181. return -EINVAL;
  182. }
  183. resolution = (inst->fmts[port].fmt.pix_mp.width << 16) |
  184. inst->fmts[port].fmt.pix_mp.height;
  185. s_vpr_h(inst->sid, "%s: width: %d height: %d\n", __func__,
  186. inst->fmts[port].fmt.pix_mp.width,
  187. inst->fmts[port].fmt.pix_mp.height);
  188. rc = venus_hfi_session_property(inst,
  189. HFI_PROP_BITSTREAM_RESOLUTION,
  190. HFI_HOST_FLAGS_NONE,
  191. get_hfi_port(inst, port),
  192. HFI_PAYLOAD_32_PACKED,
  193. &resolution,
  194. sizeof(u32));
  195. if (rc)
  196. return rc;
  197. return 0;
  198. }
  199. static int msm_venc_set_crop_offsets(struct msm_vidc_inst *inst,
  200. enum msm_vidc_port_type port)
  201. {
  202. int rc = 0;
  203. u32 left_offset, top_offset, right_offset, bottom_offset;
  204. u64 crop;
  205. if (port != OUTPUT_PORT) {
  206. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  207. return -EINVAL;
  208. }
  209. left_offset = inst->crop.left;
  210. top_offset = inst->crop.top;
  211. right_offset = (inst->fmts[port].fmt.pix_mp.width -
  212. inst->crop.width);
  213. bottom_offset = (inst->fmts[port].fmt.pix_mp.height -
  214. inst->crop.height);
  215. crop = (u64)right_offset << 48 | (u64)bottom_offset << 32 |
  216. (u64)left_offset << 16 | top_offset;
  217. s_vpr_h(inst->sid, "%s: left_offset: %d top_offset: %d "
  218. "right_offset: %d bottom_offset: %d", __func__,
  219. left_offset, top_offset, right_offset, bottom_offset);
  220. rc = venus_hfi_session_property(inst,
  221. HFI_PROP_CROP_OFFSETS,
  222. HFI_HOST_FLAGS_NONE,
  223. get_hfi_port(inst, port),
  224. HFI_PAYLOAD_64_PACKED,
  225. &crop,
  226. sizeof(u64));
  227. if (rc)
  228. return rc;
  229. return 0;
  230. }
  231. static int msm_venc_set_host_max_buf_count(struct msm_vidc_inst *inst,
  232. enum msm_vidc_port_type port)
  233. {
  234. int rc = 0;
  235. u32 count = DEFAULT_MAX_HOST_BUF_COUNT;
  236. if (port != INPUT_PORT && port != OUTPUT_PORT) {
  237. s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
  238. return -EINVAL;
  239. }
  240. s_vpr_h(inst->sid, "%s: count: %u port: %u\n", __func__, count, port);
  241. rc = venus_hfi_session_property(inst,
  242. HFI_PROP_BUFFER_HOST_MAX_COUNT,
  243. HFI_HOST_FLAGS_NONE,
  244. get_hfi_port(inst, port),
  245. HFI_PAYLOAD_U32,
  246. &count,
  247. sizeof(u32));
  248. if (rc)
  249. return rc;
  250. return 0;
  251. }
  252. static int msm_venc_set_stage(struct msm_vidc_inst *inst)
  253. {
  254. int rc = 0;
  255. struct msm_vidc_core *core = inst->core;
  256. rc = call_session_op(core, decide_work_mode, inst);
  257. if (rc) {
  258. s_vpr_e(inst->sid, "%s: decide_work_mode failed\n",
  259. __func__);
  260. return -EINVAL;
  261. }
  262. s_vpr_h(inst->sid, "%s: stage: %u\n", __func__, inst->stage);
  263. rc = venus_hfi_session_property(inst,
  264. HFI_PROP_STAGE,
  265. HFI_HOST_FLAGS_NONE,
  266. HFI_PORT_NONE,
  267. HFI_PAYLOAD_U32,
  268. &inst->stage,
  269. sizeof(u32));
  270. if (rc)
  271. return rc;
  272. return 0;
  273. }
  274. static int msm_venc_set_pipe(struct msm_vidc_inst *inst)
  275. {
  276. int rc = 0;
  277. struct msm_vidc_core *core = inst->core;
  278. rc = call_session_op(core, decide_work_route, inst);
  279. if (rc) {
  280. s_vpr_e(inst->sid, "%s: decide_work_route failed\n",
  281. __func__);
  282. return -EINVAL;
  283. }
  284. s_vpr_h(inst->sid, "%s: pipe: %u\n", __func__, inst->pipe);
  285. rc = venus_hfi_session_property(inst,
  286. HFI_PROP_PIPE,
  287. HFI_HOST_FLAGS_NONE,
  288. HFI_PORT_NONE,
  289. HFI_PAYLOAD_U32,
  290. &inst->pipe,
  291. sizeof(u32));
  292. if (rc)
  293. return rc;
  294. return 0;
  295. }
  296. static int msm_venc_set_quality_mode(struct msm_vidc_inst *inst)
  297. {
  298. int rc = 0;
  299. if (!inst->quality_mode) {
  300. s_vpr_e(inst->sid, "%s: invalid mode: %u\n",
  301. __func__, inst->quality_mode);
  302. return -EINVAL;
  303. }
  304. s_vpr_h(inst->sid, "%s: quality_mode: %u\n", __func__, inst->quality_mode);
  305. rc = venus_hfi_session_property(inst,
  306. HFI_PROP_QUALITY_MODE,
  307. HFI_HOST_FLAGS_NONE,
  308. HFI_PORT_BITSTREAM,
  309. HFI_PAYLOAD_U32_ENUM,
  310. &inst->quality_mode,
  311. sizeof(u32));
  312. if (rc)
  313. return rc;
  314. return 0;
  315. }
  316. static int msm_venc_set_input_properties(struct msm_vidc_inst *inst)
  317. {
  318. int rc = 0;
  319. int i = 0;
  320. d_vpr_h("%s()\n", __func__);
  321. if (!inst) {
  322. d_vpr_e("%s: invalid params\n", __func__);
  323. return -EINVAL;
  324. }
  325. for (i = 0; i < ARRAY_SIZE(msm_venc_input_set_prop);
  326. i++) {
  327. switch (msm_venc_input_set_prop[i]) {
  328. case HFI_PROP_COLOR_FORMAT:
  329. rc = msm_venc_set_colorformat(inst, INPUT_PORT);
  330. break;
  331. case HFI_PROP_RAW_RESOLUTION:
  332. rc = msm_venc_set_raw_resolution(inst, INPUT_PORT);
  333. break;
  334. case HFI_PROP_LINEAR_ALIGNMENT_FACTOR:
  335. rc = msm_venc_set_linear_alignment_factor(inst, INPUT_PORT);
  336. break;
  337. case HFI_PROP_BUFFER_HOST_MAX_COUNT:
  338. rc = msm_venc_set_host_max_buf_count(inst, INPUT_PORT);
  339. break;
  340. default:
  341. d_vpr_e("%s: unknown property %#x\n", __func__,
  342. msm_venc_input_set_prop[i]);
  343. rc = -EINVAL;
  344. break;
  345. }
  346. }
  347. return rc;
  348. }
  349. static int msm_venc_set_output_properties(struct msm_vidc_inst *inst)
  350. {
  351. int rc = 0;
  352. int i = 0;
  353. d_vpr_h("%s()\n", __func__);
  354. if (!inst) {
  355. d_vpr_e("%s: invalid params\n", __func__);
  356. return -EINVAL;
  357. }
  358. for (i = 0; i < ARRAY_SIZE(msm_venc_output_set_prop);
  359. i++) {
  360. switch (msm_venc_output_set_prop[i]) {
  361. case HFI_PROP_BITSTREAM_RESOLUTION:
  362. rc = msm_venc_set_bitstream_resolution(inst, OUTPUT_PORT);
  363. break;
  364. case HFI_PROP_CROP_OFFSETS:
  365. rc = msm_venc_set_crop_offsets(inst, OUTPUT_PORT);
  366. break;
  367. case HFI_PROP_BUFFER_HOST_MAX_COUNT:
  368. rc = msm_venc_set_host_max_buf_count(inst, OUTPUT_PORT);
  369. break;
  370. default:
  371. d_vpr_e("%s: unknown property %#x\n", __func__,
  372. msm_venc_output_set_prop[i]);
  373. rc = -EINVAL;
  374. break;
  375. }
  376. }
  377. return rc;
  378. }
  379. static int msm_venc_set_internal_properties(struct msm_vidc_inst *inst)
  380. {
  381. int rc = 0;
  382. d_vpr_h("%s()\n", __func__);
  383. if (!inst) {
  384. d_vpr_e("%s: invalid params\n", __func__);
  385. return -EINVAL;
  386. }
  387. //TODO: set HFI_PORT_NONE properties at master port streamon.
  388. rc = msm_venc_set_stage(inst);
  389. if (rc)
  390. return rc;
  391. rc = msm_venc_set_pipe(inst);
  392. if (rc)
  393. return rc;
  394. rc = msm_venc_set_quality_mode(inst);
  395. if (rc)
  396. return rc;
  397. return rc;
  398. }
  399. static int msm_venc_get_input_internal_buffers(struct msm_vidc_inst *inst)
  400. {
  401. int rc = 0;
  402. struct msm_vidc_core *core;
  403. if (!inst || !inst->core) {
  404. d_vpr_e("%s: invalid params\n", __func__);
  405. return -EINVAL;
  406. }
  407. core = inst->core;
  408. inst->buffers.arp.size = call_session_op(core, buffer_size,
  409. inst, MSM_VIDC_BUF_ARP) + 100000000;
  410. inst->buffers.bin.size = call_session_op(core, buffer_size,
  411. inst, MSM_VIDC_BUF_BIN) + 100000000;
  412. inst->buffers.comv.size = call_session_op(core, buffer_size,
  413. inst, MSM_VIDC_BUF_COMV) + 100000000;
  414. inst->buffers.non_comv.size = call_session_op(core, buffer_size,
  415. inst, MSM_VIDC_BUF_NON_COMV) + 100000000;
  416. inst->buffers.line.size = call_session_op(core, buffer_size,
  417. inst, MSM_VIDC_BUF_LINE) + 100000000;
  418. inst->buffers.dpb.size = call_session_op(core, buffer_size,
  419. inst, MSM_VIDC_BUF_DPB) + 100000000;
  420. //inst->buffers.vpss.size = call_session_op(core, buffer_size,
  421. //inst, MSM_VIDC_BUF_VPSS) + 100000000;
  422. //vpss is req - 100 mb
  423. /* inst->buffers.persist.size = call_session_op(core, buffer_size,
  424. inst, MSM_VIDC_BUF_PERSIST); */
  425. inst->buffers.arp.min_count = call_session_op(core, min_count,
  426. inst, MSM_VIDC_BUF_ARP);
  427. inst->buffers.bin.min_count = call_session_op(core, min_count,
  428. inst, MSM_VIDC_BUF_BIN);
  429. inst->buffers.comv.min_count = call_session_op(core, min_count,
  430. inst, MSM_VIDC_BUF_COMV);
  431. inst->buffers.non_comv.min_count = call_session_op(core, min_count,
  432. inst, MSM_VIDC_BUF_NON_COMV);
  433. inst->buffers.line.min_count = call_session_op(core, min_count,
  434. inst, MSM_VIDC_BUF_LINE);
  435. inst->buffers.dpb.min_count = call_session_op(core, min_count,
  436. inst, MSM_VIDC_BUF_DPB);
  437. /* inst->buffers.persist.min_count = call_session_op(core, min_count,
  438. inst, MSM_VIDC_BUF_PERSIST); */
  439. s_vpr_h(inst->sid, "internal buffer: min size\n");
  440. s_vpr_h(inst->sid, "arp buffer: %d %d\n",
  441. inst->buffers.arp.min_count,
  442. inst->buffers.arp.size);
  443. s_vpr_h(inst->sid, "bin buffer: %d %d\n",
  444. inst->buffers.bin.min_count,
  445. inst->buffers.bin.size);
  446. s_vpr_h(inst->sid, "comv buffer: %d %d\n",
  447. inst->buffers.comv.min_count,
  448. inst->buffers.comv.size);
  449. s_vpr_h(inst->sid, "non_comv buffer: %d %d\n",
  450. inst->buffers.non_comv.min_count,
  451. inst->buffers.non_comv.size);
  452. s_vpr_h(inst->sid, "line buffer: %d %d\n",
  453. inst->buffers.line.min_count,
  454. inst->buffers.line.size);
  455. s_vpr_h(inst->sid, "dpb buffer: %d %d\n",
  456. inst->buffers.dpb.min_count,
  457. inst->buffers.dpb.size);
  458. /* s_vpr_h(inst->sid, "persist buffer: %d %d\n",
  459. inst->buffers.persist.min_count,
  460. inst->buffers.persist.size); */
  461. return rc;
  462. }
  463. static int msm_venc_create_input_internal_buffers(struct msm_vidc_inst *inst)
  464. {
  465. int rc = 0;
  466. d_vpr_h("%s()\n", __func__);
  467. if (!inst || !inst->core) {
  468. d_vpr_e("%s: invalid params\n", __func__);
  469. return -EINVAL;
  470. }
  471. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_ARP);
  472. if (rc)
  473. return rc;
  474. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_BIN);
  475. if (rc)
  476. return rc;
  477. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_COMV);
  478. if (rc)
  479. return rc;
  480. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_NON_COMV);
  481. if (rc)
  482. return rc;
  483. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_LINE);
  484. if (rc)
  485. return rc;
  486. rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_DPB);
  487. if (rc)
  488. return rc;
  489. /* rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_PERSIST);
  490. if (rc)
  491. return rc; */
  492. return 0;
  493. }
  494. static int msm_venc_queue_input_internal_buffers(struct msm_vidc_inst *inst)
  495. {
  496. int rc = 0;
  497. d_vpr_h("%s()\n", __func__);
  498. if (!inst || !inst->core) {
  499. d_vpr_e("%s: invalid params\n", __func__);
  500. return -EINVAL;
  501. }
  502. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_ARP);
  503. if (rc)
  504. return rc;
  505. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_BIN);
  506. if (rc)
  507. return rc;
  508. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_COMV);
  509. if (rc)
  510. return rc;
  511. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_NON_COMV);
  512. if (rc)
  513. return rc;
  514. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_LINE);
  515. if (rc)
  516. return rc;
  517. rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_DPB);
  518. if (rc)
  519. return rc;
  520. // TODO: fw is not accepting persist buffer and returning session error.
  521. //rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_PERSIST);
  522. if (rc)
  523. return rc;
  524. return 0;
  525. }
  526. static int msm_venc_property_subscription(struct msm_vidc_inst *inst,
  527. enum msm_vidc_port_type port)
  528. {
  529. int rc = 0;
  530. struct msm_vidc_core *core;
  531. u32 payload[32] = {0};
  532. u32 i;
  533. u32 payload_size = 0;
  534. if (!inst || !inst->core) {
  535. d_vpr_e("%s: invalid params\n", __func__);
  536. return -EINVAL;
  537. }
  538. core = inst->core;
  539. d_vpr_h("%s()\n", __func__);
  540. payload[0] = HFI_MODE_PROPERTY;
  541. if (port == INPUT_PORT) {
  542. for (i = 0; i < ARRAY_SIZE(msm_venc_input_subscribe_for_properties); i++)
  543. payload[i + 1] = msm_venc_input_subscribe_for_properties[i];
  544. payload_size = (ARRAY_SIZE(msm_venc_input_subscribe_for_properties) + 1) *
  545. sizeof(u32);
  546. } else if (port == OUTPUT_PORT) {
  547. for (i = 0; i < ARRAY_SIZE(msm_venc_output_subscribe_for_properties); i++)
  548. payload[i + 1] = msm_venc_output_subscribe_for_properties[i];
  549. payload_size = (ARRAY_SIZE(msm_venc_output_subscribe_for_properties) + 1) *
  550. sizeof(u32);
  551. } else {
  552. s_vpr_e(inst->sid, "%s: invalid port: %d\n", __func__, port);
  553. return -EINVAL;
  554. }
  555. rc = venus_hfi_session_command(inst,
  556. HFI_CMD_SUBSCRIBE_MODE,
  557. port,
  558. HFI_PAYLOAD_U32_ARRAY,
  559. &payload[0],
  560. payload_size);
  561. return rc;
  562. }
  563. static int msm_venc_metadata_delivery(struct msm_vidc_inst *inst,
  564. enum msm_vidc_port_type port)
  565. {
  566. int rc = 0;
  567. struct msm_vidc_core *core;
  568. u32 payload[32] = {0};
  569. u32 i;
  570. if (!inst || !inst->core) {
  571. d_vpr_e("%s: invalid params\n", __func__);
  572. return -EINVAL;
  573. }
  574. core = inst->core;
  575. d_vpr_h("%s()\n", __func__);
  576. payload[0] = HFI_MODE_METADATA;
  577. for (i = 0; i < ARRAY_SIZE(msm_venc_deliver_as_metadata); i++)
  578. payload[i + 1] = msm_venc_deliver_as_metadata[i];
  579. rc = venus_hfi_session_command(inst,
  580. HFI_CMD_DELIVERY_MODE,
  581. port,
  582. HFI_PAYLOAD_U32_ARRAY,
  583. &payload[0],
  584. (ARRAY_SIZE(msm_venc_deliver_as_metadata) + 1) *
  585. sizeof(u32));
  586. return rc;
  587. }
  588. static int msm_venc_metadata_subscription(struct msm_vidc_inst *inst,
  589. enum msm_vidc_port_type port)
  590. {
  591. int rc = 0;
  592. struct msm_vidc_core *core;
  593. u32 payload[32] = {0};
  594. u32 i;
  595. if (!inst || !inst->core) {
  596. d_vpr_e("%s: invalid params\n", __func__);
  597. return -EINVAL;
  598. }
  599. core = inst->core;
  600. d_vpr_h("%s()\n", __func__);
  601. payload[0] = HFI_MODE_METADATA;
  602. for (i = 0; i < ARRAY_SIZE(msm_venc_subscribe_for_metadata); i++)
  603. payload[i + 1] = msm_venc_subscribe_for_metadata[i];
  604. rc = venus_hfi_session_command(inst,
  605. HFI_CMD_SUBSCRIBE_MODE,
  606. port,
  607. HFI_PAYLOAD_U32_ARRAY,
  608. &payload[0],
  609. (ARRAY_SIZE(msm_venc_subscribe_for_metadata) + 1) *
  610. sizeof(u32));
  611. return rc;
  612. }
  613. int msm_venc_stop_input(struct msm_vidc_inst *inst)
  614. {
  615. int rc = 0;
  616. if (!inst || !inst->core) {
  617. d_vpr_e("%s: invalid params\n", __func__);
  618. return -EINVAL;
  619. }
  620. rc = msm_vidc_session_stop(inst, INPUT_PORT);
  621. if (rc)
  622. return rc;
  623. return 0;
  624. }
  625. int msm_venc_start_input(struct msm_vidc_inst *inst)
  626. {
  627. int rc = 0;
  628. struct msm_vidc_core *core;
  629. if (!inst || !inst->core) {
  630. d_vpr_e("%s: invalid params\n", __func__);
  631. return -EINVAL;
  632. }
  633. core = inst->core;
  634. s_vpr_h(inst->sid, "%s()\n", __func__);
  635. //rc = msm_vidc_check_session_supported(inst);
  636. if (rc)
  637. goto error;
  638. //rc = msm_vidc_check_scaling_supported(inst);
  639. if (rc)
  640. goto error;
  641. rc = msm_venc_set_input_properties(inst);
  642. if (rc)
  643. goto error;
  644. /* Decide bse vpp delay after work mode */
  645. //msm_vidc_set_bse_vpp_delay(inst);
  646. rc = msm_venc_get_input_internal_buffers(inst);
  647. if (rc)
  648. goto error;
  649. /* check for memory after all buffers calculation */
  650. //rc = msm_vidc_check_memory_supported(inst);
  651. if (rc)
  652. goto error;
  653. //msm_vidc_update_dcvs(inst);
  654. //msm_vidc_update_batching(inst);
  655. //msm_vidc_scale_power(inst);
  656. rc = msm_venc_create_input_internal_buffers(inst);
  657. rc = 0; // TODO
  658. if (rc)
  659. goto error;
  660. rc = msm_venc_queue_input_internal_buffers(inst);
  661. rc = 0; // TODO
  662. if (rc)
  663. goto error;
  664. rc = msm_venc_property_subscription(inst, INPUT_PORT);
  665. if (rc)
  666. return rc;
  667. rc = msm_venc_metadata_delivery(inst, INPUT_PORT);
  668. if (rc)
  669. return rc;
  670. rc = venus_hfi_start(inst, INPUT_PORT);
  671. if (rc)
  672. goto error;
  673. s_vpr_h(inst->sid, "%s: done\n", __func__);
  674. return 0;
  675. error:
  676. s_vpr_e(inst->sid, "%s: failed\n", __func__);
  677. msm_venc_stop_input(inst);
  678. return rc;
  679. }
  680. int msm_venc_process_cmd(struct msm_vidc_inst *inst, u32 cmd)
  681. {
  682. int rc = 0;
  683. if (!inst || !inst->core) {
  684. d_vpr_e("%s: invalid params\n", __func__);
  685. return -EINVAL;
  686. }
  687. if (cmd == V4L2_ENC_CMD_STOP) {
  688. rc = venus_hfi_session_command(inst,
  689. HFI_CMD_DRAIN,
  690. INPUT_PORT,
  691. HFI_PAYLOAD_NONE,
  692. NULL,
  693. 0);
  694. if (rc)
  695. return rc;
  696. } else {
  697. d_vpr_e("%s: unknown cmd %d\n", __func__, cmd);
  698. return -EINVAL;
  699. }
  700. return 0;
  701. }
  702. int msm_venc_stop_output(struct msm_vidc_inst *inst)
  703. {
  704. int rc = 0;
  705. if (!inst || !inst->core) {
  706. d_vpr_e("%s: invalid params\n", __func__);
  707. return -EINVAL;
  708. }
  709. rc = msm_vidc_session_stop(inst, OUTPUT_PORT);
  710. if (rc)
  711. return rc;
  712. return 0;
  713. }
  714. int msm_venc_start_output(struct msm_vidc_inst *inst)
  715. {
  716. int rc = 0;
  717. d_vpr_h("%s()\n", __func__);
  718. if (!inst || !inst->core) {
  719. d_vpr_e("%s: invalid params\n", __func__);
  720. return -EINVAL;
  721. }
  722. rc = msm_venc_set_output_properties(inst);
  723. if (rc)
  724. goto error;
  725. rc = msm_vidc_adjust_v4l2_properties(inst);
  726. if (rc)
  727. return -EINVAL;
  728. rc = msm_vidc_set_v4l2_properties(inst);
  729. if (rc)
  730. return -EINVAL;
  731. rc = msm_venc_set_internal_properties(inst);
  732. if (rc)
  733. goto error;
  734. rc = msm_venc_property_subscription(inst, OUTPUT_PORT);
  735. if (rc)
  736. return rc;
  737. rc = msm_venc_metadata_subscription(inst, OUTPUT_PORT);
  738. if (rc)
  739. return rc;
  740. rc = venus_hfi_start(inst, OUTPUT_PORT);
  741. if (rc)
  742. goto error;
  743. d_vpr_h("%s: done\n", __func__);
  744. return 0;
  745. error:
  746. msm_venc_stop_output(inst);
  747. return rc;
  748. }
  749. int msm_venc_s_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f)
  750. {
  751. int rc = 0;
  752. struct msm_vidc_core *core;
  753. struct v4l2_format *fmt;
  754. d_vpr_h("%s()\n", __func__);
  755. if (!inst || !inst->core) {
  756. d_vpr_e("%s: invalid params\n", __func__);
  757. return -EINVAL;
  758. }
  759. core = inst->core;
  760. if (inst->state == MSM_VIDC_START) {
  761. d_vpr_e("%s: invalid state %d\n", __func__, inst->state);
  762. return -EINVAL;
  763. }
  764. if (f->type == INPUT_MPLANE) {
  765. if (inst->state == MSM_VIDC_START_INPUT) {
  766. d_vpr_e("%s: invalid state %d\n", __func__, inst->state);
  767. return -EINVAL;
  768. }
  769. fmt = &inst->fmts[INPUT_PORT];
  770. fmt->type = INPUT_MPLANE;
  771. fmt->fmt.pix_mp.pixelformat = f->fmt.pix_mp.pixelformat;
  772. fmt->fmt.pix_mp.width = VENUS_Y_STRIDE(
  773. v4l2_colorformat_to_media(fmt->fmt.pix_mp.pixelformat,
  774. __func__),
  775. f->fmt.pix_mp.width);
  776. fmt->fmt.pix_mp.height = VENUS_Y_SCANLINES(
  777. v4l2_colorformat_to_media(fmt->fmt.pix_mp.pixelformat,
  778. __func__),
  779. f->fmt.pix_mp.height);
  780. fmt->fmt.pix_mp.num_planes = 1;
  781. fmt->fmt.pix_mp.plane_fmt[0].bytesperline =
  782. fmt->fmt.pix_mp.width;
  783. fmt->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  784. buffer_size, inst, MSM_VIDC_BUF_INPUT);
  785. inst->buffers.input.min_count = call_session_op(core,
  786. min_count, inst, MSM_VIDC_BUF_INPUT);
  787. inst->buffers.input.extra_count = call_session_op(core,
  788. extra_count, inst, MSM_VIDC_BUF_INPUT);
  789. if (inst->buffers.input.actual_count <
  790. inst->buffers.input.min_count +
  791. inst->buffers.input.extra_count) {
  792. inst->buffers.input.actual_count =
  793. inst->buffers.input.min_count +
  794. inst->buffers.input.extra_count;
  795. }
  796. inst->buffers.input.size =
  797. fmt->fmt.pix_mp.plane_fmt[0].sizeimage;
  798. //rc = msm_vidc_check_session_supported(inst);
  799. if (rc)
  800. goto err_invalid_fmt;
  801. //update_log_ctxt(inst->sid, inst->session_type,
  802. // mplane->pixelformat);
  803. s_vpr_h(inst->sid,
  804. "%s: input: codec %#x width %d height %d size %d min_count %d extra_count %d\n",
  805. __func__, f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width,
  806. f->fmt.pix_mp.height,
  807. fmt->fmt.pix_mp.plane_fmt[0].sizeimage,
  808. inst->buffers.input.min_count,
  809. inst->buffers.input.extra_count);
  810. //msm_vidc_update_dcvs(inst);
  811. //msm_vidc_update_batching(inst);
  812. } else if (f->type == INPUT_META_PLANE) {
  813. if (inst->state == MSM_VIDC_START_INPUT) {
  814. d_vpr_e("%s: invalid state %d\n", __func__, inst->state);
  815. return -EINVAL;
  816. }
  817. fmt = &inst->fmts[INPUT_META_PORT];
  818. fmt->type = INPUT_META_PLANE;
  819. fmt->fmt.meta.dataformat = V4L2_META_FMT_VIDC;
  820. fmt->fmt.meta.buffersize = call_session_op(core, buffer_size,
  821. inst, MSM_VIDC_BUF_INPUT_META);
  822. inst->buffers.input_meta.min_count =
  823. inst->buffers.input.min_count;
  824. inst->buffers.input_meta.extra_count =
  825. inst->buffers.input.extra_count;
  826. inst->buffers.input_meta.actual_count =
  827. inst->buffers.input.actual_count;
  828. inst->buffers.input_meta.size = fmt->fmt.meta.buffersize;
  829. s_vpr_h(inst->sid,
  830. "%s: input meta: size %d min_count %d extra_count %d\n",
  831. __func__, fmt->fmt.meta.buffersize,
  832. inst->buffers.input_meta.min_count,
  833. inst->buffers.input_meta.extra_count);
  834. } else if (f->type == OUTPUT_MPLANE) {
  835. if (inst->state == MSM_VIDC_START_OUTPUT) {
  836. d_vpr_e("%s: invalid state %d\n", __func__, inst->state);
  837. return -EINVAL;
  838. }
  839. fmt = &inst->fmts[OUTPUT_PORT];
  840. if (fmt->fmt.pix_mp.pixelformat != f->fmt.pix_mp.pixelformat) {
  841. s_vpr_e(inst->sid,
  842. "%s: codec changed from %#x to %#x\n", __func__,
  843. fmt->fmt.pix_mp.pixelformat, f->fmt.pix_mp.pixelformat);
  844. rc = msm_venc_codec_change(inst, f->fmt.pix_mp.pixelformat);
  845. if (rc)
  846. goto err_invalid_fmt;
  847. }
  848. fmt->type = OUTPUT_MPLANE;
  849. if (f->fmt.pix_mp.pixelformat == V4L2_PIX_FMT_HEVC) {
  850. fmt->fmt.pix_mp.width = ALIGN(f->fmt.pix_mp.width,
  851. H265_BITSTREM_ALIGNMENT);
  852. fmt->fmt.pix_mp.height = ALIGN(f->fmt.pix_mp.height,
  853. H265_BITSTREM_ALIGNMENT);
  854. } else {
  855. fmt->fmt.pix_mp.width = ALIGN(f->fmt.pix_mp.width,
  856. DEFAULT_BITSTREM_ALIGNMENT);
  857. fmt->fmt.pix_mp.height = ALIGN(f->fmt.pix_mp.height,
  858. DEFAULT_BITSTREM_ALIGNMENT);
  859. }
  860. fmt->fmt.pix_mp.pixelformat = f->fmt.pix_mp.pixelformat;
  861. fmt->fmt.pix_mp.num_planes = 1;
  862. fmt->fmt.pix_mp.plane_fmt[0].bytesperline = 0;
  863. fmt->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  864. buffer_size, inst, MSM_VIDC_BUF_OUTPUT);
  865. inst->buffers.output.min_count = call_session_op(core,
  866. min_count, inst, MSM_VIDC_BUF_OUTPUT);
  867. inst->buffers.output.extra_count = call_session_op(core,
  868. extra_count, inst, MSM_VIDC_BUF_OUTPUT);
  869. if (inst->buffers.output.actual_count <
  870. inst->buffers.output.min_count +
  871. inst->buffers.output.extra_count) {
  872. inst->buffers.output.actual_count =
  873. inst->buffers.output.min_count +
  874. inst->buffers.output.extra_count;
  875. }
  876. inst->buffers.output.size =
  877. fmt->fmt.pix_mp.plane_fmt[0].sizeimage;
  878. //rc = msm_vidc_check_session_supported(inst);
  879. if (rc)
  880. goto err_invalid_fmt;
  881. /* update crop dimensions */
  882. inst->crop.left = inst->crop.top = 0;
  883. inst->crop.width = f->fmt.pix_mp.width;
  884. inst->crop.height = f->fmt.pix_mp.height;
  885. //update_log_ctxt(inst->sid, inst->session_type,
  886. // mplane->pixelformat);
  887. s_vpr_h(inst->sid,
  888. "%s: output: format %#x width %d height %d size %d min_count %d extra_count %d\n",
  889. __func__, fmt->fmt.pix_mp.pixelformat, fmt->fmt.pix_mp.width,
  890. fmt->fmt.pix_mp.height,
  891. fmt->fmt.pix_mp.plane_fmt[0].sizeimage,
  892. inst->buffers.output.min_count,
  893. inst->buffers.output.extra_count);
  894. } else if (f->type == OUTPUT_META_PLANE) {
  895. if (inst->state == MSM_VIDC_START_OUTPUT) {
  896. d_vpr_e("%s: invalid state %d\n", __func__, inst->state);
  897. return -EINVAL;
  898. }
  899. fmt = &inst->fmts[OUTPUT_META_PORT];
  900. fmt->type = OUTPUT_META_PLANE;
  901. fmt->fmt.meta.dataformat = V4L2_META_FMT_VIDC;
  902. fmt->fmt.meta.buffersize = call_session_op(core, buffer_size,
  903. inst, MSM_VIDC_BUF_OUTPUT_META);
  904. inst->buffers.output_meta.min_count =
  905. inst->buffers.output.min_count;
  906. inst->buffers.output_meta.extra_count =
  907. inst->buffers.output.extra_count;
  908. inst->buffers.output_meta.actual_count =
  909. inst->buffers.output.actual_count;
  910. inst->buffers.output_meta.size = fmt->fmt.meta.buffersize;
  911. s_vpr_h(inst->sid,
  912. "%s: output meta: size %d min_count %d extra_count %d\n",
  913. __func__, fmt->fmt.meta.buffersize,
  914. inst->buffers.output_meta.min_count,
  915. inst->buffers.output_meta.extra_count);
  916. } else {
  917. s_vpr_e(inst->sid, "%s: invalid type %d\n", __func__, f->type);
  918. goto err_invalid_fmt;
  919. }
  920. memcpy(f, fmt, sizeof(struct v4l2_format));
  921. err_invalid_fmt:
  922. return rc;
  923. }
  924. int msm_venc_g_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f)
  925. {
  926. int rc = 0;
  927. int port;
  928. d_vpr_h("%s()\n", __func__);
  929. if (!inst) {
  930. d_vpr_e("%s: invalid params\n", __func__);
  931. return -EINVAL;
  932. }
  933. port = v4l2_type_to_driver_port(inst, f->type, __func__);
  934. if (port < 0)
  935. return -EINVAL;
  936. memcpy(f, &inst->fmts[port], sizeof(struct v4l2_format));
  937. return rc;
  938. }
  939. int msm_venc_enum_fmt(struct msm_vidc_inst *inst, struct v4l2_fmtdesc *f)
  940. {
  941. int rc = 0;
  942. struct msm_vidc_core *core;
  943. u32 array[32] = {0};
  944. u32 i = 0, idx = 0;
  945. if (!inst || !inst->core || !inst->capabilities || !f) {
  946. d_vpr_e("%s: invalid params\n", __func__);
  947. return -EINVAL;
  948. }
  949. core = inst->core;
  950. if (f->type == OUTPUT_MPLANE) {
  951. u32 codecs = core->capabilities[DEC_CODECS].value;
  952. while (codecs) {
  953. if (idx > 31)
  954. break;
  955. if (codecs & BIT(i)) {
  956. array[idx] = codecs & BIT(i);
  957. idx++;
  958. }
  959. i++;
  960. codecs >>= 1;
  961. }
  962. f->pixelformat = v4l2_codec_from_driver(array[f->index],
  963. __func__);
  964. if (!f->pixelformat)
  965. return -EINVAL;
  966. f->flags = V4L2_FMT_FLAG_COMPRESSED;
  967. strlcpy(f->description, "codec", sizeof(f->description));
  968. } else if (f->type == INPUT_MPLANE) {
  969. u32 formats = inst->capabilities->cap[PIX_FMTS].step_or_mask;
  970. while (formats) {
  971. if (idx > 31)
  972. break;
  973. if (formats & BIT(i)) {
  974. array[idx] = formats & BIT(i);
  975. idx++;
  976. }
  977. i++;
  978. formats >>= 1;
  979. }
  980. f->pixelformat = v4l2_colorformat_from_driver(array[f->index],
  981. __func__);
  982. if (!f->pixelformat)
  983. return -EINVAL;
  984. strlcpy(f->description, "colorformat", sizeof(f->description));
  985. } else if (f->type == INPUT_META_PLANE || f->type == OUTPUT_META_PLANE) {
  986. if (!f->index) {
  987. f->pixelformat = V4L2_META_FMT_VIDC;
  988. strlcpy(f->description, "metadata", sizeof(f->description));
  989. } else {
  990. return -EINVAL;
  991. }
  992. }
  993. memset(f->reserved, 0, sizeof(f->reserved));
  994. s_vpr_h(inst->sid, "%s: index %d, %s : %#x, flags %#x\n",
  995. __func__, f->index, f->description, f->pixelformat, f->flags);
  996. return rc;
  997. }
  998. int msm_venc_inst_init(struct msm_vidc_inst *inst)
  999. {
  1000. int rc = 0;
  1001. struct msm_vidc_core *core;
  1002. struct v4l2_format *f;
  1003. d_vpr_h("%s()\n", __func__);
  1004. if (!inst || !inst->core) {
  1005. d_vpr_e("%s: invalid params\n", __func__);
  1006. return -EINVAL;
  1007. }
  1008. core = inst->core;
  1009. f = &inst->fmts[OUTPUT_PORT];
  1010. f->type = OUTPUT_MPLANE;
  1011. f->fmt.pix_mp.width = DEFAULT_WIDTH;
  1012. f->fmt.pix_mp.height = DEFAULT_HEIGHT;
  1013. f->fmt.pix_mp.pixelformat = V4L2_PIX_FMT_H264;
  1014. f->fmt.pix_mp.num_planes = 1;
  1015. f->fmt.pix_mp.plane_fmt[0].bytesperline = 0;
  1016. f->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  1017. buffer_size, inst, MSM_VIDC_BUF_OUTPUT);
  1018. inst->buffers.output.min_count = call_session_op(core,
  1019. min_count, inst, MSM_VIDC_BUF_OUTPUT);
  1020. inst->buffers.output.extra_count = call_session_op(core,
  1021. extra_count, inst, MSM_VIDC_BUF_OUTPUT);
  1022. inst->buffers.output.actual_count =
  1023. inst->buffers.output.min_count +
  1024. inst->buffers.output.extra_count;
  1025. inst->buffers.output.size = f->fmt.pix_mp.plane_fmt[0].sizeimage;
  1026. inst->crop.left = inst->crop.top = 0;
  1027. inst->crop.width = f->fmt.pix_mp.width;
  1028. inst->crop.height = f->fmt.pix_mp.height;
  1029. f = &inst->fmts[OUTPUT_META_PORT];
  1030. f->type = OUTPUT_META_PLANE;
  1031. f->fmt.meta.dataformat = V4L2_META_FMT_VIDC;
  1032. f->fmt.meta.buffersize = call_session_op(core, buffer_size,
  1033. inst, MSM_VIDC_BUF_OUTPUT_META);
  1034. inst->buffers.output_meta.min_count = inst->buffers.output.min_count;
  1035. inst->buffers.output_meta.extra_count = inst->buffers.output.extra_count;
  1036. inst->buffers.output_meta.actual_count = inst->buffers.output.actual_count;
  1037. inst->buffers.output_meta.size = f->fmt.meta.buffersize;
  1038. f = &inst->fmts[INPUT_PORT];
  1039. f->type = INPUT_MPLANE;
  1040. f->fmt.pix_mp.pixelformat = V4L2_PIX_FMT_VIDC_NV12C;
  1041. f->fmt.pix_mp.width = VENUS_Y_STRIDE(
  1042. v4l2_colorformat_to_media(f->fmt.pix_mp.pixelformat, __func__),
  1043. DEFAULT_WIDTH);
  1044. f->fmt.pix_mp.height = VENUS_Y_SCANLINES(
  1045. v4l2_colorformat_to_media(f->fmt.pix_mp.pixelformat, __func__),
  1046. DEFAULT_HEIGHT);
  1047. f->fmt.pix_mp.num_planes = 1;
  1048. f->fmt.pix_mp.plane_fmt[0].bytesperline = f->fmt.pix_mp.width;
  1049. f->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
  1050. buffer_size, inst, MSM_VIDC_BUF_INPUT);
  1051. inst->buffers.input.min_count = call_session_op(core,
  1052. min_count, inst, MSM_VIDC_BUF_INPUT);
  1053. inst->buffers.input.extra_count = call_session_op(core,
  1054. extra_count, inst, MSM_VIDC_BUF_INPUT);
  1055. inst->buffers.input.actual_count =
  1056. inst->buffers.input.min_count +
  1057. inst->buffers.input.extra_count;
  1058. inst->buffers.input.size = f->fmt.pix_mp.plane_fmt[0].sizeimage;
  1059. f = &inst->fmts[INPUT_META_PORT];
  1060. f->type = INPUT_META_PLANE;
  1061. f->fmt.meta.dataformat = V4L2_META_FMT_VIDC;
  1062. f->fmt.meta.buffersize = call_session_op(core, buffer_size,
  1063. inst, MSM_VIDC_BUF_INPUT_META);
  1064. inst->buffers.input_meta.min_count = inst->buffers.input.min_count;
  1065. inst->buffers.input_meta.extra_count = inst->buffers.input.extra_count;
  1066. inst->buffers.input_meta.actual_count = inst->buffers.input.actual_count;
  1067. inst->buffers.input_meta.size = f->fmt.meta.buffersize;
  1068. inst->prop.frame_rate = DEFAULT_FPS << 16;
  1069. inst->prop.operating_rate = DEFAULT_FPS << 16;
  1070. inst->stage = MSM_VIDC_STAGE_2;
  1071. inst->pipe = MSM_VIDC_PIPE_4;
  1072. inst->quality_mode = MSM_VIDC_MAX_QUALITY_MODE;
  1073. rc = msm_venc_codec_change(inst,
  1074. inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat);
  1075. return rc;
  1076. }