LCOV - code coverage report
Current view: top level - media/server/main/include - MediaKeysServerInternal.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 2 2
Test Date: 2025-11-04 14:59:28 Functions: 100.0 % 2 2

            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_MEDIA_KEYS_SERVER_INTERNAL_H_
      21              : #define FIREBOLT_RIALTO_SERVER_MEDIA_KEYS_SERVER_INTERNAL_H_
      22              : 
      23              : #include "IMainThread.h"
      24              : #include "IMediaKeySession.h"
      25              : #include "IMediaKeysServerInternal.h"
      26              : #include "IOcdmSystem.h"
      27              : #include <map>
      28              : #include <memory>
      29              : #include <string>
      30              : #include <vector>
      31              : 
      32              : namespace firebolt::rialto::server
      33              : {
      34              : /**
      35              :  * @brief IMediaKeys factory class definition.
      36              :  */
      37              : class MediaKeysServerInternalFactory : public IMediaKeysServerInternalFactory
      38              : {
      39              : public:
      40            2 :     MediaKeysServerInternalFactory() = default;
      41            2 :     ~MediaKeysServerInternalFactory() override = default;
      42              : 
      43              :     std::unique_ptr<IMediaKeys> createMediaKeys(const std::string &keySystem) const override;
      44              :     std::unique_ptr<IMediaKeysServerInternal> createMediaKeysServerInternal(const std::string &keySystem) const override;
      45              : };
      46              : 
      47              : }; // namespace firebolt::rialto::server
      48              : 
      49              : namespace firebolt::rialto::server
      50              : {
      51              : /**
      52              :  * @brief The definition of the MediaKeysServerInternal.
      53              :  */
      54              : class MediaKeysServerInternal : public IMediaKeysServerInternal
      55              : {
      56              : public:
      57              :     /**
      58              :      * @brief The constructor.
      59              :      *
      60              :      * @param[in] keySystem                 : The key system for which to create a Media Keys instance.
      61              :      * @param[in] mainThreadFactory         : The main thread factory.
      62              :      * @param[in] ocdmSystemFactory         : The ocdm system factory.
      63              :      * @param[in] mediaKeySessionFactory    : The media key session factory.
      64              :      *
      65              :      */
      66              :     MediaKeysServerInternal(const std::string &keySystem, const std::shared_ptr<IMainThreadFactory> &mainThreadFactory,
      67              :                             std::shared_ptr<firebolt::rialto::wrappers::IOcdmSystemFactory> ocdmSystemFactory,
      68              :                             std::shared_ptr<IMediaKeySessionFactory> mediaKeySessionFactory);
      69              : 
      70              :     /**
      71              :      * @brief Virtual destructor.
      72              :      */
      73              :     virtual ~MediaKeysServerInternal();
      74              : 
      75              :     MediaKeyErrorStatus selectKeyId(int32_t keySessionId, const std::vector<uint8_t> &keyId) override;
      76              : 
      77              :     bool containsKey(int32_t keySessionId, const std::vector<uint8_t> &keyId) override;
      78              : 
      79              :     MediaKeyErrorStatus createKeySession(KeySessionType sessionType, std::weak_ptr<IMediaKeysClient> client, bool isLDL,
      80              :                                          int32_t &keySessionId) override;
      81              : 
      82              :     MediaKeyErrorStatus generateRequest(int32_t keySessionId, InitDataType initDataType,
      83              :                                         const std::vector<uint8_t> &initData) override;
      84              : 
      85              :     MediaKeyErrorStatus loadSession(int32_t keySessionId) override;
      86              : 
      87              :     MediaKeyErrorStatus updateSession(int32_t keySessionId, const std::vector<uint8_t> &responseData) override;
      88              : 
      89              :     MediaKeyErrorStatus setDrmHeader(int32_t keySessionId, const std::vector<uint8_t> &requestData) override;
      90              : 
      91              :     MediaKeyErrorStatus closeKeySession(int32_t keySessionId) override;
      92              : 
      93              :     MediaKeyErrorStatus removeKeySession(int32_t keySessionId) override;
      94              : 
      95              :     MediaKeyErrorStatus deleteDrmStore() override;
      96              : 
      97              :     MediaKeyErrorStatus deleteKeyStore() override;
      98              : 
      99              :     MediaKeyErrorStatus getDrmStoreHash(std::vector<unsigned char> &drmStoreHash) override;
     100              : 
     101              :     MediaKeyErrorStatus getKeyStoreHash(std::vector<unsigned char> &keyStoreHash) override;
     102              : 
     103              :     MediaKeyErrorStatus getLdlSessionsLimit(uint32_t &ldlLimit) override;
     104              : 
     105              :     MediaKeyErrorStatus getLastDrmError(int32_t keySessionId, uint32_t &errorCode) override;
     106              : 
     107              :     MediaKeyErrorStatus getDrmTime(uint64_t &drmTime) override;
     108              : 
     109              :     MediaKeyErrorStatus getCdmKeySessionId(int32_t keySessionId, std::string &cdmKeySessionId) override;
     110              : 
     111              :     MediaKeyErrorStatus releaseKeySession(int32_t keySessionId) override;
     112              : 
     113              :     MediaKeyErrorStatus decrypt(int32_t keySessionId, GstBuffer *encrypted, GstCaps *caps) override;
     114              : 
     115              :     MediaKeyErrorStatus getMetricSystemData(std::vector<uint8_t> &buffer) override;
     116              : 
     117              :     bool isNetflixPlayreadyKeySystem() const override;
     118              : 
     119              :     void ping(std::unique_ptr<IHeartbeatHandler> &&heartbeatHandler) override;
     120              : 
     121              : private:
     122              :     /**
     123              :      * @brief The mainThread object.
     124              :      */
     125              :     std::shared_ptr<IMainThread> m_mainThread;
     126              : 
     127              :     /**
     128              :      * @brief The factory for creating MediaKeySessions.
     129              :      */
     130              :     std::shared_ptr<IMediaKeySessionFactory> m_mediaKeySessionFactory;
     131              : 
     132              :     /**
     133              :      * @brief The IOcdmSystem instance.
     134              :      */
     135              :     std::shared_ptr<firebolt::rialto::wrappers::IOcdmSystem> m_ocdmSystem;
     136              : 
     137              :     /**
     138              :      * @brief Map containing created sessions.
     139              :      */
     140              :     std::map<int32_t, std::unique_ptr<IMediaKeySession>> m_mediaKeySessions;
     141              : 
     142              :     /**
     143              :      * @brief KeySystem type of the MediaKeysServerInternal.
     144              :      */
     145              :     const std::string m_kKeySystem;
     146              : 
     147              :     /**
     148              :      * @brief This objects id registered on the main thread
     149              :      */
     150              :     uint32_t m_mainThreadClientId;
     151              : 
     152              :     /**
     153              :      * @brief Creates a session internally, only to be called on the main thread.
     154              :      *
     155              :      * @param[in]  sessionType : The session type.
     156              :      * @param[in]  client      : Client object for callbacks
     157              :      * @param[in]  isLDL       : Is this an LDL
     158              :      * @param[out] keySessionId: The key session id
     159              :      *
     160              :      * @retval an error status.
     161              :      */
     162              :     MediaKeyErrorStatus createKeySessionInternal(KeySessionType sessionType, std::weak_ptr<IMediaKeysClient> client,
     163              :                                                  bool isLDL, int32_t &keySessionId);
     164              : 
     165              :     /**
     166              :      * @brief Generate internally, only to be called on the main thread.
     167              :      *
     168              :      * @param[in]  keySessionId : The key session id for the session.
     169              :      * @param[in]  initDataType : The init data type.
     170              :      * @param[in]  initData     : The init data.
     171              :      *
     172              :      * @retval an error status.
     173              :      */
     174              :     MediaKeyErrorStatus generateRequestInternal(int32_t keySessionId, InitDataType initDataType,
     175              :                                                 const std::vector<uint8_t> &initData);
     176              : 
     177              :     /**
     178              :      * @brief Load internally, only to be called on the main thread.
     179              :      *
     180              :      * @param[in] keySessionId : The key session id for the session.
     181              :      *
     182              :      * @retval an error status.
     183              :      */
     184              :     MediaKeyErrorStatus loadSessionInternal(int32_t keySessionId);
     185              : 
     186              :     /**
     187              :      * @brief Update internally, only to be called on the main thread.
     188              :      *
     189              :      * @param[in] keySessionId : The key session id for the session.
     190              :      * @param[in] responseData : The license response data.
     191              :      *
     192              :      * @retval an error status.
     193              :      */
     194              :     MediaKeyErrorStatus updateSessionInternal(int32_t keySessionId, const std::vector<uint8_t> &responseData);
     195              : 
     196              :     /**
     197              :      * @brief Close a key session internally, only to be called on the main thread.
     198              :      *
     199              :      * @param[in] keySessionId : The key session id.
     200              :      *
     201              :      * @retval an error status.
     202              :      */
     203              :     MediaKeyErrorStatus closeKeySessionInternal(int32_t keySessionId);
     204              : 
     205              :     /**
     206              :      * @brief Removes a key session internally, only to be called on the main thread.
     207              :      *
     208              :      * @param[in] keySessionId : The key session id.
     209              :      *
     210              :      * @retval an error status.
     211              :      */
     212              :     MediaKeyErrorStatus removeKeySessionInternal(int32_t keySessionId);
     213              : 
     214              :     /**
     215              :      * @brief Get the key session id internally, only to be called on the main thread.
     216              :      *
     217              :      * @param[in]   keySessionId    : The key session id for the session.
     218              :      * @param[out]  cdmKeySessionId : The internal CDM key session ID
     219              :      *
     220              :      * @retval an error status.
     221              :      */
     222              :     MediaKeyErrorStatus getCdmKeySessionIdInternal(int32_t keySessionId, std::string &cdmKeySessionId);
     223              : 
     224              :     /**
     225              :      * @brief Decrypt internally, only to be called on the main thread.
     226              :      *
     227              :      * @param[in] keySessionId    : The session id for the session.
     228              :      * @param[in] encrypted       : Gstreamer buffer containing encrypted data and related meta data. If applicable,
     229              :      *                              decrypted data will be stored here after this call returns.
     230              :      * @param[in] caps            : The gst caps of buffer.
     231              :      *
     232              :      * @retval an error status.
     233              :      */
     234              :     MediaKeyErrorStatus decryptInternal(int32_t keySessionId, GstBuffer *encrypted, GstCaps *caps);
     235              : 
     236              :     /**
     237              :      * @brief Selects the specified keyId for the key session internally, only to be called on the main thread.
     238              :      *
     239              :      * @param[in] keySessionId : The key session id for the session.
     240              :      * @param[in] keyId        : The key id to select.
     241              :      *
     242              :      * @retval an error status.
     243              :      */
     244              :     MediaKeyErrorStatus selectKeyIdInternal(int32_t keySessionId, const std::vector<uint8_t> &keyId);
     245              : 
     246              :     /**
     247              :      * @brief Returns true if the Key Session object contains the specified key internally,
     248              :      *        only to be called on the main thread.
     249              :      *
     250              :      * @param[in] keySessionId : The key session id for the session.
     251              :      * @param[in] keyId        : The key id.
     252              :      *
     253              :      * @retval true if it contains the key.
     254              :      */
     255              :     bool containsKeyInternal(int32_t keySessionId, const std::vector<uint8_t> &keyId);
     256              : 
     257              :     /**
     258              :      * @brief Set DRM Header for a key session internally, only to be called on the main thread.
     259              :      *
     260              :      * @param[in] keySessionId : The session id for the session.
     261              :      * @param[in] requestData  : The request data.
     262              :      *
     263              :      * @retval an error status.
     264              :      */
     265              :     MediaKeyErrorStatus setDrmHeaderInternal(int32_t keySessionId, const std::vector<uint8_t> &requestData);
     266              : 
     267              :     /**
     268              :      * @brief Get the last cdm specific DRM error code internally, only to be called on the main thread.
     269              :      *
     270              :      * @param[in] keySessionId : The key session id.
     271              :      * @param[out] errorCode : the error code.
     272              :      *
     273              :      * @retval the return status value.
     274              :      */
     275              :     MediaKeyErrorStatus getLastDrmErrorInternal(int32_t keySessionId, uint32_t &errorCode);
     276              : 
     277              :     /**
     278              :      * @brief Releases a key session internally, only to be called on the main thread.
     279              :      *
     280              :      * @param[in] keySessionId : The key session id.
     281              :      *
     282              :      * @retval an error status.
     283              :      */
     284              :     MediaKeyErrorStatus releaseKeySessionInternal(int32_t keySessionId);
     285              : };
     286              : 
     287              : }; // namespace firebolt::rialto::server
     288              : 
     289              : #endif // FIREBOLT_RIALTO_SERVER_MEDIA_KEYS_SERVER_INTERNAL_H_
        

Generated by: LCOV version 2.0-1