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>
21 int image_meta_destroy(image_meta_h image)
23 int ret = MEDIA_CONTENT_ERROR_NONE;
24 image_meta_s *_image = (image_meta_s*)image;
27 SAFE_FREE(_image->media_id);
28 SAFE_FREE(_image->date_taken);
29 SAFE_FREE(_image->title);
30 SAFE_FREE(_image->weather);
31 SAFE_FREE(_image->burst_id);
32 SAFE_FREE(_image->exposure_time);
33 SAFE_FREE(_image->model);
36 ret = MEDIA_CONTENT_ERROR_NONE;
38 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
39 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
45 int image_meta_clone(image_meta_h *dst, image_meta_h src)
47 int ret = MEDIA_CONTENT_ERROR_NONE;
48 image_meta_s *_src = (image_meta_s*)src;
51 image_meta_s *_dst = (image_meta_s*)calloc(1, sizeof(image_meta_s));
52 media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
54 if (STRING_VALID(_src->media_id)) {
55 _dst->media_id = strdup(_src->media_id);
56 if (_dst->media_id == NULL) {
57 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
58 image_meta_destroy((image_meta_h)_dst);
59 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
63 if (STRING_VALID(_src->date_taken)) {
64 _dst->date_taken = strdup(_src->date_taken);
65 if (_dst->date_taken == 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->title)) {
73 _dst->title = strdup(_src->title);
74 if (_dst->title == NULL) {
75 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
76 image_meta_destroy((image_meta_h)_dst);
77 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
81 if (STRING_VALID(_src->weather)) {
82 _dst->weather = strdup(_src->weather);
83 if (_dst->weather == NULL) {
84 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
85 image_meta_destroy((image_meta_h)_dst);
86 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
90 if (STRING_VALID(_src->burst_id)) {
91 _dst->burst_id = strdup(_src->burst_id);
92 if (_dst->burst_id == NULL) {
93 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
94 image_meta_destroy((image_meta_h)_dst);
95 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
99 if (STRING_VALID(_src->exposure_time)) {
100 _dst->exposure_time = strdup(_src->exposure_time);
101 if (_dst->exposure_time == NULL) {
102 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
103 image_meta_destroy((image_meta_h)_dst);
104 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
108 if (STRING_VALID(_src->model)) {
109 _dst->model = strdup(_src->model);
110 if (_dst->model == NULL) {
111 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
112 image_meta_destroy((image_meta_h)_dst);
113 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
117 _dst->fnumber = _src->fnumber;
118 _dst->iso = _src->iso;
119 _dst->width = _src->width;
120 _dst->height = _src->height;
121 _dst->orientation = _src->orientation;
123 *dst = (image_meta_h)_dst;
125 ret = MEDIA_CONTENT_ERROR_NONE;
127 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
128 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
134 int image_meta_get_media_id(image_meta_h image, char **media_id)
136 int ret = MEDIA_CONTENT_ERROR_NONE;
137 image_meta_s *_image = (image_meta_s*)image;
139 if (_image && media_id) {
140 if (STRING_VALID(_image->media_id)) {
141 char *new_string = strdup(_image->media_id);
142 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
144 *media_id = new_string;
148 ret = MEDIA_CONTENT_ERROR_NONE;
151 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
152 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
159 int image_meta_get_width(image_meta_h image, int *width)
161 int ret = MEDIA_CONTENT_ERROR_NONE;
162 image_meta_s *_image = (image_meta_s*)image;
164 if (_image && width) {
165 *width = _image->width;
166 ret = MEDIA_CONTENT_ERROR_NONE;
168 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
169 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
174 int image_meta_get_height(image_meta_h image, int *height)
176 int ret = MEDIA_CONTENT_ERROR_NONE;
177 image_meta_s *_image = (image_meta_s*)image;
179 if (_image && height) {
180 *height = _image->height;
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_orientation(image_meta_h image, media_content_orientation_e* orientation)
192 int ret = MEDIA_CONTENT_ERROR_NONE;
193 image_meta_s *_image = (image_meta_s*)image;
195 if (_image && orientation) {
196 *orientation = _image->orientation;
197 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_date_taken(image_meta_h image, char **date_taken)
208 int ret = MEDIA_CONTENT_ERROR_NONE;
209 image_meta_s *_image = (image_meta_s*)image;
211 if (_image && date_taken) {
212 if (STRING_VALID(_image->date_taken)) {
213 char *new_string = strdup(_image->date_taken);
214 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
216 *date_taken = new_string;
221 ret = MEDIA_CONTENT_ERROR_NONE;
223 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
224 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
230 int image_meta_get_burst_id(image_meta_h image, char **burst_id)
232 int ret = MEDIA_CONTENT_ERROR_NONE;
233 image_meta_s *_image = (image_meta_s*)image;
235 if (_image && burst_id) {
236 if (STRING_VALID(_image->burst_id)) {
237 *burst_id = strdup(_image->burst_id);
238 media_content_retvm_if(*burst_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
242 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_exposure_time(image_meta_h image, char **exposure_time)
253 int ret = MEDIA_CONTENT_ERROR_NONE;
254 image_meta_s *_image = (image_meta_s*)image;
256 if (_image && exposure_time) {
257 if (STRING_VALID(_image->exposure_time)) {
258 *exposure_time = strdup(_image->exposure_time);
259 media_content_retvm_if(*exposure_time == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
261 *exposure_time = NULL;
263 ret = MEDIA_CONTENT_ERROR_NONE;
265 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
266 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
272 int image_meta_get_fnumber(image_meta_h image, double *fnumber)
274 int ret = MEDIA_CONTENT_ERROR_NONE;
275 image_meta_s *_image = (image_meta_s*)image;
277 if (_image && fnumber) {
278 *fnumber = _image->fnumber;
279 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;
288 int image_meta_get_iso(image_meta_h image, int *iso)
290 int ret = MEDIA_CONTENT_ERROR_NONE;
291 image_meta_s *_image = (image_meta_s*)image;
295 ret = MEDIA_CONTENT_ERROR_NONE;
297 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
298 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
304 int image_meta_get_model(image_meta_h image, char **model)
306 int ret = MEDIA_CONTENT_ERROR_NONE;
307 image_meta_s *_image = (image_meta_s*)image;
309 if (_image && model) {
310 if (STRING_VALID(_image->model)) {
311 *model = strdup(_image->model);
312 media_content_retvm_if(*model == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
316 ret = MEDIA_CONTENT_ERROR_NONE;
318 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
319 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
325 int image_meta_is_burst_shot(image_meta_h image, bool *is_burst_shot)
327 int ret = MEDIA_CONTENT_ERROR_NONE;
328 image_meta_s *_image = (image_meta_s*)image;
330 if (_image && is_burst_shot) {
331 if (STRING_VALID(_image->burst_id))
332 *is_burst_shot = true;
334 *is_burst_shot = false;
336 ret = MEDIA_CONTENT_ERROR_NONE;
338 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
339 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
345 int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation)
347 int ret = MEDIA_CONTENT_ERROR_NONE;
348 image_meta_s *_image = (image_meta_s*)image;
350 if (_image == NULL) {
351 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
352 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
355 if ((orientation < MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE) || (orientation > MEDIA_CONTENT_ORIENTATION_ROT_270)) {
356 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
357 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
360 _image->orientation = orientation;
365 int image_meta_update_to_db(image_meta_h image)
367 int ret = MEDIA_CONTENT_ERROR_NONE;
368 image_meta_s *_image = (image_meta_s*)image;
371 if (_image != NULL && STRING_VALID(_image->media_id)) {
372 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,};
373 memset(storage_id, 0x00, sizeof(storage_id));
375 ret = _media_db_get_storage_id_by_media_id(_image->media_id, storage_id);
376 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
378 sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, storage_id, _image->orientation, _image->weather, _image->media_id);
379 ret = _content_query_sql(sql);
380 SQLITE3_SAFE_FREE(sql);
382 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
383 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;