• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 I_POLICY_PROVIDER_H
17 #define I_POLICY_PROVIDER_H
18 
19 #include <memory>
20 #include <vector>
21 
22 #include "audio_info.h"
23 #include "audio_device_descriptor.h"
24 #include "audio_shared_memory.h"
25 
26 namespace OHOS {
27 namespace AudioStandard {
28 namespace {
29     static const std::vector<std::pair<AudioVolumeType, DeviceGroup>> g_volumeIndexVector = {
30         {STREAM_VOICE_CALL, DEVICE_GROUP_EARPIECE},
31         {STREAM_VOICE_CALL, DEVICE_GROUP_BUILT_IN},
32         {STREAM_VOICE_CALL, DEVICE_GROUP_WIRELESS},
33         {STREAM_VOICE_CALL, DEVICE_GROUP_WIRED},
34         {STREAM_VOICE_CALL, DEVICE_GROUP_REMOTE_CAST},
35         {STREAM_RING, DEVICE_GROUP_EARPIECE},
36         {STREAM_RING, DEVICE_GROUP_BUILT_IN},
37         {STREAM_RING, DEVICE_GROUP_WIRELESS},
38         {STREAM_RING, DEVICE_GROUP_WIRED},
39         {STREAM_RING, DEVICE_GROUP_REMOTE_CAST},
40         {STREAM_MUSIC, DEVICE_GROUP_EARPIECE},
41         {STREAM_MUSIC, DEVICE_GROUP_BUILT_IN},
42         {STREAM_MUSIC, DEVICE_GROUP_WIRELESS},
43         {STREAM_MUSIC, DEVICE_GROUP_WIRED},
44         {STREAM_MUSIC, DEVICE_GROUP_REMOTE_CAST},
45         {STREAM_VOICE_ASSISTANT, DEVICE_GROUP_EARPIECE},
46         {STREAM_VOICE_ASSISTANT, DEVICE_GROUP_BUILT_IN},
47         {STREAM_VOICE_ASSISTANT, DEVICE_GROUP_WIRELESS},
48         {STREAM_VOICE_ASSISTANT, DEVICE_GROUP_WIRED},
49         {STREAM_VOICE_ASSISTANT, DEVICE_GROUP_REMOTE_CAST},
50         {STREAM_ALARM, DEVICE_GROUP_EARPIECE},
51         {STREAM_ALARM, DEVICE_GROUP_BUILT_IN},
52         {STREAM_ALARM, DEVICE_GROUP_WIRELESS},
53         {STREAM_ALARM, DEVICE_GROUP_WIRED},
54         {STREAM_ALARM, DEVICE_GROUP_REMOTE_CAST},
55         {STREAM_ACCESSIBILITY, DEVICE_GROUP_EARPIECE},
56         {STREAM_ACCESSIBILITY, DEVICE_GROUP_BUILT_IN},
57         {STREAM_ACCESSIBILITY, DEVICE_GROUP_WIRELESS},
58         {STREAM_ACCESSIBILITY, DEVICE_GROUP_WIRED},
59         {STREAM_ACCESSIBILITY, DEVICE_GROUP_REMOTE_CAST},
60         {STREAM_ULTRASONIC, DEVICE_GROUP_EARPIECE},
61         {STREAM_ULTRASONIC, DEVICE_GROUP_BUILT_IN},
62         {STREAM_ULTRASONIC, DEVICE_GROUP_WIRELESS},
63         {STREAM_ULTRASONIC, DEVICE_GROUP_WIRED},
64         {STREAM_ULTRASONIC, DEVICE_GROUP_REMOTE_CAST},
65         {STREAM_ALL, DEVICE_GROUP_EARPIECE},
66         {STREAM_ALL, DEVICE_GROUP_BUILT_IN},
67         {STREAM_ALL, DEVICE_GROUP_WIRELESS},
68         {STREAM_ALL, DEVICE_GROUP_WIRED},
69         {STREAM_ALL, DEVICE_GROUP_REMOTE_CAST},
70     };
71 }
72 class IPolicyProvider {
73 public:
74     virtual int32_t GetProcessDeviceInfo(const AudioProcessConfig &config, bool lockFlag,
75         AudioDeviceDescriptor &deviceInfo) = 0;
76 
77     virtual int32_t InitSharedVolume(std::shared_ptr<AudioSharedMemory> &buffer) = 0;
78 
79     virtual int32_t SetWakeUpAudioCapturerFromAudioServer(const AudioProcessConfig &config) = 0;
80 
81     virtual int32_t NotifyCapturerAdded(AudioCapturerInfo capturerInfo, AudioStreamInfo streamInfo,
82         uint32_t sessionId) = 0;
83 
84     virtual int32_t NotifyWakeUpCapturerRemoved() = 0;
85 
86     virtual bool IsAbsVolumeSupported() = 0;
87 
88     virtual int32_t OffloadGetRenderPosition(uint32_t &delayValue, uint64_t &sendDataSize, uint32_t &timeStamp) = 0;
89 
90     virtual int32_t GetAndSaveClientType(uint32_t uid, const std::string &bundleName) = 0;
91 
92     virtual int32_t GetMaxRendererInstances() = 0;
93 
94     virtual int32_t ActivateConcurrencyFromServer(AudioPipeType incomingPipe) = 0;
95 
96     virtual ~IPolicyProvider() = default;
97 
GetVolumeIndex(AudioVolumeType streamType,DeviceGroup deviceGroup,size_t & index)98     static bool GetVolumeIndex(AudioVolumeType streamType, DeviceGroup deviceGroup, size_t &index)
99     {
100         bool isFind = false;
101         for (size_t tempIndex = 0; tempIndex < g_volumeIndexVector.size(); tempIndex++) {
102             if (g_volumeIndexVector[tempIndex].first == streamType &&
103                 g_volumeIndexVector[tempIndex].second == deviceGroup) {
104                 isFind = true;
105                 index = tempIndex;
106                 break;
107             }
108         }
109         return isFind;
110     };
GetVolumeVectorSize()111     static size_t GetVolumeVectorSize()
112     {
113         return g_volumeIndexVector.size();
114     };
115 };
116 } // namespace AudioStandard
117 } // namespace OHOS
118 #endif // I_POLICY_PROVIDER_H
119