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 2026 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 "MediaCapabilitiesIpc.h"
21 : #include "CapabilityConverters.h"
22 : #include "IIpcClient.h"
23 : #include "RialtoClientLogging.h"
24 :
25 : namespace firebolt::rialto::client
26 : {
27 1 : std::shared_ptr<IMediaCapabilitiesIpcFactory> IMediaCapabilitiesIpcFactory::createFactory()
28 : {
29 1 : std::shared_ptr<IMediaCapabilitiesIpcFactory> factory;
30 :
31 : try
32 : {
33 1 : factory = std::make_shared<MediaCapabilitiesIpcFactory>();
34 : }
35 0 : catch (const std::exception &e)
36 : {
37 0 : RIALTO_CLIENT_LOG_ERROR("Failed to create the media capabilities ipc factory, reason: %s", e.what());
38 : }
39 :
40 1 : return factory;
41 : }
42 :
43 1 : std::unique_ptr<IMediaCapabilities> MediaCapabilitiesIpcFactory::createMediaCapabilitiesIpc() const
44 : {
45 1 : std::unique_ptr<IMediaCapabilities> mediaCapabilitiesIpc;
46 :
47 : try
48 : {
49 : mediaCapabilitiesIpc =
50 1 : std::make_unique<client::MediaCapabilitiesIpc>(IIpcClientAccessor::instance().getIpcClient());
51 : }
52 1 : catch (const std::exception &e)
53 : {
54 1 : RIALTO_CLIENT_LOG_ERROR("Failed to create the media capabilities ipc, reason: %s", e.what());
55 : }
56 :
57 1 : return mediaCapabilitiesIpc;
58 : }
59 :
60 11 : MediaCapabilitiesIpc::MediaCapabilitiesIpc(IIpcClient &ipcClient) : IpcModule(ipcClient)
61 : {
62 11 : RIALTO_CLIENT_LOG_DEBUG("entry:");
63 11 : if (!attachChannel())
64 1 : throw std::runtime_error("Failed to attach to the IPC channel");
65 13 : }
66 :
67 20 : MediaCapabilitiesIpc::~MediaCapabilitiesIpc()
68 : {
69 10 : RIALTO_CLIENT_LOG_DEBUG("entry:");
70 10 : detachChannel();
71 20 : }
72 :
73 12 : bool MediaCapabilitiesIpc::createRpcStubs(const std::shared_ptr<ipc::IChannel> &ipcChannel)
74 : {
75 12 : m_stub = std::make_unique<::firebolt::rialto::MediaCapabilitiesModule_Stub>(ipcChannel.get());
76 12 : return m_stub != nullptr;
77 : }
78 :
79 4 : firebolt::rialto::common::AudioDecoderCapabilities MediaCapabilitiesIpc::getSupportedAudioCapabilities()
80 : {
81 4 : if (!reattachChannelIfRequired())
82 : {
83 1 : RIALTO_CLIENT_LOG_ERROR("IPC channel reattachment failed");
84 1 : return firebolt::rialto::common::AudioDecoderCapabilities{};
85 : }
86 :
87 3 : firebolt::rialto::GetSupportedAudioCapabilitiesRequest request;
88 3 : firebolt::rialto::AudioCapabilities response;
89 3 : auto ipcController = m_ipc.createRpcController();
90 3 : auto blockingClosure = m_ipc.createBlockingClosure();
91 3 : m_stub->getSupportedAudioCapabilities(ipcController.get(), &request, &response, blockingClosure.get());
92 3 : blockingClosure->wait();
93 :
94 3 : if (ipcController->Failed())
95 : {
96 1 : RIALTO_CLIENT_LOG_ERROR("IMediaCapabilities::getSupportedAudioCapabilities failed: %s",
97 : ipcController->ErrorText().c_str());
98 1 : return firebolt::rialto::common::AudioDecoderCapabilities{};
99 : }
100 :
101 2 : RIALTO_CLIENT_LOG_INFO("IMediaCapabilities: audio capabilities received");
102 2 : return firebolt::rialto::ipc::common::deserialiseAudioCapabilities(response);
103 3 : }
104 :
105 4 : firebolt::rialto::common::VideoDecoderCapabilities MediaCapabilitiesIpc::getSupportedVideoCapabilities()
106 : {
107 4 : RIALTO_CLIENT_LOG_DEBUG("entry:");
108 4 : if (!reattachChannelIfRequired())
109 : {
110 1 : RIALTO_CLIENT_LOG_ERROR("IPC channel reattachment failed");
111 1 : return firebolt::rialto::common::VideoDecoderCapabilities{};
112 : }
113 :
114 3 : firebolt::rialto::GetSupportedVideoCapabilitiesRequest request;
115 3 : firebolt::rialto::VideoCapabilities response;
116 3 : auto ipcController = m_ipc.createRpcController();
117 3 : auto blockingClosure = m_ipc.createBlockingClosure();
118 3 : m_stub->getSupportedVideoCapabilities(ipcController.get(), &request, &response, blockingClosure.get());
119 3 : blockingClosure->wait();
120 :
121 3 : if (ipcController->Failed())
122 : {
123 1 : RIALTO_CLIENT_LOG_ERROR("IMediaCapabilities::getSupportedVideoCapabilities failed: %s",
124 : ipcController->ErrorText().c_str());
125 1 : return firebolt::rialto::common::VideoDecoderCapabilities{};
126 : }
127 :
128 2 : RIALTO_CLIENT_LOG_INFO("IMediaCapabilities: video capabilities received");
129 2 : return firebolt::rialto::ipc::common::deserialiseVideoCapabilities(response);
130 3 : }
131 :
132 : } // namespace firebolt::rialto::client
|