LCOV - code coverage report
Current view: top level - media/server/main/source - TextTrackSession.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 67.3 % 55 37
Test Date: 2025-02-18 13:13:53 Functions: 76.9 % 13 10

            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 "TextTrackSession.h"
      21              : #include "ITextTrackAccessor.h"
      22              : #include "RialtoServerLogging.h"
      23              : #include <stdexcept>
      24              : 
      25              : namespace firebolt::rialto::server
      26              : {
      27            0 : ITextTrackSessionFactory &ITextTrackSessionFactory::getFactory()
      28              : {
      29            0 :     static TextTrackSessionFactory factory;
      30            0 :     return factory;
      31              : }
      32              : 
      33            0 : std::unique_ptr<ITextTrackSession> TextTrackSessionFactory::createTextTrackSession(const std::string &display) const
      34              : {
      35            0 :     return std::make_unique<TextTrackSession>(display, ITextTrackAccessorFactory::getFactory());
      36              : }
      37              : 
      38           10 : TextTrackSession::TextTrackSession(const std::string &displayName,
      39           10 :                                    const ITextTrackAccessorFactory &textTrackAccessorFactory)
      40              : {
      41           10 :     m_textTrackAccessor = textTrackAccessorFactory.getTextTrackAccessor();
      42           10 :     if (!m_textTrackAccessor)
      43              :     {
      44            1 :         RIALTO_SERVER_LOG_ERROR("Failed to get TextTrackAccessor");
      45            1 :         throw std::runtime_error("Failed to get TextTrackAccessor");
      46              :     }
      47              : 
      48            9 :     std::optional<uint32_t> sessionId = m_textTrackAccessor->openSession(displayName);
      49            9 :     if (!sessionId)
      50              :     {
      51            1 :         RIALTO_SERVER_LOG_ERROR("Failed to create TextTrack session");
      52            1 :         throw std::runtime_error("Failed to create TextTrack session");
      53              :     }
      54              : 
      55            8 :     m_sessionId = sessionId.value();
      56           14 : }
      57              : 
      58           16 : TextTrackSession::~TextTrackSession()
      59              : {
      60            8 :     m_textTrackAccessor->closeSession(m_sessionId);
      61           16 : }
      62              : 
      63            0 : bool TextTrackSession::resetSession()
      64              : {
      65            0 :     if (!m_textTrackAccessor->resetSession(m_sessionId))
      66              :     {
      67            0 :         return false;
      68              :     }
      69              : 
      70            0 :     if (m_dataType == ITextTrackAccessor::DataType::WebVTT)
      71              :     {
      72            0 :         return setSessionWebVTTSelection();
      73              :     }
      74            0 :     else if (m_dataType == ITextTrackAccessor::DataType::TTML)
      75              :     {
      76            0 :         return setSessionTTMLSelection();
      77              :     }
      78            0 :     else if (m_dataType == ITextTrackAccessor::DataType::CC)
      79              :     {
      80            0 :         if (m_ccService.has_value())
      81              :         {
      82            0 :             return setSessionCCSelection(m_ccService.value());
      83              :         }
      84              :         else
      85              :         {
      86            0 :             RIALTO_SERVER_LOG_ERROR("CC service not set");
      87            0 :             return false;
      88              :         }
      89              :     }
      90              : 
      91            0 :     return true;
      92              : }
      93              : 
      94            1 : bool TextTrackSession::pause()
      95              : {
      96            1 :     return m_textTrackAccessor->pause(m_sessionId);
      97              : }
      98              : 
      99            1 : bool TextTrackSession::play()
     100              : {
     101            1 :     return m_textTrackAccessor->play(m_sessionId);
     102              : }
     103              : 
     104            1 : bool TextTrackSession::mute(bool mute)
     105              : {
     106            1 :     return m_textTrackAccessor->mute(m_sessionId, mute);
     107              : }
     108              : 
     109            1 : bool TextTrackSession::setPosition(uint64_t mediaTimestampMs)
     110              : {
     111            1 :     return m_textTrackAccessor->setPosition(m_sessionId, mediaTimestampMs);
     112              : }
     113              : 
     114            2 : bool TextTrackSession::sendData(const std::string &data, int32_t displayOffsetMs)
     115              : {
     116            2 :     return m_textTrackAccessor->sendData(m_sessionId, data, m_dataType, displayOffsetMs);
     117              : }
     118              : 
     119            1 : bool TextTrackSession::setSessionWebVTTSelection()
     120              : {
     121            1 :     m_dataType = ITextTrackAccessor::DataType::WebVTT;
     122            1 :     m_ccService = std::optional<std::string>();
     123            1 :     return m_textTrackAccessor->setSessionWebVTTSelection(m_sessionId);
     124              : }
     125              : 
     126            1 : bool TextTrackSession::setSessionTTMLSelection()
     127              : {
     128            1 :     m_dataType = ITextTrackAccessor::DataType::TTML;
     129            1 :     m_ccService = std::optional<std::string>();
     130            1 :     return m_textTrackAccessor->setSessionTTMLSelection(m_sessionId);
     131              : }
     132              : 
     133            1 : bool TextTrackSession::setSessionCCSelection(const std::string &service)
     134              : {
     135            1 :     m_dataType = ITextTrackAccessor::DataType::CC;
     136            1 :     m_ccService = service;
     137            1 :     return m_textTrackAccessor->setSessionCCSelection(m_sessionId, service);
     138              : }
     139              : } // namespace firebolt::rialto::server
        

Generated by: LCOV version 2.0-1