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>
21 int audio_meta_destroy(audio_meta_h audio)
23 int ret = MEDIA_CONTENT_ERROR_NONE;
24 audio_meta_s *_audio = (audio_meta_s*)audio;
28 SAFE_FREE(_audio->media_id);
29 SAFE_FREE(_audio->title);
30 SAFE_FREE(_audio->album);
31 SAFE_FREE(_audio->artist);
32 SAFE_FREE(_audio->album_artist);
33 SAFE_FREE(_audio->genre);
34 SAFE_FREE(_audio->composer);
35 SAFE_FREE(_audio->year);
36 SAFE_FREE(_audio->recorded_date);
37 SAFE_FREE(_audio->copyright);
38 SAFE_FREE(_audio->track_num);
41 ret = MEDIA_CONTENT_ERROR_NONE;
45 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
46 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
52 int audio_meta_clone(audio_meta_h *dst, audio_meta_h src)
54 int ret = MEDIA_CONTENT_ERROR_NONE;
55 audio_meta_s *_src = (audio_meta_s*)src;
59 audio_meta_s *_dst = (audio_meta_s*)calloc(1, sizeof(audio_meta_s));
64 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
65 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
68 if(STRING_VALID(_src->media_id))
70 _dst->media_id = strdup(_src->media_id);
71 if(_dst->media_id == NULL)
73 audio_meta_destroy((audio_meta_h)_dst);
74 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
75 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
79 if(STRING_VALID(_src->title))
81 _dst->title = strdup(_src->title);
82 if(_dst->title == NULL)
84 audio_meta_destroy((audio_meta_h)_dst);
85 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
86 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
90 if(STRING_VALID(_src->album))
92 _dst->album = strdup(_src->album);
93 if(_dst->album == NULL)
95 audio_meta_destroy((audio_meta_h)_dst);
96 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
97 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
101 if(STRING_VALID(_src->artist))
103 _dst->artist = strdup(_src->artist);
104 if(_dst->artist == 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;
112 if(STRING_VALID(_src->album_artist))
114 _dst->album_artist = strdup(_src->album_artist);
115 if(_dst->album_artist == NULL)
117 audio_meta_destroy((audio_meta_h)_dst);
118 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
119 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
123 if(STRING_VALID(_src->genre))
125 _dst->genre = strdup(_src->genre);
126 if(_dst->genre == NULL)
128 audio_meta_destroy((audio_meta_h)_dst);
129 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
130 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
134 if(STRING_VALID(_src->composer))
136 _dst->composer = strdup(_src->composer);
137 if(_dst->composer == NULL)
139 audio_meta_destroy((audio_meta_h)_dst);
140 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
141 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
145 if(STRING_VALID(_src->year))
147 _dst->year = strdup(_src->year);
148 if(_dst->year == NULL)
150 audio_meta_destroy((audio_meta_h)_dst);
151 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
152 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
156 if(STRING_VALID(_src->recorded_date))
158 _dst->recorded_date = strdup(_src->recorded_date);
159 if(_dst->recorded_date == NULL)
161 audio_meta_destroy((audio_meta_h)_dst);
162 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
163 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
167 if(STRING_VALID(_src->copyright))
169 _dst->copyright = strdup(_src->copyright);
170 if(_dst->copyright == NULL)
172 audio_meta_destroy((audio_meta_h)_dst);
173 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
174 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
178 if(STRING_VALID(_src->track_num))
180 _dst->track_num = strdup(_src->track_num);
181 if(_dst->track_num == NULL)
183 audio_meta_destroy((audio_meta_h)_dst);
184 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
185 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
189 _dst->bitrate = _src->bitrate;
190 _dst->bitpersample = _src->bitpersample;
191 _dst->samplerate = _src->samplerate;
192 _dst->channel = _src->channel;
193 _dst->duration = _src->duration;
194 _dst->played_count = _src->played_count;
195 _dst->played_time = _src->played_time;
196 _dst->played_position = _src->played_position;
198 *dst = (audio_meta_h)_dst;
200 ret = MEDIA_CONTENT_ERROR_NONE;
204 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
205 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
211 int audio_meta_get_media_id(audio_meta_h audio, char **media_id)
213 int ret = MEDIA_CONTENT_ERROR_NONE;
214 audio_meta_s *_audio = (audio_meta_s*)audio;
217 if(STRING_VALID(_audio->media_id))
219 *media_id = strdup(_audio->media_id);
220 if(*media_id == NULL)
222 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
223 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
230 ret = MEDIA_CONTENT_ERROR_NONE;
235 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
236 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
242 int audio_meta_get_album(audio_meta_h audio, char **album_name)
244 int ret = MEDIA_CONTENT_ERROR_NONE;
245 audio_meta_s *_audio = (audio_meta_s*)audio;
248 if(STRING_VALID(_audio->album))
250 *album_name = strdup(_audio->album);
251 if(*album_name == NULL)
253 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
254 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
261 ret = MEDIA_CONTENT_ERROR_NONE;
266 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
267 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
273 int audio_meta_get_artist(audio_meta_h audio, char **artist_name)
275 int ret = MEDIA_CONTENT_ERROR_NONE;
276 audio_meta_s *_audio = (audio_meta_s*)audio;
280 if(STRING_VALID(_audio->artist))
282 *artist_name = strdup(_audio->artist);
283 if(*artist_name == NULL)
285 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
286 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
293 ret = MEDIA_CONTENT_ERROR_NONE;
298 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
299 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
305 int audio_meta_get_album_artist(audio_meta_h audio, char **album_artist_name)
307 int ret = MEDIA_CONTENT_ERROR_NONE;
308 audio_meta_s *_audio = (audio_meta_s*)audio;
312 if(STRING_VALID(_audio->album_artist))
314 *album_artist_name = strdup(_audio->album_artist);
315 if(*album_artist_name == NULL)
317 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
318 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
323 *album_artist_name = NULL;
325 ret = MEDIA_CONTENT_ERROR_NONE;
330 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
331 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
337 int audio_meta_get_genre(audio_meta_h audio, char **genre_name)
339 int ret = MEDIA_CONTENT_ERROR_NONE;
340 audio_meta_s *_audio = (audio_meta_s*)audio;
343 if(STRING_VALID(_audio->genre))
345 *genre_name = strdup(_audio->genre);
346 if(*genre_name == NULL)
348 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
349 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
357 ret = MEDIA_CONTENT_ERROR_NONE;
361 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
362 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
368 int audio_meta_get_composer(audio_meta_h audio, char **composer_name)
370 int ret = MEDIA_CONTENT_ERROR_NONE;
371 audio_meta_s *_audio = (audio_meta_s*)audio;
374 if(STRING_VALID(_audio->composer))
376 *composer_name = strdup(_audio->composer);
377 if(*composer_name == NULL)
379 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
380 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
385 *composer_name = NULL;
388 ret = MEDIA_CONTENT_ERROR_NONE;
392 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
393 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
399 int audio_meta_get_year(audio_meta_h audio, char **year)
401 int ret = MEDIA_CONTENT_ERROR_NONE;
402 audio_meta_s *_audio = (audio_meta_s*)audio;
405 if(STRING_VALID(_audio->year))
407 *year = strdup(_audio->year);
410 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
411 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
419 ret = MEDIA_CONTENT_ERROR_NONE;
423 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
424 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
430 int audio_meta_get_recorded_date(audio_meta_h audio, char **recorded_date)
432 int ret = MEDIA_CONTENT_ERROR_NONE;
433 audio_meta_s *_audio = (audio_meta_s*)audio;
436 if(STRING_VALID(_audio->recorded_date))
438 *recorded_date = strdup(_audio->recorded_date);
439 if(*recorded_date == NULL)
441 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
442 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
447 *recorded_date = NULL;
450 ret = MEDIA_CONTENT_ERROR_NONE;
454 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
455 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
461 int audio_meta_get_copyright(audio_meta_h audio, char **copyright)
463 int ret = MEDIA_CONTENT_ERROR_NONE;
464 audio_meta_s *_audio = (audio_meta_s*)audio;
467 if(STRING_VALID(_audio->copyright))
469 *copyright = strdup(_audio->copyright);
470 if(*copyright == NULL)
472 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
473 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
481 ret = MEDIA_CONTENT_ERROR_NONE;
485 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
486 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
492 int audio_meta_get_track_num(audio_meta_h audio, char **track_num)
494 int ret = MEDIA_CONTENT_ERROR_NONE;
495 audio_meta_s *_audio = (audio_meta_s*)audio;
498 if(STRING_VALID(_audio->track_num))
500 *track_num = strdup(_audio->track_num);
501 if(*track_num == NULL)
503 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
504 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
512 ret = MEDIA_CONTENT_ERROR_NONE;
516 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
517 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
523 int audio_meta_get_bit_rate(audio_meta_h audio, int *bit_rate)
525 int ret = MEDIA_CONTENT_ERROR_NONE;
526 audio_meta_s *_audio = (audio_meta_s*)audio;
528 if(_audio && bit_rate)
530 *bit_rate = _audio->bitrate;
531 ret = MEDIA_CONTENT_ERROR_NONE;
535 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
536 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
542 int audio_meta_get_bitpersample(audio_meta_h audio, int *bitpersample)
544 int ret = MEDIA_CONTENT_ERROR_NONE;
545 audio_meta_s *_audio = (audio_meta_s*)audio;
547 if(_audio && bitpersample)
549 *bitpersample = _audio->bitpersample;
550 ret = MEDIA_CONTENT_ERROR_NONE;
554 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
555 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
561 int audio_meta_get_sample_rate(audio_meta_h audio, int *sample_rate)
563 int ret = MEDIA_CONTENT_ERROR_NONE;
564 audio_meta_s *_audio = (audio_meta_s*)audio;
566 if(_audio && sample_rate)
568 *sample_rate = _audio->samplerate;
569 ret = MEDIA_CONTENT_ERROR_NONE;
573 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
574 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
580 int audio_meta_get_channel(audio_meta_h audio, int *channel)
582 int ret = MEDIA_CONTENT_ERROR_NONE;
583 audio_meta_s *_audio = (audio_meta_s*)audio;
585 if(_audio && channel)
587 *channel = _audio->channel;
588 ret = MEDIA_CONTENT_ERROR_NONE;
592 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
593 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
599 int audio_meta_get_duration(audio_meta_h audio, int *duration)
601 int ret = MEDIA_CONTENT_ERROR_NONE;
602 audio_meta_s *_audio = (audio_meta_s*)audio;
606 *duration = _audio->duration;
607 ret = MEDIA_CONTENT_ERROR_NONE;
611 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
612 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
618 int audio_meta_get_played_count(audio_meta_h audio, int *played_count)
620 int ret = MEDIA_CONTENT_ERROR_NONE;
621 audio_meta_s *_audio = (audio_meta_s*)audio;
625 *played_count = _audio->played_count;
626 ret = MEDIA_CONTENT_ERROR_NONE;
630 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
631 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
637 int audio_meta_get_played_time(audio_meta_h audio, time_t* played_time)
639 int ret = MEDIA_CONTENT_ERROR_NONE;
640 audio_meta_s *_audio = (audio_meta_s*)audio;
644 *played_time = _audio->played_time;
645 ret = MEDIA_CONTENT_ERROR_NONE;
649 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
650 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
656 int audio_meta_get_played_position(audio_meta_h audio, int *played_position)
658 int ret = MEDIA_CONTENT_ERROR_NONE;
659 audio_meta_s *_audio = (audio_meta_s*)audio;
663 *played_position = _audio->played_position;
664 ret = MEDIA_CONTENT_ERROR_NONE;
668 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
669 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
675 int audio_meta_set_played_count(audio_meta_h audio, int played_count)
677 int ret = MEDIA_CONTENT_ERROR_NONE;
679 audio_meta_s *_audio = (audio_meta_s*)audio;
681 if((_audio != NULL) && (played_count >= 0))
683 _audio->played_count = played_count;
687 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
688 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
694 int audio_meta_set_played_time(audio_meta_h audio, time_t played_time)
696 int ret = MEDIA_CONTENT_ERROR_NONE;
698 audio_meta_s *_audio = (audio_meta_s*)audio;
700 if((_audio != NULL) && (played_time >= 0))
702 _audio->played_time = played_time;
706 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
707 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
713 int audio_meta_set_played_position(audio_meta_h audio, int played_position)
715 int ret = MEDIA_CONTENT_ERROR_NONE;
716 audio_meta_s *_audio = (audio_meta_s*)audio;
718 if((_audio != NULL) && (played_position >= 0))
720 _audio->played_position = played_position;
724 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
725 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
731 int audio_meta_update_to_db(audio_meta_h audio)
733 int ret = MEDIA_CONTENT_ERROR_NONE;
734 audio_meta_s *_audio = (audio_meta_s*)audio;
737 if(_audio != NULL && STRING_VALID(_audio->media_id))
739 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,};
740 memset(storage_id, 0x00, sizeof(storage_id));
742 ret = _media_db_get_storage_id_by_media_id(_audio->media_id, storage_id);
743 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
745 sql = sqlite3_mprintf(UPDATE_AV_META_FROM_MEDIA, storage_id, _audio->played_count, _audio->played_time, _audio->played_position, _audio->media_id);
746 ret = _content_query_sql(sql);
751 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
752 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;