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);
38 ret = MEDIA_CONTENT_ERROR_NONE;
42 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
43 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
49 int image_meta_clone(image_meta_h *dst, image_meta_h src)
51 int ret = MEDIA_CONTENT_ERROR_NONE;
52 image_meta_s *_src = (image_meta_s*)src;
56 image_meta_s *_dst = (image_meta_s*)calloc(1, sizeof(image_meta_s));
59 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
60 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
63 if(STRING_VALID(_src->media_id))
65 _dst->media_id = strdup(_src->media_id);
66 if(_dst->media_id == NULL)
68 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
69 image_meta_destroy((image_meta_h)_dst);
70 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
74 if(STRING_VALID(_src->date_taken))
76 _dst->date_taken = strdup(_src->date_taken);
77 if(_dst->date_taken == NULL)
79 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
80 image_meta_destroy((image_meta_h)_dst);
81 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
85 if(STRING_VALID(_src->title))
87 _dst->title = strdup(_src->title);
88 if(_dst->title == NULL)
90 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
91 image_meta_destroy((image_meta_h)_dst);
92 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
96 if(STRING_VALID(_src->weather))
98 _dst->weather = strdup(_src->weather);
99 if(_dst->weather == NULL)
101 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
102 image_meta_destroy((image_meta_h)_dst);
103 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
107 if(STRING_VALID(_src->burst_id))
109 _dst->burst_id = strdup(_src->burst_id);
110 if(_dst->burst_id == NULL)
112 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
113 image_meta_destroy((image_meta_h)_dst);
114 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
118 _dst->width = _src->width;
119 _dst->height = _src->height;
120 _dst->orientation = _src->orientation;
122 *dst = (image_meta_h)_dst;
124 ret = MEDIA_CONTENT_ERROR_NONE;
128 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
129 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
135 int image_meta_get_media_id(image_meta_h image, char **media_id)
137 int ret = MEDIA_CONTENT_ERROR_NONE;
138 image_meta_s *_image = (image_meta_s*)image;
140 if(_image && media_id)
142 if(STRING_VALID(_image->media_id))
144 char *new_string = strdup(_image->media_id);
145 if(NULL == new_string)
147 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
148 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
150 *media_id = new_string;
156 ret = MEDIA_CONTENT_ERROR_NONE;
161 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
162 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
169 int image_meta_get_width(image_meta_h image, int *width)
171 int ret = MEDIA_CONTENT_ERROR_NONE;
172 image_meta_s *_image = (image_meta_s*)image;
176 *width = _image->width;
177 ret = MEDIA_CONTENT_ERROR_NONE;
181 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
182 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
187 int image_meta_get_height(image_meta_h image, int *height)
189 int ret = MEDIA_CONTENT_ERROR_NONE;
190 image_meta_s *_image = (image_meta_s*)image;
194 *height = _image->height;
195 ret = MEDIA_CONTENT_ERROR_NONE;
199 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
200 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
206 int image_meta_get_orientation(image_meta_h image, media_content_orientation_e* orientation)
208 int ret = MEDIA_CONTENT_ERROR_NONE;
209 image_meta_s *_image = (image_meta_s*)image;
211 if(_image && orientation)
213 *orientation = _image->orientation;
214 ret = MEDIA_CONTENT_ERROR_NONE;
218 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
219 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
225 int image_meta_get_date_taken(image_meta_h image, char **date_taken)
227 int ret = MEDIA_CONTENT_ERROR_NONE;
228 image_meta_s *_image = (image_meta_s*)image;
230 if(_image && date_taken)
232 if(STRING_VALID(_image->date_taken))
234 char *new_string = strdup(_image->date_taken);
235 if(NULL == new_string)
237 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
238 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
240 *date_taken = new_string;
247 ret = MEDIA_CONTENT_ERROR_NONE;
251 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
252 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
258 int image_meta_get_burst_id(image_meta_h image, char **burst_id)
260 int ret = MEDIA_CONTENT_ERROR_NONE;
261 image_meta_s *_image = (image_meta_s*)image;
263 if(_image && burst_id)
265 if(STRING_VALID(_image->burst_id))
267 *burst_id = strdup(_image->burst_id);
268 if(*burst_id == NULL)
270 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
271 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
278 ret = MEDIA_CONTENT_ERROR_NONE;
282 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
283 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
289 int image_meta_is_burst_shot(image_meta_h image, bool *is_burst_shot)
291 int ret = MEDIA_CONTENT_ERROR_NONE;
292 image_meta_s *_image = (image_meta_s*)image;
294 if(_image && is_burst_shot)
296 if(STRING_VALID(_image->burst_id))
297 *is_burst_shot = true;
299 *is_burst_shot = false;
301 ret = MEDIA_CONTENT_ERROR_NONE;
305 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
306 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
312 int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation)
314 int ret = MEDIA_CONTENT_ERROR_NONE;
315 image_meta_s *_image = (image_meta_s*)image;
319 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
320 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
323 if((orientation < MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE) || (orientation > MEDIA_CONTENT_ORIENTATION_ROT_270))
325 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
326 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
329 _image->orientation = orientation;
334 int image_meta_update_to_db(image_meta_h image)
336 int ret = MEDIA_CONTENT_ERROR_NONE;
337 image_meta_s *_image = (image_meta_s*)image;
340 if(_image != NULL && STRING_VALID(_image->media_id))
342 sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, _image->orientation, _image->weather, _image->media_id);
343 ret = _content_query_sql(sql);
348 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
349 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;