diff --git a/frameworks/BUILD.gn b/frameworks/BUILD.gn index d49fbd3d828037487af8e6829e21bffa74f78741..00c5f275cbf4776ef047df2e739f2a3bfa117ee4 100755 --- a/frameworks/BUILD.gn +++ b/frameworks/BUILD.gn @@ -9,11 +9,10 @@ # See the License for the specific language governing permissions and # limitations under the License. import("//build/lite/config/component/lite_component.gni") +import("//build/lite/config/subsystem/media/config.gni") shared_library("camera_lite") { sources = [ - "binder/src/camera_device_client.cpp", - "binder/src/camera_service_client.cpp", "camera_ability.cpp", "camera_client.cpp", "camera_config.cpp", @@ -24,21 +23,54 @@ shared_library("camera_lite") { "event_handler.cpp", "frame_config.cpp", ] - include_dirs = [ - "//foundation/multimedia/camera_lite/services/server/include", - "//foundation/multimedia/camera_lite/services/impl/include", - "//foundation/multimedia/camera_lite/frameworks/binder/include", + + if (enable_media_passthrough_mode == true) { + sources += [ + "passthrough/src/camera_device_client.cpp", + "passthrough/src/camera_service_client.cpp", + "../services/impl/src/camera_service.cpp", + "../services/impl/src/camera_device.cpp", + ] + include_dirs = [ + "//drivers/peripheral/display/interfaces/include", + "//drivers/peripheral/codec/interfaces/include", + "//foundation/multimedia/camera_lite/frameworks/passthrough/include", + "//foundation/multimedia/utils/lite/hals", + "//drivers/peripheral/base" + ] + + ldflags = [ + "-lhdi_camera", + ] + defines = [ "ENABLE_PASSTHROUGH_MODE" ] + } else { + sources += [ + "binder/src/camera_device_client.cpp", + "binder/src/camera_service_client.cpp", + ] + include_dirs = [ + "//foundation/multimedia/camera_lite/frameworks/binder/include", + "//utils/native/lite/include", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/communication/broadcast", + "//foundation/communication/ipc_lite/interfaces/kits", + ] + ldflags = [ ] + } + + include_dirs += [ "//foundation/multimedia/camera_lite/frameworks", - "//utils/native/lite/include", - "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", - "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", - "//foundation/distributedschedule/samgr_lite/interfaces/kits/communication/broadcast", - "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/multimedia/camera_lite/interfaces/kits", + "//foundation/multimedia/camera_lite/services/impl/include", + "//foundation/multimedia/camera_lite/services/server/include", + "//foundation/multimedia/utils/lite/interfaces/kits", "//base/security/permission/interfaces/kits/permission_lite", ] + public_configs = [ ":camera_client_external_library_config" ] - ldflags = [ + ldflags += [ "-lstdc++", "-lpthread", "-lcodec", diff --git a/frameworks/binder/src/camera_device_client.cpp b/frameworks/binder/src/camera_device_client.cpp index 7a9401d2b1e9f0738d12e68be1b8b65896b775a6..3cd14ee864e81c4f2cf6620623ca45df41c3a1ff 100644 --- a/frameworks/binder/src/camera_device_client.cpp +++ b/frameworks/binder/src/camera_device_client.cpp @@ -136,7 +136,7 @@ int32_t SerilizeFrameConfig(IpcIo &io, FrameConfig &fc, uint32_t maxSurfaceNum) IpcIoPushInt32(&io, streamCrop.y); IpcIoPushInt32(&io, streamCrop.w); IpcIoPushInt32(&io, streamCrop.h); - + int32_t format = -1; fc.GetParameter(CAM_IMAGE_FORMAT, format); IpcIoPushInt32(&io, format); @@ -316,7 +316,7 @@ int32_t CameraDeviceClient::DeviceClientCallback(const IpcContext* context, void } case ON_CAMERA_STATUS_CHANGE: { int32_t ret = IpcIoPopInt32(io); - MEDIA_INFO_LOG("ON_CAMERA_STATUS_CHANGE : ret=%d.", ret); + MEDIA_INFO_LOG("ON_CAMERA_STATUS_CHANGE: ret=%d", ret); break; } default: { diff --git a/frameworks/camera_impl.cpp b/frameworks/camera_impl.cpp index 90e5976a093658099c2dde44cf14f2c876d5a3f2..f1cf794c8b0ba01a8e221e844e4530ab60f924da 100755 --- a/frameworks/camera_impl.cpp +++ b/frameworks/camera_impl.cpp @@ -102,7 +102,7 @@ int32_t CameraImpl::TriggerLoopingCapture(FrameConfig &fc) MEDIA_ERR_LOG("looping capture not support FRAME_CONFIG_CAPTURE"); return MEDIA_ERR; } - FrameConfig *curFc = GetFrameConfig(fc.GetFrameConfigType()); + FrameConfig *curFc = GetFrameConfig(type); if (curFc != nullptr) { MEDIA_ERR_LOG("Frame config of the input type is already existed."); return MEDIA_ERR; diff --git a/frameworks/passthrough/include/camera_device_client.h b/frameworks/passthrough/include/camera_device_client.h new file mode 100644 index 0000000000000000000000000000000000000000..93184824a12a1512845ce09ef5b3a1e6602880e6 --- /dev/null +++ b/frameworks/passthrough/include/camera_device_client.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2022-2023 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 CAMERA_DEVICE_CLIENT_H +#define CAMERA_DEVICE_CLIENT_H + +#include "camera_config.h" +#include "camera_service.h" + +#include + +namespace OHOS { +namespace Media { +class CameraImpl; +class CameraDeviceClient { +public: + static CameraDeviceClient *GetInstance(); + CameraDeviceClient(); + ~CameraDeviceClient(); + + int32_t SetCameraConfig(CameraConfig &cc); + int32_t TriggerLoopingCapture(FrameConfig &fc); + void StopLoopingCapture(); + int32_t TriggerSingleCapture(FrameConfig &fc); + void Release(); + + void SetCameraId(std::string cameraId); + void SetCameraImpl(CameraImpl *cameraImpl); + void SetCameraCallback(); +private: + std::string cameraId_; + CameraImpl *cameraImpl_ = nullptr; + CameraConfig *cc_ = nullptr; + CameraService *cameraService_ = nullptr; +}; +} +} +#endif // CAMERA_DEVICE_CLIENT_H \ No newline at end of file diff --git a/frameworks/passthrough/include/camera_service_client.h b/frameworks/passthrough/include/camera_service_client.h new file mode 100644 index 0000000000000000000000000000000000000000..8d1fa2a52b91c72cd15fdafca8b7a62c4be82757 --- /dev/null +++ b/frameworks/passthrough/include/camera_service_client.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022-2023 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 CAMERA_SERVICE_CLIENT_H +#define CAMERA_SERVICE_CLIENT_H + +#include "camera_ability.h" +#include "camera_info_impl.h" +#include "camera_service.h" + +namespace OHOS { +namespace Media { +class CameraServiceClient { +public: + ~CameraServiceClient(); + static CameraServiceClient *GetInstance(); + std::list GetCameraIdList(); + void InitCameraServiceClient(CameraServiceCallback *callback); + CameraAbility *GetCameraAbility(std::string &cameraId); + CameraInfo *GetCameraInfo(std::string &cameraId); + void CreateCamera(std::string cameraId); + uint8_t GetCameraModeNum(); + int32_t SetCameraMode(uint8_t modeIndex); + +private: + CameraServiceClient(); + CameraService *cameraService_ = nullptr; + CameraServiceCallback *cameraServiceCb_ = nullptr; +}; +} // namespace Media +} // namespace OHOS + +#endif // CAMERA_SERVICE_CLIENT_H diff --git a/frameworks/passthrough/src/camera_device_client.cpp b/frameworks/passthrough/src/camera_device_client.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f4bc413bd17e9b08cafdf1c468bca9621e92cb72 --- /dev/null +++ b/frameworks/passthrough/src/camera_device_client.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2022-2023 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 "camera_device_client.h" +#include "camera_impl.h" +#include "media_log.h" +#include "camera_config.h" +#include "frame_config.h" + +#include + +using namespace std; +namespace OHOS { +namespace Media { +CameraDeviceClient *CameraDeviceClient::GetInstance() +{ + static CameraDeviceClient client; + return &client; +} + +CameraDeviceClient::CameraDeviceClient() +{ + cameraService_ = CameraService::GetInstance(); +} + +CameraDeviceClient::~CameraDeviceClient() {} + +void CameraDeviceClient::SetCameraId(string cameraId) +{ + cameraId_ = cameraId; +} + +void CameraDeviceClient::SetCameraImpl(CameraImpl *cameraImpl) +{ + cameraImpl_ = cameraImpl; +} +void CameraDeviceClient::SetCameraCallback() {} + +int32_t CameraDeviceClient::SetCameraConfig(CameraConfig &cc) +{ + CameraDevice *device_ = cameraService_->GetCameraDevice(cameraId_); + if (device_ == nullptr) { + MEDIA_ERR_LOG("device_ is null"); + return -1; + } + cc_ = &cc; + int32_t ret = device_->SetCameraConfig(); + cameraImpl_->OnConfigured(ret, *cc_); + return ret; +} + + +int32_t CameraDeviceClient::TriggerLoopingCapture(FrameConfig &fc) +{ + CameraDevice *device_ = cameraService_->GetCameraDevice(cameraId_); + if (device_ == nullptr) { + MEDIA_ERR_LOG("device_ is null"); + return -1; + } + uint32_t streamId = 0; + return device_->TriggerLoopingCapture(fc, &streamId); +} + +int32_t CameraDeviceClient::TriggerSingleCapture(FrameConfig &fc) +{ + CameraDevice *device_ = cameraService_->GetCameraDevice(cameraId_); + if (device_ == nullptr) { + MEDIA_ERR_LOG("device_ is null"); + return -1; + } + uint32_t streamId = 0; + int32_t ret = device_->TriggerSingleCapture(fc, &streamId); + cameraImpl_->OnFrameFinished(ret, fc); + return ret; +} + +void CameraDeviceClient::StopLoopingCapture() +{ + CameraDevice *device_ = cameraService_->GetCameraDevice(cameraId_); + if (device_ == nullptr) { + MEDIA_ERR_LOG("device_ is null"); + return; + } + return device_->StopLoopingCapture(); +} + +void CameraDeviceClient::Release() +{ + cameraService_->CloseCamera(cameraId_); +} +} +} \ No newline at end of file diff --git a/frameworks/passthrough/src/camera_service_client.cpp b/frameworks/passthrough/src/camera_service_client.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8301469da0754ec17ec8e73c294052d133e3892c --- /dev/null +++ b/frameworks/passthrough/src/camera_service_client.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2022-2023 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 "camera_service_client.h" +#include "media_log.h" +#include "camera_type.h" +#include "camera_manager.h" +#include "meta_data.h" + +#include +#include + +using namespace std; +namespace OHOS { +namespace Media { +CameraServiceClient *CameraServiceClient::GetInstance() +{ + static CameraServiceClient client; + return &client; +} + +CameraServiceClient::CameraServiceClient() +{ + cameraService_ = CameraService::GetInstance(); +} + +CameraServiceClient::~CameraServiceClient() {} + +void CameraServiceClient::InitCameraServiceClient(CameraServiceCallback *callback) +{ + cameraServiceCb_ = callback; + cameraService_->Initialize(); + list cameraList = cameraService_->GetCameraIdList(); + cameraServiceCb_->OnCameraServiceInitialized(cameraList); +} + +list CameraServiceClient::GetCameraIdList() +{ + return cameraService_->GetCameraIdList(); +} + +uint8_t CameraServiceClient::GetCameraModeNum() +{ + return cameraService_->GetCameraModeNum(); +} + +CameraAbility *CameraServiceClient::GetCameraAbility(string &cameraId) +{ + return cameraService_->GetCameraAbility(cameraId); +} + +CameraInfo *CameraServiceClient::GetCameraInfo(string &cameraId) +{ + return cameraService_->GetCameraInfo(cameraId); +} + +int32_t CameraServiceClient::SetCameraMode(uint8_t modeIndex) +{ + return cameraService_->SetCameraMode(modeIndex); +} + +void CameraServiceClient::CreateCamera(string cameraId) +{ + CameraServiceCallback::CameraStauts cameraStatus = + static_cast(cameraService_->CreateCamera(cameraId)); + cameraServiceCb_->OnCameraStatusChange(cameraId, cameraStatus); +} +} +} diff --git a/services/impl/src/camera_device.cpp b/services/impl/src/camera_device.cpp index 60e33b7b2a09cd4fee3b9b858ed998c8e8a39fb5..fccd851c455a511a79e2d2f59b92a9c354f02fe8 100644 --- a/services/impl/src/camera_device.cpp +++ b/services/impl/src/camera_device.cpp @@ -57,8 +57,8 @@ inline PicSize Convert2CodecSize(int32_t width, int32_t height) { struct SizeMap { PicSize res_; - uint32_t width_; - uint32_t height_; + int32_t width_; + int32_t height_; }; static SizeMap sizeMap[] = { {RESOLUTION_CIF, 352, 288}, {RESOLUTION_360P, 640, 360}, {RESOLUTION_D1_PAL, 720, 576}, @@ -494,7 +494,7 @@ int32_t PreviewAssistant::SetFrameConfig(FrameConfig &fc, uint32_t *streamId) StreamAttrInitialize(&stream, surface, STREAM_PREVIEW, fc); int32_t ret = HalCameraStreamCreate(cameraId_, &stream, streamId); if (ret != MEDIA_OK) { - MEDIA_ERR_LOG(" creat Preview stream failed."); + MEDIA_ERR_LOG(" creat preview stream failed."); return MEDIA_ERR; } StreamInfo streamInfo; @@ -521,7 +521,7 @@ int32_t PreviewAssistant::Start(uint32_t streamId) int32_t ret = HalCameraStreamOn(cameraId_, streamId); if (ret != MEDIA_OK) { - MEDIA_ERR_LOG("Preview start failed. (ret=%d)", ret); + MEDIA_ERR_LOG("Preview start failed of HalCameraStreamOn.(ret=%d)", ret); Stop(); return MEDIA_ERR; } @@ -635,7 +635,9 @@ FREE_RESOURCE: CodecDestroy(vencHdl_); HalCameraStreamOff(cameraId_, streamId); HalCameraStreamDestroy(cameraId_, streamId); +#ifndef ENABLE_PASSTHROUGH_MODE delete capSurface_; +#endif capSurface_ = nullptr; state_ = LOOP_STOP; diff --git a/services/impl/src/camera_service.cpp b/services/impl/src/camera_service.cpp index 89d05f0f3c70c5973ff0bc7e0a6eec4e052f1fae..fcd3f27093c234163d0374b85356f0321b40cac0 100644 --- a/services/impl/src/camera_service.cpp +++ b/services/impl/src/camera_service.cpp @@ -24,6 +24,19 @@ CameraService::CameraService() {} CameraService::~CameraService() { + auto iter = deviceMap_.begin(); + while (iter != deviceMap_.end()) { + if (iter->second != nullptr) { + iter->second->StopLoopingCapture(); + int32_t ret = HalCameraDeviceClose((uint32_t)std::atoi(iter->first.c_str())); + if (ret != 0) { + MEDIA_ERR_LOG("HalCameraDeviceClose failed. ret(%d)", ret); + } + deviceMap_.erase(iter++); + } else { + ++iter; + } + } int32_t ret = HalCameraDeinit(); if (ret != 0) { MEDIA_ERR_LOG("HiCameraDeInit return failed ret(%d).", ret); @@ -58,7 +71,7 @@ CameraAbility *CameraService::GetCameraAbility(std::string &cameraId) StreamCap *streamCap = nullptr; int32_t ret = HalCameraGetStreamCapNum(atoi(cameraId.c_str()), &streamCapNum); streamCap = new StreamCap[streamCapNum]; - for (int pos = 0; pos < streamCapNum; pos++) { + for (uint32_t pos = 0; pos < streamCapNum; pos++) { streamCap[pos].type = CAP_DESC_ENUM; } ret = HalCameraGetStreamCap(atoi(cameraId.c_str()), streamCap, streamCapNum); diff --git a/services/server/src/camera_server.cpp b/services/server/src/camera_server.cpp index 3bd42a0dd450dd32d4351ed8459728b6c0046612..f8ed26fec901cff53e33e60375356f724e95092b 100644 --- a/services/server/src/camera_server.cpp +++ b/services/server/src/camera_server.cpp @@ -230,7 +230,8 @@ FrameConfig *DeserializeFrameConfig(IpcIo &io) streamCrop.y = IpcIoPopInt32(&io); streamCrop.w = IpcIoPopInt32(&io); streamCrop.h = IpcIoPopInt32(&io); - + fc->SetParameter(CAM_IMAGE_CROP_RECT, streamCrop); + int32_t streamFormat = IpcIoPopInt32(&io); fc->SetParameter(CAM_IMAGE_FORMAT, streamFormat); MEDIA_INFO_LOG("streamFormat is %d", streamFormat);