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

Generated by: LCOV version 2.0-1