• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #undef LOG_TAG
16 #define LOG_TAG "PlayerDfxWriter"
17 
18 #include <map>
19 
20 #include "recorder_dfx_writer.h"
21 
22 namespace OHOS {
23 namespace AudioStandard {
24 
RecorderDfxWriter(const AppInfo & appInfo,uint32_t index)25 RecorderDfxWriter::RecorderDfxWriter(const AppInfo &appInfo, uint32_t index)
26 {
27     dfxCollector_ = std::make_unique<AudioCapturerDfxCollector>();
28     appInfo_ = appInfo;
29     index_ = index;
30 }
31 
~RecorderDfxWriter()32 RecorderDfxWriter::~RecorderDfxWriter()
33 {
34     AUDIO_INFO_LOG("enter deconstruct");
35     CHECK_AND_RETURN_LOG(dfxCollector_ != nullptr, "nullptr");
36     dfxCollector_->FlushDfxMsg(index_, appInfo_.appUid);
37 }
38 
WriteDfxStartMsg(uint32_t index,CapturerStage stage,const AudioProcessConfig & processConfig)39 void RecorderDfxWriter::WriteDfxStartMsg(uint32_t index, CapturerStage stage, const AudioProcessConfig &processConfig)
40 {
41     CHECK_AND_RETURN_LOG(dfxCollector_ != nullptr, "nullptr");
42     if (stage != CAPTURER_STAGE_START_OK &&
43         stage != CAPTURER_STAGE_START_FAIL) {
44         return;
45     }
46 
47     CapturerDfxBuilder dfxBuilder;
48     auto dfxInfo = dfxBuilder.WriteActionMsg(++dfxCollector_->dfxIndex_, stage).WriteInfoMsg(
49         processConfig.capturerInfo.sourceType).GetResult();
50     dfxCollector_->AddDfxMsg(index, dfxInfo);
51 }
52 
WriteDfxStopMsg(uint32_t index,CapturerStage stage,int64_t duration,const AudioProcessConfig & processConfig)53 void RecorderDfxWriter::WriteDfxStopMsg(uint32_t index, CapturerStage stage,
54     int64_t duration, const AudioProcessConfig &processConfig)
55 {
56     CHECK_AND_RETURN_LOG(dfxCollector_ != nullptr, "nullptr");
57     if (stage != CAPTURER_STAGE_STOP_OK) {
58         return;
59     }
60 
61     CapturerDfxBuilder dfxBuilder;
62     dfxBuilder.WriteActionMsg(dfxCollector_->dfxIndex_, stage);
63     dfxBuilder.WriteStatMsg(processConfig.capturerInfo, {duration});
64     dfxCollector_->AddDfxMsg(index, dfxBuilder.GetResult());
65 }
66 
WriteDfxActionMsg(uint32_t index,CapturerStage stage)67 void RecorderDfxWriter::WriteDfxActionMsg(uint32_t index, CapturerStage stage)
68 {
69     CHECK_AND_RETURN_LOG(dfxCollector_ != nullptr, "nullptr");
70     CapturerDfxBuilder dfxBuilder;
71     auto dfxInfo = dfxBuilder.WriteActionMsg(dfxCollector_->dfxIndex_, stage).GetResult();
72     dfxCollector_->AddDfxMsg(index, dfxInfo);
73 }
74 
75 } // namespace AudioStandard
76 } // namespace OHOS
77