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 "MediaPipelineCapabilitiesIpc.h"
21 : #include "RialtoClientLogging.h"
22 : #include "RialtoCommonIpc.h"
23 :
24 : namespace firebolt::rialto::client
25 : {
26 1 : std::shared_ptr<IMediaPipelineCapabilitiesIpcFactory> IMediaPipelineCapabilitiesIpcFactory::createFactory()
27 : {
28 1 : std::shared_ptr<IMediaPipelineCapabilitiesIpcFactory> factory;
29 :
30 : try
31 : {
32 1 : factory = std::make_shared<MediaPipelineCapabilitiesIpcFactory>();
33 : }
34 0 : catch (const std::exception &e)
35 : {
36 0 : RIALTO_CLIENT_LOG_ERROR("Failed to create the media pipeline capabilities ipc factory, reason: %s", e.what());
37 : }
38 :
39 1 : return factory;
40 : }
41 :
42 1 : std::unique_ptr<IMediaPipelineCapabilities> MediaPipelineCapabilitiesIpcFactory::createMediaPipelineCapabilitiesIpc() const
43 : {
44 1 : std::unique_ptr<IMediaPipelineCapabilities> mediaPipelineCapabilitiesIpc;
45 :
46 : try
47 : {
48 : mediaPipelineCapabilitiesIpc =
49 1 : std::make_unique<client::MediaPipelineCapabilitiesIpc>(IIpcClientAccessor::instance().getIpcClient());
50 : }
51 1 : catch (const std::exception &e)
52 : {
53 1 : RIALTO_CLIENT_LOG_ERROR("Failed to create the media pipeline capabilities ipc, reason: %s", e.what());
54 : }
55 :
56 1 : return mediaPipelineCapabilitiesIpc;
57 : }
58 :
59 14 : MediaPipelineCapabilitiesIpc::MediaPipelineCapabilitiesIpc(IIpcClient &ipcClient) : IpcModule(ipcClient)
60 : {
61 14 : RIALTO_CLIENT_LOG_DEBUG("entry:");
62 :
63 14 : if (!attachChannel())
64 : {
65 1 : throw std::runtime_error("Failed attach to the ipc channel");
66 : }
67 16 : }
68 :
69 26 : MediaPipelineCapabilitiesIpc::~MediaPipelineCapabilitiesIpc()
70 : {
71 13 : RIALTO_CLIENT_LOG_DEBUG("entry:");
72 :
73 13 : detachChannel();
74 26 : }
75 :
76 16 : bool MediaPipelineCapabilitiesIpc::createRpcStubs(const std::shared_ptr<ipc::IChannel> &ipcChannel)
77 : {
78 : m_mediaPipelineCapabilitiesStub =
79 16 : std::make_unique<::firebolt::rialto::MediaPipelineCapabilitiesModule_Stub>(ipcChannel.get());
80 16 : if (!m_mediaPipelineCapabilitiesStub)
81 : {
82 0 : return false;
83 : }
84 16 : return true;
85 : }
86 :
87 5 : std::vector<std::string> MediaPipelineCapabilitiesIpc::getSupportedMimeTypes(MediaSourceType sourceType)
88 : {
89 5 : if (!reattachChannelIfRequired())
90 : {
91 1 : RIALTO_CLIENT_LOG_ERROR("Reattachment of the ipc channel failed, ipc disconnected");
92 1 : return {};
93 : }
94 :
95 4 : firebolt::rialto::GetSupportedMimeTypesRequest request;
96 4 : request.set_media_type(convertProtoMediaSourceType(sourceType));
97 :
98 4 : firebolt::rialto::GetSupportedMimeTypesResponse response;
99 4 : auto ipcController = m_ipc.createRpcController();
100 4 : auto blockingClosure = m_ipc.createBlockingClosure();
101 8 : m_mediaPipelineCapabilitiesStub->getSupportedMimeTypes(ipcController.get(), &request, &response,
102 4 : blockingClosure.get());
103 :
104 : // wait for the call to complete
105 4 : blockingClosure->wait();
106 :
107 : // check the result
108 4 : if (ipcController->Failed())
109 : {
110 1 : RIALTO_CLIENT_LOG_ERROR("failed to get supported mime types due to '%s'", ipcController->ErrorText().c_str());
111 1 : return {};
112 : }
113 :
114 9 : return std::vector<std::string>{response.mime_types().begin(), response.mime_types().end()};
115 4 : }
116 :
117 4 : bool MediaPipelineCapabilitiesIpc::isMimeTypeSupported(const std::string &mimeType)
118 : {
119 4 : if (!reattachChannelIfRequired())
120 : {
121 1 : RIALTO_CLIENT_LOG_ERROR("Reattachment of the ipc channel failed, ipc disconnected");
122 1 : return false;
123 : }
124 :
125 3 : firebolt::rialto::IsMimeTypeSupportedRequest request;
126 : request.set_mime_type(mimeType);
127 :
128 3 : firebolt::rialto::IsMimeTypeSupportedResponse response;
129 3 : auto ipcController = m_ipc.createRpcController();
130 3 : auto blockingClosure = m_ipc.createBlockingClosure();
131 3 : m_mediaPipelineCapabilitiesStub->isMimeTypeSupported(ipcController.get(), &request, &response, blockingClosure.get());
132 :
133 : // wait for the call to complete
134 3 : blockingClosure->wait();
135 :
136 : // check the result
137 3 : if (ipcController->Failed())
138 : {
139 1 : RIALTO_CLIENT_LOG_ERROR("failed to check if mime type '%s' is supported due to '%s'", mimeType.c_str(),
140 : ipcController->ErrorText().c_str());
141 1 : return false;
142 : }
143 :
144 2 : return response.is_supported();
145 3 : }
146 :
147 3 : std::vector<std::string> MediaPipelineCapabilitiesIpc::getSupportedProperties(MediaSourceType mediaType,
148 : const std::vector<std::string> &propertyNames)
149 : {
150 3 : if (!reattachChannelIfRequired())
151 : {
152 0 : RIALTO_CLIENT_LOG_ERROR("Reattachment of the ipc channel failed, ipc disconnected");
153 0 : return {};
154 : }
155 :
156 3 : firebolt::rialto::GetSupportedPropertiesRequest request;
157 3 : request.set_media_type(convertProtoMediaSourceType(mediaType));
158 6 : for (const std::string &property : propertyNames)
159 3 : request.add_property_names(property);
160 :
161 3 : firebolt::rialto::GetSupportedPropertiesResponse response;
162 3 : auto ipcController = m_ipc.createRpcController();
163 3 : auto blockingClosure = m_ipc.createBlockingClosure();
164 6 : m_mediaPipelineCapabilitiesStub->getSupportedProperties(ipcController.get(), &request, &response,
165 3 : blockingClosure.get());
166 :
167 : // wait for the call to complete
168 3 : blockingClosure->wait();
169 :
170 : // check the result
171 3 : if (ipcController->Failed())
172 : {
173 1 : RIALTO_CLIENT_LOG_ERROR("failed due to '%s'", ipcController->ErrorText().c_str());
174 1 : return std::vector<std::string>{};
175 : }
176 :
177 6 : return std::vector<std::string>{response.supported_properties().begin(), response.supported_properties().end()};
178 3 : }
179 :
180 : }; // namespace firebolt::rialto::client
|