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 media_content_warn("DEPRECATION WARNING: image_meta_get_burst_id() is deprecated and will be removed from next release.");
234 image_meta_s *_image = (image_meta_s*)image;
236 if (_image && burst_id) {
237 if (STRING_VALID(_image->burst_id)) {
238 *burst_id = strdup(_image->burst_id);
239 media_content_retvm_if(*burst_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
243 ret = MEDIA_CONTENT_ERROR_NONE;
245 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
246 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
252 int image_meta_get_exposure_time(image_meta_h image, char **exposure_time)
254 int ret = MEDIA_CONTENT_ERROR_NONE;
255 image_meta_s *_image = (image_meta_s*)image;
257 if (_image && exposure_time) {
258 if (STRING_VALID(_image->exposure_time)) {
259 *exposure_time = strdup(_image->exposure_time);
260 media_content_retvm_if(*exposure_time == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
262 *exposure_time = NULL;
264 ret = MEDIA_CONTENT_ERROR_NONE;
266 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
267 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
273 int image_meta_get_fnumber(image_meta_h image, double *fnumber)
275 int ret = MEDIA_CONTENT_ERROR_NONE;
276 image_meta_s *_image = (image_meta_s*)image;
278 if (_image && fnumber) {
279 *fnumber = _image->fnumber;
280 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_get_iso(image_meta_h image, int *iso)
291 int ret = MEDIA_CONTENT_ERROR_NONE;
292 image_meta_s *_image = (image_meta_s*)image;
296 ret = MEDIA_CONTENT_ERROR_NONE;
298 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
299 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
305 int image_meta_get_model(image_meta_h image, char **model)
307 int ret = MEDIA_CONTENT_ERROR_NONE;
308 image_meta_s *_image = (image_meta_s*)image;
310 if (_image && model) {
311 if (STRING_VALID(_image->model)) {
312 *model = strdup(_image->model);
313 media_content_retvm_if(*model == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
317 ret = MEDIA_CONTENT_ERROR_NONE;
319 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
320 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
326 int image_meta_is_burst_shot(image_meta_h image, bool *is_burst_shot)
328 int ret = MEDIA_CONTENT_ERROR_NONE;
329 media_content_warn("DEPRECATION WARNING: image_meta_is_burst_shot() is deprecated and will be removed from next release.");
330 image_meta_s *_image = (image_meta_s*)image;
332 if (_image && is_burst_shot) {
333 if (STRING_VALID(_image->burst_id))
334 *is_burst_shot = true;
336 *is_burst_shot = false;
338 ret = MEDIA_CONTENT_ERROR_NONE;
340 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
341 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
347 int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation)
349 int ret = MEDIA_CONTENT_ERROR_NONE;
350 media_content_warn("DEPRECATION WARNING: image_meta_set_orientation() is deprecated and will be removed from next release.");
351 image_meta_s *_image = (image_meta_s*)image;
353 if (_image == NULL) {
354 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
355 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
358 if ((orientation < MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE) || (orientation > MEDIA_CONTENT_ORIENTATION_ROT_270)) {
359 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
360 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
363 _image->orientation = orientation;
368 int image_meta_update_to_db(image_meta_h image)
370 int ret = MEDIA_CONTENT_ERROR_NONE;
371 media_content_warn("DEPRECATION WARNING: image_meta_update_to_db() is deprecated and will be removed from next release.");
372 image_meta_s *_image = (image_meta_s*)image;
375 if (_image != NULL && STRING_VALID(_image->media_id)) {
376 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,};
377 memset(storage_id, 0x00, sizeof(storage_id));
379 ret = _media_db_get_storage_id_by_media_id(_image->media_id, storage_id);
380 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
382 sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, storage_id, _image->orientation, _image->weather, _image->media_id);
383 ret = _content_query_sql(sql);
384 SQLITE3_SAFE_FREE(sql);
386 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
387 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;