Audio breaks up and pulseaudio eventually crashes with Alsa a52 (ac3) plugin (Ubuntu 13.04)

Bug #1188425 reported by Artur de Araújo
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pulseaudio (Ubuntu)
Expired
Undecided
Unassigned

Bug Description

I am encoding all audio in AC3 and sending it to my Logitech Z-5500 speakers through the SPDIF out jack on my laptop. Audio works fine for a while until it breaks up randomly and pulseaudio eventually crashes. By looking to the pulseaudio logs one can see some buffer underruns. I also tested with the 3.9.4 mainline kernel though I am not sure this issue is driver related. The result is always the same! I have this in /usr/share/alsa/alsa.conf.d/a52.conf

pcm.a52 {
 @args [CARD]
 @args.CARD {
  type string
 }
 type rate
 slave {
  pcm {
   type a52
   format S16_LE # S16_LE, S16_BE
   channels 6 # 2, 4, 6
   bitrate 640 # 192, 224, 256, 320, 384, 448, 512, 576, 640
   card $CARD
  }
  rate 48000 # 44100, 48000
 }
}

One other thing I tried was the dcaenc-2 alsa plugin from this web page http://aepatrakov.narod.ru/index/0-2 and this plugin appears to not have the same problem. The disadvantage of the dca plugin is that it needs a lot more processing power! So I would prefer the a52 plugin if it worked flawlessly.

These are the answers to the first two questions:

1)
Ubuntu 13.04

2)
libasound2-plugins-extra:
  Installed: 1.0.25-2ubuntu3
  Candidate: 1.0.25-2ubuntu3
  Version table:
 *** 1.0.25-2ubuntu3 0
        500 http://pt.archive.ubuntu.com/ubuntu/ raring/universe amd64 Packages
        100 /var/lib/dpkg/status

Revision history for this message
Artur de Araújo (artur-stat) wrote :
Revision history for this message
Artur de Araújo (artur-stat) wrote :

This is the pulseadio log where you can see the dca alsa plugin doing it's job. There is no registry of audio breaks!

Revision history for this message
Raymond (superquad-vortex2) wrote :

I: [alsa-sink] alsa-sink.c: Starting playback.
I: [alsa-sink] (alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_START failed (-77)
D: [alsa-sink] alsa-util.c: Got POLLERR from ALSA
D: [alsa-sink] alsa-util.c: Got POLLOUT from ALSA
D: [alsa-sink] alsa-util.c: PCM state is RUNNING
I: [alsa-sink] alsa-sink.c: Starting playback.
I: [alsa-sink] (alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_START failed (-77)
D: [alsa-sink] sink-input.c: Requesting rewind due to uncorking
D: [alsa-sink] alsa-sink.c: Requested to rewind 0 bytes.
D: [alsa-sink] alsa-sink.c: Mhmm, actually there is nothing to rewind.
D: [pulseaudio] module-suspend-on-idle.c: Sink alsa_output.pci-0000_00_1b.0.iec958-ac3-surround-51 becomes busy.
D: [alsa-sink] protocol-native.c: Requesting rewind due to rewrite.
D: [alsa-sink] alsa-sink.c: Requested to rewind 0 bytes.
D: [alsa-sink] alsa-sink.c: Mhmm, actually there is nothing to rewind.
D: [alsa-sink] protocol-native.c: Requesting rewind due to rewrite.
D: [alsa-sink] alsa-sink.c: Requested to rewind 0 bytes.
D: [alsa-sink] alsa-sink.c: Mhmm, actually there is nothing to rewind.
D: [alsa-sink] protocol-native.c: Requesting rewind due to rewrite.
D: [alsa-sink] alsa-sink.c: Requested to rewind 0 bytes.

Revision history for this message
Artur de Araújo (artur-stat) wrote :

Updated alsa-lib and alsa-plugins to latest version 1.0.27. Unfortunately the a52 plugin makes pulseaudio crash immediately. Had to compile the alsa-plugins against libav 9 instead of libav 0.8.6 (that comes with raring) to make it work! Unfortunately the problem with audio breaking up persists. The pulseaudio log is attached.

Revision history for this message
Artur de Araújo (artur-stat) wrote :

This also appears in the logs at least once:

D: [alsa-sink-] protocol-native.c: Requesting rewind due to end of underrun.
D: [alsa-sink-] protocol-native.c: Requesting rewind due to end of underrun.
D: [alsa-sink-] protocol-native.c: Requesting rewind due to end of underrun.
D: [alsa-sink-] sink-input.c: Requesting rewind due to uncorking
D: [alsa-sink-] alsa-sink.c: Requested to rewind 0 bytes.
D: [pulseaudio] module-suspend-on-idle.c: Sink alsa_output.pci-0000_00_1b.0.iec958-ac3-surround-51 becomes busy, resuming.
D: [alsa-sink-] alsa-sink.c: Mhmm, actually there is nothing to rewind.
E: [alsa-sink-] alsa-sink.c: ALSA woke us up to write new data to the device, but there was actually nothing to write!
E: [alsa-sink-] alsa-sink.c: Most likely this is a bug in the ALSA driver '(null)'. Please report this issue to the ALSA developers.
E: [alsa-sink-] alsa-sink.c: We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail() returned 0 or another value < min_avail.

Revision history for this message
Raymond (superquad-vortex2) wrote :

I: [alsa-sink] alsa-sink.c: Starting playback.
 I: [alsa-sink] (alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_START failed (-77)

snd_pcm_start already fail but pulseaudio ignore this fatal error

Revision history for this message
Raymond (superquad-vortex2) wrote :

do a52 require any specific (minimum) amount of data to be written before you start the hardware decoder ?

Revision history for this message
Artur de Araújo (artur-stat) wrote :
Download full text (5.6 KiB)

Thanks for giving attention to my problem.

The hardware decoder is integrated in the logitech Z-5500 speakers. I don't have knowledge of any specific limit on the amount of data. There is however information regarding a maximum hw buffer size on the pulseaudio logs:

D: [pulseaudio] alsa-util.c: Trying a52:0 with SND_PCM_NO_AUTO_FORMAT ...
D: [pulseaudio] alsa-util.c: Managed to open a52:0
D: [pulseaudio] alsa-util.c: snd_pcm_hw_params_set_format(Signed 32 bit Little Endian) failed: Invalid argument
D: [pulseaudio] alsa-util.c: snd_pcm_hw_params_set_format(Signed 32 bit Big Endian) failed: Invalid argument
D: [pulseaudio] alsa-util.c: snd_pcm_hw_params_set_format(Float 32 bit Little Endian) failed: Invalid argument
D: [pulseaudio] alsa-util.c: snd_pcm_hw_params_set_format(Float 32 bit Big Endian) failed: Invalid argument
D: [pulseaudio] alsa-util.c: snd_pcm_hw_params_set_format(Signed 32 bit Little Endian) failed: Invalid argument
D: [pulseaudio] alsa-util.c: snd_pcm_hw_params_set_format(Signed 32 bit Big Endian) failed: Invalid argument
D: [pulseaudio] alsa-util.c: snd_pcm_hw_params_set_format(Signed 24 bit Little Endian) failed: Invalid argument
D: [pulseaudio] alsa-util.c: snd_pcm_hw_params_set_format(Signed 24 bit Big Endian) failed: Invalid argument
D: [pulseaudio] alsa-util.c: snd_pcm_hw_params_set_format(Signed 24 bit Little Endian in 3bytes) failed: Invalid argument
D: [pulseaudio] alsa-util.c: snd_pcm_hw_params_set_format(Signed 24 bit Big Endian in 3bytes) failed: Invalid argument
D: [pulseaudio] alsa-util.c: Maximum hw buffer size is 320 ms
D: [pulseaudio] alsa-util.c: Set buffer size first (to 3840 samples), period size second (to 480 samples).
I: [pulseaudio] alsa-util.c: Device a52:0 doesn't support sample format s32le, changed to s16le.
I: [pulseaudio] alsa-sink.c: Successfully opened device a52:0.
I: [pulseaudio] alsa-sink.c: Selected mapping 'Digital Surround 5.1 (IEC958/AC3)' (iec958-ac3-surround-51).
I: [pulseaudio] alsa-sink.c: Cannot enable timer-based scheduling, falling back to sound IRQ scheduling.
I: [pulseaudio] alsa-sink.c: Successfully enabled mmap() mode.
I: [pulseaudio] (alsa-lib)control.c: Invalid CTL a52:0
I: [pulseaudio] alsa-util.c: Unable to attach to mixer a52:0: No such file or directory
I: [pulseaudio] alsa-sink.c: Failed to find a working mixer device.

The dca plugin reports the same number of samples. Here is what I get from the dca plugin (heavier cpu usage):

D: [pulseaudio] reserve-wrap.c: Successfully create reservation lock monitor for device 'Audio0'
D: [pulseaudio] alsa-util.c: Trying dca:0 with SND_PCM_NO_AUTO_FORMAT ...
D: [pulseaudio] alsa-util.c: Managed to open dca:0
I: [pulseaudio] alsa-util.c: Trying to disable ALSA period wakeups, using timers only
D: [pulseaudio] alsa-util.c: Maximum hw buffer size is 341 ms
D: [pulseaudio] alsa-util.c: Set buffer size first (to 96000 samples), period size second (to 96000 samples).
I: [pulseaudio] alsa-util.c: ALSA period wakeups disabled
I: [pulseaudio] alsa-sink.c: Successfully opened device dca:0.
I: [pulseaudio] alsa-sink.c: Selected mapping 'Digital Surround 5.1 (IEC958/DTS)' (iec958-dts-surround-51).
I: [pulseaudio] alsa-sink.c: Successfully ena...

Read more...

Revision history for this message
Artur de Araújo (artur-stat) wrote :

I added this to the a52.conf file located in /us/share/alsa/alsa.conf.d/a52.conf:

ctl.a52 {
 @args [ CARD ]
 @args.CARD {
  type string
  default 0
 }
 type hw
 card $CARD
}

And now I get this from pulseaudio:

I: [pulseaudio] alsa-sink.c: Successfully opened device a52:0.
I: [pulseaudio] alsa-sink.c: Selected mapping 'Digital Surround 5.1 (IEC958/AC3)' (iec958-ac3-surround-51).
I: [pulseaudio] alsa-sink.c: Cannot enable timer-based scheduling, falling back to sound IRQ scheduling.
I: [pulseaudio] alsa-sink.c: Successfully enabled mmap() mode.
I: [pulseaudio] alsa-util.c: Successfully attached to mixer 'a52:0'

Previously pulseaudio reported this:

I: [pulseaudio] alsa-sink.c: Successfully opened device a52:0.
I: [pulseaudio] alsa-sink.c: Selected mapping 'Digital Surround 5.1 (IEC958/AC3)' (iec958-ac3-surround-51).
I: [pulseaudio] alsa-sink.c: Cannot enable timer-based scheduling, falling back to sound IRQ scheduling.
I: [pulseaudio] alsa-sink.c: Successfully enabled mmap() mode.
I: [pulseaudio] (alsa-lib)control.c: Invalid CTL a52:0
I: [pulseaudio] alsa-util.c: Unable to attach to mixer a52:0: No such file or directory
I: [pulseaudio] alsa-sink.c: Failed to find a working mixer device.

This is an improvement that didn't resolved the audio breaking. The rest of the log file still looks the same!

Revision history for this message
Artur de Araújo (artur-stat) wrote :

I think I found a way to at least minimize this issue. From the pulseaudio logs I found that for the AC3 plugin it isn't using the default fragment settings from /etc/pulse/daemon.conf which are:

default-fragments = 8
default-fragment-size-msec = 10

Instead it adjusts to the nearest latency with a default fragment size of 32 ms. So 8*10=80 ms. 32*3=96 ms is the nearest latency. It is using a default fragment size of 32 ms no matter what size I set in daemon.conf. This is what I am talking about:

I: [pulseaudio] alsa-sink.c: Using 3.0 fragments of size 18432 bytes (32.00ms), buffer size is 55296 bytes (96.00ms)
I: [pulseaudio] alsa-sink.c: Disabling rewind for device a52:0

I tried to lower the number of fragments and found that the frequency of the audio drops increases. It might be too frequent actually. So increasing the number of fragments should minimize the problem, right? I can increase the number of fragments to the maximum hw buffer size reported:

D: [pulseaudio] alsa-util.c: Maximum hw buffer size is 320 ms
D: [pulseaudio] alsa-util.c: Set buffer size first (to 3840 samples), period size second (to 480 samples).

So if I set 10 or more fragments it will use 10 fragments. However when I set a too large buffer size (at leat 8 fragments) applications that play through the alsa plugin for pulseaudio will cause noise. So now I am using 5 fragments with good results so far. Here is what I have written inside daemon.conf:

default-fragments = 5 # 8
default-fragment-size-msec = 32 # 10

This yields a buffer size of 160 ms. An increase of 64 ms from the original 96 ms.

Revision history for this message
SpmP (scarletpimpernal) wrote :

Artur Agostinho Araújo :
 Did you ever find a solution?
In 14.04, with the fragment sizes you suggest this is better, but still crashes periodically. This plugin is amazing! Especially if I could control how many channels were upsampled on a per application basis (ie 2.0 -> 2.1, not 2.0 -> 5.1)
 Banshee in particular crashes PA with a52.

Revision history for this message
Artur de Araújo (artur-stat) wrote :

Yes this bug affects all ubuntu releases since at least 13.04
No I haven't found a solution yet. This was the best I came up with. You can try to increase the default-fragments number but that will increase latency. A number of 5 is a compromise between latency and probability of crash.
I suggest you use Alexander Patrakov's dca alsa plugin

http://aepatrakov.narod.ru/index/0-2

Its main disadvantage is the higher cpu usage! However it doesn't suffer from this bug.

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Thank you for reporting this bug to Ubuntu.
Ubuntu 13.04 (raring) reached end-of-life on January 27, 2014.

See this document for currently supported Ubuntu releases:
https://wiki.ubuntu.com/Releases

We appreciate that this bug may be old and you might not be interested in discussing it any more. But if you are then please upgrade to the latest Ubuntu version and re-test.

Changed in pulseaudio (Ubuntu):
status: New → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for pulseaudio (Ubuntu) because there has been no activity for 60 days.]

Changed in pulseaudio (Ubuntu):
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.