diff --git a/multimedia/drm_framework/BUILD.gn b/multimedia/drm_framework/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a55bca69ef5df9b1fcda66291795f7dc166deca4 --- /dev/null +++ b/multimedia/drm_framework/BUILD.gn @@ -0,0 +1,85 @@ +# 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/ace/ace.gni") + +DRM_ROOT_DIR = "//foundation/multimedia/drm_framework" + +group("drm_capi_package") { + deps = [] + deps += [ + "$DRM_ROOT_DIR/interfaces/kits/c/drm_capi:native_drm", + ] +} + +config("drm_capi_common_config") { + include_dirs = [ + "$DRM_ROOT_DIR/interfaces/kits/c/drm_capi/include", + "$DRM_ROOT_DIR/interfaces/kits/c/drm_capi/common", + "$DRM_ROOT_DIR/interfaces/inner_api/native/drm", + "$DRM_ROOT_DIR/services/utils/include", + "//foundation//arkui/napi/interfaces/kits", + "//utils/system/safwk/native/include", + "//foundation/multimedia/drm_framework/frameworks/native/drm", + ] + cflags = [ + "-fno-exceptions", + "-Wall", + "-fno-common", + "-fstack-protector-all", + "-Wshadow", + "-FPIC", + "-FS", + "-O2", + "-D_FORTIFY_SOURCE=2", + "-Wformat=2", + "-Wdate-time", + ] + + cflags_cc = [ + "-std=c++17", + "-fno-rtti", + ] +} + +ohos_shared_library("native_drm") { + install_enable = true + configs = [ ":drm_capi_common_config" ] + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = true + } + + sources = [ + "$DRM_ROOT_DIR/frameworks/c/drm_capi/native_mediakeysystem.cpp", + "$DRM_ROOT_DIR/frameworks/c/drm_capi/native_mediakeysession.cpp", + ] + + deps = [ + "$DRM_ROOT_DIR/frameworks/native:drm_framework", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "napi:ace_napi", + ] + output_extension = "so" + subsystem_name = "multimedia" + part_name = "multimedia_drm_framework" +} + diff --git a/multimedia/drm_framework/common/native_drm_base.h b/multimedia/drm_framework/common/native_drm_base.h new file mode 100644 index 0000000000000000000000000000000000000000..654bb0e02e2c4da3c8f40cb43f4e084eaad581c5 --- /dev/null +++ b/multimedia/drm_framework/common/native_drm_base.h @@ -0,0 +1,52 @@ +/* + * 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. + */ + +#ifndef NATIVE_DRM_BASE_H +#define NATIVE_DRM_BASE_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif +/** + * @brief MediaKeySystem struct. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_MediaKeySystem : public OHOS::RefBase { + OH_MediaKeySystem() = default; + virtual ~OH_MediaKeySystem() = default; +} OH_MediaKeySystem; + +/** + * @brief MediaKeySession struct. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_MediaKeySession : public OHOS::RefBase { + OH_MediaKeySession() = default; + virtual ~OH_MediaKeySession() = default; +} OH_MediaKeySession; + +#ifdef __cplusplus +} +#endif + +#endif // NATIVE_DRM_BASE_H \ No newline at end of file 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..cebbf81a1d50aee9f4bf37965bccec4706dfcd35 --- /dev/null +++ b/multimedia/drm_framework/common/native_drm_common.h @@ -0,0 +1,379 @@ +/* + * 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. + */ + +#ifndef NATIVE_DRM_COMMON_H +#define NATIVE_DRM_COMMON_H + +#include +#include +#include "native_drm_err.h" +#include "native_drm_base.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup Drm + * @{ + * + * @brief Provides APIs of Drm. + * + * @Syscap SystemCapability.Multimedia.Drm.Core + * @since 11 + * @version 1.0 + */ + +/** + * @file native_drm_common.h + * + * @brief Defines the Drm common struct. + * + * @library libdrm_framework.z.so + * @since 11 + * @version 1.0 + */ + +/** + * @brief Content potection level. + * @syscap SystemCapability.Multimedia.Drm.Core + * @since 11 + * @version 1.0 + */ +typedef enum OH_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 all levels supported. + */ + CONTENT_PROTECTION_LEVEL_HW_ALL, + /** + * Content potection level max stub. + */ + CONTENT_PROTECTION_LEVEL_MAX, +} OH_DRM_ContentProtectionLevel; + +/** + * @brief Media key type. + * @syscap SystemCapability.Multimedia.Drm.Core + * @since 11 + * @version 1.0 + */ +typedef enum OH_DRM_MediaKeyType { + /** + * Media key type offline. + */ + MEDIA_KEY_TYPE_OFFLINE = 0, + /** + * Media key type online + */ + MEDIA_KEY_TYPE_ONLINE, +} OH_DRM_MediaKeyType; + +/** + * @brief Media key request type. + * @syscap SystemCapability.Multimedia.Drm.Core + * @since 11 + * @version 1.0 + */ +typedef enum OH_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, +} OH_DRM_MediaKeyRequestType; + +/** + * @brief Offline media key status. + * @syscap SystemCapability.Multimedia.Drm.Core + * @since 11 + * @version 1.0 + */ +typedef enum OH_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, +} OH_DRM_OfflineMediaKeyStatus; + +/** + * @brief Certificate status. + * @syscap SystemCapability.Multimedia.Drm.Core + * @since 11 + * @version 1.0 + */ +typedef enum OH_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, +} OH_DRM_CertificateStatus; + +/** + * @brief Offline media key status. + * @syscap SystemCapability.Multimedia.Drm.Core + * @since 11 + * @version 1.0 + */ +typedef enum OH_DRM_MediaKeyStatus { + /** + * Media key status OK. + */ + MEDIA_KEY_STATUS_OK = 0, + /** + * Media key is invalid e.g. not exist. + */ + MEDIA_KEY_STATUS_NOT_EXIST = 1, +} OH_DRM_MediaKeyStatus; + +/** + * @brief Unsigned char buffer. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_DRM_Uint8Buffer { + /** + * Unsigned char buffer addr. + */ + unsigned char *buffer; + /** + * Unsigned char buffer len. + */ + uint32_t bufferLen; +} OH_DRM_Uint8Buffer; + +/** + * @brief Char buffer. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_DRM_CharBuffer { + /** + * Char buffer addr. + */ + char *buffer; + /** + * Char buffer len. + */ + uint32_t bufferLen; +} OH_DRM_CharBuffer; + +/** + * @brief Char-char buffer pair. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_DRM_CharBufferPair { + /* Name buffer in chars.*/ + OH_DRM_CharBuffer name; + /* Value buffer in chars.*/ + OH_DRM_CharBuffer value; +} OH_DRM_CharBufferPair; + +/** + * @brief Unsignedchar-char buffer. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_DRM_Uint8CharBufferPair { + /* Key buffer in Uint8Array.*/ + OH_DRM_Uint8Buffer key; + /* Value buffer in chars.*/ + OH_DRM_CharBuffer value; +} OH_DRM_Uint8CharBufferPair; + +/** + * @brief Media key request info. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_DRM_MediaKeyRequestInfo { + /** + * Offline or online media key type. + */ + OH_DRM_MediaKeyType type; + /** + * Initial data format as PSSH after base64 encoding. + */ + OH_DRM_Uint8Buffer data; + /** + * Media content mime type. + */ + OH_DRM_CharBuffer mimeType; + /** + * OptionsData count. + */ + uint32_t optionsCount; + /** + * Options data the application set to drm framework. + */ + OH_DRM_CharBufferPair *optionsData; +} OH_DRM_MediaKeyRequestInfo; + +/** + * @brief Statistics of OH_MediaKeySystem. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_DRM_Statistics { + /* Statistics count.*/ + uint32_t statisticsCount; + /* Statistics info.*/ + OH_DRM_CharBufferPair *info; +} OH_DRM_Statistics; + +/** + * @brief MediaKeyIds array. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_DRM_MediakeyIdArray { + /* MediaKeyId count.*/ + uint32_t mediaKeyIdCount; + /* MediaKeyIds.*/ + OH_DRM_Uint8Buffer *mediaKeyIds; +} OH_DRM_MediakeyIdArray; + +/** + * @brief Media key info. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_DRM_KeysInfo { + /* Keys count.*/ + uint32_t keysCount; + /* Keys info.*/ + OH_DRM_Uint8CharBufferPair *keysInfo; +} OH_DRM_KeysInfo; + +/** + * @brief MediaKeydescription + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_DRM_MediaKeyDescription { + /* MediaKeycount.*/ + uint32_t mediaKeyCount; + /* MediaKeyinfo.*/ + OH_DRM_CharBufferPair *description; +} OH_DRM_MediaKeyDescription; + +/** + * @brief PSSH info by uuid. + * + * @since 11 + * @version 1.0 + */ +#define UUID_LEN 16 +typedef struct OH_DRM_PsshInfo { + /** + * Uuid. + */ + char uuid[UUID_LEN]; + /** + * Unsigned char PSSH len. + */ + uint32_t dataLen; + /** + * Unsigned char PSSH data. + */ + unsigned char *data; +} OH_DRM_PsshInfo; + +/** + * @brief DrmInfo used for player to get DRM info from media source. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_DRM_DrmInfo { + /* PSSH count.*/ + uint32_t psshCount; + /* PSSH info.*/ + OH_DRM_PsshInfo *psshInfo; +} OH_DRM_DrmInfo; + +#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..6d29aef104c8858259d06ddea2abb40e5e61e147 --- /dev/null +++ b/multimedia/drm_framework/common/native_drm_err.h @@ -0,0 +1,91 @@ +/* + * 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. + */ + +#ifndef NATIVE_DRM_ERR_H +#define NATIVE_DRM_ERR_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief DRM error code + * @syscap SystemCapability.Multimedia.Drm.Core + * @since 11 + * @version 1.0 + */ +typedef enum OH_DrmErrCode { + /** + * the operation completed successfully. + */ + DRM_ERR_OK = 0, + /** + * no memory. + */ + DRM_ERR_NO_MEMORY, + /** + * opertation not be permitted. + */ + DRM_ERR_OPERATE_NOT_PERMIT, + /** + * 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_UNSUPPORT, + /** + * 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, +} OH_DrmErrCode; + +#ifdef __cplusplus +} +#endif + +#endif // NATIVE_DRM_ERR_H \ No newline at end of file diff --git a/multimedia/drm_framework/common/native_drm_object.h b/multimedia/drm_framework/common/native_drm_object.h new file mode 100644 index 0000000000000000000000000000000000000000..91b2145a62e458b100a83b8b2a2354c836c7e7ae --- /dev/null +++ b/multimedia/drm_framework/common/native_drm_object.h @@ -0,0 +1,52 @@ +/* + * 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. + */ + +#ifndef NATIVE_DRM_OBJECT_H +#define NATIVE_DRM_OBJECT_H + +#include +#include +#include "native_drm_err.h" +#include "native_drm_base.h" + +#include "key_session_impl.h" +#include "media_key_system_impl.h" +#include "media_key_system_factory_impl.h" +#include "media_decrypt_module_impl.h" + +struct MediaKeySystemObject : public OH_MediaKeySystem +{ + explicit MediaKeySystemObject(const OHOS::sptr &impl) + : systemImpl_(impl) + { + } + ~MediaKeySystemObject() = default; + + const OHOS::sptr systemImpl_ = nullptr; +}; + +struct MediaKeySessionObject : public OH_MediaKeySession +{ + explicit MediaKeySessionObject(const OHOS::sptr &impl) + : sessionImpl_(impl) + { + } + ~MediaKeySessionObject() = default; + + const OHOS::sptr sessionImpl_ = nullptr; +}; + + +#endif // NATIVE_DRM_OBJECT_H \ No newline at end of file diff --git a/multimedia/drm_framework/include/BUILD.gn b/multimedia/drm_framework/include/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9db3488d41bf89dda8a82ea3eaf6ca3144761765 --- /dev/null +++ b/multimedia/drm_framework/include/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (C) 2022 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/multimedia_drm_framework" + sources = [ + "//foundation/multimedia/drm_framework/interfaces/kits/c/drm_capi/include/native_mediakeysession.h", + "//foundation/multimedia/drm_framework/interfaces/kits/c/drm_capi/include/native_mediakeysystem.h" + ] +} + +ohos_ndk_library("libnative_drm") { + ndk_description_file = "./libnative_drm.ndk.json" + min_compact_version = "1" + 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", + ] +} \ No newline at end of file diff --git a/multimedia/drm_framework/include/libnative_drm.ndk.json b/multimedia/drm_framework/include/libnative_drm.ndk.json new file mode 100644 index 0000000000000000000000000000000000000000..cd2af3891389999624fd0588f31230329c00ebf4 --- /dev/null +++ b/multimedia/drm_framework/include/libnative_drm.ndk.json @@ -0,0 +1,8 @@ +[ + { "name": "OH_MediaKeySystem_Create" }, + { "name": "OH_MediaKeySystem_Destroy" }, + { "name": "OH_MediaKeySystem_CreateMediaKeySession" }, + { "name": "OH_MediaKeySession_GenerateLicenseRequest" }, + { "name": "OH_MediaKeySession_ProcessLicenseResponse" }, + { "name": "OH_MediaKeySession_CheckLicenseStatus" } +] \ No newline at end of file diff --git a/multimedia/drm_framework/include/native_mediakeysession.h b/multimedia/drm_framework/include/native_mediakeysession.h new file mode 100644 index 0000000000000000000000000000000000000000..71212f6a3951c4f9bbe11fef644b714f1ed094d7 --- /dev/null +++ b/multimedia/drm_framework/include/native_mediakeysession.h @@ -0,0 +1,198 @@ +/* + * 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. + * + * @Syscap SystemCapability.Multimedia.Drm.Core + * @since 11 + * @version 1.0 + */ + +/** + * @file native_mediakeysession.h + * + * @brief Defines the Drm MediaKeySession APIs. + * + * @library libdrm_framework.z.so + * @since 11 + * @version 1.0 + */ + +#ifndef OHOS_DRM_NATIVE_MEDIA_KEY_SYSTEM_H +#define OHOS_DRM_NATIVE_MEDIA_KEY_SYSTEM_H + +#include +#include +#include "native_drm_common.h" +#include "native_drm_base.h" +#include "native_drm_err.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef OH_DrmErrCode (*OH_MediaKeySessionEventCallback)(OH_DRM_CharBufferPair *eventInfo); +typedef OH_DrmErrCode (*OH_MediaKeySessionKeyChangeCallback)(OH_DRM_CharBufferPair *OH_DRM_KeysInfo); +/** + * @brief OH_MediaKeySessionCallback struct, used to listen event like key expired and + * key change etc.. + * + * @since 11 + * @version 1.0 + */ +typedef struct OH_MediaKeySessionCallback { + /** + * Normal event callback like key expired etc.. + */ + OH_MediaKeySessionEventCallback eventCallback; + /** + * Key change callback for keys change event. + */ + OH_MediaKeySessionKeyChangeCallback keyChangeCallback; +} OH_MediaKeySessionCallback; + +/** + * @brief Generate media key request. + * @param mediaKeySession Media key session instance. + * if the function return DRM_ERR_OK. + * @param info Media key request info. + * @param mediaKeyRequest Media key request. + * @return OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySession_GenerateMediaKeyRequest(OH_MediaKeySession *mediaKeySession, + OH_DRM_MediaKeyRequestInfo *info, unsigned char **mediaKeyRequest, int32_t *mediaKeyRequestLen); + +/** + * @brief Process media key response. + * @param mediaKeySession Media key session instance. + * @param response Media Key resposne. + * @param mediaKeyId Media key identifier. + * @return OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySession_ProcessMediaKeyResponse(OH_MediaKeySession *keySession, + OH_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 OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySession_CheckMediaKeyStatus(OH_MediaKeySession *mediaKeySessoin, + OH_DRM_MediaKeyDescription **mediaKeyDescription); + +/** + * @brief Clear media keys of the current session . + * @param mediaKeySession Media key session instance. + * @return OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySession_ClearMediaKeys(OH_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. + * @return OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySession_GenerateOfflineReleaseRequest(OH_MediaKeySession *mediaKeySessoin, + OH_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 OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySession_ProcessOfflineReleaseResponse(OH_MediaKeySession *mediaKeySessoin, + OH_DRM_Uint8Buffer *mediaKeyId, OH_DRM_Uint8Buffer *releaseReponse); + +/** + * @brief Restore offline media keys by ID. + * @param mediaKeySession Media key session instance. + * @param mediaKeyId Media key identifier. + * @return OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySession_RestoreOfflineMediaKeys(OH_MediaKeySession *mediaKeySessoin, + OH_DRM_Uint8Buffer *mediaKeyId); + +/** + * @brief Get content protection level of the session. + * @param mediaKeySession Media key session instance. + * @param contentProtectionLevel Content protection level. + * @return OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySession_GetContentProtectionLevel(OH_MediaKeySession *mediaKeySessoin, + OH_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 OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySession_RequireSecureDecoderModule(OH_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 OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySession_SetMediaKeySessionCallback(OH_MediaKeySession *mediaKeySessoin, + OH_MediaKeySessionCallback *callback); + +/** + * @brief Release the resource before the session gonna be unused. + * @param mediaKeySession Media key session instance. + * @return OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySession_Destroy(OH_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/include/native_mediakeysystem.h b/multimedia/drm_framework/include/native_mediakeysystem.h new file mode 100644 index 0000000000000000000000000000000000000000..427d68c6c2c41cb27f3a84734819b32e33dc9483 --- /dev/null +++ b/multimedia/drm_framework/include/native_mediakeysystem.h @@ -0,0 +1,256 @@ +/* + * 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. + * + * @Syscap SystemCapability.Multimedia.Drm.Core + * @since 11 + * @version 1.0 + */ + +/** + * @file native_mediakeysystem.h + * + * @brief Defines the Drm MediaKeySystem APIs. + * + * @library libdrm_framework.z.so + * @since 11 + * @version 1.0 + */ + +#ifndef OHOS_DRM_NATIVE_MEDIA_KEY_SYSTEM_H +#define OHOS_DRM_NATIVE_MEDIA_KEY_SYSTEM_H + +#include +#include +#include "native_drm_base.h" +#include "native_drm_err.h" +#include "native_drm_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +typedef OH_DrmErrCode (*OH_MediaKeySystemCallback)(OH_DRM_CharBufferPair *eventInfo); +/** + * @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, OH_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 Returns OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySystem_Create(const char *name, OH_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 Returns OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySystem_SetConfigurationString(OH_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. + * @return Returns OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySystem_GetConfigurationString(OH_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 Returns OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySystem_SetConfigurationByteArray(OH_MediaKeySystem *mediaKeySystem, + const char *configName, OH_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. + * @return Returns OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySystem_GetConfigurationByteArray(OH_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 Returns OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySystem_GetStatistics(OH_MediaKeySystem *mediaKeySystem, OH_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 Returns OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySystem_GetMaxContentProtectionLevel(OH_MediaKeySystem *mediaKeySystem, + OH_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 Returns OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySystem_SetMediaKeySystemCallback(OH_MediaKeySystem *mediaKeySystem, + OH_MediaKeySystemCallback 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 OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySystem_CreateMediaKeySession(OH_MediaKeySystem *mediaKeySystem, + OH_DRM_ContentProtectionLevel *level, OH_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 defaultUrl Provision server URL. + * @return OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySystem_GenerateKeySystemRequest(OH_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 OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySystem_ProcessKeySystemResponse(OH_MediaKeySystem *mediaKeySystem, + OH_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 OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySystem_GetOfflineMediaKeyIds(OH_MediaKeySystem *mediaKeySystem, + OH_DRM_MediaKeyIdArray **mediaKeyIds, int32_t *mediaKeyIdsLen); + +/** + * @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 OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySystem_GetOfflineMediaKeyStatus(OH_MediaKeySystem *mediaKeySystem, + OH_DRM_Uint8Buffer *mediaKeyId, OH_DRM_OfflineMediaKeyStatus *status); + +/** + * @brief Clear an offline media key by id. + * @param mediaKeySystem Media key system instance. + * @param mediaKeyId Media key identifier. + * @return OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySystem_ClearOfflineMediaKeys(OH_MediaKeySystem *mediaKeySystem, + OH_DRM_Uint8Buffer *mediaKeyId); + +/** + * @brief Get certificate status of media key system. + * @param mediaKeySystem Media key system instance. + * @param certStatus Status will be gotten. + * @return OH_DrmErrCode. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySystem_GetCertificateStatus(OH_MediaKeySystem *mediaKeySystem, + OH_DRM_CertificateStatus *certStatus); + +/** + * @brief Destroy a media key system instance. + * @param mediaKeySystem Secifies which media key system instance will be destroyed. + * @since 11 + * @version 1.0 + */ +OH_DrmErrCode OH_MediaKeySystem_Destroy(OH_MediaKeySystem *mediaKeySystem); + + +#ifdef __cplusplus +} +#endif + +#endif // OHOS_DRM_NATIVE_MEDIA_KEY_SYSTEM_H \ No newline at end of file