• 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 "AudioInterruptDfxCollector"
17 
18 #include <map>
19 
20 #include "audio_interrupt_dfx_collector.h"
21 #include "media_monitor_manager.h"
22 #include "running_process_info.h"
23 #include "audio_system_manager.h"
24 #include "dfx_msg_manager.h"
25 
26 namespace OHOS {
27 namespace AudioStandard {
28 
FlushDfxMsg(uint32_t index,int32_t appUid)29 void AudioInterruptDfxCollector::FlushDfxMsg(uint32_t index, int32_t appUid)
30 {
31     if (!IsExist(index) || appUid == DFX_INVALID_APP_UID) {
32         AUDIO_INFO_LOG("flush failed index=%{public}d, appUid=%{public}d", index, appUid);
33         return;
34     }
35     AUDIO_INFO_LOG("FlushDfxMsg..., index=%{public}u, appUid=%{public}d", index, appUid);
36     auto &item = dfxInfos_[index];
37     DfxMsgManager::GetInstance().Enqueue({.appUid = appUid, .interruptInfo = item});
38 
39     dfxInfos_.erase(index);
40     if (dfxIdx2InfoIdx_.count(index) != 0) {
41         dfxIdx2InfoIdx_.erase(index);
42     }
43 }
44 
GetDfxIndexes(uint32_t index)45 std::tuple<uint8_t, uint8_t> &AudioInterruptDfxCollector::GetDfxIndexes(uint32_t index)
46 {
47     auto iter = dfxIdx2InfoIdx_.find(index);
48     if (iter == dfxIdx2InfoIdx_.end()) {
49         dfxIdx2InfoIdx_.insert({index, {0, 0}});
50     }
51     return dfxIdx2InfoIdx_[index];
52 }
53 
54 
WriteActionMsg(uint8_t infoIndex,uint8_t effectIdx,InterruptStage stage)55 InterruptDfxBuilder &InterruptDfxBuilder::WriteActionMsg(uint8_t infoIndex, uint8_t effectIdx, InterruptStage stage)
56 {
57     AUDIO_INFO_LOG("[WriteInfoMsg] infoIdx=%{public}d, effectIdx=%{public}d", infoIndex, effectIdx);
58     dfxInfo_.interruptAction = {infoIndex, effectIdx, 0, stage};
59     return *this;
60 }
61 
WriteInfoMsg(const AudioInterrupt & audioInterrupt)62 InterruptDfxBuilder &InterruptDfxBuilder::WriteInfoMsg(const AudioInterrupt &audioInterrupt)
63 {
64     AUDIO_INFO_LOG("[WriteInfoMsg] streamUsage=%{public}d, concurrencyMode=%{public}d",
65         audioInterrupt.streamUsage, audioInterrupt.sessionStrategy.concurrencyMode);
66     uint8_t value3 = static_cast<uint8_t>(audioInterrupt.streamUsage);
67 
68     uint8_t interruptType = 0;
69     uint8_t value4 = (static_cast<uint8_t>(audioInterrupt.sessionStrategy.concurrencyMode) & 0x0F) << 4 |
70         (interruptType & 0x0F);
71 
72     dfxInfo_.interruptInfo = {0, 0, value3, value4};
73     return *this;
74 }
75 
WriteEffectMsg(uint8_t appstate,const std::string & bundleName,const AudioInterrupt & audioInterrupt,const InterruptHint & hintType)76 InterruptDfxBuilder &InterruptDfxBuilder::WriteEffectMsg(uint8_t appstate, const std::string &bundleName,
77     const AudioInterrupt &audioInterrupt, const InterruptHint &hintType)
78 {
79     InterruptEffect interruptEffect{bundleName, audioInterrupt.streamUsage, appstate, hintType};
80     dfxInfo_.interruptEffectVec.push_back(interruptEffect);
81     return *this;
82 }
83 
GetResult()84 InterruptDfxInfo InterruptDfxBuilder::GetResult()
85 {
86     return dfxInfo_;
87 }
88 
89 } // namespace AudioStandard
90 } // namespace OHOS
91