LCOV - code coverage report
Current view: top level - media/server/main/source - TextTrackAccessor.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 86.6 % 134 116
Test Date: 2025-09-15 11:52:04 Functions: 81.2 % 16 13

            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 2024 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 "TextTrackAccessor.h"
      21              : 
      22              : #include <cinttypes>
      23              : #include <stdexcept>
      24              : #include <string>
      25              : 
      26              : namespace firebolt::rialto::server
      27              : {
      28            0 : ITextTrackAccessorFactory &ITextTrackAccessorFactory::getFactory()
      29              : {
      30            0 :     static TextTrackAccessorFactory factory;
      31            0 :     return factory;
      32              : }
      33              : 
      34            0 : std::shared_ptr<ITextTrackAccessor> TextTrackAccessorFactory::getTextTrackAccessor() const
      35              : try
      36              : {
      37              :     static std::shared_ptr<TextTrackAccessor> textTrackAccessor{
      38            0 :         std::make_shared<TextTrackAccessor>(firebolt::rialto::wrappers::ITextTrackPluginWrapperFactory::getFactory()
      39            0 :                                                 ->getTextTrackPluginWrapper(),
      40            0 :                                             firebolt::rialto::wrappers::IThunderWrapperFactory::getFactory()
      41            0 :                                                 ->getThunderWrapper())};
      42              : 
      43            0 :     return textTrackAccessor;
      44              : }
      45            0 : catch (const std::exception &e)
      46              : {
      47            0 :     return nullptr;
      48              : }
      49              : 
      50           32 : TextTrackAccessor::TextTrackAccessor(
      51              :     const std::shared_ptr<firebolt::rialto::wrappers::ITextTrackPluginWrapper> &textTrackPluginWrapper,
      52           32 :     const std::shared_ptr<firebolt::rialto::wrappers::IThunderWrapper> &thunderWrapper)
      53           32 :     : m_textTrackPluginWrapper{textTrackPluginWrapper}, m_thunderWrapper{thunderWrapper}
      54              : {
      55           32 :     if (!createTextTrackControlInterface())
      56              :     {
      57            4 :         RIALTO_SERVER_LOG_ERROR("Failed to create TextTrack interfaces");
      58            4 :         throw std::runtime_error("Failed to create TextTrack interfaces");
      59              :     }
      60           44 : }
      61              : 
      62              : TextTrackAccessor::~TextTrackAccessor() {}
      63              : 
      64            2 : std::optional<uint32_t> TextTrackAccessor::openSession(const std::string &displayName)
      65              : {
      66            2 :     uint32_t sessionId = {};
      67            2 :     uint32_t result = m_textTrackWrapper->openSession(displayName, sessionId);
      68            2 :     if (m_thunderWrapper->isSuccessful(result))
      69              :     {
      70            1 :         RIALTO_SERVER_LOG_MIL("TextTrack session %u created with display '%s'", sessionId, displayName.c_str());
      71            1 :         return sessionId;
      72              :     }
      73              : 
      74            1 :     RIALTO_SERVER_LOG_ERROR("Failed to create TextTrack session with display '%s'; error '%s'", displayName.c_str(),
      75              :                             m_thunderWrapper->errorToString(result));
      76            1 :     return std::nullopt;
      77              : }
      78              : 
      79            2 : bool TextTrackAccessor::closeSession(uint32_t sessionId)
      80              : {
      81            2 :     uint32_t result = m_textTrackWrapper->closeSession(sessionId);
      82            2 :     if (m_thunderWrapper->isSuccessful(result))
      83              :     {
      84            1 :         RIALTO_SERVER_LOG_MIL("TextTrack session %u closed", sessionId);
      85            1 :         return true;
      86              :     }
      87              : 
      88            1 :     RIALTO_SERVER_LOG_ERROR("Failed to close TextTrack session %u; error %s", sessionId,
      89              :                             m_thunderWrapper->errorToString(result));
      90            1 :     return false;
      91              : }
      92              : 
      93            2 : bool TextTrackAccessor::pause(uint32_t sessionId)
      94              : {
      95            2 :     uint32_t result = m_textTrackWrapper->pauseSession(sessionId);
      96            2 :     if (m_thunderWrapper->isSuccessful(result))
      97              :     {
      98            1 :         RIALTO_SERVER_LOG_INFO("TextTrack session %u paused", sessionId);
      99            1 :         return true;
     100              :     }
     101              : 
     102            1 :     RIALTO_SERVER_LOG_ERROR("Failed to pause TextTrack session %u; error %s", sessionId,
     103              :                             m_thunderWrapper->errorToString(result));
     104            1 :     return false;
     105              : }
     106              : 
     107            2 : bool TextTrackAccessor::play(uint32_t sessionId)
     108              : {
     109            2 :     uint32_t result = m_textTrackWrapper->resumeSession(sessionId);
     110            2 :     if (m_thunderWrapper->isSuccessful(result))
     111              :     {
     112            1 :         RIALTO_SERVER_LOG_INFO("TextTrack session %u resumed", sessionId);
     113            1 :         return true;
     114              :     }
     115              : 
     116            1 :     RIALTO_SERVER_LOG_ERROR("Failed to resume TextTrack session %u; error %s", sessionId,
     117              :                             m_thunderWrapper->errorToString(result));
     118            1 :     return false;
     119              : }
     120              : 
     121            4 : bool TextTrackAccessor::mute(uint32_t sessionId, bool mute)
     122              : {
     123            4 :     if (mute)
     124              :     {
     125            2 :         uint32_t result = m_textTrackWrapper->muteSession(sessionId);
     126            2 :         if (m_thunderWrapper->isSuccessful(result))
     127              :         {
     128            1 :             RIALTO_SERVER_LOG_INFO("TextTrack session %u muted", sessionId);
     129            1 :             return true;
     130              :         }
     131              : 
     132            1 :         RIALTO_SERVER_LOG_ERROR("Failed to mute TextTrack session %u; error %s", sessionId,
     133              :                                 m_thunderWrapper->errorToString(result));
     134              :     }
     135              :     else
     136              :     {
     137            2 :         uint32_t result = m_textTrackWrapper->unmuteSession(sessionId);
     138            2 :         if (m_thunderWrapper->isSuccessful(result))
     139              :         {
     140            1 :             RIALTO_SERVER_LOG_INFO("TextTrack session %u unmuted", sessionId);
     141            1 :             return true;
     142              :         }
     143              : 
     144            1 :         RIALTO_SERVER_LOG_ERROR("Failed to unmute TextTrack session %u; error %s", sessionId,
     145              :                                 m_thunderWrapper->errorToString(result));
     146              :     }
     147              : 
     148            2 :     return false;
     149              : }
     150              : 
     151            2 : bool TextTrackAccessor::setPosition(uint32_t sessionId, uint64_t mediaTimestampMs)
     152              : {
     153            2 :     uint32_t result = m_textTrackWrapper->sendSessionTimestamp(sessionId, mediaTimestampMs);
     154            2 :     if (m_thunderWrapper->isSuccessful(result))
     155              :     {
     156            1 :         RIALTO_SERVER_LOG_INFO("TextTrack session %u set position to %" PRIu64, sessionId, mediaTimestampMs);
     157            1 :         return true;
     158              :     }
     159              : 
     160            1 :     RIALTO_SERVER_LOG_ERROR("Failed to set position of TextTrack session %u to  %" PRIu64 "; error %s", sessionId,
     161              :                             mediaTimestampMs, m_thunderWrapper->errorToString(result));
     162            1 :     return false;
     163              : }
     164              : 
     165            5 : bool TextTrackAccessor::sendData(uint32_t sessionId, const std::string &data, DataType datatype, int64_t displayOffsetMs)
     166              : {
     167            5 :     firebolt::rialto::wrappers::ITextTrackWrapper::DataType wrapperDataType{};
     168            5 :     if (datatype == DataType::WebVTT)
     169              :     {
     170            1 :         wrapperDataType = firebolt::rialto::wrappers::ITextTrackWrapper::DataType::WEBVTT;
     171              :     }
     172            4 :     else if (datatype == DataType::TTML)
     173              :     {
     174            2 :         wrapperDataType = firebolt::rialto::wrappers::ITextTrackWrapper::DataType::TTML;
     175              :     }
     176            2 :     else if (datatype == DataType::CC)
     177              :     {
     178            1 :         RIALTO_SERVER_LOG_WARN("Data received for ClosedCaptions. It should not happen.");
     179            1 :         return false;
     180              :     }
     181              :     else
     182              :     {
     183            1 :         RIALTO_SERVER_LOG_ERROR("Unknown data type");
     184            1 :         return false;
     185              :     }
     186              : 
     187            3 :     const uint32_t result = m_textTrackWrapper->sendSessionData(sessionId, wrapperDataType, displayOffsetMs, data);
     188            3 :     if (m_thunderWrapper->isSuccessful(result))
     189              :     {
     190            2 :         RIALTO_SERVER_LOG_DEBUG("Sending data to TextTrack session %u was successful; size %zu", sessionId, data.size());
     191            2 :         return true;
     192              :     }
     193              : 
     194            1 :     RIALTO_SERVER_LOG_ERROR("Failed to send data to TextTrack session %u; error %s", sessionId,
     195              :                             m_thunderWrapper->errorToString(result));
     196            1 :     return false;
     197              : }
     198              : 
     199           32 : bool TextTrackAccessor::createTextTrackControlInterface()
     200              : {
     201           32 :     if (!m_textTrackPluginWrapper)
     202              :     {
     203            1 :         RIALTO_SERVER_LOG_ERROR("TextTrackPlugin is null!");
     204            1 :         return false;
     205              :     }
     206              : 
     207           31 :     uint32_t openResult = m_textTrackPluginWrapper->open();
     208              : 
     209           31 :     if (m_thunderWrapper->isSuccessful(openResult))
     210              :     {
     211           30 :         if (m_textTrackPluginWrapper->isOperational())
     212              :         {
     213           29 :             m_textTrackWrapper = m_textTrackPluginWrapper->interface();
     214           29 :             if (m_textTrackWrapper)
     215              :             {
     216           28 :                 RIALTO_SERVER_LOG_INFO("Created TextTrack interface");
     217           28 :                 return true;
     218              :             }
     219              :             else
     220              :             {
     221            1 :                 RIALTO_SERVER_LOG_ERROR("Failed to create TextTrack interface");
     222              :             }
     223              :         }
     224              :         else
     225              :         {
     226            1 :             RIALTO_SERVER_LOG_ERROR("TextTrack plugin is NOT operational");
     227              :         }
     228              :     }
     229              :     else
     230              :     {
     231            1 :         RIALTO_SERVER_LOG_ERROR("Failed to open TextTrack plugin; error '%s'",
     232              :                                 m_thunderWrapper->errorToString(openResult));
     233              :     }
     234              : 
     235            3 :     return false;
     236              : }
     237              : 
     238            2 : bool TextTrackAccessor::setSessionWebVTTSelection(uint32_t sessionId)
     239              : {
     240            2 :     uint32_t result = m_textTrackWrapper->setSessionWebVTTSelection(sessionId);
     241              : 
     242            2 :     if (m_thunderWrapper->isSuccessful(result))
     243              :     {
     244            1 :         RIALTO_SERVER_LOG_INFO("Setting WebVTT selection for session %u was successful", sessionId);
     245            1 :         return true;
     246              :     }
     247              : 
     248            1 :     RIALTO_SERVER_LOG_ERROR("Failed to set WebVTT selection for session %u; error %s", sessionId,
     249              :                             m_thunderWrapper->errorToString(result));
     250            1 :     return false;
     251              : }
     252              : 
     253            2 : bool TextTrackAccessor::setSessionTTMLSelection(uint32_t sessionId)
     254              : {
     255            2 :     uint32_t result = m_textTrackWrapper->setSessionTTMLSelection(sessionId);
     256            2 :     if (m_thunderWrapper->isSuccessful(result))
     257              :     {
     258            1 :         RIALTO_SERVER_LOG_INFO("Setting TTML selection for session %u was successful", sessionId);
     259            1 :         return true;
     260              :     }
     261              : 
     262            1 :     RIALTO_SERVER_LOG_ERROR("Failed to set TTML selection for session %u; error %s", sessionId,
     263              :                             m_thunderWrapper->errorToString(result));
     264            1 :     return false;
     265              : }
     266              : 
     267            2 : bool TextTrackAccessor::setSessionCCSelection(uint32_t sessionId, const std::string &service)
     268              : {
     269            2 :     uint32_t result = m_textTrackWrapper->setSessionClosedCaptionsService(sessionId, service);
     270            2 :     if (m_thunderWrapper->isSuccessful(result))
     271              :     {
     272            1 :         RIALTO_SERVER_LOG_INFO("Setting CC selection service '%s' for session %u was successful", service.c_str(),
     273              :                                sessionId);
     274            1 :         return true;
     275              :     }
     276              : 
     277            1 :     RIALTO_SERVER_LOG_ERROR("Failed to set CC selection service '%s' for session %u; error %s", service.c_str(),
     278              :                             sessionId, m_thunderWrapper->errorToString(result));
     279            1 :     return false;
     280              : }
     281              : 
     282            0 : bool TextTrackAccessor::resetSession(uint32_t sessionId)
     283              : {
     284            0 :     uint32_t result = m_textTrackWrapper->resetSession(sessionId);
     285            0 :     if (m_thunderWrapper->isSuccessful(result))
     286              :     {
     287            0 :         RIALTO_SERVER_LOG_MIL("Resseting session %u was successful", sessionId);
     288            0 :         return true;
     289              :     }
     290              : 
     291            0 :     RIALTO_SERVER_LOG_ERROR("Failed to reset session %u; error %s", sessionId, m_thunderWrapper->errorToString(result));
     292            0 :     return false;
     293              : }
     294              : 
     295            2 : bool TextTrackAccessor::associateVideoDecoder(uint32_t sessionId, const std::string &videoDecoder)
     296              : {
     297            2 :     uint32_t result = m_textTrackWrapper->associateVideoDecoder(sessionId, videoDecoder);
     298            2 :     if (m_thunderWrapper->isSuccessful(result))
     299              :     {
     300            1 :         RIALTO_SERVER_LOG_MIL("Associating video decoder '%s' with session %u was successful", videoDecoder.c_str(),
     301              :                               sessionId);
     302            1 :         return true;
     303              :     }
     304              : 
     305            1 :     RIALTO_SERVER_LOG_ERROR("Failed to associate video decoder '%s' with session %u; error %s", videoDecoder.c_str(),
     306              :                             sessionId, m_thunderWrapper->errorToString(result));
     307            1 :     return false;
     308              : }
     309              : 
     310              : } // namespace firebolt::rialto::server
        

Generated by: LCOV version 2.0-1