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.
18 #include <drm_client.h>
19 #include <drm_client_types.h>
23 #include "mp-video-log.h"
24 #include "video-player.h"
25 #include "mp-drm-ctrl.h"
27 static int nCheckConsumption = VIDEO_DRM_CONSUMPTION_STATE_DISABLE;
29 static drm_file_type_e nDrmFileType = DRM_TYPE_UNDEFINED;
31 #define ACCUMULATED_DATE 86400 /* 24*60*60 */
32 #define RO_MESSAGE_LEN 1024
34 #define MOUNTH_COUNT 12
38 static bool bForwordLock = FALSE;
47 bool MpVideoDrmGetForwardLookState()
54 void MpVideoDrmSetConsumptionState(int nState)
58 nCheckConsumption = nState;
61 int MpVideoDrmGetConsumption()
65 return nCheckConsumption;
68 void MpVideoDrmStartConsumption(char *szPath)
73 if (MpVideoDrmGetConsumption()) {
76 VideoLogInfo("Disable consumption.");
80 void MpVideoDrmPauseConsumption()
84 if (MpVideoDrmGetConsumption()) {
86 VideoLogInfo("Disable consumption.");
90 void MpVideoDrmResumeConsumption()
94 if (MpVideoDrmGetConsumption()) {
96 VideoLogInfo("Disable consumption.");
100 void MpVideoDrmStopConsumption()
104 if (MpVideoDrmGetConsumption()) {
105 MpVideoDrmSetConsumptionState (VIDEO_DRM_CONSUMPTION_STATE_DISABLE);
107 VideoLogInfo("Disable consumption.");
111 bool MpVideoDrmIsDrmFile(char *szPath)
116 VideoLogInfo("[ERR]");
119 int nRet = DRM_RETURN_SUCCESS;
120 drm_bool_type_e is_drm = DRM_FALSE;
122 nRet = drm_is_drm_file(szPath, &is_drm);
123 if(nRet != DRM_RETURN_SUCCESS) {
124 VideoLogInfo("[ERR]drm_is_drm_file : %d", nRet);
128 if(is_drm != DRM_TRUE) {
129 VideoLogInfo("It's not drm file.");
134 drm_file_type_e drm_type = DRM_TYPE_UNDEFINED;
136 nRet = drm_get_file_type(szPath, &drm_type);
137 if(nRet != DRM_RETURN_SUCCESS) {
138 VideoLogInfo("[ERR]drm_get_file_type : %d", nRet);
142 nDrmFileType = drm_type;
144 if(drm_type != DRM_TYPE_OMA_V1 && drm_type != DRM_TYPE_OMA_V2) {
145 VideoLogInfo("It's not OMA drm file : %d", drm_type);
152 bool MpVideoDrmHasValidRo(char *szPath)
157 VideoLogInfo("[ERR]");
161 int nRet = DRM_RETURN_SUCCESS;
162 drm_license_status_e license_status = DRM_LICENSE_STATUS_UNDEFINED;
163 nRet = drm_get_license_status(szPath, DRM_PERMISSION_TYPE_PLAY, &license_status);
164 if(nRet != DRM_RETURN_SUCCESS) {
165 VideoLogInfo("[ERR]drm_get_license_status : %d", nRet);
169 if(license_status != DRM_LICENSE_STATUS_VALID) {
170 VideoLogInfo("Invalid license status : %d", license_status);
177 bool MpVideoDrmCheckForward(char *szPath)
182 VideoLogInfo("[ERR]");
186 int nRet = DRM_RETURN_SUCCESS;
187 drm_action_allowed_data_s action_data;
188 drm_bool_type_e is_allow = DRM_FALSE;
189 memset(&action_data, 0, sizeof(drm_action_allowed_data_s));
190 snprintf(action_data.file_path , DRM_MAX_LEN_FILEPATH, "%s", szPath);
192 nRet = drm_is_action_allowed(DRM_IS_FORWARDING_ALLOWED,&action_data, &is_allow);
193 if(nRet != DRM_RETURN_SUCCESS) {
194 VideoLogInfo("[ERR]drm_is_action_allowed : %d", nRet);
195 bForwordLock = FALSE;
199 if(is_allow == DRM_TRUE) {
207 MpVideoDrmInfo *MpVideoDrmCheckLeftRo(char *szVideoTitle, char *szPath)
210 MpVideoDrmInfo *pResult = NULL;
211 pResult = calloc(1, sizeof(MpVideoDrmInfo));
214 VideoLogInfo("[ERR] No has video title.");
215 pResult->nErrorCode = MP_VIDEO_DRM_ERROR_INTERNAL;
220 VideoLogInfo("[ERR] No has path.");
221 pResult->nErrorCode = MP_VIDEO_DRM_ERROR_INTERNAL;
227 int nRet = DRM_RETURN_SUCCESS;
228 drm_constraint_info_s constraint_info;
229 memset(&constraint_info, 0, sizeof(drm_constraint_info_s));
230 nRet = drm_get_constraint_info(szPath, DRM_PERMISSION_TYPE_PLAY, &constraint_info);
231 if(nRet != DRM_RETURN_SUCCESS) {
232 VideoLogInfo("[ERR]drm_get_file_info : %d", nRet);
233 pResult->nErrorCode = MP_VIDEO_DRM_ERROR_INTERNAL;
237 if(constraint_info.const_type.is_unlimited) {
238 VideoLogInfo("Unlimited DRM Contents");
239 pResult->nErrorCode = MP_VIDEO_DRM_ERROR_NONE;
242 else if(constraint_info.const_type.is_count) {
243 if(constraint_info.remaining_count <= 0) {
244 VideoLogInfo("Count expired : %d / %d",
245 constraint_info.remaining_count,
246 constraint_info.original_count);
247 pResult->nErrorCode = MP_VIDEO_DRM_ERROR_COUNT;
248 pResult->nData = constraint_info.remaining_count;
251 else if(constraint_info.remaining_count == 1 ||
252 constraint_info.remaining_count == 2) {
253 VideoLogInfo("Count Small : %d / %d",
254 constraint_info.remaining_count,
255 constraint_info.original_count);
256 pResult->nErrorCode = MP_VIDEO_DRM_ERROR_COUNT_SMALL;
257 pResult->nData = constraint_info.remaining_count;
261 VideoLogInfo("Count valid : %d / %d",
262 constraint_info.remaining_count,
263 constraint_info.original_count);
264 pResult->nErrorCode = MP_VIDEO_DRM_ERROR_NONE;
265 pResult->nData = constraint_info.remaining_count;
269 else if(constraint_info.const_type.is_datetime) {
270 VideoLogInfo("Start time: Year=%d,Month=%d,Day=%d,"
271 "Hour=%d, minute=%d, Second=%d",
272 constraint_info.start_time.tm_year,
273 constraint_info.start_time.tm_mon,
274 constraint_info.start_time.tm_mday,
275 constraint_info.start_time.tm_hour,
276 constraint_info.start_time.tm_min,
277 constraint_info.start_time.tm_sec);
280 VideoLogInfo("End time: Year=%d,Month=%d,Day=%d,"
281 "Hour=%d, minute=%d, Second=%d",
282 constraint_info.end_time.tm_year,
283 constraint_info.end_time.tm_mon,
284 constraint_info.end_time.tm_mday,
285 constraint_info.end_time.tm_hour,
286 constraint_info.end_time.tm_min,
287 constraint_info.end_time.tm_sec);
289 pResult->nErrorCode = MP_VIDEO_DRM_ERROR_NONE;
292 else if(constraint_info.const_type.is_interval) {
293 VideoLogInfo("Interval time: Year=%d,Month=%d,Day=%d,"
294 "Hour=%d, minute=%d, Second=%d",
295 constraint_info.interval_time.tm_year,
296 constraint_info.interval_time.tm_mon,
297 constraint_info.interval_time.tm_mday,
298 constraint_info.interval_time.tm_hour,
299 constraint_info.interval_time.tm_min,
300 constraint_info.interval_time.tm_sec);
302 pResult->nErrorCode = MP_VIDEO_DRM_ERROR_INTERVAL_FIRST_USE;
303 pResult->nData = ((constraint_info.interval_time.tm_year * MOUNTH_COUNT + constraint_info.interval_time.tm_mon) * DAY_COUNT + constraint_info.interval_time.tm_mday);
307 else if(constraint_info.const_type.is_timedcount) {
308 VideoLogInfo("DRM TimeCount "
309 "(original : %d, remainnig : %d, count_timer: %d)",
310 constraint_info.timed_original_count,
311 constraint_info.timed_remaining_count,
312 constraint_info.timed_count_timer);
313 pResult->nErrorCode = MP_VIDEO_DRM_ERROR_NONE;
316 else if(constraint_info.const_type.is_accumulated) {
317 pResult->nErrorCode = MP_VIDEO_DRM_ERROR_ACCUMULATED;
320 else if(constraint_info.const_type.is_individual) {
321 pResult->nErrorCode = MP_VIDEO_DRM_ERROR_NONE;
324 else if(constraint_info.const_type.is_system) {
325 pResult->nErrorCode = MP_VIDEO_DRM_ERROR_NONE;
332 bool MpVideoDrmIsDivX(char *szPath)
337 VideoLogInfo("[ERR]");
342 int nRet = DRM_RETURN_SUCCESS;
343 drm_bool_type_e is_drm = DRM_FALSE;
345 nRet = drm_is_drm_file(szPath, &is_drm);
346 if(nRet != DRM_RETURN_SUCCESS) {
347 VideoLogInfo("[ERR]drm_is_drm_file : %d", nRet);
351 if(is_drm != DRM_TRUE) {
352 VideoLogInfo("It's not drm file.");
356 drm_file_type_e drm_type = DRM_TYPE_UNDEFINED;
358 nRet = drm_get_file_type(szPath, &drm_type);
359 if(nRet != DRM_RETURN_SUCCESS) {
360 VideoLogInfo("[ERR]drm_get_file_type : %d", nRet);
364 nDrmFileType = drm_type;
366 if(drm_type != DRM_TYPE_DIVX ) {
367 VideoLogInfo("It's not DivX drm file : %d", drm_type);
375 bool MpVideoDrmCheckDivX(char *szPath)
380 VideoLogInfo("[ERR]");
387 void MpVideoDrmGetFileExtension(char *szPath, char *szContentType, int nContentTypeStrSize)
389 if (!szContentType) {
390 VideoLogInfo("[ERR]");
395 VideoLogInfo("[ERR]");
399 memset(szContentType, 0, nContentTypeStrSize);
401 drm_content_info_s content_info;
402 int nRet = DRM_RETURN_SUCCESS;
403 memset(&content_info, 0, sizeof(drm_content_info_s));
405 nRet = drm_get_content_info(szPath,&content_info);
408 VideoLogInfo("contentType: %s", content_info.mime_type);
410 strncpy(szContentType, content_info.mime_type, nContentTypeStrSize - 1);