LCOV - code coverage report
Current view: top level - media/server/gstplayer/source/tasks/generic - AttachSource.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 96.4 % 56 54
Test Date: 2026-05-14 05:59:51 Functions: 100.0 % 5 5

            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 2022 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/AttachSource.h"
      21              : #include "GstMimeMapping.h"
      22              : #include "IGlibWrapper.h"
      23              : #include "IGstWrapper.h"
      24              : #include "IMediaPipeline.h"
      25              : #include "RialtoServerLogging.h"
      26              : #include "TypeConverters.h"
      27              : #include "Utils.h"
      28              : #include <unordered_map>
      29              : 
      30              : namespace firebolt::rialto::server::tasks::generic
      31              : {
      32           22 : AttachSource::AttachSource(GenericPlayerContext &context,
      33              :                            const std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> &gstWrapper,
      34              :                            const std::shared_ptr<firebolt::rialto::wrappers::IGlibWrapper> &glibWrapper,
      35              :                            const std::shared_ptr<IGstTextTrackSinkFactory> &gstTextTrackSinkFactory,
      36           22 :                            IGstGenericPlayerPrivate &player, const std::unique_ptr<IMediaPipeline::MediaSource> &source)
      37           22 :     : m_context{context}, m_gstWrapper{gstWrapper}, m_glibWrapper{glibWrapper},
      38           44 :       m_gstTextTrackSinkFactory{gstTextTrackSinkFactory}, m_player{player}, m_attachedSource{source->copy()}
      39              : {
      40           22 :     RIALTO_SERVER_LOG_DEBUG("Constructing AttachSource");
      41              : }
      42              : 
      43           23 : AttachSource::~AttachSource()
      44              : {
      45           22 :     RIALTO_SERVER_LOG_DEBUG("AttachSource finished");
      46           23 : }
      47              : 
      48           21 : void AttachSource::execute() const
      49              : {
      50           21 :     RIALTO_SERVER_LOG_DEBUG("Executing AttachSource %u", static_cast<uint32_t>(m_attachedSource->getType()));
      51              : 
      52           21 :     if (m_attachedSource->getType() == MediaSourceType::UNKNOWN)
      53              :     {
      54            1 :         RIALTO_SERVER_LOG_ERROR("Unknown media source type");
      55            1 :         return;
      56              :     }
      57              : 
      58           20 :     if (m_context.streamInfo.find(m_attachedSource->getType()) == m_context.streamInfo.end())
      59              :     {
      60           18 :         addSource();
      61              :     }
      62            2 :     else if (m_attachedSource->getType() == MediaSourceType::AUDIO)
      63              :     {
      64            2 :         reattachAudioSource();
      65              :     }
      66              :     else
      67              :     {
      68            0 :         RIALTO_SERVER_LOG_ERROR("cannot update caps");
      69              :     }
      70              : }
      71              : 
      72           18 : void AttachSource::addSource() const
      73              : {
      74           18 :     GstCaps *caps = createCapsFromMediaSource(m_gstWrapper, m_glibWrapper, m_attachedSource);
      75           18 :     if (!caps)
      76              :     {
      77            3 :         RIALTO_SERVER_LOG_ERROR("Failed to create caps from media source");
      78            3 :         return;
      79              :     }
      80           15 :     std::string profilerInfo;
      81           15 :     gchar *capsStr = m_gstWrapper->gstCapsToString(caps);
      82           15 :     GstElement *appSrc = nullptr;
      83           15 :     if (m_attachedSource->getType() == MediaSourceType::AUDIO)
      84              :     {
      85            7 :         RIALTO_SERVER_LOG_MIL("Adding Audio appsrc with caps %s", capsStr);
      86            7 :         appSrc = m_gstWrapper->gstElementFactoryMake("appsrc", "audsrc");
      87            7 :         profilerInfo = "audsrc";
      88              :     }
      89            8 :     else if (m_attachedSource->getType() == MediaSourceType::VIDEO)
      90              :     {
      91            7 :         RIALTO_SERVER_LOG_MIL("Adding Video appsrc with caps %s", capsStr);
      92            7 :         appSrc = m_gstWrapper->gstElementFactoryMake("appsrc", "vidsrc");
      93            7 :         profilerInfo = "vidsrc";
      94              :     }
      95            1 :     else if (m_attachedSource->getType() == MediaSourceType::SUBTITLE)
      96              :     {
      97            1 :         RIALTO_SERVER_LOG_MIL("Adding Subtitle appsrc with caps %s", capsStr);
      98            1 :         appSrc = m_gstWrapper->gstElementFactoryMake("appsrc", "subsrc");
      99            1 :         profilerInfo = "subsrc";
     100              : 
     101            1 :         if (m_glibWrapper->gObjectClassFindProperty(G_OBJECT_GET_CLASS(m_context.pipeline), "text-sink"))
     102              :         {
     103            1 :             GstElement *elem = m_gstTextTrackSinkFactory->createGstTextTrackSink();
     104            1 :             m_context.subtitleSink = elem;
     105              : 
     106            1 :             m_glibWrapper->gObjectSet(m_context.pipeline, "text-sink", elem, nullptr);
     107              :         }
     108              :     }
     109           15 :     if (appSrc)
     110              :     {
     111           30 :         auto recordId = m_context.gstProfiler->createRecord("Created AppSrc Element", profilerInfo);
     112           15 :         if (recordId)
     113            0 :             m_context.gstProfiler->logRecord(recordId.value());
     114              :     }
     115              : 
     116           15 :     m_glibWrapper->gFree(capsStr);
     117              : 
     118           15 :     m_gstWrapper->gstAppSrcSetCaps(GST_APP_SRC(appSrc), caps);
     119           15 :     m_context.streamInfo.emplace(m_attachedSource->getType(), StreamInfo{appSrc, m_attachedSource->getHasDrm()});
     120              : 
     121           15 :     if (caps)
     122           15 :         m_gstWrapper->gstCapsUnref(caps);
     123              : }
     124              : 
     125            2 : void AttachSource::reattachAudioSource() const
     126              : {
     127            2 :     if (!m_player.reattachSource(m_attachedSource))
     128              :     {
     129            1 :         RIALTO_SERVER_LOG_ERROR("Reattaching source failed!");
     130            1 :         return;
     131              :     }
     132            1 :     RIALTO_SERVER_LOG_MIL("Audio source reattached");
     133              : }
     134              : } // namespace firebolt::rialto::server::tasks::generic
        

Generated by: LCOV version 2.0-1