1 /*
2 * Copyright (c) 2023 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 "avcast_controller_callback_proxy.h"
17 #include "avsession_log.h"
18
19 namespace OHOS::AVSession {
AVCastControllerCallbackProxy(const sptr<IRemoteObject> & impl)20 AVCastControllerCallbackProxy::AVCastControllerCallbackProxy(const sptr<IRemoteObject>& impl)
21 : IRemoteProxy<IAVCastControllerCallback>(impl)
22 {
23 SLOGD("construct");
24 }
25
OnCastPlaybackStateChange(const AVPlaybackState & state)26 void AVCastControllerCallbackProxy::OnCastPlaybackStateChange(const AVPlaybackState& state)
27 {
28 MessageParcel parcel;
29 CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
30 CHECK_AND_RETURN_LOG(parcel.WriteParcelable(&state), "write PlaybackState failed");
31
32 MessageParcel reply;
33 MessageOption option = { MessageOption::TF_ASYNC };
34 auto remote = Remote();
35 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
36 CHECK_AND_RETURN_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_ON_CAST_PLAYBACK_STATE_CHANGE,
37 parcel, reply, option) == 0,
38 "send request failed");
39 }
40
OnMediaItemChange(const AVQueueItem & avQueueItem)41 void AVCastControllerCallbackProxy::OnMediaItemChange(const AVQueueItem& avQueueItem)
42 {
43 MessageParcel parcel;
44 CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
45 CHECK_AND_RETURN_LOG(parcel.WriteParcelable(&avQueueItem), "Write avQueueItem failed");
46
47 MessageParcel reply;
48 MessageOption option = { MessageOption::TF_ASYNC };
49 auto remote = Remote();
50 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
51 CHECK_AND_RETURN_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_ON_MEDIA_ITEM_CHANGE, parcel, reply, option) == 0,
52 "send request failed");
53 }
54
OnPlayNext()55 void AVCastControllerCallbackProxy::OnPlayNext()
56 {
57 MessageParcel parcel;
58 CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
59
60 MessageParcel reply;
61 MessageOption option = { MessageOption::TF_ASYNC };
62 auto remote = Remote();
63 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
64 CHECK_AND_RETURN_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_ON_PLAY_NEXT, parcel, reply, option) == 0,
65 "send request failed");
66 }
67
OnPlayPrevious()68 void AVCastControllerCallbackProxy::OnPlayPrevious()
69 {
70 MessageParcel parcel;
71 CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
72
73 MessageParcel reply;
74 MessageOption option = { MessageOption::TF_ASYNC };
75 auto remote = Remote();
76 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
77 CHECK_AND_RETURN_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_ON_PLAY_PREVIOUS, parcel, reply, option) == 0,
78 "send request failed");
79 }
80
OnSeekDone(const int32_t seekNumber)81 void AVCastControllerCallbackProxy::OnSeekDone(const int32_t seekNumber)
82 {
83 MessageParcel parcel;
84 CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
85 CHECK_AND_RETURN_LOG(parcel.WriteInt32(seekNumber), "write seekNumber failed");
86
87 MessageParcel reply;
88 MessageOption option = { MessageOption::TF_ASYNC };
89 auto remote = Remote();
90 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
91 CHECK_AND_RETURN_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_ON_SEEK_DONE, parcel, reply, option) == 0,
92 "send request failed");
93 }
94
OnVideoSizeChange(const int32_t width,const int32_t height)95 void AVCastControllerCallbackProxy::OnVideoSizeChange(const int32_t width, const int32_t height)
96 {
97 MessageParcel parcel;
98 CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
99 CHECK_AND_RETURN_LOG(parcel.WriteInt32(width), "write width failed");
100 CHECK_AND_RETURN_LOG(parcel.WriteInt32(height), "write height failed");
101
102 MessageParcel reply;
103 MessageOption option = { MessageOption::TF_ASYNC };
104 auto remote = Remote();
105 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
106 CHECK_AND_RETURN_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_ON_VIDEO_SIZE_CHANGE, parcel, reply, option) == 0,
107 "send request failed");
108 }
109
OnPlayerError(const int32_t errorCode,const std::string & errorMsg)110 void AVCastControllerCallbackProxy::OnPlayerError(const int32_t errorCode, const std::string& errorMsg)
111 {
112 MessageParcel parcel;
113 CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
114 CHECK_AND_RETURN_LOG(parcel.WriteInt32(errorCode), "write time failed");
115 CHECK_AND_RETURN_LOG(parcel.WriteString(errorMsg), "write time failed");
116
117 MessageParcel reply;
118 MessageOption option = { MessageOption::TF_ASYNC };
119 auto remote = Remote();
120 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
121 CHECK_AND_RETURN_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_ON_ERROR, parcel, reply, option) == 0,
122 "send request failed");
123 }
124
OnEndOfStream(const int32_t isLooping)125 void AVCastControllerCallbackProxy::OnEndOfStream(const int32_t isLooping)
126 {
127 MessageParcel parcel;
128 CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
129 CHECK_AND_RETURN_LOG(parcel.WriteInt32(isLooping), "write isLooping failed");
130
131 MessageParcel reply;
132 MessageOption option = { MessageOption::TF_ASYNC };
133 auto remote = Remote();
134 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
135 CHECK_AND_RETURN_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_ON_END_OF_STREAM, parcel, reply, option) == 0,
136 "send request failed");
137 }
138 } // namespace OHOS::AVSession
139