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