• 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 
36     std::lock_guard<std::mutex> lock(mutex_);
37     auto &item = dfxInfos_[index];
38     AUDIO_INFO_LOG("FlushDfxMsg..., index=%{public}u, appUid=%{public}d, size=%{public}d", index, appUid,
39         static_cast<int32_t>(item.size()));
40     DfxMsgManager::GetInstance().Enqueue({.appUid = appUid, .interruptInfo = item});
41 
42     dfxInfos_.erase(index);
43     if (dfxIdx2InfoIdx_.count(index) != 0) {
44         dfxIdx2InfoIdx_.erase(index);
45     }
46 }
47 
GetDfxIndexes(uint32_t index)48 std::tuple<uint8_t, uint8_t> &AudioInterruptDfxCollector::GetDfxIndexes(uint32_t index)
49 {
50     auto iter = dfxIdx2InfoIdx_.find(index);
51     if (iter == dfxIdx2InfoIdx_.end()) {
52         dfxIdx2InfoIdx_.insert({index, {0, 0}});
53     }
54     return dfxIdx2InfoIdx_[index];
55 }
56 
57 
WriteActionMsg(uint8_t infoIndex,uint8_t effectIdx,InterruptStage stage)58 InterruptDfxBuilder &InterruptDfxBuilder::WriteActionMsg(uint8_t infoIndex, uint8_t effectIdx, InterruptStage stage)
59 {
60     dfxInfo_.interruptAction = {infoIndex, effectIdx, 0, stage};
61     return *this;
62 }
63 
WriteInfoMsg(const AudioInterrupt & audioInterrupt,const AudioSessionStrategy & strategy,InterruptRole interruptType)64 InterruptDfxBuilder &InterruptDfxBuilder::WriteInfoMsg(const AudioInterrupt &audioInterrupt,
65     const AudioSessionStrategy &strategy, InterruptRole interruptType)
66 {
67     AUDIO_INFO_LOG("[WriteInfoMsg] streamUsage=%{public}d, concurrencyMode=%{public}d",
68         audioInterrupt.streamUsage, audioInterrupt.sessionStrategy.concurrencyMode);
69     uint8_t value3 = static_cast<uint8_t>(audioInterrupt.streamUsage);
70 
71     uint8_t value4 = (static_cast<uint8_t>(strategy.concurrencyMode) & 0x0F) << 4 |
72         (static_cast<uint8_t>(interruptType) & 0x0F);
73 
74     dfxInfo_.interruptInfo = {0, 0, value3, value4};
75     return *this;
76 }
77 
WriteEffectMsg(uint8_t appstate,const std::string & bundleName,const AudioInterrupt & audioInterrupt,const InterruptHint & hintType)78 InterruptDfxBuilder &InterruptDfxBuilder::WriteEffectMsg(uint8_t appstate, const std::string &bundleName,
79     const AudioInterrupt &audioInterrupt, const InterruptHint &hintType)
80 {
81     InterruptEffect interruptEffect{bundleName, audioInterrupt.streamUsage, appstate, hintType};
82     dfxInfo_.interruptEffectVec.push_back(interruptEffect);
83     return *this;
84 }
85 
GetResult()86 InterruptDfxInfo InterruptDfxBuilder::GetResult()
87 {
88     return dfxInfo_;
89 }
90 
91 } // namespace AudioStandard
92 } // namespace OHOS
93