diff --git a/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp b/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp index ff6b8783f024383f6348002ef08c5a96ed62e2eb..8bef3f5537c18262533c9480dcd75b1a684f0e2a 100644 --- a/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp +++ b/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp @@ -601,10 +601,13 @@ void DStreamOperator::ConvertStreamInfo(std::shared_ptr &srcInfo, st dstInfo->dataspace_ = srcInfo->datasapce_; dstInfo->encodeType_ = (DCEncodeType)srcInfo->encodeType_; - if ((srcInfo->intent_ == STILL_CAPTURE) || (srcInfo->intent_ == POST_VIEW) || - (dstInfo->encodeType_ == ENCODE_TYPE_JPEG)) { + if ((srcInfo->intent_ == STILL_CAPTURE) || (srcInfo->intent_ == POST_VIEW)) { dstInfo->type_ = DCStreamType::SNAPSHOT_FRAME; - dstInfo->format_ = OHOS_CAMERA_FORMAT_JPEG; + if (dstInfo->encodeType_ == ENCODE_TYPE_JPEG) { + dstInfo->format_ = OHOS_CAMERA_FORMAT_JPEG; + } else if (dstInfo->encodeType_ == ENCODE_TYPE_NULL){ + dstInfo->format_ = OHOS_CAMERA_FORMAT_YCRCB_420_SP; + } } else { dstInfo->type_ = DCStreamType::CONTINUOUS_FRAME; dstInfo->format_ = @@ -706,7 +709,11 @@ void DStreamOperator::ChooseSuitableFormat(std::vector 0) { captureInfo->format_ = dcSupportedFormatMap_[DCSceneType::PHOTO].at(0); } else { - captureInfo->format_ = OHOS_CAMERA_FORMAT_JPEG; + if ((streamInfo.at(0))->encodeType_ == DCEncodeType::ENCODE_TYPE_JPEG) { + captureInfo->format_ = OHOS_CAMERA_FORMAT_JPEG; + } else { + captureInfo->format_ = OHOS_CAMERA_FORMAT_YCRCB_420_SP; + } } } } @@ -760,7 +767,11 @@ void DStreamOperator::ChooseSuitableEncodeType(std::vectorencodeType_ = DCEncodeType::ENCODE_TYPE_NULL; } } else { - captureInfo->encodeType_ = DCEncodeType::ENCODE_TYPE_JPEG; + if ((streamInfo.at(0))->encodeType_ == DCEncodeType::ENCODE_TYPE_JPEG) { + captureInfo->encodeType_ = DCEncodeType::ENCODE_TYPE_JPEG; + } else { + captureInfo->encodeType_ = DCEncodeType::ENCODE_TYPE_NULL; + } } } diff --git a/camera_hdf/interfaces/hdi_ipc/config/host/BUILD.gn b/camera_hdf/interfaces/hdi_ipc/config/host/BUILD.gn deleted file mode 100644 index 7b744eb809028d1c6f14524de2af136a94f87a1f..0000000000000000000000000000000000000000 --- a/camera_hdf/interfaces/hdi_ipc/config/host/BUILD.gn +++ /dev/null @@ -1,87 +0,0 @@ -# Copyright (c) 2021 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( - "//foundation/distributedhardware/distributedcamera/distributedcamera.gni") - -ohos_shared_library("distributed_camera_host_config") { - include_dirs = [ - "${distributedcamera_hdf_path}/interfaces/include", - "${distributedcamera_hdf_path}/interfaces/hdi_ipc/server/host", - "${distributedcamera_hdf_path}/interfaces/hdi_ipc/server/device", - "${distributedcamera_hdf_path}/interfaces/hdi_ipc/server/operator", - "${distributedcamera_hdf_path}/hdi_impl/include/dcamera_host", - "${distributedcamera_hdf_path}/hdi_impl/include/dcamera_device", - "${distributedcamera_hdf_path}/hdi_impl/include/dstream_operator", - "${distributedcamera_hdf_path}/hdi_impl/include/utils", - "${common_path}/include/constants", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "${hdf_framework_path}/include/utils", - "${hdf_framework_path}/include/core", - "${hdf_framework_path}/include/osal", - "${hdf_uhdf_path}/include/hdi", - "${hdf_uhdf_path}/osal/include", - "${hdf_uhdf_path}/ipc/include", - "${hdf_uhdf_path}/include/host", - - #producer - "//foundation/graphic/standard/frameworks/surface/include", - "//foundation/graphic/standard/interfaces/kits/surface", - "//foundation/graphic/standard/utils/include", - "//foundation/communication/ipc/ipc/native/src/core/include", - "//foundation/multimedia/camera_standard/frameworks/native/metadata/include", - ] - - cflags = [ - "-fPIC", - "-Wall", - ] - - if (device_name == "baltimore") { - cflags += [ "-DBALTIMORE_CAMERA" ] - include_dirs += [ "${camera_hdf_path_baltimore}/camera/interfaces/include" ] - } else { - include_dirs += [ - "${camera_hdf_path}/camera/interfaces/include", - "${camera_hdf_path}/camera/interfaces/hdi_ipc", - ] - } - - sources = [ "dcamera_host_config.cpp" ] - - deps = [ - "${distributedcamera_hdf_path}/hdi_impl:distributed_camera_hdf", - "//foundation/graphic/standard/frameworks/surface:surface", - "//utils/native/base:utils", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"distributedcamerahdf\"", - "LOG_DOMAIN=0xD004100", - ] - - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_single", - ] - install_images = [ chipset_base_dir ] - - cflags_cc = cflags - subsystem_name = "distributedhardware" - - part_name = "distributed_camera" -} diff --git a/camera_hdf/interfaces/hdi_ipc/config/host/dcamera_host_config.cpp b/camera_hdf/interfaces/hdi_ipc/config/host/dcamera_host_config.cpp index 61c53aae97f0ac3e42f850cb314d99dec5363de0..841ba72759e77efcbc2fd3aa4776da687528e086 100644 --- a/camera_hdf/interfaces/hdi_ipc/config/host/dcamera_host_config.cpp +++ b/camera_hdf/interfaces/hdi_ipc/config/host/dcamera_host_config.cpp @@ -16,6 +16,7 @@ #include "dcamera_host_stub.h" #include #include +#include #include #include @@ -37,6 +38,15 @@ static int32_t DCameraServiceDispatch(struct HdfDeviceIoClient *client, int cmdI int HdfDCameraHostDriverInit(struct HdfDeviceObject *deviceObject) { + 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; } diff --git a/camera_hdf/interfaces/hdi_ipc/config/provider/BUILD.gn b/camera_hdf/interfaces/hdi_ipc/config/provider/BUILD.gn index 1d80115f5ce77a54eaf73fa70d11d4f294df378f..b5b48721e9db8e7066ee36313fe85de2bd7e62d9 100644 --- a/camera_hdf/interfaces/hdi_ipc/config/provider/BUILD.gn +++ b/camera_hdf/interfaces/hdi_ipc/config/provider/BUILD.gn @@ -70,6 +70,7 @@ ohos_shared_library("distributed_camera_provider_config") { ] external_deps = [ + "device_driver_framework:libhdf_host", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_single", ] diff --git a/camera_hdf/interfaces/hdi_ipc/config/provider/dcamera_provider_config.cpp b/camera_hdf/interfaces/hdi_ipc/config/provider/dcamera_provider_config.cpp index acd1cd70abeeaf315354acd1d26e02d40d639d1e..8e49f3f20a6f5fea3a8ac3ee28f1c50045791861 100644 --- a/camera_hdf/interfaces/hdi_ipc/config/provider/dcamera_provider_config.cpp +++ b/camera_hdf/interfaces/hdi_ipc/config/provider/dcamera_provider_config.cpp @@ -33,6 +33,15 @@ static int32_t DCameraProviderServiceDispatch(struct HdfDeviceIoClient *client, int HdfDCameraProviderConfigInit(struct HdfDeviceObject *deviceObject) { + if (deviceObject == nullptr) { + HDF_LOGE("HdfDCameraProviderConfigInit: HdfDeviceObject is NULL !"); + return HDF_FAILURE; + } + + if (!HdfDeviceSetClass(deviceObject, DEVICE_CLASS_CAMERA)) { + HDF_LOGE("HdfDCameraProviderConfigInit set camera class failed"); + return HDF_FAILURE; + } return HDF_SUCCESS; } diff --git a/services/cameraservice/sourceservice/BUILD.gn b/services/cameraservice/sourceservice/BUILD.gn index 8f53c80dc8be0b59c64408fbb07e004dac756646..911aeb82aec5fd985fc50c484aa22155a22a168e 100644 --- a/services/cameraservice/sourceservice/BUILD.gn +++ b/services/cameraservice/sourceservice/BUILD.gn @@ -75,6 +75,7 @@ ohos_shared_library("distributed_camera_source") { "src/distributedcameramgr/dcameradata/dcamera_stream_data_process.cpp", "src/distributedcameramgr/dcameradata/dcamera_stream_data_process_pipeline_listener.cpp", "src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp", + "src/distributedcameramgr/dcamerahdf/dcamera_hdf_operate.cpp", "src/distributedcameramgr/dcamerahdf/dcamera_provider_callback_impl.cpp", "src/distributedcameramgr/dcamerastate/dcamera_source_capture_state.cpp", "src/distributedcameramgr/dcamerastate/dcamera_source_config_stream_state.cpp", @@ -102,6 +103,8 @@ ohos_shared_library("distributed_camera_source") { ] external_deps = [ + "device_driver_framework:libhdf_utils", + "device_driver_framework:libhdi", "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerahdf/dcamera_hdf_operate.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerahdf/dcamera_hdf_operate.h new file mode 100644 index 0000000000000000000000000000000000000000..f8e1ba47da503a5793081e23fe4eefb17a5891e9 --- /dev/null +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcamerahdf/dcamera_hdf_operate.h @@ -0,0 +1,72 @@ +/* + * 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. + */ + +#ifndef OHOS_DCAMERA_HDF_OPERATE_H +#define OHOS_DCAMERA_HDF_OPERATE_H + +#include +#include + +#include "iservstat_listener_hdi.h" +#include "idevmgr_hdi.h" +#include "iservmgr_hdi.h" +#include "single_instance.h" + +using OHOS::HDI::DeviceManager::V1_0::IDeviceManager; +using OHOS::HDI::ServiceManager::V1_0::IServiceManager; +using OHOS::HDI::ServiceManager::V1_0::IServStatListener; +using OHOS::HDI::ServiceManager::V1_0::ServiceStatus; +using OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub; +const std::string CAMERA_SERVICE_NAME = "distributed_camera_service"; +const std::string PROVIDER_SERVICE_NAME = "distributed_camera_provider_service"; +constexpr uint16_t INVALID_VALUE = 0xffff; +constexpr int32_t WAIT_TIME = 500; + +namespace OHOS { +namespace DistributedHardware { +class DCameraHdfOperate { +DECLARE_SINGLE_INSTANCE(DCameraHdfOperate); + +public: + int32_t LoadDcameraHDFImpl(); + int32_t UnLoadDcameraHDFImpl(); + +private: + int32_t WaitLoadService(const uint16_t& servStatus, const std::string& servName); + +private: + OHOS::sptr devmgr_; + OHOS::sptr servMgr_; + uint16_t cameraServStatus_ = INVALID_VALUE; + uint16_t providerServStatus_ = INVALID_VALUE; + std::condition_variable hdfOperateCon_; + std::mutex hdfOperateMutex_; +}; + +class DCameraHdfServStatListener : public OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub { +public: + using StatusCallback = std::function; + explicit DCameraHdfServStatListener(StatusCallback callback) : callback_(std::move(callback)) + { + } + ~DCameraHdfServStatListener() = default; + void OnReceive(const ServiceStatus& status) override; + +private: + StatusCallback callback_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DCAMERA_HDF_OPERATE_H \ No newline at end of file diff --git a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp index 1119e87b61d8fbf5bd5e4a0b905bf643d38f6fdb..d749c646c0064e691f7896c23bf3116453588e32 100644 --- a/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp +++ b/services/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp @@ -23,6 +23,7 @@ #include "system_ability_definition.h" #include "anonymous_string.h" +#include "dcamera_hdf_operate.h" #include "dcamera_service_state_listener.h" #include "dcamera_source_service_ipc.h" #include "distributed_camera_errno.h" @@ -187,11 +188,25 @@ int32_t DistributedCameraSourceService::DCameraNotify(const std::string& devId, int32_t DistributedCameraSourceService::LoadDCameraHDF() { + DHLOGI("load hdf driver start"); + int32_t ret = DCameraHdfOperate::GetInstance().LoadDcameraHDFImpl(); + if (ret != DCAMERA_OK) { + DHLOGE("load hdf driver failed, ret %d", ret); + return ret; + } + DHLOGI("load hdf driver end"); return DCAMERA_OK; } int32_t DistributedCameraSourceService::UnLoadCameraHDF() { + DHLOGI("unload hdf driver start"); + int32_t ret = DCameraHdfOperate::GetInstance().UnLoadDcameraHDFImpl(); + if (ret != DCAMERA_OK) { + DHLOGE("unload hdf driver failed, ret %d", ret); + return ret; + } + DHLOGI("unload hdf driver end"); return DCAMERA_OK; } } // namespace DistributedHardware diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerahdf/dcamera_hdf_operate.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerahdf/dcamera_hdf_operate.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5d43b97fda2ab8a581fe4921025f7494ee1f990f --- /dev/null +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcamerahdf/dcamera_hdf_operate.cpp @@ -0,0 +1,131 @@ +/* + * 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 "dcamera_hdf_operate.h" + +#include + +#include "anonymous_string.h" +#include "distributed_camera_errno.h" +#include "distributed_hardware_log.h" +#include "types.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(DCameraHdfOperate); + +void DCameraHdfServStatListener::OnReceive(const ServiceStatus& status) +{ + DHLOGI("service status on receive"); + if (status.serviceName == CAMERA_SERVICE_NAME || status.serviceName == PROVIDER_SERVICE_NAME) { + callback_(status); + } +} + +int32_t DCameraHdfOperate::LoadDcameraHDFImpl() +{ + if (cameraServStatus_ == OHOS::HDI::ServiceManager::V1_0::SERVIE_STATUS_START && + providerServStatus_ == OHOS::HDI::ServiceManager::V1_0::SERVIE_STATUS_START) { + DHLOGI("service has already start"); + return DCAMERA_OK; + } + servMgr_ = IServiceManager::Get(); + devmgr_ = IDeviceManager::Get(); + if (servMgr_ == nullptr || devmgr_ == nullptr) { + DHLOGE("get hdi service manager or device manager failed!"); + return DCAMERA_BAD_VALUE; + } + + ::OHOS::sptr listener = + new DCameraHdfServStatListener(DCameraHdfServStatListener::StatusCallback([&](const ServiceStatus& status) { + DHLOGI("LoadCameraService service status callback, serviceName: %s, status: %d", + status.serviceName.c_str(), status.status); + std::unique_lock lock(hdfOperateMutex_); + if (status.serviceName == CAMERA_SERVICE_NAME) { + cameraServStatus_ = status.status; + hdfOperateCon_.notify_one(); + } else if (status.serviceName == PROVIDER_SERVICE_NAME) { + providerServStatus_ = status.status; + hdfOperateCon_.notify_one(); + } + })); + if (servMgr_->RegisterServiceStatusListener(listener, DEVICE_CLASS_CAMERA) != 0) { + DHLOGE("RegisterServiceStatusListener failed!"); + return DCAMERA_BAD_VALUE; + } + + if (devmgr_->LoadDevice(CAMERA_SERVICE_NAME) != 0) { + DHLOGE("Load camera service failed!"); + return DCAMERA_BAD_OPERATE; + } + if (WaitLoadService(cameraServStatus_, CAMERA_SERVICE_NAME) != DCAMERA_OK) { + DHLOGE("Wait load camera service failed!"); + return DCAMERA_BAD_OPERATE; + } + + if (devmgr_->LoadDevice(PROVIDER_SERVICE_NAME) != 0) { + DHLOGE("Load provider service failed!"); + return DCAMERA_BAD_OPERATE; + } + if (WaitLoadService(providerServStatus_, PROVIDER_SERVICE_NAME) != DCAMERA_OK) { + DHLOGE("Wait load provider service failed!"); + return DCAMERA_BAD_OPERATE; + } + + if (servMgr_->UnregisterServiceStatusListener(listener) != 0) { + DHLOGE("UnregisterServiceStatusListener failed!"); + } + return DCAMERA_OK; +} + +int32_t DCameraHdfOperate::WaitLoadService(const uint16_t& servStatus, const std::string& servName) +{ + std::unique_lock lock(hdfOperateMutex_); + hdfOperateCon_.wait_for(lock, std::chrono::milliseconds(WAIT_TIME), [servStatus] { + return (servStatus == OHOS::HDI::ServiceManager::V1_0::SERVIE_STATUS_START); + }); + + if (servStatus != OHOS::HDI::ServiceManager::V1_0::SERVIE_STATUS_START) { + DHLOGE("wait load service %s failed, status %d", servName.c_str(), servStatus); + return DCAMERA_BAD_OPERATE; + } + + return DCAMERA_OK; +} + +int32_t DCameraHdfOperate::UnLoadDcameraHDFImpl() +{ + DHLOGI("UnLoadCameraHDFImpl begin!"); + devmgr_ = IDeviceManager::Get(); + if (devmgr_ == nullptr) { + DHLOGE("get hdi device manager failed!"); + return DCAMERA_BAD_VALUE; + } + + int32_t ret = devmgr_->UnloadDevice(CAMERA_SERVICE_NAME); + if (ret != 0) { + DHLOGE("Unload camera service failed, ret: %d", ret); + } + ret = devmgr_->UnloadDevice(PROVIDER_SERVICE_NAME); + if (ret != 0) { + DHLOGE("Unload provider service failed, ret: %d", ret); + } + cameraServStatus_ = INVALID_VALUE; + providerServStatus_ = INVALID_VALUE; + DHLOGI("UnLoadCameraHDFImpl end!"); + return DCAMERA_OK; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file