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_proxy.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 {
HStreamRepeatCallbackProxy(const sptr<IRemoteObject> & impl)23 HStreamRepeatCallbackProxy::HStreamRepeatCallbackProxy(const sptr<IRemoteObject> &impl)
24     : IRemoteProxy<IStreamRepeatCallback>(impl) { }
25 
OnFrameStarted()26 int32_t HStreamRepeatCallbackProxy::OnFrameStarted()
27 {
28     MessageParcel data;
29     MessageParcel reply;
30     MessageOption option;
31     option.SetFlags(option.TF_ASYNC);
32 
33     data.WriteInterfaceToken(GetDescriptor());
34     int error = Remote()->SendRequest(
35         static_cast<uint32_t>(StreamRepeatCallbackInterfaceCode::CAMERA_STREAM_REPEAT_ON_FRAME_STARTED),
36         data, reply, option);
37     if (error != ERR_NONE) {
38         MEDIA_ERR_LOG("HStreamRepeatCallbackProxy OnFrameStarted failed, error: %{public}d", error);
39     }
40 
41     return error;
42 }
43 
OnFrameEnded(int32_t frameCount)44 int32_t HStreamRepeatCallbackProxy::OnFrameEnded(int32_t frameCount)
45 {
46     MessageParcel data;
47     MessageParcel reply;
48     MessageOption option;
49     option.SetFlags(option.TF_ASYNC);
50 
51     data.WriteInterfaceToken(GetDescriptor());
52     data.WriteInt32(frameCount);
53 
54     int error = Remote()->SendRequest(
55         static_cast<uint32_t>(StreamRepeatCallbackInterfaceCode::CAMERA_STREAM_REPEAT_ON_FRAME_ENDED),
56         data, reply, option);
57     if (error != ERR_NONE) {
58         MEDIA_ERR_LOG("HStreamRepeatCallbackProxy OnFrameEnded failed, error: %{public}d", error);
59     }
60 
61     return error;
62 }
63 
OnFrameError(int32_t errorCode)64 int32_t HStreamRepeatCallbackProxy::OnFrameError(int32_t errorCode)
65 {
66     MessageParcel data;
67     MessageParcel reply;
68     MessageOption option;
69     option.SetFlags(option.TF_ASYNC);
70 
71     data.WriteInterfaceToken(GetDescriptor());
72     data.WriteInt32(errorCode);
73 
74     int error = Remote()->SendRequest(
75         static_cast<uint32_t>(StreamRepeatCallbackInterfaceCode::CAMERA_STREAM_REPEAT_ON_ERROR), data, reply, option);
76     if (error != ERR_NONE) {
77         MEDIA_ERR_LOG("HStreamRepeatCallbackProxy OnFrameError failed, error: %{public}d", error);
78     }
79 
80     return error;
81 }
82 
OnSketchStatusChanged(SketchStatus status)83 int32_t HStreamRepeatCallbackProxy::OnSketchStatusChanged(SketchStatus status)
84 {
85     MessageParcel data;
86     MessageParcel reply;
87     MessageOption option;
88     option.SetFlags(option.TF_ASYNC);
89     data.WriteInterfaceToken(GetDescriptor());
90     data.WriteInt32(static_cast<int32_t>(status));
91 
92     int error = Remote()->SendRequest(
93         static_cast<uint32_t>(StreamRepeatCallbackInterfaceCode::CAMERA_STREAM_SKETCH_STATUS_ON_CHANGED), data, reply,
94         option);
95     if (error != ERR_NONE) {
96         MEDIA_ERR_LOG("HStreamRepeatCallbackProxy OnSketchStatusChanged failed, error: %{public}d", error);
97     }
98     return error;
99 }
100 
OnDeferredVideoEnhancementInfo(CaptureEndedInfoExt captureEndedInfo)101 int32_t HStreamRepeatCallbackProxy::OnDeferredVideoEnhancementInfo(CaptureEndedInfoExt captureEndedInfo)
102 {
103     MessageParcel data;
104     MessageParcel reply;
105     MessageOption option;
106     option.SetFlags(option.TF_ASYNC);
107     data.WriteInterfaceToken(GetDescriptor());
108     data.WriteInt32(captureEndedInfo.streamId);
109     data.WriteInt32(captureEndedInfo.frameCount);
110     data.WriteBool(captureEndedInfo.isDeferredVideoEnhancementAvailable);
111     data.WriteString(captureEndedInfo.videoId);
112     int error = Remote()->SendRequest(
113         static_cast<uint32_t>(StreamRepeatCallbackInterfaceCode::CAMERA_STREAM_REPEAT_VIDEO_DEFERRED_INFO), data, reply,
114         option);
115     if (error != ERR_NONE) {
116         MEDIA_ERR_LOG("HStreamRepeatCallbackProxy OnDeferredVideoEnhancementInfo failed, error: %{public}d", error);
117     }
118     return error;
119 }
120 } // namespace CameraStandard
121 } // namespace OHOS
122