Add image info.
[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         if(_image)
30         {
31                 SAFE_FREE(_image->media_id);
32                 SAFE_FREE(_image->date_taken);
33                 SAFE_FREE(_image->title);
34                 SAFE_FREE(_image->weather);
35                 SAFE_FREE(_image->burst_id);
36                 SAFE_FREE(_image->exposure_time);
37                 SAFE_FREE(_image->model);
38                 SAFE_FREE(_image);
39
40                 ret = MEDIA_CONTENT_ERROR_NONE;
41         }
42         else
43         {
44                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
45                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
46         }
47
48         return ret;
49 }
50
51 int image_meta_clone(image_meta_h *dst, image_meta_h src)
52 {
53         int ret = MEDIA_CONTENT_ERROR_NONE;
54         image_meta_s *_src = (image_meta_s*)src;
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->title))
88                 {
89                         _dst->title = strdup(_src->title);
90                         if(_dst->title == 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                 if(STRING_VALID(_src->weather))
99                 {
100                         _dst->weather = strdup(_src->weather);
101                         if(_dst->weather == NULL)
102                         {
103                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
104                                 image_meta_destroy((image_meta_h)_dst);
105                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
106                         }
107                 }
108
109                 if(STRING_VALID(_src->burst_id))
110                 {
111                         _dst->burst_id = strdup(_src->burst_id);
112                         if(_dst->burst_id == NULL)
113                         {
114                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
115                                 image_meta_destroy((image_meta_h)_dst);
116                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
117                         }
118                 }
119
120                 if(STRING_VALID(_src->exposure_time))
121                 {
122                         _dst->exposure_time = strdup(_src->exposure_time);
123                         if(_dst->exposure_time == NULL)
124                         {
125                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
126                                 image_meta_destroy((image_meta_h)_dst);
127                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
128                         }
129                 }
130
131                 if(STRING_VALID(_src->model))
132                 {
133                         _dst->model = strdup(_src->model);
134                         if(_dst->model == NULL)
135                         {
136                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
137                                 image_meta_destroy((image_meta_h)_dst);
138                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
139                         }
140                 }
141
142                 _dst->fnumber = _src->fnumber;
143                 _dst->iso = _src->iso;
144                 _dst->width = _src->width;
145                 _dst->height = _src->height;
146                 _dst->orientation = _src->orientation;
147
148                 *dst = (image_meta_h)_dst;
149
150                 ret = MEDIA_CONTENT_ERROR_NONE;
151         }
152         else
153         {
154                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
155                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
156         }
157
158         return ret;
159 }
160
161 int image_meta_get_media_id(image_meta_h image, char **media_id)
162 {
163         int ret = MEDIA_CONTENT_ERROR_NONE;
164         image_meta_s *_image = (image_meta_s*)image;
165
166         if(_image && media_id)
167         {
168                 if(STRING_VALID(_image->media_id))
169                 {
170                         char *new_string = strdup(_image->media_id);
171                         if(NULL == new_string)
172                         {
173                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
174                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
175                         }
176                         *media_id = new_string;
177                 }
178                 else
179                 {
180                         *media_id = NULL;
181                 }
182                 ret = MEDIA_CONTENT_ERROR_NONE;
183
184         }
185         else
186         {
187                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
188                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
189         }
190
191         return ret;
192
193 }
194
195 int image_meta_get_width(image_meta_h image, int *width)
196 {
197         int ret = MEDIA_CONTENT_ERROR_NONE;
198         image_meta_s *_image = (image_meta_s*)image;
199
200         if(_image && width)
201         {
202                 *width = _image->width;
203                 ret = MEDIA_CONTENT_ERROR_NONE;
204         }
205         else
206         {
207                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
208                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
209         }
210
211         return ret;
212 }
213 int image_meta_get_height(image_meta_h image, int *height)
214 {
215         int ret = MEDIA_CONTENT_ERROR_NONE;
216         image_meta_s *_image = (image_meta_s*)image;
217
218         if(_image && height)
219         {
220                 *height = _image->height;
221                 ret = MEDIA_CONTENT_ERROR_NONE;
222         }
223         else
224         {
225                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
226                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
227         }
228
229         return ret;
230 }
231
232 int image_meta_get_orientation(image_meta_h image, media_content_orientation_e* orientation)
233 {
234         int ret = MEDIA_CONTENT_ERROR_NONE;
235         image_meta_s *_image = (image_meta_s*)image;
236
237         if(_image && orientation)
238         {
239                 *orientation = _image->orientation;
240                 ret = MEDIA_CONTENT_ERROR_NONE;
241         }
242         else
243         {
244                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
245                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
246         }
247
248         return ret;
249 }
250
251 int image_meta_get_date_taken(image_meta_h image, char **date_taken)
252 {
253         int ret = MEDIA_CONTENT_ERROR_NONE;
254         image_meta_s *_image = (image_meta_s*)image;
255
256         if(_image && date_taken)
257         {
258                 if(STRING_VALID(_image->date_taken))
259                 {
260                         char *new_string = strdup(_image->date_taken);
261                         if(NULL == new_string)
262                         {
263                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
264                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
265                         }
266                         *date_taken = new_string;
267                 }
268                 else
269                 {
270                         *date_taken = NULL;
271                 }
272
273                 ret = MEDIA_CONTENT_ERROR_NONE;
274         }
275         else
276         {
277                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
278                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
279         }
280
281         return ret;
282 }
283
284 int image_meta_get_burst_id(image_meta_h image, char **burst_id)
285 {
286         int ret = MEDIA_CONTENT_ERROR_NONE;
287         image_meta_s *_image = (image_meta_s*)image;
288
289         if(_image && burst_id)
290         {
291                 if(STRING_VALID(_image->burst_id))
292                 {
293                         *burst_id = strdup(_image->burst_id);
294                         if(*burst_id == NULL)
295                         {
296                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
297                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
298                         }
299                 }
300                 else
301                 {
302                         *burst_id = NULL;
303                 }
304                 ret = MEDIA_CONTENT_ERROR_NONE;
305         }
306         else
307         {
308                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
309                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
310         }
311
312         return ret;
313 }
314
315 int image_meta_get_exposure_time(image_meta_h image, char **exposure_time)
316 {
317         int ret = MEDIA_CONTENT_ERROR_NONE;
318         image_meta_s *_image = (image_meta_s*)image;
319
320         if(_image && exposure_time)
321         {
322                 if(STRING_VALID(_image->exposure_time))
323                 {
324                         *exposure_time = strdup(_image->exposure_time);
325                         if(*exposure_time == NULL)
326                         {
327                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
328                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
329                         }
330                 }
331                 else
332                 {
333                         *exposure_time = NULL;
334                 }
335                 ret = MEDIA_CONTENT_ERROR_NONE;
336         }
337         else
338         {
339                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
340                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
341         }
342
343         return ret;
344 }
345
346 int image_meta_get_fnumber(image_meta_h image, double *fnumber)
347 {
348         int ret = MEDIA_CONTENT_ERROR_NONE;
349         image_meta_s *_image = (image_meta_s*)image;
350
351         if(_image && fnumber)
352         {
353                 *fnumber = _image->fnumber;
354                 ret = MEDIA_CONTENT_ERROR_NONE;
355         }
356         else
357         {
358                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
359                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
360         }
361
362         return ret;
363 }
364
365 int image_meta_get_iso(image_meta_h image, int *iso)
366 {
367         int ret = MEDIA_CONTENT_ERROR_NONE;
368         image_meta_s *_image = (image_meta_s*)image;
369
370         if(_image && iso)
371         {
372                 *iso = _image->iso;
373                 ret = MEDIA_CONTENT_ERROR_NONE;
374         }
375         else
376         {
377                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
378                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
379         }
380
381         return ret;
382 }
383
384 int image_meta_get_model(image_meta_h image, char **model)
385 {
386         int ret = MEDIA_CONTENT_ERROR_NONE;
387         image_meta_s *_image = (image_meta_s*)image;
388
389         if(_image && model)
390         {
391                 if(STRING_VALID(_image->model))
392                 {
393                         *model = strdup(_image->model);
394                         if(*model == NULL)
395                         {
396                                 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
397                                 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
398                         }
399                 }
400                 else
401                 {
402                         *model = NULL;
403                 }
404                 ret = MEDIA_CONTENT_ERROR_NONE;
405         }
406         else
407         {
408                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
409                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
410         }
411
412         return ret;
413 }
414
415 int image_meta_is_burst_shot(image_meta_h image, bool *is_burst_shot)
416 {
417         int ret = MEDIA_CONTENT_ERROR_NONE;
418         image_meta_s *_image = (image_meta_s*)image;
419
420         if(_image && is_burst_shot)
421         {
422                 if(STRING_VALID(_image->burst_id))
423                         *is_burst_shot = true;
424                 else
425                         *is_burst_shot = false;
426
427                 ret = MEDIA_CONTENT_ERROR_NONE;
428         }
429         else
430         {
431                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
432                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
433         }
434
435         return ret;
436 }
437
438 int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation)
439 {
440         int ret = MEDIA_CONTENT_ERROR_NONE;
441         image_meta_s *_image = (image_meta_s*)image;
442
443         if(_image == NULL)
444         {
445                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
446                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
447         }
448
449         if((orientation < MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE) || (orientation > MEDIA_CONTENT_ORIENTATION_ROT_270))
450         {
451                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
452                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
453         }
454
455         _image->orientation = orientation;
456
457         return ret;
458 }
459
460 int image_meta_update_to_db(image_meta_h image)
461 {
462         int ret = MEDIA_CONTENT_ERROR_NONE;
463         image_meta_s *_image = (image_meta_s*)image;
464         char *sql = NULL;
465
466         if(_image != NULL && STRING_VALID(_image->media_id))
467         {
468                 sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, _image->orientation, _image->weather, _image->media_id);
469                 ret = _content_query_sql(sql);
470                 sqlite3_free(sql);
471         }
472         else
473         {
474                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
475                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
476         }
477
478         return ret;
479 }