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));
60 media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
62 if(STRING_VALID(_src->media_id))
64 _dst->media_id = strdup(_src->media_id);
65 if(_dst->media_id == NULL)
67 audio_meta_destroy((audio_meta_h)_dst);
68 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
69 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
73 if(STRING_VALID(_src->title))
75 _dst->title = strdup(_src->title);
76 if(_dst->title == NULL)
78 audio_meta_destroy((audio_meta_h)_dst);
79 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
80 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
84 if(STRING_VALID(_src->album))
86 _dst->album = strdup(_src->album);
87 if(_dst->album == NULL)
89 audio_meta_destroy((audio_meta_h)_dst);
90 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
91 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
95 if(STRING_VALID(_src->artist))
97 _dst->artist = strdup(_src->artist);
98 if(_dst->artist == NULL)
100 audio_meta_destroy((audio_meta_h)_dst);
101 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
102 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
106 if(STRING_VALID(_src->album_artist))
108 _dst->album_artist = strdup(_src->album_artist);
109 if(_dst->album_artist == NULL)
111 audio_meta_destroy((audio_meta_h)_dst);
112 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
113 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
117 if(STRING_VALID(_src->genre))
119 _dst->genre = strdup(_src->genre);
120 if(_dst->genre == NULL)
122 audio_meta_destroy((audio_meta_h)_dst);
123 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
124 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
128 if(STRING_VALID(_src->composer))
130 _dst->composer = strdup(_src->composer);
131 if(_dst->composer == 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;
139 if(STRING_VALID(_src->year))
141 _dst->year = strdup(_src->year);
142 if(_dst->year == NULL)
144 audio_meta_destroy((audio_meta_h)_dst);
145 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
146 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
150 if(STRING_VALID(_src->recorded_date))
152 _dst->recorded_date = strdup(_src->recorded_date);
153 if(_dst->recorded_date == NULL)
155 audio_meta_destroy((audio_meta_h)_dst);
156 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
157 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
161 if(STRING_VALID(_src->copyright))
163 _dst->copyright = strdup(_src->copyright);
164 if(_dst->copyright == NULL)
166 audio_meta_destroy((audio_meta_h)_dst);
167 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
168 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
172 if(STRING_VALID(_src->track_num))
174 _dst->track_num = strdup(_src->track_num);
175 if(_dst->track_num == NULL)
177 audio_meta_destroy((audio_meta_h)_dst);
178 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
179 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
183 _dst->bitrate = _src->bitrate;
184 _dst->bitpersample = _src->bitpersample;
185 _dst->samplerate = _src->samplerate;
186 _dst->channel = _src->channel;
187 _dst->duration = _src->duration;
188 _dst->played_count = _src->played_count;
189 _dst->played_time = _src->played_time;
190 _dst->played_position = _src->played_position;
192 *dst = (audio_meta_h)_dst;
194 ret = MEDIA_CONTENT_ERROR_NONE;
198 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
199 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
205 int audio_meta_get_media_id(audio_meta_h audio, char **media_id)
207 int ret = MEDIA_CONTENT_ERROR_NONE;
208 audio_meta_s *_audio = (audio_meta_s*)audio;
211 if(STRING_VALID(_audio->media_id))
213 *media_id = strdup(_audio->media_id);
214 media_content_retvm_if(*media_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
220 ret = MEDIA_CONTENT_ERROR_NONE;
225 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
226 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
232 int audio_meta_get_album(audio_meta_h audio, char **album)
234 int ret = MEDIA_CONTENT_ERROR_NONE;
235 audio_meta_s *_audio = (audio_meta_s*)audio;
238 if(STRING_VALID(_audio->album))
240 *album = strdup(_audio->album);
241 media_content_retvm_if(*album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
247 ret = MEDIA_CONTENT_ERROR_NONE;
252 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
253 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
259 int audio_meta_get_artist(audio_meta_h audio, char **artist)
261 int ret = MEDIA_CONTENT_ERROR_NONE;
262 audio_meta_s *_audio = (audio_meta_s*)audio;
266 if(STRING_VALID(_audio->artist))
268 *artist = strdup(_audio->artist);
269 media_content_retvm_if(*artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
275 ret = MEDIA_CONTENT_ERROR_NONE;
280 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
281 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
287 int audio_meta_get_album_artist(audio_meta_h audio, char **album_artist)
289 int ret = MEDIA_CONTENT_ERROR_NONE;
290 audio_meta_s *_audio = (audio_meta_s*)audio;
294 if(STRING_VALID(_audio->album_artist))
296 *album_artist = strdup(_audio->album_artist);
297 media_content_retvm_if(*album_artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
301 *album_artist = NULL;
303 ret = MEDIA_CONTENT_ERROR_NONE;
308 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
309 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
315 int audio_meta_get_genre(audio_meta_h audio, char **genre)
317 int ret = MEDIA_CONTENT_ERROR_NONE;
318 audio_meta_s *_audio = (audio_meta_s*)audio;
322 if(STRING_VALID(_audio->genre))
324 *genre = strdup(_audio->genre);
325 media_content_retvm_if(*genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
332 ret = MEDIA_CONTENT_ERROR_NONE;
336 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
337 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
343 int audio_meta_get_composer(audio_meta_h audio, char **composer)
345 int ret = MEDIA_CONTENT_ERROR_NONE;
346 audio_meta_s *_audio = (audio_meta_s*)audio;
350 if(STRING_VALID(_audio->composer))
352 *composer = strdup(_audio->composer);
353 media_content_retvm_if(*composer == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
360 ret = MEDIA_CONTENT_ERROR_NONE;
364 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
365 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
371 int audio_meta_get_year(audio_meta_h audio, char **year)
373 int ret = MEDIA_CONTENT_ERROR_NONE;
374 audio_meta_s *_audio = (audio_meta_s*)audio;
378 if(STRING_VALID(_audio->year))
380 *year = strdup(_audio->year);
381 media_content_retvm_if(*year == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
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_recorded_date(audio_meta_h audio, char **recorded_date)
401 int ret = MEDIA_CONTENT_ERROR_NONE;
402 audio_meta_s *_audio = (audio_meta_s*)audio;
406 if(STRING_VALID(_audio->recorded_date))
408 *recorded_date = strdup(_audio->recorded_date);
409 media_content_retvm_if(*recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
413 *recorded_date = NULL;
416 ret = MEDIA_CONTENT_ERROR_NONE;
420 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
421 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
427 int audio_meta_get_copyright(audio_meta_h audio, char **copyright)
429 int ret = MEDIA_CONTENT_ERROR_NONE;
430 audio_meta_s *_audio = (audio_meta_s*)audio;
434 if(STRING_VALID(_audio->copyright))
436 *copyright = strdup(_audio->copyright);
437 media_content_retvm_if(*copyright == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
444 ret = MEDIA_CONTENT_ERROR_NONE;
448 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
449 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
455 int audio_meta_get_track_num(audio_meta_h audio, char **track_num)
457 int ret = MEDIA_CONTENT_ERROR_NONE;
458 audio_meta_s *_audio = (audio_meta_s*)audio;
462 if(STRING_VALID(_audio->track_num))
464 *track_num = strdup(_audio->track_num);
465 media_content_retvm_if(*track_num == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
472 ret = MEDIA_CONTENT_ERROR_NONE;
476 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
477 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
483 int audio_meta_get_bit_rate(audio_meta_h audio, int *bit_rate)
485 int ret = MEDIA_CONTENT_ERROR_NONE;
486 audio_meta_s *_audio = (audio_meta_s*)audio;
488 if(_audio && bit_rate)
490 *bit_rate = _audio->bitrate;
491 ret = MEDIA_CONTENT_ERROR_NONE;
495 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
496 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
502 int audio_meta_get_bitpersample(audio_meta_h audio, int *bitpersample)
504 int ret = MEDIA_CONTENT_ERROR_NONE;
505 audio_meta_s *_audio = (audio_meta_s*)audio;
507 if(_audio && bitpersample)
509 *bitpersample = _audio->bitpersample;
510 ret = MEDIA_CONTENT_ERROR_NONE;
514 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
515 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
521 int audio_meta_get_sample_rate(audio_meta_h audio, int *sample_rate)
523 int ret = MEDIA_CONTENT_ERROR_NONE;
524 audio_meta_s *_audio = (audio_meta_s*)audio;
526 if(_audio && sample_rate)
528 *sample_rate = _audio->samplerate;
529 ret = MEDIA_CONTENT_ERROR_NONE;
533 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
534 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
540 int audio_meta_get_channel(audio_meta_h audio, int *channel)
542 int ret = MEDIA_CONTENT_ERROR_NONE;
543 audio_meta_s *_audio = (audio_meta_s*)audio;
545 if(_audio && channel)
547 *channel = _audio->channel;
548 ret = MEDIA_CONTENT_ERROR_NONE;
552 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
553 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
559 int audio_meta_get_duration(audio_meta_h audio, int *duration)
561 int ret = MEDIA_CONTENT_ERROR_NONE;
562 audio_meta_s *_audio = (audio_meta_s*)audio;
566 *duration = _audio->duration;
567 ret = MEDIA_CONTENT_ERROR_NONE;
571 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
572 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
578 int audio_meta_get_played_count(audio_meta_h audio, int *played_count)
580 int ret = MEDIA_CONTENT_ERROR_NONE;
581 audio_meta_s *_audio = (audio_meta_s*)audio;
583 if(_audio && played_count)
585 *played_count = _audio->played_count;
586 ret = MEDIA_CONTENT_ERROR_NONE;
590 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
591 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
597 int audio_meta_get_played_time(audio_meta_h audio, time_t* played_time)
599 int ret = MEDIA_CONTENT_ERROR_NONE;
600 audio_meta_s *_audio = (audio_meta_s*)audio;
604 *played_time = _audio->played_time;
605 ret = MEDIA_CONTENT_ERROR_NONE;
609 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
610 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
616 int audio_meta_get_played_position(audio_meta_h audio, int *played_position)
618 int ret = MEDIA_CONTENT_ERROR_NONE;
619 audio_meta_s *_audio = (audio_meta_s*)audio;
623 *played_position = _audio->played_position;
624 ret = MEDIA_CONTENT_ERROR_NONE;
628 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
629 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
635 int audio_meta_set_played_count(audio_meta_h audio, int played_count)
637 int ret = MEDIA_CONTENT_ERROR_NONE;
638 audio_meta_s *_audio = (audio_meta_s*)audio;
640 if((_audio != NULL) && (played_count >= 0))
642 _audio->played_count = played_count;
646 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
647 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
653 int audio_meta_set_played_time(audio_meta_h audio, time_t played_time)
655 int ret = MEDIA_CONTENT_ERROR_NONE;
656 audio_meta_s *_audio = (audio_meta_s*)audio;
658 if((_audio != NULL) && (played_time >= 0))
660 _audio->played_time = played_time;
664 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
665 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
671 int audio_meta_set_played_position(audio_meta_h audio, int played_position)
673 int ret = MEDIA_CONTENT_ERROR_NONE;
674 audio_meta_s *_audio = (audio_meta_s*)audio;
676 if((_audio != NULL) && (played_position >= 0))
678 _audio->played_position = played_position;
682 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
683 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
689 int audio_meta_update_to_db(audio_meta_h audio)
691 int ret = MEDIA_CONTENT_ERROR_NONE;
692 audio_meta_s *_audio = (audio_meta_s*)audio;
695 if(_audio != NULL && STRING_VALID(_audio->media_id))
697 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
698 memset(storage_id, 0x00, sizeof(storage_id));
700 ret = _media_db_get_storage_id_by_media_id(_audio->media_id, storage_id);
701 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
703 sql = sqlite3_mprintf(UPDATE_AV_META_FROM_MEDIA, storage_id, _audio->played_count, _audio->played_time, _audio->played_position, _audio->media_id);
704 ret = _content_query_sql(sql);
705 SQLITE3_SAFE_FREE(sql);
709 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
710 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;