From 71be9380efc897667de6abafd1fd20b9146ec780 Mon Sep 17 00:00:00 2001 From: wangchaole Date: Mon, 23 May 2022 16:44:45 +0800 Subject: [PATCH 1/5] =?UTF-8?q?dhf=E4=B8=8Esa=E8=A7=A3=E8=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- camera_hdf/hdi_impl/BUILD.gn | 12 +-- .../include/dstream_operator/dimage_buffer.h | 3 +- .../hdi_impl/include/utils/anonymous_string.h | 27 ++++++ camera_hdf/hdi_impl/include/utils/constants.h | 32 ++++++- camera_hdf/hdi_impl/include/utils/dh_log.h | 43 +++++++++ .../include/utils/distributed_hardware_log.h | 38 ++++++++ .../src/dcamera_device/dcamera_device.cpp | 3 +- .../dcamera_device/dmetadata_processor.cpp | 4 +- .../src/dstream_operator/dbuffer_manager.cpp | 3 +- .../src/dstream_operator/dstream_operator.cpp | 2 +- .../hdi_impl/src/utils/anonymous_string.cpp | 68 +++++++++++++++ camera_hdf/hdi_impl/src/utils/dh_log.cpp | 87 +++++++++++++++++++ camera_hdf/interfaces/hdi_ipc/client/BUILD.gn | 9 +- 13 files changed, 307 insertions(+), 24 deletions(-) create mode 100644 camera_hdf/hdi_impl/include/utils/anonymous_string.h create mode 100644 camera_hdf/hdi_impl/include/utils/dh_log.h create mode 100644 camera_hdf/hdi_impl/include/utils/distributed_hardware_log.h create mode 100644 camera_hdf/hdi_impl/src/utils/anonymous_string.cpp create mode 100644 camera_hdf/hdi_impl/src/utils/dh_log.cpp diff --git a/camera_hdf/hdi_impl/BUILD.gn b/camera_hdf/hdi_impl/BUILD.gn index bd015647..a33bd3b3 100644 --- a/camera_hdf/hdi_impl/BUILD.gn +++ b/camera_hdf/hdi_impl/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-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 @@ -31,12 +31,6 @@ ohos_shared_library("distributed_camera_hdf") { "../interfaces/hdi_ipc/server/provider", "//utils/native/base/include", "//utils/system/safwk/native/include", - "${common_path}/include/utils", - "${common_path}/include/constants", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include/", - "${fwk_utils_path}/include", - "${fwk_utils_path}/include/log", "${display_hdf_path}/interfaces/include", "${hdf_framework_path}/include/utils", "${hdf_framework_path}/include/core", @@ -77,12 +71,12 @@ ohos_shared_library("distributed_camera_hdf") { "src/dstream_operator/dimage_buffer.cpp", "src/dstream_operator/doffline_stream_operator.cpp", "src/dstream_operator/dstream_operator.cpp", + "src/utils/anonymous_string.cpp", "src/utils/dcamera.cpp", + "src/utils/dh_log.cpp", ] deps = [ - "${common_path}:distributed_camera_utils", - "${fwk_utils_path}:distributedhardwareutils", "//drivers/adapter/uhdf2/ipc:libhdf_ipc_adapter", "//drivers/peripheral/camera/interfaces/metadata:metadata", "//drivers/peripheral/display/hal:hdi_display_gralloc", diff --git a/camera_hdf/hdi_impl/include/dstream_operator/dimage_buffer.h b/camera_hdf/hdi_impl/include/dstream_operator/dimage_buffer.h index 10134379..207e4c44 100644 --- a/camera_hdf/hdi_impl/include/dstream_operator/dimage_buffer.h +++ b/camera_hdf/hdi_impl/include/dstream_operator/dimage_buffer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -18,7 +18,6 @@ #include #include "constants.h" -#include "distributed_camera_constants.h" namespace OHOS { namespace DistributedHardware { diff --git a/camera_hdf/hdi_impl/include/utils/anonymous_string.h b/camera_hdf/hdi_impl/include/utils/anonymous_string.h new file mode 100644 index 00000000..20d0ba55 --- /dev/null +++ b/camera_hdf/hdi_impl/include/utils/anonymous_string.h @@ -0,0 +1,27 @@ +/* + * 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_DISTRIBUTED_HARDWARE_ANONYMOUS_STRING_H +#define OHOS_DISTRIBUTED_HARDWARE_ANONYMOUS_STRING_H + +#include + +namespace OHOS { +namespace DistributedHardware { +std::string GetAnonyString(const std::string &value); +std::string GetAnonyInt32(const int32_t value); +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/camera_hdf/hdi_impl/include/utils/constants.h b/camera_hdf/hdi_impl/include/utils/constants.h index 818115cb..fd3b6928 100644 --- a/camera_hdf/hdi_impl/include/utils/constants.h +++ b/camera_hdf/hdi_impl/include/utils/constants.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -54,6 +54,36 @@ const uint32_t WAIT_OPEN_TIMEOUT_SEC = 5; const std::string ENCODE_TYPE_STR_H264 = "OMX_hisi_video_encoder_avc"; const std::string ENCODE_TYPE_STR_H265 = "OMX_hisi_video_encoder_hevc"; const std::string ENCODE_TYPE_STR_JPEG = "jpeg"; +const std::string DH_LOG_TITLE_TAG = "DHFWK"; +constexpr int32_t LOG_MAX_LEN = 4096; + +typedef enum { + OHOS_CAMERA_FORMAT_INVALID = 0, + OHOS_CAMERA_FORMAT_RGBA_8888, + OHOS_CAMERA_FORMAT_YCBCR_420_888, + OHOS_CAMERA_FORMAT_YCRCB_420_SP, + OHOS_CAMERA_FORMAT_JPEG, +} DCameraFormat; + +typedef enum { + DCAMERA_MESSAGE = 0, + DCAMERA_OPERATION = 1, +} DCameraEventType; + +typedef enum { + DCAMERA_EVENT_CHANNEL_DISCONNECTED = 0, + DCAMERA_EVENT_CHANNEL_CONNECTED = 1, + DCAMERA_EVENT_CAMERA_SUCCESS = 2, + + DCAMERA_EVENT_CAMERA_ERROR = -1, + DCAMERA_EVENT_OPEN_CHANNEL_ERROR = -2, + DCAMERA_EVENT_CLOSE_CHANNEL_ERROR = -3, + DCAMERA_EVENT_CONFIG_STREAMS_ERROR = -4, + DCAMERA_EVENT_RELEASE_STREAMS_ERROR = -5, + DCAMERA_EVENT_START_CAPTURE_ERROR = -6, + DCAMERA_EVENT_STOP_CAPTURE_ERROR = -7, + DCAMERA_EVENT_UPDATE_SETTINGS_ERROR = -8, +} DCameraEventResult; enum DCameraBufferUsage : uint64_t { CAMERA_USAGE_SW_READ_OFTEN = (1 << 0), diff --git a/camera_hdf/hdi_impl/include/utils/dh_log.h b/camera_hdf/hdi_impl/include/utils/dh_log.h new file mode 100644 index 00000000..be8b441a --- /dev/null +++ b/camera_hdf/hdi_impl/include/utils/dh_log.h @@ -0,0 +1,43 @@ +/* + * 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_DH_LOG_H +#define OHOS_DH_LOG_H + +namespace OHOS { +namespace DistributedHardware { +typedef enum { + DH_LOG_DEBUG, + DH_LOG_INFO, + DH_LOG_WARN, + DH_LOG_ERROR, +} DHLogLevel; + +void DHLog(DHLogLevel logLevel, const char *fmt, ...); + +#define ULOGD(fmt, ...) DHLog(DH_LOG_DEBUG, \ + (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) + +#define ULOGI(fmt, ...) DHLog(DH_LOG_INFO, \ + (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) + +#define ULOGW(fmt, ...) DHLog(DH_LOG_WARN, \ + (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) + +#define ULOGE(fmt, ...) DHLog(DH_LOG_ERROR, \ + (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/camera_hdf/hdi_impl/include/utils/distributed_hardware_log.h b/camera_hdf/hdi_impl/include/utils/distributed_hardware_log.h new file mode 100644 index 00000000..971d046c --- /dev/null +++ b/camera_hdf/hdi_impl/include/utils/distributed_hardware_log.h @@ -0,0 +1,38 @@ +/* + * 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_DISTRIBUTED_HARDWARE_LOG_H +#define OHOS_DISTRIBUTED_HARDWARE_LOG_H + +#include + +#include "dh_log.h" + +namespace OHOS { +namespace DistributedHardware { +#define DHLOGD(fmt, ...) DHLog(DH_LOG_DEBUG, \ + (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) + +#define DHLOGI(fmt, ...) DHLog(DH_LOG_INFO, \ + (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) + +#define DHLOGW(fmt, ...) DHLog(DH_LOG_WARN, \ + (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) + +#define DHLOGE(fmt, ...) DHLog(DH_LOG_ERROR, \ + (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/camera_hdf/hdi_impl/src/dcamera_device/dcamera_device.cpp b/camera_hdf/hdi_impl/src/dcamera_device/dcamera_device.cpp index 490aad11..c198d35d 100644 --- a/camera_hdf/hdi_impl/src/dcamera_device/dcamera_device.cpp +++ b/camera_hdf/hdi_impl/src/dcamera_device/dcamera_device.cpp @@ -18,9 +18,10 @@ #include #include #include "anonymous_string.h" +#include "constants.h" +#include "dcamera.h" #include "dcamera_host.h" #include "dcamera_provider.h" -#include "dcamera_utils_tools.h" #include "distributed_hardware_log.h" #include "metadata_utils.h" diff --git a/camera_hdf/hdi_impl/src/dcamera_device/dmetadata_processor.cpp b/camera_hdf/hdi_impl/src/dcamera_device/dmetadata_processor.cpp index aaf8aa35..bd7f880e 100644 --- a/camera_hdf/hdi_impl/src/dcamera_device/dmetadata_processor.cpp +++ b/camera_hdf/hdi_impl/src/dcamera_device/dmetadata_processor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 @@ -18,7 +18,7 @@ #include #include "dbuffer_manager.h" -#include "dcamera_utils_tools.h" +#include "dcamera.h" #include "distributed_hardware_log.h" #include "json/json.h" #include "metadata_utils.h" diff --git a/camera_hdf/hdi_impl/src/dstream_operator/dbuffer_manager.cpp b/camera_hdf/hdi_impl/src/dstream_operator/dbuffer_manager.cpp index 0b7e38d6..0ab0ef89 100644 --- a/camera_hdf/hdi_impl/src/dstream_operator/dbuffer_manager.cpp +++ b/camera_hdf/hdi_impl/src/dstream_operator/dbuffer_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -15,7 +15,6 @@ #include "dbuffer_manager.h" #include -#include "distributed_camera_constants.h" #include "distributed_hardware_log.h" namespace OHOS { 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 10fa5767..30dc282c 100644 --- a/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp +++ b/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp @@ -16,7 +16,7 @@ #include "dstream_operator.h" #include "dbuffer_manager.h" #include "dcamera_provider.h" -#include "dcamera_utils_tools.h" +#include "dcamera.h" #include "distributed_hardware_log.h" #include "json/json.h" #include "metadata_utils.h" diff --git a/camera_hdf/hdi_impl/src/utils/anonymous_string.cpp b/camera_hdf/hdi_impl/src/utils/anonymous_string.cpp new file mode 100644 index 00000000..b6cfa82d --- /dev/null +++ b/camera_hdf/hdi_impl/src/utils/anonymous_string.cpp @@ -0,0 +1,68 @@ +/* + * 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 "anonymous_string.h" + +#include "securec.h" + +namespace OHOS { +namespace DistributedHardware { +std::string GetAnonyString(const std::string &value) +{ + constexpr size_t INT32_SHORT_ID_LENGTH = 20; + constexpr size_t INT32_PLAINTEXT_LENGTH = 4; + constexpr size_t INT32_MIN_ID_LENGTH = 3; + std::string res; + std::string tmpStr("******"); + size_t strLen = value.length(); + if (strLen < INT32_MIN_ID_LENGTH) { + return tmpStr; + } + + if (strLen <= INT32_SHORT_ID_LENGTH) { + res += value[0]; + res += tmpStr; + res += value[strLen - 1]; + } else { + res.append(value, 0, INT32_PLAINTEXT_LENGTH); + res += tmpStr; + res.append(value, strLen - INT32_PLAINTEXT_LENGTH, INT32_PLAINTEXT_LENGTH); + } + + return res; +} + +std::string GetAnonyInt32(const int32_t value) +{ + constexpr int32_t INT32_STRING_LENGTH = 40; + char tempBuffer[INT32_STRING_LENGTH] = ""; + int32_t secRet = sprintf_s(tempBuffer, INT32_STRING_LENGTH, "%d", value); + if (secRet <= 0) { + std::string nullString(""); + return nullString; + } + size_t length = strlen(tempBuffer); + for (size_t i = 1; i <= length - 1; i++) { + tempBuffer[i] = '*'; + } + if (length == 0x01) { + tempBuffer[0] = '*'; + } + + std::string tempString(tempBuffer); + return tempString; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/camera_hdf/hdi_impl/src/utils/dh_log.cpp b/camera_hdf/hdi_impl/src/utils/dh_log.cpp new file mode 100644 index 00000000..f2278de4 --- /dev/null +++ b/camera_hdf/hdi_impl/src/utils/dh_log.cpp @@ -0,0 +1,87 @@ +/* + * 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 "dh_log.h" + +#include "securec.h" + +#include "constants.h" + +#ifdef HI_LOG_ENABLE +#include "hilog/log.h" +#else +#include +#endif + +namespace OHOS { +namespace DistributedHardware { +static void DHLogOut(DHLogLevel logLevel, const char *logBuf) +{ +#ifdef HI_LOG_ENABLE + LogLevel hiLogLevel = LOG_INFO; + switch (logLevel) { + case DH_LOG_DEBUG: + hiLogLevel = LOG_DEBUG; + break; + case DH_LOG_INFO: + hiLogLevel = LOG_INFO; + break; + case DH_LOG_WARN: + hiLogLevel = LOG_WARN; + break; + case DH_LOG_ERROR: + hiLogLevel = LOG_ERROR; + break; + default: + break; + } + (void)HiLogPrint(LOG_CORE, hiLogLevel, LOG_DOMAIN, DH_LOG_TITLE_TAG.c_str(), "%{public}s", logBuf); +#else + switch (logLevel) { + case DH_LOG_DEBUG: + printf("[D]%s\n", logBuf); + break; + case DH_LOG_INFO: + printf("[I]%s\n", logBuf); + break; + case DH_LOG_WARN: + printf("[W]%s\n", logBuf); + break; + case DH_LOG_ERROR: + printf("[E]%s\n", logBuf); + break; + default: + break; + } +#endif +} + +void DHLog(DHLogLevel logLevel, const char *fmt, ...) +{ + char logBuf[LOG_MAX_LEN] = {0}; + va_list arg; + + (void)memset_s(&arg, sizeof(va_list), 0, sizeof(va_list)); + va_start(arg, fmt); + int32_t ret = vsprintf_s(logBuf, sizeof(logBuf), fmt, arg); + va_end(arg); + if (ret < 0) { + DHLogOut(logLevel, "DH log length error."); + return; + } + DHLogOut(logLevel, logBuf); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/camera_hdf/interfaces/hdi_ipc/client/BUILD.gn b/camera_hdf/interfaces/hdi_ipc/client/BUILD.gn index 12ae6f5e..a4a22d64 100644 --- a/camera_hdf/interfaces/hdi_ipc/client/BUILD.gn +++ b/camera_hdf/interfaces/hdi_ipc/client/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-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 @@ -24,10 +24,7 @@ ohos_shared_library("distributed_camera_hdf_client") { "//utils/system/safwk/native/include", "${camera_hdf_path}/camera/interfaces/include", "${camera_hdf_path}/camera/interfaces/hdi_ipc", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include/", - "${fwk_utils_path}/include", - "${fwk_utils_path}/include/log", + "${distributedcamera_hdf_path}/hdi_impl/include/utils", "${hdf_framework_path}/include/utils", "${hdf_uhdf_path}/include/hdi", "${hdf_uhdf_path}/osal/include", @@ -67,11 +64,11 @@ ohos_shared_library("distributed_camera_hdf_client") { ] deps = [ - "${fwk_utils_path}:distributedhardwareutils", "${hdf_uhdf_path}/hdi:libhdi", "//drivers/peripheral/camera/interfaces/metadata:metadata", "//drivers/peripheral/display/hal:hdi_display_gralloc", "//foundation/graphic/graphic/frameworks/surface:surface", + "${distributedcamera_hdf_path}/hdi_impl:distributed_camera_hdf", "//utils/native/base:utils", ] -- Gitee From a832b279627e46197cf30afc2c88829060eeb2bf Mon Sep 17 00:00:00 2001 From: wangchaole Date: Mon, 23 May 2022 16:48:30 +0800 Subject: [PATCH 2/5] =?UTF-8?q?dhf=E4=B8=8Esa=E8=A7=A3=E8=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 30dc282c..2d6bbca1 100644 --- a/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp +++ b/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 -- Gitee From 90241d1c08afd537c2d7ea1df30f19918cf99564 Mon Sep 17 00:00:00 2001 From: wangchaole Date: Mon, 23 May 2022 17:58:44 +0800 Subject: [PATCH 3/5] =?UTF-8?q?dhf=E4=B8=8Esa=E8=A7=A3=E8=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- camera_hdf/hdi_impl/src/utils/dcamera.cpp | 104 ++++++++++++++++++ camera_hdf/interfaces/hdi_ipc/client/BUILD.gn | 2 +- 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/camera_hdf/hdi_impl/src/utils/dcamera.cpp b/camera_hdf/hdi_impl/src/utils/dcamera.cpp index 73b77851..c618cc5a 100644 --- a/camera_hdf/hdi_impl/src/utils/dcamera.cpp +++ b/camera_hdf/hdi_impl/src/utils/dcamera.cpp @@ -18,6 +18,13 @@ namespace OHOS { namespace DistributedHardware { +const int OFFSET2 = 2; +const int OFFSET4 = 4; +const int OFFSET6 = 6; +const int INDEX_FIRST = 0; +const int INDEX_SECOND = 1; +const int INDEX_THIRD = 2; +const int INDEX_FORTH = 3; CamRetCode MapToExternalRetCode(DCamRetCode retCode) { switch (retCode) { @@ -85,5 +92,102 @@ void SplitString(const std::string &str, std::vector &tokens, const tokens.push_back(str.substr(lastPos)); } } + +std::string Base64Encode(const unsigned char *toEncode, unsigned int len) +{ + std::string ret; + uint32_t i = 0; + unsigned char charArray3[3]; + unsigned char charArray4[4]; + + while (len--) { + charArray3[i++] = *(toEncode++); + if (i == sizeof(charArray3)) { + charArray4[INDEX_FIRST] = (charArray3[INDEX_FIRST] & 0xfc) >> OFFSET2; + charArray4[INDEX_SECOND] = ((charArray3[INDEX_FIRST] & 0x03) << OFFSET4) + + ((charArray3[INDEX_SECOND] & 0xf0) >> OFFSET4); + charArray4[INDEX_THIRD] = ((charArray3[INDEX_SECOND] & 0x0f) << OFFSET2) + + ((charArray3[INDEX_THIRD] & 0xc0) >> OFFSET6); + charArray4[INDEX_FORTH] = charArray3[INDEX_THIRD] & 0x3f; + for (i = 0; i < sizeof(charArray4); i++) { + ret += BASE_64_CHARS[charArray4[i]]; + } + i = 0; + } + } + + if (i) { + uint32_t j = 0; + for (j = i; j < sizeof(charArray3); j++) { + charArray3[j] = '\0'; + } + charArray4[INDEX_FIRST] = (charArray3[INDEX_FIRST] & 0xfc) >> OFFSET2; + charArray4[INDEX_SECOND] = ((charArray3[INDEX_FIRST] & 0x03) << OFFSET4) + + ((charArray3[INDEX_SECOND] & 0xf0) >> OFFSET4); + charArray4[INDEX_THIRD] = ((charArray3[INDEX_SECOND] & 0x0f) << OFFSET2) + + ((charArray3[INDEX_THIRD] & 0xc0) >> OFFSET6); + charArray4[INDEX_FORTH] = charArray3[INDEX_THIRD] & 0x3f; + for (j = 0; j < i + 1; j++) { + ret += BASE_64_CHARS[charArray4[j]]; + } + while (i++ < sizeof(charArray3)) { + ret += '='; + } + } + return ret; +} + +std::string Base64Decode(const std::string& basicString) +{ + std::string ret; + uint32_t i = 0; + int index = 0; + int len = static_cast(basicString.size()); + unsigned char charArray3[3]; + unsigned char charArray4[4]; + + while (len-- && (basicString[index] != '=') && IsBase64(basicString[index])) { + charArray4[i++] = basicString[index]; + index++; + if (i == sizeof(charArray4)) { + for (i = 0; i < sizeof(charArray4); i++) { + charArray4[i] = BASE_64_CHARS.find(charArray4[i]); + } + charArray3[INDEX_FIRST] = (charArray4[INDEX_FIRST] << OFFSET2) + + ((charArray4[INDEX_SECOND] & 0x30) >> OFFSET4); + charArray3[INDEX_SECOND] = ((charArray4[INDEX_SECOND] & 0xf) << OFFSET4) + + ((charArray4[INDEX_THIRD] & 0x3c) >> OFFSET2); + charArray3[INDEX_THIRD] = ((charArray4[INDEX_THIRD] & 0x3) << OFFSET6) + charArray4[INDEX_FORTH]; + for (i = 0; i < sizeof(charArray3); i++) { + ret += charArray3[i]; + } + i = 0; + } + } + + if (i) { + uint32_t j = 0; + for (j = i; j < sizeof(charArray4); j++) { + charArray4[j] = 0; + } + for (j = 0; j < sizeof(charArray4); j++) { + charArray4[j] = BASE_64_CHARS.find(charArray4[j]); + } + charArray3[INDEX_FIRST] = (charArray4[INDEX_FIRST] << OFFSET2) + + ((charArray4[INDEX_SECOND] & 0x30) >> OFFSET4); + charArray3[INDEX_SECOND] = ((charArray4[INDEX_SECOND] & 0xf) << OFFSET4) + + ((charArray4[INDEX_THIRD] & 0x3c) >> OFFSET2); + charArray3[INDEX_THIRD] = ((charArray4[INDEX_THIRD] & 0x3) << OFFSET6) + charArray4[INDEX_FORTH]; + for (j = 0; j < i - 1; j++) { + ret += charArray3[j]; + } + } + return ret; +} + +bool IsBase64(unsigned char c) +{ + return (isalnum(c) || (c == '+') || (c == '/')); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/camera_hdf/interfaces/hdi_ipc/client/BUILD.gn b/camera_hdf/interfaces/hdi_ipc/client/BUILD.gn index a4a22d64..51957d0d 100644 --- a/camera_hdf/interfaces/hdi_ipc/client/BUILD.gn +++ b/camera_hdf/interfaces/hdi_ipc/client/BUILD.gn @@ -64,11 +64,11 @@ ohos_shared_library("distributed_camera_hdf_client") { ] deps = [ + "${distributedcamera_hdf_path}/hdi_impl:distributed_camera_hdf", "${hdf_uhdf_path}/hdi:libhdi", "//drivers/peripheral/camera/interfaces/metadata:metadata", "//drivers/peripheral/display/hal:hdi_display_gralloc", "//foundation/graphic/graphic/frameworks/surface:surface", - "${distributedcamera_hdf_path}/hdi_impl:distributed_camera_hdf", "//utils/native/base:utils", ] -- Gitee From bcd5b69b015de8326bcb5fc11ee2449c812ae626 Mon Sep 17 00:00:00 2001 From: wangchaole Date: Mon, 23 May 2022 18:59:42 +0800 Subject: [PATCH 4/5] =?UTF-8?q?dhf=E4=B8=8Esa=E8=A7=A3=E8=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- camera_hdf/hdi_impl/include/utils/dcamera.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/camera_hdf/hdi_impl/include/utils/dcamera.h b/camera_hdf/hdi_impl/include/utils/dcamera.h index 40ce77aa..af8b610e 100644 --- a/camera_hdf/hdi_impl/include/utils/dcamera.h +++ b/camera_hdf/hdi_impl/include/utils/dcamera.h @@ -24,6 +24,7 @@ namespace DistributedHardware { using namespace OHOS::Camera; using RetCode = uint32_t; using MetaType = int32_t; +const std::string BASE_64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; CamRetCode MapToExternalRetCode(DCamRetCode retCode); @@ -32,6 +33,12 @@ DCamRetCode MapToInternalRetCode(CamRetCode retCode); uint64_t GetCurrentLocalTimeStamp(); void SplitString(const std::string &str, std::vector &tokens, const std::string &delimiters); + +std::string Base64Encode(const unsigned char *toEncode, unsigned int len); + +std::string Base64Decode(const std::string& basicString); + +bool IsBase64(unsigned char c); } // namespace DistributedHardware } // namespace OHOS #endif // DISTRIBUTED_CAMERA_H -- Gitee From e93be6ef87f35ebf0d2d9c744f9eaceaab2daba3 Mon Sep 17 00:00:00 2001 From: wangchaole Date: Tue, 31 May 2022 09:13:31 +0800 Subject: [PATCH 5/5] =?UTF-8?q?hdf=E5=92=8Csa=E8=A7=A3=E8=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangchaole --- camera_hdf/hdi_impl/include/utils/anonymous_string.h | 6 +++--- camera_hdf/hdi_impl/include/utils/dh_log.h | 6 +++--- .../hdi_impl/include/utils/distributed_hardware_log.h | 6 +++--- .../hdi_impl/src/dcamera_device/dmetadata_processor.cpp | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/camera_hdf/hdi_impl/include/utils/anonymous_string.h b/camera_hdf/hdi_impl/include/utils/anonymous_string.h index 20d0ba55..8cbfaaaa 100644 --- a/camera_hdf/hdi_impl/include/utils/anonymous_string.h +++ b/camera_hdf/hdi_impl/include/utils/anonymous_string.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_DISTRIBUTED_HARDWARE_ANONYMOUS_STRING_H -#define OHOS_DISTRIBUTED_HARDWARE_ANONYMOUS_STRING_H +#ifndef OHOS_DISTRIBUTED_CAMERA_ANONYMOUS_STRING_H +#define OHOS_DISTRIBUTED_CAMERA_ANONYMOUS_STRING_H #include @@ -24,4 +24,4 @@ std::string GetAnonyString(const std::string &value); std::string GetAnonyInt32(const int32_t value); } // namespace DistributedHardware } // namespace OHOS -#endif +#endif // OHOS_DISTRIBUTED_CAMERA_ANONYMOUS_STRING_H diff --git a/camera_hdf/hdi_impl/include/utils/dh_log.h b/camera_hdf/hdi_impl/include/utils/dh_log.h index be8b441a..6a8e3801 100644 --- a/camera_hdf/hdi_impl/include/utils/dh_log.h +++ b/camera_hdf/hdi_impl/include/utils/dh_log.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_DH_LOG_H -#define OHOS_DH_LOG_H +#ifndef OHOS_DCAMERA_LOG_H +#define OHOS_DCAMERA_LOG_H namespace OHOS { namespace DistributedHardware { @@ -40,4 +40,4 @@ void DHLog(DHLogLevel logLevel, const char *fmt, ...); (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) } // namespace DistributedHardware } // namespace OHOS -#endif +#endif // OHOS_DCAMERA_LOG_H diff --git a/camera_hdf/hdi_impl/include/utils/distributed_hardware_log.h b/camera_hdf/hdi_impl/include/utils/distributed_hardware_log.h index 971d046c..d7e1c1ee 100644 --- a/camera_hdf/hdi_impl/include/utils/distributed_hardware_log.h +++ b/camera_hdf/hdi_impl/include/utils/distributed_hardware_log.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_DISTRIBUTED_HARDWARE_LOG_H -#define OHOS_DISTRIBUTED_HARDWARE_LOG_H +#ifndef OHOS_DISTRIBUTED_CAMERA_LOG_H +#define OHOS_DISTRIBUTED_CAMERA_LOG_H #include @@ -35,4 +35,4 @@ namespace DistributedHardware { (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) } // namespace DistributedHardware } // namespace OHOS -#endif +#endif // OHOS_DISTRIBUTED_CAMERA_LOG_H diff --git a/camera_hdf/hdi_impl/src/dcamera_device/dmetadata_processor.cpp b/camera_hdf/hdi_impl/src/dcamera_device/dmetadata_processor.cpp index bd7f880e..82fbd581 100644 --- a/camera_hdf/hdi_impl/src/dcamera_device/dmetadata_processor.cpp +++ b/camera_hdf/hdi_impl/src/dcamera_device/dmetadata_processor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 -- Gitee