• 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     CHECK_AND_RETURN_LOG(dfxCollector_ != nullptr, "nullptr");
35     dfxCollector_->FlushDfxMsg(index_, appInfo_.appUid);
36 }
37 
WriteDfxStartMsg(uint32_t index,RendererStage stage,int64_t sourceDuration,const AudioProcessConfig & processConfig)38 void PlayerDfxWriter::WriteDfxStartMsg(uint32_t index, RendererStage stage,
39     int64_t sourceDuration, const AudioProcessConfig &processConfig)
40 {
41     CHECK_AND_RETURN_LOG(dfxCollector_ != nullptr, "nullptr");
42     if (stage != RENDERER_STAGE_START_OK &&
43         stage != RENDERER_STAGE_START_FAIL) {
44         return;
45     }
46 
47     RenderDfxBuilder dfxBuilder;
48     ++dfxCollector_->dfxIndex_;
49     dfxBuilder.WriteInfoMsg(sourceDuration, processConfig.rendererInfo);
50 
51     dfxBuilder.WriteActionMsg(dfxCollector_->dfxIndex_, stage);
52     dfxCollector_->AddDfxMsg(index, dfxBuilder.GetResult());
53 }
54 
WriteDfxStopMsg(uint32_t index,RendererStage stage,const PlayStat & stat,const AudioProcessConfig & processConfig)55 void PlayerDfxWriter::WriteDfxStopMsg(uint32_t index, RendererStage stage,
56     const PlayStat &stat, const AudioProcessConfig &processConfig)
57 {
58     CHECK_AND_RETURN_LOG(dfxCollector_ != nullptr, "nullptr");
59     if (stage != RENDERER_STAGE_STOP_OK &&
60         stage != RENDERER_STAGE_STOP_BY_RELEASE) {
61         return;
62     }
63 
64     RenderDfxBuilder dfxBuilder;
65     dfxBuilder.WriteStatMsg(
66         processConfig, {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