Line data Source code
1 : /*
2 : * If not stated otherwise in this file or this component's LICENSE file the
3 : * following copyright and licenses apply:
4 : *
5 : * Copyright 2022 Sky UK
6 : *
7 : * Licensed under the Apache License, Version 2.0 (the "License");
8 : * you may not use this file except in compliance with the License.
9 : * You may obtain a copy of the License at
10 : *
11 : * http://www.apache.org/licenses/LICENSE-2.0
12 : *
13 : * Unless required by applicable law or agreed to in writing, software
14 : * distributed under the License is distributed on an "AS IS" BASIS,
15 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 : * See the License for the specific language governing permissions and
17 : * limitations under the License.
18 : */
19 :
20 : #ifndef FIREBOLT_RIALTO_CLIENT_MEDIA_KEYS_IPC_H_
21 : #define FIREBOLT_RIALTO_CLIENT_MEDIA_KEYS_IPC_H_
22 :
23 : #include "IEventThread.h"
24 : #include "IMediaKeysClient.h"
25 : #include "IMediaKeysIpcFactory.h"
26 : #include "IpcModule.h"
27 : #include <memory>
28 : #include <string>
29 : #include <vector>
30 :
31 : #include "mediakeysmodule.pb.h"
32 :
33 : namespace firebolt::rialto::client
34 : {
35 : /**
36 : * @brief IMediaKeysIpc factory class definition.
37 : */
38 : class MediaKeysIpcFactory : public IMediaKeysIpcFactory
39 : {
40 : public:
41 0 : MediaKeysIpcFactory() = default;
42 0 : ~MediaKeysIpcFactory() override = default;
43 :
44 : std::unique_ptr<IMediaKeys> createMediaKeysIpc(const std::string &keySystem) const override;
45 : };
46 :
47 : /**
48 : * @brief The definition of the MediaKeysIpc.
49 : */
50 : class MediaKeysIpc : public IMediaKeys, public IpcModule
51 : {
52 : public:
53 : /**
54 : * @brief The constructor.
55 : *
56 : * @param[in] keySystem : The key system for which to create a Media Keys Ipc instance
57 : * @param[in] ipcClient : The ipc client
58 : * @param[in] eventThreadFactory : The event thread factory
59 : */
60 : MediaKeysIpc(const std::string &keySystem, IIpcClient &ipcClient,
61 : const std::shared_ptr<common::IEventThreadFactory> &eventThreadFactory);
62 :
63 : /**
64 : * @brief Virtual destructor.
65 : */
66 : virtual ~MediaKeysIpc();
67 :
68 : MediaKeyErrorStatus selectKeyId(int32_t keySessionId, const std::vector<uint8_t> &keyId) override;
69 :
70 : bool containsKey(int32_t keySessionId, const std::vector<uint8_t> &keyId) override;
71 :
72 : MediaKeyErrorStatus createKeySession(KeySessionType sessionType, std::weak_ptr<IMediaKeysClient> client,
73 : int32_t &keySessionId) override;
74 :
75 : MediaKeyErrorStatus generateRequest(int32_t keySessionId, InitDataType initDataType,
76 : const std::vector<uint8_t> &initData,
77 : const LimitedDurationLicense &ldlState) override;
78 :
79 : MediaKeyErrorStatus loadSession(int32_t keySessionId) override;
80 :
81 : MediaKeyErrorStatus updateSession(int32_t keySessionId, const std::vector<uint8_t> &responseData) override;
82 :
83 : MediaKeyErrorStatus setDrmHeader(int32_t keySessionId, const std::vector<uint8_t> &requestData) override;
84 :
85 : MediaKeyErrorStatus closeKeySession(int32_t keySessionId) override;
86 :
87 : MediaKeyErrorStatus removeKeySession(int32_t keySessionId) override;
88 :
89 : MediaKeyErrorStatus deleteDrmStore() override;
90 :
91 : MediaKeyErrorStatus deleteKeyStore() override;
92 :
93 : MediaKeyErrorStatus getDrmStoreHash(std::vector<unsigned char> &drmStoreHash) override;
94 :
95 : MediaKeyErrorStatus getKeyStoreHash(std::vector<unsigned char> &keyStoreHash) override;
96 :
97 : MediaKeyErrorStatus getLdlSessionsLimit(uint32_t &ldlLimit) override;
98 :
99 : MediaKeyErrorStatus getLastDrmError(int32_t keySessionId, uint32_t &errorCode) override;
100 :
101 : MediaKeyErrorStatus getDrmTime(uint64_t &drmTime) override;
102 :
103 : MediaKeyErrorStatus getCdmKeySessionId(int32_t keySessionId, std::string &cdmKeySessionId) override;
104 :
105 : MediaKeyErrorStatus releaseKeySession(int32_t keySessionId) override;
106 :
107 : MediaKeyErrorStatus getMetricSystemData(std::vector<uint8_t> &buffer) override;
108 :
109 : private:
110 : /**
111 : * @brief The ipc protobuf media keys stub.
112 : */
113 : std::unique_ptr<::firebolt::rialto::MediaKeysModule_Stub> m_mediaKeysStub;
114 :
115 : /**
116 : * @brief The media key handle for the current session.
117 : */
118 : std::atomic<int> m_mediaKeysHandle;
119 :
120 : /**
121 : * @brief Thread for handling media player events from the server.
122 : */
123 : std::unique_ptr<common::IEventThread> m_eventThread;
124 :
125 : /**
126 : * @brief The media keys client ipc.
127 : */
128 : std::weak_ptr<IMediaKeysClient> m_mediaKeysIpcClient;
129 :
130 : bool createRpcStubs(const std::shared_ptr<ipc::IChannel> &ipcChannel) override;
131 :
132 : bool subscribeToEvents(const std::shared_ptr<ipc::IChannel> &ipcChannel) override;
133 :
134 : /**
135 : * @brief Handler for a license request from the server.
136 : *
137 : * @param[in] event : The license request event structure.
138 : */
139 : void onLicenseRequest(const std::shared_ptr<rialto::LicenseRequestEvent> &event);
140 :
141 : /**
142 : * @brief Handler for a license renewal from the server.
143 : *
144 : * @param[in] event : The license renewal event structure.
145 : */
146 : void onLicenseRenewal(const std::shared_ptr<rialto::LicenseRenewalEvent> &event);
147 :
148 : /**
149 : * @brief Handler for a key statues change from the server.
150 : *
151 : * @param[in] event : The key statues change event structure.
152 : */
153 : void onKeyStatusesChanged(const std::shared_ptr<rialto::KeyStatusesChangedEvent> &event);
154 :
155 : /**
156 : * @brief Create a new media keys instance.
157 : *
158 : * @retval true on success, false otherwise.
159 : */
160 : bool createMediaKeys(const std::string &keySystem);
161 :
162 : /**
163 : * @brief Destroy the current media keys instance.
164 : */
165 : void destroyMediaKeys();
166 :
167 : /**
168 : * @brief Checks the Ipc controller and ProtoMediaKeyErrorStatus for failures and return the MediaKeyErrorStatus.
169 : *
170 : * @param[in] methodName : The name of the ipc method.
171 : * @param[in] controller : The rpc controller object.
172 : * @param[in] status : The protobuf response status.
173 : *
174 : * @retval The MediaKeyErrorStatus to return.
175 : */
176 : MediaKeyErrorStatus
177 : getMediaKeyErrorStatusFromResponse(const std::string methodName,
178 : const std::shared_ptr<google::protobuf::RpcController> &controller,
179 : ProtoMediaKeyErrorStatus status);
180 : };
181 :
182 : }; // namespace firebolt::rialto::client
183 :
184 : #endif // FIREBOLT_RIALTO_CLIENT_MEDIA_KEYS_IPC_H_
|