• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup Drm
18  * @{
19  *
20  * @brief Provides APIs of Drm.
21  * @kit Drm.
22  * @since 11
23  * @version 1.0
24  */
25 
26 /**
27  * @file native_drm_common.h
28  *
29  * @brief Defines the Drm common struct.
30  * @library libnative_drm.z.so
31  * @syscap SystemCapability.Multimedia.Drm.Core
32  * @since 11
33  * @version 1.0
34  */
35 
36 #ifndef NATIVE_DRM_COMMON_H
37 #define NATIVE_DRM_COMMON_H
38 
39 #include <stdint.h>
40 #include <stdio.h>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /**
47  * @brief Enumerates event types of listener.
48  * @since 11
49  * @version 1.0
50  */
51 typedef enum DRM_EventType {
52     /**
53      * DRM event base.
54      */
55     EVENT_DRM_BASE = 200,
56     /**
57      * Provision required event.
58      */
59     EVENT_PROVISION_REQUIRED = 201,
60     /**
61      * Media key required event.
62      */
63     EVENT_KEY_REQUIRED = 202,
64     /**
65      * Media key expired event.
66      */
67     EVENT_KEY_EXPIRED = 203,
68     /**
69      * Vendor defined event.
70      */
71     EVENT_VENDOR_DEFINED = 204,
72     /**
73      * Expiration update event.
74      */
75     EVENT_EXPIRATION_UPDATE = 206,
76 } DRM_EventType;
77 
78 /**
79  * @brief Content potection level.
80  * @syscap SystemCapability.Multimedia.Drm.Core
81  * @since 11
82  * @version 1.0
83  */
84 typedef enum DRM_ContentProtectionLevel {
85     /**
86      * Content potection level unknown.
87      */
88     CONTENT_PROTECTION_LEVEL_UNKNOWN = 0,
89     /**
90      * Content potection level software crypto.
91      */
92     CONTENT_PROTECTION_LEVEL_SW_CRYPTO,
93     /**
94      * Content potection level hardware crypto.
95      */
96     CONTENT_PROTECTION_LEVEL_HW_CRYPTO,
97     /**
98      * Content potection level enhanced hardware crypto.
99      */
100     CONTENT_PROTECTION_LEVEL_ENHANCED_HW_CRYPTO,
101     /**
102      * Content potection level max stub.
103      */
104     CONTENT_PROTECTION_LEVEL_MAX,
105 } DRM_ContentProtectionLevel;
106 
107 /**
108  * @brief Media key type.
109  * @syscap SystemCapability.Multimedia.Drm.Core
110  * @since 11
111  * @version 1.0
112  */
113 typedef enum DRM_MediaKeyType {
114     /**
115      * Media key type offline.
116      */
117     MEDIA_KEY_TYPE_OFFLINE = 0,
118     /**
119      * Media key type online
120      */
121     MEDIA_KEY_TYPE_ONLINE,
122 } DRM_MediaKeyType;
123 
124 /**
125  * @brief Media key request type.
126  * @syscap SystemCapability.Multimedia.Drm.Core
127  * @since 11
128  * @version 1.0
129  */
130 typedef enum DRM_MediaKeyRequestType {
131     /**
132      * Media key request type unknown.
133      */
134     MEDIA_KEY_REQUEST_TYPE_UNKNOWN = 0,
135     /**
136      * Media key request type initial.
137      */
138     MEDIA_KEY_REQUEST_TYPE_INITIAL,
139     /**
140      * Media key request type renewal.
141      */
142     MEDIA_KEY_REQUEST_TYPE_RENEWAL,
143     /**
144      * Media key request type release.
145      */
146     MEDIA_KEY_REQUEST_TYPE_RELEASE,
147     /**
148      * Media key request type none.
149      */
150     MEDIA_KEY_REQUEST_TYPE_NONE,
151     /**
152      * Media key request type update.
153      */
154     MEDIA_KEY_REQUEST_TYPE_UPDATE,
155 } DRM_MediaKeyRequestType;
156 
157 /**
158  * @brief Offline media key status.
159  * @syscap SystemCapability.Multimedia.Drm.Core
160  * @since 11
161  * @version 1.0
162  */
163 typedef enum DRM_OfflineMediaKeyStatus {
164     /**
165      * Offline media key status unknown.
166      */
167     OFFLINE_MEDIA_KEY_STATUS_UNKNOWN = 0,
168     /**
169      * Offline media key status usable.
170      */
171     OFFLINE_MEDIA_KEY_STATUS_USABLE,
172     /**
173      * Offline media key status inactive.
174      */
175     OFFLINE_MEDIA_KEY_STATUS_INACTIVE,
176 } DRM_OfflineMediaKeyStatus;
177 
178 /**
179  * @brief Certificate status.
180  * @syscap SystemCapability.Multimedia.Drm.Core
181  * @since 11
182  * @version 1.0
183  */
184 typedef enum DRM_CertificateStatus {
185     /**
186      * Device already provisioned.
187      */
188     CERT_STATUS_PROVISIONED = 0,
189     /**
190      * Device not provisioned.
191      */
192     CERT_STATUS_NOT_PROVISIONED,
193     /**
194      * Cert already expired.
195      */
196     CERT_STATUS_EXPIRED,
197     /**
198      * Certs are invalid.
199      */
200     CERT_STATUS_INVALID,
201     /**
202      * Get certs status failed.
203      */
204     CERT_STATUS_UNAVAILABLE,
205 } DRM_CertificateStatus;
206 
207 /**
208  * @brief Max count of media key request option.
209  * @since 11
210  * @version 1.0
211  */
212 #define MAX_MEDIA_KEY_REQUEST_OPTION_COUNT 16
213 /**
214  * @brief Max len of media key request option name.
215  * @since 11
216  * @version 1.0
217  */
218 #define MAX_MEDIA_KEY_REQUEST_OPTION_NAME_LEN 64
219 /**
220  * @brief Max len of media key request option data.
221  * @since 11
222  * @version 1.0
223  */
224 #define MAX_MEDIA_KEY_REQUEST_OPTION_DATA_LEN 128
225 /**
226  * @brief Max len of media key request init data.
227  * @since 11
228  * @version 1.0
229  */
230 #define MAX_INIT_DATA_LEN 2048
231 /**
232  * @brief Max len of media mimetype.
233  * @since 11
234  * @version 1.0
235  */
236 #define MAX_MIMETYPE_LEN 64
237 
238 /**
239  * @brief Media key request info.
240  * @since 11
241  * @version 1.0
242  */
243 typedef struct DRM_MediaKeyRequestInfo {
244     /**
245      * Offline or online media key type.
246      */
247     DRM_MediaKeyType type;
248     /**
249      * Initial data len.
250      */
251     int32_t initDataLen;
252     /**
253      * Initial data format as PSSH after base64 encoding.
254      */
255     uint8_t initData[MAX_INIT_DATA_LEN];
256     /**
257      * Media content mime type.
258      */
259     char mimeType[MAX_MIMETYPE_LEN];
260     /**
261      * OptionsData count.
262      */
263     uint32_t optionsCount;
264     /**
265      * Options name the application set to drm framework.
266      */
267     char optionName[MAX_MEDIA_KEY_REQUEST_OPTION_COUNT][MAX_MEDIA_KEY_REQUEST_OPTION_NAME_LEN];
268     /**
269      * Options data the application set to drm framework.
270      */
271     char optionData[MAX_MEDIA_KEY_REQUEST_OPTION_COUNT][MAX_MEDIA_KEY_REQUEST_OPTION_DATA_LEN];
272 } DRM_MediaKeyRequestInfo;
273 
274 /**
275  * @brief Max len of media key request.
276  * @since 11
277  * @version 1.0
278  */
279 #define MAX_MEDIA_KEY_REQUEST_DATA_LEN 8192
280 /**
281  * @brief Max len of URL.
282  * @since 11
283  * @version 1.0
284  */
285 #define MAX_DEFAULT_URL_LEN 2048
286 /**
287  * @brief Media key request.
288  * @since 11
289  * @version 1.0
290  */
291 typedef struct DRM_MediaKeyRequest {
292     /**
293      * Media key request type.
294      */
295     DRM_MediaKeyRequestType type;
296     /**
297      * Media key request data len.
298      */
299     int32_t dataLen;
300     /**
301      * Media key request data sent to media key server.
302      */
303     uint8_t data[MAX_MEDIA_KEY_REQUEST_DATA_LEN];
304     /**
305      * Media key server URL.
306      */
307     char defaultUrl[MAX_DEFAULT_URL_LEN];
308 } DRM_MediaKeyRequest;
309 
310 /**
311  * @brief Max count of statistics item.
312  * @since 11
313  * @version 1.0
314  */
315 #define MAX_STATISTICS_COUNT 10
316 /**
317  * @brief Max len of statistics item name.
318  * @since 11
319  * @version 1.0
320  */
321 #define MAX_STATISTICS_NAME_LEN 64
322 /**
323  * @brief Max len of statistics item buffer.
324  * @since 11
325  * @version 1.0
326  */
327 #define MAX_STATISTICS_BUFFER_LEN 256
328 
329 /**
330  * @brief Statistics of MediaKeySystem.
331  * @since 11
332  * @version 1.0
333  */
334 typedef struct DRM_Statistics {
335     /* Statistics count. */
336     uint32_t statisticsCount;
337     /* Statistics name. */
338     char statisticsName[MAX_STATISTICS_COUNT][MAX_STATISTICS_NAME_LEN];
339     /* Statistics description. */
340     char statisticsDescription[MAX_STATISTICS_COUNT][MAX_STATISTICS_BUFFER_LEN];
341 } DRM_Statistics;
342 
343 /**
344  * @brief Max count of offline media key id.
345  * @since 11
346  * @version 1.0
347  */
348 #define MAX_OFFLINE_MEDIA_KEY_ID_COUNT 512
349 /**
350  * @brief Max len of offline media key id.
351  * @since 11
352  * @version 1.0
353  */
354 #define MAX_OFFLINE_MEDIA_KEY_ID_LEN 64
355 
356 /**
357  * @brief Offline media key ids array.
358  * @since 11
359  * @version 1.0
360  */
361 typedef struct DRM_OfflineMediakeyIdArray {
362     /* Ids count. */
363     uint32_t idsCount;
364     /* Ids len. */
365     int32_t idsLen[MAX_OFFLINE_MEDIA_KEY_ID_COUNT];
366     /* Ids. */
367     uint8_t ids[MAX_OFFLINE_MEDIA_KEY_ID_COUNT][MAX_OFFLINE_MEDIA_KEY_ID_LEN];
368 } DRM_OfflineMediakeyIdArray;
369 
370 /**
371  * @brief Max count of key info.
372  * @since 11
373  * @version 1.0
374  */
375 #define MAX_KEY_INFO_COUNT 64
376 /**
377  * @brief Max len of key id.
378  * @since 11
379  * @version 1.0
380  */
381 #define MAX_KEY_ID_LEN 16
382 /**
383  * @brief Max len of key status value.
384  * @since 11
385  * @version 1.0
386  */
387 #define MAX_KEY_STATUS_VALUE_LEN 128
388 
389 /**
390  * @brief Media key info.
391  * @since 11
392  * @version 1.0
393  */
394 typedef struct DRM_KeysInfo {
395     /* Keys count. */
396     uint32_t keysInfoCount;
397     /* Key id. */
398     uint8_t keyId[MAX_KEY_INFO_COUNT][MAX_KEY_ID_LEN];
399     /* Key status value. */
400     char statusValue[MAX_KEY_INFO_COUNT][MAX_KEY_STATUS_VALUE_LEN];
401 } DRM_KeysInfo;
402 
403 /**
404  * @brief Max count of media key status.
405  * @since 11
406  * @version 1.0
407  */
408 #define MAX_MEDIA_KEY_STATUS_COUNT 64
409 /**
410  * @brief Max len of media key status name.
411  * @since 11
412  * @version 1.0
413  */
414 #define MAX_MEDIA_KEY_STATUS_NAME_LEN 64
415 /**
416  * @brief Max len of media key status value.
417  * @since 11
418  * @version 1.0
419  */
420 #define MAX_MEDIA_KEY_STATUS_VALUE_LEN 256
421 
422 /**
423  * @brief Media key status like pocily etc.
424  * @since 11
425  * @version 1.0
426  */
427 typedef struct DRM_MediaKeyStatus {
428     /* Status count. */
429     uint32_t statusCount;
430     /* Status name. */
431     char statusName[MAX_MEDIA_KEY_STATUS_COUNT][MAX_MEDIA_KEY_STATUS_NAME_LEN];
432     /* Status value. */
433     char statusValue[MAX_MEDIA_KEY_STATUS_COUNT][MAX_MEDIA_KEY_STATUS_VALUE_LEN];
434 } DRM_MediaKeyStatus;
435 
436 /**
437  * @brief Drm system uuid len.
438  * @since 11
439  * @version 1.0
440  */
441 #define DRM_UUID_LEN 16
442 /**
443  * @brief Max len of PSSH data.
444  * @since 11
445  * @version 1.0
446  */
447 #define MAX_PSSH_DATA_LEN 2048
448 
449 /**
450  * @brief PSSH info by uuid.
451  * @since 11
452  * @version 1.0
453  */
454 typedef struct DRM_PsshInfo {
455     /**
456      * Uuid.
457      */
458     uint8_t uuid[DRM_UUID_LEN];
459     /**
460      * PSSH data len.
461      */
462     int32_t dataLen;
463     /**
464      * uint8_t PSSH data.
465      */
466     uint8_t data[MAX_PSSH_DATA_LEN];
467 } DRM_PsshInfo;
468 
469 /**
470  * @brief Max count of PSSH info.
471  * @since 11
472  * @version 1.0
473  */
474 #define MAX_PSSH_INFO_COUNT 8
475 
476 /**
477  * @brief MediaKeySystemInfo used for player to get media key system info from media source.
478  * @since 11
479  * @version 1.0
480  */
481 typedef struct DRM_MediaKeySystemInfo {
482     /* PSSH count. */
483     uint32_t psshCount;
484     /* PSSH info. */
485     DRM_PsshInfo psshInfo[MAX_PSSH_INFO_COUNT];
486 } DRM_MediaKeySystemInfo;
487 
488 typedef void (*DRM_MediaKeySystemInfoCallback)(DRM_MediaKeySystemInfo *mediaKeySystemInfo);
489 
490 /**
491  * @brief Media key system struct.
492  * @since 11
493  * @version 1.0
494  */
495 typedef struct MediaKeySystem MediaKeySystem;
496 
497 /**
498  * @brief Media key session struct.
499  * @since 11
500  * @version 1.0
501  */
502 typedef struct MediaKeySession MediaKeySession;
503 
504 #ifdef __cplusplus
505 }
506 #endif
507 
508 #endif // NATIVE_DRM_COMMON_H
509