jiabin | 783c48b | 2023-02-28 18:28:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2023 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <map> |
| 20 | #include <memory> |
| 21 | #include <mutex> |
jiabin | 783c48b | 2023-02-28 18:28:06 +0000 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
| 24 | #include <android-base/thread_annotations.h> |
| 25 | #include <android/binder_auto_utils.h> |
| 26 | |
Mikhail Naganov | c337a87 | 2023-07-07 12:01:17 -0700 | [diff] [blame] | 27 | #include "alsa/Mixer.h" |
jiabin | 783c48b | 2023-02-28 18:28:06 +0000 | [diff] [blame] | 28 | |
| 29 | namespace aidl::android::hardware::audio::core::usb { |
| 30 | |
jiabin | 783c48b | 2023-02-28 18:28:06 +0000 | [diff] [blame] | 31 | class UsbAlsaMixerControl { |
| 32 | public: |
| 33 | static UsbAlsaMixerControl& getInstance(); |
| 34 | |
| 35 | void setDeviceConnectionState(int card, bool masterMuted, float masterVolume, bool connected); |
| 36 | |
| 37 | // Master volume settings will be applied to all sound cards, it is only set by the |
| 38 | // USB module. |
| 39 | ndk::ScopedAStatus setMasterMute(bool muted); |
| 40 | ndk::ScopedAStatus setMasterVolume(float volume); |
| 41 | // The volume settings can be different on sound cards. It is controlled by streams. |
Mikhail Naganov | c337a87 | 2023-07-07 12:01:17 -0700 | [diff] [blame] | 42 | ndk::ScopedAStatus setVolumes(int card, const std::vector<float>& volumes); |
jiabin | 783c48b | 2023-02-28 18:28:06 +0000 | [diff] [blame] | 43 | |
| 44 | private: |
Mikhail Naganov | c337a87 | 2023-07-07 12:01:17 -0700 | [diff] [blame] | 45 | std::shared_ptr<alsa::Mixer> getAlsaMixer(int card); |
| 46 | std::map<int, std::shared_ptr<alsa::Mixer>> getAlsaMixers(); |
jiabin | 783c48b | 2023-02-28 18:28:06 +0000 | [diff] [blame] | 47 | |
| 48 | std::mutex mLock; |
| 49 | // A map whose key is the card number and value is a shared pointer to corresponding |
| 50 | // AlsaMixer object. |
Mikhail Naganov | c337a87 | 2023-07-07 12:01:17 -0700 | [diff] [blame] | 51 | std::map<int, std::shared_ptr<alsa::Mixer>> mMixerControls GUARDED_BY(mLock); |
jiabin | 783c48b | 2023-02-28 18:28:06 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | } // namespace aidl::android::hardware::audio::core::usb |