blob: c3265f8fd3e1979bbbee9a0a4f6ad25486e7c52a [file] [log] [blame]
jiabin783c48b2023-02-28 18:28:06 +00001/*
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>
jiabin783c48b2023-02-28 18:28:06 +000022#include <vector>
23
24#include <android-base/thread_annotations.h>
25#include <android/binder_auto_utils.h>
26
Mikhail Naganovc337a872023-07-07 12:01:17 -070027#include "alsa/Mixer.h"
jiabin783c48b2023-02-28 18:28:06 +000028
29namespace aidl::android::hardware::audio::core::usb {
30
jiabin783c48b2023-02-28 18:28:06 +000031class 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 Naganovc337a872023-07-07 12:01:17 -070042 ndk::ScopedAStatus setVolumes(int card, const std::vector<float>& volumes);
jiabin783c48b2023-02-28 18:28:06 +000043
44 private:
Mikhail Naganovc337a872023-07-07 12:01:17 -070045 std::shared_ptr<alsa::Mixer> getAlsaMixer(int card);
46 std::map<int, std::shared_ptr<alsa::Mixer>> getAlsaMixers();
jiabin783c48b2023-02-28 18:28:06 +000047
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 Naganovc337a872023-07-07 12:01:17 -070051 std::map<int, std::shared_ptr<alsa::Mixer>> mMixerControls GUARDED_BY(mLock);
jiabin783c48b2023-02-28 18:28:06 +000052};
53
54} // namespace aidl::android::hardware::audio::core::usb