1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <unordered_map>
17 #include "hpae_pcm_dumper.h"
18 #include "audio_dump_pcm.h"
19 #include "audio_errors.h"
20 #include "audio_utils.h"
21 #include "securec.h"
22 #include "audio_engine_log.h"
23
24 namespace OHOS {
25 namespace AudioStandard {
26 namespace HPAE {
27
HpaePcmDumper(const std::string & filename)28 HpaePcmDumper::HpaePcmDumper(const std::string &filename)
29 {
30 DumpFileUtil::OpenDumpFile(DumpFileUtil::DUMP_SERVER_PARA, filename, &dumpFile_);
31 filename_ = filename;
32 }
33
~HpaePcmDumper()34 HpaePcmDumper::~HpaePcmDumper()
35 {
36 DumpFileUtil::CloseDumpFile(&dumpFile_);
37 }
38
Dump(const int8_t * buffer,int32_t length)39 int32_t HpaePcmDumper::Dump(const int8_t *buffer, int32_t length)
40 {
41 DumpFileUtil::WriteDumpFile(dumpFile_, (void *)(buffer), length);
42 AudioCacheMgr::GetInstance().CacheData(filename_, (void *)(buffer), length);
43 return SUCCESS;
44 }
45
CheckAndReopenHandle()46 bool HpaePcmDumper::CheckAndReopenHandle()
47 {
48 if (dumpFile_ != nullptr) {
49 return true;
50 } else {
51 DumpFileUtil::OpenDumpFile(DumpFileUtil::DUMP_SERVER_PARA, filename_, &dumpFile_);
52 AUDIO_DEBUG_LOG("Reopen dump file: %{public}s", filename_.c_str());
53 }
54 return false;
55 }
56
57 } // namespace HPAE
58 } // namespace AudioStandard
59 } // namespace OHOS
60