Update LICENSE file.
[apps/core/preloaded/video-player.git] / src / mp-drm-ctrl.c
1 /*
2  * Copyright (c) [2012] Samsung Electronics Co., Ltd.
3  *
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
7  *
8  *     http://floralicense.org/license/
9  *
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.
15  */
16
17
18 #include <drm_client.h>
19 #include <drm_client_types.h>
20
21
22 #include "mp-util.h"
23 #include "mp-video-log.h"
24 #include "video-player.h"
25 #include "mp-drm-ctrl.h"
26
27 static int                      nCheckConsumption = VIDEO_DRM_CONSUMPTION_STATE_DISABLE;
28
29 static drm_file_type_e          nDrmFileType = DRM_TYPE_UNDEFINED;
30
31 #define ACCUMULATED_DATE                86400   /* 24*60*60 */
32 #define RO_MESSAGE_LEN                  1024
33
34 #define MOUNTH_COUNT    12
35 #define DAY_COUNT       30
36 #define HOUR_COUNT      24
37
38 static bool bForwordLock = FALSE;
39 /*
40  * External function
41  */
42 void MpVideoDrmInit()
43 {
44         VideoLogInfo("");
45 }
46
47 bool MpVideoDrmGetForwardLookState()
48 {
49         VideoLogInfo("");
50
51         return bForwordLock;
52 }
53
54 void MpVideoDrmSetConsumptionState(int nState)
55 {
56         VideoLogInfo("");
57
58         nCheckConsumption = nState;
59 }
60
61 int MpVideoDrmGetConsumption()
62 {
63         VideoLogInfo("");
64
65         return nCheckConsumption;
66 }
67
68 void MpVideoDrmStartConsumption(char *szPath)
69 {
70         VideoLogInfo("");
71
72
73         if (MpVideoDrmGetConsumption()) {
74
75         } else {
76                 VideoLogInfo("Disable consumption.");
77         }
78 }
79
80 void MpVideoDrmPauseConsumption()
81 {
82         VideoLogInfo("");
83
84         if (MpVideoDrmGetConsumption()) {
85         } else {
86                 VideoLogInfo("Disable consumption.");
87         }
88 }
89
90 void MpVideoDrmResumeConsumption()
91 {
92         VideoLogInfo("");
93
94         if (MpVideoDrmGetConsumption()) {
95         } else {
96                 VideoLogInfo("Disable consumption.");
97         }
98 }
99
100 void MpVideoDrmStopConsumption()
101 {
102         VideoLogInfo("");
103
104         if (MpVideoDrmGetConsumption()) {
105                 MpVideoDrmSetConsumptionState (VIDEO_DRM_CONSUMPTION_STATE_DISABLE);
106         } else {
107                 VideoLogInfo("Disable consumption.");
108         }
109 }
110
111 bool MpVideoDrmIsDrmFile(char *szPath)
112 {
113         VideoLogInfo("");
114
115         if (!szPath) {
116                 VideoLogInfo("[ERR]");
117                 return FALSE;
118         }
119         int nRet = DRM_RETURN_SUCCESS;
120         drm_bool_type_e is_drm =  DRM_FALSE;
121
122         nRet = drm_is_drm_file(szPath, &is_drm);
123         if(nRet != DRM_RETURN_SUCCESS) {
124                 VideoLogInfo("[ERR]drm_is_drm_file : %d", nRet);
125                 return FALSE;
126         }
127
128         if(is_drm != DRM_TRUE) {
129                 VideoLogInfo("It's not drm file.");
130                 return FALSE;
131         }
132
133
134         drm_file_type_e drm_type = DRM_TYPE_UNDEFINED;
135
136         nRet = drm_get_file_type(szPath, &drm_type);
137         if(nRet != DRM_RETURN_SUCCESS) {
138                 VideoLogInfo("[ERR]drm_get_file_type : %d", nRet);
139                 return FALSE;
140         }
141
142         nDrmFileType = drm_type;
143
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);
146                 return FALSE;
147         }
148
149         return TRUE;
150 }
151
152 bool MpVideoDrmHasValidRo(char *szPath)
153 {
154         VideoLogInfo("");
155
156         if (!szPath) {
157                 VideoLogInfo("[ERR]");
158                 return FALSE;
159         }
160
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);
166                 return FALSE;
167         }
168
169         if(license_status != DRM_LICENSE_STATUS_VALID) {
170                 VideoLogInfo("Invalid license status : %d", license_status);
171                 return FALSE;
172         }
173
174         return TRUE;
175 }
176
177 bool MpVideoDrmCheckForward(char *szPath)
178 {
179         VideoLogInfo("");
180
181         if (!szPath) {
182                 VideoLogInfo("[ERR]");
183                 return FALSE;
184         }
185
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);
191
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;
196                 return FALSE;
197         }
198
199         if(is_allow == DRM_TRUE) {
200                 bForwordLock = TRUE;
201                 return TRUE;
202         }
203
204         return FALSE;
205 }
206
207 MpVideoDrmInfo *MpVideoDrmCheckLeftRo(char *szVideoTitle, char *szPath)
208 {
209         VideoLogInfo("");
210         MpVideoDrmInfo *pResult = NULL;
211         pResult = calloc(1, sizeof(MpVideoDrmInfo));
212
213         if (!szVideoTitle) {
214                 VideoLogInfo("[ERR] No has video title.");
215                 pResult->nErrorCode = MP_VIDEO_DRM_ERROR_INTERNAL;
216                 return pResult;
217         }
218
219         if (!szPath) {
220                 VideoLogInfo("[ERR] No has path.");
221                 pResult->nErrorCode = MP_VIDEO_DRM_ERROR_INTERNAL;
222                 return pResult;
223         }
224
225
226
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;
234                 return pResult;
235         }
236
237         if(constraint_info.const_type.is_unlimited) {
238                 VideoLogInfo("Unlimited DRM Contents");
239                 pResult->nErrorCode = MP_VIDEO_DRM_ERROR_NONE;
240                 return pResult;
241         }
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;
249                         return pResult;
250                 }
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;
258                         return pResult;
259                 }
260                 else {
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;
266                         return pResult;
267                 }
268         }
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);
278
279
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);
288
289                 pResult->nErrorCode = MP_VIDEO_DRM_ERROR_NONE;
290                 return pResult;
291         }
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);
301
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);
304                 return pResult;
305
306         }
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;
314                 return pResult;
315         }
316         else if(constraint_info.const_type.is_accumulated) {
317                 pResult->nErrorCode = MP_VIDEO_DRM_ERROR_ACCUMULATED;
318                 return pResult;
319         }
320         else if(constraint_info.const_type.is_individual) {
321                 pResult->nErrorCode = MP_VIDEO_DRM_ERROR_NONE;
322                 return pResult;
323         }
324         else if(constraint_info.const_type.is_system) {
325                 pResult->nErrorCode = MP_VIDEO_DRM_ERROR_NONE;
326                 return pResult;
327         }
328
329         return pResult;
330 }
331
332 bool MpVideoDrmIsDivX(char *szPath)
333 {
334         VideoLogInfo("");
335
336         if (!szPath) {
337                 VideoLogInfo("[ERR]");
338                 return FALSE;
339         }
340
341
342         int nRet = DRM_RETURN_SUCCESS;
343         drm_bool_type_e is_drm =  DRM_FALSE;
344
345         nRet = drm_is_drm_file(szPath, &is_drm);
346         if(nRet != DRM_RETURN_SUCCESS) {
347                 VideoLogInfo("[ERR]drm_is_drm_file : %d", nRet);
348                 return FALSE;
349         }
350
351         if(is_drm != DRM_TRUE) {
352                 VideoLogInfo("It's not drm file.");
353                 return FALSE;
354         }
355
356         drm_file_type_e drm_type = DRM_TYPE_UNDEFINED;
357
358         nRet = drm_get_file_type(szPath, &drm_type);
359         if(nRet != DRM_RETURN_SUCCESS) {
360                 VideoLogInfo("[ERR]drm_get_file_type : %d", nRet);
361                 return FALSE;
362         }
363
364         nDrmFileType = drm_type;
365
366         if(drm_type != DRM_TYPE_DIVX ) {
367                 VideoLogInfo("It's not DivX drm file : %d", drm_type);
368                 return FALSE;
369         }
370
371         return TRUE;
372
373 }
374
375 bool MpVideoDrmCheckDivX(char *szPath)
376 {
377         VideoLogInfo("");
378
379         if (!szPath) {
380                 VideoLogInfo("[ERR]");
381                 return FALSE;
382         }
383
384         return TRUE;
385 }
386
387 void MpVideoDrmGetFileExtension(char *szPath, char *szContentType, int nContentTypeStrSize)
388 {
389         if (!szContentType) {
390                 VideoLogInfo("[ERR]");
391                 return;
392         }
393
394         if (!szPath) {
395                 VideoLogInfo("[ERR]");
396                 return;
397         }
398
399         memset(szContentType, 0, nContentTypeStrSize);
400
401         drm_content_info_s content_info;
402         int nRet = DRM_RETURN_SUCCESS;
403         memset(&content_info, 0, sizeof(drm_content_info_s));
404
405         nRet = drm_get_content_info(szPath,&content_info);
406
407
408         VideoLogInfo("contentType: %s", content_info.mime_type);
409
410         strncpy(szContentType, content_info.mime_type, nContentTypeStrSize - 1);
411 }