1094332d3Sopenharmony_ci# ClearPlay 2094332d3Sopenharmony_ci 3094332d3Sopenharmony_ci## 概述 4094332d3Sopenharmony_ci 5094332d3Sopenharmony_ciOpenHarmony ClearPlay驱动对上实现媒体版权保护(DRM)的HDI(Hardware Device Interface)接口, 6094332d3Sopenharmony_ci为DRM框架提供DRM版权保护的具体实现;作为DRM插件适配样例,指导用户适配其他产商的DRM插件。 7094332d3Sopenharmony_ci 8094332d3Sopenharmony_ci## 目录 9094332d3Sopenharmony_ci 10094332d3Sopenharmony_ci- ClearPlay模块目录表如下: 11094332d3Sopenharmony_ci 12094332d3Sopenharmony_ci ``` 13094332d3Sopenharmony_ci/drivers/peripheral/ClearPlay 14094332d3Sopenharmony_ci├── bundle.json # ClearPlay驱动构建脚本 15094332d3Sopenharmony_ci├── hdi_service # ClearPlay驱动服务功能实现代码 16094332d3Sopenharmony_ci│ ├── common # ClearPlay驱动服务依赖的工具类代码,包含json解析、base64编解码 17094332d3Sopenharmony_ci│ ├── include # ClearPlay驱动服务头文件 18094332d3Sopenharmony_ci│ └── src # ClearPlay驱动服务具体实现代码 19094332d3Sopenharmony_ci├── interfaces # ClearPlay驱动能力接口 20094332d3Sopenharmony_ci│ ├── include # ClearPlay驱动能力接口头文件 21094332d3Sopenharmony_ci│ └── src # ClearPlay驱动能力接口实现 22094332d3Sopenharmony_ci└── test # ClearPlay驱动测试代码 23094332d3Sopenharmony_ci ├── sample # ClearPlay驱动功能验证demo 24094332d3Sopenharmony_ci │ ├── include # ClearPlay驱动功能验证demo头文件 25094332d3Sopenharmony_ci │ └── src # ClearPlay驱动功能验证demo具体实现 26094332d3Sopenharmony_ci └── unittest # ClearPlay驱动UT用例 27094332d3Sopenharmony_ci ├── include # ClearPlay驱动UT用例头文件 28094332d3Sopenharmony_ci └── src # ClearPlay驱动UT用例实现 29094332d3Sopenharmony_ci ``` 30094332d3Sopenharmony_ci 31094332d3Sopenharmony_ci## ClearPlay驱动能力接口说明 32094332d3Sopenharmony_ci 33094332d3Sopenharmony_ci- imedia_key_system_factory.h 34094332d3Sopenharmony_ci 35094332d3Sopenharmony_ci | 功能描述 | 接口名称 | 36094332d3Sopenharmony_ci | -------------------------------- | ------------------------------------------------------------ | 37094332d3Sopenharmony_ci | 查询设备是否支持uuid/媒体类型/安全级别对应的插件 | int32_t IsMediaKeySystemSupported(const std::string& uuid, const std::string& mimeType, ContentProtectionLevel level, bool& isSupported) | 38094332d3Sopenharmony_ci | 创建MediaKeySysem对象 | int32_t CreateMediaKeySystem(sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystem>& mediaKeySystem) | 39094332d3Sopenharmony_ci | 获取插件版本 | int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) | 40094332d3Sopenharmony_ci 41094332d3Sopenharmony_ci 42094332d3Sopenharmony_ci - imedia_key_system.h 43094332d3Sopenharmony_ci 44094332d3Sopenharmony_ci | 功能描述 | 接口名称 | 45094332d3Sopenharmony_ci | -------------------------------- | ------------------------------------------------------------ | 46094332d3Sopenharmony_ci | 根据配置类型和属性名获取对应配置值,包括输出保护状态、设备属性、支持的最大会话数、当前会话数 | int32_t GetConfigurationString(const std::string& name, std::string& value) | 47094332d3Sopenharmony_ci | 根据配置类型和属性名设置对应配置值 | int32_t SetConfigurationString(const std::string& name, const std::string& value) | 48094332d3Sopenharmony_ci | 根据配置类型和属性名获取对应配置值,包括输出保护状态、设备属性、支持的最大会话数、当前会话数 | int32_t GetConfigurationByteArray(const std::string& name, std::vector<uint8_t>& value) | 49094332d3Sopenharmony_ci | 根据配置类型和属性名设置对应配置值 | int32_t SetConfigurationByteArray(const std::string& name, const std::vector<uint8_t>& value) | 50094332d3Sopenharmony_ci | 获取DRM度量值 | int32_t GetMetrics(std::map<std::string, std::string>& metrics) | 51094332d3Sopenharmony_ci | 获取MediaKeySystem最大安全级别 | int32_t GetMaxContentProtectionLevel(ContentProtectionLevel& level) | 52094332d3Sopenharmony_ci | 生成设备证书获取请求 | int32_t GenerateKeySystemRequest(std::string& defaultUrl, std::vector<uint8_t>& request) | 53094332d3Sopenharmony_ci | 解析设备证书获取响应 | int32_t ProcessKeySystemResponse(const std::vector<uint8_t>& response) | 54094332d3Sopenharmony_ci | 获取证书状态 | int32_t GetOemCertificateStatus(CertificateStatus& status) | 55094332d3Sopenharmony_ci | 注册和取消注册MediaKeySystem监听时事件 | int32_t SetCallback(const sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystemCallback>& callback) | 56094332d3Sopenharmony_ci | 根据安全级别创建会话 | int32_t CreateMediaKeySession(ContentProtectionLevel level, 57094332d3Sopenharmony_ci sptr<OHOS::HDI::Drm::V1_0::IMediaKeySession>& keySession) | 58094332d3Sopenharmony_ci | 创建会话 | int32_t CreateMediaKeySessionDefault(sptr<OHOS::HDI::Drm::V1_0::IMediaKeySession>& keySession) | 59094332d3Sopenharmony_ci | 获取所有离线密钥或密钥组索引 | int32_t GetOfflineMediaKeyIds(std::vector<std::vector<uint8_t>>& mediakeyIds) | 60094332d3Sopenharmony_ci | 获取所有离线密钥或密钥组索引 | int32_t GetOfflineMediaKeyIds(std::vector<std::vector<uint8_t>>& mediakeyIds) | 61094332d3Sopenharmony_ci | 获取指定离线密钥或密钥组状态 | int32_t GetOfflineMediaKeyStatus(const std::vector<uint8_t>& mediakeyId, OfflineMediaKeyStatus& mediakeyStatus) | 62094332d3Sopenharmony_ci | 获取OEM证书 | int32_t GetOemCertificate(sptr<OHOS::HDI::Drm::V1_0::IOemCertificate>& oemCert) | 63094332d3Sopenharmony_ci | 释放MediaKeySystem | int32_t Destroy() | 64094332d3Sopenharmony_ci 65094332d3Sopenharmony_ci 66094332d3Sopenharmony_ci - ikey_session.h 67094332d3Sopenharmony_ci 68094332d3Sopenharmony_ci | 功能描述 | 接口名称 | 69094332d3Sopenharmony_ci | -------------------------------- | ------------------------------------------------------------ | 70094332d3Sopenharmony_ci | 生成一个许可证获取请求 | int32_t GenerateMediaKeyRequest(const MediaKeyRequestInfo& mediakeyRequestInfo, 71094332d3Sopenharmony_ci MediaKeyRequest& mediakeyRequest) | 72094332d3Sopenharmony_ci | 解析许可证获取响应 | int32_t ProcessMediaKeyResponse(const std::vector<uint8_t>& mediakeyResponse, std::vector<uint8_t>& mediakeyId) | 73094332d3Sopenharmony_ci | 检查当前会话的许可证状态 | int32_t CheckMediaKeyStatus(std::map<std::string, OHOS::HDI::Drm::V1_0::MediaKeySessionKeyStatus>& mediakeyStatus) | 74094332d3Sopenharmony_ci | 移除当前会话下所有许可证 | int32_t RemoveMediaKey() | 75094332d3Sopenharmony_ci | 生成离线密钥释放请求 | int32_t GetOfflineReleaseRequest(const std::vector<uint8_t>& mediakeyId, std::vector<uint8_t>& releaseRequest) | 76094332d3Sopenharmony_ci | 解析离线密钥释放响应 | int32_t ProcessOfflineReleaseResponse(const std::vector<uint8_t>& mediakeyId, const std::vector<uint8_t>& response) | 77094332d3Sopenharmony_ci | 恢复离线密钥和密钥组,并加载到当前会话中 | int32_t RestoreOfflineMediaKey(const std::vector<uint8_t>& mediakeyId) | 78094332d3Sopenharmony_ci | 获取KeySession安全级别 | int32_t GetContentProtectionLevel(ContentProtectionLevel& level) | 79094332d3Sopenharmony_ci | 查询是否支持安全解码 | int32_t RequiresSecureDecoderModule(const std::string& mimeType, bool& required) | 80094332d3Sopenharmony_ci | 注册和取消注册监听事件 | int32_t SetCallback(const sptr<OHOS::HDI::Drm::V1_0::IMediaKeySessionCallback>& callback) | 81094332d3Sopenharmony_ci | 获取解密模块 | int32_t GetMediaDecryptModule(sptr<OHOS::HDI::Drm::V1_0::IMediaDecryptModule>& decryptModule) | 82094332d3Sopenharmony_ci | 释放当前会话 | int32_t Destroy() | 83094332d3Sopenharmony_ci 84094332d3Sopenharmony_ci 85094332d3Sopenharmony_ci - imedia_decrypt_module.h 86094332d3Sopenharmony_ci 87094332d3Sopenharmony_ci | 功能描述 | 接口名称 | 88094332d3Sopenharmony_ci | -------------------------------- | ------------------------------------------------------------ | 89094332d3Sopenharmony_ci | 解密媒体数据 | int32_t DecryptMediaData(bool secure, const AVBuffer& srcBuffer, const AVBuffer& destBuffer) | 90094332d3Sopenharmony_ci | 解密模块资源释放 | int32_t Release() | 91094332d3Sopenharmony_ci 92094332d3Sopenharmony_ci 93094332d3Sopenharmony_ci - ikey_session_callback.h 94094332d3Sopenharmony_ci 95094332d3Sopenharmony_ci | 功能描述 | 接口名称 | 96094332d3Sopenharmony_ci | ------------------------------| ------------------------------------------------------------ | 97094332d3Sopenharmony_ci | HDI MediaKeySession事件监听接口 | int32_t SendEvent(EventType eventType, int32_t extra, const std::vector<uint8_t>& data) | 98094332d3Sopenharmony_ci | HDI MediaKeySession事件监听接口,密钥状态改变 | int32_t SendEventKeyChange(const std::map<std::vector<uint8_t>, OHOS::HDI::Drm::V1_0::MediaKeySessionKeyStatus>& keyStatus, bool hasNewGoodMediaKey) | 99094332d3Sopenharmony_ci 100094332d3Sopenharmony_ci- imedia_key_system_callback.h 101094332d3Sopenharmony_ci 102094332d3Sopenharmony_ci | 功能描述 | 接口名称 | 103094332d3Sopenharmony_ci | ------------------------------| ----------------------------------------------------------- | 104094332d3Sopenharmony_ci | MediaKeySystem事件监听回调 | int32_t SendEvent(EventType eventType, int32_t extra, const std::vector<uint8_t>& data) | 105094332d3Sopenharmony_ci 106094332d3Sopenharmony_ci - ioem_certificate.h 107094332d3Sopenharmony_ci 108094332d3Sopenharmony_ci | 功能描述 | 接口名称 | 109094332d3Sopenharmony_ci | --------------------------------| ------------------------------------------------------------ | 110094332d3Sopenharmony_ci | 设备证书provision请求 | int32_t GetOemProvisionRequest(std::string& defaultUrl, std::vector<uint8_t>& request) | 111094332d3Sopenharmony_ci | 设备证书provision请求响应 | int32_t ProvideOemProvisionResponse(const std::vector<uint8_t>& response) | 112094332d3Sopenharmony_ci 113094332d3Sopenharmony_ci 114094332d3Sopenharmony_ci## 使用方法 115094332d3Sopenharmony_ci 116094332d3Sopenharmony_ci在/drivers/peripheral/ClearPlay/test目录下有一个关于ClearPlay的sample,该sample可以验证ClearPlay证书下载、解密播放等基础功能。下面我们就以此sample为例讲述怎样用HDI接口去编写MediaKeySystem的创建、会话管理、证书管理、许可证管理、数据解密等功能的用例。 117094332d3Sopenharmony_cisample编译命令:./build.sh --product-name rk3568 --build-target clearplay_test_entry 118094332d3Sopenharmony_ci编译产物路径:./out/rk3568/exe.unstripped/hdf/drivers_peripheral_clearplay 119094332d3Sopenharmony_ci 120094332d3Sopenharmony_ci 121094332d3Sopenharmony_ci1. 在clearplay_sample_media_key_system_factory.cpp的main函数中构造一个media_key_system_factory 对象,该对象中有查询设备所支持插件类型、创建和销毁MediaKeySystem的方法。 122094332d3Sopenharmony_ci 123094332d3Sopenharmony_ci ``` 124094332d3Sopenharmony_ciint main(int argc, char *argv[]) 125094332d3Sopenharmony_ci{ 126094332d3Sopenharmony_ci // data init 127094332d3Sopenharmony_ci std::string clearPlayUuid = "com.drm.clearplay"; 128094332d3Sopenharmony_ci bool isSupported = false; 129094332d3Sopenharmony_ci 130094332d3Sopenharmony_ci // create key system factory 131094332d3Sopenharmony_ci sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystemFactory> media_key_system_factory = new MediaKeySystemFactoryService(); 132094332d3Sopenharmony_ci 133094332d3Sopenharmony_ci // IsMediaKeySystemSupported case 1 134094332d3Sopenharmony_ci media_key_system_factory->IsMediaKeySystemSupported(clearPlayUuid, isoVideoMimeType, SECURE_UNKNOWN, isSupported); 135094332d3Sopenharmony_ci printf("IsMediaKeySystemSupported: %d, expect 1\n", isSupported); 136094332d3Sopenharmony_ci // IsMediaKeySystemSupported case 2 137094332d3Sopenharmony_ci clearPlayUuid = "E79628B6406A6724DCD5A1DA50B53E81"; // wrong uuid 138094332d3Sopenharmony_ci media_key_system_factory->IsMediaKeySystemSupported(clearPlayUuid, isoVideoMimeType, SECURE_UNKNOWN, isSupported); 139094332d3Sopenharmony_ci printf("IsMediaKeySystemSupported: %d, expect 0\n", isSupported); 140094332d3Sopenharmony_ci 141094332d3Sopenharmony_ci // CreateMediaKeySystem 142094332d3Sopenharmony_ci sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystem> media_key_system; 143094332d3Sopenharmony_ci media_key_system_factory->CreateMediaKeySystem(media_key_system); 144094332d3Sopenharmony_ci printf("CreateMediaKeySystem\n"); 145094332d3Sopenharmony_ci 146094332d3Sopenharmony_ci // MediaKeySystem Close 147094332d3Sopenharmony_ci media_key_system->Close(); 148094332d3Sopenharmony_ci printf("Close\n"); 149094332d3Sopenharmony_ci return 0; 150094332d3Sopenharmony_ci} ``` 151094332d3Sopenharmony_ci 152094332d3Sopenharmony_ci2. clearplay_sample_media_key_system.cpp的main函数中构造一个media_key_system_factory 对象,用该对象创建一个media_key_system对象,使用media_key_system验证设备证书请求、设备证书响应、多会话、属性获取与设置、安全级别获取、DRM度量等功能。 153094332d3Sopenharmony_ci 154094332d3Sopenharmony_ci ``` 155094332d3Sopenharmony_ciint main(int argc, char *argv[]) 156094332d3Sopenharmony_ci{ 157094332d3Sopenharmony_ci // data init 158094332d3Sopenharmony_ci std::vector<uint8_t> inputValue; 159094332d3Sopenharmony_ci std::vector<uint8_t> outputValue; 160094332d3Sopenharmony_ci std::map<std::string, std::string> metric; 161094332d3Sopenharmony_ci ContentProtectionLevel level = SECURE_UNKNOWN; 162094332d3Sopenharmony_ci sptr<OHOS::HDI::Drm::V1_0::IKeySession> key_session_1; 163094332d3Sopenharmony_ci sptr<OHOS::HDI::Drm::V1_0::IKeySession> key_session_2; 164094332d3Sopenharmony_ci sptr<OHOS::HDI::Drm::V1_0::IKeySession> key_session_3; 165094332d3Sopenharmony_ci sptr<OHOS::HDI::Drm::V1_0::IKeySession> key_session_4; 166094332d3Sopenharmony_ci 167094332d3Sopenharmony_ci // create key system factory 168094332d3Sopenharmony_ci sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystemFactory> media_key_system_factory = new MediaKeySystemFactoryService(); 169094332d3Sopenharmony_ci 170094332d3Sopenharmony_ci // CreateMediaKeySystem 171094332d3Sopenharmony_ci sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystem> media_key_system; 172094332d3Sopenharmony_ci media_key_system_factory->CreateMediaKeySystem(media_key_system); 173094332d3Sopenharmony_ci printf("CreateMediaKeySystem\n"); 174094332d3Sopenharmony_ci 175094332d3Sopenharmony_ci // set and get configuration 176094332d3Sopenharmony_ci printf("\ntest set and get configuration\n"); 177094332d3Sopenharmony_ci inputValue.push_back('v'); 178094332d3Sopenharmony_ci inputValue.push_back('a'); 179094332d3Sopenharmony_ci inputValue.push_back('l'); 180094332d3Sopenharmony_ci inputValue.push_back('u'); 181094332d3Sopenharmony_ci inputValue.push_back('e'); 182094332d3Sopenharmony_ci media_key_system->SetConfiguration(CONFIG_TYPE_KEY_SESSION, "name1", inputValue); 183094332d3Sopenharmony_ci media_key_system->SetConfiguration(CONFIG_TYPE_KEY_SESSION, "name2", inputValue); 184094332d3Sopenharmony_ci media_key_system->SetConfiguration(CONFIG_TYPE_KEY_SESSION, "name3", inputValue); 185094332d3Sopenharmony_ci 186094332d3Sopenharmony_ci media_key_system->GetConfiguration(CONFIG_TYPE_KEY_SESSION, "name1", outputValue); 187094332d3Sopenharmony_ci printf("outputValue: %s, expect: value\n", outputValue.data()); 188094332d3Sopenharmony_ci 189094332d3Sopenharmony_ci // GetMetric 190094332d3Sopenharmony_ci printf("\ntest GetMetric\n"); 191094332d3Sopenharmony_ci media_key_system->GetMetric(metric); // 当前可度量信息:插件版本信息、会话数量、解密次数、解密失败次数 192094332d3Sopenharmony_ci for (auto& pair:metric) { 193094332d3Sopenharmony_ci printf("key: %s, value: %s\n", pair.first.c_str(), pair.second.c_str()); 194094332d3Sopenharmony_ci } 195094332d3Sopenharmony_ci 196094332d3Sopenharmony_ci // GetContentProtectionLevel 197094332d3Sopenharmony_ci printf("result of GetContentProtectionLevel: %d, expect: -1\n", media_key_system->GetContentProtectionLevel(level)); 198094332d3Sopenharmony_ci 199094332d3Sopenharmony_ci // CreateKeySession 200094332d3Sopenharmony_ci /* 201094332d3Sopenharmony_ci SECURE_UNKNOWN = 0, 202094332d3Sopenharmony_ci SW_SECURE_CRYPTO = 1, 203094332d3Sopenharmony_ci SW_SECURE_DECODE = 2, 204094332d3Sopenharmony_ci HW_SECURE_CRYPTO = 3, 205094332d3Sopenharmony_ci HW_SECURE_DECODE = 4, 206094332d3Sopenharmony_ci HW_SECURE_ALL = 5, 207094332d3Sopenharmony_ci */ 208094332d3Sopenharmony_ci printf("\ntest CreateKeySession\n"); 209094332d3Sopenharmony_ci media_key_system->CreateKeySession(SW_SECURE_CRYPTO, key_session_1); 210094332d3Sopenharmony_ci media_key_system->CreateKeySession(SW_SECURE_DECODE, key_session_2); 211094332d3Sopenharmony_ci media_key_system->CreateKeySession(HW_SECURE_CRYPTO, key_session_3); 212094332d3Sopenharmony_ci media_key_system->CreateKeySession(HW_SECURE_DECODE, key_session_4); 213094332d3Sopenharmony_ci printf("CreateKeySession\n"); 214094332d3Sopenharmony_ci 215094332d3Sopenharmony_ci // GetContentProtectionLevel 216094332d3Sopenharmony_ci printf("\ntest GetContentProtectionLevel\n"); 217094332d3Sopenharmony_ci media_key_system->GetContentProtectionLevel(level); 218094332d3Sopenharmony_ci printf("level: %d, expect: 4\n", level); 219094332d3Sopenharmony_ci key_session_4->Close(); 220094332d3Sopenharmony_ci media_key_system->GetContentProtectionLevel(level); 221094332d3Sopenharmony_ci printf("level: %d, expect: 3\n", level); 222094332d3Sopenharmony_ci 223094332d3Sopenharmony_ci // GenerateKeySystemRequest 224094332d3Sopenharmony_ci std::vector<uint8_t> request; 225094332d3Sopenharmony_ci std::string defaultUrl; 226094332d3Sopenharmony_ci media_key_system->GenerateKeySystemRequest(REQUEST_TYPE_INITIAL, defaultUrl, request); 227094332d3Sopenharmony_ci // std::string requestString(request.begin(), request.end()); 228094332d3Sopenharmony_ci printf("request: %s, expect: REQUEST_TYPE_INITIAL\n", request.data()); 229094332d3Sopenharmony_ci 230094332d3Sopenharmony_ci // ProcessKeySystemResponse 231094332d3Sopenharmony_ci media_key_system->ProcessKeySystemResponse(REQUEST_TYPE_INITIAL, request); 232094332d3Sopenharmony_ci 233094332d3Sopenharmony_ci // MediaKeySystem Close 234094332d3Sopenharmony_ci media_key_system->Close(); 235094332d3Sopenharmony_ci printf("Close\n"); 236094332d3Sopenharmony_ci return 0; 237094332d3Sopenharmony_ci} ``` 238094332d3Sopenharmony_ci 239094332d3Sopenharmony_ci2. clearplay_sample_media_key_system.cpp的main函数中构造一个media_key_system_factory 对象,用该对象创建一个media_key_system对象,使用media_key_system对象创建key_session对象,使用key_session对象验证许可证获取请求、解析许可证响应、获取解密模块对象以及数据解密和释放解密模块功能。 240094332d3Sopenharmony_ci 241094332d3Sopenharmony_ci ``` 242094332d3Sopenharmony_ciint main(int argc, char *argv[]) 243094332d3Sopenharmony_ci{ 244094332d3Sopenharmony_ci // create key system factory 245094332d3Sopenharmony_ci sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystemFactory> media_key_system_factory = new MediaKeySystemFactoryService(); 246094332d3Sopenharmony_ci 247094332d3Sopenharmony_ci // CreateMediaKeySystem 248094332d3Sopenharmony_ci sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystem> media_key_system; 249094332d3Sopenharmony_ci media_key_system_factory->CreateMediaKeySystem(media_key_system); 250094332d3Sopenharmony_ci printf("CreateMediaKeySystem\n"); 251094332d3Sopenharmony_ci 252094332d3Sopenharmony_ci // CreateKeySession 253094332d3Sopenharmony_ci printf("\ntest CreateKeySession\n"); 254094332d3Sopenharmony_ci sptr<OHOS::HDI::Drm::V1_0::IKeySession> key_session; 255094332d3Sopenharmony_ci media_key_system->CreateKeySession(SECURE_UNKNOWN, key_session); 256094332d3Sopenharmony_ci printf("CreateKeySession\n"); 257094332d3Sopenharmony_ci 258094332d3Sopenharmony_ci // ProcessMediaKeyResponse 259094332d3Sopenharmony_ci printf("\ntest ProcessMediaKeyResponse\n"); 260094332d3Sopenharmony_ci std::string responseString = "key1:1234567812345678"; 261094332d3Sopenharmony_ci std::vector<uint8_t> response(responseString.begin(), responseString.end()); 262094332d3Sopenharmony_ci std::vector<uint8_t> keyId; 263094332d3Sopenharmony_ci 264094332d3Sopenharmony_ci key_session->ProcessMediaKeyResponse(response, keyId); 265094332d3Sopenharmony_ci printf("keyid: %s, expect: key1\n", keyId.data()); 266094332d3Sopenharmony_ci 267094332d3Sopenharmony_ci // GetMediaDecryptModule 268094332d3Sopenharmony_ci sptr<OHOS::HDI::Drm::V1_0::IMediaDecryptModule> decryptModule; 269094332d3Sopenharmony_ci key_session->GetMediaDecryptModule(decryptModule); 270094332d3Sopenharmony_ci 271094332d3Sopenharmony_ci // DecryptData 272094332d3Sopenharmony_ci printf("\nDecryptData\n"); 273094332d3Sopenharmony_ci CryptoInfo info; 274094332d3Sopenharmony_ci info.type = ALGTYPE_AES_CBC; 275094332d3Sopenharmony_ci info.keyIdLen = 4; 276094332d3Sopenharmony_ci info.keyId = keyId; 277094332d3Sopenharmony_ci info.ivLen = 16; 278094332d3Sopenharmony_ci info.iv = { // 网络安全,设置默认值,实际调用由DRM框架传真实值 279094332d3Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 280094332d3Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 281094332d3Sopenharmony_ci }; 282094332d3Sopenharmony_ci info.pattern.encryptBlocks = 0; 283094332d3Sopenharmony_ci info.pattern.skipBlocks = 0; 284094332d3Sopenharmony_ci SubSample subSample; 285094332d3Sopenharmony_ci subSample.clearHeaderLen = 0; 286094332d3Sopenharmony_ci subSample.payLoadLen = 16; 287094332d3Sopenharmony_ci info.subSamples.push_back(subSample); 288094332d3Sopenharmony_ci info.subSampleNum = 1; 289094332d3Sopenharmony_ci std::vector<uint8_t> srcBuffer = { // 网络安全,设置默认值,实际调用由DRM框架传真实值 290094332d3Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 291094332d3Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 292094332d3Sopenharmony_ci }; 293094332d3Sopenharmony_ci std::vector<uint8_t> dstBuffer = { // 网络安全,设置默认值,实际调用由DRM框架传真实值 294094332d3Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 295094332d3Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 296094332d3Sopenharmony_ci }; 297094332d3Sopenharmony_ci decryptModule->DecryptData(false, info, srcBuffer, dstBuffer); 298094332d3Sopenharmony_ci for (size_t i = 0; i < dstBuffer.size(); ++i) { 299094332d3Sopenharmony_ci printf("%02x ", dstBuffer[i]); 300094332d3Sopenharmony_ci } 301094332d3Sopenharmony_ci printf("\n\n"); 302094332d3Sopenharmony_ci 303094332d3Sopenharmony_ci media_key_system->Close(); 304094332d3Sopenharmony_ci printf("Close\n"); 305094332d3Sopenharmony_ci return 0; 306094332d3Sopenharmony_ci} ``` 307094332d3Sopenharmony_ci 308094332d3Sopenharmony_ci``` 309