Switching from default to plughw:0,0
I have coded an application that uses ALSA and plays back movie's audios, together with their videos. I have pulseaudio installed by default as it comes with Ubuntu Xenian.
My goal is to provide the user with an easy pull-down where they can select the audio device to play the audio in.
The first audio device is "default" and defaults to ALSA's default in the Ubuntu Sound Preferences. All that works fine. I can change the Ubuntu Sound Preferences and the default driver immediately picks up the other cards or outputs in the system.
My problem is that when I choose the default, which is equivalent to plughw:0,0, when I go to force select in my program the plughw:0,0 (HDA Intel PCH: ALC1150 Analog), I get a Device or resource busy.
Sure enough, if I do:
$ fuser -v /dev/snd/*
USUARIO ORDEN DE ACCESO PID
/dev/snd/controlC0: gga 3594 F.... pulseaudio
/dev/snd/controlC1: gga 3594 F.... pulseaudio
/dev/snd/pcmC0D0p: gga 4821 F...m pulseaudioI am very careful in closing the audio before reopening it again. However the resource remains busy for about 7 seconds. Then it turns into:
USUARIO ORDEN DE ACCESO PID
/dev/snd/controlC0: gga 3594 F.... pulseaudio /dev/snd/controlC1: gga 3594 F.... pulseaudio /dev/snd/pcmC0D0p: gga 4821 F...m mrViewer
and the audio works again. My close function looks like:
bool ALSAEngine::close()
{ if ( _pcm_handle )
{
int err = snd_pcm_drop( _pcm_handle );
if ( err < 0 )
{
std::cerr << "ERROR: [alsa] snd_pcm_drop failed with "
<< snd_strerror(err)
<< std::endl;
}
err = snd_pcm_close( _pcm_handle );
if ( err < 0 )
{
std::cerr << "ERROR: [alsa] snd_pcm_close failed with "
<< snd_strerror(err)
<< std::endl;
}
_pcm_handle = NULL;
}
return true;}
and the open function (simplified till it fails).
bool ALSAEngine::open( const unsigned channels,
const unsigned freq,
const AudioFormat format,
const unsigned bits )
{
try
{
close();
int status;
unsigned int test_format = (unsigned int) format;
char buf[256];
/* Open the audio device */
/* Name of device should depend on # channels in spec */
_pcm_handle = NULL;
status = snd_pcm_open(&_pcm_handle, device().c_str(),
SND_PCM_STREAM_PLAYBACK, 0);
if ( status < 0 || _pcm_handle == NULL ) {
sprintf( buf, _("Couldn't open audio device %s: %s"),
device().c_str(), snd_strerror(status));
THROW(buf);
}....snip.....
}
Quoted 1 line · Gonzalo Garramuño
My problem is that when I choose the default, which is equivalent to plughw:0,0
The default actually is PulseAudio or dmix.
Regards,
Clemens
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 7 lines · Clemens Ladisch
Quoted 1 line · Gonzalo Garramuño
My problem is that when I choose the default, which is equivalent to plughw:0,0
The default actually is PulseAudio or dmix.
Regards,
Clemens
I can confirm this is a bug in alsa/pulseaudio. I managed to get the same behavior out of vlc, by calling it with:
vlc -A alsa --alsa-audio-device plughw:0,0
/media/gga/Datos/movies/trailers/Frozen-Let_it_go.mp4
and then switching back and forth between Pulse Audio Sound Server and HDA Intel PCH. When switching back to intel (plughw:0,0), the resource is busy and the audio fails.
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 7 lines · Gonzalo Garramuño
Quoted 4 lines · Clemens Ladisch
Quoted 1 line · Gonzalo Garramuño
My problem is that when I choose the default, which is equivalent to plughw:0,0
The default actually is PulseAudio or dmix.
dmix is not installed in my system
It's part of ALSA.
Quoted 1 line
Do I have to deal with the pulseaudio api, instead of the ALSA api?
When PulseAudio is configured as the default, it can be accessed through the ALSA API.
Anyway, the correct name for the default device is "default".
To get a list of devices, see "aplay -L".
Regards,
Clemens
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 1 line · Clemens Ladisch
When PulseAudio is configured as the default, it can be accessed through the ALSA API.
How exactly?
Quoted 4 lines
Anyway, the correct name for the default device is "default".
To get a list of devices, see "aplay -L".
Here's the output of aplay -L
$ aplay -L
default
Playback/recording through the PulseAudio sound server
null
Discard all samples (playback) or generate zero samples (capture)
pulse
PulseAudio Sound Server
sysdefault:CARD=PCH
HDA Intel PCH, ALC1150 Analog
Default Audio Device
front:CARD=PCH,DEV=0
HDA Intel PCH, ALC1150 Analog
Front speakers
surround21:CARD=PCH,DEV=0
HDA Intel PCH, ALC1150 Analog
2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=PCH,DEV=0
HDA Intel PCH, ALC1150 Analog
4.0 Surround output to Front and Rear speakers
surround41:CARD=PCH,DEV=0
HDA Intel PCH, ALC1150 Analog
4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=PCH,DEV=0
HDA Intel PCH, ALC1150 Analog
5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=PCH,DEV=0
HDA Intel PCH, ALC1150 Analog
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=PCH,DEV=0
HDA Intel PCH, ALC1150 Analog
7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=PCH,DEV=0
HDA Intel PCH, ALC1150 Digital
IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=PCH,DEV=0
HDA Intel PCH, ALC1150 Analog
Direct sample mixing device
dmix:CARD=PCH,DEV=1
HDA Intel PCH, ALC1150 Digital
Direct sample mixing device
dsnoop:CARD=PCH,DEV=0
HDA Intel PCH, ALC1150 Analog
Direct sample snooping device
dsnoop:CARD=PCH,DEV=1
HDA Intel PCH, ALC1150 Digital
Direct sample snooping device
hw:CARD=PCH,DEV=0
HDA Intel PCH, ALC1150 Analog
Direct hardware device without any conversions
hw:CARD=PCH,DEV=1
HDA Intel PCH, ALC1150 Digital
Direct hardware device without any conversions
plughw:CARD=PCH,DEV=0
HDA Intel PCH, ALC1150 Analog
Hardware device with all software conversions
plughw:CARD=PCH,DEV=1
HDA Intel PCH, ALC1150 Digital
Hardware device with all software conversions
hdmi:CARD=NVidia,DEV=0
HDA NVidia, HDMI 0
HDMI Audio Output
hdmi:CARD=NVidia,DEV=1
HDA NVidia, HDMI 1
HDMI Audio Output
hdmi:CARD=NVidia,DEV=2
HDA NVidia, HDMI 2
HDMI Audio Output
hdmi:CARD=NVidia,DEV=3
HDA NVidia, HDMI 3
HDMI Audio Output
dmix:CARD=NVidia,DEV=3
HDA NVidia, HDMI 0
Direct sample mixing device
dmix:CARD=NVidia,DEV=7
HDA NVidia, HDMI 1
Direct sample mixing device
dmix:CARD=NVidia,DEV=8
HDA NVidia, HDMI 2
Direct sample mixing device
dmix:CARD=NVidia,DEV=9
HDA NVidia, HDMI 3
Direct sample mixing device
dsnoop:CARD=NVidia,DEV=3
HDA NVidia, HDMI 0
Direct sample snooping device
dsnoop:CARD=NVidia,DEV=7
HDA NVidia, HDMI 1
Direct sample snooping device
dsnoop:CARD=NVidia,DEV=8
HDA NVidia, HDMI 2
Direct sample snooping device
dsnoop:CARD=NVidia,DEV=9
HDA NVidia, HDMI 3
Direct sample snooping device
hw:CARD=NVidia,DEV=3
HDA NVidia, HDMI 0
Direct hardware device without any conversions
hw:CARD=NVidia,DEV=7
HDA NVidia, HDMI 1
Direct hardware device without any conversions
hw:CARD=NVidia,DEV=8
HDA NVidia, HDMI 2
Direct hardware device without any conversions
hw:CARD=NVidia,DEV=9
HDA NVidia, HDMI 3
Direct hardware device without any conversions
plughw:CARD=NVidia,DEV=3
HDA NVidia, HDMI 0
Hardware device with all software conversions
plughw:CARD=NVidia,DEV=7
HDA NVidia, HDMI 1
Hardware device with all software conversions
plughw:CARD=NVidia,DEV=8
HDA NVidia, HDMI 2
Hardware device with all software conversions
plughw:CARD=NVidia,DEV=9
HDA NVidia, HDMI 3
Hardware device with all software conversions
Quoted 3 lines
Regards,
Clemens
Thanks, Clemens. My code works with the "default" device. On the gnome-control-center, I am able to switch the default device and all works fine.
My problem is when I want my program to specify the device to use directly from the GUI: plughw:0,0. The device is in control of pulseaudio and does not release it until about 7 seconds go by with no audio. I tried a similar set up in vlc and the result was the same (vlc reported that it could not open the device), so I know it is not my code.
Let me know how can I control pulseaudio to close immediately the virtual device it opens.
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel