• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_stub.h"
17 #include "camera_log.h"
18 #include "camera_util.h"
19 #include "remote_request_code.h"
20 
21 namespace OHOS {
22 namespace CameraStandard {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)23 int HStreamRepeatStub::OnRemoteRequest(
24     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
25 {
26     DisableJeMalloc();
27     int errCode = -1;
28 
29     if (data.ReadInterfaceToken() != GetDescriptor()) {
30         return errCode;
31     }
32     switch (code) {
33         case CAMERA_START_VIDEO_RECORDING:
34             errCode = Start();
35             break;
36         case CAMERA_STOP_VIDEO_RECORDING:
37             errCode = Stop();
38             break;
39         case CAMERA_STREAM_REPEAT_SET_CALLBACK:
40             errCode = HStreamRepeatStub::HandleSetCallback(data);
41             break;
42         case CAMERA_STREAM_REPEAT_RELEASE:
43             errCode = Release();
44             break;
45         case CAMERA_ADD_DEFERRED_SURFACE:
46             errCode = HStreamRepeatStub::HandleAddDeferredSurface(data);
47             break;
48         default:
49             MEDIA_ERR_LOG("HStreamRepeatStub request code %{public}u not handled", code);
50             errCode = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
51             break;
52     }
53 
54     return errCode;
55 }
56 
HandleSetCallback(MessageParcel & data)57 int HStreamRepeatStub::HandleSetCallback(MessageParcel &data)
58 {
59     auto remoteObject = data.ReadRemoteObject();
60     if (remoteObject == nullptr) {
61         MEDIA_ERR_LOG("HStreamRepeatStub HandleSetCallback StreamRepeatCallback is null");
62         return IPC_STUB_INVALID_DATA_ERR;
63     }
64 
65     auto callback = iface_cast<IStreamRepeatCallback>(remoteObject);
66 
67     return SetCallback(callback);
68 }
69 
HandleAddDeferredSurface(MessageParcel & data)70 int HStreamRepeatStub::HandleAddDeferredSurface(MessageParcel &data)
71 {
72     sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
73 
74     if (remoteObj == nullptr) {
75         MEDIA_ERR_LOG("HStreamRepeatStub HandleAddDeferredSurface BufferProducer is null");
76         return IPC_STUB_INVALID_DATA_ERR;
77     }
78 
79     sptr<OHOS::IBufferProducer> producer = iface_cast<OHOS::IBufferProducer>(remoteObj);
80     int errCode = AddDeferredSurface(producer);
81     if (errCode != ERR_NONE) {
82         MEDIA_ERR_LOG("HStreamRepeatStub::HandleAddDeferredSurface add deferred surface failed : %{public}d", errCode);
83         return errCode;
84     }
85 
86     return errCode;
87 }
88 } // namespace CameraStandard
89 } // namespace OHOS
90