1

Recently ,I am trying to develop a alsa driver for Linux(actually ,Android TV).I came across a problem about alsa(alsa refers to Advanced Linux Sound Architecture) devices handling

Actually ,I have studied part of source code of alsa-lib-1.0.27.1, and tinyalsa(for android devices). And I studied audio driver of Samsung Devices.

User space application uses /dev/snd/pcmXXXXX to play/capture audio data. However, there is a problem.If there is only one audio devices,it is fine;

/dev/snd/
├── by-path
│   └── pci-0000:02:02.0 -> ../controlC0
├── controlC0
├── midiC0D0
├── pcmC0D0c
├── pcmC0D0p
├── pcmC0D1p
└── timer

But ,if there is more than one device(for instance,when I plug in a usb audio device).

/dev/snd/
├── by-path
│   └── pci-0000:02:02.0 -> ../controlC0
├── controlC0    
├── controlC1    //new Control channel
├── midiC0D0
├── pcmC0D0c
├── pcmC0D0p
├── pcmC0D1p
├── pcmC1D0c     //new card,new capture channel
├── pcmC1D0p     //new card,new playback channel
└── timer

How can user application handle these devices correctly.

I am really confused by Samsung Driver. ==>linux-3.5.4/device/samsung/crespo/libaudio/AudioHardware.cpp

status_t AudioHardware::AudioStreamInALSA::open_l()
{
//.....
    ALOGV("open pcm_in driver");
    TRACE_DRIVER_IN(DRV_PCM_OPEN)
    mPcm = pcm_open(0, 0, flags, &config); 
          //Why it always uses Card 0 and device 0.
          //does this mean it can not support multi-devices

Further more, I would really appreciate if you could share me a piece of source code for more information(for instance ,other drivers...)

thank you very much indeed.

1 Answer 1

5
mPcm = pcm_open(0, 0, flags, &config); 
      //Why it always uses Card 0 and device 0.
      //does this mean it can not support multi-devices

On the platforms I've worked with, all audio devices except for USB were located on card 0. I'm not saying that it's a good idea to hardcode card and device numbers - just that it's usually not going to be a real problem in practice. Until you start adding more cards..

On those platforms, the ALSA card/device number of the USB audio accessory would be picked up by the WiredAccessoryManager (or the UsbDeviceManager in the case of host-mode accessories) (this is in the Java layers of Android). So the information is available if you want to avoid having the audio HAL hardcoding the card/device numbers for USB audio accessories (but I suspect that there are implementations that simply assume card 1 for USB audio accessories).

Here's a link to the audio HAL implementation at the CodeAurora Forum, which serves as the sort-of reference implementation for a lot of Qualcomm's platforms. And here's the driver for host-mode USB audio accessories (Android Open Accessory).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.