• 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).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         stage != CAPTURER_STAGE_PAUSE_OK &&
59         stage != CAPTURER_STAGE_STOP_BY_RELEASE) {
60         return;
61     }
62 
63     CapturerDfxBuilder dfxBuilder;
64     dfxBuilder.WriteActionMsg(dfxCollector_->dfxIndex_, stage);
65     dfxBuilder.WriteStatMsg(processConfig, {duration});
66     dfxCollector_->AddDfxMsg(index, dfxBuilder.GetResult());
67 }
68 
WriteDfxActionMsg(uint32_t index,CapturerStage stage)69 void RecorderDfxWriter::WriteDfxActionMsg(uint32_t index, CapturerStage stage)
70 {
71     CHECK_AND_RETURN_LOG(dfxCollector_ != nullptr, "nullptr");
72     CapturerDfxBuilder dfxBuilder;
73     auto dfxInfo = dfxBuilder.WriteActionMsg(dfxCollector_->dfxIndex_, stage).GetResult();
74     dfxCollector_->AddDfxMsg(index, dfxInfo);
75 }
76 
77 } // namespace AudioStandard
78 } // namespace OHOS
79