Git init
[framework/multimedia/libmedia-thumbnail.git] / src / codec / img-codec-osal.c
1 /*
2  * libmedia-thumbnail
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include "img-codec-osal.h"
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26
27 #include <drm-service.h>
28
29 void *IfegMemAlloc(unsigned int size)
30 {
31         void *pmem;
32         pmem = malloc(size);
33         return pmem;
34 }
35
36 void IfegMemFree(void *pMem)
37 {
38         free(pMem);
39         pMem = 0;
40 }
41
42 void *IfegMemcpy(void *dest, const void *src, unsigned int count)
43 {
44         return memcpy(dest, src, count);
45 }
46
47 void *IfegMemset(void *dest, int c, unsigned int count)
48 {
49         return memset(dest, c, count);
50 }
51
52 ULONG IfegGetAvailableMemSize(void)
53 {
54         return 1;
55 }
56
57 int IfegMemcmp(const void *pMem1, const void *pMem2, size_t length)
58 {
59         return memcmp(pMem1, pMem2, length);
60 }
61
62 DRM_FILE_HANDLE hDrmFile = NULL;
63 static BOOL _is_real_drm = FALSE;
64
65 HFile DrmOpenFile(const char *szPathName)
66 {
67         if (drm_svc_is_drm_file(szPathName) == DRM_TRUE) {
68                 _is_real_drm = TRUE;
69         } else {
70                 _is_real_drm = FALSE;
71         }
72
73         if (!_is_real_drm) {
74                 FILE *fp = fopen(szPathName, "rb");
75
76                 if (fp == NULL) {
77                         return (HFile) INVALID_HOBJ;
78                 }
79
80                 return fp;
81
82         } else {
83                 int ret =
84                     drm_svc_open_file(szPathName, DRM_PERMISSION_DISPLAY,
85                                       &hDrmFile);
86
87                 if (ret != DRM_RESULT_SUCCESS) {
88                         return (HFile) INVALID_HOBJ;
89                 }
90                 return hDrmFile;
91         }
92 }
93
94 BOOL DrmReadFile(HFile hFile, void *pBuffer, ULONG bufLen, ULONG * pReadLen)
95 {
96         size_t readCnt = -1;
97
98         if (!_is_real_drm) {
99                 readCnt = fread(pBuffer, sizeof(char), bufLen, hFile);
100                 *pReadLen = (ULONG) readCnt;
101         } else {
102                 drm_svc_read_file((DRM_FILE_HANDLE) hFile, pBuffer, bufLen,
103                                   &readCnt);
104                 *pReadLen = (ULONG) readCnt;
105         }
106         return TRUE;
107 }
108
109 long DrmTellFile(HFile hFile)
110 {
111         if (!_is_real_drm) {
112                 return ftell(hFile);
113         } else {
114                 return drm_svc_tell_file((DRM_FILE_HANDLE) hFile);
115         }
116 }
117
118 BOOL DrmSeekFile(HFile hFile, long position, long offset)
119 {
120
121         if (position < 0) {
122                 return FALSE;
123         }
124         if (!_is_real_drm) {
125                 fseek(hFile, offset, position);
126         } else {
127                 drm_svc_seek_file((DRM_FILE_HANDLE) hFile, offset, position);
128         }
129
130         return TRUE;
131 }
132
133 BOOL DrmGetFileAttributes(const char *szPathName, FmFileAttribute * pFileAttr)
134 {
135         FILE *f = NULL;
136
137         f = fopen(szPathName, "r");
138
139         if (f == NULL) {
140                 return FALSE;
141         }
142
143         fseek(f, 0, SEEK_END);
144         pFileAttr->fileSize = ftell(f);
145         fclose(f);
146
147         return TRUE;
148 }
149
150 BOOL DrmCloseFile(HFile hFile)
151 {
152         if (!_is_real_drm) {
153                 fclose(hFile);
154         } else {
155                 drm_svc_close_file((DRM_FILE_HANDLE) hFile);
156         }
157
158         return TRUE;
159 }