• 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_shared_memory.h"
24 
25 namespace OHOS {
26 namespace AudioStandard {
27 namespace {
28     static const std::vector<std::pair<AudioStreamType, DeviceType>> g_volumeIndexVector = {
29         {STREAM_MUSIC, DEVICE_TYPE_SPEAKER},
30         {STREAM_MUSIC, DEVICE_TYPE_WIRED_HEADSET},
31         {STREAM_MUSIC, DEVICE_TYPE_USB_HEADSET},
32         {STREAM_MUSIC, DEVICE_TYPE_WIRED_HEADPHONES},
33         {STREAM_RING, DEVICE_TYPE_SPEAKER},
34         {STREAM_RING, DEVICE_TYPE_WIRED_HEADSET},
35         {STREAM_RING, DEVICE_TYPE_USB_HEADSET},
36         {STREAM_RING, DEVICE_TYPE_WIRED_HEADPHONES},
37         {STREAM_VOICE_ASSISTANT, DEVICE_TYPE_SPEAKER},
38         {STREAM_VOICE_ASSISTANT, DEVICE_TYPE_WIRED_HEADSET},
39         {STREAM_VOICE_ASSISTANT, DEVICE_TYPE_USB_HEADSET},
40         {STREAM_VOICE_ASSISTANT, DEVICE_TYPE_WIRED_HEADPHONES},
41         {STREAM_SYSTEM, DEVICE_TYPE_SPEAKER},
42         {STREAM_SYSTEM, DEVICE_TYPE_WIRED_HEADSET},
43         {STREAM_SYSTEM, DEVICE_TYPE_USB_HEADSET},
44         {STREAM_SYSTEM, DEVICE_TYPE_WIRED_HEADPHONES}};
45 }
46 class IPolicyProvider {
47 public:
48     virtual int32_t GetProcessDeviceInfo(const AudioProcessConfig &config, DeviceInfo &deviceInfo) = 0;
49 
50     virtual int32_t InitSharedVolume(std::shared_ptr<AudioSharedMemory> &buffer) = 0;
51 
52     // virtual int32_t GetVolume(AudioStreamType streamType, DeviceType deviceType, Volume &vol) = 0;
53 
54     // virtual int32_t SetVolume(AudioStreamType streamType, DeviceType deviceType, Volume vol) = 0;
55 
56     virtual ~IPolicyProvider() = default;
57 
GetVolumeIndex(AudioStreamType streamType,DeviceType deviceType,size_t & index)58     static bool GetVolumeIndex(AudioStreamType streamType, DeviceType deviceType, size_t &index)
59     {
60         bool isFind = false;
61         for (size_t tempIndex = 0; tempIndex < g_volumeIndexVector.size(); tempIndex++) {
62             if (g_volumeIndexVector[tempIndex].first == streamType &&
63                 g_volumeIndexVector[tempIndex].second == deviceType) {
64                 isFind = true;
65                 index = tempIndex;
66                 break;
67             }
68         }
69         return isFind;
70     };
GetVolumeVectorSize()71     static size_t GetVolumeVectorSize()
72     {
73         return g_volumeIndexVector.size();
74     };
75 };
76 } // namespace AudioStandard
77 } // namespace OHOS
78 #endif // I_POLICY_PROVIDER_H
79