Merge "add service_profile field for pvr table" into tizen
[platform/core/api/media-content.git] / src / media_video.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 #define media_content_retv_free_video_if(expr, val, p_str) do { \
21                                 if (expr) {     \
22                                         LOGE(FONT_COLOR_RED"Memory allocation failure"FONT_COLOR_RESET);        \
23                                         video_meta_destroy(p_str);      \
24                                         return (val);   \
25                                 }       \
26                         } while (0)
27
28
29 int video_meta_destroy(video_meta_h video)
30 {
31         video_meta_s *_video = (video_meta_s*)video;
32         media_content_retvm_if(_video == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Video handle is null");
33
34         SAFE_FREE(_video->media_id);
35         SAFE_FREE(_video->title);
36         SAFE_FREE(_video->album);
37         SAFE_FREE(_video->artist);
38         SAFE_FREE(_video->album_artist);
39         SAFE_FREE(_video->genre);
40         SAFE_FREE(_video->composer);
41         SAFE_FREE(_video->year);
42         SAFE_FREE(_video->recorded_date);
43         SAFE_FREE(_video->copyright);
44         SAFE_FREE(_video->track_num);
45         SAFE_FREE(_video);
46
47         return MEDIA_CONTENT_ERROR_NONE;
48 }
49
50 int video_meta_clone(video_meta_h *dst, video_meta_h src)
51 {
52         video_meta_s *_src = (video_meta_s*)src;
53         media_content_retvm_if(_src == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Source handle is null");
54
55         video_meta_s *_dst = (video_meta_s*)calloc(1, sizeof(video_meta_s));
56         media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
57
58         if (_src->media_id != NULL) {
59                 _dst->media_id = g_strdup(_src->media_id);
60                 media_content_retv_free_video_if(_dst->media_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (video_meta_h)_dst);
61         }
62
63         if (_src->title != NULL) {
64                 _dst->title = g_strdup(_src->title);
65                 media_content_retv_free_video_if(_dst->title == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (video_meta_h)_dst);
66         }
67
68         if (_src->album != NULL) {
69                 _dst->album = g_strdup(_src->album);
70                 media_content_retv_free_video_if(_dst->album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (video_meta_h)_dst);
71         }
72
73         if (_src->artist != NULL) {
74                 _dst->artist = g_strdup(_src->artist);
75                 media_content_retv_free_video_if(_dst->artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (video_meta_h)_dst);
76         }
77
78         if (_src->album_artist != NULL) {
79                 _dst->album_artist = g_strdup(_src->album_artist);
80                 media_content_retv_free_video_if(_dst->album_artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (video_meta_h)_dst);
81         }
82
83         if (_src->genre != NULL) {
84                 _dst->genre = g_strdup(_src->genre);
85                 media_content_retv_free_video_if(_dst->genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (video_meta_h)_dst);
86         }
87
88         if (_src->composer != NULL) {
89                 _dst->composer = g_strdup(_src->composer);
90                 media_content_retv_free_video_if(_dst->composer == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (video_meta_h)_dst);
91         }
92
93         if (_src->year != NULL) {
94                 _dst->year = g_strdup(_src->year);
95                 media_content_retv_free_video_if(_dst->year == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (video_meta_h)_dst);
96         }
97
98         if (_src->recorded_date != NULL) {
99                 _dst->recorded_date = g_strdup(_src->recorded_date);
100                 media_content_retv_free_video_if(_dst->recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (video_meta_h)_dst);
101         }
102
103         if (_src->copyright != NULL) {
104                 _dst->copyright = g_strdup(_src->copyright);
105                 media_content_retv_free_video_if(_dst->copyright == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (video_meta_h)_dst);
106         }
107
108         if (_src->track_num != NULL) {
109                 _dst->track_num = g_strdup(_src->track_num);
110                 media_content_retv_free_video_if(_dst->track_num == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (video_meta_h)_dst);
111         }
112
113         _dst->bitrate = _src->bitrate;
114         _dst->duration = _src->duration;
115         _dst->width = _src->width;
116         _dst->height = _src->height;
117         _dst->rotation = _src->rotation;
118
119         *dst = (video_meta_h)_dst;
120
121         return MEDIA_CONTENT_ERROR_NONE;
122 }
123
124 int video_meta_get_media_id(video_meta_h video, char **media_id)
125 {
126         int ret = MEDIA_CONTENT_ERROR_NONE;
127         video_meta_s *_video = (video_meta_s*)video;
128         if (_video) {
129                 if (_video->media_id != NULL) {
130                         char *new_string = strdup(_video->media_id);
131                         media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
132
133                         *media_id = new_string;
134                 } else {
135                         *media_id = NULL;
136                 }
137                 ret = MEDIA_CONTENT_ERROR_NONE;
138
139         } else {
140                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
141                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
142         }
143
144         return ret;
145 }
146
147 int video_meta_get_album(video_meta_h video, char **album)
148 {
149         int ret = MEDIA_CONTENT_ERROR_NONE;
150         video_meta_s *_video = (video_meta_s*)video;
151         if (_video) {
152                 if (_video->album != NULL) {
153                         char *new_string = strdup(_video->album);
154                         media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
155
156                         *album = new_string;
157                 } else {
158                         *album = NULL;
159                 }
160                 ret = MEDIA_CONTENT_ERROR_NONE;
161
162         } else {
163                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
164                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
165         }
166
167         return ret;
168 }
169
170 int video_meta_get_artist(video_meta_h video, char **artist)
171 {
172         int ret = MEDIA_CONTENT_ERROR_NONE;
173         video_meta_s *_video = (video_meta_s*)video;
174         if (_video) {
175                 if (_video->artist != NULL) {
176                         char *new_string = strdup(_video->artist);
177                         media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
178
179                         *artist = new_string;
180                 } else {
181                         *artist = NULL;
182                 }
183                 ret = MEDIA_CONTENT_ERROR_NONE;
184
185         } else {
186                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
187                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
188         }
189
190         return ret;
191 }
192
193 int video_meta_get_album_artist(video_meta_h video, char **album_artist)
194 {
195         int ret = MEDIA_CONTENT_ERROR_NONE;
196         video_meta_s *_video = (video_meta_s*)video;
197         if (_video) {
198                 if (_video->album_artist != NULL) {
199                         char *new_string = strdup(_video->album_artist);
200                         media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
201
202                         *album_artist = new_string;
203                 } else {
204                         *album_artist = NULL;
205                 }
206                 ret = MEDIA_CONTENT_ERROR_NONE;
207
208         } else {
209                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
210                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
211         }
212
213         return ret;
214 }
215
216 int video_meta_get_genre(video_meta_h video, char **genre)
217 {
218         int ret = MEDIA_CONTENT_ERROR_NONE;
219         video_meta_s *_video = (video_meta_s*)video;
220         if (_video) {
221                 if (_video->genre != NULL) {
222                         char *new_string = strdup(_video->genre);
223                         media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
224
225                         *genre = new_string;
226                 } else {
227                         *genre = NULL;
228                 }
229
230                 ret = MEDIA_CONTENT_ERROR_NONE;
231         } else {
232                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
233                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
234         }
235
236         return ret;
237 }
238
239 int video_meta_get_composer(video_meta_h video, char **composer)
240 {
241         int ret = MEDIA_CONTENT_ERROR_NONE;
242         video_meta_s *_video = (video_meta_s*)video;
243         if (_video) {
244                 if (_video->composer != NULL) {
245                         char *new_string = strdup(_video->composer);
246                         media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
247
248                         *composer = new_string;
249                 } else {
250                         *composer = NULL;
251                 }
252
253                 ret = MEDIA_CONTENT_ERROR_NONE;
254         } else {
255                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
256                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
257         }
258
259         return ret;
260 }
261
262 int video_meta_get_year(video_meta_h video, char **year)
263 {
264         int ret = MEDIA_CONTENT_ERROR_NONE;
265         video_meta_s *_video = (video_meta_s*)video;
266         if (_video) {
267                 if (_video->year != NULL) {
268                         char *new_string = strdup(_video->year);
269                         media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
270
271                         *year = new_string;
272                 } else {
273                         *year = NULL;
274                 }
275
276                 ret = MEDIA_CONTENT_ERROR_NONE;
277         } else {
278                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
279                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
280         }
281
282         return ret;
283 }
284
285 int video_meta_get_recorded_date(video_meta_h video, char **recorded_date)
286 {
287         int ret = MEDIA_CONTENT_ERROR_NONE;
288         video_meta_s *_video = (video_meta_s*)video;
289         if (_video) {
290                 if (_video->recorded_date != NULL) {
291                         char *new_string = strdup(_video->recorded_date);
292                         media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
293
294                         *recorded_date = new_string;
295                 } else {
296                         *recorded_date = NULL;
297                 }
298
299                 ret = MEDIA_CONTENT_ERROR_NONE;
300         } else {
301                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
302                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
303         }
304
305         return ret;
306 }
307
308 int video_meta_get_copyright(video_meta_h video, char **copyright)
309 {
310         int ret = MEDIA_CONTENT_ERROR_NONE;
311         video_meta_s *_video = (video_meta_s*)video;
312         if (_video) {
313                 if (_video->copyright != NULL) {
314                         char *new_string = strdup(_video->copyright);
315                         media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
316
317                         *copyright = new_string;
318                 } else {
319                         *copyright = NULL;
320                 }
321
322                 ret = MEDIA_CONTENT_ERROR_NONE;
323         } else {
324                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
325                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
326         }
327
328         return ret;
329 }
330
331 int video_meta_get_track_num(video_meta_h video, char **track_num)
332 {
333         int ret = MEDIA_CONTENT_ERROR_NONE;
334         video_meta_s *_video = (video_meta_s*)video;
335         if (_video) {
336                 if (_video->track_num != NULL) {
337                         char *new_string = strdup(_video->track_num);
338                         media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
339
340                         *track_num = new_string;
341                 } else {
342                         *track_num = NULL;
343                 }
344
345                 ret = MEDIA_CONTENT_ERROR_NONE;
346         } else {
347                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
348                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
349         }
350
351         return ret;
352 }
353
354 int video_meta_get_bit_rate(video_meta_h video, int *bit_rate)
355 {
356         int ret = MEDIA_CONTENT_ERROR_NONE;
357         video_meta_s *_video = (video_meta_s*)video;
358
359         if (_video && bit_rate) {
360                 *bit_rate = _video->bitrate;
361                 ret = MEDIA_CONTENT_ERROR_NONE;
362         } else {
363                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
364                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
365         }
366
367         return ret;
368 }
369
370 int video_meta_get_duration(video_meta_h video, int *duration)
371 {
372         int ret = MEDIA_CONTENT_ERROR_NONE;
373         video_meta_s *_video = (video_meta_s*)video;
374
375         if (_video && duration) {
376                 *duration = _video->duration;
377                 ret = MEDIA_CONTENT_ERROR_NONE;
378         } else {
379                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
380                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
381         }
382
383         return ret;
384 }
385
386 int video_meta_get_width(video_meta_h video, int *width)
387 {
388         int ret = MEDIA_CONTENT_ERROR_NONE;
389         video_meta_s *_video = (video_meta_s*)video;
390
391         if (_video && width) {
392                 *width = _video->width;
393                 ret = MEDIA_CONTENT_ERROR_NONE;
394         } else {
395                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
396                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
397         }
398
399         return ret;
400 }
401
402 int video_meta_get_height(video_meta_h video, int *height)
403 {
404         int ret = MEDIA_CONTENT_ERROR_NONE;
405         video_meta_s *_video = (video_meta_s*)video;
406         if (_video && height) {
407                 *height = _video->height;
408                 ret = MEDIA_CONTENT_ERROR_NONE;
409         } else {
410                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
411                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
412         }
413
414         return ret;
415 }
416
417 int video_meta_get_rotation(video_meta_h video, int *rotation)
418 {
419         int ret = MEDIA_CONTENT_ERROR_NONE;
420         video_meta_s *_video = (video_meta_s*)video;
421         if (_video && rotation) {
422                 *rotation = _video->rotation;
423                 ret = MEDIA_CONTENT_ERROR_NONE;
424         } else {
425                 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
426                 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
427         }
428
429         return ret;
430 }