LCOV - code coverage report
Current view: top level - media/server/main/include - MediaKeySession.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 2 2
Test Date: 2026-03-04 13:20:25 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_KEY_SESSION_H_
      21              : #define FIREBOLT_RIALTO_SERVER_MEDIA_KEY_SESSION_H_
      22              : 
      23              : #include "IMainThread.h"
      24              : #include "IMediaKeySession.h"
      25              : #include "IOcdmSessionClient.h"
      26              : #include <atomic>
      27              : #include <memory>
      28              : #include <mutex>
      29              : #include <string>
      30              : #include <vector>
      31              : 
      32              : namespace firebolt::rialto::server
      33              : {
      34              : /**
      35              :  * @brief IMediaKeySessionFactory factory class definition.
      36              :  */
      37              : class MediaKeySessionFactory : public IMediaKeySessionFactory
      38              : {
      39              : public:
      40            2 :     MediaKeySessionFactory() = default;
      41            2 :     ~MediaKeySessionFactory() override = default;
      42              : 
      43              :     std::unique_ptr<IMediaKeySession> createMediaKeySession(const std::string &keySystem, int32_t keySessionId,
      44              :                                                             const firebolt::rialto::wrappers::IOcdmSystem &ocdmSystem,
      45              :                                                             KeySessionType sessionType,
      46              :                                                             std::weak_ptr<IMediaKeysClient> client) const override;
      47              : };
      48              : 
      49              : /**
      50              :  * @brief The definition of the MediaKeySession.
      51              :  */
      52              : class MediaKeySession : public IMediaKeySession, public firebolt::rialto::wrappers::IOcdmSessionClient
      53              : {
      54              : public:
      55              :     /**
      56              :      * @brief The constructor.
      57              :      *
      58              :      * @param[in]  keySystem            : The key system for this session.
      59              :      * @param[in]  keySessionId         : The key session id for this session.
      60              :      * @param[in]  ocdmSystem           : The ocdm system object to create the session on.
      61              :      * @param[in]  sessionType          : The session type.
      62              :      * @param[in]  client               : Client object for callbacks.
      63              :      * @param[in]  mainThreadFactory    : The main thread factory.
      64              :      */
      65              :     MediaKeySession(const std::string &keySystem, int32_t keySessionId,
      66              :                     const firebolt::rialto::wrappers::IOcdmSystem &ocdmSystem, KeySessionType sessionType,
      67              :                     std::weak_ptr<IMediaKeysClient> client, const std::shared_ptr<IMainThreadFactory> &mainThreadFactory);
      68              : 
      69              :     /**
      70              :      * @brief Virtual destructor.
      71              :      */
      72              :     virtual ~MediaKeySession();
      73              : 
      74              :     MediaKeyErrorStatus generateRequest(InitDataType initDataType, const std::vector<uint8_t> &initData,
      75              :                                         const LimitedDurationLicense &ldlState) override;
      76              : 
      77              :     MediaKeyErrorStatus loadSession() override;
      78              : 
      79              :     MediaKeyErrorStatus updateSession(const std::vector<uint8_t> &responseData) override;
      80              : 
      81              :     MediaKeyErrorStatus decrypt(GstBuffer *encrypted, GstCaps *caps) override;
      82              : 
      83              :     MediaKeyErrorStatus closeKeySession() override;
      84              : 
      85              :     MediaKeyErrorStatus removeKeySession() override;
      86              : 
      87              :     MediaKeyErrorStatus getCdmKeySessionId(std::string &cdmKeySessionId) override;
      88              : 
      89              :     bool containsKey(const std::vector<uint8_t> &keyId) override;
      90              : 
      91              :     MediaKeyErrorStatus setDrmHeader(const std::vector<uint8_t> &requestData) override;
      92              : 
      93              :     MediaKeyErrorStatus getLastDrmError(uint32_t &errorCode) override;
      94              : 
      95              :     MediaKeyErrorStatus selectKeyId(const std::vector<uint8_t> &keyId) override;
      96              : 
      97              :     void onProcessChallenge(const char url[], const uint8_t challenge[], const uint16_t challengeLength) override;
      98              : 
      99              :     void onKeyUpdated(const uint8_t keyId[], const uint8_t keyIdLength) override;
     100              : 
     101              :     void onAllKeysUpdated() override;
     102              : 
     103              :     void onError(const char message[]) override;
     104              : 
     105              : private:
     106              :     /**
     107              :      * @brief KeySystem type of the MediaKeys.
     108              :      */
     109              :     const std::string m_kKeySystem;
     110              : 
     111              :     /**
     112              :      * @brief The key session id for this session.
     113              :      */
     114              :     const int32_t m_kKeySessionId;
     115              : 
     116              :     /**
     117              :      * @brief The key session type of this session.
     118              :      */
     119              :     const KeySessionType m_kSessionType;
     120              : 
     121              :     /**
     122              :      * @brief The media keys client object.
     123              :      */
     124              :     std::weak_ptr<IMediaKeysClient> m_mediaKeysClient;
     125              : 
     126              :     /**
     127              :      * @brief The IOcdmSession instance.
     128              :      */
     129              :     std::unique_ptr<firebolt::rialto::wrappers::IOcdmSession> m_ocdmSession;
     130              : 
     131              :     /**
     132              :      * @brief The mainThread object.
     133              :      */
     134              :     std::shared_ptr<IMainThread> m_mainThread;
     135              : 
     136              :     /**
     137              :      * @brief Is the ocdm session constructed.
     138              :      */
     139              :     bool m_isSessionConstructed;
     140              : 
     141              :     /**
     142              :      * @brief Is the ocdm session closed.
     143              :      */
     144              :     bool m_isSessionClosed;
     145              : 
     146              :     /**
     147              :      * @brief Set to true if generateRequest has complete and waiting for license response.
     148              :      */
     149              :     std::atomic<bool> m_licenseRequested;
     150              : 
     151              :     /**
     152              :      * @brief Store of the updated key statuses from a onKeyUpdated.
     153              :      */
     154              :     KeyStatusVector m_updatedKeyStatuses;
     155              : 
     156              :     /**
     157              :      * @brief This objects id registered on the main thread
     158              :      */
     159              :     uint32_t m_mainThreadClientId;
     160              : 
     161              :     /**
     162              :      * @brief Currently selected key id (Netflix specific)
     163              :      */
     164              :     std::vector<uint8_t> m_selectedKeyId;
     165              : 
     166              :     /**
     167              :      * @brief Whether a Ocdm call is currently ongoing.
     168              :      */
     169              :     bool m_ongoingOcdmOperation;
     170              : 
     171              :     /**
     172              :      * @brief Whether Ocdm has returned an error via the onError callback.
     173              :      */
     174              :     bool m_ocdmError;
     175              : 
     176              :     /**
     177              :      * @brief Mutex protecting the ocdm error checking.
     178              :      */
     179              :     std::mutex m_ocdmErrorMutex;
     180              : 
     181              :     /**
     182              :      * @brief Drm header to be set once the session is constructed
     183              :      */
     184              :     std::vector<uint8_t> m_queuedDrmHeader;
     185              : 
     186              :     /**
     187              :      * @brief Flag used to check if extended interface is used
     188              :      */
     189              :     bool m_extendedInterfaceInUse{false};
     190              : 
     191              :     /**
     192              :      * @brief Posts a getChallenge task onto the main thread.
     193              :      *
     194              :      * @param[in] ldlState : The Limited Duration License state.
     195              :      *
     196              :      * The challenge data is retrieved from ocdm and notified on a onLicenseRequest.
     197              :      */
     198              :     void getChallenge(const LimitedDurationLicense &ldlState);
     199              : 
     200              :     /**
     201              :      * @brief Initalises the ocdm error data which checks for onError callbacks.
     202              :      */
     203              :     void initOcdmErrorChecking();
     204              : 
     205              :     /**
     206              :      * @brief Checks if onError has been received.
     207              :      *
     208              :      * @param[in] operationStr : Operation name for logging purposes.
     209              :      *
     210              :      * @retval True if an error was received.
     211              :      */
     212              :     bool checkForOcdmErrors(const char *operationStr);
     213              : };
     214              : } // namespace firebolt::rialto::server
     215              : 
     216              : #endif // FIREBOLT_RIALTO_SERVER_MEDIA_KEY_SESSION_H_
        

Generated by: LCOV version 2.0-1