• 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 #include "avcast_controller_callback_stub.h"
16 #include "avsession_errors.h"
17 #include "avsession_log.h"
18 #include "avsession_trace.h"
19 
20 namespace OHOS::AVSession {
CheckInterfaceToken(MessageParcel & data)21 bool AVCastControllerCallbackStub::CheckInterfaceToken(MessageParcel& data)
22 {
23     auto localDescriptor = IAVCastControllerCallback::GetDescriptor();
24     auto remoteDescriptor = data.ReadInterfaceToken();
25     if (remoteDescriptor != localDescriptor) {
26         SLOGI("interface token is not equal");
27         return false;
28     }
29     return true;
30 }
31 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)32 int32_t AVCastControllerCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
33     MessageOption &option)
34 {
35     if (!CheckInterfaceToken(data)) {
36         return AVSESSION_ERROR;
37     }
38     if (code < CAST_CONTROLLER_CMD_MAX) {
39         return (this->*handlers[code])(data, reply);
40     }
41     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
42 }
43 
HandleOnStateChange(MessageParcel & data,MessageParcel & reply)44 int32_t AVCastControllerCallbackStub::HandleOnStateChange(MessageParcel& data, MessageParcel& reply)
45 {
46     sptr<AVPlaybackState> state = data.ReadParcelable<AVPlaybackState>();
47 
48     CHECK_AND_RETURN_RET_LOG(state != nullptr, ERR_NONE, "read PlaybackState failed");
49     AVSESSION_TRACE_SYNC_START("AVCastControllerCallbackStub::HandleOnStateChange");
50     SLOGI("HandleOnStateChange with state: %{public}d", state->GetState());
51     OnCastPlaybackStateChange(*state);
52     return ERR_NONE;
53 }
54 
HandleOnMediaItemChange(MessageParcel & data,MessageParcel & reply)55 int32_t AVCastControllerCallbackStub::HandleOnMediaItemChange(MessageParcel& data, MessageParcel& reply)
56 {
57     AVSESSION_TRACE_SYNC_START("AVCastControllerCallbackStub::HandleOnMediaItemChange");
58     sptr<AVQueueItem> item = data.ReadParcelable<AVQueueItem>();
59     CHECK_AND_RETURN_RET_LOG(item != nullptr, ERR_UNMARSHALLING, "read parcelable AVQueueItem failed");
60     SLOGI("HandleOnMediaItemChange in");
61     OnMediaItemChange(*item);
62     return ERR_NONE;
63 }
64 
HandleOnPlayNext(MessageParcel & data,MessageParcel & reply)65 int32_t AVCastControllerCallbackStub::HandleOnPlayNext(MessageParcel& data, MessageParcel& reply)
66 {
67     OnPlayNext();
68     return ERR_NONE;
69 }
70 
HandleOnPlayPrevious(MessageParcel & data,MessageParcel & reply)71 int32_t AVCastControllerCallbackStub::HandleOnPlayPrevious(MessageParcel& data, MessageParcel& reply)
72 {
73     OnPlayPrevious();
74     return ERR_NONE;
75 }
76 
HandleOnSeekDone(MessageParcel & data,MessageParcel & reply)77 int32_t AVCastControllerCallbackStub::HandleOnSeekDone(MessageParcel& data, MessageParcel& reply)
78 {
79     int32_t seekNumber;
80     CHECK_AND_RETURN_RET_LOG(data.ReadInt32(seekNumber), ERR_NONE, "read seekNumber failed");
81     OnSeekDone(seekNumber);
82     return ERR_NONE;
83 }
84 
HandleOnVideoSizeChange(MessageParcel & data,MessageParcel & reply)85 int32_t AVCastControllerCallbackStub::HandleOnVideoSizeChange(MessageParcel& data, MessageParcel& reply)
86 {
87     int32_t width;
88     int32_t height;
89     CHECK_AND_RETURN_RET_LOG(data.ReadInt32(width), ERR_NONE, "read time failed");
90     CHECK_AND_RETURN_RET_LOG(data.ReadInt32(height), ERR_NONE, "read time failed");
91     OnVideoSizeChange(width, height);
92     return ERR_NONE;
93 }
94 
HandleOnPlayerError(MessageParcel & data,MessageParcel & reply)95 int32_t AVCastControllerCallbackStub::HandleOnPlayerError(MessageParcel& data, MessageParcel& reply)
96 {
97     int32_t errorCode;
98     CHECK_AND_RETURN_RET_LOG(data.ReadInt32(errorCode), ERR_NONE, "read time failed");
99     std::string errorMsg;
100     CHECK_AND_RETURN_RET_LOG(data.ReadString(errorMsg), ERR_NONE, "read time failed");
101     OnPlayerError(errorCode, errorMsg);
102     return ERR_NONE;
103 }
104 
HandleOnEndOfStream(MessageParcel & data,MessageParcel & reply)105 int32_t AVCastControllerCallbackStub::HandleOnEndOfStream(MessageParcel& data, MessageParcel& reply)
106 {
107     int32_t isLooping;
108     CHECK_AND_RETURN_RET_LOG(data.ReadInt32(isLooping), ERR_NONE, "read isLooping failed");
109     OnEndOfStream(isLooping);
110     return ERR_NONE;
111 }
112 
HandleOnPlayRequest(MessageParcel & data,MessageParcel & reply)113 int32_t AVCastControllerCallbackStub::HandleOnPlayRequest(MessageParcel& data, MessageParcel& reply)
114 {
115     AVSESSION_TRACE_SYNC_START("AVCastControllerCallbackStub::HandleOnPlayRequest");
116     sptr<AVQueueItem> item = data.ReadParcelable<AVQueueItem>();
117     CHECK_AND_RETURN_RET_LOG(item != nullptr, ERR_UNMARSHALLING, "read parcelable preload AVQueueItem failed");
118     SLOGI("HandleOnPlayRequest in");
119     OnPlayRequest(*item);
120     return ERR_NONE;
121 }
122 } // namespace OHOS::AVSession
123