From 69e8933c814d8900261ef877d59b81e7114cf840 Mon Sep 17 00:00:00 2001 From: byndyx Date: Tue, 21 Nov 2023 09:44:42 +0800 Subject: [PATCH] add dump Signed-off-by: byndyx --- common/BUILD.gn | 3 + .../constants/distributed_camera_constants.h | 8 ++ common/include/utils/dcamera_hidumper.h | 45 ++++++++++ common/include/utils/dcamera_utils_tools.h | 3 + common/src/utils/dcamera_hidumper.cpp | 44 +++++++++ common/src/utils/dcamera_utils_tools.cpp | 42 +++++++++ common/test/unittest/common/utils/BUILD.gn | 3 + .../common/utils/dcamera_hidumper_test.cpp | 89 +++++++++++++++++++ .../common/utils/dcamera_utils_tools_test.cpp | 20 +++++ .../cameraoperator/client/BUILD.gn | 6 ++ .../listener/dcamera_photo_surface_listener.h | 1 + .../dcamera_photo_surface_listener.cpp | 11 ++- services/cameraservice/sinkservice/BUILD.gn | 4 + .../distributedcamera/dcamera_sink_hidumper.h | 2 + .../dcamera_sink_hidumper.cpp | 37 ++++++-- .../dcamera_sink_data_process.cpp | 7 ++ services/cameraservice/sourceservice/BUILD.gn | 4 + .../dcamera_source_hidumper.h | 2 + .../dcamera_stream_data_process_producer.h | 1 + .../dcamera_source_hidumper.cpp | 37 ++++++-- .../dcamera_stream_data_process_producer.cpp | 15 ++++ services/data_process/BUILD.gn | 6 ++ .../decoder/decode_data_process.h | 1 + .../decoder/decode_data_process.cpp | 24 ++++- .../decoder/decode_data_process_common.cpp | 24 ++++- 25 files changed, 417 insertions(+), 22 deletions(-) create mode 100644 common/include/utils/dcamera_hidumper.h create mode 100644 common/src/utils/dcamera_hidumper.cpp create mode 100644 common/test/unittest/common/utils/dcamera_hidumper_test.cpp diff --git a/common/BUILD.gn b/common/BUILD.gn index b29befe9..99b92991 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -47,6 +47,7 @@ ohos_shared_library("distributed_camera_utils") { "src/utils/anonymous_string.cpp", "src/utils/data_buffer.cpp", "src/utils/dcamera_buffer_handle.cpp", + "src/utils/dcamera_hidumper.cpp", "src/utils/dcamera_hisysevent_adapter.cpp", "src/utils/dcamera_hitrace_adapter.cpp", "src/utils/dcamera_utils_tools.cpp", @@ -66,6 +67,8 @@ ohos_shared_library("distributed_camera_utils") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", ] cflags_cc = cflags diff --git a/common/include/constants/distributed_camera_constants.h b/common/include/constants/distributed_camera_constants.h index d6ae70c9..294421a6 100644 --- a/common/include/constants/distributed_camera_constants.h +++ b/common/include/constants/distributed_camera_constants.h @@ -115,11 +115,13 @@ const int32_t RESOLUTION_MAX_WIDTH_CONTINUOUS = 1920; const int32_t RESOLUTION_MAX_HEIGHT_CONTINUOUS = 1080; const int32_t RESOLUTION_MIN_WIDTH = 320; const int32_t RESOLUTION_MIN_HEIGHT = 240; +const int32_t DUMP_FILE_MAX_SIZE = 295 * 1024 *1024; const uint32_t DCAMERA_SHIFT_32 = 32; const uint32_t DCAMERA_SHIFT_24 = 24; const uint32_t DCAMERA_SHIFT_16 = 16; const uint32_t DCAMERA_SHIFT_8 = 8; +const uint32_t COUNT_INIT_NUM = 1; const uint32_t UINT32_SHIFT_MASK_24 = 0xff000000; const uint32_t UINT32_SHIFT_MASK_16 = 0x00ff0000; @@ -134,6 +136,12 @@ const std::string SINK_START_EVENT = "sinkStartEvent"; const std::string SOURCE_START_EVENT = "srcStartEvent"; const std::string UNREGISTER_SERVICE_NOTIFY = "unregSvcNotify"; const std::string LOOPER_SMOOTH = "looperSmooth"; +const std::string DUMP_PATH = "/data/data/dcamera/"; +const std::string DUMP_PHOTO_PATH = "/data/data/dcamera/photodump/"; +const std::string TO_DISPLAY = "AfterDecodeToDisplay.yuv"; +const std::string SINK_PHOTO = "_SinkPhoto.jpg"; +const std::string AFTER_ENCODE = "SinkAfterEncode.h265"; +const std::string BEFORE_DECODE = "SourceBeforeDecode.h265"; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DISTRIBUTED_CAMERA_CONSTANTS_H \ No newline at end of file diff --git a/common/include/utils/dcamera_hidumper.h b/common/include/utils/dcamera_hidumper.h new file mode 100644 index 00000000..164aedd8 --- /dev/null +++ b/common/include/utils/dcamera_hidumper.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021-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 OHOS_DCAMERA_HIDUMPER_H +#define OHOS_DCAMERA_HIDUMPER_H + +#include +#include +#include + +#include "single_instance.h" + +namespace OHOS { +namespace DistributedHardware { + +class DcameraHidumper { +DECLARE_SINGLE_INSTANCE_BASE(DcameraHidumper); + +public: + int32_t StartDump(); + int32_t StopDump(); + bool GetDumpFlag(); + +private: + explicit DcameraHidumper() = default; + ~DcameraHidumper() = default; + +private: + bool dumpFlag_ = false; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DCAMERA_HIDUMPER_H \ No newline at end of file diff --git a/common/include/utils/dcamera_utils_tools.h b/common/include/utils/dcamera_utils_tools.h index 986ac658..bd97dbf0 100644 --- a/common/include/utils/dcamera_utils_tools.h +++ b/common/include/utils/dcamera_utils_tools.h @@ -18,6 +18,7 @@ #include #include +#include namespace OHOS { namespace DistributedHardware { @@ -29,7 +30,9 @@ int64_t GetNowTimeStampUs(); int32_t GetAlignedHeight(int32_t width); std::string Base64Encode(const unsigned char *toEncode, unsigned int len); std::string Base64Decode(const std::string& basicString); +void DumpBufferToFile(std::string fileName, uint8_t *buffer, size_t bufSize); bool IsBase64(unsigned char c); +int32_t IsUnderDumpMaxSize(std::string fileName); } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DCAMERA_UTILS_TOOL_H diff --git a/common/src/utils/dcamera_hidumper.cpp b/common/src/utils/dcamera_hidumper.cpp new file mode 100644 index 00000000..b898b494 --- /dev/null +++ b/common/src/utils/dcamera_hidumper.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2021-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 "dcamera_hidumper.h" + +#include "distributed_camera_errno.h" +#include "distributed_hardware_log.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(DcameraHidumper); + +int32_t DcameraHidumper::StartDump() +{ + DHLOGI("hidumper set dumpflag"); + dumpFlag_ = true; + return DCAMERA_OK; +} + +int32_t DcameraHidumper::StopDump() +{ + DHLOGI("hidumper reset dumpflag"); + dumpFlag_ = false; + return DCAMERA_OK; +} + +bool DcameraHidumper::GetDumpFlag() +{ + return dumpFlag_; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/common/src/utils/dcamera_utils_tools.cpp b/common/src/utils/dcamera_utils_tools.cpp index 65cc9405..cc90d44a 100644 --- a/common/src/utils/dcamera_utils_tools.cpp +++ b/common/src/utils/dcamera_utils_tools.cpp @@ -181,5 +181,47 @@ bool IsBase64(unsigned char c) { return (isalnum(c) || (c == '+') || (c == '/')); } + +void DumpBufferToFile(std::string fileName, uint8_t *buffer, size_t bufSize) +{ + if (fileName.empty() || buffer == nullptr) { + DHLOGE("dumpsaving : input param err."); + return; + } + std::ofstream ofs(fileName, std::ios::binary | std::ios::out | std::ios::app); + if (!ofs.is_open()) { + DHLOGE("dumpsaving : open file failed."); + return; + } + ofs.write(reinterpret_cast(buffer), bufSize); + ofs.close(); + return; +} + +int32_t IsUnderDumpMaxSize(std::string fileName) +{ + if (fileName.empty()) { + DHLOGE("dumpsaving : input fileName empty."); + return DCAMERA_INIT_ERR; + } + std::ofstream ofs(fileName, std::ios::binary | std::ios::out | std::ios::app); + if (!ofs.is_open()) { + DHLOGE("dumpsaving : open file failed."); + return DCAMERA_INIT_ERR; + } + ofs.seekp(0, std::ios::end); + std::ofstream::pos_type fileSize = ofs.tellp(); + if (fileSize < 0) { + DHLOGE("filesize get err"); + fileSize = 0; + return DCAMERA_INIT_ERR; + } + ofs.close(); + if (static_cast(fileSize) <= DUMP_FILE_MAX_SIZE) { + return DCAMERA_OK; + } else { + return DCAMERA_BAD_VALUE; + } +} } // namespace DistributedHardware } // namespace OHOS diff --git a/common/test/unittest/common/utils/BUILD.gn b/common/test/unittest/common/utils/BUILD.gn index 9a1e7ef9..78bd715e 100644 --- a/common/test/unittest/common/utils/BUILD.gn +++ b/common/test/unittest/common/utils/BUILD.gn @@ -35,6 +35,7 @@ ohos_unittest("CommonUtilsTest") { sources = [ "data_buffer_test.cpp", "dcamera_buffer_handle_test.cpp", + "dcamera_hidumper_test.cpp", "dcamera_hisysevent_adapter_test.cpp", "dcamera_utils_tools_test.cpp", ] @@ -55,6 +56,8 @@ ohos_unittest("CommonUtilsTest") { "c_utils:utils", "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.0", "hdf_core:libhdi", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", ] defines = [ diff --git a/common/test/unittest/common/utils/dcamera_hidumper_test.cpp b/common/test/unittest/common/utils/dcamera_hidumper_test.cpp new file mode 100644 index 00000000..ed4f699f --- /dev/null +++ b/common/test/unittest/common/utils/dcamera_hidumper_test.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "dcamera_hidumper.h" +#include "distributed_camera_errno.h" +#include "distributed_hardware_log.h" + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +class DcameraHidumperTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void DcameraHidumperTest::SetUpTestCase(void) +{ + DHLOGI("enter"); +} + +void DcameraHidumperTest::TearDownTestCase(void) +{ + DHLOGI("enter"); +} + +void DcameraHidumperTest::SetUp(void) +{ + DHLOGI("enter"); +} + +void DcameraHidumperTest::TearDown(void) +{ + DHLOGI("enter"); +} + +/** + * @tc.name: GetDumpFlag_001 + * @tc.desc: Verify the GetDumpFlag function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DcameraHidumperTest, GetDumpFlag_001, TestSize.Level1) +{ + EXPECT_EQ(false, DcameraHidumper::GetInstance().GetDumpFlag()); +} + +/** + * @tc.name: SetDumpFlag_001 + * @tc.desc: Verify the StartDump function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DcameraHidumperTest, SetDumpFlag_001, TestSize.Level1) +{ + EXPECT_EQ(DCAMERA_OK, DcameraHidumper::GetInstance().StartDump()); + EXPECT_EQ(true, DcameraHidumper::GetInstance().GetDumpFlag()); +} + +/** + * @tc.name: ResetDumpFlag_001 + * @tc.desc: Verify the StopDump function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DcameraHidumperTest, ResetDumpFlag_001, TestSize.Level1) +{ + EXPECT_EQ(DCAMERA_OK, DcameraHidumper::GetInstance().StopDump()); + EXPECT_EQ(false, DcameraHidumper::GetInstance().GetDumpFlag()); +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/common/test/unittest/common/utils/dcamera_utils_tools_test.cpp b/common/test/unittest/common/utils/dcamera_utils_tools_test.cpp index 93a77a74..22418635 100644 --- a/common/test/unittest/common/utils/dcamera_utils_tools_test.cpp +++ b/common/test/unittest/common/utils/dcamera_utils_tools_test.cpp @@ -15,6 +15,8 @@ #include +#include + #include "accesstoken_kit.h" #include "anonymous_string.h" #include "dcamera_utils_tools.h" @@ -177,5 +179,23 @@ HWTEST_F(DcameraUtilsToolsTest, GetAnonyInt32_001, TestSize.Level1) EXPECT_EQ(DCAMERA_OK, ret); } +/** + * @tc.name: IsOverDumpSize_001 + * @tc.desc: Verify the IsUnderDumpMaxSize function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DcameraUtilsToolsTest, IsOverDumpSize_001, TestSize.Level1) +{ + std::string fileName = ""; + uint8_t *buf = nullptr; + size_t size = 0; + DumpBufferToFile(fileName, buf, size); + EXPECT_EQ(DCAMERA_INIT_ERR, IsUnderDumpMaxSize(fileName)); + fileName = "test"; + uint8_t str[] = "test"; + size = strlen(reinterpret_cast(str)); + DumpBufferToFile(fileName, str, size); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/cameraoperator/client/BUILD.gn b/services/cameraservice/cameraoperator/client/BUILD.gn index 0a19ff0d..a0a6641f 100644 --- a/services/cameraservice/cameraoperator/client/BUILD.gn +++ b/services/cameraservice/cameraoperator/client/BUILD.gn @@ -73,6 +73,10 @@ ohos_shared_library("distributed_camera_client") { "LOG_DOMAIN=0xD004100", ] + if (build_variant == "root") { + defines += [ "DUMP_DCAMERA_FILE" ] + } + external_deps = [ "c_utils:utils", "camera_framework:camera_framework", @@ -82,6 +86,8 @@ ohos_shared_library("distributed_camera_client") { "drivers_peripheral_display:hdi_gralloc_client", "graphic_2d:surface", "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", ] subsystem_name = "distributedhardware" diff --git a/services/cameraservice/cameraoperator/client/include/listener/dcamera_photo_surface_listener.h b/services/cameraservice/cameraoperator/client/include/listener/dcamera_photo_surface_listener.h index a6e7f22b..341dfe07 100644 --- a/services/cameraservice/cameraoperator/client/include/listener/dcamera_photo_surface_listener.h +++ b/services/cameraservice/cameraoperator/client/include/listener/dcamera_photo_surface_listener.h @@ -32,6 +32,7 @@ private: sptr surface_; std::shared_ptr callback_; const int32_t SURFACE_BUFFER_MAX_SIZE = 50 * 1024 * 1024; + uint32_t photoCount_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/cameraoperator/client/src/listener/dcamera_photo_surface_listener.cpp b/services/cameraservice/cameraoperator/client/src/listener/dcamera_photo_surface_listener.cpp index ea9ca250..9bb4b217 100644 --- a/services/cameraservice/cameraoperator/client/src/listener/dcamera_photo_surface_listener.cpp +++ b/services/cameraservice/cameraoperator/client/src/listener/dcamera_photo_surface_listener.cpp @@ -18,6 +18,8 @@ #include #include "data_buffer.h" +#include "dcamera_hidumper.h" +#include "dcamera_utils_tools.h" #include "distributed_camera_errno.h" #include "distributed_hardware_log.h" @@ -26,6 +28,7 @@ namespace DistributedHardware { DCameraPhotoSurfaceListener::DCameraPhotoSurfaceListener(const sptr& surface, const std::shared_ptr& callback) : surface_(surface), callback_(callback) { + photoCount_ = COUNT_INIT_NUM; } void DCameraPhotoSurfaceListener::OnBufferAvailable() @@ -57,7 +60,6 @@ void DCameraPhotoSurfaceListener::OnBufferAvailable() DHLOGE("DCameraPhotoSurfaceListener invalid params, size: %d", size); break; } - DHLOGI("DCameraPhotoSurfaceListener size: %d", size); std::shared_ptr dataBuffer = std::make_shared(size); int32_t ret = memcpy_s(dataBuffer->Data(), dataBuffer->Capacity(), address, size); @@ -65,7 +67,12 @@ void DCameraPhotoSurfaceListener::OnBufferAvailable() DHLOGE("DCameraPhotoSurfaceListener Memory Copy failed, ret: %d", ret); break; } - +#ifdef DUMP_DCAMERA_FILE + std::string fileName = DUMP_PHOTO_PATH + std::to_string(photoCount_++) + SINK_PHOTO; + if (DcameraHidumper::GetInstance().GetDumpFlag() && (IsUnderDumpMaxSize(fileName) == DCAMERA_OK)) { + DumpBufferToFile(fileName, dataBuffer->Data(), dataBuffer->Size()); + } +#endif callback_->OnPhotoResult(dataBuffer); } while (0); surface_->ReleaseBuffer(buffer, -1); diff --git a/services/cameraservice/sinkservice/BUILD.gn b/services/cameraservice/sinkservice/BUILD.gn index 70885687..e156c6dd 100644 --- a/services/cameraservice/sinkservice/BUILD.gn +++ b/services/cameraservice/sinkservice/BUILD.gn @@ -117,6 +117,10 @@ ohos_shared_library("distributed_camera_sink") { "LOG_DOMAIN=0xD004100", ] + if (build_variant == "root") { + defines += [ "DUMP_DCAMERA_FILE" ] + } + external_deps = [ "c_utils:utils", "camera_framework:camera_framework", diff --git a/services/cameraservice/sinkservice/include/distributedcamera/dcamera_sink_hidumper.h b/services/cameraservice/sinkservice/include/distributedcamera/dcamera_sink_hidumper.h index 4cd40fa1..a2ede462 100644 --- a/services/cameraservice/sinkservice/include/distributedcamera/dcamera_sink_hidumper.h +++ b/services/cameraservice/sinkservice/include/distributedcamera/dcamera_sink_hidumper.h @@ -31,6 +31,8 @@ enum class HidumpFlag { GET_CAMERA_INFO, GET_OPENED_INFO, GET_VERSION_INFO, + START_DUMP, + STOP_DUMP, }; struct CameraDumpInfo { diff --git a/services/cameraservice/sinkservice/src/distributedcamera/dcamera_sink_hidumper.cpp b/services/cameraservice/sinkservice/src/distributedcamera/dcamera_sink_hidumper.cpp index 4ab38912..a6ffe27c 100644 --- a/services/cameraservice/sinkservice/src/distributedcamera/dcamera_sink_hidumper.cpp +++ b/services/cameraservice/sinkservice/src/distributedcamera/dcamera_sink_hidumper.cpp @@ -15,6 +15,7 @@ #include "dcamera_sink_hidumper.h" +#include "dcamera_hidumper.h" #include "distributed_camera_errno.h" #include "distributed_camera_sink_service.h" #include "distributed_hardware_log.h" @@ -27,6 +28,8 @@ namespace { const std::string ARGS_HELP = "-h"; const std::string ARGS_VERSION_INFO = "--version"; const std::string ARGS_CAMERA_INFO = "--camNum"; +const std::string ARGS_START_DUMP = "--startdump"; +const std::string ARGS_STOP_DUMP = "--stopdump"; const std::string ARGS_OPENED_INFO = "--opened"; const std::map ARGS_MAP = { @@ -34,6 +37,8 @@ const std::map ARGS_MAP = { { ARGS_CAMERA_INFO, HidumpFlag::GET_CAMERA_INFO }, { ARGS_OPENED_INFO, HidumpFlag::GET_OPENED_INFO }, { ARGS_VERSION_INFO, HidumpFlag::GET_VERSION_INFO }, + { ARGS_START_DUMP, HidumpFlag::START_DUMP }, + { ARGS_STOP_DUMP, HidumpFlag::STOP_DUMP }, }; } @@ -95,6 +100,16 @@ int32_t DcameraSinkHidumper::ProcessDump(const std::string& args, std::string& r ret = GetVersionInfo(result); break; } + case HidumpFlag::START_DUMP: { + ret = DcameraHidumper::GetInstance().StartDump(); + result.append("Send dump order ok\n"); + break; + } + case HidumpFlag::STOP_DUMP: { + ret = DcameraHidumper::GetInstance().StopDump(); + result.append("Send stop dump order ok\n"); + break; + } default: { ret = ShowIllegalInfomation(result); break; @@ -136,15 +151,19 @@ void DcameraSinkHidumper::ShowHelp(std::string& result) { DHLOGI("ShowHelp Dump."); result.append("Usage:dump [options]\n") - .append("Description:\n") - .append("-h ") - .append(": show help\n") - .append("--version ") - .append(": dump camera version in the system\n") - .append("--camNum ") - .append(": dump local camera numbers in the system\n") - .append("--opened ") - .append(": dump the opened camera in the system\n"); + .append("Description:\n") + .append("-h ") + .append(": show help\n") + .append("--version ") + .append(": dump camera version in the system\n") + .append("--camNum ") + .append(": dump local camera numbers in the system\n") + .append("--opened ") + .append(": dump the opened camera in the system\n") + .append("--startdump ") + .append(": dump camera data in /data/data/dcamera\n") + .append("--stopdump ") + .append(": stop dump camera data\n"); } int32_t DcameraSinkHidumper::ShowIllegalInfomation(std::string& result) diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process.cpp index 6a0f5b9e..d121e813 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_data_process.cpp @@ -19,6 +19,8 @@ #include "dcamera_channel_sink_impl.h" #include "dcamera_pipeline_sink.h" #include "dcamera_sink_data_process_listener.h" +#include "dcamera_hidumper.h" +#include "dcamera_utils_tools.h" #include "distributed_camera_constants.h" #include "distributed_camera_errno.h" #include "distributed_hardware_log.h" @@ -155,6 +157,11 @@ void DCameraSinkDataProcess::SendDataAsync(const std::shared_ptr& bu void DCameraSinkDataProcess::OnProcessedVideoBuffer(const std::shared_ptr& videoResult) { +#ifdef DUMP_DCAMERA_FILE + if (DcameraHidumper::GetInstance().GetDumpFlag() && (IsUnderDumpMaxSize(DUMP_PATH + AFTER_ENCODE) == DCAMERA_OK)) { + DumpBufferToFile(DUMP_PATH + AFTER_ENCODE, videoResult->Data(), videoResult->Size()); + } +#endif SendDataAsync(videoResult); } diff --git a/services/cameraservice/sourceservice/BUILD.gn b/services/cameraservice/sourceservice/BUILD.gn index 6f0c82e5..c5ac04fe 100644 --- a/services/cameraservice/sourceservice/BUILD.gn +++ b/services/cameraservice/sourceservice/BUILD.gn @@ -117,6 +117,10 @@ ohos_shared_library("distributed_camera_source") { "LOG_DOMAIN=0xD004100", ] + if (build_variant == "root") { + defines += [ "DUMP_DCAMERA_FILE" ] + } + external_deps = [ "c_utils:utils", "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.0", diff --git a/services/cameraservice/sourceservice/include/distributedcamera/dcamera_source_hidumper.h b/services/cameraservice/sourceservice/include/distributedcamera/dcamera_source_hidumper.h index 85b2c17a..033a7810 100644 --- a/services/cameraservice/sourceservice/include/distributedcamera/dcamera_source_hidumper.h +++ b/services/cameraservice/sourceservice/include/distributedcamera/dcamera_source_hidumper.h @@ -31,6 +31,8 @@ enum class HidumpFlag { GET_REGISTERED_INFO, GET_CURRENTSTATE_INFO, GET_VERSION_INFO, + START_DUMP, + STOP_DUMP, }; typedef enum { diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.h index f133fcfd..d485dfe9 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.h @@ -67,6 +67,7 @@ private: std::deque> buffers_; DCameraProducerState state_; uint32_t interval_; + uint32_t photoCount_; int32_t streamId_; DCStreamType streamType_; std::shared_ptr eventHandler_; diff --git a/services/cameraservice/sourceservice/src/distributedcamera/dcamera_source_hidumper.cpp b/services/cameraservice/sourceservice/src/distributedcamera/dcamera_source_hidumper.cpp index cb65059e..e5878a86 100644 --- a/services/cameraservice/sourceservice/src/distributedcamera/dcamera_source_hidumper.cpp +++ b/services/cameraservice/sourceservice/src/distributedcamera/dcamera_source_hidumper.cpp @@ -15,6 +15,7 @@ #include "dcamera_source_hidumper.h" +#include "dcamera_hidumper.h" #include "distributed_camera_errno.h" #include "distributed_camera_source_service.h" #include "distributed_hardware_log.h" @@ -28,6 +29,8 @@ const std::string ARGS_HELP = "-h"; const std::string ARGS_VERSION_INFO = "--version"; const std::string ARGS_REGISTERED_INFO = "--registered"; const std::string ARGS_CURRENTSTATE_INFO = "--curState"; +const std::string ARGS_START_DUMP = "--startdump"; +const std::string ARGS_STOP_DUMP = "--stopdump"; const std::string STATE_INT = "Init"; const std::string STATE_REGISTERED = "Registered"; const std::string STATE_OPENED = "Opened"; @@ -39,6 +42,8 @@ const std::map ARGS_MAP = { { ARGS_REGISTERED_INFO, HidumpFlag::GET_REGISTERED_INFO }, { ARGS_CURRENTSTATE_INFO, HidumpFlag::GET_CURRENTSTATE_INFO }, { ARGS_VERSION_INFO, HidumpFlag::GET_VERSION_INFO }, + { ARGS_START_DUMP, HidumpFlag::START_DUMP }, + { ARGS_STOP_DUMP, HidumpFlag::STOP_DUMP }, }; const std::map STATE_MAP = { @@ -108,6 +113,16 @@ int32_t DcameraSourceHidumper::ProcessDump(const std::string& args, std::string& ret = GetVersionInfo(result); break; } + case HidumpFlag::START_DUMP: { + ret = DcameraHidumper::GetInstance().StartDump(); + result.append("Send dump order ok\n"); + break; + } + case HidumpFlag::STOP_DUMP: { + ret = DcameraHidumper::GetInstance().StopDump(); + result.append("Send stop dump order ok\n"); + break; + } default: { ret = ShowIllegalInfomation(result); break; @@ -161,15 +176,19 @@ void DcameraSourceHidumper::ShowHelp(std::string& result) { DHLOGI("ShowHelp Dump."); result.append("Usage:dump [options]\n") - .append("Description:\n") - .append("-h ") - .append(": show help\n") - .append("--version ") - .append(": dump camera version in the system\n") - .append("--registered ") - .append(": dump number of registered cameras in the system\n") - .append("--curState ") - .append(": dump current state of the camera in the system\n"); + .append("Description:\n") + .append("-h ") + .append(": show help\n") + .append("--version ") + .append(": dump camera version in the system\n") + .append("--registered ") + .append(": dump number of registered cameras in the system\n") + .append("--curState ") + .append(": dump current state of the camera in the system\n") + .append("--startdump ") + .append(": dump camera data in /data/data/dcamera\n") + .append("--stopdump ") + .append(": stop dump camera data\n"); } int32_t DcameraSourceHidumper::ShowIllegalInfomation(std::string& result) diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp index e7a3c7c6..4f2ab1dc 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameradata/dcamera_stream_data_process_producer.cpp @@ -20,6 +20,7 @@ #include "anonymous_string.h" #include "dcamera_buffer_handle.h" +#include "dcamera_hidumper.h" #include "dcamera_utils_tools.h" #include "distributed_camera_constants.h" #include "distributed_camera_errno.h" @@ -38,6 +39,7 @@ DCameraStreamDataProcessProducer::DCameraStreamDataProcessProducer(std::string d GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, streamId_); state_ = DCAMERA_PRODUCER_STATE_STOP; interval_ = DCAMERA_PRODUCER_ONE_MINUTE_MS / DCAMERA_PRODUCER_FPS_DEFAULT; + photoCount_ = COUNT_INIT_NUM; } DCameraStreamDataProcessProducer::~DCameraStreamDataProcessProducer() @@ -166,6 +168,13 @@ void DCameraStreamDataProcessProducer::LooperSnapShot() GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, streamId_, state_); continue; } +#ifdef DUMP_DCAMERA_FILE + std::string fileName = DUMP_PHOTO_PATH + + "SourceCapture_streamId(" + std::to_string(streamId_) + ")_" + std::to_string(photoCount_++) + ".jpg"; + if (DcameraHidumper::GetInstance().GetDumpFlag() && (IsUnderDumpMaxSize(fileName) == DCAMERA_OK)) { + DumpBufferToFile(fileName, buffer->Data(), buffer->Size()); + } +#endif int32_t ret = FeedStreamToDriver(dhBase, buffer); if (ret != DCAMERA_OK) { std::this_thread::sleep_for(std::chrono::milliseconds(DCAMERA_PRODUCER_RETRY_SLEEP_MS)); @@ -260,6 +269,12 @@ void DCameraStreamDataProcessProducer::OnSmoothFinished(const std::shared_ptrData(), buffer->Size()); + } +#endif auto feedFunc = [this, dhBase, buffer]() { FeedStreamToDriver(dhBase, buffer); }; diff --git a/services/data_process/BUILD.gn b/services/data_process/BUILD.gn index e30527c6..3cbe5adb 100644 --- a/services/data_process/BUILD.gn +++ b/services/data_process/BUILD.gn @@ -97,6 +97,10 @@ ohos_shared_library("distributed_camera_data_process") { "LOG_DOMAIN=0xD004100", ] + if (build_variant == "root") { + defines += [ "DUMP_DCAMERA_FILE" ] + } + external_deps = [ "av_codec:av_codec_client", "c_utils:utils", @@ -104,6 +108,8 @@ ohos_shared_library("distributed_camera_data_process") { "eventhandler:libeventhandler", "graphic_2d:surface", "hitrace:hitrace_meter", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", ] if (!distributed_camera_common) { diff --git a/services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_data_process.h b/services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_data_process.h index b2cfb62b..71c638d4 100644 --- a/services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_data_process.h +++ b/services/data_process/include/pipeline_node/multimedia_codec/decoder/decode_data_process.h @@ -90,6 +90,7 @@ private: void ReleaseVideoDecoder(); void ReleaseDecoderSurface(); void ReleaseCodecEvent(); + void BeforeDecodeDump(uint8_t *buffer, size_t bufSize); int32_t FeedDecoderInputBuffer(); int64_t GetDecoderTimeStamp(); void IncreaseWaitDecodeCnt(); diff --git a/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process.cpp b/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process.cpp index ad029d58..60edcbce 100644 --- a/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process.cpp +++ b/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process.cpp @@ -19,6 +19,7 @@ #include "distributed_camera_constants.h" #include "distributed_hardware_log.h" #include "dcamera_hisysevent_adapter.h" +#include "dcamera_hidumper.h" #include "dcamera_utils_tools.h" #include "decode_surface_listener.h" #include "decode_video_callback.h" @@ -405,6 +406,20 @@ int32_t DecodeDataProcess::ProcessData(std::vector>& return DCAMERA_OK; } +void DecodeDataProcess::BeforeDecodeDump(uint8_t *buffer, size_t bufSize) +{ +#ifdef DUMP_DCAMERA_FILE + if (buffer == nullptr) { + DHLOGE("dumpsaving : input param nullptr."); + return; + } + if (DcameraHidumper::GetInstance().GetDumpFlag() && (IsUnderDumpMaxSize(DUMP_PATH + BEFORE_DECODE) == DCAMERA_OK)) { + DumpBufferToFile(DUMP_PATH + BEFORE_DECODE, buffer, bufSize); + } +#endif + return; +} + int32_t DecodeDataProcess::FeedDecoderInputBuffer() { DHLOGD("Feed decoder input buffer."); @@ -433,6 +448,7 @@ int32_t DecodeDataProcess::FeedDecoderInputBuffer() DHLOGE("Failed to obtain the input shared memory corresponding to the [%u] index.", index); return DCAMERA_BAD_VALUE; } + BeforeDecodeDump(buffer->Data(), buffer->Size()); size_t inputMemoDataSize = static_cast(sharedMemoryInput->GetSize()); errno_t err = memcpy_s(sharedMemoryInput->GetBase(), inputMemoDataSize, buffer->Data(), buffer->Size()); if (err != EOK) { @@ -574,7 +590,13 @@ void DecodeDataProcess::CopyDecodedImage(const sptr& surBuf, int3 bufferOutput->SetInt32("alignedHeight", processedConfig_.GetHeight()); bufferOutput->SetInt32("width", processedConfig_.GetWidth()); bufferOutput->SetInt32("height", processedConfig_.GetHeight()); - +#ifdef DUMP_DCAMERA_FILE + std::string fileName = "SourceAfterDecode_width(" + std::to_string(processedConfig_.GetWidth()) + + ")height(" + std::to_string(processedConfig_.GetHeight()) + ").yuv"; + if (DcameraHidumper::GetInstance().GetDumpFlag() && (IsUnderDumpMaxSize(DUMP_PATH + fileName) == DCAMERA_OK)) { + DumpBufferToFile(DUMP_PATH + fileName, bufferOutput->Data(), bufferOutput->Size()); + } +#endif PostOutputDataBuffers(bufferOutput); } diff --git a/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process_common.cpp b/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process_common.cpp index c3d94ed4..f78cfbf7 100644 --- a/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process_common.cpp +++ b/services/data_process/src/pipeline_node/multimedia_codec/decoder/decode_data_process_common.cpp @@ -19,6 +19,7 @@ #include "graphic_common_c.h" #include "dcamera_hisysevent_adapter.h" +#include "dcamera_hidumper.h" #include "dcamera_utils_tools.h" #include "decode_surface_listener.h" #include "decode_video_callback.h" @@ -426,6 +427,20 @@ int32_t DecodeDataProcess::ProcessData(std::vector>& return DCAMERA_OK; } +void DecodeDataProcess::BeforeDecodeDump(uint8_t *buffer, size_t bufSize) +{ +#ifdef DUMP_DCAMERA_FILE + if (buffer == nullptr) { + DHLOGE("dumpsaving : input param nullptr."); + return; + } + if (DcameraHidumper::GetInstance().GetDumpFlag() && (IsUnderDumpMaxSize(DUMP_PATH + BEFORE_DECODE) == DCAMERA_OK)) { + DumpBufferToFile(DUMP_PATH + BEFORE_DECODE, buffer, bufSize); + } +#endif + return; +} + int32_t DecodeDataProcess::FeedDecoderInputBuffer() { DHLOGD("Feed decoder input buffer."); @@ -454,6 +469,7 @@ int32_t DecodeDataProcess::FeedDecoderInputBuffer() DHLOGE("Failed to obtain the input shared memory corresponding to the [%u] index.", index); return DCAMERA_BAD_VALUE; } + BeforeDecodeDump(buffer->Data(), buffer->Size()); size_t inputMemoDataSize = static_cast(sharedMemoryInput->GetSize()); errno_t err = memcpy_s(sharedMemoryInput->GetBase(), inputMemoDataSize, buffer->Data(), buffer->Size()); if (err != EOK) { @@ -578,7 +594,13 @@ void DecodeDataProcess::CopyDecodedImage(const sptr& surBuf, int3 bufferOutput->SetInt32("alignedHeight", processedConfig_.GetHeight()); bufferOutput->SetInt32("width", processedConfig_.GetWidth()); bufferOutput->SetInt32("height", processedConfig_.GetHeight()); - +#ifdef DUMP_DCAMERA_FILE + std::string fileName = "SourceAfterDecode_width(" + std::to_string(processedConfig_.GetWidth()) + + ")height(" + std::to_string(processedConfig_.GetHeight()) + ").yuv"; + if (DcameraHidumper::GetInstance().GetDumpFlag() && (IsUnderDumpMaxSize(DUMP_PATH + fileName) == DCAMERA_OK)) { + DumpBufferToFile(DUMP_PATH + fileName, bufferOutput->Data(), bufferOutput->Size()); + } +#endif PostOutputDataBuffers(bufferOutput); } -- Gitee