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 2023 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 CDM_BACKEND_H_
21 : #define CDM_BACKEND_H_
22 :
23 : #include "ICdmBackend.h"
24 : #include "Logger.h"
25 : #include "MessageDispatcher.h"
26 : #include <IControlClient.h>
27 : #include <IMediaKeys.h>
28 : #include <condition_variable>
29 : #include <memory>
30 : #include <mutex>
31 : #include <string>
32 : #include <vector>
33 :
34 : class CdmBackend : public ICdmBackend, public firebolt::rialto::IControlClient
35 : {
36 : public:
37 : CdmBackend(const std::string &keySystem, const std::shared_ptr<firebolt::rialto::IMediaKeysClient> &mediaKeysClient,
38 : const std::shared_ptr<firebolt::rialto::IMediaKeysFactory> &mediaKeysFactory);
39 85 : ~CdmBackend() override = default;
40 :
41 : void notifyApplicationState(firebolt::rialto::ApplicationState state) override;
42 :
43 : bool initialize(const firebolt::rialto::ApplicationState &initialState) override;
44 :
45 : bool selectKeyId(int32_t keySessionId, const std::vector<uint8_t> &keyId) override;
46 : bool containsKey(int32_t keySessionId, const std::vector<uint8_t> &keyId) override;
47 : bool createKeySession(firebolt::rialto::KeySessionType sessionType, bool isLDL, int32_t &keySessionId) override;
48 : bool generateRequest(int32_t keySessionId, firebolt::rialto::InitDataType initDataType,
49 : const std::vector<uint8_t> &initData) override;
50 : bool loadSession(int32_t keySessionId) override;
51 : bool updateSession(int32_t keySessionId, const std::vector<uint8_t> &responseData) override;
52 : bool setDrmHeader(int32_t keySessionId, const std::vector<uint8_t> &requestData) override;
53 : bool closeKeySession(int32_t keySessionId) override;
54 : bool removeKeySession(int32_t keySessionId) override;
55 : bool deleteDrmStore() override;
56 : bool deleteKeyStore() override;
57 : bool getDrmStoreHash(std::vector<unsigned char> &drmStoreHash) override;
58 : bool getKeyStoreHash(std::vector<unsigned char> &keyStoreHash) override;
59 : bool getLdlSessionsLimit(uint32_t &ldlLimit) override;
60 : bool getLastDrmError(int32_t keySessionId, uint32_t &errorCode) override;
61 : bool getDrmTime(uint64_t &drmTime) override;
62 : bool getCdmKeySessionId(int32_t keySessionId, std::string &cdmKeySessionId) override;
63 : bool releaseKeySession(int32_t keySessionId) override;
64 : bool getMetricSystemData(std::vector<uint8_t> &buffer) override;
65 :
66 : private:
67 : bool createMediaKeys();
68 :
69 : private:
70 : Logger m_log;
71 : std::mutex m_mutex;
72 : std::condition_variable m_cv;
73 : firebolt::rialto::ApplicationState m_appState;
74 : const std::string m_keySystem;
75 : std::shared_ptr<firebolt::rialto::IMediaKeysClient> m_mediaKeysClient;
76 : std::shared_ptr<firebolt::rialto::IMediaKeysFactory> m_mediaKeysFactory;
77 : std::unique_ptr<firebolt::rialto::IMediaKeys> m_mediaKeys;
78 : };
79 :
80 : #endif // CDM_BACKEND_H_
|