LCOV - code coverage report
Current view: top level - media/server/ipc/source - MediaPipelineModuleService.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 87.6 % 450 394
Test Date: 2025-06-05 13:57:59 Functions: 98.1 % 52 51

            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 "MediaPipelineClient.h"
      23              : #include "RialtoCommonModule.h"
      24              : #include "RialtoServerLogging.h"
      25              : #include <IIpcController.h>
      26              : #include <algorithm>
      27              : #include <cstdint>
      28              : #include <unordered_map>
      29              : 
      30              : namespace
      31              : {
      32           20 : int generateSessionId()
      33              : {
      34              :     static int sessionId{0};
      35           20 :     return sessionId++;
      36              : }
      37              : 
      38            2 : firebolt::rialto::MediaType convertMediaType(const firebolt::rialto::LoadRequest_MediaType &mediaType)
      39              : {
      40            2 :     switch (mediaType)
      41              :     {
      42            0 :     case firebolt::rialto::LoadRequest_MediaType::LoadRequest_MediaType_UNKNOWN:
      43              :     {
      44            0 :         return firebolt::rialto::MediaType::UNKNOWN;
      45              :     }
      46            2 :     case firebolt::rialto::LoadRequest_MediaType::LoadRequest_MediaType_MSE:
      47              :     {
      48            2 :         return firebolt::rialto::MediaType::MSE;
      49              :     }
      50              :     }
      51            0 :     return firebolt::rialto::MediaType::UNKNOWN;
      52              : }
      53              : 
      54            2 : firebolt::rialto::EaseType convertEaseType(const firebolt::rialto::SetVolumeRequest_EaseType &easeType)
      55              : {
      56            2 :     switch (easeType)
      57              :     {
      58            2 :     case firebolt::rialto::SetVolumeRequest_EaseType::SetVolumeRequest_EaseType_EASE_LINEAR:
      59              :     {
      60            2 :         return firebolt::rialto::EaseType::EASE_LINEAR;
      61              :     }
      62            0 :     case firebolt::rialto::SetVolumeRequest_EaseType::SetVolumeRequest_EaseType_EASE_IN_CUBIC:
      63              :     {
      64            0 :         return firebolt::rialto::EaseType::EASE_IN_CUBIC;
      65              :     }
      66            0 :     case firebolt::rialto::SetVolumeRequest_EaseType::SetVolumeRequest_EaseType_EASE_OUT_CUBIC:
      67              :     {
      68            0 :         return firebolt::rialto::EaseType::EASE_OUT_CUBIC;
      69              :     }
      70              :     }
      71            0 :     return firebolt::rialto::EaseType::EASE_LINEAR;
      72              : }
      73              : 
      74              : firebolt::rialto::MediaSourceStatus
      75            2 : convertMediaSourceStatus(const firebolt::rialto::HaveDataRequest_MediaSourceStatus &status)
      76              : {
      77            2 :     switch (status)
      78              :     {
      79            0 :     case firebolt::rialto::HaveDataRequest_MediaSourceStatus_UNKNOWN:
      80              :     {
      81            0 :         return firebolt::rialto::MediaSourceStatus::ERROR;
      82              :     }
      83            0 :     case firebolt::rialto::HaveDataRequest_MediaSourceStatus_OK:
      84              :     {
      85            0 :         return firebolt::rialto::MediaSourceStatus::OK;
      86              :     }
      87            0 :     case firebolt::rialto::HaveDataRequest_MediaSourceStatus_EOS:
      88              :     {
      89            0 :         return firebolt::rialto::MediaSourceStatus::EOS;
      90              :     }
      91            0 :     case firebolt::rialto::HaveDataRequest_MediaSourceStatus_ERROR:
      92              :     {
      93            0 :         return firebolt::rialto::MediaSourceStatus::ERROR;
      94              :     }
      95            2 :     case firebolt::rialto::HaveDataRequest_MediaSourceStatus_CODEC_CHANGED:
      96              :     {
      97            2 :         return firebolt::rialto::MediaSourceStatus::CODEC_CHANGED;
      98              :     }
      99            0 :     case firebolt::rialto::HaveDataRequest_MediaSourceStatus_NO_AVAILABLE_SAMPLES:
     100              :     {
     101            0 :         return firebolt::rialto::MediaSourceStatus::NO_AVAILABLE_SAMPLES;
     102              :     }
     103              :     }
     104            0 :     return firebolt::rialto::MediaSourceStatus::ERROR;
     105              : }
     106              : 
     107            9 : firebolt::rialto::SourceConfigType convertConfigType(const firebolt::rialto::AttachSourceRequest_ConfigType &configType)
     108              : {
     109            9 :     switch (configType)
     110              :     {
     111            1 :     case firebolt::rialto::AttachSourceRequest_ConfigType_CONFIG_TYPE_UNKNOWN:
     112              :     {
     113            1 :         return firebolt::rialto::SourceConfigType::UNKNOWN;
     114              :     }
     115            5 :     case firebolt::rialto::AttachSourceRequest_ConfigType_CONFIG_TYPE_AUDIO:
     116              :     {
     117            5 :         return firebolt::rialto::SourceConfigType::AUDIO;
     118              :     }
     119            1 :     case firebolt::rialto::AttachSourceRequest_ConfigType_CONFIG_TYPE_VIDEO:
     120              :     {
     121            1 :         return firebolt::rialto::SourceConfigType::VIDEO;
     122              :     }
     123            1 :     case firebolt::rialto::AttachSourceRequest_ConfigType_CONFIG_TYPE_VIDEO_DOLBY_VISION:
     124              :     {
     125            1 :         return firebolt::rialto::SourceConfigType::VIDEO_DOLBY_VISION;
     126              :     }
     127            1 :     case firebolt::rialto::AttachSourceRequest_ConfigType_CONFIG_TYPE_SUBTITLE:
     128              :     {
     129            1 :         return firebolt::rialto::SourceConfigType::SUBTITLE;
     130              :     }
     131              :     }
     132            0 :     return firebolt::rialto::SourceConfigType::UNKNOWN;
     133              : }
     134              : 
     135              : firebolt::rialto::SegmentAlignment
     136            7 : convertSegmentAlignment(const firebolt::rialto::AttachSourceRequest_SegmentAlignment &alignment)
     137              : {
     138            7 :     switch (alignment)
     139              :     {
     140            7 :     case firebolt::rialto::AttachSourceRequest_SegmentAlignment_ALIGNMENT_UNDEFINED:
     141              :     {
     142            7 :         return firebolt::rialto::SegmentAlignment::UNDEFINED;
     143              :     }
     144            0 :     case firebolt::rialto::AttachSourceRequest_SegmentAlignment_ALIGNMENT_NAL:
     145              :     {
     146            0 :         return firebolt::rialto::SegmentAlignment::NAL;
     147              :     }
     148            0 :     case firebolt::rialto::AttachSourceRequest_SegmentAlignment_ALIGNMENT_AU:
     149              :     {
     150            0 :         return firebolt::rialto::SegmentAlignment::AU;
     151              :     }
     152              :     }
     153              : 
     154            0 :     return firebolt::rialto::SegmentAlignment::UNDEFINED;
     155              : }
     156              : 
     157            7 : firebolt::rialto::StreamFormat convertStreamFormat(const firebolt::rialto::AttachSourceRequest_StreamFormat &streamFormat)
     158              : {
     159            7 :     switch (streamFormat)
     160              :     {
     161            1 :     case firebolt::rialto::AttachSourceRequest_StreamFormat_STREAM_FORMAT_RAW:
     162              :     {
     163            1 :         return firebolt::rialto::StreamFormat::RAW;
     164              :     }
     165            0 :     case firebolt::rialto::AttachSourceRequest_StreamFormat_STREAM_FORMAT_AVC:
     166              :     {
     167            0 :         return firebolt::rialto::StreamFormat::AVC;
     168              :     }
     169            0 :     case firebolt::rialto::AttachSourceRequest_StreamFormat_STREAM_FORMAT_BYTE_STREAM:
     170              :     {
     171            0 :         return firebolt::rialto::StreamFormat::BYTE_STREAM;
     172              :     }
     173            0 :     case firebolt::rialto::AttachSourceRequest_StreamFormat_STREAM_FORMAT_HVC1:
     174              :     {
     175            0 :         return firebolt::rialto::StreamFormat::HVC1;
     176              :     }
     177            0 :     case firebolt::rialto::AttachSourceRequest_StreamFormat_STREAM_FORMAT_HEV1:
     178              :     {
     179            0 :         return firebolt::rialto::StreamFormat::HEV1;
     180              :     }
     181            6 :     default:
     182            6 :         return firebolt::rialto::StreamFormat::UNDEFINED;
     183              :     }
     184              : }
     185              : 
     186            1 : firebolt::rialto::CodecDataType convertCodecDataType(const firebolt::rialto::AttachSourceRequest_CodecData_Type &type)
     187              : {
     188            1 :     if (firebolt::rialto::AttachSourceRequest_CodecData_Type_STRING == type)
     189              :     {
     190            0 :         return firebolt::rialto::CodecDataType::STRING;
     191              :     }
     192            1 :     return firebolt::rialto::CodecDataType::BUFFER;
     193              : }
     194              : 
     195            1 : firebolt::rialto::Format convertFormat(const firebolt::rialto::AttachSourceRequest_AudioConfig_Format &format)
     196              : {
     197              :     static const std::unordered_map<firebolt::rialto::AttachSourceRequest_AudioConfig_Format, firebolt::rialto::Format>
     198              :         kFormatConversionMap{
     199              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S8, firebolt::rialto::Format::S8},
     200              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U8, firebolt::rialto::Format::U8},
     201              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S16LE, firebolt::rialto::Format::S16LE},
     202              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S16BE, firebolt::rialto::Format::S16BE},
     203              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U16LE, firebolt::rialto::Format::U16LE},
     204              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U16BE, firebolt::rialto::Format::U16BE},
     205              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S24_32LE, firebolt::rialto::Format::S24_32LE},
     206              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S24_32BE, firebolt::rialto::Format::S24_32BE},
     207              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U24_32LE, firebolt::rialto::Format::U24_32LE},
     208              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U24_32BE, firebolt::rialto::Format::U24_32BE},
     209              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S32LE, firebolt::rialto::Format::S32LE},
     210              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S32BE, firebolt::rialto::Format::S32BE},
     211              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U32LE, firebolt::rialto::Format::U32LE},
     212              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U32BE, firebolt::rialto::Format::U32BE},
     213              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S24LE, firebolt::rialto::Format::S24LE},
     214              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S24BE, firebolt::rialto::Format::S24BE},
     215              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U24LE, firebolt::rialto::Format::U24LE},
     216              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U24BE, firebolt::rialto::Format::U24BE},
     217              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S20LE, firebolt::rialto::Format::S20LE},
     218              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S20BE, firebolt::rialto::Format::S20BE},
     219              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U20LE, firebolt::rialto::Format::U20LE},
     220              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U20BE, firebolt::rialto::Format::U20BE},
     221              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S18LE, firebolt::rialto::Format::S18LE},
     222              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_S18BE, firebolt::rialto::Format::S18BE},
     223              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U18LE, firebolt::rialto::Format::U18LE},
     224              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_U18BE, firebolt::rialto::Format::U18BE},
     225              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_F32LE, firebolt::rialto::Format::F32LE},
     226              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_F32BE, firebolt::rialto::Format::F32BE},
     227              :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_F64LE, firebolt::rialto::Format::F64LE},
     228            3 :             {firebolt::rialto::AttachSourceRequest_AudioConfig_Format_F64BE, firebolt::rialto::Format::F64BE}};
     229            1 :     const auto kIt = kFormatConversionMap.find(format);
     230            1 :     if (kFormatConversionMap.end() != kIt)
     231              :     {
     232            1 :         return kIt->second;
     233              :     }
     234            0 :     return firebolt::rialto::Format::S8;
     235              : }
     236              : 
     237            1 : firebolt::rialto::Layout convertLayout(const firebolt::rialto::AttachSourceRequest_AudioConfig_Layout &layout)
     238              : {
     239              :     static const std::unordered_map<firebolt::rialto::AttachSourceRequest_AudioConfig_Layout, firebolt::rialto::Layout>
     240              :         kLayoutConversionMap{{firebolt::rialto::AttachSourceRequest_AudioConfig_Layout_INTERLEAVED,
     241              :                               firebolt::rialto::Layout::INTERLEAVED},
     242              :                              {firebolt::rialto::AttachSourceRequest_AudioConfig_Layout_NON_INTERLEAVED,
     243            3 :                               firebolt::rialto::Layout::NON_INTERLEAVED}};
     244            1 :     const auto kIt = kLayoutConversionMap.find(layout);
     245            1 :     if (kLayoutConversionMap.end() != kIt)
     246              :     {
     247            1 :         return kIt->second;
     248              :     }
     249            0 :     return firebolt::rialto::Layout::INTERLEAVED;
     250              : }
     251              : } // namespace
     252              : 
     253              : namespace firebolt::rialto::server::ipc
     254              : {
     255            1 : std::shared_ptr<IMediaPipelineModuleServiceFactory> IMediaPipelineModuleServiceFactory::createFactory()
     256              : {
     257            1 :     std::shared_ptr<IMediaPipelineModuleServiceFactory> factory;
     258              : 
     259              :     try
     260              :     {
     261            1 :         factory = std::make_shared<MediaPipelineModuleServiceFactory>();
     262              :     }
     263            0 :     catch (const std::exception &e)
     264              :     {
     265            0 :         RIALTO_SERVER_LOG_ERROR("Failed to create the media player module service factory, reason: %s", e.what());
     266              :     }
     267              : 
     268            1 :     return factory;
     269              : }
     270              : 
     271              : std::shared_ptr<IMediaPipelineModuleService>
     272            1 : MediaPipelineModuleServiceFactory::create(service::IMediaPipelineService &mediaPipelineService) const
     273              : {
     274            1 :     std::shared_ptr<IMediaPipelineModuleService> mediaPipelineModule;
     275              : 
     276              :     try
     277              :     {
     278            1 :         mediaPipelineModule = std::make_shared<MediaPipelineModuleService>(mediaPipelineService);
     279              :     }
     280            0 :     catch (const std::exception &e)
     281              :     {
     282            0 :         RIALTO_SERVER_LOG_ERROR("Failed to create the media player module service, reason: %s", e.what());
     283              :     }
     284              : 
     285            1 :     return mediaPipelineModule;
     286              : }
     287              : 
     288           90 : MediaPipelineModuleService::MediaPipelineModuleService(service::IMediaPipelineService &mediaPipelineService)
     289           90 :     : m_mediaPipelineService{mediaPipelineService}
     290              : {
     291              : }
     292              : 
     293              : MediaPipelineModuleService::~MediaPipelineModuleService() {}
     294              : 
     295            2 : void MediaPipelineModuleService::clientConnected(const std::shared_ptr<::firebolt::rialto::ipc::IClient> &ipcClient)
     296              : {
     297            2 :     RIALTO_SERVER_LOG_INFO("Client Connected!");
     298              :     {
     299            2 :         m_clientSessions.emplace(ipcClient, std::set<int>());
     300              :     }
     301            2 :     ipcClient->exportService(shared_from_this());
     302              : }
     303              : 
     304            1 : void MediaPipelineModuleService::clientDisconnected(const std::shared_ptr<::firebolt::rialto::ipc::IClient> &ipcClient)
     305              : {
     306            1 :     RIALTO_SERVER_LOG_INFO("Client disconnected!");
     307            1 :     std::set<int> sessionIds;
     308              :     {
     309            1 :         auto sessionIter = m_clientSessions.find(ipcClient);
     310            1 :         if (sessionIter == m_clientSessions.end())
     311              :         {
     312            0 :             RIALTO_SERVER_LOG_ERROR("unknown client disconnected");
     313            0 :             return;
     314              :         }
     315            1 :         sessionIds = sessionIter->second; // copy to avoid deadlock
     316            1 :         m_clientSessions.erase(sessionIter);
     317              :     }
     318            2 :     for (const auto &sessionId : sessionIds)
     319              :     {
     320            1 :         m_mediaPipelineService.destroySession(sessionId);
     321              :     }
     322              : }
     323              : 
     324           20 : void MediaPipelineModuleService::createSession(::google::protobuf::RpcController *controller,
     325              :                                                const ::firebolt::rialto::CreateSessionRequest *request,
     326              :                                                ::firebolt::rialto::CreateSessionResponse *response,
     327              :                                                ::google::protobuf::Closure *done)
     328              : {
     329           20 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     330           20 :     auto ipcController = dynamic_cast<firebolt::rialto::ipc::IController *>(controller);
     331           20 :     if (!ipcController)
     332              :     {
     333            0 :         RIALTO_SERVER_LOG_ERROR("ipc library provided incompatible controller object");
     334            0 :         controller->SetFailed("ipc library provided incompatible controller object");
     335            0 :         done->Run();
     336            0 :         return;
     337              :     }
     338              : 
     339           20 :     int sessionId = generateSessionId();
     340              :     bool sessionCreated =
     341           40 :         m_mediaPipelineService.createSession(sessionId,
     342           40 :                                              std::make_shared<MediaPipelineClient>(sessionId, ipcController->getClient()),
     343              :                                              request->max_width(), request->max_height());
     344           20 :     if (sessionCreated)
     345              :     {
     346              :         // Assume that IPC library works well and client is present
     347           19 :         m_clientSessions[ipcController->getClient()].insert(sessionId);
     348           19 :         response->set_session_id(sessionId);
     349              :     }
     350              :     else
     351              :     {
     352            1 :         RIALTO_SERVER_LOG_ERROR("Create session failed");
     353            3 :         controller->SetFailed("Operation failed");
     354              :     }
     355           20 :     done->Run();
     356              : }
     357              : 
     358            2 : void MediaPipelineModuleService::destroySession(::google::protobuf::RpcController *controller,
     359              :                                                 const ::firebolt::rialto::DestroySessionRequest *request,
     360              :                                                 ::firebolt::rialto::DestroySessionResponse *response,
     361              :                                                 ::google::protobuf::Closure *done)
     362              : {
     363            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     364            2 :     auto ipcController = dynamic_cast<firebolt::rialto::ipc::IController *>(controller);
     365            2 :     if (!ipcController)
     366              :     {
     367            0 :         RIALTO_SERVER_LOG_ERROR("ipc library provided incompatible controller object");
     368            0 :         controller->SetFailed("ipc library provided incompatible controller object");
     369            0 :         done->Run();
     370            1 :         return;
     371              :     }
     372              : 
     373            2 :     if (!m_mediaPipelineService.destroySession(request->session_id()))
     374              :     {
     375            1 :         RIALTO_SERVER_LOG_ERROR("Destroy session failed");
     376            2 :         controller->SetFailed("Operation failed");
     377            1 :         done->Run();
     378            1 :         return;
     379              :     }
     380            1 :     auto sessionIter = m_clientSessions.find(ipcController->getClient());
     381            1 :     if (sessionIter != m_clientSessions.end())
     382              :     {
     383            0 :         sessionIter->second.erase(request->session_id());
     384              :     }
     385            1 :     done->Run();
     386              : }
     387              : 
     388            2 : void MediaPipelineModuleService::load(::google::protobuf::RpcController *controller,
     389              :                                       const ::firebolt::rialto::LoadRequest *request,
     390              :                                       ::firebolt::rialto::LoadResponse *response, ::google::protobuf::Closure *done)
     391              : {
     392            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     393            2 :     if (!m_mediaPipelineService.load(request->session_id(), convertMediaType(request->type()), request->mime_type(),
     394              :                                      request->url()))
     395              :     {
     396            1 :         RIALTO_SERVER_LOG_ERROR("Load failed");
     397            3 :         controller->SetFailed("Operation failed");
     398              :     }
     399            2 :     done->Run();
     400              : }
     401              : 
     402            2 : void MediaPipelineModuleService::setVideoWindow(::google::protobuf::RpcController *controller,
     403              :                                                 const ::firebolt::rialto::SetVideoWindowRequest *request,
     404              :                                                 ::firebolt::rialto::SetVideoWindowResponse *response,
     405              :                                                 ::google::protobuf::Closure *done)
     406              : {
     407            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     408            2 :     if (!m_mediaPipelineService.setVideoWindow(request->session_id(), request->x(), request->y(), request->width(),
     409              :                                                request->height()))
     410              :     {
     411            1 :         RIALTO_SERVER_LOG_ERROR("Set Video Window failed");
     412            3 :         controller->SetFailed("Operation failed");
     413              :     }
     414            2 :     done->Run();
     415              : }
     416              : 
     417            9 : void MediaPipelineModuleService::attachSource(::google::protobuf::RpcController *controller,
     418              :                                               const ::firebolt::rialto::AttachSourceRequest *request,
     419              :                                               ::firebolt::rialto::AttachSourceResponse *response,
     420              :                                               ::google::protobuf::Closure *done)
     421              : {
     422            9 :     RIALTO_SERVER_LOG_DEBUG("mime_type: %s", request->mime_type().c_str());
     423              : 
     424            9 :     std::shared_ptr<CodecData> codecData{};
     425            9 :     if (request->has_codec_data())
     426              :     {
     427            1 :         auto codecDataProto = request->codec_data();
     428            1 :         codecData = std::make_shared<CodecData>();
     429            1 :         codecData->data = std::vector<std::uint8_t>(codecDataProto.data().begin(), codecDataProto.data().end());
     430            1 :         codecData->type = convertCodecDataType(codecDataProto.type());
     431              :     }
     432            9 :     std::unique_ptr<IMediaPipeline::MediaSource> mediaSource;
     433            9 :     firebolt::rialto::SourceConfigType configType = convertConfigType(request->config_type());
     434            9 :     bool hasDrm = request->has_drm();
     435              : 
     436            9 :     if (configType == firebolt::rialto::SourceConfigType::AUDIO)
     437              :     {
     438            5 :         const auto &kConfig = request->audio_config();
     439            5 :         uint32_t numberofchannels = kConfig.number_of_channels();
     440            5 :         uint32_t sampleRate = kConfig.sample_rate();
     441              : 
     442            5 :         std::vector<uint8_t> codecSpecificConfig;
     443            5 :         if (kConfig.has_codec_specific_config())
     444              :         {
     445            1 :             auto codecSpecificConfigStr = kConfig.codec_specific_config();
     446            1 :             codecSpecificConfig.assign(codecSpecificConfigStr.begin(), codecSpecificConfigStr.end());
     447              :         }
     448            5 :         std::optional<firebolt::rialto::Format> format{std::nullopt};
     449            5 :         if (kConfig.has_format())
     450              :         {
     451            1 :             format = convertFormat(kConfig.format());
     452              :         }
     453            5 :         std::optional<firebolt::rialto::Layout> layout{std::nullopt};
     454            5 :         if (kConfig.has_layout())
     455              :         {
     456            1 :             layout = convertLayout(kConfig.layout());
     457              :         }
     458            5 :         std::optional<uint64_t> channelMask{std::nullopt};
     459            5 :         if (kConfig.has_channel_mask())
     460              :         {
     461            1 :             channelMask = kConfig.channel_mask();
     462              :         }
     463            5 :         std::vector<std::vector<uint8_t>> streamHeaders;
     464            6 :         for (int i = 0; i < kConfig.stream_header_size(); ++i)
     465              :         {
     466            1 :             auto streamHeaderStr = kConfig.stream_header(i);
     467            2 :             streamHeaders.push_back(std::vector<uint8_t>{streamHeaderStr.begin(), streamHeaderStr.end()});
     468            1 :         }
     469            5 :         std::optional<bool> framed;
     470            5 :         if (kConfig.has_framed())
     471              :         {
     472            1 :             framed = kConfig.framed();
     473              :         }
     474              :         AudioConfig audioConfig{numberofchannels, sampleRate,  codecSpecificConfig, format,
     475            5 :                                 layout,           channelMask, streamHeaders,       framed};
     476              : 
     477              :         mediaSource =
     478           10 :             std::make_unique<IMediaPipeline::MediaSourceAudio>(request->mime_type(), hasDrm, audioConfig,
     479            5 :                                                                convertSegmentAlignment(request->segment_alignment()),
     480           10 :                                                                convertStreamFormat(request->stream_format()), codecData);
     481            5 :     }
     482            4 :     else if (configType == firebolt::rialto::SourceConfigType::VIDEO)
     483              :     {
     484              :         mediaSource =
     485            2 :             std::make_unique<IMediaPipeline::MediaSourceVideo>(request->mime_type().c_str(), hasDrm, request->width(),
     486            1 :                                                                request->height(),
     487            1 :                                                                convertSegmentAlignment(request->segment_alignment()),
     488            3 :                                                                convertStreamFormat(request->stream_format()), codecData);
     489              :     }
     490            3 :     else if (configType == firebolt::rialto::SourceConfigType::VIDEO_DOLBY_VISION)
     491              :     {
     492              :         mediaSource =
     493            2 :             std::make_unique<IMediaPipeline::MediaSourceVideoDolbyVision>(request->mime_type().c_str(),
     494            1 :                                                                           request->dolby_vision_profile(), hasDrm,
     495            1 :                                                                           request->width(), request->height(),
     496            1 :                                                                           convertSegmentAlignment(
     497            1 :                                                                               request->segment_alignment()),
     498            2 :                                                                           convertStreamFormat(request->stream_format()),
     499            1 :                                                                           codecData);
     500              :     }
     501            2 :     else if (configType == firebolt::rialto::SourceConfigType::SUBTITLE)
     502              :     {
     503            2 :         mediaSource = std::make_unique<IMediaPipeline::MediaSourceSubtitle>(request->mime_type().c_str(),
     504            2 :                                                                             request->text_track_identifier());
     505              :     }
     506              :     else
     507              :     {
     508            1 :         RIALTO_SERVER_LOG_ERROR("Unknown source type");
     509            2 :         controller->SetFailed("Operation failed");
     510            1 :         done->Run();
     511            1 :         return;
     512              :     }
     513              : 
     514            8 :     if (!request->has_switch_source() || !request->switch_source())
     515              :     {
     516            6 :         RIALTO_SERVER_LOG_DEBUG("Attaching source");
     517            6 :         if (!m_mediaPipelineService.attachSource(request->session_id(), mediaSource))
     518              :         {
     519            1 :             RIALTO_SERVER_LOG_ERROR("Attach source failed");
     520            3 :             controller->SetFailed("Operation failed");
     521              :         }
     522              :     }
     523              :     else
     524              :     {
     525            2 :         RIALTO_SERVER_LOG_DEBUG("Switching source");
     526            2 :         if (!m_mediaPipelineService.switchSource(request->session_id(), mediaSource))
     527              :         {
     528            1 :             RIALTO_SERVER_LOG_ERROR("Switch source failed");
     529            3 :             controller->SetFailed("Operation failed");
     530              :         }
     531              :     }
     532            8 :     response->set_source_id(mediaSource->getId());
     533            8 :     done->Run();
     534           10 : }
     535              : 
     536            0 : void MediaPipelineModuleService::removeSource(::google::protobuf::RpcController *controller,
     537              :                                               const ::firebolt::rialto::RemoveSourceRequest *request,
     538              :                                               ::firebolt::rialto::RemoveSourceResponse *response,
     539              :                                               ::google::protobuf::Closure *done)
     540              : {
     541            0 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     542            0 :     if (!m_mediaPipelineService.removeSource(request->session_id(), request->source_id()))
     543              :     {
     544            0 :         RIALTO_SERVER_LOG_ERROR("Remove source failed");
     545            0 :         controller->SetFailed("Operation failed");
     546              :     }
     547            0 :     done->Run();
     548              : }
     549              : 
     550            2 : void MediaPipelineModuleService::allSourcesAttached(::google::protobuf::RpcController *controller,
     551              :                                                     const ::firebolt::rialto::AllSourcesAttachedRequest *request,
     552              :                                                     ::firebolt::rialto::AllSourcesAttachedResponse *response,
     553              :                                                     ::google::protobuf::Closure *done)
     554              : {
     555            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     556            2 :     if (!m_mediaPipelineService.allSourcesAttached(request->session_id()))
     557              :     {
     558            1 :         RIALTO_SERVER_LOG_ERROR("All sources attached failed");
     559            3 :         controller->SetFailed("Operation failed");
     560              :     }
     561            2 :     done->Run();
     562              : }
     563              : 
     564            2 : void MediaPipelineModuleService::play(::google::protobuf::RpcController *controller,
     565              :                                       const ::firebolt::rialto::PlayRequest *request,
     566              :                                       ::firebolt::rialto::PlayResponse *response, ::google::protobuf::Closure *done)
     567              : {
     568            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     569            2 :     if (!m_mediaPipelineService.play(request->session_id()))
     570              :     {
     571            1 :         RIALTO_SERVER_LOG_ERROR("Play failed");
     572            3 :         controller->SetFailed("Operation failed");
     573              :     }
     574            2 :     done->Run();
     575              : }
     576              : 
     577            2 : void MediaPipelineModuleService::pause(::google::protobuf::RpcController *controller,
     578              :                                        const ::firebolt::rialto::PauseRequest *request,
     579              :                                        ::firebolt::rialto::PauseResponse *response, ::google::protobuf::Closure *done)
     580              : {
     581            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     582            2 :     if (!m_mediaPipelineService.pause(request->session_id()))
     583              :     {
     584            1 :         RIALTO_SERVER_LOG_ERROR("pause failed");
     585            3 :         controller->SetFailed("Operation failed");
     586              :     }
     587            2 :     done->Run();
     588              : }
     589              : 
     590            2 : void MediaPipelineModuleService::stop(::google::protobuf::RpcController *controller,
     591              :                                       const ::firebolt::rialto::StopRequest *request,
     592              :                                       ::firebolt::rialto::StopResponse *response, ::google::protobuf::Closure *done)
     593              : {
     594            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     595            2 :     if (!m_mediaPipelineService.stop(request->session_id()))
     596              :     {
     597            1 :         RIALTO_SERVER_LOG_ERROR("Stop failed");
     598            3 :         controller->SetFailed("Operation failed");
     599              :     }
     600            2 :     done->Run();
     601              : }
     602              : 
     603            2 : void MediaPipelineModuleService::setPosition(::google::protobuf::RpcController *controller,
     604              :                                              const ::firebolt::rialto::SetPositionRequest *request,
     605              :                                              ::firebolt::rialto::SetPositionResponse *response,
     606              :                                              ::google::protobuf::Closure *done)
     607              : {
     608            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     609            2 :     if (!m_mediaPipelineService.setPosition(request->session_id(), request->position()))
     610              :     {
     611            1 :         RIALTO_SERVER_LOG_ERROR("Set Position failed");
     612            3 :         controller->SetFailed("Operation failed");
     613              :     }
     614            2 :     done->Run();
     615              : }
     616              : 
     617            2 : void MediaPipelineModuleService::haveData(::google::protobuf::RpcController *controller,
     618              :                                           const ::firebolt::rialto::HaveDataRequest *request,
     619              :                                           ::firebolt::rialto::HaveDataResponse *response,
     620              :                                           ::google::protobuf::Closure *done)
     621              : {
     622            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     623            2 :     firebolt::rialto::MediaSourceStatus status{convertMediaSourceStatus(request->status())};
     624            2 :     if (!m_mediaPipelineService.haveData(request->session_id(), status, request->num_frames(), request->request_id()))
     625              :     {
     626            1 :         RIALTO_SERVER_LOG_ERROR("Have data failed");
     627            3 :         controller->SetFailed("Operation failed");
     628              :     }
     629            2 :     done->Run();
     630              : }
     631              : 
     632            2 : void MediaPipelineModuleService::setPlaybackRate(::google::protobuf::RpcController *controller,
     633              :                                                  const ::firebolt::rialto::SetPlaybackRateRequest *request,
     634              :                                                  ::firebolt::rialto::SetPlaybackRateResponse *response,
     635              :                                                  ::google::protobuf::Closure *done)
     636              : {
     637            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     638            2 :     if (!m_mediaPipelineService.setPlaybackRate(request->session_id(), request->rate()))
     639              :     {
     640            1 :         RIALTO_SERVER_LOG_ERROR("Set playback rate failed");
     641            3 :         controller->SetFailed("Operation failed");
     642              :     }
     643            2 :     done->Run();
     644              : }
     645              : 
     646            2 : void MediaPipelineModuleService::getPosition(::google::protobuf::RpcController *controller,
     647              :                                              const ::firebolt::rialto::GetPositionRequest *request,
     648              :                                              ::firebolt::rialto::GetPositionResponse *response,
     649              :                                              ::google::protobuf::Closure *done)
     650              : {
     651            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     652            2 :     int64_t position{};
     653            2 :     if (!m_mediaPipelineService.getPosition(request->session_id(), position))
     654              :     {
     655            1 :         RIALTO_SERVER_LOG_ERROR("Get position failed");
     656            3 :         controller->SetFailed("Operation failed");
     657              :     }
     658              :     else
     659              :     {
     660            1 :         response->set_position(position);
     661              :     }
     662            2 :     done->Run();
     663              : }
     664              : 
     665            2 : void MediaPipelineModuleService::setImmediateOutput(::google::protobuf::RpcController *controller,
     666              :                                                     const ::firebolt::rialto::SetImmediateOutputRequest *request,
     667              :                                                     ::firebolt::rialto::SetImmediateOutputResponse *response,
     668              :                                                     ::google::protobuf::Closure *done)
     669              : {
     670            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     671            2 :     if (!m_mediaPipelineService.setImmediateOutput(request->session_id(), request->source_id(),
     672            2 :                                                    request->immediate_output()))
     673              :     {
     674            1 :         RIALTO_SERVER_LOG_ERROR("Set Immediate Output failed");
     675            3 :         controller->SetFailed("Operation failed");
     676              :     }
     677            2 :     done->Run();
     678              : }
     679              : 
     680            2 : void MediaPipelineModuleService::getImmediateOutput(::google::protobuf::RpcController *controller,
     681              :                                                     const ::firebolt::rialto::GetImmediateOutputRequest *request,
     682              :                                                     ::firebolt::rialto::GetImmediateOutputResponse *response,
     683              :                                                     ::google::protobuf::Closure *done)
     684              : {
     685            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     686              :     bool immediateOutputState;
     687            2 :     if (!m_mediaPipelineService.getImmediateOutput(request->session_id(), request->source_id(), immediateOutputState))
     688              :     {
     689            1 :         RIALTO_SERVER_LOG_ERROR("Get Immediate Output failed");
     690            3 :         controller->SetFailed("Operation failed");
     691              :     }
     692              :     else
     693              :     {
     694            1 :         response->set_immediate_output(immediateOutputState);
     695              :     }
     696            2 :     done->Run();
     697              : }
     698              : 
     699            2 : void MediaPipelineModuleService::getStats(::google::protobuf::RpcController *controller,
     700              :                                           const ::firebolt::rialto::GetStatsRequest *request,
     701              :                                           ::firebolt::rialto::GetStatsResponse *response,
     702              :                                           ::google::protobuf::Closure *done)
     703              : {
     704            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     705              :     uint64_t renderedFrames;
     706              :     uint64_t droppedFrames;
     707            2 :     if (!m_mediaPipelineService.getStats(request->session_id(), request->source_id(), renderedFrames, droppedFrames))
     708              :     {
     709            1 :         RIALTO_SERVER_LOG_ERROR("Get stats failed");
     710            3 :         controller->SetFailed("Operation failed");
     711              :     }
     712              :     else
     713              :     {
     714            1 :         response->set_rendered_frames(renderedFrames);
     715            1 :         response->set_dropped_frames(droppedFrames);
     716              :     }
     717            2 :     done->Run();
     718              : }
     719              : 
     720            2 : void MediaPipelineModuleService::renderFrame(::google::protobuf::RpcController *controller,
     721              :                                              const ::firebolt::rialto::RenderFrameRequest *request,
     722              :                                              ::firebolt::rialto::RenderFrameResponse *response,
     723              :                                              ::google::protobuf::Closure *done)
     724              : {
     725            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     726              : 
     727            2 :     if (!m_mediaPipelineService.renderFrame(request->session_id()))
     728              :     {
     729            1 :         RIALTO_SERVER_LOG_ERROR("Render frame");
     730            3 :         controller->SetFailed("Operation failed");
     731              :     }
     732              : 
     733            2 :     done->Run();
     734              : }
     735              : 
     736            2 : void MediaPipelineModuleService::setVolume(::google::protobuf::RpcController *controller,
     737              :                                            const ::firebolt::rialto::SetVolumeRequest *request,
     738              :                                            ::firebolt::rialto::SetVolumeResponse *response,
     739              :                                            ::google::protobuf::Closure *done)
     740              : {
     741            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     742              : 
     743            2 :     if (!m_mediaPipelineService.setVolume(request->session_id(), request->volume(), request->volume_duration(),
     744            4 :                                           convertEaseType(request->ease_type())))
     745              :     {
     746            1 :         RIALTO_SERVER_LOG_ERROR("Set volume failed.");
     747            3 :         controller->SetFailed("Operation failed");
     748              :     }
     749              : 
     750            2 :     done->Run();
     751              : }
     752              : 
     753            2 : void MediaPipelineModuleService::getVolume(::google::protobuf::RpcController *controller,
     754              :                                            const ::firebolt::rialto::GetVolumeRequest *request,
     755              :                                            ::firebolt::rialto::GetVolumeResponse *response,
     756              :                                            ::google::protobuf::Closure *done)
     757              : {
     758            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     759            2 :     double volume{};
     760              : 
     761            2 :     if (!m_mediaPipelineService.getVolume(request->session_id(), volume))
     762              :     {
     763            1 :         RIALTO_SERVER_LOG_ERROR("Get volume failed.");
     764            3 :         controller->SetFailed("Operation failed");
     765              :     }
     766              :     else
     767              :     {
     768            1 :         response->set_volume(volume);
     769              :     }
     770              : 
     771            2 :     done->Run();
     772              : }
     773              : 
     774            2 : void MediaPipelineModuleService::setMute(::google::protobuf::RpcController *controller,
     775              :                                          const ::firebolt::rialto::SetMuteRequest *request,
     776              :                                          ::firebolt::rialto::SetMuteResponse *response, ::google::protobuf::Closure *done)
     777              : {
     778            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     779              : 
     780            2 :     if (!m_mediaPipelineService.setMute(request->session_id(), request->source_id(), request->mute()))
     781              :     {
     782            1 :         RIALTO_SERVER_LOG_ERROR("Set mute failed.");
     783            3 :         controller->SetFailed("Operation failed");
     784              :     }
     785              : 
     786            2 :     done->Run();
     787              : }
     788              : 
     789            2 : void MediaPipelineModuleService::getMute(::google::protobuf::RpcController *controller,
     790              :                                          const ::firebolt::rialto::GetMuteRequest *request,
     791              :                                          ::firebolt::rialto::GetMuteResponse *response, ::google::protobuf::Closure *done)
     792              : {
     793            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     794            2 :     bool mute{};
     795              : 
     796            2 :     if (!m_mediaPipelineService.getMute(request->session_id(), request->source_id(), mute))
     797              :     {
     798            1 :         RIALTO_SERVER_LOG_ERROR("Get mute failed.");
     799            3 :         controller->SetFailed("Operation failed");
     800              :     }
     801              :     else
     802              :     {
     803            1 :         response->set_mute(mute);
     804              :     }
     805              : 
     806            2 :     done->Run();
     807              : }
     808              : 
     809            2 : void MediaPipelineModuleService::setTextTrackIdentifier(::google::protobuf::RpcController *controller,
     810              :                                                         const ::firebolt::rialto::SetTextTrackIdentifierRequest *request,
     811              :                                                         ::firebolt::rialto::SetTextTrackIdentifierResponse *response,
     812              :                                                         ::google::protobuf::Closure *done)
     813              : {
     814            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     815              : 
     816            2 :     if (!m_mediaPipelineService.setTextTrackIdentifier(request->session_id(), request->text_track_identifier()))
     817              :     {
     818            1 :         RIALTO_SERVER_LOG_ERROR("Set text track identifier failed.");
     819            3 :         controller->SetFailed("Operation failed");
     820              :     }
     821              : 
     822            2 :     done->Run();
     823              : }
     824              : 
     825            2 : void MediaPipelineModuleService::getTextTrackIdentifier(::google::protobuf::RpcController *controller,
     826              :                                                         const ::firebolt::rialto::GetTextTrackIdentifierRequest *request,
     827              :                                                         ::firebolt::rialto::GetTextTrackIdentifierResponse *response,
     828              :                                                         ::google::protobuf::Closure *done)
     829              : {
     830            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     831            2 :     std::string textTrackIdentifier{};
     832              : 
     833            2 :     if (!m_mediaPipelineService.getTextTrackIdentifier(request->session_id(), textTrackIdentifier))
     834              :     {
     835            1 :         RIALTO_SERVER_LOG_ERROR("Get TextTrackIdentifier failed.");
     836            3 :         controller->SetFailed("Operation failed");
     837              :     }
     838              :     else
     839              :     {
     840              :         response->set_text_track_identifier(textTrackIdentifier);
     841              :     }
     842              : 
     843            2 :     done->Run();
     844              : }
     845              : 
     846            2 : void MediaPipelineModuleService::setLowLatency(::google::protobuf::RpcController *controller,
     847              :                                                const ::firebolt::rialto::SetLowLatencyRequest *request,
     848              :                                                ::firebolt::rialto::SetLowLatencyResponse *response,
     849              :                                                ::google::protobuf::Closure *done)
     850              : {
     851            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     852              : 
     853            2 :     if (!m_mediaPipelineService.setLowLatency(request->session_id(), request->low_latency()))
     854              :     {
     855            1 :         RIALTO_SERVER_LOG_ERROR("Set low latency failed.");
     856            3 :         controller->SetFailed("Operation failed");
     857              :     }
     858              : 
     859            2 :     done->Run();
     860              : }
     861              : 
     862            2 : void MediaPipelineModuleService::setSync(::google::protobuf::RpcController *controller,
     863              :                                          const ::firebolt::rialto::SetSyncRequest *request,
     864              :                                          ::firebolt::rialto::SetSyncResponse *response, ::google::protobuf::Closure *done)
     865              : {
     866            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     867              : 
     868            2 :     if (!m_mediaPipelineService.setSync(request->session_id(), request->sync()))
     869              :     {
     870            1 :         RIALTO_SERVER_LOG_ERROR("Set sync failed.");
     871            3 :         controller->SetFailed("Operation failed");
     872              :     }
     873              : 
     874            2 :     done->Run();
     875              : }
     876              : 
     877            2 : void MediaPipelineModuleService::getSync(::google::protobuf::RpcController *controller,
     878              :                                          const ::firebolt::rialto::GetSyncRequest *request,
     879              :                                          ::firebolt::rialto::GetSyncResponse *response, ::google::protobuf::Closure *done)
     880              : {
     881            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     882            2 :     bool sync{};
     883              : 
     884            2 :     if (!m_mediaPipelineService.getSync(request->session_id(), sync))
     885              :     {
     886            1 :         RIALTO_SERVER_LOG_ERROR("Get sync failed.");
     887            3 :         controller->SetFailed("Operation failed");
     888              :     }
     889              :     else
     890              :     {
     891            1 :         response->set_sync(sync);
     892              :     }
     893              : 
     894            2 :     done->Run();
     895              : }
     896              : 
     897            2 : void MediaPipelineModuleService::setSyncOff(::google::protobuf::RpcController *controller,
     898              :                                             const ::firebolt::rialto::SetSyncOffRequest *request,
     899              :                                             ::firebolt::rialto::SetSyncOffResponse *response,
     900              :                                             ::google::protobuf::Closure *done)
     901              : {
     902            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     903              : 
     904            2 :     if (!m_mediaPipelineService.setSyncOff(request->session_id(), request->sync_off()))
     905              :     {
     906            1 :         RIALTO_SERVER_LOG_ERROR("Set sync off failed.");
     907            3 :         controller->SetFailed("Operation failed");
     908              :     }
     909              : 
     910            2 :     done->Run();
     911              : }
     912              : 
     913            2 : void MediaPipelineModuleService::setStreamSyncMode(::google::protobuf::RpcController *controller,
     914              :                                                    const ::firebolt::rialto::SetStreamSyncModeRequest *request,
     915              :                                                    ::firebolt::rialto::SetStreamSyncModeResponse *response,
     916              :                                                    ::google::protobuf::Closure *done)
     917              : {
     918            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     919              : 
     920            2 :     if (!m_mediaPipelineService.setStreamSyncMode(request->session_id(), request->source_id(),
     921              :                                                   request->stream_sync_mode()))
     922              :     {
     923            1 :         RIALTO_SERVER_LOG_ERROR("Set stream sync mode failed.");
     924            3 :         controller->SetFailed("Operation failed");
     925              :     }
     926              : 
     927            2 :     done->Run();
     928              : }
     929              : 
     930            2 : void MediaPipelineModuleService::getStreamSyncMode(::google::protobuf::RpcController *controller,
     931              :                                                    const ::firebolt::rialto::GetStreamSyncModeRequest *request,
     932              :                                                    ::firebolt::rialto::GetStreamSyncModeResponse *response,
     933              :                                                    ::google::protobuf::Closure *done)
     934              : {
     935            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     936            2 :     int32_t streamSyncMode{};
     937              : 
     938            2 :     if (!m_mediaPipelineService.getStreamSyncMode(request->session_id(), streamSyncMode))
     939              :     {
     940            1 :         RIALTO_SERVER_LOG_ERROR("Get stream sync mode failed.");
     941            3 :         controller->SetFailed("Operation failed");
     942              :     }
     943              :     else
     944              :     {
     945            1 :         response->set_stream_sync_mode(streamSyncMode);
     946              :     }
     947              : 
     948            2 :     done->Run();
     949              : }
     950              : 
     951            2 : void MediaPipelineModuleService::flush(::google::protobuf::RpcController *controller,
     952              :                                        const ::firebolt::rialto::FlushRequest *request,
     953              :                                        ::firebolt::rialto::FlushResponse *response, ::google::protobuf::Closure *done)
     954              : {
     955            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     956              : 
     957            2 :     bool isAsync{false};
     958            2 :     if (!m_mediaPipelineService.flush(request->session_id(), request->source_id(), request->reset_time(), isAsync))
     959              :     {
     960            1 :         RIALTO_SERVER_LOG_ERROR("Flush failed.");
     961            3 :         controller->SetFailed("Operation failed");
     962              :     }
     963            2 :     response->set_async(isAsync);
     964              : 
     965            2 :     done->Run();
     966              : }
     967              : 
     968            2 : void MediaPipelineModuleService::setSourcePosition(::google::protobuf::RpcController *controller,
     969              :                                                    const ::firebolt::rialto::SetSourcePositionRequest *request,
     970              :                                                    ::firebolt::rialto::SetSourcePositionResponse *response,
     971              :                                                    ::google::protobuf::Closure *done)
     972              : {
     973            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     974            4 :     if (!m_mediaPipelineService.setSourcePosition(request->session_id(), request->source_id(), request->position(),
     975            2 :                                                   request->reset_time(), request->applied_rate(),
     976              :                                                   request->stop_position()))
     977              :     {
     978            1 :         RIALTO_SERVER_LOG_ERROR("Set Source Position failed.");
     979            3 :         controller->SetFailed("Operation failed");
     980              :     }
     981            2 :     done->Run();
     982              : }
     983              : 
     984            2 : void MediaPipelineModuleService::processAudioGap(::google::protobuf::RpcController *controller,
     985              :                                                  const ::firebolt::rialto::ProcessAudioGapRequest *request,
     986              :                                                  ::firebolt::rialto::ProcessAudioGapResponse *response,
     987              :                                                  ::google::protobuf::Closure *done)
     988              : {
     989            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
     990            2 :     if (!m_mediaPipelineService.processAudioGap(request->session_id(), request->position(), request->duration(),
     991            2 :                                                 request->discontinuity_gap(), request->audio_aac()))
     992              :     {
     993            1 :         RIALTO_SERVER_LOG_ERROR("Process audio gap failed.");
     994            3 :         controller->SetFailed("Operation failed");
     995              :     }
     996            2 :     done->Run();
     997              : }
     998              : 
     999            2 : void MediaPipelineModuleService::setBufferingLimit(::google::protobuf::RpcController *controller,
    1000              :                                                    const ::firebolt::rialto::SetBufferingLimitRequest *request,
    1001              :                                                    ::firebolt::rialto::SetBufferingLimitResponse *response,
    1002              :                                                    ::google::protobuf::Closure *done)
    1003              : {
    1004            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1005            2 :     if (!m_mediaPipelineService.setBufferingLimit(request->session_id(), request->limit_buffering_ms()))
    1006              :     {
    1007            1 :         RIALTO_SERVER_LOG_ERROR("Set buffering limit failed.");
    1008            3 :         controller->SetFailed("Operation failed");
    1009              :     }
    1010            2 :     done->Run();
    1011              : }
    1012              : 
    1013            2 : void MediaPipelineModuleService::getBufferingLimit(::google::protobuf::RpcController *controller,
    1014              :                                                    const ::firebolt::rialto::GetBufferingLimitRequest *request,
    1015              :                                                    ::firebolt::rialto::GetBufferingLimitResponse *response,
    1016              :                                                    ::google::protobuf::Closure *done)
    1017              : {
    1018            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1019            2 :     uint32_t bufferingLimit{};
    1020              : 
    1021            2 :     if (!m_mediaPipelineService.getBufferingLimit(request->session_id(), bufferingLimit))
    1022              :     {
    1023            1 :         RIALTO_SERVER_LOG_ERROR("Get buffering limit failed.");
    1024            3 :         controller->SetFailed("Operation failed");
    1025              :     }
    1026              :     else
    1027              :     {
    1028            1 :         response->set_limit_buffering_ms(bufferingLimit);
    1029              :     }
    1030              : 
    1031            2 :     done->Run();
    1032              : }
    1033              : 
    1034            2 : void MediaPipelineModuleService::setUseBuffering(::google::protobuf::RpcController *controller,
    1035              :                                                  const ::firebolt::rialto::SetUseBufferingRequest *request,
    1036              :                                                  ::firebolt::rialto::SetUseBufferingResponse *response,
    1037              :                                                  ::google::protobuf::Closure *done)
    1038              : {
    1039            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1040            2 :     if (!m_mediaPipelineService.setUseBuffering(request->session_id(), request->use_buffering()))
    1041              :     {
    1042            1 :         RIALTO_SERVER_LOG_ERROR("Set use buffering failed.");
    1043            3 :         controller->SetFailed("Operation failed");
    1044              :     }
    1045            2 :     done->Run();
    1046              : }
    1047              : 
    1048            2 : void MediaPipelineModuleService::getUseBuffering(::google::protobuf::RpcController *controller,
    1049              :                                                  const ::firebolt::rialto::GetUseBufferingRequest *request,
    1050              :                                                  ::firebolt::rialto::GetUseBufferingResponse *response,
    1051              :                                                  ::google::protobuf::Closure *done)
    1052              : {
    1053            2 :     RIALTO_SERVER_LOG_DEBUG("entry:");
    1054            2 :     bool useBuffering{};
    1055              : 
    1056            2 :     if (!m_mediaPipelineService.getUseBuffering(request->session_id(), useBuffering))
    1057              :     {
    1058            1 :         RIALTO_SERVER_LOG_ERROR("Get use buffering failed.");
    1059            3 :         controller->SetFailed("Operation failed");
    1060              :     }
    1061              :     else
    1062              :     {
    1063            1 :         response->set_use_buffering(useBuffering);
    1064              :     }
    1065              : 
    1066            2 :     done->Run();
    1067              : }
    1068              : } // namespace firebolt::rialto::server::ipc
        

Generated by: LCOV version 2.0-1