1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566 |
- /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 and
- * only version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- */
- #include <media/v4l2-subdev.h>
- #include <mach/iommu_domains.h>
- #include "enc-subdev.h"
- #include "wfd-util.h"
- #include <media/msm/vcd_api.h>
- #include <media/msm/vidc_init.h>
- #include <media/msm/vcd_property.h>
- #include <linux/time.h>
- #include <linux/ktime.h>
- #include <linux/slab.h>
- #define VID_ENC_MAX_ENCODER_CLIENTS 1
- #define MAX_NUM_CTRLS 20
- #define V4L2_FRAME_FLAGS (V4L2_BUF_FLAG_KEYFRAME | V4L2_BUF_FLAG_PFRAME | \
- V4L2_BUF_FLAG_BFRAME | V4L2_QCOM_BUF_FLAG_CODECCONFIG)
- static long venc_fill_outbuf(struct v4l2_subdev *sd, void *arg);
- struct venc_inst {
- struct video_client_ctx venc_client;
- void *cbdata;
- void (*op_buffer_done)(void *cookie, u32 status,
- struct vb2_buffer *buf);
- void (*ip_buffer_done)(void *cookie, u32 status,
- struct mem_region *mregion);
- u32 width;
- u32 height;
- int secure;
- struct mem_region unqueued_op_bufs;
- bool streaming;
- enum venc_framerate_modes framerate_mode;
- };
- struct venc {
- s32 device_handle;
- void *virt_base;
- struct venc_inst venc_clients[VID_ENC_MAX_ENCODER_CLIENTS];
- struct mutex lock;
- struct ion_client *iclient;
- };
- static struct venc venc_p;
- static void *venc_map_dev_base_addr(void *device_name)
- {
- return venc_p.virt_base;
- }
- static void venc_interrupt_deregister(void)
- {
- }
- static void venc_interrupt_register(void *device_name)
- {
- }
- static void venc_interrupt_clear(void)
- {
- }
- int venc_load_fw(struct v4l2_subdev *sd)
- {
- return !vidc_load_firmware();
- }
- static u32 venc_get_empty_client_index(void)
- {
- u32 i;
- u32 found = false;
- for (i = 0; i < VID_ENC_MAX_ENCODER_CLIENTS; i++) {
- if (!venc_p.venc_clients[i].venc_client.vcd_handle) {
- found = true;
- break;
- }
- }
- if (!found) {
- WFD_MSG_ERR("%s():ERROR No space for new client\n",
- __func__);
- return -ENOMEM;
- }
- WFD_MSG_INFO("%s(): available client index = %u\n",
- __func__, i);
- return i;
- }
- int venc_init(struct v4l2_subdev *sd, u32 val)
- {
- struct vcd_init_config vcd_init_config;
- mutex_init(&venc_p.lock);
- venc_p.virt_base = vidc_get_ioaddr();
- vcd_init_config.device_name = "VIDC";
- vcd_init_config.map_dev_base_addr = venc_map_dev_base_addr;
- vcd_init_config.interrupt_clr = venc_interrupt_clear;
- vcd_init_config.register_isr = venc_interrupt_register;
- vcd_init_config.deregister_isr = venc_interrupt_deregister;
- vcd_init(&vcd_init_config, &venc_p.device_handle);
- return 0;
- }
- static void venc_notify_client(struct video_client_ctx *client_ctx)
- {
- if (client_ctx)
- complete(&client_ctx->event);
- }
- static void venc_open_done(struct video_client_ctx *client_ctx,
- struct vcd_handle_container *handle_container)
- {
- if (client_ctx) {
- if (handle_container)
- client_ctx->vcd_handle = handle_container->handle;
- else
- WFD_MSG_ERR("handle_container is NULL\n");
- venc_notify_client(client_ctx);
- } else
- WFD_MSG_ERR("ERROR. client_ctx is NULL");
- }
- static void venc_start_done(struct video_client_ctx *client_ctx, u32 status)
- {
- if (client_ctx)
- venc_notify_client(client_ctx);
- else
- WFD_MSG_ERR("ERROR. client_ctx is NULL");
- }
- static void venc_stop_done(struct video_client_ctx *client_ctx, u32 status)
- {
- WFD_MSG_DBG("Inside venc_stop_done: E\n");
- if (client_ctx)
- venc_notify_client(client_ctx);
- else
- WFD_MSG_ERR("ERROR. client_ctx is NULL");
- WFD_MSG_DBG("Inside venc_stop_done: X\n");
- }
- static void venc_cb(u32 event, u32 status, void *info, u32 size, void *handle,
- void *const client_data)
- {
- struct venc_inst *inst = client_data;
- struct video_client_ctx *client_ctx = &inst->venc_client;
- struct vb2_buffer *vbuf;
- struct mem_region *mregion;
- struct vcd_frame_data *frame_data = (struct vcd_frame_data *)info;
- if (!client_ctx) {
- WFD_MSG_ERR("Client context is NULL\n");
- return;
- }
- client_ctx->event_status = status;
- switch (event) {
- case VCD_EVT_RESP_OPEN:
- WFD_MSG_DBG("EVENT: open done = %d\n", event);
- venc_open_done(client_ctx,
- (struct vcd_handle_container *)info);
- break;
- case VCD_EVT_RESP_INPUT_DONE:
- case VCD_EVT_RESP_INPUT_FLUSHED:
- WFD_MSG_DBG("EVENT: input done = %d\n", event);
- mregion = (struct mem_region *)
- frame_data->frm_clnt_data;
- inst->ip_buffer_done(inst->cbdata, status, mregion);
- break;
- case VCD_EVT_RESP_OUTPUT_DONE:
- case VCD_EVT_RESP_OUTPUT_FLUSHED:
- WFD_MSG_DBG("EVENT: output done = %d\n", event);
- vbuf = (struct vb2_buffer *)
- frame_data->frm_clnt_data;
- vbuf->v4l2_planes[0].bytesused =
- frame_data->data_len;
- vbuf->v4l2_buf.flags &= ~(V4L2_FRAME_FLAGS);
- switch (frame_data->frame) {
- case VCD_FRAME_I:
- case VCD_FRAME_IDR:
- vbuf->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME;
- break;
- case VCD_FRAME_P:
- vbuf->v4l2_buf.flags |= V4L2_BUF_FLAG_PFRAME;
- break;
- case VCD_FRAME_B:
- vbuf->v4l2_buf.flags |= V4L2_BUF_FLAG_BFRAME;
- break;
- default:
- break;
- }
- if (frame_data->flags & VCD_FRAME_FLAG_CODECCONFIG)
- vbuf->v4l2_buf.flags |= V4L2_QCOM_BUF_FLAG_CODECCONFIG;
- vbuf->v4l2_buf.timestamp =
- ns_to_timeval(frame_data->time_stamp * NSEC_PER_USEC);
- WFD_MSG_DBG("bytes used %d, ts: %d.%d, frame type is %d\n",
- frame_data->data_len,
- (int)vbuf->v4l2_buf.timestamp.tv_sec,
- (int)vbuf->v4l2_buf.timestamp.tv_usec,
- frame_data->frame);
- /*
- * Output buffers are enc-subdev and vcd's problem, so
- * if buffer is cached, need to flush before giving to
- * client. So doing the dirty stuff in this little context
- */
- {
- unsigned long kvaddr, phys_addr;
- s32 buffer_index = -1, ion_flags = 0;
- struct ion_handle *ion_handle;
- int pmem_fd;
- struct file *filp;
- bool rc;
- rc = vidc_lookup_addr_table(client_ctx,
- BUFFER_TYPE_OUTPUT, true,
- (unsigned long *)&frame_data->
- frm_clnt_data, &kvaddr, &phys_addr,
- &pmem_fd, &filp, &buffer_index);
- if (rc)
- ion_flags = vidc_get_fd_info(client_ctx,
- BUFFER_TYPE_OUTPUT, pmem_fd,
- kvaddr, buffer_index, &ion_handle);
- else
- WFD_MSG_ERR("Got an output buffer that we " \
- "couldn't recognize!\n");
- if (msm_ion_do_cache_op(client_ctx->user_ion_client,
- ion_handle, &kvaddr, frame_data->data_len,
- ION_IOC_CLEAN_INV_CACHES))
- WFD_MSG_ERR("OP buffer flush failed\n");
- }
- inst->op_buffer_done(inst->cbdata, status, vbuf);
- break;
- case VCD_EVT_RESP_START:
- WFD_MSG_DBG("EVENT: start done = %d\n", event);
- venc_start_done(client_ctx, status);
- /*TODO: should wait for this event*/
- break;
- case VCD_EVT_RESP_STOP:
- WFD_MSG_DBG("EVENT: not expected = %d\n", event);
- venc_stop_done(client_ctx, status);
- break;
- case VCD_EVT_RESP_FLUSH_INPUT_DONE:
- case VCD_EVT_RESP_FLUSH_OUTPUT_DONE:
- venc_notify_client(client_ctx);
- break;
- case VCD_EVT_RESP_PAUSE:
- case VCD_EVT_IND_OUTPUT_RECONFIG:
- WFD_MSG_DBG("EVENT: not expected = %d\n", event);
- break;
- case VCD_EVT_IND_HWERRFATAL:
- case VCD_EVT_IND_RESOURCES_LOST:
- WFD_MSG_DBG("EVENT: error = %d\n", event);
- break;
- default:
- WFD_MSG_ERR("Invalid event type = %u\n", event);
- break;
- }
- }
- static long venc_open(struct v4l2_subdev *sd, void *arg)
- {
- u32 client_index;
- int rc = 0;
- struct venc_inst *inst;
- struct video_client_ctx *client_ctx;
- struct venc_msg_ops *vmops = arg;
- int flags = 0;
- mutex_lock(&venc_p.lock);
- client_index = venc_get_empty_client_index();
- if (client_index < 0) {
- WFD_MSG_ERR("No free clients, client_index = %d\n",
- client_index);
- rc = -ENODEV;
- goto no_free_client;
- }
- inst = &venc_p.venc_clients[client_index];
- client_ctx = &inst->venc_client;
- init_completion(&client_ctx->event);
- mutex_init(&client_ctx->msg_queue_lock);
- mutex_init(&client_ctx->enrty_queue_lock);
- INIT_LIST_HEAD(&client_ctx->msg_queue);
- init_waitqueue_head(&client_ctx->msg_wait);
- inst->op_buffer_done = vmops->op_buffer_done;
- inst->ip_buffer_done = vmops->ip_buffer_done;
- INIT_LIST_HEAD(&inst->unqueued_op_bufs.list);
- inst->cbdata = vmops->cbdata;
- inst->secure = vmops->secure;
- inst->streaming = false;
- inst->framerate_mode = VENC_MODE_VFR;
- if (vmops->secure) {
- WFD_MSG_ERR("OPENING SECURE SESSION\n");
- flags |= VCD_CP_SESSION;
- }
- if (vcd_get_ion_status()) {
- client_ctx->user_ion_client = vcd_get_ion_client();
- if (!client_ctx->user_ion_client) {
- WFD_MSG_ERR("vcd_open ion get client failed");
- return -EFAULT;
- }
- }
- rc = vcd_open(venc_p.device_handle, false, venc_cb,
- inst, flags);
- if (rc) {
- WFD_MSG_ERR("vcd_open failed, rc = %d\n", rc);
- rc = -ENODEV;
- goto no_free_client;
- }
- wait_for_completion(&client_ctx->event);
- if (client_ctx->event_status) {
- WFD_MSG_ERR("callback for vcd_open returned error: %u",
- client_ctx->event_status);
- goto no_free_client;
- }
- WFD_MSG_ERR("NOTE: client_ctx = %p\n", client_ctx);
- vmops->cookie = inst;
- sd->dev_priv = inst;
- no_free_client:
- mutex_unlock(&venc_p.lock);
- return rc;
- }
- static long venc_close(struct v4l2_subdev *sd, void *arg)
- {
- long rc = 0;
- struct venc_inst *inst;
- struct video_client_ctx *client_ctx = NULL;
- mutex_lock(&venc_p.lock);
- inst = sd->dev_priv;
- client_ctx = &inst->venc_client;
- if (!client_ctx || !client_ctx->vcd_handle) {
- WFD_MSG_ERR("Invalid client context in close\n");
- rc = -ENODEV;
- goto end;
- }
- rc = vcd_close(client_ctx->vcd_handle);
- if (rc) {
- WFD_MSG_ERR("Failed to close encoder subdevice\n");
- goto end;
- }
- memset((void *)client_ctx, 0,
- sizeof(struct video_client_ctx));
- end:
- mutex_unlock(&venc_p.lock);
- return rc;
- }
- static long venc_get_buffer_req(struct v4l2_subdev *sd, void *arg)
- {
- int rc = 0;
- struct v4l2_requestbuffers *b = arg;
- struct vcd_buffer_requirement buf_req;
- struct venc_inst *inst = sd->dev_priv;
- struct video_client_ctx *client_ctx = &inst->venc_client;
- if (!client_ctx) {
- WFD_MSG_ERR("Invalid client context");
- rc = -EINVAL;
- goto err;
- }
- rc = vcd_get_buffer_requirements(client_ctx->vcd_handle,
- VCD_BUFFER_OUTPUT, &buf_req);
- if (rc) {
- WFD_MSG_ERR("Failed to get out buf reqs rc = %d", rc);
- goto err;
- }
- buf_req.actual_count = b->count = max(buf_req.min_count, b->count);
- rc = vcd_set_buffer_requirements(client_ctx->vcd_handle,
- VCD_BUFFER_OUTPUT, &buf_req);
- if (rc) {
- WFD_MSG_ERR("Failed to set out buf reqs rc = %d", rc);
- goto err;
- }
- err:
- return rc;
- }
- static long venc_set_buffer_req(struct v4l2_subdev *sd, void *arg)
- {
- int rc = 0;
- struct bufreq *b = arg;
- struct vcd_buffer_requirement buf_req;
- struct venc_inst *inst = sd->dev_priv;
- struct video_client_ctx *client_ctx = &inst->venc_client;
- int aligned_width, aligned_height;
- if (!client_ctx) {
- WFD_MSG_ERR("Invalid client context");
- rc = -EINVAL;
- goto err;
- }
- aligned_width = ALIGN(b->width, 16);
- aligned_height = ALIGN(b->height, 16);
- if (aligned_width != b->width) {
- WFD_MSG_ERR("Width not 16 byte aligned\n");
- rc = -EINVAL;
- goto err;
- }
- buf_req.actual_count = b->count;
- buf_req.min_count = b->count;
- buf_req.max_count = b->count;
- buf_req.sz = ALIGN(aligned_height * aligned_width, SZ_2K)
- + ALIGN(aligned_height * aligned_width * 1/2, SZ_2K);
- buf_req.align = SZ_4K;
- inst->width = b->width;
- inst->height = b->height;
- rc = vcd_set_buffer_requirements(client_ctx->vcd_handle,
- VCD_BUFFER_INPUT, &buf_req);
- if (rc) {
- WFD_MSG_ERR("Failed to get out buf reqs rc = %d", rc);
- goto err;
- }
- b->size = buf_req.sz;
- err:
- return rc;
- }
- static long venc_start(struct v4l2_subdev *sd)
- {
- struct venc_inst *inst = sd->dev_priv;
- struct video_client_ctx *client_ctx = &inst->venc_client;
- struct mem_region *curr = NULL, *temp = NULL;
- int rc;
- if (!client_ctx) {
- WFD_MSG_ERR("Client context is NULL");
- return -EINVAL;
- }
- rc = vcd_encode_start(client_ctx->vcd_handle);
- if (rc) {
- WFD_MSG_ERR("vcd_encode_start failed, rc = %d\n", rc);
- goto err;
- }
- wait_for_completion(&client_ctx->event);
- if (client_ctx->event_status)
- WFD_MSG_ERR("callback for vcd_encode_start returned error: %u",
- client_ctx->event_status);
- inst->streaming = true;
- /* Push any buffers that we have held back */
- list_for_each_entry_safe(curr, temp,
- &inst->unqueued_op_bufs.list, list) {
- venc_fill_outbuf(sd, curr);
- list_del(&curr->list);
- kfree(curr);
- }
- err:
- return rc;
- }
- static long venc_stop(struct v4l2_subdev *sd)
- {
- struct venc_inst *inst = sd->dev_priv;
- struct video_client_ctx *client_ctx = &inst->venc_client;
- struct mem_region *curr = NULL, *temp = NULL;
- int rc;
- if (!client_ctx) {
- WFD_MSG_ERR("Client context is NULL");
- return -EINVAL;
- }
- rc = vcd_stop(client_ctx->vcd_handle);
- wait_for_completion(&client_ctx->event);
- inst->streaming = false;
- /* Drop whatever frames we haven't queued */
- list_for_each_entry_safe(curr, temp,
- &inst->unqueued_op_bufs.list, list) {
- inst->op_buffer_done(inst->cbdata, 0,
- (struct vb2_buffer *)curr->cookie);
- list_del(&curr->list);
- kfree(curr);
- }
- return rc;
- }
- static long venc_set_codec(struct video_client_ctx *client_ctx, __s32 codec)
- {
- struct vcd_property_codec vcd_property_codec;
- struct vcd_property_hdr vcd_property_hdr;
- vcd_property_hdr.prop_id = VCD_I_CODEC;
- vcd_property_hdr.sz = sizeof(struct vcd_property_codec);
- vcd_property_codec.codec = VCD_CODEC_H264;
- switch (codec) {
- case V4L2_PIX_FMT_H264:
- vcd_property_codec.codec = VCD_CODEC_H264;
- break;
- case V4L2_PIX_FMT_MPEG4:
- vcd_property_codec.codec = VCD_CODEC_MPEG4;
- break;
- default:
- WFD_MSG_ERR("Codec not supported, defaulting to h264\n");
- break;
- }
- return vcd_set_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vcd_property_codec);
- }
- static long venc_set_codec_level(struct video_client_ctx *client_ctx,
- __s32 codec, __s32 level)
- {
- struct vcd_property_level vcd_property_level;
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_codec vcd_property_codec;
- int rc = 0;
- int mpeg4_base = VCD_LEVEL_MPEG4_0;
- int h264_base = VCD_LEVEL_H264_1;
- /* Validate params */
- vcd_property_hdr.prop_id = VCD_I_CODEC;
- vcd_property_hdr.sz = sizeof(struct vcd_property_codec);
- rc = vcd_get_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vcd_property_codec);
- if (rc < 0) {
- WFD_MSG_ERR("Error getting codec property");
- rc = -EINVAL;
- goto err;
- }
- if (!((vcd_property_codec.codec == VCD_CODEC_H264
- && codec == V4L2_CID_MPEG_VIDEO_H264_LEVEL) ||
- (vcd_property_codec.codec == VCD_CODEC_MPEG4
- && codec == V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL))) {
- WFD_MSG_ERR("Attempting to set %d for codec type %d",
- codec, vcd_property_codec.codec);
- rc = -EINVAL;
- goto err;
- }
- /* Set property */
- vcd_property_hdr.prop_id = VCD_I_LEVEL;
- vcd_property_hdr.sz = sizeof(struct vcd_property_level);
- if (codec == V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL) {
- vcd_property_level.level = mpeg4_base + level;
- if (vcd_property_level.level < VCD_LEVEL_MPEG4_0
- || vcd_property_level.level > VCD_LEVEL_MPEG4_X) {
- WFD_MSG_ERR("Level (%d) out of range for codec (%d)\n",
- level, codec);
- rc = -EINVAL;
- goto err;
- }
- } else if (codec == V4L2_CID_MPEG_VIDEO_H264_LEVEL) {
- vcd_property_level.level = h264_base + level;
- if (vcd_property_level.level < VCD_LEVEL_H264_1
- || vcd_property_level.level > VCD_LEVEL_H264_5p1) {
- WFD_MSG_ERR("Level (%d) out of range for codec (%d)\n",
- level, codec);
- rc = -EINVAL;
- goto err;
- }
- } else {
- WFD_MSG_ERR("Codec (%d) not supported, not setting level (%d)",
- codec, level);
- rc = -ENOTSUPP;
- goto err;
- }
- rc = vcd_set_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vcd_property_level);
- err:
- return rc;
- }
- static long venc_get_codec_level(struct video_client_ctx *client_ctx,
- __s32 codec, __s32 *level)
- {
- struct vcd_property_level vcd_property_level;
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_codec vcd_property_codec;
- int rc = 0;
- int mpeg4_base = VCD_LEVEL_MPEG4_0;
- int h264_base = VCD_LEVEL_H264_1;
- /* Validate params */
- vcd_property_hdr.prop_id = VCD_I_CODEC;
- vcd_property_hdr.sz = sizeof(struct vcd_property_codec);
- rc = vcd_get_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vcd_property_codec);
- if (rc < 0) {
- WFD_MSG_ERR("Error getting codec property");
- rc = -EINVAL;
- goto err;
- }
- if (!((vcd_property_codec.codec == VCD_CODEC_H264
- && codec == V4L2_CID_MPEG_VIDEO_H264_LEVEL) ||
- (vcd_property_codec.codec == VCD_CODEC_MPEG4
- && codec == V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL))) {
- WFD_MSG_ERR("Attempting to get %d for codec type %d",
- codec, vcd_property_codec.codec);
- rc = -EINVAL;
- goto err;
- }
- vcd_property_hdr.prop_id = VCD_I_LEVEL;
- vcd_property_hdr.sz = sizeof(struct vcd_property_level);
- rc = vcd_get_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vcd_property_level);
- if (rc < 0) {
- rc = -EINVAL;
- goto err;
- }
- if (codec == V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL) {
- *level = vcd_property_level.level - mpeg4_base;
- } else if (codec == V4L2_CID_MPEG_VIDEO_H264_LEVEL) {
- *level = vcd_property_level.level - h264_base;
- } else {
- WFD_MSG_ERR("Codec (%d) not supported", codec);
- rc = -ENOTSUPP;
- goto err;
- }
- err:
- return rc;
- }
- static long venc_set_codec_profile(struct video_client_ctx *client_ctx,
- __s32 codec, __s32 profile)
- {
- struct vcd_property_profile vcd_property_profile;
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_codec vcd_property_codec;
- struct vcd_property_i_period vcd_property_i_period;
- int rc = 0;
- /* Validate params */
- vcd_property_hdr.prop_id = VCD_I_CODEC;
- vcd_property_hdr.sz = sizeof(struct vcd_property_codec);
- rc = vcd_get_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vcd_property_codec);
- if (rc < 0) {
- WFD_MSG_ERR("Error getting codec property");
- rc = -EINVAL;
- goto err_set_profile;
- }
- if (!((vcd_property_codec.codec == VCD_CODEC_H264
- && codec == V4L2_CID_MPEG_VIDEO_H264_PROFILE) ||
- (vcd_property_codec.codec == VCD_CODEC_MPEG4
- && codec == V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE))) {
- WFD_MSG_ERR("Attempting to set %d for codec type %d",
- codec, vcd_property_codec.codec);
- rc = -EINVAL;
- goto err_set_profile;
- }
- /* Set property */
- vcd_property_hdr.prop_id = VCD_I_PROFILE;
- vcd_property_hdr.sz = sizeof(struct vcd_property_profile);
- if (codec == V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE) {
- switch (profile) {
- case V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE:
- vcd_property_profile.profile = VCD_PROFILE_MPEG4_SP;
- break;
- case V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE:
- vcd_property_profile.profile = VCD_PROFILE_MPEG4_ASP;
- break;
- default:
- WFD_MSG_ERR("Profile %d not supported, defaulting " \
- "to simple (%d)", profile,
- VCD_PROFILE_MPEG4_SP);
- vcd_property_profile.profile = VCD_PROFILE_MPEG4_SP;
- break;
- }
- } else if (codec == V4L2_CID_MPEG_VIDEO_H264_PROFILE) {
- switch (profile) {
- case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
- vcd_property_profile.profile =
- VCD_PROFILE_H264_BASELINE;
- break;
- case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
- vcd_property_profile.profile = VCD_PROFILE_H264_MAIN;
- break;
- case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
- vcd_property_profile.profile = VCD_PROFILE_H264_HIGH;
- break;
- default:
- WFD_MSG_ERR("Profile %d not supported, defaulting " \
- "to baseline (%d)", profile,
- VCD_PROFILE_H264_BASELINE);
- vcd_property_profile.profile =
- VCD_PROFILE_H264_BASELINE;
- break;
- }
- } else {
- WFD_MSG_ERR("Codec (%d) not supported, not "\
- "setting profile (%d)", codec, profile);
- rc = -ENOTSUPP;
- goto err_set_profile;
- }
- rc = vcd_set_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vcd_property_profile);
- /* Disable B-frames, since VSG doesn't support out of order i/p bufs */
- vcd_property_hdr.prop_id = VCD_I_INTRA_PERIOD;
- vcd_property_hdr.sz = sizeof(struct vcd_property_i_period);
- rc = vcd_get_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vcd_property_i_period);
- if (rc) {
- WFD_MSG_ERR("Error getting I-period property");
- goto err_set_profile;
- }
- vcd_property_i_period.b_frames = 0;
- rc = vcd_set_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vcd_property_i_period);
- if (rc) {
- WFD_MSG_ERR("Error setting I-period property");
- goto err_set_profile;
- }
- err_set_profile:
- return rc;
- }
- static long venc_get_codec_profile(struct video_client_ctx *client_ctx,
- __s32 codec, __s32 *profile)
- {
- struct vcd_property_profile vcd_property_profile;
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_codec vcd_property_codec;
- int rc = 0;
- /* Validate params */
- vcd_property_hdr.prop_id = VCD_I_CODEC;
- vcd_property_hdr.sz = sizeof(struct vcd_property_codec);
- rc = vcd_get_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vcd_property_codec);
- if (rc < 0) {
- WFD_MSG_ERR("Error getting codec property");
- rc = -EINVAL;
- goto err;
- }
- if (!((vcd_property_codec.codec == VCD_CODEC_H264
- && codec == V4L2_CID_MPEG_VIDEO_H264_PROFILE) ||
- (vcd_property_codec.codec == VCD_CODEC_MPEG4
- && codec == V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE))) {
- WFD_MSG_ERR("Attempting to set %d for codec type %d",
- codec, vcd_property_codec.codec);
- rc = -EINVAL;
- goto err;
- }
- /* Set property */
- vcd_property_hdr.prop_id = VCD_I_PROFILE;
- vcd_property_hdr.sz = sizeof(struct vcd_property_profile);
- rc = vcd_get_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vcd_property_profile);
- if (rc < 0) {
- WFD_MSG_ERR("Unable to get property");
- rc = -EINVAL;
- goto err;
- }
- switch (vcd_property_profile.profile) {
- case VCD_PROFILE_MPEG4_SP:
- *profile = V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE;
- break;
- case VCD_PROFILE_MPEG4_ASP:
- *profile = V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE;
- break;
- case VCD_PROFILE_H264_BASELINE:
- *profile = V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE;
- break;
- case VCD_PROFILE_H264_MAIN:
- *profile = V4L2_MPEG_VIDEO_H264_PROFILE_MAIN;
- break;
- case VCD_PROFILE_H264_HIGH:
- *profile = V4L2_MPEG_VIDEO_H264_PROFILE_HIGH;
- break;
- default:
- WFD_MSG_ERR("Unexpected profile");
- rc = -EINVAL;
- goto err;
- break;
- }
- err:
- return rc;
- }
- static long venc_set_h264_intra_period(struct video_client_ctx *client_ctx,
- __s32 period)
- {
- struct vcd_property_i_period vcd_property_i_period;
- struct vcd_property_codec vcd_property_codec;
- struct vcd_property_hdr vcd_property_hdr;
- int rc = 0;
- vcd_property_hdr.prop_id = VCD_I_CODEC;
- vcd_property_hdr.sz = sizeof(struct vcd_property_codec);
- rc = vcd_get_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vcd_property_codec);
- if (rc < 0) {
- WFD_MSG_ERR("Error getting codec property\n");
- goto err;
- }
- if (vcd_property_codec.codec != VCD_CODEC_H264) {
- rc = -ENOTSUPP;
- WFD_MSG_ERR("Control not supported for non H264 codec\n");
- goto err;
- }
- vcd_property_hdr.prop_id = VCD_I_INTRA_PERIOD;
- vcd_property_hdr.sz = sizeof(struct vcd_property_i_period);
- vcd_property_i_period.p_frames = period - 1;
- vcd_property_i_period.b_frames = 0;
- rc = vcd_set_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vcd_property_i_period);
- if (rc < 0) {
- WFD_MSG_ERR("Error setting intra period\n");
- goto err;
- }
- err:
- return rc;
- }
- static long venc_get_h264_intra_period(struct video_client_ctx *client_ctx,
- __s32 *period)
- {
- struct vcd_property_i_period vcd_property_i_period;
- struct vcd_property_codec vcd_property_codec;
- struct vcd_property_hdr vcd_property_hdr;
- int rc = 0;
- vcd_property_hdr.prop_id = VCD_I_CODEC;
- vcd_property_hdr.sz = sizeof(struct vcd_property_codec);
- rc = vcd_get_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vcd_property_codec);
- if (rc < 0) {
- WFD_MSG_ERR("Error getting codec property\n");
- goto err;
- }
- if (vcd_property_codec.codec != VCD_CODEC_H264) {
- rc = -ENOTSUPP;
- WFD_MSG_ERR("Control not supported for non H264 codec\n");
- goto err;
- }
- vcd_property_hdr.prop_id = VCD_I_INTRA_PERIOD;
- vcd_property_hdr.sz = sizeof(struct vcd_property_i_period);
- rc = vcd_get_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vcd_property_i_period);
- if (rc < 0) {
- WFD_MSG_ERR("Error getting intra period\n");
- goto err;
- }
- *period = vcd_property_i_period.p_frames + 1;
- err:
- return rc;
- }
- static long venc_request_frame(struct video_client_ctx *client_ctx, __s32 type)
- {
- struct vcd_property_req_i_frame vcd_property_req_i_frame;
- struct vcd_property_hdr vcd_property_hdr;
- vcd_property_hdr.prop_id = VCD_I_REQ_IFRAME;
- vcd_property_hdr.sz = sizeof(struct vcd_property_req_i_frame);
- vcd_property_req_i_frame.req_i_frame = 1;
- return vcd_set_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vcd_property_req_i_frame);
- }
- static long venc_set_bitrate(struct video_client_ctx *client_ctx,
- __s32 bitrate)
- {
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_target_bitrate bit_rate;
- if (!client_ctx || !bitrate)
- return -EINVAL;
- vcd_property_hdr.prop_id = VCD_I_TARGET_BITRATE;
- vcd_property_hdr.sz =
- sizeof(struct vcd_property_target_bitrate);
- bit_rate.target_bitrate = bitrate;
- return vcd_set_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &bit_rate);
- }
- static long venc_get_bitrate(struct video_client_ctx *client_ctx,
- __s32 *bitrate)
- {
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_target_bitrate bit_rate;
- int rc = 0;
- if (!client_ctx || !bitrate)
- return -EINVAL;
- vcd_property_hdr.prop_id = VCD_I_TARGET_BITRATE;
- vcd_property_hdr.sz =
- sizeof(struct vcd_property_target_bitrate);
- rc = vcd_get_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &bit_rate);
- if (rc < 0) {
- WFD_MSG_ERR("Failed getting property for bitrate");
- return rc;
- }
- *bitrate = bit_rate.target_bitrate;
- return rc;
- }
- static long venc_set_bitrate_mode(struct video_client_ctx *client_ctx,
- __s32 mode)
- {
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_rate_control rate_control;
- int rc = 0;
- if (!client_ctx) {
- rc = -EINVAL;
- goto err;
- }
- vcd_property_hdr.prop_id = VCD_I_RATE_CONTROL;
- vcd_property_hdr.sz = sizeof(struct vcd_property_rate_control);
- /*
- * XXX: V4L doesn't seem have a control to toggle between CFR
- * and VFR, so assuming worse case VFR.
- */
- switch (mode) {
- case V4L2_MPEG_VIDEO_BITRATE_MODE_VBR:
- rate_control.rate_control = VCD_RATE_CONTROL_VBR_VFR;
- break;
- case V4L2_MPEG_VIDEO_BITRATE_MODE_CBR:
- rate_control.rate_control = VCD_RATE_CONTROL_CBR_VFR;
- break;
- default:
- WFD_MSG_ERR("unknown bitrate mode %d", mode);
- rc = -EINVAL;
- goto err;
- }
- rc = vcd_set_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &rate_control);
- err:
- return rc;
- }
- static long venc_get_bitrate_mode(struct video_client_ctx *client_ctx,
- __s32 *mode)
- {
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_rate_control rate_control;
- int rc = 0;
- if (!client_ctx)
- return -EINVAL;
- vcd_property_hdr.prop_id = VCD_I_RATE_CONTROL;
- vcd_property_hdr.sz = sizeof(struct vcd_property_rate_control);
- rc = vcd_get_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &rate_control);
- switch (rate_control.rate_control) {
- case VCD_RATE_CONTROL_CBR_VFR:
- case VCD_RATE_CONTROL_CBR_CFR:
- *mode = V4L2_MPEG_VIDEO_BITRATE_MODE_CBR;
- break;
- case VCD_RATE_CONTROL_VBR_VFR:
- case VCD_RATE_CONTROL_VBR_CFR:
- *mode = V4L2_MPEG_VIDEO_BITRATE_MODE_VBR;
- break;
- default:
- WFD_MSG_ERR("unknown bitrate mode %d",
- rate_control.rate_control);
- return -EINVAL;
- }
- return 0;
- }
- static long venc_set_frame_size(struct video_client_ctx *client_ctx,
- u32 height, u32 width)
- {
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_frame_size frame_size;
- vcd_property_hdr.prop_id = VCD_I_FRAME_SIZE;
- vcd_property_hdr.sz =
- sizeof(struct vcd_property_frame_size);
- frame_size.height = height;
- frame_size.width = width;
- return vcd_set_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &frame_size);
- }
- static long venc_set_format(struct v4l2_subdev *sd, void *arg)
- {
- struct venc_inst *inst;
- struct video_client_ctx *client_ctx;
- struct v4l2_format *fmt = arg;
- struct vcd_buffer_requirement buf_req;
- int rc = 0;
- inst = sd->dev_priv;
- client_ctx = &inst->venc_client;
- if (!inst || !client_ctx || !fmt) {
- WFD_MSG_ERR("Invalid parameters\n");
- return -EINVAL;
- }
- rc = venc_set_codec(client_ctx, fmt->fmt.pix.pixelformat);
- if (rc) {
- WFD_MSG_ERR("Failed to set codec, rc = %d\n", rc);
- goto err;
- }
- rc = venc_set_frame_size(client_ctx, fmt->fmt.pix.height,
- fmt->fmt.pix.width);
- if (rc) {
- WFD_MSG_ERR("Failed to set frame size, rc = %d\n", rc);
- goto err;
- }
- rc = vcd_get_buffer_requirements(client_ctx->vcd_handle,
- VCD_BUFFER_OUTPUT, &buf_req);
- if (rc) {
- WFD_MSG_ERR("Failed to get buf requrements, rc = %d\n", rc);
- goto err;
- }
- fmt->fmt.pix.sizeimage = buf_req.sz;
- err:
- return rc;
- }
- static long venc_set_framerate(struct v4l2_subdev *sd,
- void *arg)
- {
- struct venc_inst *inst = sd->dev_priv;
- struct video_client_ctx *client_ctx = &inst->venc_client;
- struct v4l2_fract *frate = arg;
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_frame_rate vcd_frame_rate;
- struct vcd_property_vop_timing_constant_delta vcd_delta;
- int rc;
- vcd_property_hdr.prop_id = VCD_I_FRAME_RATE;
- vcd_property_hdr.sz =
- sizeof(struct vcd_property_frame_rate);
- /* v4l2 passes in "fps" as "spf", so take reciprocal*/
- vcd_frame_rate.fps_denominator = frate->numerator;
- vcd_frame_rate.fps_numerator = frate->denominator;
- rc = vcd_set_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vcd_frame_rate);
- if (rc) {
- WFD_MSG_ERR("Failed to set frame rate, rc = %d\n", rc);
- goto set_framerate_fail;
- }
- vcd_property_hdr.prop_id = VCD_I_VOP_TIMING_CONSTANT_DELTA;
- vcd_property_hdr.sz = sizeof(vcd_delta);
- vcd_delta.constant_delta = (frate->numerator * USEC_PER_SEC) /
- frate->denominator;
- rc = vcd_set_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vcd_delta);
- if (rc) {
- WFD_MSG_ERR("Failed to set frame delta, rc = %d", rc);
- goto set_framerate_fail;
- }
- set_framerate_fail:
- return rc;
- }
- static long venc_set_framerate_mode(struct v4l2_subdev *sd,
- void *arg)
- {
- struct venc_inst *inst = sd->dev_priv;
- inst->framerate_mode = *(enum venc_framerate_modes *)arg;
- return 0;
- }
- static long venc_set_qp_value(struct video_client_ctx *client_ctx,
- __s32 frametype, __s32 qp)
- {
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_session_qp vcd_property_session_qp;
- int rc = 0;
- if (!client_ctx) {
- WFD_MSG_ERR("Invalid parameters\n");
- return -EINVAL;
- }
- vcd_property_hdr.prop_id = VCD_I_SESSION_QP;
- vcd_property_hdr.sz = sizeof(vcd_property_session_qp);
- rc = vcd_get_property(client_ctx->vcd_handle, &vcd_property_hdr,
- &vcd_property_session_qp);
- if (rc) {
- WFD_MSG_ERR("Failed to get session qp\n");
- goto err;
- }
- switch (frametype) {
- case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP:
- vcd_property_session_qp.i_frame_qp = qp;
- break;
- case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP:
- vcd_property_session_qp.p_frame_qp = qp;
- break;
- case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP:
- vcd_property_session_qp.b_frame_qp = qp;
- break;
- case V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP:
- rc = -ENOTSUPP;
- goto err;
- default:
- rc = -EINVAL;
- goto err;
- }
- rc = vcd_set_property(client_ctx->vcd_handle, &vcd_property_hdr,
- &vcd_property_session_qp);
- if (rc) {
- WFD_MSG_ERR("Failed to set session qp\n");
- goto err;
- }
- err:
- return rc;
- }
- static long venc_get_qp_value(struct video_client_ctx *client_ctx,
- __s32 frametype, __s32 *qp)
- {
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_session_qp vcd_property_session_qp;
- int rc = 0;
- if (!client_ctx) {
- WFD_MSG_ERR("Invalid parameters\n");
- return -EINVAL;
- }
- vcd_property_hdr.prop_id = VCD_I_SESSION_QP;
- vcd_property_hdr.sz = sizeof(vcd_property_session_qp);
- rc = vcd_get_property(client_ctx->vcd_handle, &vcd_property_hdr,
- &vcd_property_session_qp);
- if (rc) {
- WFD_MSG_ERR("Failed to get session qp\n");
- goto err;
- }
- switch (frametype) {
- case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP:
- *qp = vcd_property_session_qp.i_frame_qp;
- break;
- case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP:
- *qp = vcd_property_session_qp.p_frame_qp;
- break;
- case V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP:
- *qp = vcd_property_session_qp.b_frame_qp;
- break;
- default:
- rc = -EINVAL;
- goto err;
- }
- err:
- return rc;
- }
- static long venc_set_qp_range(struct video_client_ctx *client_ctx,
- __s32 type, __s32 qp)
- {
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_qp_range vcd_property_qp_range;
- int rc = 0;
- if (!client_ctx) {
- WFD_MSG_ERR("Invalid parameters\n");
- return -EINVAL;
- }
- vcd_property_hdr.prop_id = VCD_I_QP_RANGE;
- vcd_property_hdr.sz = sizeof(vcd_property_qp_range);
- rc = vcd_get_property(client_ctx->vcd_handle, &vcd_property_hdr,
- &vcd_property_qp_range);
- if (rc) {
- WFD_MSG_ERR("Failed to get qp range\n");
- goto err;
- }
- switch (type) {
- case V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP:
- case V4L2_CID_MPEG_VIDEO_H263_MIN_QP:
- case V4L2_CID_MPEG_VIDEO_H264_MIN_QP:
- vcd_property_qp_range.min_qp = qp;
- break;
- case V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP:
- case V4L2_CID_MPEG_VIDEO_H263_MAX_QP:
- case V4L2_CID_MPEG_VIDEO_H264_MAX_QP:
- vcd_property_qp_range.max_qp = qp;
- break;
- default:
- rc = -EINVAL;
- goto err;
- }
- rc = vcd_set_property(client_ctx->vcd_handle, &vcd_property_hdr,
- &vcd_property_qp_range);
- if (rc) {
- WFD_MSG_ERR("Failed to set qp range\n");
- goto err;
- }
- err:
- return rc;
- }
- static long venc_get_qp_range(struct video_client_ctx *client_ctx,
- __s32 type, __s32 *qp)
- {
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_qp_range vcd_property_qp_range;
- int rc = 0;
- if (!client_ctx) {
- WFD_MSG_ERR("Invalid parameters\n");
- return -EINVAL;
- }
- vcd_property_hdr.prop_id = VCD_I_QP_RANGE;
- vcd_property_hdr.sz = sizeof(vcd_property_qp_range);
- rc = vcd_get_property(client_ctx->vcd_handle, &vcd_property_hdr,
- &vcd_property_qp_range);
- if (rc) {
- WFD_MSG_ERR("Failed to get qp range\n");
- goto err;
- }
- switch (type) {
- case V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP:
- case V4L2_CID_MPEG_VIDEO_H263_MIN_QP:
- case V4L2_CID_MPEG_VIDEO_H264_MIN_QP:
- *qp = vcd_property_qp_range.min_qp;
- break;
- case V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP:
- case V4L2_CID_MPEG_VIDEO_H263_MAX_QP:
- case V4L2_CID_MPEG_VIDEO_H264_MAX_QP:
- *qp = vcd_property_qp_range.max_qp;
- break;
- default:
- rc = -EINVAL;
- goto err;
- }
- rc = vcd_set_property(client_ctx->vcd_handle, &vcd_property_hdr,
- &vcd_property_qp_range);
- if (rc) {
- WFD_MSG_ERR("Failed to set qp range\n");
- goto err;
- }
- err:
- return rc;
- }
- static long venc_set_max_perf_level(struct video_client_ctx *client_ctx,
- __s32 value)
- {
- int rc = 0;
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_perf_level perf;
- int level = 0;
- switch (value) {
- case V4L2_CID_MPEG_VIDC_PERF_LEVEL_PERFORMANCE:
- level = VCD_PERF_LEVEL2;
- break;
- case V4L2_CID_MPEG_VIDC_PERF_LEVEL_TURBO:
- level = VCD_PERF_LEVEL_TURBO;
- break;
- default:
- WFD_MSG_ERR("Unknown performance level: %d\n", value);
- rc = -ENOTSUPP;
- goto err_set_perf_level;
- }
- vcd_property_hdr.prop_id = VCD_REQ_PERF_LEVEL;
- vcd_property_hdr.sz =
- sizeof(struct vcd_property_perf_level);
- perf.level = level;
- rc = vcd_set_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &perf);
- err_set_perf_level:
- return rc;
- }
- static long venc_set_avc_delimiter(struct video_client_ctx *client_ctx,
- __s32 flag)
- {
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_avc_delimiter_enable delimiter_flag;
- if (!client_ctx)
- return -EINVAL;
- vcd_property_hdr.prop_id = VCD_I_ENABLE_DELIMITER_FLAG;
- vcd_property_hdr.sz =
- sizeof(struct vcd_property_avc_delimiter_enable);
- delimiter_flag.avc_delimiter_enable_flag = flag;
- return vcd_set_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &delimiter_flag);
- }
- static long venc_get_avc_delimiter(struct video_client_ctx *client_ctx,
- __s32 *flag)
- {
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_avc_delimiter_enable delimiter_flag;
- int rc = 0;
- if (!client_ctx || !flag)
- return -EINVAL;
- vcd_property_hdr.prop_id = VCD_I_ENABLE_DELIMITER_FLAG;
- vcd_property_hdr.sz =
- sizeof(struct vcd_property_avc_delimiter_enable);
- rc = vcd_get_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &delimiter_flag);
- if (rc < 0) {
- WFD_MSG_ERR("Failed getting property for delimiter");
- return rc;
- }
- *flag = delimiter_flag.avc_delimiter_enable_flag;
- return rc;
- }
- static long venc_set_vui_timing_info(struct video_client_ctx *client_ctx,
- struct venc_inst *inst, __s32 flag)
- {
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_vui_timing_info_enable vui_timing_info_enable;
- if (!client_ctx)
- return -EINVAL;
- if (inst->framerate_mode == VENC_MODE_VFR) {
- WFD_MSG_ERR("VUI timing info not suported in VFR mode ");
- return -EINVAL;
- }
- vcd_property_hdr.prop_id = VCD_I_ENABLE_VUI_TIMING_INFO;
- vcd_property_hdr.sz =
- sizeof(struct vcd_property_vui_timing_info_enable);
- vui_timing_info_enable.vui_timing_info = flag;
- return vcd_set_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vui_timing_info_enable);
- }
- static long venc_get_vui_timing_info(struct video_client_ctx *client_ctx,
- __s32 *flag)
- {
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_vui_timing_info_enable vui_timing_info_enable;
- int rc = 0;
- if (!client_ctx || !flag)
- return -EINVAL;
- vcd_property_hdr.prop_id = VCD_I_ENABLE_VUI_TIMING_INFO;
- vcd_property_hdr.sz =
- sizeof(struct vcd_property_vui_timing_info_enable);
- rc = vcd_get_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vui_timing_info_enable);
- if (rc < 0) {
- WFD_MSG_ERR("Failed getting property for VUI timing info");
- return rc;
- }
- *flag = vui_timing_info_enable.vui_timing_info;
- return rc;
- }
- static long venc_set_header_mode(struct video_client_ctx *client_ctx,
- __s32 mode)
- {
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_sps_pps_for_idr_enable sps_pps_for_idr_enable;
- int rc = 0;
- if (!client_ctx) {
- WFD_MSG_ERR("Invalid parameters\n");
- rc = -EINVAL;
- goto err;
- }
- vcd_property_hdr.prop_id = VCD_I_ENABLE_SPS_PPS_FOR_IDR;
- vcd_property_hdr.sz = sizeof(sps_pps_for_idr_enable);
- switch (mode) {
- case V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE:
- sps_pps_for_idr_enable.sps_pps_for_idr_enable_flag = 0;
- break;
- case V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_I_FRAME:
- sps_pps_for_idr_enable.sps_pps_for_idr_enable_flag = 1;
- break;
- case V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME:
- default:
- WFD_MSG_ERR("Video header mode %d not supported\n",
- mode);
- rc = -ENOTSUPP;
- goto err;
- }
- rc = vcd_set_property(client_ctx->vcd_handle, &vcd_property_hdr,
- &sps_pps_for_idr_enable);
- if (rc) {
- WFD_MSG_ERR("Failed to set enable_sps_pps_for_idr\n");
- goto err;
- }
- err:
- return rc;
- }
- static long venc_get_header_mode(struct video_client_ctx *client_ctx,
- __s32 *mode)
- {
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_sps_pps_for_idr_enable sps_pps_for_idr_enable;
- int rc = 0;
- if (!client_ctx) {
- WFD_MSG_ERR("Invalid parameters\n");
- rc = -EINVAL;
- goto err;
- }
- vcd_property_hdr.prop_id = VCD_I_ENABLE_SPS_PPS_FOR_IDR;
- vcd_property_hdr.sz = sizeof(sps_pps_for_idr_enable);
- rc = vcd_get_property(client_ctx->vcd_handle, &vcd_property_hdr,
- &sps_pps_for_idr_enable);
- if (rc) {
- WFD_MSG_ERR("Failed to get sps/pps for idr enable\n");
- goto err;
- }
- *mode = sps_pps_for_idr_enable.sps_pps_for_idr_enable_flag ?
- V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_I_FRAME :
- V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE;
- err:
- return rc;
- }
- static long venc_set_multislicing_mode(struct video_client_ctx *client_ctx,
- __u32 control, __s32 value)
- {
- int rc = 0;
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_frame_size vcd_frame_size;
- struct vcd_buffer_requirement vcd_buf_req;
- struct vcd_property_multi_slice vcd_multi_slice;
- if (!client_ctx) {
- WFD_MSG_ERR("Invalid parameters\n");
- rc = -EINVAL;
- goto set_multislicing_mode_fail;
- }
- vcd_property_hdr.prop_id = VCD_I_FRAME_SIZE;
- vcd_property_hdr.sz =
- sizeof(vcd_frame_size);
- rc = vcd_get_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vcd_frame_size);
- if (rc) {
- WFD_MSG_ERR("Failed to get frame size\n");
- goto set_multislicing_mode_fail;
- }
- rc = vcd_get_buffer_requirements(client_ctx->vcd_handle,
- VCD_BUFFER_OUTPUT, &vcd_buf_req);
- if (rc) {
- WFD_MSG_ERR("Failed to get buf reqs\n");
- goto set_multislicing_mode_fail;
- }
- vcd_property_hdr.prop_id = VCD_I_MULTI_SLICE;
- vcd_property_hdr.sz = sizeof(vcd_multi_slice);
- rc = vcd_get_property(client_ctx->vcd_handle, &vcd_property_hdr,
- &vcd_multi_slice);
- if (rc) {
- WFD_MSG_ERR("Failed to get multi slice\n");
- goto set_multislicing_mode_fail;
- }
- switch (control) {
- case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES:
- if (vcd_multi_slice.m_slice_sel !=
- VCD_MSLICE_BY_BYTE_COUNT) {
- WFD_MSG_ERR("Not in proper mode\n");
- goto set_multislicing_mode_fail;
- }
- vcd_multi_slice.m_slice_size = value;
- break;
- case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB:
- if (vcd_multi_slice.m_slice_sel !=
- VCD_MSLICE_BY_MB_COUNT) {
- WFD_MSG_ERR("Not in proper mode\n");
- goto set_multislicing_mode_fail;
- }
- vcd_multi_slice.m_slice_size = value;
- break;
- case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE:
- switch (value) {
- case V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE:
- vcd_multi_slice.m_slice_sel = VCD_MSLICE_OFF;
- break;
- case V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB:
- vcd_multi_slice.m_slice_sel = VCD_MSLICE_BY_MB_COUNT;
- /* Just a temporary size until client calls
- * V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB */
- vcd_multi_slice.m_slice_size =
- (vcd_frame_size.stride / 16) *
- (vcd_frame_size.scan_lines / 16);
- break;
- case V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES:
- vcd_multi_slice.m_slice_sel = VCD_MSLICE_BY_BYTE_COUNT;
- /* Just a temporary size until client calls
- * V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES */
- vcd_multi_slice.m_slice_size = vcd_buf_req.sz;
- break;
- default:
- WFD_MSG_ERR("Unrecognized mode %d\n", value);
- rc = -ENOTSUPP;
- goto set_multislicing_mode_fail;
- }
- break;
- default:
- rc = -EINVAL;
- goto set_multislicing_mode_fail;
- }
- rc = vcd_set_property(client_ctx->vcd_handle, &vcd_property_hdr,
- &vcd_multi_slice);
- if (rc) {
- WFD_MSG_ERR("Failed to set multi slice\n");
- goto set_multislicing_mode_fail;
- }
- set_multislicing_mode_fail:
- return rc;
- }
- static long venc_get_multislicing_mode(struct video_client_ctx *client_ctx,
- __u32 control, __s32 *value)
- {
- int rc = 0;
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_frame_size vcd_frame_size;
- struct vcd_buffer_requirement vcd_buf_req;
- struct vcd_property_multi_slice vcd_multi_slice;
- if (!client_ctx) {
- WFD_MSG_ERR("Invalid parameters\n");
- rc = -EINVAL;
- goto get_multislicing_mode_fail;
- }
- vcd_property_hdr.prop_id = VCD_I_FRAME_SIZE;
- vcd_property_hdr.sz =
- sizeof(vcd_frame_size);
- rc = vcd_get_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &vcd_frame_size);
- if (rc) {
- WFD_MSG_ERR("Failed to get frame size\n");
- goto get_multislicing_mode_fail;
- }
- vcd_property_hdr.prop_id = VCD_I_MULTI_SLICE;
- vcd_property_hdr.sz = sizeof(vcd_multi_slice);
- rc = vcd_get_property(client_ctx->vcd_handle, &vcd_property_hdr,
- &vcd_multi_slice);
- if (rc) {
- WFD_MSG_ERR("Failed to get multi slice\n");
- goto get_multislicing_mode_fail;
- }
- rc = vcd_get_buffer_requirements(client_ctx->vcd_handle,
- VCD_BUFFER_OUTPUT, &vcd_buf_req);
- if (rc) {
- WFD_MSG_ERR("Failed to get buf reqs\n");
- goto get_multislicing_mode_fail;
- }
- switch (control) {
- case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES:
- if (vcd_multi_slice.m_slice_sel == VCD_MSLICE_BY_BYTE_COUNT)
- *value = vcd_multi_slice.m_slice_size;
- else {
- WFD_MSG_ERR("Invalid query when in slice mode %d\n",
- vcd_multi_slice.m_slice_sel);
- rc = -EINVAL;
- goto get_multislicing_mode_fail;
- }
- break;
- case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB:
- if (vcd_multi_slice.m_slice_sel == VCD_MSLICE_BY_MB_COUNT)
- *value = vcd_multi_slice.m_slice_size;
- else {
- WFD_MSG_ERR("Invalid query when in slice mode %d\n",
- vcd_multi_slice.m_slice_sel);
- rc = -EINVAL;
- goto get_multislicing_mode_fail;
- }
- break;
- case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE:
- switch (vcd_multi_slice.m_slice_sel) {
- case VCD_MSLICE_OFF:
- *value = V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE;
- break;
- case VCD_MSLICE_BY_MB_COUNT:
- *value = V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB;
- break;
- case VCD_MSLICE_BY_BYTE_COUNT:
- *value = V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES;
- break;
- default:
- WFD_MSG_ERR("Encoder in an unknown mode %d\n",
- vcd_multi_slice.m_slice_sel);
- rc = -ENOENT;
- goto get_multislicing_mode_fail;
- }
- break;
- default:
- rc = -EINVAL;
- goto get_multislicing_mode_fail;
- }
- get_multislicing_mode_fail:
- return rc;
- }
- static long venc_set_entropy_mode(struct video_client_ctx *client_ctx,
- __s32 value)
- {
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_entropy_control entropy_control;
- int rc = 0;
- if (!client_ctx) {
- WFD_MSG_ERR("Invalid parameters\n");
- rc = -EINVAL;
- goto set_entropy_mode_fail;
- }
- vcd_property_hdr.prop_id = VCD_I_ENTROPY_CTRL;
- vcd_property_hdr.sz = sizeof(entropy_control);
- switch (value) {
- case V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC:
- entropy_control.entropy_sel = VCD_ENTROPY_SEL_CAVLC;
- break;
- case V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC:
- entropy_control.entropy_sel = VCD_ENTROPY_SEL_CABAC;
- entropy_control.cabac_model = VCD_CABAC_MODEL_NUMBER_0;
- break;
- default:
- WFD_MSG_ERR("Entropy type %d not supported\n", value);
- rc = -ENOTSUPP;
- goto set_entropy_mode_fail;
- }
- rc = vcd_set_property(client_ctx->vcd_handle, &vcd_property_hdr,
- &entropy_control);
- if (rc) {
- WFD_MSG_ERR("Failed to set entropy mode\n");
- goto set_entropy_mode_fail;
- }
- set_entropy_mode_fail:
- return rc;
- }
- static long venc_get_entropy_mode(struct video_client_ctx *client_ctx,
- __s32 *value)
- {
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_entropy_control entropy_control;
- int rc = 0;
- if (!client_ctx || !value) {
- WFD_MSG_ERR("Invalid parameters\n");
- rc = -EINVAL;
- goto get_entropy_mode_fail;
- }
- vcd_property_hdr.prop_id = VCD_I_ENTROPY_CTRL;
- vcd_property_hdr.sz = sizeof(entropy_control);
- rc = vcd_get_property(client_ctx->vcd_handle, &vcd_property_hdr,
- &entropy_control);
- if (rc) {
- WFD_MSG_ERR("Failed to get entropy mode\n");
- goto get_entropy_mode_fail;
- }
- switch (entropy_control.entropy_sel) {
- case VCD_ENTROPY_SEL_CAVLC:
- *value = V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC;
- break;
- case VCD_ENTROPY_SEL_CABAC:
- *value = V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC;
- break;
- default:
- WFD_MSG_ERR("Entropy type %d not known\n",
- entropy_control.entropy_sel);
- rc = -EINVAL;
- goto get_entropy_mode_fail;
- }
- get_entropy_mode_fail:
- return rc;
- }
- static long venc_set_cyclic_intra_refresh_mb(
- struct video_client_ctx *client_ctx,
- __s32 value)
- {
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_intra_refresh_mb_number cir_mb_num;
- int rc = 0;
- if (!client_ctx) {
- WFD_MSG_ERR("Invalid parameters\n");
- rc = -EINVAL;
- goto set_cir_mbs_fail;
- }
- vcd_property_hdr.prop_id = VCD_I_INTRA_REFRESH;
- vcd_property_hdr.sz = sizeof(cir_mb_num);
- cir_mb_num.cir_mb_number = value;
- rc = vcd_set_property(client_ctx->vcd_handle, &vcd_property_hdr,
- &cir_mb_num);
- if (rc) {
- WFD_MSG_ERR("Failed to set CIR MBs\n");
- goto set_cir_mbs_fail;
- }
- set_cir_mbs_fail:
- return rc;
- }
- static long venc_get_cyclic_intra_refresh_mb(
- struct video_client_ctx *client_ctx,
- __s32 *value)
- {
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_intra_refresh_mb_number cir_mb_num;
- int rc = 0;
- if (!client_ctx || !value) {
- WFD_MSG_ERR("Invalid parameters\n");
- rc = -EINVAL;
- goto get_cir_mbs_fail;
- }
- vcd_property_hdr.prop_id = VCD_I_INTRA_REFRESH;
- vcd_property_hdr.sz = sizeof(cir_mb_num);
- rc = vcd_get_property(client_ctx->vcd_handle, &vcd_property_hdr,
- &cir_mb_num);
- if (rc) {
- WFD_MSG_ERR("Failed to set CIR MBs\n");
- goto get_cir_mbs_fail;
- }
- *value = cir_mb_num.cir_mb_number;
- get_cir_mbs_fail:
- return rc;
- }
- static long venc_set_input_buffer(struct v4l2_subdev *sd, void *arg)
- {
- struct mem_region *mregion = arg;
- struct venc_inst *inst = sd->dev_priv;
- unsigned long paddr, kvaddr, temp;
- struct video_client_ctx *client_ctx = &inst->venc_client;
- int rc = 0;
- if (!client_ctx || !mregion) {
- WFD_MSG_ERR("Invalid input\n");
- rc = -EINVAL;
- goto ins_table_fail;
- }
- kvaddr = (unsigned long)mregion->kvaddr;
- paddr = (unsigned long)mregion->paddr;
- if (!kvaddr || !paddr) {
- WFD_MSG_ERR("Invalid addresses\n");
- rc = -EINVAL;
- goto ins_table_fail;
- }
- /*
- * Just a note: the third arg of vidc_insert_\
- * addr_table_kernel is supposed to be a userspace
- * address that is used as a key in the table. As
- * these bufs never leave the kernel, we need to have
- * an unique value to use as a key. So re-using kernel
- * virtual addr for this purpose
- */
- rc = vidc_insert_addr_table_kernel(client_ctx,
- BUFFER_TYPE_INPUT, kvaddr, kvaddr,
- paddr, 32, mregion->size);
- if (rc == (u32)false) {
- WFD_MSG_ERR("Failed to insert input buffer into table\n");
- rc = -EFAULT;
- goto ins_table_fail;
- }
- rc = vcd_set_buffer(client_ctx->vcd_handle,
- VCD_BUFFER_INPUT, (u8 *)kvaddr,
- mregion->size);
- if (rc) {
- WFD_MSG_ERR("Failed to set input buffer\n");
- rc = -EFAULT;
- goto set_input_buf_fail;
- }
- return rc;
- set_input_buf_fail:
- vidc_delete_addr_table(client_ctx, BUFFER_TYPE_INPUT,
- kvaddr, &temp);
- ins_table_fail:
- return rc;
- }
- static long venc_set_output_buffer(struct v4l2_subdev *sd, void *arg)
- {
- int rc = 0;
- struct venc_inst *inst = sd->dev_priv;
- struct video_client_ctx *client_ctx = &inst->venc_client;
- struct mem_region *mregion = arg;
- if (!client_ctx || !mregion) {
- WFD_MSG_ERR("Invalid input\n");
- return -EINVAL;
- }
- WFD_MSG_DBG("size = %u, offset = %u fd = %d\n", mregion->size,
- mregion->offset, mregion->fd);
- rc = vidc_insert_addr_table(client_ctx, BUFFER_TYPE_OUTPUT,
- mregion->cookie,
- (unsigned long *)&mregion->kvaddr,
- mregion->fd,
- mregion->offset,
- 32,
- mregion->size);
- if (rc == (u32)false) {
- WFD_MSG_ERR("Failed to insert outbuf in table\n");
- rc = -EINVAL;
- goto err;
- }
- WFD_MSG_DBG("size = %u, %p\n", mregion->size, mregion->kvaddr);
- rc = vcd_set_buffer(client_ctx->vcd_handle,
- VCD_BUFFER_OUTPUT, (u8 *) mregion->kvaddr,
- mregion->size);
- if (rc)
- WFD_MSG_ERR("Failed to set outbuf on encoder\n");
- err:
- return rc;
- }
- static long venc_fill_outbuf(struct v4l2_subdev *sd, void *arg)
- {
- int rc = 0;
- struct venc_inst *inst = sd->dev_priv;
- struct video_client_ctx *client_ctx = &inst->venc_client;
- struct mem_region *mregion = arg;
- struct vcd_frame_data vcd_frame = {0};
- unsigned long kernel_vaddr, phy_addr, user_vaddr;
- int pmem_fd;
- struct file *file;
- s32 buffer_index = -1;
- if (inst->streaming) {
- user_vaddr = mregion->cookie;
- rc = vidc_lookup_addr_table(client_ctx, BUFFER_TYPE_OUTPUT,
- true, &user_vaddr,
- &kernel_vaddr, &phy_addr, &pmem_fd, &file,
- &buffer_index);
- if (!rc) {
- WFD_MSG_ERR("Address lookup failed\n");
- goto err;
- }
- vcd_frame.virtual = (u8 *) kernel_vaddr;
- vcd_frame.frm_clnt_data = mregion->cookie;
- vcd_frame.alloc_len = mregion->size;
- rc = vcd_fill_output_buffer(client_ctx->vcd_handle, &vcd_frame);
- if (rc)
- WFD_MSG_ERR("Failed to fill output buffer on encoder");
- } else {
- struct mem_region *temp = kzalloc(sizeof(*temp), GFP_KERNEL);
- *temp = *mregion;
- INIT_LIST_HEAD(&temp->list);
- list_add_tail(&temp->list, &inst->unqueued_op_bufs.list);
- }
- err:
- return rc;
- }
- static long venc_encode_frame(struct v4l2_subdev *sd, void *arg)
- {
- int rc = 0;
- struct venc_inst *inst = sd->dev_priv;
- struct video_client_ctx *client_ctx = &inst->venc_client;
- struct venc_buf_info *venc_buf = arg;
- struct mem_region *mregion = venc_buf->mregion;
- struct vcd_frame_data vcd_input_buffer = {0};
- int64_t ts = 0;
- ts = venc_buf->timestamp;
- do_div(ts, NSEC_PER_USEC);
- vcd_input_buffer.virtual = mregion->kvaddr;
- vcd_input_buffer.frm_clnt_data = (u32)mregion;
- vcd_input_buffer.ip_frm_tag = (u32)mregion;
- vcd_input_buffer.data_len = mregion->size;
- vcd_input_buffer.time_stamp = ts;
- vcd_input_buffer.offset = 0;
- rc = vcd_encode_frame(client_ctx->vcd_handle,
- &vcd_input_buffer);
- if (rc)
- WFD_MSG_ERR("encode frame failed\n");
- return rc;
- }
- static long venc_alloc_recon_buffers(struct v4l2_subdev *sd, void *arg)
- {
- int rc = 0;
- struct venc_inst *inst = sd->dev_priv;
- struct video_client_ctx *client_ctx = &inst->venc_client;
- struct vcd_property_hdr vcd_property_hdr;
- struct vcd_property_buffer_size control;
- struct vcd_property_enc_recon_buffer *ctrl = NULL;
- unsigned long phy_addr;
- int i = 0;
- int heap_mask = 0;
- u32 ion_flags = 0;
- u32 len;
- control.width = inst->width;
- control.height = inst->height;
- vcd_property_hdr.prop_id = VCD_I_GET_RECON_BUFFER_SIZE;
- vcd_property_hdr.sz = sizeof(struct vcd_property_buffer_size);
- rc = vcd_get_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &control);
- if (rc) {
- WFD_MSG_ERR("Failed to get recon buf size\n");
- goto err;
- }
- heap_mask = ION_HEAP(ION_CP_MM_HEAP_ID);
- heap_mask |= inst->secure ? 0 : ION_HEAP(ION_IOMMU_HEAP_ID);
- ion_flags |= inst->secure ? ION_FLAG_SECURE : 0;
- if (vcd_get_ion_status()) {
- for (i = 0; i < 4; ++i) {
- ctrl = &client_ctx->recon_buffer[i];
- ctrl->buffer_size = control.size;
- ctrl->pmem_fd = 0;
- ctrl->offset = 0;
- ctrl->user_virtual_addr = (void *)i;
- client_ctx->recon_buffer_ion_handle[i]
- = ion_alloc(client_ctx->user_ion_client,
- control.size, SZ_8K, heap_mask, ion_flags);
- ctrl->kernel_virtual_addr = ion_map_kernel(
- client_ctx->user_ion_client,
- client_ctx->recon_buffer_ion_handle[i]);
- if (IS_ERR_OR_NULL(ctrl->kernel_virtual_addr)) {
- WFD_MSG_ERR("ion map kernel failed\n");
- rc = -EINVAL;
- goto free_ion_alloc;
- }
- if (inst->secure) {
- rc = ion_phys(client_ctx->user_ion_client,
- client_ctx->recon_buffer_ion_handle[i],
- &phy_addr, (size_t *)&len);
- if (rc || !phy_addr) {
- WFD_MSG_ERR("ion physical failed\n");
- goto unmap_ion_alloc;
- }
- } else {
- rc = ion_map_iommu(client_ctx->user_ion_client,
- client_ctx->recon_buffer_ion_handle[i],
- VIDEO_DOMAIN, VIDEO_MAIN_POOL, SZ_4K,
- 0, &phy_addr, (unsigned long *)&len,
- 0, 0);
- if (rc || !phy_addr) {
- WFD_MSG_ERR(
- "ion map iommu failed, rc = %d, phy_addr = 0x%lx\n",
- rc, phy_addr);
- goto unmap_ion_alloc;
- }
- }
- ctrl->physical_addr = (u8 *) phy_addr;
- ctrl->dev_addr = ctrl->physical_addr;
- vcd_property_hdr.prop_id = VCD_I_RECON_BUFFERS;
- vcd_property_hdr.sz =
- sizeof(struct vcd_property_enc_recon_buffer);
- rc = vcd_set_property(client_ctx->vcd_handle,
- &vcd_property_hdr, ctrl);
- if (rc) {
- WFD_MSG_ERR("Failed to set recon buffers\n");
- goto unmap_ion_iommu;
- }
- }
- } else {
- WFD_MSG_ERR("PMEM not suported\n");
- return -ENOMEM;
- }
- return rc;
- unmap_ion_iommu:
- if (!inst->secure) {
- if (client_ctx->recon_buffer_ion_handle[i]) {
- ion_unmap_iommu(client_ctx->user_ion_client,
- client_ctx->recon_buffer_ion_handle[i],
- VIDEO_DOMAIN, VIDEO_MAIN_POOL);
- }
- }
- unmap_ion_alloc:
- if (client_ctx->recon_buffer_ion_handle[i]) {
- ion_unmap_kernel(client_ctx->user_ion_client,
- client_ctx->recon_buffer_ion_handle[i]);
- ctrl->kernel_virtual_addr = NULL;
- ctrl->physical_addr = NULL;
- }
- free_ion_alloc:
- if (client_ctx->recon_buffer_ion_handle[i]) {
- ion_free(client_ctx->user_ion_client,
- client_ctx->recon_buffer_ion_handle[i]);
- client_ctx->recon_buffer_ion_handle[i] = NULL;
- }
- WFD_MSG_ERR("Failed to allo recon buffers\n");
- err:
- return rc;
- }
- static long venc_free_output_buffer(struct v4l2_subdev *sd, void *arg)
- {
- int rc = 0;
- struct venc_inst *inst = sd->dev_priv;
- struct video_client_ctx *client_ctx = &inst->venc_client;
- struct mem_region *mregion = arg;
- unsigned long kernel_vaddr, user_vaddr;
- if (!client_ctx || !mregion) {
- WFD_MSG_ERR("Invalid input\n");
- return -EINVAL;
- }
- user_vaddr = mregion->cookie;
- rc = vidc_delete_addr_table(client_ctx, BUFFER_TYPE_OUTPUT,
- user_vaddr,
- &kernel_vaddr);
- if (!rc) {
- WFD_MSG_ERR("Failed to delete buf from address table\n");
- return -EINVAL;
- }
- return vcd_free_buffer(client_ctx->vcd_handle, VCD_BUFFER_OUTPUT,
- (u8 *)kernel_vaddr);
- }
- static long venc_flush_buffers(struct v4l2_subdev *sd, void *arg)
- {
- int rc = 0;
- struct venc_inst *inst = sd->dev_priv;
- struct video_client_ctx *client_ctx = &inst->venc_client;
- if (!client_ctx) {
- WFD_MSG_ERR("Invalid input\n");
- return -EINVAL;
- }
- rc = vcd_flush(client_ctx->vcd_handle, VCD_FLUSH_INPUT);
- if (rc) {
- WFD_MSG_ERR("Failed to flush input buffers\n");
- rc = -EIO;
- goto flush_failed;
- }
- wait_for_completion(&client_ctx->event);
- if (client_ctx->event_status) {
- WFD_MSG_ERR("callback for vcd_flush input returned error: %u",
- client_ctx->event_status);
- rc = -EIO;
- goto flush_failed;
- }
- rc = vcd_flush(client_ctx->vcd_handle, VCD_FLUSH_OUTPUT);
- if (rc) {
- WFD_MSG_ERR("Failed to flush output buffers\n");
- rc = -EIO;
- goto flush_failed;
- }
- wait_for_completion(&client_ctx->event);
- if (client_ctx->event_status) {
- WFD_MSG_ERR("callback for vcd_flush output returned error: %u",
- client_ctx->event_status);
- rc = -EIO;
- goto flush_failed;
- }
- flush_failed:
- return rc;
- }
- static long venc_free_input_buffer(struct v4l2_subdev *sd, void *arg)
- {
- int del_rc = 0, free_rc = 0;
- struct venc_inst *inst = sd->dev_priv;
- struct video_client_ctx *client_ctx = &inst->venc_client;
- struct mem_region *mregion = arg;
- unsigned long vidc_kvaddr;
- if (!client_ctx || !mregion) {
- WFD_MSG_ERR("Invalid input\n");
- return -EINVAL;
- }
- del_rc = vidc_delete_addr_table(client_ctx, BUFFER_TYPE_INPUT,
- (unsigned long)mregion->kvaddr,
- &vidc_kvaddr);
- /*
- * Even if something went wrong in when
- * deleting from table, call vcd_free_buf
- */
- if (del_rc == (u32)false) {
- WFD_MSG_ERR("Failed to delete buf from address table\n");
- del_rc = -ENOKEY;
- } else if ((u8 *)vidc_kvaddr != mregion->kvaddr) {
- WFD_MSG_ERR("Failed to find expected buffer\n");
- del_rc = -EINVAL;
- } else
- del_rc = 0;
- free_rc = vcd_free_buffer(client_ctx->vcd_handle, VCD_BUFFER_INPUT,
- (u8 *)vidc_kvaddr);
- if (free_rc) {
- WFD_MSG_ERR("Failed to free buffer from encoder\n");
- free_rc = -EINVAL;
- }
- return del_rc ? del_rc : free_rc;
- }
- static long venc_free_recon_buffers(struct v4l2_subdev *sd, void *arg)
- {
- int rc = 0;
- struct venc_inst *inst = sd->dev_priv;
- struct video_client_ctx *client_ctx = &inst->venc_client;
- struct vcd_property_hdr vcd_property_hdr;
- int i;
- if (vcd_get_ion_status()) {
- for (i = 0; i < 4; i++) {
- vcd_property_hdr.prop_id = VCD_I_FREE_RECON_BUFFERS;
- vcd_property_hdr.sz =
- sizeof(struct vcd_property_buffer_size);
- rc = vcd_set_property(client_ctx->vcd_handle,
- &vcd_property_hdr, &client_ctx->recon_buffer[i]);
- if (rc)
- WFD_MSG_ERR("Failed to free recon buffer\n");
- if (!IS_ERR_OR_NULL(
- client_ctx->recon_buffer_ion_handle[i])) {
- if (!inst->secure) {
- ion_unmap_iommu(
- client_ctx->user_ion_client,
- client_ctx->recon_buffer_ion_handle[i],
- VIDEO_DOMAIN, VIDEO_MAIN_POOL);
- }
- ion_unmap_kernel(client_ctx->user_ion_client,
- client_ctx->recon_buffer_ion_handle[i]);
- ion_free(client_ctx->user_ion_client,
- client_ctx->recon_buffer_ion_handle[i]);
- client_ctx->recon_buffer_ion_handle[i] = NULL;
- }
- }
- }
- return rc;
- }
- static long venc_set_property(struct v4l2_subdev *sd, void *arg)
- {
- int rc = 0;
- struct venc_inst *inst = sd->dev_priv;
- struct v4l2_control *ctrl = arg;
- struct video_client_ctx *client_ctx = &inst->venc_client;
- switch (ctrl->id) {
- case V4L2_CID_MPEG_VIDEO_BITRATE:
- rc = venc_set_bitrate(client_ctx, ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
- rc = venc_set_bitrate_mode(client_ctx, ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDEO_H264_I_PERIOD:
- rc = venc_set_h264_intra_period(client_ctx, ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDEO_H264_LEVEL:
- rc = venc_set_codec_level(client_ctx, ctrl->id, ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDEO_H264_PROFILE:
- rc = venc_set_codec_profile(client_ctx, ctrl->id, ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDC_VIDEO_REQUEST_IFRAME:
- rc = venc_request_frame(client_ctx, ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP:
- rc = venc_set_qp_value(client_ctx, ctrl->id, ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP:
- case V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP:
- case V4L2_CID_MPEG_VIDEO_H263_MIN_QP:
- case V4L2_CID_MPEG_VIDEO_H263_MAX_QP:
- case V4L2_CID_MPEG_VIDEO_H264_MIN_QP:
- case V4L2_CID_MPEG_VIDEO_H264_MAX_QP:
- rc = venc_set_qp_range(client_ctx, ctrl->id, ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDEO_HEADER_MODE:
- rc = venc_set_header_mode(client_ctx, ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES:
- case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB:
- case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE:
- rc = venc_set_multislicing_mode(client_ctx, ctrl->id,
- ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDC_SET_PERF_LEVEL:
- rc = venc_set_max_perf_level(client_ctx, ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDC_VIDEO_H264_AU_DELIMITER:
- rc = venc_set_avc_delimiter(client_ctx, ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDC_VIDEO_H264_VUI_TIMING_INFO:
- rc = venc_set_vui_timing_info(client_ctx, inst, ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE:
- rc = venc_set_entropy_mode(client_ctx, ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB:
- rc = venc_set_cyclic_intra_refresh_mb(client_ctx, ctrl->value);
- break;
- default:
- WFD_MSG_ERR("Set property not suported: %d\n", ctrl->id);
- rc = -ENOTSUPP;
- break;
- }
- return rc;
- }
- static long venc_get_property(struct v4l2_subdev *sd, void *arg)
- {
- int rc = 0;
- struct venc_inst *inst = sd->dev_priv;
- struct v4l2_control *ctrl = arg;
- struct video_client_ctx *client_ctx = &inst->venc_client;
- switch (ctrl->id) {
- case V4L2_CID_MPEG_VIDEO_BITRATE:
- rc = venc_get_bitrate(client_ctx, &ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
- rc = venc_get_bitrate_mode(client_ctx, &ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDEO_H264_LEVEL:
- rc = venc_get_codec_level(client_ctx, ctrl->id, &ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDEO_H264_PROFILE:
- rc = venc_get_codec_profile(client_ctx, ctrl->id, &ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDEO_H264_I_PERIOD:
- rc = venc_get_h264_intra_period(client_ctx, &ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP:
- rc = venc_get_qp_value(client_ctx, ctrl->id, &ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP:
- case V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP:
- case V4L2_CID_MPEG_VIDEO_H263_MIN_QP:
- case V4L2_CID_MPEG_VIDEO_H263_MAX_QP:
- case V4L2_CID_MPEG_VIDEO_H264_MIN_QP:
- case V4L2_CID_MPEG_VIDEO_H264_MAX_QP:
- rc = venc_get_qp_range(client_ctx, ctrl->id, &ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDEO_HEADER_MODE:
- rc = venc_get_header_mode(client_ctx, &ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES:
- case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB:
- case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE:
- rc = venc_get_multislicing_mode(client_ctx, ctrl->id,
- &ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE:
- rc = venc_get_entropy_mode(client_ctx, &ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB:
- rc = venc_get_cyclic_intra_refresh_mb(client_ctx, &ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDC_VIDEO_H264_AU_DELIMITER:
- rc = venc_get_avc_delimiter(client_ctx, &ctrl->value);
- break;
- case V4L2_CID_MPEG_VIDC_VIDEO_H264_VUI_TIMING_INFO:
- rc = venc_get_vui_timing_info(client_ctx, &ctrl->value);
- break;
- default:
- WFD_MSG_ERR("Get property not suported: %d\n", ctrl->id);
- rc = -ENOTSUPP;
- break;
- }
- return rc;
- }
- long venc_mmap(struct v4l2_subdev *sd, void *arg)
- {
- struct venc_inst *inst = sd->dev_priv;
- struct mem_region_map *mmap = arg;
- struct mem_region *mregion = NULL;
- unsigned long rc = 0, size = 0;
- void *paddr = NULL;
- if (!sd) {
- WFD_MSG_ERR("Subdevice required for %s\n", __func__);
- return -EINVAL;
- } else if (!mmap || !mmap->mregion) {
- WFD_MSG_ERR("Memregion required for %s\n", __func__);
- return -EINVAL;
- }
- mregion = mmap->mregion;
- if (mregion->size % SZ_4K != 0) {
- WFD_MSG_ERR("Memregion not aligned to %d\n", SZ_4K);
- return -EINVAL;
- }
- if (inst->secure) {
- rc = ion_phys(mmap->ion_client, mregion->ion_handle,
- (unsigned long *)&paddr,
- (size_t *)&size);
- } else {
- rc = ion_map_iommu(mmap->ion_client, mregion->ion_handle,
- VIDEO_DOMAIN, VIDEO_MAIN_POOL, SZ_4K,
- 0, (unsigned long *)&paddr,
- &size, 0, 0);
- }
- if (rc) {
- WFD_MSG_ERR("Failed to get physical addr\n");
- paddr = NULL;
- } else if (size < mregion->size) {
- WFD_MSG_ERR("Failed to map enough memory\n");
- rc = -ENOMEM;
- }
- mregion->paddr = paddr;
- return rc;
- }
- long venc_munmap(struct v4l2_subdev *sd, void *arg)
- {
- struct venc_inst *inst = sd->dev_priv;
- struct mem_region_map *mmap = arg;
- struct mem_region *mregion = NULL;
- if (!sd) {
- WFD_MSG_ERR("Subdevice required for %s\n", __func__);
- return -EINVAL;
- } else if (!mregion) {
- WFD_MSG_ERR("Memregion required for %s\n", __func__);
- return -EINVAL;
- }
- mregion = mmap->mregion;
- if (!inst->secure) {
- ion_unmap_iommu(mmap->ion_client, mregion->ion_handle,
- VIDEO_DOMAIN, VIDEO_MAIN_POOL);
- }
- return 0;
- }
- long venc_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
- {
- long rc = 0;
- switch (cmd) {
- case OPEN:
- rc = venc_open(sd, arg);
- break;
- case CLOSE:
- rc = venc_close(sd, arg);
- break;
- case ENCODE_START:
- rc = venc_start(sd);
- break;
- case ENCODE_FRAME:
- venc_encode_frame(sd, arg);
- break;
- case ENCODE_STOP:
- rc = venc_stop(sd);
- break;
- case SET_PROP:
- rc = venc_set_property(sd, arg);
- break;
- case GET_PROP:
- rc = venc_get_property(sd, arg);
- break;
- case GET_BUFFER_REQ:
- rc = venc_get_buffer_req(sd, arg);
- break;
- case SET_BUFFER_REQ:
- rc = venc_set_buffer_req(sd, arg);
- break;
- case FREE_BUFFER:
- break;
- case FILL_OUTPUT_BUFFER:
- rc = venc_fill_outbuf(sd, arg);
- break;
- case SET_FORMAT:
- rc = venc_set_format(sd, arg);
- break;
- case SET_FRAMERATE:
- rc = venc_set_framerate(sd, arg);
- break;
- case SET_INPUT_BUFFER:
- rc = venc_set_input_buffer(sd, arg);
- break;
- case SET_OUTPUT_BUFFER:
- rc = venc_set_output_buffer(sd, arg);
- break;
- case ALLOC_RECON_BUFFERS:
- rc = venc_alloc_recon_buffers(sd, arg);
- break;
- case FREE_OUTPUT_BUFFER:
- rc = venc_free_output_buffer(sd, arg);
- break;
- case FREE_INPUT_BUFFER:
- rc = venc_free_input_buffer(sd, arg);
- break;
- case FREE_RECON_BUFFERS:
- rc = venc_free_recon_buffers(sd, arg);
- break;
- case ENCODE_FLUSH:
- rc = venc_flush_buffers(sd, arg);
- break;
- case ENC_MMAP:
- rc = venc_mmap(sd, arg);
- break;
- case ENC_MUNMAP:
- rc = venc_munmap(sd, arg);
- break;
- case SET_FRAMERATE_MODE:
- rc = venc_set_framerate_mode(sd, arg);
- break;
- default:
- rc = -1;
- break;
- }
- return rc;
- }
|