123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563 |
- // SPDX-License-Identifier: GPL-2.0-only
- /*
- * Copyright (c) 2020, The Linux Foundation. All rights reserved.
- */
- #include <media/v4l2_vidc_extensions.h>
- #include <media/msm_media_info.h>
- #include "msm_venc.h"
- #include "msm_vidc_core.h"
- #include "msm_vidc_inst.h"
- #include "msm_vidc_driver.h"
- #include "msm_vidc_internal.h"
- #include "msm_vidc_platform.h"
- #include "msm_vidc_control.h"
- #include "msm_vidc_debug.h"
- #include "venus_hfi.h"
- #include "hfi_packet.h"
- u32 msm_venc_input_set_prop[] = {
- HFI_PROP_COLOR_FORMAT,
- HFI_PROP_RAW_RESOLUTION,
- HFI_PROP_LINEAR_ALIGNMENT_FACTOR,
- HFI_PROP_BUFFER_HOST_MAX_COUNT,
- };
- u32 msm_venc_output_set_prop[] = {
- HFI_PROP_BITSTREAM_RESOLUTION,
- HFI_PROP_CROP_OFFSETS,
- HFI_PROP_BUFFER_HOST_MAX_COUNT,
- };
- u32 msm_venc_input_subscribe_for_properties[] = {
- HFI_PROP_NO_OUTPUT,
- };
- u32 msm_venc_output_subscribe_for_properties[] = {
- HFI_PROP_PICTURE_TYPE,
- HFI_PROP_BUFFER_MARK,
- };
- static int msm_venc_codec_change(struct msm_vidc_inst *inst, u32 v4l2_codec)
- {
- int rc = 0;
- if (inst->codec && inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat == v4l2_codec)
- return 0;
- s_vpr_h(inst->sid, "%s: codec changed from %#x to %#x\n",
- __func__, inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat, v4l2_codec);
- inst->codec = v4l2_codec_to_driver(v4l2_codec, __func__);
- rc = msm_vidc_get_inst_capability(inst);
- if (rc)
- goto exit;
- rc = msm_vidc_ctrl_deinit(inst);
- if (rc)
- goto exit;
- rc = msm_vidc_ctrl_init(inst);
- if (rc)
- goto exit;
- exit:
- return rc;
- }
- /* todo: add logs for each property once finalised */
- static int msm_venc_set_colorformat(struct msm_vidc_inst *inst,
- enum msm_vidc_port_type port)
- {
- int rc = 0;
- u32 pixelformat;
- enum msm_vidc_colorformat_type colorformat;
- u32 hfi_colorformat;
- if (port != INPUT_PORT && port != OUTPUT_PORT) {
- s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
- return -EINVAL;
- }
- pixelformat = inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat;
- if (pixelformat != V4L2_PIX_FMT_VIDC_NV12C &&
- pixelformat != V4L2_PIX_FMT_VIDC_TP10C) {
- s_vpr_e(inst->sid, "%s: invalid pixelformat %#x\n",
- __func__, pixelformat);
- return -EINVAL;
- }
- colorformat = v4l2_colorformat_to_driver(pixelformat, __func__);
- hfi_colorformat = get_hfi_colorformat(inst, colorformat);
- rc = venus_hfi_session_property(inst,
- HFI_PROP_COLOR_FORMAT,
- HFI_HOST_FLAGS_NONE,
- get_hfi_port(inst, port),
- HFI_PAYLOAD_U32_ENUM,
- &hfi_colorformat,
- sizeof(u32));
- if (rc)
- return rc;
- return 0;
- }
- /* TODO: Enable when NV12 support is required */
- static int msm_venc_set_linear_alignment_factor(struct msm_vidc_inst *inst,
- enum msm_vidc_port_type port)
- {
- /* int rc = 0;
- u32 pixelformat;
- u32 alignment_factor[2];
- if (port != INPUT_PORT) {
- s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
- return -EINVAL;
- }
- pixelformat = inst->fmts[INPUT_PORT].fmt.pix_mp.pixelformat;
- if (pixelformat == V4L2_PIX_FMT_VIDC_NV12C ||
- pixelformat == V4L2_PIX_FMT_VIDC_TP10C ||
- pixelformat == V4L2_PIX_FMT_VIDC_ARGB32C) {
- s_vpr_e(inst->sid,
- "%s: not a linear color fmt, property is not set\n",
- __func__);
- return 0;
- }
- if (pixelformat == V4L2_PIX_FMT_ARGB32) {
- alignment_factor[0] =
- (rgb_stride_alignment(pixelformat, __func__) << 16) |
- rgb_scanline_alignment(pixelformat, __func__);
- alignment_factor[1] = 0;
- } else {
- alignment_factor[0] =
- (y_stride_alignment(pixelformat, __func__) << 16) |
- y_scanline_alignment(pixelformat, __func__);
- alignment_factor[1] =
- (uv_stride_alignment(pixelformat, __func__) << 16) |
- uv_scanline_alignment(pixelformat, __func__);
- }
- s_vpr_h(inst->sid, "%s: payload[0]: %u payload[1]: %u\n", __func__,
- alignment_factor[0], alignment_factor[1]);
- rc = venus_hfi_session_property(inst,
- HFI_PROP_LINEAR_ALIGNMENT_FACTOR,
- HFI_HOST_FLAGS_NONE,
- get_hfi_port(inst, port),
- HFI_PAYLOAD_64_PACKED,
- &alignment_factor,
- sizeof(u64));
- if (rc)
- return rc;
- */
- return 0;
- }
- static int msm_venc_set_raw_resolution(struct msm_vidc_inst *inst,
- enum msm_vidc_port_type port)
- {
- int rc = 0;
- u32 resolution;
- if (port != INPUT_PORT) {
- s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
- return -EINVAL;
- }
- resolution = inst->crop.width << 16 | inst->crop.height;
- s_vpr_h(inst->sid, "%s: width: %d height: %d\n", __func__,
- inst->crop.width, inst->crop.height);
- rc = venus_hfi_session_property(inst,
- HFI_PROP_RAW_RESOLUTION,
- HFI_HOST_FLAGS_NONE,
- get_hfi_port(inst, port),
- HFI_PAYLOAD_32_PACKED,
- &resolution,
- sizeof(u32));
- if (rc)
- return rc;
- return 0;
- }
- static int msm_venc_set_bitstream_resolution(struct msm_vidc_inst *inst,
- enum msm_vidc_port_type port)
- {
- int rc = 0;
- u32 resolution;
- if (port != OUTPUT_PORT) {
- s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
- return -EINVAL;
- }
- resolution = (inst->fmts[port].fmt.pix_mp.width << 16) |
- inst->fmts[port].fmt.pix_mp.height;
- s_vpr_h(inst->sid, "%s: width: %d height: %d\n", __func__,
- inst->fmts[port].fmt.pix_mp.width,
- inst->fmts[port].fmt.pix_mp.height);
- rc = venus_hfi_session_property(inst,
- HFI_PROP_BITSTREAM_RESOLUTION,
- HFI_HOST_FLAGS_NONE,
- get_hfi_port(inst, port),
- HFI_PAYLOAD_32_PACKED,
- &resolution,
- sizeof(u32));
- if (rc)
- return rc;
- return 0;
- }
- static int msm_venc_set_crop_offsets(struct msm_vidc_inst *inst,
- enum msm_vidc_port_type port)
- {
- int rc = 0;
- u32 left_offset, top_offset, right_offset, bottom_offset;
- u64 crop;
- if (port != OUTPUT_PORT) {
- s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
- return -EINVAL;
- }
- left_offset = inst->crop.left;
- top_offset = inst->crop.top;
- right_offset = (inst->fmts[port].fmt.pix_mp.width -
- inst->crop.width);
- bottom_offset = (inst->fmts[port].fmt.pix_mp.height -
- inst->crop.height);
- crop = (u64)right_offset << 48 | (u64)bottom_offset << 32 |
- (u64)left_offset << 16 | top_offset;
- s_vpr_h(inst->sid, "%s: left_offset: %d top_offset: %d "
- "right_offset: %d bottom_offset: %d", __func__,
- left_offset, top_offset, right_offset, bottom_offset);
- rc = venus_hfi_session_property(inst,
- HFI_PROP_CROP_OFFSETS,
- HFI_HOST_FLAGS_NONE,
- get_hfi_port(inst, port),
- HFI_PAYLOAD_64_PACKED,
- &crop,
- sizeof(u64));
- if (rc)
- return rc;
- return 0;
- }
- static int msm_venc_set_host_max_buf_count(struct msm_vidc_inst *inst,
- enum msm_vidc_port_type port)
- {
- int rc = 0;
- u32 count = DEFAULT_MAX_HOST_BUF_COUNT;
- if (port != INPUT_PORT && port != OUTPUT_PORT) {
- s_vpr_e(inst->sid, "%s: invalid port %d\n", __func__, port);
- return -EINVAL;
- }
- s_vpr_h(inst->sid, "%s: count: %u port: %u\n", __func__, count, port);
- rc = venus_hfi_session_property(inst,
- HFI_PROP_BUFFER_HOST_MAX_COUNT,
- HFI_HOST_FLAGS_NONE,
- get_hfi_port(inst, port),
- HFI_PAYLOAD_U32,
- &count,
- sizeof(u32));
- if (rc)
- return rc;
- return 0;
- }
- static int msm_venc_set_stage(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- struct msm_vidc_core *core = inst->core;
- struct msm_vidc_inst_capability *capability = inst->capabilities;
- u32 stage;
- rc = call_session_op(core, decide_work_mode, inst);
- if (rc) {
- s_vpr_e(inst->sid, "%s: decide_work_mode failed\n",
- __func__);
- return -EINVAL;
- }
- stage = capability->cap[STAGE].value;
- s_vpr_h(inst->sid, "%s: stage: %u\n", __func__, stage);
- rc = venus_hfi_session_property(inst,
- HFI_PROP_STAGE,
- HFI_HOST_FLAGS_NONE,
- HFI_PORT_NONE,
- HFI_PAYLOAD_U32,
- &stage,
- sizeof(u32));
- if (rc)
- return rc;
- return 0;
- }
- static int msm_venc_set_pipe(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- struct msm_vidc_core *core = inst->core;
- struct msm_vidc_inst_capability *capability = inst->capabilities;
- u32 pipe;
- rc = call_session_op(core, decide_work_route, inst);
- if (rc) {
- s_vpr_e(inst->sid, "%s: decide_work_route failed\n",
- __func__);
- return -EINVAL;
- }
- pipe = capability->cap[PIPE].value;
- s_vpr_h(inst->sid, "%s: pipe: %u\n", __func__, pipe);
- rc = venus_hfi_session_property(inst,
- HFI_PROP_PIPE,
- HFI_HOST_FLAGS_NONE,
- HFI_PORT_NONE,
- HFI_PAYLOAD_U32,
- &pipe,
- sizeof(u32));
- if (rc)
- return rc;
- return 0;
- }
- static int msm_venc_set_quality_mode(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- struct msm_vidc_inst_capability *capability = inst->capabilities;
- u32 mode;
- mode = capability->cap[QUALITY_MODE].value;
- s_vpr_h(inst->sid, "%s: quality_mode: %u\n", __func__, mode);
- rc = venus_hfi_session_property(inst,
- HFI_PROP_QUALITY_MODE,
- HFI_HOST_FLAGS_NONE,
- HFI_PORT_BITSTREAM,
- HFI_PAYLOAD_U32_ENUM,
- &mode,
- sizeof(u32));
- if (rc)
- return rc;
- return 0;
- }
- static int msm_venc_set_input_properties(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- int i = 0;
- d_vpr_h("%s()\n", __func__);
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- for (i = 0; i < ARRAY_SIZE(msm_venc_input_set_prop);
- i++) {
- switch (msm_venc_input_set_prop[i]) {
- case HFI_PROP_COLOR_FORMAT:
- rc = msm_venc_set_colorformat(inst, INPUT_PORT);
- break;
- case HFI_PROP_RAW_RESOLUTION:
- rc = msm_venc_set_raw_resolution(inst, INPUT_PORT);
- break;
- case HFI_PROP_LINEAR_ALIGNMENT_FACTOR:
- rc = msm_venc_set_linear_alignment_factor(inst, INPUT_PORT);
- break;
- case HFI_PROP_BUFFER_HOST_MAX_COUNT:
- rc = msm_venc_set_host_max_buf_count(inst, INPUT_PORT);
- break;
- default:
- d_vpr_e("%s: unknown property %#x\n", __func__,
- msm_venc_input_set_prop[i]);
- rc = -EINVAL;
- break;
- }
- }
- return rc;
- }
- static int msm_venc_set_output_properties(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- int i = 0;
- d_vpr_h("%s()\n", __func__);
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- for (i = 0; i < ARRAY_SIZE(msm_venc_output_set_prop);
- i++) {
- switch (msm_venc_output_set_prop[i]) {
- case HFI_PROP_BITSTREAM_RESOLUTION:
- rc = msm_venc_set_bitstream_resolution(inst, OUTPUT_PORT);
- break;
- case HFI_PROP_CROP_OFFSETS:
- rc = msm_venc_set_crop_offsets(inst, OUTPUT_PORT);
- break;
- case HFI_PROP_BUFFER_HOST_MAX_COUNT:
- rc = msm_venc_set_host_max_buf_count(inst, OUTPUT_PORT);
- break;
- default:
- d_vpr_e("%s: unknown property %#x\n", __func__,
- msm_venc_output_set_prop[i]);
- rc = -EINVAL;
- break;
- }
- }
- return rc;
- }
- static int msm_venc_set_internal_properties(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- d_vpr_h("%s()\n", __func__);
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- //TODO: set HFI_PORT_NONE properties at master port streamon.
- rc = msm_venc_set_stage(inst);
- if (rc)
- return rc;
- rc = msm_venc_set_pipe(inst);
- if (rc)
- return rc;
- rc = msm_venc_set_quality_mode(inst);
- if (rc)
- return rc;
- return rc;
- }
- static int msm_venc_get_input_internal_buffers(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- struct msm_vidc_core *core;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- inst->buffers.arp.size = call_session_op(core, buffer_size,
- inst, MSM_VIDC_BUF_ARP) + 100000000;
- inst->buffers.bin.size = call_session_op(core, buffer_size,
- inst, MSM_VIDC_BUF_BIN) + 100000000;
- inst->buffers.comv.size = call_session_op(core, buffer_size,
- inst, MSM_VIDC_BUF_COMV) + 100000000;
- inst->buffers.non_comv.size = call_session_op(core, buffer_size,
- inst, MSM_VIDC_BUF_NON_COMV) + 100000000;
- inst->buffers.line.size = call_session_op(core, buffer_size,
- inst, MSM_VIDC_BUF_LINE) + 100000000;
- inst->buffers.dpb.size = call_session_op(core, buffer_size,
- inst, MSM_VIDC_BUF_DPB) + 100000000;
- //inst->buffers.vpss.size = call_session_op(core, buffer_size,
- //inst, MSM_VIDC_BUF_VPSS) + 100000000;
- //vpss is req - 100 mb
- /* inst->buffers.persist.size = call_session_op(core, buffer_size,
- inst, MSM_VIDC_BUF_PERSIST); */
- inst->buffers.arp.min_count = call_session_op(core, min_count,
- inst, MSM_VIDC_BUF_ARP);
- inst->buffers.bin.min_count = call_session_op(core, min_count,
- inst, MSM_VIDC_BUF_BIN);
- inst->buffers.comv.min_count = call_session_op(core, min_count,
- inst, MSM_VIDC_BUF_COMV);
- inst->buffers.non_comv.min_count = call_session_op(core, min_count,
- inst, MSM_VIDC_BUF_NON_COMV);
- inst->buffers.line.min_count = call_session_op(core, min_count,
- inst, MSM_VIDC_BUF_LINE);
- inst->buffers.dpb.min_count = call_session_op(core, min_count,
- inst, MSM_VIDC_BUF_DPB);
- /* inst->buffers.persist.min_count = call_session_op(core, min_count,
- inst, MSM_VIDC_BUF_PERSIST); */
- s_vpr_h(inst->sid, "internal buffer: min size\n");
- s_vpr_h(inst->sid, "arp buffer: %d %d\n",
- inst->buffers.arp.min_count,
- inst->buffers.arp.size);
- s_vpr_h(inst->sid, "bin buffer: %d %d\n",
- inst->buffers.bin.min_count,
- inst->buffers.bin.size);
- s_vpr_h(inst->sid, "comv buffer: %d %d\n",
- inst->buffers.comv.min_count,
- inst->buffers.comv.size);
- s_vpr_h(inst->sid, "non_comv buffer: %d %d\n",
- inst->buffers.non_comv.min_count,
- inst->buffers.non_comv.size);
- s_vpr_h(inst->sid, "line buffer: %d %d\n",
- inst->buffers.line.min_count,
- inst->buffers.line.size);
- s_vpr_h(inst->sid, "dpb buffer: %d %d\n",
- inst->buffers.dpb.min_count,
- inst->buffers.dpb.size);
- /* s_vpr_h(inst->sid, "persist buffer: %d %d\n",
- inst->buffers.persist.min_count,
- inst->buffers.persist.size); */
- return rc;
- }
- static int msm_venc_create_input_internal_buffers(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- d_vpr_h("%s()\n", __func__);
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_ARP);
- if (rc)
- return rc;
- rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_BIN);
- if (rc)
- return rc;
- rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_COMV);
- if (rc)
- return rc;
- rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_NON_COMV);
- if (rc)
- return rc;
- rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_LINE);
- if (rc)
- return rc;
- rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_DPB);
- if (rc)
- return rc;
- /* rc = msm_vidc_create_internal_buffers(inst, MSM_VIDC_BUF_PERSIST);
- if (rc)
- return rc; */
- return 0;
- }
- static int msm_venc_queue_input_internal_buffers(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- d_vpr_h("%s()\n", __func__);
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_ARP);
- if (rc)
- return rc;
- rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_BIN);
- if (rc)
- return rc;
- rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_COMV);
- if (rc)
- return rc;
- rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_NON_COMV);
- if (rc)
- return rc;
- rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_LINE);
- if (rc)
- return rc;
- rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_DPB);
- if (rc)
- return rc;
- // TODO: fw is not accepting persist buffer and returning session error.
- //rc = msm_vidc_queue_internal_buffers(inst, MSM_VIDC_BUF_PERSIST);
- if (rc)
- return rc;
- return 0;
- }
- static int msm_venc_property_subscription(struct msm_vidc_inst *inst,
- enum msm_vidc_port_type port)
- {
- int rc = 0;
- struct msm_vidc_core *core;
- u32 payload[32] = {0};
- u32 i;
- u32 payload_size = 0;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- d_vpr_h("%s()\n", __func__);
- payload[0] = HFI_MODE_PROPERTY;
- if (port == INPUT_PORT) {
- for (i = 0; i < ARRAY_SIZE(msm_venc_input_subscribe_for_properties); i++)
- payload[i + 1] = msm_venc_input_subscribe_for_properties[i];
- payload_size = (ARRAY_SIZE(msm_venc_input_subscribe_for_properties) + 1) *
- sizeof(u32);
- } else if (port == OUTPUT_PORT) {
- for (i = 0; i < ARRAY_SIZE(msm_venc_output_subscribe_for_properties); i++)
- payload[i + 1] = msm_venc_output_subscribe_for_properties[i];
- payload_size = (ARRAY_SIZE(msm_venc_output_subscribe_for_properties) + 1) *
- sizeof(u32);
- } else {
- s_vpr_e(inst->sid, "%s: invalid port: %d\n", __func__, port);
- return -EINVAL;
- }
- rc = venus_hfi_session_command(inst,
- HFI_CMD_SUBSCRIBE_MODE,
- port,
- HFI_PAYLOAD_U32_ARRAY,
- &payload[0],
- payload_size);
- return rc;
- }
- static int msm_venc_metadata_delivery(struct msm_vidc_inst *inst,
- enum msm_vidc_port_type port)
- {
- int rc = 0;
- struct msm_vidc_core *core;
- u32 payload[32] = {0};
- u32 i, count = 0;
- struct msm_vidc_inst_capability *capability;
- u32 metadata_list[] = {
- META_SEI_MASTERING_DISP,
- META_SEI_CLL,
- META_HDR10PLUS,
- META_EVA_STATS,
- META_BUF_TAG,
- META_ROI_INFO,
- };
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- d_vpr_h("%s()\n", __func__);
- capability = inst->capabilities;
- payload[0] = HFI_MODE_METADATA;
- for (i = 0; i < ARRAY_SIZE(metadata_list); i++) {
- if (capability->cap[metadata_list[i]].value) {
- payload[count + 1] =
- capability->cap[metadata_list[i]].hfi_id;
- count++;
- }
- };
- rc = venus_hfi_session_command(inst,
- HFI_CMD_DELIVERY_MODE,
- port,
- HFI_PAYLOAD_U32_ARRAY,
- &payload[0],
- (count + 1) * sizeof(u32));
- return rc;
- }
- static int msm_venc_metadata_subscription(struct msm_vidc_inst *inst,
- enum msm_vidc_port_type port)
- {
- int rc = 0;
- struct msm_vidc_core *core;
- u32 payload[32] = {0};
- u32 i, count = 0;
- struct msm_vidc_inst_capability *capability;
- u32 metadata_list[] = {
- META_LTR_MARK_USE,
- META_SEQ_HDR_NAL,
- META_TIMESTAMP,
- META_BUF_TAG,
- META_SUBFRAME_OUTPUT,
- META_ENC_QP_METADATA,
- };
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- d_vpr_h("%s()\n", __func__);
- capability = inst->capabilities;
- payload[0] = HFI_MODE_METADATA;
- for (i = 0; i < ARRAY_SIZE(metadata_list); i++) {
- if (capability->cap[metadata_list[i]].value) {
- payload[count + 1] =
- capability->cap[metadata_list[i]].hfi_id;
- count++;
- }
- };
- rc = venus_hfi_session_command(inst,
- HFI_CMD_SUBSCRIBE_MODE,
- port,
- HFI_PAYLOAD_U32_ARRAY,
- &payload[0],
- (count + 1) * sizeof(u32));
- return rc;
- }
- int msm_venc_streamoff_input(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- rc = msm_vidc_session_streamoff(inst, INPUT_PORT);
- if (rc)
- return rc;
- return 0;
- }
- int msm_venc_streamon_input(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (is_input_meta_enabled(inst) &&
- !inst->vb2q[INPUT_META_PORT].streaming) {
- s_vpr_e(inst->sid,
- "%s: Meta port must be streamed on before data port\n",
- __func__);
- return -EINVAL;
- }
- //rc = msm_vidc_check_session_supported(inst);
- if (rc)
- goto error;
- //rc = msm_vidc_check_scaling_supported(inst);
- if (rc)
- goto error;
- rc = msm_venc_set_input_properties(inst);
- if (rc)
- goto error;
- /* Decide bse vpp delay after work mode */
- //msm_vidc_set_bse_vpp_delay(inst);
- rc = msm_venc_get_input_internal_buffers(inst);
- if (rc)
- goto error;
- /* check for memory after all buffers calculation */
- //rc = msm_vidc_check_memory_supported(inst);
- if (rc)
- goto error;
- //msm_vidc_update_dcvs(inst);
- //msm_vidc_update_batching(inst);
- //msm_vidc_scale_power(inst);
- rc = msm_venc_create_input_internal_buffers(inst);
- rc = 0; // TODO
- if (rc)
- goto error;
- rc = msm_venc_queue_input_internal_buffers(inst);
- rc = 0; // TODO
- if (rc)
- goto error;
- rc = msm_venc_property_subscription(inst, INPUT_PORT);
- if (rc)
- return rc;
- rc = msm_venc_metadata_delivery(inst, INPUT_PORT);
- if (rc)
- return rc;
- rc = msm_vidc_session_streamon(inst, INPUT_PORT);
- if (rc)
- goto error;
- return 0;
- error:
- s_vpr_e(inst->sid, "%s: failed\n", __func__);
- msm_venc_streamoff_input(inst);
- return rc;
- }
- int msm_venc_process_cmd(struct msm_vidc_inst *inst, u32 cmd)
- {
- int rc = 0;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (cmd == V4L2_ENC_CMD_STOP) {
- if (!msm_vidc_allow_stop(inst))
- return -EBUSY;
- rc = venus_hfi_session_command(inst,
- HFI_CMD_DRAIN,
- INPUT_PORT,
- HFI_PAYLOAD_NONE,
- NULL,
- 0);
- if (rc)
- return rc;
- rc = msm_vidc_state_change_stop(inst);
- if (rc)
- return rc;
- } else if (cmd == V4L2_ENC_CMD_START) {
- if (!msm_vidc_allow_start(inst))
- return -EBUSY;
- rc = msm_vidc_state_change_start(inst);
- if (rc)
- return rc;
- rc = venus_hfi_session_command(inst,
- HFI_CMD_RESUME,
- INPUT_PORT,
- HFI_PAYLOAD_NONE,
- NULL,
- 0);
- if (rc)
- return rc;
- } else {
- d_vpr_e("%s: unknown cmd %d\n", __func__, cmd);
- return -EINVAL;
- }
- return 0;
- }
- int msm_venc_streamoff_output(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- rc = msm_vidc_session_streamoff(inst, OUTPUT_PORT);
- if (rc)
- return rc;
- return 0;
- }
- int msm_venc_streamon_output(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (is_output_meta_enabled(inst) &&
- !inst->vb2q[OUTPUT_META_PORT].streaming) {
- s_vpr_e(inst->sid,
- "%s: Meta port must be streamed on before data port\n",
- __func__);
- return -EINVAL;
- }
- rc = msm_venc_set_output_properties(inst);
- if (rc)
- goto error;
- rc = msm_vidc_adjust_v4l2_properties(inst);
- if (rc)
- goto error;
- rc = msm_vidc_set_v4l2_properties(inst);
- if (rc)
- goto error;
- rc = msm_venc_set_internal_properties(inst);
- if (rc)
- goto error;
- rc = msm_venc_property_subscription(inst, OUTPUT_PORT);
- if (rc)
- goto error;
- rc = msm_venc_metadata_subscription(inst, OUTPUT_PORT);
- if (rc)
- goto error;
- rc = msm_vidc_session_streamon(inst, OUTPUT_PORT);
- if (rc)
- goto error;
- return 0;
- error:
- s_vpr_e(inst->sid, "%s: failed\n", __func__);
- msm_venc_streamoff_output(inst);
- return rc;
- }
- // TODO: use PIX_FMTS caps to check supported color format
- int msm_venc_s_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f)
- {
- int rc = 0;
- struct msm_vidc_core *core;
- struct v4l2_format *fmt;
- u32 codec_align;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- if (f->type == INPUT_MPLANE) {
- fmt = &inst->fmts[INPUT_PORT];
- fmt->type = INPUT_MPLANE;
- fmt->fmt.pix_mp.pixelformat = f->fmt.pix_mp.pixelformat;
- fmt->fmt.pix_mp.width = VENUS_Y_STRIDE(
- v4l2_colorformat_to_media(fmt->fmt.pix_mp.pixelformat, __func__),
- f->fmt.pix_mp.width);
- fmt->fmt.pix_mp.height = VENUS_Y_SCANLINES(
- v4l2_colorformat_to_media(fmt->fmt.pix_mp.pixelformat, __func__),
- f->fmt.pix_mp.height);
- fmt->fmt.pix_mp.num_planes = 1;
- fmt->fmt.pix_mp.plane_fmt[0].bytesperline =
- fmt->fmt.pix_mp.width;
- fmt->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
- buffer_size, inst, MSM_VIDC_BUF_INPUT);
- inst->buffers.input.min_count = call_session_op(core,
- min_count, inst, MSM_VIDC_BUF_INPUT);
- inst->buffers.input.extra_count = call_session_op(core,
- extra_count, inst, MSM_VIDC_BUF_INPUT);
- if (inst->buffers.input.actual_count <
- inst->buffers.input.min_count +
- inst->buffers.input.extra_count) {
- inst->buffers.input.actual_count =
- inst->buffers.input.min_count +
- inst->buffers.input.extra_count;
- }
- inst->buffers.input.size =
- fmt->fmt.pix_mp.plane_fmt[0].sizeimage;
- codec_align = inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat ==
- V4L2_PIX_FMT_HEVC ? 32 : 16;
- /* check if resolution changed */
- if (inst->fmts[OUTPUT_PORT].fmt.pix_mp.width !=
- ALIGN(f->fmt.pix_mp.width, codec_align) ||
- inst->fmts[OUTPUT_PORT].fmt.pix_mp.height !=
- ALIGN(f->fmt.pix_mp.height, codec_align)) {
- /* reset bitstream port with updated resolution */
- inst->fmts[OUTPUT_PORT].fmt.pix_mp.width =
- ALIGN(f->fmt.pix_mp.width, codec_align);
- inst->fmts[OUTPUT_PORT].fmt.pix_mp.height =
- ALIGN(f->fmt.pix_mp.height, codec_align);
- inst->fmts[OUTPUT_PORT].fmt.pix_mp.plane_fmt[0].sizeimage =
- call_session_op(core, buffer_size,
- inst, MSM_VIDC_BUF_OUTPUT);
- /* reset crop dimensions with updated resolution */
- inst->crop.top = inst->crop.left = 0;
- inst->crop.width = f->fmt.pix_mp.width;
- inst->crop.height = f->fmt.pix_mp.height;
- /* reset compose dimensions with updated resolution */
- inst->compose.top = inst->crop.left = 0;
- inst->compose.width = f->fmt.pix_mp.width;
- inst->compose.height = f->fmt.pix_mp.height;
- }
- //rc = msm_vidc_check_session_supported(inst);
- if (rc)
- goto err_invalid_fmt;
- //update_log_ctxt(inst->sid, inst->session_type,
- // mplane->pixelformat);
- s_vpr_h(inst->sid,
- "%s: input: codec %#x width %d height %d size %d min_count %d extra_count %d\n",
- __func__, f->fmt.pix_mp.pixelformat, f->fmt.pix_mp.width,
- f->fmt.pix_mp.height,
- fmt->fmt.pix_mp.plane_fmt[0].sizeimage,
- inst->buffers.input.min_count,
- inst->buffers.input.extra_count);
- //msm_vidc_update_dcvs(inst);
- //msm_vidc_update_batching(inst);
- } else if (f->type == INPUT_META_PLANE) {
- fmt = &inst->fmts[INPUT_META_PORT];
- fmt->type = INPUT_META_PLANE;
- fmt->fmt.meta.dataformat = V4L2_META_FMT_VIDC;
- if (is_input_meta_enabled(inst)) {
- fmt->fmt.meta.buffersize = call_session_op(core,
- buffer_size, inst, MSM_VIDC_BUF_OUTPUT_META);
- inst->buffers.input_meta.min_count =
- inst->buffers.input.min_count;
- inst->buffers.input_meta.extra_count =
- inst->buffers.input.extra_count;
- inst->buffers.input_meta.actual_count =
- inst->buffers.input.actual_count;
- inst->buffers.input_meta.size = fmt->fmt.meta.buffersize;
- } else {
- fmt->fmt.meta.buffersize = 0;
- inst->buffers.input_meta.min_count = 0;
- inst->buffers.input_meta.extra_count = 0;
- inst->buffers.input_meta.actual_count = 0;
- inst->buffers.input_meta.size = 0;
- }
- s_vpr_h(inst->sid,
- "%s: input meta: size %d min_count %d extra_count %d\n",
- __func__, fmt->fmt.meta.buffersize,
- inst->buffers.input_meta.min_count,
- inst->buffers.input_meta.extra_count);
- } else if (f->type == OUTPUT_MPLANE) {
- fmt = &inst->fmts[OUTPUT_PORT];
- if (fmt->fmt.pix_mp.pixelformat != f->fmt.pix_mp.pixelformat) {
- s_vpr_e(inst->sid,
- "%s: codec changed from %#x to %#x\n", __func__,
- fmt->fmt.pix_mp.pixelformat, f->fmt.pix_mp.pixelformat);
- rc = msm_venc_codec_change(inst, f->fmt.pix_mp.pixelformat);
- if (rc)
- goto err_invalid_fmt;
- }
- fmt->type = OUTPUT_MPLANE;
- codec_align = f->fmt.pix_mp.pixelformat ==
- V4L2_PIX_FMT_HEVC ? 32 : 16;
- /* width, height is readonly for client */
- fmt->fmt.pix_mp.width = ALIGN(inst->crop.width, codec_align);
- fmt->fmt.pix_mp.height = ALIGN(inst->crop.height, codec_align);
- fmt->fmt.pix_mp.pixelformat = f->fmt.pix_mp.pixelformat;
- fmt->fmt.pix_mp.num_planes = 1;
- fmt->fmt.pix_mp.plane_fmt[0].bytesperline = 0;
- fmt->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
- buffer_size, inst, MSM_VIDC_BUF_OUTPUT);
- inst->buffers.output.min_count = call_session_op(core,
- min_count, inst, MSM_VIDC_BUF_OUTPUT);
- inst->buffers.output.extra_count = call_session_op(core,
- extra_count, inst, MSM_VIDC_BUF_OUTPUT);
- if (inst->buffers.output.actual_count <
- inst->buffers.output.min_count +
- inst->buffers.output.extra_count) {
- inst->buffers.output.actual_count =
- inst->buffers.output.min_count +
- inst->buffers.output.extra_count;
- }
- inst->buffers.output.size =
- fmt->fmt.pix_mp.plane_fmt[0].sizeimage;
- //rc = msm_vidc_check_session_supported(inst);
- if (rc)
- goto err_invalid_fmt;
- //update_log_ctxt(inst->sid, inst->session_type,
- // mplane->pixelformat);
- s_vpr_h(inst->sid,
- "%s: output: format %#x width %d height %d size %d min_count %d extra_count %d\n",
- __func__, fmt->fmt.pix_mp.pixelformat, fmt->fmt.pix_mp.width,
- fmt->fmt.pix_mp.height,
- fmt->fmt.pix_mp.plane_fmt[0].sizeimage,
- inst->buffers.output.min_count,
- inst->buffers.output.extra_count);
- } else if (f->type == OUTPUT_META_PLANE) {
- fmt = &inst->fmts[OUTPUT_META_PORT];
- fmt->type = OUTPUT_META_PLANE;
- fmt->fmt.meta.dataformat = V4L2_META_FMT_VIDC;
- if (is_output_meta_enabled(inst)) {
- fmt->fmt.meta.buffersize = call_session_op(core,
- buffer_size, inst, MSM_VIDC_BUF_OUTPUT_META);
- inst->buffers.output_meta.min_count =
- inst->buffers.output.min_count;
- inst->buffers.output_meta.extra_count =
- inst->buffers.output.extra_count;
- inst->buffers.output_meta.actual_count =
- inst->buffers.output.actual_count;
- inst->buffers.output_meta.size = fmt->fmt.meta.buffersize;
- } else {
- fmt->fmt.meta.buffersize = 0;
- inst->buffers.output_meta.min_count = 0;
- inst->buffers.output_meta.extra_count = 0;
- inst->buffers.output_meta.actual_count = 0;
- inst->buffers.output_meta.size = 0;
- }
- s_vpr_h(inst->sid,
- "%s: output meta: size %d min_count %d extra_count %d\n",
- __func__, fmt->fmt.meta.buffersize,
- inst->buffers.output_meta.min_count,
- inst->buffers.output_meta.extra_count);
- } else {
- s_vpr_e(inst->sid, "%s: invalid type %d\n", __func__, f->type);
- goto err_invalid_fmt;
- }
- memcpy(f, fmt, sizeof(struct v4l2_format));
- err_invalid_fmt:
- return rc;
- }
- int msm_venc_g_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f)
- {
- int rc = 0;
- int port;
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- port = v4l2_type_to_driver_port(inst, f->type, __func__);
- if (port < 0)
- return -EINVAL;
- memcpy(f, &inst->fmts[port], sizeof(struct v4l2_format));
- return rc;
- }
- int msm_venc_s_selection(struct msm_vidc_inst* inst, struct v4l2_selection* s)
- {
- int rc = 0;
- u32 codec_align;
- if (!inst || !s) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (s->type != INPUT_MPLANE && s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
- s_vpr_e(inst->sid, "%s: invalid type %d\n", __func__, s->type);
- return -EINVAL;
- }
- switch (s->target) {
- case V4L2_SEL_TGT_CROP_BOUNDS:
- case V4L2_SEL_TGT_CROP_DEFAULT:
- case V4L2_SEL_TGT_CROP:
- codec_align = inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat ==
- V4L2_PIX_FMT_HEVC ? 32 : 16;
- if (s->r.left || s->r.top) {
- s_vpr_h(inst->sid, "%s: unsupported top %d or left %d\n",
- __func__, s->r.left, s->r.top);
- s->r.left = s->r.top = 0;
- }
- if (s->r.width > inst->fmts[OUTPUT_PORT].fmt.pix_mp.width ||
- ALIGN(s->r.width, codec_align) != inst->fmts[OUTPUT_PORT].fmt.pix_mp.width) {
- s_vpr_h(inst->sid, "%s: unsupported width %d, fmt width %d\n",
- __func__, s->r.width,
- inst->fmts[OUTPUT_PORT].fmt.pix_mp.width);
- s->r.width = inst->fmts[OUTPUT_PORT].fmt.pix_mp.width;
- }
- if (s->r.height > inst->fmts[OUTPUT_PORT].fmt.pix_mp.height ||
- ALIGN(s->r.height, codec_align) != inst->fmts[OUTPUT_PORT].fmt.pix_mp.height) {
- s_vpr_h(inst->sid, "%s: unsupported height %d, fmt height %d\n",
- __func__, s->r.height,
- inst->fmts[OUTPUT_PORT].fmt.pix_mp.height);
- s->r.height = inst->fmts[OUTPUT_PORT].fmt.pix_mp.height;
- }
- inst->crop.left = s->r.left;
- inst->crop.top = s->r.top;
- inst->crop.width = s->r.width;
- inst->crop.height = s->r.height;
- /* adjust compose such that it is within crop */
- if (inst->compose.left < inst->crop.left)
- inst->compose.left = inst->crop.left;
- if (inst->compose.top < inst->crop.top)
- inst->compose.top = inst->crop.top;
- if (inst->compose.width > inst->crop.width)
- inst->compose.width = inst->crop.width;
- if (inst->compose.height > inst->crop.height)
- inst->compose.height = inst->crop.height;
- break;
- case V4L2_SEL_TGT_COMPOSE_BOUNDS:
- case V4L2_SEL_TGT_COMPOSE_PADDED:
- case V4L2_SEL_TGT_COMPOSE_DEFAULT:
- case V4L2_SEL_TGT_COMPOSE:
- if (s->r.left < inst->crop.left) {
- s_vpr_e(inst->sid,
- "%s: compose left (%d) less than crop left (%d)\n",
- __func__, s->r.left, inst->crop.left);
- s->r.left = inst->crop.left;
- }
- if (s->r.top < inst->crop.top) {
- s_vpr_e(inst->sid,
- "%s: compose top (%d) less than crop top (%d)\n",
- __func__, s->r.top, inst->crop.top);
- s->r.top = inst->crop.top;
- }
- if (s->r.width > inst->crop.width) {
- s_vpr_e(inst->sid,
- "%s: compose width (%d) greate than crop width (%d)\n",
- __func__, s->r.width, inst->crop.width);
- s->r.width = inst->crop.width;
- }
- if (s->r.height > inst->crop.height) {
- s_vpr_e(inst->sid,
- "%s: compose height (%d) greate than crop height (%d)\n",
- __func__, s->r.height, inst->crop.height);
- s->r.height = inst->crop.height;
- }
- inst->compose.left = s->r.left;
- inst->compose.top = s->r.top;
- inst->compose.width = s->r.width;
- inst->compose.height= s->r.height;
- break;
- default:
- s_vpr_e(inst->sid, "%s: invalid target %d\n",
- __func__, s->target);
- rc = -EINVAL;
- break;
- }
- if (!rc)
- s_vpr_h(inst->sid, "%s: target %d, r [%d, %d, %d, %d]\n",
- __func__, s->target, s->r.top, s->r.left,
- s->r.width, s->r.height);
- return rc;
- }
- int msm_venc_g_selection(struct msm_vidc_inst* inst, struct v4l2_selection* s)
- {
- int rc = 0;
- if (!inst || !s) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (s->type != INPUT_MPLANE && s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
- s_vpr_e(inst->sid, "%s: invalid type %d\n", __func__, s->type);
- return -EINVAL;
- }
- switch (s->target) {
- case V4L2_SEL_TGT_CROP_BOUNDS:
- case V4L2_SEL_TGT_CROP_DEFAULT:
- case V4L2_SEL_TGT_CROP:
- s->r.left = inst->crop.left;
- s->r.top = inst->crop.top;
- s->r.width = inst->crop.width;
- s->r.height = inst->crop.height;
- break;
- case V4L2_SEL_TGT_COMPOSE_BOUNDS:
- case V4L2_SEL_TGT_COMPOSE_PADDED:
- case V4L2_SEL_TGT_COMPOSE_DEFAULT:
- case V4L2_SEL_TGT_COMPOSE:
- s->r.left = inst->compose.left;
- s->r.top = inst->compose.top;
- s->r.width = inst->compose.width;
- s->r.height = inst->compose.height;
- break;
- default:
- s_vpr_e(inst->sid, "%s: invalid target %d\n",
- __func__, s->target);
- rc = -EINVAL;
- break;
- }
- if (!rc)
- s_vpr_h(inst->sid, "%s: target %d, r [%d, %d, %d, %d]\n",
- __func__, s->target, s->r.top, s->r.left,
- s->r.width, s->r.height);
- return rc;
- }
- int msm_venc_s_param(struct msm_vidc_inst *inst,
- struct v4l2_streamparm *s_parm)
- {
- int rc = 0;
- struct msm_vidc_inst_capability *capability = NULL;
- struct v4l2_fract *timeperframe = NULL;
- u32 q16_rate, max_rate, default_rate;
- u64 us_per_frame = 0, input_rate = 0;
- bool is_frame_rate = false;
- if (!inst || !s_parm) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- capability = inst->capabilities;
- if (s_parm->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
- timeperframe = &s_parm->parm.output.timeperframe;
- max_rate = capability->cap[OPERATING_RATE].max;
- default_rate = capability->cap[OPERATING_RATE].value;
- } else {
- timeperframe = &s_parm->parm.capture.timeperframe;
- is_frame_rate = true;
- max_rate = capability->cap[FRAME_RATE].value;
- default_rate = capability->cap[FRAME_RATE].value;
- }
- if (!timeperframe->denominator || !timeperframe->numerator) {
- s_vpr_e(inst->sid,
- "%s: invalid rate for type %u\n",
- __func__, s_parm->type);
- input_rate = default_rate >> 16;
- goto set_default;
- }
- us_per_frame = timeperframe->numerator * (u64)USEC_PER_SEC;
- do_div(us_per_frame, timeperframe->denominator);
- if (!us_per_frame) {
- s_vpr_e(inst->sid, "%s: us_per_frame is zero\n",
- __func__);
- rc = -EINVAL;
- goto exit;
- }
- input_rate = (u64)USEC_PER_SEC;
- do_div(input_rate, us_per_frame);
- /* Check max allowed rate */
- if (input_rate > max_rate) {
- s_vpr_e(inst->sid,
- "%s: Unsupported rate %u, max_fps %u, type: %u\n",
- __func__, input_rate, max_rate, s_parm->type);
- rc = -ENOTSUPP;
- goto exit;
- }
- set_default:
- q16_rate = (u32)input_rate << 16;
- s_vpr_h(inst->sid, "%s: type %u value %#x\n",
- __func__, s_parm->type, q16_rate);
- if (!is_frame_rate) {
- capability->cap[OPERATING_RATE].value = q16_rate;
- goto exit;
- } else {
- capability->cap[FRAME_RATE].value = q16_rate;
- }
- /*
- * In static case, frame rate is set during via
- * inst database set function mentioned in
- * FRAME_RATE cap id.
- * In dynamic case, frame rate is set like below.
- */
- if (inst->vb2q[OUTPUT_PORT].streaming) {
- rc = venus_hfi_session_property(inst,
- HFI_PROP_FRAME_RATE,
- HFI_HOST_FLAGS_NONE,
- HFI_PORT_BITSTREAM,
- HFI_PAYLOAD_Q16,
- &q16_rate,
- sizeof(u32));
- if (rc) {
- s_vpr_e(inst->sid,
- "%s: failed to set frame rate to fw\n",
- __func__);
- goto exit;
- }
- }
- exit:
- return rc;
- }
- int msm_venc_g_param(struct msm_vidc_inst *inst,
- struct v4l2_streamparm *s_parm)
- {
- struct msm_vidc_inst_capability *capability = NULL;
- struct v4l2_fract *timeperframe = NULL;
- if (!inst || !s_parm) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- capability = inst->capabilities;
- if (s_parm->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
- timeperframe = &s_parm->parm.output.timeperframe;
- timeperframe->numerator = 1;
- timeperframe->denominator =
- capability->cap[OPERATING_RATE].value >> 16;
- } else {
- timeperframe = &s_parm->parm.capture.timeperframe;
- timeperframe->numerator = 1;
- timeperframe->denominator =
- capability->cap[FRAME_RATE].value >> 16;
- }
- s_vpr_h(inst->sid, "%s: type %u, num %u denom %u\n",
- __func__, s_parm->type, timeperframe->numerator,
- timeperframe->denominator);
- return 0;
- }
- int msm_venc_enum_fmt(struct msm_vidc_inst *inst, struct v4l2_fmtdesc *f)
- {
- int rc = 0;
- struct msm_vidc_core *core;
- u32 array[32] = {0};
- u32 i = 0, idx = 0;
- if (!inst || !inst->core || !inst->capabilities || !f) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- if (f->type == OUTPUT_MPLANE) {
- u32 codecs = core->capabilities[DEC_CODECS].value;
- while (codecs) {
- if (idx > 31)
- break;
- if (codecs & BIT(i)) {
- array[idx] = codecs & BIT(i);
- idx++;
- }
- i++;
- codecs >>= 1;
- }
- f->pixelformat = v4l2_codec_from_driver(array[f->index],
- __func__);
- if (!f->pixelformat)
- return -EINVAL;
- f->flags = V4L2_FMT_FLAG_COMPRESSED;
- strlcpy(f->description, "codec", sizeof(f->description));
- } else if (f->type == INPUT_MPLANE) {
- u32 formats = inst->capabilities->cap[PIX_FMTS].step_or_mask;
- while (formats) {
- if (idx > 31)
- break;
- if (formats & BIT(i)) {
- array[idx] = formats & BIT(i);
- idx++;
- }
- i++;
- formats >>= 1;
- }
- f->pixelformat = v4l2_colorformat_from_driver(array[f->index],
- __func__);
- if (!f->pixelformat)
- return -EINVAL;
- strlcpy(f->description, "colorformat", sizeof(f->description));
- } else if (f->type == INPUT_META_PLANE || f->type == OUTPUT_META_PLANE) {
- if (!f->index) {
- f->pixelformat = V4L2_META_FMT_VIDC;
- strlcpy(f->description, "metadata", sizeof(f->description));
- } else {
- return -EINVAL;
- }
- }
- memset(f->reserved, 0, sizeof(f->reserved));
- s_vpr_h(inst->sid, "%s: index %d, %s : %#x, flags %#x\n",
- __func__, f->index, f->description, f->pixelformat, f->flags);
- return rc;
- }
- int msm_venc_inst_init(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- struct msm_vidc_core *core;
- struct v4l2_format *f;
- d_vpr_h("%s()\n", __func__);
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- f = &inst->fmts[OUTPUT_PORT];
- f->type = OUTPUT_MPLANE;
- f->fmt.pix_mp.width = DEFAULT_WIDTH;
- f->fmt.pix_mp.height = DEFAULT_HEIGHT;
- f->fmt.pix_mp.pixelformat = V4L2_PIX_FMT_H264;
- f->fmt.pix_mp.num_planes = 1;
- f->fmt.pix_mp.plane_fmt[0].bytesperline = 0;
- f->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
- buffer_size, inst, MSM_VIDC_BUF_OUTPUT);
- inst->buffers.output.min_count = call_session_op(core,
- min_count, inst, MSM_VIDC_BUF_OUTPUT);
- inst->buffers.output.extra_count = call_session_op(core,
- extra_count, inst, MSM_VIDC_BUF_OUTPUT);
- inst->buffers.output.actual_count =
- inst->buffers.output.min_count +
- inst->buffers.output.extra_count;
- inst->buffers.output.size = f->fmt.pix_mp.plane_fmt[0].sizeimage;
- inst->crop.left = inst->crop.top = 0;
- inst->crop.width = f->fmt.pix_mp.width;
- inst->crop.height = f->fmt.pix_mp.height;
- f = &inst->fmts[OUTPUT_META_PORT];
- f->type = OUTPUT_META_PLANE;
- f->fmt.meta.dataformat = V4L2_META_FMT_VIDC;
- f->fmt.meta.buffersize = call_session_op(core, buffer_size,
- inst, MSM_VIDC_BUF_OUTPUT_META);
- inst->buffers.output_meta.min_count = inst->buffers.output.min_count;
- inst->buffers.output_meta.extra_count = inst->buffers.output.extra_count;
- inst->buffers.output_meta.actual_count = inst->buffers.output.actual_count;
- inst->buffers.output_meta.size = f->fmt.meta.buffersize;
- f = &inst->fmts[INPUT_PORT];
- f->type = INPUT_MPLANE;
- f->fmt.pix_mp.pixelformat = V4L2_PIX_FMT_VIDC_NV12C;
- f->fmt.pix_mp.width = VENUS_Y_STRIDE(
- v4l2_colorformat_to_media(f->fmt.pix_mp.pixelformat, __func__),
- DEFAULT_WIDTH);
- f->fmt.pix_mp.height = VENUS_Y_SCANLINES(
- v4l2_colorformat_to_media(f->fmt.pix_mp.pixelformat, __func__),
- DEFAULT_HEIGHT);
- f->fmt.pix_mp.num_planes = 1;
- f->fmt.pix_mp.plane_fmt[0].bytesperline = f->fmt.pix_mp.width;
- f->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
- buffer_size, inst, MSM_VIDC_BUF_INPUT);
- inst->buffers.input.min_count = call_session_op(core,
- min_count, inst, MSM_VIDC_BUF_INPUT);
- inst->buffers.input.extra_count = call_session_op(core,
- extra_count, inst, MSM_VIDC_BUF_INPUT);
- inst->buffers.input.actual_count =
- inst->buffers.input.min_count +
- inst->buffers.input.extra_count;
- inst->buffers.input.size = f->fmt.pix_mp.plane_fmt[0].sizeimage;
- f = &inst->fmts[INPUT_META_PORT];
- f->type = INPUT_META_PLANE;
- f->fmt.meta.dataformat = V4L2_META_FMT_VIDC;
- f->fmt.meta.buffersize = call_session_op(core, buffer_size,
- inst, MSM_VIDC_BUF_INPUT_META);
- inst->buffers.input_meta.min_count = inst->buffers.input.min_count;
- inst->buffers.input_meta.extra_count = inst->buffers.input.extra_count;
- inst->buffers.input_meta.actual_count = inst->buffers.input.actual_count;
- inst->buffers.input_meta.size = f->fmt.meta.buffersize;
- rc = msm_venc_codec_change(inst,
- inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat);
- return rc;
- }
- int msm_venc_inst_deinit(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- rc = msm_vidc_ctrl_deinit(inst);
- return rc;
- }
|