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;
27 SAFE_FREE(_video->media_id);
28 SAFE_FREE(_video->title);
29 SAFE_FREE(_video->album);
30 SAFE_FREE(_video->artist);
31 SAFE_FREE(_video->album_artist);
32 SAFE_FREE(_video->genre);
33 SAFE_FREE(_video->composer);
34 SAFE_FREE(_video->year);
35 SAFE_FREE(_video->recorded_date);
36 SAFE_FREE(_video->copyright);
37 SAFE_FREE(_video->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 video_meta_clone(video_meta_h *dst, video_meta_h src)
51 int ret = MEDIA_CONTENT_ERROR_NONE;
52 video_meta_s *_src = (video_meta_s*)src;
55 video_meta_s *_dst = (video_meta_s*)calloc(1, sizeof(video_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 video_meta_destroy((video_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 video_meta_destroy((video_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 video_meta_destroy((video_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 video_meta_destroy((video_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 video_meta_destroy((video_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 video_meta_destroy((video_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 video_meta_destroy((video_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 video_meta_destroy((video_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 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 (_src->copyright != NULL) {
140 _dst->copyright = g_strdup(_src->copyright);
141 if (_dst->copyright == NULL) {
142 video_meta_destroy((video_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 video_meta_destroy((video_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->duration = _src->duration;
159 _dst->width = _src->width;
160 _dst->height = _src->height;
161 _dst->played_count = _src->played_count;
162 _dst->played_time = _src->played_time;
163 _dst->played_position = _src->played_position;
164 _dst->rotation = _src->rotation;
166 *dst = (video_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 video_meta_get_media_id(video_meta_h video, char **media_id)
179 int ret = MEDIA_CONTENT_ERROR_NONE;
180 video_meta_s *_video = (video_meta_s*)video;
182 if (_video->media_id != NULL) {
183 char *new_string = strdup(_video->media_id);
184 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
186 *media_id = new_string;
190 ret = MEDIA_CONTENT_ERROR_NONE;
193 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
194 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
200 int video_meta_get_album(video_meta_h video, char **album)
202 int ret = MEDIA_CONTENT_ERROR_NONE;
203 video_meta_s *_video = (video_meta_s*)video;
205 if (_video->album != NULL) {
206 char *new_string = strdup(_video->album);
207 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
213 ret = MEDIA_CONTENT_ERROR_NONE;
216 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
217 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
223 int video_meta_get_artist(video_meta_h video, char **artist)
225 int ret = MEDIA_CONTENT_ERROR_NONE;
226 video_meta_s *_video = (video_meta_s*)video;
228 if (_video->artist != NULL) {
229 char *new_string = strdup(_video->artist);
230 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
232 *artist = new_string;
236 ret = MEDIA_CONTENT_ERROR_NONE;
239 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
240 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
246 int video_meta_get_album_artist(video_meta_h video, char **album_artist)
248 int ret = MEDIA_CONTENT_ERROR_NONE;
249 video_meta_s *_video = (video_meta_s*)video;
251 if (_video->album_artist != NULL) {
252 char *new_string = strdup(_video->album_artist);
253 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
255 *album_artist = new_string;
257 *album_artist = NULL;
259 ret = MEDIA_CONTENT_ERROR_NONE;
262 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
263 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
269 int video_meta_get_genre(video_meta_h video, char **genre)
271 int ret = MEDIA_CONTENT_ERROR_NONE;
272 video_meta_s *_video = (video_meta_s*)video;
274 if (_video->genre != NULL) {
275 char *new_string = strdup(_video->genre);
276 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
283 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 video_meta_get_composer(video_meta_h video, char **composer)
294 int ret = MEDIA_CONTENT_ERROR_NONE;
295 video_meta_s *_video = (video_meta_s*)video;
297 if (_video->composer != NULL) {
298 char *new_string = strdup(_video->composer);
299 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
301 *composer = new_string;
306 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 video_meta_get_year(video_meta_h video, char **year)
317 int ret = MEDIA_CONTENT_ERROR_NONE;
318 video_meta_s *_video = (video_meta_s*)video;
320 if (_video->year != NULL) {
321 char *new_string = strdup(_video->year);
322 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
329 ret = MEDIA_CONTENT_ERROR_NONE;
331 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
332 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
338 int video_meta_get_recorded_date(video_meta_h video, char **recorded_date)
340 int ret = MEDIA_CONTENT_ERROR_NONE;
341 video_meta_s *_video = (video_meta_s*)video;
343 if (_video->recorded_date != NULL) {
344 char *new_string = strdup(_video->recorded_date);
345 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
347 *recorded_date = new_string;
349 *recorded_date = NULL;
352 ret = MEDIA_CONTENT_ERROR_NONE;
354 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
355 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
361 int video_meta_get_copyright(video_meta_h video, char **copyright)
363 int ret = MEDIA_CONTENT_ERROR_NONE;
364 video_meta_s *_video = (video_meta_s*)video;
366 if (_video->copyright != NULL) {
367 char *new_string = strdup(_video->copyright);
368 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
370 *copyright = new_string;
375 ret = MEDIA_CONTENT_ERROR_NONE;
377 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
378 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
384 int video_meta_get_track_num(video_meta_h video, char **track_num)
386 int ret = MEDIA_CONTENT_ERROR_NONE;
387 video_meta_s *_video = (video_meta_s*)video;
389 if (_video->track_num != NULL) {
390 char *new_string = strdup(_video->track_num);
391 media_content_retvm_if(new_string == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
393 *track_num = new_string;
398 ret = MEDIA_CONTENT_ERROR_NONE;
400 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
401 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
407 int video_meta_get_bit_rate(video_meta_h video, int *bit_rate)
409 int ret = MEDIA_CONTENT_ERROR_NONE;
410 video_meta_s *_video = (video_meta_s*)video;
412 if (_video && bit_rate) {
413 *bit_rate = _video->bitrate;
414 ret = MEDIA_CONTENT_ERROR_NONE;
416 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
417 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
423 int video_meta_get_duration(video_meta_h video, int *duration)
425 int ret = MEDIA_CONTENT_ERROR_NONE;
426 video_meta_s *_video = (video_meta_s*)video;
428 if (_video && duration) {
429 *duration = _video->duration;
430 ret = MEDIA_CONTENT_ERROR_NONE;
432 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
433 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
439 int video_meta_get_width(video_meta_h video, int *width)
441 int ret = MEDIA_CONTENT_ERROR_NONE;
442 video_meta_s *_video = (video_meta_s*)video;
444 if (_video && width) {
445 *width = _video->width;
446 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 video_meta_get_height(video_meta_h video, int *height)
457 int ret = MEDIA_CONTENT_ERROR_NONE;
458 video_meta_s *_video = (video_meta_s*)video;
459 if (_video && height) {
460 *height = _video->height;
461 ret = MEDIA_CONTENT_ERROR_NONE;
463 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
464 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
470 int video_meta_get_rotation(video_meta_h video, int *rotation)
472 int ret = MEDIA_CONTENT_ERROR_NONE;
473 video_meta_s *_video = (video_meta_s*)video;
474 if (_video && rotation) {
475 *rotation = _video->rotation;
476 ret = MEDIA_CONTENT_ERROR_NONE;
478 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
479 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
486 int video_meta_get_played_count(video_meta_h video, int *played_count)
488 int ret = MEDIA_CONTENT_ERROR_NONE;
489 video_meta_s *_video = (video_meta_s*)video;
491 if (_video && played_count) {
492 *played_count = _video->played_count;
493 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 video_meta_get_played_time(video_meta_h video, time_t* played_time)
504 int ret = MEDIA_CONTENT_ERROR_NONE;
505 video_meta_s *_video = (video_meta_s*)video;
508 *played_time = _video->played_time;
509 ret = MEDIA_CONTENT_ERROR_NONE;
511 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
512 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
518 int video_meta_get_played_position(video_meta_h video, int *played_position)
520 int ret = MEDIA_CONTENT_ERROR_NONE;
521 video_meta_s *_video = (video_meta_s*)video;
524 *played_position = _video->played_position;
525 ret = MEDIA_CONTENT_ERROR_NONE;
527 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
528 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
534 int video_meta_set_played_count(video_meta_h video, int played_count)
536 int ret = MEDIA_CONTENT_ERROR_NONE;
537 video_meta_s *_video = (video_meta_s*)video;
539 if ((_video != NULL) && (played_count >= 0)) {
540 _video->played_count = played_count;
542 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
543 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
549 int video_meta_set_played_time(video_meta_h video, time_t played_time)
551 int ret = MEDIA_CONTENT_ERROR_NONE;
552 video_meta_s *_video = (video_meta_s*)video;
554 if ((_video != NULL) && (played_time >= 0)) {
555 _video->played_time = played_time;
557 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
558 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
564 int video_meta_set_played_position(video_meta_h video, int played_position)
566 int ret = MEDIA_CONTENT_ERROR_NONE;
567 video_meta_s *_video = (video_meta_s*)video;
569 if ((_video != NULL) && (played_position >= 0)) {
570 _video->played_position = played_position;
572 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
573 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
579 int video_meta_update_to_db(video_meta_h video)
581 int ret = MEDIA_CONTENT_ERROR_NONE;
582 video_meta_s *_video = (video_meta_s*)video;
585 if (_video != NULL && STRING_VALID(_video->media_id)) {
586 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
587 memset(storage_id, 0x00, sizeof(storage_id));
589 ret = _media_db_get_storage_id_by_media_id(_video->media_id, storage_id);
590 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
592 sql = sqlite3_mprintf(UPDATE_AV_META_FROM_MEDIA, storage_id, _video->played_count, _video->played_time, _video->played_position, _video->media_id);
593 ret = _content_query_sql(sql);
594 SQLITE3_SAFE_FREE(sql);
596 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
597 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;