1 /*
2  * Copyright (c) 2021-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 "hstream_repeat_callback_stub.h"
17 #include "camera_log.h"
18 #include "camera_service_ipc_interface_code.h"
19 #include "istream_repeat_callback.h"
20 
21 namespace OHOS {
22 namespace CameraStandard {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)23 int HStreamRepeatCallbackStub::OnRemoteRequest(
24     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
25 {
26     int errCode = -1;
27 
28     CHECK_AND_RETURN_RET(data.ReadInterfaceToken() == GetDescriptor(), errCode);
29     switch (code) {
30         case static_cast<uint32_t>(StreamRepeatCallbackInterfaceCode::CAMERA_STREAM_REPEAT_ON_FRAME_STARTED):
31             errCode = OnFrameStarted();
32             break;
33         case static_cast<uint32_t>(StreamRepeatCallbackInterfaceCode::CAMERA_STREAM_REPEAT_ON_FRAME_ENDED):
34             errCode = HStreamRepeatCallbackStub::HandleOnFrameEnded(data);
35             break;
36         case static_cast<uint32_t>(StreamRepeatCallbackInterfaceCode::CAMERA_STREAM_REPEAT_ON_ERROR):
37             errCode = HStreamRepeatCallbackStub::HandleOnFrameError(data);
38             break;
39         case static_cast<uint32_t>(StreamRepeatCallbackInterfaceCode::CAMERA_STREAM_SKETCH_STATUS_ON_CHANGED):
40             errCode = HStreamRepeatCallbackStub::HandleOnSketchStatusChanged(data);
41             break;
42         case static_cast<uint32_t>(StreamRepeatCallbackInterfaceCode::CAMERA_STREAM_REPEAT_VIDEO_DEFERRED_INFO):
43             errCode = HStreamRepeatCallbackStub::HandleOnDeferredVideoEnhancementInfo(data);
44             break;
45         default:
46             MEDIA_ERR_LOG("HStreamRepeatCallbackStub request code %{public}u not handled", code);
47             errCode = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
48             break;
49     }
50 
51     return errCode;
52 }
53 
HandleOnFrameEnded(MessageParcel & data)54 int HStreamRepeatCallbackStub::HandleOnFrameEnded(MessageParcel& data)
55 {
56     int32_t frameCount = data.ReadInt32();
57     return OnFrameEnded(frameCount);
58 }
59 
HandleOnFrameError(MessageParcel & data)60 int HStreamRepeatCallbackStub::HandleOnFrameError(MessageParcel& data)
61 {
62     int32_t errorType = static_cast<int32_t>(data.ReadUint64());
63     return OnFrameError(errorType);
64 }
65 
HandleOnSketchStatusChanged(MessageParcel & data)66 int HStreamRepeatCallbackStub::HandleOnSketchStatusChanged(MessageParcel& data)
67 {
68     int32_t status = data.ReadInt32();
69     return OnSketchStatusChanged(static_cast<SketchStatus>(status));
70 }
71 
HandleOnDeferredVideoEnhancementInfo(MessageParcel & data)72 int HStreamRepeatCallbackStub::HandleOnDeferredVideoEnhancementInfo(MessageParcel& data)
73 {
74     CaptureEndedInfoExt captureEndedInfo;
75     captureEndedInfo.streamId = data.ReadInt32();
76     captureEndedInfo.frameCount = data.ReadInt32();
77     captureEndedInfo.isDeferredVideoEnhancementAvailable = data.ReadBool();
78     captureEndedInfo.videoId = data.ReadString();
79     return OnDeferredVideoEnhancementInfo(captureEndedInfo);
80 }
81 } // namespace CameraStandard
82 } // namespace OHOS
83