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->burst_id);
31 SAFE_FREE(_image->exposure_time);
32 SAFE_FREE(_image->model);
35 ret = MEDIA_CONTENT_ERROR_NONE;
37 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
38 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
44 int image_meta_clone(image_meta_h *dst, image_meta_h src)
46 int ret = MEDIA_CONTENT_ERROR_NONE;
47 image_meta_s *_src = (image_meta_s*)src;
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 if (_dst->media_id == NULL) {
56 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
57 image_meta_destroy((image_meta_h)_dst);
58 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
62 if (STRING_VALID(_src->date_taken)) {
63 _dst->date_taken = strdup(_src->date_taken);
64 if (_dst->date_taken == NULL) {
65 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
66 image_meta_destroy((image_meta_h)_dst);
67 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
71 if (STRING_VALID(_src->title)) {
72 _dst->title = strdup(_src->title);
73 if (_dst->title == NULL) {
74 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
75 image_meta_destroy((image_meta_h)_dst);
76 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
80 if (STRING_VALID(_src->burst_id)) {
81 _dst->burst_id = strdup(_src->burst_id);
82 if (_dst->burst_id == NULL) {
83 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
84 image_meta_destroy((image_meta_h)_dst);
85 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
89 if (STRING_VALID(_src->exposure_time)) {
90 _dst->exposure_time = strdup(_src->exposure_time);
91 if (_dst->exposure_time == NULL) {
92 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
93 image_meta_destroy((image_meta_h)_dst);
94 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
98 if (STRING_VALID(_src->model)) {
99 _dst->model = strdup(_src->model);
100 if (_dst->model == 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 _dst->fnumber = _src->fnumber;
108 _dst->iso = _src->iso;
109 _dst->width = _src->width;
110 _dst->height = _src->height;
111 _dst->orientation = _src->orientation;
113 *dst = (image_meta_h)_dst;
115 ret = MEDIA_CONTENT_ERROR_NONE;
117 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
118 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
124 int image_meta_get_media_id(image_meta_h image, char **media_id)
126 int ret = MEDIA_CONTENT_ERROR_NONE;
127 image_meta_s *_image = (image_meta_s*)image;
129 if (_image && media_id) {
130 if (STRING_VALID(_image->media_id)) {
131 char *new_string = strdup(_image->media_id);
132 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
134 *media_id = new_string;
138 ret = MEDIA_CONTENT_ERROR_NONE;
141 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
142 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
149 int image_meta_get_width(image_meta_h image, int *width)
151 int ret = MEDIA_CONTENT_ERROR_NONE;
152 image_meta_s *_image = (image_meta_s*)image;
154 if (_image && width) {
155 *width = _image->width;
156 ret = MEDIA_CONTENT_ERROR_NONE;
158 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
159 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
164 int image_meta_get_height(image_meta_h image, int *height)
166 int ret = MEDIA_CONTENT_ERROR_NONE;
167 image_meta_s *_image = (image_meta_s*)image;
169 if (_image && height) {
170 *height = _image->height;
171 ret = MEDIA_CONTENT_ERROR_NONE;
173 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
174 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
180 int image_meta_get_orientation(image_meta_h image, media_content_orientation_e* orientation)
182 int ret = MEDIA_CONTENT_ERROR_NONE;
183 image_meta_s *_image = (image_meta_s*)image;
185 if (_image && orientation) {
186 *orientation = _image->orientation;
187 ret = MEDIA_CONTENT_ERROR_NONE;
189 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
190 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
196 int image_meta_get_date_taken(image_meta_h image, char **date_taken)
198 int ret = MEDIA_CONTENT_ERROR_NONE;
199 image_meta_s *_image = (image_meta_s*)image;
201 if (_image && date_taken) {
202 if (STRING_VALID(_image->date_taken)) {
203 char *new_string = strdup(_image->date_taken);
204 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
206 *date_taken = new_string;
211 ret = MEDIA_CONTENT_ERROR_NONE;
213 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
214 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
220 int image_meta_get_burst_id(image_meta_h image, char **burst_id)
222 int ret = MEDIA_CONTENT_ERROR_NONE;
223 media_content_warn("DEPRECATION WARNING: image_meta_get_burst_id() is deprecated and will be removed from next release.");
224 image_meta_s *_image = (image_meta_s*)image;
226 if (_image && burst_id) {
227 if (STRING_VALID(_image->burst_id)) {
228 *burst_id = strdup(_image->burst_id);
229 media_content_retvm_if(*burst_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
233 ret = MEDIA_CONTENT_ERROR_NONE;
235 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
236 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
242 int image_meta_get_exposure_time(image_meta_h image, char **exposure_time)
244 int ret = MEDIA_CONTENT_ERROR_NONE;
245 image_meta_s *_image = (image_meta_s*)image;
247 if (_image && exposure_time) {
248 if (STRING_VALID(_image->exposure_time)) {
249 *exposure_time = strdup(_image->exposure_time);
250 media_content_retvm_if(*exposure_time == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
252 *exposure_time = NULL;
254 ret = MEDIA_CONTENT_ERROR_NONE;
256 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
257 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
263 int image_meta_get_fnumber(image_meta_h image, double *fnumber)
265 int ret = MEDIA_CONTENT_ERROR_NONE;
266 image_meta_s *_image = (image_meta_s*)image;
268 if (_image && fnumber) {
269 *fnumber = _image->fnumber;
270 ret = MEDIA_CONTENT_ERROR_NONE;
272 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
273 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
279 int image_meta_get_iso(image_meta_h image, int *iso)
281 int ret = MEDIA_CONTENT_ERROR_NONE;
282 image_meta_s *_image = (image_meta_s*)image;
286 ret = MEDIA_CONTENT_ERROR_NONE;
288 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
289 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
295 int image_meta_get_model(image_meta_h image, char **model)
297 int ret = MEDIA_CONTENT_ERROR_NONE;
298 image_meta_s *_image = (image_meta_s*)image;
300 if (_image && model) {
301 if (STRING_VALID(_image->model)) {
302 *model = strdup(_image->model);
303 media_content_retvm_if(*model == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
307 ret = MEDIA_CONTENT_ERROR_NONE;
309 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
310 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
316 int image_meta_is_burst_shot(image_meta_h image, bool *is_burst_shot)
318 int ret = MEDIA_CONTENT_ERROR_NONE;
319 media_content_warn("DEPRECATION WARNING: image_meta_is_burst_shot() is deprecated and will be removed from next release.");
320 image_meta_s *_image = (image_meta_s*)image;
322 if (_image && is_burst_shot) {
323 if (STRING_VALID(_image->burst_id))
324 *is_burst_shot = true;
326 *is_burst_shot = false;
328 ret = MEDIA_CONTENT_ERROR_NONE;
330 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
331 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
337 int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation)
339 int ret = MEDIA_CONTENT_ERROR_NONE;
340 media_content_warn("DEPRECATION WARNING: image_meta_set_orientation() is deprecated and will be removed from next release.");
341 image_meta_s *_image = (image_meta_s*)image;
343 if (_image == NULL) {
344 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
345 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
348 if ((orientation < MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE) || (orientation > MEDIA_CONTENT_ORIENTATION_ROT_270)) {
349 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
350 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
353 _image->orientation = orientation;
358 int image_meta_update_to_db(image_meta_h image)
360 int ret = MEDIA_CONTENT_ERROR_NONE;
361 media_content_warn("DEPRECATION WARNING: image_meta_update_to_db() is deprecated and will be removed from next release.");
362 image_meta_s *_image = (image_meta_s*)image;
365 if (_image != NULL && STRING_VALID(_image->media_id)) {
366 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,};
367 memset(storage_id, 0x00, sizeof(storage_id));
369 ret = _media_db_get_storage_id_by_media_id(_image->media_id, storage_id);
370 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
372 sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, storage_id, _image->orientation, _image->media_id);
373 ret = _content_query_sql(sql);
374 SQLITE3_SAFE_FREE(sql);
376 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
377 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;