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_content.h>
19 #include <media_info_private.h>
22 int audio_meta_destroy(audio_meta_h audio)
24 int ret = MEDIA_CONTENT_ERROR_NONE;
25 audio_meta_s *_audio = (audio_meta_s*)audio;
29 SAFE_FREE(_audio->media_id);
30 SAFE_FREE(_audio->title);
31 SAFE_FREE(_audio->album);
32 SAFE_FREE(_audio->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->genre))
114 _dst->genre = strdup(_src->genre);
115 if(_dst->genre == 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->composer))
125 _dst->composer = strdup(_src->composer);
126 if(_dst->composer == 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->year))
136 _dst->year = strdup(_src->year);
137 if(_dst->year == 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->recorded_date))
147 _dst->recorded_date = strdup(_src->recorded_date);
148 if(_dst->recorded_date == 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->copyright))
158 _dst->copyright = strdup(_src->copyright);
159 if(_dst->copyright == 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->track_num))
169 _dst->track_num = strdup(_src->track_num);
170 if(_dst->track_num == 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 _dst->bitrate = _src->bitrate;
179 _dst->samplerate = _src->samplerate;
180 _dst->channel = _src->channel;
181 _dst->duration = _src->duration;
182 _dst->played_count = _src->played_count;
183 _dst->played_time = _src->played_time;
184 _dst->played_position = _src->played_position;
186 *dst = (audio_meta_h)_dst;
188 ret = MEDIA_CONTENT_ERROR_NONE;
192 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
193 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
199 int audio_meta_get_media_id(audio_meta_h audio, char **media_id)
201 int ret = MEDIA_CONTENT_ERROR_NONE;
202 audio_meta_s *_audio = (audio_meta_s*)audio;
205 if(STRING_VALID(_audio->media_id))
207 *media_id = strdup(_audio->media_id);
208 if(*media_id == NULL)
210 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
211 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
218 ret = MEDIA_CONTENT_ERROR_NONE;
223 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
224 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
230 int audio_meta_get_title(audio_meta_h audio, char **title)
232 int ret = MEDIA_CONTENT_ERROR_NONE;
233 audio_meta_s *_audio = (audio_meta_s*)audio;
236 if(STRING_VALID(_audio->title))
238 *title = strdup(_audio->title);
241 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
242 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
249 ret = MEDIA_CONTENT_ERROR_NONE;
254 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
255 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
261 int audio_meta_get_album(audio_meta_h audio, char **album_name)
263 int ret = MEDIA_CONTENT_ERROR_NONE;
264 audio_meta_s *_audio = (audio_meta_s*)audio;
267 if(STRING_VALID(_audio->album))
269 *album_name = strdup(_audio->album);
270 if(*album_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_artist(audio_meta_h audio, char **artist_name)
294 int ret = MEDIA_CONTENT_ERROR_NONE;
295 audio_meta_s *_audio = (audio_meta_s*)audio;
299 if(STRING_VALID(_audio->artist))
301 *artist_name = strdup(_audio->artist);
302 if(*artist_name == NULL)
304 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
305 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
312 ret = MEDIA_CONTENT_ERROR_NONE;
317 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
318 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
324 int audio_meta_get_genre(audio_meta_h audio, char **genre_name)
326 int ret = MEDIA_CONTENT_ERROR_NONE;
327 audio_meta_s *_audio = (audio_meta_s*)audio;
330 if(STRING_VALID(_audio->genre))
332 *genre_name = strdup(_audio->genre);
333 if(*genre_name == NULL)
335 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
336 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
344 ret = MEDIA_CONTENT_ERROR_NONE;
348 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
349 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
355 int audio_meta_get_composer(audio_meta_h audio, char **composer_name)
357 int ret = MEDIA_CONTENT_ERROR_NONE;
358 audio_meta_s *_audio = (audio_meta_s*)audio;
361 if(STRING_VALID(_audio->composer))
363 *composer_name = strdup(_audio->composer);
364 if(*composer_name == NULL)
366 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
367 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
372 *composer_name = NULL;
375 ret = MEDIA_CONTENT_ERROR_NONE;
379 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
380 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
386 int audio_meta_get_year(audio_meta_h audio, char **year)
388 int ret = MEDIA_CONTENT_ERROR_NONE;
389 audio_meta_s *_audio = (audio_meta_s*)audio;
392 if(STRING_VALID(_audio->year))
394 *year = strdup(_audio->year);
397 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
398 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
406 ret = MEDIA_CONTENT_ERROR_NONE;
410 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
411 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
417 int audio_meta_get_recorded_date(audio_meta_h audio, char **recorded_date)
419 int ret = MEDIA_CONTENT_ERROR_NONE;
420 audio_meta_s *_audio = (audio_meta_s*)audio;
423 if(STRING_VALID(_audio->recorded_date))
425 *recorded_date = strdup(_audio->recorded_date);
426 if(*recorded_date == NULL)
428 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
429 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
434 *recorded_date = NULL;
437 ret = MEDIA_CONTENT_ERROR_NONE;
441 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
442 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
448 int audio_meta_get_copyright(audio_meta_h audio, char **copyright)
450 int ret = MEDIA_CONTENT_ERROR_NONE;
451 audio_meta_s *_audio = (audio_meta_s*)audio;
454 if(STRING_VALID(_audio->copyright))
456 *copyright = strdup(_audio->copyright);
457 if(*copyright == NULL)
459 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
460 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
468 ret = MEDIA_CONTENT_ERROR_NONE;
472 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
473 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
479 int audio_meta_get_track_num(audio_meta_h audio, char **track_num)
481 int ret = MEDIA_CONTENT_ERROR_NONE;
482 audio_meta_s *_audio = (audio_meta_s*)audio;
485 if(STRING_VALID(_audio->track_num))
487 *track_num = strdup(_audio->track_num);
488 if(*track_num == NULL)
490 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
491 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
499 ret = MEDIA_CONTENT_ERROR_NONE;
503 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
504 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
510 int audio_meta_get_bit_rate(audio_meta_h audio, int *bit_rate)
512 int ret = MEDIA_CONTENT_ERROR_NONE;
513 audio_meta_s *_audio = (audio_meta_s*)audio;
515 if(_audio && bit_rate)
517 *bit_rate = _audio->bitrate;
518 ret = MEDIA_CONTENT_ERROR_NONE;
522 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
523 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
529 int audio_meta_get_sample_rate(audio_meta_h audio, int *sample_rate)
531 int ret = MEDIA_CONTENT_ERROR_NONE;
532 audio_meta_s *_audio = (audio_meta_s*)audio;
534 if(_audio && sample_rate)
536 *sample_rate = _audio->samplerate;
537 ret = MEDIA_CONTENT_ERROR_NONE;
541 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
542 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
548 int audio_meta_get_channel(audio_meta_h audio, int *channel)
550 int ret = MEDIA_CONTENT_ERROR_NONE;
551 audio_meta_s *_audio = (audio_meta_s*)audio;
553 if(_audio && channel)
555 *channel = _audio->channel;
556 ret = MEDIA_CONTENT_ERROR_NONE;
560 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
561 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
567 int audio_meta_get_duration(audio_meta_h audio, int *duration)
569 int ret = MEDIA_CONTENT_ERROR_NONE;
570 audio_meta_s *_audio = (audio_meta_s*)audio;
574 *duration = _audio->duration;
575 ret = MEDIA_CONTENT_ERROR_NONE;
579 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
580 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
586 int audio_meta_get_played_count(audio_meta_h audio, int *played_count)
588 int ret = MEDIA_CONTENT_ERROR_NONE;
589 audio_meta_s *_audio = (audio_meta_s*)audio;
593 *played_count = _audio->played_count;
594 ret = MEDIA_CONTENT_ERROR_NONE;
598 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
599 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
605 int audio_meta_get_played_time(audio_meta_h audio, time_t* played_time)
607 int ret = MEDIA_CONTENT_ERROR_NONE;
608 audio_meta_s *_audio = (audio_meta_s*)audio;
612 *played_time = _audio->played_time;
613 ret = MEDIA_CONTENT_ERROR_NONE;
617 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
618 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
624 int audio_meta_get_played_position(audio_meta_h audio, int *played_position)
626 int ret = MEDIA_CONTENT_ERROR_NONE;
627 audio_meta_s *_audio = (audio_meta_s*)audio;
631 *played_position = _audio->played_position;
632 ret = MEDIA_CONTENT_ERROR_NONE;
636 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
637 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
643 int audio_meta_set_played_count(audio_meta_h audio, int played_count)
645 int ret = MEDIA_CONTENT_ERROR_NONE;
647 audio_meta_s *_audio = (audio_meta_s*)audio;
649 if((_audio != NULL) && (played_count >= 0))
651 _audio->played_count = played_count;
655 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
656 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
662 int audio_meta_set_played_time(audio_meta_h audio, time_t played_time)
664 int ret = MEDIA_CONTENT_ERROR_NONE;
666 audio_meta_s *_audio = (audio_meta_s*)audio;
668 if((_audio != NULL) && (played_time >= 0))
670 _audio->played_time = played_time;
674 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
675 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
681 int audio_meta_set_played_position(audio_meta_h audio, int played_position)
683 int ret = MEDIA_CONTENT_ERROR_NONE;
684 audio_meta_s *_audio = (audio_meta_s*)audio;
686 if((_audio != NULL) && (played_position >= 0))
688 _audio->played_position = played_position;
692 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
693 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
699 int audio_meta_update_to_db(audio_meta_h audio)
701 int ret = MEDIA_CONTENT_ERROR_NONE;
702 audio_meta_s *_audio = (audio_meta_s*)audio;
705 if(_audio != NULL && STRING_VALID(_audio->media_id))
707 sql = sqlite3_mprintf(UPDATE_AV_META_FROM_MEDIA, _audio->played_count, _audio->played_time, _audio->played_position, _audio->media_id);
708 ret = _content_query_sql(sql);
713 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
714 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;