merge with master
[platform/core/api/media-content.git] / src / media_image.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 #include <media_image.h>
19 #include <media_content.h>
20 #include <media_info_private.h>
21 #include <media-svc.h>
22
23
24 int image_meta_destroy(image_meta_h image)
25 {
26         int ret = MEDIA_CONTENT_ERROR_NONE;
27         image_meta_s *_image = (image_meta_s*)image;
28
29         media_content_debug_func();
30
31         if(_image)
32         {
33                 SAFE_FREE(_image->media_id);
34                 SAFE_FREE(_image->date_taken);
35                 SAFE_FREE(_image->burst_id);
36                 SAFE_FREE(_image);
37
38                 ret = MEDIA_CONTENT_ERROR_NONE;
39         }
40         else
41         {
42                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
43                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
44         }
45
46         return ret;
47 }
48
49 int image_meta_clone(image_meta_h *dst, image_meta_h src)
50 {
51         int ret = MEDIA_CONTENT_ERROR_NONE;
52         image_meta_s *_src = (image_meta_s*)src;
53
54         media_content_debug_func();
55
56         if(_src != NULL)
57         {
58                 image_meta_s *_dst = (image_meta_s*)calloc(1, sizeof(image_meta_s));
59                 if(NULL == _dst)
60                 {
61                         media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
62                         return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
63                 }
64
65                 if(STRING_VALID(_src->media_id))
66                 {
67                         _dst->media_id = strdup(_src->media_id);
68                         if(_dst->media_id == NULL)
69                         {
70                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
71                                 image_meta_destroy((image_meta_h)_dst);
72                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
73                         }
74                 }
75
76                 if(STRING_VALID(_src->date_taken))
77                 {
78                         _dst->date_taken = strdup(_src->date_taken);
79                         if(_dst->date_taken == NULL)
80                         {
81                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
82                                 image_meta_destroy((image_meta_h)_dst);
83                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
84                         }
85                 }
86
87                 if(STRING_VALID(_src->burst_id))
88                 {
89                         _dst->burst_id = strdup(_src->burst_id);
90                         if(_dst->burst_id == NULL)
91                         {
92                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
93                                 image_meta_destroy((image_meta_h)_dst);
94                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
95                         }
96                 }
97
98                 _dst->width = _src->width;
99                 _dst->height = _src->height;
100                 _dst->orientation = _src->orientation;
101
102                 *dst = (image_meta_h)_dst;
103
104                 ret = MEDIA_CONTENT_ERROR_NONE;
105         }
106         else
107         {
108                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
109                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
110         }
111
112         return ret;
113 }
114
115 int image_meta_get_media_id(image_meta_h image, char **media_id)
116 {
117         int ret = MEDIA_CONTENT_ERROR_NONE;
118         image_meta_s *_image = (image_meta_s*)image;
119
120         if(_image && media_id)
121         {
122                 if(STRING_VALID(_image->media_id))
123                 {
124                         char *new_string = strdup(_image->media_id);
125                         if(NULL == new_string)
126                         {
127                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
128                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
129                         }
130                         *media_id = new_string;
131                 }
132                 else
133                 {
134                         *media_id = NULL;
135                 }
136                 ret = MEDIA_CONTENT_ERROR_NONE;
137
138         }
139         else
140         {
141                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
142                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
143         }
144
145         return ret;
146
147 }
148
149 int image_meta_get_width(image_meta_h image, int *width)
150 {
151         int ret = MEDIA_CONTENT_ERROR_NONE;
152         image_meta_s *_image = (image_meta_s*)image;
153
154         if(_image && width)
155         {
156                 *width = _image->width;
157                 ret = MEDIA_CONTENT_ERROR_NONE;
158         }
159         else
160         {
161                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
162                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
163         }
164
165         return ret;
166 }
167 int image_meta_get_height(image_meta_h image, int *height)
168 {
169         int ret = MEDIA_CONTENT_ERROR_NONE;
170         image_meta_s *_image = (image_meta_s*)image;
171
172         if(_image && height)
173         {
174                 *height = _image->height;
175                 ret = MEDIA_CONTENT_ERROR_NONE;
176         }
177         else
178         {
179                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
180                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
181         }
182
183         return ret;
184 }
185
186 int image_meta_get_orientation(image_meta_h image, media_content_orientation_e* orientation)
187 {
188         int ret = MEDIA_CONTENT_ERROR_NONE;
189         image_meta_s *_image = (image_meta_s*)image;
190
191         if(_image && orientation)
192         {
193                 *orientation = _image->orientation;
194                 ret = MEDIA_CONTENT_ERROR_NONE;
195         }
196         else
197         {
198                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
199                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
200         }
201
202         return ret;
203 }
204
205 int image_meta_get_date_taken(image_meta_h image, char **date_taken)
206 {
207         int ret = MEDIA_CONTENT_ERROR_NONE;
208         image_meta_s *_image = (image_meta_s*)image;
209
210         if(_image && date_taken)
211         {
212                 if(STRING_VALID(_image->date_taken))
213                 {
214                         char *new_string = strdup(_image->date_taken);
215                         if(NULL == new_string)
216                         {
217                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
218                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
219                         }
220                         *date_taken = new_string;
221                 }
222                 else
223                 {
224                         *date_taken = NULL;
225                 }
226
227                 ret = MEDIA_CONTENT_ERROR_NONE;
228         }
229         else
230         {
231                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
232                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
233         }
234
235         return ret;
236 }
237
238 int image_meta_get_burst_id(image_meta_h image, char **burst_id)
239 {
240         int ret = MEDIA_CONTENT_ERROR_NONE;
241         image_meta_s *_image = (image_meta_s*)image;
242
243         if(_image && burst_id)
244         {
245                 if(STRING_VALID(_image->burst_id))
246                 {
247                         *burst_id = strdup(_image->burst_id);
248                         if(*burst_id == NULL)
249                         {
250                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
251                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
252                         }
253                 }
254                 else
255                 {
256                         *burst_id = NULL;
257                 }
258                 ret = MEDIA_CONTENT_ERROR_NONE;
259         }
260         else
261         {
262                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
263                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
264         }
265
266         return ret;
267 }
268
269 int image_meta_is_burst_shot(image_meta_h image, bool *is_burst_shot)
270 {
271         int ret = MEDIA_CONTENT_ERROR_NONE;
272         image_meta_s *_image = (image_meta_s*)image;
273
274         if(_image && is_burst_shot)
275         {
276                 if(STRING_VALID(_image->burst_id))
277                         *is_burst_shot = true;
278                 else
279                         *is_burst_shot = false;
280
281                 ret = MEDIA_CONTENT_ERROR_NONE;
282         }
283         else
284         {
285                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
286                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
287         }
288
289         return ret;
290 }
291 int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation)
292 {
293         int ret = MEDIA_CONTENT_ERROR_NONE;
294         image_meta_s *_image = (image_meta_s*)image;
295
296         if(_image == NULL)
297         {
298                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
299                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
300         }
301
302         if((orientation < MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE) || (orientation > MEDIA_CONTENT_ORIENTATION_ROT_270))
303         {
304                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
305                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
306         }
307
308         _image->orientation = orientation;
309
310         return ret;
311 }
312
313 int image_meta_update_to_db(image_meta_h image)
314 {
315         int ret = MEDIA_CONTENT_ERROR_NONE;
316         image_meta_s *_image = (image_meta_s*)image;
317         char *sql = NULL;
318
319         if(_image != NULL && STRING_VALID(_image->media_id))
320         {
321                 sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, _image->orientation, _image->media_id);
322                 ret = _content_query_sql(sql);
323                 sqlite3_free(sql);
324         }
325         else
326         {
327                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
328                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
329         }
330
331         return ret;
332 }