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.
17 #include <media_info_private.h>
18 #include <media_util_private.h>
19 #include <media_uhd.h>
21 int media_uhd_get_media_count_from_db(filter_h filter, int *media_count)
23 int ret = MEDIA_CONTENT_ERROR_NONE;
26 ret = _media_db_get_group_item_count(NULL, filter, MEDIA_GROUP_UHD, media_count);
28 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
29 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
35 int media_uhd_foreach_media_from_db(filter_h filter, media_uhd_cb callback, void *user_data)
37 int ret = MEDIA_CONTENT_ERROR_NONE;
39 if (callback != NULL) {
40 ret = _media_db_get_uhd(filter, callback, user_data);
42 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
43 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
49 int media_uhd_destroy(media_uhd_h uhd)
51 int ret = MEDIA_CONTENT_ERROR_NONE;
52 media_uhd_s *_uhd = (media_uhd_s*)uhd;
54 SAFE_FREE(_uhd->media_id);
55 SAFE_FREE(_uhd->storage_id);
56 SAFE_FREE(_uhd->path);
57 SAFE_FREE(_uhd->content_id);
58 SAFE_FREE(_uhd->content_title);
59 SAFE_FREE(_uhd->file_name);
60 SAFE_FREE(_uhd->release_date);
63 ret = MEDIA_CONTENT_ERROR_NONE;
65 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
66 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
72 int media_uhd_clone(media_uhd_h *dst, media_uhd_h src)
74 int ret = MEDIA_CONTENT_ERROR_NONE;
75 media_uhd_s *_src = (media_uhd_s*)src;
78 media_uhd_s *_dst = (media_uhd_s*)calloc(1, sizeof(media_uhd_s));
80 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
81 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
84 if (STRING_VALID(_src->media_id)) {
85 _dst->media_id = strdup(_src->media_id);
86 if (_dst->media_id == NULL) {
87 media_uhd_destroy((media_uhd_h)_dst);
88 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
89 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
93 if (STRING_VALID(_src->storage_id)) {
94 _dst->storage_id = strdup(_src->storage_id);
95 if (_dst->storage_id == NULL) {
96 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
97 media_uhd_destroy((media_uhd_h)_dst);
98 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
102 if (STRING_VALID(_src->path)) {
103 _dst->path = strdup(_src->path);
104 if (_dst->path == NULL) {
105 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
106 media_uhd_destroy((media_uhd_h)_dst);
107 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
111 if (STRING_VALID(_src->content_id)) {
112 _dst->content_id = strdup(_src->content_id);
113 if (_dst->content_id == NULL) {
114 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
115 media_uhd_destroy((media_uhd_h)_dst);
116 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
120 if (STRING_VALID(_src->content_title)) {
121 _dst->content_title = strdup(_src->content_title);
122 if (_dst->content_title == NULL) {
123 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
124 media_uhd_destroy((media_uhd_h)_dst);
125 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
129 if (STRING_VALID(_src->release_date)) {
130 _dst->release_date = strdup(_src->release_date);
131 if (_dst->release_date == NULL) {
132 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
133 media_uhd_destroy((media_uhd_h)_dst);
134 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
138 if (STRING_VALID(_src->file_name)) {
139 _dst->file_name = strdup(_src->file_name);
140 if (_dst->file_name == NULL) {
141 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
142 media_uhd_destroy((media_uhd_h)_dst);
143 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
147 _dst->size = _src->size;
148 _dst->modified_time = _src->modified_time;
149 _dst->played_position = _src->played_position;
150 _dst->sub_type = _src->sub_type;
151 _dst->played_count = _src->played_count;
152 *dst = (media_uhd_h)_dst;
154 ret = MEDIA_CONTENT_ERROR_NONE;
156 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
157 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
163 int media_uhd_get_uhd_from_db(const char *media_id, media_uhd_h *uhd)
165 int ret = MEDIA_CONTENT_ERROR_NONE;
166 char *select_query = NULL;
167 sqlite3_stmt *stmt = NULL;
169 if (!STRING_VALID(media_id) || (uhd == NULL)) {
170 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
171 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
174 select_query = sqlite3_mprintf(SELECT_UHD_FROM_UHD, media_id);
176 ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
177 sqlite3_free(select_query);
178 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
180 media_uhd_s *_uhd = NULL;
182 while (sqlite3_step(stmt) == SQLITE_ROW) {
184 media_uhd_destroy((media_uhd_h)_uhd);
186 _uhd = (media_uhd_s*)calloc(1, sizeof(media_uhd_s));
189 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
190 SQLITE3_FINALIZE(stmt);
191 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
194 _media_uhd_item_get_detail(stmt, (media_uhd_h)_uhd);
196 *uhd = (media_uhd_h)_uhd;
199 SQLITE3_FINALIZE(stmt);
204 int media_uhd_get_media_id(media_uhd_h uhd, char **media_id)
206 int ret = MEDIA_CONTENT_ERROR_NONE;
207 media_uhd_s *_uhd = (media_uhd_s*)uhd;
209 if (_uhd && media_id) {
210 if (STRING_VALID(_uhd->media_id)) {
211 *media_id = strdup(_uhd->media_id);
212 if (*media_id == NULL) {
213 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
214 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
220 ret = MEDIA_CONTENT_ERROR_NONE;
222 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
223 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
229 int media_uhd_get_storage_id(media_uhd_h uhd, char **storage_id)
231 int ret = MEDIA_CONTENT_ERROR_NONE;
232 media_uhd_s *_uhd = (media_uhd_s*)uhd;
234 if (_uhd && storage_id) {
235 if (STRING_VALID(_uhd->storage_id)) {
236 *storage_id = strdup(_uhd->storage_id);
237 if (*storage_id == NULL) {
238 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
239 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
245 ret = MEDIA_CONTENT_ERROR_NONE;
247 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
248 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
254 int media_uhd_get_path(media_uhd_h uhd, char **path)
256 int ret = MEDIA_CONTENT_ERROR_NONE;
257 media_uhd_s *_uhd = (media_uhd_s*)uhd;
260 if (STRING_VALID(_uhd->path)) {
261 *path = strdup(_uhd->path);
263 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
264 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
270 ret = MEDIA_CONTENT_ERROR_NONE;
272 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
273 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
279 int media_uhd_get_size(media_uhd_h uhd, unsigned long long *size)
281 int ret = MEDIA_CONTENT_ERROR_NONE;
282 media_uhd_s *_uhd = (media_uhd_s*)uhd;
286 ret = MEDIA_CONTENT_ERROR_NONE;
288 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
289 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
295 int media_uhd_get_content_id(media_uhd_h uhd, char **content_id)
297 int ret = MEDIA_CONTENT_ERROR_NONE;
298 media_uhd_s *_uhd = (media_uhd_s*)uhd;
300 if (_uhd && content_id) {
301 if (STRING_VALID(_uhd->content_id)) {
302 *content_id = strdup(_uhd->content_id);
303 if (*content_id == NULL) {
304 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
305 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
311 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;
320 int media_uhd_get_content_title(media_uhd_h uhd, char **content_title)
322 int ret = MEDIA_CONTENT_ERROR_NONE;
323 media_uhd_s *_uhd = (media_uhd_s*)uhd;
325 if (_uhd && content_title) {
326 if (STRING_VALID(_uhd->content_title)) {
327 *content_title = strdup(_uhd->content_title);
328 if (*content_title == NULL) {
329 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
330 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
333 *content_title = NULL;
336 ret = MEDIA_CONTENT_ERROR_NONE;
338 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
339 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
345 int media_uhd_get_file_name(media_uhd_h uhd, char **file_name)
347 int ret = MEDIA_CONTENT_ERROR_NONE;
348 media_uhd_s *_uhd = (media_uhd_s*)uhd;
350 if (_uhd && file_name) {
351 if (STRING_VALID(_uhd->file_name)) {
352 *file_name = strdup(_uhd->file_name);
353 if (*file_name == NULL) {
354 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
355 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
361 ret = MEDIA_CONTENT_ERROR_NONE;
363 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
364 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
370 int media_uhd_get_release_date(media_uhd_h uhd, char **release_date)
372 int ret = MEDIA_CONTENT_ERROR_NONE;
373 media_uhd_s *_uhd = (media_uhd_s*)uhd;
375 if (_uhd && release_date) {
376 if (STRING_VALID(_uhd->release_date)) {
377 *release_date = strdup(_uhd->release_date);
378 if (*release_date == NULL) {
379 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
380 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
383 *release_date = NULL;
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 media_uhd_get_modified_time(media_uhd_h uhd, time_t *modified_time)
397 int ret = MEDIA_CONTENT_ERROR_NONE;
398 media_uhd_s *_uhd = (media_uhd_s*)uhd;
400 if (_uhd && modified_time) {
401 *modified_time = _uhd->modified_time;
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 media_uhd_get_played_position(media_uhd_h uhd, int *played_position)
413 int ret = MEDIA_CONTENT_ERROR_NONE;
414 media_uhd_s *_uhd = (media_uhd_s*)uhd;
417 *played_position = _uhd->played_position;
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 media_uhd_get_sub_type(media_uhd_h uhd, int *sub_type)
429 int ret = MEDIA_CONTENT_ERROR_NONE;
430 media_uhd_s *_uhd = (media_uhd_s*)uhd;
433 *sub_type = _uhd->sub_type;
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 media_uhd_get_played_count(media_uhd_h uhd, int *played_count)
445 int ret = MEDIA_CONTENT_ERROR_NONE;
446 media_uhd_s *_uhd = (media_uhd_s*)uhd;
449 *played_count = _uhd->played_count;
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 media_uhd_set_played_position(media_uhd_h uhd, int played_position)
461 int ret = MEDIA_CONTENT_ERROR_NONE;
462 media_uhd_s *_uhd = (media_uhd_s*)uhd;
464 if ((_uhd != NULL) && (played_position >= 0)) {
465 _uhd->played_position = played_position;
467 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
468 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
474 int media_uhd_set_content_title(media_uhd_h uhd, const char *content_title)
476 int ret = MEDIA_CONTENT_ERROR_NONE;
477 media_uhd_s *_uhd = (media_uhd_s*)uhd;
479 if (_uhd != NULL && STRING_VALID(content_title)) {
480 SAFE_FREE(_uhd->content_title);
481 _uhd->content_title = strdup(content_title);
482 if (_uhd->content_title == NULL) {
483 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
484 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
487 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
488 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
494 int media_uhd_set_release_date(media_uhd_h uhd, const char *release_date)
496 int ret = MEDIA_CONTENT_ERROR_NONE;
497 media_uhd_s *_uhd = (media_uhd_s*)uhd;
499 if (_uhd != NULL && STRING_VALID(release_date)) {
500 SAFE_FREE(_uhd->release_date);
501 _uhd->release_date = strdup(release_date);
502 if (_uhd->release_date == NULL) {
503 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
504 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
507 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
508 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
514 int media_uhd_set_sub_type(media_uhd_h uhd, int sub_type)
516 int ret = MEDIA_CONTENT_ERROR_NONE;
517 media_uhd_s *_uhd = (media_uhd_s*)uhd;
519 if ((_uhd != NULL) && (sub_type >= 0)) {
520 _uhd->sub_type = sub_type;
522 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
523 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
529 int media_uhd_set_played_count(media_uhd_h uhd, int played_count)
531 int ret = MEDIA_CONTENT_ERROR_NONE;
532 media_uhd_s *_uhd = (media_uhd_s*)uhd;
535 _uhd->played_count = played_count;
537 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
538 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
544 int media_uhd_update_to_db(media_uhd_h uhd)
546 int ret = MEDIA_CONTENT_ERROR_NONE;
547 media_uhd_s *_uhd = (media_uhd_s*)uhd;
548 char *update_query = NULL;
550 if (_uhd != NULL && STRING_VALID(_uhd->media_id) && STRING_VALID(_uhd->path)) {
551 update_query = sqlite3_mprintf(UPDATE_UHD_META_FROM_UHD, _uhd->content_title, _uhd->release_date, _uhd->played_position, _uhd->sub_type, _uhd->played_count, _uhd->media_id);
553 ret = _content_query_sql(update_query);
554 sqlite3_free(update_query);
556 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
557 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;