• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     SLOGI("OnCastPlaybackStateChange in proxy for state %{public}d", state.GetState());
29     MessageParcel parcel;
30     CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
31     CHECK_AND_RETURN_LOG(parcel.WriteParcelable(&state), "write PlaybackState failed");
32 
33     MessageParcel reply;
34     MessageOption option = { MessageOption::TF_ASYNC };
35     auto remote = Remote();
36     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
37     SLOGI("OnCastPlaybackStateChange in proxy to send request for state %{public}d", state.GetState());
38     CHECK_AND_RETURN_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_ON_CAST_PLAYBACK_STATE_CHANGE,
39         parcel, reply, option) == 0,
40         "send request failed");
41     SLOGI("OnCastPlaybackStateChange done in proxy for state %{public}d", state.GetState());
42 }
43 
OnMediaItemChange(const AVQueueItem & avQueueItem)44 void AVCastControllerCallbackProxy::OnMediaItemChange(const AVQueueItem& avQueueItem)
45 {
46     SLOGI("OnMediaItemChange in proxy");
47     MessageParcel parcel;
48     CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
49     CHECK_AND_RETURN_LOG(parcel.WriteParcelable(&avQueueItem), "Write avQueueItem failed");
50 
51     MessageParcel reply;
52     MessageOption option = { MessageOption::TF_ASYNC };
53     auto remote = Remote();
54     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
55     SLOGI("OnMediaItemChange in proxy to send request");
56     CHECK_AND_RETURN_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_ON_MEDIA_ITEM_CHANGE, parcel, reply, option) == 0,
57         "send request failed");
58     SLOGI("OnMediaItemChange in proxy done");
59 }
60 
OnPlayNext()61 void AVCastControllerCallbackProxy::OnPlayNext()
62 {
63     MessageParcel parcel;
64     CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
65 
66     MessageParcel reply;
67     MessageOption option = { MessageOption::TF_ASYNC };
68     auto remote = Remote();
69     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
70     CHECK_AND_RETURN_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_ON_PLAY_NEXT, parcel, reply, option) == 0,
71         "send request failed");
72 }
73 
OnPlayPrevious()74 void AVCastControllerCallbackProxy::OnPlayPrevious()
75 {
76     MessageParcel parcel;
77     CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
78 
79     MessageParcel reply;
80     MessageOption option = { MessageOption::TF_ASYNC };
81     auto remote = Remote();
82     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
83     CHECK_AND_RETURN_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_ON_PLAY_PREVIOUS, parcel, reply, option) == 0,
84         "send request failed");
85 }
86 
OnSeekDone(const int32_t seekNumber)87 void AVCastControllerCallbackProxy::OnSeekDone(const int32_t seekNumber)
88 {
89     MessageParcel parcel;
90     CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
91     CHECK_AND_RETURN_LOG(parcel.WriteInt32(seekNumber), "write seekNumber failed");
92 
93     MessageParcel reply;
94     MessageOption option = { MessageOption::TF_ASYNC };
95     auto remote = Remote();
96     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
97     CHECK_AND_RETURN_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_ON_SEEK_DONE, parcel, reply, option) == 0,
98         "send request failed");
99 }
100 
OnVideoSizeChange(const int32_t width,const int32_t height)101 void AVCastControllerCallbackProxy::OnVideoSizeChange(const int32_t width, const int32_t height)
102 {
103     MessageParcel parcel;
104     CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
105     CHECK_AND_RETURN_LOG(parcel.WriteInt32(width), "write width failed");
106     CHECK_AND_RETURN_LOG(parcel.WriteInt32(height), "write height failed");
107 
108     MessageParcel reply;
109     MessageOption option = { MessageOption::TF_ASYNC };
110     auto remote = Remote();
111     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
112     CHECK_AND_RETURN_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_ON_VIDEO_SIZE_CHANGE, parcel, reply, option) == 0,
113         "send request failed");
114 }
115 
OnPlayerError(const int32_t errorCode,const std::string & errorMsg)116 void AVCastControllerCallbackProxy::OnPlayerError(const int32_t errorCode, const std::string& errorMsg)
117 {
118     MessageParcel parcel;
119     CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
120     CHECK_AND_RETURN_LOG(parcel.WriteInt32(errorCode), "write time failed");
121     CHECK_AND_RETURN_LOG(parcel.WriteString(errorMsg), "write time failed");
122 
123     MessageParcel reply;
124     MessageOption option = { MessageOption::TF_ASYNC };
125     auto remote = Remote();
126     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
127     CHECK_AND_RETURN_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_ON_ERROR, parcel, reply, option) == 0,
128         "send request failed");
129 }
130 
OnEndOfStream(const int32_t isLooping)131 void AVCastControllerCallbackProxy::OnEndOfStream(const int32_t isLooping)
132 {
133     MessageParcel parcel;
134     CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
135     CHECK_AND_RETURN_LOG(parcel.WriteInt32(isLooping), "write isLooping failed");
136 
137     MessageParcel reply;
138     MessageOption option = { MessageOption::TF_ASYNC };
139     auto remote = Remote();
140     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
141     CHECK_AND_RETURN_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_ON_END_OF_STREAM, parcel, reply, option) == 0,
142         "send request failed");
143 }
144 
OnPlayRequest(const AVQueueItem & avQueueItem)145 void AVCastControllerCallbackProxy::OnPlayRequest(const AVQueueItem& avQueueItem)
146 {
147     SLOGI("OnPlayRequest in proxy");
148     MessageParcel parcel;
149     CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
150     CHECK_AND_RETURN_LOG(parcel.WriteParcelable(&avQueueItem), "Write avQueueItem failed");
151 
152     MessageParcel reply;
153     MessageOption option = { MessageOption::TF_ASYNC };
154     auto remote = Remote();
155     CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
156     SLOGI("OnPlayRequest in proxy to send request");
157     CHECK_AND_RETURN_LOG(remote->SendRequest(CAST_CONTROLLER_CMD_ON_PLAY_REQUEST, parcel, reply, option) == 0,
158         "send request failed");
159     SLOGI("OnPlayRequest in proxy done");
160 }
161 } // namespace OHOS::AVSession
162