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