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

Generated by: LCOV version 2.0-1