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 "MediaKeysClient.h"
21 : #include "IIpcServer.h"
22 : #include "RialtoServerLogging.h"
23 : #include "mediakeysmodule.pb.h"
24 :
25 : namespace
26 : {
27 3 : firebolt::rialto::KeyStatusesChangedEvent_KeyStatus convertKeyStatus(const firebolt::rialto::KeyStatus &keyStatus)
28 : {
29 3 : switch (keyStatus)
30 : {
31 1 : case firebolt::rialto::KeyStatus::USABLE:
32 : {
33 1 : return firebolt::rialto::KeyStatusesChangedEvent_KeyStatus_USABLE;
34 : }
35 1 : case firebolt::rialto::KeyStatus::EXPIRED:
36 : {
37 1 : return firebolt::rialto::KeyStatusesChangedEvent_KeyStatus_EXPIRED;
38 : }
39 1 : case firebolt::rialto::KeyStatus::OUTPUT_RESTRICTED:
40 : {
41 1 : return firebolt::rialto::KeyStatusesChangedEvent_KeyStatus_OUTPUT_RESTRICTED;
42 : }
43 0 : case firebolt::rialto::KeyStatus::PENDING:
44 : {
45 0 : return firebolt::rialto::KeyStatusesChangedEvent_KeyStatus_PENDING;
46 : }
47 0 : case firebolt::rialto::KeyStatus::INTERNAL_ERROR:
48 : {
49 0 : return firebolt::rialto::KeyStatusesChangedEvent_KeyStatus_INTERNAL_ERROR;
50 : }
51 0 : case firebolt::rialto::KeyStatus::RELEASED:
52 : {
53 0 : return firebolt::rialto::KeyStatusesChangedEvent_KeyStatus_RELEASED;
54 : }
55 : }
56 0 : return firebolt::rialto::KeyStatusesChangedEvent_KeyStatus_INTERNAL_ERROR;
57 : }
58 : } // namespace
59 :
60 : namespace firebolt::rialto::server::ipc
61 : {
62 49 : MediaKeysClient::MediaKeysClient(int mediaKeysHandle, const std::shared_ptr<::firebolt::rialto::ipc::IClient> &ipcClient)
63 49 : : m_mediaKeysHandle{mediaKeysHandle}, m_ipcClient{ipcClient}
64 : {
65 : }
66 :
67 : MediaKeysClient::~MediaKeysClient() {}
68 :
69 1 : void MediaKeysClient::onLicenseRequest(int32_t keySessionId, const std::vector<unsigned char> &licenseRequestMessage,
70 : const std::string &url)
71 : {
72 1 : RIALTO_SERVER_LOG_DEBUG("Sending LicenseRequestEvent");
73 :
74 1 : auto event = std::make_shared<firebolt::rialto::LicenseRequestEvent>();
75 4 : for (auto it = licenseRequestMessage.begin(); it != licenseRequestMessage.end(); it++)
76 : {
77 3 : event->add_license_request_message(*it);
78 : }
79 1 : event->set_media_keys_handle(m_mediaKeysHandle);
80 1 : event->set_key_session_id(keySessionId);
81 1 : event->set_url(url);
82 :
83 1 : m_ipcClient->sendEvent(event);
84 : }
85 :
86 1 : void MediaKeysClient::onLicenseRenewal(int32_t keySessionId, const std::vector<unsigned char> &licenseRenewalMessage)
87 : {
88 1 : RIALTO_SERVER_LOG_DEBUG("Sending LicenseRenewalEvent");
89 :
90 1 : auto event = std::make_shared<firebolt::rialto::LicenseRenewalEvent>();
91 4 : for (auto it = licenseRenewalMessage.begin(); it != licenseRenewalMessage.end(); it++)
92 : {
93 3 : event->add_license_renewal_message(*it);
94 : }
95 1 : event->set_media_keys_handle(m_mediaKeysHandle);
96 1 : event->set_key_session_id(keySessionId);
97 :
98 1 : m_ipcClient->sendEvent(event);
99 : }
100 :
101 1 : void MediaKeysClient::onKeyStatusesChanged(int32_t keySessionId, const KeyStatusVector &keyStatuses)
102 : {
103 1 : RIALTO_SERVER_LOG_DEBUG("Sending KeyStatusesChangedEvent");
104 :
105 1 : auto event = std::make_shared<firebolt::rialto::KeyStatusesChangedEvent>();
106 4 : for (auto it = keyStatuses.begin(); it != keyStatuses.end(); it++)
107 : {
108 3 : ::firebolt::rialto::KeyStatusesChangedEvent_KeyStatusPair *keyStatusPair = event->add_key_statuses();
109 6 : for (auto it2 = it->first.begin(); it2 != it->first.end(); it2++)
110 : {
111 3 : keyStatusPair->add_key_id(*it2);
112 : }
113 3 : keyStatusPair->set_key_status(convertKeyStatus(it->second));
114 : }
115 1 : event->set_media_keys_handle(m_mediaKeysHandle);
116 1 : event->set_key_session_id(keySessionId);
117 :
118 1 : m_ipcClient->sendEvent(event);
119 : }
120 : } // namespace firebolt::rialto::server::ipc
|