From 08c80db53d9ffe5d9182e9b1a418846019cde427 Mon Sep 17 00:00:00 2001 From: Bobie Date: Tue, 28 May 2024 15:08:58 +0800 Subject: [PATCH] fix dump feature Signed-off-by: Bobie --- common/include/daudio_util.h | 19 +++- common/src/daudio_util.cpp | 92 ++++++++++++++++--- .../micclient/include/dmic_client.h | 5 +- .../audioclient/micclient/src/dmic_client.cpp | 10 +- .../spkclient/include/dspeaker_client.h | 5 +- .../spkclient/src/dspeaker_client.cpp | 11 +-- .../include/daudio_echo_cannel_manager.h | 7 ++ .../managersource/include/dmic_dev.h | 7 +- .../managersource/include/dspeaker_dev.h | 7 +- .../src/daudio_echo_cannel_manager.cpp | 14 +-- .../managersource/src/dmic_dev.cpp | 23 ++--- .../managersource/src/dspeaker_dev.cpp | 22 ++--- services/audiomanager/servicesink/BUILD.gn | 9 +- 13 files changed, 148 insertions(+), 83 deletions(-) diff --git a/common/include/daudio_util.h b/common/include/daudio_util.h index 3d05d5c4..07a42e57 100644 --- a/common/include/daudio_util.h +++ b/common/include/daudio_util.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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,6 +18,7 @@ #include #include +#include #include #include "cJSON.h" @@ -26,6 +27,9 @@ #define AUDIO_NS_PER_SECOND ((int64_t)1000000000) namespace OHOS { namespace DistributedHardware { +const std::string DUMP_SERVER_PARA = "sys.daudio.dump.write.enable"; +const std::string DUMP_SERVICE_DIR = "/data/local/tmp/"; + int32_t GetLocalDeviceNetworkId(std::string &networkId); std::string GetRandomID(); std::string GetAnonyString(const std::string &value); @@ -57,6 +61,19 @@ std::string ReduceDhIdPrefix(const std::string &dhId); template bool GetSysPara(const char *key, T &value); bool IsParamEnabled(const std::string &key, bool &isEnabled); + +class DumpFileUtil { +public: + static void OpenDumpFile(const std::string ¶, const std::string &fileName, FILE **file); + static void CloseDumpFile(FILE **dumpFile); + static void WriteDumpFile(FILE *dumpFile, void *buffer, size_t bufferSize); + + static std::map g_lastPara; + +private: + static FILE *OpenDumpFileInner(const std::string ¶, const std::string &fileName); + static void ChangeDumpFileState(const std::string ¶, FILE **dumpFile, const std::string &fileName); +}; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DAUDIO_UTIL_H diff --git a/common/src/daudio_util.cpp b/common/src/daudio_util.cpp index 1357ddc5..38b270c0 100644 --- a/common/src/daudio_util.cpp +++ b/common/src/daudio_util.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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,12 +15,14 @@ #include "daudio_util.h" -#include #include +#include #include #include +#include #include #include +#include #include #include "softbus_bus_center.h" @@ -520,17 +522,12 @@ std::string ReduceDhIdPrefix(const std::string &dhId) template bool GetSysPara(const char *key, T &value) { - if (key == nullptr) { - DHLOGE("GetSysPara: key is nullptr"); - return false; - } - char paraValue[20] = {0}; // 20 for system parameter + CHECK_AND_RETURN_RET_LOG(key == nullptr, false, "key is nullptr"); + char paraValue[30] = {0}; // 30 for system parameter auto res = GetParameter(key, "-1", paraValue, sizeof(paraValue)); - if (res <= 0) { - DHLOGD("GetSysPara fail, key:%{public}s res:%{public}d", key, res); - return false; - } - DHLOGI("GetSysPara: key:%{public}s value:%{public}s", key, paraValue); + + CHECK_AND_RETURN_RET_LOG(res <= 0, false, "GetParameter fail, key:%{public}s res:%{public}d", key, res); + DHLOGI("GetSysPara key:%{public}s value:%{public}s", key, paraValue); std::stringstream valueStr; valueStr << paraValue; valueStr >> value; @@ -569,5 +566,76 @@ void SaveFile(const std::string fileName, uint8_t *audioData, int32_t size) ofs.write(reinterpret_cast(audioData), size); ofs.close(); } + +std::map DumpFileUtil::g_lastPara = {}; + +FILE *DumpFileUtil::OpenDumpFileInner(const std::string ¶, const std::string &fileName) +{ + std::string filePath = DUMP_SERVICE_DIR + fileName; + std::string dumpPara; + FILE *dumpFile = nullptr; + bool res = GetSysPara(para.c_str(), dumpPara); + if (!res || dumpPara.empty()) { + DHLOGI("%{public}s is not set, dump dcamera is not required", para.c_str()); + g_lastPara[para] = dumpPara; + return dumpFile; + } + DHLOGI("%{public}s = %{public}s, filePath: %{public}s", para.c_str(), dumpPara.c_str(), filePath.c_str()); + if (dumpPara == "w") { + dumpFile = fopen(filePath.c_str(), "wb+"); + CHECK_AND_RETURN_RET_LOG(dumpFile == nullptr, dumpFile, "Error opening dump file!"); + } else if (dumpPara == "a") { + dumpFile = fopen(filePath.c_str(), "ab+"); + CHECK_AND_RETURN_RET_LOG(dumpFile == nullptr, dumpFile, "Error opening dump file!"); + } + g_lastPara[para] = dumpPara; + return dumpFile; +} + +void DumpFileUtil::WriteDumpFile(FILE *dumpFile, void *buffer, size_t bufferSize) +{ + if (dumpFile == nullptr) { + return; + } + CHECK_AND_RETURN_LOG(buffer == nullptr, "Invalid write param"); + size_t writeResult = fwrite(buffer, 1, bufferSize, dumpFile); + CHECK_AND_RETURN_LOG(writeResult != bufferSize, "Failed to write the file."); +} + +void DumpFileUtil::CloseDumpFile(FILE **dumpFile) +{ + if (*dumpFile) { + fclose(*dumpFile); + *dumpFile = nullptr; + } +} + +void DumpFileUtil::ChangeDumpFileState(const std::string ¶, FILE **dumpFile, const std::string &filePath) +{ + CHECK_AND_RETURN_LOG(*dumpFile == nullptr, "Invalid file para"); + CHECK_AND_RETURN_LOG(g_lastPara[para] != "w" || g_lastPara[para] != "a", "Invalid input para"); + std::string dumpPara; + bool res = GetSysPara(para.c_str(), dumpPara); + if (!res || dumpPara.empty()) { + DHLOGE("get %{public}s fail", para.c_str()); + } + if (g_lastPara[para] == "w" && dumpPara == "w") { + return; + } + CloseDumpFile(dumpFile); + OpenDumpFile(para, filePath, dumpFile); +} + +void DumpFileUtil::OpenDumpFile(const std::string ¶, const std::string &fileName, FILE **file) +{ + if (*file != nullptr) { + DumpFileUtil::ChangeDumpFileState(para, file, fileName); + return; + } + + if (para == DUMP_SERVER_PARA) { + *file = DumpFileUtil::OpenDumpFileInner(para, fileName); + } +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/audioclient/micclient/include/dmic_client.h b/services/audioclient/micclient/include/dmic_client.h index 41896aae..f1b09b55 100644 --- a/services/audioclient/micclient/include/dmic_client.h +++ b/services/audioclient/micclient/include/dmic_client.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -75,7 +75,7 @@ private: private: constexpr static uint8_t CHANNEL_WAIT_SECONDS = 5; static constexpr const char* CAPTURETHREAD = "captureThread"; - const std::string MIC_CLIENT_FILENAME = DUMP_FILE_PATH + "/sink_mic_send_to_trans.pcm"; + const std::string DUMP_DAUDIO_MIC_BEFORE_TRANS_NAME = "dump_sink_mic_before_trans.pcm"; std::string devId_; int32_t dhId_; @@ -92,6 +92,7 @@ private: int64_t lastCaptureStartTime_ = 0; int64_t lastTransStartTime_ = 0; std::atomic isPauseStatus_ = false; + FILE *dumpFile_ = nullptr; }; } // DistributedHardware } // OHOS diff --git a/services/audioclient/micclient/src/dmic_client.cpp b/services/audioclient/micclient/src/dmic_client.cpp index 7271744d..cefedb24 100644 --- a/services/audioclient/micclient/src/dmic_client.cpp +++ b/services/audioclient/micclient/src/dmic_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -161,6 +161,7 @@ int32_t DMicClient::SetUp(const AudioParam ¶m) param.comParam.sampleRate, param.comParam.bitFormat, param.comParam.channelMask, param.captureOpts.sourceType, param.captureOpts.capturerFlags, param.comParam.frameSize); audioParam_ = param; + DumpFileUtil::OpenDumpFile(DUMP_SERVER_PARA, DUMP_DAUDIO_MIC_BEFORE_TRANS_NAME, &dumpFile_); return AudioFwkClientSetUp(); } @@ -204,6 +205,7 @@ int32_t DMicClient::Release() if (isReleaseError) { return ERR_DH_AUDIO_FAILED; } + DumpFileUtil::CloseDumpFile(&dumpFile_); return DH_SUCCESS; } @@ -269,11 +271,7 @@ void DMicClient::AudioFwkCaptureData() if (isPauseStatus_.load()) { memset_s(audioData->Data(), audioData->Size(), 0, audioData->Size()); } -#ifdef DUMP_DMICCLIENT_FILE - if (DaudioSinkHidumper::GetInstance().QueryDumpDataFlag()) { - SaveFile(MIC_CLIENT_FILENAME, const_cast(audioData->Data()), audioData->Size()); - } -#endif + DumpFileUtil::WriteDumpFile(dumpFile_, static_cast(audioData->Data()), audioData->Size()); int64_t startTransTime = GetNowTimeUs(); int32_t ret = micTrans_->FeedAudioData(audioData); if (ret != DH_SUCCESS) { diff --git a/services/audioclient/spkclient/include/dspeaker_client.h b/services/audioclient/spkclient/include/dspeaker_client.h index 29020232..052a5140 100644 --- a/services/audioclient/spkclient/include/dspeaker_client.h +++ b/services/audioclient/spkclient/include/dspeaker_client.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -94,7 +94,7 @@ private: constexpr static size_t DATA_QUEUE_SIZE = 8; constexpr static size_t SLEEP_TIME = 5000; static constexpr const char* RENDERTHREAD = "renderThread"; - const std::string SPK_CLIENT_FILENAME = DUMP_FILE_PATH + "/sink_spk_recv_from_trans.pcm"; + const std::string DUMP_DAUDIO_SPK_AFTER_TRANS_NAME = "dump_sink_spk_recv_from_trans.pcm"; std::string devId_; const int32_t dhId_; @@ -112,6 +112,7 @@ private: std::weak_ptr eventCallback_; int64_t lastPlayStartTime_ = 0; int64_t lastReceiveStartTime_ = 0; + FILE *dumpFile_ = nullptr; }; } // DistributedHardware } // OHOS diff --git a/services/audioclient/spkclient/src/dspeaker_client.cpp b/services/audioclient/spkclient/src/dspeaker_client.cpp index 90765131..117b769a 100644 --- a/services/audioclient/spkclient/src/dspeaker_client.cpp +++ b/services/audioclient/spkclient/src/dspeaker_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -153,8 +153,8 @@ int32_t DSpeakerClient::SetUp(const AudioParam ¶m) DHLOGE("Set up failed, Create Audio renderer failed."); return ret; } + DumpFileUtil::OpenDumpFile(DUMP_SERVER_PARA, DUMP_DAUDIO_SPK_AFTER_TRANS_NAME, &dumpFile_); CHECK_NULL_RETURN(speakerTrans_, ERR_DH_AUDIO_NULLPTR); - ret = speakerTrans_->SetUp(audioParam_, audioParam_, shared_from_this(), CAP_SPK); if (ret != DH_SUCCESS) { DHLOGE("Speaker trans setup failed."); @@ -207,6 +207,7 @@ int32_t DSpeakerClient::Release() audioRenderer_ = nullptr; } clientStatus_ = AudioStatus::STATUS_IDLE; + DumpFileUtil::CloseDumpFile(&dumpFile_); return isSucess ? DH_SUCCESS : ERR_DH_AUDIO_CLIENT_RENDER_RELEASE_FAILED; } @@ -289,11 +290,7 @@ void DSpeakerClient::PlayThreadRunning() uint64_t queueSize = static_cast(dataQueue_.size()); DHLOGD("Pop spk data, dataqueue size: %{public}" PRIu64, queueSize); } -#ifdef DUMP_DSPEAKERCLIENT_FILE - if (DaudioSinkHidumper::GetInstance().QueryDumpDataFlag()) { - SaveFile(SPK_CLIENT_FILENAME, const_cast(audioData->Data()), audioData->Size()); - } -#endif + DumpFileUtil::WriteDumpFile(dumpFile_, static_cast(audioData->Data()), audioData->Size()); int32_t writeOffSet = 0; while (writeOffSet < static_cast(audioData->Capacity())) { int32_t writeLen = audioRenderer_->Write(audioData->Data() + writeOffSet, diff --git a/services/audiomanager/managersource/include/daudio_echo_cannel_manager.h b/services/audiomanager/managersource/include/daudio_echo_cannel_manager.h index 49e2b971..7fde6e33 100644 --- a/services/audiomanager/managersource/include/daudio_echo_cannel_manager.h +++ b/services/audiomanager/managersource/include/daudio_echo_cannel_manager.h @@ -27,6 +27,7 @@ #include "audio_data.h" #include "audio_param.h" +#include "daudio_util.h" namespace OHOS { namespace DistributedHardware { @@ -62,6 +63,10 @@ private: int32_t StopAecProcessor(); int32_t ReleaseAecProcessor(); +private: + const std::string DUMP_DAUDIO_AEC_REFERENCE_FILENAME = "dump_aec_reference_signal.pcm"; + const std::string DUMP_DAUDIO_AEC_RECORD_FILENAME = "dump_aec_record_signal.pcm"; + std::unique_ptr audioCapturer_ = nullptr; std::atomic isAecRunning_ = false; std::thread aecProcessThread_; @@ -79,6 +84,8 @@ private: std::mutex outQueueMtx_; std::condition_variable refQueueCond_; std::atomic isStarted = false; + FILE *dumpFileRef_ = nullptr; + FILE *dumpFileRec_ = nullptr; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/audiomanager/managersource/include/dmic_dev.h b/services/audiomanager/managersource/include/dmic_dev.h index 1928c68f..cfb8a76d 100644 --- a/services/audiomanager/managersource/include/dmic_dev.h +++ b/services/audiomanager/managersource/include/dmic_dev.h @@ -97,8 +97,8 @@ private: static constexpr size_t LOW_LATENCY_JITTER_TIME_MS = 50; static constexpr uint32_t MMAP_WAIT_FRAME_US = 5000; static constexpr const char* ENQUEUE_THREAD = "micEnqueueTh"; - const std::string MIC_DEV_FILENAME = DUMP_FILE_PATH + "/source_mic_read_from_trans.pcm"; - const std::string MIC_LOWLATENCY_FILENAME = DUMP_FILE_PATH + "/source_mic_write_to_ashmem.pcm"; + const std::string DUMP_DAUDIO_MIC_READ_FROM_BUF_NAME = "dump_source_mic_read_from_trans.pcm"; + const std::string DUMP_DAUDIO_LOWLATENCY_MIC_FROM_BUF_NAME = "dump_source_mic_write_to_ashmem.pcm"; std::weak_ptr audioEventCallback_; std::mutex dataQueueMtx_; @@ -107,7 +107,6 @@ private: int32_t curPort_ = 0; std::atomic isTransReady_ = false; std::atomic isOpened_ = false; - std::atomic dumpFlag_ = false; std::shared_ptr micTrans_ = nullptr; #ifdef ECHO_CANNEL_ENABLE std::shared_ptr echoManager_ = nullptr; @@ -137,6 +136,8 @@ private: std::condition_variable dataQueueCond_; int32_t dhId_ = -1; bool echoCannelOn_ = false; + FILE *dumpFileCommn_ = nullptr; + FILE *dumpFileFast_ = nullptr; }; } // DistributedHardware } // OHOS diff --git a/services/audiomanager/managersource/include/dspeaker_dev.h b/services/audiomanager/managersource/include/dspeaker_dev.h index 4340a08b..057c095a 100644 --- a/services/audiomanager/managersource/include/dspeaker_dev.h +++ b/services/audiomanager/managersource/include/dspeaker_dev.h @@ -84,15 +84,14 @@ private: private: static constexpr const char* ENQUEUE_THREAD = "spkEnqueueTh"; - const std::string SPK_DEV_FILENAME = DUMP_FILE_PATH + "/source_spk_write_to_trans.pcm"; - const std::string SPK_LOWLATENCY_FILENAME = DUMP_FILE_PATH + "/source_spk_read_from_ashmem.pcm"; + const std::string SPK_DEV_FILENAME = "dump_source_spk_write_to_trans.pcm"; + const std::string SPK_LOWLATENCY_FILENAME = "dump_source_spk_fast_read_from_ashmem.pcm"; std::weak_ptr audioEventCallback_; std::mutex channelWaitMutex_; std::condition_variable channelWaitCond_; std::atomic isTransReady_ = false; std::atomic isOpened_ = false; - std::atomic dumpFlag_ = false; int32_t curPort_ = 0; std::shared_ptr speakerTrans_ = nullptr; @@ -113,6 +112,8 @@ private: std::thread enqueueDataThread_; int64_t lastwriteStartTime_ = 0; int32_t dhId_ = -1; + FILE *dumpFileCommn_ = nullptr; + FILE *dumpFileFast_ = nullptr; }; } // DistributedHardware } // OHOS diff --git a/services/audiomanager/managersource/src/daudio_echo_cannel_manager.cpp b/services/audiomanager/managersource/src/daudio_echo_cannel_manager.cpp index a3d5524e..fb23e5be 100644 --- a/services/audiomanager/managersource/src/daudio_echo_cannel_manager.cpp +++ b/services/audiomanager/managersource/src/daudio_echo_cannel_manager.cpp @@ -64,6 +64,8 @@ int32_t DAudioEchoCannelManager::SetUp(const AudioCommonParam param, } ret = InitAecProcessor(); CHECK_AND_RETURN_RET_LOG(ret != DH_SUCCESS, ret, "Init Aec Processor error. ret: %{public}d.", ret); + DumpFileUtil::OpenDumpFile(DUMP_SERVER_PARA, DUMP_DAUDIO_AEC_REFERENCE_FILENAME, &dumpFileRef_); + DumpFileUtil::OpenDumpFile(DUMP_SERVER_PARA, DUMP_DAUDIO_AEC_RECORD_FILENAME, &dumpFileRec_); ret = AudioCaptureSetUp(); CHECK_AND_RETURN_RET_LOG(ret != DH_SUCCESS, ret, "Init Get Reference error. ret: %{public}d.", ret); @@ -106,6 +108,8 @@ int32_t DAudioEchoCannelManager::Release() ret = ReleaseAecProcessor(); CHECK_AND_RETURN_RET_LOG(ret != DH_SUCCESS, ret, "Release Aec Processor error. ret: %{public}d.", ret); UnLoadAecProcessor(); + DumpFileUtil::CloseDumpFile(&dumpFileRef_); + DumpFileUtil::CloseDumpFile(&dumpFileRec_); isStarted.store(false); return DH_SUCCESS; } @@ -124,9 +128,7 @@ int32_t DAudioEchoCannelManager::OnMicDataReceived(const std::shared_ptrOnDecodeTransDataDone(pipeInData); return ERR_DH_AUDIO_FAILED; } -#ifdef DUMP_FILE - SaveFile("/data/luzhi.pcm", const_cast(pipeInData->Data()), pipeInData->Size()); -#endif + DumpFileUtil::WriteDumpFile(dumpFileRec_, static_cast(pipeInData->Data()), pipeInData->Size()); devCallback_->OnDecodeTransDataDone(micOutData); } else { devCallback_->OnDecodeTransDataDone(pipeInData); @@ -183,9 +185,7 @@ void DAudioEchoCannelManager::AecProcessData() refDataQueue_.pop(); DHLOGI("Pop new echo ref data, ref dataqueue size: %{public}zu.", refDataQueue_.size()); } -#ifdef DUMP_FILE - SaveFile("/data/cankao.pcm", const_cast(refInData->Data()), refInData->Size()); -#endif + DumpFileUtil::WriteDumpFile(dumpFileRef_, static_cast(refInData->Data()), refInData->Size()); int32_t ret = aecProcessor_->OnSendOriginData(aecProcessor_, refInData->Data(), refInData->Size(), StreamType::REF, &refOutDataExt); if (ret != DH_SUCCESS) { @@ -349,7 +349,7 @@ int32_t DAudioEchoCannelManager::InitAecProcessor() return ERR_DH_AUDIO_NULLPTR; } int32_t ret = aecProcessor_->Init(aecProcessor_, param); - if (ret != DH_SUCESS) { + if (ret != DH_SUCCESS) { DHLOGE("Aec effect processor init fail. errorcode: %{public}d", ret); return ERR_DH_AUDIO_FAILED; } diff --git a/services/audiomanager/managersource/src/dmic_dev.cpp b/services/audiomanager/managersource/src/dmic_dev.cpp index fcb47e46..d18d84fd 100644 --- a/services/audiomanager/managersource/src/dmic_dev.cpp +++ b/services/audiomanager/managersource/src/dmic_dev.cpp @@ -240,6 +240,8 @@ int32_t DMicDev::SetUp() echoManager_->SetUp(info, shared_from_this()); } #endif + DumpFileUtil::OpenDumpFile(DUMP_SERVER_PARA, DUMP_DAUDIO_MIC_READ_FROM_BUF_NAME, &dumpFileCommn_); + DumpFileUtil::OpenDumpFile(DUMP_SERVER_PARA, DUMP_DAUDIO_LOWLATENCY_MIC_FROM_BUF_NAME, &dumpFileFast_); return DH_SUCCESS; } @@ -326,7 +328,8 @@ int32_t DMicDev::Release() echoManager_ = nullptr; } #endif - dumpFlag_.store(false); + DumpFileUtil::CloseDumpFile(&dumpFileCommn_); + DumpFileUtil::CloseDumpFile(&dumpFileFast_); return DH_SUCCESS; } @@ -365,16 +368,8 @@ int32_t DMicDev::ReadStreamData(const int32_t streamId, std::shared_ptr(data->Data()), data->Size()); - } -#endif + + DumpFileUtil::WriteDumpFile(dumpFileCommn_, static_cast(data->Data()), data->Size()); int64_t endTime = GetNowTimeUs(); if (IsOutDurationRange(startTime, endTime, lastReadStartTime_)) { DHLOGE("This time read data spend: %{public}" PRId64" us, The interval of read data this time and " @@ -454,11 +449,7 @@ void DMicDev::EnqueueThread() dataQueue_.pop(); } } -#ifdef DUMP_DMICDEV_FILE - if (DaudioHidumper::GetInstance().QueryDumpDataFlag()) { - SaveFile(MIC_LOWLATENCY_FILENAME, const_cast(audioData->Data()), audioData->Size()); - } -#endif + DumpFileUtil::WriteDumpFile(dumpFileFast_, static_cast(audioData->Data()), audioData->Size()); bool writeRet = ashmem_->WriteToAshmem(audioData->Data(), audioData->Size(), writeIndex_); if (writeRet) { DHLOGD("Write to ashmem success! write index: %{public}d, writeLength: %{public}d.", diff --git a/services/audiomanager/managersource/src/dspeaker_dev.cpp b/services/audiomanager/managersource/src/dspeaker_dev.cpp index 7e6b65ad..a37c9df4 100644 --- a/services/audiomanager/managersource/src/dspeaker_dev.cpp +++ b/services/audiomanager/managersource/src/dspeaker_dev.cpp @@ -197,6 +197,8 @@ int32_t DSpeakerDev::SetUp() DHLOGE("Speaker trans set up failed. ret:%{public}d", ret); return ret; } + DumpFileUtil::OpenDumpFile(DUMP_SERVER_PARA, SPK_DEV_FILENAME, &dumpFileCommn_); + DumpFileUtil::OpenDumpFile(DUMP_SERVER_PARA, SPK_LOWLATENCY_FILENAME, &dumpFileFast_); return DH_SUCCESS; } @@ -248,7 +250,8 @@ int32_t DSpeakerDev::Release() if (ret != DH_SUCCESS) { DHLOGE("Release speaker trans failed, ret: %{public}d.", ret); } - dumpFlag_.store(false); + DumpFileUtil::CloseDumpFile(&dumpFileCommn_); + DumpFileUtil::CloseDumpFile(&dumpFileFast_); return DH_SUCCESS; } @@ -296,16 +299,7 @@ int32_t DSpeakerDev::WriteStreamData(const int32_t streamId, std::shared_ptr(data->Data()), data->Size()); - } -#endif + DumpFileUtil::WriteDumpFile(dumpFileCommn_, static_cast(data->Data()), data->Size()); int32_t ret = speakerTrans_->FeedAudioData(data); if (ret != DH_SUCCESS) { DHLOGE("Write stream data failed, ret: %{public}d.", ret); @@ -388,11 +382,7 @@ void DSpeakerDev::EnqueueThread() } } CHECK_NULL_VOID(speakerTrans_); -#ifdef DUMP_DSPEAKERDEV_FILE - if (DaudioHidumper::GetInstance().QueryDumpDataFlag()) { - SaveFile(SPK_LOWLATENCY_FILENAME, const_cast(audioData->Data()), audioData->Size()); - } -#endif + DumpFileUtil::WriteDumpFile(dumpFileFast_, static_cast(audioData->Data()), audioData->Size()); int32_t ret = speakerTrans_->FeedAudioData(audioData); if (ret != DH_SUCCESS) { DHLOGE("Speaker enqueue thread, write stream data failed, ret: %{public}d.", ret); diff --git a/services/audiomanager/servicesink/BUILD.gn b/services/audiomanager/servicesink/BUILD.gn index 8c56903e..7d0ba2f8 100755 --- a/services/audiomanager/servicesink/BUILD.gn +++ b/services/audiomanager/servicesink/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2024 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 @@ -101,13 +101,6 @@ ohos_shared_library("distributed_audio_sink") { "LOG_DOMAIN=0xD004130", ] - if (build_variant == "root") { - defines += [ - "DUMP_DMICCLIENT_FILE", - "DUMP_DSPEAKERCLIENT_FILE", - ] - } - subsystem_name = "distributedhardware" part_name = "distributed_audio" -- Gitee