• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>
22 #include <vector>
23 
24 #include <android-base/thread_annotations.h>
25 #include <android/binder_auto_utils.h>
26 
27 #include "alsa/Mixer.h"
28 
29 namespace aidl::android::hardware::audio::core::usb {
30 
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.
42     ndk::ScopedAStatus setVolumes(int card, const std::vector<float>& volumes);
43 
44   private:
45     std::shared_ptr<alsa::Mixer> getAlsaMixer(int card);
46     std::map<int, std::shared_ptr<alsa::Mixer>> getAlsaMixers();
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.
51     std::map<int, std::shared_ptr<alsa::Mixer>> mMixerControls GUARDED_BY(mLock);
52 };
53 
54 }  // namespace aidl::android::hardware::audio::core::usb
55