LCOV - code coverage report
Current view: top level - media/server/gstplayer/source/tasks/generic - AttachSamples.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 92.6 % 54 50
Test Date: 2026-03-18 08:38:49 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 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/AttachSamples.h"
      21              : #include "GenericPlayerContext.h"
      22              : #include "IGstGenericPlayerPrivate.h"
      23              : #include "RialtoServerLogging.h"
      24              : #include "TypeConverters.h"
      25              : #include <utility>
      26              : 
      27              : namespace firebolt::rialto::server::tasks::generic
      28              : {
      29            5 : AttachSamples::AttachSamples(GenericPlayerContext &context,
      30              :                              const std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> &gstWrapper,
      31            5 :                              IGstGenericPlayerPrivate &player, const IMediaPipeline::MediaSegmentVector &mediaSegments)
      32            5 :     : m_context{context}, m_gstWrapper{gstWrapper}, m_player{player}
      33              : {
      34            5 :     RIALTO_SERVER_LOG_DEBUG("Constructing AttachSamples");
      35           13 :     for (const auto &mediaSegment : mediaSegments)
      36              :     {
      37            8 :         GstBuffer *gstBuffer = m_player.createBuffer(*mediaSegment);
      38            8 :         if (mediaSegment->getType() == firebolt::rialto::MediaSourceType::VIDEO)
      39              :         {
      40              :             try
      41              :             {
      42              :                 IMediaPipeline::MediaSegmentVideo &videoSegment =
      43            2 :                     dynamic_cast<IMediaPipeline::MediaSegmentVideo &>(*mediaSegment);
      44            4 :                 VideoData videoData = {gstBuffer, videoSegment.getWidth(), videoSegment.getHeight(),
      45            2 :                                        videoSegment.getFrameRate(), videoSegment.getCodecData()};
      46            2 :                 m_videoData.push_back(std::move(videoData));
      47              :             }
      48            0 :             catch (const std::exception &e)
      49              :             {
      50              :                 // Catching error, but continuing as best as we can
      51            0 :                 RIALTO_SERVER_LOG_ERROR("Failed to get the video segment, reason: %s", e.what());
      52              :             }
      53              :         }
      54            6 :         else if (mediaSegment->getType() == firebolt::rialto::MediaSourceType::AUDIO)
      55              :         {
      56              :             try
      57              :             {
      58              :                 IMediaPipeline::MediaSegmentAudio &audioSegment =
      59            2 :                     dynamic_cast<IMediaPipeline::MediaSegmentAudio &>(*mediaSegment);
      60              :                 AudioData audioData = {gstBuffer,
      61            2 :                                        audioSegment.getSampleRate(),
      62            2 :                                        audioSegment.getNumberOfChannels(),
      63              :                                        audioSegment.getCodecData(),
      64            2 :                                        audioSegment.getClippingStart(),
      65            2 :                                        audioSegment.getClippingEnd()};
      66            2 :                 m_audioData.push_back(std::move(audioData));
      67              :             }
      68            0 :             catch (const std::exception &e)
      69              :             {
      70              :                 // Catching error, but continuing as best as we can
      71            0 :                 RIALTO_SERVER_LOG_ERROR("Failed to get the audio segment, reason: %s", e.what());
      72              :             }
      73              :         }
      74            4 :         else if (mediaSegment->getType() == firebolt::rialto::MediaSourceType::SUBTITLE)
      75              :         {
      76            4 :             m_subtitleData.push_back(gstBuffer);
      77              :         }
      78              :     }
      79            5 : }
      80              : 
      81            6 : AttachSamples::~AttachSamples()
      82              : {
      83            5 :     RIALTO_SERVER_LOG_DEBUG("AttachSamples finished");
      84            6 : }
      85              : 
      86            4 : void AttachSamples::execute() const
      87              : {
      88            4 :     RIALTO_SERVER_LOG_DEBUG("Executing AttachSamples");
      89            6 :     for (AudioData audioData : m_audioData)
      90              :     {
      91            2 :         m_player.updateAudioCaps(audioData.rate, audioData.channels, audioData.codecData);
      92            2 :         m_player.addAudioClippingToBuffer(audioData.buffer, audioData.clippingStart, audioData.clippingEnd);
      93              : 
      94            2 :         attachData(firebolt::rialto::MediaSourceType::AUDIO, audioData.buffer);
      95              :     }
      96            6 :     for (VideoData videoData : m_videoData)
      97              :     {
      98            2 :         m_player.updateVideoCaps(videoData.width, videoData.height, videoData.frameRate, videoData.codecData);
      99              : 
     100            2 :         attachData(firebolt::rialto::MediaSourceType::VIDEO, videoData.buffer);
     101              :     }
     102            8 :     for (GstBuffer *buffer : m_subtitleData)
     103              :     {
     104            4 :         attachData(firebolt::rialto::MediaSourceType::SUBTITLE, buffer);
     105              :     }
     106              : 
     107            4 :     if (!m_audioData.empty())
     108              :     {
     109            1 :         m_player.notifyNeedMediaData(firebolt::rialto::MediaSourceType::AUDIO);
     110              :     }
     111            3 :     else if (!m_videoData.empty())
     112              :     {
     113            1 :         m_player.notifyNeedMediaData(firebolt::rialto::MediaSourceType::VIDEO);
     114              :     }
     115            2 :     else if (!m_subtitleData.empty())
     116              :     {
     117            2 :         m_player.notifyNeedMediaData(firebolt::rialto::MediaSourceType::SUBTITLE);
     118              :     }
     119            4 : }
     120              : 
     121            8 : void AttachSamples::attachData(const firebolt::rialto::MediaSourceType mediaType, GstBuffer *buffer) const
     122              : {
     123            8 :     auto elem = m_context.streamInfo.find(mediaType);
     124            8 :     if (elem != m_context.streamInfo.end())
     125              :     {
     126            6 :         elem->second.buffers.push_back(buffer);
     127            6 :         m_player.attachData(mediaType);
     128              :     }
     129              :     else
     130              :     {
     131            2 :         RIALTO_SERVER_LOG_WARN("Could not find stream info for %s", common::convertMediaSourceType(mediaType));
     132            2 :         m_gstWrapper->gstBufferUnref(buffer);
     133              :     }
     134            8 : }
     135              : 
     136              : } // namespace firebolt::rialto::server::tasks::generic
        

Generated by: LCOV version 2.0-1