diff --git a/multimedia/drm_framework/BUILD.gn b/multimedia/drm_framework/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8c04d9bbb4b0f28ca3ab1a238c6ec46758f68ec4 --- /dev/null +++ b/multimedia/drm_framework/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (C) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/ohos/ndk/ndk.gni") +ohos_ndk_headers("native_drm_header") { + dest_dir = "$ndk_headers_out_dir/multimedia/drm_framework" + sources = [ + "./native_mediakeysession.h", + "./native_mediakeysystem.h", + ] +} + +ohos_ndk_library("libnative_drm") { + ndk_description_file = "./libnativedrm.ndk.json" + min_compact_version = "11" + output_name = "native_drm" + output_extension = "so" + + system_capability = "SystemCapability.Multimedia.Drm.Core" + system_capability_headers = [ + "multimedia/drm_framework/native_mediakeysession.h", + "multimedia/drm_framework/native_mediakeysystem.h", + ] +} diff --git a/multimedia/drm_framework/common/native_drm_common.h b/multimedia/drm_framework/common/native_drm_common.h new file mode 100644 index 0000000000000000000000000000000000000000..881be7c068de2cfad8eeb4084b1e0cda09ed8824 --- /dev/null +++ b/multimedia/drm_framework/common/native_drm_common.h @@ -0,0 +1,452 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup Drm + * @{ + * + * @brief Provides APIs of Drm. + * @kit Drm. + * @since 11 + * @version 1.0 + */ + +/** + * @file native_drm_common.h + * + * @brief Defines the Drm common struct. + * @library libnative_drm.z.so + * @Syscap SystemCapability.Multimedia.Drm.Core + * @since 11 + * @version 1.0 + */ + +#ifndef NATIVE_DRM_COMMON_H +#define NATIVE_DRM_COMMON_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Enumerates event types of listener. + * @brief Content potection level. + * @since 11 + * @version 1.0 +*/ +typedef enum DRM_ListenerType { + /** + * DRM event base. + */ + LISTENER_DRM_EVENT = 200, + /** + * Provision required event. + */ + LISTENER_PROVISION_REQUIRED = 201, + /** + * Media key required event. + */ + LISTENER_KEY_REQUIRED = 202, + /** + * Media key expired event. + */ + LISTENER_KEY_EXPIRED = 203, + /** + * Vendor defined event. + */ + LISTENER_VENDOR_DEFINED = 204, + /** + * Expiration update event. + */ + LISTENER_EXPIRATION_UPDATE = 206, + } DRM_ListenerType; + +/** + * @brief Content potection level. + * @Syscap SystemCapability.Multimedia.Drm.Core + * @since 11 + * @version 1.0 + */ +typedef enum DRM_ContentProtectionLevel { + /** + * Content potection level unknown. + */ + CONTENT_PROTECTION_LEVEL_UNKNOWN = 0, + /** + * Content potection level software crypto. + */ + CONTENT_PROTECTION_LEVEL_SW_CRYPTO, + /** + * Content potection level hardware crypto. + */ + CONTENT_PROTECTION_LEVEL_HW_CRYPTO, + /** + * Content potection level enhanced hardware crypto. + */ + CONTENT_PROTECTION_LEVEL_ENHANCED_HW_CRYPTO, + /** + * Content potection level max stub. + */ + CONTENT_PROTECTION_LEVEL_MAX, +} DRM_ContentProtectionLevel; + +/** + * @brief Media key type. + * @Syscap SystemCapability.Multimedia.Drm.Core + * @since 11 + * @version 1.0 + */ +typedef enum DRM_MediaKeyType { + /** + * Media key type offline. + */ + MEDIA_KEY_TYPE_OFFLINE = 0, + /** + * Media key type online + */ + MEDIA_KEY_TYPE_ONLINE, +} DRM_MediaKeyType; + +/** + * @brief Media key request type. + * @Syscap SystemCapability.Multimedia.Drm.Core + * @since 11 + * @version 1.0 + */ +typedef enum DRM_MediaKeyRequestType { + /** + * Media key request type unknown. + */ + MEDIA_KEY_REQUEST_TYPE_UNKNOWN = 0, + /** + * Media key request type initial. + */ + MEDIA_KEY_REQUEST_TYPE_INITIAL, + /** + * Media key request type renewal. + */ + MEDIA_KEY_REQUEST_TYPE_RENEWAL, + /** + * Media key request type release. + */ + MEDIA_KEY_REQUEST_TYPE_RELEASE, + /** + * Media key request type none. + */ + MEDIA_KEY_REQUEST_TYPE_NONE, + /** + * Media key request type update. + */ + MEDIA_KEY_REQUEST_TYPE_UPDATE, +} DRM_MediaKeyRequestType; + +/** + * @brief Offline media key status. + * @Syscap SystemCapability.Multimedia.Drm.Core + * @since 11 + * @version 1.0 + */ +typedef enum DRM_OfflineMediaKeyStatus { + /** + * Offline media key status unknown. + */ + OFFLINE_MEDIA_KEY_STATUS_UNKNOWN = 0, + /** + * Offline media key status usable. + */ + OFFLINE_MEDIA_KEY_STATUS_USABLE, + /** + * Offline media key status inactive. + */ + OFFLINE_MEDIA_KEY_STATUS_INACTIVE, +} DRM_OfflineMediaKeyStatus; + +/** + * @brief Certificate status. + * @Syscap SystemCapability.Multimedia.Drm.Core + * @since 11 + * @version 1.0 + */ +typedef enum DRM_CertificateStatus { + /** + * Device already provisioned. + */ + CERT_STATUS_PROVISIONED = 0, + /** + * Device not provisioned. + */ + CERT_STATUS_NOT_PROVISIONED, + /** + * Cert already expired. + */ + CERT_STATUS_EXPIRED, + /** + * Certs are invalid. + */ + CERT_STATUS_INVALID, + /** + * Get certs status failed. + */ + CERT_STATUS_UNAVAILABLE, +} DRM_CertificateStatus; + +/** + * @brief Media key status. + * @Syscap SystemCapability.Multimedia.Drm.Core + * @since 11 + * @version 1.0 + */ +typedef enum DRM_MediaKeyStatus { + /** + * Media key is usable. + */ + MEDIA_KEY_STATUS_USABLE = 0, + /** + * Media key expires. + */ + MEDIA_KEY_STATUS_EXPIRED, + /** + * Output not allowed with the media key. + */ + MEDIA_KEY_STATUS_OUTPUT_NOT_ALLOWED, + /** + * Media key is pending. + */ + MEDIA_KEY_STATUS_PENDING, + /** + * Media key is in internal error. + */ + MEDIA_KEY_STATUS_INTERNAL_ERROR, + /** + * Media key will be usable in future. + */ + MEDIA_KEY_STATUS_USABLE_IN_FUTURE, +} DRM_MediaKeyStatus; + +/** + * @brief Unsigned char buffer. + * @since 11 + * @version 1.0 + */ +typedef struct DRM_Uint8Buffer { + /** + * Unsigned char buffer addr. + */ + unsigned char *buffer; + /** + * Unsigned char buffer len. + */ + uint32_t bufferLen; +} DRM_Uint8Buffer; + +/** + * @brief Char buffer. + * @since 11 + * @version 1.0 + */ +typedef struct DRM_CharBuffer { + /** + * Char buffer addr. + */ + char *buffer; + /** + * Char buffer len. + */ + uint32_t bufferLen; +} DRM_CharBuffer; + +/** + * @brief Char-char buffer pair. + * @since 11 + * @version 1.0 + */ +typedef struct DRM_CharBufferPair { + /* Name buffer in chars. */ + DRM_CharBuffer name; + /* Value buffer in chars. */ + DRM_CharBuffer value; +} DRM_CharBufferPair; + +/** + * @brief Unsignedchar-char buffer. + * @since 11 + * @version 1.0 + */ +typedef struct DRM_Uint8CharBufferPair { + /* Key buffer in Uint8Array. */ + DRM_Uint8Buffer key; + /* Value buffer in chars. */ + DRM_CharBuffer value; +} DRM_Uint8CharBufferPair; + +/** + * @brief Media key request info. + * @since 11 + * @version 1.0 + */ +typedef struct DRM_MediaKeyRequestInfo { + /** + * Offline or online media key type. + */ + DRM_MediaKeyType type; + /** + * Initial data format as PSSH after base64 encoding. + */ + DRM_Uint8Buffer data; + /** + * Media content mime type. + */ + DRM_CharBuffer mimeType; + /** + * OptionsData count. + */ + uint32_t optionsCount; + /** + * Options data the application set to drm framework. + */ + DRM_CharBufferPair optionsData[0]; +} DRM_MediaKeyRequestInfo; + +/** + * @brief Media key request info. + * @since 11 + * @version 1.0 + */ +typedef struct DRM_MediaKeyRequest { + /** + * Media key request type. + */ + DRM_MediaKeyRequestType type; + /** + * Media key request data sent to media key server. + */ + DRM_Uint8Buffer data; + /** + * Media key server URL. + */ + DRM_CharBuffer defaultUrl; +} DRM_MediaKeyRequest; + +/** + * @brief Statistics of MediaKeySystem. + * @since 11 + * @version 1.0 + */ +typedef struct DRM_Statistics { + /* Statistics count. */ + uint32_t statisticsCount; + /* Statistics info. */ + DRM_CharBufferPair info[0]; +} DRM_Statistics; + +/** + * @brief MediaKeyIds array. + * @since 11 + * @version 1.0 + */ +typedef struct DRM_MediakeyIdArray { + /* MediaKeyId count. */ + uint32_t mediaKeyIdCount; + /* MediaKeyIds. */ + DRM_Uint8Buffer mediaKeyIds[0]; +} DRM_MediakeyIdArray; + +/** + * @brief Media key info. + * @since 11 + * @version 1.0 + */ +typedef struct DRM_KeysInfo { + /* Keys count. */ + uint32_t keysCount; + /* Keys info. */ + DRM_Uint8CharBufferPair keysInfo[0]; +} DRM_KeysInfo; + +/** + * @brief MediaKeydescription + * @since 11 + * @version 1.0 + */ +typedef struct DRM_MediaKeyDescription { + /* MediaKeycount. */ + uint32_t mediaKeyCount; + /* MediaKeyinfo. */ + DRM_CharBufferPair description[0]; +} DRM_MediaKeyDescription; + +/** + * @brief Drm system uuid. + * @since 11 + * @version 1.0 + */ +#define DRM_UUID_LEN 16 + +/** + * @brief PSSH info by uuid. + * @since 11 + * @version 1.0 + */ +typedef struct DRM_PsshInfo { + /** + * Uuid. + */ + char uuid[DRM_UUID_LEN]; + /** + * Unsigned char PSSH len. + */ + uint32_t dataLen; + /** + * Unsigned char PSSH data. + */ + unsigned char *data; +} DRM_PsshInfo; + +/** + * @brief MediaKeySystemInfo used for player to get media key system info from media source. + * @since 11 + * @version 1.0 + */ +typedef struct DRM_MediaKeySystemInfo { + /* PSSH count. */ + uint32_t psshCount; + /* PSSH info. */ + DRM_PsshInfo psshInfo[0]; +} DRM_MediaKeySystemInfo; + +typedef void (*DRM_MediaKeySystemInfoCallback)(DRM_MediaKeySystemInfo* mediaKeySystemInfo); + +/** + * @brief Media key system struct. + * @since 11 + * @version 1.0 + */ +typedef struct MediaKeySystem MediaKeySystem; + +/** + * @brief Media key session struct. + * @since 11 + * @version 1.0 + */ +typedef struct MediaKeySession MediaKeySession; + +#ifdef __cplusplus +} +#endif + +#endif // NATIVE_DRM_COMMON_H \ No newline at end of file diff --git a/multimedia/drm_framework/common/native_drm_err.h b/multimedia/drm_framework/common/native_drm_err.h new file mode 100644 index 0000000000000000000000000000000000000000..40e5b60ff56abe3b10fadd6c2757530042ce5f2b --- /dev/null +++ b/multimedia/drm_framework/common/native_drm_err.h @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup Drm + * @{ + * + * @brief Provides APIs of Drm. + * @kit Drm. + * @since 11 + * @version 1.0 + */ + +/** + * @file native_drm_err.h + * @brief Defines the Drm errors. + * @library libnative_drm.z.so + * @Syscap SystemCapability.Multimedia.Drm.Core + * @since 11 + * @version 1.0 + */ + +#ifndef NATIVE_DRM_ERR_H +#define NATIVE_DRM_ERR_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief DRM error code + * @since 11 + * @version 1.0 + */ +typedef enum Drm_ErrCode { + /** + * the operation completed successfully. + */ + DRM_ERR_OK = 0, + /** + * no memory. + */ + DRM_ERR_NO_MEMORY, + /** + * opertation not be permitted. + */ + DRM_ERR_OPERATION_NOT_PERMITTED, + /** + * invalid argument. + */ + DRM_ERR_INVALID_VAL, + /** + * IO error. + */ + DRM_ERR_IO, + /** + * network timeout. + */ + DRM_ERR_TIMEOUT, + /** + * unknown error. + */ + DRM_ERR_UNKNOWN, + /** + * drm service died. + */ + DRM_ERR_SERVICE_DIED, + /** + * not support this operation in this state. + */ + DRM_ERR_INVALID_STATE, + /** + * unsupport interface. + */ + DRM_ERR_UNSUPPORTED, + /** + * Meet max MediaKeySystem num limit. + */ + DRM_ERR_MAX_SYSTEM_NUM_REACHED, + /** + * Meet max MediaKeySession num limit. + */ + DRM_ERR_MAX_SESSION_NUM_REACHED, + /** + * extend err start. + */ + DRM_ERR_EXTEND_START = 100, +} Drm_ErrCode; + +#ifdef __cplusplus +} +#endif + +#endif // NATIVE_DRM_ERR_H \ No newline at end of file diff --git a/multimedia/drm_framework/libnativedrm.ndk.json b/multimedia/drm_framework/libnativedrm.ndk.json new file mode 100644 index 0000000000000000000000000000000000000000..859f6423ebf69af8266d899300a799ad240987ca --- /dev/null +++ b/multimedia/drm_framework/libnativedrm.ndk.json @@ -0,0 +1,32 @@ +[ + { "name": "OH_MediaKeySystem_IsSupported" }, + { "name": "OH_MediaKeySystem_IsSupported2" }, + { "name": "OH_MediaKeySystem_IsSupported3" }, + { "name": "OH_MediaKeySystem_Create" }, + { "name": "OH_MediaKeySystem_SetConfigurationString" }, + { "name": "OH_MediaKeySystem_GetConfigurationString" }, + { "name": "OH_MediaKeySystem_SetConfigurationByteArray" }, + { "name": "OH_MediaKeySystem_GetConfigurationByteArray" }, + { "name": "OH_MediaKeySystem_GetStatistics" }, + { "name": "OH_MediaKeySystem_GetMaxContentProtectionLevel" }, + { "name": "OH_MediaKeySystem_SetMediaKeySystemCallback" }, + { "name": "OH_MediaKeySystem_CreateMediaKeySession" }, + { "name": "OH_MediaKeySystem_GenerateKeySystemRequest" }, + { "name": "OH_MediaKeySystem_ProcessKeySystemResponse" }, + { "name": "OH_MediaKeySystem_GetOfflineMediaKeyIds" }, + { "name": "OH_MediaKeySystem_GetOfflineMediaKeyStatus" }, + { "name": "OH_MediaKeySystem_ClearOfflineMediaKeys" }, + { "name": "OH_MediaKeySystem_GetCertificateStatus" }, + { "name": "OH_MediaKeySystem_Destroy" }, + { "name": "OH_MediaKeySession_GenerateMediaKeyRequest" }, + { "name": "OH_MediaKeySession_ProcessMediaKeyResponse" }, + { "name": "OH_MediaKeySession_CheckMediaKeyStatus" }, + { "name": "OH_MediaKeySession_ClearMediaKeys" }, + { "name": "OH_MediaKeySession_GenerateOfflineReleaseRequest" }, + { "name": "OH_MediaKeySession_ProcessOfflineReleaseResponse" }, + { "name": "OH_MediaKeySession_RestoreOfflineMediaKeys" }, + { "name": "OH_MediaKeySession_GetContentProtectionLevel" }, + { "name": "OH_MediaKeySession_RequireSecureDecoderModule" }, + { "name": "OH_MediaKeySession_SetMediaKeySessionCallback" }, + { "name": "OH_MediaKeySession_Destroy" } +] \ No newline at end of file diff --git a/multimedia/drm_framework/native_mediakeysession.h b/multimedia/drm_framework/native_mediakeysession.h new file mode 100644 index 0000000000000000000000000000000000000000..9c377ce2a7d89055578817dd60a8f5530a60f999 --- /dev/null +++ b/multimedia/drm_framework/native_mediakeysession.h @@ -0,0 +1,214 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup Drm + * @{ + * + * @brief Provides APIs of Drm. + * @kit Drm. + * @since 11 + * @version 1.0 + */ + +/** + * @file native_mediakeysession.h + * @brief Defines the Drm MediaKeySession APIs. Provide following function: + * generate media key request, process media key response, event listening, + * get content protection level, check media key status, remove media key etc.. + * @library libnative_drm.z.so + * @Syscap SystemCapability.Multimedia.Drm.Core + * @since 11 + * @version 1.0 + */ + +#ifndef OHOS_DRM_NATIVE_MEDIA_KEY_SESSION_H +#define OHOS_DRM_NATIVE_MEDIA_KEY_SESSION_H + +#include +#include +#include "native_drm_err.h" +#include "native_drm_common.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** + * @brief Call back will be invoked when event triggers. + * @param eventType Event type. + * @param eventInfo Event info gotten from media key system. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +typedef Drm_ErrCode (*MediaKeySession_EventCallback)(DRM_ListenerType eventType, DRM_Uint8CharBufferPair *eventInfo); + +/** + * @brief Call back will be invoked when key changes. + * @param keysInfo Key info gotten from media key system. + * @param newKeysAvailable If new keys available. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +typedef Drm_ErrCode (*MediaKeySession_KeyChangeCallback)(DRM_KeysInfo *keysInfo, bool newKeysAvailable); + +/** + * @brief MediaKeySession_Callback struct, used to listen event like key expired and key change etc.. + * @since 11 + * @version 1.0 + */ +typedef struct MediaKeySession_Callback { + /** + * Normal event callback like key expired etc.. + */ + MediaKeySession_EventCallback eventCallback; + /** + * Key change callback for keys change event. + */ + MediaKeySession_KeyChangeCallback keyChangeCallback; +} MediaKeySession_Callback; + +/** + * @brief Generate media key request. + * @param mediaKeySession Media key session instance. + * @param info Media key request info. + * @param mediaKeyRequest Media key request. + * @return Drm_ErrCode. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySession_GenerateMediaKeyRequest(MediaKeySession *mediaKeySession, + DRM_MediaKeyRequestInfo *info, DRM_MediaKeyRequest **mediaKeyRequest); + +/** + * @brief Process media key response. + * @param mediaKeySession Media key session instance. + * @param response Media Key resposne. + * @param mediaKeyId Media key identifier. + * @param mediaKeyIdLen Media key identifier len. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySession_ProcessMediaKeyResponse(MediaKeySession *keySession, + DRM_Uint8Buffer *response, unsigned char **mediaKeyId, int32_t *mediaKeyIdLen); + +/** + * @brief Check media key status. + * @param mediaKeySession Media key session instance. + * @param mediaKeyDescription Media key status description. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySession_CheckMediaKeyStatus(MediaKeySession *mediaKeySessoin, + DRM_MediaKeyDescription **mediaKeyDescription); + +/** + * @brief Clear media keys of the current session . + * @param mediaKeySession Media key session instance. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySession_ClearMediaKeys(MediaKeySession *mediaKeySessoin); + +/** + * @brief Generate offline media key release request. + * @param mediaKeySession Media key session instance. + * @param mediaKeyId Media key identifier. + * @param releaseRequest Media Key release request. + * @param releaseRequestLen Media Key release request len. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySession_GenerateOfflineReleaseRequest(MediaKeySession *mediaKeySessoin, + DRM_Uint8Buffer *mediaKeyId, unsigned char **releaseRequest, int32_t *releaseRequestLen); + +/** + * @brief Process offline media key release response. + * @param mediaKeySession Media key session instance. + * @param mediaKeyId Media key identifier. + * @param releaseReponse Media Key resposne. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySession_ProcessOfflineReleaseResponse(MediaKeySession *mediaKeySessoin, + DRM_Uint8Buffer *mediaKeyId, DRM_Uint8Buffer *releaseReponse); + +/** + * @brief Restore offline media keys by ID. + * @param mediaKeySession Media key session instance. + * @param mediaKeyId Media key identifier. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySession_RestoreOfflineMediaKeys(MediaKeySession *mediaKeySessoin, + DRM_Uint8Buffer *mediaKeyId); + +/** + * @brief Get content protection level of the session. + * @param mediaKeySession Media key session instance. + * @param contentProtectionLevel Content protection level. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySession_GetContentProtectionLevel(MediaKeySession *mediaKeySessoin, + DRM_ContentProtectionLevel *contentProtectionLevel); + +/** + * @brief Whether the encrypted content require a secure decoder or not. + * @param mediaKeySession Media key session instance. + * @param mimeType The media type. + * @param status Whether secure decoder is required. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySession_RequireSecureDecoderModule(MediaKeySession *mediaKeySessoin, + const char *mimeType, bool *status); + +/** + * @brief Set media key session event callback. + * @param mediaKeySession Media key session instance. + * @param callback Callback to be set to the media key session. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySession_SetMediaKeySessionCallback(MediaKeySession *mediaKeySessoin, + MediaKeySession_Callback *callback); + +/** + * @brief Release the resource before the session gonna be unused. + * @param mediaKeySession Media key session instance. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySession_Destroy(MediaKeySession *mediaKeySessoin); + +#ifdef __cplusplus +} +#endif + +#endif // OHOS_DRM_NATIVE_MEDIA_KEY_SYSTEM_H \ No newline at end of file diff --git a/multimedia/drm_framework/native_mediakeysystem.h b/multimedia/drm_framework/native_mediakeysystem.h new file mode 100644 index 0000000000000000000000000000000000000000..9e62402799d7bee6c3626b68d2cb5ddb0e825adb --- /dev/null +++ b/multimedia/drm_framework/native_mediakeysystem.h @@ -0,0 +1,284 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup Drm + * @{ + * + * @brief Provides APIs of Drm. + * @kit Drm. + * @since 11 + * @version 1.0 + */ + +/** + * @file native_mediakeysystem.h + * @brief Defines the Drm MediaKeySystem APIs. Provide following function: + * query if specific drm supported or not, create media key session, + * get and set configurations, get statistics, get content protection level, + * generate provision request, process provision response, event listening, + * get content protection level, manage offline media key etc.. + * @library libnative_drm.z.so + * @Syscap SystemCapability.Multimedia.Drm.Core + * @since 11 + * @version 1.0 + */ + +#ifndef OHOS_DRM_NATIVE_MEDIA_KEY_SYSTEM_H +#define OHOS_DRM_NATIVE_MEDIA_KEY_SYSTEM_H + +#include +#include +#include +#include "native_drm_err.h" +#include "native_drm_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Call back will be invoked when event triggers. + * @param eventType Event type. + * @param eventInfo Event info gotten from media key system. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +typedef Drm_ErrCode (*MediaKeySystem_Callback)(DRM_ListenerType eventType, DRM_Uint8CharBufferPair *eventInfo); +/** + * @brief Get a media key system name by uuid. + * @param uuid Secifies drm system. + * @param name Name string to be gotten. + * @param nameLen Name string len. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySystem_GetMediaKeySystemName(const char *uuid, unsigned char **name, int32_t *nameLen); + +/** + * @brief Query if media key system is supported. + * @param name Used to point a Digital Right Management solution. + * @return Supported or not in boolean. + * @since 11 + * @version 1.0 + */ +bool OH_MediaKeySystem_IsSupported(const char *name); +/** + * @brief Query if media key system is supported. + * @param name Used to point a Digital Right Management solution. + * @param mimeType Used to specifies the media type. + * @return Supported or not in boolean. + * @since 11 + * @version 1.0 + */ +bool OH_MediaKeySystem_IsSupported2(const char *name, const char *mimeType); +/** + * @brief Query if media key system is supported. + * @param name Used to point a Digital Right Management solution. + * @param mimeType Used to specifies the media type. + * @param contentProtectionLevel Used to specifies the ContentProtectionLevel. + * @return Supported or not in boolean. + * @since 11 + * @version 1.0 + */ +bool OH_MediaKeySystem_IsSupported3(const char *name, const char *mimeType, + DRM_ContentProtectionLevel contentProtectionLevel); + +/** + * @brief Creates a media key system instance from the name. + * @param name Secifies which drm system will be created by name. + * @param mediaKeySystem Media key system instance. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully, + * return DRM_ERR_MAX_SYSTEM_NUM_REACHED when max num media key system reached. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySystem_Create(const char *name, MediaKeySystem **mediaKeySystem); +/** + * @brief Set media key system configuration value by name. + * @param mediaKeySystem Media key system instance. + * @param configName Configuratoin name string. + * @param value Configuratoin vaule string to be set. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySystem_SetConfigurationString(MediaKeySystem *mediaKeySystem, + const char *configName, const char *value); +/** + * @brief Get media key system configuration value by name. + * @param mediaKeySystem Media key system instance. + * @param configName Configuratoin name string. + * @param value Configuratoin vaule string to be get. + * @param valueLen Configuratoin vaule string len. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySystem_GetConfigurationString(MediaKeySystem *mediaKeySystem, + const char *configName, char **value, int32_t *valueLen); +/** + * @brief Set media key system configuration value by name. + * @param mediaKeySystem Media key system instance. + * @param configName Configuratoin name string. + * @param value Configuratoin vaule in byte array to be set. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySystem_SetConfigurationByteArray(MediaKeySystem *mediaKeySystem, + const char *configName, DRM_Uint8Buffer *value); +/** + * @brief Get media key system configuration value by name. + * @param mediaKeySystem Media key system instance. + * @param configName Configuratoin name string. + * @param value Configuratoin vaule in byte array to be get. + * @param valueLen Configuratoin vaule len in byte. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySystem_GetConfigurationByteArray(MediaKeySystem *mediaKeySystem, + const char *configName, unsigned char **value, int32_t *valueLen); +/** + * @brief Get media key system statistics info. + * @param mediaKeySystem Media key system instance. + * @param statistics Statistic info gotten. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySystem_GetStatistics(MediaKeySystem *mediaKeySystem, DRM_Statistics **statistics); +/** + * @brief Get the max content protection level media key system supported. + * @param mediaKeySystem Media key system instance. + * @param contentProtectionLevel Content protection level. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySystem_GetMaxContentProtectionLevel(MediaKeySystem *mediaKeySystem, + DRM_ContentProtectionLevel *contentProtectionLevel); +/** + * @brief Set media key system event callback. + * @param mediaKeySystem Media key system instance. + * @param callback Callback to be set to the media key system. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OR when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySystem_SetMediaKeySystemCallback(MediaKeySystem *mediaKeySystem, + MediaKeySystem_Callback callback); + +/** + * @brief Create a media key session instance. + * @param mediaKeySystem Media key system instance which will create the media key session. + * @param level Specifies the content protection level. + * @param mediaKeySession Media key session instance. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully, + * return DRM_ERR_MAX_SESSION_NUM_REACHED when max num media key system reached. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySystem_CreateMediaKeySession(MediaKeySystem *mediaKeySystem, + DRM_ContentProtectionLevel *level, MediaKeySession **mediaKeySession); + +/** + * @brief Generate a media key system provision request. + * @param mediaKeySystem Media key system instance. + * @param request Provision request data sent to provision server. + * @param requestLen Provision request data len. + * @param defaultUrl Provision server URL. + * @param defaultUrlLen Provision server URL len. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySystem_GenerateKeySystemRequest(MediaKeySystem *mediaKeySystem, unsigned char **request, + int32_t *requestLen, char **defaultUrl, int32_t *defaultUrlLen); + +/** + * @brief Process a media key system provision response. + * @param mediaKeySystem Media key system instance. + * @param response The provision reponse will be processed. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySystem_ProcessKeySystemResponse(MediaKeySystem *mediaKeySystem, + DRM_Uint8Buffer *response); + +/** + * @brief Get offline media key ids . + * @param mediaKeySystem Media key system instance. + * @param mediaKeyIds Media key ids of all offline media keys. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySystem_GetOfflineMediaKeyIds(MediaKeySystem *mediaKeySystem, + DRM_MediakeyIdArray **mediaKeyIds); + +/** + * @brief Get offline media key status. + * @param mediaKeySystem Media key system instance. + * @param mediaKeyId Media key identifier. + * @param status The media key status gotten. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySystem_GetOfflineMediaKeyStatus(MediaKeySystem *mediaKeySystem, + DRM_Uint8Buffer *mediaKeyId, DRM_OfflineMediaKeyStatus *status); + +/** + * @brief Clear an offline media key by id. + * @param mediaKeySystem Media key system instance. + * @param mediaKeyId Media key identifier. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySystem_ClearOfflineMediaKeys(MediaKeySystem *mediaKeySystem, + DRM_Uint8Buffer *mediaKeyId); + +/** + * @brief Get certificate status of media key system. + * @param mediaKeySystem Media key system instance. + * @param certStatus Status will be gotten. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySystem_GetCertificateStatus(MediaKeySystem *mediaKeySystem, + DRM_CertificateStatus *certStatus); + +/** + * @brief Destroy a media key system instance. + * @param mediaKeySystem Secifies which media key system instance will be destroyed. + * @return DRM_ERR_INVALID_VAL when the params checked failure, return DRM_ERR_OK when function called successfully. + * @since 11 + * @version 1.0 + */ +Drm_ErrCode OH_MediaKeySystem_Destroy(MediaKeySystem *mediaKeySystem); + + +#ifdef __cplusplus +} +#endif + +#endif // OHOS_DRM_NATIVE_MEDIA_KEY_SYSTEM_H \ No newline at end of file