1 /* 2 * Copyright (c) 2010, Texas Instruments Incorporated 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * * Neither the name of Texas Instruments Incorporated nor the names of 17 * its contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /** 34 * @file omx_proxy_camera.c 35 * This file contains methods that provides the functionality for 36 * the OpenMAX1.1 DOMX Framework Tunnel Proxy component. 37 ****************************************************************************** 38 This is the proxy specific wrapper that passes the component name to the 39 generic proxy init() The proxy wrapper also does some runtime/static time 40 config on per proxy basis This is a thin wrapper that is called when 41 componentiit() of the proxy is called static OMX_ERRORTYPE PROXY_Wrapper_init 42 (OMX_HANDLETYPE hComponent, OMX_PTR pAppData); 43 this layer gets called first whenever a proxy s get handle is called 44 ****************************************************************************** 45 * @path WTSD_DucatiMMSW\omx\omx_il_1_x\omx_proxy_component\src 46 * 47 * @rev 1.0 48 */ 49 50 /*============================================================== 51 *! Revision History 52 *! ============================ 53 *! 19-August-2009 B Ravi Kiran ravi.kiran (at) ti.com: Initial Version 54 *================================================================*/ 55 56 /****************************************************************** 57 * INCLUDE FILES 58 ******************************************************************/ 59 #include <stdio.h> 60 #include <string.h> 61 #include <assert.h> 62 #include <dirent.h> 63 #include <stdio.h> 64 #include <string.h> 65 #include <pthread.h> 66 #include <sys/time.h> 67 #include <stdlib.h> 68 69 #include <timm_osal_interfaces.h> 70 #include <OMX_TI_IVCommon.h> 71 #include <OMX_TI_Index.h> 72 #include "omx_proxy_common.h" 73 #include "timm_osal_mutex.h" 74 75 #ifdef USE_ION 76 #include <unistd.h> 77 #include <ion.h> 78 #include <sys/ioctl.h> 79 #include <sys/mman.h> 80 #include <sys/eventfd.h> 81 #include <fcntl.h> 82 83 #else 84 /* Tiler APIs */ 85 #include <memmgr.h> 86 #endif 87 88 #define COMPONENT_NAME "OMX.TI.DUCATI1.VIDEO.CAMERA" 89 /*Needs to be specific for every configuration wrapper*/ 90 91 #undef LOG_TAG 92 #define LOG_TAG "CameraHAL" 93 94 #define DEFAULT_DCC 1 95 #ifdef _Android 96 #define DCC_PATH "/data/misc/camera/" 97 #else 98 #define DCC_PATH "/usr/share/omapcam/" 99 #endif 100 #define LINUX_PAGE_SIZE (4 * 1024) 101 102 #define _PROXY_OMX_INIT_PARAM(param,type) do { \ 103 TIMM_OSAL_Memset((param), 0, sizeof (type)); \ 104 (param)->nSize = sizeof (type); \ 105 (param)->nVersion.s.nVersionMajor = 1; \ 106 (param)->nVersion.s.nVersionMinor = 1; \ 107 } while(0) 108 109 /* Incase of multiple instance, making sure DCC is initialized only for 110 first instance */ 111 static OMX_S16 numofInstance = 0; 112 int dcc_flag = 0; 113 TIMM_OSAL_PTR cam_mutex = NULL; 114 115 /* To store DCC buffer size */ 116 OMX_S32 dccbuf_size = 0; 117 118 /* Ducati Mapped Addr */ 119 OMX_PTR DCC_Buff = NULL; 120 121 #ifdef USE_ION 122 OMX_PTR DCC_Buff_ptr = NULL; 123 int ion_fd; 124 int mmap_fd; 125 126 #else 127 MemAllocBlock *MemReqDescTiler; 128 #endif 129 130 OMX_S32 read_DCCdir(OMX_PTR, OMX_STRING *, OMX_U16); 131 OMX_ERRORTYPE DCC_Init(OMX_HANDLETYPE); 132 OMX_ERRORTYPE send_DCCBufPtr(OMX_HANDLETYPE hComponent); 133 void DCC_DeInit(); 134 OMX_ERRORTYPE PROXY_ComponentDeInit(OMX_HANDLETYPE); 135 OMX_ERRORTYPE __PROXY_SetConfig(OMX_HANDLETYPE, OMX_INDEXTYPE, 136 OMX_PTR, OMX_PTR); 137 OMX_ERRORTYPE __PROXY_GetConfig(OMX_HANDLETYPE, OMX_INDEXTYPE, 138 OMX_PTR, OMX_PTR); 139 OMX_ERRORTYPE __PROXY_SetParameter(OMX_IN OMX_HANDLETYPE, OMX_INDEXTYPE, 140 OMX_PTR, OMX_PTR); 141 OMX_ERRORTYPE __PROXY_GetParameter(OMX_IN OMX_HANDLETYPE, OMX_INDEXTYPE, 142 OMX_PTR, OMX_PTR); 143 OMX_ERRORTYPE CameraMaptoTilerDuc(OMX_TI_CONFIG_SHAREDBUFFER *, OMX_PTR *); 144 //COREID TARGET_CORE_ID = CORE_APPM3; 145 146 static OMX_ERRORTYPE ComponentPrivateDeInit(OMX_IN OMX_HANDLETYPE hComponent) 147 { 148 OMX_ERRORTYPE eError = OMX_ErrorNone; 149 TIMM_OSAL_ERRORTYPE eOsalError = TIMM_OSAL_ERR_NONE; 150 151 if (dcc_flag) 152 { 153 eOsalError = 154 TIMM_OSAL_MutexObtain(cam_mutex, TIMM_OSAL_SUSPEND); 155 if (eOsalError != TIMM_OSAL_ERR_NONE) 156 { 157 TIMM_OSAL_Error("Mutex Obtain failed"); 158 } 159 160 numofInstance = numofInstance - 1; 161 162 eOsalError = TIMM_OSAL_MutexRelease(cam_mutex); 163 PROXY_assert(eOsalError == TIMM_OSAL_ERR_NONE, 164 OMX_ErrorInsufficientResources, "Mutex release failed"); 165 } 166 167 eError = PROXY_ComponentDeInit(hComponent); 168 169 EXIT: 170 return eError; 171 } 172 173 /* ===========================================================================*/ 174 /** 175 * @name CameraGetConfig() 176 * @brief For some specific indices, buffer allocated on A9 side 177 * needs to be mapped and sent to Ducati. 178 * @param 179 * @return OMX_ErrorNone = Successful 180 */ 181 /* ===========================================================================*/ 182 183 static OMX_ERRORTYPE CameraGetConfig(OMX_IN OMX_HANDLETYPE 184 hComponent, OMX_IN OMX_INDEXTYPE nParamIndex, 185 OMX_INOUT OMX_PTR pComponentParameterStructure) 186 { 187 OMX_ERRORTYPE eError = OMX_ErrorNone; 188 OMX_TI_CONFIG_SHAREDBUFFER *pConfigSharedBuffer = NULL; 189 OMX_PTR pTempSharedBuff = NULL; 190 OMX_U32 status = 0; 191 192 switch (nParamIndex) 193 { 194 case OMX_TI_IndexConfigAAAskipBuffer: 195 case OMX_TI_IndexConfigCamCapabilities: 196 case OMX_TI_IndexConfigExifTags: 197 case OMX_TI_IndexConfigAlgoAreas: 198 pConfigSharedBuffer = 199 (OMX_TI_CONFIG_SHAREDBUFFER *) pComponentParameterStructure; 200 201 pTempSharedBuff = pConfigSharedBuffer->pSharedBuff; 202 203 // TODO(XXX): Cache API is not yet available. Client needs to 204 // allocate tiler buffer directly and assign to pSharedBuff. 205 // Ptr allocated by MemMgr_Alloc in uncacheable so there 206 // would be no need to cache API 207 208 eError = __PROXY_GetConfig(hComponent, 209 nParamIndex, 210 pConfigSharedBuffer, 211 &(pConfigSharedBuffer->pSharedBuff)); 212 213 PROXY_assert((eError == OMX_ErrorNone), eError, 214 "Error in GetConfig"); 215 216 pConfigSharedBuffer->pSharedBuff = pTempSharedBuff; 217 218 goto EXIT; 219 break; 220 default: 221 break; 222 } 223 224 return __PROXY_GetConfig(hComponent, 225 nParamIndex, 226 pComponentParameterStructure, 227 NULL); 228 229 EXIT: 230 return eError; 231 } 232 233 /* ===========================================================================*/ 234 /** 235 * @name CameraSetConfig() 236 * @brief For some specific indices, buffer allocated on A9 side needs to 237 * be mapped and sent to Ducati. 238 * @param 239 * @return OMX_ErrorNone = Successful 240 */ 241 /* ===========================================================================*/ 242 243 244 static OMX_ERRORTYPE CameraSetConfig(OMX_IN OMX_HANDLETYPE 245 hComponent, OMX_IN OMX_INDEXTYPE nParamIndex, 246 OMX_INOUT OMX_PTR pComponentParameterStructure) 247 { 248 OMX_ERRORTYPE eError = OMX_ErrorNone; 249 OMX_TI_CONFIG_SHAREDBUFFER *pConfigSharedBuffer = NULL; 250 OMX_PTR pTempSharedBuff = NULL; 251 OMX_U32 status = 0; 252 253 switch (nParamIndex) 254 { 255 case OMX_TI_IndexConfigAAAskipBuffer: 256 case OMX_TI_IndexConfigCamCapabilities: 257 case OMX_TI_IndexConfigExifTags: 258 case OMX_TI_IndexConfigAlgoAreas: 259 pConfigSharedBuffer = 260 (OMX_TI_CONFIG_SHAREDBUFFER *) 261 pComponentParameterStructure; 262 263 pTempSharedBuff = pConfigSharedBuffer->pSharedBuff; 264 265 // TODO(XXX): Cache API is not yet available. Client needs to 266 // allocate tiler buffer directly and assign to pSharedBuff. 267 // Ptr allocated by MemMgr_Alloc in uncacheable so there 268 // would be no need to cache API 269 270 eError = __PROXY_SetConfig(hComponent, 271 nParamIndex, 272 pConfigSharedBuffer, 273 &(pConfigSharedBuffer->pSharedBuff)); 274 275 PROXY_assert((eError == OMX_ErrorNone), eError, 276 "Error in GetConfig"); 277 278 pConfigSharedBuffer->pSharedBuff = pTempSharedBuff; 279 280 goto EXIT; 281 break; 282 default: 283 break; 284 } 285 286 return __PROXY_SetConfig(hComponent, 287 nParamIndex, 288 pComponentParameterStructure, 289 NULL); 290 291 EXIT: 292 return eError; 293 } 294 295 OMX_ERRORTYPE OMX_ComponentInit(OMX_HANDLETYPE hComponent) 296 { 297 OMX_ERRORTYPE eError = OMX_ErrorNone; 298 OMX_ERRORTYPE dcc_eError = OMX_ErrorNone; 299 OMX_COMPONENTTYPE *pHandle = NULL; 300 PROXY_COMPONENT_PRIVATE *pComponentPrivate; 301 pHandle = (OMX_COMPONENTTYPE *) hComponent; 302 TIMM_OSAL_ERRORTYPE eOsalError = TIMM_OSAL_ERR_NONE; 303 DOMX_ENTER("_____________________INSIDE CAMERA PROXY" 304 "WRAPPER__________________________\n"); 305 pHandle->pComponentPrivate = (PROXY_COMPONENT_PRIVATE *) 306 TIMM_OSAL_Malloc(sizeof(PROXY_COMPONENT_PRIVATE), 307 TIMM_OSAL_TRUE, 0, TIMMOSAL_MEM_SEGMENT_INT); 308 309 pComponentPrivate = 310 (PROXY_COMPONENT_PRIVATE *) pHandle->pComponentPrivate; 311 if (pHandle->pComponentPrivate == NULL) 312 { 313 DOMX_ERROR(" ERROR IN ALLOCATING PROXY COMPONENT" 314 "PRIVATE STRUCTURE"); 315 eError = OMX_ErrorInsufficientResources; 316 goto EXIT; 317 } 318 TIMM_OSAL_Memset(pComponentPrivate, 0, 319 sizeof(PROXY_COMPONENT_PRIVATE)); 320 321 pComponentPrivate->cCompName = 322 TIMM_OSAL_Malloc(MAX_COMPONENT_NAME_LENGTH * sizeof(OMX_U8), 323 TIMM_OSAL_TRUE, 0, TIMMOSAL_MEM_SEGMENT_INT); 324 /*Copying component Name - this will be picked up in the proxy common */ 325 assert(strlen(COMPONENT_NAME) + 1 < MAX_COMPONENT_NAME_LENGTH); 326 TIMM_OSAL_Memcpy(pComponentPrivate->cCompName, COMPONENT_NAME, 327 strlen(COMPONENT_NAME) + 1); 328 329 /*Calling Proxy Common Init() */ 330 eError = OMX_ProxyCommonInit(hComponent); 331 if (eError != OMX_ErrorNone) 332 { 333 DOMX_ERROR("\Error in Initializing Proxy"); 334 TIMM_OSAL_Free(pComponentPrivate->cCompName); 335 TIMM_OSAL_Free(pComponentPrivate); 336 goto EXIT; 337 } 338 339 pHandle->ComponentDeInit = ComponentPrivateDeInit; 340 pHandle->GetConfig = CameraGetConfig; 341 pHandle->SetConfig = CameraSetConfig; 342 char *val = getenv("SET_DCC"); 343 dcc_flag = val ? strtol(val, NULL, 0) : DEFAULT_DCC; 344 DOMX_DEBUG(" DCC: 0 - disabled 1 - enabled : val: %d", dcc_flag); 345 346 if (dcc_flag) 347 { 348 eOsalError = 349 TIMM_OSAL_MutexObtain(cam_mutex, TIMM_OSAL_SUSPEND); 350 PROXY_assert(eOsalError == TIMM_OSAL_ERR_NONE, 351 OMX_ErrorInsufficientResources, "Mutex lock failed"); 352 353 if (numofInstance == 0) 354 { 355 dcc_eError = DCC_Init(hComponent); 356 if (dcc_eError != OMX_ErrorNone) 357 { 358 DOMX_DEBUG(" Error in DCC Init"); 359 } 360 361 /* Configure Ducati to use DCC buffer from A9 side 362 *ONLY* if DCC_Init is successful. */ 363 if (dcc_eError == OMX_ErrorNone) 364 { 365 dcc_eError = send_DCCBufPtr(hComponent); 366 if (dcc_eError != OMX_ErrorNone) 367 { 368 DOMX_DEBUG(" Error in Sending DCC Buf ptr"); 369 } 370 DCC_DeInit(); 371 } 372 } 373 numofInstance = numofInstance + 1; 374 eOsalError = TIMM_OSAL_MutexRelease(cam_mutex); 375 PROXY_assert(eOsalError == TIMM_OSAL_ERR_NONE, 376 OMX_ErrorInsufficientResources, "Mutex release failed"); 377 } 378 EXIT: 379 return eError; 380 } 381 382 /* ===========================================================================*/ 383 /** 384 * @name DCC_Init() 385 * @brief 386 * @param void 387 * @return OMX_ErrorNone = Successful 388 * @sa TBD 389 * 390 */ 391 /* ===========================================================================*/ 392 OMX_ERRORTYPE DCC_Init(OMX_HANDLETYPE hComponent) 393 { 394 OMX_TI_PARAM_DCCURIINFO param; 395 OMX_PTR ptempbuf; 396 OMX_U16 nIndex = 0; 397 OMX_ERRORTYPE eError = OMX_ErrorNone; 398 #ifdef USE_ION 399 int ret; 400 #endif 401 402 OMX_S32 status = 0; 403 OMX_STRING dcc_dir[200]; 404 OMX_U16 i; 405 _PROXY_OMX_INIT_PARAM(¶m, OMX_TI_PARAM_DCCURIINFO); 406 407 DOMX_ENTER("ENTER"); 408 /* Read the the DCC URI info */ 409 for (nIndex = 0; eError != OMX_ErrorNoMore; nIndex++) 410 { 411 param.nIndex = nIndex; 412 eError = 413 OMX_GetParameter(hComponent, 414 OMX_TI_IndexParamDccUriInfo, ¶m); 415 416 PROXY_assert((eError == OMX_ErrorNone) || 417 (eError == OMX_ErrorNoMore), eError, 418 "Error in GetParam for Dcc URI info"); 419 420 if (eError == OMX_ErrorNone) 421 { 422 DOMX_DEBUG("DCC URI's %s ", param.sDCCURI); 423 dcc_dir[nIndex] = 424 TIMM_OSAL_Malloc(sizeof(OMX_U8) * 425 (strlen(DCC_PATH) + MAX_URI_LENGTH + 1), 426 TIMM_OSAL_TRUE, 0, TIMMOSAL_MEM_SEGMENT_INT); 427 PROXY_assert(dcc_dir[nIndex] != NULL, 428 OMX_ErrorInsufficientResources, "Malloc failed"); 429 strcpy(dcc_dir[nIndex], DCC_PATH); 430 strncat(dcc_dir[nIndex], (OMX_STRING) param.sDCCURI, MAX_URI_LENGTH); 431 strcat(dcc_dir[nIndex], "/"); 432 } 433 } 434 435 /* setting back errortype OMX_ErrorNone */ 436 if (eError == OMX_ErrorNoMore) 437 { 438 eError = OMX_ErrorNone; 439 } 440 441 dccbuf_size = read_DCCdir(NULL, dcc_dir, nIndex); 442 443 if(dccbuf_size <= 0) 444 { 445 DOMX_DEBUG("No DCC files found, switching back to default DCC"); 446 return OMX_ErrorInsufficientResources; 447 } 448 449 #ifdef USE_ION 450 ion_fd = ion_open(); 451 if(ion_fd == 0) 452 { 453 DOMX_ERROR("ion_open failed!!!"); 454 return OMX_ErrorInsufficientResources; 455 } 456 dccbuf_size = (dccbuf_size + LINUX_PAGE_SIZE -1) & ~(LINUX_PAGE_SIZE - 1); 457 ret = ion_alloc(ion_fd, dccbuf_size, 0x1000, 1 << ION_HEAP_TYPE_CARVEOUT, &DCC_Buff); 458 if (ret) 459 return OMX_ErrorInsufficientResources; 460 461 if (ion_map(ion_fd, DCC_Buff, dccbuf_size, PROT_READ | PROT_WRITE, MAP_SHARED, 0, 462 &DCC_Buff_ptr,&mmap_fd) < 0) 463 { 464 DOMX_ERROR("userspace mapping of ION buffers returned error"); 465 return OMX_ErrorInsufficientResources; 466 } 467 ptempbuf = DCC_Buff_ptr; 468 #else 469 MemReqDescTiler = 470 (MemAllocBlock *) TIMM_OSAL_Malloc((sizeof(MemAllocBlock) * 2), 471 TIMM_OSAL_TRUE, 0, TIMMOSAL_MEM_SEGMENT_EXT); 472 PROXY_assert(MemReqDescTiler != NULL, 473 OMX_ErrorInsufficientResources, "Malloc failed"); 474 475 /* Allocate 1D Tiler buffer for 'N'DCC files */ 476 MemReqDescTiler[0].fmt = PIXEL_FMT_PAGE; 477 MemReqDescTiler[0].dim.len = dccbuf_size; 478 MemReqDescTiler[0].stride = 0; 479 DCC_Buff = MemMgr_Alloc(MemReqDescTiler, 1); 480 PROXY_assert(DCC_Buff != NULL, 481 OMX_ErrorInsufficientResources, "ERROR Allocating 1D TILER BUF"); 482 ptempbuf = DCC_Buff; 483 #endif 484 dccbuf_size = read_DCCdir(ptempbuf, dcc_dir, nIndex); 485 486 PROXY_assert(dccbuf_size > 0, OMX_ErrorInsufficientResources, 487 "ERROR in copy DCC files into buffer"); 488 489 EXIT: 490 for (i = 0; i < nIndex - 1; i++) 491 { 492 TIMM_OSAL_Free(dcc_dir[i]); 493 } 494 495 return eError; 496 497 } 498 499 /* ===========================================================================*/ 500 /** 501 * @name send_DCCBufPtr() 502 * @brief : Sending the DCC uri buff addr to ducati 503 * @param void 504 * @return return = 0 is successful 505 * @sa TBD 506 * 507 */ 508 /* ===========================================================================*/ 509 510 OMX_ERRORTYPE send_DCCBufPtr(OMX_HANDLETYPE hComponent) 511 { 512 OMX_TI_CONFIG_SHAREDBUFFER uribufparam; 513 OMX_ERRORTYPE eError = OMX_ErrorNone; 514 515 _PROXY_OMX_INIT_PARAM(&uribufparam, OMX_TI_CONFIG_SHAREDBUFFER); 516 uribufparam.nPortIndex = OMX_ALL; 517 518 DOMX_ENTER("ENTER"); 519 520 uribufparam.nSharedBuffSize = dccbuf_size; 521 uribufparam.pSharedBuff = (OMX_U8 *) DCC_Buff; 522 523 DOMX_DEBUG("SYSLINK MAPPED ADDR: 0x%x sizeof buffer %d", 524 uribufparam.pSharedBuff, uribufparam.nSharedBuffSize); 525 526 eError = __PROXY_SetParameter(hComponent, 527 OMX_TI_IndexParamDccUriBuffer, 528 &uribufparam, 529 &(uribufparam.pSharedBuff)); 530 531 if (eError != OMX_ErrorNone) { 532 DOMX_ERROR(" Error in SetParam for DCC Uri Buffer 0x%x", eError); 533 } 534 535 DOMX_EXIT("EXIT"); 536 return eError; 537 } 538 539 /* ===========================================================================*/ 540 /** 541 * @name read_DCCdir() 542 * @brief : copies all the dcc profiles into the allocated 1D-Tiler buffer 543 * and returns the size of the buffer. 544 * @param void : OMX_PTR is null then returns the size of the DCC directory 545 * @return return = size of the DCC directory or error in case of any failures 546 * in file read or open 547 * @sa TBD 548 * 549 */ 550 /* ===========================================================================*/ 551 OMX_S32 read_DCCdir(OMX_PTR buffer, OMX_STRING * dir_path, OMX_U16 numofURI) 552 { 553 FILE *pFile; 554 OMX_S32 lSize; 555 OMX_S32 dcc_buf_size = 0; 556 size_t result; 557 OMX_STRING filename; 558 char temp[200]; 559 OMX_STRING dotdot = ".."; 560 DIR *d; 561 struct dirent *dir; 562 OMX_U16 i = 0; 563 OMX_S32 ret = 0; 564 565 DOMX_ENTER("ENTER"); 566 for (i = 0; i < numofURI - 1; i++) 567 { 568 d = opendir(dir_path[i]); 569 if (d) 570 { 571 /* read each filename */ 572 while ((dir = readdir(d)) != NULL) 573 { 574 filename = dir->d_name; 575 strcpy(temp, dir_path[i]); 576 strcat(temp, filename); 577 if ((*filename != *dotdot)) 578 { 579 DOMX_DEBUG 580 ("\n\t DCC Profiles copying into buffer => %s mpu_addr: %p", 581 temp, buffer); 582 pFile = fopen(temp, "rb"); 583 if (pFile == NULL) 584 { 585 DOMX_ERROR("File open error"); 586 ret = -1; 587 } else 588 { 589 fseek(pFile, 0, SEEK_END); 590 lSize = ftell(pFile); 591 rewind(pFile); 592 /* buffer is not NULL then copy all the DCC profiles into buffer 593 else return the size of the DCC directory */ 594 if (buffer) 595 { 596 // copy file into the buffer: 597 result = 598 fread(buffer, 1, 599 lSize, pFile); 600 if (result != (size_t) lSize) 601 { 602 DOMX_ERROR 603 ("fread: Reading error"); 604 ret = -1; 605 } 606 buffer = 607 buffer + lSize; 608 } 609 /* getting the size of the total dcc files available in FS */ 610 dcc_buf_size = 611 dcc_buf_size + lSize; 612 // terminate 613 fclose(pFile); 614 } 615 } 616 } 617 closedir(d); 618 } 619 } 620 if (ret == 0) 621 ret = dcc_buf_size; 622 623 DOMX_EXIT("return %d", ret); 624 return ret; 625 } 626 627 /* ===========================================================================*/ 628 /** 629 * @name DCC_Deinit() 630 * @brief 631 * @param void 632 * @return void 633 * @sa TBD 634 * 635 */ 636 /* ===========================================================================*/ 637 void DCC_DeInit() 638 { 639 DOMX_ENTER("ENTER"); 640 641 if (DCC_Buff) 642 { 643 #ifdef USE_ION 644 munmap(DCC_Buff_ptr, dccbuf_size); 645 close(mmap_fd); 646 ion_free(ion_fd, DCC_Buff); 647 ion_close(ion_fd); 648 DCC_Buff = NULL; 649 #else 650 MemMgr_Free(DCC_Buff); 651 #endif 652 } 653 #ifndef USE_ION 654 if (MemReqDescTiler) 655 TIMM_OSAL_Free(MemReqDescTiler); 656 #endif 657 658 DOMX_EXIT("EXIT"); 659 } 660 661 662 663 /*===============================================================*/ 664 /** @fn Cam_Setup : This function is called when the the OMX Camera library is 665 * loaded. It creates a mutex, which is used during DCC_Init() 666 */ 667 /*===============================================================*/ 668 void __attribute__ ((constructor)) Cam_Setup(void) 669 { 670 TIMM_OSAL_ERRORTYPE eError = TIMM_OSAL_ERR_NONE; 671 672 eError = TIMM_OSAL_MutexCreate(&cam_mutex); 673 if (eError != TIMM_OSAL_ERR_NONE) 674 { 675 TIMM_OSAL_Error("Creation of default mutex failed"); 676 } 677 } 678 679 680 /*===============================================================*/ 681 /** @fn Cam_Destroy : This function is called when the the OMX Camera library is 682 * unloaded. It destroys the mutex which was created by 683 * Core_Setup(). 684 * 685 */ 686 /*===============================================================*/ 687 void __attribute__ ((destructor)) Cam_Destroy(void) 688 { 689 TIMM_OSAL_ERRORTYPE eError = TIMM_OSAL_ERR_NONE; 690 691 eError = TIMM_OSAL_MutexDelete(cam_mutex); 692 if (eError != TIMM_OSAL_ERR_NONE) 693 { 694 TIMM_OSAL_Error("Destruction of default mutex failed"); 695 } 696 } 697