From cdf2bb157dab00036ee383a547a7d826b5d5adb5 Mon Sep 17 00:00:00 2001 From: chen0088 Date: Wed, 3 Aug 2022 16:34:01 +0800 Subject: [PATCH 1/3] feat:local camera interface modify Signed-off-by: chen0088 --- .../include/callback/dcamera_input_callback.h | 1 + .../callback/dcamera_manager_callback.h | 2 +- .../include/callback/dcamera_photo_callback.h | 2 +- .../callback/dcamera_preview_callback.h | 2 +- .../include/callback/dcamera_video_callback.h | 2 +- .../client/include/dcamera_client.h | 4 +- .../src/callback/dcamera_manager_callback.cpp | 2 +- .../client/src/dcamera_client.cpp | 54 ++++++-- .../client/src/dcamera_client_common.cpp | 54 ++++++-- .../client/test/sample/dcamera_client_demo.h | 8 +- .../client/test/sample/main.cpp | 8 +- .../handler/include/dcamera_handler.h | 16 +-- .../handler/src/dcamera_handler.cpp | 121 +++++++++--------- .../handler/src/dcamera_handler_common.cpp | 111 ++++++++-------- 14 files changed, 221 insertions(+), 166 deletions(-) diff --git a/services/cameraservice/cameraoperator/client/include/callback/dcamera_input_callback.h b/services/cameraservice/cameraoperator/client/include/callback/dcamera_input_callback.h index 5efe7702..1669fe60 100644 --- a/services/cameraservice/cameraoperator/client/include/callback/dcamera_input_callback.h +++ b/services/cameraservice/cameraoperator/client/include/callback/dcamera_input_callback.h @@ -17,6 +17,7 @@ #define OHOS_DCAMERA_INPUT_CALLBACK_H #include "camera_input.h" +#include "capture_session.h" #include diff --git a/services/cameraservice/cameraoperator/client/include/callback/dcamera_manager_callback.h b/services/cameraservice/cameraoperator/client/include/callback/dcamera_manager_callback.h index 6d2aa46d..f3f4b2be 100644 --- a/services/cameraservice/cameraoperator/client/include/callback/dcamera_manager_callback.h +++ b/services/cameraservice/cameraoperator/client/include/callback/dcamera_manager_callback.h @@ -24,7 +24,7 @@ class DCameraManagerCallback : public CameraStandard::CameraManagerCallback { public: void OnCameraStatusChanged(const CameraStandard::CameraStatusInfo &cameraStatusInfo) const override; void OnFlashlightStatusChanged(const std::string &cameraID, - const CameraStandard::FlashlightStatus flashStatus) const override; + const CameraStandard::FlashStatus flashStatus) const override; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/cameraoperator/client/include/callback/dcamera_photo_callback.h b/services/cameraservice/cameraoperator/client/include/callback/dcamera_photo_callback.h index 9e8bd211..1268ab0d 100644 --- a/services/cameraservice/cameraoperator/client/include/callback/dcamera_photo_callback.h +++ b/services/cameraservice/cameraoperator/client/include/callback/dcamera_photo_callback.h @@ -22,7 +22,7 @@ namespace OHOS { namespace DistributedHardware { -class DCameraPhotoCallback : public CameraStandard::PhotoCallback { +class DCameraPhotoCallback : public CameraStandard::PhotoStateCallback { public: explicit DCameraPhotoCallback(const std::shared_ptr& callback); void OnCaptureStarted(const int32_t captureID) const override; diff --git a/services/cameraservice/cameraoperator/client/include/callback/dcamera_preview_callback.h b/services/cameraservice/cameraoperator/client/include/callback/dcamera_preview_callback.h index fad4a501..4550b499 100644 --- a/services/cameraservice/cameraoperator/client/include/callback/dcamera_preview_callback.h +++ b/services/cameraservice/cameraoperator/client/include/callback/dcamera_preview_callback.h @@ -24,7 +24,7 @@ namespace OHOS { namespace DistributedHardware { -class DCameraPreviewCallback : public CameraStandard::PreviewCallback { +class DCameraPreviewCallback : public CameraStandard::PreviewStateCallback { public: explicit DCameraPreviewCallback(const std::shared_ptr& callback); void OnFrameStarted() const override; diff --git a/services/cameraservice/cameraoperator/client/include/callback/dcamera_video_callback.h b/services/cameraservice/cameraoperator/client/include/callback/dcamera_video_callback.h index ff7cdec1..0e45b03e 100644 --- a/services/cameraservice/cameraoperator/client/include/callback/dcamera_video_callback.h +++ b/services/cameraservice/cameraoperator/client/include/callback/dcamera_video_callback.h @@ -22,7 +22,7 @@ namespace OHOS { namespace DistributedHardware { -class DCameraVideoCallback : public CameraStandard::VideoCallback { +class DCameraVideoCallback : public CameraStandard::VideoStateCallback { public: explicit DCameraVideoCallback(const std::shared_ptr& callback); void OnFrameStarted() const override; diff --git a/services/cameraservice/cameraoperator/client/include/dcamera_client.h b/services/cameraservice/cameraoperator/client/include/dcamera_client.h index 87c231f6..17beea5c 100644 --- a/services/cameraservice/cameraoperator/client/include/dcamera_client.h +++ b/services/cameraservice/cameraoperator/client/include/dcamera_client.h @@ -21,6 +21,7 @@ #include "camera_info.h" #include "camera_input.h" #include "camera_manager.h" +#include "camera_output_capability.h" #include "capture_input.h" #include "capture_output.h" #include "capture_session.h" @@ -64,12 +65,13 @@ private: std::shared_ptr& photoCaptureSetting); void ReleaseCaptureSession(); int32_t CameraServiceErrorType(const int32_t errorType); + CameraStandard::CameraFormat ConvertToCameraFormat(int32_t format); bool isInit_; std::string cameraId_; sptr photoSurface_; sptr videoSurface_; - sptr cameraInfo_; + sptr cameraInfo_; sptr cameraManager_; sptr captureSession_; sptr cameraInput_; diff --git a/services/cameraservice/cameraoperator/client/src/callback/dcamera_manager_callback.cpp b/services/cameraservice/cameraoperator/client/src/callback/dcamera_manager_callback.cpp index f65adf08..da9d73c0 100644 --- a/services/cameraservice/cameraoperator/client/src/callback/dcamera_manager_callback.cpp +++ b/services/cameraservice/cameraoperator/client/src/callback/dcamera_manager_callback.cpp @@ -27,7 +27,7 @@ void DCameraManagerCallback::OnCameraStatusChanged(const CameraStandard::CameraS } void DCameraManagerCallback::OnFlashlightStatusChanged(const std::string &cameraID, - const CameraStandard::FlashlightStatus flashStatus) const + const CameraStandard::FlashStatus flashStatus) const { DHLOGI("DCameraManagerCallback::OnFlashlightStatusChanged, cameraID: %s, flashStatus: %d", GetAnonyString(cameraID).c_str(), flashStatus); diff --git a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp index 8d241716..df4943d3 100644 --- a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp +++ b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp @@ -55,7 +55,7 @@ int32_t DCameraClient::Init() } cameraManager_->SetCallback(std::make_shared()); - std::vector> cameraList = cameraManager_->GetCameras(); + std::vector> cameraList = cameraManager_->GetSupportedCameras(); DHLOGI("DCameraClient::Init camera size: %d", cameraList.size()); for (auto& info : cameraList) { if (info->GetID() == cameraId_) { @@ -105,12 +105,12 @@ int32_t DCameraClient::UpdateSettings(std::vector &)cameraInput_)->SetCameraSettings(metadataStr); - if (ret != DCAMERA_OK) { - DHLOGE("DCameraClient::UpdateSettings %s update metadata settings failed, ret: %d", - GetAnonyString(cameraId_).c_str(), ret); - return ret; - } + // int32_t ret = ((sptr &)cameraInput_)->SetCameraSettings(metadataStr); + // if (ret != DCAMERA_OK) { + // DHLOGE("DCameraClient::UpdateSettings %s update metadata settings failed, ret: %d", + // GetAnonyString(cameraId_).c_str(), ret); + // return ret; + // } break; } default: { @@ -291,9 +291,6 @@ int32_t DCameraClient::ConfigCaptureSession(std::vector inputCallback = std::make_shared(stateCallback_); - ((sptr &)cameraInput_)->SetErrorCallback(inputCallback); - ((sptr &)cameraInput_)->SetFocusCallback(inputCallback); captureSession_ = cameraManager_->CreateCaptureSession(); if (captureSession_ == nullptr) { @@ -301,6 +298,10 @@ int32_t DCameraClient::ConfigCaptureSession(std::vector inputCallback = std::make_shared(stateCallback_); + ((sptr &)cameraInput_)->SetErrorCallback(inputCallback); + captureSession_->SetFocusCallback(inputCallback); captureSession_->SetCallback(std::make_shared(stateCallback_)); int32_t ret = CreateCaptureOutput(captureInfos); @@ -404,7 +405,10 @@ int32_t DCameraClient::CreatePhotoOutput(std::shared_ptr& in photoSurface_->SetUserData(CAMERA_SURFACE_FORMAT, std::to_string(info->format_)); photoListener_ = new DCameraPhotoSurfaceListener(photoSurface_, resultCallback_); photoSurface_->RegisterConsumerListener((sptr &)photoListener_); - photoOutput_ = cameraManager_->CreatePhotoOutput(photoSurface_); + CameraStandard::CameraFormat photoFormat = ConvertToCameraFormat(info->format_); + CameraStandard::Size photoSize = {info->height_, info->width_}; + CameraStandard::Profile photoProfile(photoFormat, photoSize); + photoOutput_ = cameraManager_->CreatePhotoOutput(photoProfile, photoSurface_); if (photoOutput_ == nullptr) { DHLOGE("DCameraClient::CreatePhotoOutput %s create photo output failed", GetAnonyString(cameraId_).c_str()); return DCAMERA_BAD_VALUE; @@ -425,7 +429,10 @@ int32_t DCameraClient::CreateVideoOutput(std::shared_ptr& in videoSurface_->SetUserData(CAMERA_SURFACE_FORMAT, std::to_string(info->format_)); videoListener_ = new DCameraVideoSurfaceListener(videoSurface_, resultCallback_); videoSurface_->RegisterConsumerListener((sptr &)videoListener_); - videoOutput_ = cameraManager_->CreateVideoOutput(videoSurface_); + CameraStandard::CameraFormat videoFormat = ConvertToCameraFormat(info->format_); + CameraStandard::Size videoSize = {info->height_, info->width_}; + CameraStandard::Profile videoProfile(videoFormat, videoSize); + videoOutput_ = cameraManager_->CreateVideoOutput(videoProfile, videoSurface_); if (videoOutput_ == nullptr) { DHLOGE("DCameraClient::CreateVideoOutput %s create video output failed", GetAnonyString(cameraId_).c_str()); return DCAMERA_BAD_VALUE; @@ -436,6 +443,29 @@ int32_t DCameraClient::CreateVideoOutput(std::shared_ptr& in return DCAMERA_OK; } +CameraStandard::CameraFormat DCameraClient::ConvertToCameraFormat(int32_t format) +{ + CameraStandard::CameraFormat ret = CameraStandard::CameraFormat::CAMERA_FORMAT_INVALID; + DCameraFormat df = static_cast(format); + switch (df) { + case OHOS_CAMERA_FORMAT_RGBA_8888: + ret = CameraStandard::CameraFormat::CAMERA_FORMAT_RGBA_8888; + break; + case OHOS_CAMERA_FORMAT_YCBCR_420_888: + ret = CameraStandard::CameraFormat::CAMERA_FORMAT_YCBCR_420_888; + break; + case OHOS_CAMERA_FORMAT_YCRCB_420_SP: + ret = CameraStandard::CameraFormat::CAMERA_FORMAT_YUV_420_SP; + break; + case OHOS_CAMERA_FORMAT_JPEG: + ret = CameraStandard::CameraFormat::CAMERA_FORMAT_JPEG; + break; + default: + break; + } + return ret; +} + int32_t DCameraClient::StartCaptureInner(std::shared_ptr& info) { switch (info->streamType_) { diff --git a/services/cameraservice/cameraoperator/client/src/dcamera_client_common.cpp b/services/cameraservice/cameraoperator/client/src/dcamera_client_common.cpp index f1c0bc19..34a100f9 100644 --- a/services/cameraservice/cameraoperator/client/src/dcamera_client_common.cpp +++ b/services/cameraservice/cameraoperator/client/src/dcamera_client_common.cpp @@ -55,7 +55,7 @@ int32_t DCameraClient::Init() } cameraManager_->SetCallback(std::make_shared()); - std::vector> cameraList = cameraManager_->GetCameras(); + std::vector> cameraList = cameraManager_->GetSupportedCameras(); DHLOGI("DCameraClientCommon::Init camera size: %d", cameraList.size()); for (auto& info : cameraList) { if (info->GetID() == cameraId_) { @@ -106,12 +106,12 @@ int32_t DCameraClient::UpdateSettings(std::vector &)cameraInput_)->SetCameraSettings(metadataStr); - if (ret != DCAMERA_OK) { - DHLOGE("DCameraClientCommon::UpdateSettings %s update metadata settings failed, ret: %d", - GetAnonyString(cameraId_).c_str(), ret); - return ret; - } + // int32_t ret = ((sptr &)cameraInput_)->SetCameraSettings(metadataStr); + // if (ret != DCAMERA_OK) { + // DHLOGE("DCameraClientCommon::UpdateSettings %s update metadata settings failed, ret: %d", + // GetAnonyString(cameraId_).c_str(), ret); + // return ret; + // } break; } default: { @@ -255,9 +255,6 @@ int32_t DCameraClient::ConfigCaptureSession(std::vector inputCallback = std::make_shared(stateCallback_); - ((sptr &)cameraInput_)->SetErrorCallback(inputCallback); - ((sptr &)cameraInput_)->SetFocusCallback(inputCallback); captureSession_ = cameraManager_->CreateCaptureSession(); if (captureSession_ == nullptr) { @@ -265,6 +262,10 @@ int32_t DCameraClient::ConfigCaptureSession(std::vector inputCallback = std::make_shared(stateCallback_); + ((sptr &)cameraInput_)->SetErrorCallback(inputCallback); + captureSession_->SetFocusCallback(inputCallback); captureSession_->SetCallback(std::make_shared(stateCallback_)); int32_t ret = CreateCaptureOutput(captureInfos); @@ -369,7 +370,10 @@ int32_t DCameraClient::CreatePhotoOutput(std::shared_ptr& in photoSurface_->SetUserData(CAMERA_SURFACE_FORMAT, std::to_string(camera_format_t::OHOS_CAMERA_FORMAT_RGBA_8888)); photoListener_ = new DCameraPhotoSurfaceListener(photoSurface_, resultCallback_); photoSurface_->RegisterConsumerListener((sptr &)photoListener_); - photoOutput_ = cameraManager_->CreatePhotoOutput(photoSurface_); + CameraStandard::CameraFormat photoFormat = ConvertToCameraFormat(info->format_); + CameraStandard::Size photoSize = {info->height_, info->width_}; + CameraStandard::Profile photoProfile(photoFormat, photoSize); + photoOutput_ = cameraManager_->CreatePhotoOutput(photoProfile, photoSurface_); if (photoOutput_ == nullptr) { DHLOGE("DCameraClientCommon::CreatePhotoOutput %s create photo output failed", GetAnonyString(cameraId_).c_str()); @@ -391,7 +395,10 @@ int32_t DCameraClient::CreateVideoOutput(std::shared_ptr& in videoSurface_->SetUserData(CAMERA_SURFACE_FORMAT, std::to_string(camera_format_t::OHOS_CAMERA_FORMAT_RGBA_8888)); videoListener_ = new DCameraVideoSurfaceListener(videoSurface_, resultCallback_); videoSurface_->RegisterConsumerListener((sptr &)videoListener_); - previewOutput_ = cameraManager_->CreateCustomPreviewOutput(videoSurface_, info->width_, info->height_); + CameraStandard::CameraFormat previewFormat = ConvertToCameraFormat(info->format_); + CameraStandard::Size previewSize = {info->height_, info->width_}; + CameraStandard::Profile previewProfile(previewFormat, previewSize); + previewOutput_ = cameraManager_->CreatePreviewOutput(previewProfile, videoSurface_); if (previewOutput_ == nullptr) { DHLOGE("DCameraClientCommon::CreatePreviewOutput %s create preview output failed", GetAnonyString(cameraId_).c_str()); @@ -403,6 +410,29 @@ int32_t DCameraClient::CreateVideoOutput(std::shared_ptr& in return DCAMERA_OK; } +CameraStandard::CameraFormat DCameraClient::ConvertToCameraFormat(int32_t format) +{ + CameraStandard::CameraFormat ret = CameraStandard::CameraFormat::CAMERA_FORMAT_INVALID; + DCameraFormat df = static_cast(format); + switch (df) { + case OHOS_CAMERA_FORMAT_RGBA_8888: + ret = CameraStandard::CameraFormat::CAMERA_FORMAT_RGBA_8888; + break; + case OHOS_CAMERA_FORMAT_YCBCR_420_888: + ret = CameraStandard::CameraFormat::CAMERA_FORMAT_YCBCR_420_888; + break; + case OHOS_CAMERA_FORMAT_YCRCB_420_SP: + ret = CameraStandard::CameraFormat::CAMERA_FORMAT_YUV_420_SP; + break; + case OHOS_CAMERA_FORMAT_JPEG: + ret = CameraStandard::CameraFormat::CAMERA_FORMAT_JPEG; + break; + default: + break; + } + return ret; +} + int32_t DCameraClient::StartCaptureInner(std::shared_ptr& info) { switch (info->streamType_) { diff --git a/services/cameraservice/cameraoperator/client/test/sample/dcamera_client_demo.h b/services/cameraservice/cameraoperator/client/test/sample/dcamera_client_demo.h index 8408cc0c..4c1fc0a8 100644 --- a/services/cameraservice/cameraoperator/client/test/sample/dcamera_client_demo.h +++ b/services/cameraservice/cameraoperator/client/test/sample/dcamera_client_demo.h @@ -20,10 +20,10 @@ #include "anonymous_string.h" #include "camera_device_ability_items.h" -#include "camera_info.h" #include "camera_input.h" #include "camera_manager.h" #include "camera_metadata_operator.h" +#include "camera_output_capability.h" #include "capture_input.h" #include "capture_output.h" #include "capture_session.h" @@ -192,7 +192,7 @@ protected: } }; -class DemoDCameraPhotoCallback : public CameraStandard::PhotoCallback { +class DemoDCameraPhotoCallback : public CameraStandard::PhotoStateCallback { public: void OnCaptureStarted(const int32_t captureID) const { @@ -215,7 +215,7 @@ public: } }; -class DemoDCameraPreviewCallback : public CameraStandard::PreviewCallback { +class DemoDCameraPreviewCallback : public CameraStandard::PreviewStateCallback { public: void OnFrameStarted() const { @@ -233,7 +233,7 @@ public: } }; -class DemoDCameraVideoCallback : public CameraStandard::VideoCallback { +class DemoDCameraVideoCallback : public CameraStandard::VideoStateCallback { public: void OnFrameStarted() const { diff --git a/services/cameraservice/cameraoperator/client/test/sample/main.cpp b/services/cameraservice/cameraoperator/client/test/sample/main.cpp index 7e268cbb..5ed4dfe5 100644 --- a/services/cameraservice/cameraoperator/client/test/sample/main.cpp +++ b/services/cameraservice/cameraoperator/client/test/sample/main.cpp @@ -32,7 +32,7 @@ constexpr int32_t VIDEO_HEIGTH = 480; constexpr int32_t SLEEP_FIVE_SECOND = 5; constexpr int32_t SLEEP_TWENTY_SECOND = 20; -static sptr g_cameraInfo = nullptr; +static sptr g_cameraInfo = nullptr; static sptr g_cameraManager = nullptr; static sptr g_cameraInput = nullptr; static sptr g_photoOutput = nullptr; @@ -61,13 +61,13 @@ static int32_t InitCameraStandard() g_captureSession = g_cameraManager->CreateCaptureSession(); g_captureSession->SetCallback(std::make_shared()); - std::vector> cameraObjList = g_cameraManager->GetCameras(); + std::vector> cameraObjList = g_cameraManager->GetSupportedCameras(); for (auto info : cameraObjList) { DHLOGI("Camera: %s, position: %d, camera type: %d, connection type: %d", GetAnonyString(info->GetID()).c_str(), info->GetPosition(), info->GetCameraType(), info->GetConnectionType()); // OHOS_CAMERA_POSITION_FRONT or OHOS_CAMERA_POSITION_BACK - if ((info->GetPosition() == OHOS_CAMERA_POSITION_FRONT) && - (info->GetConnectionType() == OHOS_CAMERA_CONNECTION_TYPE_REMOTE)) { + if ((info->GetPosition() == CameraPosition::CAMERA_POSITION_FRONT) && + (info->GetConnectionType() == ConnectionType::CAMERA_CONNECTION_REMOTE)) { g_cameraInfo = info; break; } diff --git a/services/cameraservice/cameraoperator/handler/include/dcamera_handler.h b/services/cameraservice/cameraoperator/handler/include/dcamera_handler.h index 83a77072..d0dcbeef 100644 --- a/services/cameraservice/cameraoperator/handler/include/dcamera_handler.h +++ b/services/cameraservice/cameraoperator/handler/include/dcamera_handler.h @@ -23,6 +23,7 @@ #include "camera_info.h" #include "camera_input.h" #include "camera_manager.h" +#include "camera_output_capability.h" #include "json/json.h" #include "single_instance.h" #include "v1_0/dcamera_types.h" @@ -30,11 +31,6 @@ namespace OHOS { namespace DistributedHardware { using namespace OHOS::HDI::DistributedCamera::V1_0; -struct ConfigInfo { - DCStreamType type; - std::string formatKey; - sptr cameraInput; -}; class DCameraHandler : public IHardwareHandler { DECLARE_SINGLE_INSTANCE_BASE(DCameraHandler); @@ -53,11 +49,11 @@ private: ~DCameraHandler(); private: - DHItem CreateDHItem(sptr& info); - std::string GetCameraPosition(camera_position_enum_t position); - void ConfigFormatAndResolution(ConfigInfo& info, Json::Value& outputFormat, Json::Value& resolution, - std::vector& formatList, std::set& formatSet); - bool IsValid(const DCStreamType type, const CameraStandard::CameraPicSize& size); + DHItem CreateDHItem(sptr& info); + std::string GetCameraPosition(CameraStandard::CameraPosition position); + void ConfigFormatAndResolution(const DCStreamType type, Json::Value& root, + std::vector& profileList); + bool IsValid(const DCStreamType type, const CameraStandard::Size& size); sptr cameraManager_; std::shared_ptr pluginListener_; diff --git a/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp b/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp index cd335571..5ef85869 100644 --- a/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp +++ b/services/cameraservice/cameraoperator/handler/src/dcamera_handler.cpp @@ -53,21 +53,21 @@ int32_t DCameraHandler::Initialize() std::vector DCameraHandler::Query() { std::vector itemList; - std::vector> cameraList = cameraManager_->GetCameras(); + std::vector> cameraList = cameraManager_->GetSupportedCameras(); DHLOGI("DCameraHandler::Query get %d cameras", cameraList.size()); if (cameraList.empty()) { DHLOGE("DCameraHandler::Query no camera device"); return itemList; } for (auto& info : cameraList) { - if (info->GetConnectionType() != OHOS_CAMERA_CONNECTION_TYPE_BUILTIN) { + if (info->GetConnectionType() != CameraStandard::ConnectionType::CAMERA_CONNECTION_BUILT_IN) { DHLOGI("DCameraHandler::Query connection type: %d", info->GetConnectionType()); continue; } - if ((info->GetPosition() == OHOS_CAMERA_POSITION_OTHER) || - (info->GetPosition() == OHOS_CAMERA_POSITION_FRONT) || - (info->GetPosition() == OHOS_CAMERA_POSITION_BACK && - info->GetCameraType() == OHOS_CAMERA_TYPE_LOGICAL)) { + if ((info->GetPosition() == CameraStandard::CameraPosition::CAMERA_POSITION_UNSPECIFIED) || + (info->GetPosition() == CameraStandard::CameraPosition::CAMERA_POSITION_FRONT) || + (info->GetPosition() == CameraStandard::CameraPosition::CAMERA_POSITION_BACK && + info->GetCameraType() == static_cast(OHOS_CAMERA_TYPE_LOGICAL))) { DHItem item = CreateDHItem(info); itemList.emplace_back(item); } @@ -107,21 +107,21 @@ void DCameraHandler::UnRegisterPluginListener() std::vector DCameraHandler::GetCameras() { std::vector cameras; - std::vector> cameraList = cameraManager_->GetCameras(); + std::vector> cameraList = cameraManager_->GetSupportedCameras(); DHLOGI("DCameraHandler::GetCameras get %d cameras", cameraList.size()); if (cameraList.empty()) { DHLOGE("DCameraHandler::GetCameras no camera device"); return cameras; } for (auto& info : cameraList) { - if (info->GetConnectionType() != OHOS_CAMERA_CONNECTION_TYPE_BUILTIN) { + if (info->GetConnectionType() != CameraStandard::ConnectionType::CAMERA_CONNECTION_BUILT_IN) { DHLOGI("DCameraHandler::GetCameras connection type: %d", info->GetConnectionType()); continue; } - if ((info->GetPosition() == OHOS_CAMERA_POSITION_OTHER) || - (info->GetPosition() == OHOS_CAMERA_POSITION_FRONT) || - (info->GetPosition() == OHOS_CAMERA_POSITION_BACK && - info->GetCameraType() == OHOS_CAMERA_TYPE_LOGICAL)) { + if ((info->GetPosition() == CameraStandard::CameraPosition::CAMERA_POSITION_UNSPECIFIED) || + (info->GetPosition() == CameraStandard::CameraPosition::CAMERA_POSITION_FRONT) || + (info->GetPosition() == CameraStandard::CameraPosition::CAMERA_POSITION_BACK && + info->GetCameraType() == static_cast(OHOS_CAMERA_TYPE_LOGICAL))) { std::string dhId = CAMERA_ID_PREFIX + info->GetID(); cameras.emplace_back(dhId); } @@ -130,7 +130,7 @@ std::vector DCameraHandler::GetCameras() return cameras; } -DHItem DCameraHandler::CreateDHItem(sptr& info) +DHItem DCameraHandler::CreateDHItem(sptr& info) { DHItem item; std::string id = info->GetID(); @@ -150,61 +150,49 @@ DHItem DCameraHandler::CreateDHItem(sptr& info) DHLOGI("DCameraHandler::CreateDHItem codec type: %s", name.c_str()); } + sptr capability = cameraManager_->GetSupportedOutputCapability(info); + std::vector photoProfiles = capability->GetPhotoProfiles(); + ConfigFormatAndResolution(SNAPSHOT_FRAME, root, photoProfiles); + + std::vector previewProfiles = capability->GetPreviewProfiles(); + ConfigFormatAndResolution(CONTINUOUS_FRAME, root, previewProfiles); + sptr cameraInput = cameraManager_->CreateCameraInput(info); if (cameraInput == nullptr) { DHLOGE("DCameraHandler::CreateDHItem create cameraInput failed"); return item; } - Json::Value outputFormat; - Json::Value resolution; - std::set formatSet; - - std::vector videoFormats = cameraInput->GetSupportedVideoFormats(); - ConfigInfo videoConfig = {CONTINUOUS_FRAME, CAMERA_FORMAT_VIDEO, cameraInput}; - ConfigFormatAndResolution(videoConfig, outputFormat, resolution, videoFormats, formatSet); - - std::vector previewFormats = cameraInput->GetSupportedPreviewFormats(); - ConfigInfo previewInfo = {CONTINUOUS_FRAME, CAMERA_FORMAT_PREVIEW, cameraInput}; - ConfigFormatAndResolution(previewInfo, outputFormat, resolution, previewFormats, formatSet); - - std::vector photoFormats = cameraInput->GetSupportedPhotoFormats(); - ConfigInfo photoConfig = {SNAPSHOT_FRAME, CAMERA_FORMAT_PHOTO, cameraInput}; - ConfigFormatAndResolution(photoConfig, outputFormat, resolution, photoFormats, formatSet); + // std::hash h; + // std::string abilityString = cameraInput->GetCameraSettings(); + // DHLOGI("DCameraHandler::CreateDHItem abilityString hash: %zu, length: %zu", + // h(abilityString), abilityString.length()); - root[CAMERA_FORMAT_KEY] = outputFormat; - root[CAMERA_RESOLUTION_KEY] = resolution; - - std::hash h; - std::string abilityString = cameraInput->GetCameraSettings(); - DHLOGI("DCameraHandler::CreateDHItem abilityString hash: %zu, length: %zu", - h(abilityString), abilityString.length()); - - std::string encodeString = Base64Encode(reinterpret_cast(abilityString.c_str()), - abilityString.length()); - DHLOGI("DCameraHandler::CreateDHItem encodeString hash: %zu, length: %zu", - h(encodeString), encodeString.length()); - root[CAMERA_METADATA_KEY] = Json::Value(encodeString); + // std::string encodeString = Base64Encode(reinterpret_cast(abilityString.c_str()), + // abilityString.length()); + // DHLOGI("DCameraHandler::CreateDHItem encodeString hash: %zu, length: %zu", + // h(encodeString), encodeString.length()); + // root[CAMERA_METADATA_KEY] = Json::Value(encodeString); item.attrs = root.toStyledString(); cameraInput->Release(); return item; } -std::string DCameraHandler::GetCameraPosition(camera_position_enum_t position) +std::string DCameraHandler::GetCameraPosition(CameraStandard::CameraPosition position) { DHLOGI("DCameraHandler::GetCameraPosition position: %d", position); std::string ret = ""; switch (position) { - case OHOS_CAMERA_POSITION_BACK: { + case CameraStandard::CameraPosition::CAMERA_POSITION_BACK: { ret = CAMERA_POSITION_BACK; break; } - case OHOS_CAMERA_POSITION_FRONT: { + case CameraStandard::CameraPosition::CAMERA_POSITION_FRONT: { ret = CAMERA_POSITION_FRONT; break; } - case OHOS_CAMERA_POSITION_OTHER: { + case CameraStandard::CameraPosition::CAMERA_POSITION_UNSPECIFIED: { ret = CAMERA_POSITION_UNSPECIFIED; break; } @@ -217,29 +205,38 @@ std::string DCameraHandler::GetCameraPosition(camera_position_enum_t position) return ret; } -void DCameraHandler::ConfigFormatAndResolution(ConfigInfo& info, Json::Value& outputFormat, Json::Value& resolution, - std::vector& formatList, std::set& formatSet) +void DCameraHandler::ConfigFormatAndResolution(const DCStreamType type, Json::Value& root, + std::vector& profileList) { - DHLOGI("DCameraHandler::ConfigFormatAndResolution camera format size: %d", formatList.size()); - for (auto& format : formatList) { - DHLOGI("DCameraHandler::ConfigFormatAndResolution %s format: %d", info.formatKey.c_str(), format); - outputFormat[info.formatKey].append(format); - if (formatSet.insert(format).second) { - std::vector picSizes = info.cameraInput->getSupportedSizes(format); - std::string keyName = std::to_string(format); - DHLOGI("DCameraHandler::ConfigFormatAndResolution get %d supported camera pic size", picSizes.size()); - for (auto& size : picSizes) { - if (IsValid(info.type, size)) { - std::string value = std::to_string(size.width) + "*" + std::to_string(size.height); - resolution[keyName].append(value); - DHLOGI("DCameraHandler::ConfigFormatAndResolution format %d resolution %s", format, value.c_str()); - } + DHLOGI("DCameraHandler::ConfigFormatAndResolution camera Profile size: %d", profileList.size()); + std::set formatSet; + for (auto& profile : profileList) { + CameraStandard::CameraFormat format = profile.GetCameraFormat(); + CameraStandard::Size picSize = profile.GetSize(); + formatSet.insert(format); + std::string formatName = std::to_string(format); + if (IsValid(type, picSize)) { + std::string resolutionValue = std::to_string(picSize.width) + "*" + std::to_string(picSize.height); + if (type == SNAPSHOT_FRAME) { + root[CAMERA_FORMAT_PHOTO][CAMERA_RESOLUTION_KEY][formatName].append(resolutionValue); + } else if (type == CONTINUOUS_FRAME) { + root[CAMERA_FORMAT_PREVIEW][CAMERA_RESOLUTION_KEY][formatName].append(resolutionValue); + root[CAMERA_FORMAT_VIDEO][CAMERA_RESOLUTION_KEY][formatName].append(resolutionValue); } } } + + for (auto format : formatSet) { + if (type == SNAPSHOT_FRAME) { + root[CAMERA_FORMAT_PHOTO][CAMERA_FORMAT_KEY].append(format); + } else if (type == CONTINUOUS_FRAME) { + root[CAMERA_FORMAT_PREVIEW][CAMERA_FORMAT_KEY].append(format); + root[CAMERA_FORMAT_VIDEO][CAMERA_FORMAT_KEY].append(format); + } + } } -bool DCameraHandler::IsValid(const DCStreamType type, const CameraStandard::CameraPicSize& size) +bool DCameraHandler::IsValid(const DCStreamType type, const CameraStandard::Size& size) { bool ret = false; switch (type) { diff --git a/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp b/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp index 414fc97c..0171d2c2 100644 --- a/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp +++ b/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp @@ -53,21 +53,21 @@ int32_t DCameraHandler::Initialize() std::vector DCameraHandler::Query() { std::vector itemList; - std::vector> cameraList = cameraManager_->GetCameras(); + std::vector> cameraList = cameraManager_->GetSupportedCameras(); DHLOGI("DCameraHandlerCommon::Query get %d cameras", cameraList.size()); if (cameraList.empty()) { DHLOGE("DCameraHandlerCommon::Query no camera device"); return itemList; } for (auto& info : cameraList) { - if (info->GetConnectionType() != OHOS_CAMERA_CONNECTION_TYPE_BUILTIN) { + if (info->GetConnectionType() != CameraStandard::ConnectionType::CAMERA_CONNECTION_BUILT_IN) { DHLOGI("DCameraHandlerCommon::Query connection type: %d", info->GetConnectionType()); continue; } - if ((info->GetPosition() == OHOS_CAMERA_POSITION_OTHER) || - (info->GetPosition() == OHOS_CAMERA_POSITION_FRONT) || - (info->GetPosition() == OHOS_CAMERA_POSITION_BACK && - info->GetCameraType() == OHOS_CAMERA_TYPE_LOGICAL)) { + if ((info->GetPosition() == CameraStandard::CameraPosition::CAMERA_POSITION_UNSPECIFIED) || + (info->GetPosition() == CameraStandard::CameraPosition::CAMERA_POSITION_FRONT) || + (info->GetPosition() == CameraStandard::CameraPosition::CAMERA_POSITION_BACK && + info->GetCameraType() == static_cast(OHOS_CAMERA_TYPE_LOGICAL))) { DHItem item = CreateDHItem(info); itemList.emplace_back(item); } @@ -107,21 +107,21 @@ void DCameraHandler::UnRegisterPluginListener() std::vector DCameraHandler::GetCameras() { std::vector cameras; - std::vector> cameraList = cameraManager_->GetCameras(); + std::vector> cameraList = cameraManager_->GetSupportedCameras(); DHLOGI("DCameraHandlerCommon::GetCameras get %d cameras", cameraList.size()); if (cameraList.empty()) { DHLOGE("DCameraHandlerCommon::GetCameras no camera device"); return cameras; } for (auto& info : cameraList) { - if (info->GetConnectionType() != OHOS_CAMERA_CONNECTION_TYPE_BUILTIN) { + if (info->GetConnectionType() != CameraStandard::ConnectionType::CAMERA_CONNECTION_BUILT_IN) { DHLOGI("DCameraHandlerCommon::GetCameras connection type: %d", info->GetConnectionType()); continue; } - if ((info->GetPosition() == OHOS_CAMERA_POSITION_OTHER) || - (info->GetPosition() == OHOS_CAMERA_POSITION_FRONT) || - (info->GetPosition() == OHOS_CAMERA_POSITION_BACK && - info->GetCameraType() == OHOS_CAMERA_TYPE_LOGICAL)) { + if ((info->GetPosition() == CameraStandard::CameraPosition::CAMERA_POSITION_UNSPECIFIED) || + (info->GetPosition() == CameraStandard::CameraPosition::CAMERA_POSITION_FRONT) || + (info->GetPosition() == CameraStandard::CameraPosition::CAMERA_POSITION_BACK && + info->GetCameraType() == static_cast(OHOS_CAMERA_TYPE_LOGICAL))) { std::string dhId = CAMERA_ID_PREFIX + info->GetID(); cameras.emplace_back(dhId); } @@ -130,7 +130,7 @@ std::vector DCameraHandler::GetCameras() return cameras; } -DHItem DCameraHandler::CreateDHItem(sptr& info) +DHItem DCameraHandler::CreateDHItem(sptr& info) { DHItem item; std::string id = info->GetID(); @@ -148,58 +148,43 @@ DHItem DCameraHandler::CreateDHItem(sptr& info) return item; } - Json::Value outputFormat; - Json::Value resolution; - std::set formatSet; + sptr capability = cameraManager_->GetSupportedOutputCapability(info); + std::vector photoProfiles = capability->GetPhotoProfiles(); + ConfigFormatAndResolution(SNAPSHOT_FRAME, root, photoProfiles); - std::vector videoFormats; - videoFormats.emplace_back(camera_format_t::OHOS_CAMERA_FORMAT_RGBA_8888); - ConfigInfo videoConfig = {CONTINUOUS_FRAME, CAMERA_FORMAT_VIDEO, cameraInput}; - ConfigFormatAndResolution(videoConfig, outputFormat, resolution, videoFormats, formatSet); + std::vector previewProfiles = capability->GetPreviewProfiles(); + ConfigFormatAndResolution(CONTINUOUS_FRAME, root, previewProfiles); - std::vector previewFormats; - previewFormats.emplace_back(camera_format_t::OHOS_CAMERA_FORMAT_RGBA_8888); - ConfigInfo previewInfo = {CONTINUOUS_FRAME, CAMERA_FORMAT_PREVIEW, cameraInput}; - ConfigFormatAndResolution(previewInfo, outputFormat, resolution, previewFormats, formatSet); + // std::hash h; + // std::string abilityString = cameraInput->GetCameraSettings(); + // DHLOGI("DCameraHandlerCommon::CreateDHItem abilityString hash: %zu, length: %zu", + // h(abilityString), abilityString.length()); - std::vector photoFormats; - photoFormats.emplace_back(camera_format_t::OHOS_CAMERA_FORMAT_RGBA_8888); - ConfigInfo photoConfig = {SNAPSHOT_FRAME, CAMERA_FORMAT_PHOTO, cameraInput}; - ConfigFormatAndResolution(photoConfig, outputFormat, resolution, photoFormats, formatSet); - - root[CAMERA_FORMAT_KEY] = outputFormat; - root[CAMERA_RESOLUTION_KEY] = resolution; - - std::hash h; - std::string abilityString = cameraInput->GetCameraSettings(); - DHLOGI("DCameraHandlerCommon::CreateDHItem abilityString hash: %zu, length: %zu", - h(abilityString), abilityString.length()); - - std::string encodeString = Base64Encode(reinterpret_cast(abilityString.c_str()), - abilityString.length()); - DHLOGI("DCameraHandlerCommon::CreateDHItem encodeString hash: %zu, length: %zu", - h(encodeString), encodeString.length()); - root[CAMERA_METADATA_KEY] = Json::Value(encodeString); + // std::string encodeString = Base64Encode(reinterpret_cast(abilityString.c_str()), + // abilityString.length()); + // DHLOGI("DCameraHandlerCommon::CreateDHItem encodeString hash: %zu, length: %zu", + // h(encodeString), encodeString.length()); + // root[CAMERA_METADATA_KEY] = Json::Value(encodeString); item.attrs = root.toStyledString(); cameraInput->Release(); return item; } -std::string DCameraHandler::GetCameraPosition(camera_position_enum_t position) +std::string DCameraHandler::GetCameraPosition(CameraStandard::CameraPosition position) { DHLOGI("DCameraHandler::GetCameraPosition position: %d", position); std::string ret = ""; switch (position) { - case OHOS_CAMERA_POSITION_BACK: { + case CameraStandard::CameraPosition::CAMERA_POSITION_BACK: { ret = CAMERA_POSITION_BACK; break; } - case OHOS_CAMERA_POSITION_FRONT: { + case CameraStandard::CameraPosition::CAMERA_POSITION_FRONT: { ret = CAMERA_POSITION_FRONT; break; } - case OHOS_CAMERA_POSITION_OTHER: { + case CameraStandard::CameraPosition::CAMERA_POSITION_UNSPECIFIED: { ret = CAMERA_POSITION_UNSPECIFIED; break; } @@ -212,21 +197,35 @@ std::string DCameraHandler::GetCameraPosition(camera_position_enum_t position) return ret; } -void DCameraHandler::ConfigFormatAndResolution(ConfigInfo& info, Json::Value& outputFormat, Json::Value& resolution, - std::vector& formatList, std::set& formatSet) +void DCameraHandler::ConfigFormatAndResolution(const DCStreamType type, Json::Value& root, + std::vector& profileList) { - DHLOGI("DCameraHandlerCommon::ConfigFormatAndResolution camera format size: %d", formatList.size()); - for (auto& format : formatList) { - DHLOGI("DCameraHandlerCommon::ConfigFormatAndResolution %s format: %d", info.formatKey.c_str(), format); - outputFormat[info.formatKey].append(format); - if (formatSet.insert(format).second) { - std::string keyName = std::to_string(format); - resolution[keyName].append("640*480"); + DHLOGI("DCameraHandler::ConfigFormatAndResolution camera Profile size: %d", profileList.size()); + std::set formatSet; + for (auto& profile : profileList) { + CameraStandard::CameraFormat format = profile.GetCameraFormat(); + // CameraStandard::Size picSize = profile.GetSize(); + formatSet.insert(format); + std::string formatName = std::to_string(format); + if (type == SNAPSHOT_FRAME) { + root[CAMERA_FORMAT_PHOTO][CAMERA_RESOLUTION_KEY][formatName].append("640*480"); + } else if (type == CONTINUOUS_FRAME) { + root[CAMERA_FORMAT_PREVIEW][CAMERA_RESOLUTION_KEY][formatName].append("640*480"); + root[CAMERA_FORMAT_VIDEO][CAMERA_RESOLUTION_KEY][formatName].append("640*480"); + } + } + + for (auto format : formatSet) { + if (type == SNAPSHOT_FRAME) { + root[CAMERA_FORMAT_PHOTO][CAMERA_FORMAT_KEY].append(format); + } else if (type == CONTINUOUS_FRAME) { + root[CAMERA_FORMAT_PREVIEW][CAMERA_FORMAT_KEY].append(format); + root[CAMERA_FORMAT_VIDEO][CAMERA_FORMAT_KEY].append(format); } } } -bool DCameraHandler::IsValid(const DCStreamType type, const CameraStandard::CameraPicSize& size) +bool DCameraHandler::IsValid(const DCStreamType type, const CameraStandard::Size& size) { bool ret = false; switch (type) { -- Gitee From f4927ba59512e514aa72bc67c70e3fd7f36a0bab Mon Sep 17 00:00:00 2001 From: chen0088 Date: Thu, 4 Aug 2022 14:42:41 +0800 Subject: [PATCH 2/3] feat:local camera interface modify Signed-off-by: chen0088 --- .../client/src/dcamera_client.cpp | 3 +- .../client/src/dcamera_client_common.cpp | 8 +-- .../client/test/sample/dcamera_client_demo.h | 2 +- .../client/test/sample/main.cpp | 59 +++++++++++++++---- 4 files changed, 53 insertions(+), 19 deletions(-) diff --git a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp index df4943d3..4edda842 100644 --- a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp +++ b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp @@ -431,7 +431,8 @@ int32_t DCameraClient::CreateVideoOutput(std::shared_ptr& in videoSurface_->RegisterConsumerListener((sptr &)videoListener_); CameraStandard::CameraFormat videoFormat = ConvertToCameraFormat(info->format_); CameraStandard::Size videoSize = {info->height_, info->width_}; - CameraStandard::Profile videoProfile(videoFormat, videoSize); + std::vector framerates = {}; + CameraStandard::VideoProfile videoProfile(videoFormat, videoSize, framerates); videoOutput_ = cameraManager_->CreateVideoOutput(videoProfile, videoSurface_); if (videoOutput_ == nullptr) { DHLOGE("DCameraClient::CreateVideoOutput %s create video output failed", GetAnonyString(cameraId_).c_str()); diff --git a/services/cameraservice/cameraoperator/client/src/dcamera_client_common.cpp b/services/cameraservice/cameraoperator/client/src/dcamera_client_common.cpp index 34a100f9..b80b5f22 100644 --- a/services/cameraservice/cameraoperator/client/src/dcamera_client_common.cpp +++ b/services/cameraservice/cameraoperator/client/src/dcamera_client_common.cpp @@ -415,16 +415,16 @@ CameraStandard::CameraFormat DCameraClient::ConvertToCameraFormat(int32_t format CameraStandard::CameraFormat ret = CameraStandard::CameraFormat::CAMERA_FORMAT_INVALID; DCameraFormat df = static_cast(format); switch (df) { - case OHOS_CAMERA_FORMAT_RGBA_8888: + case DCameraFormat::OHOS_CAMERA_FORMAT_RGBA_8888: ret = CameraStandard::CameraFormat::CAMERA_FORMAT_RGBA_8888; break; - case OHOS_CAMERA_FORMAT_YCBCR_420_888: + case DCameraFormat::OHOS_CAMERA_FORMAT_YCBCR_420_888: ret = CameraStandard::CameraFormat::CAMERA_FORMAT_YCBCR_420_888; break; - case OHOS_CAMERA_FORMAT_YCRCB_420_SP: + case DCameraFormat::OHOS_CAMERA_FORMAT_YCRCB_420_SP: ret = CameraStandard::CameraFormat::CAMERA_FORMAT_YUV_420_SP; break; - case OHOS_CAMERA_FORMAT_JPEG: + case DCameraFormat::OHOS_CAMERA_FORMAT_JPEG: ret = CameraStandard::CameraFormat::CAMERA_FORMAT_JPEG; break; default: diff --git a/services/cameraservice/cameraoperator/client/test/sample/dcamera_client_demo.h b/services/cameraservice/cameraoperator/client/test/sample/dcamera_client_demo.h index 4c1fc0a8..d21e0fc7 100644 --- a/services/cameraservice/cameraoperator/client/test/sample/dcamera_client_demo.h +++ b/services/cameraservice/cameraoperator/client/test/sample/dcamera_client_demo.h @@ -272,7 +272,7 @@ public: } void OnFlashlightStatusChanged(const std::string &cameraID, - const CameraStandard::FlashlightStatus flashStatus) const + const CameraStandard::FlashStatus flashStatus) const { DHLOGI("DemoDCameraManagerCallback::OnFlashlightStatusChanged cameraID: %s, flashStatus: %d", GetAnonyString(cameraID).c_str(), flashStatus); diff --git a/services/cameraservice/cameraoperator/client/test/sample/main.cpp b/services/cameraservice/cameraoperator/client/test/sample/main.cpp index 5ed4dfe5..5076faaa 100644 --- a/services/cameraservice/cameraoperator/client/test/sample/main.cpp +++ b/services/cameraservice/cameraoperator/client/test/sample/main.cpp @@ -81,7 +81,7 @@ static int32_t InitCameraStandard() g_cameraInput = g_cameraManager->CreateCameraInput(g_cameraInfo); std::shared_ptr inputCallback = std::make_shared(); ((sptr &)g_cameraInput)->SetErrorCallback(inputCallback); - ((sptr &)g_cameraInput)->SetFocusCallback(inputCallback); + g_captureSession->SetFocusCallback(inputCallback); return DCAMERA_OK; } @@ -103,6 +103,29 @@ static void InitCaptureInfo() g_videoInfo->format_ = VIDEO_FORMAT; } +static CameraFormat ConvertToCameraFormat(int32_t format) +{ + CameraFormat ret = CameraFormat::CAMERA_FORMAT_INVALID; + DCameraFormat df = static_cast(format); + switch (df) { + case DCameraFormat::OHOS_CAMERA_FORMAT_RGBA_8888: + ret = CameraFormat::CAMERA_FORMAT_RGBA_8888; + break; + case DCameraFormat::OHOS_CAMERA_FORMAT_YCBCR_420_888: + ret = CameraFormat::CAMERA_FORMAT_YCBCR_420_888; + break; + case DCameraFormat::OHOS_CAMERA_FORMAT_YCRCB_420_SP: + ret = CameraFormat::CAMERA_FORMAT_YUV_420_SP; + break; + case DCameraFormat::OHOS_CAMERA_FORMAT_JPEG: + ret = CameraFormat::CAMERA_FORMAT_JPEG; + break; + default: + break; + } + return ret; +} + static void InitPhotoOutput() { DHLOGI("Distributed Camera Demo: Create PhotoOutput, width = %d, height = %d, format = %d", @@ -112,7 +135,10 @@ static void InitPhotoOutput() photoSurface->SetDefaultWidthAndHeight(g_photoInfo->width_, g_photoInfo->height_); photoSurface->SetUserData(CAMERA_SURFACE_FORMAT, std::to_string(g_photoInfo->format_)); photoSurface->RegisterConsumerListener(photoListener); - g_photoOutput = g_cameraManager->CreatePhotoOutput(photoSurface); + CameraFormat photoFormat = ConvertToCameraFormat(g_photoInfo->format_); + Size photoSize = {g_photoInfo->height_, g_photoInfo->width_}; + Profile photoProfile(photoFormat, photoSize); + g_photoOutput = g_cameraManager->CreatePhotoOutput(photoProfile, photoSurface); ((sptr &)g_photoOutput)->SetCallback(std::make_shared()); } @@ -125,7 +151,10 @@ static void InitPreviewOutput() previewSurface->SetDefaultWidthAndHeight(g_previewInfo->width_, g_previewInfo->height_); previewSurface->SetUserData(CAMERA_SURFACE_FORMAT, std::to_string(g_previewInfo->format_)); previewSurface->RegisterConsumerListener(previewListener); - g_previewOutput = g_cameraManager->CreatePreviewOutput(previewSurface); + CameraFormat previewFormat = ConvertToCameraFormat(g_previewInfo->format_); + Size previewSize = {g_previewInfo->height_, g_previewInfo->width_}; + Profile previewProfile(previewFormat, previewSize); + g_previewOutput = g_cameraManager->CreatePreviewOutput(previewProfile, previewSurface); ((sptr &)g_previewOutput)->SetCallback(std::make_shared()); } @@ -138,25 +167,29 @@ static void InitVideoOutput() videoSurface->SetDefaultWidthAndHeight(g_videoInfo->width_, g_videoInfo->height_); videoSurface->SetUserData(CAMERA_SURFACE_FORMAT, std::to_string(g_videoInfo->format_)); videoSurface->RegisterConsumerListener(videoListener); - g_videoOutput = g_cameraManager->CreateVideoOutput(videoSurface); + CameraFormat videoFormat = ConvertToCameraFormat(g_videoInfo->format_); + Size videoSize = {g_videoInfo->height_, g_videoInfo->width_}; + std::vector framerates = {}; + VideoProfile videoProfile(videoFormat, videoSize, framerates); + g_videoOutput = g_cameraManager->CreateVideoOutput(videoProfile, videoSurface); ((sptr &)g_videoOutput)->SetCallback(std::make_shared()); } static void ConfigFocusAndExposure() { - ((sptr &)g_cameraInput)->LockForControl(); - camera_focus_mode_enum_t focusMode = OHOS_CAMERA_FOCUS_MODE_AUTO; - camera_exposure_mode_enum_t exposureMode = OHOS_CAMERA_EXPOSURE_MODE_AUTO; + g_captureSession->LockForControl(); + FocusMode focusMode = FOCUS_MODE_CONTINUOUS_AUTO; + ExposureMode exposureMode = EXPOSURE_MODE_AUTO; int32_t exposureValue = 0; - std::vector biasRange = ((sptr &)g_cameraInput)->GetExposureBiasRange(); + std::vector biasRange = g_captureSession->GetExposureBiasRange(); if (!biasRange.empty()) { DHLOGI("Distributed Camera Demo: get %d exposure compensation range", biasRange.size()); exposureValue = biasRange[0]; } - ((sptr &)g_cameraInput)->SetFocusMode(focusMode); - ((sptr &)g_cameraInput)->SetExposureMode(exposureMode); - ((sptr &)g_cameraInput)->SetExposureBias(exposureValue); - ((sptr &)g_cameraInput)->UnlockForControl(); + g_captureSession->SetFocusMode(focusMode); + g_captureSession->SetExposureMode(exposureMode); + g_captureSession->SetExposureBias(exposureValue); + g_captureSession->UnlockForControl(); } static std::shared_ptr ConfigPhotoCaptureSetting() @@ -166,7 +199,7 @@ static std::shared_ptr ConfigPhotoCaptureSetting() PhotoCaptureSetting::RotationConfig rotation = PhotoCaptureSetting::RotationConfig::Rotation_0; photoCaptureSettings->SetRotation(rotation); // QualityLevel - PhotoCaptureSetting::QualityLevel quality = PhotoCaptureSetting::QualityLevel::HIGH_QUALITY; + PhotoCaptureSetting::QualityLevel quality = PhotoCaptureSetting::QualityLevel::QUALITY_LEVEL_HIGH; photoCaptureSettings->SetQuality(quality); // Location std::unique_ptr location = std::make_unique(); -- Gitee From 55b4a85c07c0b9c9a128cce9e2ba89781db74b01 Mon Sep 17 00:00:00 2001 From: chen0088 Date: Fri, 26 Aug 2022 14:40:40 +0800 Subject: [PATCH 3/3] feat:local camera interface modify service Signed-off-by: chen0088 --- .../cameraoperator/handler/src/dcamera_handler_common.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp b/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp index 0171d2c2..a738bdb9 100644 --- a/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp +++ b/services/cameraservice/cameraoperator/handler/src/dcamera_handler_common.cpp @@ -67,7 +67,7 @@ std::vector DCameraHandler::Query() if ((info->GetPosition() == CameraStandard::CameraPosition::CAMERA_POSITION_UNSPECIFIED) || (info->GetPosition() == CameraStandard::CameraPosition::CAMERA_POSITION_FRONT) || (info->GetPosition() == CameraStandard::CameraPosition::CAMERA_POSITION_BACK && - info->GetCameraType() == static_cast(OHOS_CAMERA_TYPE_LOGICAL))) { + info->GetCameraType() == static_cast(OHOS_CAMERA_TYPE_LOGICAL))) { DHItem item = CreateDHItem(info); itemList.emplace_back(item); } -- Gitee