LCOV - code coverage report
Current view: top level - media/server/ipc/source - MediaPipelineModuleService.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 84.5 % 639 540
Test Date: 2026-12-04 20:46:59 Functions: 96.6 % 59 57

            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 "MediaPipelineModuleService.h"
      21              : #include "IMediaPipelineService.h"
      22              : #include "IPrivateMetricsModuleService.h"
      23              : #include "MediaPipelineClient.h"
      24              : #include "RialtoCommonModule.h"
      25              : #include "RialtoServerLogging.h"
      26              : #include <IIpcController.h>
      27              : #include <algorithm>
      28              : #include <cstdint>
      29              : #include <optional>
      30              : #include <unordered_map>
      31              : #include <utility>
      32              : #include <vector>
      33              : 
      34              : namespace
      35              : {
      36           45 : int generateSessionId()
      37              : {
      38              :     static int sessionId{0};
      39           45 :     return sessionId++;
      40              : }
      41              : 
      42            2 : firebolt::rialto::MediaType convertMediaType(const firebolt::rialto::LoadRequest_MediaType &mediaType)
      43              : {
      44            2 :     switch (mediaType)
      45              :     {
      46            0 :     case firebolt::rialto::LoadRequest_MediaType::LoadRequest_MediaType_UNKNOWN:
      47              :     {
      48            0 :         return firebolt::rialto::MediaType::UNKNOWN;
      49              :     }
      50            2 :     case firebolt::rialto::LoadRequest_MediaType::LoadRequest_MediaType_MSE:
      51              :     {
      52            2 :         return firebolt::rialto::MediaType::MSE;
      53              :     }
      54              :     }
      55            0 :     return firebolt::rialto::MediaType::UNKNOWN;
      56              : }
      57              : 
      58            2 : firebolt::rialto::EaseType convertEaseType(const firebolt::rialto::SetVolumeRequest_EaseType &easeType)
      59              : {
      60            2 :     switch (easeType)
      61              :     {
      62            2 :     case firebolt::rialto::SetVolumeRequest_EaseType::SetVolumeRequest_EaseType_EASE_LINEAR:
      63              :     {
      64            2 :         return firebolt::rialto::EaseType::EASE_LINEAR;
      65              :     }
      66            0 :     case firebolt::rialto::SetVolumeRequest_EaseType::SetVolumeRequest_EaseType_EASE_IN_CUBIC:
      67              :     {
      68            0 :         return firebolt::rialto::EaseType::EASE_IN_CUBIC;
      69              :     }
      70            0 :     case firebolt::rialto::SetVolumeRequest_EaseType::SetVolumeRequest_EaseType_EASE_OUT_CUBIC:
      71              :     {
      72            0 :         return firebolt::rialto::EaseType::EASE_OUT_CUBIC;
      73              :     }
      74              :     }
      75            0 :     return firebolt::rialto::EaseType::EASE_LINEAR;
      76              : }
      77              : 
      78              : firebolt::rialto::MediaSourceStatus
      79            2 : convertMediaSourceStatus(const firebolt::rialto::HaveDataRequest_MediaSourceStatus &status)
      80              : {
      81            2 :     switch (status)
      82              :     {
      83            0 :     case firebolt::rialto::HaveDataRequest_MediaSourceStatus_UNKNOWN:
      84              :     {
      85            0 :         return firebolt::rialto::MediaSourceStatus::ERROR;
      86              :     }
      87            0 :     case firebolt::rialto::HaveDataRequest_MediaSourceStatus_OK:
      88              :     {
      89            0 :         return firebolt::rialto::MediaSourceStatus::OK;
      90              :     }
      91            0 :     case firebolt::rialto::HaveDataRequest_MediaSourceStatus_EOS:
      92              :     {
      93            0 :         return firebolt::rialto::MediaSourceStatus::EOS;
      94              :     }
      95            0 :     case firebolt::rialto::HaveDataRequest_MediaSourceStatus_ERROR:
      96              :     {
      97            0 :         return firebolt::rialto::MediaSourceStatus::ERROR;
      98              :     }
      99            2 :     case firebolt::rialto::HaveDataRequest_MediaSourceStatus_CODEC_CHANGED:
     100              :     {
     101            2 :         return firebolt::rialto::MediaSourceStatus::CODEC_CHANGED;
     102              :     }
     103            0 :     case firebolt::rialto::HaveDataRequest_MediaSourceStatus_NO_AVAILABLE_SAMPLES:
     104              :     {
     105            0 :         return firebolt::rialto::MediaSourceStatus::NO_AVAILABLE_SAMPLES;
     106              :     }
     107            0 :     case firebolt::rialto::HaveDataRequest_MediaSourceStatus_NO_SPACE_FOR_SAMPLES:
     108              :     {
     109            0 :         return firebolt::rialto::MediaSourceStatus::NO_SPACE_FOR_SAMPLES;
     110              :     }
     111              :     }
     112            0 :     return firebolt::rialto::MediaSourceStatus::ERROR;
     113              : }
     114              : 
     115           24 : firebolt::rialto::SourceConfigType convertConfigType(const firebolt::rialto::AttachSourceRequest_ConfigType &configType)
     116              : {
     117           24 :     switch (configType)
     118              :     {
     119            1 :     case firebolt::rialto::AttachSourceRequest_ConfigType_CONFIG_TYPE_UNKNOWN:
     120              :     {
     121            1 :         return firebolt::rialto::SourceConfigType::UNKNOWN;
     122              :     }
     123           14 :     case firebolt::rialto::AttachSourceRequest_ConfigType_CONFIG_TYPE_AUDIO:
     124              :     {
     125           14 :         return firebolt::rialto::SourceConfigType::AUDIO;
     126              :     }
     127            7 :     case firebolt::rialto::AttachSourceRequest_ConfigType_CONFIG_TYPE_VIDEO:
     128              :     {
     129            7 :         return firebolt::rialto::SourceConfigType::VIDEO;
     130              :     }
     131            1 :     case firebolt::rialto::AttachSourceRequest_ConfigType_CONFIG_TYPE_VIDEO_DOLBY_VISION:
     132              :     {
     133            1 :         return firebolt::rialto::SourceConfigType::VIDEO_DOLBY_VISION;
     134              :     }
     135            1 :     case firebolt::rialto::AttachSourceRequest_ConfigType_CONFIG_TYPE_SUBTITLE:
     136              :     {
     137            1 :         return firebolt::rialto::SourceConfigType::SUBTITLE;
     138              :     }
     139              :     }
     140            0 :     return firebolt::rialto::SourceConfigType::UNKNOWN;
     141              : }
     142              : 
     143              : firebolt::rialto::SegmentAlignment
     144           22 : convertSegmentAlignment(const firebolt::rialto::AttachSourceRequest_SegmentAlignment &alignment)
     145              : {
     146           22 :     switch (alignment)
     147              :     {
     148           22 :     case firebolt::rialto::AttachSourceRequest_SegmentAlignment_ALIGNMENT_UNDEFINED:
     149              :     {
     150           22 :         return firebolt::rialto::SegmentAlignment::UNDEFINED;
     151              :     }
     152            0 :     case firebolt::rialto::AttachSourceRequest_SegmentAlignment_ALIGNMENT_NAL:
     153              :     {
     154            0 :         return firebolt::rialto::SegmentAlignment::NAL;
     155              :     }
     156            0 :     case firebolt::rialto::AttachSourceRequest_SegmentAlignment_ALIGNMENT_AU:
     157              :     {
     158            0 :         return firebolt::rialto::SegmentAlignment::AU;
     159              :     }
     160              :     }
     161              : 
     162            0 :     return firebolt::rialto::SegmentAlignment::UNDEFINED;
     163              : }
     164              : 
     165           22 : firebolt::rialto::StreamFormat convertStreamFormat(const firebolt::rialto::AttachSourceRequest_StreamFormat &streamFormat)
     166              : {
     167           22 :     switch (streamFormat)
     168              :     {
     169            1 :     case firebolt::rialto::AttachSourceRequest_StreamFormat_STREAM_FORMAT_RAW:
     170              :     {
     171            1 :         return firebolt::rialto::StreamFormat::RAW;
     172              :     }
     173            0 :     case firebolt::rialto::AttachSourceRequest_StreamFormat_STREAM_FORMAT_AVC:
     174              :     {
     175            0 :         return firebolt::rialto::StreamFormat::AVC;
     176              :     }
     177            0 :     case firebolt::rialto::AttachSourceRequest_StreamFormat_STREAM_FORMAT_BYTE_STREAM:
     178              :     {
     179            0 :         return firebolt::rialto::StreamFormat::BYTE_STREAM;
     180              :     }
     181            0 :     case firebolt::rialto::AttachSourceRequest_StreamFormat_STREAM_FORMAT_HVC1:
     182              :     {
     183            0 :         return firebolt::rialto::StreamFormat::HVC1;
     184              :     }
     185            0 :     case firebolt::rialto::AttachSourceRequest_StreamFormat_STREAM_FORMAT_HEV1:
     186              :     {
     187            0 :         return firebolt::rialto::StreamFormat::HEV1;
     188              :     }
     189           21 :     default:
     190           21 :         return firebolt::rialto::StreamFormat::UNDEFINED;
     191              :     }
     192              : }
     193              : 
     194            1 : firebolt::rialto::CodecDataType convertCodecDataType(const firebolt::rialto::AttachSourceRequest_CodecData_Type &type)
     195              : {
     196            1 :     if (firebolt::rialto::AttachSourceRequest_CodecData_Type_STRING == type)
     197              :     {
     198            0 :         return firebolt::rialto::CodecDataType::STRING;
     199              :     }
     200            1 :     return firebolt::rialto::CodecDataType::BUFFER;
     201              : }
     202              : 
     203            1 : firebolt::rialto::Format convertFormat(const firebolt::rialto::AttachSourceRequest_AudioConfig_Format &format)
     204              : {
     205              :     static const std::unordered_map<firebolt::rialto::AttachSourceRequest_AudioConfig_Format, firebolt::rialto::Format>
     206              :         kFormatConversionMap{
     207              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S8, firebolt::rialto::Format::S8},
     208              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U8, firebolt::rialto::Format::U8},
     209              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S16LE, firebolt::rialto::Format::S16LE},
     210              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S16BE, firebolt::rialto::Format::S16BE},
     211              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U16LE, firebolt::rialto::Format::U16LE},
     212              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U16BE, firebolt::rialto::Format::U16BE},
     213              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S24_32LE, firebolt::rialto::Format::S24_32LE},
     214              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S24_32BE, firebolt::rialto::Format::S24_32BE},
     215              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U24_32LE, firebolt::rialto::Format::U24_32LE},
     216              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U24_32BE, firebolt::rialto::Format::U24_32BE},
     217              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S32LE, firebolt::rialto::Format::S32LE},
     218              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S32BE, firebolt::rialto::Format::S32BE},
     219              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U32LE, firebolt::rialto::Format::U32LE},
     220              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U32BE, firebolt::rialto::Format::U32BE},
     221              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S24LE, firebolt::rialto::Format::S24LE},
     222              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S24BE, firebolt::rialto::Format::S24BE},
     223              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U24LE, firebolt::rialto::Format::U24LE},
     224              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U24BE, firebolt::rialto::Format::U24BE},
     225              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S20LE, firebolt::rialto::Format::S20LE},
     226              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S20BE, firebolt::rialto::Format::S20BE},
     227              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U20LE, firebolt::rialto::Format::U20LE},
     228              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U20BE, firebolt::rialto::Format::U20BE},
     229              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S18LE, firebolt::rialto::Format::S18LE},
     230              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S18BE, firebolt::rialto::Format::S18BE},
     231              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U18LE, firebolt::rialto::Format::U18LE},
     232              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U18BE, firebolt::rialto::Format::U18BE},
     233              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_F32LE, firebolt::rialto::Format::F32LE},
     234              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_F32BE, firebolt::rialto::Format::F32BE},
     235              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_F64LE, firebolt::rialto::Format::F64LE},
     236            3 :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_F64BE, firebolt::rialto::Format::F64BE}};
     237            1 :     const auto kIt = kFormatConversionMap.find(format);
     238            1 :     if (kFormatConversionMap.end() != kIt)
     239              :     {
     240            1 :         return kIt->second;
     241              :     }
     242            0 :     return firebolt::rialto::Format::S8;
     243              : }
     244              : 
     245            1 : firebolt::rialto::Layout convertLayout(const firebolt::rialto::AttachSourceRequest_AudioConfig_Layout &layout)
     246              : {
     247              :     static const std::unordered_map<firebolt::rialto::AttachSourceRequest_AudioConfig_Layout, firebolt::rialto::Layout>
     248              :         kLayoutConversionMap{{firebolt::rialto::AttachSourceRequest_AudioConfig_Layout_INTERLEAVED,
     249              :                               firebolt::rialto::Layout::INTERLEAVED},
     250              :                              {firebolt::rialto::AttachSourceRequest_AudioConfig_Layout_NON_INTERLEAVED,
     251            3 :                               firebolt::rialto::Layout::NON_INTERLEAVED}};
     252            1 :     const auto kIt = kLayoutConversionMap.find(layout);
     253            1 :     if (kLayoutConversionMap.end() != kIt)
     254              :     {
     255            1 :         return kIt->second;
     256              :     }
     257            0 :     return firebolt::rialto::Layout::INTERLEAVED;
     258              : }
     259              : } // namespace
     260              : 
     261              : namespace firebolt::rialto::server::ipc
     262              : {
     263            1 : std::shared_ptr<IMediaPipelineModuleServiceFactory> IMediaPipelineModuleServiceFactory::createFactory()
     264              : {
     265            1 :     std::shared_ptr<IMediaPipelineModuleServiceFactory> factory;
     266              : 
     267              :     try
     268              :     {
     269            1 :         factory = std::make_shared<MediaPipelineModuleServiceFactory>();
     270              :     }
     271            0 :     catch (const std::exception &e)
     272              :     {
     273            0 :         RIALTO_SERVER_LOG_ERROR("Failed to create the media player module service factory, reason: %s", e.what());
     274              :     }
     275              : 
     276            1 :     return factory;
     277              : }
     278              : 
     279              : std::shared_ptr<IMediaPipelineModuleService>
     280            1 : MediaPipelineModuleServiceFactory::create(service::IMediaPipelineService &mediaPipelineService) const
     281              : {
     282            1 :     std::shared_ptr<IMediaPipelineModuleService> mediaPipelineModule;
     283              : 
     284              :     try
     285              :     {
     286            1 :         mediaPipelineModule = std::make_shared<MediaPipelineModuleService>(mediaPipelineService);
     287              :     }
     288            0 :     catch (const std::exception &e)
     289              :     {
     290            0 :         RIALTO_SERVER_LOG_ERROR("Failed to create the media player module service, reason: %s", e.what());
     291              :     }
     292              : 
     293            1 :     return mediaPipelineModule;
     294              : }
     295              : 
     296          111 : MediaPipelineModuleService::MediaPipelineModuleService(service::IMediaPipelineService &mediaPipelineService)
     297          111 :     : m_mediaPipelineService{mediaPipelineService}
     298              : {
     299              : }
     300              : 
     301              : MediaPipelineModuleService::~MediaPipelineModuleService() {}
     302              : 
     303            2 : void MediaPipelineModuleService::clientConnected(const std::shared_ptr<::firebolt::rialto::ipc::IClient> &ipcClient)
     304              : {
     305            2 :     RIALTO_SERVER_LOG_INFO("Client Connected!");
     306              :     {
     307            2 :         m_clientSessions.emplace(ipcClient, std::set<int>());
     308              :     }
     309            2 :     ipcClient->exportService(shared_from_this());
     310              : }
     311              : 
     312            1 : void MediaPipelineModuleService::clientDisconnected(const std::shared_ptr<::firebolt::rialto::ipc::IClient> &ipcClient)
     313              : {
     314            1 :     RIALTO_SERVER_LOG_INFO("Client disconnected!");
     315            1 :     std::set<int> sessionIds;
     316              :     {
     317            1 :         auto sessionIter = m_clientSessions.find(ipcClient);
     318            1 :         if (sessionIter == m_clientSessions.end())
     319              :         {
     320            0 :             RIALTO_SERVER_LOG_ERROR("unknown client disconnected");
     321            0 :             return;
     322              :         }
     323            1 :         sessionIds = sessionIter->second; // copy to avoid deadlock
     324            1 :         m_clientSessions.erase(sessionIter);
     325              :     }
     326            2 :     for (const auto &sessionId : sessionIds)
     327              :     {
     328            1 :         m_mediaPipelineService.destroySession(sessionId);
     329            1 :         m_sessionSources.erase(sessionId);
     330            1 :         m_sessionImmediateOutput.erase(sessionId);
     331              :     }
     332              : }
     333              : 
     334           45 : void MediaPipelineModuleService::createSession(::google::protobuf::RpcController *controller,
     335              :                                                const ::firebolt::rialto::CreateSessionRequest *request,
     336              :                                                ::firebolt::rialto::CreateSessionResponse *response,
     337              :                                                ::google::protobuf::Closure *done)
     338              : {
     339           45 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     340           45 :     auto ipcController = dynamic_cast<firebolt::rialto::ipc::IController *>(controller);
     341           45 :     if (!ipcController)
     342              :     {
     343            0 :         RIALTO_SERVER_LOG_ERROR("ipc library provided incompatible controller object");
     344            0 :         controller->SetFailed("ipc library provided incompatible controller object");
     345            0 :         done->Run();
     346            0 :         return;
     347              :     }
     348              : 
     349           45 :     int sessionId = generateSessionId();
     350              :     bool sessionCreated =
     351           90 :         m_mediaPipelineService.createSession(sessionId,
     352           90 :                                              std::make_shared<MediaPipelineClient>(sessionId, ipcController->getClient()),
     353              :                                              request->max_width(), request->max_height());
     354           45 :     if (sessionCreated)
     355              :     {
     356              :         // Assume that IPC library works well and client is present
     357           44 :         m_clientSessions[ipcController->getClient()].insert(sessionId);
     358           44 :         m_sessionSources.emplace(sessionId, std::map<int32_t, MediaSourceType>{});
     359           44 :         response->set_session_id(sessionId);
     360              :     }
     361              :     else
     362              :     {
     363            1 :         RIALTO_SERVER_LOG_ERROR("Create session failed");
     364            3 :         controller->SetFailed("Operation failed");
     365              :     }
     366           45 :     done->Run();
     367              : }
     368              : 
     369            2 : void MediaPipelineModuleService::destroySession(::google::protobuf::RpcController *controller,
     370              :                                                 const ::firebolt::rialto::DestroySessionRequest *request,
     371              :                                                 ::firebolt::rialto::DestroySessionResponse *response,
     372              :                                                 ::google::protobuf::Closure *done)
     373              : {
     374            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     375            2 :     auto ipcController = dynamic_cast<firebolt::rialto::ipc::IController *>(controller);
     376            2 :     if (!ipcController)
     377              :     {
     378            0 :         RIALTO_SERVER_LOG_ERROR("ipc library provided incompatible controller object");
     379            0 :         controller->SetFailed("ipc library provided incompatible controller object");
     380            0 :         done->Run();
     381            1 :         return;
     382              :     }
     383              : 
     384            2 :     if (!m_mediaPipelineService.destroySession(request->session_id()))
     385              :     {
     386            1 :         RIALTO_SERVER_LOG_ERROR("Destroy session failed");
     387            2 :         controller->SetFailed("Operation failed");
     388            1 :         done->Run();
     389            1 :         return;
     390              :     }
     391            1 :     auto sessionIter = m_clientSessions.find(ipcController->getClient());
     392            1 :     if (sessionIter != m_clientSessions.end())
     393              :     {
     394            0 :         sessionIter->second.erase(request->session_id());
     395              :     }
     396            1 :     m_sessionSources.erase(request->session_id());
     397            1 :     m_sessionImmediateOutput.erase(request->session_id());
     398            1 :     done->Run();
     399              : }
     400              : 
     401            2 : void MediaPipelineModuleService::load(::google::protobuf::RpcController *controller,
     402              :                                       const ::firebolt::rialto::LoadRequest *request,
     403              :                                       ::firebolt::rialto::LoadResponse *response, ::google::protobuf::Closure *done)
     404              : {
     405            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     406            2 :     if (!m_mediaPipelineService.load(request->session_id(), convertMediaType(request->type()), request->mime_type(),
     407            2 :                                      request->url(), request->is_live()))
     408              :     {
     409            1 :         RIALTO_SERVER_LOG_ERROR("Load failed");
     410            3 :         controller->SetFailed("Operation failed");
     411              :     }
     412            2 :     done->Run();
     413              : }
     414              : 
     415            2 : void MediaPipelineModuleService::setVideoWindow(::google::protobuf::RpcController *controller,
     416              :                                                 const ::firebolt::rialto::SetVideoWindowRequest *request,
     417              :                                                 ::firebolt::rialto::SetVideoWindowResponse *response,
     418              :                                                 ::google::protobuf::Closure *done)
     419              : {
     420            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     421            2 :     if (!m_mediaPipelineService.setVideoWindow(request->session_id(), request->x(), request->y(), request->width(),
     422              :                                                request->height()))
     423              :     {
     424            1 :         RIALTO_SERVER_LOG_ERROR("Set Video Window failed");
     425            3 :         controller->SetFailed("Operation failed");
     426              :     }
     427            2 :     done->Run();
     428              : }
     429              : 
     430           24 : void MediaPipelineModuleService::attachSource(::google::protobuf::RpcController *controller,
     431              :                                               const ::firebolt::rialto::AttachSourceRequest *request,
     432              :                                               ::firebolt::rialto::AttachSourceResponse *response,
     433              :                                               ::google::protobuf::Closure *done)
     434              : {
     435           24 :     RIALTO_SERVER_LOG_DEBUG("mime_type: %s", request->mime_type().c_str());
     436              : 
     437           24 :     std::shared_ptr<CodecData> codecData{};
     438           24 :     if (request->has_codec_data())
     439              :     {
     440            1 :         const auto &kCodecDataProto = request->codec_data();
     441            1 :         codecData = std::make_shared<CodecData>();
     442            1 :         codecData->data = std::vector<std::uint8_t>(kCodecDataProto.data().begin(), kCodecDataProto.data().end());
     443            1 :         codecData->type = convertCodecDataType(kCodecDataProto.type());
     444              :     }
     445           24 :     std::unique_ptr<IMediaPipeline::MediaSource> mediaSource;
     446           24 :     firebolt::rialto::SourceConfigType configType = convertConfigType(request->config_type());
     447           24 :     bool hasDrm = request->has_drm();
     448              : 
     449           24 :     if (configType == firebolt::rialto::SourceConfigType::AUDIO)
     450              :     {
     451           14 :         const auto &kConfig = request->audio_config();
     452           14 :         uint32_t numberofchannels = kConfig.number_of_channels();
     453           14 :         uint32_t sampleRate = kConfig.sample_rate();
     454              : 
     455           14 :         std::vector<uint8_t> codecSpecificConfig;
     456           14 :         if (kConfig.has_codec_specific_config())
     457              :         {
     458            1 :             auto codecSpecificConfigStr = kConfig.codec_specific_config();
     459            1 :             codecSpecificConfig.assign(codecSpecificConfigStr.begin(), codecSpecificConfigStr.end());
     460              :         }
     461           14 :         std::optional<firebolt::rialto::Format> format{std::nullopt};
     462           14 :         if (kConfig.has_format())
     463              :         {
     464            1 :             format = convertFormat(kConfig.format());
     465              :         }
     466           14 :         std::optional<firebolt::rialto::Layout> layout{std::nullopt};
     467           14 :         if (kConfig.has_layout())
     468              :         {
     469            1 :             layout = convertLayout(kConfig.layout());
     470              :         }
     471           14 :         std::optional<uint64_t> channelMask{std::nullopt};
     472           14 :         if (kConfig.has_channel_mask())
     473              :         {
     474            1 :             channelMask = kConfig.channel_mask();
     475              :         }
     476           14 :         std::vector<std::vector<uint8_t>> streamHeaders;
     477           15 :         for (int i = 0; i < kConfig.stream_header_size(); ++i)
     478              :         {
     479            1 :             auto streamHeaderStr = kConfig.stream_header(i);
     480            2 :             streamHeaders.push_back(std::vector<uint8_t>{streamHeaderStr.begin(), streamHeaderStr.end()});
     481            1 :         }
     482           14 :         std::optional<bool> framed;
     483           14 :         if (kConfig.has_framed())
     484              :         {
     485            1 :             framed = kConfig.framed();
     486              :         }
     487           14 :         AudioConfig audioConfig{numberofchannels, sampleRate,  std::move(codecSpecificConfig), format,
     488           14 :                                 layout,           channelMask, std::move(streamHeaders),       framed};
     489              : 
     490              :         mediaSource =
     491           28 :             std::make_unique<IMediaPipeline::MediaSourceAudio>(request->mime_type(), hasDrm, audioConfig,
     492           14 :                                                                convertSegmentAlignment(request->segment_alignment()),
     493           28 :                                                                convertStreamFormat(request->stream_format()), codecData);
     494           14 :     }
     495           10 :     else if (configType == firebolt::rialto::SourceConfigType::VIDEO)
     496              :     {
     497              :         mediaSource =
     498           14 :             std::make_unique<IMediaPipeline::MediaSourceVideo>(request->mime_type().c_str(), hasDrm, request->width(),
     499            7 :                                                                request->height(),
     500            7 :                                                                convertSegmentAlignment(request->segment_alignment()),
     501           21 :                                                                convertStreamFormat(request->stream_format()), codecData);
     502              :     }
     503            3 :     else if (configType == firebolt::rialto::SourceConfigType::VIDEO_DOLBY_VISION)
     504              :     {
     505              :         mediaSource =
     506            2 :             std::make_unique<IMediaPipeline::MediaSourceVideoDolbyVision>(request->mime_type().c_str(),
     507            1 :                                                                           request->dolby_vision_profile(), hasDrm,
     508            1 :                                                                           request->width(), request->height(),
     509            1 :                                                                           convertSegmentAlignment(
     510            1 :                                                                               request->segment_alignment()),
     511            2 :                                                                           convertStreamFormat(request->stream_format()),
     512            1 :                                                                           codecData);
     513              :     }
     514            2 :     else if (configType == firebolt::rialto::SourceConfigType::SUBTITLE)
     515              :     {
     516            2 :         mediaSource = std::make_unique<IMediaPipeline::MediaSourceSubtitle>(request->mime_type().c_str(),
     517            2 :                                                                             request->text_track_identifier());
     518              :     }
     519              :     else
     520              :     {
     521            1 :         RIALTO_SERVER_LOG_ERROR("Unknown source type");
     522            2 :         controller->SetFailed("Operation failed");
     523            1 :         done->Run();
     524            1 :         return;
     525              :     }
     526              : 
     527           23 :     bool sourceAttached{false};
     528           23 :     if (!request->has_switch_source() || !request->switch_source())
     529              :     {
     530           20 :         RIALTO_SERVER_LOG_DEBUG("Attaching source");
     531           20 :         sourceAttached = m_mediaPipelineService.attachSource(request->session_id(), mediaSource);
     532           20 :         if (!sourceAttached)
     533              :         {
     534            1 :             RIALTO_SERVER_LOG_ERROR("Attach source failed");
     535            3 :             controller->SetFailed("Operation failed");
     536              :         }
     537              :     }
     538              :     else
     539              :     {
     540            3 :         RIALTO_SERVER_LOG_DEBUG("Switching source");
     541            3 :         const auto sessionSourcesIter = m_sessionSources.find(request->session_id());
     542            3 :         if (sessionSourcesIter != m_sessionSources.end())
     543              :         {
     544              :             const auto existingSourceIter =
     545            1 :                 std::find_if(sessionSourcesIter->second.begin(), sessionSourcesIter->second.end(),
     546            2 :                              [&mediaSource](const auto &source) { return source.second == mediaSource->getType(); });
     547            1 :             if (existingSourceIter != sessionSourcesIter->second.end())
     548              :             {
     549            1 :                 mediaSource->setId(existingSourceIter->first);
     550              :             }
     551              :             else
     552              :             {
     553            0 :                 RIALTO_SERVER_LOG_WARN("Switching source with no tracked source id");
     554              :             }
     555              :         }
     556            3 :         sourceAttached = m_mediaPipelineService.switchSource(request->session_id(), mediaSource);
     557            3 :         if (!sourceAttached)
     558              :         {
     559            1 :             RIALTO_SERVER_LOG_ERROR("Switch source failed");
     560            3 :             controller->SetFailed("Operation failed");
     561              :         }
     562              :     }
     563           23 :     if (sourceAttached)
     564              :     {
     565           21 :         if (!request->has_switch_source() || !request->switch_source())
     566              :         {
     567           19 :             auto &sessionSources = m_sessionSources[request->session_id()];
     568           19 :             sessionSources[mediaSource->getId()] = mediaSource->getType();
     569              :         }
     570              : 
     571           21 :         if (mediaSource->getType() == MediaSourceType::AUDIO)
     572              :         {
     573           12 :             const auto immediateOutputIter = m_sessionImmediateOutput.find(request->session_id());
     574           12 :             if (immediateOutputIter != m_sessionImmediateOutput.end())
     575              :             {
     576            2 :                 RIALTO_SERVER_LOG_INFO("Applying saved immediate-output to AUDIO source in session %d",
     577              :                                        request->session_id());
     578            2 :                 if (!m_mediaPipelineService.setImmediateOutput(request->session_id(), mediaSource->getId(),
     579            2 :                                                                immediateOutputIter->second))
     580              :                 {
     581            0 :                     RIALTO_SERVER_LOG_ERROR("Failed to apply saved immediate-output to AUDIO source");
     582            0 :                     controller->SetFailed("Operation failed");
     583              :                 }
     584              :             }
     585              :         }
     586              :     }
     587           23 :     response->set_source_id(mediaSource->getId());
     588           23 :     done->Run();
     589           25 : }
     590              : 
     591            0 : void MediaPipelineModuleService::removeSource(::google::protobuf::RpcController *controller,
     592              :                                               const ::firebolt::rialto::RemoveSourceRequest *request,
     593              :                                               ::firebolt::rialto::RemoveSourceResponse *response,
     594              :                                               ::google::protobuf::Closure *done)
     595              : {
     596            0 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     597            0 :     if (!m_mediaPipelineService.removeSource(request->session_id(), request->source_id()))
     598              :     {
     599            0 :         RIALTO_SERVER_LOG_ERROR("Remove source failed");
     600            0 :         controller->SetFailed("Operation failed");
     601              :     }
     602              :     else
     603              :     {
     604            0 :         const auto sessionSourcesIter = m_sessionSources.find(request->session_id());
     605            0 :         if (sessionSourcesIter != m_sessionSources.end())
     606              :         {
     607            0 :             sessionSourcesIter->second.erase(request->source_id());
     608              :         }
     609              :     }
     610            0 :     done->Run();
     611              : }
     612              : 
     613            2 : void MediaPipelineModuleService::allSourcesAttached(::google::protobuf::RpcController *controller,
     614              :                                                     const ::firebolt::rialto::AllSourcesAttachedRequest *request,
     615              :                                                     ::firebolt::rialto::AllSourcesAttachedResponse *response,
     616              :                                                     ::google::protobuf::Closure *done)
     617              : {
     618            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     619            2 :     if (!m_mediaPipelineService.allSourcesAttached(request->session_id()))
     620              :     {
     621            1 :         RIALTO_SERVER_LOG_ERROR("All sources attached failed");
     622            3 :         controller->SetFailed("Operation failed");
     623              :     }
     624            2 :     done->Run();
     625              : }
     626              : 
     627            2 : void MediaPipelineModuleService::play(::google::protobuf::RpcController *controller,
     628              :                                       const ::firebolt::rialto::PlayRequest *request,
     629              :                                       ::firebolt::rialto::PlayResponse *response, ::google::protobuf::Closure *done)
     630              : {
     631            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     632            2 :     bool async{false};
     633            2 :     if (!m_mediaPipelineService.play(request->session_id(), async))
     634              :     {
     635            1 :         RIALTO_SERVER_LOG_ERROR("Play failed");
     636            3 :         controller->SetFailed("Operation failed");
     637              :     }
     638            2 :     response->set_async(async);
     639            2 :     done->Run();
     640              : }
     641              : 
     642            2 : void MediaPipelineModuleService::pause(::google::protobuf::RpcController *controller,
     643              :                                        const ::firebolt::rialto::PauseRequest *request,
     644              :                                        ::firebolt::rialto::PauseResponse *response, ::google::protobuf::Closure *done)
     645              : {
     646            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     647            2 :     if (!m_mediaPipelineService.pause(request->session_id()))
     648              :     {
     649            1 :         RIALTO_SERVER_LOG_ERROR("pause failed");
     650            3 :         controller->SetFailed("Operation failed");
     651              :     }
     652            2 :     done->Run();
     653              : }
     654              : 
     655            2 : void MediaPipelineModuleService::stop(::google::protobuf::RpcController *controller,
     656              :                                       const ::firebolt::rialto::StopRequest *request,
     657              :                                       ::firebolt::rialto::StopResponse *response, ::google::protobuf::Closure *done)
     658              : {
     659            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     660            2 :     if (!m_mediaPipelineService.stop(request->session_id()))
     661              :     {
     662            1 :         RIALTO_SERVER_LOG_ERROR("Stop failed");
     663            3 :         controller->SetFailed("Operation failed");
     664              :     }
     665            2 :     done->Run();
     666              : }
     667              : 
     668            2 : void MediaPipelineModuleService::setPosition(::google::protobuf::RpcController *controller,
     669              :                                              const ::firebolt::rialto::SetPositionRequest *request,
     670              :                                              ::firebolt::rialto::SetPositionResponse *response,
     671              :                                              ::google::protobuf::Closure *done)
     672              : {
     673            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     674            2 :     if (!m_mediaPipelineService.setPosition(request->session_id(), request->position()))
     675              :     {
     676            1 :         RIALTO_SERVER_LOG_ERROR("Set Position failed");
     677            3 :         controller->SetFailed("Operation failed");
     678              :     }
     679            2 :     done->Run();
     680              : }
     681              : 
     682            2 : void MediaPipelineModuleService::haveData(::google::protobuf::RpcController *controller,
     683              :                                           const ::firebolt::rialto::HaveDataRequest *request,
     684              :                                           ::firebolt::rialto::HaveDataResponse *response,
     685              :                                           ::google::protobuf::Closure *done)
     686              : {
     687            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     688            2 :     firebolt::rialto::MediaSourceStatus status{convertMediaSourceStatus(request->status())};
     689            2 :     if (!m_mediaPipelineService.haveData(request->session_id(), status, request->num_frames(), request->request_id()))
     690              :     {
     691            1 :         RIALTO_SERVER_LOG_ERROR("Have data failed");
     692            3 :         controller->SetFailed("Operation failed");
     693              :     }
     694            2 :     done->Run();
     695              : }
     696              : 
     697            2 : void MediaPipelineModuleService::setPlaybackRate(::google::protobuf::RpcController *controller,
     698              :                                                  const ::firebolt::rialto::SetPlaybackRateRequest *request,
     699              :                                                  ::firebolt::rialto::SetPlaybackRateResponse *response,
     700              :                                                  ::google::protobuf::Closure *done)
     701              : {
     702            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     703            2 :     if (!m_mediaPipelineService.setPlaybackRate(request->session_id(), request->rate()))
     704              :     {
     705            1 :         RIALTO_SERVER_LOG_ERROR("Set playback rate failed");
     706            3 :         controller->SetFailed("Operation failed");
     707              :     }
     708            2 :     done->Run();
     709              : }
     710              : 
     711            2 : void MediaPipelineModuleService::getPosition(::google::protobuf::RpcController *controller,
     712              :                                              const ::firebolt::rialto::GetPositionRequest *request,
     713              :                                              ::firebolt::rialto::GetPositionResponse *response,
     714              :                                              ::google::protobuf::Closure *done)
     715              : {
     716            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     717            2 :     int64_t position{};
     718            2 :     if (!m_mediaPipelineService.getPosition(request->session_id(), position))
     719              :     {
     720            1 :         RIALTO_SERVER_LOG_ERROR("Get position failed");
     721            3 :         controller->SetFailed("Operation failed");
     722              :     }
     723              :     else
     724              :     {
     725            1 :         response->set_position(position);
     726              :     }
     727            2 :     done->Run();
     728              : }
     729              : 
     730            2 : void MediaPipelineModuleService::getDuration(::google::protobuf::RpcController *controller,
     731              :                                              const ::firebolt::rialto::GetDurationRequest *request,
     732              :                                              ::firebolt::rialto::GetDurationResponse *response,
     733              :                                              ::google::protobuf::Closure *done)
     734              : {
     735            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     736            2 :     int64_t duration{};
     737            2 :     if (!m_mediaPipelineService.getDuration(request->session_id(), duration))
     738              :     {
     739            1 :         RIALTO_SERVER_LOG_ERROR("Get duration failed");
     740            3 :         controller->SetFailed("Operation failed");
     741              :     }
     742              :     else
     743              :     {
     744            1 :         response->set_duration(duration);
     745              :     }
     746            2 :     done->Run();
     747              : }
     748              : 
     749            8 : void MediaPipelineModuleService::setImmediateOutput(::google::protobuf::RpcController *controller,
     750              :                                                     const ::firebolt::rialto::SetImmediateOutputRequest *request,
     751              :                                                     ::firebolt::rialto::SetImmediateOutputResponse *response,
     752              :                                                     ::google::protobuf::Closure *done)
     753              : {
     754            8 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     755            8 :     auto ipcController = dynamic_cast<firebolt::rialto::ipc::IController *>(controller);
     756            8 :     if (!ipcController)
     757              :     {
     758            0 :         RIALTO_SERVER_LOG_ERROR("ipc library provided incompatible controller object");
     759            0 :         controller->SetFailed("ipc library provided incompatible controller object");
     760            0 :         done->Run();
     761            0 :         return;
     762              :     }
     763              : 
     764            8 :     const auto clientSessionsIter = m_clientSessions.find(ipcController->getClient());
     765            8 :     if (clientSessionsIter == m_clientSessions.end())
     766              :     {
     767            0 :         RIALTO_SERVER_LOG_ERROR("Set immediate output requested by unknown client");
     768            0 :         controller->SetFailed("Operation failed");
     769            0 :         done->Run();
     770            0 :         return;
     771              :     }
     772              : 
     773            8 :     const auto sourceSessionIter = m_sessionSources.find(request->session_id());
     774            8 :     const auto ownedSessionIter = clientSessionsIter->second.find(request->session_id());
     775            8 :     if (ownedSessionIter == clientSessionsIter->second.end())
     776              :     {
     777            0 :         RIALTO_SERVER_LOG_ERROR("Set immediate output requested for session not owned by client");
     778            0 :         controller->SetFailed("Operation failed");
     779            0 :         done->Run();
     780            0 :         return;
     781              :     }
     782              : 
     783            8 :     bool success = m_mediaPipelineService.setImmediateOutput(request->session_id(), request->source_id(),
     784            8 :                                                              request->immediate_output());
     785            8 :     if (success && sourceSessionIter != m_sessionSources.end())
     786              :     {
     787            7 :         const auto sourceIter = sourceSessionIter->second.find(request->source_id());
     788            7 :         if (sourceIter != sourceSessionIter->second.end() && sourceIter->second == MediaSourceType::VIDEO)
     789              :         {
     790            6 :             std::vector<int32_t> sameSessionAudioSourceIds;
     791            6 :             std::map<int, std::vector<int32_t>> peerSessionAudioSourceIds;
     792            6 :             std::vector<int> emptyPeerSessions;
     793           16 :             for (const int sessionId : clientSessionsIter->second)
     794              :             {
     795           10 :                 const auto sessionSourcesIter = m_sessionSources.find(sessionId);
     796           10 :                 if (sessionSourcesIter == m_sessionSources.end())
     797              :                 {
     798            0 :                     continue;
     799              :                 }
     800           10 :                 bool hasAudioOrVideoSource{false};
     801           22 :                 for (const auto &[sourceId, sourceType] : sessionSourcesIter->second)
     802              :                 {
     803           12 :                     if (sourceType == MediaSourceType::AUDIO)
     804              :                     {
     805            6 :                         hasAudioOrVideoSource = true;
     806            6 :                         auto &audioSourceIds = sessionId == request->session_id() ? sameSessionAudioSourceIds
     807            3 :                                                                                   : peerSessionAudioSourceIds[sessionId];
     808            6 :                         audioSourceIds.push_back(sourceId);
     809              :                     }
     810            6 :                     else if (sourceType == MediaSourceType::VIDEO)
     811              :                     {
     812            6 :                         hasAudioOrVideoSource = true;
     813              :                     }
     814              :                 }
     815           10 :                 if (sessionId != request->session_id() && !hasAudioOrVideoSource)
     816              :                 {
     817            1 :                     emptyPeerSessions.push_back(sessionId);
     818              :                 }
     819              :             }
     820              : 
     821            6 :             m_sessionImmediateOutput[request->session_id()] = request->immediate_output();
     822            6 :             int audioSessionId{request->session_id()};
     823            6 :             std::vector<int32_t> *audioSourceIds{&sameSessionAudioSourceIds};
     824            6 :             bool pendingAudioSource{false};
     825            6 :             if (sameSessionAudioSourceIds.empty())
     826              :             {
     827            4 :                 if (peerSessionAudioSourceIds.size() == 1)
     828              :                 {
     829            1 :                     audioSessionId = peerSessionAudioSourceIds.begin()->first;
     830            1 :                     audioSourceIds = &peerSessionAudioSourceIds.begin()->second;
     831              :                 }
     832            3 :                 else if (peerSessionAudioSourceIds.size() > 1)
     833              :                 {
     834            1 :                     RIALTO_SERVER_LOG_WARN(
     835              :                         "Cannot pair immediate-output with AUDIO: multiple AUDIO sessions belong to client");
     836              :                 }
     837            2 :                 else if (emptyPeerSessions.size() == 1)
     838              :                 {
     839            1 :                     audioSessionId = emptyPeerSessions.front();
     840            1 :                     pendingAudioSource = true;
     841            1 :                     m_sessionImmediateOutput[audioSessionId] = request->immediate_output();
     842            1 :                     RIALTO_SERVER_LOG_INFO("Saved immediate-output for pending AUDIO source in session %d",
     843              :                                            audioSessionId);
     844              :                 }
     845            1 :                 else if (emptyPeerSessions.size() > 1)
     846              :                 {
     847            0 :                     RIALTO_SERVER_LOG_WARN(
     848              :                         "Cannot pair immediate-output with pending AUDIO: multiple empty sessions belong to client");
     849              :                 }
     850              :             }
     851              : 
     852            6 :             if (!pendingAudioSource && !audioSourceIds->empty())
     853              :             {
     854            3 :                 m_sessionImmediateOutput[audioSessionId] = request->immediate_output();
     855            7 :                 for (const int32_t audioSourceId : *audioSourceIds)
     856              :                 {
     857            4 :                     RIALTO_SERVER_LOG_INFO("Applying immediate-output to AUDIO source %d in session %d", audioSourceId,
     858              :                                            audioSessionId);
     859            4 :                     if (!m_mediaPipelineService.setImmediateOutput(audioSessionId, audioSourceId,
     860            4 :                                                                    request->immediate_output()))
     861              :                     {
     862            0 :                         success = false;
     863              :                     }
     864              :                 }
     865              :             }
     866            6 :         }
     867              :     }
     868            8 :     if (!success)
     869              :     {
     870            1 :         RIALTO_SERVER_LOG_ERROR("Set Immediate Output failed");
     871            3 :         controller->SetFailed("Operation failed");
     872              :     }
     873            8 :     done->Run();
     874              : }
     875              : 
     876            2 : void MediaPipelineModuleService::setReportDecodeErrors(::google::protobuf::RpcController *controller,
     877              :                                                        const ::firebolt::rialto::SetReportDecodeErrorsRequest *request,
     878              :                                                        ::firebolt::rialto::SetReportDecodeErrorsResponse *response,
     879              :                                                        ::google::protobuf::Closure *done)
     880              : {
     881            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     882            2 :     if (!m_mediaPipelineService.setReportDecodeErrors(request->session_id(), request->source_id(),
     883            2 :                                                       request->report_decode_errors()))
     884              :     {
     885            1 :         RIALTO_SERVER_LOG_ERROR("Set Report Decode Error failed");
     886            3 :         controller->SetFailed("Operation failed");
     887              :     }
     888            2 :     done->Run();
     889              : }
     890              : 
     891            3 : void MediaPipelineModuleService::setMetricSubscription(::google::protobuf::RpcController *controller,
     892              :                                                        const ::firebolt::rialto::SetMediaMetricsRequest *request,
     893              :                                                        ::firebolt::rialto::SetMediaMetricsResponse *response,
     894              :                                                        ::google::protobuf::Closure *done)
     895              : {
     896            3 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     897              : 
     898            3 :     auto ipcController = dynamic_cast<firebolt::rialto::ipc::IController *>(controller);
     899            3 :     if (!ipcController)
     900              :     {
     901            0 :         RIALTO_SERVER_LOG_ERROR("ipc library provided incompatible controller object");
     902            0 :         controller->SetFailed("ipc library provided incompatible controller object");
     903            0 :         done->Run();
     904            1 :         return;
     905              :     }
     906              : 
     907            3 :     const auto clientSessionsIter = m_clientSessions.find(ipcController->getClient());
     908            3 :     if (clientSessionsIter == m_clientSessions.end())
     909              :     {
     910            0 :         RIALTO_SERVER_LOG_ERROR("Set metric subscription requested by unknown client");
     911            0 :         controller->SetFailed("Operation failed");
     912            0 :         done->Run();
     913            0 :         return;
     914              :     }
     915              : 
     916            3 :     const auto ownedSessionIter = clientSessionsIter->second.find(request->session_id());
     917            3 :     if (ownedSessionIter == clientSessionsIter->second.end())
     918              :     {
     919            1 :         RIALTO_SERVER_LOG_ERROR("Set metric subscription requested for session not owned by client");
     920            2 :         controller->SetFailed("Operation failed");
     921            1 :         done->Run();
     922            1 :         return;
     923              :     }
     924              : 
     925            2 :     std::vector<MetricType> types;
     926            2 :     types.reserve(request->types_size());
     927            6 :     for (const auto &type : request->types())
     928              :     {
     929            4 :         types.push_back(static_cast<MetricType>(static_cast<uint32_t>(type)));
     930              :     }
     931              : 
     932            2 :     const bool result = m_mediaPipelineService.setMetricSubscription(request->session_id(), types);
     933            2 :     response->set_result(result);
     934            2 :     if (!result)
     935              :     {
     936            1 :         RIALTO_SERVER_LOG_ERROR("Set Metric Subscription failed");
     937            3 :         controller->SetFailed("Operation failed");
     938              :     }
     939            2 :     done->Run();
     940              : }
     941              : 
     942            2 : void MediaPipelineModuleService::getQueuedFrames(::google::protobuf::RpcController *controller,
     943              :                                                  const ::firebolt::rialto::GetQueuedFramesRequest *request,
     944              :                                                  ::firebolt::rialto::GetQueuedFramesResponse *response,
     945              :                                                  ::google::protobuf::Closure *done)
     946              : {
     947            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     948              :     uint32_t queuedFramesNumber;
     949            2 :     if (!m_mediaPipelineService.getQueuedFrames(request->session_id(), request->source_id(), queuedFramesNumber))
     950              :     {
     951            1 :         RIALTO_SERVER_LOG_ERROR("Get queued frames failed");
     952            3 :         controller->SetFailed("Operation failed");
     953              :     }
     954              :     else
     955              :     {
     956            1 :         response->set_queued_frames(queuedFramesNumber);
     957              :     }
     958            2 :     done->Run();
     959              : }
     960              : 
     961            2 : void MediaPipelineModuleService::getImmediateOutput(::google::protobuf::RpcController *controller,
     962              :                                                     const ::firebolt::rialto::GetImmediateOutputRequest *request,
     963              :                                                     ::firebolt::rialto::GetImmediateOutputResponse *response,
     964              :                                                     ::google::protobuf::Closure *done)
     965              : {
     966            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     967              :     bool immediateOutputState;
     968            2 :     if (!m_mediaPipelineService.getImmediateOutput(request->session_id(), request->source_id(), immediateOutputState))
     969              :     {
     970            1 :         RIALTO_SERVER_LOG_ERROR("Get Immediate Output failed");
     971            3 :         controller->SetFailed("Operation failed");
     972              :     }
     973              :     else
     974              :     {
     975            1 :         response->set_immediate_output(immediateOutputState);
     976              :     }
     977            2 :     done->Run();
     978              : }
     979              : 
     980            2 : void MediaPipelineModuleService::getStats(::google::protobuf::RpcController *controller,
     981              :                                           const ::firebolt::rialto::GetStatsRequest *request,
     982              :                                           ::firebolt::rialto::GetStatsResponse *response,
     983              :                                           ::google::protobuf::Closure *done)
     984              : {
     985            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     986              :     uint64_t renderedFrames;
     987              :     uint64_t droppedFrames;
     988            2 :     if (!m_mediaPipelineService.getStats(request->session_id(), request->source_id(), renderedFrames, droppedFrames))
     989              :     {
     990            1 :         RIALTO_SERVER_LOG_ERROR("Get stats failed");
     991            3 :         controller->SetFailed("Operation failed");
     992              :     }
     993              :     else
     994              :     {
     995            1 :         response->set_rendered_frames(renderedFrames);
     996            1 :         response->set_dropped_frames(droppedFrames);
     997              :     }
     998            2 :     done->Run();
     999              : }
    1000              : 
    1001            3 : void MediaPipelineModuleService::getFrameCounters(::google::protobuf::RpcController *controller,
    1002              :                                                   const ::firebolt::rialto::GetFrameCountersRequest *request,
    1003              :                                                   ::firebolt::rialto::GetFrameCountersResponse *response,
    1004              :                                                   ::google::protobuf::Closure *done)
    1005              : {
    1006            3 :     RIALTO_SERVER_LOG_DEBUG("GetFrameCounters request sessionId: %d, sourceId: %d", request->session_id(),
    1007              :                             request->source_id());
    1008              : 
    1009            3 :     auto ipcController = dynamic_cast<firebolt::rialto::ipc::IController *>(controller);
    1010            3 :     if (!ipcController)
    1011              :     {
    1012            0 :         RIALTO_SERVER_LOG_ERROR("ipc library provided incompatible controller object");
    1013            0 :         controller->SetFailed("ipc library provided incompatible controller object");
    1014            0 :         done->Run();
    1015            1 :         return;
    1016              :     }
    1017              : 
    1018            3 :     const auto clientSessionsIter = m_clientSessions.find(ipcController->getClient());
    1019            3 :     if (clientSessionsIter == m_clientSessions.end())
    1020              :     {
    1021            0 :         RIALTO_SERVER_LOG_ERROR("GetFrameCounters requested by unknown client");
    1022            0 :         controller->SetFailed("Operation failed");
    1023            0 :         done->Run();
    1024            0 :         return;
    1025              :     }
    1026              : 
    1027            3 :     const auto ownedSessionIter = clientSessionsIter->second.find(request->session_id());
    1028            3 :     if (ownedSessionIter == clientSessionsIter->second.end())
    1029              :     {
    1030            1 :         RIALTO_SERVER_LOG_ERROR("GetFrameCounters requested for session not owned by client");
    1031            2 :         controller->SetFailed("Operation failed");
    1032            1 :         done->Run();
    1033            1 :         return;
    1034              :     }
    1035              : 
    1036              :     uint64_t renderedFrames;
    1037              :     uint64_t droppedFrames;
    1038              :     uint64_t corruptedFrames;
    1039              :     uint64_t timestamp;
    1040            2 :     if (!m_mediaPipelineService.getFrameCounters(request->session_id(), request->source_id(), renderedFrames,
    1041              :                                                  droppedFrames, corruptedFrames, timestamp))
    1042              :     {
    1043            1 :         RIALTO_SERVER_LOG_ERROR("GetFrameCounters failed for sessionId: %d, sourceId: %d", request->session_id(),
    1044              :                                 request->source_id());
    1045            3 :         controller->SetFailed("Operation failed");
    1046              :     }
    1047              :     else
    1048              :     {
    1049            1 :         response->set_rendered_frames(renderedFrames);
    1050            1 :         response->set_dropped_frames(droppedFrames);
    1051            1 :         response->set_corrupted_frames(corruptedFrames);
    1052            1 :         response->set_timestamp(timestamp);
    1053            1 :         RIALTO_SERVER_LOG_DEBUG("GetFrameCounters response sessionId: %d, sourceId: %d, rendered: %llu, dropped: %llu, "
    1054              :                                 "corrupted: %llu, timestamp: %llu",
    1055              :                                 request->session_id(), request->source_id(),
    1056              :                                 static_cast<unsigned long long>(renderedFrames),  // NOLINT(runtime/int)
    1057              :                                 static_cast<unsigned long long>(droppedFrames),   // NOLINT(runtime/int)
    1058              :                                 static_cast<unsigned long long>(corruptedFrames), // NOLINT(runtime/int)
    1059              :                                 static_cast<unsigned long long>(timestamp));      // NOLINT(runtime/int)
    1060              :     }
    1061            2 :     done->Run();
    1062              : }
    1063              : 
    1064            2 : void MediaPipelineModuleService::renderFrame(::google::protobuf::RpcController *controller,
    1065              :                                              const ::firebolt::rialto::RenderFrameRequest *request,
    1066              :                                              ::firebolt::rialto::RenderFrameResponse *response,
    1067              :                                              ::google::protobuf::Closure *done)
    1068              : {
    1069            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1070              : 
    1071            2 :     if (!m_mediaPipelineService.renderFrame(request->session_id()))
    1072              :     {
    1073            1 :         RIALTO_SERVER_LOG_ERROR("Render frame");
    1074            3 :         controller->SetFailed("Operation failed");
    1075              :     }
    1076              : 
    1077            2 :     done->Run();
    1078              : }
    1079              : 
    1080            2 : void MediaPipelineModuleService::setVolume(::google::protobuf::RpcController *controller,
    1081              :                                            const ::firebolt::rialto::SetVolumeRequest *request,
    1082              :                                            ::firebolt::rialto::SetVolumeResponse *response,
    1083              :                                            ::google::protobuf::Closure *done)
    1084              : {
    1085            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1086              : 
    1087            2 :     if (!m_mediaPipelineService.setVolume(request->session_id(), request->volume(), request->volume_duration(),
    1088            4 :                                           convertEaseType(request->ease_type())))
    1089              :     {
    1090            1 :         RIALTO_SERVER_LOG_ERROR("Set volume failed.");
    1091            3 :         controller->SetFailed("Operation failed");
    1092              :     }
    1093              : 
    1094            2 :     done->Run();
    1095              : }
    1096              : 
    1097            2 : void MediaPipelineModuleService::getVolume(::google::protobuf::RpcController *controller,
    1098              :                                            const ::firebolt::rialto::GetVolumeRequest *request,
    1099              :                                            ::firebolt::rialto::GetVolumeResponse *response,
    1100              :                                            ::google::protobuf::Closure *done)
    1101              : {
    1102            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1103            2 :     double volume{};
    1104              : 
    1105            2 :     if (!m_mediaPipelineService.getVolume(request->session_id(), volume))
    1106              :     {
    1107            1 :         RIALTO_SERVER_LOG_ERROR("Get volume failed.");
    1108            3 :         controller->SetFailed("Operation failed");
    1109              :     }
    1110              :     else
    1111              :     {
    1112            1 :         response->set_volume(volume);
    1113              :     }
    1114              : 
    1115            2 :     done->Run();
    1116              : }
    1117              : 
    1118            2 : void MediaPipelineModuleService::setMute(::google::protobuf::RpcController *controller,
    1119              :                                          const ::firebolt::rialto::SetMuteRequest *request,
    1120              :                                          ::firebolt::rialto::SetMuteResponse *response, ::google::protobuf::Closure *done)
    1121              : {
    1122            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1123              : 
    1124            2 :     if (!m_mediaPipelineService.setMute(request->session_id(), request->source_id(), request->mute()))
    1125              :     {
    1126            1 :         RIALTO_SERVER_LOG_ERROR("Set mute failed.");
    1127            3 :         controller->SetFailed("Operation failed");
    1128              :     }
    1129              : 
    1130            2 :     done->Run();
    1131              : }
    1132              : 
    1133            2 : void MediaPipelineModuleService::getMute(::google::protobuf::RpcController *controller,
    1134              :                                          const ::firebolt::rialto::GetMuteRequest *request,
    1135              :                                          ::firebolt::rialto::GetMuteResponse *response, ::google::protobuf::Closure *done)
    1136              : {
    1137            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1138            2 :     bool mute{};
    1139              : 
    1140            2 :     if (!m_mediaPipelineService.getMute(request->session_id(), request->source_id(), mute))
    1141              :     {
    1142            1 :         RIALTO_SERVER_LOG_ERROR("Get mute failed.");
    1143            3 :         controller->SetFailed("Operation failed");
    1144              :     }
    1145              :     else
    1146              :     {
    1147            1 :         response->set_mute(mute);
    1148              :     }
    1149              : 
    1150            2 :     done->Run();
    1151              : }
    1152              : 
    1153            2 : void MediaPipelineModuleService::setTextTrackIdentifier(::google::protobuf::RpcController *controller,
    1154              :                                                         const ::firebolt::rialto::SetTextTrackIdentifierRequest *request,
    1155              :                                                         ::firebolt::rialto::SetTextTrackIdentifierResponse *response,
    1156              :                                                         ::google::protobuf::Closure *done)
    1157              : {
    1158            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1159              : 
    1160            2 :     if (!m_mediaPipelineService.setTextTrackIdentifier(request->session_id(), request->text_track_identifier()))
    1161              :     {
    1162            1 :         RIALTO_SERVER_LOG_ERROR("Set text track identifier failed.");
    1163            3 :         controller->SetFailed("Operation failed");
    1164              :     }
    1165              : 
    1166            2 :     done->Run();
    1167              : }
    1168              : 
    1169            2 : void MediaPipelineModuleService::getTextTrackIdentifier(::google::protobuf::RpcController *controller,
    1170              :                                                         const ::firebolt::rialto::GetTextTrackIdentifierRequest *request,
    1171              :                                                         ::firebolt::rialto::GetTextTrackIdentifierResponse *response,
    1172              :                                                         ::google::protobuf::Closure *done)
    1173              : {
    1174            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1175            2 :     std::string textTrackIdentifier{};
    1176              : 
    1177            2 :     if (!m_mediaPipelineService.getTextTrackIdentifier(request->session_id(), textTrackIdentifier))
    1178              :     {
    1179            1 :         RIALTO_SERVER_LOG_ERROR("Get TextTrackIdentifier failed.");
    1180            3 :         controller->SetFailed("Operation failed");
    1181              :     }
    1182              :     else
    1183              :     {
    1184              :         response->set_text_track_identifier(textTrackIdentifier);
    1185              :     }
    1186              : 
    1187            2 :     done->Run();
    1188              : }
    1189              : 
    1190            2 : void MediaPipelineModuleService::setLowLatency(::google::protobuf::RpcController *controller,
    1191              :                                                const ::firebolt::rialto::SetLowLatencyRequest *request,
    1192              :                                                ::firebolt::rialto::SetLowLatencyResponse *response,
    1193              :                                                ::google::protobuf::Closure *done)
    1194              : {
    1195            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1196              : 
    1197            2 :     if (!m_mediaPipelineService.setLowLatency(request->session_id(), request->low_latency()))
    1198              :     {
    1199            1 :         RIALTO_SERVER_LOG_ERROR("Set low latency failed.");
    1200            3 :         controller->SetFailed("Operation failed");
    1201              :     }
    1202              : 
    1203            2 :     done->Run();
    1204              : }
    1205              : 
    1206            2 : void MediaPipelineModuleService::setSync(::google::protobuf::RpcController *controller,
    1207              :                                          const ::firebolt::rialto::SetSyncRequest *request,
    1208              :                                          ::firebolt::rialto::SetSyncResponse *response, ::google::protobuf::Closure *done)
    1209              : {
    1210            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1211              : 
    1212            2 :     if (!m_mediaPipelineService.setSync(request->session_id(), request->sync()))
    1213              :     {
    1214            1 :         RIALTO_SERVER_LOG_ERROR("Set sync failed.");
    1215            3 :         controller->SetFailed("Operation failed");
    1216              :     }
    1217              : 
    1218            2 :     done->Run();
    1219              : }
    1220              : 
    1221            2 : void MediaPipelineModuleService::getSync(::google::protobuf::RpcController *controller,
    1222              :                                          const ::firebolt::rialto::GetSyncRequest *request,
    1223              :                                          ::firebolt::rialto::GetSyncResponse *response, ::google::protobuf::Closure *done)
    1224              : {
    1225            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1226            2 :     bool sync{};
    1227              : 
    1228            2 :     if (!m_mediaPipelineService.getSync(request->session_id(), sync))
    1229              :     {
    1230            1 :         RIALTO_SERVER_LOG_ERROR("Get sync failed.");
    1231            3 :         controller->SetFailed("Operation failed");
    1232              :     }
    1233              :     else
    1234              :     {
    1235            1 :         response->set_sync(sync);
    1236              :     }
    1237              : 
    1238            2 :     done->Run();
    1239              : }
    1240              : 
    1241            2 : void MediaPipelineModuleService::setSyncOff(::google::protobuf::RpcController *controller,
    1242              :                                             const ::firebolt::rialto::SetSyncOffRequest *request,
    1243              :                                             ::firebolt::rialto::SetSyncOffResponse *response,
    1244              :                                             ::google::protobuf::Closure *done)
    1245              : {
    1246            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1247              : 
    1248            2 :     if (!m_mediaPipelineService.setSyncOff(request->session_id(), request->sync_off()))
    1249              :     {
    1250            1 :         RIALTO_SERVER_LOG_ERROR("Set sync off failed.");
    1251            3 :         controller->SetFailed("Operation failed");
    1252              :     }
    1253              : 
    1254            2 :     done->Run();
    1255              : }
    1256              : 
    1257            2 : void MediaPipelineModuleService::setStreamSyncMode(::google::protobuf::RpcController *controller,
    1258              :                                                    const ::firebolt::rialto::SetStreamSyncModeRequest *request,
    1259              :                                                    ::firebolt::rialto::SetStreamSyncModeResponse *response,
    1260              :                                                    ::google::protobuf::Closure *done)
    1261              : {
    1262            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1263              : 
    1264            2 :     if (!m_mediaPipelineService.setStreamSyncMode(request->session_id(), request->source_id(),
    1265              :                                                   request->stream_sync_mode()))
    1266              :     {
    1267            1 :         RIALTO_SERVER_LOG_ERROR("Set stream sync mode failed.");
    1268            3 :         controller->SetFailed("Operation failed");
    1269              :     }
    1270              : 
    1271            2 :     done->Run();
    1272              : }
    1273              : 
    1274            2 : void MediaPipelineModuleService::getStreamSyncMode(::google::protobuf::RpcController *controller,
    1275              :                                                    const ::firebolt::rialto::GetStreamSyncModeRequest *request,
    1276              :                                                    ::firebolt::rialto::GetStreamSyncModeResponse *response,
    1277              :                                                    ::google::protobuf::Closure *done)
    1278              : {
    1279            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1280            2 :     int32_t streamSyncMode{};
    1281              : 
    1282            2 :     if (!m_mediaPipelineService.getStreamSyncMode(request->session_id(), streamSyncMode))
    1283              :     {
    1284            1 :         RIALTO_SERVER_LOG_ERROR("Get stream sync mode failed.");
    1285            3 :         controller->SetFailed("Operation failed");
    1286              :     }
    1287              :     else
    1288              :     {
    1289            1 :         response->set_stream_sync_mode(streamSyncMode);
    1290              :     }
    1291              : 
    1292            2 :     done->Run();
    1293              : }
    1294              : 
    1295            2 : void MediaPipelineModuleService::flush(::google::protobuf::RpcController *controller,
    1296              :                                        const ::firebolt::rialto::FlushRequest *request,
    1297              :                                        ::firebolt::rialto::FlushResponse *response, ::google::protobuf::Closure *done)
    1298              : {
    1299            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1300              : 
    1301            2 :     bool isAsync{false};
    1302            2 :     if (!m_mediaPipelineService.flush(request->session_id(), request->source_id(), request->reset_time(), isAsync))
    1303              :     {
    1304            1 :         RIALTO_SERVER_LOG_ERROR("Flush failed.");
    1305            3 :         controller->SetFailed("Operation failed");
    1306              :     }
    1307            2 :     response->set_async(isAsync);
    1308              : 
    1309            2 :     done->Run();
    1310              : }
    1311              : 
    1312            2 : void MediaPipelineModuleService::setSourcePosition(::google::protobuf::RpcController *controller,
    1313              :                                                    const ::firebolt::rialto::SetSourcePositionRequest *request,
    1314              :                                                    ::firebolt::rialto::SetSourcePositionResponse *response,
    1315              :                                                    ::google::protobuf::Closure *done)
    1316              : {
    1317            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1318            4 :     if (!m_mediaPipelineService.setSourcePosition(request->session_id(), request->source_id(), request->position(),
    1319            2 :                                                   request->reset_time(), request->applied_rate(),
    1320              :                                                   request->stop_position()))
    1321              :     {
    1322            1 :         RIALTO_SERVER_LOG_ERROR("Set Source Position failed.");
    1323            3 :         controller->SetFailed("Operation failed");
    1324              :     }
    1325            2 :     done->Run();
    1326              : }
    1327              : 
    1328            0 : void MediaPipelineModuleService::setSubtitleOffset(::google::protobuf::RpcController *controller,
    1329              :                                                    const ::firebolt::rialto::SetSubtitleOffsetRequest *request,
    1330              :                                                    ::firebolt::rialto::SetSubtitleOffsetResponse *response,
    1331              :                                                    ::google::protobuf::Closure *done)
    1332              : {
    1333            0 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1334            0 :     if (!m_mediaPipelineService.setSubtitleOffset(request->session_id(), request->source_id(), request->position()))
    1335              :     {
    1336            0 :         RIALTO_SERVER_LOG_ERROR("Set Subtitle Offset failed.");
    1337            0 :         controller->SetFailed("Operation failed");
    1338              :     }
    1339            0 :     done->Run();
    1340              : }
    1341              : 
    1342            2 : void MediaPipelineModuleService::processAudioGap(::google::protobuf::RpcController *controller,
    1343              :                                                  const ::firebolt::rialto::ProcessAudioGapRequest *request,
    1344              :                                                  ::firebolt::rialto::ProcessAudioGapResponse *response,
    1345              :                                                  ::google::protobuf::Closure *done)
    1346              : {
    1347            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1348            2 :     if (!m_mediaPipelineService.processAudioGap(request->session_id(), request->position(), request->duration(),
    1349            2 :                                                 request->discontinuity_gap(), request->audio_aac()))
    1350              :     {
    1351            1 :         RIALTO_SERVER_LOG_ERROR("Process audio gap failed.");
    1352            3 :         controller->SetFailed("Operation failed");
    1353              :     }
    1354            2 :     done->Run();
    1355              : }
    1356              : 
    1357            2 : void MediaPipelineModuleService::setBufferingLimit(::google::protobuf::RpcController *controller,
    1358              :                                                    const ::firebolt::rialto::SetBufferingLimitRequest *request,
    1359              :                                                    ::firebolt::rialto::SetBufferingLimitResponse *response,
    1360              :                                                    ::google::protobuf::Closure *done)
    1361              : {
    1362            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1363            2 :     if (!m_mediaPipelineService.setBufferingLimit(request->session_id(), request->limit_buffering_ms()))
    1364              :     {
    1365            1 :         RIALTO_SERVER_LOG_ERROR("Set buffering limit failed.");
    1366            3 :         controller->SetFailed("Operation failed");
    1367              :     }
    1368            2 :     done->Run();
    1369              : }
    1370              : 
    1371            2 : void MediaPipelineModuleService::getBufferingLimit(::google::protobuf::RpcController *controller,
    1372              :                                                    const ::firebolt::rialto::GetBufferingLimitRequest *request,
    1373              :                                                    ::firebolt::rialto::GetBufferingLimitResponse *response,
    1374              :                                                    ::google::protobuf::Closure *done)
    1375              : {
    1376            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1377            2 :     uint32_t bufferingLimit{};
    1378              : 
    1379            2 :     if (!m_mediaPipelineService.getBufferingLimit(request->session_id(), bufferingLimit))
    1380              :     {
    1381            1 :         RIALTO_SERVER_LOG_ERROR("Get buffering limit failed.");
    1382            3 :         controller->SetFailed("Operation failed");
    1383              :     }
    1384              :     else
    1385              :     {
    1386            1 :         response->set_limit_buffering_ms(bufferingLimit);
    1387              :     }
    1388              : 
    1389            2 :     done->Run();
    1390              : }
    1391              : 
    1392            2 : void MediaPipelineModuleService::setUseBuffering(::google::protobuf::RpcController *controller,
    1393              :                                                  const ::firebolt::rialto::SetUseBufferingRequest *request,
    1394              :                                                  ::firebolt::rialto::SetUseBufferingResponse *response,
    1395              :                                                  ::google::protobuf::Closure *done)
    1396              : {
    1397            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1398            2 :     if (!m_mediaPipelineService.setUseBuffering(request->session_id(), request->use_buffering()))
    1399              :     {
    1400            1 :         RIALTO_SERVER_LOG_ERROR("Set use buffering failed.");
    1401            3 :         controller->SetFailed("Operation failed");
    1402              :     }
    1403            2 :     done->Run();
    1404              : }
    1405              : 
    1406            2 : void MediaPipelineModuleService::getUseBuffering(::google::protobuf::RpcController *controller,
    1407              :                                                  const ::firebolt::rialto::GetUseBufferingRequest *request,
    1408              :                                                  ::firebolt::rialto::GetUseBufferingResponse *response,
    1409              :                                                  ::google::protobuf::Closure *done)
    1410              : {
    1411            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1412            2 :     bool useBuffering{};
    1413              : 
    1414            2 :     if (!m_mediaPipelineService.getUseBuffering(request->session_id(), useBuffering))
    1415              :     {
    1416            1 :         RIALTO_SERVER_LOG_ERROR("Get use buffering failed.");
    1417            3 :         controller->SetFailed("Operation failed");
    1418              :     }
    1419              :     else
    1420              :     {
    1421            1 :         response->set_use_buffering(useBuffering);
    1422              :     }
    1423              : 
    1424            2 :     done->Run();
    1425              : }
    1426              : } // namespace firebolt::rialto::server::ipc
        

Generated by: LCOV version 2.0-1