• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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) do { \
36     if ((lv) compare (rv)) { \
37         return ret; \
38     } \
39 } while (false)
40 #endif
41 
42 #ifndef HDI_CHECK_VALUE_RET_GOTO
43 #define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \
44     if ((lv) compare (rv)) { \
45         ret = value; \
46         goto table; \
47     } \
48 } while (false)
49 #endif
50 
51 namespace OHOS {
52 namespace HDI {
53 namespace Drm {
54 namespace V1_0 {
55 using namespace OHOS;
56 using namespace OHOS::HDI;
57 
58 enum {
59     CMD_MEDIA_KEY_SYSTEM_GET_VERSION = 0,
60     CMD_MEDIA_KEY_SYSTEM_GET_CONFIGURATION_STRING = 1,
61     CMD_MEDIA_KEY_SYSTEM_SET_CONFIGURATION_STRING = 2,
62     CMD_MEDIA_KEY_SYSTEM_GET_CONFIGURATION_BYTE_ARRAY = 3,
63     CMD_MEDIA_KEY_SYSTEM_SET_CONFIGURATION_BYTE_ARRAY = 4,
64     CMD_MEDIA_KEY_SYSTEM_GET_STATISTICS = 5,
65     CMD_MEDIA_KEY_SYSTEM_GET_MAX_CONTENT_PROTECTION_LEVEL = 6,
66     CMD_MEDIA_KEY_SYSTEM_GENERATE_KEY_SYSTEM_REQUEST = 7,
67     CMD_MEDIA_KEY_SYSTEM_PROCESS_KEY_SYSTEM_RESPONSE = 8,
68     CMD_MEDIA_KEY_SYSTEM_GET_OEM_CERTIFICATE_STATUS = 9,
69     CMD_MEDIA_KEY_SYSTEM_SET_CALLBACK = 10,
70     CMD_MEDIA_KEY_SYSTEM_CREATE_MEDIA_KEY_SESSION = 11,
71     CMD_MEDIA_KEY_SYSTEM_GET_OFFLINE_MEDIA_KEY_IDS = 12,
72     CMD_MEDIA_KEY_SYSTEM_GET_OFFLINE_MEDIA_KEY_STATUS = 13,
73     CMD_MEDIA_KEY_SYSTEM_CLEAR_OFFLINE_MEDIA_KEYS = 14,
74     CMD_MEDIA_KEY_SYSTEM_GET_OEM_CERTIFICATE = 15,
75     CMD_MEDIA_KEY_SYSTEM_DESTROY = 16,
76 };
77 
78 class IMediaKeySystem : public HdiBase {
79 public:
80     DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.drm.v1_0.IMediaKeySystem");
81 
82     virtual ~IMediaKeySystem() = default;
83 
84     virtual int32_t GetConfigurationString(const std::string& name, std::string& value) = 0;
85 
86     virtual int32_t SetConfigurationString(const std::string& name, const std::string& value) = 0;
87 
88     virtual int32_t GetConfigurationByteArray(const std::string& name, std::vector<uint8_t>& value) = 0;
89 
90     virtual int32_t SetConfigurationByteArray(const std::string& name, const std::vector<uint8_t>& value) = 0;
91 
92     virtual int32_t GetStatistics(std::map<std::string, std::string>& statistics) = 0;
93 
94     virtual int32_t GetMaxContentProtectionLevel(OHOS::HDI::Drm::V1_0::ContentProtectionLevel& level) = 0;
95 
96     virtual int32_t GenerateKeySystemRequest(std::string& defaultUrl, std::vector<uint8_t>& request) = 0;
97 
98     virtual int32_t ProcessKeySystemResponse(const std::vector<uint8_t>& response) = 0;
99 
100     virtual int32_t GetOemCertificateStatus(OHOS::HDI::Drm::V1_0::CertificateStatus& status) = 0;
101 
102     virtual int32_t SetCallback(const sptr<OHOS::HDI::Drm::V1_0::IMediaKeySystemCallback>& systemCallback) = 0;
103 
104     virtual int32_t CreateMediaKeySession(OHOS::HDI::Drm::V1_0::ContentProtectionLevel level,
105          sptr<OHOS::HDI::Drm::V1_0::IMediaKeySession>& keySession) = 0;
106 
107     virtual int32_t GetOfflineMediaKeyIds(std::vector<std::vector<uint8_t>>& mediaKeyIds) = 0;
108 
109     virtual int32_t GetOfflineMediaKeyStatus(const std::vector<uint8_t>& mediaKeyId,
110          OHOS::HDI::Drm::V1_0::OfflineMediaKeyStatus& mediaKeyStatus) = 0;
111 
112     virtual int32_t ClearOfflineMediaKeys(const std::vector<uint8_t>& mediaKeyId) = 0;
113 
114     virtual int32_t GetOemCertificate(sptr<OHOS::HDI::Drm::V1_0::IOemCertificate>& oemCert) = 0;
115 
116     virtual int32_t Destroy() = 0;
117 
GetVersion(uint32_t & majorVer,uint32_t & minorVer)118     virtual int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer)
119     {
120         majorVer = 1;
121         minorVer = 0;
122         return HDF_SUCCESS;
123     }
124 
IsProxy()125     virtual bool IsProxy()
126     {
127         return false;
128     }
129 
GetDesc()130     virtual const std::u16string GetDesc()
131     {
132         return metaDescriptor_;
133     }
134 };
135 } // V1_0
136 } // Drm
137 } // HDI
138 } // OHOS
139 
140 #endif // OHOS_HDI_DRM_V1_0_IMEDIAKEYSYSTEM_H