/* * 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 #include "mp-util.h" #include "mp-video-log.h" #include "video-player.h" #include "mp-video-type-define.h" #include "mp-video-string-define.h" #include "mp-video-streaming-ctrl.h" #define NETWORK_TIMEOUT 30.0 static MpNetworkType nNetworkStatus = MP_NETWORK_TYPE_OFF; static MpNetworkWifiState nWifiState = MP_NETWORK_WIFI_OFF; static MpNetworkCellularState nCellularState = MP_NETWORK_CELLULAR_NO_SERVICE; static Ecore_Pipe *pEcorePipeHandleForPause = NULL; static Ecore_Pipe *pEcorePipeHandleForResume = NULL; static Eina_Bool bIsInitCallbackFunc = FALSE; static Ecore_Timer *pNetworkTimeoutTimer = NULL; /* * Callback function. */ static void MpVideoStreamingCtrlExitCb(void *pUserData, Evas_Object *pObject, void *pEventInfo) { if (!pUserData) { VideoLogInfo("No exist pUserData"); return; } VideoLogInfo(""); VideoAppData *pAppData = (VideoAppData *)pUserData; pAppData->VideoAppCtrlCallbackFunc.VideoAppCtrlExit(pAppData); } static int MpVideoStreamingCtrlResumeCb(void *pUserData) { VideoLogInfo(""); if (!pUserData) { VideoLogInfo("No exist pUserData"); return 0; } VideoAppData *pAppData = (VideoAppData *)pUserData; if (pNetworkTimeoutTimer) { ecore_timer_del(pNetworkTimeoutTimer); pNetworkTimeoutTimer = NULL; } pAppData->VideoAppCtrlCallbackFunc.VideoAppCtrlStopByAppPause(pAppData); pAppData->VideoAppCtrlCallbackFunc.VideoAppCtrlStartByAppResume(pAppData); return 0; } static Eina_Bool MpVideoStreamingCtrlPopupCb(void *pUserData) { VideoLogInfo(""); if (!pUserData) { VideoLogInfo("No exist pUserData"); return EINA_FALSE; } VideoAppData *pAppData = (VideoAppData *)pUserData; if (pNetworkTimeoutTimer) { ecore_timer_del(pNetworkTimeoutTimer); pNetworkTimeoutTimer = NULL; } MpUtilNotifyPopUp(pAppData, MP_COM_CONNECTION_FAIL, MpVideoStreamingCtrlExitCb); return EINA_FALSE; } static int MpVideoStreamingCtrlPauseCb(void *pUserData) { VideoLogInfo(""); if (!pUserData) { VideoLogInfo("No exist pUserData"); return 0; } VideoAppData *pAppData = (VideoAppData *)pUserData; pAppData->VideoAppCtrlCallbackFunc.VideoAppCtrlStopByAppPause(pAppData); if (pNetworkTimeoutTimer) { ecore_timer_del(pNetworkTimeoutTimer); pNetworkTimeoutTimer = NULL; } pNetworkTimeoutTimer = ecore_timer_add(NETWORK_TIMEOUT, MpVideoStreamingCtrlPopupCb, pAppData); return 0; } static void MpVideoStreamingCtrlNetworkOnOffCb(keynode_t *pKeyNode,void *pUserData) { VideoLogInfo(""); if (!pUserData || !pKeyNode) { VideoLogInfo("User data is NULL."); return; } char *szkeyname = NULL; szkeyname = vconf_keynode_get_name(pKeyNode); if (!strcmp(szkeyname, VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND)) { switch(vconf_keynode_get_int(pKeyNode)) { case MP_NETWORK_CLOSE: VideoLogInfo("MP_NETWORK_CLOSE"); if(pEcorePipeHandleForPause) { if(!ecore_pipe_write(pEcorePipeHandleForPause, pUserData, sizeof(VideoAppData))) { VideoLogDebug("FAIL PIPE WRITE"); } } break; case MP_NETWORK_ON: VideoLogInfo("MP_NETWORK_ON"); if(pEcorePipeHandleForResume) { if(!ecore_pipe_write(pEcorePipeHandleForResume, pUserData, sizeof(VideoAppData))) { VideoLogDebug("FAIL PIPE WRITE"); } } break; default: VideoLogInfo("UNKNOWN NETWORK CONFIG"); break; } } else { } } static void MpVideoStreamingCtrlNetworkStatusCb(keynode_t *pKeyNode,void *pUserData) { if (!pUserData || !pKeyNode) { VideoLogInfo("User data is NULL."); return; } VideoLogInfo(""); char *szkeyname = NULL; szkeyname = vconf_keynode_get_name(pKeyNode); if (!strcmp(szkeyname, VCONFKEY_NETWORK_STATUS)) { switch(vconf_keynode_get_int(pKeyNode)) { case VCONFKEY_NETWORK_OFF: nNetworkStatus = MP_NETWORK_TYPE_OFF; VideoLogInfo("MP_NETWORK_TYPE_OFF"); /* if(pEcorePipeHandleForPause) { if(!ecore_pipe_write(pEcorePipeHandleForPause, pUserData, sizeof(VideoAppData))) { VideoLogDebug("FAIL PIPE WRITE"); } } */ break; case VCONFKEY_NETWORK_CELLULAR: VideoLogInfo("MP_NETWORK_TYPE_CELLULAR"); /* if(pEcorePipeHandleForResume) { if(!ecore_pipe_write(pEcorePipeHandleForResume, pUserData, sizeof(VideoAppData))) { VideoLogDebug("FAIL PIPE WRITE"); } } nNetworkStatus = MP_NETWORK_TYPE_CELLULAR; */ break; case VCONFKEY_NETWORK_WIFI: VideoLogInfo("MP_NETWORK_TYPE_WIFI"); /* if(pEcorePipeHandleForResume) { if(!ecore_pipe_write(pEcorePipeHandleForResume, pUserData, sizeof(VideoAppData))) { VideoLogDebug("FAIL PIPE WRITE"); } } nNetworkStatus = MP_NETWORK_TYPE_WIFI; */ break; default: nNetworkStatus = MP_NETWORK_TYPE_OFF; VideoLogInfo("UNKNOWN NETWORK STATE"); if(pEcorePipeHandleForPause) { if(!ecore_pipe_write(pEcorePipeHandleForPause, pUserData, sizeof(VideoAppData))) { VideoLogDebug("FAIL PIPE WRITE"); } } break; } } else { if(pEcorePipeHandleForPause) { if(!ecore_pipe_write(pEcorePipeHandleForPause, pUserData, sizeof(VideoAppData))) { VideoLogDebug("FAIL PIPE WRITE"); } } } } static void MpVideoStreamingCtrlChangeIpCb(keynode_t *pKeyNode, void *pUserData) { VideoLogInfo(""); if (!pUserData || !pKeyNode) { VideoLogInfo("User data is NULL."); return; } char *szkeyname = NULL; char *szTmp = NULL; szkeyname = vconf_keynode_get_name(pKeyNode); if(szkeyname == NULL) { VideoLogInfo("key name value is NULL"); return; } if (!strcmp(szkeyname, VCONFKEY_NETWORK_IP)) { szTmp = vconf_keynode_get_str(pKeyNode); if(szTmp == NULL) { VideoLogInfo("node string value is NULL"); return; } VideoLogInfo("Network ip address : %s", szTmp); } else { VideoLogInfo("Invalid ip address."); } } static void MpVideoStreamingCtrlWiFiStateCb(keynode_t *pKeyNode, void *pUserData) { VideoLogInfo(""); if (!pUserData || !pKeyNode) { VideoLogInfo("User data is NULL."); return; } char *szkeyname = NULL; szkeyname = vconf_keynode_get_name(pKeyNode); if (!strcmp(szkeyname, VCONFKEY_NETWORK_WIFI_STATE)) { switch(vconf_keynode_get_int(pKeyNode)) { case VCONFKEY_NETWORK_WIFI_OFF: nWifiState = MP_NETWORK_WIFI_OFF; VideoLogInfo("MP_NETWORK_WIFI_OFF"); break; case VCONFKEY_NETWORK_WIFI_NOT_CONNECTED: nWifiState = MP_NETWORK_WIFI_NOT_CONNECTED; VideoLogInfo("MP_NETWORK_WIFI_NOT_CONNECTED"); break; case VCONFKEY_NETWORK_WIFI_CONNECTED: nWifiState = MP_NETWORK_WIFI_CONNECTED; VideoLogInfo("MP_NETWORK_WIFI_CONNECTED"); break; default: nWifiState = MP_NETWORK_WIFI_OFF; VideoLogInfo("MP_NETWORK_WIFI_OFF - default"); break; } } else { nWifiState = MP_NETWORK_WIFI_OFF; VideoLogInfo("MP_NETWORK_WIFI_OFF - invalid value"); } } static void MpVideoStreamingCtrlCellularStateCb(keynode_t *pKeyNode,void *pUserData) { VideoLogInfo(""); if (!pUserData || !pKeyNode) { VideoLogInfo("User data is NULL."); return; } char *szkeyname = NULL; szkeyname = vconf_keynode_get_name(pKeyNode); if (!strcmp(szkeyname, VCONFKEY_NETWORK_CELLULAR_STATE)) { switch(vconf_keynode_get_int(pKeyNode)) { case VCONFKEY_NETWORK_CELLULAR_ON: nCellularState = MP_NETWORK_CELLULAR_ON; VideoLogInfo("MP_NETWORK_CELLULAR_ON"); break; case VCONFKEY_NETWORK_CELLULAR_3G_OPTION_OFF: nCellularState = MP_NETWORK_CELLULAR_3G_OPTION_OFF; VideoLogInfo("MP_NETWORK_CELLULAR_3G_OPTION_OFF"); break; case VCONFKEY_NETWORK_CELLULAR_ROAMING_OFF: nCellularState = MP_NETWORK_CELLULAR_ROAMING_OFF; VideoLogInfo("MP_NETWORK_CELLULAR_ROAMING_OFF"); break; case VCONFKEY_NETWORK_CELLULAR_FLIGHT_MODE: nCellularState = MP_NETWORK_CELLULAR_FLIGHT_MODE; VideoLogInfo("MP_NETWORK_CELLULAR_FLIGHT_MODE"); break; case VCONFKEY_NETWORK_CELLULAR_NO_SERVICE : nCellularState = MP_NETWORK_CELLULAR_NO_SERVICE; VideoLogInfo("MP_NETWORK_CELLULAR_NO_SERVICE"); break; default: nCellularState = MP_NETWORK_CELLULAR_NO_SERVICE; VideoLogInfo("MP_NETWORK_CELLULAR_NO_SERVICE - default"); break; } } else { nCellularState = MP_NETWORK_CELLULAR_NO_SERVICE; VideoLogInfo("MP_NETWORK_CELLULAR_NO_SERVICE - invalid value"); } } static void MpVideoStreamingCtrlPipeInit(void *pUserData) { VideoLogInfo(""); if (!pUserData) { VideoLogInfo("No exist pUserData"); return; } VideoAppData *pAppData = (VideoAppData *)pUserData; if(pEcorePipeHandleForPause) { ecore_pipe_del(pEcorePipeHandleForPause); pEcorePipeHandleForPause = NULL; } pEcorePipeHandleForPause = ecore_pipe_add( (Ecore_Pipe_Cb)MpVideoStreamingCtrlPauseCb, (void *)pAppData); if(pEcorePipeHandleForResume) { ecore_pipe_del(pEcorePipeHandleForResume); pEcorePipeHandleForResume = NULL; } pEcorePipeHandleForResume = ecore_pipe_add( (Ecore_Pipe_Cb)MpVideoStreamingCtrlResumeCb, (void *)pAppData); } /* * Internal function. */ bool MpVideoStreamingCtrlSetNotifyNetworkOnOff(void *pUserData) { if (!pUserData) { VideoLogInfo("[ERR] No exist pUserData."); return FALSE; } VideoLogInfo(""); VideoAppData *pAppData = (VideoAppData *)pUserData; int nRet = 0; nRet = vconf_notify_key_changed(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, MpVideoStreamingCtrlNetworkOnOffCb, (void*)pAppData); if (nRet < 0) { VideoLogInfo("[ERR] Fail to set network on/off notification."); return FALSE; } return TRUE; } bool MpVideoStreamingCtrlSetNotifyNetworkStatus(void *pUserData) { if (!pUserData) { VideoLogInfo("[ERR] No exist pUserData."); return FALSE; } VideoLogInfo(""); VideoAppData *pAppData = (VideoAppData *)pUserData; int nRet = 0; nRet = vconf_notify_key_changed(VCONFKEY_NETWORK_STATUS, MpVideoStreamingCtrlNetworkStatusCb, (void*)pAppData); if (nRet < 0) { VideoLogInfo("[ERR] Fail to set network status notification."); return FALSE; } return TRUE; } bool MpVideoStreamingCtrlSetNotifyChangingIp(void *pUserData) { if (!pUserData) { VideoLogInfo("[ERR] No exist pUserData."); return FALSE; } VideoLogInfo(""); VideoAppData *pAppData = (VideoAppData *)pUserData; int nRet = 0; nRet = vconf_notify_key_changed(VCONFKEY_NETWORK_IP, MpVideoStreamingCtrlChangeIpCb, (void*)pAppData); if (nRet < 0) { VideoLogInfo("[ERR] Fail to set ip address changing notification."); return FALSE; } return TRUE; } bool MpVideoStreamingCtrlSetNotifyWiFiState(void *pUserData) { if (!pUserData) { VideoLogInfo("[ERR] No exist pUserData."); return FALSE; } VideoLogInfo(""); VideoAppData *pAppData = (VideoAppData *)pUserData; int nRet = 0; nRet = vconf_notify_key_changed(VCONFKEY_NETWORK_WIFI_STATE, MpVideoStreamingCtrlWiFiStateCb, (void*)pAppData); if (nRet < 0) { VideoLogInfo("[ERR] Fail to set wifi state notification."); return FALSE; } return TRUE; } bool MpVideoStreamingCtrlSetNotifyCellularState(void *pUserData) { if (!pUserData) { VideoLogInfo("[ERR] No exist pUserData."); return FALSE; } VideoLogInfo(""); VideoAppData *pAppData = (VideoAppData *)pUserData; int nRet = 0; nRet = vconf_notify_key_changed(VCONFKEY_NETWORK_CELLULAR_STATE, MpVideoStreamingCtrlCellularStateCb, (void*)pAppData); if (nRet < 0) { VideoLogInfo("[ERR] Fail to set cellular notification."); return FALSE; } return TRUE; } /* * External function. */ bool MpVideoStreamingCtrlGetIpAddress(char* szRetIpAddress) { VideoLogInfo(""); char *szTmp = NULL; szTmp = vconf_get_str(VCONFKEY_NETWORK_IP); if (szTmp) { memset(szRetIpAddress, 0, sizeof(char) * STR_LEN_MAX); strncpy(szRetIpAddress, szTmp, STR_LEN_MAX - 1); VideoLogInfo("Current network ip address : %s", szRetIpAddress); if(szTmp) free(szTmp); return TRUE; } return FALSE; } bool MpVideoStreamingCtrlGetProxy(char* szRetProxy) { VideoLogInfo(""); char *szTmp = NULL; szTmp = vconf_get_str(VCONFKEY_NETWORK_PROXY); if (szTmp) { memset(szRetProxy, 0, sizeof(char) * STR_LEN_MAX); strncpy(szRetProxy, szTmp, STR_LEN_MAX - 1); VideoLogInfo("Current network ip address : %s", szRetProxy); if(szTmp) free(szTmp); return TRUE; } return FALSE; } bool MpVideoStreamingCtrlIsNetworkOn(void) { VideoLogInfo(""); int ntmpCheckNetworkON = 0; if (!vconf_get_int(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, &ntmpCheckNetworkON)) { switch(ntmpCheckNetworkON) { case MP_NETWORK_CLOSE: VideoLogInfo("Network close."); return FALSE; case MP_NETWORK_ON: VideoLogInfo("Network on."); return TRUE; } } else { VideoLogInfo("Network close."); } return FALSE; } int MpVideoStreamingCtrlGetNetworkStatus(void) { VideoLogInfo(""); int ntmpGetNetworkStatus = 0; if (!vconf_get_int(VCONFKEY_NETWORK_STATUS, &ntmpGetNetworkStatus)) { switch(ntmpGetNetworkStatus) { case VCONFKEY_NETWORK_OFF: nNetworkStatus = MP_NETWORK_TYPE_OFF; VideoLogInfo("MP_NETWORK_TYPE_OFF"); break; case VCONFKEY_NETWORK_CELLULAR: nNetworkStatus = MP_NETWORK_TYPE_CELLULAR; VideoLogInfo("MP_NETWORK_TYPE_CELLULAR"); break; case VCONFKEY_NETWORK_WIFI: nNetworkStatus = MP_NETWORK_TYPE_WIFI; VideoLogInfo("MP_NETWORK_TYPE_WIFI"); break; default: nNetworkStatus = MP_NETWORK_TYPE_OFF; VideoLogInfo("MP_NETWORK_TYPE_OFF - default"); break; } } else { nNetworkStatus = MP_NETWORK_TYPE_OFF; VideoLogInfo("MP_NETWORK_TYPE_OFF - invalid value"); } return nNetworkStatus; } int MpVideoStreamingCtrlGetWifiState() { VideoLogInfo(""); int ntmpGetWifiState = 0; if (!vconf_get_int(VCONFKEY_NETWORK_WIFI_STATE, &ntmpGetWifiState)) { switch(ntmpGetWifiState) { case VCONFKEY_NETWORK_WIFI_OFF: nWifiState = MP_NETWORK_WIFI_OFF; VideoLogInfo("MP_NETWORK_WIFI_OFF"); break; case VCONFKEY_NETWORK_WIFI_NOT_CONNECTED: nWifiState = MP_NETWORK_WIFI_NOT_CONNECTED; VideoLogInfo("MP_NETWORK_WIFI_NOT_CONNECTED"); break; case VCONFKEY_NETWORK_WIFI_CONNECTED: nWifiState = MP_NETWORK_WIFI_CONNECTED; VideoLogInfo("MP_NETWORK_WIFI_CONNECTED"); break; default: nWifiState = MP_NETWORK_WIFI_OFF; VideoLogInfo("MP_NETWORK_WIFI_OFF - default"); break; } } else { nWifiState = MP_NETWORK_WIFI_OFF; VideoLogInfo("MP_NETWORK_WIFI_OFF - invalid value"); } return nWifiState; } int MpVideoStreamingCtrlGetCellularState() { VideoLogInfo(""); int ntmpGetCellularState = 0; if (!vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &ntmpGetCellularState)) { switch(ntmpGetCellularState) { case VCONFKEY_NETWORK_CELLULAR_ON: nCellularState = MP_NETWORK_CELLULAR_ON; VideoLogInfo("MP_NETWORK_CELLULAR_ON"); break; case VCONFKEY_NETWORK_CELLULAR_3G_OPTION_OFF: nCellularState = MP_NETWORK_CELLULAR_3G_OPTION_OFF; VideoLogInfo("MP_NETWORK_CELLULAR_3G_OPTION_OFF"); break; case VCONFKEY_NETWORK_CELLULAR_ROAMING_OFF: nCellularState = MP_NETWORK_CELLULAR_ROAMING_OFF; VideoLogInfo("MP_NETWORK_CELLULAR_ROAMING_OFF"); break; case VCONFKEY_NETWORK_CELLULAR_FLIGHT_MODE: nCellularState = MP_NETWORK_CELLULAR_FLIGHT_MODE; VideoLogInfo("MP_NETWORK_CELLULAR_FLIGHT_MODE"); break; case VCONFKEY_NETWORK_CELLULAR_NO_SERVICE : nCellularState = MP_NETWORK_CELLULAR_NO_SERVICE; VideoLogInfo("MP_NETWORK_CELLULAR_NO_SERVICE"); break; default: nCellularState = MP_NETWORK_CELLULAR_NO_SERVICE; VideoLogInfo("MP_NETWORK_CELLULAR_NO_SERVICE - default"); break; } } else { nCellularState = MP_NETWORK_CELLULAR_NO_SERVICE; VideoLogInfo("MP_NETWORK_CELLULAR_NO_SERVICE - invalid value"); } return nCellularState; } void MpVideoStreamingCtrlDestroy(void *pUserData) { VideoLogInfo(""); if (pNetworkTimeoutTimer) { ecore_timer_del(pNetworkTimeoutTimer); pNetworkTimeoutTimer = NULL; } if(pEcorePipeHandleForPause) { ecore_pipe_del(pEcorePipeHandleForPause); pEcorePipeHandleForPause = NULL; } if(pEcorePipeHandleForResume) { ecore_pipe_del(pEcorePipeHandleForResume); pEcorePipeHandleForResume = NULL; } } bool MpVideoStreamingCtrlInit(void *pUserData) { if (!pUserData) { VideoLogInfo("[ERR] No exist pUserData."); return FALSE; } VideoLogInfo(""); VideoAppData *pAppData = (VideoAppData *)pUserData; char szTmp[STR_LEN_MAX] = {0}; bool bNetworkState = FALSE; if(bIsInitCallbackFunc == EINA_FALSE) { MpVideoStreamingCtrlPipeInit(pUserData); MpVideoStreamingCtrlSetNotifyNetworkStatus(pUserData); MpVideoStreamingCtrlSetNotifyChangingIp(pUserData); MpVideoStreamingCtrlSetNotifyWiFiState(pUserData); MpVideoStreamingCtrlSetNotifyCellularState(pUserData); bIsInitCallbackFunc = EINA_TRUE; } if (pNetworkTimeoutTimer) { ecore_timer_del(pNetworkTimeoutTimer); pNetworkTimeoutTimer = NULL; } switch(MpVideoStreamingCtrlGetNetworkStatus()) { case MP_NETWORK_TYPE_OFF: VideoLogInfo("MP_NETWORK_TYPE_OFF"); pNetworkTimeoutTimer = ecore_timer_add(NETWORK_TIMEOUT, MpVideoStreamingCtrlPopupCb, pAppData); bNetworkState = FALSE; break; case MP_NETWORK_TYPE_CELLULAR: VideoLogInfo("MP_NETWORK_TYPE_CELLULAR"); if(MpVideoStreamingCtrlGetCellularState() == MP_NETWORK_CELLULAR_ON) bNetworkState = TRUE; break; case MP_NETWORK_TYPE_WIFI: VideoLogInfo("MP_NETWORK_TYPE_WIFI"); if(MpVideoStreamingCtrlGetWifiState() == MP_NETWORK_WIFI_CONNECTED) bNetworkState = TRUE; break; } if(bNetworkState) { MpVideoStreamingCtrlGetIpAddress(szTmp); VideoLogInfo("Current IP Address : %s", szTmp); memset(szTmp, 0, STR_LEN_MAX); MpVideoStreamingCtrlGetProxy(szTmp); VideoLogInfo("Current Proxy Address : %s", szTmp); memset(pAppData->szProxyAddress, 0, STR_LEN_MAX); strncpy(pAppData->szProxyAddress, szTmp, STR_LEN_MAX - 1); } return bNetworkState; }