From 2d8f139e4ae23f9584c3396b92543d2a6e225bbe Mon Sep 17 00:00:00 2001 From: byndyx Date: Tue, 26 Sep 2023 22:46:37 +0800 Subject: [PATCH] add screen dump Signed-off-by: byndyx --- .../av_trans_input/dsoftbus_input/BUILD.gn | 6 + .../dsoftbus_input/dsoftbus_input_plugin.cpp | 8 ++ .../av_trans_output/dsoftbus_output/BUILD.gn | 6 + .../dsoftbus_output_plugin.cpp | 7 + common/utils/include/constants.h | 3 + .../include/hidumphelper/hidump_helper.h | 17 +++ .../src/hidumphelper/hidump_helper.cpp | 120 ++++++++++++++++++ 7 files changed, 167 insertions(+) diff --git a/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input/BUILD.gn b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input/BUILD.gn index 2a1663b2..e5c7c1f7 100644 --- a/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input/BUILD.gn +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input/BUILD.gn @@ -17,11 +17,17 @@ import( ohos_source_set("plugin_AVTransDsoftbusInput") { include_dirs = [ + "//foundation/distributedhardware/distributed_hardware_fwk/common/inculde"; + "//foundation/distributedhardware/distributed_hardware_fwk/common/utils/inculde"; + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/common/inculde"; "${common_path}/include", "${plugin_path}/interface", "//third_party/json/include", + "//foundation/distributedhardware/distributed_hardware_fwk/services/distributedhardwarefwkservice/inculde/hidumphelper"; ] + deps = [ "//foundation/distributedhardware/distributed_hardware_fwk/services/distributedhardwarefwkservice:distributedhardwarefwksvr" ] + sources = [ "dsoftbus_input_plugin.cpp" ] external_deps = [ diff --git a/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input/dsoftbus_input_plugin.cpp b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input/dsoftbus_input_plugin.cpp index 1555cf0c..642bd20e 100644 --- a/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input/dsoftbus_input_plugin.cpp +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_input/dsoftbus_input/dsoftbus_input_plugin.cpp @@ -15,6 +15,8 @@ #include "dsoftbus_input_plugin.h" +#include "constants.h" +#include "hidump_helper.h" #include "foundation/utils/constants.h" #include "plugin/common/share_memory.h" #include "plugin/common/plugin_caps_builder.h" @@ -246,6 +248,12 @@ void DsoftbusInputPlugin::OnStreamReceived(const StreamData *data, const StreamD if (buffer != nullptr) { DataEnqueue(buffer); } + + if(HidumpHelper::GetInstance().GetDumpFlag() == true) { + HidumpHelper::GetInstance().DumpDfxDataToFile((DUMP_FILE_PATH + "/" + SCREEN_FILE_NAME_AFTERCODING), + static_cast(buffer), buffer->GetMemoryCount()); + HidumpHelper::GetInstance().SetDumpFlagFalse(); + } } std::shared_ptr DsoftbusInputPlugin::CreateBuffer(uint32_t metaType, diff --git a/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output/BUILD.gn b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output/BUILD.gn index 08779769..49914125 100644 --- a/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output/BUILD.gn +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output/BUILD.gn @@ -17,11 +17,17 @@ import( ohos_source_set("plugin_AVTransDsoftbusOutput") { include_dirs = [ + "//foundation/distributedhardware/distributed_hardware_fwk/common/inculde"; + "//foundation/distributedhardware/distributed_hardware_fwk/common/utils/inculde"; + "//foundation/distributedhardware/distributed_hardware_fwk/av_transport/common/inculde"; "${common_path}/include", "${plugin_path}/interface", "//third_party/json/include", + "//foundation/distributedhardware/distributed_hardware_fwk/services/distributedhardwarefwkservice/inculde/hidumphelper"; ] + deps = [ "//foundation/distributedhardware/distributed_hardware_fwk/services/distributedhardwarefwkservice:distributedhardwarefwksvr" ] + sources = [ "dsoftbus_output_plugin.cpp" ] external_deps = [ diff --git a/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output/dsoftbus_output_plugin.cpp b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output/dsoftbus_output_plugin.cpp index abcd5dc4..95e62bb0 100644 --- a/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output/dsoftbus_output_plugin.cpp +++ b/av_transport/av_trans_engine/plugin/plugins/av_trans_output/dsoftbus_output/dsoftbus_output_plugin.cpp @@ -14,6 +14,8 @@ */ #include "dsoftbus_output_plugin.h" +#include "constants.h" +#include "hidump_helper.h" #include "foundation/utils/constants.h" #include "plugin/common/plugin_caps_builder.h" #include "plugin/factory/plugin_factory.h" @@ -252,6 +254,11 @@ Status DsoftbusOutputPlugin::PushData(const std::string &inPort, std::shared_ptr } dataQueue_.push(buffer); dataCond_.notify_all(); + if(HidumpHelper::GetInstance().GetDumpFlag() == true) { + HidumpHelper::GetInstance().DumpDfxDataToFile((DUMP_FILE_PATH + "/" + SCREEN_FILE_NAME_AFTERCODING), + static_cast(buffer), buffer->GetMemoryCount()); + HidumpHelper::GetInstance().SetDumpFlagFalse(); + } return Status::OK; } diff --git a/common/utils/include/constants.h b/common/utils/include/constants.h index 72da5f47..01415af3 100644 --- a/common/utils/include/constants.h +++ b/common/utils/include/constants.h @@ -62,6 +62,9 @@ namespace DistributedHardware { const std::string DH_COMPONENT_SINK_VER = "version"; const std::string DH_COMPONENT_DEFAULT_VERSION = "1.0"; const std::string LOW_LATENCY_ENABLE = "low_latency_enable"; + const std::string DUMP_FILE_PATH = "/data/data/dscreen"; + const std::string SCREEN_FILE_NAME_AFTERCODING = "Screen_Aftercoding.jpg"; + const std::string SCREEN_FILE_NAME_BEFOREENCODING = "Screen_BeforeEncoding.jpg"; constexpr const char *DO_RECOVER = "DoRecover"; constexpr const char *SEND_ONLINE = "SendOnLine"; constexpr const char *DISABLE_TASK_INNER = "DisableTask"; diff --git a/services/distributedhardwarefwkservice/include/hidumphelper/hidump_helper.h b/services/distributedhardwarefwkservice/include/hidumphelper/hidump_helper.h index a89a5952..56893816 100644 --- a/services/distributedhardwarefwkservice/include/hidumphelper/hidump_helper.h +++ b/services/distributedhardwarefwkservice/include/hidumphelper/hidump_helper.h @@ -33,16 +33,33 @@ enum class HidumpFlag { GET_TASK_LIST, GET_CAPABILITY_LIST, }; +constexpr uint32_t DUMP_FILE_MAX_SIZE = 295 * 1024 * 1024; class HidumpHelper { DECLARE_SINGLE_INSTANCE_BASE(HidumpHelper); public: int32_t Dump(const std::vector& args, std::string &result); + bool GetDumpFlag(); + bool GetFileFullFlag(); + bool GetReDumpFlag(); + void SetDumpFlagTrue(); + void SetDumpFlagFalse(); + void SetFileFullFlagTrue(); + void SetFileFullFlagFalse(); + void SetReDumpFlagTrue(); + void SetReDumpFlagFalse(); + void DumpDfxDataToFile(std::string fileName, uint8_t *buffer, int32_t bufSize); private: explicit HidumpHelper() = default; ~HidumpHelper() = default; + bool DumpFlag_ = false; + bool FileFullFlag_ = false; + bool ReDumpFlag_ = false; + + int32_t DumpScreenData(std::string &result); + int32_t ReDumpScreenData(std::string &result); int32_t ProcessDump(const HidumpFlag &flag, std::string &result); int32_t ShowAllLoadedComps(std::string &result); int32_t ShowAllEnabledComps(std::string &result); diff --git a/services/distributedhardwarefwkservice/src/hidumphelper/hidump_helper.cpp b/services/distributedhardwarefwkservice/src/hidumphelper/hidump_helper.cpp index 88adf956..9d06609b 100644 --- a/services/distributedhardwarefwkservice/src/hidumphelper/hidump_helper.cpp +++ b/services/distributedhardwarefwkservice/src/hidumphelper/hidump_helper.cpp @@ -17,6 +17,7 @@ #include +#include "constants.h" #include "capability_info_manager.h" #include "component_loader.h" #include "component_manager.h" @@ -33,6 +34,8 @@ const std::string LOADED_COMP_LIST = "-l"; const std::string ENABLED_COMP_LIST = "-e"; const std::string TASK_LIST = "-t"; const std::string CAPABILITY_LIST = "-c"; +const std::string ARGS_DUMP_SOURCE_SCREEN_DATA = "--dump"; +const std::string ARGS_DUMP_SOURCE_SCREEN_DATA_RESTART = "--redump"; const std::unordered_map MAP_ARGS = { { ARGS_HELP, HidumpFlag::GET_HELP }, @@ -40,6 +43,8 @@ const std::unordered_map MAP_ARGS = { { ENABLED_COMP_LIST, HidumpFlag::GET_ENABLED_COMP_LIST }, { TASK_LIST, HidumpFlag::GET_TASK_LIST }, { CAPABILITY_LIST, HidumpFlag::GET_CAPABILITY_LIST }, + { ARGS_DUMP_SOURCE_SCREEN_DATA, HidumpFlag::DUMP_SOURCE_SCREEN_DATA }, + { ARGS_DUMP_SOURCE_SCREEN_DATA_RESTART, HidumpFlag::DUMP_SOURCE_SCREEN_DATA_RESTART }, }; std::unordered_map g_mapTaskType = { @@ -113,6 +118,14 @@ int32_t HidumpHelper::ProcessDump(const HidumpFlag &flag, std::string &result) errCode = ShowAllCapabilityInfos(result); break; } + case HidumpFlag::DUMP_SOURCE_SCREEN_DATA : { + errCode = DumpScreenData(result); + break; + } + case HidumpFlag::DUMP_SOURCE_SCREEN_DATA_RESTART : { + errCode = ReDumpScreenData(result); + break; + } default: { errCode = ShowIllealInfomation(result); break; @@ -295,6 +308,10 @@ int32_t HidumpHelper::ShowHelp(std::string &result) result.append(": Show all tasks\n"); result.append(" -c "); result.append(": Show all Capability info of online components\n\n"); + result.append(" --dump"); + result.append(": dump screen data in /data/data/dscreen\n\n"); + result.append(" --redump"); + result.append(": clear file and restart dump source screen data\n\n"); return DH_FWK_SUCCESS; } @@ -308,3 +325,106 @@ int32_t HidumpHelper::ShowIllealInfomation(std::string &result) } } // namespace DistributedHardware } // namespace OHOS + +bool HidumpHelper::GetDumpFlag() +{ + return DumpFlag_; +} +bool HidumpHelper::GetFileFullFlag() +{ + return FileFullFlag_; +} +bool HidumpHelper::GetReDumpFlag() +{ + return ReDumpFlag_; +} +void HidumpHelper::SetDumpFlagTrue() +{ + DumpFlag_ = true; +} +void HidumpHelper::SetDumpFlagFalse() +{ + DumpFlag_ = false; +} +void HidumpHelper::SetFileFullFlagTrue() +{ + FileFullFlag_ = true; +} +void HidumpHelper::SetFileFullFlagFalse() +{ + FileFullFlag_ = false; +} +void HidumpHelper::SetReDumpFlagTrue() +{ + ReDumpFlag_ = true; +} +void HidumpHelper::SetReDumpFlagFalse() +{ + ReDumpFlag_ = false; +} + +void HidumpHelper::DumpDfxDataToFile(std::string fileName, uint8_t *buffer, int32_t bufSize) +{ + DHLOGE("DumpDfxDataToFile."); + if (GetReDumpFlag() == true) { + std::remove(fileName.c_str()); + SetReDumpFlagFalse(); + } + std::ofstream ofs(fileName, std::ios::binary | std::ios::out | std::ios::app); + + if (!ofs.is_open()) { + DHLOGE("open file failed."); + return; + } + DHLOGE("open Hidumper SaveFile file success."); + ofs.seekp(0, std::ios::end); + uint32_t fileSize = ofs.tellp(); + DHLOGE("fileSize = %d, video.size = %d, maxsize = %d", fileSize, bufSize, + DUMP_FILE_MAX_SIZE); + if ((fileSize + bufSize) < DUMP_FILE_MAX_SIZE) { + SetFileFullFlagFalse(); + ofs.write((const char *)buffer, bufSize); + } else { + SetFileFullFlagTrue(); + } + ofs.close(); +} + +int32_t HidumpHelper::DumpScreenData(std::string &result) +{ + DHLOGI("Dump screen data."); + + if (access(DUMP_FILE_PATH.c_str(), 0) < 0) { + if (mkdir(DUMP_FILE_PATH.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) { + DHLOGI("Create dir err."); + DHLOGI("dir path : %s", DUMP_FILE_PATH.c_str()); + return ERR_DH_FWK_HIDUMP_ERROR; + } + } + + if (FileFullFlag_ == false) { + result.append("Dump..."); + SetDumpFlagTrue(); + } else { + result.append("File oversize 300M : stop dump, use parameter \"--redump\" to clear dumpfile and redump"); + } + return DH_FWK_SUCCESS; +} + +int32_t HidumpHelper::ReDumpScreenData(std::string &result) +{ + DHLOGI("Redump screen data."); + + if (access(DUMP_FILE_PATH.c_str(), 0) < 0) { + if (mkdir(DUMP_FILE_PATH.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) { + DHLOGI("Create dir err."); + DHLOGI("dir path : %s", DUMP_FILE_PATH.c_str()); + return ERR_DH_FWK_HIDUMP_ERROR; + } + } + SetFileFlagFalse(); + SetReDumpFlagTrue(); + result.append("ReDumpStart..."); + SetDumpFlagTrue(); + return DH_FWK_SUCCESS; +} -- Gitee