• 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     OnCastPlaybackStateChange(*state);
51     return ERR_NONE;
52 }
53 
HandleOnMediaItemChange(MessageParcel & data,MessageParcel & reply)54 int32_t AVCastControllerCallbackStub::HandleOnMediaItemChange(MessageParcel& data, MessageParcel& reply)
55 {
56     AVSESSION_TRACE_SYNC_START("AVCastControllerCallbackStub::HandleOnMediaItemChange");
57     sptr<AVQueueItem> item = data.ReadParcelable<AVQueueItem>();
58     CHECK_AND_RETURN_RET_LOG(item != nullptr, ERR_UNMARSHALLING, "read parcelable AVQueueItem failed");
59     OnMediaItemChange(*item);
60     return ERR_NONE;
61 }
62 
HandleOnPlayNext(MessageParcel & data,MessageParcel & reply)63 int32_t AVCastControllerCallbackStub::HandleOnPlayNext(MessageParcel& data, MessageParcel& reply)
64 {
65     OnPlayNext();
66     return ERR_NONE;
67 }
68 
HandleOnPlayPrevious(MessageParcel & data,MessageParcel & reply)69 int32_t AVCastControllerCallbackStub::HandleOnPlayPrevious(MessageParcel& data, MessageParcel& reply)
70 {
71     OnPlayPrevious();
72     return ERR_NONE;
73 }
74 
HandleOnSeekDone(MessageParcel & data,MessageParcel & reply)75 int32_t AVCastControllerCallbackStub::HandleOnSeekDone(MessageParcel& data, MessageParcel& reply)
76 {
77     int32_t seekNumber;
78     CHECK_AND_RETURN_RET_LOG(data.ReadInt32(seekNumber), ERR_NONE, "read seekNumber failed");
79     OnSeekDone(seekNumber);
80     return ERR_NONE;
81 }
82 
HandleOnVideoSizeChange(MessageParcel & data,MessageParcel & reply)83 int32_t AVCastControllerCallbackStub::HandleOnVideoSizeChange(MessageParcel& data, MessageParcel& reply)
84 {
85     int32_t width;
86     int32_t height;
87     CHECK_AND_RETURN_RET_LOG(data.ReadInt32(width), ERR_NONE, "read time failed");
88     CHECK_AND_RETURN_RET_LOG(data.ReadInt32(height), ERR_NONE, "read time failed");
89     OnVideoSizeChange(width, height);
90     return ERR_NONE;
91 }
92 
HandleOnPlayerError(MessageParcel & data,MessageParcel & reply)93 int32_t AVCastControllerCallbackStub::HandleOnPlayerError(MessageParcel& data, MessageParcel& reply)
94 {
95     int32_t errorCode;
96     CHECK_AND_RETURN_RET_LOG(data.ReadInt32(errorCode), ERR_NONE, "read time failed");
97     std::string errorMsg;
98     CHECK_AND_RETURN_RET_LOG(data.ReadString(errorMsg), ERR_NONE, "read time failed");
99     OnPlayerError(errorCode, errorMsg);
100     return ERR_NONE;
101 }
102 
HandleOnEndOfStream(MessageParcel & data,MessageParcel & reply)103 int32_t AVCastControllerCallbackStub::HandleOnEndOfStream(MessageParcel& data, MessageParcel& reply)
104 {
105     int32_t isLooping;
106     CHECK_AND_RETURN_RET_LOG(data.ReadInt32(isLooping), ERR_NONE, "read isLooping failed");
107     OnEndOfStream(isLooping);
108     return ERR_NONE;
109 }
110 } // namespace OHOS::AVSession
111