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

Generated by: LCOV version 2.0-1