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_info_private.h>
20 #define media_content_retv_free_image_if(expr, val, p_str) do { \
22 LOGE(FONT_COLOR_RED"Memory allocation failure"FONT_COLOR_RESET); \
23 image_meta_destroy(p_str); \
29 int image_meta_destroy(image_meta_h image)
31 image_meta_s *_image = (image_meta_s*)image;
32 media_content_retvm_if(_image == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Image handle is null");
34 SAFE_FREE(_image->media_id);
35 SAFE_FREE(_image->date_taken);
36 SAFE_FREE(_image->title);
37 SAFE_FREE(_image->burst_id);
38 SAFE_FREE(_image->exposure_time);
39 SAFE_FREE(_image->model);
42 return MEDIA_CONTENT_ERROR_NONE;
45 int image_meta_clone(image_meta_h *dst, image_meta_h src)
47 image_meta_s *_src = (image_meta_s*)src;
48 media_content_retvm_if(_src == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Source handle is null");
50 image_meta_s *_dst = (image_meta_s*)calloc(1, sizeof(image_meta_s));
51 media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
53 if (STRING_VALID(_src->media_id)) {
54 _dst->media_id = strdup(_src->media_id);
55 media_content_retv_free_image_if(_dst->media_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (image_meta_h)_dst);
58 if (STRING_VALID(_src->date_taken)) {
59 _dst->date_taken = strdup(_src->date_taken);
60 media_content_retv_free_image_if(_dst->date_taken == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (image_meta_h)_dst);
63 if (STRING_VALID(_src->title)) {
64 _dst->title = strdup(_src->title);
65 media_content_retv_free_image_if(_dst->title == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (image_meta_h)_dst);
68 if (STRING_VALID(_src->burst_id)) {
69 _dst->burst_id = strdup(_src->burst_id);
70 media_content_retv_free_image_if(_dst->burst_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (image_meta_h)_dst);
73 if (STRING_VALID(_src->exposure_time)) {
74 _dst->exposure_time = strdup(_src->exposure_time);
75 media_content_retv_free_image_if(_dst->exposure_time == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (image_meta_h)_dst);
78 if (STRING_VALID(_src->model)) {
79 _dst->model = strdup(_src->model);
80 media_content_retv_free_image_if(_dst->model == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (image_meta_h)_dst);
83 _dst->fnumber = _src->fnumber;
84 _dst->iso = _src->iso;
85 _dst->width = _src->width;
86 _dst->height = _src->height;
87 _dst->orientation = _src->orientation;
89 *dst = (image_meta_h)_dst;
91 return MEDIA_CONTENT_ERROR_NONE;
94 int image_meta_get_media_id(image_meta_h image, char **media_id)
96 int ret = MEDIA_CONTENT_ERROR_NONE;
97 image_meta_s *_image = (image_meta_s*)image;
99 if (_image && media_id) {
100 if (STRING_VALID(_image->media_id)) {
101 char *new_string = strdup(_image->media_id);
102 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
104 *media_id = new_string;
108 ret = MEDIA_CONTENT_ERROR_NONE;
111 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
112 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
119 int image_meta_get_width(image_meta_h image, int *width)
121 int ret = MEDIA_CONTENT_ERROR_NONE;
122 image_meta_s *_image = (image_meta_s*)image;
124 if (_image && width) {
125 *width = _image->width;
126 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;
134 int image_meta_get_height(image_meta_h image, int *height)
136 int ret = MEDIA_CONTENT_ERROR_NONE;
137 image_meta_s *_image = (image_meta_s*)image;
139 if (_image && height) {
140 *height = _image->height;
141 ret = MEDIA_CONTENT_ERROR_NONE;
143 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
144 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
150 int image_meta_get_orientation(image_meta_h image, media_content_orientation_e* orientation)
152 int ret = MEDIA_CONTENT_ERROR_NONE;
153 image_meta_s *_image = (image_meta_s*)image;
155 if (_image && orientation) {
156 *orientation = _image->orientation;
157 ret = MEDIA_CONTENT_ERROR_NONE;
159 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
160 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
166 int image_meta_get_date_taken(image_meta_h image, char **date_taken)
168 int ret = MEDIA_CONTENT_ERROR_NONE;
169 image_meta_s *_image = (image_meta_s*)image;
171 if (_image && date_taken) {
172 if (STRING_VALID(_image->date_taken)) {
173 char *new_string = strdup(_image->date_taken);
174 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
176 *date_taken = new_string;
181 ret = MEDIA_CONTENT_ERROR_NONE;
183 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
184 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
190 int image_meta_get_burst_id(image_meta_h image, char **burst_id)
192 int ret = MEDIA_CONTENT_ERROR_NONE;
193 media_content_warn("DEPRECATION WARNING: image_meta_get_burst_id() is deprecated and will be removed from next release.");
194 image_meta_s *_image = (image_meta_s*)image;
196 if (_image && burst_id) {
197 if (STRING_VALID(_image->burst_id)) {
198 *burst_id = strdup(_image->burst_id);
199 media_content_retvm_if(*burst_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
203 ret = MEDIA_CONTENT_ERROR_NONE;
205 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
206 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
212 int image_meta_get_exposure_time(image_meta_h image, char **exposure_time)
214 int ret = MEDIA_CONTENT_ERROR_NONE;
215 image_meta_s *_image = (image_meta_s*)image;
217 if (_image && exposure_time) {
218 if (STRING_VALID(_image->exposure_time)) {
219 *exposure_time = strdup(_image->exposure_time);
220 media_content_retvm_if(*exposure_time == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
222 *exposure_time = NULL;
224 ret = MEDIA_CONTENT_ERROR_NONE;
226 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
227 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
233 int image_meta_get_fnumber(image_meta_h image, double *fnumber)
235 int ret = MEDIA_CONTENT_ERROR_NONE;
236 image_meta_s *_image = (image_meta_s*)image;
238 if (_image && fnumber) {
239 *fnumber = _image->fnumber;
240 ret = MEDIA_CONTENT_ERROR_NONE;
242 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
243 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
249 int image_meta_get_iso(image_meta_h image, int *iso)
251 int ret = MEDIA_CONTENT_ERROR_NONE;
252 image_meta_s *_image = (image_meta_s*)image;
256 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_get_model(image_meta_h image, char **model)
267 int ret = MEDIA_CONTENT_ERROR_NONE;
268 image_meta_s *_image = (image_meta_s*)image;
270 if (_image && model) {
271 if (STRING_VALID(_image->model)) {
272 *model = strdup(_image->model);
273 media_content_retvm_if(*model == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
277 ret = MEDIA_CONTENT_ERROR_NONE;
279 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
280 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
286 int image_meta_is_burst_shot(image_meta_h image, bool *is_burst_shot)
288 int ret = MEDIA_CONTENT_ERROR_NONE;
289 media_content_warn("DEPRECATION WARNING: image_meta_is_burst_shot() is deprecated and will be removed from next release.");
290 image_meta_s *_image = (image_meta_s*)image;
292 if (_image && is_burst_shot) {
293 if (STRING_VALID(_image->burst_id))
294 *is_burst_shot = true;
296 *is_burst_shot = false;
298 ret = MEDIA_CONTENT_ERROR_NONE;
300 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
301 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
307 int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation)
309 int ret = MEDIA_CONTENT_ERROR_NONE;
310 media_content_warn("DEPRECATION WARNING: image_meta_set_orientation() is deprecated and will be removed from next release.");
311 image_meta_s *_image = (image_meta_s*)image;
313 if (_image == NULL) {
314 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
315 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
318 if ((orientation < MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE) || (orientation > MEDIA_CONTENT_ORIENTATION_ROT_270)) {
319 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
320 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
323 _image->orientation = orientation;
328 int image_meta_update_to_db(image_meta_h image)
330 int ret = MEDIA_CONTENT_ERROR_NONE;
331 media_content_warn("DEPRECATION WARNING: image_meta_update_to_db() is deprecated and will be removed from next release.");
332 image_meta_s *_image = (image_meta_s*)image;
335 if (_image != NULL && STRING_VALID(_image->media_id)) {
336 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,};
337 memset(storage_id, 0x00, sizeof(storage_id));
339 ret = _media_db_get_storage_id_by_media_id(_image->media_id, storage_id);
340 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
342 sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, storage_id, _image->orientation, _image->media_id);
343 ret = _content_query_sql(sql);
344 SQLITE3_SAFE_FREE(sql);
346 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
347 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;