• 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_DRM_MEDIA_KEY_SYSTEMP_IMPL_H
17 #define OHOS_DRM_MEDIA_KEY_SYSTEMP_IMPL_H
18 
19 #include "ipc_skeleton.h"
20 #include "iservice_registry.h"
21 #include "nocopyable.h"
22 #include "system_ability_definition.h"
23 #include "drm_log.h"
24 #include "drm_death_recipient.h"
25 #include "key_session_impl.h"
26 #include "i_mediakeysystem_service.h"
27 #include "mediakeysystem_service_callback_stub.h"
28 
29 namespace OHOS {
30 namespace DrmStandard {
31 namespace MediaKeySystemEvent {
32 const std::string EVENT_STR_PROVISION_REQUIRED = "keySystemRequired";
33 }
34 class MediaKeySystemImplCallback : public RefBase {
35 public:
36     MediaKeySystemImplCallback() = default;
37     virtual ~MediaKeySystemImplCallback() = default;
38     virtual void SendEvent(const std::string &event, int32_t extra, const std::vector<uint8_t> &data) = 0;
39 };
40 
41 class MediaKeySystemImpl : public RefBase {
42 public:
43     explicit MediaKeySystemImpl(sptr<IMediaKeySystemService> &mediaKeysystem);
44     ~MediaKeySystemImpl();
45 
46     int32_t SetConfigurationString(std::string &configName, std::string &value);
47     int32_t GetConfigurationString(std::string &configName, std::string &value);
48     int32_t SetConfigurationByteArray(std::string &configName, std::vector<uint8_t> &value);
49     int32_t GetConfigurationByteArray(std::string &configName, std::vector<uint8_t> &value);
50     int32_t CreateMediaKeySession(IMediaKeySessionService::ContentProtectionLevel securityLevel,
51         sptr<MediaKeySessionImpl> *keySessionImpl);
52     int32_t GetStatistics(std::vector<IMediaKeySystemService::MetircKeyValue> &metrics);
53     int32_t GetMaxContentProtectionLevel(IMediaKeySessionService::ContentProtectionLevel *securityLevel);
54 
55     int32_t GenerateKeySystemRequest(std::vector<uint8_t> &request, std::string &defaultUrl);
56     int32_t ProcessKeySystemResponse(const std::vector<uint8_t> &response);
57 
58     int32_t GetOfflineMediaKeyIds(std::vector<std::vector<uint8_t>> &licenseIds);
59     int32_t GetOfflineMediaKeyStatus(std::vector<uint8_t> &licenseId,
60         IMediaKeySessionService::OfflineMediaKeyStatus &status);
61     int32_t ClearOfflineMediaKeys(std::vector<uint8_t> &licenseId);
62 
63     int32_t GetCertificateStatus(IMediaKeySystemService::CertificateStatus *certStatus);
64     sptr<MediaKeySystemImplCallback> GetApplicationCallback();
65     int32_t SetCallback(const sptr<MediaKeySystemImplCallback> &callback);
66     int32_t Release();
67 
68 private:
69     std::mutex mutex_;
70     sptr<IMediaKeySystemService> serviceProxy_;
71     sptr<MediaKeySystemImplCallback> mediaKeySystemApplicationCallback_;
72     sptr<IMeidaKeySystemServiceCallback> serviceCallback_;
73     std::vector<sptr<MediaKeySessionImpl>> keySessionVec;
74     uint32_t keySessionNumber = 0;
75 };
76 
77 class MediaKeySystemCallback : public MeidaKeySystemServiceCallbackStub {
78 public:
MediaKeySystemCallback()79     MediaKeySystemCallback() : systemImpl_(nullptr)
80     {
81         InitEventMap();
82     };
MediaKeySystemCallback(const sptr<MediaKeySystemImpl> & systemImpl)83     explicit MediaKeySystemCallback(const sptr<MediaKeySystemImpl> &systemImpl) : systemImpl_(systemImpl)
84     {
85         InitEventMap();
86     };
87     ~MediaKeySystemCallback();
88     void InitEventMap();
89     std::string GetEventName(DrmEventType event);
90     int32_t SendEvent(DrmEventType event, int32_t extra, const std::vector<uint8_t> data) override;
91 
92 private:
93     sptr<MediaKeySystemImpl> systemImpl_;
94     std::unordered_map<int32_t, std::string> eventMap_;
95 };
96 } // DrmStandard
97 } // OHOS
98 #endif // OHOS_DRM_MEDIA_KEY_SYSTEMP_IMPL_H