Closed Bug 780531 Opened 8 years ago Closed 7 years ago

libcubeb: no sound with alsa-plugins-oss

Categories

(Core :: Audio/Video, defect)

x86_64
FreeBSD
defect
Not set

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: jbeich, Unassigned)

References

(Depends on 1 open bug, )

Details

Attachments

(1 file, 2 obsolete files)

User Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:17.0) Gecko/17.0 Firefox/17.0
Build ID: 20120805233037

Steps to reproduce:

Play an .ogg file or view HTML5 video with ALSA backend on FreeBSD.

Tried both with linux-f10-alsa-plugins-oss-1.0.21_3 (via linuxulator) and alsa-plugins-1.0.25 (native).


Actual results:

It plays as usual but there is no sound.


Expected results:

Play with sound like when using media.use_cubeb=false.
In linuxulator case I've tested against official Nightly linux snapshot.
test_tone from cubeb on github does produce a tone but later crashes

$ ./test/test_tone
Assertion failed: (wrote >= 0 && wrote == got), function cubeb_refill_stream, file src/cubeb_alsa.c, line 307.
Abort
Hmm, after a bit more testing I have sound with linux firefox. What doesn't work is

    #!/bin/sh
    exec /usr/local/lib/linux-firefox/firefox "$@"

that www/linux-firefox port installs. Either invoking the binary directly or adding LD_LIBRARY_PATH to the script helps. Not sure why libcubeb may affect it.

However, there is still no sound with FreeBSD build.
Oops, that was with 10.0.6 (esr). Ignore previous post.
Thanks for filing this.

(In reply to Jan Beich from comment #2)
> test_tone from cubeb on github does produce a tone but later crashes

Okay, this provides a big clue.  test_tone uses signed 16-bit samples, Firefox uses 32-bit floats.  snd_pcm_set_params in cubeb_stream_init is probably failing for that reason.

> $ ./test/test_tone
> Assertion failed: (wrote >= 0 && wrote == got), function
> cubeb_refill_stream, file src/cubeb_alsa.c, line 307.

This'll be a different bug.  Can you use gdb (or add some printf logging) to find out what 'wrote' and 'got' are?
Status: UNCONFIRMED → NEW
Ever confirmed: true
To be clear, Firefox switched to 32-bit floats with libcubeb, which is why the old libsydneyaudio backend works.
(In reply to Matthew Gregan [:kinetik] from comment #5) 
> > $ ./test/test_tone
> > Assertion failed: (wrote >= 0 && wrote == got), function
> > cubeb_refill_stream, file src/cubeb_alsa.c, line 307.
> 
> This'll be a different bug.  Can you use gdb (or add some printf logging) to
> find out what 'wrote' and 'got' are?

#3  0x000000080081f2bf in cubeb_refill_stream (stm=0x801c18180) at src/cubeb_alsa.c:307
        wrote = 4384
        revents = 4
        avail = 12000
        draining = 0
        r = 0
        got = 12000
        p = (void *) 0x802010000
(In reply to Jan Beich from comment #7)
> #3  0x000000080081f2bf in cubeb_refill_stream (stm=0x801c18180) at
> src/cubeb_alsa.c:307
>         wrote = 4384
>         revents = 4
>         avail = 12000
>         draining = 0
>         r = 0
>         got = 12000
>         p = (void *) 0x802010000

Thanks.  avail is supposed to be the amount writable, so I don't know why a short write is happening.  It's probably a bug in the alsa-oss plugin.  The fact that it's returning avail=12000 during playback is pretty suspicious... that suggests the entire ALSA buffer is empty.
test_tone doesn't crash on assert if I disable FreeBSD-specific patch (authored by ariff@freebsd.org).
http://www.freebsd.org/cgi/cvsweb.cgi/ports/audio/alsa-plugins/files/alsa-plugins.patch

Note, I already had one regression with firefox when avg@freebsd.org tried to remove SNDCTL_DSP_GETIPTR workaround in it.
(In reply to Matthew Gregan [:kinetik] from comment #6)
> To be clear, Firefox switched to 32-bit floats with libcubeb, which is why
> the old libsydneyaudio backend works.

After looking at nsBuiltinDecoderReader.h I decided to try MOZ_TREMOR build - it *has* sound.
Right, the Tremor/ARM code uses sint16 since floats are slow on ARM.  You might not want to use Tremor on desktops system for audio quality reasons, but I'm not sure how much difference it really makes.

Handling formats that aren't supported by the audio backend is effectively bug 706327 and bug 704993.  In the future, we'll open the audio backend using the OS's preferred format/configuration, and resample/remix the samples as necessary.

Before all of that matters, the issue in comment 8 will need to be fixed.  I don't know OSS's API, so I can't say much about the patch linked in comment 9 right now.

What's the common audio configuration (if there is one) on FreeBSD systems?  It'd be nice to have alsa-plugins-oss working, but if most people are using PulseAudio, it makes more sense to spend time getting the PA backend (or, at least, the ALSA backend with alsa-plugins-pulse) working.  Is the sndio backend contributed for OpenBSD usable on FreeBSD too?
(In reply to Matthew Gregan [:kinetik] from comment #11)
> Before all of that matters, the issue in comment 8 will need to be
> fixed.  I don't know OSS's API, so I can't say much about the patch
> linked in comment 9 right now.

That could be the port's bug. Otherwise, assert would trigger under
linuxulator, too.

> What's the common audio configuration (if there is one) on FreeBSD systems? 

OSS4 API, sound(4) in GENERIC kernel.

# see default dependencies/options
http://www.freshports.org/www/firefox

> It'd be nice to have alsa-plugins-oss working, but if most people are
> using PulseAudio,

PulseAudio can sometimes be found on a Gnome desktop. It's a reasonable
alternative if there is no audio backend for a particular system.

gstreamer-plugins-good can also be often found. Besides it's used by
KDE4 desktop (phonon) which is default for PC-BSD.

GStreamer has advantage of already being used by Firefox for viewing
HTML5 H264 video. I was a bit surprised that audio didn't go through
its sound plugins, too.

> Is the sndio backend contributed for OpenBSD usable on FreeBSD too?

Not sure, there is only Sun Audio backend in libsndio. It can probably
be used on NetBSD.
Depends on: 782507
Blocks: 807683
Attached patch temporary hack (obsolete) — Splinter Review
Attachment #677633 - Flags: review?(kinetik)
Attachment #677633 - Flags: review?(kinetik)
The original patch broke with the recent landing of bug #879651.
This new hack is just an unbitrotted version of the original.
Attachment #677633 - Attachment is obsolete: true
It seems I haven't mastered ~/.asoundrc. There's 'plug' plugin that lets alsa-lib convert sample type, rate, etc. automatically. Tested on both firefox and linux-firefox ports.

http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html#pcm_plugins_plug
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → WORKSFORME
See Also: → 1021761
Attached file sorry, wrong bug :( (obsolete) —
I've made a patch for libcubeb to load libasound.so with dlopen/dlsym in the same manner the pulseaudio backend does this.
It doesn't test if libasound is actually capable to output sound though.

Two problems with this:

1) I havn't tested if I broke sound output with ALSA (I don't have ALSA support in my kernel).

2)I'm not very good with autotools so I don't know how to prevent libcubeb from linking with libasound.so. I've added the MOZ_ALSA_LIBS="" to configure.in for testing purposes.
Attachment #8486766 - Attachment description: Make ALSA optional on linux → sorry, wrong bug :(
Attachment #8486766 - Attachment is obsolete: true
Attachment #8486766 - Attachment is patch: false
You need to log in before you can comment on or make changes to this bug.