omx_proxy_camera.c revision 70ff025808c44ce9e01c045d879c5e60605de242
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@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  "/system/etc/omapcam/"
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 */
111static OMX_S16 numofInstance = 0;
112int dcc_flag = 0;
113TIMM_OSAL_PTR cam_mutex = NULL;
114
115/* To store DCC buffer size */
116OMX_S32 dccbuf_size = 0;
117
118/* Ducati Mapped Addr  */
119OMX_PTR DCC_Buff = NULL;
120
121#ifdef USE_ION
122OMX_PTR DCC_Buff_ptr = NULL;
123int ion_fd;
124int mmap_fd;
125
126#else
127MemAllocBlock *MemReqDescTiler;
128#endif
129
130OMX_S32 read_DCCdir(OMX_PTR, OMX_STRING *, OMX_U16);
131OMX_ERRORTYPE DCC_Init(OMX_HANDLETYPE);
132OMX_ERRORTYPE send_DCCBufPtr(OMX_HANDLETYPE hComponent);
133void DCC_DeInit();
134OMX_ERRORTYPE PROXY_ComponentDeInit(OMX_HANDLETYPE);
135OMX_ERRORTYPE __PROXY_SetConfig(OMX_HANDLETYPE, OMX_INDEXTYPE,
136								OMX_PTR, OMX_PTR);
137OMX_ERRORTYPE __PROXY_GetConfig(OMX_HANDLETYPE, OMX_INDEXTYPE,
138								OMX_PTR, OMX_PTR);
139OMX_ERRORTYPE __PROXY_SetParameter(OMX_IN OMX_HANDLETYPE, OMX_INDEXTYPE,
140									OMX_PTR, OMX_PTR);
141OMX_ERRORTYPE __PROXY_GetParameter(OMX_IN OMX_HANDLETYPE, OMX_INDEXTYPE,
142									OMX_PTR, OMX_PTR);
143OMX_ERRORTYPE CameraMaptoTilerDuc(OMX_TI_CONFIG_SHAREDBUFFER *, OMX_PTR *);
144//COREID TARGET_CORE_ID = CORE_APPM3;
145
146static 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
183static 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
244static 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
295OMX_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	}
337
338	pHandle->ComponentDeInit = ComponentPrivateDeInit;
339	pHandle->GetConfig = CameraGetConfig;
340	pHandle->SetConfig = CameraSetConfig;
341	char *val = getenv("SET_DCC");
342	dcc_flag = val ? strtol(val, NULL, 0) : DEFAULT_DCC;
343	DOMX_DEBUG(" DCC: 0 - disabled 1 - enabled : val: %d", dcc_flag);
344
345	if (dcc_flag)
346	{
347		eOsalError =
348		    TIMM_OSAL_MutexObtain(cam_mutex, TIMM_OSAL_SUSPEND);
349		PROXY_assert(eOsalError == TIMM_OSAL_ERR_NONE,
350		    OMX_ErrorInsufficientResources, "Mutex lock failed");
351
352		if (numofInstance == 0)
353		{
354			dcc_eError = DCC_Init(hComponent);
355			if (dcc_eError != OMX_ErrorNone)
356			{
357				DOMX_DEBUG(" Error in DCC Init");
358			}
359
360			/* Configure Ducati to use DCC buffer from A9 side
361			*ONLY* if DCC_Init is successful. */
362			if (dcc_eError == OMX_ErrorNone)
363			{
364				dcc_eError = send_DCCBufPtr(hComponent);
365				if (dcc_eError != OMX_ErrorNone)
366				{
367					DOMX_DEBUG(" Error in Sending DCC Buf ptr");
368				}
369				DCC_DeInit();
370			}
371                }
372                numofInstance = numofInstance + 1;
373		eOsalError = TIMM_OSAL_MutexRelease(cam_mutex);
374		PROXY_assert(eOsalError == TIMM_OSAL_ERR_NONE,
375		    OMX_ErrorInsufficientResources, "Mutex release failed");
376	}
377      EXIT:
378	return eError;
379}
380
381/* ===========================================================================*/
382/**
383 * @name DCC_Init()
384 * @brief
385 * @param void
386 * @return OMX_ErrorNone = Successful
387 * @sa TBD
388 *
389 */
390/* ===========================================================================*/
391OMX_ERRORTYPE DCC_Init(OMX_HANDLETYPE hComponent)
392{
393	OMX_TI_PARAM_DCCURIINFO param;
394	OMX_PTR ptempbuf;
395	OMX_U16 nIndex = 0;
396	OMX_ERRORTYPE eError = OMX_ErrorNone;
397#ifdef USE_ION
398	int ret;
399#endif
400
401	OMX_S32 status = 0;
402	OMX_STRING dcc_dir[200];
403	OMX_U16 i;
404	_PROXY_OMX_INIT_PARAM(&param, OMX_TI_PARAM_DCCURIINFO);
405
406	DOMX_ENTER("ENTER");
407	/* Read the the DCC URI info */
408	for (nIndex = 0; eError != OMX_ErrorNoMore; nIndex++)
409	{
410		param.nIndex = nIndex;
411		eError =
412			OMX_GetParameter(hComponent,
413			OMX_TI_IndexParamDccUriInfo, &param);
414
415		PROXY_assert((eError == OMX_ErrorNone) ||
416			(eError == OMX_ErrorNoMore), eError,
417			"Error in GetParam for Dcc URI info");
418
419		if (eError == OMX_ErrorNone)
420		{
421			DOMX_DEBUG("DCC URI's %s ", param.sDCCURI);
422			dcc_dir[nIndex] =
423				TIMM_OSAL_Malloc(sizeof(OMX_U8) *
424				(strlen(DCC_PATH) + MAX_URI_LENGTH + 1),
425				TIMM_OSAL_TRUE, 0, TIMMOSAL_MEM_SEGMENT_INT);
426			PROXY_assert(dcc_dir[nIndex] != NULL,
427				OMX_ErrorInsufficientResources, "Malloc failed");
428			strcpy(dcc_dir[nIndex], DCC_PATH);
429			strncat(dcc_dir[nIndex], (OMX_STRING) param.sDCCURI, MAX_URI_LENGTH);
430			strcat(dcc_dir[nIndex], "/");
431		}
432	}
433
434	/* setting  back errortype OMX_ErrorNone */
435	if (eError == OMX_ErrorNoMore)
436	{
437		eError = OMX_ErrorNone;
438	}
439
440	dccbuf_size = read_DCCdir(NULL, dcc_dir, nIndex);
441
442    if(dccbuf_size <= 0)
443    {
444	    DOMX_DEBUG("No DCC files found, switching back to default DCC");
445        return OMX_ErrorInsufficientResources;
446    }
447
448#ifdef USE_ION
449	ion_fd = ion_open();
450	if(ion_fd == 0)
451	{
452		DOMX_ERROR("ion_open failed!!!");
453		return OMX_ErrorInsufficientResources;
454	}
455	dccbuf_size = (dccbuf_size + LINUX_PAGE_SIZE -1) & ~(LINUX_PAGE_SIZE - 1);
456	ret = ion_alloc(ion_fd, dccbuf_size, 0x1000, 1 << ION_HEAP_TYPE_CARVEOUT, &DCC_Buff);
457	if (ret)
458			return OMX_ErrorInsufficientResources;
459
460	if (ion_map(ion_fd, DCC_Buff, dccbuf_size, PROT_READ | PROT_WRITE, MAP_SHARED, 0,
461                  &DCC_Buff_ptr,&mmap_fd) < 0)
462	{
463		DOMX_ERROR("userspace mapping of ION buffers returned error");
464		return OMX_ErrorInsufficientResources;
465	}
466	ptempbuf = DCC_Buff_ptr;
467#else
468	MemReqDescTiler =
469		(MemAllocBlock *) TIMM_OSAL_Malloc((sizeof(MemAllocBlock) * 2),
470		TIMM_OSAL_TRUE, 0, TIMMOSAL_MEM_SEGMENT_EXT);
471	PROXY_assert(MemReqDescTiler != NULL,
472	    OMX_ErrorInsufficientResources, "Malloc failed");
473
474	/* Allocate 1D Tiler buffer for 'N'DCC files  */
475	MemReqDescTiler[0].fmt = PIXEL_FMT_PAGE;
476	MemReqDescTiler[0].dim.len = dccbuf_size;
477	MemReqDescTiler[0].stride = 0;
478	DCC_Buff = MemMgr_Alloc(MemReqDescTiler, 1);
479	PROXY_assert(DCC_Buff != NULL,
480		OMX_ErrorInsufficientResources, "ERROR Allocating 1D TILER BUF");
481	ptempbuf = DCC_Buff;
482#endif
483	dccbuf_size = read_DCCdir(ptempbuf, dcc_dir, nIndex);
484
485	PROXY_assert(dccbuf_size > 0, OMX_ErrorInsufficientResources,
486		"ERROR in copy DCC files into buffer");
487
488 EXIT:
489	for (i = 0; i < nIndex - 1; i++)
490	{
491			TIMM_OSAL_Free(dcc_dir[i]);
492	}
493
494	return eError;
495
496}
497
498/* ===========================================================================*/
499/**
500 * @name send_DCCBufPtr()
501 * @brief : Sending the DCC uri buff addr to ducati
502 * @param void
503 * @return return = 0 is successful
504 * @sa TBD
505 *
506 */
507/* ===========================================================================*/
508
509OMX_ERRORTYPE send_DCCBufPtr(OMX_HANDLETYPE hComponent)
510{
511	OMX_TI_CONFIG_SHAREDBUFFER uribufparam;
512	OMX_ERRORTYPE eError = OMX_ErrorNone;
513
514	_PROXY_OMX_INIT_PARAM(&uribufparam, OMX_TI_CONFIG_SHAREDBUFFER);
515	uribufparam.nPortIndex = OMX_ALL;
516
517	DOMX_ENTER("ENTER");
518
519	uribufparam.nSharedBuffSize = dccbuf_size;
520	uribufparam.pSharedBuff = (OMX_U8 *) DCC_Buff;
521
522	DOMX_DEBUG("SYSLINK MAPPED ADDR:  0x%x sizeof buffer %d",
523		uribufparam.pSharedBuff, uribufparam.nSharedBuffSize);
524
525	eError = __PROXY_SetParameter(hComponent,
526								OMX_TI_IndexParamDccUriBuffer,
527								&uribufparam,
528								&(uribufparam.pSharedBuff));
529
530	if (eError != OMX_ErrorNone) {
531		DOMX_ERROR(" Error in SetParam for DCC Uri Buffer 0x%x", eError);
532	}
533
534	DOMX_EXIT("EXIT");
535	return eError;
536}
537
538/* ===========================================================================*/
539/**
540 * @name read_DCCdir()
541 * @brief : copies all the dcc profiles into the allocated 1D-Tiler buffer
542 *          and returns the size of the buffer.
543 * @param void : OMX_PTR is null then returns the size of the DCC directory
544 * @return return = size of the DCC directory or error in case of any failures
545 *		    in file read or open
546 * @sa TBD
547 *
548 */
549/* ===========================================================================*/
550OMX_S32 read_DCCdir(OMX_PTR buffer, OMX_STRING * dir_path, OMX_U16 numofURI)
551{
552	FILE *pFile;
553	OMX_S32 lSize;
554	OMX_S32 dcc_buf_size = 0;
555	size_t result;
556	OMX_STRING filename;
557	char temp[200];
558	OMX_STRING dotdot = "..";
559	DIR *d;
560	struct dirent *dir;
561	OMX_U16 i = 0;
562	OMX_S32 ret = 0;
563
564	DOMX_ENTER("ENTER");
565	for (i = 0; i < numofURI - 1; i++)
566	{
567		d = opendir(dir_path[i]);
568		if (d)
569		{
570			/* read each filename */
571			while ((dir = readdir(d)) != NULL)
572			{
573				filename = dir->d_name;
574				strcpy(temp, dir_path[i]);
575				strcat(temp, filename);
576				if ((*filename != *dotdot))
577				{
578					DOMX_DEBUG
579					    ("\n\t DCC Profiles copying into buffer => %s mpu_addr: %p",
580					    temp, buffer);
581					pFile = fopen(temp, "rb");
582					if (pFile == NULL)
583					{
584						DOMX_ERROR("File open error");
585						ret = -1;
586					} else
587					{
588						fseek(pFile, 0, SEEK_END);
589						lSize = ftell(pFile);
590						rewind(pFile);
591						/* buffer is not NULL then copy all the DCC profiles into buffer
592						   else return the size of the DCC directory */
593						if (buffer)
594						{
595							// copy file into the buffer:
596							result =
597							    fread(buffer, 1,
598							    lSize, pFile);
599							if (result != (size_t) lSize)
600							{
601								DOMX_ERROR
602								    ("fread: Reading error");
603								ret = -1;
604							}
605							buffer =
606							    buffer + lSize;
607						}
608						/* getting the size of the total dcc files available in FS */
609						dcc_buf_size =
610						    dcc_buf_size + lSize;
611						// terminate
612						fclose(pFile);
613					}
614				}
615			}
616			closedir(d);
617		}
618	}
619	if (ret == 0)
620		ret = dcc_buf_size;
621
622	DOMX_EXIT("return %d", ret);
623	return ret;
624}
625
626/* ===========================================================================*/
627/**
628 * @name DCC_Deinit()
629 * @brief
630 * @param void
631 * @return void
632 * @sa TBD
633 *
634 */
635/* ===========================================================================*/
636void DCC_DeInit()
637{
638	DOMX_ENTER("ENTER");
639
640	if (DCC_Buff)
641	{
642#ifdef USE_ION
643		munmap(DCC_Buff_ptr, dccbuf_size);
644		close(mmap_fd);
645		ion_free(ion_fd, DCC_Buff);
646		DCC_Buff = NULL;
647#else
648		MemMgr_Free(DCC_Buff);
649#endif
650	}
651#ifndef USE_ION
652	if (MemReqDescTiler)
653		TIMM_OSAL_Free(MemReqDescTiler);
654#endif
655
656	DOMX_EXIT("EXIT");
657}
658
659
660
661/*===============================================================*/
662/** @fn Cam_Setup : This function is called when the the OMX Camera library is
663 *                  loaded. It creates a mutex, which is used during DCC_Init()
664 */
665/*===============================================================*/
666void __attribute__ ((constructor)) Cam_Setup(void)
667{
668	TIMM_OSAL_ERRORTYPE eError = TIMM_OSAL_ERR_NONE;
669
670	eError = TIMM_OSAL_MutexCreate(&cam_mutex);
671	if (eError != TIMM_OSAL_ERR_NONE)
672	{
673		TIMM_OSAL_Error("Creation of default mutex failed");
674	}
675}
676
677
678/*===============================================================*/
679/** @fn Cam_Destroy : This function is called when the the OMX Camera library is
680 *                    unloaded. It destroys the mutex which was created by
681 *                    Core_Setup().
682 *
683 */
684/*===============================================================*/
685void __attribute__ ((destructor)) Cam_Destroy(void)
686{
687	TIMM_OSAL_ERRORTYPE eError = TIMM_OSAL_ERR_NONE;
688
689	eError = TIMM_OSAL_MutexDelete(cam_mutex);
690	if (eError != TIMM_OSAL_ERR_NONE)
691	{
692		TIMM_OSAL_Error("Destruction of default mutex failed");
693	}
694}
695