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, bool isLDL,
73 : int32_t &keySessionId) override;
74 :
75 : MediaKeyErrorStatus generateRequest(int32_t keySessionId, InitDataType initDataType,
76 : const std::vector<uint8_t> &initData) override;
77 :
78 : MediaKeyErrorStatus loadSession(int32_t keySessionId) override;
79 :
80 : MediaKeyErrorStatus updateSession(int32_t keySessionId, const std::vector<uint8_t> &responseData) override;
81 :
82 : MediaKeyErrorStatus setDrmHeader(int32_t keySessionId, const std::vector<uint8_t> &requestData) override;
83 :
84 : MediaKeyErrorStatus closeKeySession(int32_t keySessionId) override;
85 :
86 : MediaKeyErrorStatus removeKeySession(int32_t keySessionId) override;
87 :
88 : MediaKeyErrorStatus deleteDrmStore() override;
89 :
90 : MediaKeyErrorStatus deleteKeyStore() override;
91 :
92 : MediaKeyErrorStatus getDrmStoreHash(std::vector<unsigned char> &drmStoreHash) override;
93 :
94 : MediaKeyErrorStatus getKeyStoreHash(std::vector<unsigned char> &keyStoreHash) override;
95 :
96 : MediaKeyErrorStatus getLdlSessionsLimit(uint32_t &ldlLimit) override;
97 :
98 : MediaKeyErrorStatus getLastDrmError(int32_t keySessionId, uint32_t &errorCode) override;
99 :
100 : MediaKeyErrorStatus getDrmTime(uint64_t &drmTime) override;
101 :
102 : MediaKeyErrorStatus getCdmKeySessionId(int32_t keySessionId, std::string &cdmKeySessionId) override;
103 :
104 : MediaKeyErrorStatus releaseKeySession(int32_t keySessionId) override;
105 :
106 : private:
107 : /**
108 : * @brief The ipc protobuf media keys stub.
109 : */
110 : std::unique_ptr<::firebolt::rialto::MediaKeysModule_Stub> m_mediaKeysStub;
111 :
112 : /**
113 : * @brief The media key handle for the current session.
114 : */
115 : std::atomic<int> m_mediaKeysHandle;
116 :
117 : /**
118 : * @brief Thread for handling media player events from the server.
119 : */
120 : std::unique_ptr<common::IEventThread> m_eventThread;
121 :
122 : /**
123 : * @brief The media keys client ipc.
124 : */
125 : std::weak_ptr<IMediaKeysClient> m_mediaKeysIpcClient;
126 :
127 : bool createRpcStubs(const std::shared_ptr<ipc::IChannel> &ipcChannel) override;
128 :
129 : bool subscribeToEvents(const std::shared_ptr<ipc::IChannel> &ipcChannel) override;
130 :
131 : /**
132 : * @brief Handler for a license request from the server.
133 : *
134 : * @param[in] event : The license request event structure.
135 : */
136 : void onLicenseRequest(const std::shared_ptr<rialto::LicenseRequestEvent> &event);
137 :
138 : /**
139 : * @brief Handler for a license renewal from the server.
140 : *
141 : * @param[in] event : The license renewal event structure.
142 : */
143 : void onLicenseRenewal(const std::shared_ptr<rialto::LicenseRenewalEvent> &event);
144 :
145 : /**
146 : * @brief Handler for a key statues change from the server.
147 : *
148 : * @param[in] event : The key statues change event structure.
149 : */
150 : void onKeyStatusesChanged(const std::shared_ptr<rialto::KeyStatusesChangedEvent> &event);
151 :
152 : /**
153 : * @brief Create a new media keys instance.
154 : *
155 : * @retval true on success, false otherwise.
156 : */
157 : bool createMediaKeys(const std::string &keySystem);
158 :
159 : /**
160 : * @brief Destroy the current media keys instance.
161 : */
162 : void destroyMediaKeys();
163 :
164 : /**
165 : * @brief Checks the Ipc controller and ProtoMediaKeyErrorStatus for failures and return the MediaKeyErrorStatus.
166 : *
167 : * @param[in] methodName : The name of the ipc method.
168 : * @param[in] controller : The rpc controller object.
169 : * @param[in] status : The protobuf response status.
170 : *
171 : * @retval The MediaKeyErrorStatus to return.
172 : */
173 : MediaKeyErrorStatus
174 : getMediaKeyErrorStatusFromResponse(const std::string methodName,
175 : const std::shared_ptr<google::protobuf::RpcController> &controller,
176 : ProtoMediaKeyErrorStatus status);
177 : };
178 :
179 : }; // namespace firebolt::rialto::client
180 :
181 : #endif // FIREBOLT_RIALTO_CLIENT_MEDIA_KEYS_IPC_H_
|