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 "WebAudioPlayerClient.h"
21 : #include "RialtoServerLogging.h"
22 : #include "webaudioplayermodule.pb.h"
23 : #include <IIpcServer.h>
24 :
25 : namespace
26 : {
27 : firebolt::rialto::WebAudioPlayerStateEvent_WebAudioPlayerState
28 1 : convertWebAudioPlayerState(const firebolt::rialto::WebAudioPlayerState &state)
29 : {
30 1 : switch (state)
31 : {
32 0 : case firebolt::rialto::WebAudioPlayerState::UNKNOWN:
33 : {
34 0 : return firebolt::rialto::WebAudioPlayerStateEvent_WebAudioPlayerState_UNKNOWN;
35 : }
36 0 : case firebolt::rialto::WebAudioPlayerState::IDLE:
37 : {
38 0 : return firebolt::rialto::WebAudioPlayerStateEvent_WebAudioPlayerState_IDLE;
39 : }
40 0 : case firebolt::rialto::WebAudioPlayerState::PLAYING:
41 : {
42 0 : return firebolt::rialto::WebAudioPlayerStateEvent_WebAudioPlayerState_PLAYING;
43 : }
44 0 : case firebolt::rialto::WebAudioPlayerState::PAUSED:
45 : {
46 0 : return firebolt::rialto::WebAudioPlayerStateEvent_WebAudioPlayerState_PAUSED;
47 : }
48 1 : case firebolt::rialto::WebAudioPlayerState::END_OF_STREAM:
49 : {
50 1 : return firebolt::rialto::WebAudioPlayerStateEvent_WebAudioPlayerState_END_OF_STREAM;
51 : }
52 0 : case firebolt::rialto::WebAudioPlayerState::FAILURE:
53 : {
54 0 : return firebolt::rialto::WebAudioPlayerStateEvent_WebAudioPlayerState_FAILURE;
55 : }
56 : }
57 0 : return firebolt::rialto::WebAudioPlayerStateEvent_WebAudioPlayerState_UNKNOWN;
58 : }
59 : } // namespace
60 :
61 : namespace firebolt::rialto::server::ipc
62 : {
63 5 : WebAudioPlayerClient::WebAudioPlayerClient(int webAudioPlayerHandle,
64 5 : const std::shared_ptr<::firebolt::rialto::ipc::IClient> &ipcClient)
65 5 : : m_webAudioPlayerHandle{webAudioPlayerHandle}, m_ipcClient{ipcClient}
66 : {
67 : }
68 :
69 : WebAudioPlayerClient::~WebAudioPlayerClient() {}
70 :
71 1 : void WebAudioPlayerClient::notifyState(WebAudioPlayerState state)
72 : {
73 1 : RIALTO_SERVER_LOG_DEBUG("Sending WebAudioPlayerStateEvent");
74 :
75 1 : auto event = std::make_shared<firebolt::rialto::WebAudioPlayerStateEvent>();
76 1 : event->set_web_audio_player_handle(m_webAudioPlayerHandle);
77 1 : event->set_state(convertWebAudioPlayerState(state));
78 :
79 1 : m_ipcClient->sendEvent(event);
80 : }
81 :
82 : } // namespace firebolt::rialto::server::ipc
|