audio: Move tinyALSA-specific code to Module/StreamAlsa
Extract code interacting with tinyALSA which is not
specific to USB into "abstract" module and stream
implementations ModuleAlsa and StreamAlsa. Also, move
utility code which does not need module or stream
context into Utils.
This facilitates implementation of the CF core HAL which
also uses tinyALSA, allowing to share common code.
Bug: 264712385
Test: atest VtsHalAudioCoreTargetTest
Change-Id: I2134b15e970c78e8a48b254e15199b8207a8ab34
diff --git a/audio/aidl/default/usb/UsbAlsaMixerControl.h b/audio/aidl/default/usb/UsbAlsaMixerControl.h
index cbcddd8..c3265f8 100644
--- a/audio/aidl/default/usb/UsbAlsaMixerControl.h
+++ b/audio/aidl/default/usb/UsbAlsaMixerControl.h
@@ -19,67 +19,15 @@
#include <map>
#include <memory>
#include <mutex>
-#include <optional>
-#include <string>
#include <vector>
#include <android-base/thread_annotations.h>
#include <android/binder_auto_utils.h>
-extern "C" {
-#include <tinyalsa/mixer.h>
-}
+#include "alsa/Mixer.h"
namespace aidl::android::hardware::audio::core::usb {
-class MixerControl {
- public:
- explicit MixerControl(struct mixer_ctl* ctl);
-
- unsigned int getNumValues() const;
- int getMaxValue() const;
- int getMinValue() const;
- int setArray(const void* array, size_t count);
-
- private:
- std::mutex mLock;
- // The mixer_ctl object is owned by ALSA and will be released when the mixer is closed.
- struct mixer_ctl* mCtl GUARDED_BY(mLock);
- const unsigned int mNumValues;
- const int mMinValue;
- const int mMaxValue;
-};
-
-class AlsaMixer {
- public:
- explicit AlsaMixer(struct mixer* mixer);
-
- ~AlsaMixer();
-
- bool isValid() const { return mMixer != nullptr; }
-
- ndk::ScopedAStatus setMasterMute(bool muted);
- ndk::ScopedAStatus setMasterVolume(float volume);
- ndk::ScopedAStatus setVolumes(std::vector<float> volumes);
-
- private:
- enum Control {
- MASTER_SWITCH,
- MASTER_VOLUME,
- HW_VOLUME,
- };
- using ControlNamesAndExpectedCtlType = std::pair<std::string, enum mixer_ctl_type>;
- static const std::map<Control, std::vector<ControlNamesAndExpectedCtlType>> kPossibleControls;
- static std::map<Control, std::shared_ptr<MixerControl>> initializeMixerControls(
- struct mixer* mixer);
-
- // The mixer object is owned by ALSA and will be released when the mixer is closed.
- struct mixer* mMixer;
- // `mMixerControls` will only be initialized in constructor. After that, it wil only be
- // read but not be modified.
- const std::map<Control, std::shared_ptr<MixerControl>> mMixerControls;
-};
-
class UsbAlsaMixerControl {
public:
static UsbAlsaMixerControl& getInstance();
@@ -91,16 +39,16 @@
ndk::ScopedAStatus setMasterMute(bool muted);
ndk::ScopedAStatus setMasterVolume(float volume);
// The volume settings can be different on sound cards. It is controlled by streams.
- ndk::ScopedAStatus setVolumes(int card, std::vector<float> volumes);
+ ndk::ScopedAStatus setVolumes(int card, const std::vector<float>& volumes);
private:
- std::shared_ptr<AlsaMixer> getAlsaMixer(int card);
- std::map<int, std::shared_ptr<AlsaMixer>> getAlsaMixers();
+ std::shared_ptr<alsa::Mixer> getAlsaMixer(int card);
+ std::map<int, std::shared_ptr<alsa::Mixer>> getAlsaMixers();
std::mutex mLock;
// A map whose key is the card number and value is a shared pointer to corresponding
// AlsaMixer object.
- std::map<int, std::shared_ptr<AlsaMixer>> mMixerControls GUARDED_BY(mLock);
+ std::map<int, std::shared_ptr<alsa::Mixer>> mMixerControls GUARDED_BY(mLock);
};
} // namespace aidl::android::hardware::audio::core::usb