13d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel/* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved. 23d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 33d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Redistribution and use in source and binary forms, with or without 43d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * modification, are permitted provided that the following conditions are 53d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * met: 63d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * * Redistributions of source code must retain the above copyright 73d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * notice, this list of conditions and the following disclaimer. 83d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * * Redistributions in binary form must reproduce the above 93d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * copyright notice, this list of conditions and the following 103d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * disclaimer in the documentation and/or other materials provided 113d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * with the distribution. 123d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * * Neither the name of The Linux Foundation nor the names of its 133d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * contributors may be used to endorse or promote products derived 143d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * from this software without specific prior written permission. 153d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 163d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 173d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 183d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 193d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 203d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 213d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 223d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 233d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 243d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 253d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 263d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 273d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 283d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel */ 293d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 303d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel// To remove 313d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel#include <utils/Log.h> 323d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 333d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel// System dependencies 343d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel#include <errno.h> 353d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel#include <fcntl.h> 363d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel#include <poll.h> 373d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel#include <pthread.h> 383d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel#include <sys/ioctl.h> 393d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel#include <sys/prctl.h> 403d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel#include <sys/stat.h> 413d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel#include <sys/types.h> 423d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 433d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel// Camera dependencies 443d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel#include "img_common.h" 453d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel#include "img_comp.h" 463d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel#include "img_comp_factory.h" 473d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel#include "img_buffer.h" 483d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel#include "lib2d.h" 493d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel#include "mm_lib2d.h" 503d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel#include "img_meta.h" 513d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 523d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel/** lib2d_job_private_info 533d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * @jobid: Job id of this process request 543d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * @userdata: Client userdata that will be passed on callback 553d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * @lib2d_client_cb: Application's callback function pointer 563d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * which will be called upon completion of current job. 573d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel**/ 583d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudeltypedef struct lib2d_job_private_info_t { 593d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel int jobid; 603d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel void *userdata; 613d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel lib2d_error (*lib2d_client_cb) (void *userdata, int jobid); 623d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel} lib2d_job_private_info; 633d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 643d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel/** img_lib_t 653d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * @ptr: handle to imglib library 663d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * @img_core_get_comp: function pointer for img_core_get_comp 673d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * @img_wait_for_completion: function pointer for img_wait_for_completion 683d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel**/ 693d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudeltypedef struct { 703d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel void *ptr; 713d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel int (*img_core_get_comp) (img_comp_role_t role, char *name, 723d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel img_core_ops_t *p_ops); 733d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel int (*img_wait_for_completion) (pthread_cond_t *p_cond, 743d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel pthread_mutex_t *p_mutex, int32_t ms); 753d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel} img_lib_t; 763d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 773d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel/** mm_lib2d_obj 783d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * @core_ops: image core ops structure handle 793d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * @comp: component structure handle 803d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * @comp_mode: underlying component mode 813d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * @lib2d_mode: lib2d mode requested by client 823d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * @img_lib: imglib library, function ptrs handle 833d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * @mutex: lib2d mutex used for synchronization 843d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * @cond: librd cond used for synchronization 853d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel**/ 863d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudeltypedef struct mm_lib2d_obj_t { 873d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel img_core_ops_t core_ops; 883d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel img_component_ops_t comp; 893d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel img_comp_mode_t comp_mode; 903d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel lib2d_mode lib2d_mode; 913d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel img_lib_t img_lib; 923d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel pthread_mutex_t mutex; 933d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel pthread_cond_t cond; 943d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel} mm_lib2d_obj; 953d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 963d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 973d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel/** 983d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Function: lib2d_event_handler 993d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 1003d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Description: Event handler. All the component events 1013d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * are received here. 1023d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 1033d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Input parameters: 1043d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * p_appdata - lib2d test object 1053d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * p_event - pointer to the event 1063d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 1073d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Return values: 1083d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * IMG_SUCCESS 1093d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * IMG_ERR_INVALID_INPUT 1103d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 1113d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Notes: none 1123d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel **/ 1133d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudelint lib2d_event_handler(void* p_appdata, img_event_t *p_event) 1143d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel{ 1153d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel mm_lib2d_obj *lib2d_obj = (mm_lib2d_obj *)p_appdata; 1163d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 1173d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if ((NULL == p_event) || (NULL == p_appdata)) { 1183d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("invalid event"); 1193d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return IMG_ERR_INVALID_INPUT; 1203d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 1213d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 1223d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGD("type %d", p_event->type); 1233d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 1243d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel switch (p_event->type) { 1253d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel case QIMG_EVT_DONE: 1263d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel pthread_cond_signal(&lib2d_obj->cond); 1273d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel break; 1283d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel default:; 1293d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 1303d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return IMG_SUCCESS; 1313d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel} 1323d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 1333d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel/** 1343d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Function: lib2d_callback_handler 1353d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 1363d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Description: Callback handler. Registered with Component 1373d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * on IMG_COMP_INIT. Will be called when processing 1383d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * of current request is completed. If component running in 1393d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * async mode, this is where client will know the execution 1403d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * is finished for in, out frames. 1413d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 1423d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Input parameters: 1433d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * p_appdata - lib2d test object 1443d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * p_in_frame - pointer to input frame 1453d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * p_out_frame - pointer to output frame 1463d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * p_meta - pointer to meta data 1473d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 1483d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Return values: 1493d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * IMG_SUCCESS 1503d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * IMG_ERR_GENERAL 1513d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 1523d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Notes: none 1533d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel **/ 1543d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudelint lib2d_callback_handler(void *userdata, img_frame_t *p_in_frame, 1553d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel img_frame_t *p_out_frame, img_meta_t *p_meta) 1563d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel{ 1573d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel lib2d_job_private_info *job_info = NULL; 1583d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 1593d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (NULL == userdata) { 1603d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("invalid event"); 1613d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return IMG_ERR_INVALID_INPUT; 1623d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 1633d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 1643d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel // assert(p_in_frame->private_data == p_out_frame->private_data); 1653d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 1663d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel job_info = (lib2d_job_private_info *)p_in_frame->private_data; 1673d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (job_info->lib2d_client_cb != NULL) { 1683d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel job_info->lib2d_client_cb(job_info->userdata, job_info->jobid); 1693d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 1703d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 1713d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel free(p_in_frame->private_data); 1723d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel free(p_in_frame); 1733d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel free(p_out_frame); 1743d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel free(p_meta); 1753d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 1763d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return IMG_SUCCESS; 1773d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel} 1783d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 1793d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel/** 1803d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Function: lib2d_fill_img_frame 1813d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 1823d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Description: Setup img_frame_t for given buffer 1833d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 1843d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Input parameters: 1853d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * p_frame - pointer to img_frame_t that needs to be setup 1863d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * lib2d_buffer - pointer to input buffer 1873d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * jobid - job id 1883d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 1893d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Return values: 1903d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * MM_LIB2D_SUCCESS 1913d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * MM_LIB2D_ERR_GENERAL 1923d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 1933d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Notes: none 1943d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel **/ 1953d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudellib2d_error lib2d_fill_img_frame(img_frame_t *p_frame, 1963d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel mm_lib2d_buffer* lib2d_buffer, int jobid) 1973d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel{ 1983d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel // use job id for now 1993d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame_cnt = jobid; 2003d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->idx = jobid; 2013d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame_id = jobid; 2023d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 2033d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (lib2d_buffer->buffer_type == MM_LIB2D_BUFFER_TYPE_RGB) { 2043d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel mm_lib2d_rgb_buffer *rgb_buffer = &lib2d_buffer->rgb_buffer; 2053d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 2063d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->info.num_planes = 1; 2073d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->info.width = rgb_buffer->width; 2083d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->info.height = rgb_buffer->height; 2093d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 2103d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane_cnt = 1; 2113d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[0].plane_type = PLANE_ARGB; 2123d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[0].addr = rgb_buffer->buffer; 2133d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[0].stride = rgb_buffer->stride; 2143d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[0].length = (rgb_buffer->stride * 2153d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel rgb_buffer->height); 2163d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[0].fd = rgb_buffer->fd; 2173d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[0].height = rgb_buffer->height; 2183d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[0].width = rgb_buffer->width; 2193d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[0].offset = 0; 2203d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[0].scanline = rgb_buffer->height; 2213d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } else if (lib2d_buffer->buffer_type == MM_LIB2D_BUFFER_TYPE_YUV) { 2223d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel mm_lib2d_yuv_buffer *yuv_buffer = &lib2d_buffer->yuv_buffer; 2233d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 2243d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->info.num_planes = 2; 2253d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->info.width = yuv_buffer->width; 2263d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->info.height = yuv_buffer->height; 2273d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 2283d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane_cnt = 2; 2293d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[0].plane_type = PLANE_Y; 2303d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[0].addr = yuv_buffer->plane0; 2313d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[0].stride = yuv_buffer->stride0; 2323d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[0].length = (yuv_buffer->stride0 * 2333d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel yuv_buffer->height); 2343d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[0].fd = yuv_buffer->fd; 2353d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[0].height = yuv_buffer->height; 2363d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[0].width = yuv_buffer->width; 2373d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[0].offset = 0; 2383d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[0].scanline = yuv_buffer->height; 2393d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 2403d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (yuv_buffer->format == CAM_FORMAT_YUV_420_NV12) { 2413d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[1].plane_type = PLANE_CB_CR; 2423d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } else if(yuv_buffer->format == CAM_FORMAT_YUV_420_NV21) { 2433d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[1].plane_type = PLANE_CR_CB; 2443d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 2453d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[1].addr = yuv_buffer->plane1; 2463d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[1].stride = yuv_buffer->stride1; 2473d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[1].length = (yuv_buffer->stride1 * 2483d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel yuv_buffer->height / 2); 2493d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[1].fd = yuv_buffer->fd; 2503d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[1].height = yuv_buffer->height; 2513d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[1].width = yuv_buffer->width; 2523d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[1].offset = 0; 2533d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_frame->frame[0].plane[1].scanline = yuv_buffer->height; 2543d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } else { 2553d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return MM_LIB2D_ERR_GENERAL; 2563d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 2573d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 2583d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return MM_LIB2D_SUCCESS; 2593d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel} 2603d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 2613d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel/** 2623d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Function: mm_lib2d_init 2633d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 2643d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Description: Initialization function for Lib2D. src_format, dst_format 2653d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * are hints to the underlying component to initialize. 2663d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 2673d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Input parameters: 2683d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * mode - Mode (sync/async) in which App wants lib2d to run. 2693d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * src_format - source surface format 2703d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * dst_format - Destination surface format 2713d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * my_obj - handle that will be returned on succesful Init. App has to 2723d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * call other lib2d functions by passing this handle. 2733d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 2743d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Return values: 2753d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * MM_LIB2D_SUCCESS 2763d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * MM_LIB2D_ERR_MEMORY 2773d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * MM_LIB2D_ERR_BAD_PARAM 2783d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * MM_LIB2D_ERR_GENERAL 2793d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 2803d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Notes: none 2813d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel **/ 2823d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 2833d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudellib2d_error mm_lib2d_init(lib2d_mode mode, cam_format_t src_format, 2843d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel cam_format_t dst_format, void **my_obj) 2853d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel{ 2863d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel int32_t rc = IMG_SUCCESS; 2873d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel mm_lib2d_obj *lib2d_obj = NULL; 2883d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel img_core_ops_t *p_core_ops = NULL; 2893d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel img_component_ops_t *p_comp = NULL; 2903d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 2913d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (my_obj == NULL) { 2923d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return MM_LIB2D_ERR_BAD_PARAM; 2933d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 2943d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 2953d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel // validate src_format, dst_format to check whether we support these. 2963d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel // Currently support NV21 to ARGB conversions only. Others not tested. 2973d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if ((src_format != CAM_FORMAT_YUV_420_NV21) || 2983d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel (dst_format != CAM_FORMAT_8888_ARGB)) { 2993d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("Formats conversion from %d to %d not supported", 3003d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel src_format, dst_format); 3013d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 3023d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 3033d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel lib2d_obj = malloc(sizeof(mm_lib2d_obj)); 3043d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (lib2d_obj == NULL) { 3053d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return MM_LIB2D_ERR_MEMORY; 3063d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 3073d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 3083d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel // Open libmmcamera_imglib 3093d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel lib2d_obj->img_lib.ptr = dlopen("libmmcamera_imglib.so", RTLD_NOW); 3103d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (!lib2d_obj->img_lib.ptr) { 3113d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("ERROR: couldn't dlopen libmmcamera_imglib.so: %s", 3123d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel dlerror()); 3133d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel goto FREE_LIB2D_OBJ; 3143d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 3153d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 3163d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel /* Get function pointer for functions supported by C2D */ 3173d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel *(void **)&lib2d_obj->img_lib.img_core_get_comp = 3183d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel dlsym(lib2d_obj->img_lib.ptr, "img_core_get_comp"); 3193d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel *(void **)&lib2d_obj->img_lib.img_wait_for_completion = 3203d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel dlsym(lib2d_obj->img_lib.ptr, "img_wait_for_completion"); 3213d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 3223d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel /* Validate function pointers */ 3233d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if ((lib2d_obj->img_lib.img_core_get_comp == NULL) || 3243d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel (lib2d_obj->img_lib.img_wait_for_completion == NULL)) { 3253d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE(" ERROR mapping symbols from libc2d2.so"); 3263d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel goto FREE_LIB2D_OBJ; 3273d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 3283d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 3293d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_core_ops = &lib2d_obj->core_ops; 3303d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_comp = &lib2d_obj->comp; 3313d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 3323d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel pthread_mutex_init(&lib2d_obj->mutex, NULL); 3333d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel pthread_cond_init(&lib2d_obj->cond, NULL); 3343d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 3353d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel rc = lib2d_obj->img_lib.img_core_get_comp(IMG_COMP_LIB2D, 3363d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel "qti.lib2d", p_core_ops); 3373d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (rc != IMG_SUCCESS) { 3383d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("rc %d", rc); 3393d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel goto FREE_LIB2D_OBJ; 3403d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 3413d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 3423d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel rc = IMG_COMP_LOAD(p_core_ops, NULL); 3433d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (rc != IMG_SUCCESS) { 3443d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("rc %d", rc); 3453d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel goto FREE_LIB2D_OBJ; 3463d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 3473d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 3483d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel rc = IMG_COMP_CREATE(p_core_ops, p_comp); 3493d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (rc != IMG_SUCCESS) { 3503d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("rc %d", rc); 3513d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel goto COMP_UNLOAD; 3523d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 3533d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 3543d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel rc = IMG_COMP_INIT(p_comp, (void *)lib2d_obj, lib2d_callback_handler); 3553d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (rc != IMG_SUCCESS) { 3563d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("rc %d", rc); 3573d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel goto COMP_UNLOAD; 3583d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 3593d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 3603d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel rc = IMG_COMP_SET_CB(p_comp, lib2d_event_handler); 3613d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (rc != IMG_SUCCESS) { 3623d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("rc %d", rc); 3633d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel goto COMP_DEINIT; 3643d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 3653d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 3663d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel lib2d_obj->lib2d_mode = mode; 3673d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel img_comp_mode_t comp_mode; 3683d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (lib2d_obj->lib2d_mode == MM_LIB2D_SYNC_MODE) { 3693d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel comp_mode = IMG_SYNC_MODE; 3703d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } else { 3713d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel comp_mode = IMG_ASYNC_MODE; 3723d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 3733d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 3743d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel // Set source format 3753d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel rc = IMG_COMP_SET_PARAM(p_comp, QLIB2D_SOURCE_FORMAT, (void *)&src_format); 3763d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (rc != IMG_SUCCESS) { 3773d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("rc %d", rc); 3783d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel goto COMP_DEINIT; 3793d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 3803d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 3813d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel // Set destination format 3823d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel rc = IMG_COMP_SET_PARAM(p_comp, QLIB2D_DESTINATION_FORMAT, 3833d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel (void *)&dst_format); 3843d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (rc != IMG_SUCCESS) { 3853d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("rc %d", rc); 3863d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel goto COMP_DEINIT; 3873d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 3883d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 3893d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel // Try setting the required mode. 3903d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel rc = IMG_COMP_SET_PARAM(p_comp, QIMG_PARAM_MODE, (void *)&comp_mode); 3913d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (rc != IMG_SUCCESS) { 3923d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("rc %d", rc); 3933d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel goto COMP_DEINIT; 3943d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 3953d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 3963d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel // Get the mode to make sure whether the component is really running 3973d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel // in the mode what we set. 3983d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel rc = IMG_COMP_GET_PARAM(p_comp, QIMG_PARAM_MODE, 3993d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel (void *)&lib2d_obj->comp_mode); 4003d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (rc != IMG_SUCCESS) { 4013d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("rc %d", rc); 4023d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel goto COMP_DEINIT; 4033d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 4043d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 4053d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (comp_mode != lib2d_obj->comp_mode) { 4063d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGD("Component is running in %d mode", 4073d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel lib2d_obj->comp_mode); 4083d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 4093d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 4103d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel *my_obj = (void *)lib2d_obj; 4113d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 4123d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return MM_LIB2D_SUCCESS; 4133d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 4143d63919a23d7e7954e160c48c36713267106c3c2Thierry StrudelCOMP_DEINIT : 4153d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel rc = IMG_COMP_DEINIT(p_comp); 4163d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (rc != IMG_SUCCESS) { 4173d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("rc %d", rc); 4183d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return MM_LIB2D_ERR_GENERAL; 4193d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 4203d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 4213d63919a23d7e7954e160c48c36713267106c3c2Thierry StrudelCOMP_UNLOAD : 4223d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel rc = IMG_COMP_UNLOAD(p_core_ops); 4233d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (rc != IMG_SUCCESS) { 4243d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("rc %d", rc); 4253d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return MM_LIB2D_ERR_GENERAL; 4263d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 4273d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 4283d63919a23d7e7954e160c48c36713267106c3c2Thierry StrudelFREE_LIB2D_OBJ : 4293d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel free(lib2d_obj); 4303d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return MM_LIB2D_ERR_GENERAL; 4313d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel} 4323d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 4333d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel/** 4343d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Function: mm_lib2d_deinit 4353d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 4363d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Description: De-Initialization function for Lib2D 4373d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 4383d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Input parameters: 4393d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * lib2d_obj_handle - handle tto the lib2d object 4403d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 4413d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Return values: 4423d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * MM_LIB2D_SUCCESS 4433d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * MM_LIB2D_ERR_GENERAL 4443d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 4453d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Notes: none 4463d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel **/ 4473d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudellib2d_error mm_lib2d_deinit(void *lib2d_obj_handle) 4483d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel{ 4493d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel mm_lib2d_obj *lib2d_obj = (mm_lib2d_obj *)lib2d_obj_handle; 4503d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel int rc = IMG_SUCCESS; 4513d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel img_core_ops_t *p_core_ops = &lib2d_obj->core_ops; 4523d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel img_component_ops_t *p_comp = &lib2d_obj->comp; 4533d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 4543d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel rc = IMG_COMP_DEINIT(p_comp); 4553d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (rc != IMG_SUCCESS) { 4563d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("rc %d", rc); 4573d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return MM_LIB2D_ERR_GENERAL; 4583d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 4593d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 4603d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel rc = IMG_COMP_UNLOAD(p_core_ops); 4613d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (rc != IMG_SUCCESS) { 4623d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("rc %d", rc); 4633d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return MM_LIB2D_ERR_GENERAL; 4643d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 4653d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 4663d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel dlclose(lib2d_obj->img_lib.ptr); 4673d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel free(lib2d_obj); 4683d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 4693d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return MM_LIB2D_SUCCESS; 4703d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel} 4713d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 4723d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel/** 4733d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Function: mm_lib2d_start_job 4743d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 4753d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Description: Start executing the job 4763d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 4773d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Input parameters: 4783d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * lib2d_obj_handle - handle tto the lib2d object 4793d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * src_buffer - pointer to the source buffer 4803d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * dst_buffer - pointer to the destination buffer 4813d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * jobid - job id of this request 4823d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * userdata - userdata that will be pass through callback function 4833d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * cb - callback function that will be called on completion of this job 4843d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * rotation - rotation to be applied 4853d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 4863d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Return values: 4873d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * MM_LIB2D_SUCCESS 4883d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * MM_LIB2D_ERR_MEMORY 4893d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * MM_LIB2D_ERR_GENERAL 4903d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * 4913d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel * Notes: none 4923d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel **/ 4933d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudellib2d_error mm_lib2d_start_job(void *lib2d_obj_handle, 4943d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel mm_lib2d_buffer* src_buffer, mm_lib2d_buffer* dst_buffer, 4953d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel int jobid, void *userdata, lib2d_client_cb cb, uint32_t rotation) 4963d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel{ 4973d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel mm_lib2d_obj *lib2d_obj = (mm_lib2d_obj *)lib2d_obj_handle; 4983d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel int rc = IMG_SUCCESS; 4993d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel img_component_ops_t *p_comp = &lib2d_obj->comp; 5003d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 5013d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel img_frame_t *p_in_frame = malloc(sizeof(img_frame_t)); 5023d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (p_in_frame == NULL) { 5033d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return MM_LIB2D_ERR_MEMORY; 5043d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 5053d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 5063d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel img_frame_t *p_out_frame = malloc(sizeof(img_frame_t)); 5073d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (p_out_frame == NULL) { 5083d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel free(p_in_frame); 5093d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return MM_LIB2D_ERR_MEMORY; 5103d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 5113d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 5123d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel img_meta_t *p_meta = malloc(sizeof(img_meta_t)); 5133d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (p_meta == NULL) { 5143d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel free(p_in_frame); 5153d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel free(p_out_frame); 5163d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return MM_LIB2D_ERR_MEMORY; 5173d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 5183d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 5193d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel lib2d_job_private_info *p_job_info = malloc(sizeof(lib2d_job_private_info)); 5203d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (p_out_frame == NULL) { 5213d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel free(p_in_frame); 5223d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel free(p_out_frame); 5233d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel free(p_meta); 5243d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return MM_LIB2D_ERR_MEMORY; 5253d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 5263d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 5273d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel memset(p_in_frame, 0x0, sizeof(img_frame_t)); 5283d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel memset(p_out_frame, 0x0, sizeof(img_frame_t)); 5293d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel memset(p_meta, 0x0, sizeof(img_meta_t)); 5303d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel memset(p_job_info, 0x0, sizeof(lib2d_job_private_info)); 5313d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 5323d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel // Fill up job info private data structure that can be used in callback to 5333d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel // inform back to the client. 5343d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_job_info->jobid = jobid; 5353d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_job_info->userdata = userdata; 5363d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_job_info->lib2d_client_cb = cb; 5373d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 5383d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_in_frame->private_data = (void *)p_job_info; 5393d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_out_frame->private_data = (void *)p_job_info; 5403d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 5413d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel // convert the input info into component understandble data structures 5423d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 5433d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel // Prepare Input, output frames 5443d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel lib2d_fill_img_frame(p_in_frame, src_buffer, jobid); 5453d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel lib2d_fill_img_frame(p_out_frame, dst_buffer, jobid); 5463d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 5473d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_meta->frame_id = jobid; 5483d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_meta->rotation.device_rotation = (int32_t)rotation; 5493d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel p_meta->rotation.frame_rotation = (int32_t)rotation; 5503d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 5513d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel // call set_param to set the source, destination formats 5523d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 5533d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel rc = IMG_COMP_Q_BUF(p_comp, p_in_frame, IMG_IN); 5543d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (rc != IMG_SUCCESS) { 5553d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("rc %d", rc); 5563d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel goto ERROR; 5573d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 5583d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 5593d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel rc = IMG_COMP_Q_BUF(p_comp, p_out_frame, IMG_OUT); 5603d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (rc != IMG_SUCCESS) { 5613d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("rc %d", rc); 5623d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel goto ERROR; 5633d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 5643d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 5653d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel rc = IMG_COMP_Q_META_BUF(p_comp, p_meta); 5663d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (rc != IMG_SUCCESS) { 5673d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("rc %d", rc); 5683d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel goto ERROR; 5693d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 5703d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 5713d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel rc = IMG_COMP_START(p_comp, NULL); 5723d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (rc != IMG_SUCCESS) { 5733d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("rc %d", rc); 5743d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel goto ERROR; 5753d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 5763d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 5773d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (lib2d_obj->lib2d_mode == MM_LIB2D_SYNC_MODE) { 5783d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (lib2d_obj->comp_mode == IMG_ASYNC_MODE) { 5793d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGD("before wait rc %d", rc); 5803d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel rc = lib2d_obj->img_lib.img_wait_for_completion(&lib2d_obj->cond, 5813d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel &lib2d_obj->mutex, 10000); 5823d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (rc != IMG_SUCCESS) { 5833d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("rc %d", rc); 5843d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel goto ERROR; 5853d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 5863d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 5873d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 5883d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 5893d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel rc = IMG_COMP_ABORT(p_comp, NULL); 5903d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel if (IMG_ERROR(rc)) { 5913d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel LOGE("comp abort failed %d", rc); 5923d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return rc; 5933d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel } 5943d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 5953d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return MM_LIB2D_SUCCESS; 5963d63919a23d7e7954e160c48c36713267106c3c2Thierry StrudelERROR: 5973d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel free(p_in_frame); 5983d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel free(p_out_frame); 5993d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel free(p_meta); 6003d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel free(p_job_info); 6013d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 6023d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel return MM_LIB2D_ERR_GENERAL; 6033d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel} 6043d63919a23d7e7954e160c48c36713267106c3c2Thierry Strudel 605