1# native_mediakeysession.h 2 3## Overview 4 5The file declares the MediaKeySession APIs. 6 7The APIs can be used to generate media key requests, process responses to media key requests, listen for events, obtain content protection levels, check media key status, and delete media keys. 8 9**File to include**: <multimedia/drm_framework/native_mediakeysession.h> 10 11**Library**: libnative_drm.z.so 12 13**System capability**: SystemCapability.Multimedia.Drm.Core 14 15**Since**: 11 16 17**Related module**: [Drm](capi-drm.md) 18 19## Summary 20 21### Structs 22 23| Name| typedef Keyword| Description| 24| -- | -- | -- | 25| [MediaKeySession_Callback](capi-drm-mediakeysession-callback.md) | MediaKeySession_Callback | Describes the callback used to listen for events such as media key expiry or change, without returning media key session instances. It applies to the scenario where a single media key session needs to be decrypted.| 26| [OH_MediaKeySession_Callback](capi-drm-oh-mediakeysession-callback.md) | OH_MediaKeySession_Callback | Describes the callback used to listen for events such as media key expiry or change, with media key session instances returned. It applies to the scenario where multiple media key sessions need to be decrypted.| 27 28### Functions 29 30| Name| typedef Keyword| Description| 31| -- | -- | -- | 32| [typedef Drm_ErrCode (\*MediaKeySession_EventCallback)(DRM_EventType eventType, uint8_t *info,int32_t infoLen, char *extra)](#mediakeysession_eventcallback) | MediaKeySession_EventCallback | Defines the callback used to listen for media key session events, for example, a key expiration event.| 33| [typedef Drm_ErrCode (\*MediaKeySession_KeyChangeCallback)(DRM_KeysInfo *keysInfo, bool newKeysAvailable)](#mediakeysession_keychangecallback) | MediaKeySession_KeyChangeCallback | Defines the callback that is invoked when the key is changed.| 34| [typedef Drm_ErrCode (\*OH_MediaKeySession_EventCallback)(MediaKeySession *mediaKeySession, DRM_EventType eventType,uint8_t *info, int32_t infoLen, char *extra)](#oh_mediakeysession_eventcallback) | OH_MediaKeySession_EventCallback | Defines the callback that is invoked when a media key session event is triggered.| 35| [typedef Drm_ErrCode (\*OH_MediaKeySession_KeyChangeCallback)(MediaKeySession *mediaKeySession, DRM_KeysInfo *keysInfo,bool newKeysAvailable)](#oh_mediakeysession_keychangecallback) | OH_MediaKeySession_KeyChangeCallback | Defines the callback that is invoked when the key is changed.| 36| [Drm_ErrCode OH_MediaKeySession_GenerateMediaKeyRequest(MediaKeySession *mediaKeySession,DRM_MediaKeyRequestInfo *info, DRM_MediaKeyRequest *mediaKeyRequest)](#oh_mediakeysession_generatemediakeyrequest) | - | Generates a media key request.| 37| [Drm_ErrCode OH_MediaKeySession_ProcessMediaKeyResponse(MediaKeySession *mediaKeySession,uint8_t *response, int32_t responseLen, uint8_t *offlineMediaKeyId, int32_t *offlineMediaKeyIdLen)](#oh_mediakeysession_processmediakeyresponse) | - | Processes a media key response.| 38| [Drm_ErrCode OH_MediaKeySession_CheckMediaKeyStatus(MediaKeySession *mediaKeySession,DRM_MediaKeyStatus *mediaKeyStatus)](#oh_mediakeysession_checkmediakeystatus) | - | Checks the status of media keys.| 39| [Drm_ErrCode OH_MediaKeySession_ClearMediaKeys(MediaKeySession *mediaKeySession)](#oh_mediakeysession_clearmediakeys) | - | Clears media keys.| 40| [Drm_ErrCode OH_MediaKeySession_GenerateOfflineReleaseRequest(MediaKeySession *mediaKeySession,uint8_t *offlineMediaKeyId, int32_t offlineMediaKeyIdLen, uint8_t *releaseRequest,int32_t *releaseRequestLen)](#oh_mediakeysession_generateofflinereleaserequest) | - | Generates a request to release offline media keys.| 41| [Drm_ErrCode OH_MediaKeySession_ProcessOfflineReleaseResponse(MediaKeySession *mediaKeySession,uint8_t *offlineMediaKeyId, int32_t offlineMediaKeyIdLen, uint8_t *releaseReponse,int32_t releaseReponseLen)](#oh_mediakeysession_processofflinereleaseresponse) | - | Processes a response to a request for releasing offline media keys.| 42| [Drm_ErrCode OH_MediaKeySession_RestoreOfflineMediaKeys(MediaKeySession *mediaKeySession,uint8_t *offlineMediaKeyId, int32_t offlineMediaKeyIdLen)](#oh_mediakeysession_restoreofflinemediakeys) | - | Restores offline media keys.| 43| [Drm_ErrCode OH_MediaKeySession_GetContentProtectionLevel(MediaKeySession *mediaKeySession,DRM_ContentProtectionLevel *contentProtectionLevel)](#oh_mediakeysession_getcontentprotectionlevel) | - | Obtains the content protection level of a media key session.| 44| [Drm_ErrCode OH_MediaKeySession_RequireSecureDecoderModule(MediaKeySession *mediaKeySession,const char *mimeType, bool *status)](#oh_mediakeysession_requiresecuredecodermodule) | - | Checks whether secure decoding is required.| 45| [Drm_ErrCode OH_MediaKeySession_SetMediaKeySessionCallback(MediaKeySession *mediaKeySession,MediaKeySession_Callback *callback)](#oh_mediakeysession_setmediakeysessioncallback) | - | Sets a media key session event callback.| 46| [Drm_ErrCode OH_MediaKeySession_SetCallback(MediaKeySession *mediaKeySession,OH_MediaKeySession_Callback *callback)](#oh_mediakeysession_setcallback) | - | Sets a media key session event callback.| 47| [Drm_ErrCode OH_MediaKeySession_Destroy(MediaKeySession *mediaKeySession)](#oh_mediakeysession_destroy) | - | Destroys a MediaKeySession instance.| 48 49## Function Description 50 51### MediaKeySession_EventCallback() 52 53``` 54typedef Drm_ErrCode (*MediaKeySession_EventCallback)(DRM_EventType eventType, uint8_t *info,int32_t infoLen, char *extra) 55``` 56 57**Description** 58 59Defines the callback used to listen for media key session events, for example, a key expiration event. 60 61**Since**: 11 62 63 64**Parameters** 65 66| Name| Description| 67| -- | -- | 68| [DRM_EventType](capi-native-drm-common-h.md#drm_eventtype) eventType | Event type.| 69| uint8_t *info | Pointer to the event information obtained from the media key session.| 70| int32_t infoLen | Length of the event information.| 71| char *extra | Pointer to the additional information obtained from the media key session.| 72 73**Returns** 74 75| Type| Description| 76| -- | -- | 77| [Drm_ErrCode](capi-native-drm-err-h.md#drm_errcode) | Error code.| 78 79### MediaKeySession_KeyChangeCallback() 80 81``` 82typedef Drm_ErrCode (*MediaKeySession_KeyChangeCallback)(DRM_KeysInfo *keysInfo, bool newKeysAvailable) 83``` 84 85**Description** 86 87Defines the callback that is invoked when the key is changed. 88 89**Since**: 11 90 91 92**Parameters** 93 94| Name| Description| 95| -- | -- | 96| [DRM_KeysInfo](capi-drm-drm-keysinfo.md) *keysInfo | Pointer to the media key information.| 97| bool newKeysAvailable | Whether the new key is available.| 98 99**Returns** 100 101| Type| Description| 102| -- | -- | 103| [Drm_ErrCode](capi-native-drm-err-h.md#drm_errcode) | **DRM_ERR_OK**: The operation is successful.<br>**DRM_ERR_INVALID_VAL**: Parameter check fails.| 104 105### OH_MediaKeySession_EventCallback() 106 107``` 108typedef Drm_ErrCode (*OH_MediaKeySession_EventCallback)(MediaKeySession *mediaKeySession, DRM_EventType eventType,uint8_t *info, int32_t infoLen, char *extra) 109``` 110 111**Description** 112 113Defines the callback that is invoked when a media key session event is triggered. 114 115**Since**: 12 116 117 118**Parameters** 119 120| Name| Description| 121| -- | -- | 122| [MediaKeySession](capi-drm-mediakeysession.md) *mediaKeySession | Pointer to the MediaKeySession instance.| 123| [DRM_EventType](capi-native-drm-common-h.md#drm_eventtype) eventType | Event type.| 124| uint8_t *info | Pointer to the event information.| 125| int32_t infoLen | Length of the event information.| 126| char *extra | Pointer to extended event information.| 127 128**Returns** 129 130| Type| Description| 131| -- | -- | 132| [Drm_ErrCode](capi-native-drm-err-h.md#drm_errcode) | Error code.| 133 134### OH_MediaKeySession_KeyChangeCallback() 135 136``` 137typedef Drm_ErrCode (*OH_MediaKeySession_KeyChangeCallback)(MediaKeySession *mediaKeySession, DRM_KeysInfo *keysInfo,bool newKeysAvailable) 138``` 139 140**Description** 141 142Defines the callback that is invoked when the key is changed. 143 144**Since**: 12 145 146 147**Parameters** 148 149| Name| Description| 150| -- | -- | 151| [MediaKeySession](capi-drm-mediakeysession.md) *mediaKeySession | Pointer to the MediaKeySession instance.| 152| [DRM_KeysInfo](capi-drm-drm-keysinfo.md) *keysInfo | Pointer to the media key information.| 153| bool newKeysAvailable | Whether the new keys are available. **true** if available, **false** otherwise.| 154 155**Returns** 156 157| Type| Description| 158| -- | -- | 159| [Drm_ErrCode](capi-native-drm-err-h.md#drm_errcode) | **DRM_ERR_OK**: The operation is successful.<br>**DRM_ERR_INVALID_VAL**: Parameter check fails.| 160 161### OH_MediaKeySession_GenerateMediaKeyRequest() 162 163``` 164Drm_ErrCode OH_MediaKeySession_GenerateMediaKeyRequest(MediaKeySession *mediaKeySession,DRM_MediaKeyRequestInfo *info, DRM_MediaKeyRequest *mediaKeyRequest) 165``` 166 167**Description** 168 169Generates a media key request. 170 171**Since**: 11 172 173 174**Parameters** 175 176| Name| Description| 177| -- | -- | 178| [MediaKeySession](capi-drm-mediakeysession.md) *mediaKeySession | Pointer to the MediaKeySession instance.| 179| [DRM_MediaKeyRequestInfo](capi-drm-drm-mediakeyrequestinfo.md) *info | Pointer to the information about the media key request.| 180| [DRM_MediaKeyRequest](capi-drm-drm-mediakeyrequest.md) *mediaKeyRequest | Pointer to the media key request.| 181 182**Returns** 183 184| Type| Description| 185| -- | -- | 186| [Drm_ErrCode](capi-native-drm-err-h.md#drm_errcode) | **DRM_ERR_OK**: The operation is successful.<br>**DRM_ERR_NO_MEMORY**: The memory fails to be allocated due to insufficient memory.<br>**DRM_ERR_INVALID_VAL**: The input parameter **mediaKeySession** is nullptr or invalid, or **info** or **mediaKeyRequest** is nullptr.<br>**DRM_ERR_UNKNOWN**: An internal error occurs. Check the log details.| 187 188### OH_MediaKeySession_ProcessMediaKeyResponse() 189 190``` 191Drm_ErrCode OH_MediaKeySession_ProcessMediaKeyResponse(MediaKeySession *mediaKeySession,uint8_t *response, int32_t responseLen, uint8_t *offlineMediaKeyId, int32_t *offlineMediaKeyIdLen) 192``` 193 194**Description** 195 196Processes a media key response. 197 198**Since**: 11 199 200 201**Parameters** 202 203| Name| Description| 204| -- | -- | 205| [MediaKeySession](capi-drm-mediakeysession.md) *mediaKeySession | Pointer to the MediaKeySession instance.| 206| uint8_t *response | Pointer to a media key response.| 207| int32_t responseLen | Pointer to the length of the media key response.| 208| uint8_t *offlineMediaKeyId | Pointer to the ID of an offline media key.| 209| int32_t *offlineMediaKeyIdLen | Length of the offline media key ID.| 210 211**Returns** 212 213| Type| Description| 214| -- | -- | 215| [Drm_ErrCode](capi-native-drm-err-h.md#drm_errcode) | **DRM_ERR_OK**: The operation is successful.<br>**DRM_ERR_NO_MEMORY**: The memory fails to be allocated due to insufficient memory.<br>**DRM_ERR_INVALID_VAL**: The input parameter **mediaKeySession** is nullptr or invalid, or another parameter of the pointer type is nullptr.<br>**DRM_ERR_UNKNOWN**: An internal error occurs. Check the log details.| 216 217### OH_MediaKeySession_CheckMediaKeyStatus() 218 219``` 220Drm_ErrCode OH_MediaKeySession_CheckMediaKeyStatus(MediaKeySession *mediaKeySession,DRM_MediaKeyStatus *mediaKeyStatus) 221``` 222 223**Description** 224 225Checks the status of media keys. 226 227**Since**: 11 228 229 230**Parameters** 231 232| Name| Description| 233| -- | -- | 234| [MediaKeySession](capi-drm-mediakeysession.md) *mediaKeySession | Pointer to the MediaKeySession instance.| 235| [DRM_MediaKeyStatus](capi-drm-drm-mediakeystatus.md) *mediaKeyStatus | Pointer to the media key status obtained.| 236 237**Returns** 238 239| Type| Description| 240| -- | -- | 241| [Drm_ErrCode](capi-native-drm-err-h.md#drm_errcode) | **DRM_ERR_OK**: The operation is successful.<br>**DRM_ERR_NO_MEMORY**: The memory fails to be allocated due to insufficient memory.<br>**DRM_ERR_INVALID_VAL**: The input parameter **mediaKeySession** is nullptr or invalid, or **mediaKeyStatus** is nullptr.<br>**DRM_ERR_UNKNOWN**: An internal error occurs. Check the log details.| 242 243### OH_MediaKeySession_ClearMediaKeys() 244 245``` 246Drm_ErrCode OH_MediaKeySession_ClearMediaKeys(MediaKeySession *mediaKeySession) 247``` 248 249**Description** 250 251Clears media keys. 252 253**Since**: 11 254 255 256**Parameters** 257 258| Name| Description| 259| -- | -- | 260| [MediaKeySession](capi-drm-mediakeysession.md) *mediaKeySession | Pointer to the MediaKeySession instance.| 261 262**Returns** 263 264| Type| Description| 265| -- | -- | 266| [Drm_ErrCode](capi-native-drm-err-h.md#drm_errcode) | **DRM_ERR_OK**: The operation is successful.<br>**DRM_ERR_INVALID_VAL**: The input parameter **mediaKeySession** is nullptr or invalid.<br>**DRM_ERR_UNKNOWN**: An internal error occurs. Check the log details.| 267 268### OH_MediaKeySession_GenerateOfflineReleaseRequest() 269 270``` 271Drm_ErrCode OH_MediaKeySession_GenerateOfflineReleaseRequest(MediaKeySession *mediaKeySession,uint8_t *offlineMediaKeyId, int32_t offlineMediaKeyIdLen, uint8_t *releaseRequest,int32_t *releaseRequestLen) 272``` 273 274**Description** 275 276Generates a request to release offline media keys. 277 278**Since**: 11 279 280 281**Parameters** 282 283| Name| Description| 284| -- | -- | 285| [MediaKeySession](capi-drm-mediakeysession.md) *mediaKeySession | Pointer to the MediaKeySession instance.| 286| uint8_t *offlineMediaKeyId | Pointer to the ID of an offline media key.| 287| int32_t *releaseRequestLen | Length of the offline media key ID.| 288| uint8_t *releaseRequest | Pointer to a request to release offline media keys.| 289| int32_t *releaseRequestLen | Length of the request to release offline media keys.| 290 291**Returns** 292 293| Type| Description| 294| -- | -- | 295| [Drm_ErrCode](capi-native-drm-err-h.md#drm_errcode) | **DRM_ERR_OK**: The operation is successful.<br>**DRM_ERR_NO_MEMORY**: The memory fails to be allocated due to insufficient memory.<br>**DRM_ERR_INVALID_VAL**: The input parameter **mediaKeySession** is nullptr or invalid, or another parameter of the pointer type is nullptr.<br>**DRM_ERR_UNKNOWN**: An internal error occurs or the DRM solution on the device does not support offline media key release. Check the log details.| 296 297### OH_MediaKeySession_ProcessOfflineReleaseResponse() 298 299``` 300Drm_ErrCode OH_MediaKeySession_ProcessOfflineReleaseResponse(MediaKeySession *mediaKeySession,uint8_t *offlineMediaKeyId, int32_t offlineMediaKeyIdLen, uint8_t *releaseReponse,int32_t releaseReponseLen) 301``` 302 303**Description** 304 305Processes a response to a request for releasing offline media keys. 306 307**Since**: 11 308 309 310**Parameters** 311 312| Name| Description| 313| -- | -- | 314| [MediaKeySession](capi-drm-mediakeysession.md) *mediaKeySession | Pointer to the MediaKeySession instance.| 315| uint8_t *offlineMediaKeyId | Pointer to the ID of an offline media key.| 316| int32_t offlineMediaKeyIdLen | Length of the offline media key ID.| 317| uint8_t *releaseReponse | Pointer to the response.| 318| int32_t releaseReponseLen | Length of the response.| 319 320**Returns** 321 322| Type| Description| 323| -- | -- | 324| [Drm_ErrCode](capi-native-drm-err-h.md#drm_errcode) | **DRM_ERR_OK**: The operation is successful.<br>**DRM_ERR_INVALID_VAL**: The input parameter **mediaKeySession** is nullptr or invalid, or another parameter of the pointer type is nullptr.<br>**DRM_ERR_UNKNOWN**: An internal error occurs or the DRM solution on the device does not support offline media key release. Check the log details.| 325 326### OH_MediaKeySession_RestoreOfflineMediaKeys() 327 328``` 329Drm_ErrCode OH_MediaKeySession_RestoreOfflineMediaKeys(MediaKeySession *mediaKeySession,uint8_t *offlineMediaKeyId, int32_t offlineMediaKeyIdLen) 330``` 331 332**Description** 333 334Restores offline media keys. 335 336**Since**: 11 337 338 339**Parameters** 340 341| Name| Description| 342| -- | -- | 343| [MediaKeySession](capi-drm-mediakeysession.md) *mediaKeySession | Pointer to the MediaKeySession instance.| 344| uint8_t *offlineMediaKeyId | Pointer to the ID of an offline media key.| 345| int32_t offlineMediaKeyIdLen | Length of the offline media key ID.| 346 347**Returns** 348 349| Type| Description| 350| -- | -- | 351| [Drm_ErrCode](capi-native-drm-err-h.md#drm_errcode) | **DRM_ERR_OK**: The operation is successful.<br>**DRM_ERR_INVALID_VAL**: The input parameter **mediaKeySession** is nullptr or invalid, or another parameter of the pointer type is nullptr.<br>**DRM_ERR_UNKNOWN**: An internal error occurs. Check the log details.| 352 353### OH_MediaKeySession_GetContentProtectionLevel() 354 355``` 356Drm_ErrCode OH_MediaKeySession_GetContentProtectionLevel(MediaKeySession *mediaKeySession,DRM_ContentProtectionLevel *contentProtectionLevel) 357``` 358 359**Description** 360 361Obtains the content protection level of a media key session. 362 363**Since**: 11 364 365 366**Parameters** 367 368| Name| Description| 369| -- | -- | 370| [MediaKeySession](capi-drm-mediakeysession.md) *mediaKeySession | Pointer to the MediaKeySession instance.| 371| [DRM_ContentProtectionLevel](capi-native-drm-common-h.md#drm_contentprotectionlevel) *contentProtectionLevel | Pointer to the content protection level.| 372 373**Returns** 374 375| Type| Description| 376| -- | -- | 377| [Drm_ErrCode](capi-native-drm-err-h.md#drm_errcode) | **DRM_ERR_OK**: The operation is successful.<br>**DRM_ERR_INVALID_VAL**: The input parameter **mediaKeySession** is nullptr or invalid, or **contentProtectionLevel** is nullptr.<br>**DRM_ERR_UNKNOWN**: An internal error occurs. Check the log details.| 378 379### OH_MediaKeySession_RequireSecureDecoderModule() 380 381``` 382Drm_ErrCode OH_MediaKeySession_RequireSecureDecoderModule(MediaKeySession *mediaKeySession,const char *mimeType, bool *status) 383``` 384 385**Description** 386 387Checks whether secure decoding is required. 388 389**Since**: 11 390 391 392**Parameters** 393 394| Name| Description| 395| -- | -- | 396| [MediaKeySession](capi-drm-mediakeysession.md) *mediaKeySession | Pointer to the MediaKeySession instance.| 397| const char *mimeType | Pointer to the MIME type. The supported MIME types depend on the DRM solution. Example types are video/avc and video/hev.| 398| bool *status | Pointer to the result indicating whether secure decoding is required.| 399 400**Returns** 401 402| Type| Description| 403| -- | -- | 404| [Drm_ErrCode](capi-native-drm-err-h.md#drm_errcode) | **DRM_ERR_OK**: The operation is successful.<br>**DRM_ERR_INVALID_VAL**: The input parameter **mediaKeySession** is nullptr or invalid, or another parameter of the pointer type is nullptr.<br>**DRM_ERR_UNKNOWN**: An internal error occurs. Check the log details.| 405 406### OH_MediaKeySession_SetMediaKeySessionCallback() 407 408``` 409Drm_ErrCode OH_MediaKeySession_SetMediaKeySessionCallback(MediaKeySession *mediaKeySession,MediaKeySession_Callback *callback) 410``` 411 412**Description** 413 414Sets a media key session event callback. 415 416**Since**: 11 417 418 419**Parameters** 420 421| Name| Description| 422| -- | -- | 423| [MediaKeySession](capi-drm-mediakeysession.md) *mediaKeySession | Pointer to the MediaKeySession instance.| 424| [MediaKeySession_Callback](capi-drm-mediakeysession-callback.md) *callback | Pointer to the callback for the media key session event.| 425 426**Returns** 427 428| Type| Description| 429| -- | -- | 430| [Drm_ErrCode](capi-native-drm-err-h.md#drm_errcode) | **DRM_ERR_OK**: The operation is successful.<br>**DRM_ERR_INVALID_VAL**: The input parameter **mediaKeySession** is nullptr or invalid, or **callback** is nullptr.| 431 432### OH_MediaKeySession_SetCallback() 433 434``` 435Drm_ErrCode OH_MediaKeySession_SetCallback(MediaKeySession *mediaKeySession,OH_MediaKeySession_Callback *callback) 436``` 437 438**Description** 439 440Sets a media key session event callback. 441 442**Since**: 12 443 444 445**Parameters** 446 447| Name| Description| 448| -- | -- | 449| [MediaKeySession](capi-drm-mediakeysession.md) *mediaKeySession | Pointer to the MediaKeySession instance.| 450| [OH_MediaKeySession_Callback](capi-drm-oh-mediakeysession-callback.md) *callback | Pointer to the callback for the media key session event.| 451 452**Returns** 453 454| Type| Description| 455| -- | -- | 456| [Drm_ErrCode](capi-native-drm-err-h.md#drm_errcode) | **DRM_ERR_OK**: The operation is successful.<br>**DRM_ERR_INVALID_VAL**: The input parameter **mediaKeySession** is nullptr or invalid, or **callback** is nullptr.| 457 458### OH_MediaKeySession_Destroy() 459 460``` 461Drm_ErrCode OH_MediaKeySession_Destroy(MediaKeySession *mediaKeySession) 462``` 463 464**Description** 465 466Destroys a MediaKeySession instance. 467 468**Since**: 11 469 470 471**Parameters** 472 473| Name| Description| 474| -- | -- | 475| [MediaKeySession](capi-drm-mediakeysession.md) *mediaKeySession | Pointer to the MediaKeySession instance.| 476 477**Returns** 478 479| Type| Description| 480| -- | -- | 481| [Drm_ErrCode](capi-native-drm-err-h.md#drm_errcode) | **DRM_ERR_OK**: The operation is successful.<br>**DRM_ERR_INVALID_VAL**: The input parameter **mediaKeySession** is nullptr or invalid.<br>**DRM_ERR_UNKNOWN**: An internal error occurs. Check the log details.| 482