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_DRM_KEY_SESSION_SERVICE_H 17 #define OHOS_DRM_KEY_SESSION_SERVICE_H 18 19 #include <iostream> 20 #include <refbase.h> 21 #include "drm_dfx_utils.h" 22 #include "drm_dfx.h" 23 #include "drm_log.h" 24 #include "drm_host_manager.h" 25 #include "media_key_session_service_stub.h" 26 #include "media_decrypt_module_service.h" 27 #include "v1_0/media_key_session_proxy.h" 28 #include "v1_0/media_decrypt_module_proxy.h" 29 30 namespace OHOS { 31 namespace DrmStandard { 32 using namespace OHOS::HDI::Drm::V1_0; 33 using namespace OHOS::HDI; 34 35 class IMediaKeySessionServiceOperatorsCallback; 36 37 class MediaKeySessionService : public MediaKeySessionServiceStub, public IMediaKeySessionCallback { 38 public: 39 explicit MediaKeySessionService(sptr<OHOS::HDI::Drm::V1_0::IMediaKeySession> hdiMediaKeySession); 40 explicit MediaKeySessionService(sptr<OHOS::HDI::Drm::V1_0::IMediaKeySession> hdiMediaKeySession, 41 StatisticsInfo statisticsInfo); 42 ~MediaKeySessionService(); 43 int32_t Release() override; 44 int32_t GetMediaDecryptModule(sptr<IMediaDecryptModuleService> &decryptModule) override; 45 int32_t SetMediaKeySessionServiceOperatorsCallback(wptr<IMediaKeySessionServiceOperatorsCallback> callback); 46 int32_t CloseMediaKeySessionServiceByCallback(); 47 int32_t GenerateMediaKeyRequest(const MediaKeyRequestInfo &licenseRequestInfo, 48 MediaKeyRequest &licenseRequest) override; 49 int32_t ProcessMediaKeyResponse(std::vector<uint8_t> &licenseId, 50 const std::vector<uint8_t> &licenseResponse) override; 51 int32_t GenerateOfflineReleaseRequest(const std::vector<uint8_t> &licenseId, 52 std::vector<uint8_t> &releaseRequest) override; 53 int32_t ProcessOfflineReleaseResponse(const std::vector<uint8_t> &licenseId, 54 const std::vector<uint8_t> &releaseResponse) override; 55 int32_t CheckMediaKeyStatus(std::map<std::string, std::string> &licenseStatus) override; 56 int32_t RestoreOfflineMediaKeys(const std::vector<uint8_t> &licenseId) override; 57 int32_t ClearMediaKeys() override; 58 int32_t GetContentProtectionLevel(ContentProtectionLevel &securityLevel) override; 59 int32_t RequireSecureDecoderModule(const std::string &mimeType, bool &status) override; 60 int32_t SetCallback(const sptr<IMediaKeySessionServiceCallback> &callback) override; 61 62 // for hdi callback 63 int32_t SendEvent(OHOS::HDI::Drm::V1_0::EventType eventType, int32_t extra, 64 const std::vector<uint8_t> &data) override; 65 int32_t SendEventKeyChange( 66 const std::map<std::vector<uint8_t>, OHOS::HDI::Drm::V1_0::MediaKeySessionKeyStatus> &keyStatus, 67 bool hasNewGoodLicense) override; 68 std::string GetDecryptModuleDumpInfo(); 69 70 private: 71 std::recursive_mutex sessionMutex_; 72 std::recursive_mutex callbackMutex_; 73 sptr<IMediaKeySessionServiceCallback> callback_; 74 wptr<IMediaKeySessionServiceOperatorsCallback> sessionOperatorsCallback_; 75 sptr<OHOS::HDI::Drm::V1_0::IMediaKeySession> hdiMediaKeySession_; 76 sptr<MediaDecryptModuleService> decryptModule_; 77 StatisticsInfo statisticsInfo_; 78 std::string generationResult_; 79 std::string mediaKeyType_; 80 uint32_t generationDuration_ = 0; 81 }; 82 83 class IMediaKeySessionServiceOperatorsCallback : public virtual RefBase { 84 public: 85 IMediaKeySessionServiceOperatorsCallback() = default; 86 virtual ~IMediaKeySessionServiceOperatorsCallback() = default; 87 virtual int32_t CloseMediaKeySessionService(sptr<MediaKeySessionService> sessionService) = 0; 88 }; 89 } // DrmStandard 90 } // OHOS 91 92 #endif // OHOS_DRM_KEY_SESSION_SERVICE_H