• 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 #include <mutex>
17 #include <shared_mutex>
18 #include <string>
19 #include <refbase.h>
20 #include <securec.h>
21 #include "drm_log.h"
22 #include "drm_trace.h"
23 #include "native_drm_base.h"
24 #include "native_drm_object.h"
25 #include "key_session_impl.h"
26 #include "native_mediakeysession.h"
27 #include "native_mediakeysystem.h"
28 #include "drm_api_operation.h"
29 
30 using namespace OHOS::DrmStandard;
31 
DealMediaKeyRequest(MediaKeyRequest & licenseRequest,DRM_MediaKeyRequest * mediaKeyRequest)32 static Drm_ErrCode DealMediaKeyRequest(MediaKeyRequest &licenseRequest,
33     DRM_MediaKeyRequest *mediaKeyRequest)
34 {
35     DrmTrace trace("DealMediaKeyRequest");
36     DRM_INFO_LOG("DealMediaKeyRequest enter.");
37     memset_s(mediaKeyRequest, sizeof(DRM_MediaKeyRequest), 0, sizeof(DRM_MediaKeyRequest));
38     mediaKeyRequest->type = (DRM_MediaKeyRequestType)(licenseRequest.requestType);
39     mediaKeyRequest->dataLen = (int32_t)licenseRequest.mData.size();
40     DRM_CHECK_AND_RETURN_RET_LOG(
41         ((mediaKeyRequest->dataLen > 0) && (mediaKeyRequest->dataLen <= MAX_MEDIA_KEY_REQUEST_DATA_LEN)),
42         DRM_ERR_NO_MEMORY, "licenseRequest dataLen err!");
43     int ret = memcpy_s(mediaKeyRequest->data, sizeof(mediaKeyRequest->data), licenseRequest.mData.data(),
44         licenseRequest.mData.size());
45     if (ret != 0) {
46         DRM_DEBUG_LOG("memcpy_s mediaKeyRequest->data failed!");
47         return DRM_ERR_NO_MEMORY;
48     }
49     if (licenseRequest.mDefaultURL.size() == 0) {
50         return DRM_ERR_OK;
51     }
52     ret = memcpy_s(mediaKeyRequest->defaultUrl, sizeof(mediaKeyRequest->defaultUrl), licenseRequest.mDefaultURL.data(),
53         licenseRequest.mDefaultURL.size());
54     if (ret != 0) {
55         DRM_DEBUG_LOG("memcpy_s mediaKeyRequest->defaultUrl failed!");
56         return DRM_ERR_NO_MEMORY;
57     }
58     return DRM_ERR_OK;
59 }
60 
OH_MediaKeySession_GenerateMediaKeyRequest(MediaKeySession * mediaKeySession,DRM_MediaKeyRequestInfo * info,DRM_MediaKeyRequest * mediaKeyRequest)61 Drm_ErrCode OH_MediaKeySession_GenerateMediaKeyRequest(MediaKeySession *mediaKeySession, DRM_MediaKeyRequestInfo *info,
62     DRM_MediaKeyRequest *mediaKeyRequest)
63 {
64     DRM_INFO_LOG("OH_MediaKeySession_GenerateMediaKeyRequest enter");
65     DrmTrace trace("OH_MediaKeySession_GenerateMediaKeyRequest");
66     DRM_CHECK_AND_RETURN_RET_LOG(((mediaKeySession != nullptr) && (info != nullptr) && (mediaKeyRequest != nullptr)),
67         DRM_ERR_INVALID_VAL, "parameter is error.");
68     DRM_CHECK_AND_RETURN_RET_LOG(((info->initDataLen >= 0) && (info->initDataLen <= MAX_INIT_DATA_LEN) &&
69         (info->optionsCount <= MAX_MEDIA_KEY_REQUEST_OPTION_COUNT)), DRM_ERR_INVALID_VAL, "info err");
70     MediaKeyRequestInfo licenseRequestInfo;
71     MediaKeyRequest licenseRequest;
72     licenseRequest.requestType = RequestType::REQUEST_TYPE_RELEASE;
73     licenseRequestInfo.mediaKeyType = (MediaKeyType)info->type;
74     licenseRequestInfo.mimeType = std::string(info->mimeType, info->mimeType + sizeof(info->mimeType));
75     std::vector<uint8_t> initDataStr(info->initData, info->initData + info->initDataLen);
76     licenseRequestInfo.initData = initDataStr;
77     for (uint32_t i = 0; i < info->optionsCount; i++) {
78         std::string optionsname(info->optionName[i], info->optionName[i] + strlen(info->optionName[i]));
79         std::string optionsvalue(info->optionData[i], info->optionData[i] + strlen(info->optionData[i]));
80         licenseRequestInfo.optionalData.insert(std::make_pair(optionsname, optionsvalue));
81     }
82     MediaKeySessionObject *sessionObject = reinterpret_cast<MediaKeySessionObject *>(mediaKeySession);
83     DRM_CHECK_AND_RETURN_RET_LOG(sessionObject->sessionImpl_ != nullptr, DRM_ERR_INVALID_VAL,
84         "OH_MediaKeySession_GenerateMediaKeyRequest inner sessionImpl is nullptr!");
85     int ret = sessionObject->sessionImpl_->GenerateMediaKeyRequest(licenseRequestInfo, licenseRequest);
86     DRM_CHECK_AND_RETURN_RET_LOG((ret == DRM_ERR_OK), DRM_ERR_UNKNOWN,
87         "OH_MediaKeySession_GenerateMediaKeyRequest call Failed!");
88     Drm_ErrCode result = DealMediaKeyRequest(licenseRequest, mediaKeyRequest);
89     return result;
90 }
91 
OH_MediaKeySession_ProcessMediaKeyResponse(MediaKeySession * mediaKeySession,uint8_t * response,int32_t responseLen,uint8_t * offlineMediaKeyId,int32_t * offlineMediaKeyIdLen)92 Drm_ErrCode OH_MediaKeySession_ProcessMediaKeyResponse(MediaKeySession *mediaKeySession, uint8_t *response,
93     int32_t responseLen, uint8_t *offlineMediaKeyId, int32_t *offlineMediaKeyIdLen)
94 {
95     DRM_INFO_LOG("OH_MediaKeySession_ProcessMediaKeyResponse enter.");
96     int64_t beginTime = std::chrono::duration_cast<std::chrono::milliseconds>(
97         std::chrono::system_clock::now().time_since_epoch()).count();
98     DrmTrace trace("OH_MediaKeySession_ProcessMediaKeyResponse");
99     DRM_CHECK_AND_RETURN_RET_LOG(
100         ((mediaKeySession != nullptr) && (response != nullptr) && (responseLen > 0) &&
101         (offlineMediaKeyId != nullptr) && (offlineMediaKeyIdLen != nullptr)), DRM_ERR_INVALID_VAL,
102         "parameter is error!");
103     MediaKeySessionObject *sessionObject = reinterpret_cast<MediaKeySessionObject *>(mediaKeySession);
104     DRM_CHECK_AND_RETURN_RET_LOG(sessionObject->sessionImpl_ != nullptr, DRM_ERR_INVALID_VAL,
105         "OH_MediaKeySession_ProcessMediaKeyResponse inner sessionImpl is nullptr!");
106     std::vector<uint8_t> licenseResponseVec(response, response + responseLen);
107     std::vector<uint8_t> keyIdVec;
108     int32_t ret = sessionObject->sessionImpl_->ProcessMediaKeyResponse(keyIdVec, licenseResponseVec);
109     DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_ERR_OK, DRM_ERR_UNKNOWN, "got licenseResponse null!");
110     ConfigParser::WriteEndEvent(0, 0, std::string("OH_MediaKeySession_ProcessMediaKeyResponse"), beginTime);
111     if (keyIdVec.size() == 0) {
112         DRM_DEBUG_LOG("keyIdVec.data() is nullptr!");
113         return DRM_ERR_OK;
114     }
115     DRM_CHECK_AND_RETURN_RET_LOG((*offlineMediaKeyIdLen > 0), DRM_ERR_NO_MEMORY, "offlineMediaKeyIdLen err!");
116     ret = memcpy_s(offlineMediaKeyId, *offlineMediaKeyIdLen, keyIdVec.data(), keyIdVec.size());
117     *offlineMediaKeyIdLen = keyIdVec.size();
118     if (ret != 0) {
119         DRM_ERR_LOG("memcpy_s offlineMediaKeyId faild!");
120         return DRM_ERR_NO_MEMORY;
121     }
122     return DRM_ERR_OK;
123 }
124 
MapToClist(std::map<std::string,std::string> licenseStatus,DRM_MediaKeyStatus * mediaKeyStatus)125 static Drm_ErrCode MapToClist(std::map<std::string, std::string> licenseStatus, DRM_MediaKeyStatus *mediaKeyStatus)
126 {
127     DRM_INFO_LOG("MapToClist enter.");
128     memset_s(mediaKeyStatus, sizeof(DRM_MediaKeyStatus), 0, sizeof(DRM_MediaKeyStatus));
129     mediaKeyStatus->statusCount = licenseStatus.size();
130     DRM_CHECK_AND_RETURN_RET_LOG((mediaKeyStatus->statusCount <= MAX_MEDIA_KEY_STATUS_COUNT),
131         DRM_ERR_NO_MEMORY, "statusCount err!");
132     auto it = licenseStatus.begin();
133     for (size_t i = 0; i < licenseStatus.size(); i++) {
134         if (it->first.size() != 0) {
135             int32_t ret = memcpy_s(mediaKeyStatus->statusName[i], sizeof(mediaKeyStatus->statusName[i]),
136                 it->first.c_str(), it->first.size());
137             if (ret != 0) {
138                 DRM_DEBUG_LOG("memcpy_s mediaKeyStatus->statusName failed!");
139                 return DRM_ERR_NO_MEMORY;
140             }
141         }
142         if (it->second.size() != 0) {
143             int32_t ret = memcpy_s(mediaKeyStatus->statusValue[i], sizeof(mediaKeyStatus->statusValue[i]),
144                 it->second.c_str(), it->second.size());
145             if (ret != 0) {
146                 DRM_DEBUG_LOG("memcpy_s mediaKeyStatus->statusValue failed!");
147                 return DRM_ERR_NO_MEMORY;
148             }
149         }
150         it++;
151     }
152     return DRM_ERR_OK;
153 }
154 
OH_MediaKeySession_CheckMediaKeyStatus(MediaKeySession * mediaKeySessoin,DRM_MediaKeyStatus * mediaKeyStatus)155 Drm_ErrCode OH_MediaKeySession_CheckMediaKeyStatus(MediaKeySession *mediaKeySessoin, DRM_MediaKeyStatus *mediaKeyStatus)
156 {
157     DRM_INFO_LOG("OH_MediaKeySession_CheckMediaKeyStatus enter");
158     std::map<std::string, std::string> licenseStatus;
159     DRM_CHECK_AND_RETURN_RET_LOG(((mediaKeySessoin != nullptr) && (mediaKeyStatus != nullptr)), DRM_ERR_INVALID_VAL,
160         "OH_MediaKeySession_CheckMediaKeyStatus parameter is error!");
161     MediaKeySessionObject *sessionObject = reinterpret_cast<MediaKeySessionObject *>(mediaKeySessoin);
162     DRM_CHECK_AND_RETURN_RET_LOG(sessionObject->sessionImpl_ != nullptr, DRM_ERR_INVALID_VAL,
163         "OH_MediaKeySession_CheckMediaKeyStatus inner sessionImpl is nullptr!");
164     int32_t result = sessionObject->sessionImpl_->CheckMediaKeyStatus(licenseStatus);
165     DRM_CHECK_AND_RETURN_RET_LOG(result == DRM_ERR_OK, DRM_ERR_UNKNOWN,
166         "mediaKeySystemImpl::CheckMediaKeyStatus faild!");
167     if (licenseStatus.size() == 0) {
168         DRM_ERR_LOG("Licence not exist.");
169         return DRM_ERR_UNKNOWN;
170     }
171     Drm_ErrCode ret = MapToClist(licenseStatus, mediaKeyStatus);
172     return ret;
173 }
174 
OH_MediaKeySession_ClearMediaKeys(MediaKeySession * mediaKeySessoin)175 Drm_ErrCode OH_MediaKeySession_ClearMediaKeys(MediaKeySession *mediaKeySessoin)
176 {
177     DRM_INFO_LOG("OH_MediaKeySession_ClearMediaKeys enter.");
178     DRM_CHECK_AND_RETURN_RET_LOG(mediaKeySessoin != nullptr, DRM_ERR_INVALID_VAL,
179         "OH_MediaKeySession_ClearMediaKeys parameter is error!");
180     int32_t currentPid = OHOS::IPCSkeleton::GetCallingPid();
181     DRM_DEBUG_LOG("MediaKeySessionNapi GetCallingPID: %{public}d", currentPid);
182     int32_t result = DRM_ERR_OK;
183     MediaKeySessionObject *sessionObject = reinterpret_cast<MediaKeySessionObject *>(mediaKeySessoin);
184     DRM_CHECK_AND_RETURN_RET_LOG(sessionObject->sessionImpl_ != nullptr, DRM_ERR_INVALID_VAL,
185         "OH_MediaKeySession_ClearMediaKeys inner sessionImpl is nullptr!");
186     result = sessionObject->sessionImpl_->ClearMediaKeys();
187     DRM_CHECK_AND_RETURN_RET_LOG(result == DRM_ERR_OK, DRM_ERR_UNKNOWN,
188         "OH_SetConfigurationByteArray mediaKeySystemImpl::SetConfigurationByteArray faild!");
189     return DRM_ERR_OK;
190 }
191 
OH_MediaKeySession_GenerateOfflineReleaseRequest(MediaKeySession * mediaKeySessoin,uint8_t * offlineMediaKeyId,int32_t offlineMediaKeyIdLen,uint8_t * releaseRequest,int32_t * releaseRequestLen)192 Drm_ErrCode OH_MediaKeySession_GenerateOfflineReleaseRequest(MediaKeySession *mediaKeySessoin,
193     uint8_t *offlineMediaKeyId, int32_t offlineMediaKeyIdLen, uint8_t *releaseRequest, int32_t *releaseRequestLen)
194 {
195     DRM_INFO_LOG("OH_MediaKeySession_GenerateOfflineReleaseRequest enter");
196     DRM_CHECK_AND_RETURN_RET_LOG(((mediaKeySessoin != nullptr) && (offlineMediaKeyId != nullptr) &&
197         (offlineMediaKeyIdLen > 0) && (offlineMediaKeyIdLen <= MAX_OFFLINE_MEDIA_KEY_ID_LEN) &&
198         (releaseRequest != nullptr) && (releaseRequestLen != nullptr)),
199         DRM_ERR_INVALID_VAL, "OH_MediaKeySession_GenerateOfflineReleaseRequest parameter is error!");
200     std::vector<uint8_t> ReleaseRequest;
201     std::vector<uint8_t> licenseIdVec(offlineMediaKeyId, offlineMediaKeyId + offlineMediaKeyIdLen);
202 
203     MediaKeySessionObject *sessionObject = reinterpret_cast<MediaKeySessionObject *>(mediaKeySessoin);
204     DRM_CHECK_AND_RETURN_RET_LOG(sessionObject->sessionImpl_ != nullptr, DRM_ERR_INVALID_VAL,
205         "OH_MediaKeySession_GenerateOfflineReleaseRequest inner sessionImpl is nullptr!");
206 
207     int32_t result = sessionObject->sessionImpl_->GenerateOfflineReleaseRequest(licenseIdVec, ReleaseRequest);
208     DRM_CHECK_AND_RETURN_RET_LOG(result == DRM_ERR_OK, DRM_ERR_UNKNOWN,
209         "OH_MediaKeySession_GenerateOfflineReleaseRequest GenerateOfflineReleaseRequest faild!");
210     if (ReleaseRequest.size() == 0) {
211         DRM_DEBUG_LOG("ReleaseRequest.data() is nullptr!");
212         return DRM_ERR_OK;
213     }
214     DRM_CHECK_AND_RETURN_RET_LOG((*releaseRequestLen > 0), DRM_ERR_NO_MEMORY, "releaseRequestLen err!");
215     int32_t ret = memcpy_s(releaseRequest, *releaseRequestLen, ReleaseRequest.data(), ReleaseRequest.size());
216     *releaseRequestLen = ReleaseRequest.size();
217     if (ret != 0) {
218         DRM_ERR_LOG("memcpy_s releaseRequest faild!");
219         return DRM_ERR_NO_MEMORY;
220     }
221     return DRM_ERR_OK;
222 }
223 
OH_MediaKeySession_ProcessOfflineReleaseResponse(MediaKeySession * mediaKeySessoin,uint8_t * offlineMediaKeyId,int32_t offlineMediaKeyIdLen,uint8_t * releaseReponse,int32_t releaseReponseLen)224 Drm_ErrCode OH_MediaKeySession_ProcessOfflineReleaseResponse(MediaKeySession *mediaKeySessoin,
225     uint8_t *offlineMediaKeyId, int32_t offlineMediaKeyIdLen, uint8_t *releaseReponse, int32_t releaseReponseLen)
226 {
227     DRM_INFO_LOG("OH_MediaKeySession_ProcessOfflineReleaseResponse enter.");
228     DRM_CHECK_AND_RETURN_RET_LOG(((mediaKeySessoin != nullptr) && (offlineMediaKeyId != nullptr) &&
229         (offlineMediaKeyIdLen > 0) && (offlineMediaKeyIdLen <= MAX_OFFLINE_MEDIA_KEY_ID_LEN) &&
230         (releaseReponse != nullptr) && (releaseReponseLen > 0)),
231         DRM_ERR_INVALID_VAL, "OH_MediaKeySession_ProcessOfflineReleaseResponse parameter is error!");
232     std::vector<uint8_t> licenseIdVec(offlineMediaKeyId, offlineMediaKeyId + offlineMediaKeyIdLen);
233     std::vector<uint8_t> responseVec(releaseReponse, releaseReponse + releaseReponseLen);
234     int32_t result = DRM_ERR_OK;
235     MediaKeySessionObject *sessionObject = reinterpret_cast<MediaKeySessionObject *>(mediaKeySessoin);
236     DRM_CHECK_AND_RETURN_RET_LOG(sessionObject->sessionImpl_ != nullptr, DRM_ERR_INVALID_VAL,
237         "OH_MediaKeySession_ProcessOfflineReleaseResponse inner sessionImpl is nullptr!");
238     result = sessionObject->sessionImpl_->ProcessOfflineReleaseResponse(licenseIdVec, responseVec);
239     DRM_CHECK_AND_RETURN_RET_LOG((result == DRM_ERR_OK), DRM_ERR_UNKNOWN,
240         "OH_MediaKeySession_ProcessOfflineReleaseResponse call Failed!");
241     return DRM_ERR_OK;
242 }
243 
OH_MediaKeySession_RestoreOfflineMediaKeys(MediaKeySession * mediaKeySessoin,uint8_t * offlineMediaKeyId,int32_t offlineMediaKeyIdLen)244 Drm_ErrCode OH_MediaKeySession_RestoreOfflineMediaKeys(MediaKeySession *mediaKeySessoin,
245     uint8_t *offlineMediaKeyId, int32_t offlineMediaKeyIdLen)
246 {
247     DRM_INFO_LOG("OH_MediaKeySession_RestoreOfflineMediaKeys enter.");
248     int64_t beginTime = std::chrono::duration_cast<std::chrono::milliseconds>(
249         std::chrono::system_clock::now().time_since_epoch()).count();
250     DRM_CHECK_AND_RETURN_RET_LOG(
251         ((mediaKeySessoin != nullptr) && (offlineMediaKeyId != nullptr) && (offlineMediaKeyIdLen > 0) &&
252         (offlineMediaKeyIdLen <= MAX_OFFLINE_MEDIA_KEY_ID_LEN)),
253         DRM_ERR_INVALID_VAL, "OH_MediaKeySession_RestoreOfflineMediaKeys parameter is error!");
254     std::vector<uint8_t> licenseIdVec(offlineMediaKeyId, offlineMediaKeyId + offlineMediaKeyIdLen);
255     int32_t result = DRM_ERR_OK;
256     MediaKeySessionObject *sessionObject = reinterpret_cast<MediaKeySessionObject *>(mediaKeySessoin);
257     DRM_CHECK_AND_RETURN_RET_LOG(sessionObject->sessionImpl_ != nullptr, DRM_ERR_INVALID_VAL,
258         "OH_MediaKeySession_RestoreOfflineMediaKeys inner sessionImpl is nullptr!");
259     result = sessionObject->sessionImpl_->RestoreOfflineMediaKeys(licenseIdVec);
260     DRM_CHECK_AND_RETURN_RET_LOG((result == DRM_ERR_OK), DRM_ERR_UNKNOWN,
261         "OH_MediaKeySession_RestoreOfflineMediaKeys call Failed!");
262     ConfigParser::WriteEndEvent(0, 0, std::string("OH_MediaKeySession_RestoreOfflineMediaKeys"), beginTime);
263     return DRM_ERR_OK;
264 }
265 
OH_MediaKeySession_GetContentProtectionLevel(MediaKeySession * mediaKeySessoin,DRM_ContentProtectionLevel * contentProtectionLevel)266 Drm_ErrCode OH_MediaKeySession_GetContentProtectionLevel(MediaKeySession *mediaKeySessoin,
267     DRM_ContentProtectionLevel *contentProtectionLevel)
268 {
269     DRM_INFO_LOG("OH_MediaKeySession_GetContentProtectionLevel enter.");
270     DRM_CHECK_AND_RETURN_RET_LOG(((mediaKeySessoin != nullptr) && (contentProtectionLevel != nullptr)),
271         DRM_ERR_INVALID_VAL, "OH_MediaKeySession_GetContentProtectionLevel parameter is error!");
272     int32_t result = DRM_ERR_OK;
273     ContentProtectionLevel level =
274         ContentProtectionLevel::CONTENT_PROTECTION_LEVEL_UNKNOWN;
275     MediaKeySessionObject *sessionObject = reinterpret_cast<MediaKeySessionObject *>(mediaKeySessoin);
276     DRM_CHECK_AND_RETURN_RET_LOG(sessionObject->sessionImpl_ != nullptr, DRM_ERR_INVALID_VAL,
277         "OH_MediaKeySession_GetContentProtectionLevel inner sessionImpl is nullptr!");
278     result = sessionObject->sessionImpl_->GetContentProtectionLevel(&level);
279     DRM_CHECK_AND_RETURN_RET_LOG((result == DRM_ERR_OK), DRM_ERR_UNKNOWN,
280         "OH_MediaKeySession_GetContentProtectionLevel get level fail!");
281     *contentProtectionLevel = static_cast<DRM_ContentProtectionLevel>(level);
282     if (*contentProtectionLevel <= CONTENT_PROTECTION_LEVEL_UNKNOWN ||
283         *contentProtectionLevel >= CONTENT_PROTECTION_LEVEL_MAX) {
284         DRM_ERR_LOG("OH_MediaKeySession_GetContentProtectionLevel the level obtained is beyond reasonable range!");
285         return DRM_ERR_UNKNOWN;
286     }
287     return DRM_ERR_OK;
288 }
289 
OH_MediaKeySession_RequireSecureDecoderModule(MediaKeySession * mediaKeySessoin,const char * mimeType,bool * status)290 Drm_ErrCode OH_MediaKeySession_RequireSecureDecoderModule(MediaKeySession *mediaKeySessoin, const char *mimeType,
291     bool *status)
292 {
293     DRM_INFO_LOG("OH_MediaKeySession_RequireSecureDecoderModule enter.");
294     DRM_CHECK_AND_RETURN_RET_LOG(((mediaKeySessoin != nullptr) && (mimeType != nullptr) && (status != nullptr)),
295         DRM_ERR_INVALID_VAL, "OH_MediaKeySession_RequireSecureDecoderModule parameter is error!");
296     std::string mimeTypeBuf = std::string(mimeType);
297     DRM_CHECK_AND_RETURN_RET_LOG((mimeTypeBuf.size() != 0), DRM_ERR_INVALID_VAL,
298         "OH_MediaKeySession_RequireSecureDecoderModule mimeTypesize is zero!");
299     bool statusValue = false;
300     int32_t result = DRM_ERR_OK;
301     MediaKeySessionObject *sessionObject = reinterpret_cast<MediaKeySessionObject *>(mediaKeySessoin);
302     DRM_CHECK_AND_RETURN_RET_LOG(sessionObject->sessionImpl_ != nullptr, DRM_ERR_INVALID_VAL,
303         "OH_MediaKeySession_RequireSecureDecoderModule inner sessionImpl is nullptr!");
304     result = sessionObject->sessionImpl_->RequireSecureDecoderModule(mimeTypeBuf, &statusValue);
305     if (result != DRM_ERR_OK) {
306         DRM_ERR_LOG("OH_MediaKeySession_RequireSecureDecoderModule keySessionImpl_->RequireSecureDecoderModule faild!");
307         return DRM_ERR_UNKNOWN;
308     }
309     *status = statusValue;
310     return DRM_ERR_OK;
311 }
312 
OH_MediaKeySession_SetMediaKeySessionCallback(MediaKeySession * mediaKeySessoin,MediaKeySession_Callback * callback)313 Drm_ErrCode OH_MediaKeySession_SetMediaKeySessionCallback(MediaKeySession *mediaKeySessoin,
314     MediaKeySession_Callback *callback)
315 {
316     DRM_INFO_LOG("OH_MediaKeySession_SetMediaKeySessionCallback enter.");
317     DRM_CHECK_AND_RETURN_RET_LOG(((mediaKeySessoin != nullptr) && (callback != nullptr)), DRM_ERR_INVALID_VAL,
318         "mediaKeySessoin is nullptr!");
319     MediaKeySessionObject *sessionObject = reinterpret_cast<MediaKeySessionObject *>(mediaKeySessoin);
320     DRM_CHECK_AND_RETURN_RET_LOG(sessionObject->sessionImpl_ != nullptr, DRM_ERR_INVALID_VAL,
321         "OH_MediaKeySession_SetMediaKeySessionCallback inner sessionImpl is nullptr!");
322     sessionObject->sessionCallback_->SetCallbackReference(*callback);
323     return DRM_ERR_OK;
324 }
325 
OH_MediaKeySession_SetCallback(MediaKeySession * mediaKeySessoin,OH_MediaKeySession_Callback * callback)326 Drm_ErrCode OH_MediaKeySession_SetCallback(MediaKeySession *mediaKeySessoin,
327     OH_MediaKeySession_Callback *callback)
328 {
329     DRM_INFO_LOG("OH_MediaKeySession_SetCallback enter.");
330     DRM_CHECK_AND_RETURN_RET_LOG(((mediaKeySessoin != nullptr) && (callback != nullptr)), DRM_ERR_INVALID_VAL,
331         "mediaKeySessoin is nullptr!");
332     MediaKeySessionObject *sessionObject = reinterpret_cast<MediaKeySessionObject *>(mediaKeySessoin);
333     DRM_CHECK_AND_RETURN_RET_LOG(sessionObject->sessionImpl_ != nullptr, DRM_ERR_INVALID_VAL,
334         "OH_MediaKeySession_SetCallback inner sessionImpl is nullptr!");
335     sessionObject->sessionCallback_->SetCallbackReference(mediaKeySessoin, *callback);
336     return DRM_ERR_OK;
337 }
338 
OH_MediaKeySession_Destroy(MediaKeySession * keySession)339 Drm_ErrCode OH_MediaKeySession_Destroy(MediaKeySession *keySession)
340 {
341     DRM_INFO_LOG("OH_MediaKeySession_Destroy enter.");
342     DRM_CHECK_AND_RETURN_RET_LOG(keySession != nullptr, DRM_ERR_INVALID_VAL,
343         "OH_MediaKeySession_Destroy keySession is nullptr!");
344     int32_t result = DRM_ERR_OK;
345     MediaKeySessionObject *sessionObject = reinterpret_cast<MediaKeySessionObject *>(keySession);
346     DRM_CHECK_AND_RETURN_RET_LOG(sessionObject->sessionImpl_ != nullptr, DRM_ERR_INVALID_VAL,
347         "OH_MediaKeySession_Destroy inner sessionImpl is nullptr!");
348     result = sessionObject->sessionImpl_->Release();
349     if (result != DRM_ERR_OK) {
350         DRM_ERR_LOG("OH_MediaKeySession_Destroy keySessionImpl_->Release faild!");
351         return DRM_ERR_UNKNOWN;
352     }
353     delete keySession;
354     keySession = nullptr;
355     return DRM_ERR_OK;
356 }