/* * 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 "mp-util.h" #include "mp-video-log.h" #include "video-player.h" #include "mp-drm-ctrl.h" static int nCheckConsumption = VIDEO_DRM_CONSUMPTION_STATE_DISABLE; static drm_file_type_e nDrmFileType = DRM_TYPE_UNDEFINED; #define ACCUMULATED_DATE 86400 /* 24*60*60 */ #define RO_MESSAGE_LEN 1024 #define MOUNTH_COUNT 12 #define DAY_COUNT 30 #define HOUR_COUNT 24 static bool bForwordLock = FALSE; /* * External function */ void MpVideoDrmInit() { VideoLogInfo(""); } bool MpVideoDrmGetForwardLookState() { VideoLogInfo(""); return bForwordLock; } void MpVideoDrmSetConsumptionState(int nState) { VideoLogInfo(""); nCheckConsumption = nState; } int MpVideoDrmGetConsumption() { VideoLogInfo(""); return nCheckConsumption; } void MpVideoDrmStartConsumption(char *szPath) { VideoLogInfo(""); if (MpVideoDrmGetConsumption()) { } else { VideoLogInfo("Disable consumption."); } } void MpVideoDrmPauseConsumption() { VideoLogInfo(""); if (MpVideoDrmGetConsumption()) { } else { VideoLogInfo("Disable consumption."); } } void MpVideoDrmResumeConsumption() { VideoLogInfo(""); if (MpVideoDrmGetConsumption()) { } else { VideoLogInfo("Disable consumption."); } } void MpVideoDrmStopConsumption() { VideoLogInfo(""); if (MpVideoDrmGetConsumption()) { MpVideoDrmSetConsumptionState (VIDEO_DRM_CONSUMPTION_STATE_DISABLE); } else { VideoLogInfo("Disable consumption."); } } bool MpVideoDrmIsDrmFile(char *szPath) { VideoLogInfo(""); if (!szPath) { VideoLogInfo("[ERR]"); return FALSE; } int nRet = DRM_RETURN_SUCCESS; drm_bool_type_e is_drm = DRM_FALSE; nRet = drm_is_drm_file(szPath, &is_drm); if(nRet != DRM_RETURN_SUCCESS) { VideoLogInfo("[ERR]drm_is_drm_file : %d", nRet); return FALSE; } if(is_drm != DRM_TRUE) { VideoLogInfo("It's not drm file."); return FALSE; } drm_file_type_e drm_type = DRM_TYPE_UNDEFINED; nRet = drm_get_file_type(szPath, &drm_type); if(nRet != DRM_RETURN_SUCCESS) { VideoLogInfo("[ERR]drm_get_file_type : %d", nRet); return FALSE; } nDrmFileType = drm_type; if(drm_type != DRM_TYPE_OMA_V1 && drm_type != DRM_TYPE_OMA_V2) { VideoLogInfo("It's not OMA drm file : %d", drm_type); return FALSE; } return TRUE; } bool MpVideoDrmHasValidRo(char *szPath) { VideoLogInfo(""); if (!szPath) { VideoLogInfo("[ERR]"); return FALSE; } int nRet = DRM_RETURN_SUCCESS; drm_license_status_e license_status = DRM_LICENSE_STATUS_UNDEFINED; nRet = drm_get_license_status(szPath, DRM_PERMISSION_TYPE_PLAY, &license_status); if(nRet != DRM_RETURN_SUCCESS) { VideoLogInfo("[ERR]drm_get_license_status : %d", nRet); return FALSE; } if(license_status != DRM_LICENSE_STATUS_VALID) { VideoLogInfo("Invalid license status : %d", license_status); return FALSE; } return TRUE; } bool MpVideoDrmCheckForward(char *szPath) { VideoLogInfo(""); if (!szPath) { VideoLogInfo("[ERR]"); return FALSE; } int nRet = DRM_RETURN_SUCCESS; drm_action_allowed_data_s action_data; drm_bool_type_e is_allow = DRM_FALSE; memset(&action_data, 0, sizeof(drm_action_allowed_data_s)); snprintf(action_data.file_path , DRM_MAX_LEN_FILEPATH, "%s", szPath); nRet = drm_is_action_allowed(DRM_IS_FORWARDING_ALLOWED,&action_data, &is_allow); if(nRet != DRM_RETURN_SUCCESS) { VideoLogInfo("[ERR]drm_is_action_allowed : %d", nRet); bForwordLock = FALSE; return FALSE; } if(is_allow == DRM_TRUE) { bForwordLock = TRUE; return TRUE; } return FALSE; } MpVideoDrmInfo *MpVideoDrmCheckLeftRo(char *szVideoTitle, char *szPath) { VideoLogInfo(""); MpVideoDrmInfo *pResult = NULL; pResult = calloc(1, sizeof(MpVideoDrmInfo)); if (!szVideoTitle) { VideoLogInfo("[ERR] No has video title."); pResult->nErrorCode = MP_VIDEO_DRM_ERROR_INTERNAL; return pResult; } if (!szPath) { VideoLogInfo("[ERR] No has path."); pResult->nErrorCode = MP_VIDEO_DRM_ERROR_INTERNAL; return pResult; } int nRet = DRM_RETURN_SUCCESS; drm_constraint_info_s constraint_info; memset(&constraint_info, 0, sizeof(drm_constraint_info_s)); nRet = drm_get_constraint_info(szPath, DRM_PERMISSION_TYPE_PLAY, &constraint_info); if(nRet != DRM_RETURN_SUCCESS) { VideoLogInfo("[ERR]drm_get_file_info : %d", nRet); pResult->nErrorCode = MP_VIDEO_DRM_ERROR_INTERNAL; return pResult; } if(constraint_info.const_type.is_unlimited) { VideoLogInfo("Unlimited DRM Contents"); pResult->nErrorCode = MP_VIDEO_DRM_ERROR_NONE; return pResult; } else if(constraint_info.const_type.is_count) { if(constraint_info.remaining_count <= 0) { VideoLogInfo("Count expired : %d / %d", constraint_info.remaining_count, constraint_info.original_count); pResult->nErrorCode = MP_VIDEO_DRM_ERROR_COUNT; pResult->nData = constraint_info.remaining_count; return pResult; } else if(constraint_info.remaining_count == 1 || constraint_info.remaining_count == 2) { VideoLogInfo("Count Small : %d / %d", constraint_info.remaining_count, constraint_info.original_count); pResult->nErrorCode = MP_VIDEO_DRM_ERROR_COUNT_SMALL; pResult->nData = constraint_info.remaining_count; return pResult; } else { VideoLogInfo("Count valid : %d / %d", constraint_info.remaining_count, constraint_info.original_count); pResult->nErrorCode = MP_VIDEO_DRM_ERROR_NONE; pResult->nData = constraint_info.remaining_count; return pResult; } } else if(constraint_info.const_type.is_datetime) { VideoLogInfo("Start time: Year=%d,Month=%d,Day=%d," "Hour=%d, minute=%d, Second=%d", constraint_info.start_time.tm_year, constraint_info.start_time.tm_mon, constraint_info.start_time.tm_mday, constraint_info.start_time.tm_hour, constraint_info.start_time.tm_min, constraint_info.start_time.tm_sec); VideoLogInfo("End time: Year=%d,Month=%d,Day=%d," "Hour=%d, minute=%d, Second=%d", constraint_info.end_time.tm_year, constraint_info.end_time.tm_mon, constraint_info.end_time.tm_mday, constraint_info.end_time.tm_hour, constraint_info.end_time.tm_min, constraint_info.end_time.tm_sec); pResult->nErrorCode = MP_VIDEO_DRM_ERROR_NONE; return pResult; } else if(constraint_info.const_type.is_interval) { VideoLogInfo("Interval time: Year=%d,Month=%d,Day=%d," "Hour=%d, minute=%d, Second=%d", constraint_info.interval_time.tm_year, constraint_info.interval_time.tm_mon, constraint_info.interval_time.tm_mday, constraint_info.interval_time.tm_hour, constraint_info.interval_time.tm_min, constraint_info.interval_time.tm_sec); pResult->nErrorCode = MP_VIDEO_DRM_ERROR_INTERVAL_FIRST_USE; pResult->nData = ((constraint_info.interval_time.tm_year * MOUNTH_COUNT + constraint_info.interval_time.tm_mon) * DAY_COUNT + constraint_info.interval_time.tm_mday); return pResult; } else if(constraint_info.const_type.is_timedcount) { VideoLogInfo("DRM TimeCount " "(original : %d, remainnig : %d, count_timer: %d)", constraint_info.timed_original_count, constraint_info.timed_remaining_count, constraint_info.timed_count_timer); pResult->nErrorCode = MP_VIDEO_DRM_ERROR_NONE; return pResult; } else if(constraint_info.const_type.is_accumulated) { pResult->nErrorCode = MP_VIDEO_DRM_ERROR_ACCUMULATED; return pResult; } else if(constraint_info.const_type.is_individual) { pResult->nErrorCode = MP_VIDEO_DRM_ERROR_NONE; return pResult; } else if(constraint_info.const_type.is_system) { pResult->nErrorCode = MP_VIDEO_DRM_ERROR_NONE; return pResult; } return pResult; } bool MpVideoDrmIsDivX(char *szPath) { VideoLogInfo(""); if (!szPath) { VideoLogInfo("[ERR]"); return FALSE; } int nRet = DRM_RETURN_SUCCESS; drm_bool_type_e is_drm = DRM_FALSE; nRet = drm_is_drm_file(szPath, &is_drm); if(nRet != DRM_RETURN_SUCCESS) { VideoLogInfo("[ERR]drm_is_drm_file : %d", nRet); return FALSE; } if(is_drm != DRM_TRUE) { VideoLogInfo("It's not drm file."); return FALSE; } drm_file_type_e drm_type = DRM_TYPE_UNDEFINED; nRet = drm_get_file_type(szPath, &drm_type); if(nRet != DRM_RETURN_SUCCESS) { VideoLogInfo("[ERR]drm_get_file_type : %d", nRet); return FALSE; } nDrmFileType = drm_type; if(drm_type != DRM_TYPE_DIVX ) { VideoLogInfo("It's not DivX drm file : %d", drm_type); return FALSE; } return TRUE; } bool MpVideoDrmCheckDivX(char *szPath) { VideoLogInfo(""); if (!szPath) { VideoLogInfo("[ERR]"); return FALSE; } return TRUE; } void MpVideoDrmGetFileExtension(char *szPath, char *szContentType, int nContentTypeStrSize) { if (!szContentType) { VideoLogInfo("[ERR]"); return; } if (!szPath) { VideoLogInfo("[ERR]"); return; } memset(szContentType, 0, nContentTypeStrSize); drm_content_info_s content_info; int nRet = DRM_RETURN_SUCCESS; memset(&content_info, 0, sizeof(drm_content_info_s)); nRet = drm_get_content_info(szPath,&content_info); VideoLogInfo("contentType: %s", content_info.mime_type); strncpy(szContentType, content_info.mime_type, nContentTypeStrSize - 1); }