openharmony 鸿蒙 capi-native-mediakeysession-h

2026-08-25 浏览 (1)

native_mediakeysession.h

Overview

The file declares the MediaKeySession APIs for DRM operations.
The 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 remove media keys.

File to include: <multimedia/drm_framework/native_mediakeysession.h>

Library: libnative_drm.so

System capability: SystemCapability.Multimedia.Drm.Core

Since: 11

Related module: Drm

Summary

Structs

Nametypedef KeywordDescription
MediaKeySession_CallbackMediaKeySession_CallbackDefines the callbacks for media key session events such as key expiration and key changes. It does not provide a MediaKeySession instance, making it suitable for single-session decryption scenarios.
OH_MediaKeySession_CallbackOH_MediaKeySession_CallbackDefines the callbacks for media key session events such as key expiration and key changes. It provides a MediaKeySession instance, making it suitable for multi-session decryption scenarios.

Functions

Nametypedef KeywordDescription
typedef Drm_ErrCode (*MediaKeySession_EventCallback)(DRM_EventType eventType, uint8_t *info,int32_t infoLen, char *extra)MediaKeySession_EventCallbackDefines the callback used to listen for media key session events, for example, key expiration events.
typedef Drm_ErrCode (*MediaKeySession_KeyChangeCallback)(DRM_KeysInfo *keysInfo, bool newKeysAvailable)MediaKeySession_KeyChangeCallbackDefines the callback used to listen for media key change events.
typedef Drm_ErrCode (*OH_MediaKeySession_EventCallback)(MediaKeySession *mediaKeySession, DRM_EventType eventType,uint8_t *info, int32_t infoLen, char *extra)OH_MediaKeySession_EventCallbackDefines the callback used to listen for media key session events.
typedef Drm_ErrCode (*OH_MediaKeySession_KeyChangeCallback)(MediaKeySession *mediaKeySession, DRM_KeysInfo *keysInfo, bool newKeysAvailable)OH_MediaKeySession_KeyChangeCallbackDefines the callback used to listen for media key change events.
Drm_ErrCode OH_MediaKeySession_GenerateMediaKeyRequest(MediaKeySession *mediaKeySession, DRM_MediaKeyRequestInfo *info, DRM_MediaKeyRequest *mediaKeyRequest)-Generates a media key request.
Drm_ErrCode OH_MediaKeySession_ProcessMediaKeyResponse(MediaKeySession *mediaKeySession, uint8_t *response, int32_t responseLen, uint8_t *offlineMediaKeyId, int32_t *offlineMediaKeyIdLen)-Processes the response to a media key request.
Drm_ErrCode OH_MediaKeySession_CheckMediaKeyStatus(MediaKeySession *mediaKeySession, DRM_MediaKeyStatus *mediaKeyStatus)-Checks the status of a media key.
Drm_ErrCode OH_MediaKeySession_ClearMediaKeys(MediaKeySession *mediaKeySession)-Clears media keys.
Drm_ErrCode OH_MediaKeySession_GenerateOfflineReleaseRequest(MediaKeySession *mediaKeySession, uint8_t *offlineMediaKeyId, int32_t offlineMediaKeyIdLen, uint8_t *releaseRequest,int32_t *releaseRequestLen)-Generates a request to release offline media keys.
Drm_ErrCode OH_MediaKeySession_ProcessOfflineReleaseResponse(MediaKeySession *mediaKeySession, uint8_t *offlineMediaKeyId, int32_t offlineMediaKeyIdLen, uint8_t *releaseResponse,int32_t releaseResponseLen)-Processes the response to a request for releasing offline media keys.
Drm_ErrCode OH_MediaKeySession_RestoreOfflineMediaKeys(MediaKeySession *mediaKeySession, uint8_t *offlineMediaKeyId, int32_t offlineMediaKeyIdLen)-Restores offline media keys.
Drm_ErrCode OH_MediaKeySession_GetContentProtectionLevel(MediaKeySession *mediaKeySession, DRM_ContentProtectionLevel *contentProtectionLevel)-Obtains the content protection level of a media key session.
Drm_ErrCode OH_MediaKeySession_RequireSecureDecoderModule(MediaKeySession *mediaKeySession, const char *mimeType, bool *status)-Checks whether secure decoding is required.
Drm_ErrCode OH_MediaKeySession_SetMediaKeySessionCallback(MediaKeySession *mediaKeySession, MediaKeySession_Callback *callback)-Sets a media key session event callback.
Drm_ErrCode OH_MediaKeySession_SetCallback(MediaKeySession *mediaKeySession, OH_MediaKeySession_Callback *callback)-Sets a media key session event callback.
Drm_ErrCode OH_MediaKeySession_Destroy(MediaKeySession *mediaKeySession)-Destroys a MediaKeySession instance.

Function Description

MediaKeySession_EventCallback()

typedef  Drm_ErrCode (*MediaKeySession_EventCallback)(DRM_EventType eventType, uint8_t *info,int32_t infoLen, char *extra)

Description

Defines the callback used to listen for media key session events, for example, key expiration events.

Since: 11

Parameters

NameDescription
DRM_EventType eventTypeEvent type.
uint8_t *infoPointer to the event information obtained from the media key session.
int32_t infoLenLength of the event information.
char *extraPointer to the additional information obtained from the media key session.

Returns

TypeDescription
Drm_ErrCodeError code.

MediaKeySession_KeyChangeCallback()

typedef  Drm_ErrCode (*MediaKeySession_KeyChangeCallback)(DRM_KeysInfo *keysInfo, bool newKeysAvailable)

Description

Defines the callback used to listen for media key change events.

Since: 11

Parameters

NameDescription
DRM_KeysInfo *keysInfoPointer to the media key information.
bool newKeysAvailableWhether the new keys are available. true if available, false otherwise.

Returns

TypeDescription
Drm_ErrCodeDRM_ERR_OK: The operation is successful.
DRM_ERR_INVALID_VAL: Parameter check fails.

OH_MediaKeySession_EventCallback()

typedef Drm_ErrCode (*OH_MediaKeySession_EventCallback)(MediaKeySession *mediaKeySession, DRM_EventType eventType,uint8_t *info, int32_t infoLen, char *extra)

Description

Defines the callback used to listen for media key session events.

Since: 12

Parameters

NameDescription
MediaKeySession *mediaKeySessionPointer to the MediaKeySession instance.
DRM_EventType eventTypeEvent type.
uint8_t *infoPointer to the event information.
int32_t infoLenLength of the event information.
char *extraPointer to the additional information.

Returns

TypeDescription
Drm_ErrCodeError code.

OH_MediaKeySession_KeyChangeCallback()

typedef Drm_ErrCode (*OH_MediaKeySession_KeyChangeCallback)(MediaKeySession *mediaKeySession, DRM_KeysInfo *keysInfo,bool newKeysAvailable)

Description

Defines the callback used to listen for media key change events.

Since: 12

Parameters

NameDescription
MediaKeySession *mediaKeySessionPointer to the MediaKeySession instance.
DRM_KeysInfo *keysInfoPointer to the media key information.
bool newKeysAvailableWhether the new keys are available. true if available, false otherwise.

Returns

TypeDescription
Drm_ErrCodeDRM_ERR_OK: The operation is successful.
DRM_ERR_INVALID_VAL: Parameter check fails.

OH_MediaKeySession_GenerateMediaKeyRequest()

Drm_ErrCode OH_MediaKeySession_GenerateMediaKeyRequest(MediaKeySession *mediaKeySession,DRM_MediaKeyRequestInfo *info, DRM_MediaKeyRequest *mediaKeyRequest)

Description

Generates a media key request.

Since: 11

Parameters

NameDescription
MediaKeySession *mediaKeySessionPointer to the MediaKeySession instance.
DRM_MediaKeyRequestInfo *infoPointer to the information about the media key request.
DRM_MediaKeyRequest *mediaKeyRequestPointer to the media key request.

Returns

TypeDescription
Drm_ErrCodeDRM_ERR_OK: The operation is successful.
DRM_ERR_NO_MEMORY: Memory allocation fails due to insufficient system memory.
DRM_ERR_INVALID_VAL: The input parameter mediaKeySession is nullptr or invalid, or info or mediaKeyRequest is nullptr.
DRM_ERR_UNKNOWN: An internal error occurs. Check the log details.

OH_MediaKeySession_ProcessMediaKeyResponse()

Drm_ErrCode OH_MediaKeySession_ProcessMediaKeyResponse(MediaKeySession *mediaKeySession,uint8_t *response, int32_t responseLen, uint8_t *offlineMediaKeyId, int32_t *offlineMediaKeyIdLen)

Description

Processes the response to a media key request.

Since: 11

Parameters

NameDescription
MediaKeySession *mediaKeySessionPointer to the MediaKeySession instance.
uint8_t *responsePointer to the response to a media key request.
int32_t responseLenPointer to the length of the response.
uint8_t *offlineMediaKeyIdPointer to the ID of an offline media key.
int32_t *offlineMediaKeyIdLenLength of the offline media key ID.

Returns

TypeDescription
Drm_ErrCodeDRM_ERR_OK: The operation is successful.
DRM_ERR_NO_MEMORY: Memory allocation fails due to insufficient system memory.
DRM_ERR_INVALID_VAL: The input parameter mediaKeySession is nullptr or invalid, or another parameter of the pointer type is nullptr.
DRM_ERR_UNKNOWN: An internal error occurs. Check the log details.

OH_MediaKeySession_CheckMediaKeyStatus()

Drm_ErrCode OH_MediaKeySession_CheckMediaKeyStatus(MediaKeySession *mediaKeySession,DRM_MediaKeyStatus *mediaKeyStatus)

Description

Checks the status of a media key.

Since: 11

Parameters

NameDescription
MediaKeySession *mediaKeySessionPointer to the MediaKeySession instance.
DRM_MediaKeyStatus *mediaKeyStatusPointer to the media key status obtained.

Returns

TypeDescription
Drm_ErrCodeDRM_ERR_OK: The operation is successful.
DRM_ERR_NO_MEMORY: Memory allocation fails due to insufficient system memory.
DRM_ERR_INVALID_VAL: The input parameter mediaKeySession is nullptr or invalid, or mediaKeyStatus is nullptr.
DRM_ERR_UNKNOWN: An internal error occurs. Check the log details.

OH_MediaKeySession_ClearMediaKeys()

Drm_ErrCode OH_MediaKeySession_ClearMediaKeys(MediaKeySession *mediaKeySession)

Description

Clears media keys.

Since: 11

Parameters

NameDescription
MediaKeySession *mediaKeySessionPointer to the MediaKeySession instance.

Returns

TypeDescription
Drm_ErrCodeDRM_ERR_OK: The operation is successful.
DRM_ERR_INVALID_VAL: The input parameter mediaKeySession is nullptr or invalid.
DRM_ERR_UNKNOWN: An internal error occurs. Check the log details.

OH_MediaKeySession_GenerateOfflineReleaseRequest()

Drm_ErrCode OH_MediaKeySession_GenerateOfflineReleaseRequest(MediaKeySession *mediaKeySession,uint8_t *offlineMediaKeyId, int32_t offlineMediaKeyIdLen, uint8_t *releaseRequest,int32_t *releaseRequestLen)

Description

Generates a request to release offline media keys.

Since: 11

Parameters

NameDescription
MediaKeySession *mediaKeySessionPointer to the MediaKeySession instance.
uint8_t *offlineMediaKeyIdPointer to the ID of an offline media key.
int32_t *releaseRequestLenLength of the offline media key ID.
uint8_t *releaseRequestPointer to the request to release offline media keys.
int32_t *releaseRequestLenLength of the request to release offline media keys.

Returns

TypeDescription
Drm_ErrCodeDRM_ERR_OK: The operation is successful.
DRM_ERR_NO_MEMORY: Memory allocation fails due to insufficient system memory.
DRM_ERR_INVALID_VAL: The input parameter mediaKeySession is nullptr or invalid, or another parameter of the pointer type is nullptr.
DRM_ERR_UNKNOWN: An internal error occurs or the DRM solution on the device does not support the release of offline media keys. Check the log details.

OH_MediaKeySession_ProcessOfflineReleaseResponse()

Drm_ErrCode OH_MediaKeySession_ProcessOfflineReleaseResponse(MediaKeySession *mediaKeySession,uint8_t *offlineMediaKeyId, int32_t offlineMediaKeyIdLen, uint8_t *releaseResponse,int32_t releaseResponseLen)

Description

Processes the response to a request for releasing offline media keys.

Since: 11

Parameters

NameDescription
MediaKeySession *mediaKeySessionPointer to the MediaKeySession instance.
uint8_t *offlineMediaKeyIdPointer to the ID of an offline media key.
int32_t offlineMediaKeyIdLenLength of the offline media key ID.
uint8_t *releaseResponsePointer to the response.
int32_t releaseResponseLenLength of the response.

Returns

TypeDescription
Drm_ErrCodeDRM_ERR_OK: The operation is successful.
DRM_ERR_INVALID_VAL: The input parameter mediaKeySession is nullptr or invalid, or another parameter of the pointer type is nullptr.
DRM_ERR_UNKNOWN: An internal error occurs or the DRM solution on the device does not support the release of offline media keys. Check the log details.

OH_MediaKeySession_RestoreOfflineMediaKeys()

Drm_ErrCode OH_MediaKeySession_RestoreOfflineMediaKeys(MediaKeySession *mediaKeySession,uint8_t *offlineMediaKeyId, int32_t offlineMediaKeyIdLen)

Description

Restores offline media keys.

Since: 11

Parameters

NameDescription
MediaKeySession *mediaKeySessionPointer to the MediaKeySession instance.
uint8_t *offlineMediaKeyIdPointer to the ID of an offline media key.
int32_t offlineMediaKeyIdLenLength of the offline media key ID.

Returns

TypeDescription
Drm_ErrCodeDRM_ERR_OK: The operation is successful.
DRM_ERR_INVALID_VAL: The input parameter mediaKeySession is nullptr or invalid, or another parameter of the pointer type is nullptr.
DRM_ERR_UNKNOWN: An internal error occurs. Check the log details.

OH_MediaKeySession_GetContentProtectionLevel()

Drm_ErrCode OH_MediaKeySession_GetContentProtectionLevel(MediaKeySession *mediaKeySession,DRM_ContentProtectionLevel *contentProtectionLevel)

Description

Obtains the content protection level of a media key session.

Since: 11

Parameters

NameDescription
MediaKeySession *mediaKeySessionPointer to the MediaKeySession instance.
DRM_ContentProtectionLevel *contentProtectionLevelPointer to the content protection level.

Returns

TypeDescription
Drm_ErrCodeDRM_ERR_OK: The operation is successful.
DRM_ERR_INVALID_VAL: The input parameter mediaKeySession is nullptr or invalid, or contentProtectionLevel is nullptr.
DRM_ERR_UNKNOWN: An internal error occurs. Check the log details.

OH_MediaKeySession_RequireSecureDecoderModule()

Drm_ErrCode OH_MediaKeySession_RequireSecureDecoderModule(MediaKeySession *mediaKeySession,const char *mimeType, bool *status)

Description

Checks whether secure decoding is required.

Since: 11

Parameters

NameDescription
MediaKeySession *mediaKeySessionPointer to the MediaKeySession instance.
const char *mimeTypePointer to the MIME type. The supported MIME types depend on the DRM solution. Example types are video/avc and video/hev.
bool *statusPointer to the result indicating whether secure decoding is required. The value true means that secure decoding is required, and the value false means the opposite.

Returns

TypeDescription
Drm_ErrCodeDRM_ERR_OK: The operation is successful.
DRM_ERR_INVALID_VAL: The input parameter mediaKeySession is nullptr or invalid, or another parameter of the pointer type is nullptr.
DRM_ERR_UNKNOWN: An internal error occurs. Check the log details.

OH_MediaKeySession_SetMediaKeySessionCallback()

Drm_ErrCode OH_MediaKeySession_SetMediaKeySessionCallback(MediaKeySession *mediaKeySession,MediaKeySession_Callback *callback)

Description

Sets a media key session event callback.

Since: 11

Parameters

NameDescription
MediaKeySession *mediaKeySessionPointer to the MediaKeySession instance.
MediaKeySession_Callback *callbackPointer to the callback for the media key session event.

Returns

TypeDescription
Drm_ErrCodeDRM_ERR_OK: The operation is successful.
DRM_ERR_INVALID_VAL: The input parameter mediaKeySession is nullptr or invalid, or callback is nullptr.

OH_MediaKeySession_SetCallback()

Drm_ErrCode OH_MediaKeySession_SetCallback(MediaKeySession *mediaKeySession,OH_MediaKeySession_Callback *callback)

Description

Sets a media key session event callback.

Since: 12

Parameters

NameDescription
MediaKeySession *mediaKeySessionPointer to the MediaKeySession instance.
OH_MediaKeySession_Callback *callbackPointer to the callback for the media key session event.

Returns

TypeDescription
Drm_ErrCodeDRM_ERR_OK: The operation is successful.
DRM_ERR_INVALID_VAL: The input parameter mediaKeySession is nullptr or invalid, or callback is nullptr.

OH_MediaKeySession_Destroy()

Drm_ErrCode OH_MediaKeySession_Destroy(MediaKeySession *mediaKeySession)

Description

Destroys a MediaKeySession instance.

Since: 11

Parameters

NameDescription
MediaKeySession *mediaKeySessionPointer to the MediaKeySession instance.

Returns

TypeDescription
Drm_ErrCodeDRM_ERR_OK: The operation is successful.
DRM_ERR_INVALID_VAL: The input parameter mediaKeySession is nullptr or invalid.
DRM_ERR_UNKNOWN: An internal error occurs. Check the log details.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-drm-drm-mediakeysystemdescription

openharmony 鸿蒙 capi-drm-drm-offlinemediakeyidarray

openharmony 鸿蒙 capi-drm

openharmony 鸿蒙 arkts-apis-drm-MediaKeySession

openharmony 鸿蒙 capi-drm-drm-keysinfo

openharmony 鸿蒙 capi-native-mediakeysystem-h

openharmony 鸿蒙 capi-drm-drm-mediakeyrequest

openharmony 鸿蒙 capi-drm-drm-mediakeyrequestinfo

openharmony 鸿蒙 arkts-apis-drm-MediaKeySystem

openharmony 鸿蒙 capi-native-drm-common-h

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/9lbBgyPk