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 % 39 39
Test Date: 2025-02-18 13:13:53 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              : 
      67            8 :     for (auto &buffer : streamInfo.buffers)
      68              :     {
      69            4 :         m_gstWrapper->gstBufferUnref(buffer);
      70              :     }
      71            4 :     streamInfo.buffers.clear();
      72              : 
      73            4 :     m_gstPlayerClient->invalidateActiveRequests(m_type);
      74              : 
      75            4 :     if (GST_STATE(m_context.pipeline) >= GST_STATE_PAUSED)
      76              :     {
      77            3 :         m_player.stopPositionReportingAndCheckAudioUnderflowTimer();
      78              :         // Flush source
      79            3 :         GstEvent *flushStart = m_gstWrapper->gstEventNewFlushStart();
      80            3 :         if (!m_gstWrapper->gstElementSendEvent(source, flushStart))
      81              :         {
      82            1 :             RIALTO_SERVER_LOG_WARN("failed to send flush-start event for %s", common::convertMediaSourceType(m_type));
      83              :         }
      84              : 
      85            3 :         GstEvent *flushStop = m_gstWrapper->gstEventNewFlushStop(m_resetTime);
      86            3 :         if (!m_gstWrapper->gstElementSendEvent(source, flushStop))
      87              :         {
      88            1 :             RIALTO_SERVER_LOG_WARN("failed to send flush-stop event for %s", common::convertMediaSourceType(m_type));
      89              :         }
      90              :     }
      91              :     else
      92              :     {
      93            1 :         RIALTO_SERVER_LOG_DEBUG("Skip sending flush event for %s - pipeline below paused",
      94              :                                 common::convertMediaSourceType(m_type));
      95              :     }
      96              : 
      97              :     // Reset Eos info
      98            4 :     m_context.endOfStreamInfo.erase(m_type);
      99            4 :     m_context.eosNotified = false;
     100              : 
     101              :     // Notify client, that flush has been finished
     102            4 :     m_gstPlayerClient->notifySourceFlushed(m_type);
     103              : }
     104              : } // namespace firebolt::rialto::server::tasks::generic
        

Generated by: LCOV version 2.0-1