• 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 
16 #ifndef ST_AUDIO_ZONE_INTERRUPT_ADAPTER_H
17 #define ST_AUDIO_ZONE_INTERRUPT_ADAPTER_H
18 
19 #include <unordered_map>
20 #include <memory>
21 #include <list>
22 #include <mutex>
23 #include <vector>
24 #include "audio_interrupt_service.h"
25 #include "audio_zone_client_manager.h"
26 #include "audio_zone_info.h"
27 
28 namespace OHOS {
29 namespace AudioStandard {
30 
31 using AudioZoneFocusList = std::list<std::pair<AudioInterrupt, AudioFocuState>>;
32 
33 class AudioZoneInterruptReporter {
34 public:
35     using ReportItem = std::pair<int32_t, std::string>;
36     using ReportItemList = std::list<ReportItem>;
37     using ReportMap = std::unordered_map<int32_t, ReportItemList>;
38     using Reporter  =  std::shared_ptr<AudioZoneInterruptReporter>;
39     using ReporterVector = std::vector<Reporter>;
40 
41     AudioZoneInterruptReporter() = default;
42     ~AudioZoneInterruptReporter() = default;
43 
44     static int32_t EnableInterruptReport(pid_t clientPid, int32_t zoneId,
45         const std::string &deviceTag, bool enable);
46     static void DisableInterruptReport(pid_t clientPid);
47     static void DisableAllInterruptReport();
48     static ReporterVector CreateReporter(std::shared_ptr<AudioInterruptService> interruptService,
49         std::shared_ptr<AudioZoneClientManager> zoneClientManager,
50         AudioZoneInterruptReason reason);
51     static ReporterVector CreateReporter(int32_t zoneId,
52         std::shared_ptr<AudioInterruptService> interruptService,
53         std::shared_ptr<AudioZoneClientManager> zoneClientManager,
54         AudioZoneInterruptReason reason);
55 
56     void ReportInterrupt();
57 
58 private:
59     std::shared_ptr<AudioInterruptService> interruptService_;
60     std::shared_ptr<AudioZoneClientManager> zoneClientManager_;
61     pid_t clientPid_ = -1;
62     int32_t zoneId_ = 0;
63     std::string deviceTag_ = "";
64     AudioZoneFocusList oldFocusList_;
65     AudioZoneInterruptReason reportReason_ = AudioZoneInterruptReason::UNKNOWN;
66 
67     static ReportMap interruptEnableMaps_;
68     static std::mutex interruptEnableMutex_;
69 
70     static int32_t RegisterInterruptReport(pid_t clientPid, int32_t zoneId,
71         const std::string &deviceTag);
72     static void UnRegisterInterruptReport(pid_t clientPid, int32_t zoneId,
73         const std::string &deviceTag);
74 
75     AudioZoneFocusList GetFocusList();
76     bool IsFocusListEqual(const AudioZoneFocusList &a, const AudioZoneFocusList &b);
77 };
78 } // namespace AudioStandard
79 } // namespace OHOS
80 
81 #endif // ST_AUDIO_ZONE_INTERRUPT_ADAPTER_H