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

Generated by: LCOV version 2.0-1