LCOV - code coverage report
Current view: top level - media/server/gstplayer/source/tasks/generic - Flush.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 42 42
Test Date: 2025-10-07 14:22:52 Functions: 100.0 % 3 3

            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 "tasks/generic/Flush.h"
      21              : #include "RialtoServerLogging.h"
      22              : #include "TypeConverters.h"
      23              : 
      24              : namespace firebolt::rialto::server::tasks::generic
      25              : {
      26            7 : Flush::Flush(GenericPlayerContext &context, IGstGenericPlayerPrivate &player, IGstGenericPlayerClient *client,
      27              :              std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> gstWrapper, const MediaSourceType &type,
      28            7 :              bool resetTime)
      29           14 :     : m_context{context}, m_player{player}, m_gstPlayerClient{client}, m_gstWrapper{gstWrapper}, m_type{type},
      30            7 :       m_resetTime{resetTime}
      31              : {
      32            7 :     RIALTO_SERVER_LOG_DEBUG("Constructing Flush");
      33              : }
      34              : 
      35            8 : Flush::~Flush()
      36              : {
      37            7 :     RIALTO_SERVER_LOG_DEBUG("Flush finished");
      38            8 : }
      39              : 
      40            6 : void Flush::execute() const
      41              : {
      42            6 :     RIALTO_SERVER_LOG_DEBUG("Executing Flush for %s source", common::convertMediaSourceType(m_type));
      43              : 
      44              :     // Get source first
      45            6 :     GstElement *source{nullptr};
      46            6 :     auto sourceElem = m_context.streamInfo.find(m_type);
      47            6 :     if (sourceElem != m_context.streamInfo.end())
      48              :     {
      49            5 :         source = sourceElem->second.appSrc;
      50              :     }
      51            6 :     if (!source)
      52              :     {
      53            1 :         RIALTO_SERVER_LOG_WARN("failed to flush %s - source is NULL", common::convertMediaSourceType(m_type));
      54            2 :         return;
      55              :     }
      56              : 
      57            5 :     if (m_type == MediaSourceType::UNKNOWN)
      58              :     {
      59            1 :         RIALTO_SERVER_LOG_WARN("Flush failed: Media source type not supported.");
      60            1 :         return;
      61              :     }
      62              : 
      63            4 :     StreamInfo &streamInfo = sourceElem->second;
      64            4 :     streamInfo.isDataNeeded = false;
      65            4 :     streamInfo.isNeedDataPending = false;
      66            4 :     m_player.clearNeedDataScheduled(GST_APP_SRC(source));
      67              : 
      68            8 :     for (auto &buffer : streamInfo.buffers)
      69              :     {
      70            4 :         m_gstWrapper->gstBufferUnref(buffer);
      71              :     }
      72            4 :     streamInfo.buffers.clear();
      73              : 
      74            4 :     m_gstPlayerClient->invalidateActiveRequests(m_type);
      75              : 
      76            4 :     if (GST_STATE(m_context.pipeline) >= GST_STATE_PAUSED)
      77              :     {
      78            3 :         m_player.stopPositionReportingAndCheckAudioUnderflowTimer();
      79              :         // Flush source
      80            3 :         GstEvent *flushStart = m_gstWrapper->gstEventNewFlushStart();
      81            3 :         if (!m_gstWrapper->gstElementSendEvent(source, flushStart))
      82              :         {
      83            1 :             RIALTO_SERVER_LOG_WARN("failed to send flush-start event for %s", common::convertMediaSourceType(m_type));
      84              :         }
      85              : 
      86            3 :         GstEvent *flushStop = m_gstWrapper->gstEventNewFlushStop(m_resetTime);
      87            3 :         if (!m_gstWrapper->gstElementSendEvent(source, flushStop))
      88              :         {
      89            1 :             RIALTO_SERVER_LOG_WARN("failed to send flush-stop event for %s", common::convertMediaSourceType(m_type));
      90              :         }
      91              :     }
      92              :     else
      93              :     {
      94            1 :         RIALTO_SERVER_LOG_DEBUG("Skip sending flush event for %s - pipeline below paused",
      95              :                                 common::convertMediaSourceType(m_type));
      96              :     }
      97              : 
      98              :     // Reset Eos info
      99            4 :     m_context.endOfStreamInfo.erase(m_type);
     100            4 :     m_context.eosNotified = false;
     101              : 
     102              :     // Notify client, that flush has been finished
     103            4 :     m_gstPlayerClient->notifySourceFlushed(m_type);
     104              : 
     105              :     // Notify GstGenericPlayer, that flush has been finished
     106            4 :     m_player.setSourceFlushed(m_type);
     107              : 
     108            4 :     RIALTO_SERVER_LOG_MIL("%s source flushed.", common::convertMediaSourceType(m_type));
     109              : }
     110              : } // namespace firebolt::rialto::server::tasks::generic
        

Generated by: LCOV version 2.0-1