Ticket #655 (reopened defect)

Opened 12 months ago

Last modified 8 weeks ago

pulseaudio crashes when using a52

Reported by: pyropeter Owned by: lennart
Milestone: Component: daemon
Keywords: Cc:

Description

I use debian lenny, alsa 1.0.21, libasound2-plugins 1.0.20-1 when I start pulseaudio I get the following error:

E: alsa-sink.c: Assertion 'err != -11' failed at modules/alsa/alsa-sink.c:395, function try_recover(). Aborting.

/etc/pulse/daemon.conf is empty /etc/pulse/default.pa:

.nofail
.fail
load-module module-device-restore
load-module module-stream-restore
load-module module-card-restore
load-module module-augment-properties

load-module module-alsa-sink sink_name=alsa_surround device=enc format=s16 channels=4 tsched=1 rate=48000
set-default-sink alsa_surround

.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif
.ifexists module-esound-protocol-unix.so
load-module module-esound-protocol-unix
.endif
load-module module-native-protocol-unix
.ifexists module-gconf.so
.nofail
load-module module-gconf
.fail
.endif
load-module module-default-device-restore
load-module module-rescue-streams
load-module module-always-sink
load-module module-intended-roles
load-module module-suspend-on-idle
load-module module-console-kit
load-module module-position-event-sounds
load-module module-cork-music-on-phone

.asoundrc:

pcm.ac3enc {
    type a52
    rate 48000
    channels 4
}

pcm.enc {
    type plug
    slave {
        pcm ac3enc
    }
}

ctl.enc {
    type hw
    card 0
}

backtrace is appended

Attachments

pulse-bt.txt (13.8 kB) - added by pyropeter 12 months ago.
backtrace
pulseaudiooutput_rateconverter.txt (21.3 kB) - added by mcarans 2 months ago.

Change History

Changed 12 months ago by pyropeter

backtrace

follow-up: ↓ 2   Changed 12 months ago by lennart

  • status changed from new to closed
  • resolution set to elsewhere

Uh. This needs to posted as a bug against the a52 alsa module upstream. It shouldn't return EAGAIN on snd_pcm_commit().

in reply to: ↑ 1   Changed 2 months ago by mcarans

  • status changed from closed to reopened
  • resolution elsewhere deleted

Replying to lennart:

Uh. This needs to posted as a bug against the a52 alsa module upstream. It shouldn't return EAGAIN on snd_pcm_commit().

Do you know if a52 alsa module been fixed and if so, which version? I am getting this error with Lucid. See ticket: http://pulseaudio.org/ticket/837

  Changed 2 months ago by mcarans

https://bugtrack.alsa-project.org/alsa-bug/view.php?id=5054 Alsa chap called Raymond suggests this is a Pulseaudio bug.

  Changed 2 months ago by coling

This patch may fix it, but it may not be the "right" place to fix it.

http://thread.gmane.org/gmane.comp.audio.pulseaudio.general/6950

FWIW I doubt the a52 plugin in alsa has had much love of late, but I could be wrong.

  Changed 2 months ago by mcarans

I have found something that works for a while.

I add to .asoundrc:

# Rate Converter to 48kHz, needed for Pulseaudio it seems
pcm.Filter_RateConvert {
    type rate slave {
        pcm "Filter_A52Encode" rate 48000
    }
}

and in default.pa:

load-module module-alsa-sink device=Filter_RateConvert rate=48000 channels=6 tsched=0 sink_properties=device.description=SPDIF sink_name=SPDIF

Music plays through AC3 via SPDIF through Pulseaudio and Alsa, but when I close the application (eg. Rhythmbox music player), the SPDIF output "disappears".

I have attached a new back trace: pulseaudiooutput_rateconverter.txt

I think it's here where the Filter_RateConvert sink gets unloaded for some reason:

I: client.c: Freed 1 "Rhythmbox"
I: protocol-native.c: Connection died.
I: module.c: Unloading "module-alsa-sink" (index: #4).
D: module-always-sink.c: Autoloading null-sink as no other sinks detected.

How can I prevent this unloading?

Changed 2 months ago by mcarans

  Changed 2 months ago by mcarans

As the above is a different issue to the one I originally reported here, I have created a separate bug for it here: http://pulseaudio.org/ticket/839

  Changed 2 months ago by mcarans

I added to default.pa: load-module module-suspend-on-idle timeout=0

and it seemed to prevent the sink unloading with Rhythmbox. SO I could open and close Rhythmbox and playing through SPDIF in Dolby Digital would work,

However, when I load Oolite that uses libsdl then the unloading still seems to occur (so Oolite produces no sound).

  Changed 2 months ago by mcarans

I forced Pulseaudio not to rewind using:

pa_sink_set_max_rewind(u->sink, 0);

This seemed to fix it.

timeout=0 is no longer needed in default.pa: default.pa: load-module module-suspend-on-idle # timeout=0

However, there is still a need for a rate converter in asoundrc: # Rate Converter to 48kHz, needed for Pulseaudio it seems pcm.Filter_RateConvert {

type rate slave {

pcm "Filter_A52Encode" rate 48000

}

}

  Changed 2 months ago by mcarans

Finally I got it all working including a52 Pulseaudio profiles!

These are the steps on Ubuntu Lucid 10.04 LTS: 1. Open from Pulse source code: src/modules/alsa/alsa-sink.c 2. Replace: pa_sink_set_max_rewind(u->sink, u->hwbuf_size); with:

    if(strcmp(u->device_name, "a52") == 0) {
        pa_sink_set_max_rewind(u->sink, 0);
    } else {
        pa_sink_set_max_rewind(u->sink, u->hwbuf_size);
    }

3. Add Colin's patch:

             if (PA_UNLIKELY((sframes = snd_pcm_mmap_commit(u->pcm_handle, offset, frames)) < 0)) {

+                if (!after_avail && (int) sframes == -EAGAIN)
+                    break;
+
                 if ((r = try_recover(u, "snd_pcm_mmap_commit", (int) sframes)) == 0)
                     continue;

4. Compile and install Pulseaudio with udev support: make and sudo make install 5. Edit /usr/local/share/pulseaudio/alsa-mixer/profile-sets/default.conf: change a52:%f to a52 6. Copy /etc/pulse/daemon.conf to ~/.pulse/daemon.conf and ensure it has uncommented: default-sample-rate = 48000 7. Edit ~/.asoundrc 8. Put in it:

# Encode AC3 -> Directly on hardware
pcm.Filter_A52Encode {
    type a52
    bitrate 448
    channels 6
    card NVidia
}

# Rate Converter to 48kHz, needed for some applications
pcm.a52 {
    type rate
    slave {
        pcm "Filter_A52Encode"
        rate 48000
    }
}

9. Change NVidia to your card's name from: cat /proc/asound/cards 10. sudo alsa reload 11. Make sure you do not have a ~/.pulse/default.pa or if you do, that it is using load-module module-udev-detect to load Alsa sinks not load-module module-alsa-sink ... 12. pulseaudio -k 13. pulseaudio -D

  Changed 8 weeks ago by mcarans

New versions of Pulseaudio will be patched, but in the meantime, here are the revised steps for Ubuntu Lucid 10.04 LTS:

1. Open from Pulse source code: src/modules/alsa/alsa-sink.c

2. Replace: pa_sink_set_max_rewind(u->sink, u->hwbuf_size); with:
if (pa_alsa_pcm_is_hw(u->pcm_handle)) {
    pa_sink_set_max_rewind(u->sink, u->hwbuf_size);
} else {
    pa_log("Disabling rewind for device %s", u->device_name);
    pa_sink_set_max_rewind(u->sink, 0);
}

3. Replace: pa_sink_set_max_rewind_within_thread(u->sink, u->hwbuf_size); with:
if (pa_alsa_pcm_is_hw(u->pcm_handle)) {
    pa_sink_set_max_rewind_within_thread(u->sink, u->hwbuf_size);
} else {
    pa_log("Disabling rewind_within_thread for device %s", u->device_name);
    pa_sink_set_max_rewind_within_thread(u->sink, 0);
}

4. After line: if (PA_UNLIKELY((sframes = snd_pcm_mmap_commit(u->pcm_handle, offset, frames)) < 0)) { add:
if (!after_avail && (int) sframes == -EAGAIN)
    break;

5. Compile and install Pulseaudio with udev support

6. Copy /etc/pulse/daemon.conf to ~/.pulse/daemon.conf and ensure it has uncommented: default-sample-rate = 48000

7. Edit ~/.asoundrc and put in it:
pcm.a52 {
   @args [CARD]
   @args.CARD {
       type string
   }
   type rate
   slave {
       pcm {
           type a52
           bitrate 448
           channels 6
           card $CARD
       }
       rate 48000 #required somehow, otherwise nothing happens in PulseAudio
   }

8. sudo alsa reload

9. Make sure you do not have a ~/.pulse/default.pa or if you do, that it is using load-module module-udev-detect to load Alsa sinks not load-module module-alsa-sink ...

10. pulseaudio -k and pulseaudio -D
Note: See TracTickets for help on using tickets.