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->burst_id);
36 ret = MEDIA_CONTENT_ERROR_NONE;
40 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
41 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
47 int image_meta_clone(image_meta_h *dst, image_meta_h src)
49 int ret = MEDIA_CONTENT_ERROR_NONE;
50 image_meta_s *_src = (image_meta_s*)src;
54 image_meta_s *_dst = (image_meta_s*)calloc(1, sizeof(image_meta_s));
57 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
58 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
61 if(STRING_VALID(_src->media_id))
63 _dst->media_id = strdup(_src->media_id);
64 if(_dst->media_id == NULL)
66 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
67 image_meta_destroy((image_meta_h)_dst);
68 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
72 if(STRING_VALID(_src->date_taken))
74 _dst->date_taken = strdup(_src->date_taken);
75 if(_dst->date_taken == NULL)
77 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
78 image_meta_destroy((image_meta_h)_dst);
79 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
83 if(STRING_VALID(_src->burst_id))
85 _dst->burst_id = strdup(_src->burst_id);
86 if(_dst->burst_id == NULL)
88 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
89 image_meta_destroy((image_meta_h)_dst);
90 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
94 _dst->width = _src->width;
95 _dst->height = _src->height;
96 _dst->orientation = _src->orientation;
98 *dst = (image_meta_h)_dst;
100 ret = MEDIA_CONTENT_ERROR_NONE;
104 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
105 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
111 int image_meta_get_media_id(image_meta_h image, char **media_id)
113 int ret = MEDIA_CONTENT_ERROR_NONE;
114 image_meta_s *_image = (image_meta_s*)image;
116 if(_image && media_id)
118 if(STRING_VALID(_image->media_id))
120 char *new_string = strdup(_image->media_id);
121 if(NULL == new_string)
123 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
124 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
126 *media_id = new_string;
132 ret = MEDIA_CONTENT_ERROR_NONE;
137 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
138 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
145 int image_meta_get_width(image_meta_h image, int *width)
147 int ret = MEDIA_CONTENT_ERROR_NONE;
148 image_meta_s *_image = (image_meta_s*)image;
152 *width = _image->width;
153 ret = MEDIA_CONTENT_ERROR_NONE;
157 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
158 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
163 int image_meta_get_height(image_meta_h image, int *height)
165 int ret = MEDIA_CONTENT_ERROR_NONE;
166 image_meta_s *_image = (image_meta_s*)image;
170 *height = _image->height;
171 ret = MEDIA_CONTENT_ERROR_NONE;
175 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
176 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
182 int image_meta_get_orientation(image_meta_h image, media_content_orientation_e* orientation)
184 int ret = MEDIA_CONTENT_ERROR_NONE;
185 image_meta_s *_image = (image_meta_s*)image;
187 if(_image && orientation)
189 *orientation = _image->orientation;
190 ret = MEDIA_CONTENT_ERROR_NONE;
194 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
195 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
201 int image_meta_get_date_taken(image_meta_h image, char **date_taken)
203 int ret = MEDIA_CONTENT_ERROR_NONE;
204 image_meta_s *_image = (image_meta_s*)image;
206 if(_image && date_taken)
208 if(STRING_VALID(_image->date_taken))
210 char *new_string = strdup(_image->date_taken);
211 if(NULL == new_string)
213 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
214 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
216 *date_taken = new_string;
223 ret = MEDIA_CONTENT_ERROR_NONE;
227 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
228 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
234 int image_meta_get_burst_id(image_meta_h image, char **burst_id)
236 int ret = MEDIA_CONTENT_ERROR_NONE;
237 image_meta_s *_image = (image_meta_s*)image;
239 if(_image && burst_id)
241 if(STRING_VALID(_image->burst_id))
243 *burst_id = strdup(_image->burst_id);
244 if(*burst_id == NULL)
246 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
247 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
254 ret = MEDIA_CONTENT_ERROR_NONE;
258 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
259 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
265 int image_meta_is_burst_shot(image_meta_h image, bool *is_burst_shot)
267 int ret = MEDIA_CONTENT_ERROR_NONE;
268 image_meta_s *_image = (image_meta_s*)image;
270 if(_image && is_burst_shot)
272 if(STRING_VALID(_image->burst_id))
273 *is_burst_shot = true;
275 *is_burst_shot = false;
277 ret = MEDIA_CONTENT_ERROR_NONE;
281 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
282 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
287 int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation)
289 int ret = MEDIA_CONTENT_ERROR_NONE;
290 image_meta_s *_image = (image_meta_s*)image;
294 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
295 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
298 if((orientation < MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE) || (orientation > MEDIA_CONTENT_ORIENTATION_ROT_270))
300 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
301 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
304 _image->orientation = orientation;
309 int image_meta_update_to_db(image_meta_h image)
311 int ret = MEDIA_CONTENT_ERROR_NONE;
312 image_meta_s *_image = (image_meta_s*)image;
315 if(_image != NULL && STRING_VALID(_image->media_id))
317 sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, _image->orientation, _image->media_id);
318 ret = _content_query_sql(sql);
323 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
324 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;