• 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 "player_dfx_writer.h"
21 
22 namespace OHOS {
23 namespace AudioStandard {
24 
PlayerDfxWriter(const AppInfo & appInfo,uint32_t index)25 PlayerDfxWriter::PlayerDfxWriter(const AppInfo &appInfo, uint32_t index)
26 {
27     dfxCollector_ = std::make_unique<AudioRenderDfxCollector>();
28     appInfo_ = appInfo;
29     index_ = index;
30 }
31 
~PlayerDfxWriter()32 PlayerDfxWriter::~PlayerDfxWriter()
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,RendererStage stage,int64_t sourceDuration,const AudioProcessConfig & processConfig)39 void PlayerDfxWriter::WriteDfxStartMsg(uint32_t index, RendererStage stage,
40     int64_t sourceDuration, const AudioProcessConfig &processConfig)
41 {
42     CHECK_AND_RETURN_LOG(dfxCollector_ != nullptr, "nullptr");
43     if (stage != RENDERER_STAGE_START_OK &&
44         stage != RENDERER_STAGE_START_FAIL) {
45         return;
46     }
47 
48     RenderDfxBuilder dfxBuilder;
49     ++dfxCollector_->dfxIndex_;
50     dfxBuilder.WriteInfoMsg(sourceDuration, processConfig.rendererInfo);
51 
52     dfxBuilder.WriteActionMsg(dfxCollector_->dfxIndex_, stage);
53     dfxCollector_->AddDfxMsg(index, dfxBuilder.GetResult());
54 }
55 
WriteDfxStopMsg(uint32_t index,RendererStage stage,const PlayStat & stat,const AudioProcessConfig & processConfig)56 void PlayerDfxWriter::WriteDfxStopMsg(uint32_t index, RendererStage stage,
57     const PlayStat &stat, const AudioProcessConfig &processConfig)
58 {
59     CHECK_AND_RETURN_LOG(dfxCollector_ != nullptr, "nullptr");
60     if (stage != RENDERER_STAGE_STOP_OK) {
61         return;
62     }
63 
64     RenderDfxBuilder dfxBuilder;
65     dfxBuilder.WriteStatMsg(
66         processConfig.rendererInfo, {stat.frameCnt, stat.muteFrameCnt,
67         stat.playDuration, stat.underFlowCnt}).GetResult();
68 
69     dfxBuilder.WriteActionMsg(dfxCollector_->dfxIndex_, stage);
70     dfxCollector_->AddDfxMsg(index, dfxBuilder.GetResult());
71 }
72 
WriteDfxActionMsg(uint32_t index,RendererStage stage)73 void PlayerDfxWriter::WriteDfxActionMsg(uint32_t index, RendererStage stage)
74 {
75     CHECK_AND_RETURN_LOG(dfxCollector_ != nullptr, "nullptr");
76     RenderDfxBuilder dfxBuilder;
77     dfxBuilder.WriteActionMsg(dfxCollector_->dfxIndex_, stage);
78     dfxCollector_->AddDfxMsg(index, dfxBuilder.GetResult());
79 }
80 
81 } // namespace AudioStandard
82 } // namespace OHOS
83