[ACR-1098] Deprecate APIs for product
[platform/core/api/media-content.git] / src / media_image.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17
18 #include <media_info_private.h>
19
20
21 int image_meta_destroy(image_meta_h image)
22 {
23         int ret = MEDIA_CONTENT_ERROR_NONE;
24         image_meta_s *_image = (image_meta_s*)image;
25
26         if (_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);
34                 SAFE_FREE(_image);
35
36                 ret = MEDIA_CONTENT_ERROR_NONE;
37         } else {
38                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
39                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
40         }
41
42         return ret;
43 }
44
45 int image_meta_clone(image_meta_h *dst, image_meta_h src)
46 {
47         int ret = MEDIA_CONTENT_ERROR_NONE;
48         image_meta_s *_src = (image_meta_s*)src;
49
50         if (_src != NULL) {
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");
53
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;
60                         }
61                 }
62
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;
69                         }
70                 }
71
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;
78                         }
79                 }
80
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;
87                         }
88                 }
89
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;
96                         }
97                 }
98
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;
105                         }
106                 }
107
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;
114                         }
115                 }
116
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;
122
123                 *dst = (image_meta_h)_dst;
124
125                 ret = MEDIA_CONTENT_ERROR_NONE;
126         } else {
127                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
128                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
129         }
130
131         return ret;
132 }
133
134 int image_meta_get_media_id(image_meta_h image, char **media_id)
135 {
136         int ret = MEDIA_CONTENT_ERROR_NONE;
137         image_meta_s *_image = (image_meta_s*)image;
138
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");
143
144                         *media_id = new_string;
145                 } else {
146                         *media_id = NULL;
147                 }
148                 ret = MEDIA_CONTENT_ERROR_NONE;
149
150         } else {
151                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
152                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
153         }
154
155         return ret;
156
157 }
158
159 int image_meta_get_width(image_meta_h image, int *width)
160 {
161         int ret = MEDIA_CONTENT_ERROR_NONE;
162         image_meta_s *_image = (image_meta_s*)image;
163
164         if (_image && width) {
165                 *width = _image->width;
166                 ret = MEDIA_CONTENT_ERROR_NONE;
167         } else {
168                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
169                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
170         }
171
172         return ret;
173 }
174 int image_meta_get_height(image_meta_h image, int *height)
175 {
176         int ret = MEDIA_CONTENT_ERROR_NONE;
177         image_meta_s *_image = (image_meta_s*)image;
178
179         if (_image && height) {
180                 *height = _image->height;
181                 ret = MEDIA_CONTENT_ERROR_NONE;
182         } else {
183                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
184                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
185         }
186
187         return ret;
188 }
189
190 int image_meta_get_orientation(image_meta_h image, media_content_orientation_e* orientation)
191 {
192         int ret = MEDIA_CONTENT_ERROR_NONE;
193         image_meta_s *_image = (image_meta_s*)image;
194
195         if (_image && orientation) {
196                 *orientation = _image->orientation;
197                 ret = MEDIA_CONTENT_ERROR_NONE;
198         } else {
199                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
200                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
201         }
202
203         return ret;
204 }
205
206 int image_meta_get_date_taken(image_meta_h image, char **date_taken)
207 {
208         int ret = MEDIA_CONTENT_ERROR_NONE;
209         image_meta_s *_image = (image_meta_s*)image;
210
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");
215
216                         *date_taken = new_string;
217                 } else {
218                         *date_taken = NULL;
219                 }
220
221                 ret = MEDIA_CONTENT_ERROR_NONE;
222         } else {
223                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
224                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
225         }
226
227         return ret;
228 }
229
230 int image_meta_get_burst_id(image_meta_h image, char **burst_id)
231 {
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;
235
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");
240                 } else {
241                         *burst_id = NULL;
242                 }
243                 ret = MEDIA_CONTENT_ERROR_NONE;
244         } else {
245                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
246                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
247         }
248
249         return ret;
250 }
251
252 int image_meta_get_exposure_time(image_meta_h image, char **exposure_time)
253 {
254         int ret = MEDIA_CONTENT_ERROR_NONE;
255         image_meta_s *_image = (image_meta_s*)image;
256
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");
261                 } else {
262                         *exposure_time = NULL;
263                 }
264                 ret = MEDIA_CONTENT_ERROR_NONE;
265         } else {
266                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
267                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
268         }
269
270         return ret;
271 }
272
273 int image_meta_get_fnumber(image_meta_h image, double *fnumber)
274 {
275         int ret = MEDIA_CONTENT_ERROR_NONE;
276         image_meta_s *_image = (image_meta_s*)image;
277
278         if (_image && fnumber) {
279                 *fnumber = _image->fnumber;
280                 ret = MEDIA_CONTENT_ERROR_NONE;
281         } else {
282                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
283                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
284         }
285
286         return ret;
287 }
288
289 int image_meta_get_iso(image_meta_h image, int *iso)
290 {
291         int ret = MEDIA_CONTENT_ERROR_NONE;
292         image_meta_s *_image = (image_meta_s*)image;
293
294         if (_image && iso) {
295                 *iso = _image->iso;
296                 ret = MEDIA_CONTENT_ERROR_NONE;
297         } else {
298                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
299                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
300         }
301
302         return ret;
303 }
304
305 int image_meta_get_model(image_meta_h image, char **model)
306 {
307         int ret = MEDIA_CONTENT_ERROR_NONE;
308         image_meta_s *_image = (image_meta_s*)image;
309
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");
314                 } else {
315                         *model = NULL;
316                 }
317                 ret = MEDIA_CONTENT_ERROR_NONE;
318         } else {
319                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
320                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
321         }
322
323         return ret;
324 }
325
326 int image_meta_is_burst_shot(image_meta_h image, bool *is_burst_shot)
327 {
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;
331
332         if (_image && is_burst_shot) {
333                 if (STRING_VALID(_image->burst_id))
334                         *is_burst_shot = true;
335                 else
336                         *is_burst_shot = false;
337
338                 ret = MEDIA_CONTENT_ERROR_NONE;
339         } else {
340                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
341                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
342         }
343
344         return ret;
345 }
346
347 int image_meta_set_orientation(image_meta_h image, media_content_orientation_e orientation)
348 {
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;
352
353         if (_image == NULL) {
354                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
355                 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
356         }
357
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;
361         }
362
363         _image->orientation = orientation;
364
365         return ret;
366 }
367
368 int image_meta_update_to_db(image_meta_h image)
369 {
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;
373         char *sql = NULL;
374
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));
378
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);
381
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);
385         } else {
386                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
387                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
388         }
389
390         return ret;
391 }