1 /* 2 * Copyright (c) 2023 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_IMEDIAKEYSESSION_H 17 #define OHOS_HDI_DRM_V1_0_IMEDIAKEYSESSION_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_decrypt_module.h" 26 #include "drm/v1_0/imedia_key_session_callback.h" 27 #include "drm/v1_0/media_key_system_types.h" 28 29 #ifndef HDI_BUFF_MAX_SIZE 30 #define HDI_BUFF_MAX_SIZE (1024 * 200) 31 #endif 32 33 #ifndef HDI_CHECK_VALUE_RETURN 34 #define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \ 35 if ((lv) compare (rv)) { \ 36 return ret; \ 37 } \ 38 } while (false) 39 #endif 40 41 #ifndef HDI_CHECK_VALUE_RET_GOTO 42 #define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ 43 if ((lv) compare (rv)) { \ 44 ret = value; \ 45 goto table; \ 46 } \ 47 } while (false) 48 #endif 49 50 namespace OHOS { 51 namespace HDI { 52 namespace Drm { 53 namespace V1_0 { 54 using namespace OHOS; 55 using namespace OHOS::HDI; 56 57 enum { 58 CMD_MEDIA_KEY_SESSION_GET_VERSION = 0, 59 CMD_MEDIA_KEY_SESSION_GENERATE_MEDIA_KEY_REQUEST = 1, 60 CMD_MEDIA_KEY_SESSION_PROCESS_MEDIA_KEY_RESPONSE = 2, 61 CMD_MEDIA_KEY_SESSION_CHECK_MEDIA_KEY_STATUS = 3, 62 CMD_MEDIA_KEY_SESSION_CLEAR_MEDIA_KEYS = 4, 63 CMD_MEDIA_KEY_SESSION_GET_OFFLINE_RELEASE_REQUEST = 5, 64 CMD_MEDIA_KEY_SESSION_PROCESS_OFFLINE_RELEASE_RESPONSE = 6, 65 CMD_MEDIA_KEY_SESSION_RESTORE_OFFLINE_MEDIA_KEYS = 7, 66 CMD_MEDIA_KEY_SESSION_GET_CONTENT_PROTECTION_LEVEL = 8, 67 CMD_MEDIA_KEY_SESSION_REQUIRES_SECURE_DECODER_MODULE = 9, 68 CMD_MEDIA_KEY_SESSION_SET_CALLBACK = 10, 69 CMD_MEDIA_KEY_SESSION_GET_MEDIA_DECRYPT_MODULE = 11, 70 CMD_MEDIA_KEY_SESSION_DESTROY = 12, 71 }; 72 73 class IMediaKeySession : public HdiBase { 74 public: 75 DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.drm.v1_0.IMediaKeySession"); 76 77 virtual ~IMediaKeySession() = default; 78 79 virtual int32_t GenerateMediaKeyRequest(const OHOS::HDI::Drm::V1_0::MediaKeyRequestInfo& mediaKeyRequestInfo, 80 OHOS::HDI::Drm::V1_0::MediaKeyRequest& mediaKeyRequest) = 0; 81 82 virtual int32_t ProcessMediaKeyResponse(const std::vector<uint8_t>& mediaKeyResponse, 83 std::vector<uint8_t>& mediaKeyId) = 0; 84 85 virtual int32_t CheckMediaKeyStatus(std::map<std::string, std::string>& mediaKeyStatus) = 0; 86 87 virtual int32_t ClearMediaKeys() = 0; 88 89 virtual int32_t GetOfflineReleaseRequest(const std::vector<uint8_t>& mediaKeyId, 90 std::vector<uint8_t>& releaseRequest) = 0; 91 92 virtual int32_t ProcessOfflineReleaseResponse(const std::vector<uint8_t>& mediaKeyId, 93 const std::vector<uint8_t>& response) = 0; 94 95 virtual int32_t RestoreOfflineMediaKeys(const std::vector<uint8_t>& mediaKeyId) = 0; 96 97 virtual int32_t GetContentProtectionLevel(OHOS::HDI::Drm::V1_0::ContentProtectionLevel& level) = 0; 98 99 virtual int32_t RequiresSecureDecoderModule(const std::string& mimeType, bool& required) = 0; 100 101 virtual int32_t SetCallback(const sptr<OHOS::HDI::Drm::V1_0::IMediaKeySessionCallback>& sessionCallback) = 0; 102 103 virtual int32_t GetMediaDecryptModule(sptr<OHOS::HDI::Drm::V1_0::IMediaDecryptModule>& decryptModule) = 0; 104 105 virtual int32_t Destroy() = 0; 106 GetVersion(uint32_t & majorVer,uint32_t & minorVer)107 virtual int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer) 108 { 109 majorVer = 1; 110 minorVer = 0; 111 return HDF_SUCCESS; 112 } 113 IsProxy()114 virtual bool IsProxy() 115 { 116 return false; 117 } 118 GetDesc()119 virtual const std::u16string GetDesc() 120 { 121 return metaDescriptor_; 122 } 123 }; 124 } // V1_0 125 } // Drm 126 } // HDI 127 } // OHOS 128 129 #endif // OHOS_HDI_DRM_V1_0_IMEDIAKEYSESSION_H