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->exposure_time);
38 SAFE_FREE(_image->model);
41 return MEDIA_CONTENT_ERROR_NONE;
44 int image_meta_clone(image_meta_h *dst, image_meta_h src)
46 image_meta_s *_src = (image_meta_s*)src;
47 media_content_retvm_if(_src == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Source handle is null");
49 image_meta_s *_dst = (image_meta_s*)calloc(1, sizeof(image_meta_s));
50 media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
52 if (STRING_VALID(_src->media_id)) {
53 _dst->media_id = strdup(_src->media_id);
54 media_content_retv_free_image_if(_dst->media_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (image_meta_h)_dst);
57 if (STRING_VALID(_src->date_taken)) {
58 _dst->date_taken = strdup(_src->date_taken);
59 media_content_retv_free_image_if(_dst->date_taken == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (image_meta_h)_dst);
62 if (STRING_VALID(_src->title)) {
63 _dst->title = strdup(_src->title);
64 media_content_retv_free_image_if(_dst->title == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (image_meta_h)_dst);
67 if (STRING_VALID(_src->exposure_time)) {
68 _dst->exposure_time = strdup(_src->exposure_time);
69 media_content_retv_free_image_if(_dst->exposure_time == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (image_meta_h)_dst);
72 if (STRING_VALID(_src->model)) {
73 _dst->model = strdup(_src->model);
74 media_content_retv_free_image_if(_dst->model == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (image_meta_h)_dst);
77 _dst->fnumber = _src->fnumber;
78 _dst->iso = _src->iso;
79 _dst->width = _src->width;
80 _dst->height = _src->height;
81 _dst->orientation = _src->orientation;
83 *dst = (image_meta_h)_dst;
85 return MEDIA_CONTENT_ERROR_NONE;
88 int image_meta_get_media_id(image_meta_h image, char **media_id)
90 int ret = MEDIA_CONTENT_ERROR_NONE;
91 image_meta_s *_image = (image_meta_s*)image;
93 if (_image && media_id) {
94 if (STRING_VALID(_image->media_id)) {
95 char *new_string = strdup(_image->media_id);
96 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
98 *media_id = new_string;
102 ret = MEDIA_CONTENT_ERROR_NONE;
105 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
106 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
113 int image_meta_get_width(image_meta_h image, int *width)
115 int ret = MEDIA_CONTENT_ERROR_NONE;
116 image_meta_s *_image = (image_meta_s*)image;
118 if (_image && width) {
119 *width = _image->width;
120 ret = MEDIA_CONTENT_ERROR_NONE;
122 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
123 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
128 int image_meta_get_height(image_meta_h image, int *height)
130 int ret = MEDIA_CONTENT_ERROR_NONE;
131 image_meta_s *_image = (image_meta_s*)image;
133 if (_image && height) {
134 *height = _image->height;
135 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;
144 int image_meta_get_orientation(image_meta_h image, media_content_orientation_e* orientation)
146 int ret = MEDIA_CONTENT_ERROR_NONE;
147 image_meta_s *_image = (image_meta_s*)image;
149 if (_image && orientation) {
150 *orientation = _image->orientation;
151 ret = MEDIA_CONTENT_ERROR_NONE;
153 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
154 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
160 int image_meta_get_date_taken(image_meta_h image, char **date_taken)
162 int ret = MEDIA_CONTENT_ERROR_NONE;
163 image_meta_s *_image = (image_meta_s*)image;
165 if (_image && date_taken) {
166 if (STRING_VALID(_image->date_taken)) {
167 char *new_string = strdup(_image->date_taken);
168 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
170 *date_taken = new_string;
175 ret = MEDIA_CONTENT_ERROR_NONE;
177 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
178 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
184 int image_meta_get_exposure_time(image_meta_h image, char **exposure_time)
186 int ret = MEDIA_CONTENT_ERROR_NONE;
187 image_meta_s *_image = (image_meta_s*)image;
189 if (_image && exposure_time) {
190 if (STRING_VALID(_image->exposure_time)) {
191 *exposure_time = strdup(_image->exposure_time);
192 media_content_retvm_if(*exposure_time == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
194 *exposure_time = NULL;
196 ret = MEDIA_CONTENT_ERROR_NONE;
198 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
199 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
205 int image_meta_get_fnumber(image_meta_h image, double *fnumber)
207 int ret = MEDIA_CONTENT_ERROR_NONE;
208 image_meta_s *_image = (image_meta_s*)image;
210 if (_image && fnumber) {
211 *fnumber = _image->fnumber;
212 ret = MEDIA_CONTENT_ERROR_NONE;
214 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
215 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
221 int image_meta_get_iso(image_meta_h image, int *iso)
223 int ret = MEDIA_CONTENT_ERROR_NONE;
224 image_meta_s *_image = (image_meta_s*)image;
228 ret = MEDIA_CONTENT_ERROR_NONE;
230 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
231 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
237 int image_meta_get_model(image_meta_h image, char **model)
239 int ret = MEDIA_CONTENT_ERROR_NONE;
240 image_meta_s *_image = (image_meta_s*)image;
242 if (_image && model) {
243 if (STRING_VALID(_image->model)) {
244 *model = strdup(_image->model);
245 media_content_retvm_if(*model == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
249 ret = MEDIA_CONTENT_ERROR_NONE;
251 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
252 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
258 int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation)
263 int image_meta_update_to_db(image_meta_h image)