1 /* 2 * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_HDI_DRM_V1_0_IMEDIAKEYSYSTEM_H 17 #define OHOS_HDI_DRM_V1_0_IMEDIAKEYSYSTEM_H 18 19 #include <stdint.h> 20 #include <map> 21 #include <string> 22 #include <vector> 23 #include <hdf_base.h> 24 #include <hdi_base.h> 25 #include "drm/v1_0/imedia_key_session.h" 26 #include "drm/v1_0/imedia_key_system_callback.h" 27 #include "drm/v1_0/ioem_certificate.h" 28 #include "drm/v1_0/media_key_system_types.h" 29 30 #ifndef HDI_BUFF_MAX_SIZE 31 #define HDI_BUFF_MAX_SIZE (1024 * 200) 32 #endif 33 34 #ifndef HDI_CHECK_VALUE_RETURN 35 #define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) \ 36 do { \ 37 if ((lv)compare(rv)) { \ 38 return ret; \ 39 } \ 40 } while (false) 41 #endif 42 43 #ifndef HDI_CHECK_VALUE_RET_GOTO 44 #define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) \ 45 do { \ 46 if ((lv)compare(rv)) { \ 47 ret = value; \ 48 goto table; \ 49 } \ 50 } while (false) 51 #endif 52 53 namespace OHOS { 54 namespace HDI { 55 namespace Drm { 56 namespace V1_0 { 57 using namespace OHOS; 58 using namespace OHOS::HDI; 59 60 enum { 61 CMD_MEDIA_KEY_SYSTEM_GET_VERSION = 0, 62 CMD_MEDIA_KEY_SYSTEM_GET_CONFIGURATION_STRING = 1, 63 CMD_MEDIA_KEY_SYSTEM_SET_CONFIGURATION_STRING = 2, 64 CMD_MEDIA_KEY_SYSTEM_GET_CONFIGURATION_BYTE_ARRAY = 3, 65 CMD_MEDIA_KEY_SYSTEM_SET_CONFIGURATION_BYTE_ARRAY = 4, 66 CMD_MEDIA_KEY_SYSTEM_GET_STATISTICS = 5, 67 CMD_MEDIA_KEY_SYSTEM_GET_MAX_CONTENT_PROTECTION_LEVEL = 6, 68 CMD_MEDIA_KEY_SYSTEM_GENERATE_KEY_SYSTEM_REQUEST = 7, 69 CMD_MEDIA_KEY_SYSTEM_PROCESS_KEY_SYSTEM_RESPONSE = 8, 70 CMD_MEDIA_KEY_SYSTEM_GET_OEM_CERTIFICATE_STATUS = 9, 71 CMD_MEDIA_KEY_SYSTEM_SET_CALLBACK = 10, 72 CMD_MEDIA_KEY_SYSTEM_CREATE_MEDIA_KEY_SESSION = 11, 73 CMD_MEDIA_KEY_SYSTEM_GET_OFFLINE_MEDIA_KEY_IDS = 12, 74 CMD_MEDIA_KEY_SYSTEM_GET_OFFLINE_MEDIA_KEY_STATUS = 13, 75 CMD_MEDIA_KEY_SYSTEM_CLEAR_OFFLINE_MEDIA_KEYS = 14, 76 CMD_MEDIA_KEY_SYSTEM_GET_OEM_CERTIFICATE = 15, 77 CMD_MEDIA_KEY_SYSTEM_DESTROY = 16, 78 }; 79 80 class IMediaKeySystem : public HdiBase { 81 public: 82 DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.drm.v1_0.IMediaKeySystem"); 83 84 virtual ~IMediaKeySystem() = default; 85 86 virtual int32_t GetConfigurationString(const std::string &name, std::string &value) = 0; 87 88 virtual int32_t SetConfigurationString(const std::string &name, const std::string &value) = 0; 89 90 virtual int32_t GetConfigurationByteArray(const std::string &name, std::vector<uint8_t> &value) = 0; 91 92 virtual int32_t SetConfigurationByteArray(const std::string &name, const std::vector<uint8_t> &value) = 0; 93 94 virtual int32_t GetStatistics(std::map<std::string, std::string> &statistics) = 0; 95 96 virtual int32_t GetMaxContentProtectionLevel(OHOS::HDI::Drm::V1_0::ContentProtectionLevel &level) = 0; 97 98 virtual int32_t GenerateKeySystemRequest(std::string &defaultUrl, std::vector<uint8_t> &request) = 0; 99 100 virtual int32_t ProcessKeySystemResponse(const std::vector<uint8_t> &response) = 0; 101 102 virtual int32_t GetOemCertificateStatus(OHOS::HDI::Drm::V1_0::CertificateStatus &status) = 0; 103 104 virtual int32_t SetCallback(const sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystemCallback> &systemCallback) = 0; 105 106 virtual int32_t CreateMediaKeySession(OHOS::HDI::Drm::V1_0::ContentProtectionLevel level, 107 sptr<OHOS::HDI::Drm::V1_0::IMediaKeySession> &keySession) = 0; 108 109 virtual int32_t GetOfflineMediaKeyIds(std::vector<std::vector<uint8_t>> &mediaKeyIds) = 0; 110 111 virtual int32_t GetOfflineMediaKeyStatus(const std::vector<uint8_t> &mediaKeyId, 112 OHOS::HDI::Drm::V1_0::OfflineMediaKeyStatus &mediaKeyStatus) = 0; 113 114 virtual int32_t ClearOfflineMediaKeys(const std::vector<uint8_t> &mediaKeyId) = 0; 115 116 virtual int32_t GetOemCertificate(sptr<OHOS::HDI::Drm::V1_0::IOemCertificate> &oemCert) = 0; 117 118 virtual int32_t Destroy() = 0; 119 GetVersion(uint32_t & majorVer,uint32_t & minorVer)120 virtual int32_t GetVersion(uint32_t &majorVer, uint32_t &minorVer) 121 { 122 majorVer = 1; 123 minorVer = 0; 124 return HDF_SUCCESS; 125 } 126 IsProxy()127 virtual bool IsProxy() 128 { 129 return false; 130 } 131 GetDesc()132 virtual const std::u16string GetDesc() 133 { 134 return metaDescriptor_; 135 } 136 }; 137 } // V1_0 138 } // Drm 139 } // HDI 140 } // OHOS 141 142 #endif // OHOS_HDI_DRM_V1_0_IMEDIAKEYSYSTEM_H