Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <media/v4l2-subdev.h> |
Deva Ramasubramanian | 2e99bff | 2012-02-13 21:12:08 -0800 | [diff] [blame] | 15 | #include <mach/iommu_domains.h> |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 16 | #include "enc-subdev.h" |
| 17 | #include "wfd-util.h" |
| 18 | #include <media/msm/vcd_api.h> |
| 19 | #include <media/msm/vidc_init.h> |
| 20 | #include <media/msm/vcd_property.h> |
| 21 | #include <linux/time.h> |
| 22 | #include <linux/ktime.h> |
| 23 | |
| 24 | #define VID_ENC_MAX_ENCODER_CLIENTS 1 |
| 25 | #define MAX_NUM_CTRLS 20 |
Deva Ramasubramanian | 28796cb | 2012-11-12 12:18:09 -0800 | [diff] [blame] | 26 | #define V4L2_FRAME_FLAGS (V4L2_BUF_FLAG_KEYFRAME | V4L2_BUF_FLAG_PFRAME | \ |
| 27 | V4L2_BUF_FLAG_BFRAME | V4L2_QCOM_BUF_FLAG_CODECCONFIG) |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 28 | |
Deva Ramasubramanian | 08413fc | 2012-07-16 17:27:02 -0700 | [diff] [blame] | 29 | static long venc_fill_outbuf(struct v4l2_subdev *sd, void *arg); |
| 30 | |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 31 | struct venc_inst { |
| 32 | struct video_client_ctx venc_client; |
| 33 | void *cbdata; |
| 34 | void (*op_buffer_done)(void *cookie, u32 status, |
| 35 | struct vb2_buffer *buf); |
| 36 | void (*ip_buffer_done)(void *cookie, u32 status, |
| 37 | struct mem_region *mregion); |
| 38 | u32 width; |
| 39 | u32 height; |
Deepak kotur | 13d82f8 | 2012-03-12 11:12:32 -0700 | [diff] [blame] | 40 | int secure; |
Deva Ramasubramanian | 08413fc | 2012-07-16 17:27:02 -0700 | [diff] [blame] | 41 | struct mem_region unqueued_op_bufs; |
| 42 | bool streaming; |
Srinu Gorle | 4f8bc3a | 2012-11-15 09:36:38 +0530 | [diff] [blame] | 43 | enum venc_framerate_modes framerate_mode; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | struct venc { |
| 47 | s32 device_handle; |
| 48 | void *virt_base; |
| 49 | struct venc_inst venc_clients[VID_ENC_MAX_ENCODER_CLIENTS]; |
| 50 | struct mutex lock; |
| 51 | struct ion_client *iclient; |
| 52 | }; |
| 53 | |
| 54 | static struct venc venc_p; |
| 55 | |
| 56 | static void *venc_map_dev_base_addr(void *device_name) |
| 57 | { |
| 58 | return venc_p.virt_base; |
| 59 | } |
| 60 | |
| 61 | static void venc_interrupt_deregister(void) |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | static void venc_interrupt_register(void *device_name) |
| 66 | { |
| 67 | } |
| 68 | |
| 69 | static void venc_interrupt_clear(void) |
| 70 | { |
| 71 | } |
| 72 | |
| 73 | int venc_load_fw(struct v4l2_subdev *sd) |
| 74 | { |
| 75 | return !vidc_load_firmware(); |
| 76 | } |
| 77 | |
| 78 | static u32 venc_get_empty_client_index(void) |
| 79 | { |
| 80 | u32 i; |
| 81 | u32 found = false; |
| 82 | |
Deva Ramasubramanian | a6bde8d | 2012-04-20 16:34:29 -0700 | [diff] [blame] | 83 | for (i = 0; i < VID_ENC_MAX_ENCODER_CLIENTS; i++) { |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 84 | if (!venc_p.venc_clients[i].venc_client.vcd_handle) { |
| 85 | found = true; |
| 86 | break; |
| 87 | } |
| 88 | } |
| 89 | if (!found) { |
| 90 | WFD_MSG_ERR("%s():ERROR No space for new client\n", |
| 91 | __func__); |
| 92 | return -ENOMEM; |
| 93 | } |
| 94 | WFD_MSG_INFO("%s(): available client index = %u\n", |
| 95 | __func__, i); |
| 96 | return i; |
| 97 | } |
| 98 | |
| 99 | int venc_init(struct v4l2_subdev *sd, u32 val) |
| 100 | { |
| 101 | struct vcd_init_config vcd_init_config; |
| 102 | mutex_init(&venc_p.lock); |
| 103 | venc_p.virt_base = vidc_get_ioaddr(); |
| 104 | vcd_init_config.device_name = "VIDC"; |
| 105 | vcd_init_config.map_dev_base_addr = venc_map_dev_base_addr; |
| 106 | vcd_init_config.interrupt_clr = venc_interrupt_clear; |
| 107 | vcd_init_config.register_isr = venc_interrupt_register; |
| 108 | vcd_init_config.deregister_isr = venc_interrupt_deregister; |
| 109 | vcd_init(&vcd_init_config, &venc_p.device_handle); |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | static void venc_notify_client(struct video_client_ctx *client_ctx) |
| 114 | { |
| 115 | if (client_ctx) |
| 116 | complete(&client_ctx->event); |
| 117 | } |
| 118 | |
| 119 | static void venc_open_done(struct video_client_ctx *client_ctx, |
| 120 | struct vcd_handle_container *handle_container) |
| 121 | { |
| 122 | if (client_ctx) { |
| 123 | if (handle_container) |
| 124 | client_ctx->vcd_handle = handle_container->handle; |
| 125 | else |
| 126 | WFD_MSG_ERR("handle_container is NULL\n"); |
| 127 | venc_notify_client(client_ctx); |
| 128 | } else |
| 129 | WFD_MSG_ERR("ERROR. client_ctx is NULL"); |
| 130 | } |
| 131 | |
| 132 | static void venc_start_done(struct video_client_ctx *client_ctx, u32 status) |
| 133 | { |
| 134 | if (client_ctx) |
| 135 | venc_notify_client(client_ctx); |
| 136 | else |
| 137 | WFD_MSG_ERR("ERROR. client_ctx is NULL"); |
| 138 | } |
| 139 | |
| 140 | static void venc_stop_done(struct video_client_ctx *client_ctx, u32 status) |
| 141 | { |
| 142 | WFD_MSG_DBG("Inside venc_stop_done: E\n"); |
| 143 | if (client_ctx) |
| 144 | venc_notify_client(client_ctx); |
| 145 | else |
| 146 | WFD_MSG_ERR("ERROR. client_ctx is NULL"); |
| 147 | WFD_MSG_DBG("Inside venc_stop_done: X\n"); |
| 148 | } |
| 149 | |
| 150 | static void venc_cb(u32 event, u32 status, void *info, u32 size, void *handle, |
| 151 | void *const client_data) |
| 152 | { |
| 153 | struct venc_inst *inst = client_data; |
| 154 | struct video_client_ctx *client_ctx = &inst->venc_client; |
| 155 | struct vb2_buffer *vbuf; |
| 156 | struct mem_region *mregion; |
| 157 | struct vcd_frame_data *frame_data = (struct vcd_frame_data *)info; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 158 | |
| 159 | if (!client_ctx) { |
| 160 | WFD_MSG_ERR("Client context is NULL\n"); |
| 161 | return; |
| 162 | } |
| 163 | client_ctx->event_status = status; |
| 164 | switch (event) { |
| 165 | case VCD_EVT_RESP_OPEN: |
| 166 | WFD_MSG_DBG("EVENT: open done = %d\n", event); |
| 167 | venc_open_done(client_ctx, |
| 168 | (struct vcd_handle_container *)info); |
| 169 | break; |
| 170 | case VCD_EVT_RESP_INPUT_DONE: |
| 171 | case VCD_EVT_RESP_INPUT_FLUSHED: |
| 172 | WFD_MSG_DBG("EVENT: input done = %d\n", event); |
| 173 | mregion = (struct mem_region *) |
| 174 | frame_data->frm_clnt_data; |
| 175 | inst->ip_buffer_done(inst->cbdata, status, mregion); |
| 176 | break; |
| 177 | case VCD_EVT_RESP_OUTPUT_DONE: |
| 178 | case VCD_EVT_RESP_OUTPUT_FLUSHED: |
| 179 | WFD_MSG_DBG("EVENT: output done = %d\n", event); |
| 180 | vbuf = (struct vb2_buffer *) |
| 181 | frame_data->frm_clnt_data; |
| 182 | vbuf->v4l2_planes[0].bytesused = |
| 183 | frame_data->data_len; |
| 184 | |
Deva Ramasubramanian | 28796cb | 2012-11-12 12:18:09 -0800 | [diff] [blame] | 185 | vbuf->v4l2_buf.flags &= ~(V4L2_FRAME_FLAGS); |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 186 | switch (frame_data->frame) { |
| 187 | case VCD_FRAME_I: |
| 188 | case VCD_FRAME_IDR: |
| 189 | vbuf->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME; |
| 190 | break; |
| 191 | case VCD_FRAME_P: |
| 192 | vbuf->v4l2_buf.flags |= V4L2_BUF_FLAG_PFRAME; |
| 193 | break; |
| 194 | case VCD_FRAME_B: |
| 195 | vbuf->v4l2_buf.flags |= V4L2_BUF_FLAG_BFRAME; |
| 196 | break; |
| 197 | default: |
| 198 | break; |
| 199 | } |
| 200 | |
Deva Ramasubramanian | aa653ab | 2012-10-23 17:39:52 -0700 | [diff] [blame] | 201 | if (frame_data->flags & VCD_FRAME_FLAG_CODECCONFIG) |
| 202 | vbuf->v4l2_buf.flags |= V4L2_QCOM_BUF_FLAG_CODECCONFIG; |
| 203 | |
Deva Ramasubramanian | b84fc50 | 2012-01-16 11:42:58 -0800 | [diff] [blame] | 204 | vbuf->v4l2_buf.timestamp = |
Deva Ramasubramanian | 4947d8c | 2012-04-03 12:41:06 -0700 | [diff] [blame] | 205 | ns_to_timeval(frame_data->time_stamp * NSEC_PER_USEC); |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 206 | |
| 207 | WFD_MSG_DBG("bytes used %d, ts: %d.%d, frame type is %d\n", |
| 208 | frame_data->data_len, |
| 209 | (int)vbuf->v4l2_buf.timestamp.tv_sec, |
| 210 | (int)vbuf->v4l2_buf.timestamp.tv_usec, |
| 211 | frame_data->frame); |
| 212 | |
Deva Ramasubramanian | 2e99bff | 2012-02-13 21:12:08 -0800 | [diff] [blame] | 213 | /* |
| 214 | * Output buffers are enc-subdev and vcd's problem, so |
| 215 | * if buffer is cached, need to flush before giving to |
| 216 | * client. So doing the dirty stuff in this little context |
| 217 | */ |
| 218 | { |
| 219 | unsigned long kvaddr, phys_addr; |
| 220 | s32 buffer_index = -1, ion_flags = 0; |
| 221 | struct ion_handle *ion_handle; |
| 222 | int pmem_fd; |
| 223 | struct file *filp; |
| 224 | bool rc; |
| 225 | |
| 226 | rc = vidc_lookup_addr_table(client_ctx, |
| 227 | BUFFER_TYPE_OUTPUT, true, |
| 228 | (unsigned long *)&frame_data-> |
| 229 | frm_clnt_data, &kvaddr, &phys_addr, |
| 230 | &pmem_fd, &filp, &buffer_index); |
| 231 | |
| 232 | if (rc) |
| 233 | ion_flags = vidc_get_fd_info(client_ctx, |
| 234 | BUFFER_TYPE_OUTPUT, pmem_fd, |
| 235 | kvaddr, buffer_index, &ion_handle); |
| 236 | else |
Deva Ramasubramanian | 1efb995 | 2012-07-31 11:11:15 -0700 | [diff] [blame] | 237 | WFD_MSG_ERR("Got an output buffer that we " \ |
Deva Ramasubramanian | 2e99bff | 2012-02-13 21:12:08 -0800 | [diff] [blame] | 238 | "couldn't recognize!\n"); |
| 239 | |
| 240 | if (msm_ion_do_cache_op(client_ctx->user_ion_client, |
| 241 | ion_handle, &kvaddr, frame_data->data_len, |
| 242 | ION_IOC_CLEAN_INV_CACHES)) |
| 243 | WFD_MSG_ERR("OP buffer flush failed\n"); |
| 244 | |
| 245 | } |
| 246 | |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 247 | inst->op_buffer_done(inst->cbdata, status, vbuf); |
| 248 | break; |
| 249 | case VCD_EVT_RESP_START: |
| 250 | WFD_MSG_DBG("EVENT: start done = %d\n", event); |
| 251 | venc_start_done(client_ctx, status); |
| 252 | /*TODO: should wait for this event*/ |
| 253 | break; |
| 254 | case VCD_EVT_RESP_STOP: |
| 255 | WFD_MSG_DBG("EVENT: not expected = %d\n", event); |
| 256 | venc_stop_done(client_ctx, status); |
| 257 | break; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 258 | case VCD_EVT_RESP_FLUSH_INPUT_DONE: |
| 259 | case VCD_EVT_RESP_FLUSH_OUTPUT_DONE: |
Vinay Kalia | b6dd587 | 2012-04-05 15:24:58 -0700 | [diff] [blame] | 260 | venc_notify_client(client_ctx); |
| 261 | break; |
| 262 | case VCD_EVT_RESP_PAUSE: |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 263 | case VCD_EVT_IND_OUTPUT_RECONFIG: |
| 264 | WFD_MSG_DBG("EVENT: not expected = %d\n", event); |
| 265 | break; |
| 266 | case VCD_EVT_IND_HWERRFATAL: |
| 267 | case VCD_EVT_IND_RESOURCES_LOST: |
| 268 | WFD_MSG_DBG("EVENT: error = %d\n", event); |
| 269 | break; |
| 270 | default: |
| 271 | WFD_MSG_ERR("Invalid event type = %u\n", event); |
| 272 | break; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | static long venc_open(struct v4l2_subdev *sd, void *arg) |
| 277 | { |
| 278 | u32 client_index; |
| 279 | int rc = 0; |
| 280 | struct venc_inst *inst; |
| 281 | struct video_client_ctx *client_ctx; |
| 282 | struct venc_msg_ops *vmops = arg; |
Deepak kotur | 13d82f8 | 2012-03-12 11:12:32 -0700 | [diff] [blame] | 283 | int flags = 0; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 284 | mutex_lock(&venc_p.lock); |
| 285 | client_index = venc_get_empty_client_index(); |
| 286 | if (client_index < 0) { |
| 287 | WFD_MSG_ERR("No free clients, client_index = %d\n", |
| 288 | client_index); |
| 289 | rc = -ENODEV; |
| 290 | goto no_free_client; |
| 291 | } |
| 292 | inst = &venc_p.venc_clients[client_index]; |
| 293 | client_ctx = &inst->venc_client; |
| 294 | init_completion(&client_ctx->event); |
| 295 | mutex_init(&client_ctx->msg_queue_lock); |
| 296 | mutex_init(&client_ctx->enrty_queue_lock); |
| 297 | INIT_LIST_HEAD(&client_ctx->msg_queue); |
| 298 | init_waitqueue_head(&client_ctx->msg_wait); |
| 299 | inst->op_buffer_done = vmops->op_buffer_done; |
| 300 | inst->ip_buffer_done = vmops->ip_buffer_done; |
Deva Ramasubramanian | 08413fc | 2012-07-16 17:27:02 -0700 | [diff] [blame] | 301 | INIT_LIST_HEAD(&inst->unqueued_op_bufs.list); |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 302 | inst->cbdata = vmops->cbdata; |
Deepak kotur | 13d82f8 | 2012-03-12 11:12:32 -0700 | [diff] [blame] | 303 | inst->secure = vmops->secure; |
Deva Ramasubramanian | 08413fc | 2012-07-16 17:27:02 -0700 | [diff] [blame] | 304 | inst->streaming = false; |
Srinu Gorle | 4f8bc3a | 2012-11-15 09:36:38 +0530 | [diff] [blame] | 305 | inst->framerate_mode = VENC_MODE_VFR; |
| 306 | |
Deepak kotur | 13d82f8 | 2012-03-12 11:12:32 -0700 | [diff] [blame] | 307 | if (vmops->secure) { |
| 308 | WFD_MSG_ERR("OPENING SECURE SESSION\n"); |
| 309 | flags |= VCD_CP_SESSION; |
| 310 | } |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 311 | if (vcd_get_ion_status()) { |
| 312 | client_ctx->user_ion_client = vcd_get_ion_client(); |
| 313 | if (!client_ctx->user_ion_client) { |
| 314 | WFD_MSG_ERR("vcd_open ion get client failed"); |
| 315 | return -EFAULT; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | rc = vcd_open(venc_p.device_handle, false, venc_cb, |
Deepak kotur | 13d82f8 | 2012-03-12 11:12:32 -0700 | [diff] [blame] | 320 | inst, flags); |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 321 | if (rc) { |
| 322 | WFD_MSG_ERR("vcd_open failed, rc = %d\n", rc); |
Deepak kotur | 13d82f8 | 2012-03-12 11:12:32 -0700 | [diff] [blame] | 323 | rc = -ENODEV; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 324 | goto no_free_client; |
| 325 | } |
| 326 | wait_for_completion(&client_ctx->event); |
| 327 | if (client_ctx->event_status) { |
| 328 | WFD_MSG_ERR("callback for vcd_open returned error: %u", |
| 329 | client_ctx->event_status); |
| 330 | goto no_free_client; |
| 331 | } |
| 332 | WFD_MSG_ERR("NOTE: client_ctx = %p\n", client_ctx); |
| 333 | vmops->cookie = inst; |
| 334 | sd->dev_priv = inst; |
| 335 | no_free_client: |
| 336 | mutex_unlock(&venc_p.lock); |
| 337 | return rc; |
| 338 | } |
| 339 | |
| 340 | static long venc_close(struct v4l2_subdev *sd, void *arg) |
| 341 | { |
| 342 | long rc = 0; |
| 343 | struct venc_inst *inst; |
| 344 | struct video_client_ctx *client_ctx = NULL; |
| 345 | mutex_lock(&venc_p.lock); |
| 346 | inst = sd->dev_priv; |
| 347 | client_ctx = &inst->venc_client; |
| 348 | if (!client_ctx || !client_ctx->vcd_handle) { |
| 349 | WFD_MSG_ERR("Invalid client context in close\n"); |
| 350 | rc = -ENODEV; |
| 351 | goto end; |
| 352 | } |
| 353 | rc = vcd_close(client_ctx->vcd_handle); |
| 354 | if (rc) { |
| 355 | WFD_MSG_ERR("Failed to close encoder subdevice\n"); |
| 356 | goto end; |
| 357 | } |
| 358 | memset((void *)client_ctx, 0, |
| 359 | sizeof(struct video_client_ctx)); |
| 360 | end: |
| 361 | mutex_unlock(&venc_p.lock); |
| 362 | return rc; |
| 363 | } |
| 364 | |
| 365 | static long venc_get_buffer_req(struct v4l2_subdev *sd, void *arg) |
| 366 | { |
| 367 | int rc = 0; |
| 368 | struct v4l2_requestbuffers *b = arg; |
| 369 | struct vcd_buffer_requirement buf_req; |
| 370 | struct venc_inst *inst = sd->dev_priv; |
| 371 | struct video_client_ctx *client_ctx = &inst->venc_client; |
| 372 | if (!client_ctx) { |
| 373 | WFD_MSG_ERR("Invalid client context"); |
| 374 | rc = -EINVAL; |
| 375 | goto err; |
| 376 | } |
| 377 | rc = vcd_get_buffer_requirements(client_ctx->vcd_handle, |
| 378 | VCD_BUFFER_OUTPUT, &buf_req); |
| 379 | if (rc) { |
| 380 | WFD_MSG_ERR("Failed to get out buf reqs rc = %d", rc); |
| 381 | goto err; |
| 382 | } |
Deva Ramasubramanian | 66d2cbe4 | 2012-03-16 12:28:55 -0700 | [diff] [blame] | 383 | |
| 384 | buf_req.actual_count = b->count = max(buf_req.min_count, b->count); |
| 385 | rc = vcd_set_buffer_requirements(client_ctx->vcd_handle, |
| 386 | VCD_BUFFER_OUTPUT, &buf_req); |
| 387 | if (rc) { |
| 388 | WFD_MSG_ERR("Failed to set out buf reqs rc = %d", rc); |
| 389 | goto err; |
| 390 | } |
| 391 | |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 392 | err: |
| 393 | return rc; |
| 394 | } |
| 395 | |
| 396 | static long venc_set_buffer_req(struct v4l2_subdev *sd, void *arg) |
| 397 | { |
| 398 | int rc = 0; |
| 399 | struct bufreq *b = arg; |
| 400 | struct vcd_buffer_requirement buf_req; |
| 401 | struct venc_inst *inst = sd->dev_priv; |
| 402 | struct video_client_ctx *client_ctx = &inst->venc_client; |
Deva Ramasubramanian | a6e4923 | 2012-03-01 18:06:48 -0800 | [diff] [blame] | 403 | int aligned_width, aligned_height; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 404 | if (!client_ctx) { |
| 405 | WFD_MSG_ERR("Invalid client context"); |
| 406 | rc = -EINVAL; |
| 407 | goto err; |
| 408 | } |
Deva Ramasubramanian | a6e4923 | 2012-03-01 18:06:48 -0800 | [diff] [blame] | 409 | aligned_width = ALIGN(b->width, 16); |
| 410 | aligned_height = ALIGN(b->height, 16); |
| 411 | |
| 412 | if (aligned_width != b->width) { |
| 413 | WFD_MSG_ERR("Width not 16 byte aligned\n"); |
| 414 | rc = -EINVAL; |
| 415 | goto err; |
| 416 | } |
| 417 | |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 418 | buf_req.actual_count = b->count; |
| 419 | buf_req.min_count = b->count; |
| 420 | buf_req.max_count = b->count; |
Deva Ramasubramanian | a6e4923 | 2012-03-01 18:06:48 -0800 | [diff] [blame] | 421 | buf_req.sz = ALIGN(aligned_height * aligned_width, SZ_2K) |
| 422 | + ALIGN(aligned_height * aligned_width * 1/2, SZ_2K); |
Deva Ramasubramanian | 2e99bff | 2012-02-13 21:12:08 -0800 | [diff] [blame] | 423 | buf_req.align = SZ_4K; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 424 | inst->width = b->width; |
| 425 | inst->height = b->height; |
| 426 | rc = vcd_set_buffer_requirements(client_ctx->vcd_handle, |
| 427 | VCD_BUFFER_INPUT, &buf_req); |
| 428 | if (rc) { |
| 429 | WFD_MSG_ERR("Failed to get out buf reqs rc = %d", rc); |
| 430 | goto err; |
| 431 | } |
| 432 | b->size = buf_req.sz; |
| 433 | err: |
| 434 | return rc; |
| 435 | } |
| 436 | |
| 437 | static long venc_start(struct v4l2_subdev *sd) |
| 438 | { |
| 439 | struct venc_inst *inst = sd->dev_priv; |
| 440 | struct video_client_ctx *client_ctx = &inst->venc_client; |
Deva Ramasubramanian | 08413fc | 2012-07-16 17:27:02 -0700 | [diff] [blame] | 441 | struct mem_region *curr = NULL, *temp = NULL; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 442 | int rc; |
| 443 | if (!client_ctx) { |
| 444 | WFD_MSG_ERR("Client context is NULL"); |
| 445 | return -EINVAL; |
| 446 | } |
Deva Ramasubramanian | 08413fc | 2012-07-16 17:27:02 -0700 | [diff] [blame] | 447 | |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 448 | rc = vcd_encode_start(client_ctx->vcd_handle); |
| 449 | if (rc) { |
| 450 | WFD_MSG_ERR("vcd_encode_start failed, rc = %d\n", rc); |
| 451 | goto err; |
| 452 | } |
| 453 | wait_for_completion(&client_ctx->event); |
| 454 | if (client_ctx->event_status) |
| 455 | WFD_MSG_ERR("callback for vcd_encode_start returned error: %u", |
| 456 | client_ctx->event_status); |
Deva Ramasubramanian | 08413fc | 2012-07-16 17:27:02 -0700 | [diff] [blame] | 457 | |
| 458 | inst->streaming = true; |
| 459 | /* Push any buffers that we have held back */ |
| 460 | list_for_each_entry_safe(curr, temp, |
| 461 | &inst->unqueued_op_bufs.list, list) { |
| 462 | venc_fill_outbuf(sd, curr); |
| 463 | list_del(&curr->list); |
| 464 | kfree(curr); |
| 465 | } |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 466 | err: |
| 467 | return rc; |
| 468 | } |
| 469 | |
| 470 | static long venc_stop(struct v4l2_subdev *sd) |
| 471 | { |
| 472 | struct venc_inst *inst = sd->dev_priv; |
| 473 | struct video_client_ctx *client_ctx = &inst->venc_client; |
Deva Ramasubramanian | 08413fc | 2012-07-16 17:27:02 -0700 | [diff] [blame] | 474 | struct mem_region *curr = NULL, *temp = NULL; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 475 | int rc; |
| 476 | if (!client_ctx) { |
| 477 | WFD_MSG_ERR("Client context is NULL"); |
| 478 | return -EINVAL; |
| 479 | } |
| 480 | rc = vcd_stop(client_ctx->vcd_handle); |
| 481 | wait_for_completion(&client_ctx->event); |
Deva Ramasubramanian | 08413fc | 2012-07-16 17:27:02 -0700 | [diff] [blame] | 482 | inst->streaming = false; |
| 483 | /* Drop whatever frames we haven't queued */ |
| 484 | list_for_each_entry_safe(curr, temp, |
| 485 | &inst->unqueued_op_bufs.list, list) { |
| 486 | inst->op_buffer_done(inst->cbdata, 0, |
| 487 | (struct vb2_buffer *)curr->cookie); |
| 488 | list_del(&curr->list); |
| 489 | kfree(curr); |
| 490 | } |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 491 | return rc; |
| 492 | } |
| 493 | |
| 494 | static long venc_set_codec(struct video_client_ctx *client_ctx, __s32 codec) |
| 495 | { |
| 496 | struct vcd_property_codec vcd_property_codec; |
| 497 | struct vcd_property_hdr vcd_property_hdr; |
| 498 | vcd_property_hdr.prop_id = VCD_I_CODEC; |
| 499 | vcd_property_hdr.sz = sizeof(struct vcd_property_codec); |
| 500 | vcd_property_codec.codec = VCD_CODEC_H264; |
Deva Ramasubramanian | c34de06 | 2012-01-25 14:42:58 -0800 | [diff] [blame] | 501 | |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 502 | switch (codec) { |
Deva Ramasubramanian | c34de06 | 2012-01-25 14:42:58 -0800 | [diff] [blame] | 503 | case V4L2_PIX_FMT_H264: |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 504 | vcd_property_codec.codec = VCD_CODEC_H264; |
| 505 | break; |
Deva Ramasubramanian | c34de06 | 2012-01-25 14:42:58 -0800 | [diff] [blame] | 506 | case V4L2_PIX_FMT_MPEG4: |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 507 | vcd_property_codec.codec = VCD_CODEC_MPEG4; |
| 508 | break; |
| 509 | default: |
| 510 | WFD_MSG_ERR("Codec not supported, defaulting to h264\n"); |
| 511 | break; |
| 512 | } |
| 513 | return vcd_set_property(client_ctx->vcd_handle, |
| 514 | &vcd_property_hdr, &vcd_property_codec); |
| 515 | } |
| 516 | |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 517 | static long venc_set_codec_level(struct video_client_ctx *client_ctx, |
| 518 | __s32 codec, __s32 level) |
| 519 | { |
| 520 | struct vcd_property_level vcd_property_level; |
| 521 | struct vcd_property_hdr vcd_property_hdr; |
| 522 | struct vcd_property_codec vcd_property_codec; |
| 523 | |
| 524 | int rc = 0; |
| 525 | int mpeg4_base = VCD_LEVEL_MPEG4_0; |
| 526 | int h264_base = VCD_LEVEL_H264_1; |
| 527 | |
| 528 | /* Validate params */ |
| 529 | vcd_property_hdr.prop_id = VCD_I_CODEC; |
| 530 | vcd_property_hdr.sz = sizeof(struct vcd_property_codec); |
| 531 | rc = vcd_get_property(client_ctx->vcd_handle, |
| 532 | &vcd_property_hdr, &vcd_property_codec); |
| 533 | |
| 534 | if (rc < 0) { |
| 535 | WFD_MSG_ERR("Error getting codec property"); |
| 536 | rc = -EINVAL; |
| 537 | goto err; |
| 538 | } |
| 539 | |
| 540 | if (!((vcd_property_codec.codec == VCD_CODEC_H264 |
| 541 | && codec == V4L2_CID_MPEG_VIDEO_H264_LEVEL) || |
| 542 | (vcd_property_codec.codec == VCD_CODEC_MPEG4 |
| 543 | && codec == V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL))) { |
| 544 | WFD_MSG_ERR("Attempting to set %d for codec type %d", |
| 545 | codec, vcd_property_codec.codec); |
| 546 | rc = -EINVAL; |
| 547 | goto err; |
| 548 | } |
| 549 | |
| 550 | /* Set property */ |
| 551 | vcd_property_hdr.prop_id = VCD_I_LEVEL; |
| 552 | vcd_property_hdr.sz = sizeof(struct vcd_property_level); |
| 553 | |
| 554 | if (codec == V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL) { |
| 555 | vcd_property_level.level = mpeg4_base + level; |
| 556 | |
| 557 | if (vcd_property_level.level < VCD_LEVEL_MPEG4_0 |
| 558 | || vcd_property_level.level > VCD_LEVEL_MPEG4_X) { |
Deva Ramasubramanian | 1efb995 | 2012-07-31 11:11:15 -0700 | [diff] [blame] | 559 | WFD_MSG_ERR("Level (%d) out of range for codec (%d)\n", |
| 560 | level, codec); |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 561 | |
| 562 | rc = -EINVAL; |
| 563 | goto err; |
| 564 | } |
| 565 | } else if (codec == V4L2_CID_MPEG_VIDEO_H264_LEVEL) { |
| 566 | vcd_property_level.level = h264_base + level; |
| 567 | |
| 568 | if (vcd_property_level.level < VCD_LEVEL_H264_1 |
| 569 | || vcd_property_level.level > VCD_LEVEL_H264_5p1) { |
Deva Ramasubramanian | 1efb995 | 2012-07-31 11:11:15 -0700 | [diff] [blame] | 570 | WFD_MSG_ERR("Level (%d) out of range for codec (%d)\n", |
| 571 | level, codec); |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 572 | |
| 573 | rc = -EINVAL; |
| 574 | goto err; |
| 575 | } |
| 576 | } else { |
| 577 | WFD_MSG_ERR("Codec (%d) not supported, not setting level (%d)", |
| 578 | codec, level); |
| 579 | rc = -ENOTSUPP; |
| 580 | goto err; |
| 581 | } |
| 582 | |
| 583 | rc = vcd_set_property(client_ctx->vcd_handle, |
| 584 | &vcd_property_hdr, &vcd_property_level); |
| 585 | err: |
| 586 | return rc; |
| 587 | } |
| 588 | |
| 589 | static long venc_get_codec_level(struct video_client_ctx *client_ctx, |
| 590 | __s32 codec, __s32 *level) |
| 591 | { |
| 592 | struct vcd_property_level vcd_property_level; |
| 593 | struct vcd_property_hdr vcd_property_hdr; |
| 594 | struct vcd_property_codec vcd_property_codec; |
| 595 | |
| 596 | int rc = 0; |
| 597 | int mpeg4_base = VCD_LEVEL_MPEG4_0; |
| 598 | int h264_base = VCD_LEVEL_H264_1; |
| 599 | |
| 600 | /* Validate params */ |
| 601 | vcd_property_hdr.prop_id = VCD_I_CODEC; |
| 602 | vcd_property_hdr.sz = sizeof(struct vcd_property_codec); |
| 603 | rc = vcd_get_property(client_ctx->vcd_handle, |
| 604 | &vcd_property_hdr, &vcd_property_codec); |
| 605 | |
| 606 | if (rc < 0) { |
| 607 | WFD_MSG_ERR("Error getting codec property"); |
| 608 | rc = -EINVAL; |
| 609 | goto err; |
| 610 | } |
| 611 | |
| 612 | if (!((vcd_property_codec.codec == VCD_CODEC_H264 |
| 613 | && codec == V4L2_CID_MPEG_VIDEO_H264_LEVEL) || |
| 614 | (vcd_property_codec.codec == VCD_CODEC_MPEG4 |
| 615 | && codec == V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL))) { |
| 616 | WFD_MSG_ERR("Attempting to get %d for codec type %d", |
| 617 | codec, vcd_property_codec.codec); |
| 618 | rc = -EINVAL; |
| 619 | goto err; |
| 620 | } |
| 621 | |
| 622 | vcd_property_hdr.prop_id = VCD_I_LEVEL; |
| 623 | vcd_property_hdr.sz = sizeof(struct vcd_property_level); |
| 624 | |
| 625 | rc = vcd_get_property(client_ctx->vcd_handle, |
| 626 | &vcd_property_hdr, &vcd_property_level); |
| 627 | if (rc < 0) { |
| 628 | rc = -EINVAL; |
| 629 | goto err; |
| 630 | } |
| 631 | |
| 632 | if (codec == V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL) { |
| 633 | *level = vcd_property_level.level - mpeg4_base; |
| 634 | } else if (codec == V4L2_CID_MPEG_VIDEO_H264_LEVEL) { |
| 635 | *level = vcd_property_level.level - h264_base; |
| 636 | } else { |
| 637 | WFD_MSG_ERR("Codec (%d) not supported", codec); |
| 638 | rc = -ENOTSUPP; |
| 639 | goto err; |
| 640 | } |
| 641 | |
| 642 | err: |
| 643 | return rc; |
| 644 | } |
| 645 | |
| 646 | static long venc_set_codec_profile(struct video_client_ctx *client_ctx, |
| 647 | __s32 codec, __s32 profile) |
| 648 | { |
| 649 | struct vcd_property_profile vcd_property_profile; |
| 650 | struct vcd_property_hdr vcd_property_hdr; |
| 651 | struct vcd_property_codec vcd_property_codec; |
Deva Ramasubramanian | 147c760 | 2012-04-29 14:46:58 -0700 | [diff] [blame] | 652 | struct vcd_property_i_period vcd_property_i_period; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 653 | int rc = 0; |
| 654 | |
| 655 | /* Validate params */ |
| 656 | vcd_property_hdr.prop_id = VCD_I_CODEC; |
| 657 | vcd_property_hdr.sz = sizeof(struct vcd_property_codec); |
| 658 | rc = vcd_get_property(client_ctx->vcd_handle, |
| 659 | &vcd_property_hdr, &vcd_property_codec); |
| 660 | |
| 661 | if (rc < 0) { |
| 662 | WFD_MSG_ERR("Error getting codec property"); |
| 663 | rc = -EINVAL; |
Deva Ramasubramanian | 147c760 | 2012-04-29 14:46:58 -0700 | [diff] [blame] | 664 | goto err_set_profile; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | if (!((vcd_property_codec.codec == VCD_CODEC_H264 |
| 668 | && codec == V4L2_CID_MPEG_VIDEO_H264_PROFILE) || |
| 669 | (vcd_property_codec.codec == VCD_CODEC_MPEG4 |
| 670 | && codec == V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE))) { |
| 671 | WFD_MSG_ERR("Attempting to set %d for codec type %d", |
| 672 | codec, vcd_property_codec.codec); |
| 673 | rc = -EINVAL; |
Deva Ramasubramanian | 147c760 | 2012-04-29 14:46:58 -0700 | [diff] [blame] | 674 | goto err_set_profile; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | /* Set property */ |
| 678 | vcd_property_hdr.prop_id = VCD_I_PROFILE; |
| 679 | vcd_property_hdr.sz = sizeof(struct vcd_property_profile); |
| 680 | |
| 681 | if (codec == V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE) { |
| 682 | switch (profile) { |
| 683 | case V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE: |
| 684 | vcd_property_profile.profile = VCD_PROFILE_MPEG4_SP; |
| 685 | break; |
| 686 | case V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE: |
| 687 | vcd_property_profile.profile = VCD_PROFILE_MPEG4_ASP; |
| 688 | break; |
| 689 | default: |
Deva Ramasubramanian | 1efb995 | 2012-07-31 11:11:15 -0700 | [diff] [blame] | 690 | WFD_MSG_ERR("Profile %d not supported, defaulting " \ |
| 691 | "to simple (%d)", profile, |
| 692 | VCD_PROFILE_MPEG4_SP); |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 693 | vcd_property_profile.profile = VCD_PROFILE_MPEG4_SP; |
| 694 | break; |
| 695 | } |
| 696 | } else if (codec == V4L2_CID_MPEG_VIDEO_H264_PROFILE) { |
| 697 | switch (profile) { |
| 698 | case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE: |
| 699 | vcd_property_profile.profile = |
| 700 | VCD_PROFILE_H264_BASELINE; |
| 701 | break; |
| 702 | case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN: |
| 703 | vcd_property_profile.profile = VCD_PROFILE_H264_MAIN; |
| 704 | break; |
| 705 | case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH: |
| 706 | vcd_property_profile.profile = VCD_PROFILE_H264_HIGH; |
| 707 | break; |
| 708 | default: |
Deva Ramasubramanian | 1efb995 | 2012-07-31 11:11:15 -0700 | [diff] [blame] | 709 | WFD_MSG_ERR("Profile %d not supported, defaulting " \ |
| 710 | "to baseline (%d)", profile, |
| 711 | VCD_PROFILE_H264_BASELINE); |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 712 | vcd_property_profile.profile = |
| 713 | VCD_PROFILE_H264_BASELINE; |
| 714 | break; |
| 715 | } |
| 716 | } else { |
Deva Ramasubramanian | 1efb995 | 2012-07-31 11:11:15 -0700 | [diff] [blame] | 717 | WFD_MSG_ERR("Codec (%d) not supported, not "\ |
| 718 | "setting profile (%d)", codec, profile); |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 719 | rc = -ENOTSUPP; |
Deva Ramasubramanian | 147c760 | 2012-04-29 14:46:58 -0700 | [diff] [blame] | 720 | goto err_set_profile; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | rc = vcd_set_property(client_ctx->vcd_handle, |
| 724 | &vcd_property_hdr, &vcd_property_profile); |
Deva Ramasubramanian | 147c760 | 2012-04-29 14:46:58 -0700 | [diff] [blame] | 725 | |
| 726 | /* Disable B-frames, since VSG doesn't support out of order i/p bufs */ |
| 727 | vcd_property_hdr.prop_id = VCD_I_INTRA_PERIOD; |
| 728 | vcd_property_hdr.sz = sizeof(struct vcd_property_i_period); |
| 729 | |
| 730 | rc = vcd_get_property(client_ctx->vcd_handle, |
| 731 | &vcd_property_hdr, &vcd_property_i_period); |
| 732 | if (rc) { |
| 733 | WFD_MSG_ERR("Error getting I-period property"); |
| 734 | goto err_set_profile; |
| 735 | } |
| 736 | vcd_property_i_period.b_frames = 0; |
| 737 | rc = vcd_set_property(client_ctx->vcd_handle, |
| 738 | &vcd_property_hdr, &vcd_property_i_period); |
| 739 | if (rc) { |
| 740 | WFD_MSG_ERR("Error setting I-period property"); |
| 741 | goto err_set_profile; |
| 742 | } |
| 743 | |
| 744 | err_set_profile: |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 745 | return rc; |
| 746 | } |
| 747 | |
| 748 | static long venc_get_codec_profile(struct video_client_ctx *client_ctx, |
| 749 | __s32 codec, __s32 *profile) |
| 750 | { |
| 751 | struct vcd_property_profile vcd_property_profile; |
| 752 | struct vcd_property_hdr vcd_property_hdr; |
| 753 | struct vcd_property_codec vcd_property_codec; |
| 754 | int rc = 0; |
| 755 | |
| 756 | /* Validate params */ |
| 757 | vcd_property_hdr.prop_id = VCD_I_CODEC; |
| 758 | vcd_property_hdr.sz = sizeof(struct vcd_property_codec); |
| 759 | rc = vcd_get_property(client_ctx->vcd_handle, |
| 760 | &vcd_property_hdr, &vcd_property_codec); |
| 761 | |
| 762 | if (rc < 0) { |
| 763 | WFD_MSG_ERR("Error getting codec property"); |
| 764 | rc = -EINVAL; |
| 765 | goto err; |
| 766 | } |
| 767 | |
| 768 | if (!((vcd_property_codec.codec == VCD_CODEC_H264 |
| 769 | && codec == V4L2_CID_MPEG_VIDEO_H264_PROFILE) || |
| 770 | (vcd_property_codec.codec == VCD_CODEC_MPEG4 |
| 771 | && codec == V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE))) { |
| 772 | WFD_MSG_ERR("Attempting to set %d for codec type %d", |
| 773 | codec, vcd_property_codec.codec); |
| 774 | rc = -EINVAL; |
| 775 | goto err; |
| 776 | } |
| 777 | |
| 778 | /* Set property */ |
| 779 | vcd_property_hdr.prop_id = VCD_I_PROFILE; |
| 780 | vcd_property_hdr.sz = sizeof(struct vcd_property_profile); |
| 781 | |
| 782 | rc = vcd_get_property(client_ctx->vcd_handle, |
| 783 | &vcd_property_hdr, &vcd_property_profile); |
| 784 | |
| 785 | if (rc < 0) { |
| 786 | WFD_MSG_ERR("Unable to get property"); |
| 787 | rc = -EINVAL; |
| 788 | goto err; |
| 789 | } |
| 790 | |
| 791 | switch (vcd_property_profile.profile) { |
| 792 | case VCD_PROFILE_MPEG4_SP: |
| 793 | *profile = V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE; |
| 794 | break; |
| 795 | case VCD_PROFILE_MPEG4_ASP: |
| 796 | *profile = V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE; |
| 797 | break; |
| 798 | case VCD_PROFILE_H264_BASELINE: |
| 799 | *profile = V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE; |
| 800 | break; |
| 801 | case VCD_PROFILE_H264_MAIN: |
| 802 | *profile = V4L2_MPEG_VIDEO_H264_PROFILE_MAIN; |
| 803 | break; |
| 804 | case VCD_PROFILE_H264_HIGH: |
| 805 | *profile = V4L2_MPEG_VIDEO_H264_PROFILE_HIGH; |
| 806 | break; |
| 807 | default: |
| 808 | WFD_MSG_ERR("Unexpected profile"); |
| 809 | rc = -EINVAL; |
| 810 | goto err; |
| 811 | break; |
| 812 | } |
| 813 | err: |
| 814 | return rc; |
| 815 | } |
| 816 | |
| 817 | static long venc_set_h264_intra_period(struct video_client_ctx *client_ctx, |
Deva Ramasubramanian | 3f2e602 | 2012-02-06 15:02:51 -0800 | [diff] [blame] | 818 | __s32 period) |
| 819 | { |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 820 | struct vcd_property_i_period vcd_property_i_period; |
| 821 | struct vcd_property_codec vcd_property_codec; |
| 822 | struct vcd_property_hdr vcd_property_hdr; |
| 823 | int rc = 0; |
| 824 | |
| 825 | vcd_property_hdr.prop_id = VCD_I_CODEC; |
| 826 | vcd_property_hdr.sz = sizeof(struct vcd_property_codec); |
| 827 | |
| 828 | rc = vcd_get_property(client_ctx->vcd_handle, |
| 829 | &vcd_property_hdr, &vcd_property_codec); |
| 830 | |
| 831 | if (rc < 0) { |
| 832 | WFD_MSG_ERR("Error getting codec property\n"); |
| 833 | goto err; |
| 834 | } |
| 835 | |
| 836 | if (vcd_property_codec.codec != VCD_CODEC_H264) { |
| 837 | rc = -ENOTSUPP; |
| 838 | WFD_MSG_ERR("Control not supported for non H264 codec\n"); |
| 839 | goto err; |
| 840 | } |
| 841 | |
| 842 | vcd_property_hdr.prop_id = VCD_I_INTRA_PERIOD; |
| 843 | vcd_property_hdr.sz = sizeof(struct vcd_property_i_period); |
| 844 | |
| 845 | vcd_property_i_period.p_frames = period - 1; |
Deva Ramasubramanian | 3f2e602 | 2012-02-06 15:02:51 -0800 | [diff] [blame] | 846 | vcd_property_i_period.b_frames = 0; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 847 | |
| 848 | rc = vcd_set_property(client_ctx->vcd_handle, |
| 849 | &vcd_property_hdr, &vcd_property_i_period); |
| 850 | |
| 851 | if (rc < 0) { |
| 852 | WFD_MSG_ERR("Error setting intra period\n"); |
| 853 | goto err; |
| 854 | } |
| 855 | |
| 856 | err: |
| 857 | return rc; |
| 858 | } |
| 859 | |
Deva Ramasubramanian | 3f2e602 | 2012-02-06 15:02:51 -0800 | [diff] [blame] | 860 | static long venc_get_h264_intra_period(struct video_client_ctx *client_ctx, |
| 861 | __s32 *period) |
| 862 | { |
| 863 | struct vcd_property_i_period vcd_property_i_period; |
| 864 | struct vcd_property_codec vcd_property_codec; |
| 865 | struct vcd_property_hdr vcd_property_hdr; |
| 866 | int rc = 0; |
| 867 | |
| 868 | vcd_property_hdr.prop_id = VCD_I_CODEC; |
| 869 | vcd_property_hdr.sz = sizeof(struct vcd_property_codec); |
| 870 | |
| 871 | rc = vcd_get_property(client_ctx->vcd_handle, |
| 872 | &vcd_property_hdr, &vcd_property_codec); |
| 873 | |
| 874 | if (rc < 0) { |
| 875 | WFD_MSG_ERR("Error getting codec property\n"); |
| 876 | goto err; |
| 877 | } |
| 878 | |
| 879 | if (vcd_property_codec.codec != VCD_CODEC_H264) { |
| 880 | rc = -ENOTSUPP; |
| 881 | WFD_MSG_ERR("Control not supported for non H264 codec\n"); |
| 882 | goto err; |
| 883 | } |
| 884 | |
| 885 | vcd_property_hdr.prop_id = VCD_I_INTRA_PERIOD; |
| 886 | vcd_property_hdr.sz = sizeof(struct vcd_property_i_period); |
| 887 | |
| 888 | rc = vcd_get_property(client_ctx->vcd_handle, |
| 889 | &vcd_property_hdr, &vcd_property_i_period); |
| 890 | |
| 891 | if (rc < 0) { |
| 892 | WFD_MSG_ERR("Error getting intra period\n"); |
| 893 | goto err; |
| 894 | } |
| 895 | |
| 896 | *period = vcd_property_i_period.p_frames + 1; |
| 897 | err: |
| 898 | return rc; |
| 899 | } |
| 900 | |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 901 | static long venc_request_frame(struct video_client_ctx *client_ctx, __s32 type) |
| 902 | { |
| 903 | struct vcd_property_req_i_frame vcd_property_req_i_frame; |
| 904 | struct vcd_property_hdr vcd_property_hdr; |
| 905 | |
| 906 | int rc = 0; |
| 907 | switch (type) { |
| 908 | case V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_DISABLED: |
| 909 | /*So...nothing to do?*/ |
| 910 | break; |
| 911 | case V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_I_FRAME: |
| 912 | vcd_property_hdr.prop_id = VCD_I_REQ_IFRAME; |
| 913 | vcd_property_hdr.sz = sizeof(struct vcd_property_req_i_frame); |
| 914 | vcd_property_req_i_frame.req_i_frame = 1; |
| 915 | |
| 916 | rc = vcd_set_property(client_ctx->vcd_handle, |
| 917 | &vcd_property_hdr, &vcd_property_req_i_frame); |
| 918 | break; |
| 919 | case V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_NOT_CODED: |
| 920 | default: |
| 921 | rc = -ENOTSUPP; |
| 922 | } |
| 923 | |
| 924 | return rc; |
| 925 | } |
| 926 | |
| 927 | static long venc_set_bitrate(struct video_client_ctx *client_ctx, |
| 928 | __s32 bitrate) |
| 929 | { |
| 930 | struct vcd_property_hdr vcd_property_hdr; |
| 931 | struct vcd_property_target_bitrate bit_rate; |
| 932 | if (!client_ctx || !bitrate) |
| 933 | return -EINVAL; |
| 934 | |
| 935 | vcd_property_hdr.prop_id = VCD_I_TARGET_BITRATE; |
| 936 | vcd_property_hdr.sz = |
| 937 | sizeof(struct vcd_property_target_bitrate); |
| 938 | bit_rate.target_bitrate = bitrate; |
| 939 | return vcd_set_property(client_ctx->vcd_handle, |
| 940 | &vcd_property_hdr, &bit_rate); |
| 941 | } |
| 942 | |
| 943 | static long venc_get_bitrate(struct video_client_ctx *client_ctx, |
| 944 | __s32 *bitrate) |
| 945 | { |
| 946 | struct vcd_property_hdr vcd_property_hdr; |
| 947 | struct vcd_property_target_bitrate bit_rate; |
| 948 | int rc = 0; |
| 949 | |
| 950 | if (!client_ctx || !bitrate) |
| 951 | return -EINVAL; |
| 952 | |
| 953 | vcd_property_hdr.prop_id = VCD_I_TARGET_BITRATE; |
| 954 | vcd_property_hdr.sz = |
| 955 | sizeof(struct vcd_property_target_bitrate); |
| 956 | rc = vcd_get_property(client_ctx->vcd_handle, |
| 957 | &vcd_property_hdr, &bit_rate); |
| 958 | |
| 959 | if (rc < 0) { |
| 960 | WFD_MSG_ERR("Failed getting property for bitrate"); |
| 961 | return rc; |
| 962 | } |
| 963 | |
| 964 | *bitrate = bit_rate.target_bitrate; |
| 965 | return rc; |
| 966 | } |
| 967 | |
| 968 | static long venc_set_bitrate_mode(struct video_client_ctx *client_ctx, |
| 969 | __s32 mode) |
| 970 | { |
| 971 | struct vcd_property_hdr vcd_property_hdr; |
| 972 | struct vcd_property_rate_control rate_control; |
| 973 | int rc = 0; |
| 974 | |
| 975 | if (!client_ctx) { |
| 976 | rc = -EINVAL; |
| 977 | goto err; |
| 978 | } |
| 979 | |
| 980 | vcd_property_hdr.prop_id = VCD_I_RATE_CONTROL; |
| 981 | vcd_property_hdr.sz = sizeof(struct vcd_property_rate_control); |
| 982 | /* |
| 983 | * XXX: V4L doesn't seem have a control to toggle between CFR |
| 984 | * and VFR, so assuming worse case VFR. |
| 985 | */ |
| 986 | switch (mode) { |
| 987 | case V4L2_MPEG_VIDEO_BITRATE_MODE_VBR: |
| 988 | rate_control.rate_control = VCD_RATE_CONTROL_VBR_VFR; |
| 989 | break; |
| 990 | case V4L2_MPEG_VIDEO_BITRATE_MODE_CBR: |
| 991 | rate_control.rate_control = VCD_RATE_CONTROL_CBR_VFR; |
| 992 | break; |
| 993 | default: |
| 994 | WFD_MSG_ERR("unknown bitrate mode %d", mode); |
| 995 | rc = -EINVAL; |
| 996 | goto err; |
| 997 | } |
| 998 | |
| 999 | rc = vcd_set_property(client_ctx->vcd_handle, |
| 1000 | &vcd_property_hdr, &rate_control); |
| 1001 | err: |
| 1002 | return rc; |
| 1003 | } |
| 1004 | |
| 1005 | static long venc_get_bitrate_mode(struct video_client_ctx *client_ctx, |
| 1006 | __s32 *mode) |
| 1007 | { |
| 1008 | struct vcd_property_hdr vcd_property_hdr; |
| 1009 | struct vcd_property_rate_control rate_control; |
| 1010 | int rc = 0; |
| 1011 | |
| 1012 | if (!client_ctx) |
| 1013 | return -EINVAL; |
| 1014 | |
| 1015 | vcd_property_hdr.prop_id = VCD_I_RATE_CONTROL; |
| 1016 | vcd_property_hdr.sz = sizeof(struct vcd_property_rate_control); |
| 1017 | rc = vcd_get_property(client_ctx->vcd_handle, |
| 1018 | &vcd_property_hdr, &rate_control); |
| 1019 | |
| 1020 | switch (rate_control.rate_control) { |
| 1021 | case VCD_RATE_CONTROL_CBR_VFR: |
| 1022 | case VCD_RATE_CONTROL_CBR_CFR: |
| 1023 | *mode = V4L2_MPEG_VIDEO_BITRATE_MODE_CBR; |
| 1024 | break; |
| 1025 | case VCD_RATE_CONTROL_VBR_VFR: |
| 1026 | case VCD_RATE_CONTROL_VBR_CFR: |
| 1027 | *mode = V4L2_MPEG_VIDEO_BITRATE_MODE_VBR; |
| 1028 | break; |
| 1029 | default: |
| 1030 | WFD_MSG_ERR("unknown bitrate mode %d", |
| 1031 | rate_control.rate_control); |
| 1032 | return -EINVAL; |
| 1033 | } |
| 1034 | |
| 1035 | return 0; |
| 1036 | } |
| 1037 | |
| 1038 | static long venc_set_frame_size(struct video_client_ctx *client_ctx, |
| 1039 | u32 height, u32 width) |
| 1040 | { |
| 1041 | struct vcd_property_hdr vcd_property_hdr; |
| 1042 | struct vcd_property_frame_size frame_size; |
| 1043 | vcd_property_hdr.prop_id = VCD_I_FRAME_SIZE; |
| 1044 | vcd_property_hdr.sz = |
| 1045 | sizeof(struct vcd_property_frame_size); |
| 1046 | frame_size.height = height; |
| 1047 | frame_size.width = width; |
| 1048 | return vcd_set_property(client_ctx->vcd_handle, |
| 1049 | &vcd_property_hdr, &frame_size); |
| 1050 | } |
| 1051 | |
| 1052 | static long venc_set_format(struct v4l2_subdev *sd, void *arg) |
| 1053 | { |
| 1054 | struct venc_inst *inst; |
| 1055 | struct video_client_ctx *client_ctx; |
| 1056 | struct v4l2_format *fmt = arg; |
| 1057 | struct vcd_buffer_requirement buf_req; |
| 1058 | int rc = 0; |
| 1059 | |
| 1060 | inst = sd->dev_priv; |
| 1061 | client_ctx = &inst->venc_client; |
| 1062 | if (!inst || !client_ctx || !fmt) { |
| 1063 | WFD_MSG_ERR("Invalid parameters\n"); |
| 1064 | return -EINVAL; |
| 1065 | } |
Deva Ramasubramanian | c34de06 | 2012-01-25 14:42:58 -0800 | [diff] [blame] | 1066 | rc = venc_set_codec(client_ctx, fmt->fmt.pix.pixelformat); |
| 1067 | if (rc) { |
| 1068 | WFD_MSG_ERR("Failed to set codec, rc = %d\n", rc); |
| 1069 | goto err; |
| 1070 | } |
| 1071 | |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 1072 | rc = venc_set_frame_size(client_ctx, fmt->fmt.pix.height, |
| 1073 | fmt->fmt.pix.width); |
| 1074 | if (rc) { |
| 1075 | WFD_MSG_ERR("Failed to set frame size, rc = %d\n", rc); |
| 1076 | goto err; |
| 1077 | } |
| 1078 | rc = vcd_get_buffer_requirements(client_ctx->vcd_handle, |
| 1079 | VCD_BUFFER_OUTPUT, &buf_req); |
| 1080 | if (rc) { |
| 1081 | WFD_MSG_ERR("Failed to get buf requrements, rc = %d\n", rc); |
| 1082 | goto err; |
| 1083 | } |
| 1084 | fmt->fmt.pix.sizeimage = buf_req.sz; |
| 1085 | err: |
| 1086 | return rc; |
| 1087 | } |
| 1088 | |
| 1089 | static long venc_set_framerate(struct v4l2_subdev *sd, |
| 1090 | void *arg) |
| 1091 | { |
| 1092 | struct venc_inst *inst = sd->dev_priv; |
| 1093 | struct video_client_ctx *client_ctx = &inst->venc_client; |
| 1094 | struct v4l2_fract *frate = arg; |
| 1095 | struct vcd_property_hdr vcd_property_hdr; |
| 1096 | struct vcd_property_frame_rate vcd_frame_rate; |
Deva Ramasubramanian | 4947d8c | 2012-04-03 12:41:06 -0700 | [diff] [blame] | 1097 | struct vcd_property_vop_timing_constant_delta vcd_delta; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 1098 | int rc; |
| 1099 | vcd_property_hdr.prop_id = VCD_I_FRAME_RATE; |
| 1100 | vcd_property_hdr.sz = |
| 1101 | sizeof(struct vcd_property_frame_rate); |
Deva Ramasubramanian | b84fc50 | 2012-01-16 11:42:58 -0800 | [diff] [blame] | 1102 | /* v4l2 passes in "fps" as "spf", so take reciprocal*/ |
| 1103 | vcd_frame_rate.fps_denominator = frate->numerator; |
| 1104 | vcd_frame_rate.fps_numerator = frate->denominator; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 1105 | rc = vcd_set_property(client_ctx->vcd_handle, |
| 1106 | &vcd_property_hdr, &vcd_frame_rate); |
Deva Ramasubramanian | 4947d8c | 2012-04-03 12:41:06 -0700 | [diff] [blame] | 1107 | if (rc) { |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 1108 | WFD_MSG_ERR("Failed to set frame rate, rc = %d\n", rc); |
Deva Ramasubramanian | 4947d8c | 2012-04-03 12:41:06 -0700 | [diff] [blame] | 1109 | goto set_framerate_fail; |
| 1110 | } |
| 1111 | |
| 1112 | vcd_property_hdr.prop_id = VCD_I_VOP_TIMING_CONSTANT_DELTA; |
| 1113 | vcd_property_hdr.sz = sizeof(vcd_delta); |
| 1114 | |
| 1115 | vcd_delta.constant_delta = (frate->numerator * USEC_PER_SEC) / |
| 1116 | frate->denominator; |
| 1117 | rc = vcd_set_property(client_ctx->vcd_handle, |
| 1118 | &vcd_property_hdr, &vcd_delta); |
| 1119 | |
| 1120 | if (rc) { |
| 1121 | WFD_MSG_ERR("Failed to set frame delta, rc = %d", rc); |
| 1122 | goto set_framerate_fail; |
| 1123 | } |
| 1124 | |
| 1125 | set_framerate_fail: |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 1126 | return rc; |
| 1127 | } |
| 1128 | |
Srinu Gorle | 4f8bc3a | 2012-11-15 09:36:38 +0530 | [diff] [blame] | 1129 | static long venc_set_framerate_mode(struct v4l2_subdev *sd, |
| 1130 | void *arg) |
| 1131 | { |
| 1132 | struct venc_inst *inst = sd->dev_priv; |
| 1133 | inst->framerate_mode = *(enum venc_framerate_modes *)arg; |
| 1134 | return 0; |
| 1135 | } |
| 1136 | |
Deva Ramasubramanian | 3f2e602 | 2012-02-06 15:02:51 -0800 | [diff] [blame] | 1137 | static long venc_set_qp_value(struct video_client_ctx *client_ctx, |
| 1138 | __s32 frametype, __s32 qp) |
| 1139 | { |
| 1140 | struct vcd_property_hdr vcd_property_hdr; |
| 1141 | struct vcd_property_session_qp vcd_property_session_qp; |
| 1142 | int rc = 0; |
| 1143 | |
| 1144 | if (!client_ctx) { |
| 1145 | WFD_MSG_ERR("Invalid parameters\n"); |
| 1146 | return -EINVAL; |
| 1147 | } |
| 1148 | |
| 1149 | vcd_property_hdr.prop_id = VCD_I_SESSION_QP; |
| 1150 | vcd_property_hdr.sz = sizeof(vcd_property_session_qp); |
| 1151 | |
| 1152 | rc = vcd_get_property(client_ctx->vcd_handle, &vcd_property_hdr, |
| 1153 | &vcd_property_session_qp); |
| 1154 | |
| 1155 | if (rc) { |
| 1156 | WFD_MSG_ERR("Failed to get session qp\n"); |
| 1157 | goto err; |
| 1158 | } |
| 1159 | |
| 1160 | switch (frametype) { |
| 1161 | case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP: |
| 1162 | vcd_property_session_qp.i_frame_qp = qp; |
| 1163 | break; |
| 1164 | case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP: |
| 1165 | vcd_property_session_qp.p_frame_qp = qp; |
| 1166 | break; |
| 1167 | case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP: |
| 1168 | vcd_property_session_qp.b_frame_qp = qp; |
| 1169 | break; |
| 1170 | case V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP: |
| 1171 | case V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP: |
| 1172 | case V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP: |
| 1173 | case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP: |
| 1174 | case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP: |
| 1175 | case V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP: |
| 1176 | rc = -ENOTSUPP; |
| 1177 | goto err; |
| 1178 | default: |
| 1179 | rc = -EINVAL; |
| 1180 | goto err; |
| 1181 | } |
| 1182 | |
| 1183 | |
| 1184 | rc = vcd_set_property(client_ctx->vcd_handle, &vcd_property_hdr, |
| 1185 | &vcd_property_session_qp); |
| 1186 | |
| 1187 | if (rc) { |
| 1188 | WFD_MSG_ERR("Failed to set session qp\n"); |
| 1189 | goto err; |
| 1190 | } |
| 1191 | err: |
| 1192 | return rc; |
| 1193 | } |
| 1194 | |
| 1195 | static long venc_get_qp_value(struct video_client_ctx *client_ctx, |
| 1196 | __s32 frametype, __s32 *qp) |
| 1197 | { |
| 1198 | struct vcd_property_hdr vcd_property_hdr; |
| 1199 | struct vcd_property_session_qp vcd_property_session_qp; |
| 1200 | int rc = 0; |
| 1201 | |
| 1202 | if (!client_ctx) { |
| 1203 | WFD_MSG_ERR("Invalid parameters\n"); |
| 1204 | return -EINVAL; |
| 1205 | } |
| 1206 | |
| 1207 | vcd_property_hdr.prop_id = VCD_I_SESSION_QP; |
| 1208 | vcd_property_hdr.sz = sizeof(vcd_property_session_qp); |
| 1209 | |
| 1210 | rc = vcd_get_property(client_ctx->vcd_handle, &vcd_property_hdr, |
| 1211 | &vcd_property_session_qp); |
| 1212 | |
| 1213 | if (rc) { |
| 1214 | WFD_MSG_ERR("Failed to get session qp\n"); |
| 1215 | goto err; |
| 1216 | } |
| 1217 | |
| 1218 | switch (frametype) { |
| 1219 | case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP: |
| 1220 | case V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP: |
| 1221 | case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP: |
| 1222 | *qp = vcd_property_session_qp.i_frame_qp; |
| 1223 | break; |
| 1224 | case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP: |
| 1225 | case V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP: |
| 1226 | case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP: |
| 1227 | *qp = vcd_property_session_qp.p_frame_qp; |
| 1228 | break; |
| 1229 | case V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP: |
| 1230 | case V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP: |
| 1231 | case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP: |
| 1232 | *qp = vcd_property_session_qp.b_frame_qp; |
| 1233 | break; |
| 1234 | default: |
| 1235 | rc = -EINVAL; |
| 1236 | goto err; |
| 1237 | } |
| 1238 | |
| 1239 | err: |
| 1240 | return rc; |
| 1241 | } |
| 1242 | |
| 1243 | static long venc_set_qp_range(struct video_client_ctx *client_ctx, |
| 1244 | __s32 type, __s32 qp) |
| 1245 | { |
| 1246 | struct vcd_property_hdr vcd_property_hdr; |
| 1247 | struct vcd_property_qp_range vcd_property_qp_range; |
| 1248 | int rc = 0; |
| 1249 | |
| 1250 | if (!client_ctx) { |
| 1251 | WFD_MSG_ERR("Invalid parameters\n"); |
| 1252 | return -EINVAL; |
| 1253 | } |
| 1254 | |
| 1255 | vcd_property_hdr.prop_id = VCD_I_QP_RANGE; |
| 1256 | vcd_property_hdr.sz = sizeof(vcd_property_qp_range); |
| 1257 | |
| 1258 | rc = vcd_get_property(client_ctx->vcd_handle, &vcd_property_hdr, |
| 1259 | &vcd_property_qp_range); |
| 1260 | |
| 1261 | if (rc) { |
| 1262 | WFD_MSG_ERR("Failed to get qp range\n"); |
| 1263 | goto err; |
| 1264 | } |
| 1265 | |
| 1266 | switch (type) { |
| 1267 | case V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP: |
| 1268 | case V4L2_CID_MPEG_VIDEO_H263_MIN_QP: |
| 1269 | case V4L2_CID_MPEG_VIDEO_H264_MIN_QP: |
| 1270 | vcd_property_qp_range.min_qp = qp; |
| 1271 | break; |
| 1272 | case V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP: |
| 1273 | case V4L2_CID_MPEG_VIDEO_H263_MAX_QP: |
| 1274 | case V4L2_CID_MPEG_VIDEO_H264_MAX_QP: |
| 1275 | vcd_property_qp_range.max_qp = qp; |
| 1276 | break; |
| 1277 | default: |
| 1278 | rc = -EINVAL; |
| 1279 | goto err; |
| 1280 | } |
| 1281 | |
| 1282 | rc = vcd_set_property(client_ctx->vcd_handle, &vcd_property_hdr, |
| 1283 | &vcd_property_qp_range); |
| 1284 | |
| 1285 | if (rc) { |
| 1286 | WFD_MSG_ERR("Failed to set qp range\n"); |
| 1287 | goto err; |
| 1288 | } |
| 1289 | err: |
| 1290 | return rc; |
| 1291 | } |
| 1292 | |
| 1293 | static long venc_get_qp_range(struct video_client_ctx *client_ctx, |
| 1294 | __s32 type, __s32 *qp) |
| 1295 | { |
| 1296 | struct vcd_property_hdr vcd_property_hdr; |
| 1297 | struct vcd_property_qp_range vcd_property_qp_range; |
| 1298 | int rc = 0; |
| 1299 | |
| 1300 | if (!client_ctx) { |
| 1301 | WFD_MSG_ERR("Invalid parameters\n"); |
| 1302 | return -EINVAL; |
| 1303 | } |
| 1304 | |
| 1305 | vcd_property_hdr.prop_id = VCD_I_QP_RANGE; |
| 1306 | vcd_property_hdr.sz = sizeof(vcd_property_qp_range); |
| 1307 | |
| 1308 | rc = vcd_get_property(client_ctx->vcd_handle, &vcd_property_hdr, |
| 1309 | &vcd_property_qp_range); |
| 1310 | |
| 1311 | if (rc) { |
| 1312 | WFD_MSG_ERR("Failed to get qp range\n"); |
| 1313 | goto err; |
| 1314 | } |
| 1315 | |
| 1316 | switch (type) { |
| 1317 | case V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP: |
| 1318 | case V4L2_CID_MPEG_VIDEO_H263_MIN_QP: |
| 1319 | case V4L2_CID_MPEG_VIDEO_H264_MIN_QP: |
| 1320 | *qp = vcd_property_qp_range.min_qp; |
| 1321 | break; |
| 1322 | case V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP: |
| 1323 | case V4L2_CID_MPEG_VIDEO_H263_MAX_QP: |
| 1324 | case V4L2_CID_MPEG_VIDEO_H264_MAX_QP: |
| 1325 | *qp = vcd_property_qp_range.max_qp; |
| 1326 | break; |
| 1327 | default: |
| 1328 | rc = -EINVAL; |
| 1329 | goto err; |
| 1330 | } |
| 1331 | |
| 1332 | rc = vcd_set_property(client_ctx->vcd_handle, &vcd_property_hdr, |
| 1333 | &vcd_property_qp_range); |
| 1334 | |
| 1335 | if (rc) { |
| 1336 | WFD_MSG_ERR("Failed to set qp range\n"); |
| 1337 | goto err; |
| 1338 | } |
| 1339 | err: |
| 1340 | return rc; |
| 1341 | } |
Vinay Kalia | 700f5c2 | 2012-03-28 17:35:28 -0700 | [diff] [blame] | 1342 | static long venc_set_max_perf_level(struct video_client_ctx *client_ctx, |
Deva Ramasubramanian | 837ae36 | 2012-05-12 23:26:53 -0700 | [diff] [blame] | 1343 | __s32 value) |
Vinay Kalia | 700f5c2 | 2012-03-28 17:35:28 -0700 | [diff] [blame] | 1344 | { |
| 1345 | int rc = 0; |
| 1346 | struct vcd_property_hdr vcd_property_hdr; |
| 1347 | struct vcd_property_perf_level perf; |
Deva Ramasubramanian | 837ae36 | 2012-05-12 23:26:53 -0700 | [diff] [blame] | 1348 | int level = 0; |
| 1349 | |
| 1350 | switch (value) { |
| 1351 | case V4L2_CID_MPEG_QCOM_PERF_LEVEL_PERFORMANCE: |
| 1352 | level = VCD_PERF_LEVEL2; |
| 1353 | break; |
| 1354 | case V4L2_CID_MPEG_QCOM_PERF_LEVEL_TURBO: |
| 1355 | level = VCD_PERF_LEVEL_TURBO; |
| 1356 | break; |
| 1357 | default: |
| 1358 | WFD_MSG_ERR("Unknown performance level: %d\n", value); |
| 1359 | rc = -ENOTSUPP; |
| 1360 | goto err_set_perf_level; |
| 1361 | } |
| 1362 | |
Vinay Kalia | 700f5c2 | 2012-03-28 17:35:28 -0700 | [diff] [blame] | 1363 | vcd_property_hdr.prop_id = VCD_REQ_PERF_LEVEL; |
| 1364 | vcd_property_hdr.sz = |
| 1365 | sizeof(struct vcd_property_perf_level); |
Deva Ramasubramanian | 837ae36 | 2012-05-12 23:26:53 -0700 | [diff] [blame] | 1366 | perf.level = level; |
Vinay Kalia | 700f5c2 | 2012-03-28 17:35:28 -0700 | [diff] [blame] | 1367 | rc = vcd_set_property(client_ctx->vcd_handle, |
| 1368 | &vcd_property_hdr, &perf); |
Deva Ramasubramanian | 837ae36 | 2012-05-12 23:26:53 -0700 | [diff] [blame] | 1369 | err_set_perf_level: |
Vinay Kalia | 700f5c2 | 2012-03-28 17:35:28 -0700 | [diff] [blame] | 1370 | return rc; |
| 1371 | } |
Srinu Gorle | efe5bf3 | 2012-09-05 13:02:13 +0530 | [diff] [blame] | 1372 | |
| 1373 | static long venc_set_avc_delimiter(struct video_client_ctx *client_ctx, |
| 1374 | __s32 flag) |
| 1375 | { |
| 1376 | struct vcd_property_hdr vcd_property_hdr; |
| 1377 | struct vcd_property_avc_delimiter_enable delimiter_flag; |
| 1378 | if (!client_ctx) |
| 1379 | return -EINVAL; |
| 1380 | |
| 1381 | vcd_property_hdr.prop_id = VCD_I_ENABLE_DELIMITER_FLAG; |
| 1382 | vcd_property_hdr.sz = |
| 1383 | sizeof(struct vcd_property_avc_delimiter_enable); |
| 1384 | delimiter_flag.avc_delimiter_enable_flag = flag; |
| 1385 | return vcd_set_property(client_ctx->vcd_handle, |
| 1386 | &vcd_property_hdr, &delimiter_flag); |
| 1387 | } |
| 1388 | |
| 1389 | static long venc_get_avc_delimiter(struct video_client_ctx *client_ctx, |
| 1390 | __s32 *flag) |
| 1391 | { |
| 1392 | struct vcd_property_hdr vcd_property_hdr; |
| 1393 | struct vcd_property_avc_delimiter_enable delimiter_flag; |
| 1394 | int rc = 0; |
| 1395 | |
| 1396 | if (!client_ctx || !flag) |
| 1397 | return -EINVAL; |
| 1398 | |
| 1399 | vcd_property_hdr.prop_id = VCD_I_ENABLE_DELIMITER_FLAG; |
| 1400 | vcd_property_hdr.sz = |
| 1401 | sizeof(struct vcd_property_avc_delimiter_enable); |
| 1402 | rc = vcd_get_property(client_ctx->vcd_handle, |
| 1403 | &vcd_property_hdr, &delimiter_flag); |
| 1404 | |
| 1405 | if (rc < 0) { |
| 1406 | WFD_MSG_ERR("Failed getting property for delimiter"); |
| 1407 | return rc; |
| 1408 | } |
| 1409 | |
| 1410 | *flag = delimiter_flag.avc_delimiter_enable_flag; |
| 1411 | return rc; |
| 1412 | } |
| 1413 | |
Srinu Gorle | 4f8bc3a | 2012-11-15 09:36:38 +0530 | [diff] [blame] | 1414 | static long venc_set_vui_timing_info(struct video_client_ctx *client_ctx, |
| 1415 | struct venc_inst *inst, __s32 flag) |
| 1416 | { |
| 1417 | struct vcd_property_hdr vcd_property_hdr; |
| 1418 | struct vcd_property_vui_timing_info_enable vui_timing_info_enable; |
| 1419 | |
| 1420 | if (!client_ctx) |
| 1421 | return -EINVAL; |
| 1422 | if (inst->framerate_mode == VENC_MODE_VFR) { |
| 1423 | WFD_MSG_ERR("VUI timing info not suported in VFR mode "); |
| 1424 | return -EINVAL; |
| 1425 | } |
| 1426 | vcd_property_hdr.prop_id = VCD_I_ENABLE_VUI_TIMING_INFO; |
| 1427 | vcd_property_hdr.sz = |
| 1428 | sizeof(struct vcd_property_vui_timing_info_enable); |
| 1429 | vui_timing_info_enable.vui_timing_info = flag; |
| 1430 | return vcd_set_property(client_ctx->vcd_handle, |
| 1431 | &vcd_property_hdr, &vui_timing_info_enable); |
| 1432 | } |
| 1433 | |
| 1434 | static long venc_get_vui_timing_info(struct video_client_ctx *client_ctx, |
| 1435 | __s32 *flag) |
| 1436 | { |
| 1437 | struct vcd_property_hdr vcd_property_hdr; |
| 1438 | struct vcd_property_vui_timing_info_enable vui_timing_info_enable; |
| 1439 | int rc = 0; |
| 1440 | |
| 1441 | if (!client_ctx || !flag) |
| 1442 | return -EINVAL; |
| 1443 | |
| 1444 | vcd_property_hdr.prop_id = VCD_I_ENABLE_VUI_TIMING_INFO; |
| 1445 | vcd_property_hdr.sz = |
| 1446 | sizeof(struct vcd_property_vui_timing_info_enable); |
| 1447 | rc = vcd_get_property(client_ctx->vcd_handle, |
| 1448 | &vcd_property_hdr, &vui_timing_info_enable); |
| 1449 | |
| 1450 | if (rc < 0) { |
| 1451 | WFD_MSG_ERR("Failed getting property for VUI timing info"); |
| 1452 | return rc; |
| 1453 | } |
| 1454 | |
| 1455 | *flag = vui_timing_info_enable.vui_timing_info; |
| 1456 | return rc; |
| 1457 | } |
| 1458 | |
Deva Ramasubramanian | c84975c | 2012-03-10 21:16:27 -0800 | [diff] [blame] | 1459 | static long venc_set_header_mode(struct video_client_ctx *client_ctx, |
| 1460 | __s32 mode) |
| 1461 | { |
| 1462 | struct vcd_property_hdr vcd_property_hdr; |
| 1463 | struct vcd_property_sps_pps_for_idr_enable sps_pps_for_idr_enable; |
| 1464 | int rc = 0; |
| 1465 | |
| 1466 | if (!client_ctx) { |
| 1467 | WFD_MSG_ERR("Invalid parameters\n"); |
| 1468 | rc = -EINVAL; |
| 1469 | goto err; |
| 1470 | } |
| 1471 | |
| 1472 | vcd_property_hdr.prop_id = VCD_I_ENABLE_SPS_PPS_FOR_IDR; |
| 1473 | vcd_property_hdr.sz = sizeof(sps_pps_for_idr_enable); |
| 1474 | switch (mode) { |
| 1475 | case V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE: |
| 1476 | sps_pps_for_idr_enable.sps_pps_for_idr_enable_flag = 0; |
| 1477 | break; |
| 1478 | case V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_I_FRAME: |
| 1479 | sps_pps_for_idr_enable.sps_pps_for_idr_enable_flag = 1; |
| 1480 | break; |
| 1481 | case V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME: |
| 1482 | default: |
| 1483 | WFD_MSG_ERR("Video header mode %d not supported\n", |
| 1484 | mode); |
| 1485 | rc = -ENOTSUPP; |
| 1486 | goto err; |
| 1487 | } |
| 1488 | |
| 1489 | rc = vcd_set_property(client_ctx->vcd_handle, &vcd_property_hdr, |
| 1490 | &sps_pps_for_idr_enable); |
| 1491 | if (rc) { |
| 1492 | WFD_MSG_ERR("Failed to set enable_sps_pps_for_idr\n"); |
| 1493 | goto err; |
| 1494 | } |
| 1495 | err: |
| 1496 | return rc; |
| 1497 | } |
| 1498 | |
| 1499 | static long venc_get_header_mode(struct video_client_ctx *client_ctx, |
| 1500 | __s32 *mode) |
| 1501 | { |
| 1502 | struct vcd_property_hdr vcd_property_hdr; |
| 1503 | struct vcd_property_sps_pps_for_idr_enable sps_pps_for_idr_enable; |
| 1504 | int rc = 0; |
| 1505 | |
| 1506 | if (!client_ctx) { |
| 1507 | WFD_MSG_ERR("Invalid parameters\n"); |
| 1508 | rc = -EINVAL; |
| 1509 | goto err; |
| 1510 | } |
| 1511 | |
| 1512 | vcd_property_hdr.prop_id = VCD_I_ENABLE_SPS_PPS_FOR_IDR; |
| 1513 | vcd_property_hdr.sz = sizeof(sps_pps_for_idr_enable); |
| 1514 | rc = vcd_get_property(client_ctx->vcd_handle, &vcd_property_hdr, |
| 1515 | &sps_pps_for_idr_enable); |
| 1516 | if (rc) { |
| 1517 | WFD_MSG_ERR("Failed to get sps/pps for idr enable\n"); |
| 1518 | goto err; |
| 1519 | } |
| 1520 | |
| 1521 | *mode = sps_pps_for_idr_enable.sps_pps_for_idr_enable_flag ? |
| 1522 | V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_I_FRAME : |
| 1523 | V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE; |
| 1524 | err: |
| 1525 | return rc; |
| 1526 | } |
| 1527 | |
Deva Ramasubramanian | 607fbf2 | 2012-04-03 16:23:11 -0700 | [diff] [blame] | 1528 | static long venc_set_multislicing_mode(struct video_client_ctx *client_ctx, |
| 1529 | __u32 control, __s32 value) |
| 1530 | { |
| 1531 | int rc = 0; |
| 1532 | struct vcd_property_hdr vcd_property_hdr; |
| 1533 | struct vcd_property_frame_size vcd_frame_size; |
| 1534 | struct vcd_buffer_requirement vcd_buf_req; |
| 1535 | struct vcd_property_multi_slice vcd_multi_slice; |
| 1536 | |
| 1537 | if (!client_ctx) { |
| 1538 | WFD_MSG_ERR("Invalid parameters\n"); |
| 1539 | rc = -EINVAL; |
| 1540 | goto set_multislicing_mode_fail; |
| 1541 | } |
| 1542 | |
| 1543 | vcd_property_hdr.prop_id = VCD_I_FRAME_SIZE; |
| 1544 | vcd_property_hdr.sz = |
| 1545 | sizeof(vcd_frame_size); |
| 1546 | rc = vcd_get_property(client_ctx->vcd_handle, |
| 1547 | &vcd_property_hdr, &vcd_frame_size); |
| 1548 | |
| 1549 | if (rc) { |
| 1550 | WFD_MSG_ERR("Failed to get frame size\n"); |
| 1551 | goto set_multislicing_mode_fail; |
| 1552 | } |
| 1553 | |
| 1554 | rc = vcd_get_buffer_requirements(client_ctx->vcd_handle, |
| 1555 | VCD_BUFFER_OUTPUT, &vcd_buf_req); |
| 1556 | |
| 1557 | if (rc) { |
| 1558 | WFD_MSG_ERR("Failed to get buf reqs\n"); |
| 1559 | goto set_multislicing_mode_fail; |
| 1560 | } |
| 1561 | |
| 1562 | vcd_property_hdr.prop_id = VCD_I_MULTI_SLICE; |
| 1563 | vcd_property_hdr.sz = sizeof(vcd_multi_slice); |
| 1564 | rc = vcd_get_property(client_ctx->vcd_handle, &vcd_property_hdr, |
| 1565 | &vcd_multi_slice); |
| 1566 | if (rc) { |
| 1567 | WFD_MSG_ERR("Failed to get multi slice\n"); |
| 1568 | goto set_multislicing_mode_fail; |
| 1569 | } |
| 1570 | |
| 1571 | switch (control) { |
| 1572 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES: |
| 1573 | if (vcd_multi_slice.m_slice_sel != |
| 1574 | VCD_MSLICE_BY_BYTE_COUNT) { |
| 1575 | WFD_MSG_ERR("Not in proper mode\n"); |
| 1576 | goto set_multislicing_mode_fail; |
| 1577 | } |
| 1578 | vcd_multi_slice.m_slice_size = value; |
| 1579 | break; |
| 1580 | |
| 1581 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB: |
| 1582 | if (vcd_multi_slice.m_slice_sel != |
| 1583 | VCD_MSLICE_BY_MB_COUNT) { |
| 1584 | WFD_MSG_ERR("Not in proper mode\n"); |
| 1585 | goto set_multislicing_mode_fail; |
| 1586 | } |
| 1587 | vcd_multi_slice.m_slice_size = value; |
| 1588 | break; |
| 1589 | |
| 1590 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE: |
| 1591 | switch (value) { |
| 1592 | case V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE: |
| 1593 | vcd_multi_slice.m_slice_sel = VCD_MSLICE_OFF; |
| 1594 | break; |
| 1595 | case V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB: |
| 1596 | vcd_multi_slice.m_slice_sel = VCD_MSLICE_BY_MB_COUNT; |
| 1597 | /* Just a temporary size until client calls |
| 1598 | * V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB */ |
| 1599 | vcd_multi_slice.m_slice_size = |
| 1600 | (vcd_frame_size.stride / 16) * |
| 1601 | (vcd_frame_size.scan_lines / 16); |
| 1602 | break; |
| 1603 | case V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES: |
| 1604 | vcd_multi_slice.m_slice_sel = VCD_MSLICE_BY_BYTE_COUNT; |
| 1605 | /* Just a temporary size until client calls |
| 1606 | * V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES */ |
| 1607 | vcd_multi_slice.m_slice_size = vcd_buf_req.sz; |
| 1608 | break; |
| 1609 | default: |
| 1610 | WFD_MSG_ERR("Unrecognized mode %d\n", value); |
| 1611 | rc = -ENOTSUPP; |
| 1612 | goto set_multislicing_mode_fail; |
| 1613 | } |
| 1614 | |
| 1615 | break; |
| 1616 | default: |
| 1617 | rc = -EINVAL; |
| 1618 | goto set_multislicing_mode_fail; |
| 1619 | } |
| 1620 | |
| 1621 | rc = vcd_set_property(client_ctx->vcd_handle, &vcd_property_hdr, |
| 1622 | &vcd_multi_slice); |
| 1623 | if (rc) { |
| 1624 | WFD_MSG_ERR("Failed to set multi slice\n"); |
| 1625 | goto set_multislicing_mode_fail; |
| 1626 | } |
| 1627 | |
| 1628 | set_multislicing_mode_fail: |
| 1629 | return rc; |
| 1630 | } |
| 1631 | |
| 1632 | static long venc_get_multislicing_mode(struct video_client_ctx *client_ctx, |
| 1633 | __u32 control, __s32 *value) |
| 1634 | { |
| 1635 | int rc = 0; |
| 1636 | struct vcd_property_hdr vcd_property_hdr; |
| 1637 | struct vcd_property_frame_size vcd_frame_size; |
| 1638 | struct vcd_buffer_requirement vcd_buf_req; |
| 1639 | struct vcd_property_multi_slice vcd_multi_slice; |
| 1640 | |
| 1641 | if (!client_ctx) { |
| 1642 | WFD_MSG_ERR("Invalid parameters\n"); |
| 1643 | rc = -EINVAL; |
| 1644 | goto get_multislicing_mode_fail; |
| 1645 | } |
| 1646 | |
| 1647 | vcd_property_hdr.prop_id = VCD_I_FRAME_SIZE; |
| 1648 | vcd_property_hdr.sz = |
| 1649 | sizeof(vcd_frame_size); |
| 1650 | rc = vcd_get_property(client_ctx->vcd_handle, |
| 1651 | &vcd_property_hdr, &vcd_frame_size); |
| 1652 | |
| 1653 | if (rc) { |
| 1654 | WFD_MSG_ERR("Failed to get frame size\n"); |
| 1655 | goto get_multislicing_mode_fail; |
| 1656 | } |
| 1657 | |
| 1658 | vcd_property_hdr.prop_id = VCD_I_MULTI_SLICE; |
| 1659 | vcd_property_hdr.sz = sizeof(vcd_multi_slice); |
| 1660 | rc = vcd_get_property(client_ctx->vcd_handle, &vcd_property_hdr, |
| 1661 | &vcd_multi_slice); |
| 1662 | if (rc) { |
| 1663 | WFD_MSG_ERR("Failed to get multi slice\n"); |
| 1664 | goto get_multislicing_mode_fail; |
| 1665 | } |
| 1666 | |
| 1667 | rc = vcd_get_buffer_requirements(client_ctx->vcd_handle, |
| 1668 | VCD_BUFFER_OUTPUT, &vcd_buf_req); |
| 1669 | |
| 1670 | if (rc) { |
| 1671 | WFD_MSG_ERR("Failed to get buf reqs\n"); |
| 1672 | goto get_multislicing_mode_fail; |
| 1673 | } |
| 1674 | |
| 1675 | switch (control) { |
| 1676 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES: |
| 1677 | if (vcd_multi_slice.m_slice_sel == VCD_MSLICE_BY_BYTE_COUNT) |
| 1678 | *value = vcd_multi_slice.m_slice_size; |
| 1679 | else { |
| 1680 | WFD_MSG_ERR("Invalid query when in slice mode %d\n", |
| 1681 | vcd_multi_slice.m_slice_sel); |
| 1682 | rc = -EINVAL; |
| 1683 | goto get_multislicing_mode_fail; |
| 1684 | } |
| 1685 | break; |
| 1686 | |
| 1687 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB: |
| 1688 | if (vcd_multi_slice.m_slice_sel == VCD_MSLICE_BY_MB_COUNT) |
| 1689 | *value = vcd_multi_slice.m_slice_size; |
| 1690 | else { |
| 1691 | WFD_MSG_ERR("Invalid query when in slice mode %d\n", |
| 1692 | vcd_multi_slice.m_slice_sel); |
| 1693 | rc = -EINVAL; |
| 1694 | goto get_multislicing_mode_fail; |
| 1695 | } |
| 1696 | break; |
| 1697 | |
| 1698 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE: |
| 1699 | switch (vcd_multi_slice.m_slice_sel) { |
| 1700 | case VCD_MSLICE_OFF: |
| 1701 | *value = V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE; |
| 1702 | break; |
| 1703 | case VCD_MSLICE_BY_MB_COUNT: |
| 1704 | *value = V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB; |
| 1705 | break; |
| 1706 | case VCD_MSLICE_BY_BYTE_COUNT: |
| 1707 | *value = V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES; |
| 1708 | break; |
| 1709 | default: |
| 1710 | WFD_MSG_ERR("Encoder in an unknown mode %d\n", |
| 1711 | vcd_multi_slice.m_slice_sel); |
| 1712 | rc = -ENOENT; |
| 1713 | goto get_multislicing_mode_fail; |
| 1714 | |
| 1715 | } |
| 1716 | break; |
| 1717 | default: |
| 1718 | rc = -EINVAL; |
| 1719 | goto get_multislicing_mode_fail; |
| 1720 | } |
| 1721 | |
| 1722 | get_multislicing_mode_fail: |
| 1723 | return rc; |
| 1724 | } |
| 1725 | |
Deva Ramasubramanian | f94df43 | 2012-04-29 11:09:03 -0700 | [diff] [blame] | 1726 | static long venc_set_entropy_mode(struct video_client_ctx *client_ctx, |
| 1727 | __s32 value) |
| 1728 | { |
| 1729 | struct vcd_property_hdr vcd_property_hdr; |
| 1730 | struct vcd_property_entropy_control entropy_control; |
| 1731 | int rc = 0; |
| 1732 | |
| 1733 | if (!client_ctx) { |
| 1734 | WFD_MSG_ERR("Invalid parameters\n"); |
| 1735 | rc = -EINVAL; |
| 1736 | goto set_entropy_mode_fail; |
| 1737 | } |
| 1738 | |
| 1739 | vcd_property_hdr.prop_id = VCD_I_ENTROPY_CTRL; |
| 1740 | vcd_property_hdr.sz = sizeof(entropy_control); |
| 1741 | |
| 1742 | switch (value) { |
| 1743 | case V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC: |
| 1744 | entropy_control.entropy_sel = VCD_ENTROPY_SEL_CAVLC; |
| 1745 | break; |
| 1746 | case V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC: |
| 1747 | entropy_control.entropy_sel = VCD_ENTROPY_SEL_CABAC; |
| 1748 | entropy_control.cabac_model = VCD_CABAC_MODEL_NUMBER_0; |
| 1749 | break; |
| 1750 | default: |
| 1751 | WFD_MSG_ERR("Entropy type %d not supported\n", value); |
| 1752 | rc = -ENOTSUPP; |
| 1753 | goto set_entropy_mode_fail; |
| 1754 | } |
| 1755 | rc = vcd_set_property(client_ctx->vcd_handle, &vcd_property_hdr, |
| 1756 | &entropy_control); |
| 1757 | if (rc) { |
| 1758 | WFD_MSG_ERR("Failed to set entropy mode\n"); |
| 1759 | goto set_entropy_mode_fail; |
| 1760 | } |
| 1761 | |
| 1762 | set_entropy_mode_fail: |
| 1763 | return rc; |
| 1764 | } |
| 1765 | |
| 1766 | static long venc_get_entropy_mode(struct video_client_ctx *client_ctx, |
| 1767 | __s32 *value) |
| 1768 | { |
| 1769 | struct vcd_property_hdr vcd_property_hdr; |
| 1770 | struct vcd_property_entropy_control entropy_control; |
| 1771 | int rc = 0; |
| 1772 | |
| 1773 | if (!client_ctx || !value) { |
| 1774 | WFD_MSG_ERR("Invalid parameters\n"); |
| 1775 | rc = -EINVAL; |
| 1776 | goto get_entropy_mode_fail; |
| 1777 | } |
| 1778 | |
| 1779 | vcd_property_hdr.prop_id = VCD_I_ENTROPY_CTRL; |
| 1780 | vcd_property_hdr.sz = sizeof(entropy_control); |
| 1781 | |
| 1782 | rc = vcd_get_property(client_ctx->vcd_handle, &vcd_property_hdr, |
| 1783 | &entropy_control); |
| 1784 | |
| 1785 | if (rc) { |
| 1786 | WFD_MSG_ERR("Failed to get entropy mode\n"); |
| 1787 | goto get_entropy_mode_fail; |
| 1788 | } |
| 1789 | |
| 1790 | switch (entropy_control.entropy_sel) { |
| 1791 | case VCD_ENTROPY_SEL_CAVLC: |
| 1792 | *value = V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC; |
| 1793 | break; |
| 1794 | case VCD_ENTROPY_SEL_CABAC: |
| 1795 | *value = V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC; |
| 1796 | break; |
| 1797 | default: |
| 1798 | WFD_MSG_ERR("Entropy type %d not known\n", |
| 1799 | entropy_control.entropy_sel); |
| 1800 | rc = -EINVAL; |
| 1801 | goto get_entropy_mode_fail; |
| 1802 | } |
| 1803 | get_entropy_mode_fail: |
| 1804 | return rc; |
| 1805 | } |
| 1806 | |
Deva Ramasubramanian | e5ce772 | 2012-04-30 11:27:45 -0700 | [diff] [blame] | 1807 | static long venc_set_cyclic_intra_refresh_mb( |
| 1808 | struct video_client_ctx *client_ctx, |
| 1809 | __s32 value) |
| 1810 | { |
| 1811 | struct vcd_property_hdr vcd_property_hdr; |
| 1812 | struct vcd_property_intra_refresh_mb_number cir_mb_num; |
| 1813 | int rc = 0; |
| 1814 | |
| 1815 | if (!client_ctx) { |
| 1816 | WFD_MSG_ERR("Invalid parameters\n"); |
| 1817 | rc = -EINVAL; |
| 1818 | goto set_cir_mbs_fail; |
| 1819 | } |
| 1820 | |
| 1821 | vcd_property_hdr.prop_id = VCD_I_INTRA_REFRESH; |
| 1822 | vcd_property_hdr.sz = sizeof(cir_mb_num); |
| 1823 | |
| 1824 | cir_mb_num.cir_mb_number = value; |
| 1825 | |
| 1826 | rc = vcd_set_property(client_ctx->vcd_handle, &vcd_property_hdr, |
| 1827 | &cir_mb_num); |
| 1828 | if (rc) { |
| 1829 | WFD_MSG_ERR("Failed to set CIR MBs\n"); |
| 1830 | goto set_cir_mbs_fail; |
| 1831 | } |
| 1832 | |
| 1833 | set_cir_mbs_fail: |
| 1834 | return rc; |
| 1835 | } |
| 1836 | |
| 1837 | static long venc_get_cyclic_intra_refresh_mb( |
| 1838 | struct video_client_ctx *client_ctx, |
| 1839 | __s32 *value) |
| 1840 | { |
| 1841 | struct vcd_property_hdr vcd_property_hdr; |
| 1842 | struct vcd_property_intra_refresh_mb_number cir_mb_num; |
| 1843 | int rc = 0; |
| 1844 | |
| 1845 | if (!client_ctx || !value) { |
| 1846 | WFD_MSG_ERR("Invalid parameters\n"); |
| 1847 | rc = -EINVAL; |
| 1848 | goto get_cir_mbs_fail; |
| 1849 | } |
| 1850 | |
| 1851 | vcd_property_hdr.prop_id = VCD_I_INTRA_REFRESH; |
| 1852 | vcd_property_hdr.sz = sizeof(cir_mb_num); |
| 1853 | |
| 1854 | rc = vcd_get_property(client_ctx->vcd_handle, &vcd_property_hdr, |
| 1855 | &cir_mb_num); |
| 1856 | if (rc) { |
| 1857 | WFD_MSG_ERR("Failed to set CIR MBs\n"); |
| 1858 | goto get_cir_mbs_fail; |
| 1859 | } |
| 1860 | |
| 1861 | *value = cir_mb_num.cir_mb_number; |
| 1862 | |
| 1863 | get_cir_mbs_fail: |
| 1864 | return rc; |
| 1865 | } |
Deva Ramasubramanian | 2e99bff | 2012-02-13 21:12:08 -0800 | [diff] [blame] | 1866 | static long venc_set_input_buffer(struct v4l2_subdev *sd, void *arg) |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 1867 | { |
| 1868 | struct mem_region *mregion = arg; |
| 1869 | struct venc_inst *inst = sd->dev_priv; |
Deva Ramasubramanian | 2e99bff | 2012-02-13 21:12:08 -0800 | [diff] [blame] | 1870 | unsigned long paddr, kvaddr, temp; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 1871 | struct video_client_ctx *client_ctx = &inst->venc_client; |
| 1872 | int rc = 0; |
Deva Ramasubramanian | 2e99bff | 2012-02-13 21:12:08 -0800 | [diff] [blame] | 1873 | |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 1874 | if (!client_ctx || !mregion) { |
| 1875 | WFD_MSG_ERR("Invalid input\n"); |
Deva Ramasubramanian | 2e99bff | 2012-02-13 21:12:08 -0800 | [diff] [blame] | 1876 | rc = -EINVAL; |
| 1877 | goto ins_table_fail; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 1878 | } |
Deva Ramasubramanian | 2e99bff | 2012-02-13 21:12:08 -0800 | [diff] [blame] | 1879 | |
| 1880 | kvaddr = (unsigned long)mregion->kvaddr; |
| 1881 | paddr = (unsigned long)mregion->paddr; |
| 1882 | |
| 1883 | if (!kvaddr || !paddr) { |
| 1884 | WFD_MSG_ERR("Invalid addresses\n"); |
| 1885 | rc = -EINVAL; |
| 1886 | goto ins_table_fail; |
| 1887 | } |
| 1888 | |
| 1889 | /* |
| 1890 | * Just a note: the third arg of vidc_insert_\ |
| 1891 | * addr_table_kernel is supposed to be a userspace |
| 1892 | * address that is used as a key in the table. As |
| 1893 | * these bufs never leave the kernel, we need to have |
| 1894 | * an unique value to use as a key. So re-using kernel |
| 1895 | * virtual addr for this purpose |
| 1896 | */ |
| 1897 | rc = vidc_insert_addr_table_kernel(client_ctx, |
| 1898 | BUFFER_TYPE_INPUT, kvaddr, kvaddr, |
| 1899 | paddr, 32, mregion->size); |
| 1900 | |
| 1901 | if (rc == (u32)false) { |
| 1902 | WFD_MSG_ERR("Failed to insert input buffer into table\n"); |
| 1903 | rc = -EFAULT; |
| 1904 | goto ins_table_fail; |
| 1905 | } |
| 1906 | |
| 1907 | rc = vcd_set_buffer(client_ctx->vcd_handle, |
| 1908 | VCD_BUFFER_INPUT, (u8 *)kvaddr, |
| 1909 | mregion->size); |
| 1910 | |
| 1911 | if (rc) { |
| 1912 | WFD_MSG_ERR("Failed to set input buffer\n"); |
| 1913 | rc = -EFAULT; |
| 1914 | goto set_input_buf_fail; |
| 1915 | } |
| 1916 | |
| 1917 | |
| 1918 | return rc; |
| 1919 | |
| 1920 | set_input_buf_fail: |
| 1921 | vidc_delete_addr_table(client_ctx, BUFFER_TYPE_INPUT, |
| 1922 | kvaddr, &temp); |
| 1923 | ins_table_fail: |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 1924 | return rc; |
| 1925 | } |
| 1926 | |
| 1927 | static long venc_set_output_buffer(struct v4l2_subdev *sd, void *arg) |
| 1928 | { |
| 1929 | int rc = 0; |
| 1930 | struct venc_inst *inst = sd->dev_priv; |
| 1931 | struct video_client_ctx *client_ctx = &inst->venc_client; |
| 1932 | struct mem_region *mregion = arg; |
| 1933 | if (!client_ctx || !mregion) { |
| 1934 | WFD_MSG_ERR("Invalid input\n"); |
| 1935 | return -EINVAL; |
| 1936 | } |
| 1937 | WFD_MSG_DBG("size = %u, offset = %u fd = %d\n", mregion->size, |
| 1938 | mregion->offset, mregion->fd); |
| 1939 | rc = vidc_insert_addr_table(client_ctx, BUFFER_TYPE_OUTPUT, |
| 1940 | mregion->cookie, |
| 1941 | (unsigned long *)&mregion->kvaddr, |
| 1942 | mregion->fd, |
| 1943 | mregion->offset, |
| 1944 | 32, |
| 1945 | mregion->size); |
Deva Ramasubramanian | b84fc50 | 2012-01-16 11:42:58 -0800 | [diff] [blame] | 1946 | if (rc == (u32)false) { |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 1947 | WFD_MSG_ERR("Failed to insert outbuf in table\n"); |
Deva Ramasubramanian | b84fc50 | 2012-01-16 11:42:58 -0800 | [diff] [blame] | 1948 | rc = -EINVAL; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 1949 | goto err; |
| 1950 | } |
| 1951 | WFD_MSG_DBG("size = %u, %p\n", mregion->size, mregion->kvaddr); |
| 1952 | |
| 1953 | rc = vcd_set_buffer(client_ctx->vcd_handle, |
| 1954 | VCD_BUFFER_OUTPUT, (u8 *) mregion->kvaddr, |
| 1955 | mregion->size); |
| 1956 | if (rc) |
| 1957 | WFD_MSG_ERR("Failed to set outbuf on encoder\n"); |
| 1958 | err: |
| 1959 | return rc; |
| 1960 | } |
| 1961 | |
| 1962 | static long venc_fill_outbuf(struct v4l2_subdev *sd, void *arg) |
| 1963 | { |
| 1964 | int rc = 0; |
| 1965 | struct venc_inst *inst = sd->dev_priv; |
| 1966 | struct video_client_ctx *client_ctx = &inst->venc_client; |
| 1967 | struct mem_region *mregion = arg; |
| 1968 | struct vcd_frame_data vcd_frame = {0}; |
| 1969 | unsigned long kernel_vaddr, phy_addr, user_vaddr; |
| 1970 | int pmem_fd; |
| 1971 | struct file *file; |
| 1972 | s32 buffer_index = -1; |
| 1973 | |
Deva Ramasubramanian | 08413fc | 2012-07-16 17:27:02 -0700 | [diff] [blame] | 1974 | if (inst->streaming) { |
| 1975 | user_vaddr = mregion->cookie; |
| 1976 | rc = vidc_lookup_addr_table(client_ctx, BUFFER_TYPE_OUTPUT, |
| 1977 | true, &user_vaddr, |
| 1978 | &kernel_vaddr, &phy_addr, &pmem_fd, &file, |
| 1979 | &buffer_index); |
| 1980 | if (!rc) { |
| 1981 | WFD_MSG_ERR("Address lookup failed\n"); |
| 1982 | goto err; |
| 1983 | } |
| 1984 | vcd_frame.virtual = (u8 *) kernel_vaddr; |
| 1985 | vcd_frame.frm_clnt_data = mregion->cookie; |
| 1986 | vcd_frame.alloc_len = mregion->size; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 1987 | |
Deva Ramasubramanian | 08413fc | 2012-07-16 17:27:02 -0700 | [diff] [blame] | 1988 | rc = vcd_fill_output_buffer(client_ctx->vcd_handle, &vcd_frame); |
| 1989 | if (rc) |
| 1990 | WFD_MSG_ERR("Failed to fill output buffer on encoder"); |
| 1991 | } else { |
| 1992 | struct mem_region *temp = kzalloc(sizeof(*temp), GFP_KERNEL); |
| 1993 | *temp = *mregion; |
| 1994 | INIT_LIST_HEAD(&temp->list); |
| 1995 | list_add_tail(&temp->list, &inst->unqueued_op_bufs.list); |
| 1996 | } |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 1997 | err: |
| 1998 | return rc; |
| 1999 | } |
| 2000 | |
| 2001 | static long venc_encode_frame(struct v4l2_subdev *sd, void *arg) |
| 2002 | { |
| 2003 | int rc = 0; |
| 2004 | struct venc_inst *inst = sd->dev_priv; |
| 2005 | struct video_client_ctx *client_ctx = &inst->venc_client; |
Deva Ramasubramanian | b84fc50 | 2012-01-16 11:42:58 -0800 | [diff] [blame] | 2006 | struct venc_buf_info *venc_buf = arg; |
| 2007 | struct mem_region *mregion = venc_buf->mregion; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2008 | struct vcd_frame_data vcd_input_buffer = {0}; |
Deva Ramasubramanian | 4947d8c | 2012-04-03 12:41:06 -0700 | [diff] [blame] | 2009 | int64_t ts = 0; |
| 2010 | |
| 2011 | ts = venc_buf->timestamp; |
| 2012 | do_div(ts, NSEC_PER_USEC); |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2013 | |
| 2014 | vcd_input_buffer.virtual = mregion->kvaddr; |
| 2015 | vcd_input_buffer.frm_clnt_data = (u32)mregion; |
| 2016 | vcd_input_buffer.ip_frm_tag = (u32)mregion; |
| 2017 | vcd_input_buffer.data_len = mregion->size; |
Deva Ramasubramanian | 4947d8c | 2012-04-03 12:41:06 -0700 | [diff] [blame] | 2018 | vcd_input_buffer.time_stamp = ts; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2019 | vcd_input_buffer.offset = 0; |
| 2020 | |
| 2021 | rc = vcd_encode_frame(client_ctx->vcd_handle, |
| 2022 | &vcd_input_buffer); |
| 2023 | |
| 2024 | if (rc) |
| 2025 | WFD_MSG_ERR("encode frame failed\n"); |
| 2026 | return rc; |
| 2027 | } |
| 2028 | |
| 2029 | static long venc_alloc_recon_buffers(struct v4l2_subdev *sd, void *arg) |
| 2030 | { |
| 2031 | int rc = 0; |
| 2032 | struct venc_inst *inst = sd->dev_priv; |
| 2033 | struct video_client_ctx *client_ctx = &inst->venc_client; |
| 2034 | struct vcd_property_hdr vcd_property_hdr; |
| 2035 | struct vcd_property_buffer_size control; |
| 2036 | struct vcd_property_enc_recon_buffer *ctrl = NULL; |
| 2037 | unsigned long phy_addr; |
| 2038 | int i = 0; |
Hanumant Singh | 7d72bad | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 2039 | int heap_mask = 0; |
Srinu Gorle | c4a5719 | 2012-11-03 21:08:56 +0530 | [diff] [blame] | 2040 | u32 ion_flags = 0; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2041 | u32 len; |
| 2042 | control.width = inst->width; |
| 2043 | control.height = inst->height; |
| 2044 | vcd_property_hdr.prop_id = VCD_I_GET_RECON_BUFFER_SIZE; |
| 2045 | vcd_property_hdr.sz = sizeof(struct vcd_property_buffer_size); |
| 2046 | |
| 2047 | rc = vcd_get_property(client_ctx->vcd_handle, |
| 2048 | &vcd_property_hdr, &control); |
| 2049 | if (rc) { |
| 2050 | WFD_MSG_ERR("Failed to get recon buf size\n"); |
| 2051 | goto err; |
| 2052 | } |
Hanumant Singh | 7d72bad | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 2053 | heap_mask = ION_HEAP(ION_CP_MM_HEAP_ID); |
Srinu Gorle | c4a5719 | 2012-11-03 21:08:56 +0530 | [diff] [blame] | 2054 | heap_mask |= inst->secure ? 0 : ION_HEAP(ION_IOMMU_HEAP_ID); |
| 2055 | ion_flags |= inst->secure ? ION_SECURE : 0; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2056 | |
| 2057 | if (vcd_get_ion_status()) { |
| 2058 | for (i = 0; i < 4; ++i) { |
| 2059 | ctrl = &client_ctx->recon_buffer[i]; |
| 2060 | ctrl->buffer_size = control.size; |
| 2061 | ctrl->pmem_fd = 0; |
| 2062 | ctrl->offset = 0; |
| 2063 | ctrl->user_virtual_addr = (void *)i; |
| 2064 | client_ctx->recon_buffer_ion_handle[i] |
| 2065 | = ion_alloc(client_ctx->user_ion_client, |
Srinu Gorle | c4a5719 | 2012-11-03 21:08:56 +0530 | [diff] [blame] | 2066 | control.size, SZ_8K, heap_mask, ion_flags); |
Deva Ramasubramanian | 2e99bff | 2012-02-13 21:12:08 -0800 | [diff] [blame] | 2067 | |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2068 | ctrl->kernel_virtual_addr = ion_map_kernel( |
| 2069 | client_ctx->user_ion_client, |
Mitchel Humpherys | 911b4b7 | 2012-09-12 14:42:50 -0700 | [diff] [blame] | 2070 | client_ctx->recon_buffer_ion_handle[i]); |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2071 | |
Arun Menon | 0e1d3a1 | 2012-07-30 14:38:39 -0700 | [diff] [blame] | 2072 | if (IS_ERR_OR_NULL(ctrl->kernel_virtual_addr)) { |
| 2073 | WFD_MSG_ERR("ion map kernel failed\n"); |
| 2074 | rc = -EINVAL; |
| 2075 | goto free_ion_alloc; |
| 2076 | } |
| 2077 | |
| 2078 | if (inst->secure) { |
| 2079 | rc = ion_phys(client_ctx->user_ion_client, |
| 2080 | client_ctx->recon_buffer_ion_handle[i], |
| 2081 | &phy_addr, (size_t *)&len); |
| 2082 | if (rc || !phy_addr) { |
| 2083 | WFD_MSG_ERR("ion physical failed\n"); |
| 2084 | goto unmap_ion_alloc; |
| 2085 | } |
| 2086 | } else { |
| 2087 | rc = ion_map_iommu(client_ctx->user_ion_client, |
| 2088 | client_ctx->recon_buffer_ion_handle[i], |
| 2089 | VIDEO_DOMAIN, VIDEO_MAIN_POOL, SZ_4K, |
| 2090 | 0, &phy_addr, (unsigned long *)&len, |
| 2091 | 0, 0); |
| 2092 | if (rc || !phy_addr) { |
| 2093 | WFD_MSG_ERR( |
| 2094 | "ion map iommu failed, rc = %d, phy_addr = 0x%lx\n", |
| 2095 | rc, phy_addr); |
| 2096 | goto unmap_ion_alloc; |
| 2097 | } |
| 2098 | |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2099 | } |
| 2100 | ctrl->physical_addr = (u8 *) phy_addr; |
| 2101 | ctrl->dev_addr = ctrl->physical_addr; |
| 2102 | vcd_property_hdr.prop_id = VCD_I_RECON_BUFFERS; |
| 2103 | vcd_property_hdr.sz = |
| 2104 | sizeof(struct vcd_property_enc_recon_buffer); |
| 2105 | rc = vcd_set_property(client_ctx->vcd_handle, |
| 2106 | &vcd_property_hdr, ctrl); |
| 2107 | if (rc) { |
| 2108 | WFD_MSG_ERR("Failed to set recon buffers\n"); |
Arun Menon | 0e1d3a1 | 2012-07-30 14:38:39 -0700 | [diff] [blame] | 2109 | goto unmap_ion_iommu; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2110 | } |
| 2111 | } |
| 2112 | } else { |
| 2113 | WFD_MSG_ERR("PMEM not suported\n"); |
| 2114 | return -ENOMEM; |
| 2115 | } |
Arun Menon | 0e1d3a1 | 2012-07-30 14:38:39 -0700 | [diff] [blame] | 2116 | return rc; |
| 2117 | unmap_ion_iommu: |
| 2118 | if (!inst->secure) { |
| 2119 | if (client_ctx->recon_buffer_ion_handle[i]) { |
| 2120 | ion_unmap_iommu(client_ctx->user_ion_client, |
| 2121 | client_ctx->recon_buffer_ion_handle[i], |
| 2122 | VIDEO_DOMAIN, VIDEO_MAIN_POOL); |
| 2123 | } |
| 2124 | } |
| 2125 | unmap_ion_alloc: |
| 2126 | if (client_ctx->recon_buffer_ion_handle[i]) { |
| 2127 | ion_unmap_kernel(client_ctx->user_ion_client, |
| 2128 | client_ctx->recon_buffer_ion_handle[i]); |
| 2129 | ctrl->kernel_virtual_addr = NULL; |
| 2130 | ctrl->physical_addr = NULL; |
| 2131 | } |
| 2132 | free_ion_alloc: |
| 2133 | if (client_ctx->recon_buffer_ion_handle[i]) { |
| 2134 | ion_free(client_ctx->user_ion_client, |
| 2135 | client_ctx->recon_buffer_ion_handle[i]); |
| 2136 | client_ctx->recon_buffer_ion_handle[i] = NULL; |
| 2137 | } |
| 2138 | WFD_MSG_ERR("Failed to allo recon buffers\n"); |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2139 | err: |
| 2140 | return rc; |
| 2141 | } |
| 2142 | |
| 2143 | static long venc_free_output_buffer(struct v4l2_subdev *sd, void *arg) |
| 2144 | { |
| 2145 | int rc = 0; |
| 2146 | struct venc_inst *inst = sd->dev_priv; |
| 2147 | struct video_client_ctx *client_ctx = &inst->venc_client; |
| 2148 | struct mem_region *mregion = arg; |
| 2149 | unsigned long kernel_vaddr, user_vaddr; |
| 2150 | |
| 2151 | if (!client_ctx || !mregion) { |
| 2152 | WFD_MSG_ERR("Invalid input\n"); |
| 2153 | return -EINVAL; |
| 2154 | } |
| 2155 | |
| 2156 | user_vaddr = mregion->cookie; |
| 2157 | rc = vidc_delete_addr_table(client_ctx, BUFFER_TYPE_OUTPUT, |
| 2158 | user_vaddr, |
| 2159 | &kernel_vaddr); |
| 2160 | if (!rc) { |
| 2161 | WFD_MSG_ERR("Failed to delete buf from address table\n"); |
| 2162 | return -EINVAL; |
| 2163 | } |
| 2164 | return vcd_free_buffer(client_ctx->vcd_handle, VCD_BUFFER_OUTPUT, |
| 2165 | (u8 *)kernel_vaddr); |
| 2166 | } |
| 2167 | |
Vinay Kalia | b6dd587 | 2012-04-05 15:24:58 -0700 | [diff] [blame] | 2168 | static long venc_flush_buffers(struct v4l2_subdev *sd, void *arg) |
| 2169 | { |
| 2170 | int rc = 0; |
| 2171 | struct venc_inst *inst = sd->dev_priv; |
| 2172 | struct video_client_ctx *client_ctx = &inst->venc_client; |
| 2173 | if (!client_ctx) { |
| 2174 | WFD_MSG_ERR("Invalid input\n"); |
| 2175 | return -EINVAL; |
| 2176 | } |
| 2177 | rc = vcd_flush(client_ctx->vcd_handle, VCD_FLUSH_INPUT); |
| 2178 | if (rc) { |
| 2179 | WFD_MSG_ERR("Failed to flush input buffers\n"); |
| 2180 | rc = -EIO; |
| 2181 | goto flush_failed; |
| 2182 | } |
| 2183 | wait_for_completion(&client_ctx->event); |
| 2184 | if (client_ctx->event_status) { |
| 2185 | WFD_MSG_ERR("callback for vcd_flush input returned error: %u", |
| 2186 | client_ctx->event_status); |
| 2187 | rc = -EIO; |
| 2188 | goto flush_failed; |
| 2189 | } |
| 2190 | rc = vcd_flush(client_ctx->vcd_handle, VCD_FLUSH_OUTPUT); |
| 2191 | if (rc) { |
| 2192 | WFD_MSG_ERR("Failed to flush output buffers\n"); |
| 2193 | rc = -EIO; |
| 2194 | goto flush_failed; |
| 2195 | } |
| 2196 | wait_for_completion(&client_ctx->event); |
| 2197 | if (client_ctx->event_status) { |
| 2198 | WFD_MSG_ERR("callback for vcd_flush output returned error: %u", |
| 2199 | client_ctx->event_status); |
| 2200 | rc = -EIO; |
| 2201 | goto flush_failed; |
| 2202 | } |
| 2203 | |
| 2204 | flush_failed: |
| 2205 | return rc; |
| 2206 | } |
| 2207 | |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2208 | static long venc_free_input_buffer(struct v4l2_subdev *sd, void *arg) |
| 2209 | { |
Deva Ramasubramanian | 2e99bff | 2012-02-13 21:12:08 -0800 | [diff] [blame] | 2210 | int del_rc = 0, free_rc = 0; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2211 | struct venc_inst *inst = sd->dev_priv; |
| 2212 | struct video_client_ctx *client_ctx = &inst->venc_client; |
| 2213 | struct mem_region *mregion = arg; |
Deva Ramasubramanian | 2e99bff | 2012-02-13 21:12:08 -0800 | [diff] [blame] | 2214 | unsigned long vidc_kvaddr; |
| 2215 | |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2216 | if (!client_ctx || !mregion) { |
| 2217 | WFD_MSG_ERR("Invalid input\n"); |
| 2218 | return -EINVAL; |
| 2219 | } |
Deva Ramasubramanian | 2e99bff | 2012-02-13 21:12:08 -0800 | [diff] [blame] | 2220 | |
| 2221 | del_rc = vidc_delete_addr_table(client_ctx, BUFFER_TYPE_INPUT, |
| 2222 | (unsigned long)mregion->kvaddr, |
| 2223 | &vidc_kvaddr); |
| 2224 | /* |
| 2225 | * Even if something went wrong in when |
| 2226 | * deleting from table, call vcd_free_buf |
| 2227 | */ |
| 2228 | if (del_rc == (u32)false) { |
| 2229 | WFD_MSG_ERR("Failed to delete buf from address table\n"); |
| 2230 | del_rc = -ENOKEY; |
| 2231 | } else if ((u8 *)vidc_kvaddr != mregion->kvaddr) { |
| 2232 | WFD_MSG_ERR("Failed to find expected buffer\n"); |
| 2233 | del_rc = -EINVAL; |
| 2234 | } else |
| 2235 | del_rc = 0; |
| 2236 | |
| 2237 | free_rc = vcd_free_buffer(client_ctx->vcd_handle, VCD_BUFFER_INPUT, |
| 2238 | (u8 *)vidc_kvaddr); |
| 2239 | |
| 2240 | if (free_rc) { |
| 2241 | WFD_MSG_ERR("Failed to free buffer from encoder\n"); |
| 2242 | free_rc = -EINVAL; |
| 2243 | } |
| 2244 | |
| 2245 | return del_rc ? del_rc : free_rc; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | static long venc_free_recon_buffers(struct v4l2_subdev *sd, void *arg) |
| 2249 | { |
| 2250 | int rc = 0; |
| 2251 | struct venc_inst *inst = sd->dev_priv; |
| 2252 | struct video_client_ctx *client_ctx = &inst->venc_client; |
| 2253 | struct vcd_property_hdr vcd_property_hdr; |
| 2254 | int i; |
| 2255 | |
| 2256 | if (vcd_get_ion_status()) { |
| 2257 | for (i = 0; i < 4; i++) { |
| 2258 | vcd_property_hdr.prop_id = VCD_I_FREE_RECON_BUFFERS; |
| 2259 | vcd_property_hdr.sz = |
| 2260 | sizeof(struct vcd_property_buffer_size); |
| 2261 | rc = vcd_set_property(client_ctx->vcd_handle, |
| 2262 | &vcd_property_hdr, &client_ctx->recon_buffer[i]); |
| 2263 | if (rc) |
| 2264 | WFD_MSG_ERR("Failed to free recon buffer\n"); |
| 2265 | |
Srinu Gorle | 7330657 | 2012-10-01 22:13:26 +0530 | [diff] [blame] | 2266 | if (!IS_ERR_OR_NULL( |
Arun Menon | 0e1d3a1 | 2012-07-30 14:38:39 -0700 | [diff] [blame] | 2267 | client_ctx->recon_buffer_ion_handle[i])) { |
| 2268 | if (!inst->secure) { |
| 2269 | ion_unmap_iommu( |
| 2270 | client_ctx->user_ion_client, |
| 2271 | client_ctx->recon_buffer_ion_handle[i], |
| 2272 | VIDEO_DOMAIN, VIDEO_MAIN_POOL); |
| 2273 | } |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2274 | ion_unmap_kernel(client_ctx->user_ion_client, |
| 2275 | client_ctx->recon_buffer_ion_handle[i]); |
| 2276 | ion_free(client_ctx->user_ion_client, |
| 2277 | client_ctx->recon_buffer_ion_handle[i]); |
| 2278 | client_ctx->recon_buffer_ion_handle[i] = NULL; |
| 2279 | } |
| 2280 | } |
| 2281 | } |
| 2282 | return rc; |
| 2283 | } |
| 2284 | |
| 2285 | static long venc_set_property(struct v4l2_subdev *sd, void *arg) |
| 2286 | { |
| 2287 | int rc = 0; |
| 2288 | struct venc_inst *inst = sd->dev_priv; |
| 2289 | struct v4l2_control *ctrl = arg; |
| 2290 | struct video_client_ctx *client_ctx = &inst->venc_client; |
| 2291 | switch (ctrl->id) { |
| 2292 | case V4L2_CID_MPEG_VIDEO_BITRATE: |
| 2293 | rc = venc_set_bitrate(client_ctx, ctrl->value); |
| 2294 | break; |
| 2295 | case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: |
| 2296 | rc = venc_set_bitrate_mode(client_ctx, ctrl->value); |
| 2297 | break; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2298 | case V4L2_CID_MPEG_VIDEO_H264_I_PERIOD: |
| 2299 | rc = venc_set_h264_intra_period(client_ctx, ctrl->value); |
| 2300 | break; |
| 2301 | case V4L2_CID_MPEG_VIDEO_H264_LEVEL: |
| 2302 | rc = venc_set_codec_level(client_ctx, ctrl->id, ctrl->value); |
| 2303 | break; |
| 2304 | case V4L2_CID_MPEG_VIDEO_H264_PROFILE: |
| 2305 | rc = venc_set_codec_profile(client_ctx, ctrl->id, ctrl->value); |
| 2306 | break; |
| 2307 | case V4L2_CID_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE: |
| 2308 | rc = venc_request_frame(client_ctx, ctrl->value); |
| 2309 | break; |
Deva Ramasubramanian | 3f2e602 | 2012-02-06 15:02:51 -0800 | [diff] [blame] | 2310 | case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP: |
| 2311 | case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP: |
| 2312 | case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP: |
| 2313 | case V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP: |
| 2314 | case V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP: |
| 2315 | case V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP: |
| 2316 | case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP: |
| 2317 | case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP: |
| 2318 | case V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP: |
| 2319 | rc = venc_set_qp_value(client_ctx, ctrl->id, ctrl->value); |
| 2320 | break; |
| 2321 | case V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP: |
| 2322 | case V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP: |
| 2323 | case V4L2_CID_MPEG_VIDEO_H263_MIN_QP: |
| 2324 | case V4L2_CID_MPEG_VIDEO_H263_MAX_QP: |
| 2325 | case V4L2_CID_MPEG_VIDEO_H264_MIN_QP: |
| 2326 | case V4L2_CID_MPEG_VIDEO_H264_MAX_QP: |
| 2327 | rc = venc_set_qp_range(client_ctx, ctrl->id, ctrl->value); |
| 2328 | break; |
Deva Ramasubramanian | c84975c | 2012-03-10 21:16:27 -0800 | [diff] [blame] | 2329 | case V4L2_CID_MPEG_VIDEO_HEADER_MODE: |
| 2330 | rc = venc_set_header_mode(client_ctx, ctrl->value); |
| 2331 | break; |
Deva Ramasubramanian | 607fbf2 | 2012-04-03 16:23:11 -0700 | [diff] [blame] | 2332 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES: |
| 2333 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB: |
| 2334 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE: |
| 2335 | rc = venc_set_multislicing_mode(client_ctx, ctrl->id, |
| 2336 | ctrl->value); |
| 2337 | break; |
Vinay Kalia | 700f5c2 | 2012-03-28 17:35:28 -0700 | [diff] [blame] | 2338 | case V4L2_CID_MPEG_QCOM_SET_PERF_LEVEL: |
| 2339 | rc = venc_set_max_perf_level(client_ctx, ctrl->value); |
| 2340 | break; |
Srinu Gorle | efe5bf3 | 2012-09-05 13:02:13 +0530 | [diff] [blame] | 2341 | case V4L2_CID_MPEG_VIDC_VIDEO_H264_AU_DELIMITER: |
| 2342 | rc = venc_set_avc_delimiter(client_ctx, ctrl->value); |
| 2343 | break; |
Srinu Gorle | 4f8bc3a | 2012-11-15 09:36:38 +0530 | [diff] [blame] | 2344 | case V4L2_CID_MPEG_VIDC_VIDEO_H264_VUI_TIMING_INFO: |
| 2345 | rc = venc_set_vui_timing_info(client_ctx, inst, ctrl->value); |
| 2346 | break; |
Deva Ramasubramanian | f94df43 | 2012-04-29 11:09:03 -0700 | [diff] [blame] | 2347 | case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE: |
| 2348 | rc = venc_set_entropy_mode(client_ctx, ctrl->value); |
| 2349 | break; |
Deva Ramasubramanian | e5ce772 | 2012-04-30 11:27:45 -0700 | [diff] [blame] | 2350 | case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB: |
| 2351 | rc = venc_set_cyclic_intra_refresh_mb(client_ctx, ctrl->value); |
| 2352 | break; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2353 | default: |
| 2354 | WFD_MSG_ERR("Set property not suported: %d\n", ctrl->id); |
| 2355 | rc = -ENOTSUPP; |
| 2356 | break; |
| 2357 | } |
| 2358 | return rc; |
| 2359 | } |
| 2360 | |
| 2361 | static long venc_get_property(struct v4l2_subdev *sd, void *arg) |
| 2362 | { |
| 2363 | int rc = 0; |
| 2364 | struct venc_inst *inst = sd->dev_priv; |
| 2365 | struct v4l2_control *ctrl = arg; |
| 2366 | struct video_client_ctx *client_ctx = &inst->venc_client; |
| 2367 | |
| 2368 | switch (ctrl->id) { |
| 2369 | case V4L2_CID_MPEG_VIDEO_BITRATE: |
| 2370 | rc = venc_get_bitrate(client_ctx, &ctrl->value); |
| 2371 | break; |
| 2372 | case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: |
| 2373 | rc = venc_get_bitrate_mode(client_ctx, &ctrl->value); |
| 2374 | break; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2375 | case V4L2_CID_MPEG_VIDEO_H264_LEVEL: |
| 2376 | rc = venc_get_codec_level(client_ctx, ctrl->id, &ctrl->value); |
| 2377 | break; |
| 2378 | case V4L2_CID_MPEG_VIDEO_H264_PROFILE: |
| 2379 | rc = venc_get_codec_profile(client_ctx, ctrl->id, &ctrl->value); |
| 2380 | break; |
Deva Ramasubramanian | 3f2e602 | 2012-02-06 15:02:51 -0800 | [diff] [blame] | 2381 | case V4L2_CID_MPEG_VIDEO_H264_I_PERIOD: |
| 2382 | rc = venc_get_h264_intra_period(client_ctx, &ctrl->value); |
| 2383 | break; |
| 2384 | case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP: |
| 2385 | case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP: |
| 2386 | case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP: |
| 2387 | case V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP: |
| 2388 | case V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP: |
| 2389 | case V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP: |
| 2390 | case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP: |
| 2391 | case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP: |
| 2392 | case V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP: |
| 2393 | rc = venc_get_qp_value(client_ctx, ctrl->id, &ctrl->value); |
| 2394 | break; |
| 2395 | case V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP: |
| 2396 | case V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP: |
| 2397 | case V4L2_CID_MPEG_VIDEO_H263_MIN_QP: |
| 2398 | case V4L2_CID_MPEG_VIDEO_H263_MAX_QP: |
| 2399 | case V4L2_CID_MPEG_VIDEO_H264_MIN_QP: |
| 2400 | case V4L2_CID_MPEG_VIDEO_H264_MAX_QP: |
| 2401 | rc = venc_get_qp_range(client_ctx, ctrl->id, &ctrl->value); |
| 2402 | break; |
Deva Ramasubramanian | c84975c | 2012-03-10 21:16:27 -0800 | [diff] [blame] | 2403 | case V4L2_CID_MPEG_VIDEO_HEADER_MODE: |
| 2404 | rc = venc_get_header_mode(client_ctx, &ctrl->value); |
| 2405 | break; |
Deva Ramasubramanian | 607fbf2 | 2012-04-03 16:23:11 -0700 | [diff] [blame] | 2406 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES: |
| 2407 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB: |
| 2408 | case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE: |
| 2409 | rc = venc_get_multislicing_mode(client_ctx, ctrl->id, |
| 2410 | &ctrl->value); |
| 2411 | break; |
Deva Ramasubramanian | f94df43 | 2012-04-29 11:09:03 -0700 | [diff] [blame] | 2412 | case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE: |
| 2413 | rc = venc_get_entropy_mode(client_ctx, &ctrl->value); |
| 2414 | break; |
Deva Ramasubramanian | e5ce772 | 2012-04-30 11:27:45 -0700 | [diff] [blame] | 2415 | case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB: |
| 2416 | rc = venc_get_cyclic_intra_refresh_mb(client_ctx, &ctrl->value); |
| 2417 | break; |
Srinu Gorle | efe5bf3 | 2012-09-05 13:02:13 +0530 | [diff] [blame] | 2418 | case V4L2_CID_MPEG_VIDC_VIDEO_H264_AU_DELIMITER: |
| 2419 | rc = venc_get_avc_delimiter(client_ctx, &ctrl->value); |
| 2420 | break; |
Srinu Gorle | 4f8bc3a | 2012-11-15 09:36:38 +0530 | [diff] [blame] | 2421 | case V4L2_CID_MPEG_VIDC_VIDEO_H264_VUI_TIMING_INFO: |
| 2422 | rc = venc_get_vui_timing_info(client_ctx, &ctrl->value); |
| 2423 | break; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2424 | default: |
| 2425 | WFD_MSG_ERR("Get property not suported: %d\n", ctrl->id); |
| 2426 | rc = -ENOTSUPP; |
| 2427 | break; |
| 2428 | } |
| 2429 | return rc; |
| 2430 | } |
| 2431 | |
Deva Ramasubramanian | a9c2ed1 | 2012-07-31 11:11:46 -0700 | [diff] [blame] | 2432 | long venc_mmap(struct v4l2_subdev *sd, void *arg) |
| 2433 | { |
| 2434 | struct venc_inst *inst = sd->dev_priv; |
| 2435 | struct mem_region_map *mmap = arg; |
| 2436 | struct mem_region *mregion = NULL; |
| 2437 | unsigned long rc = 0, size = 0; |
| 2438 | void *paddr = NULL; |
| 2439 | |
| 2440 | if (!sd) { |
| 2441 | WFD_MSG_ERR("Subdevice required for %s\n", __func__); |
| 2442 | return -EINVAL; |
| 2443 | } else if (!mmap || !mmap->mregion) { |
| 2444 | WFD_MSG_ERR("Memregion required for %s\n", __func__); |
| 2445 | return -EINVAL; |
| 2446 | } |
| 2447 | |
| 2448 | mregion = mmap->mregion; |
| 2449 | if (mregion->size % SZ_4K != 0) { |
| 2450 | WFD_MSG_ERR("Memregion not aligned to %d\n", SZ_4K); |
| 2451 | return -EINVAL; |
| 2452 | } |
| 2453 | |
| 2454 | if (inst->secure) { |
| 2455 | rc = ion_phys(mmap->ion_client, mregion->ion_handle, |
| 2456 | (unsigned long *)&paddr, |
| 2457 | (size_t *)&size); |
| 2458 | } else { |
| 2459 | rc = ion_map_iommu(mmap->ion_client, mregion->ion_handle, |
| 2460 | VIDEO_DOMAIN, VIDEO_MAIN_POOL, SZ_4K, |
| 2461 | 0, (unsigned long *)&paddr, |
| 2462 | &size, 0, 0); |
| 2463 | } |
| 2464 | |
| 2465 | if (rc) { |
| 2466 | WFD_MSG_ERR("Failed to get physical addr\n"); |
| 2467 | paddr = NULL; |
| 2468 | } else if (size < mregion->size) { |
| 2469 | WFD_MSG_ERR("Failed to map enough memory\n"); |
| 2470 | rc = -ENOMEM; |
| 2471 | } |
| 2472 | |
| 2473 | mregion->paddr = paddr; |
| 2474 | return rc; |
| 2475 | } |
| 2476 | |
| 2477 | long venc_munmap(struct v4l2_subdev *sd, void *arg) |
| 2478 | { |
| 2479 | struct venc_inst *inst = sd->dev_priv; |
| 2480 | struct mem_region_map *mmap = arg; |
| 2481 | struct mem_region *mregion = NULL; |
| 2482 | if (!sd) { |
| 2483 | WFD_MSG_ERR("Subdevice required for %s\n", __func__); |
| 2484 | return -EINVAL; |
| 2485 | } else if (!mregion) { |
| 2486 | WFD_MSG_ERR("Memregion required for %s\n", __func__); |
| 2487 | return -EINVAL; |
| 2488 | } |
| 2489 | |
| 2490 | mregion = mmap->mregion; |
| 2491 | if (!inst->secure) { |
| 2492 | ion_unmap_iommu(mmap->ion_client, mregion->ion_handle, |
| 2493 | VIDEO_DOMAIN, VIDEO_MAIN_POOL); |
| 2494 | } |
| 2495 | |
| 2496 | return 0; |
| 2497 | } |
| 2498 | |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2499 | long venc_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) |
| 2500 | { |
| 2501 | long rc = 0; |
| 2502 | switch (cmd) { |
| 2503 | case OPEN: |
| 2504 | rc = venc_open(sd, arg); |
| 2505 | break; |
| 2506 | case CLOSE: |
| 2507 | rc = venc_close(sd, arg); |
| 2508 | break; |
| 2509 | case ENCODE_START: |
| 2510 | rc = venc_start(sd); |
| 2511 | break; |
| 2512 | case ENCODE_FRAME: |
| 2513 | venc_encode_frame(sd, arg); |
| 2514 | break; |
| 2515 | case ENCODE_STOP: |
| 2516 | rc = venc_stop(sd); |
| 2517 | break; |
| 2518 | case SET_PROP: |
| 2519 | rc = venc_set_property(sd, arg); |
| 2520 | break; |
| 2521 | case GET_PROP: |
| 2522 | rc = venc_get_property(sd, arg); |
| 2523 | break; |
| 2524 | case GET_BUFFER_REQ: |
| 2525 | rc = venc_get_buffer_req(sd, arg); |
| 2526 | break; |
| 2527 | case SET_BUFFER_REQ: |
| 2528 | rc = venc_set_buffer_req(sd, arg); |
| 2529 | break; |
| 2530 | case FREE_BUFFER: |
| 2531 | break; |
| 2532 | case FILL_OUTPUT_BUFFER: |
| 2533 | rc = venc_fill_outbuf(sd, arg); |
| 2534 | break; |
| 2535 | case SET_FORMAT: |
| 2536 | rc = venc_set_format(sd, arg); |
| 2537 | break; |
| 2538 | case SET_FRAMERATE: |
| 2539 | rc = venc_set_framerate(sd, arg); |
| 2540 | break; |
Deva Ramasubramanian | 2e99bff | 2012-02-13 21:12:08 -0800 | [diff] [blame] | 2541 | case SET_INPUT_BUFFER: |
| 2542 | rc = venc_set_input_buffer(sd, arg); |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2543 | break; |
| 2544 | case SET_OUTPUT_BUFFER: |
| 2545 | rc = venc_set_output_buffer(sd, arg); |
| 2546 | break; |
| 2547 | case ALLOC_RECON_BUFFERS: |
| 2548 | rc = venc_alloc_recon_buffers(sd, arg); |
| 2549 | break; |
| 2550 | case FREE_OUTPUT_BUFFER: |
| 2551 | rc = venc_free_output_buffer(sd, arg); |
| 2552 | break; |
| 2553 | case FREE_INPUT_BUFFER: |
| 2554 | rc = venc_free_input_buffer(sd, arg); |
| 2555 | break; |
| 2556 | case FREE_RECON_BUFFERS: |
| 2557 | rc = venc_free_recon_buffers(sd, arg); |
| 2558 | break; |
Vinay Kalia | b6dd587 | 2012-04-05 15:24:58 -0700 | [diff] [blame] | 2559 | case ENCODE_FLUSH: |
| 2560 | rc = venc_flush_buffers(sd, arg); |
| 2561 | break; |
Deva Ramasubramanian | a9c2ed1 | 2012-07-31 11:11:46 -0700 | [diff] [blame] | 2562 | case ENC_MMAP: |
| 2563 | rc = venc_mmap(sd, arg); |
| 2564 | break; |
| 2565 | case ENC_MUNMAP: |
| 2566 | rc = venc_munmap(sd, arg); |
| 2567 | break; |
Srinu Gorle | 4f8bc3a | 2012-11-15 09:36:38 +0530 | [diff] [blame] | 2568 | case SET_FRAMERATE_MODE: |
| 2569 | rc = venc_set_framerate_mode(sd, arg); |
| 2570 | break; |
Vinay Kalia | 699edcf | 2011-12-01 17:43:47 -0800 | [diff] [blame] | 2571 | default: |
| 2572 | rc = -1; |
| 2573 | break; |
| 2574 | } |
| 2575 | return rc; |
| 2576 | } |