2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <media_image.h>
19 #include <media_content.h>
20 #include <media_info_private.h>
21 #include <media-svc.h>
24 int image_meta_destroy(image_meta_h image)
26 int ret = MEDIA_CONTENT_ERROR_NONE;
27 image_meta_s *_image = (image_meta_s*)image;
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);
40 ret = MEDIA_CONTENT_ERROR_NONE;
44 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
45 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
51 int image_meta_clone(image_meta_h *dst, image_meta_h src)
53 int ret = MEDIA_CONTENT_ERROR_NONE;
54 image_meta_s *_src = (image_meta_s*)src;
58 image_meta_s *_dst = (image_meta_s*)calloc(1, sizeof(image_meta_s));
61 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
62 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
65 if(STRING_VALID(_src->media_id))
67 _dst->media_id = strdup(_src->media_id);
68 if(_dst->media_id == NULL)
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;
76 if(STRING_VALID(_src->date_taken))
78 _dst->date_taken = strdup(_src->date_taken);
79 if(_dst->date_taken == NULL)
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;
87 if(STRING_VALID(_src->title))
89 _dst->title = strdup(_src->title);
90 if(_dst->title == NULL)
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;
98 if(STRING_VALID(_src->weather))
100 _dst->weather = strdup(_src->weather);
101 if(_dst->weather == NULL)
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;
109 if(STRING_VALID(_src->burst_id))
111 _dst->burst_id = strdup(_src->burst_id);
112 if(_dst->burst_id == NULL)
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;
120 if(STRING_VALID(_src->exposure_time))
122 _dst->exposure_time = strdup(_src->exposure_time);
123 if(_dst->exposure_time == NULL)
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;
131 if(STRING_VALID(_src->model))
133 _dst->model = strdup(_src->model);
134 if(_dst->model == NULL)
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;
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;
148 *dst = (image_meta_h)_dst;
150 ret = MEDIA_CONTENT_ERROR_NONE;
154 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
155 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
161 int image_meta_get_media_id(image_meta_h image, char **media_id)
163 int ret = MEDIA_CONTENT_ERROR_NONE;
164 image_meta_s *_image = (image_meta_s*)image;
166 if(_image && media_id)
168 if(STRING_VALID(_image->media_id))
170 char *new_string = strdup(_image->media_id);
171 if(NULL == new_string)
173 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
174 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
176 *media_id = new_string;
182 ret = MEDIA_CONTENT_ERROR_NONE;
187 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
188 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
195 int image_meta_get_width(image_meta_h image, int *width)
197 int ret = MEDIA_CONTENT_ERROR_NONE;
198 image_meta_s *_image = (image_meta_s*)image;
202 *width = _image->width;
203 ret = MEDIA_CONTENT_ERROR_NONE;
207 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
208 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
213 int image_meta_get_height(image_meta_h image, int *height)
215 int ret = MEDIA_CONTENT_ERROR_NONE;
216 image_meta_s *_image = (image_meta_s*)image;
220 *height = _image->height;
221 ret = MEDIA_CONTENT_ERROR_NONE;
225 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
226 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
232 int image_meta_get_orientation(image_meta_h image, media_content_orientation_e* orientation)
234 int ret = MEDIA_CONTENT_ERROR_NONE;
235 image_meta_s *_image = (image_meta_s*)image;
237 if(_image && orientation)
239 *orientation = _image->orientation;
240 ret = MEDIA_CONTENT_ERROR_NONE;
244 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
245 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
251 int image_meta_get_date_taken(image_meta_h image, char **date_taken)
253 int ret = MEDIA_CONTENT_ERROR_NONE;
254 image_meta_s *_image = (image_meta_s*)image;
256 if(_image && date_taken)
258 if(STRING_VALID(_image->date_taken))
260 char *new_string = strdup(_image->date_taken);
261 if(NULL == new_string)
263 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
264 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
266 *date_taken = new_string;
273 ret = MEDIA_CONTENT_ERROR_NONE;
277 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
278 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
284 int image_meta_get_burst_id(image_meta_h image, char **burst_id)
286 int ret = MEDIA_CONTENT_ERROR_NONE;
287 image_meta_s *_image = (image_meta_s*)image;
289 if(_image && burst_id)
291 if(STRING_VALID(_image->burst_id))
293 *burst_id = strdup(_image->burst_id);
294 if(*burst_id == NULL)
296 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
297 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
304 ret = MEDIA_CONTENT_ERROR_NONE;
308 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
309 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
315 int image_meta_get_exposure_time(image_meta_h image, char **exposure_time)
317 int ret = MEDIA_CONTENT_ERROR_NONE;
318 image_meta_s *_image = (image_meta_s*)image;
320 if(_image && exposure_time)
322 if(STRING_VALID(_image->exposure_time))
324 *exposure_time = strdup(_image->exposure_time);
325 if(*exposure_time == NULL)
327 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
328 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
333 *exposure_time = NULL;
335 ret = MEDIA_CONTENT_ERROR_NONE;
339 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
340 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
346 int image_meta_get_fnumber(image_meta_h image, double *fnumber)
348 int ret = MEDIA_CONTENT_ERROR_NONE;
349 image_meta_s *_image = (image_meta_s*)image;
351 if(_image && fnumber)
353 *fnumber = _image->fnumber;
354 ret = MEDIA_CONTENT_ERROR_NONE;
358 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
359 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
365 int image_meta_get_iso(image_meta_h image, int *iso)
367 int ret = MEDIA_CONTENT_ERROR_NONE;
368 image_meta_s *_image = (image_meta_s*)image;
373 ret = MEDIA_CONTENT_ERROR_NONE;
377 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
378 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
384 int image_meta_get_model(image_meta_h image, char **model)
386 int ret = MEDIA_CONTENT_ERROR_NONE;
387 image_meta_s *_image = (image_meta_s*)image;
391 if(STRING_VALID(_image->model))
393 *model = strdup(_image->model);
396 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
397 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
404 ret = MEDIA_CONTENT_ERROR_NONE;
408 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
409 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
415 int image_meta_is_burst_shot(image_meta_h image, bool *is_burst_shot)
417 int ret = MEDIA_CONTENT_ERROR_NONE;
418 image_meta_s *_image = (image_meta_s*)image;
420 if(_image && is_burst_shot)
422 if(STRING_VALID(_image->burst_id))
423 *is_burst_shot = true;
425 *is_burst_shot = false;
427 ret = MEDIA_CONTENT_ERROR_NONE;
431 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
432 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
438 int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation)
440 int ret = MEDIA_CONTENT_ERROR_NONE;
441 image_meta_s *_image = (image_meta_s*)image;
445 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
446 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
449 if((orientation < MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE) || (orientation > MEDIA_CONTENT_ORIENTATION_ROT_270))
451 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
452 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
455 _image->orientation = orientation;
460 int image_meta_update_to_db(image_meta_h image)
462 int ret = MEDIA_CONTENT_ERROR_NONE;
463 image_meta_s *_image = (image_meta_s*)image;
466 if(_image != NULL && STRING_VALID(_image->media_id))
468 sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, _image->orientation, _image->weather, _image->media_id);
469 ret = _content_query_sql(sql);
474 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
475 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;