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 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 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 g_free(_uhd->media_id);
55 g_free(_uhd->storage_id);
57 g_free(_uhd->content_id);
58 g_free(_uhd->content_title);
59 g_free(_uhd->file_name);
60 g_free(_uhd->release_date);
63 ret = MEDIA_CONTENT_ERROR_NONE;
65 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 media_uhd_s *_src = (media_uhd_s*)src;
76 content_retip_if_fail(dst);
77 content_retip_if_fail(src);
79 media_uhd_s *_dst = g_new0(media_uhd_s, 1);
81 _dst->media_id = g_strdup(_src->media_id);
82 _dst->storage_id = g_strdup(_src->storage_id);
83 _dst->path = g_strdup(_src->path);
84 _dst->content_id = g_strdup(_src->content_id);
85 _dst->content_title = g_strdup(_src->content_title);
86 _dst->release_date = g_strdup(_src->release_date);
87 _dst->file_name = g_strdup(_src->file_name);
88 _dst->size = _src->size;
89 _dst->modified_time = _src->modified_time;
90 _dst->played_position = _src->played_position;
91 _dst->sub_type = _src->sub_type;
92 _dst->played_count = _src->played_count;
94 *dst = (media_uhd_h)_dst;
96 return MEDIA_CONTENT_ERROR_NONE;
99 int media_uhd_get_uhd_from_db(const char *media_id, media_uhd_h *uhd)
101 int ret = MEDIA_CONTENT_ERROR_NONE;
102 char *select_query = NULL;
103 sqlite3_stmt *stmt = NULL;
105 if (!STRING_VALID(media_id) || (uhd == NULL)) {
106 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
107 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
110 select_query = sqlite3_mprintf(SELECT_UHD_FROM_UHD, media_id);
112 ret = _content_get_result(select_query, &stmt);
113 SQLITE3_SAFE_FREE(select_query);
114 content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
116 media_uhd_s *_uhd = NULL;
118 if (sqlite3_step(stmt) == SQLITE_ROW) {
119 _uhd = g_new0(media_uhd_s, 1);
121 _media_uhd_item_get_detail(stmt, (media_uhd_h)_uhd);
123 *uhd = (media_uhd_h)_uhd;
125 content_error("Nonexistent media id[%s]", media_id);
126 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
129 SQLITE3_FINALIZE(stmt);
134 int media_uhd_get_media_id(media_uhd_h uhd, char **media_id)
136 media_uhd_s *_uhd = (media_uhd_s*)uhd;
138 content_retip_if_fail(uhd);
139 content_retip_if_fail(media_id);
141 *media_id = g_strdup(_uhd->media_id);
143 return MEDIA_CONTENT_ERROR_NONE;
146 int media_uhd_get_storage_id(media_uhd_h uhd, char **storage_id)
148 media_uhd_s *_uhd = (media_uhd_s*)uhd;
150 content_retip_if_fail(uhd);
151 content_retip_if_fail(storage_id);
153 *storage_id = g_strdup(_uhd->storage_id);
155 return MEDIA_CONTENT_ERROR_NONE;
158 int media_uhd_get_path(media_uhd_h uhd, char **path)
160 media_uhd_s *_uhd = (media_uhd_s*)uhd;
162 content_retip_if_fail(uhd);
163 content_retip_if_fail(path);
165 *path = g_strdup(_uhd->path);
167 return MEDIA_CONTENT_ERROR_NONE;
170 int media_uhd_get_size(media_uhd_h uhd, unsigned long long *size)
172 int ret = MEDIA_CONTENT_ERROR_NONE;
173 media_uhd_s *_uhd = (media_uhd_s*)uhd;
177 ret = MEDIA_CONTENT_ERROR_NONE;
179 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
180 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
186 int media_uhd_get_content_id(media_uhd_h uhd, char **content_id)
188 media_uhd_s *_uhd = (media_uhd_s*)uhd;
190 content_retip_if_fail(uhd);
191 content_retip_if_fail(content_id);
193 *content_id = g_strdup(_uhd->content_id);
195 return MEDIA_CONTENT_ERROR_NONE;
198 int media_uhd_get_content_title(media_uhd_h uhd, char **content_title)
200 media_uhd_s *_uhd = (media_uhd_s*)uhd;
202 content_retip_if_fail(uhd);
203 content_retip_if_fail(content_title);
205 *content_title = g_strdup(_uhd->content_title);
207 return MEDIA_CONTENT_ERROR_NONE;
210 int media_uhd_get_file_name(media_uhd_h uhd, char **file_name)
212 media_uhd_s *_uhd = (media_uhd_s*)uhd;
214 content_retip_if_fail(uhd);
215 content_retip_if_fail(file_name);
217 *file_name = g_strdup(_uhd->file_name);
219 return MEDIA_CONTENT_ERROR_NONE;
222 int media_uhd_get_release_date(media_uhd_h uhd, char **release_date)
224 media_uhd_s *_uhd = (media_uhd_s*)uhd;
226 content_retip_if_fail(uhd);
227 content_retip_if_fail(release_date);
229 *release_date = g_strdup(_uhd->release_date);
231 return MEDIA_CONTENT_ERROR_NONE;
234 int media_uhd_get_modified_time(media_uhd_h uhd, time_t *modified_time)
236 int ret = MEDIA_CONTENT_ERROR_NONE;
237 media_uhd_s *_uhd = (media_uhd_s*)uhd;
239 if (_uhd && modified_time) {
240 *modified_time = _uhd->modified_time;
241 ret = MEDIA_CONTENT_ERROR_NONE;
243 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
244 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
250 int media_uhd_get_played_position(media_uhd_h uhd, int *played_position)
252 int ret = MEDIA_CONTENT_ERROR_NONE;
253 media_uhd_s *_uhd = (media_uhd_s*)uhd;
256 *played_position = _uhd->played_position;
257 ret = MEDIA_CONTENT_ERROR_NONE;
259 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
260 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
266 int media_uhd_get_sub_type(media_uhd_h uhd, int *sub_type)
268 int ret = MEDIA_CONTENT_ERROR_NONE;
269 media_uhd_s *_uhd = (media_uhd_s*)uhd;
272 *sub_type = _uhd->sub_type;
273 ret = MEDIA_CONTENT_ERROR_NONE;
275 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
276 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
282 int media_uhd_get_played_count(media_uhd_h uhd, int *played_count)
284 int ret = MEDIA_CONTENT_ERROR_NONE;
285 media_uhd_s *_uhd = (media_uhd_s*)uhd;
288 *played_count = _uhd->played_count;
289 ret = MEDIA_CONTENT_ERROR_NONE;
291 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
292 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
298 int media_uhd_set_played_position(media_uhd_h uhd, int played_position)
300 int ret = MEDIA_CONTENT_ERROR_NONE;
301 media_uhd_s *_uhd = (media_uhd_s*)uhd;
303 if ((_uhd != NULL) && (played_position >= 0)) {
304 _uhd->played_position = played_position;
306 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
307 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
313 int media_uhd_set_content_title(media_uhd_h uhd, const char *content_title)
315 media_uhd_s *_uhd = (media_uhd_s*)uhd;
317 content_retip_if_fail(uhd);
318 content_retip_if_fail(STRING_VALID(content_title));
320 g_free(_uhd->content_title);
321 _uhd->content_title = g_strdup(content_title);
323 return MEDIA_CONTENT_ERROR_NONE;
326 int media_uhd_set_release_date(media_uhd_h uhd, const char *release_date)
328 media_uhd_s *_uhd = (media_uhd_s*)uhd;
330 content_retip_if_fail(uhd);
331 content_retip_if_fail(STRING_VALID(release_date));
333 g_free(_uhd->release_date);
334 _uhd->release_date = g_strdup(release_date);
336 return MEDIA_CONTENT_ERROR_NONE;
339 int media_uhd_set_sub_type(media_uhd_h uhd, int sub_type)
341 int ret = MEDIA_CONTENT_ERROR_NONE;
342 media_uhd_s *_uhd = (media_uhd_s*)uhd;
344 if ((_uhd != NULL) && (sub_type >= 0)) {
345 _uhd->sub_type = sub_type;
347 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
348 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
354 int media_uhd_set_played_count(media_uhd_h uhd, int played_count)
356 int ret = MEDIA_CONTENT_ERROR_NONE;
357 media_uhd_s *_uhd = (media_uhd_s*)uhd;
360 _uhd->played_count = played_count;
362 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
363 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
369 int media_uhd_update_to_db(media_uhd_h uhd)
371 int ret = MEDIA_CONTENT_ERROR_NONE;
372 media_uhd_s *_uhd = (media_uhd_s*)uhd;
373 char *update_query = NULL;
375 if (_uhd != NULL && STRING_VALID(_uhd->media_id) && STRING_VALID(_uhd->path)) {
376 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);
378 ret = _content_query_sql(update_query);
379 sqlite3_free(update_query);
381 content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
382 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;