2 * To apply the Flora License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
4 * Copyright [2012] [JongDong Lee <jongdong.lee@samsung.com>, ChangSun Lee <cs78.lee@samsung.com>]
6 * Licensed under the Flora License, Version 1.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.tizenopensource.org/license
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
25 #include "mp-video-log.h"
26 #include "mp-video-service-ctrl.h"
29 #define MP_VIDEO_LAUNCHED_BY_APP_KEY "launching_application"
30 #define MP_VIDEO_SORT_TYPE_KEY "order_type"
31 #define MP_VIDEO_LIST_TYPE_KEY "video_list_type"
32 #define MP_VIDEO_TAG_NAME_KEY "tag_name"
33 #define MP_VIDEO_EDIT_MODE_KEY "edit_mode"
34 #define MP_VIDEO_START_POS_TIME_KEY "start_pos_time"
35 #define MP_VIDEO_URI_PATH "path"
36 #define MP_VIDEO_COOKIE "cookie"
37 #define MP_VIDEO_MULTI_WIN_TYPE_KEY "is_multi_win_type"
38 #define MP_VIDEO_LAUNCH_TYPE "launch-type"
39 #define MP_VIDEO_SHORTCUT_VIDEO "shortcut-videoplayer"
41 static service_h pAppSvcHandle = NULL;
42 static int nPlayerType = MP_NONE_VIEW_TYPE;
43 static int nPrevPlayerType = MP_NONE_VIEW_TYPE;
44 static int nGalleryLatestTime = 0;
45 static char *g_szStreamingCookie = NULL;
46 static bool bIsShortcutType = FALSE;
49 /////////////////////////////////////////////////////////////////////////////
52 bool MpVideoServiceCtrlCheckMime(service_h pVideoServiceHandle, char **szMediaUri)
56 if(!pVideoServiceHandle)
58 VideoLogInfo("[ERR] No Exist Service handle.");
63 char *szMimeContent = NULL;
65 if(service_get_extra_data(pVideoServiceHandle, AUL_K_MIME_CONTENT, &szMimeContent) != SERVICE_ERROR_NONE)
67 VideoLogInfo("No exist mime type.");
73 *szMediaUri = (char*)malloc(strlen(szMimeContent) + 1);
74 memset(*szMediaUri, 0, strlen(szMimeContent) + 1);
75 strncpy(*szMediaUri, szMimeContent, strlen(szMimeContent));
76 VideoLogInfo("Mime content : %s", *szMediaUri);
82 VideoLogInfo("No exist MIME type.");
89 bool MpVideoServiceCtrlCheckBundle(service_h pVideoServiceHandle, char **szMediaUri)
91 if(!pVideoServiceHandle)
93 VideoLogInfo("[ERR] No exist pBundleData pointer or Service handle count value.");
98 char *szStrVideoURI = NULL;
100 if(service_get_extra_data(pVideoServiceHandle, MP_VIDEO_URI_PATH, &szStrVideoURI) != SERVICE_ERROR_NONE)
102 VideoLogInfo("No exist KEY of video/streaming URI.");
109 *szMediaUri = (char*)malloc(strlen(szStrVideoURI) + 1);
110 memset(*szMediaUri, 0, strlen(szStrVideoURI) + 1);
111 strncpy(*szMediaUri, szStrVideoURI, strlen(szStrVideoURI));
112 VideoLogInfo("Video/Streaming URI path : %s", *szMediaUri);
114 szStrVideoURI = NULL;
119 VideoLogInfo("No exist video/streaming URI.");
126 bool MpVideoServiceCtrlCheckAUL(service_h pVideoServiceHandle, char **szMediaUri)
128 if(!pVideoServiceHandle)
130 VideoLogInfo("[ERR] No exist pBundleData pointer or Service handle count value.");
135 char *pGetOperation = NULL;
137 service_get_operation(pVideoServiceHandle, &pGetOperation);
139 if(pGetOperation == NULL)
144 if(!strcmp(SERVICE_OPERATION_VIEW , pGetOperation))
146 char *szStrVideoURI = NULL;
148 service_get_uri(pVideoServiceHandle, &szStrVideoURI);
152 *szMediaUri = (char*)malloc(strlen(szStrVideoURI) + 1);
153 memset(*szMediaUri, 0, strlen(szStrVideoURI) + 1);
154 strncpy(*szMediaUri, szStrVideoURI, strlen(szStrVideoURI));
155 VideoLogInfo("Video/Streaming URI path : %s", *szMediaUri);
157 szStrVideoURI = NULL;
161 VideoLogInfo("[ERR] No exist video/streaming URI.");
166 pGetOperation = NULL;
174 VideoLogInfo("No exist Operation.");
179 pGetOperation = NULL;
185 VideoLogInfo("Video/Streaming URI path pAppData->szMediaUri : %s", *szMediaUri);
190 pGetOperation = NULL;
196 bool MpVideoServiceCtrlIsXMLUrl(char **szMediaUri)
198 VideoLogInfo("URI : %s", *szMediaUri);
200 if (!g_str_has_suffix(*szMediaUri, ".xml")) {
201 VideoLogInfo("No have xml uri.");
208 bool MpVideoServiceCtrlParseUri(service_h pVideoServiceHandle, char** szMediaUri)
212 if(!MpVideoServiceCtrlCheckMime(pVideoServiceHandle, szMediaUri))
214 if(!MpVideoServiceCtrlCheckBundle(pVideoServiceHandle, szMediaUri))
216 if(!MpVideoServiceCtrlCheckAUL(pVideoServiceHandle, szMediaUri))
218 VideoLogInfo("No exist URI path.");
224 VideoLogInfo("szMediaUri : %s", *szMediaUri);
229 int MpVideoServiceCtrlCheckUriType(char* szMediaUri)
233 VideoLogInfo("[ERR] No exist media uri.");
234 return MP_ERROR_PLAYER_TYPE;
241 if(MpUtilCheckUriType(szMediaUri))
243 VideoLogInfo("MP_STREAMING_PLAYER");
244 nRet = MP_STREAMING_PLAYER;
248 VideoLogInfo("MP_VIDEO_PLAYER");
249 nRet = MP_VIDEO_PLAYER;
255 bool MpVideoServiceCtrlCheckCookieForStreaming(service_h pVideoServiceHandle)
257 if(!pVideoServiceHandle)
259 VideoLogInfo("[ERR] No exist pBundleData pointer or Service handle count value.");
264 char *pStrVideoCookie = NULL;
266 if(service_get_extra_data(pVideoServiceHandle, MP_VIDEO_COOKIE, &pStrVideoCookie) != SERVICE_ERROR_NONE)
268 VideoLogInfo("[ERR] No exist KEY of streaming COOKIE.");
274 g_szStreamingCookie = (char*)malloc(strlen(pStrVideoCookie) + 1);
275 memset(g_szStreamingCookie, 0, strlen(pStrVideoCookie) + 1);
276 strncpy(g_szStreamingCookie, pStrVideoCookie, strlen(pStrVideoCookie));
277 VideoLogInfo("Video/Streaming URI path Cookie : %s", g_szStreamingCookie);
278 free(pStrVideoCookie);
282 VideoLogInfo("[ERR] No exist video/streaming URI.");
289 int MpVideoServiceCtrlCheckStartPositionTime(service_h pVideoServiceHandle, char *szBundleKey)
293 if(!pVideoServiceHandle)
295 VideoLogInfo("No exist Service handle data.");
299 int nStartPositionTime = 0;
300 char *szStartPosTime = NULL;
302 if(service_get_extra_data(pVideoServiceHandle, szBundleKey, &szStartPosTime) != SERVICE_ERROR_NONE)
304 VideoLogInfo("No exist mime type.");
310 VideoLogInfo("No exist pointer of position time.");
314 nStartPositionTime = atoi(szStartPosTime);
316 VideoLogInfo("Start position time : %d", nStartPositionTime);
318 free(szStartPosTime);
320 if(nStartPositionTime < 0)
322 nStartPositionTime = 0;
325 return nStartPositionTime;
328 bool MpVideoServiceCtrlGetTagNameOfGallery(service_h pVideoServiceHandle, char *szBundleKey, char *szTagName)
332 if(!pVideoServiceHandle)
334 VideoLogInfo("No exist Service handle.");
340 VideoLogInfo("No exist Service handle kay.");
346 VideoLogInfo("No exist pAppData.");
351 char *szVideoTagName = NULL;
353 if(service_get_extra_data(pVideoServiceHandle, szBundleKey, &szVideoTagName) != SERVICE_ERROR_NONE)
355 VideoLogInfo("No exist mime type.");
361 strncpy(szTagName, szVideoTagName, STR_LEN_MAX - 1);
362 VideoLogInfo("szTagName : %s", szTagName);
363 free(szVideoTagName);
368 VideoLogInfo("No exist pointer of szVideoTagName.");
375 int MpVideoServiceCtrlCheckLauncher(service_h pVideoServiceHandle)
379 if(!pVideoServiceHandle)
381 VideoLogInfo("No exist Service handle data.");
382 return MP_VIDEO_PLAYER_SIMPLE;
385 char *szLaunchingByOtherApp = NULL;
387 if(service_get_extra_data(pVideoServiceHandle, MP_VIDEO_LAUNCHED_BY_APP_KEY, &szLaunchingByOtherApp) != SERVICE_ERROR_NONE)
389 VideoLogInfo("No exist Service handle key of MP_VIDEO_LAUNCHED_BY_APP_KEY");
390 return MP_VIDEO_PLAYER_SIMPLE;
393 if(!szLaunchingByOtherApp)
395 VideoLogInfo("No exist pointer of szLaunchingByOtherApp");
396 return MP_VIDEO_PLAYER_SIMPLE;
399 MpPlayerViewType nTmpLaunchingAppType = MP_VIDEO_PLAYER_SIMPLE;
401 if(!strcmp(szLaunchingByOtherApp, "gallery"))
403 nTmpLaunchingAppType = MP_VIDEO_PLAYER_GALLERY;
405 nGalleryLatestTime = MpVideoServiceCtrlCheckStartPositionTime(pVideoServiceHandle, MP_VIDEO_START_POS_TIME_KEY);
407 else if(!strcmp(szLaunchingByOtherApp, "image_viewer"))
409 nTmpLaunchingAppType = MP_VIDEO_PLAYER_GALLERY;
411 else if(!strcmp(szLaunchingByOtherApp, "email"))
413 nTmpLaunchingAppType = MP_VIDEO_PLAYER_EMAIL;
415 else if(!strcmp(szLaunchingByOtherApp, "message"))
417 nTmpLaunchingAppType = MP_VIDEO_PLAYER_MMS;
419 else if(!strcmp(szLaunchingByOtherApp, "light_play_view"))
421 nTmpLaunchingAppType = MP_VIDEO_PLAYER_SIMPLE;
425 nTmpLaunchingAppType = MP_VIDEO_PLAYER_SIMPLE;
428 VideoLogInfo("Start position time : %d", nTmpLaunchingAppType);
430 free(szLaunchingByOtherApp);
432 return (int)nTmpLaunchingAppType;
435 bool MpVideoServiceCtrlCheckShortcut(service_h pVideoServiceHandle)
437 if(!pVideoServiceHandle)
439 VideoLogInfo("No exist Service handle.");
445 char *pGetOperation = NULL;
447 service_get_operation(pVideoServiceHandle, &pGetOperation);
449 if(pGetOperation == NULL)
451 bIsShortcutType = FALSE;
452 return bIsShortcutType;
455 if(!strcmp(pGetOperation, SERVICE_OPERATION_DEFAULT))
457 char *szOperationType = NULL;
459 if(service_get_extra_data(pVideoServiceHandle, MP_VIDEO_LAUNCH_TYPE, &szOperationType) != SERVICE_ERROR_NONE)
461 VideoLogInfo("No exist Service handle key of MP_VIDEO_LAUNCHED_BY_APP_KEY");
462 bIsShortcutType = FALSE;
467 VideoLogInfo("No exist pointer of szOperationType");
468 bIsShortcutType = FALSE;
472 if(!strcmp(szOperationType, MP_VIDEO_SHORTCUT_VIDEO))
474 bIsShortcutType = TRUE;
478 bIsShortcutType = FALSE;
483 free(szOperationType);
484 szOperationType = NULL;
489 return bIsShortcutType;
494 /////////////////////////////////////////////////////////////////////////////
497 void MpVideoServiceCtrlReset(void)
501 pAppSvcHandle = NULL;
503 nGalleryLatestTime = 0;
505 if(g_szStreamingCookie)
507 free(g_szStreamingCookie);
508 g_szStreamingCookie = NULL;
512 int MpVideoServiceCtrlInitServiceParser(void* pAppServiceHandle, char** szMediaUri)
514 if(!pAppServiceHandle)
517 return MP_ERROR_PLAYER_TYPE;
522 MpVideoServiceCtrlReset();
524 pAppSvcHandle = (service_h)pAppServiceHandle;
525 nPlayerType = MP_NONE_VIEW_TYPE;
527 if(!MpVideoServiceCtrlParseUri(pAppSvcHandle, szMediaUri))
529 VideoLogInfo("MP_VIDEO_PLAYER_LIST");
530 nPlayerType = MP_VIDEO_PLAYER;
539 VideoLogInfo("szMediaUri : %s", *szMediaUri);
544 nUriType = MpVideoServiceCtrlCheckUriType(*szMediaUri);
546 if(nUriType == MP_VIDEO_PLAYER)
548 nPlayerType = MpVideoServiceCtrlCheckLauncher(pAppSvcHandle);
551 if(nUriType == MP_STREAMING_PLAYER)
553 nPlayerType = MP_STREAMING_PLAYER;
554 MpVideoServiceCtrlCheckCookieForStreaming(pAppSvcHandle);
560 int MpVideoServiceCtrlGetLatestTime(void)
564 if(nGalleryLatestTime < 0)
566 nGalleryLatestTime = 0;
569 return nGalleryLatestTime;
572 int MpVideoServiceCtrlGetPlayerTypeWithoutLog(void)
574 if(MP_ERROR_PLAYER_TYPE > nPlayerType || MP_MAX_PLAYER_TYPE < nPlayerType)
576 nPlayerType = MP_ERROR_PLAYER_TYPE;
582 int MpVideoServiceCtrlGetPlayerType(void)
586 if(MP_ERROR_PLAYER_TYPE > nPlayerType || MP_MAX_PLAYER_TYPE < nPlayerType)
588 nPlayerType = MP_ERROR_PLAYER_TYPE;
591 VideoLogInfo("nPlayerType : %d", nPlayerType);
596 void MpVideoServiceCtrlSetPlayerType(int nSetPlayerType)
598 VideoLogInfo("nSetPlayerType : %d", nSetPlayerType);
600 if(MP_ERROR_PLAYER_TYPE < nSetPlayerType || MP_MAX_PLAYER_TYPE > nSetPlayerType)
602 MpVideoServiceCtrlSetPrevPlayerType(nPlayerType);
603 nPlayerType = nSetPlayerType;
607 int MpVideoServiceCtrlGetPrevPlayerType(void)
611 if(MP_ERROR_PLAYER_TYPE > nPlayerType || MP_MAX_PLAYER_TYPE < nPlayerType)
613 nPrevPlayerType = MP_ERROR_PLAYER_TYPE;
616 VideoLogInfo("nPrevPlayerType : %d", nPrevPlayerType);
618 return nPrevPlayerType;
621 void MpVideoServiceCtrlSetPrevPlayerType(int nSetPlayerType)
623 VideoLogInfo("nSetPlayerType : %d", nSetPlayerType);
625 if(MP_ERROR_PLAYER_TYPE < nSetPlayerType || MP_MAX_PLAYER_TYPE > nSetPlayerType)
627 nPrevPlayerType = nSetPlayerType;
631 char* MpVideoServiceCtrlGetCookieForStreaming(void)
635 if(!g_szStreamingCookie)
637 VideoLogInfo("No exist streaming cookie.");
641 return g_szStreamingCookie;