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 video_meta_destroy(video_meta_h video)
23 int ret = MEDIA_CONTENT_ERROR_NONE;
24 video_meta_s *_video = (video_meta_s*)video;
28 SAFE_FREE(_video->media_id);
29 SAFE_FREE(_video->title);
30 SAFE_FREE(_video->album);
31 SAFE_FREE(_video->artist);
32 SAFE_FREE(_video->album_artist);
33 SAFE_FREE(_video->genre);
34 SAFE_FREE(_video->composer);
35 SAFE_FREE(_video->year);
36 SAFE_FREE(_video->recorded_date);
37 SAFE_FREE(_video->copyright);
38 SAFE_FREE(_video->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 video_meta_clone(video_meta_h *dst, video_meta_h src)
54 int ret = MEDIA_CONTENT_ERROR_NONE;
55 video_meta_s *_src = (video_meta_s*)src;
59 video_meta_s *_dst = (video_meta_s*)calloc(1, sizeof(video_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 video_meta_destroy((video_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 video_meta_destroy((video_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 video_meta_destroy((video_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 video_meta_destroy((video_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 video_meta_destroy((video_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 video_meta_destroy((video_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 video_meta_destroy((video_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 video_meta_destroy((video_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 video_meta_destroy((video_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 video_meta_destroy((video_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 video_meta_destroy((video_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->duration = _src->duration;
185 _dst->width = _src->width;
186 _dst->height = _src->height;
187 _dst->played_count = _src->played_count;
188 _dst->played_time = _src->played_time;
189 _dst->played_position = _src->played_position;
191 *dst = (video_meta_h)_dst;
193 ret = MEDIA_CONTENT_ERROR_NONE;
197 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
198 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
204 int video_meta_get_media_id(video_meta_h video, char **media_id)
206 int ret = MEDIA_CONTENT_ERROR_NONE;
207 video_meta_s *_video = (video_meta_s*)video;
210 if(STRING_VALID(_video->media_id))
212 char *new_string = strdup(_video->media_id);
213 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
215 *media_id = new_string;
221 ret = MEDIA_CONTENT_ERROR_NONE;
226 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
227 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
233 int video_meta_get_album(video_meta_h video, char **album)
235 int ret = MEDIA_CONTENT_ERROR_NONE;
236 video_meta_s *_video = (video_meta_s*)video;
239 if(STRING_VALID(_video->album))
241 char *new_string = strdup(_video->album);
242 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
250 ret = MEDIA_CONTENT_ERROR_NONE;
255 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
256 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
262 int video_meta_get_artist(video_meta_h video, char **artist)
264 int ret = MEDIA_CONTENT_ERROR_NONE;
265 video_meta_s *_video = (video_meta_s*)video;
268 if(STRING_VALID(_video->artist))
270 char *new_string = strdup(_video->artist);
271 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
273 *artist = new_string;
279 ret = MEDIA_CONTENT_ERROR_NONE;
284 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
285 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
291 int video_meta_get_album_artist(video_meta_h video, char **album_artist)
293 int ret = MEDIA_CONTENT_ERROR_NONE;
294 video_meta_s *_video = (video_meta_s*)video;
297 if(STRING_VALID(_video->album_artist))
299 char *new_string = strdup(_video->album_artist);
300 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
302 *album_artist = new_string;
306 *album_artist = NULL;
308 ret = MEDIA_CONTENT_ERROR_NONE;
313 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
314 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
321 int video_meta_get_genre(video_meta_h video, char **genre)
323 int ret = MEDIA_CONTENT_ERROR_NONE;
324 video_meta_s *_video = (video_meta_s*)video;
327 if(STRING_VALID(_video->genre))
329 char *new_string = strdup(_video->genre);
330 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
339 ret = MEDIA_CONTENT_ERROR_NONE;
343 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
344 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
350 int video_meta_get_composer(video_meta_h video, char **composer)
352 int ret = MEDIA_CONTENT_ERROR_NONE;
353 video_meta_s *_video = (video_meta_s*)video;
356 if(STRING_VALID(_video->composer))
358 char *new_string = strdup(_video->composer);
359 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
361 *composer = new_string;
368 ret = MEDIA_CONTENT_ERROR_NONE;
372 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
373 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
379 int video_meta_get_year(video_meta_h video, char **year)
381 int ret = MEDIA_CONTENT_ERROR_NONE;
382 video_meta_s *_video = (video_meta_s*)video;
385 if(STRING_VALID(_video->year))
387 char *new_string = strdup(_video->year);
388 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
397 ret = MEDIA_CONTENT_ERROR_NONE;
401 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
402 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
408 int video_meta_get_recorded_date(video_meta_h video, char **recorded_date)
410 int ret = MEDIA_CONTENT_ERROR_NONE;
411 video_meta_s *_video = (video_meta_s*)video;
414 if(STRING_VALID(_video->recorded_date))
416 char *new_string = strdup(_video->recorded_date);
417 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
419 *recorded_date = new_string;
423 *recorded_date = NULL;
426 ret = MEDIA_CONTENT_ERROR_NONE;
430 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
431 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
437 int video_meta_get_copyright(video_meta_h video, char **copyright)
439 int ret = MEDIA_CONTENT_ERROR_NONE;
440 video_meta_s *_video = (video_meta_s*)video;
443 if(STRING_VALID(_video->copyright))
445 char *new_string = strdup(_video->copyright);
446 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
448 *copyright = new_string;
455 ret = MEDIA_CONTENT_ERROR_NONE;
459 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
460 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
466 int video_meta_get_track_num(video_meta_h video, char **track_num)
468 int ret = MEDIA_CONTENT_ERROR_NONE;
469 video_meta_s *_video = (video_meta_s*)video;
472 if(STRING_VALID(_video->track_num))
474 char *new_string = strdup(_video->track_num);
475 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
477 *track_num = new_string;
484 ret = MEDIA_CONTENT_ERROR_NONE;
488 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
489 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
495 int video_meta_get_bit_rate(video_meta_h video, int *bit_rate)
497 int ret = MEDIA_CONTENT_ERROR_NONE;
498 video_meta_s *_video = (video_meta_s*)video;
500 if(_video && bit_rate)
502 *bit_rate = _video->bitrate;
503 ret = MEDIA_CONTENT_ERROR_NONE;
507 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
508 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
514 int video_meta_get_duration(video_meta_h video, int *duration)
516 int ret = MEDIA_CONTENT_ERROR_NONE;
517 video_meta_s *_video = (video_meta_s*)video;
519 if(_video && duration)
521 *duration = _video->duration;
522 ret = MEDIA_CONTENT_ERROR_NONE;
526 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
527 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
533 int video_meta_get_width(video_meta_h video, int *width)
535 int ret = MEDIA_CONTENT_ERROR_NONE;
536 video_meta_s *_video = (video_meta_s*)video;
540 *width = _video->width;
541 ret = MEDIA_CONTENT_ERROR_NONE;
545 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
546 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
552 int video_meta_get_height(video_meta_h video, int *height)
554 int ret = MEDIA_CONTENT_ERROR_NONE;
555 video_meta_s *_video = (video_meta_s*)video;
558 *height = _video->height;
559 ret = MEDIA_CONTENT_ERROR_NONE;
563 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
564 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
570 int video_meta_get_played_count(video_meta_h video, int *played_count)
572 int ret = MEDIA_CONTENT_ERROR_NONE;
573 video_meta_s *_video = (video_meta_s*)video;
575 if(_video && played_count)
577 *played_count = _video->played_count;
578 ret = MEDIA_CONTENT_ERROR_NONE;
582 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
583 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
589 int video_meta_get_played_time(video_meta_h video, time_t* played_time)
591 int ret = MEDIA_CONTENT_ERROR_NONE;
592 video_meta_s *_video = (video_meta_s*)video;
596 *played_time = _video->played_time;
597 ret = MEDIA_CONTENT_ERROR_NONE;
601 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
602 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
608 int video_meta_get_played_position(video_meta_h video, int *played_position)
610 int ret = MEDIA_CONTENT_ERROR_NONE;
611 video_meta_s *_video = (video_meta_s*)video;
615 *played_position = _video->played_position;
616 ret = MEDIA_CONTENT_ERROR_NONE;
620 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
621 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
627 int video_meta_set_played_count(video_meta_h video, int played_count)
629 int ret = MEDIA_CONTENT_ERROR_NONE;
630 video_meta_s *_video = (video_meta_s*)video;
632 if((_video != NULL) && (played_count >= 0))
634 _video->played_count = played_count;
638 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
639 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
645 int video_meta_set_played_time(video_meta_h video, time_t played_time)
647 int ret = MEDIA_CONTENT_ERROR_NONE;
648 video_meta_s *_video = (video_meta_s*)video;
650 if((_video != NULL) && (played_time >= 0))
652 _video->played_time = played_time;
656 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
657 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
663 int video_meta_set_played_position(video_meta_h video, int played_position)
665 int ret = MEDIA_CONTENT_ERROR_NONE;
666 video_meta_s *_video = (video_meta_s*)video;
668 if((_video != NULL) && (played_position >= 0))
670 _video->played_position = played_position;
674 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
675 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
681 int video_meta_update_to_db(video_meta_h video)
683 int ret = MEDIA_CONTENT_ERROR_NONE;
684 video_meta_s *_video = (video_meta_s*)video;
687 if(_video != NULL && STRING_VALID(_video->media_id))
689 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
690 memset(storage_id, 0x00, sizeof(storage_id));
692 ret = _media_db_get_storage_id_by_media_id(_video->media_id, storage_id);
693 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
695 sql = sqlite3_mprintf(UPDATE_AV_META_FROM_MEDIA, storage_id, _video->played_count, _video->played_time, _video->played_position, _video->media_id);
696 ret = _content_query_sql(sql);
697 SQLITE3_SAFE_FREE(sql);
701 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
702 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;