LCOV - code coverage report
Current view: top level - media/server/main/source - NeedMediaData.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 89.3 % 28 25
Test Date: 2025-11-17 09:18:47 Functions: 100.0 % 2 2

            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 "NeedMediaData.h"
      21              : #include "IActiveRequests.h"
      22              : #include "IMediaPipelineClient.h"
      23              : #include "ISharedMemoryBuffer.h"
      24              : #include "RialtoServerLogging.h"
      25              : #include "ShmUtils.h"
      26              : #include "TypeConverters.h"
      27              : 
      28              : namespace firebolt::rialto::server
      29              : {
      30            7 : NeedMediaData::NeedMediaData(std::weak_ptr<IMediaPipelineClient> client, IActiveRequests &activeRequests,
      31              :                              const ISharedMemoryBuffer &shmBuffer, int sessionId, MediaSourceType mediaSourceType,
      32            7 :                              std::int32_t sourceId, PlaybackState currentPlaybackState)
      33            7 :     : m_client{client}, m_activeRequests{activeRequests}, m_mediaSourceType{mediaSourceType}, m_frameCount{kMaxFrames},
      34            7 :       m_sourceId{sourceId}
      35              : {
      36            7 :     if (MediaSourceType::AUDIO != mediaSourceType && MediaSourceType::VIDEO != mediaSourceType &&
      37            1 :         MediaSourceType::SUBTITLE != mediaSourceType)
      38              :     {
      39            1 :         RIALTO_SERVER_LOG_ERROR("Unable to initialize NeedMediaData - unknown mediaSourceType: %s",
      40              :                                 common::convertMediaSourceType(m_mediaSourceType));
      41            1 :         m_isValid = false;
      42            1 :         return;
      43              :     }
      44              :     try
      45              :     {
      46            6 :         m_maxMediaBytes =
      47            6 :             shmBuffer.getMaxDataLen(ISharedMemoryBuffer::MediaPlaybackType::GENERIC, sessionId, mediaSourceType) -
      48            6 :             getMaxMetadataBytes();
      49              :         auto metadataOffset =
      50            6 :             shmBuffer.getDataOffset(ISharedMemoryBuffer::MediaPlaybackType::GENERIC, sessionId, mediaSourceType);
      51            6 :         auto mediadataOffset = metadataOffset + getMaxMetadataBytes();
      52            6 :         m_shmInfo = std::make_shared<MediaPlayerShmInfo>(
      53            6 :             MediaPlayerShmInfo{getMaxMetadataBytes(), metadataOffset, mediadataOffset, m_maxMediaBytes});
      54            6 :         m_isValid = true;
      55              :     }
      56            0 :     catch (const std::exception &e)
      57              :     {
      58            0 :         RIALTO_SERVER_LOG_ERROR("Unable to construct NeedMediaData message for %s - %s",
      59              :                                 common::convertMediaSourceType(m_mediaSourceType), e.what());
      60            0 :         m_isValid = false;
      61              :     }
      62              : }
      63              : 
      64            7 : bool NeedMediaData::send() const
      65              : {
      66            7 :     auto client = m_client.lock();
      67            7 :     if (client && m_isValid)
      68              :     {
      69           12 :         client->notifyNeedMediaData(m_sourceId, m_frameCount,
      70            6 :                                     m_activeRequests.insert(m_mediaSourceType, m_maxMediaBytes), m_shmInfo);
      71            6 :         return true;
      72              :     }
      73            1 :     return false;
      74            7 : }
      75              : } // namespace firebolt::rialto::server
        

Generated by: LCOV version 2.0-1