LCOV - code coverage report
Current view: top level - media/server/ipc/source - MediaPipelineClient.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 67.7 % 158 107
Test Date: 2026-12-04 20:46:59 Functions: 81.0 % 21 17

            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 "MediaPipelineClient.h"
      21              : #include "RialtoServerLogging.h"
      22              : #include "mediapipelinemodule.pb.h"
      23              : #include <IIpcServer.h>
      24              : #include <MediaCommon.h>
      25              : 
      26              : namespace
      27              : {
      28              : firebolt::rialto::PlaybackStateChangeEvent_PlaybackState
      29            1 : convertPlaybackState(const firebolt::rialto::PlaybackState &playbackState)
      30              : {
      31            1 :     switch (playbackState)
      32              :     {
      33            0 :     case firebolt::rialto::PlaybackState::UNKNOWN:
      34              :     {
      35            0 :         return firebolt::rialto::PlaybackStateChangeEvent_PlaybackState_UNKNOWN;
      36              :     }
      37            0 :     case firebolt::rialto::PlaybackState::IDLE:
      38              :     {
      39            0 :         return firebolt::rialto::PlaybackStateChangeEvent_PlaybackState_IDLE;
      40              :     }
      41            1 :     case firebolt::rialto::PlaybackState::PLAYING:
      42              :     {
      43            1 :         return firebolt::rialto::PlaybackStateChangeEvent_PlaybackState_PLAYING;
      44              :     }
      45            0 :     case firebolt::rialto::PlaybackState::PAUSED:
      46              :     {
      47            0 :         return firebolt::rialto::PlaybackStateChangeEvent_PlaybackState_PAUSED;
      48              :     }
      49            0 :     case firebolt::rialto::PlaybackState::SEEKING:
      50              :     {
      51            0 :         return firebolt::rialto::PlaybackStateChangeEvent_PlaybackState_SEEKING;
      52              :     }
      53            0 :     case firebolt::rialto::PlaybackState::SEEK_DONE:
      54              :     {
      55            0 :         return firebolt::rialto::PlaybackStateChangeEvent_PlaybackState_SEEK_DONE;
      56              :     }
      57            0 :     case firebolt::rialto::PlaybackState::STOPPED:
      58              :     {
      59            0 :         return firebolt::rialto::PlaybackStateChangeEvent_PlaybackState_STOPPED;
      60              :     }
      61            0 :     case firebolt::rialto::PlaybackState::END_OF_STREAM:
      62              :     {
      63            0 :         return firebolt::rialto::PlaybackStateChangeEvent_PlaybackState_END_OF_STREAM;
      64              :     }
      65            0 :     case firebolt::rialto::PlaybackState::FAILURE:
      66              :     {
      67            0 :         return firebolt::rialto::PlaybackStateChangeEvent_PlaybackState_FAILURE;
      68              :     }
      69              :     }
      70            0 :     return firebolt::rialto::PlaybackStateChangeEvent_PlaybackState_UNKNOWN;
      71              : }
      72              : 
      73              : firebolt::rialto::NetworkStateChangeEvent_NetworkState
      74            1 : convertNetworkState(const firebolt::rialto::NetworkState &networkState)
      75              : {
      76            1 :     switch (networkState)
      77              :     {
      78            0 :     case firebolt::rialto::NetworkState::UNKNOWN:
      79              :     {
      80            0 :         return firebolt::rialto::NetworkStateChangeEvent_NetworkState_UNKNOWN;
      81              :     }
      82            0 :     case firebolt::rialto::NetworkState::IDLE:
      83              :     {
      84            0 :         return firebolt::rialto::NetworkStateChangeEvent_NetworkState_IDLE;
      85              :     }
      86            0 :     case firebolt::rialto::NetworkState::BUFFERING:
      87              :     {
      88            0 :         return firebolt::rialto::NetworkStateChangeEvent_NetworkState_BUFFERING;
      89              :     }
      90            0 :     case firebolt::rialto::NetworkState::BUFFERING_PROGRESS:
      91              :     {
      92            0 :         return firebolt::rialto::NetworkStateChangeEvent_NetworkState_BUFFERING_PROGRESS;
      93              :     }
      94            1 :     case firebolt::rialto::NetworkState::BUFFERED:
      95              :     {
      96            1 :         return firebolt::rialto::NetworkStateChangeEvent_NetworkState_BUFFERED;
      97              :     }
      98            0 :     case firebolt::rialto::NetworkState::STALLED:
      99              :     {
     100            0 :         return firebolt::rialto::NetworkStateChangeEvent_NetworkState_STALLED;
     101              :     }
     102            0 :     case firebolt::rialto::NetworkState::FORMAT_ERROR:
     103              :     {
     104            0 :         return firebolt::rialto::NetworkStateChangeEvent_NetworkState_FORMAT_ERROR;
     105              :     }
     106            0 :     case firebolt::rialto::NetworkState::NETWORK_ERROR:
     107              :     {
     108            0 :         return firebolt::rialto::NetworkStateChangeEvent_NetworkState_NETWORK_ERROR;
     109              :     }
     110            0 :     case firebolt::rialto::NetworkState::DECODE_ERROR:
     111              :     {
     112            0 :         return firebolt::rialto::NetworkStateChangeEvent_NetworkState_DECODE_ERROR;
     113              :     }
     114              :     }
     115            0 :     return firebolt::rialto::NetworkStateChangeEvent_NetworkState_UNKNOWN;
     116              : }
     117              : 
     118            1 : firebolt::rialto::PlaybackErrorEvent_PlaybackError convertPlaybackError(const firebolt::rialto::PlaybackError &playbackError)
     119              : {
     120            1 :     switch (playbackError)
     121              :     {
     122            0 :     case firebolt::rialto::PlaybackError::UNKNOWN:
     123              :     {
     124            0 :         return firebolt::rialto::PlaybackErrorEvent_PlaybackError_UNKNOWN;
     125              :     }
     126            1 :     case firebolt::rialto::PlaybackError::DECRYPTION:
     127              :     {
     128            1 :         return firebolt::rialto::PlaybackErrorEvent_PlaybackError_DECRYPTION;
     129              :     }
     130            0 :     case firebolt::rialto::PlaybackError::OUTPUT_PROTECTION:
     131              :     {
     132            0 :         return firebolt::rialto::PlaybackErrorEvent_PlaybackError_OUTPUT_PROTECTION;
     133              :     }
     134              :     }
     135            0 :     return firebolt::rialto::PlaybackErrorEvent_PlaybackError_UNKNOWN;
     136              : }
     137              : } // namespace
     138              : 
     139              : namespace firebolt::rialto::server::ipc
     140              : {
     141           46 : MediaPipelineClient::MediaPipelineClient(int sessionId, const std::shared_ptr<::firebolt::rialto::ipc::IClient> &ipcClient)
     142           46 :     : m_sessionId{sessionId}, m_ipcClient{ipcClient}
     143              : {
     144              : }
     145              : 
     146              : MediaPipelineClient::~MediaPipelineClient() {}
     147              : 
     148            0 : void MediaPipelineClient::notifyDuration(int64_t duration)
     149              : {
     150            0 :     RIALTO_SERVER_LOG_WARN("Notify Duration not supported");
     151              : }
     152              : 
     153            1 : void MediaPipelineClient::notifyPosition(int64_t position)
     154              : {
     155            1 :     RIALTO_SERVER_LOG_DEBUG("Sending PositionChangeEvent");
     156              : 
     157            1 :     auto event = std::make_shared<firebolt::rialto::PositionChangeEvent>();
     158            1 :     event->set_session_id(m_sessionId);
     159            1 :     event->set_position(position);
     160              : 
     161            1 :     m_ipcClient->sendEvent(event);
     162              : }
     163              : 
     164            0 : void MediaPipelineClient::notifyNativeSize(uint32_t width, uint32_t height, double aspect)
     165              : {
     166            0 :     RIALTO_SERVER_LOG_WARN("Notify Native Size not supported");
     167              : }
     168              : 
     169            1 : void MediaPipelineClient::notifyNetworkState(NetworkState state)
     170              : {
     171            1 :     RIALTO_SERVER_LOG_DEBUG("Sending NetworkStateChangeEvent");
     172              : 
     173            1 :     auto event = std::make_shared<firebolt::rialto::NetworkStateChangeEvent>();
     174            1 :     event->set_session_id(m_sessionId);
     175            1 :     event->set_state(convertNetworkState(state));
     176              : 
     177            1 :     m_ipcClient->sendEvent(event);
     178              : }
     179              : 
     180            1 : void MediaPipelineClient::notifyPlaybackState(PlaybackState state)
     181              : {
     182            1 :     RIALTO_SERVER_LOG_DEBUG("Sending PlaybackStateChangeEvent...");
     183              : 
     184            1 :     auto event = std::make_shared<firebolt::rialto::PlaybackStateChangeEvent>();
     185            1 :     event->set_session_id(m_sessionId);
     186            1 :     event->set_state(convertPlaybackState(state));
     187              : 
     188            1 :     m_ipcClient->sendEvent(event);
     189              : }
     190              : 
     191            1 : void MediaPipelineClient::notifyVideoData(bool hasData)
     192              : {
     193            1 :     sendMediaDataEvent(MediaSourceType::VIDEO, hasData);
     194              : }
     195              : 
     196            1 : void MediaPipelineClient::notifyAudioData(bool hasData)
     197              : {
     198            1 :     sendMediaDataEvent(MediaSourceType::AUDIO, hasData);
     199              : }
     200              : 
     201            2 : void MediaPipelineClient::sendMediaDataEvent(MediaSourceType mediaSourceType, bool hasData)
     202              : {
     203            2 :     RIALTO_SERVER_LOG_DEBUG("Sending MediaDataEvent...");
     204              : 
     205            2 :     auto event = std::make_shared<firebolt::rialto::MediaDataEvent>();
     206            2 :     event->set_session_id(m_sessionId);
     207            2 :     event->set_media_type(MediaSourceType::VIDEO == mediaSourceType ? firebolt::rialto::MediaDataEvent_MediaType_VIDEO
     208              :                                                                     : firebolt::rialto::MediaDataEvent_MediaType_AUDIO);
     209            2 :     event->set_data_available(hasData);
     210              : 
     211            2 :     m_ipcClient->sendEvent(event);
     212              : }
     213              : 
     214            1 : void MediaPipelineClient::notifyNeedMediaData(int32_t sourceId, size_t frameCount, uint32_t needDataRequestId,
     215              :                                               const std::shared_ptr<MediaPlayerShmInfo> &shmInfo)
     216              : {
     217            1 :     RIALTO_SERVER_LOG_DEBUG("Sending NeedMediaDataEvent...");
     218              : 
     219            1 :     auto event = std::make_shared<firebolt::rialto::NeedMediaDataEvent>();
     220            1 :     event->set_session_id(m_sessionId);
     221            1 :     event->set_source_id(sourceId);
     222            1 :     event->set_request_id(needDataRequestId);
     223            1 :     event->set_frame_count(frameCount);
     224            1 :     event->mutable_shm_info()->set_max_metadata_bytes(shmInfo->maxMetadataBytes);
     225            1 :     event->mutable_shm_info()->set_metadata_offset(shmInfo->metadataOffset);
     226            1 :     event->mutable_shm_info()->set_media_data_offset(shmInfo->mediaDataOffset);
     227            1 :     event->mutable_shm_info()->set_max_media_bytes(shmInfo->maxMediaBytes);
     228              : 
     229            1 :     m_ipcClient->sendEvent(event);
     230              : }
     231              : 
     232            0 : void MediaPipelineClient::notifyCancelNeedMediaData(int32_t sourceId)
     233              : {
     234            0 :     RIALTO_SERVER_LOG_WARN("Notify Cancel Need Media Data not supported");
     235              : }
     236              : 
     237            1 : void MediaPipelineClient::notifyQos(int32_t sourceId, const QosInfo &qosInfo)
     238              : {
     239            1 :     RIALTO_SERVER_LOG_DEBUG("Sending QosEvent...");
     240              : 
     241            1 :     auto event = std::make_shared<firebolt::rialto::QosEvent>();
     242            1 :     event->set_session_id(m_sessionId);
     243            1 :     event->set_source_id(sourceId);
     244            1 :     event->mutable_qos_info()->set_processed(qosInfo.processed);
     245            1 :     event->mutable_qos_info()->set_dropped(qosInfo.dropped);
     246              : 
     247            1 :     m_ipcClient->sendEvent(event);
     248              : }
     249              : 
     250            1 : void MediaPipelineClient::notifyMetric(const MetricEvent &metric)
     251              : {
     252            1 :     RIALTO_SERVER_LOG_DEBUG(
     253              :         "Sending playback metric IPC event sessionId: %d, sourceId: %d, ptsNs: %llu, metric: %u, observationKind: %u, "
     254              :         "count: %llu, durationNs: %llu, observedAtMonotonicNs: %llu, observedAtUnixNs: %lld",
     255              :         m_sessionId, metric.sourceId,
     256              :         static_cast<unsigned long long>(metric.presentationTimeStampNs.value_or(0)), // NOLINT(runtime/int)
     257              :         static_cast<uint32_t>(metric.type), static_cast<uint32_t>(metric.phase),
     258              :         static_cast<unsigned long long>(metric.count.value_or(0)),      // NOLINT(runtime/int)
     259              :         static_cast<unsigned long long>(metric.durationNs.value_or(0)), // NOLINT(runtime/int)
     260              :         static_cast<unsigned long long>(metric.observedAtMonotonicNs),  // NOLINT(runtime/int)
     261              :         static_cast<long long>(metric.observedAtUnixNs));               // NOLINT(runtime/int)
     262              : 
     263            1 :     auto event = std::make_shared<firebolt::rialto::MediaPipelineMetricEvent>();
     264            1 :     event->set_type(
     265            1 :         static_cast<firebolt::rialto::MediaPipelineMetricEvent::MetricType>(static_cast<uint32_t>(metric.type)));
     266            1 :     event->set_phase(
     267            1 :         static_cast<firebolt::rialto::MediaPipelineMetricEvent::MetricPhase>(static_cast<uint32_t>(metric.phase)));
     268            1 :     event->set_session_id(static_cast<uint32_t>(m_sessionId));
     269            1 :     event->set_source_id(metric.sourceId);
     270            1 :     if (metric.presentationTimeStampNs)
     271              :     {
     272            1 :         event->set_pts_ns(*metric.presentationTimeStampNs);
     273              :     }
     274            1 :     if (metric.count)
     275              :     {
     276            1 :         event->set_count(*metric.count);
     277              :     }
     278            1 :     if (metric.durationNs)
     279              :     {
     280            1 :         event->set_duration_ns(*metric.durationNs);
     281              :     }
     282            1 :     event->set_observed_at_monotonic_ns(metric.observedAtMonotonicNs);
     283            1 :     event->set_observed_at_unix_ns(metric.observedAtUnixNs);
     284              : 
     285            1 :     m_ipcClient->sendEvent(event);
     286              : }
     287              : 
     288            0 : void MediaPipelineClient::notifyBufferUnderflow(int32_t sourceId)
     289              : {
     290            0 :     RIALTO_SERVER_LOG_DEBUG("Sending BufferUnderflowEvent...");
     291              : 
     292            0 :     auto event = std::make_shared<firebolt::rialto::BufferUnderflowEvent>();
     293            0 :     event->set_session_id(m_sessionId);
     294            0 :     event->set_source_id(sourceId);
     295              : 
     296            0 :     m_ipcClient->sendEvent(event);
     297              : }
     298              : 
     299            1 : void MediaPipelineClient::notifyFirstFrameReceived(int32_t sourceId)
     300              : {
     301            1 :     RIALTO_SERVER_LOG_DEBUG("Sending FirstFrameReceivedEvent...");
     302              : 
     303            1 :     auto event = std::make_shared<firebolt::rialto::FirstFrameReceivedEvent>();
     304            1 :     event->set_session_id(m_sessionId);
     305            1 :     event->set_source_id(sourceId);
     306              : 
     307            1 :     m_ipcClient->sendEvent(event);
     308              : }
     309              : 
     310            1 : void MediaPipelineClient::notifyPlaybackError(int32_t sourceId, PlaybackError error)
     311              : {
     312            1 :     RIALTO_SERVER_LOG_DEBUG("Sending notifyPlaybackError...");
     313              : 
     314            1 :     auto event = std::make_shared<firebolt::rialto::PlaybackErrorEvent>();
     315            1 :     event->set_session_id(m_sessionId);
     316            1 :     event->set_source_id(sourceId);
     317            1 :     event->set_error(convertPlaybackError(error));
     318              : 
     319            1 :     m_ipcClient->sendEvent(event);
     320              : }
     321              : 
     322            1 : void MediaPipelineClient::notifySourceFlushed(int32_t sourceId)
     323              : {
     324            1 :     RIALTO_SERVER_LOG_DEBUG("Sending SourceFlushedEvent...");
     325              : 
     326            1 :     auto event = std::make_shared<firebolt::rialto::SourceFlushedEvent>();
     327            1 :     event->set_session_id(m_sessionId);
     328            1 :     event->set_source_id(sourceId);
     329              : 
     330            1 :     m_ipcClient->sendEvent(event);
     331              : }
     332              : 
     333            1 : void MediaPipelineClient::notifyPlaybackInfo(const PlaybackInfo &playbackInfo)
     334              : {
     335            1 :     RIALTO_SERVER_LOG_DEBUG("Sending PlaybackInfoEvent...");
     336              : 
     337            1 :     auto event = std::make_shared<firebolt::rialto::PlaybackInfoEvent>();
     338            1 :     event->set_session_id(m_sessionId);
     339            1 :     event->set_current_position(playbackInfo.currentPosition);
     340            1 :     event->set_volume(playbackInfo.volume);
     341              : 
     342            1 :     m_ipcClient->sendEvent(event);
     343              : }
     344              : } // namespace firebolt::rialto::server::ipc
        

Generated by: LCOV version 2.0-1