audio: probe pcm card from property

* Valid values for the audio device property are 'jack', 'hdmi0', 'hdmi1',
  and 'dac'.
* If 'jack' is selected, first PCM card with name 'Headphones' is used.
  If 'dac' is selected, first PCM card that doesn't match the name for 3.5mm
  or HDMI devices is used. HDMI audio uses virtual ALSA devices instead of
  using tinyalsa to open a PCM card directly.
* Allow forcing specific PCM card for debugging/development purposes.
* PCM card numbers are different between Pi 4 and Pi 5 and order can change
  depending on the DAC driver that's enabled.

Pi 4:

console:/ # cat /proc/asound/cards
 0 [Headphones     ]: bcm2835_headpho - bcm2835 Headphones
                      bcm2835 Headphones
 1 [vc4hdmi0       ]: vc4-hdmi - vc4-hdmi-0
                      vc4-hdmi-0
 2 [vc4hdmi1       ]: vc4-hdmi - vc4-hdmi-1
                      vc4-hdmi-1
Pi 5 with DAC:

console:/ # cat /proc/asound/cards
 0 [vc4hdmi0       ]: vc4-hdmi - vc4-hdmi-0
                      vc4-hdmi-0
 1 [vc4hdmi1       ]: vc4-hdmi - vc4-hdmi-1
                      vc4-hdmi-1
 2 [sndrpihifiberry]: HifiberryDacp - snd_rpi_hifiberry_dacplus
                      snd_rpi_hifiberry_dacplus
This commit is contained in:
Konsta
2025-10-25 21:41:15 +03:00
parent 7bc0df0800
commit 688b88189e
2 changed files with 44 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
/*
* Copyright (C) 2023 The Android Open Source Project
* Copyright (C) 2025 KonstaKANG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -63,6 +64,7 @@ class StreamPrimary : public StreamAlsa {
static constexpr StreamPrimary::AlsaDeviceId kStubDeviceId{
primary::PrimaryMixer::kInvalidAlsaCard, primary::PrimaryMixer::kInvalidAlsaDevice};
static AlsaDeviceId getCardId();
static AlsaDeviceId getCardAndDeviceId(
const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices);
static bool useStubStream(bool isInput,