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_audio_if(expr, val, p_str) do { \
22 LOGE(FONT_COLOR_RED"Memory allocation failure"FONT_COLOR_RESET); \
23 audio_meta_destroy(p_str); \
28 int audio_meta_destroy(audio_meta_h audio)
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");
33 SAFE_FREE(_audio->media_id);
34 SAFE_FREE(_audio->title);
35 SAFE_FREE(_audio->album);
36 SAFE_FREE(_audio->artist);
37 SAFE_FREE(_audio->album_artist);
38 SAFE_FREE(_audio->genre);
39 SAFE_FREE(_audio->composer);
40 SAFE_FREE(_audio->year);
41 SAFE_FREE(_audio->recorded_date);
42 SAFE_FREE(_audio->copyright);
43 SAFE_FREE(_audio->track_num);
46 return MEDIA_CONTENT_ERROR_NONE;
49 int audio_meta_clone(audio_meta_h *dst, audio_meta_h src)
51 audio_meta_s *_src = (audio_meta_s*)src;
52 media_content_retvm_if(_src == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Source handle is null");
54 audio_meta_s *_dst = (audio_meta_s*)calloc(1, sizeof(audio_meta_s));
55 media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
57 if (_src->media_id != NULL) {
58 _dst->media_id = g_strdup(_src->media_id);
59 media_content_retv_free_audio_if(_dst->media_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (audio_meta_h)_dst);
62 if (_src->title != NULL) {
63 _dst->title = g_strdup(_src->title);
64 media_content_retv_free_audio_if(_dst->title == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (audio_meta_h)_dst);
67 if (_src->album != NULL) {
68 _dst->album = g_strdup(_src->album);
69 media_content_retv_free_audio_if(_dst->album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (audio_meta_h)_dst);
72 if (_src->artist != NULL) {
73 _dst->artist = g_strdup(_src->artist);
74 media_content_retv_free_audio_if(_dst->artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (audio_meta_h)_dst);
77 if (_src->album_artist != NULL) {
78 _dst->album_artist = g_strdup(_src->album_artist);
79 media_content_retv_free_audio_if(_dst->album_artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (audio_meta_h)_dst);
82 if (_src->genre != NULL) {
83 _dst->genre = g_strdup(_src->genre);
84 media_content_retv_free_audio_if(_dst->genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (audio_meta_h)_dst);
87 if (_src->composer != NULL) {
88 _dst->composer = g_strdup(_src->composer);
89 media_content_retv_free_audio_if(_dst->composer == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (audio_meta_h)_dst);
92 if (_src->year != NULL) {
93 _dst->year = g_strdup(_src->year);
94 media_content_retv_free_audio_if(_dst->year == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (audio_meta_h)_dst);
97 if (_src->recorded_date != NULL) {
98 _dst->recorded_date = g_strdup(_src->recorded_date);
99 media_content_retv_free_audio_if(_dst->recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (audio_meta_h)_dst);
102 if (_src->copyright != NULL) {
103 _dst->copyright = g_strdup(_src->copyright);
104 media_content_retv_free_audio_if(_dst->copyright == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (audio_meta_h)_dst);
107 if (_src->track_num != NULL) {
108 _dst->track_num = g_strdup(_src->track_num);
109 media_content_retv_free_audio_if(_dst->track_num == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, (audio_meta_h)_dst);
112 _dst->bitrate = _src->bitrate;
113 _dst->bitpersample = _src->bitpersample;
114 _dst->samplerate = _src->samplerate;
115 _dst->channel = _src->channel;
116 _dst->duration = _src->duration;
118 *dst = (audio_meta_h)_dst;
120 return MEDIA_CONTENT_ERROR_NONE;
123 int audio_meta_get_media_id(audio_meta_h audio, char **media_id)
125 int ret = MEDIA_CONTENT_ERROR_NONE;
126 audio_meta_s *_audio = (audio_meta_s*)audio;
128 if (STRING_VALID(_audio->media_id)) {
129 *media_id = strdup(_audio->media_id);
130 media_content_retvm_if(*media_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
134 ret = MEDIA_CONTENT_ERROR_NONE;
137 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
138 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
144 int audio_meta_get_album(audio_meta_h audio, char **album)
146 int ret = MEDIA_CONTENT_ERROR_NONE;
147 audio_meta_s *_audio = (audio_meta_s*)audio;
149 if (_audio->album != NULL) {
150 *album = g_strdup(_audio->album); /*album can be empty string*/
151 media_content_retvm_if(*album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
155 ret = MEDIA_CONTENT_ERROR_NONE;
158 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
159 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
165 int audio_meta_get_artist(audio_meta_h audio, char **artist)
167 int ret = MEDIA_CONTENT_ERROR_NONE;
168 audio_meta_s *_audio = (audio_meta_s*)audio;
171 if (_audio->artist != NULL) {
172 *artist = g_strdup(_audio->artist); /*artist can be empty string*/
173 media_content_retvm_if(*artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
177 ret = MEDIA_CONTENT_ERROR_NONE;
180 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
181 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
187 int audio_meta_get_album_artist(audio_meta_h audio, char **album_artist)
189 int ret = MEDIA_CONTENT_ERROR_NONE;
190 audio_meta_s *_audio = (audio_meta_s*)audio;
193 if (_audio->album_artist != NULL) {
194 *album_artist = g_strdup(_audio->album_artist); /*album_artist can be empty string*/
195 media_content_retvm_if(*album_artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
197 *album_artist = NULL;
199 ret = MEDIA_CONTENT_ERROR_NONE;
202 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
203 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
209 int audio_meta_get_genre(audio_meta_h audio, char **genre)
211 int ret = MEDIA_CONTENT_ERROR_NONE;
212 audio_meta_s *_audio = (audio_meta_s*)audio;
215 if (_audio->genre != NULL) {
216 *genre = g_strdup(_audio->genre); /*genre can be empty string*/
217 media_content_retvm_if(*genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
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 audio_meta_get_composer(audio_meta_h audio, char **composer)
233 int ret = MEDIA_CONTENT_ERROR_NONE;
234 audio_meta_s *_audio = (audio_meta_s*)audio;
237 if (_audio->composer != NULL) {
238 *composer = g_strdup(_audio->composer); /*composer can be empty string*/
239 media_content_retvm_if(*composer == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
244 ret = MEDIA_CONTENT_ERROR_NONE;
246 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
247 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
253 int audio_meta_get_year(audio_meta_h audio, char **year)
255 int ret = MEDIA_CONTENT_ERROR_NONE;
256 audio_meta_s *_audio = (audio_meta_s*)audio;
259 if (_audio->year != NULL) {
260 *year = g_strdup(_audio->year); /*year can be empty string*/
261 media_content_retvm_if(*year == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
266 ret = MEDIA_CONTENT_ERROR_NONE;
268 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
269 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
275 int audio_meta_get_recorded_date(audio_meta_h audio, char **recorded_date)
277 int ret = MEDIA_CONTENT_ERROR_NONE;
278 audio_meta_s *_audio = (audio_meta_s*)audio;
281 if (_audio->recorded_date != NULL) {
282 *recorded_date = g_strdup(_audio->recorded_date);
283 media_content_retvm_if(*recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
285 *recorded_date = NULL;
288 ret = MEDIA_CONTENT_ERROR_NONE;
290 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
291 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
297 int audio_meta_get_copyright(audio_meta_h audio, char **copyright)
299 int ret = MEDIA_CONTENT_ERROR_NONE;
300 audio_meta_s *_audio = (audio_meta_s*)audio;
303 if (_audio->copyright != NULL) {
304 *copyright = g_strdup(_audio->copyright); /*copyright can be empty string*/
305 media_content_retvm_if(*copyright == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
310 ret = MEDIA_CONTENT_ERROR_NONE;
312 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
313 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
319 int audio_meta_get_track_num(audio_meta_h audio, char **track_num)
321 int ret = MEDIA_CONTENT_ERROR_NONE;
322 audio_meta_s *_audio = (audio_meta_s*)audio;
325 if (_audio->track_num != NULL) {
326 *track_num = g_strdup(_audio->track_num); /*track_num can be empty string*/
327 media_content_retvm_if(*track_num == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
332 ret = MEDIA_CONTENT_ERROR_NONE;
334 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
335 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
341 int audio_meta_get_bit_rate(audio_meta_h audio, int *bit_rate)
343 int ret = MEDIA_CONTENT_ERROR_NONE;
344 audio_meta_s *_audio = (audio_meta_s*)audio;
346 if (_audio && bit_rate) {
347 *bit_rate = _audio->bitrate;
348 ret = MEDIA_CONTENT_ERROR_NONE;
350 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
351 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
357 int audio_meta_get_bitpersample(audio_meta_h audio, int *bitpersample)
359 int ret = MEDIA_CONTENT_ERROR_NONE;
360 audio_meta_s *_audio = (audio_meta_s*)audio;
362 if (_audio && bitpersample) {
363 *bitpersample = _audio->bitpersample;
364 ret = MEDIA_CONTENT_ERROR_NONE;
366 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
367 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
373 int audio_meta_get_sample_rate(audio_meta_h audio, int *sample_rate)
375 int ret = MEDIA_CONTENT_ERROR_NONE;
376 audio_meta_s *_audio = (audio_meta_s*)audio;
378 if (_audio && sample_rate) {
379 *sample_rate = _audio->samplerate;
380 ret = MEDIA_CONTENT_ERROR_NONE;
382 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
383 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
389 int audio_meta_get_channel(audio_meta_h audio, int *channel)
391 int ret = MEDIA_CONTENT_ERROR_NONE;
392 audio_meta_s *_audio = (audio_meta_s*)audio;
394 if (_audio && channel) {
395 *channel = _audio->channel;
396 ret = MEDIA_CONTENT_ERROR_NONE;
398 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
399 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
405 int audio_meta_get_duration(audio_meta_h audio, int *duration)
407 int ret = MEDIA_CONTENT_ERROR_NONE;
408 audio_meta_s *_audio = (audio_meta_s*)audio;
411 *duration = _audio->duration;
412 ret = MEDIA_CONTENT_ERROR_NONE;
414 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
415 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
421 int audio_meta_update_to_db(audio_meta_h audio)
423 media_content_warn("DEPRECATION WARNING: audio_meta_update_to_db() is deprecated and will be removed from next release.");
424 audio_meta_s *_audio = (audio_meta_s*)audio;
426 if (_audio == NULL) {
427 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
428 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
431 return MEDIA_CONTENT_ERROR_NONE;