LCOV - code coverage report
Current view: top level - media/server/service/source - CdmService.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 308 308
Test Date: 2025-02-18 13:13:53 Functions: 100.0 % 39 39

            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              : #include <algorithm>
      21              : #include <exception>
      22              : #include <memory>
      23              : #include <string>
      24              : #include <utility>
      25              : #include <vector>
      26              : 
      27              : #include "CdmService.h"
      28              : #include "RialtoServerLogging.h"
      29              : 
      30              : namespace firebolt::rialto::server::service
      31              : {
      32           90 : CdmService::CdmService(std::shared_ptr<IMediaKeysServerInternalFactory> &&mediaKeysFactory,
      33           90 :                        std::shared_ptr<IMediaKeysCapabilitiesFactory> &&mediaKeysCapabilitiesFactory)
      34           90 :     : m_mediaKeysFactory{mediaKeysFactory}, m_mediaKeysCapabilitiesFactory{mediaKeysCapabilitiesFactory}, m_isActive{false}
      35              : {
      36           90 :     RIALTO_SERVER_LOG_DEBUG("CdmService is constructed");
      37              : }
      38              : 
      39           90 : CdmService::~CdmService()
      40              : {
      41           90 :     RIALTO_SERVER_LOG_DEBUG("CdmService is destructed");
      42              : }
      43              : 
      44           85 : bool CdmService::switchToActive()
      45              : {
      46           85 :     RIALTO_SERVER_LOG_INFO("Switching SessionServer to Active state.");
      47           85 :     m_isActive = true;
      48           85 :     return true;
      49              : }
      50              : 
      51            2 : void CdmService::switchToInactive()
      52              : {
      53            2 :     RIALTO_SERVER_LOG_INFO("Switching SessionServer to Inactive state. Cleaning resources...");
      54            2 :     m_isActive = false;
      55              : 
      56              :     {
      57            2 :         std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
      58            2 :         m_mediaKeys.clear();
      59              :     }
      60              : }
      61              : 
      62           57 : bool CdmService::createMediaKeys(int mediaKeysHandle, std::string keySystem)
      63              : {
      64           57 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to create new media keys handle: %d", mediaKeysHandle);
      65           57 :     if (!m_isActive)
      66              :     {
      67            2 :         RIALTO_SERVER_LOG_ERROR("Skip to create media keys handle: %d - Session Server in Inactive state",
      68              :                                 mediaKeysHandle);
      69            2 :         return false;
      70              :     }
      71              : 
      72              :     {
      73           55 :         std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
      74           55 :         if (m_mediaKeys.find(mediaKeysHandle) != m_mediaKeys.end())
      75              :         {
      76            1 :             RIALTO_SERVER_LOG_ERROR("Media keys handle: %d already exists", mediaKeysHandle);
      77            1 :             return false;
      78              :         }
      79           54 :         m_mediaKeys.emplace(std::make_pair(mediaKeysHandle, m_mediaKeysFactory->createMediaKeysServerInternal(keySystem)));
      80           54 :         if (!m_mediaKeys.at(mediaKeysHandle))
      81              :         {
      82            1 :             RIALTO_SERVER_LOG_ERROR("Could not create MediaKeys for media keys handle: %d", mediaKeysHandle);
      83            1 :             m_mediaKeys.erase(mediaKeysHandle);
      84            1 :             return false;
      85              :         }
      86           55 :     }
      87              : 
      88           53 :     RIALTO_SERVER_LOG_INFO("New media keys handle: %d created", mediaKeysHandle);
      89           53 :     return true;
      90              : }
      91              : 
      92           51 : bool CdmService::destroyMediaKeys(int mediaKeysHandle)
      93              : {
      94           51 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to destroy media keys handle: %d", mediaKeysHandle);
      95              : 
      96              :     {
      97           51 :         std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
      98           51 :         auto mediaKeysIter = m_mediaKeys.find(mediaKeysHandle);
      99           51 :         if (mediaKeysIter == m_mediaKeys.end())
     100              :         {
     101            2 :             RIALTO_SERVER_LOG_ERROR("Media keys handle: %d does not exists", mediaKeysHandle);
     102            2 :             return false;
     103              :         }
     104           49 :         m_mediaKeys.erase(mediaKeysIter);
     105           51 :     }
     106              : 
     107           49 :     RIALTO_SERVER_LOG_INFO("Media keys handle: %d destroyed", mediaKeysHandle);
     108           49 :     return true;
     109              : }
     110              : 
     111            5 : MediaKeyErrorStatus CdmService::createKeySession(int mediaKeysHandle, KeySessionType sessionType,
     112              :                                                  const std::shared_ptr<IMediaKeysClient> &client, bool isLDL,
     113              :                                                  int32_t &keySessionId)
     114              : {
     115            5 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to create key session: %d", mediaKeysHandle);
     116              : 
     117            5 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     118            5 :     auto mediaKeysIter = m_mediaKeys.find(mediaKeysHandle);
     119            5 :     if (mediaKeysIter == m_mediaKeys.end())
     120              :     {
     121            1 :         RIALTO_SERVER_LOG_ERROR("Media keys handle: %d does not exists", mediaKeysHandle);
     122            1 :         return MediaKeyErrorStatus::FAIL;
     123              :     }
     124              : 
     125            4 :     MediaKeyErrorStatus status = mediaKeysIter->second->createKeySession(sessionType, client, isLDL, keySessionId);
     126            4 :     if (MediaKeyErrorStatus::OK == status)
     127              :     {
     128            3 :         if (m_mediaKeysClients.find(keySessionId) != m_mediaKeysClients.end())
     129              :         {
     130            1 :             RIALTO_SERVER_LOG_ERROR("Media keys client for key session: %d already exists", keySessionId);
     131            1 :             static_cast<void>(removeKeySessionInternal(mediaKeysHandle, keySessionId));
     132            1 :             return MediaKeyErrorStatus::FAIL;
     133              :         }
     134            2 :         m_mediaKeysClients.emplace(std::make_pair(keySessionId, client));
     135              :     }
     136              : 
     137            3 :     return status;
     138            5 : }
     139              : 
     140            3 : MediaKeyErrorStatus CdmService::generateRequest(int mediaKeysHandle, int32_t keySessionId, InitDataType initDataType,
     141              :                                                 const std::vector<uint8_t> &initData)
     142              : {
     143            3 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to generate request: %d", mediaKeysHandle);
     144              : 
     145            3 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     146            3 :     auto mediaKeysIter = m_mediaKeys.find(mediaKeysHandle);
     147            3 :     if (mediaKeysIter == m_mediaKeys.end())
     148              :     {
     149            1 :         RIALTO_SERVER_LOG_ERROR("Media keys handle: %d does not exists", mediaKeysHandle);
     150            1 :         return MediaKeyErrorStatus::FAIL;
     151              :     }
     152            2 :     return mediaKeysIter->second->generateRequest(keySessionId, initDataType, initData);
     153            3 : }
     154              : 
     155            3 : MediaKeyErrorStatus CdmService::loadSession(int mediaKeysHandle, int32_t keySessionId)
     156              : {
     157            3 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to load session: %d", mediaKeysHandle);
     158              : 
     159            3 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     160            3 :     auto mediaKeysIter = m_mediaKeys.find(mediaKeysHandle);
     161            3 :     if (mediaKeysIter == m_mediaKeys.end())
     162              :     {
     163            1 :         RIALTO_SERVER_LOG_ERROR("Media keys handle: %d does not exists", mediaKeysHandle);
     164            1 :         return MediaKeyErrorStatus::FAIL;
     165              :     }
     166            2 :     return mediaKeysIter->second->loadSession(keySessionId);
     167            3 : }
     168              : 
     169            3 : MediaKeyErrorStatus CdmService::updateSession(int mediaKeysHandle, int32_t keySessionId,
     170              :                                               const std::vector<uint8_t> &responseData)
     171              : {
     172            3 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to update session: %d", mediaKeysHandle);
     173              : 
     174            3 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     175            3 :     auto mediaKeysIter = m_mediaKeys.find(mediaKeysHandle);
     176            3 :     if (mediaKeysIter == m_mediaKeys.end())
     177              :     {
     178            1 :         RIALTO_SERVER_LOG_ERROR("Media keys handle: %d does not exists", mediaKeysHandle);
     179            1 :         return MediaKeyErrorStatus::FAIL;
     180              :     }
     181            2 :     return mediaKeysIter->second->updateSession(keySessionId, responseData);
     182            3 : }
     183              : 
     184            3 : MediaKeyErrorStatus CdmService::closeKeySession(int mediaKeysHandle, int32_t keySessionId)
     185              : {
     186            3 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to close key session: %d", mediaKeysHandle);
     187              : 
     188            3 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     189            3 :     auto mediaKeysIter = m_mediaKeys.find(mediaKeysHandle);
     190            3 :     if (mediaKeysIter == m_mediaKeys.end())
     191              :     {
     192            1 :         RIALTO_SERVER_LOG_ERROR("Media keys handle: %d does not exists", mediaKeysHandle);
     193            1 :         return MediaKeyErrorStatus::FAIL;
     194              :     }
     195            2 :     return mediaKeysIter->second->closeKeySession(keySessionId);
     196            3 : }
     197              : 
     198            3 : MediaKeyErrorStatus CdmService::removeKeySession(int mediaKeysHandle, int32_t keySessionId)
     199              : {
     200            3 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to remove key session: %d", mediaKeysHandle);
     201              : 
     202            3 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     203            6 :     return removeKeySessionInternal(mediaKeysHandle, keySessionId);
     204            3 : }
     205              : 
     206            4 : MediaKeyErrorStatus CdmService::removeKeySessionInternal(int mediaKeysHandle, int32_t keySessionId)
     207              : {
     208            4 :     auto mediaKeysIter = m_mediaKeys.find(mediaKeysHandle);
     209            4 :     if (mediaKeysIter == m_mediaKeys.end())
     210              :     {
     211            1 :         RIALTO_SERVER_LOG_ERROR("Media keys handle: %d does not exists", mediaKeysHandle);
     212            1 :         return MediaKeyErrorStatus::FAIL;
     213              :     }
     214              : 
     215            3 :     MediaKeyErrorStatus status = mediaKeysIter->second->removeKeySession(keySessionId);
     216            3 :     if (MediaKeyErrorStatus::OK == status)
     217              :     {
     218            2 :         auto mediaKeysClientsIter = m_mediaKeysClients.find(keySessionId);
     219            2 :         if (mediaKeysClientsIter != m_mediaKeysClients.end())
     220              :         {
     221            1 :             m_mediaKeysClients.erase(mediaKeysClientsIter);
     222              :         }
     223              :     }
     224              : 
     225            3 :     return status;
     226              : }
     227              : 
     228            3 : MediaKeyErrorStatus CdmService::getCdmKeySessionId(int mediaKeysHandle, int32_t keySessionId, std::string &cdmKeySessionId)
     229              : {
     230            3 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to get cdm key session id: %d", mediaKeysHandle);
     231              : 
     232            3 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     233            3 :     auto mediaKeysIter = m_mediaKeys.find(mediaKeysHandle);
     234            3 :     if (mediaKeysIter == m_mediaKeys.end())
     235              :     {
     236            1 :         RIALTO_SERVER_LOG_ERROR("Media keys handle: %d does not exists", mediaKeysHandle);
     237            1 :         return MediaKeyErrorStatus::FAIL;
     238              :     }
     239              : 
     240            2 :     MediaKeyErrorStatus status = mediaKeysIter->second->getCdmKeySessionId(keySessionId, cdmKeySessionId);
     241            2 :     return status;
     242            3 : }
     243              : 
     244            3 : bool CdmService::containsKey(int mediaKeysHandle, int32_t keySessionId, const std::vector<uint8_t> &keyId)
     245              : {
     246            3 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to check if key is present: %d", mediaKeysHandle);
     247              : 
     248            3 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     249            3 :     auto mediaKeysIter = m_mediaKeys.find(mediaKeysHandle);
     250            3 :     if (mediaKeysIter == m_mediaKeys.end())
     251              :     {
     252            1 :         RIALTO_SERVER_LOG_ERROR("Media keys handle: %d does not exists", mediaKeysHandle);
     253            1 :         return false;
     254              :     }
     255              : 
     256            2 :     return mediaKeysIter->second->containsKey(keySessionId, keyId);
     257            3 : }
     258              : 
     259            3 : MediaKeyErrorStatus CdmService::setDrmHeader(int mediaKeysHandle, int32_t keySessionId,
     260              :                                              const std::vector<uint8_t> &requestData)
     261              : {
     262            3 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to set drm header: %d", mediaKeysHandle);
     263              : 
     264            3 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     265            3 :     auto mediaKeysIter = m_mediaKeys.find(mediaKeysHandle);
     266            3 :     if (mediaKeysIter == m_mediaKeys.end())
     267              :     {
     268            1 :         RIALTO_SERVER_LOG_ERROR("Media keys handle: %d does not exists", mediaKeysHandle);
     269            1 :         return MediaKeyErrorStatus::FAIL;
     270              :     }
     271              : 
     272            2 :     return mediaKeysIter->second->setDrmHeader(keySessionId, requestData);
     273            3 : }
     274              : 
     275            3 : MediaKeyErrorStatus CdmService::deleteDrmStore(int mediaKeysHandle)
     276              : {
     277            3 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to delete drm store: %d", mediaKeysHandle);
     278              : 
     279            3 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     280            3 :     auto mediaKeysIter = m_mediaKeys.find(mediaKeysHandle);
     281            3 :     if (mediaKeysIter == m_mediaKeys.end())
     282              :     {
     283            1 :         RIALTO_SERVER_LOG_ERROR("Media keys handle: %d does not exists", mediaKeysHandle);
     284            1 :         return MediaKeyErrorStatus::FAIL;
     285              :     }
     286            2 :     return mediaKeysIter->second->deleteDrmStore();
     287            3 : }
     288              : 
     289            3 : MediaKeyErrorStatus CdmService::deleteKeyStore(int mediaKeysHandle)
     290              : {
     291            3 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to delete key store: %d", mediaKeysHandle);
     292              : 
     293            3 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     294            3 :     auto mediaKeysIter = m_mediaKeys.find(mediaKeysHandle);
     295            3 :     if (mediaKeysIter == m_mediaKeys.end())
     296              :     {
     297            1 :         RIALTO_SERVER_LOG_ERROR("Media keys handle: %d does not exists", mediaKeysHandle);
     298            1 :         return MediaKeyErrorStatus::FAIL;
     299              :     }
     300              : 
     301            2 :     return mediaKeysIter->second->deleteKeyStore();
     302            3 : }
     303              : 
     304            3 : MediaKeyErrorStatus CdmService::getDrmStoreHash(int mediaKeysHandle, std::vector<unsigned char> &drmStoreHash)
     305              : {
     306            3 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to get drm store hash: %d", mediaKeysHandle);
     307              : 
     308            3 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     309            3 :     auto mediaKeysIter = m_mediaKeys.find(mediaKeysHandle);
     310            3 :     if (mediaKeysIter == m_mediaKeys.end())
     311              :     {
     312            1 :         RIALTO_SERVER_LOG_ERROR("Media keys handle: %d does not exists", mediaKeysHandle);
     313            1 :         return MediaKeyErrorStatus::FAIL;
     314              :     }
     315            2 :     return mediaKeysIter->second->getDrmStoreHash(drmStoreHash);
     316            3 : }
     317              : 
     318            3 : MediaKeyErrorStatus CdmService::getKeyStoreHash(int mediaKeysHandle, std::vector<unsigned char> &keyStoreHash)
     319              : {
     320            3 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to get key store hash: %d", mediaKeysHandle);
     321              : 
     322            3 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     323            3 :     auto mediaKeysIter = m_mediaKeys.find(mediaKeysHandle);
     324            3 :     if (mediaKeysIter == m_mediaKeys.end())
     325              :     {
     326            1 :         RIALTO_SERVER_LOG_ERROR("Media keys handle: %d does not exists", mediaKeysHandle);
     327            1 :         return MediaKeyErrorStatus::FAIL;
     328              :     }
     329            2 :     return mediaKeysIter->second->getKeyStoreHash(keyStoreHash);
     330            3 : }
     331              : 
     332            3 : MediaKeyErrorStatus CdmService::getLdlSessionsLimit(int mediaKeysHandle, uint32_t &ldlLimit)
     333              : {
     334            3 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to get ldl sessions limit: %d", mediaKeysHandle);
     335              : 
     336            3 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     337            3 :     auto mediaKeysIter = m_mediaKeys.find(mediaKeysHandle);
     338            3 :     if (mediaKeysIter == m_mediaKeys.end())
     339              :     {
     340            1 :         RIALTO_SERVER_LOG_ERROR("Media keys handle: %d does not exists", mediaKeysHandle);
     341            1 :         return MediaKeyErrorStatus::FAIL;
     342              :     }
     343            2 :     return mediaKeysIter->second->getLdlSessionsLimit(ldlLimit);
     344            3 : }
     345              : 
     346            3 : MediaKeyErrorStatus CdmService::getLastDrmError(int mediaKeysHandle, int32_t keySessionId, uint32_t &errorCode)
     347              : {
     348            3 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to get last drm error: %d", mediaKeysHandle);
     349              : 
     350            3 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     351            3 :     auto mediaKeysIter = m_mediaKeys.find(mediaKeysHandle);
     352            3 :     if (mediaKeysIter == m_mediaKeys.end())
     353              :     {
     354            1 :         RIALTO_SERVER_LOG_ERROR("Media keys handle: %d does not exists", mediaKeysHandle);
     355            1 :         return MediaKeyErrorStatus::FAIL;
     356              :     }
     357            2 :     return mediaKeysIter->second->getLastDrmError(keySessionId, errorCode);
     358            3 : }
     359              : 
     360            3 : MediaKeyErrorStatus CdmService::getDrmTime(int mediaKeysHandle, uint64_t &drmTime)
     361              : {
     362            3 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to get drm time: %d", mediaKeysHandle);
     363              : 
     364            3 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     365            3 :     auto mediaKeysIter = m_mediaKeys.find(mediaKeysHandle);
     366            3 :     if (mediaKeysIter == m_mediaKeys.end())
     367              :     {
     368            1 :         RIALTO_SERVER_LOG_ERROR("Media keys handle: %d does not exists", mediaKeysHandle);
     369            1 :         return MediaKeyErrorStatus::FAIL;
     370              :     }
     371            2 :     return mediaKeysIter->second->getDrmTime(drmTime);
     372            3 : }
     373              : 
     374            3 : MediaKeyErrorStatus CdmService::releaseKeySession(int mediaKeysHandle, int32_t keySessionId)
     375              : {
     376            3 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to release key session: %d", mediaKeysHandle);
     377              : 
     378            3 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     379            3 :     auto mediaKeysIter = m_mediaKeys.find(mediaKeysHandle);
     380            3 :     if (mediaKeysIter == m_mediaKeys.end())
     381              :     {
     382            1 :         RIALTO_SERVER_LOG_ERROR("Media keys handle: %d does not exists", mediaKeysHandle);
     383            1 :         return MediaKeyErrorStatus::FAIL;
     384              :     }
     385            2 :     return mediaKeysIter->second->releaseKeySession(keySessionId);
     386            3 : }
     387              : 
     388            3 : std::vector<std::string> CdmService::getSupportedKeySystems()
     389              : {
     390            3 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to getSupportedKeySystems");
     391              : 
     392            3 :     if (!m_isActive)
     393              :     {
     394            1 :         RIALTO_SERVER_LOG_ERROR("Skip to get supported key systems: Session Server in Inactive state");
     395            1 :         return {};
     396              :     }
     397              : 
     398            2 :     auto mediaKeysCapabilities = m_mediaKeysCapabilitiesFactory->getMediaKeysCapabilities();
     399            2 :     if (!mediaKeysCapabilities)
     400              :     {
     401            1 :         RIALTO_SERVER_LOG_ERROR("Failed to create the mediaKeysCapabilities object");
     402            1 :         return {};
     403              :     }
     404            1 :     return mediaKeysCapabilities->getSupportedKeySystems();
     405            2 : }
     406              : 
     407            3 : bool CdmService::supportsKeySystem(const std::string &keySystem)
     408              : {
     409            3 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to supportsKeySystem");
     410              : 
     411            3 :     if (!m_isActive)
     412              :     {
     413            1 :         RIALTO_SERVER_LOG_ERROR("Skip to get supported key systems: Session Server in Inactive state");
     414            1 :         return false;
     415              :     }
     416              : 
     417            2 :     auto mediaKeysCapabilities = m_mediaKeysCapabilitiesFactory->getMediaKeysCapabilities();
     418            2 :     if (!mediaKeysCapabilities)
     419              :     {
     420            1 :         RIALTO_SERVER_LOG_ERROR("Failed to create the mediaKeysCapabilities object");
     421            1 :         return false;
     422              :     }
     423            1 :     return mediaKeysCapabilities->supportsKeySystem(keySystem);
     424            2 : }
     425              : 
     426            4 : bool CdmService::getSupportedKeySystemVersion(const std::string &keySystem, std::string &version)
     427              : {
     428            4 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to getSupportedKeySystemVersion");
     429              : 
     430            4 :     if (!m_isActive)
     431              :     {
     432            1 :         RIALTO_SERVER_LOG_ERROR("Skip to get supported key systems: Session Server in Inactive state");
     433            1 :         return false;
     434              :     }
     435              : 
     436            3 :     auto mediaKeysCapabilities = m_mediaKeysCapabilitiesFactory->getMediaKeysCapabilities();
     437            3 :     if (!mediaKeysCapabilities)
     438              :     {
     439            1 :         RIALTO_SERVER_LOG_ERROR("Failed to create the mediaKeysCapabilities object");
     440            1 :         return false;
     441              :     }
     442            2 :     return mediaKeysCapabilities->getSupportedKeySystemVersion(keySystem, version);
     443            3 : }
     444              : 
     445            3 : bool CdmService::isServerCertificateSupported(const std::string &keySystem)
     446              : {
     447            3 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to isServerCertificateSupported");
     448              : 
     449            3 :     if (!m_isActive)
     450              :     {
     451            1 :         RIALTO_SERVER_LOG_ERROR("Skip to check if server cert is supported: Session Server in Inactive state");
     452            1 :         return false;
     453              :     }
     454              : 
     455            2 :     auto mediaKeysCapabilities = m_mediaKeysCapabilitiesFactory->getMediaKeysCapabilities();
     456            2 :     if (!mediaKeysCapabilities)
     457              :     {
     458            1 :         RIALTO_SERVER_LOG_ERROR("Failed to create the mediaKeysCapabilities object");
     459            1 :         return false;
     460              :     }
     461            1 :     return mediaKeysCapabilities->isServerCertificateSupported(keySystem);
     462            2 : }
     463              : 
     464            4 : MediaKeyErrorStatus CdmService::decrypt(int32_t keySessionId, GstBuffer *encrypted, GstCaps *caps)
     465              : {
     466            4 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to decrypt, key session id: %d", keySessionId);
     467              : 
     468            4 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     469            4 :     auto mediaKeysIter = std::find_if(m_mediaKeys.begin(), m_mediaKeys.end(),
     470            3 :                                       [&](const auto &iter) { return iter.second->hasSession(keySessionId); });
     471            4 :     if (mediaKeysIter == m_mediaKeys.end())
     472              :     {
     473            2 :         RIALTO_SERVER_LOG_ERROR("Media keys handle for mksId: %d does not exists", keySessionId);
     474            2 :         return MediaKeyErrorStatus::FAIL;
     475              :     }
     476            2 :     return mediaKeysIter->second->decrypt(keySessionId, encrypted, caps);
     477            4 : }
     478              : 
     479            4 : bool CdmService::isNetflixPlayreadyKeySystem(int32_t keySessionId)
     480              : {
     481            4 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to check if key system is Playready, key session id: %d", keySessionId);
     482              : 
     483            4 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     484            4 :     auto mediaKeysIter = std::find_if(m_mediaKeys.begin(), m_mediaKeys.end(),
     485            3 :                                       [&](const auto &iter) { return iter.second->hasSession(keySessionId); });
     486            4 :     if (mediaKeysIter == m_mediaKeys.end())
     487              :     {
     488            2 :         RIALTO_SERVER_LOG_ERROR("Media keys handle for mksId: %d does not exists", keySessionId);
     489            2 :         return false;
     490              :     }
     491            2 :     return mediaKeysIter->second->isNetflixPlayreadyKeySystem(keySessionId);
     492            4 : }
     493              : 
     494            4 : MediaKeyErrorStatus CdmService::selectKeyId(int32_t keySessionId, const std::vector<uint8_t> &keyId)
     495              : {
     496            4 :     RIALTO_SERVER_LOG_DEBUG("CdmService requested to select key id, key session id: %d", keySessionId);
     497              : 
     498            4 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     499            4 :     auto mediaKeysIter = std::find_if(m_mediaKeys.begin(), m_mediaKeys.end(),
     500            3 :                                       [&](const auto &iter) { return iter.second->hasSession(keySessionId); });
     501            4 :     if (mediaKeysIter == m_mediaKeys.end())
     502              :     {
     503            2 :         RIALTO_SERVER_LOG_ERROR("Media keys handle for mksId: %d does not exists", keySessionId);
     504            2 :         return MediaKeyErrorStatus::FAIL;
     505              :     }
     506            2 :     return mediaKeysIter->second->selectKeyId(keySessionId, keyId);
     507            4 : }
     508              : 
     509            2 : void CdmService::incrementSessionIdUsageCounter(int32_t keySessionId)
     510              : {
     511            2 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     512            2 :     auto mediaKeysIter = std::find_if(m_mediaKeys.begin(), m_mediaKeys.end(),
     513            2 :                                       [&](const auto &iter) { return iter.second->hasSession(keySessionId); });
     514            2 :     if (mediaKeysIter == m_mediaKeys.end())
     515              :     {
     516            1 :         RIALTO_SERVER_LOG_ERROR("Media keys handle for mksId: %d does not exists", keySessionId);
     517            1 :         return;
     518              :     }
     519              : 
     520            1 :     mediaKeysIter->second->incrementSessionIdUsageCounter(keySessionId);
     521            2 : }
     522              : 
     523            2 : void CdmService::decrementSessionIdUsageCounter(int32_t keySessionId)
     524              : {
     525            2 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     526            2 :     auto mediaKeysIter = std::find_if(m_mediaKeys.begin(), m_mediaKeys.end(),
     527            2 :                                       [&](const auto &iter) { return iter.second->hasSession(keySessionId); });
     528            2 :     if (mediaKeysIter == m_mediaKeys.end())
     529              :     {
     530            1 :         RIALTO_SERVER_LOG_ERROR("Media keys handle for mksId: %d does not exists", keySessionId);
     531            1 :         return;
     532              :     }
     533              : 
     534            1 :     mediaKeysIter->second->decrementSessionIdUsageCounter(keySessionId);
     535            2 : }
     536              : 
     537            1 : void CdmService::ping(const std::shared_ptr<IHeartbeatProcedure> &heartbeatProcedure)
     538              : {
     539            1 :     std::lock_guard<std::mutex> lock{m_mediaKeysMutex};
     540            2 :     for (const auto &mediaKeyPair : m_mediaKeys)
     541              :     {
     542            1 :         auto &mediaKeys = mediaKeyPair.second;
     543            1 :         mediaKeys->ping(heartbeatProcedure->createHandler());
     544              :     }
     545              : }
     546              : } // namespace firebolt::rialto::server::service
        

Generated by: LCOV version 2.0-1