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_SERVER_I_MEDIA_KEY_SESSION_H_
21 : #define FIREBOLT_RIALTO_SERVER_I_MEDIA_KEY_SESSION_H_
22 :
23 : #include "IMediaKeysClient.h"
24 : #include "IOcdmSystem.h"
25 : #include "MediaCommon.h"
26 : #include <memory>
27 : #include <string>
28 : #include <vector>
29 :
30 : namespace firebolt::rialto::server
31 : {
32 : class IMediaKeySession;
33 :
34 : /**
35 : * @brief IMediaKeySession factory class, returns a concrete implementation of IMediaKeySession
36 : */
37 : class IMediaKeySessionFactory
38 : {
39 : public:
40 61 : IMediaKeySessionFactory() = default;
41 61 : virtual ~IMediaKeySessionFactory() = default;
42 :
43 : /**
44 : * @brief Create a IMediaKeySessionFactory instance.
45 : *
46 : * @retval the factory instance or null on error.
47 : */
48 : static std::shared_ptr<IMediaKeySessionFactory> createFactory();
49 :
50 : /**
51 : * @brief IMediaKeySession factory method, returns a concrete implementation of IMediaKeySession
52 : *
53 : * @param[in] keySystem : The key system for this session.
54 : * @param[in] keySessionId : The key session id for this session.
55 : * @param[in] ocdmSystem : The ocdm system object to create the session on.
56 : * @param[in] sessionType : The session type.
57 : * @param[in] client : Client object for callbacks.
58 : *
59 : * @retval the new media keys instance or null on error.
60 : */
61 : virtual std::unique_ptr<IMediaKeySession>
62 : createMediaKeySession(const std::string &keySystem, int32_t keySessionId,
63 : const firebolt::rialto::wrappers::IOcdmSystem &ocdmSystem, KeySessionType sessionType,
64 : std::weak_ptr<IMediaKeysClient> client) const = 0;
65 : };
66 :
67 : /**
68 : * @brief The definition of the IMediaKeySession interface.
69 : */
70 : class IMediaKeySession
71 : {
72 : public:
73 110 : IMediaKeySession() = default;
74 110 : virtual ~IMediaKeySession() = default;
75 :
76 : IMediaKeySession(const IMediaKeySession &) = delete;
77 : IMediaKeySession &operator=(const IMediaKeySession &) = delete;
78 : IMediaKeySession(IMediaKeySession &&) = delete;
79 : IMediaKeySession &operator=(IMediaKeySession &&) = delete;
80 :
81 : /**
82 : * @brief Generates a licence request.
83 : *
84 : * @param[in] initDataType : The init data type.
85 : * @param[in] initData : The init data.
86 : * @param[in] ldlState : The Limited Duration License state. Most of key systems do not need this parameter.
87 : *
88 : * @retval an error status.
89 : */
90 : virtual MediaKeyErrorStatus generateRequest(InitDataType initDataType, const std::vector<uint8_t> &initData,
91 : const LimitedDurationLicense &ldlState) = 0;
92 : /**
93 : * @brief Loads the existing key session.
94 : *
95 : * @retval an error status.
96 : */
97 : virtual MediaKeyErrorStatus loadSession() = 0;
98 :
99 : /**
100 : * @brief Updates the key session's state.
101 : *
102 : * @param[in] responseData : The license response data.
103 : *
104 : * @retval an error status.
105 : */
106 : virtual MediaKeyErrorStatus updateSession(const std::vector<uint8_t> &responseData) = 0;
107 :
108 : /**
109 : * @brief Decrypts the buffer.
110 : *
111 : * @param[in] encrypted : Gstreamer buffer containing encrypted data and related meta data. If applicable,
112 : * decrypted data will be stored here after this call returns.
113 : * @param[in] caps : The gst caps of buffer.
114 : *
115 : * @retval an error status.
116 : */
117 : virtual MediaKeyErrorStatus decrypt(GstBuffer *encrypted, GstCaps *caps) = 0;
118 :
119 : /**
120 : * @brief Closes the key session.
121 : *
122 : * @retval an error status.
123 : */
124 : virtual MediaKeyErrorStatus closeKeySession() = 0;
125 :
126 : /**
127 : * @brief Removes the key session.
128 : *
129 : * @retval an error status.
130 : */
131 : virtual MediaKeyErrorStatus removeKeySession() = 0;
132 :
133 : /**
134 : * @brief Get the internal CDM key session ID
135 : *
136 : * @param[out] cdmKeySessionId : The internal CDM key session ID
137 : *
138 : * @retval the return status.
139 : */
140 : virtual MediaKeyErrorStatus getCdmKeySessionId(std::string &cdmKeySessionId) = 0;
141 :
142 : /**
143 : * @brief Returns true if the Key Session object contains the specified key.
144 : *
145 : * @param[in] keyId : The key id.
146 : *
147 : * @retval true if it contains the key.
148 : */
149 : virtual bool containsKey(const std::vector<uint8_t> &keyId) = 0;
150 :
151 : /**
152 : * @brief Set DRM Header for a key session
153 : *
154 : * This method updates a key session's DRM header. If the session id does
155 : * not exist an MediaKeyErrorStatus:BAD_SESSION_ID is returned.If the session
156 : * state is invalid an MediaKeyErrorStatus:INVALID_STATE is returned. Any
157 : * other errors will result in MediaKeyErrorStatus:FAIL.
158 : *
159 : * @param[in] requestData : The request data.
160 : *
161 : * @retval an error status.
162 : */
163 : virtual MediaKeyErrorStatus setDrmHeader(const std::vector<uint8_t> &requestData) = 0;
164 :
165 : /**
166 : * @brief Get the last cdm specific DRM error code
167 : *
168 : * @param[out] errorCode : the error code.
169 : *
170 : * @retval the return status value.
171 : */
172 : virtual MediaKeyErrorStatus getLastDrmError(uint32_t &errorCode) = 0;
173 :
174 : /**
175 : * @brief Selects the specified keyId for the key session. Netflix specific API.
176 : *
177 : * @param[in] keyId : The key id to select.
178 : *
179 : * @retval an error status.
180 : */
181 : virtual MediaKeyErrorStatus selectKeyId(const std::vector<uint8_t> &keyId) = 0;
182 : };
183 : } // namespace firebolt::rialto::server
184 :
185 : #endif // FIREBOLT_RIALTO_SERVER_I_MEDIA_KEY_SESSION_H_
|