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 "MediaPipelineCapabilitiesModuleService.h"
21 : #include "RialtoCommonModule.h"
22 : #include "RialtoServerLogging.h"
23 : #include <IIpcController.h>
24 :
25 : namespace firebolt::rialto::server::ipc
26 : {
27 : std::shared_ptr<IMediaPipelineCapabilitiesModuleServiceFactory>
28 0 : IMediaPipelineCapabilitiesModuleServiceFactory::createFactory()
29 : {
30 0 : std::shared_ptr<IMediaPipelineCapabilitiesModuleServiceFactory> factory;
31 :
32 : try
33 : {
34 0 : factory = std::make_shared<MediaPipelineCapabilitiesModuleServiceFactory>();
35 : }
36 0 : catch (const std::exception &e)
37 : {
38 0 : RIALTO_SERVER_LOG_ERROR("Failed to create the media player capabilities module service factory, reason: %s",
39 : e.what());
40 : }
41 :
42 0 : return factory;
43 : }
44 :
45 : std::shared_ptr<IMediaPipelineCapabilitiesModuleService>
46 0 : MediaPipelineCapabilitiesModuleServiceFactory::create(service::IMediaPipelineService &mediaPipelineService) const
47 : {
48 0 : std::shared_ptr<IMediaPipelineCapabilitiesModuleService> mediaPipelineCapabilitiesModule;
49 :
50 : try
51 : {
52 0 : mediaPipelineCapabilitiesModule = std::make_shared<MediaPipelineCapabilitiesModuleService>(mediaPipelineService);
53 : }
54 0 : catch (const std::exception &e)
55 : {
56 0 : RIALTO_SERVER_LOG_ERROR("Failed to create the media player module service, reason: %s", e.what());
57 : }
58 :
59 0 : return mediaPipelineCapabilitiesModule;
60 : }
61 :
62 8 : MediaPipelineCapabilitiesModuleService::MediaPipelineCapabilitiesModuleService(
63 8 : service::IMediaPipelineService &mediaPipelineService)
64 8 : : m_mediaPipelineService{mediaPipelineService}
65 : {
66 : }
67 :
68 : MediaPipelineCapabilitiesModuleService::~MediaPipelineCapabilitiesModuleService() {}
69 :
70 1 : void MediaPipelineCapabilitiesModuleService::clientConnected(const std::shared_ptr<::firebolt::rialto::ipc::IClient> &ipcClient)
71 : {
72 1 : RIALTO_SERVER_LOG_INFO("Client Connected!");
73 1 : ipcClient->exportService(shared_from_this());
74 : }
75 :
76 0 : void MediaPipelineCapabilitiesModuleService::clientDisconnected(
77 : const std::shared_ptr<::firebolt::rialto::ipc::IClient> &ipcClient)
78 : {
79 0 : RIALTO_SERVER_LOG_INFO("Client disconnected!");
80 : }
81 :
82 2 : void MediaPipelineCapabilitiesModuleService::getSupportedMimeTypes(
83 : ::google::protobuf::RpcController *controller, const ::firebolt::rialto::GetSupportedMimeTypesRequest *request,
84 : ::firebolt::rialto::GetSupportedMimeTypesResponse *response, ::google::protobuf::Closure *done)
85 : {
86 2 : RIALTO_SERVER_LOG_DEBUG("entry:");
87 2 : auto ipcController = dynamic_cast<firebolt::rialto::ipc::IController *>(controller);
88 2 : if (!ipcController)
89 : {
90 1 : RIALTO_SERVER_LOG_ERROR("ipc library provided incompatible controller object");
91 1 : controller->SetFailed("ipc library provided incompatible controller object");
92 1 : done->Run();
93 1 : return;
94 : }
95 :
96 1 : firebolt::rialto::MediaSourceType sourceType = convertMediaSourceType(request->media_type());
97 1 : std::vector<std::string> supportedMimeTypes = m_mediaPipelineService.getSupportedMimeTypes(sourceType);
98 :
99 3 : for (std::string &mimeType : supportedMimeTypes)
100 : {
101 2 : response->add_mime_types(mimeType);
102 : }
103 :
104 1 : done->Run();
105 : }
106 :
107 2 : void MediaPipelineCapabilitiesModuleService::isMimeTypeSupported(
108 : ::google::protobuf::RpcController *controller, const ::firebolt::rialto::IsMimeTypeSupportedRequest *request,
109 : ::firebolt::rialto::IsMimeTypeSupportedResponse *response, ::google::protobuf::Closure *done)
110 : {
111 2 : RIALTO_SERVER_LOG_DEBUG("entry:");
112 2 : auto ipcController = dynamic_cast<firebolt::rialto::ipc::IController *>(controller);
113 2 : if (!ipcController)
114 : {
115 1 : RIALTO_SERVER_LOG_ERROR("ipc library provided incompatible controller object");
116 1 : controller->SetFailed("ipc library provided incompatible controller object");
117 1 : done->Run();
118 1 : return;
119 : }
120 :
121 1 : bool isSupported = m_mediaPipelineService.isMimeTypeSupported(request->mime_type());
122 1 : response->set_is_supported(isSupported);
123 :
124 1 : done->Run();
125 : }
126 :
127 2 : void MediaPipelineCapabilitiesModuleService::getSupportedProperties(
128 : ::google::protobuf::RpcController *controller, const ::firebolt::rialto::GetSupportedPropertiesRequest *request,
129 : ::firebolt::rialto::GetSupportedPropertiesResponse *response, ::google::protobuf::Closure *done)
130 : {
131 2 : RIALTO_SERVER_LOG_DEBUG("entry:");
132 2 : auto ipcController = dynamic_cast<firebolt::rialto::ipc::IController *>(controller);
133 2 : if (!ipcController)
134 : {
135 1 : RIALTO_SERVER_LOG_ERROR("ipc library provided incompatible controller object");
136 1 : controller->SetFailed("ipc library provided incompatible controller object");
137 1 : done->Run();
138 1 : return;
139 : }
140 :
141 1 : firebolt::rialto::MediaSourceType mediaType = convertMediaSourceType(request->media_type());
142 1 : std::vector<std::string> propertiesToSearch{request->property_names().begin(), request->property_names().end()};
143 :
144 : std::vector<std::string> supportedProperties{
145 1 : m_mediaPipelineService.getSupportedProperties(mediaType, propertiesToSearch)};
146 :
147 3 : for (const std::string &property : supportedProperties)
148 : {
149 2 : response->add_supported_properties(property.c_str());
150 : }
151 :
152 1 : done->Run();
153 : }
154 :
155 : } // namespace firebolt::rialto::server::ipc
|