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