From 0c25212a448119fa2f383ced0add418826505514 Mon Sep 17 00:00:00 2001 From: hobbycao Date: Wed, 8 Jun 2022 17:44:09 +0800 Subject: [PATCH] feat: add distributed camera driver config Signed-off-by: hobbycao --- distributed_camera/BUILD.gn | 22 +++ distributed_camera/bundle.json | 3 +- distributed_camera/distributedcamera.gni | 17 +++ distributed_camera/hdi_service/BUILD.gn | 39 ++++++ .../src/config/dcamera_provider_config.cpp | 125 ++++++++++++++++++ 5 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 distributed_camera/BUILD.gn create mode 100644 distributed_camera/distributedcamera.gni create mode 100644 distributed_camera/hdi_service/BUILD.gn create mode 100644 distributed_camera/hdi_service/src/config/dcamera_provider_config.cpp diff --git a/distributed_camera/BUILD.gn b/distributed_camera/BUILD.gn new file mode 100644 index 0000000000..07a20277e8 --- /dev/null +++ b/distributed_camera/BUILD.gn @@ -0,0 +1,22 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if (defined(ohos_lite)) { + group("distributed_camera_entry") { + deps = [] + } +} else { + group("distributed_camera_entry") { + deps = [ "./hdi_service:hdf_distributed_camera_service" ] + } +} diff --git a/distributed_camera/bundle.json b/distributed_camera/bundle.json index 7810ef75b5..1fa7528dd5 100644 --- a/distributed_camera/bundle.json +++ b/distributed_camera/bundle.json @@ -27,8 +27,7 @@ }, "build":{ "sub_component":[ - "//foundation/distributedhardware/distributed_camera/camera_hdf/interfaces/hdi_ipc/config/host:distributed_camera_host_config", - "//foundation/distributedhardware/distributed_camera/camera_hdf/interfaces/hdi_ipc/config/provider:distributed_camera_provider_config" + "//drivers/peripheral/distributed_camera:distributed_camera_entry" ], "inner_kits":[ diff --git a/distributed_camera/distributedcamera.gni b/distributed_camera/distributedcamera.gni new file mode 100644 index 0000000000..b56debf9fd --- /dev/null +++ b/distributed_camera/distributedcamera.gni @@ -0,0 +1,17 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +distributedcamera_hdf_path = + "//foundation/distributedhardware/distributed_camera" + +hdi_service_path = "${distributedcamera_hdf_path}/camera_hdf" diff --git a/distributed_camera/hdi_service/BUILD.gn b/distributed_camera/hdi_service/BUILD.gn new file mode 100644 index 0000000000..5ee71f0915 --- /dev/null +++ b/distributed_camera/hdi_service/BUILD.gn @@ -0,0 +1,39 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//drivers/adapter/uhdf2/uhdf.gni") +import("//drivers/peripheral/distributed_camera/distributedcamera.gni") + +ohos_shared_library("libdistributed_camera_provider_config") { + include_dirs = [ "${hdi_service_path}/hdi_impl/include/dcamera_provider" ] + sources = [ "./src/config/dcamera_provider_config.cpp" ] + deps = [ "${hdi_service_path}/hdi_impl:distributed_camera_hdf" ] + + external_deps = [ + "device_driver_framework:libhdf_host", + "device_driver_framework:libhdf_ipc_adapter", + "device_driver_framework:libhdf_utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", + "utils_base:utils", + ] + + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "distributed_camera_device_driver" +} + +group("hdf_distributed_camera_service") { + deps = [ ":libdistributed_camera_provider_config" ] +} diff --git a/distributed_camera/hdi_service/src/config/dcamera_provider_config.cpp b/distributed_camera/hdi_service/src/config/dcamera_provider_config.cpp new file mode 100644 index 0000000000..8c3ca4a191 --- /dev/null +++ b/distributed_camera/hdi_service/src/config/dcamera_provider_config.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "dcamera_provider.h" +#include "v1_0/dcamera_provider_stub.h" + +using namespace OHOS::HDI::DistributedCamera::V1_0; + +struct HdfDCameraProviderHost { + struct IDeviceIoService ioService; + OHOS::sptr stub; +}; + +static int32_t DCameraProviderDriverDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, + struct HdfSBuf *reply) +{ + auto *hdfDCameraProviderHost = CONTAINER_OF(client->device->service, struct HdfDCameraProviderHost, ioService); + + OHOS::MessageParcel *dataParcel = nullptr; + OHOS::MessageParcel *replyParcel = nullptr; + OHOS::MessageOption option; + + if (SbufToParcel(data, &dataParcel) != HDF_SUCCESS) { + HDF_LOGE("%{public}s:invalid data sbuf object to dispatch", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (SbufToParcel(reply, &replyParcel) != HDF_SUCCESS) { + HDF_LOGE("%{public}s:invalid reply sbuf object to dispatch", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return hdfDCameraProviderHost->stub->SendRequest(cmdId, *dataParcel, *replyParcel, option); +} + +static int HdfDCameraProviderDriverInit(struct HdfDeviceObject *deviceObject) +{ + HDF_LOGI("HdfDCameraProviderDriverInit enter"); + if (deviceObject == nullptr) { + HDF_LOGE("HdfDCameraHostDriverInit:: HdfDeviceObject is NULL !"); + return HDF_FAILURE; + } + + if (!HdfDeviceSetClass(deviceObject, DEVICE_CLASS_CAMERA)) { + HDF_LOGE("HdfDCameraHostDriverInit set camera class failed"); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} + +static int HdfDCameraProviderDriverBind(struct HdfDeviceObject *deviceObject) +{ + HDF_LOGI("HdfDCameraProviderDriverBind enter"); + + auto *hdfDCameraProviderHost = new (std::nothrow) HdfDCameraProviderHost; + if (hdfDCameraProviderHost == nullptr) { + HDF_LOGE("%{public}s: failed to create create HdfDCameraProviderHost object", __func__); + return HDF_FAILURE; + } + + hdfDCameraProviderHost->ioService.Dispatch = DCameraProviderDriverDispatch; + hdfDCameraProviderHost->ioService.Open = NULL; + hdfDCameraProviderHost->ioService.Release = NULL; + + auto serviceImpl = OHOS::DistributedHardware::DCameraProvider::GetInstance(); + if (serviceImpl == nullptr) { + HDF_LOGE("%{public}s: failed to get of implement service", __func__); + delete hdfDCameraProviderHost; + return HDF_FAILURE; + } + + hdfDCameraProviderHost->stub = OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(serviceImpl, + IDCameraProvider::GetDescriptor()); + if (hdfDCameraProviderHost->stub == nullptr) { + HDF_LOGE("%{public}s: failed to get stub object", __func__); + delete hdfDCameraProviderHost; + return HDF_FAILURE; + } + + deviceObject->service = &hdfDCameraProviderHost->ioService; + return HDF_SUCCESS; +} + +static void HdfDCameraProviderDriverRelease(struct HdfDeviceObject *deviceObject) +{ + HDF_LOGI("HdfDCameraProviderDriverRelease enter"); + if (deviceObject == nullptr || deviceObject->service == nullptr) { + HDF_LOGE("%{public}s: parms is invalid.", __func__); + return; + } + auto *hdfDCameraProviderHost = CONTAINER_OF(deviceObject->service, struct HdfDCameraProviderHost, ioService); + delete hdfDCameraProviderHost; +} + +static struct HdfDriverEntry g_dcameraproviderDriverEntry = { + .moduleVersion = 1, + .moduleName = "distributed_camera_provider_service", + .Bind = HdfDCameraProviderDriverBind, + .Init = HdfDCameraProviderDriverInit, + .Release = HdfDCameraProviderDriverRelease, +}; + +#ifndef __cplusplus +extern "C" { +#endif +HDF_INIT(g_dcameraproviderDriverEntry); +#ifndef __cplusplus +} +#endif -- Gitee