2 * Copyright (c) [2012] Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.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.
23 #include "mp-video-log.h"
24 #include "mp-video-service-ctrl.h"
27 #define MP_VIDEO_LAUNCHED_BY_APP_KEY "launching_application"
28 #define MP_VIDEO_SORT_TYPE_KEY "order_type"
29 #define MP_VIDEO_LIST_TYPE_KEY "video_list_type"
30 #define MP_VIDEO_TAG_NAME_KEY "tag_name"
31 #define MP_VIDEO_EDIT_MODE_KEY "edit_mode"
32 #define MP_VIDEO_START_POS_TIME_KEY "start_pos_time"
33 #define MP_VIDEO_URI_PATH "path"
34 #define MP_VIDEO_COOKIE "cookie"
35 #define MP_VIDEO_MULTI_WIN_TYPE_KEY "is_multi_win_type"
36 #define MP_VIDEO_LAUNCH_TYPE "launch-type"
37 #define MP_VIDEO_SHORTCUT_VIDEO "shortcut-videoplayer"
39 static service_h pAppSvcHandle = NULL;
40 static int nPlayerType = MP_NONE_VIEW_TYPE;
41 static int nPrevPlayerType = MP_NONE_VIEW_TYPE;
42 static int nGalleryLatestTime = 0;
43 static char *g_szStreamingCookie = NULL;
44 static bool bIsShortcutType = FALSE;
47 /////////////////////////////////////////////////////////////////////////////
50 bool MpVideoServiceCtrlCheckMime(service_h pVideoServiceHandle, char **szMediaUri)
54 if(!pVideoServiceHandle)
56 VideoLogInfo("[ERR] No Exist Service handle.");
61 char *szMimeContent = NULL;
63 if(service_get_extra_data(pVideoServiceHandle, AUL_K_MIME_CONTENT, &szMimeContent) != SERVICE_ERROR_NONE)
65 VideoLogInfo("No exist mime type.");
71 *szMediaUri = (char*)malloc(strlen(szMimeContent) + 1);
72 memset(*szMediaUri, 0, strlen(szMimeContent) + 1);
73 strncpy(*szMediaUri, szMimeContent, strlen(szMimeContent));
74 VideoLogInfo("Mime content : %s", *szMediaUri);
80 VideoLogInfo("No exist MIME type.");
87 bool MpVideoServiceCtrlCheckBundle(service_h pVideoServiceHandle, char **szMediaUri)
89 if(!pVideoServiceHandle)
91 VideoLogInfo("[ERR] No exist pBundleData pointer or Service handle count value.");
96 char *szStrVideoURI = NULL;
98 if(service_get_extra_data(pVideoServiceHandle, MP_VIDEO_URI_PATH, &szStrVideoURI) != SERVICE_ERROR_NONE)
100 VideoLogInfo("No exist KEY of video/streaming URI.");
107 *szMediaUri = (char*)malloc(strlen(szStrVideoURI) + 1);
108 memset(*szMediaUri, 0, strlen(szStrVideoURI) + 1);
109 strncpy(*szMediaUri, szStrVideoURI, strlen(szStrVideoURI));
110 VideoLogInfo("Video/Streaming URI path : %s", *szMediaUri);
112 szStrVideoURI = NULL;
117 VideoLogInfo("No exist video/streaming URI.");
124 bool MpVideoServiceCtrlCheckAUL(service_h pVideoServiceHandle, char **szMediaUri)
126 if(!pVideoServiceHandle)
128 VideoLogInfo("[ERR] No exist pBundleData pointer or Service handle count value.");
133 char *pGetOperation = NULL;
135 service_get_operation(pVideoServiceHandle, &pGetOperation);
137 if(pGetOperation == NULL)
142 if(!strcmp(SERVICE_OPERATION_VIEW , pGetOperation))
144 char *szStrVideoURI = NULL;
146 service_get_uri(pVideoServiceHandle, &szStrVideoURI);
150 *szMediaUri = (char*)malloc(strlen(szStrVideoURI) + 1);
151 memset(*szMediaUri, 0, strlen(szStrVideoURI) + 1);
152 strncpy(*szMediaUri, szStrVideoURI, strlen(szStrVideoURI));
153 VideoLogInfo("Video/Streaming URI path : %s", *szMediaUri);
155 szStrVideoURI = NULL;
159 VideoLogInfo("[ERR] No exist video/streaming URI.");
164 pGetOperation = NULL;
172 VideoLogInfo("No exist Operation.");
177 pGetOperation = NULL;
183 VideoLogInfo("Video/Streaming URI path pAppData->szMediaUri : %s", *szMediaUri);
188 pGetOperation = NULL;
195 bool MpVideoServiceCtrlParseUri(service_h pVideoServiceHandle, char** szMediaUri)
199 if(!MpVideoServiceCtrlCheckMime(pVideoServiceHandle, szMediaUri))
201 if(!MpVideoServiceCtrlCheckBundle(pVideoServiceHandle, szMediaUri))
203 if(!MpVideoServiceCtrlCheckAUL(pVideoServiceHandle, szMediaUri))
205 VideoLogInfo("No exist URI path.");
211 VideoLogInfo("szMediaUri : %s", *szMediaUri);
216 int MpVideoServiceCtrlCheckUriType(char* szMediaUri)
220 VideoLogInfo("[ERR] No exist media uri.");
221 return MP_ERROR_PLAYER_TYPE;
228 if(MpUtilCheckUriType(szMediaUri))
230 VideoLogInfo("MP_STREAMING_PLAYER");
231 nRet = MP_STREAMING_PLAYER;
235 VideoLogInfo("MP_VIDEO_PLAYER");
236 nRet = MP_VIDEO_PLAYER;
242 bool MpVideoServiceCtrlCheckCookieForStreaming(service_h pVideoServiceHandle)
244 if(!pVideoServiceHandle)
246 VideoLogInfo("[ERR] No exist pBundleData pointer or Service handle count value.");
251 char *pStrVideoCookie = NULL;
253 if(service_get_extra_data(pVideoServiceHandle, MP_VIDEO_COOKIE, &pStrVideoCookie) != SERVICE_ERROR_NONE)
255 VideoLogInfo("[ERR] No exist KEY of streaming COOKIE.");
261 g_szStreamingCookie = (char*)malloc(strlen(pStrVideoCookie) + 1);
262 memset(g_szStreamingCookie, 0, strlen(pStrVideoCookie) + 1);
263 strncpy(g_szStreamingCookie, pStrVideoCookie, strlen(pStrVideoCookie));
264 VideoLogInfo("Video/Streaming URI path Cookie : %s", g_szStreamingCookie);
265 free(pStrVideoCookie);
269 VideoLogInfo("[ERR] No exist video/streaming URI.");
276 int MpVideoServiceCtrlCheckStartPositionTime(service_h pVideoServiceHandle, char *szBundleKey)
280 if(!pVideoServiceHandle)
282 VideoLogInfo("No exist Service handle data.");
286 int nStartPositionTime = 0;
287 char *szStartPosTime = NULL;
289 if(service_get_extra_data(pVideoServiceHandle, szBundleKey, &szStartPosTime) != SERVICE_ERROR_NONE)
291 VideoLogInfo("No exist mime type.");
297 VideoLogInfo("No exist pointer of position time.");
301 nStartPositionTime = atoi(szStartPosTime);
303 VideoLogInfo("Start position time : %d", nStartPositionTime);
305 free(szStartPosTime);
307 if(nStartPositionTime < 0)
309 nStartPositionTime = 0;
312 return nStartPositionTime;
315 bool MpVideoServiceCtrlGetTagNameOfGallery(service_h pVideoServiceHandle, char *szBundleKey, char *szTagName)
319 if(!pVideoServiceHandle)
321 VideoLogInfo("No exist Service handle.");
327 VideoLogInfo("No exist Service handle kay.");
333 VideoLogInfo("No exist pAppData.");
338 char *szVideoTagName = NULL;
340 if(service_get_extra_data(pVideoServiceHandle, szBundleKey, &szVideoTagName) != SERVICE_ERROR_NONE)
342 VideoLogInfo("No exist mime type.");
348 strncpy(szTagName, szVideoTagName, STR_LEN_MAX - 1);
349 VideoLogInfo("szTagName : %s", szTagName);
350 free(szVideoTagName);
355 VideoLogInfo("No exist pointer of szVideoTagName.");
362 int MpVideoServiceCtrlCheckLauncher(service_h pVideoServiceHandle)
366 if(!pVideoServiceHandle)
368 VideoLogInfo("No exist Service handle data.");
369 return MP_VIDEO_PLAYER_SIMPLE;
372 char *szLaunchingByOtherApp = NULL;
374 if(service_get_extra_data(pVideoServiceHandle, MP_VIDEO_LAUNCHED_BY_APP_KEY, &szLaunchingByOtherApp) != SERVICE_ERROR_NONE)
376 VideoLogInfo("No exist Service handle key of MP_VIDEO_LAUNCHED_BY_APP_KEY");
377 return MP_VIDEO_PLAYER_SIMPLE;
380 if(!szLaunchingByOtherApp)
382 VideoLogInfo("No exist pointer of szLaunchingByOtherApp");
383 return MP_VIDEO_PLAYER_SIMPLE;
386 MpPlayerViewType nTmpLaunchingAppType = MP_VIDEO_PLAYER_SIMPLE;
388 if(!strcmp(szLaunchingByOtherApp, "gallery"))
390 nTmpLaunchingAppType = MP_VIDEO_PLAYER_GALLERY;
392 nGalleryLatestTime = MpVideoServiceCtrlCheckStartPositionTime(pVideoServiceHandle, MP_VIDEO_START_POS_TIME_KEY);
394 else if(!strcmp(szLaunchingByOtherApp, "image_viewer"))
396 nTmpLaunchingAppType = MP_VIDEO_PLAYER_GALLERY;
398 else if(!strcmp(szLaunchingByOtherApp, "email"))
400 nTmpLaunchingAppType = MP_VIDEO_PLAYER_EMAIL;
402 else if(!strcmp(szLaunchingByOtherApp, "message"))
404 nTmpLaunchingAppType = MP_VIDEO_PLAYER_MMS;
406 else if(!strcmp(szLaunchingByOtherApp, "light_play_view"))
408 nTmpLaunchingAppType = MP_VIDEO_PLAYER_SIMPLE;
412 nTmpLaunchingAppType = MP_VIDEO_PLAYER_SIMPLE;
415 VideoLogInfo("Start position time : %d", nTmpLaunchingAppType);
417 free(szLaunchingByOtherApp);
419 return (int)nTmpLaunchingAppType;
422 bool MpVideoServiceCtrlCheckShortcut(service_h pVideoServiceHandle)
424 if(!pVideoServiceHandle)
426 VideoLogInfo("No exist Service handle.");
432 char *pGetOperation = NULL;
434 service_get_operation(pVideoServiceHandle, &pGetOperation);
436 if(pGetOperation == NULL)
438 bIsShortcutType = FALSE;
439 return bIsShortcutType;
442 if(!strcmp(pGetOperation, SERVICE_OPERATION_DEFAULT))
444 char *szOperationType = NULL;
446 if(service_get_extra_data(pVideoServiceHandle, MP_VIDEO_LAUNCH_TYPE, &szOperationType) != SERVICE_ERROR_NONE)
448 VideoLogInfo("No exist Service handle key of MP_VIDEO_LAUNCHED_BY_APP_KEY");
449 bIsShortcutType = FALSE;
454 VideoLogInfo("No exist pointer of szOperationType");
455 bIsShortcutType = FALSE;
459 if(!strcmp(szOperationType, MP_VIDEO_SHORTCUT_VIDEO))
461 bIsShortcutType = TRUE;
465 bIsShortcutType = FALSE;
470 free(szOperationType);
471 szOperationType = NULL;
476 return bIsShortcutType;
481 /////////////////////////////////////////////////////////////////////////////
484 void MpVideoServiceCtrlReset(void)
488 pAppSvcHandle = NULL;
490 nGalleryLatestTime = 0;
492 if(g_szStreamingCookie)
494 free(g_szStreamingCookie);
495 g_szStreamingCookie = NULL;
499 int MpVideoServiceCtrlInitServiceParser(void* pAppServiceHandle, char** szMediaUri)
501 if(!pAppServiceHandle)
504 return MP_ERROR_PLAYER_TYPE;
509 MpVideoServiceCtrlReset();
511 pAppSvcHandle = (service_h)pAppServiceHandle;
512 nPlayerType = MP_NONE_VIEW_TYPE;
514 if(!MpVideoServiceCtrlParseUri(pAppSvcHandle, szMediaUri))
516 VideoLogInfo("MP_VIDEO_PLAYER_LIST");
517 nPlayerType = MP_VIDEO_PLAYER;
526 VideoLogInfo("szMediaUri : %s", *szMediaUri);
531 nUriType = MpVideoServiceCtrlCheckUriType(*szMediaUri);
533 if(nUriType == MP_VIDEO_PLAYER)
535 nPlayerType = MpVideoServiceCtrlCheckLauncher(pAppSvcHandle);
538 if(nUriType == MP_STREAMING_PLAYER)
540 nPlayerType = MP_STREAMING_PLAYER;
541 MpVideoServiceCtrlCheckCookieForStreaming(pAppSvcHandle);
547 int MpVideoServiceCtrlGetLatestTime(void)
551 if(nGalleryLatestTime < 0)
553 nGalleryLatestTime = 0;
556 return nGalleryLatestTime;
559 int MpVideoServiceCtrlGetPlayerTypeWithoutLog(void)
561 if(MP_ERROR_PLAYER_TYPE > nPlayerType || MP_MAX_PLAYER_TYPE < nPlayerType)
563 nPlayerType = MP_ERROR_PLAYER_TYPE;
569 int MpVideoServiceCtrlGetPlayerType(void)
573 if(MP_ERROR_PLAYER_TYPE > nPlayerType || MP_MAX_PLAYER_TYPE < nPlayerType)
575 nPlayerType = MP_ERROR_PLAYER_TYPE;
578 VideoLogInfo("nPlayerType : %d", nPlayerType);
583 void MpVideoServiceCtrlSetPlayerType(int nSetPlayerType)
585 VideoLogInfo("nSetPlayerType : %d", nSetPlayerType);
587 if(MP_ERROR_PLAYER_TYPE < nSetPlayerType || MP_MAX_PLAYER_TYPE > nSetPlayerType)
589 MpVideoServiceCtrlSetPrevPlayerType(nPlayerType);
590 nPlayerType = nSetPlayerType;
594 int MpVideoServiceCtrlGetPrevPlayerType(void)
598 if(MP_ERROR_PLAYER_TYPE > nPlayerType || MP_MAX_PLAYER_TYPE < nPlayerType)
600 nPrevPlayerType = MP_ERROR_PLAYER_TYPE;
603 VideoLogInfo("nPrevPlayerType : %d", nPrevPlayerType);
605 return nPrevPlayerType;
608 void MpVideoServiceCtrlSetPrevPlayerType(int nSetPlayerType)
610 VideoLogInfo("nSetPlayerType : %d", nSetPlayerType);
612 if(MP_ERROR_PLAYER_TYPE < nSetPlayerType || MP_MAX_PLAYER_TYPE > nSetPlayerType)
614 nPrevPlayerType = nSetPlayerType;
618 char* MpVideoServiceCtrlGetCookieForStreaming(void)
622 if(!g_szStreamingCookie)
624 VideoLogInfo("No exist streaming cookie.");
628 return g_szStreamingCookie;