/* * Copyright (c) [2012] Samsung Electronics Co., Ltd. * * Licensed under the Flora License, Version 1.1 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://floralicense.org/license/ * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include "mp-util.h" #include "mp-video-log.h" #include "mp-video-service-ctrl.h" #define MP_VIDEO_LAUNCHED_BY_APP_KEY "launching_application" #define MP_VIDEO_SORT_TYPE_KEY "order_type" #define MP_VIDEO_LIST_TYPE_KEY "video_list_type" #define MP_VIDEO_TAG_NAME_KEY "tag_name" #define MP_VIDEO_EDIT_MODE_KEY "edit_mode" #define MP_VIDEO_START_POS_TIME_KEY "start_pos_time" #define MP_VIDEO_URI_PATH "path" #define MP_VIDEO_COOKIE "cookie" #define MP_VIDEO_MULTI_WIN_TYPE_KEY "is_multi_win_type" #define MP_VIDEO_LAUNCH_TYPE "launch-type" #define MP_VIDEO_SHORTCUT_VIDEO "shortcut-videoplayer" static service_h pAppSvcHandle = NULL; static int nPlayerType = MP_NONE_VIEW_TYPE; static int nPrevPlayerType = MP_NONE_VIEW_TYPE; static int nGalleryLatestTime = 0; static char *g_szStreamingCookie = NULL; static bool bIsShortcutType = FALSE; ///////////////////////////////////////////////////////////////////////////// // Internal Function bool MpVideoServiceCtrlCheckMime(service_h pVideoServiceHandle, char **szMediaUri) { VideoLogInfo(""); if(!pVideoServiceHandle) { VideoLogInfo("[ERR] No Exist Service handle."); return FALSE; } bool bRet = TRUE; char *szMimeContent = NULL; if(service_get_extra_data(pVideoServiceHandle, AUL_K_MIME_CONTENT, &szMimeContent) != SERVICE_ERROR_NONE) { VideoLogInfo("No exist mime type."); bRet = FALSE; } if(szMimeContent) { *szMediaUri = (char*)malloc(strlen(szMimeContent) + 1); memset(*szMediaUri, 0, strlen(szMimeContent) + 1); strncpy(*szMediaUri, szMimeContent, strlen(szMimeContent)); VideoLogInfo("Mime content : %s", *szMediaUri); free(szMimeContent); bRet = TRUE; } else { VideoLogInfo("No exist MIME type."); bRet = FALSE; } return bRet; } bool MpVideoServiceCtrlCheckBundle(service_h pVideoServiceHandle, char **szMediaUri) { if(!pVideoServiceHandle) { VideoLogInfo("[ERR] No exist pBundleData pointer or Service handle count value."); return FALSE; } bool bRet = TRUE; char *szStrVideoURI = NULL; if(service_get_extra_data(pVideoServiceHandle, MP_VIDEO_URI_PATH, &szStrVideoURI) != SERVICE_ERROR_NONE) { VideoLogInfo("No exist KEY of video/streaming URI."); bRet = FALSE; return bRet; } if(szStrVideoURI) { *szMediaUri = (char*)malloc(strlen(szStrVideoURI) + 1); memset(*szMediaUri, 0, strlen(szStrVideoURI) + 1); strncpy(*szMediaUri, szStrVideoURI, strlen(szStrVideoURI)); VideoLogInfo("Video/Streaming URI path : %s", *szMediaUri); free(szStrVideoURI); szStrVideoURI = NULL; bRet = TRUE; } else { VideoLogInfo("No exist video/streaming URI."); bRet = FALSE; } return bRet; } bool MpVideoServiceCtrlCheckAUL(service_h pVideoServiceHandle, char **szMediaUri) { if(!pVideoServiceHandle) { VideoLogInfo("[ERR] No exist pBundleData pointer or Service handle count value."); return FALSE; } char *pGetOperation = NULL; service_get_operation(pVideoServiceHandle, &pGetOperation); if(pGetOperation == NULL) { return FALSE; } if(!strcmp(SERVICE_OPERATION_VIEW , pGetOperation)) { char *szStrVideoURI = NULL; service_get_uri(pVideoServiceHandle, &szStrVideoURI); if(szStrVideoURI) { *szMediaUri = (char*)malloc(strlen(szStrVideoURI) + 1); memset(*szMediaUri, 0, strlen(szStrVideoURI) + 1); strncpy(*szMediaUri, szStrVideoURI, strlen(szStrVideoURI)); VideoLogInfo("Video/Streaming URI path : %s", *szMediaUri); free(szStrVideoURI); szStrVideoURI = NULL; } else { VideoLogInfo("[ERR] No exist video/streaming URI."); if(pGetOperation) { free(pGetOperation); pGetOperation = NULL; } return FALSE; } } else { VideoLogInfo("No exist Operation."); if(pGetOperation) { free(pGetOperation); pGetOperation = NULL; } return FALSE; } VideoLogInfo("Video/Streaming URI path pAppData->szMediaUri : %s", *szMediaUri); if(pGetOperation) { free(pGetOperation); pGetOperation = NULL; } return TRUE; } bool MpVideoServiceCtrlParseUri(service_h pVideoServiceHandle, char** szMediaUri) { VideoLogInfo(""); if(!MpVideoServiceCtrlCheckMime(pVideoServiceHandle, szMediaUri)) { if(!MpVideoServiceCtrlCheckBundle(pVideoServiceHandle, szMediaUri)) { if(!MpVideoServiceCtrlCheckAUL(pVideoServiceHandle, szMediaUri)) { VideoLogInfo("No exist URI path."); return FALSE; } } } VideoLogInfo("szMediaUri : %s", *szMediaUri); return TRUE; } int MpVideoServiceCtrlCheckUriType(char* szMediaUri) { if(!szMediaUri) { VideoLogInfo("[ERR] No exist media uri."); return MP_ERROR_PLAYER_TYPE; } VideoLogInfo(""); int nRet = 0; if(MpUtilCheckUriType(szMediaUri)) { VideoLogInfo("MP_STREAMING_PLAYER"); nRet = MP_STREAMING_PLAYER; } else { VideoLogInfo("MP_VIDEO_PLAYER"); nRet = MP_VIDEO_PLAYER; } return nRet; } bool MpVideoServiceCtrlCheckCookieForStreaming(service_h pVideoServiceHandle) { if(!pVideoServiceHandle) { VideoLogInfo("[ERR] No exist pBundleData pointer or Service handle count value."); return FALSE; } bool bRet = TRUE; char *pStrVideoCookie = NULL; if(service_get_extra_data(pVideoServiceHandle, MP_VIDEO_COOKIE, &pStrVideoCookie) != SERVICE_ERROR_NONE) { VideoLogInfo("[ERR] No exist KEY of streaming COOKIE."); bRet = FALSE; } if(pStrVideoCookie) { g_szStreamingCookie = (char*)malloc(strlen(pStrVideoCookie) + 1); memset(g_szStreamingCookie, 0, strlen(pStrVideoCookie) + 1); strncpy(g_szStreamingCookie, pStrVideoCookie, strlen(pStrVideoCookie)); VideoLogInfo("Video/Streaming URI path Cookie : %s", g_szStreamingCookie); free(pStrVideoCookie); } else { VideoLogInfo("[ERR] No exist video/streaming URI."); bRet = FALSE; } return TRUE; } int MpVideoServiceCtrlCheckStartPositionTime(service_h pVideoServiceHandle, char *szBundleKey) { VideoLogInfo(""); if(!pVideoServiceHandle) { VideoLogInfo("No exist Service handle data."); return 0; } int nStartPositionTime = 0; char *szStartPosTime = NULL; if(service_get_extra_data(pVideoServiceHandle, szBundleKey, &szStartPosTime) != SERVICE_ERROR_NONE) { VideoLogInfo("No exist mime type."); return 0; } if(!szStartPosTime) { VideoLogInfo("No exist pointer of position time."); return 0; } nStartPositionTime = atoi(szStartPosTime); VideoLogInfo("Start position time : %d", nStartPositionTime); free(szStartPosTime); if(nStartPositionTime < 0) { nStartPositionTime = 0; } return nStartPositionTime; } bool MpVideoServiceCtrlGetTagNameOfGallery(service_h pVideoServiceHandle, char *szBundleKey, char *szTagName) { VideoLogInfo(""); if(!pVideoServiceHandle) { VideoLogInfo("No exist Service handle."); return FALSE; } if(!szBundleKey) { VideoLogInfo("No exist Service handle kay."); return FALSE; } if(!szTagName) { VideoLogInfo("No exist pAppData."); return FALSE; } bool nRet = TRUE; char *szVideoTagName = NULL; if(service_get_extra_data(pVideoServiceHandle, szBundleKey, &szVideoTagName) != SERVICE_ERROR_NONE) { VideoLogInfo("No exist mime type."); nRet = FALSE; } if(szVideoTagName) { strncpy(szTagName, szVideoTagName, STR_LEN_MAX - 1); VideoLogInfo("szTagName : %s", szTagName); free(szVideoTagName); nRet = TRUE; } else { VideoLogInfo("No exist pointer of szVideoTagName."); nRet = FALSE; } return nRet; } int MpVideoServiceCtrlCheckLauncher(service_h pVideoServiceHandle) { VideoLogInfo(""); if(!pVideoServiceHandle) { VideoLogInfo("No exist Service handle data."); return MP_VIDEO_PLAYER_SIMPLE; } char *szLaunchingByOtherApp = NULL; if(service_get_extra_data(pVideoServiceHandle, MP_VIDEO_LAUNCHED_BY_APP_KEY, &szLaunchingByOtherApp) != SERVICE_ERROR_NONE) { VideoLogInfo("No exist Service handle key of MP_VIDEO_LAUNCHED_BY_APP_KEY"); return MP_VIDEO_PLAYER_SIMPLE; } if(!szLaunchingByOtherApp) { VideoLogInfo("No exist pointer of szLaunchingByOtherApp"); return MP_VIDEO_PLAYER_SIMPLE; } MpPlayerViewType nTmpLaunchingAppType = MP_VIDEO_PLAYER_SIMPLE; if(!strcmp(szLaunchingByOtherApp, "gallery")) { nTmpLaunchingAppType = MP_VIDEO_PLAYER_GALLERY; nGalleryLatestTime = MpVideoServiceCtrlCheckStartPositionTime(pVideoServiceHandle, MP_VIDEO_START_POS_TIME_KEY); } else if(!strcmp(szLaunchingByOtherApp, "image_viewer")) { nTmpLaunchingAppType = MP_VIDEO_PLAYER_GALLERY; } else if(!strcmp(szLaunchingByOtherApp, "email")) { nTmpLaunchingAppType = MP_VIDEO_PLAYER_EMAIL; } else if(!strcmp(szLaunchingByOtherApp, "message")) { nTmpLaunchingAppType = MP_VIDEO_PLAYER_MMS; } else if(!strcmp(szLaunchingByOtherApp, "light_play_view")) { nTmpLaunchingAppType = MP_VIDEO_PLAYER_SIMPLE; } else { nTmpLaunchingAppType = MP_VIDEO_PLAYER_SIMPLE; } VideoLogInfo("Start position time : %d", nTmpLaunchingAppType); free(szLaunchingByOtherApp); return (int)nTmpLaunchingAppType; } bool MpVideoServiceCtrlCheckShortcut(service_h pVideoServiceHandle) { if(!pVideoServiceHandle) { VideoLogInfo("No exist Service handle."); return FALSE; } VideoLogInfo(""); char *pGetOperation = NULL; service_get_operation(pVideoServiceHandle, &pGetOperation); if(pGetOperation == NULL) { bIsShortcutType = FALSE; return bIsShortcutType; } if(!strcmp(pGetOperation, SERVICE_OPERATION_DEFAULT)) { char *szOperationType = NULL; if(service_get_extra_data(pVideoServiceHandle, MP_VIDEO_LAUNCH_TYPE, &szOperationType) != SERVICE_ERROR_NONE) { VideoLogInfo("No exist Service handle key of MP_VIDEO_LAUNCHED_BY_APP_KEY"); bIsShortcutType = FALSE; } if(!szOperationType) { VideoLogInfo("No exist pointer of szOperationType"); bIsShortcutType = FALSE; } else { if(!strcmp(szOperationType, MP_VIDEO_SHORTCUT_VIDEO)) { bIsShortcutType = TRUE; } else { bIsShortcutType = FALSE; } if(szOperationType) { free(szOperationType); szOperationType = NULL; } } } return bIsShortcutType; } ///////////////////////////////////////////////////////////////////////////// // External Function void MpVideoServiceCtrlReset(void) { VideoLogInfo(""); pAppSvcHandle = NULL; nGalleryLatestTime = 0; if(g_szStreamingCookie) { free(g_szStreamingCookie); g_szStreamingCookie = NULL; } } int MpVideoServiceCtrlInitServiceParser(void* pAppServiceHandle, char** szMediaUri) { if(!pAppServiceHandle) { VideoLogInfo(""); return MP_ERROR_PLAYER_TYPE; } VideoLogInfo(""); MpVideoServiceCtrlReset(); pAppSvcHandle = (service_h)pAppServiceHandle; nPlayerType = MP_NONE_VIEW_TYPE; if(!MpVideoServiceCtrlParseUri(pAppSvcHandle, szMediaUri)) { VideoLogInfo("MP_VIDEO_PLAYER_LIST"); nPlayerType = MP_VIDEO_PLAYER; } if(!*szMediaUri) { return nPlayerType; } else { VideoLogInfo("szMediaUri : %s", *szMediaUri); } int nUriType = 0; nUriType = MpVideoServiceCtrlCheckUriType(*szMediaUri); if(nUriType == MP_VIDEO_PLAYER) { nPlayerType = MpVideoServiceCtrlCheckLauncher(pAppSvcHandle); } if(nUriType == MP_STREAMING_PLAYER) { nPlayerType = MP_STREAMING_PLAYER; MpVideoServiceCtrlCheckCookieForStreaming(pAppSvcHandle); } return nPlayerType; } int MpVideoServiceCtrlGetLatestTime(void) { VideoLogInfo(""); if(nGalleryLatestTime < 0) { nGalleryLatestTime = 0; } return nGalleryLatestTime; } int MpVideoServiceCtrlGetPlayerTypeWithoutLog(void) { if(MP_ERROR_PLAYER_TYPE > nPlayerType || MP_MAX_PLAYER_TYPE < nPlayerType) { nPlayerType = MP_ERROR_PLAYER_TYPE; } return nPlayerType; } int MpVideoServiceCtrlGetPlayerType(void) { VideoLogInfo(""); if(MP_ERROR_PLAYER_TYPE > nPlayerType || MP_MAX_PLAYER_TYPE < nPlayerType) { nPlayerType = MP_ERROR_PLAYER_TYPE; } VideoLogInfo("nPlayerType : %d", nPlayerType); return nPlayerType; } void MpVideoServiceCtrlSetPlayerType(int nSetPlayerType) { VideoLogInfo("nSetPlayerType : %d", nSetPlayerType); if(MP_ERROR_PLAYER_TYPE < nSetPlayerType || MP_MAX_PLAYER_TYPE > nSetPlayerType) { MpVideoServiceCtrlSetPrevPlayerType(nPlayerType); nPlayerType = nSetPlayerType; } } int MpVideoServiceCtrlGetPrevPlayerType(void) { VideoLogInfo(""); if(MP_ERROR_PLAYER_TYPE > nPlayerType || MP_MAX_PLAYER_TYPE < nPlayerType) { nPrevPlayerType = MP_ERROR_PLAYER_TYPE; } VideoLogInfo("nPrevPlayerType : %d", nPrevPlayerType); return nPrevPlayerType; } void MpVideoServiceCtrlSetPrevPlayerType(int nSetPlayerType) { VideoLogInfo("nSetPlayerType : %d", nSetPlayerType); if(MP_ERROR_PLAYER_TYPE < nSetPlayerType || MP_MAX_PLAYER_TYPE > nSetPlayerType) { nPrevPlayerType = nSetPlayerType; } } char* MpVideoServiceCtrlGetCookieForStreaming(void) { VideoLogInfo(""); if(!g_szStreamingCookie) { VideoLogInfo("No exist streaming cookie."); return NULL; } return g_szStreamingCookie; }