LCOV - code coverage report
Current view: top level - media/server/gstplayer/source/tasks/generic - SetSourcePosition.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 93.5 % 31 29
Test Date: 2025-10-29 12:43:33 Functions: 100.0 % 4 4

            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 "SetSourcePosition.h"
      21              : #include "RialtoServerLogging.h"
      22              : #include "TypeConverters.h"
      23              : 
      24              : namespace firebolt::rialto::server::tasks::generic
      25              : {
      26            6 : SetSourcePosition::SetSourcePosition(GenericPlayerContext &context,
      27              :                                      const std::shared_ptr<wrappers::IGlibWrapper> &glibWrapper,
      28              :                                      const MediaSourceType &type, std::int64_t position, bool resetTime,
      29            6 :                                      double appliedRate, uint64_t stopPosition)
      30           12 :     : m_context{context}, m_glibWrapper{glibWrapper}, m_type{type}, m_position{position}, m_resetTime{resetTime},
      31            6 :       m_appliedRate{appliedRate}, m_stopPosition{stopPosition}
      32              : {
      33            6 :     RIALTO_SERVER_LOG_DEBUG("Constructing SetSourcePosition");
      34              : }
      35              : 
      36            7 : SetSourcePosition::~SetSourcePosition()
      37              : {
      38            6 :     RIALTO_SERVER_LOG_DEBUG("SetSourcePosition finished");
      39            7 : }
      40              : 
      41            5 : void SetSourcePosition::execute() const
      42              : {
      43            5 :     RIALTO_SERVER_LOG_DEBUG("Executing SetSourcePosition for %s source", common::convertMediaSourceType(m_type));
      44              : 
      45            5 :     if (MediaSourceType::UNKNOWN == m_type)
      46              :     {
      47            1 :         RIALTO_SERVER_LOG_WARN("failed to set source position - source type is unknown");
      48            2 :         return;
      49              :     }
      50              : 
      51              :     // Get source first
      52            4 :     GstElement *source{nullptr};
      53            4 :     auto sourceElem = m_context.streamInfo.find(m_type);
      54            4 :     if (sourceElem != m_context.streamInfo.end())
      55              :     {
      56            3 :         source = sourceElem->second.appSrc;
      57              :     }
      58            4 :     if (!source)
      59              :     {
      60            1 :         RIALTO_SERVER_LOG_WARN("failed to set source position - %s source is NULL",
      61              :                                common::convertMediaSourceType(m_type));
      62            1 :         return;
      63              :     }
      64              : 
      65            3 :     if (MediaSourceType::VIDEO == m_type || MediaSourceType::AUDIO == m_type)
      66              :     {
      67            2 :         m_context.initialPositions[source].emplace_back(
      68            2 :             SegmentData{m_position, m_resetTime, m_appliedRate, m_stopPosition});
      69              :     }
      70            1 :     else if (MediaSourceType::SUBTITLE == m_type)
      71              :     {
      72            1 :         setSubtitlePosition(source);
      73              :     }
      74              : }
      75              : 
      76            1 : void SetSourcePosition::setSubtitlePosition(GstElement *source) const
      77              : {
      78              :     // in case of subtitles, all data might be already in the sink and we might not get any data anymore,
      79              :     // so set position here and to not depend on any following buffers
      80            1 :     if (m_context.setupSourceFinished)
      81              :     {
      82            1 :         m_glibWrapper->gObjectSet(m_context.subtitleSink, "position", static_cast<guint64>(m_position), nullptr);
      83              :     }
      84              :     else
      85              :     {
      86            0 :         m_context.initialPositions[source].emplace_back(
      87            0 :             SegmentData{m_position, m_resetTime, m_appliedRate, m_stopPosition});
      88              :     }
      89            1 : }
      90              : 
      91              : } // namespace firebolt::rialto::server::tasks::generic
        

Generated by: LCOV version 2.0-1