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->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);
40 ret = MEDIA_CONTENT_ERROR_NONE;
44 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
45 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
51 int audio_meta_clone(audio_meta_h *dst, audio_meta_h src)
53 int ret = MEDIA_CONTENT_ERROR_NONE;
54 audio_meta_s *_src = (audio_meta_s*)src;
58 audio_meta_s *_dst = (audio_meta_s*)calloc(1, sizeof(audio_meta_s));
63 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
64 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
67 if(STRING_VALID(_src->media_id))
69 _dst->media_id = strdup(_src->media_id);
70 if(_dst->media_id == NULL)
72 audio_meta_destroy((audio_meta_h)_dst);
73 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
74 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
78 if(STRING_VALID(_src->title))
80 _dst->title = strdup(_src->title);
81 if(_dst->title == NULL)
83 audio_meta_destroy((audio_meta_h)_dst);
84 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
85 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
89 if(STRING_VALID(_src->album))
91 _dst->album = strdup(_src->album);
92 if(_dst->album == NULL)
94 audio_meta_destroy((audio_meta_h)_dst);
95 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
96 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
100 if(STRING_VALID(_src->artist))
102 _dst->artist = strdup(_src->artist);
103 if(_dst->artist == NULL)
105 audio_meta_destroy((audio_meta_h)_dst);
106 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
107 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
111 if(STRING_VALID(_src->genre))
113 _dst->genre = strdup(_src->genre);
114 if(_dst->genre == NULL)
116 audio_meta_destroy((audio_meta_h)_dst);
117 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
118 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
122 if(STRING_VALID(_src->composer))
124 _dst->composer = strdup(_src->composer);
125 if(_dst->composer == NULL)
127 audio_meta_destroy((audio_meta_h)_dst);
128 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
129 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
133 if(STRING_VALID(_src->year))
135 _dst->year = strdup(_src->year);
136 if(_dst->year == NULL)
138 audio_meta_destroy((audio_meta_h)_dst);
139 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
140 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
144 if(STRING_VALID(_src->recorded_date))
146 _dst->recorded_date = strdup(_src->recorded_date);
147 if(_dst->recorded_date == NULL)
149 audio_meta_destroy((audio_meta_h)_dst);
150 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
151 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
155 if(STRING_VALID(_src->copyright))
157 _dst->copyright = strdup(_src->copyright);
158 if(_dst->copyright == NULL)
160 audio_meta_destroy((audio_meta_h)_dst);
161 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
162 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
166 if(STRING_VALID(_src->track_num))
168 _dst->track_num = strdup(_src->track_num);
169 if(_dst->track_num == NULL)
171 audio_meta_destroy((audio_meta_h)_dst);
172 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
173 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
177 _dst->bitrate = _src->bitrate;
178 _dst->samplerate = _src->samplerate;
179 _dst->channel = _src->channel;
180 _dst->duration = _src->duration;
181 _dst->played_count = _src->played_count;
182 _dst->played_time = _src->played_time;
183 _dst->played_position = _src->played_position;
185 *dst = (audio_meta_h)_dst;
187 ret = MEDIA_CONTENT_ERROR_NONE;
191 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
192 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
198 int audio_meta_get_media_id(audio_meta_h audio, char **media_id)
200 int ret = MEDIA_CONTENT_ERROR_NONE;
201 audio_meta_s *_audio = (audio_meta_s*)audio;
204 if(STRING_VALID(_audio->media_id))
206 *media_id = strdup(_audio->media_id);
207 if(*media_id == NULL)
209 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
210 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
217 ret = MEDIA_CONTENT_ERROR_NONE;
222 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
223 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
229 int audio_meta_get_album(audio_meta_h audio, char **album_name)
231 int ret = MEDIA_CONTENT_ERROR_NONE;
232 audio_meta_s *_audio = (audio_meta_s*)audio;
235 if(STRING_VALID(_audio->album))
237 *album_name = strdup(_audio->album);
238 if(*album_name == NULL)
240 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
241 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
248 ret = MEDIA_CONTENT_ERROR_NONE;
253 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
254 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
260 int audio_meta_get_artist(audio_meta_h audio, char **artist_name)
262 int ret = MEDIA_CONTENT_ERROR_NONE;
263 audio_meta_s *_audio = (audio_meta_s*)audio;
267 if(STRING_VALID(_audio->artist))
269 *artist_name = strdup(_audio->artist);
270 if(*artist_name == NULL)
272 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
273 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
280 ret = MEDIA_CONTENT_ERROR_NONE;
285 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
286 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
292 int audio_meta_get_genre(audio_meta_h audio, char **genre_name)
294 int ret = MEDIA_CONTENT_ERROR_NONE;
295 audio_meta_s *_audio = (audio_meta_s*)audio;
298 if(STRING_VALID(_audio->genre))
300 *genre_name = strdup(_audio->genre);
301 if(*genre_name == NULL)
303 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
304 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
312 ret = MEDIA_CONTENT_ERROR_NONE;
316 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
317 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
323 int audio_meta_get_composer(audio_meta_h audio, char **composer_name)
325 int ret = MEDIA_CONTENT_ERROR_NONE;
326 audio_meta_s *_audio = (audio_meta_s*)audio;
329 if(STRING_VALID(_audio->composer))
331 *composer_name = strdup(_audio->composer);
332 if(*composer_name == NULL)
334 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
335 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
340 *composer_name = NULL;
343 ret = MEDIA_CONTENT_ERROR_NONE;
347 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
348 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
354 int audio_meta_get_year(audio_meta_h audio, char **year)
356 int ret = MEDIA_CONTENT_ERROR_NONE;
357 audio_meta_s *_audio = (audio_meta_s*)audio;
360 if(STRING_VALID(_audio->year))
362 *year = strdup(_audio->year);
365 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
366 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
374 ret = MEDIA_CONTENT_ERROR_NONE;
378 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
379 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
385 int audio_meta_get_recorded_date(audio_meta_h audio, char **recorded_date)
387 int ret = MEDIA_CONTENT_ERROR_NONE;
388 audio_meta_s *_audio = (audio_meta_s*)audio;
391 if(STRING_VALID(_audio->recorded_date))
393 *recorded_date = strdup(_audio->recorded_date);
394 if(*recorded_date == NULL)
396 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
397 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
402 *recorded_date = NULL;
405 ret = MEDIA_CONTENT_ERROR_NONE;
409 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
410 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
416 int audio_meta_get_copyright(audio_meta_h audio, char **copyright)
418 int ret = MEDIA_CONTENT_ERROR_NONE;
419 audio_meta_s *_audio = (audio_meta_s*)audio;
422 if(STRING_VALID(_audio->copyright))
424 *copyright = strdup(_audio->copyright);
425 if(*copyright == NULL)
427 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
428 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
436 ret = MEDIA_CONTENT_ERROR_NONE;
440 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
441 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
447 int audio_meta_get_track_num(audio_meta_h audio, char **track_num)
449 int ret = MEDIA_CONTENT_ERROR_NONE;
450 audio_meta_s *_audio = (audio_meta_s*)audio;
453 if(STRING_VALID(_audio->track_num))
455 *track_num = strdup(_audio->track_num);
456 if(*track_num == NULL)
458 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
459 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
467 ret = MEDIA_CONTENT_ERROR_NONE;
471 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
472 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
478 int audio_meta_get_bit_rate(audio_meta_h audio, int *bit_rate)
480 int ret = MEDIA_CONTENT_ERROR_NONE;
481 audio_meta_s *_audio = (audio_meta_s*)audio;
483 if(_audio && bit_rate)
485 *bit_rate = _audio->bitrate;
486 ret = MEDIA_CONTENT_ERROR_NONE;
490 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
491 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
497 int audio_meta_get_sample_rate(audio_meta_h audio, int *sample_rate)
499 int ret = MEDIA_CONTENT_ERROR_NONE;
500 audio_meta_s *_audio = (audio_meta_s*)audio;
502 if(_audio && sample_rate)
504 *sample_rate = _audio->samplerate;
505 ret = MEDIA_CONTENT_ERROR_NONE;
509 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
510 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
516 int audio_meta_get_channel(audio_meta_h audio, int *channel)
518 int ret = MEDIA_CONTENT_ERROR_NONE;
519 audio_meta_s *_audio = (audio_meta_s*)audio;
521 if(_audio && channel)
523 *channel = _audio->channel;
524 ret = MEDIA_CONTENT_ERROR_NONE;
528 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
529 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
535 int audio_meta_get_duration(audio_meta_h audio, int *duration)
537 int ret = MEDIA_CONTENT_ERROR_NONE;
538 audio_meta_s *_audio = (audio_meta_s*)audio;
542 *duration = _audio->duration;
543 ret = MEDIA_CONTENT_ERROR_NONE;
547 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
548 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
554 int audio_meta_get_played_count(audio_meta_h audio, int *played_count)
556 int ret = MEDIA_CONTENT_ERROR_NONE;
557 audio_meta_s *_audio = (audio_meta_s*)audio;
561 *played_count = _audio->played_count;
562 ret = MEDIA_CONTENT_ERROR_NONE;
566 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
567 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
573 int audio_meta_get_played_time(audio_meta_h audio, time_t* played_time)
575 int ret = MEDIA_CONTENT_ERROR_NONE;
576 audio_meta_s *_audio = (audio_meta_s*)audio;
580 *played_time = _audio->played_time;
581 ret = MEDIA_CONTENT_ERROR_NONE;
585 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
586 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
592 int audio_meta_get_played_position(audio_meta_h audio, int *played_position)
594 int ret = MEDIA_CONTENT_ERROR_NONE;
595 audio_meta_s *_audio = (audio_meta_s*)audio;
599 *played_position = _audio->played_position;
600 ret = MEDIA_CONTENT_ERROR_NONE;
604 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
605 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
611 int audio_meta_set_played_count(audio_meta_h audio, int played_count)
613 int ret = MEDIA_CONTENT_ERROR_NONE;
615 audio_meta_s *_audio = (audio_meta_s*)audio;
617 if((_audio != NULL) && (played_count >= 0))
619 _audio->played_count = played_count;
623 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
624 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
630 int audio_meta_set_played_time(audio_meta_h audio, time_t played_time)
632 int ret = MEDIA_CONTENT_ERROR_NONE;
634 audio_meta_s *_audio = (audio_meta_s*)audio;
636 if((_audio != NULL) && (played_time >= 0))
638 _audio->played_time = played_time;
642 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
643 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
649 int audio_meta_set_played_position(audio_meta_h audio, int played_position)
651 int ret = MEDIA_CONTENT_ERROR_NONE;
652 audio_meta_s *_audio = (audio_meta_s*)audio;
654 if((_audio != NULL) && (played_position >= 0))
656 _audio->played_position = played_position;
660 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
661 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
667 int audio_meta_update_to_db(audio_meta_h audio)
669 int ret = MEDIA_CONTENT_ERROR_NONE;
670 audio_meta_s *_audio = (audio_meta_s*)audio;
673 if(_audio != NULL && STRING_VALID(_audio->media_id))
675 sql = sqlite3_mprintf(UPDATE_AV_META_FROM_MEDIA, _audio->played_count, _audio->played_time, _audio->played_position, _audio->media_id);
676 ret = _content_query_sql(sql);
681 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
682 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;