LCOV - code coverage report
Current view: top level - media/server/gstplayer/source/tasks/generic - DeepElementAdded.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 50 50
Test Date: 2026-05-14 05:59:51 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 2023 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/DeepElementAdded.h"
      21              : #include "RialtoServerLogging.h"
      22              : #include "Utils.h"
      23              : 
      24              : namespace
      25              : {
      26            1 : void onHaveType(GstElement *typefind, guint probability, const GstCaps *caps, gpointer data)
      27              : {
      28            1 :     firebolt::rialto::server::IGstGenericPlayerPrivate *player =
      29              :         static_cast<firebolt::rialto::server::IGstGenericPlayerPrivate *>(data);
      30            1 :     player->updatePlaybackGroup(typefind, caps);
      31              : }
      32              : } // namespace
      33              : 
      34              : namespace firebolt::rialto::server::tasks::generic
      35              : {
      36           14 : DeepElementAdded::DeepElementAdded(GenericPlayerContext &context, IGstGenericPlayerPrivate &player,
      37              :                                    const std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> &gstWrapper,
      38              :                                    const std::shared_ptr<firebolt::rialto::wrappers::IGlibWrapper> &glibWrapper,
      39           14 :                                    GstBin *pipeline, GstBin *bin, GstElement *element)
      40           14 :     : m_context{context}, m_player{player}, m_gstWrapper{gstWrapper}, m_glibWrapper{glibWrapper}, m_pipeline{pipeline},
      41           14 :       m_bin{bin}, m_element{element}, m_elementName{nullptr}, m_callbackRegistered{false}
      42              : {
      43           14 :     RIALTO_SERVER_LOG_DEBUG("Constructing DeepElementAdded");
      44              :     // Signal connection has to happen immediately (we cannot wait for thread switch)
      45           14 :     if (m_gstWrapper->gstObjectParent(m_element) == m_gstWrapper->gstObjectCast(m_bin))
      46              :     {
      47           12 :         m_elementName = m_gstWrapper->gstElementGetName(m_element);
      48           12 :         if (m_elementName)
      49              :         {
      50           10 :             RIALTO_SERVER_LOG_DEBUG("Element Name = %s", m_elementName);
      51           10 :             if (m_glibWrapper->gStrrstr(m_elementName, "typefind"))
      52              :             {
      53            3 :                 RIALTO_SERVER_LOG_DEBUG("Registering onHaveType callback");
      54            3 :                 m_glibWrapper->gSignalConnect(G_OBJECT(m_element), "have-type", G_CALLBACK(onHaveType), &m_player);
      55            3 :                 m_callbackRegistered = true;
      56              :             }
      57              : 
      58           10 :             m_context.gstProfiler->scheduleGstElementRecord(m_element);
      59              :         }
      60              :     }
      61           14 : }
      62              : 
      63           15 : DeepElementAdded::~DeepElementAdded()
      64              : {
      65           14 :     RIALTO_SERVER_LOG_DEBUG("DeepElementAdded finished");
      66           14 :     m_glibWrapper->gFree(m_elementName);
      67           15 : }
      68              : 
      69            8 : void DeepElementAdded::execute() const
      70              : {
      71            8 :     RIALTO_SERVER_LOG_DEBUG("Executing DeepElementAdded");
      72            8 :     m_context.playbackGroup.m_gstPipeline = GST_ELEMENT(m_pipeline);
      73              : 
      74            8 :     RIALTO_SERVER_LOG_DEBUG("Element = %p Bin = %p Pipeline = %p", m_element, m_bin, m_pipeline);
      75            8 :     if (m_elementName)
      76              :     {
      77            7 :         if (m_gstWrapper->gstObjectCast(m_bin) == m_gstWrapper->gstObjectCast(m_context.playbackGroup.m_curAudioDecodeBin))
      78              :         {
      79            3 :             if (isAudioParser(*m_gstWrapper, m_element))
      80              :             {
      81            1 :                 RIALTO_SERVER_LOG_DEBUG("curAudioParse = %s", m_elementName);
      82            1 :                 m_context.playbackGroup.m_curAudioParse = m_element;
      83              :             }
      84            2 :             else if (isAudioDecoder(*m_gstWrapper, m_element))
      85              :             {
      86            1 :                 RIALTO_SERVER_LOG_DEBUG("curAudioDecoder = %s", m_elementName);
      87            1 :                 m_context.playbackGroup.m_curAudioDecoder = m_element;
      88              :             }
      89            1 :             else if (m_callbackRegistered && m_glibWrapper->gStrrstr(m_elementName, "typefind"))
      90              :             {
      91            1 :                 RIALTO_SERVER_LOG_DEBUG("curAudioTypefind = %s", m_elementName);
      92            1 :                 m_context.playbackGroup.m_curAudioTypefind = m_element;
      93              :             }
      94              :         }
      95            4 :         else if (isAudioSink(*m_gstWrapper, m_element))
      96              :         {
      97            3 :             GstElement *audioSinkParent = reinterpret_cast<GstElement *>(m_gstWrapper->gstElementGetParent(m_element));
      98            3 :             if (audioSinkParent)
      99              :             {
     100            3 :                 gchar *audioSinkParentName = m_gstWrapper->gstElementGetName(audioSinkParent);
     101            3 :                 RIALTO_SERVER_LOG_DEBUG("audioSinkParentName = %s", audioSinkParentName);
     102            3 :                 if (audioSinkParentName && m_glibWrapper->gStrrstr(audioSinkParentName, "bin"))
     103              :                 {
     104            1 :                     RIALTO_SERVER_LOG_DEBUG("curAudioPlaysinkBin = %s", audioSinkParentName);
     105            1 :                     if (m_context.playbackGroup.m_curAudioPlaysinkBin)
     106              :                     {
     107              :                         // Unref previous audio playsink bin, if exists
     108            1 :                         m_gstWrapper->gstObjectUnref(m_context.playbackGroup.m_curAudioPlaysinkBin);
     109              :                     }
     110            1 :                     m_context.playbackGroup.m_curAudioPlaysinkBin = audioSinkParent;
     111              :                 }
     112              :                 else
     113              :                 {
     114            2 :                     m_gstWrapper->gstObjectUnref(audioSinkParent);
     115              :                 }
     116            3 :                 m_glibWrapper->gFree(audioSinkParentName);
     117              :             }
     118              :         }
     119              :     }
     120            8 : }
     121              : } // namespace firebolt::rialto::server::tasks::generic
        

Generated by: LCOV version 2.0-1