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->burst_id);
37 ret = MEDIA_CONTENT_ERROR_NONE;
41 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
42 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
48 int image_meta_clone(image_meta_h *dst, image_meta_h src)
50 int ret = MEDIA_CONTENT_ERROR_NONE;
51 image_meta_s *_src = (image_meta_s*)src;
55 image_meta_s *_dst = (image_meta_s*)calloc(1, sizeof(image_meta_s));
58 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
59 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
62 if(STRING_VALID(_src->media_id))
64 _dst->media_id = strdup(_src->media_id);
65 if(_dst->media_id == NULL)
67 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
68 image_meta_destroy((image_meta_h)_dst);
69 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
73 if(STRING_VALID(_src->date_taken))
75 _dst->date_taken = strdup(_src->date_taken);
76 if(_dst->date_taken == NULL)
78 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
79 image_meta_destroy((image_meta_h)_dst);
80 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
84 if(STRING_VALID(_src->title))
86 _dst->title = strdup(_src->title);
87 if(_dst->title == NULL)
89 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
90 image_meta_destroy((image_meta_h)_dst);
91 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
95 if(STRING_VALID(_src->burst_id))
97 _dst->burst_id = strdup(_src->burst_id);
98 if(_dst->burst_id == NULL)
100 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
101 image_meta_destroy((image_meta_h)_dst);
102 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
106 _dst->width = _src->width;
107 _dst->height = _src->height;
108 _dst->orientation = _src->orientation;
110 *dst = (image_meta_h)_dst;
112 ret = MEDIA_CONTENT_ERROR_NONE;
116 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
117 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
123 int image_meta_get_media_id(image_meta_h image, char **media_id)
125 int ret = MEDIA_CONTENT_ERROR_NONE;
126 image_meta_s *_image = (image_meta_s*)image;
128 if(_image && media_id)
130 if(STRING_VALID(_image->media_id))
132 char *new_string = strdup(_image->media_id);
133 if(NULL == new_string)
135 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
136 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
138 *media_id = new_string;
144 ret = MEDIA_CONTENT_ERROR_NONE;
149 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
150 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
157 int image_meta_get_width(image_meta_h image, int *width)
159 int ret = MEDIA_CONTENT_ERROR_NONE;
160 image_meta_s *_image = (image_meta_s*)image;
164 *width = _image->width;
165 ret = MEDIA_CONTENT_ERROR_NONE;
169 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
170 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
175 int image_meta_get_height(image_meta_h image, int *height)
177 int ret = MEDIA_CONTENT_ERROR_NONE;
178 image_meta_s *_image = (image_meta_s*)image;
182 *height = _image->height;
183 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;
194 int image_meta_get_orientation(image_meta_h image, media_content_orientation_e* orientation)
196 int ret = MEDIA_CONTENT_ERROR_NONE;
197 image_meta_s *_image = (image_meta_s*)image;
199 if(_image && orientation)
201 *orientation = _image->orientation;
202 ret = MEDIA_CONTENT_ERROR_NONE;
206 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
207 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
213 int image_meta_get_date_taken(image_meta_h image, char **date_taken)
215 int ret = MEDIA_CONTENT_ERROR_NONE;
216 image_meta_s *_image = (image_meta_s*)image;
218 if(_image && date_taken)
220 if(STRING_VALID(_image->date_taken))
222 char *new_string = strdup(_image->date_taken);
223 if(NULL == new_string)
225 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
226 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
228 *date_taken = new_string;
235 ret = MEDIA_CONTENT_ERROR_NONE;
239 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
240 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
246 int image_meta_get_title(image_meta_h image, char **title)
248 int ret = MEDIA_CONTENT_ERROR_NONE;
249 image_meta_s *_image = (image_meta_s*)image;
252 if(STRING_VALID(_image->title))
254 *title = strdup(_image->title);
257 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
258 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
265 ret = MEDIA_CONTENT_ERROR_NONE;
270 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
271 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
277 int image_meta_get_burst_id(image_meta_h image, char **burst_id)
279 int ret = MEDIA_CONTENT_ERROR_NONE;
280 image_meta_s *_image = (image_meta_s*)image;
282 if(_image && burst_id)
284 if(STRING_VALID(_image->burst_id))
286 *burst_id = strdup(_image->burst_id);
287 if(*burst_id == NULL)
289 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
290 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
297 ret = MEDIA_CONTENT_ERROR_NONE;
301 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
302 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
308 int image_meta_is_burst_shot(image_meta_h image, bool *is_burst_shot)
310 int ret = MEDIA_CONTENT_ERROR_NONE;
311 image_meta_s *_image = (image_meta_s*)image;
313 if(_image && is_burst_shot)
315 if(STRING_VALID(_image->burst_id))
316 *is_burst_shot = true;
318 *is_burst_shot = false;
320 ret = MEDIA_CONTENT_ERROR_NONE;
324 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
325 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
330 int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation)
332 int ret = MEDIA_CONTENT_ERROR_NONE;
333 image_meta_s *_image = (image_meta_s*)image;
337 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
338 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
341 if((orientation < MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE) || (orientation > MEDIA_CONTENT_ORIENTATION_ROT_270))
343 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
344 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
347 _image->orientation = orientation;
352 int image_meta_update_to_db(image_meta_h image)
354 int ret = MEDIA_CONTENT_ERROR_NONE;
355 image_meta_s *_image = (image_meta_s*)image;
358 if(_image != NULL && STRING_VALID(_image->media_id))
360 sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, _image->orientation, _image->media_id);
361 ret = _content_query_sql(sql);
366 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
367 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;