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->exposure_time);
37 SAFE_FREE(_image->model);
40 return MEDIA_CONTENT_ERROR_NONE;
43 int image_meta_clone(image_meta_h *dst, image_meta_h src)
45 image_meta_s *_src = (image_meta_s*)src;
46 media_content_retvm_if(_src == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Source handle is null");
48 image_meta_s *_dst = (image_meta_s*)calloc(1, sizeof(image_meta_s));
49 media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
51 if (STRING_VALID(_src->media_id)) {
52 _dst->media_id = strdup(_src->media_id);
53 media_content_retv_free_image_if(_dst->media_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (image_meta_h)_dst);
56 if (STRING_VALID(_src->date_taken)) {
57 _dst->date_taken = strdup(_src->date_taken);
58 media_content_retv_free_image_if(_dst->date_taken == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (image_meta_h)_dst);
61 if (STRING_VALID(_src->exposure_time)) {
62 _dst->exposure_time = strdup(_src->exposure_time);
63 media_content_retv_free_image_if(_dst->exposure_time == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (image_meta_h)_dst);
66 if (STRING_VALID(_src->model)) {
67 _dst->model = strdup(_src->model);
68 media_content_retv_free_image_if(_dst->model == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (image_meta_h)_dst);
71 _dst->fnumber = _src->fnumber;
72 _dst->iso = _src->iso;
73 _dst->width = _src->width;
74 _dst->height = _src->height;
75 _dst->orientation = _src->orientation;
77 *dst = (image_meta_h)_dst;
79 return MEDIA_CONTENT_ERROR_NONE;
82 int image_meta_get_media_id(image_meta_h image, char **media_id)
84 int ret = MEDIA_CONTENT_ERROR_NONE;
85 image_meta_s *_image = (image_meta_s*)image;
87 if (_image && media_id) {
88 if (STRING_VALID(_image->media_id)) {
89 char *new_string = strdup(_image->media_id);
90 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
92 *media_id = new_string;
96 ret = MEDIA_CONTENT_ERROR_NONE;
99 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
100 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
107 int image_meta_get_width(image_meta_h image, int *width)
109 int ret = MEDIA_CONTENT_ERROR_NONE;
110 image_meta_s *_image = (image_meta_s*)image;
112 if (_image && width) {
113 *width = _image->width;
114 ret = MEDIA_CONTENT_ERROR_NONE;
116 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
117 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
122 int image_meta_get_height(image_meta_h image, int *height)
124 int ret = MEDIA_CONTENT_ERROR_NONE;
125 image_meta_s *_image = (image_meta_s*)image;
127 if (_image && height) {
128 *height = _image->height;
129 ret = MEDIA_CONTENT_ERROR_NONE;
131 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
132 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
138 int image_meta_get_orientation(image_meta_h image, media_content_orientation_e* orientation)
140 int ret = MEDIA_CONTENT_ERROR_NONE;
141 image_meta_s *_image = (image_meta_s*)image;
143 if (_image && orientation) {
144 *orientation = _image->orientation;
145 ret = MEDIA_CONTENT_ERROR_NONE;
147 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
148 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
154 int image_meta_get_date_taken(image_meta_h image, char **date_taken)
156 int ret = MEDIA_CONTENT_ERROR_NONE;
157 image_meta_s *_image = (image_meta_s*)image;
159 if (_image && date_taken) {
160 if (STRING_VALID(_image->date_taken)) {
161 char *new_string = strdup(_image->date_taken);
162 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
164 *date_taken = new_string;
169 ret = MEDIA_CONTENT_ERROR_NONE;
171 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
172 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
178 int image_meta_get_exposure_time(image_meta_h image, char **exposure_time)
180 int ret = MEDIA_CONTENT_ERROR_NONE;
181 image_meta_s *_image = (image_meta_s*)image;
183 if (_image && exposure_time) {
184 if (STRING_VALID(_image->exposure_time)) {
185 *exposure_time = strdup(_image->exposure_time);
186 media_content_retvm_if(*exposure_time == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
188 *exposure_time = NULL;
190 ret = MEDIA_CONTENT_ERROR_NONE;
192 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
193 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
199 int image_meta_get_fnumber(image_meta_h image, double *fnumber)
201 int ret = MEDIA_CONTENT_ERROR_NONE;
202 image_meta_s *_image = (image_meta_s*)image;
204 if (_image && fnumber) {
205 *fnumber = _image->fnumber;
206 ret = MEDIA_CONTENT_ERROR_NONE;
208 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
209 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
215 int image_meta_get_iso(image_meta_h image, int *iso)
217 int ret = MEDIA_CONTENT_ERROR_NONE;
218 image_meta_s *_image = (image_meta_s*)image;
222 ret = MEDIA_CONTENT_ERROR_NONE;
224 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
225 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
231 int image_meta_get_model(image_meta_h image, char **model)
233 int ret = MEDIA_CONTENT_ERROR_NONE;
234 image_meta_s *_image = (image_meta_s*)image;
236 if (_image && model) {
237 if (STRING_VALID(_image->model)) {
238 *model = strdup(_image->model);
239 media_content_retvm_if(*model == 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_set_orientation(image_meta_h image, media_content_orientation_e orientation)
254 int ret = MEDIA_CONTENT_ERROR_NONE;
255 media_content_warn("DEPRECATION WARNING: image_meta_set_orientation() is deprecated and will be removed from next release.");
256 image_meta_s *_image = (image_meta_s*)image;
258 if (_image == NULL) {
259 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
260 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
263 if ((orientation < MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE) || (orientation > MEDIA_CONTENT_ORIENTATION_ROT_270)) {
264 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
265 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
268 _image->orientation = orientation;
273 int image_meta_update_to_db(image_meta_h image)
275 int ret = MEDIA_CONTENT_ERROR_NONE;
276 media_content_warn("DEPRECATION WARNING: image_meta_update_to_db() is deprecated and will be removed from next release.");
277 image_meta_s *_image = (image_meta_s*)image;
280 if (_image != NULL && STRING_VALID(_image->media_id)) {
281 #ifdef _USE_TVPD_MODE
282 char *storage_id = NULL;
283 ret = _media_db_get_storage_id_by_media_id(_image->media_id, &storage_id);
284 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
285 sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, storage_id, _image->orientation, _image->media_id);
286 SAFE_FREE(storage_id);
288 sql = sqlite3_mprintf(UPDATE_IMAGE_META_FROM_MEDIA, _image->orientation, _image->media_id);
290 ret = _content_query_sql(sql);
291 SQLITE3_SAFE_FREE(sql);
293 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
294 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;