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