• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "avsession_callback_proxy.h"
17 #include "avsession_log.h"
18 
19 namespace OHOS::AVSession {
AVSessionCallbackProxy(const sptr<IRemoteObject> & impl)20 AVSessionCallbackProxy::AVSessionCallbackProxy(const sptr<IRemoteObject>& impl)
21     : IRemoteProxy<IAVSessionCallback>(impl)
22 {
23     SLOGD("construct");
24 }
25 
OnPlay()26 void AVSessionCallbackProxy::OnPlay()
27 {
28     MessageParcel data;
29     CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
30 
31     auto remote = Remote();
32     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
33     MessageParcel reply;
34     MessageOption option = { MessageOption::TF_ASYNC };
35     CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_PLAY, data, reply, option) == 0,
36         "send request failed");
37 }
38 
OnPause()39 void AVSessionCallbackProxy::OnPause()
40 {
41     MessageParcel data;
42     CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
43 
44     auto remote = Remote();
45     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
46     MessageParcel reply;
47     MessageOption option = { MessageOption::TF_ASYNC };
48     CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_PAUSE, data, reply, option) == 0,
49         "send request failed");
50 }
51 
OnStop()52 void AVSessionCallbackProxy::OnStop()
53 {
54     MessageParcel data;
55     CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
56 
57     auto remote = Remote();
58     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
59     MessageParcel reply;
60     MessageOption option = { MessageOption::TF_ASYNC };
61     CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_STOP, data, reply, option) == 0,
62         "send request failed");
63 }
64 
OnPlayNext()65 void AVSessionCallbackProxy::OnPlayNext()
66 {
67     MessageParcel data;
68     CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
69 
70     auto remote = Remote();
71     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
72     MessageParcel reply;
73     MessageOption option = { MessageOption::TF_ASYNC };
74     CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_PLAY_NEXT, data, reply, option) == 0,
75         "send request failed");
76 }
77 
OnPlayPrevious()78 void AVSessionCallbackProxy::OnPlayPrevious()
79 {
80     MessageParcel data;
81     CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
82 
83     auto remote = Remote();
84     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
85     MessageParcel reply;
86     MessageOption option = { MessageOption::TF_ASYNC };
87     CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_PLAY_PREVIOUS, data, reply, option) == 0,
88         "send request failed");
89 }
90 
OnFastForward()91 void AVSessionCallbackProxy::OnFastForward()
92 {
93     MessageParcel data;
94     CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
95 
96     auto remote = Remote();
97     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
98     MessageParcel reply;
99     MessageOption option = { MessageOption::TF_ASYNC };
100     CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_FAST_FORWARD, data, reply, option) == 0,
101         "send request failed");
102 }
103 
OnRewind()104 void AVSessionCallbackProxy::OnRewind()
105 {
106     MessageParcel data;
107     CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
108 
109     auto remote = Remote();
110     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
111     MessageParcel reply;
112     MessageOption option = { MessageOption::TF_ASYNC };
113     CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_REWIND, data, reply, option) == 0,
114         "send request failed");
115 }
116 
OnSeek(int64_t time)117 void AVSessionCallbackProxy::OnSeek(int64_t time)
118 {
119     MessageParcel data;
120     CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
121     CHECK_AND_RETURN_LOG(data.WriteInt64(time), "write time failed");
122 
123     auto remote = Remote();
124     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
125     MessageParcel reply;
126     MessageOption option = { MessageOption::TF_ASYNC };
127     CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_SEEK, data, reply, option) == 0,
128         "OnSeek send request failed");
129 }
130 
OnSetSpeed(double speed)131 void AVSessionCallbackProxy::OnSetSpeed(double speed)
132 {
133     MessageParcel data;
134     CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
135     CHECK_AND_RETURN_LOG(data.WriteDouble(speed), "write speed failed");
136 
137     auto remote = Remote();
138     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
139     MessageParcel reply;
140     MessageOption option = { MessageOption::TF_ASYNC };
141     CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_SET_SPEED, data, reply, option) == 0,
142         "OnSetSpeed send request failed");
143 }
144 
OnSetLoopMode(int32_t loopMode)145 void AVSessionCallbackProxy::OnSetLoopMode(int32_t loopMode)
146 {
147     MessageParcel data;
148     CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
149     CHECK_AND_RETURN_LOG(data.WriteInt32(loopMode), "write loopMode failed");
150 
151     auto remote = Remote();
152     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
153     MessageParcel reply;
154     MessageOption option = { MessageOption::TF_ASYNC };
155     CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_SET_LOOPMODE, data, reply, option) == 0,
156         "send request failed");
157 }
158 
OnToggleFavorite(const std::string & mediaId)159 void AVSessionCallbackProxy::OnToggleFavorite(const std::string& mediaId)
160 {
161     MessageParcel data;
162     CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
163     CHECK_AND_RETURN_LOG(data.WriteString(mediaId), "write mediaId failed");
164 
165     auto remote = Remote();
166     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
167     MessageParcel reply;
168     MessageOption option = { MessageOption::TF_ASYNC };
169     CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_TOGGLE_FAVORITE, data, reply, option) == 0,
170         "send request failed");
171 }
172 
OnMediaKeyEvent(const MMI::KeyEvent & keyEvent)173 void AVSessionCallbackProxy::OnMediaKeyEvent(const MMI::KeyEvent& keyEvent)
174 {
175     MessageParcel data;
176     CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
177     CHECK_AND_RETURN_LOG(keyEvent.WriteToParcel(data), "write keyEvent failed");
178 
179     auto remote = Remote();
180     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
181     MessageParcel reply;
182     MessageOption option = { MessageOption::TF_ASYNC };
183     CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_MEDIA_KEY_EVENT, data, reply, option) == 0,
184         "send request failed");
185 }
186 
OnOutputDeviceChange(const OutputDeviceInfo & outputDeviceInfo)187 void AVSessionCallbackProxy::OnOutputDeviceChange(const OutputDeviceInfo& outputDeviceInfo)
188 {
189     MessageParcel data;
190     CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
191     CHECK_AND_RETURN_LOG(data.WriteBool(outputDeviceInfo.isRemote_), "write isRemote_ failed");
192     CHECK_AND_RETURN_LOG(data.WriteStringVector(outputDeviceInfo.deviceIds_), "write deviceIds_ failed");
193     CHECK_AND_RETURN_LOG(data.WriteStringVector(outputDeviceInfo.deviceNames_), "write deviceNames_ failed");
194 
195     auto remote = Remote();
196     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
197     MessageParcel reply;
198     MessageOption option = { MessageOption::TF_ASYNC };
199     CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_OUTPUT_DEVICE_CHANGE, data, reply, option) == 0,
200                          "send request failed");
201 }
202 } // namespace OHOS::AVSession