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;
27 SAFE_FREE(_audio->media_id);
28 SAFE_FREE(_audio->title);
29 SAFE_FREE(_audio->album);
30 SAFE_FREE(_audio->artist);
31 SAFE_FREE(_audio->album_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;
42 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
43 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
49 int audio_meta_clone(audio_meta_h *dst, audio_meta_h src)
51 int ret = MEDIA_CONTENT_ERROR_NONE;
52 audio_meta_s *_src = (audio_meta_s*)src;
55 audio_meta_s *_dst = (audio_meta_s*)calloc(1, sizeof(audio_meta_s));
56 media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
58 if (_src->media_id != NULL) {
59 _dst->media_id = g_strdup(_src->media_id);
60 if (_dst->media_id == NULL) {
61 audio_meta_destroy((audio_meta_h)_dst);
62 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
63 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
67 if (_src->title != NULL) {
68 _dst->title = g_strdup(_src->title);
69 if (_dst->title == NULL) {
70 audio_meta_destroy((audio_meta_h)_dst);
71 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
72 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
76 if (_src->album != NULL) {
77 _dst->album = g_strdup(_src->album);
78 if (_dst->album == NULL) {
79 audio_meta_destroy((audio_meta_h)_dst);
80 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
81 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
85 if (_src->artist != NULL) {
86 _dst->artist = g_strdup(_src->artist);
87 if (_dst->artist == NULL) {
88 audio_meta_destroy((audio_meta_h)_dst);
89 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
90 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
94 if (_src->album_artist != NULL) {
95 _dst->album_artist = g_strdup(_src->album_artist);
96 if (_dst->album_artist == NULL) {
97 audio_meta_destroy((audio_meta_h)_dst);
98 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
99 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
103 if (_src->genre != NULL) {
104 _dst->genre = g_strdup(_src->genre);
105 if (_dst->genre == 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 (_src->composer != NULL) {
113 _dst->composer = g_strdup(_src->composer);
114 if (_dst->composer == NULL) {
115 audio_meta_destroy((audio_meta_h)_dst);
116 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
117 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
121 if (_src->year != NULL) {
122 _dst->year = g_strdup(_src->year);
123 if (_dst->year == NULL) {
124 audio_meta_destroy((audio_meta_h)_dst);
125 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
126 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
130 if (_src->recorded_date != NULL) {
131 _dst->recorded_date = g_strdup(_src->recorded_date);
132 if (_dst->recorded_date == 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 (_src->copyright != NULL) {
140 _dst->copyright = g_strdup(_src->copyright);
141 if (_dst->copyright == NULL) {
142 audio_meta_destroy((audio_meta_h)_dst);
143 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
144 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
148 if (_src->track_num != NULL) {
149 _dst->track_num = g_strdup(_src->track_num);
150 if (_dst->track_num == NULL) {
151 audio_meta_destroy((audio_meta_h)_dst);
152 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
153 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
157 _dst->bitrate = _src->bitrate;
158 _dst->bitpersample = _src->bitpersample;
159 _dst->samplerate = _src->samplerate;
160 _dst->channel = _src->channel;
161 _dst->duration = _src->duration;
162 _dst->played_count = _src->played_count;
163 _dst->played_time = _src->played_time;
164 _dst->played_position = _src->played_position;
166 *dst = (audio_meta_h)_dst;
168 ret = MEDIA_CONTENT_ERROR_NONE;
170 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
171 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
177 int audio_meta_get_media_id(audio_meta_h audio, char **media_id)
179 int ret = MEDIA_CONTENT_ERROR_NONE;
180 audio_meta_s *_audio = (audio_meta_s*)audio;
182 if (STRING_VALID(_audio->media_id)) {
183 *media_id = strdup(_audio->media_id);
184 media_content_retvm_if(*media_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
188 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_album(audio_meta_h audio, char **album)
200 int ret = MEDIA_CONTENT_ERROR_NONE;
201 audio_meta_s *_audio = (audio_meta_s*)audio;
203 if (_audio->album != NULL) {
204 *album = g_strdup(_audio->album); /*album can be empty string*/
205 media_content_retvm_if(*album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
209 ret = MEDIA_CONTENT_ERROR_NONE;
212 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
213 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
219 int audio_meta_get_artist(audio_meta_h audio, char **artist)
221 int ret = MEDIA_CONTENT_ERROR_NONE;
222 audio_meta_s *_audio = (audio_meta_s*)audio;
225 if (_audio->artist != NULL) {
226 *artist = g_strdup(_audio->artist); /*artist can be empty string*/
227 media_content_retvm_if(*artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
231 ret = MEDIA_CONTENT_ERROR_NONE;
234 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
235 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
241 int audio_meta_get_album_artist(audio_meta_h audio, char **album_artist)
243 int ret = MEDIA_CONTENT_ERROR_NONE;
244 audio_meta_s *_audio = (audio_meta_s*)audio;
247 if (_audio->album_artist != NULL) {
248 *album_artist = g_strdup(_audio->album_artist); /*album_artist can be empty string*/
249 media_content_retvm_if(*album_artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
251 *album_artist = NULL;
253 ret = MEDIA_CONTENT_ERROR_NONE;
256 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
257 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
263 int audio_meta_get_genre(audio_meta_h audio, char **genre)
265 int ret = MEDIA_CONTENT_ERROR_NONE;
266 audio_meta_s *_audio = (audio_meta_s*)audio;
269 if (_audio->genre != NULL) {
270 *genre = g_strdup(_audio->genre); /*genre can be empty string*/
271 media_content_retvm_if(*genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
276 ret = MEDIA_CONTENT_ERROR_NONE;
278 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
279 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
285 int audio_meta_get_composer(audio_meta_h audio, char **composer)
287 int ret = MEDIA_CONTENT_ERROR_NONE;
288 audio_meta_s *_audio = (audio_meta_s*)audio;
291 if (_audio->composer != NULL) {
292 *composer = g_strdup(_audio->composer); /*composer can be empty string*/
293 media_content_retvm_if(*composer == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
298 ret = MEDIA_CONTENT_ERROR_NONE;
300 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
301 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
307 int audio_meta_get_year(audio_meta_h audio, char **year)
309 int ret = MEDIA_CONTENT_ERROR_NONE;
310 audio_meta_s *_audio = (audio_meta_s*)audio;
313 if (_audio->year != NULL) {
314 *year = g_strdup(_audio->year); /*year can be empty string*/
315 media_content_retvm_if(*year == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
320 ret = MEDIA_CONTENT_ERROR_NONE;
322 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
323 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
329 int audio_meta_get_recorded_date(audio_meta_h audio, char **recorded_date)
331 int ret = MEDIA_CONTENT_ERROR_NONE;
332 audio_meta_s *_audio = (audio_meta_s*)audio;
335 if (_audio->recorded_date != NULL) {
336 *recorded_date = g_strdup(_audio->recorded_date);
337 media_content_retvm_if(*recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
339 *recorded_date = NULL;
342 ret = MEDIA_CONTENT_ERROR_NONE;
344 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
345 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
351 int audio_meta_get_copyright(audio_meta_h audio, char **copyright)
353 int ret = MEDIA_CONTENT_ERROR_NONE;
354 audio_meta_s *_audio = (audio_meta_s*)audio;
357 if (_audio->copyright != NULL) {
358 *copyright = g_strdup(_audio->copyright); /*copyright can be empty string*/
359 media_content_retvm_if(*copyright == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
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_track_num(audio_meta_h audio, char **track_num)
375 int ret = MEDIA_CONTENT_ERROR_NONE;
376 audio_meta_s *_audio = (audio_meta_s*)audio;
379 if (_audio->track_num != NULL) {
380 *track_num = g_strdup(_audio->track_num); /*track_num can be empty string*/
381 media_content_retvm_if(*track_num == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
386 ret = MEDIA_CONTENT_ERROR_NONE;
388 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
389 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
395 int audio_meta_get_bit_rate(audio_meta_h audio, int *bit_rate)
397 int ret = MEDIA_CONTENT_ERROR_NONE;
398 audio_meta_s *_audio = (audio_meta_s*)audio;
400 if (_audio && bit_rate) {
401 *bit_rate = _audio->bitrate;
402 ret = MEDIA_CONTENT_ERROR_NONE;
404 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
405 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
411 int audio_meta_get_bitpersample(audio_meta_h audio, int *bitpersample)
413 int ret = MEDIA_CONTENT_ERROR_NONE;
414 audio_meta_s *_audio = (audio_meta_s*)audio;
416 if (_audio && bitpersample) {
417 *bitpersample = _audio->bitpersample;
418 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_sample_rate(audio_meta_h audio, int *sample_rate)
429 int ret = MEDIA_CONTENT_ERROR_NONE;
430 audio_meta_s *_audio = (audio_meta_s*)audio;
432 if (_audio && sample_rate) {
433 *sample_rate = _audio->samplerate;
434 ret = MEDIA_CONTENT_ERROR_NONE;
436 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
437 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
443 int audio_meta_get_channel(audio_meta_h audio, int *channel)
445 int ret = MEDIA_CONTENT_ERROR_NONE;
446 audio_meta_s *_audio = (audio_meta_s*)audio;
448 if (_audio && channel) {
449 *channel = _audio->channel;
450 ret = MEDIA_CONTENT_ERROR_NONE;
452 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
453 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
459 int audio_meta_get_duration(audio_meta_h audio, int *duration)
461 int ret = MEDIA_CONTENT_ERROR_NONE;
462 audio_meta_s *_audio = (audio_meta_s*)audio;
465 *duration = _audio->duration;
466 ret = MEDIA_CONTENT_ERROR_NONE;
468 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
469 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
475 int audio_meta_get_played_count(audio_meta_h audio, int *played_count)
477 int ret = MEDIA_CONTENT_ERROR_NONE;
478 media_content_warn("DEPRECATION WARNING: audio_meta_get_played_count() is deprecated and will be removed from next release. Use media_info_get_played_count() instead.");
479 audio_meta_s *_audio = (audio_meta_s*)audio;
481 if (_audio && played_count) {
482 *played_count = _audio->played_count;
483 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_played_time(audio_meta_h audio, time_t* played_time)
494 int ret = MEDIA_CONTENT_ERROR_NONE;
495 media_content_warn("DEPRECATION WARNING: audio_meta_get_played_time() is deprecated and will be removed from next release. Use media_info_get_played_time() instead.");
496 audio_meta_s *_audio = (audio_meta_s*)audio;
499 *played_time = _audio->played_time;
500 ret = MEDIA_CONTENT_ERROR_NONE;
502 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
503 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
509 int audio_meta_get_played_position(audio_meta_h audio, int *played_position)
511 int ret = MEDIA_CONTENT_ERROR_NONE;
512 media_content_warn("DEPRECATION WARNING: audio_meta_get_played_position() is deprecated and will be removed from next release.");
513 audio_meta_s *_audio = (audio_meta_s*)audio;
516 *played_position = _audio->played_position;
517 ret = MEDIA_CONTENT_ERROR_NONE;
519 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
520 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
526 int audio_meta_set_played_count(audio_meta_h audio, int played_count)
528 int ret = MEDIA_CONTENT_ERROR_NONE;
529 media_content_warn("DEPRECATION WARNING: audio_meta_set_played_count() is deprecated and will be removed from next release. Use media_info_increase_played_count() instead.");
530 audio_meta_s *_audio = (audio_meta_s*)audio;
532 if ((_audio != NULL) && (played_count >= 0)) {
533 _audio->played_count = played_count;
535 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
536 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
542 int audio_meta_set_played_time(audio_meta_h audio, time_t played_time)
544 int ret = MEDIA_CONTENT_ERROR_NONE;
545 media_content_warn("DEPRECATION WARNING: audio_meta_set_played_time() is deprecated and will be removed from next release. Use media_info_set_played_time() instead.");
546 audio_meta_s *_audio = (audio_meta_s*)audio;
548 if ((_audio != NULL) && (played_time >= 0)) {
549 _audio->played_time = played_time;
551 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
552 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
558 int audio_meta_set_played_position(audio_meta_h audio, int played_position)
560 int ret = MEDIA_CONTENT_ERROR_NONE;
561 media_content_warn("DEPRECATION WARNING: audio_meta_set_played_position() is deprecated and will be removed from next release.");
562 audio_meta_s *_audio = (audio_meta_s*)audio;
564 if ((_audio != NULL) && (played_position >= 0)) {
565 _audio->played_position = played_position;
567 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
568 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
574 int audio_meta_update_to_db(audio_meta_h audio)
576 int ret = MEDIA_CONTENT_ERROR_NONE;
577 audio_meta_s *_audio = (audio_meta_s*)audio;
580 if (_audio != NULL && STRING_VALID(_audio->media_id)) {
581 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
582 memset(storage_id, 0x00, sizeof(storage_id));
584 ret = _media_db_get_storage_id_by_media_id(_audio->media_id, storage_id);
585 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
587 sql = sqlite3_mprintf(UPDATE_AV_META_FROM_MEDIA, storage_id, _audio->played_count, _audio->played_time, _audio->played_position, _audio->media_id);
588 ret = _content_query_sql(sql);
589 SQLITE3_SAFE_FREE(sql);
591 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
592 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;