mikebrady / shairport-sync

AirPlay and AirPlay 2 audio player
Other
7.14k stars 565 forks source link

alsa: error -16 ("Resource busy") opening alsa device when playing to "dmix" device when running in docker #1073

Closed bedrin closed 3 years ago

bedrin commented 3 years ago

I'm trying to combine shairport-sync with bluealsa-aplay on a single Raspberry PI box. I can get them working independently and the mixer itself works fine (I can combine aplay of local file with bluealsa-aplay)

However I cannot get shairport-sync working with my mixed.

Here's my asound.conf:

pcm.dmixer {
    type dmix
    ipc_key 1024
    ipc_key_add_uid false
    ipc_perm 0666
    slave {
        pcm "hw:0,0"
        period_time 0
        period_size 1024
        buffer_size 8192
        rate 44100
    }

    bindings {
        0 0
        1 1
     }
}

pcm.dsp0 {
    type plug
    slave.pcm "dmixer"
}

pcm.!default {
    type plug
    slave.pcm "dmixer"
}

pcm.default {
    type plug
    slave.pcm "dmixer"
}

ctl.mixer0 {
    type hw
    card 0
}

aplay -L output:

aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
dmixer
dsp0
default
sysdefault:CARD=sndrpihifiberry
    snd_rpi_hifiberry_dacplus, HiFiBerry DAC+ HiFi pcm512x-hifi-0
    Default Audio Device
dmix:CARD=sndrpihifiberry,DEV=0
    snd_rpi_hifiberry_dacplus, HiFiBerry DAC+ HiFi pcm512x-hifi-0
    Direct sample mixing device
dsnoop:CARD=sndrpihifiberry,DEV=0
    snd_rpi_hifiberry_dacplus, HiFiBerry DAC+ HiFi pcm512x-hifi-0
    Direct sample snooping device
hw:CARD=sndrpihifiberry,DEV=0
    snd_rpi_hifiberry_dacplus, HiFiBerry DAC+ HiFi pcm512x-hifi-0
    Direct hardware device without any conversions
plughw:CARD=sndrpihifiberry,DEV=0
    snd_rpi_hifiberry_dacplus, HiFiBerry DAC+ HiFi pcm512x-hifi-0
    Hardware device with all software conversions

I've removed all configuration of shairport-sync I had so just using default alsa setup.

         0.028327060 "shairport.c:1636" Started!
         0.000277760 "shairport.c:1660" software version: "3.3.6-OpenSSL-Avahi-ALSA-pipe-soxr-metadata-sysconfdir:/usr/local/etc"
         0.000908070 "shairport.c:1666" log verbosity is 1.
         0.000446301 "audio_alsa.c:1018" alsa: alsa_maximum_stall_time of 0.200000 sec.
         0.000486978 "audio_alsa.c:1300" alsa: disable_standby_mode is "never".
         0.000102916 "audio_alsa.c:1304" alsa: disable_standby_mode_silence_threshold is 0.040000 seconds.
         0.000441093 "audio_alsa.c:1306" alsa: disable_standby_mode_silence_scan_interval is 0.004000 seconds.
         0.000542082 "audio_alsa.c:1346" alsa: output device name is "default".
         0.000476821 "shairport.c:1714" disable resend requests is off.
         0.000199375 "shairport.c:1715" diagnostic_drop_packet_fraction is 0.000000. A value of 0.0 means no packets will be dropped deliberately.
         0.000264687 "shairport.c:1718" statistics_requester status is 0.
         0.000182291 "shairport.c:1723" rtsp listening port is 5000.
         0.000074791 "shairport.c:1724" udp base port is 6001.
         0.000234947 "shairport.c:1725" udp port range is 10.
         0.000205208 "shairport.c:1726" player name is "Marshall".
         0.000079063 "shairport.c:1727" backend is "(null)".
         0.000246509 "shairport.c:1728" run_this_before_play_begins action is "(null)".
         0.000241041 "shairport.c:1729" run_this_after_play_ends action is "(null)".
         0.000351197 "shairport.c:1730" wait-cmd status is 0.
         0.000076094 "shairport.c:1731" run_this_before_play_begins may return output is 0.
         0.000517603 "shairport.c:1732" run_this_if_an_unfixable_error_is_detected action is "(null)".
         0.000256561 "shairport.c:1733" run_this_before_entering_active_state action is  "(null)".
         0.000304948 "shairport.c:1734" run_this_after_exiting_active_state action is  "(null)".
         0.000237186 "shairport.c:1735" active_state_timeout is  10.000000 seconds.
         0.000363229 "shairport.c:1736" mdns backend "avahi".
         0.000146145 "shairport.c:1738" interpolation setting is "auto".
         0.000172239 "shairport.c:1741" interpolation soxr_delay_threshold is 30.
         0.000229479 "shairport.c:1742" resync time is 0.050000 seconds.
         0.000178593 "shairport.c:1743" allow a session to be interrupted: 1.
         0.000079271 "shairport.c:1744" busy timeout time is 120.
         0.000281509 "shairport.c:1745" drift tolerance is 0.001995 seconds.
         0.000085261 "shairport.c:1746" password is "(null)".
         0.000240936 "shairport.c:1747" ignore_volume_control is 0.
         0.000075990 "shairport.c:1751" volume_max_db is not set
         0.000220780 "shairport.c:1752" volume range in dB (zero means use the range specified by the mixer): 0.
         0.000261771 "shairport.c:1754" volume_range_combined_hardware_priority (1 means hardware mixer attenuation is used first) is 0.
         0.000377551 "shairport.c:1757" playback_mode is 0 (0-stereo, 1-mono, 1-reverse_stereo, 2-both_left, 3-both_right).
         0.000280155 "shairport.c:1759" disable_synchronization is 0.
         0.000240989 "shairport.c:1760" use_mmap_if_available is 0.
         0.000114687 "shairport.c:1761" output_format automatic selection is enabled.
         0.002309890 "shairport.c:1765" output_rate automatic selection is enabled.
         0.000357030 "shairport.c:1769" audio backend desired buffer length is 0.200000 seconds.
         0.000208385 "shairport.c:1771" audio_backend_buffer_interpolation_threshold_in_seconds is 0.120000 seconds.
         0.000145781 "shairport.c:1773" audio backend latency offset is 0.000000 seconds.
         0.000208333 "shairport.c:1774" audio backend silence lead-in time is -1.000000 seconds. A value -1.0 means use the default.
         0.000155364 "shairport.c:1776" zeroconf regtype is "_raop._tcp".
         0.000118697 "shairport.c:1777" decoders_supported field is 3.
         0.000098281 "shairport.c:1778" use_apple_decoder is 1.
         0.000099636 "shairport.c:1779" alsa_use_hardware_mute is 0.
         0.000124114 "shairport.c:1783" no special mdns service interface was requested.
         0.000376041 "shairport.c:1786" configuration file name "conf/shairport.conf" resolves to "/conf/shairport.conf".
         0.000168176 "shairport.c:1793" metadata enabled is 1.
         0.000073750 "shairport.c:1794" metadata pipename is "/tmp/shairport-sync-metadata".
         0.000175677 "shairport.c:1795" metadata socket address is "(null)" port 0.
         0.000130885 "shairport.c:1797" metadata socket packet size is "500".
         0.000124895 "shairport.c:1798" get-coverart is 1.
         0.000250989 "shairport.c:1816" loudness is 0.
         0.000101614 "shairport.c:1817" loudness reference level is -20.000000
         0.009488308 "mdns_avahi.c:371" avahi_dacp_monitor_start Avahi DACP monitor successfully started
         1.496919910 "shairport.c:198" "soxr" interpolation has been chosen.
         7.539656410 "rtsp.c:997" Connection 1: SETUP DACP-ID "84AECB0A40458A74" from fe80::cbe:e897:165a:af5c to fe80::b1ef:d077:4a21:7a0d with UDP ports Control: 6001, Timing: 6002 and Audio: 6003.
         0.014165223 "audio_alsa.c:442" *warning: alsa: error -16 ("Resource busy") opening alsa device "default".
mikebrady commented 3 years ago

I’m afraid I don’t have an angle on this. If you use aplay to play something to the default when it’s set up like that, does it work?

bedrin commented 3 years ago

I’m afraid I don’t have an angle on this. If you use aplay to play something to the default when it’s set up like that, does it work?

Yes, it does. I can run bluealsa-aplay and just aplay against default device simultaneously and it mixes the sound correctly without any errors

bedrin commented 3 years ago

I think I've narrowed the issue down to docker. When I'm calling aplay -L inside the container it doesn't show my dmixer at all

~ # aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
sysdefault:CARD=sndrpihifiberry
    snd_rpi_hifiberry_dacplus, HiFiBerry DAC+ HiFi pcm512x-hifi-0
    Default Audio Device

I am using mikebrady/shairport-sync:3.3.7rc2 image. Had to install alsa-utils manually to call aplay -L. Tried mounting /etc/asound.conf from my host but it didn't help

bedrin commented 3 years ago

After some googling it turned out it's a common issue with docker. I guess I should switch to Pulse Audio or just use shairport-sync without docker.

Closing this issue as it seems to have nothing to do with shairport-sync.

bedrin commented 2 years ago

Sorry for using this issue as a notebook - I haven't had a chance to return to this issue yet. But it looks like it should be possible. Keywords are "--ipc=host" for running docker container and "ipc_key / ipc_perm" in asound.conf

mikebrady commented 2 years ago

Many thanks -- your "notebook" might be useful to others!

StuartIanNaylor commented 1 year ago

Yeah in your docker run just make sure you have

--ipc=host \
-v "/etc/asound.conf:/etc/asound.conf:ro" \

For my respeaker 2mic card the only thing that was missing from install was the ipc_perm 0666 but it looks like this

# The IPC key of dmix or dsnoop plugin must be unique
# If 555555 or 666666 is used by other processes, use another one

# use samplerate to resample as speexdsp resample is bad
defaults.pcm.rate_converter "samplerate"

pcm.!default {
    type asym
    playback.pcm "playback"
    capture.pcm "capture"
}

pcm.playback {
    type plug
    slave.pcm "dmixed"
}

pcm.capture {
    type plug
    slave.pcm "array"
}

pcm.dmixed {
    type dmix
    slave.pcm "hw:seeed2micvoicec"
    ipc_key 555555
    ipc_perm 0666
}

pcm.array {
    type dsnoop
    slave {
        pcm "hw:seeed2micvoicec"
        channels 2
    }
    ipc_key 666666
    ipc_perm 0666
}

speaker-test on the host cli and also in the container and I get a double mix on the same device (2mic) output