2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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.
19 #include <media-svc.h>
20 #include <visual-svc.h>
21 #include <media-svc-error.h>
22 #include <media-svc-types.h>
24 #include "mp-video-log.h"
25 #include "mp-video-value-define.h"
26 #include "mp-video-type-define.h"
27 #include "mp-util-media-service.h"
28 #include "mp-video-string-define.h"
30 static Eina_List *VideoItemList = NULL;
31 static Eina_List *pAllTagList = NULL;
33 MediaSvcHandle *pMediaSvcHandle = NULL;
38 static int MpUtilMediaSvcMitemIterateCb(Mitem * pItem, void *pUserData)
40 VideoLogInfo("Cluster ID: %s, File path:%s", pItem->cluster_uuid, pItem->file_url);
42 if (pItem->type == MINFO_ITEM_VIDEO) {
43 Eina_List **pList = (Eina_List **)pUserData;
44 *pList = eina_list_append(*pList, pItem);
50 static int MpUtilMediaSvcMtagIterateGetTagListCb(Mtag * pItem, void *pUserData)
54 Eina_List **pList = (Eina_List **)pUserData;
55 *pList = eina_list_append(*pList, pItem);
63 bool MpUtilMediaSvcGetFileDirectoryName(char *szFilePath, char *szFileName,
64 char *szDirectoryName,
65 char *szDirectoryPath)
70 VideoLogInfo("[ERR]");
77 for (nLoopCount = strlen(szFilePath); nLoopCount >= 0; nLoopCount--) {
78 if (szFilePath[nLoopCount] != '\0')
81 if (szFilePath[nLoopCount] == '/') {
83 memcpy(szFileName, &szFilePath[nLoopCount + 1], --nCount);
84 *(szFileName + nCount) = '\0';
85 VideoLogInfo("File name = %s\n", szFileName);
88 if (szDirectoryPath) {
89 memcpy(szDirectoryPath, &szFilePath[0], nLoopCount);
90 *(szDirectoryPath + nLoopCount + 1) = '\0';
91 VideoLogInfo("Directory path = %s", szDirectoryPath);
94 if (szDirectoryName) {
96 for (--nLoopCount; nLoopCount >= 0; nLoopCount--) {
98 if (szFilePath[nLoopCount] == '/') {
99 memcpy(szDirectoryName, &szFilePath[nLoopCount + 1], --nCount);
100 *(szDirectoryName + nCount) = '\0';
101 VideoLogInfo("Directory Name = %s", szDirectoryName);
115 bool MpUtilMediaSvcDestroyList(Eina_List *pList)
118 VideoLogInfo("pList is empty already.");
122 Mitem *pMitem = NULL;
123 EINA_LIST_FREE(pList, pMitem) {
125 minfo_destroy_mtype_item(pMitem);
139 void MpUtilMediaSvcInitSession(void)
145 nRet = media_svc_connect(&pMediaSvcHandle);
149 VideoLogInfo("[ERR]");
153 void MpUtilMediaSvcFinishSession(void)
157 media_svc_disconnect(pMediaSvcHandle);
160 void MpUtilMediaSvcDestoryVideoList(void)
165 MpUtilMediaSvcDestroyList(VideoItemList);
166 VideoItemList = NULL;
170 bool MpUtilMediaSvcDestroyItem(char *szFilePath)
175 VideoLogInfo("[ERR]");
179 if (!VideoItemList) {
180 VideoLogInfo("pList is empty already.");
184 Mitem *pMitem = NULL;
185 Eina_List *pIterateList = NULL;
186 EINA_LIST_FOREACH(VideoItemList, pIterateList, pMitem) {
188 if (!strcmp(pMitem->file_url, szFilePath)) {
189 VideoItemList = eina_list_remove(VideoItemList, pMitem);
196 bool MpUtilMediaSvcGetVideoFileListFromFolder(char *szFilePath, int nSortType)
201 VideoLogInfo("[ERR]");
206 VideoLogInfo("Already exist video list.");
210 VideoLogInfo("szFilePath : %s", szFilePath);
213 char szFolderID[STR_UUID_LEN_MAX] = { 0, };
214 char szDirectoryPath[STR_LEN_MAX] = { 0, };
215 minfo_item_filter m_Filter = { 0, };
217 // Get directory path from filepath.
218 MpUtilMediaSvcGetFileDirectoryName(szFilePath, NULL, NULL, szDirectoryPath);
219 VideoLogInfo("Directory Path : %s", szDirectoryPath);
221 // Get folder ID by directory path.
222 nRet = minfo_get_cluster_id_by_url(pMediaSvcHandle, szDirectoryPath, szFolderID, STR_UUID_LEN_MAX);
223 VideoLogInfo("Folder ID : %s", szFolderID);
227 case MP_MEDIA_SORT_BY_NONE:
228 m_Filter.sort_type = MINFO_MEDIA_SORT_BY_NONE;
231 case MP_MEDIA_SORT_BY_NAME_DESC:
232 m_Filter.sort_type = MINFO_MEDIA_SORT_BY_NAME_DESC;
235 case MP_MEDIA_SORT_BY_NAME_ASC:
236 m_Filter.sort_type = MINFO_MEDIA_SORT_BY_NAME_ASC;
239 case MP_MEDIA_SORT_BY_DATE_DESC:
240 m_Filter.sort_type = MINFO_MEDIA_SORT_BY_DATE_DESC;
243 case MP_MEDIA_SORT_BY_DATE_ASC:
244 m_Filter.sort_type = MINFO_MEDIA_SORT_BY_NAME_ASC;
248 m_Filter.sort_type = MINFO_MEDIA_SORT_BY_NAME_ASC;
252 m_Filter.favorite = MINFO_MEDIA_FAV_ALL;
253 m_Filter.file_type = MINFO_ITEM_VIDEO;
254 m_Filter.start_pos = -1;
255 m_Filter.end_pos = -1;
256 m_Filter.with_meta = TRUE;
259 minfo_get_item_list(pMediaSvcHandle, szFolderID, m_Filter, MpUtilMediaSvcMitemIterateCb, &VideoItemList);
263 bool MpUtilMediaSvcGetVideoFileListFromAllFolderOfGallery(int nSortType)
268 VideoLogInfo("Already exist video list.");
272 minfo_item_filter m_Filter = { 0 };
274 /* Set sorting type. */
276 case MP_MEDIA_SORT_BY_NONE:
277 m_Filter.sort_type = MINFO_MEDIA_SORT_BY_NONE;
280 case MP_MEDIA_SORT_BY_NAME_DESC:
281 m_Filter.sort_type = MINFO_MEDIA_SORT_BY_NAME_DESC;
284 case MP_MEDIA_SORT_BY_NAME_ASC:
285 m_Filter.sort_type = MINFO_MEDIA_SORT_BY_NAME_ASC;
288 case MP_MEDIA_SORT_BY_DATE_DESC:
289 m_Filter.sort_type = MINFO_MEDIA_SORT_BY_DATE_DESC;
292 case MP_MEDIA_SORT_BY_DATE_ASC:
293 m_Filter.sort_type = MINFO_MEDIA_SORT_BY_NAME_ASC;
297 m_Filter.sort_type = MINFO_MEDIA_SORT_BY_NAME_ASC;
300 VideoLogInfo("Sorting : %d", nSortType);
302 /* Set sorting type. */
303 m_Filter.favorite = MINFO_MEDIA_FAV_ALL;
304 m_Filter.file_type = MINFO_ITEM_VIDEO;
305 m_Filter.start_pos = -1;
306 m_Filter.end_pos = -1;
307 m_Filter.with_meta = TRUE;
310 minfo_get_all_item_list(pMediaSvcHandle, MINFO_CLUSTER_TYPE_LOCAL_ALL, m_Filter, MpUtilMediaSvcMitemIterateCb, &VideoItemList);
315 bool MpUtilMediaSvcGetVideoFileListByTagName(char *szTagName)
320 VideoLogInfo("[ERR] No Exist tag name.");
325 VideoLogInfo("Already exist video list.");
329 VideoLogInfo("szTagName : %s", szTagName);
331 int nRet = minfo_get_media_list_by_tagname(pMediaSvcHandle, szTagName, FALSE, MpUtilMediaSvcMitemIterateCb, &VideoItemList);
333 VideoLogInfo("Failed to get a media items' list. error code->%d", nRet);
340 bool MpUtilMediaSvcGetVideoFileListFromFavorite(int nSortType)
345 VideoLogInfo("Already exist video list.");
349 minfo_item_filter m_Filter = { 0 };
351 /* Set sorting type. */
353 case MP_MEDIA_SORT_BY_NONE:
354 m_Filter.sort_type = MINFO_MEDIA_SORT_BY_NONE;
357 case MP_MEDIA_SORT_BY_NAME_DESC:
358 m_Filter.sort_type = MINFO_MEDIA_SORT_BY_NAME_DESC;
361 case MP_MEDIA_SORT_BY_NAME_ASC:
362 m_Filter.sort_type = MINFO_MEDIA_SORT_BY_NAME_ASC;
365 case MP_MEDIA_SORT_BY_DATE_DESC:
366 m_Filter.sort_type = MINFO_MEDIA_SORT_BY_DATE_DESC;
369 case MP_MEDIA_SORT_BY_DATE_ASC:
370 m_Filter.sort_type = MINFO_MEDIA_SORT_BY_NAME_ASC;
374 m_Filter.sort_type = MINFO_MEDIA_SORT_BY_DATE_DESC;
377 m_Filter.favorite = MINFO_MEDIA_FAV_ONLY;
378 m_Filter.file_type = MINFO_ITEM_VIDEO;
379 m_Filter.start_pos = -1;
380 m_Filter.end_pos = -1;
381 m_Filter.with_meta = FALSE;
383 int nRet = minfo_get_item_list(pMediaSvcHandle, NULL, m_Filter, MpUtilMediaSvcMitemIterateCb, &VideoItemList);
385 VideoLogInfo("Failed to get a media items' list. error code->%d", nRet);
392 void MpUtilMediaSvcMtagIterateDestroyTagList(void)
397 VideoLogInfo("pAllTagList is empty already.");
402 EINA_LIST_FREE(pAllTagList, pMtag) {
404 if (pMtag->tag_name) {
405 free(pMtag->tag_name);
406 pMtag->tag_name = NULL;
416 int MpUtilMediaSvcMtagGetAllTagList(char *pTagList[])
424 MpUtilMediaSvcMtagIterateDestroyTagList();
427 minfo_get_tag_list_by_media_id(pMediaSvcHandle, NULL, MpUtilMediaSvcMtagIterateGetTagListCb, &pAllTagList);
429 if (nErr == 0 && pAllTagList != NULL) {
431 Eina_List *pTmpList = NULL;
433 EINA_LIST_FOREACH(pAllTagList, pTmpList, pMtag) {
434 if (pMtag && pMtag->tag_name) {
435 VideoLogInfo("%s of the tag has %d item(s).", pMtag->tag_name, pMtag->count);
436 pTagList[nCount++] = pMtag->tag_name;
441 VideoLogInfo("Size of User tag list is %d.", nCount);
446 bool MpUtilMediaSvcMtagAddItemToTag(const char *szTagName, char *szMediaUri)
451 VideoLogInfo("[ERR] No exist string pointer szTagName.");
455 Mitem *m_Item = NULL;
458 minfo_get_item(pMediaSvcHandle, szMediaUri, &m_Item);
462 minfo_add_tag(pMediaSvcHandle, m_Item->uuid, szTagName);
463 minfo_destroy_mtype_item(m_Item);
465 minfo_add_tag(pMediaSvcHandle, NULL, szTagName);
471 bool MpUtilMediaSvcMtagGetItemToFavorite(char *szMediaUri)
476 VideoLogInfo("[ERR] No exist string pointer szMediaUri.");
480 Mitem *m_Item = NULL;
482 minfo_get_item(pMediaSvcHandle, szMediaUri, &m_Item);
485 VideoLogInfo("Favorate value : %d", m_Item->rate);
487 minfo_destroy_mtype_item(m_Item);
490 minfo_destroy_mtype_item(m_Item);
495 VideoLogInfo("[ERR] m_Item is NULL.");
502 bool MpUtilMediaSvcMtagAddItemToFavorite(char *szMediaUri, bool bFavorite)
507 VideoLogInfo("[ERR] No exist string pointer szMediaUri.");
511 Mitem *m_Item = NULL;
513 minfo_get_item(pMediaSvcHandle, szMediaUri, &m_Item);
516 int nRet = minfo_update_media_favorite(pMediaSvcHandle, m_Item->uuid, bFavorite);
519 VideoLogInfo("success to add item to favourites folder.");
521 VideoLogInfo("fail - error code : %d ", nRet);
524 minfo_destroy_mtype_item(m_Item);
526 VideoLogInfo("[ERR] m_Item is NULL.");
533 char *MpUtilMediaSvcMitemGetThumbnailUrl(char *szMediaUri)
538 VideoLogInfo("[ERR] No exist string pointer szMediaUri.");
542 Mitem *m_Item = NULL;
543 char *thumb_path = NULL;
545 minfo_get_item(pMediaSvcHandle, szMediaUri, &m_Item);
548 /* prevent 2011/07/12 */
549 thumb_path = strdup(m_Item->thumb_url);
550 minfo_destroy_mtype_item(m_Item);
557 bool MpUtilMediaSvcGetPreNextVideoUrl(char *szCurrMediaUri, char *szPreMediaUri, char *szNextMediaUri)
561 if (!szCurrMediaUri) {
562 VideoLogInfo("[ERR] No exist current file path.");
566 if (!VideoItemList) {
567 VideoLogInfo("No exist VideoItemList.");
573 Mitem *m_Item = NULL;
574 Eina_List *pIterateList = NULL;
576 memset(szPreMediaUri, 0, sizeof(char) * STR_LEN_MAX);
577 memset(szNextMediaUri, 0, sizeof(char) * STR_LEN_MAX);
579 nListSize = eina_list_count(VideoItemList);
581 if (nListSize <= 1) {
582 VideoLogInfo("Video list size == 1.");
586 EINA_LIST_FOREACH(VideoItemList, pIterateList, m_Item) {
590 VideoLogInfo("URL of the File item - %s (%d / %d)", m_Item->file_url, nCount, nListSize);
592 if (!strcmp(m_Item->file_url, szCurrMediaUri)) {
594 m_Item = (Mitem *) eina_list_nth(VideoItemList, nCount - 1);
596 strncpy(szPreMediaUri, m_Item->file_url, (sizeof(char) * STR_LEN_MAX) - 1);
600 m_Item = (Mitem *) eina_list_nth(VideoItemList, nCount + 1);
602 strncpy(szNextMediaUri, m_Item->file_url, (sizeof(char) * STR_LEN_MAX) - 1);
605 VideoLogInfo("PreMediaUri:%s", szPreMediaUri);
606 VideoLogInfo("NextMediaUri:%s", szNextMediaUri);
617 void MpUtilMediaSvcGetVideoID(const char *szPath, char *szVideoID)
625 ret = minfo_get_item(pMediaSvcHandle, szPath, &item);
627 VideoLogInfo("minfo_get_item API error return:%s, %d", szPath, ret);
632 memset((void*)szVideoID, 0, STR_LEN_MAX);
633 strncpy(szVideoID, item->uuid, STR_LEN_MAX-1);
634 minfo_destroy_mtype_item(item);
639 void MpUtilMediaSvcSaveLastPlayedTime(char* szMediaUri, unsigned int nLastPlayedTime)
642 VideoLogInfo("No exist media uri.");
648 char szVid[STR_LEN_MAX] = {0};
650 MpUtilMediaSvcGetVideoID(szMediaUri, szVid);
652 if (strlen(szVid) > 0) {
653 minfo_update_video_meta_info_int(pMediaSvcHandle, szVid, MINFO_VIDEO_META_BOOKMARK_LAST_PLAYED, nLastPlayedTime);
655 VideoLogInfo("Invalid video ID.");