hzeller / gmrender-resurrect

Resource efficient UPnP/DLNA renderer, optimal for Raspberry Pi, CuBox or a general MediaServer. Fork of GMediaRenderer to add some features to make it usable.
GNU General Public License v2.0
851 stars 206 forks source link

disconnected client but device audio is still not relased #262

Closed MG-Sky closed 1 year ago

MG-Sky commented 1 year ago

Hello, thanks for such tool it helps me a lot but i found one problem with it. I have tested it with my audio application on my phone and homeasssitant so:

  1. when homeassitant sends any audio to the gstreamer on my raspberry i can hear sound and that 's fine but i see the audio device on raspberry is not released - i see the audio device is still locked by gstreamer on ubuntu. and any no other process can access the audio, i have to restart service.
  2. when i use my audio app it works fine and i have noticed that if i disconnect from the upnp server in the app, audio device on PI is released but when i kill the audio app. the same happens the audio isn't released.

is there any way to determine if connection is still up and or kill after the XX of idle?

mill1000 commented 1 year ago

If you're using ALSA, you could enable dmix on the audio device to allow multiple applications to access it.

e.g. In /etc/asound.conf or ~/.asoundrc, add the following to make the default device be dmix.

pcm.!default {
  type plug
  slave.pcm "dmix"
}
MG-Sky commented 1 year ago

ok i have added entry to asound.conf and configured: /etc/default/gmediarender/ to:

Configuration for gmediarender

ENABLED=1
# User and group the daemon will be running as.
DAEMON_USER="user:pulse-access"

# Device name as it will be advertised to and shown in the UPnP controller UI.
# Some string that helps you recognize the player, e.g. "Livingroom Player"
UPNP_DEVICE_NAME="Streamer on $(hostname)"

# Initial volume in decibel. 0.0 is 'full volume', -10 correspondents to '75' on
# the exported volume scale (Note, this does not change the ALSA volume, only
# internal to gmrender. So make sure to leave the ALSA volume always to 100%).
INITIAL_VOLUME_DB=-6

# If you explicitly choose a specific ALSA device here (find them with 'aplay -L'), then
# gmediarenderer will use that ALSA device to play audio.
# Otherwise, whatever default is configured for gstreamer for the '$DAEMON_USER' is
# used.
#ALSA_DEVICE="ssdefault"
ALSA_DEVICE="dmix:CARD=Device,DEV=0"

# You can pass extra arguments to the daemon
# For example, you can specify a logfile with this line
# (though you need to ensure correct permissions for a log file yourself.)

DAEMON_EXTRA_ARGS="--mime-filter audio  --logfile /var/log/gmediarender.log "****

then it works but... then pulseaudio BT doesn't play nothing:

/dev/snd/controlC1:  mike       2276 F.... (user)pulseaudio
/dev/snd/pcmC1D0p:   mike       2649 F...m (user)gmediarender
/dev/snd/timer:      mike       2649 f.... (user)gmediarender

when i play pulse audio:

ERROR [2023-07-02 14:08:17.596035 | gstreamer] sink: Error: Could not open audio device for playback. (Debug: ../ext/alsa/gstalsasink.c(874): gst_alsasink_open (): /GstAlsaSink:sink: Playback open error on device 'dmix:CARD=Device,DEV=0': Invalid argument) ERROR [2023-07-02 14:08:17.598285 | gstreamer] setting play state failed (2) ERROR [2023-07-02 14:08:17.598789 | upnp] upnp_set_error: Playing failed (704)

pulseaudio settings: load-module module-alsa-sink

when Gmedia stream enabled:

 Jul  2 14:10:31 pi-zero pulseaudio[2276]: Volume not changing
Jul  2 14:10:31 pi-zero pulseaudio[2276]: Hmm, no streams around, trying to vacuum.
Jul  2 14:10:31 pi-zero pulseaudio[2276]: bluez_source.40_EC_99_0F_C8_45.a2dp_source: state: SUSPENDED -> UNLINKED
Jul  2 14:10:31 pi-zero pulseaudio[2276]: IO thread shutdown requested, stopping cleanly
Jul  2 14:10:31 pi-zero pulseaudio[2276]: IO thread shutting down
Jul  2 14:10:31 pi-zero pulseaudio[2276]: bluez_card.40_EC_99_0F_C8_45: active_profile: a2dp_source -> off
Jul  2 14:10:31 pi-zero pulseaudio[2276]: Dropped redundant event due to change event.
Jul  2 14:10:31 pi-zero pulseaudio[2276]: Setting port unknown-input to status unknown
Jul  2 14:10:31 pi-zero pulseaudio[2276]: Dropped redundant event due to change event.
Jul  2 14:10:31 pi-zero pulseaudio[2276]: Properties changed in transport /org/bluez/hci0/dev_40_EC_99_0F_C8_45/fd2
Jul  2 14:10:36 pi-zero pulseaudio[2276]: alsa_output.usb-GeneralPlus_USB_Audio_Device-00.analog-stereo: suspend_cause: (none) -> IDLE
Jul  2 14:10:36 pi-zero pulseaudio[2276]: alsa_output.usb-GeneralPlus_USB_Audio_Device-00.analog-stereo.monitor: suspend_cause: (none) -> IDLE
Jul  2 14:10:36 pi-zero pulseaudio[2276]: Hmm, no streams around, trying to vacuum.
mill1000 commented 1 year ago

It appears you're using PulseAudio. In that case, you shouldn't use what I provided above. I haven't used this project with PA, so my advice is suspect.

That said... I think you need to ensure that gmrender-resurrect is utilizing the pulsesink.

MG-Sky commented 1 year ago

ok i have tested some settings and...

when i use:

gst-launch-1.0 -v audiotestsrc ! pulsesink it works when i play anothre sound from different pulse source

when i try using upnp: ERROR [2023-07-06 08:16:40.344508 | gstreamer] sink: Error: Failed to connect: Connection refused (Debug: ../ext/pulse/pulsesink.c(614): gst_pulseringbuffer_open_device (): /GstPulseSink:sink) ERROR [2023-07-06 08:16:40.345074 | gstreamer] setting play state failed (2) ERROR [2023-07-06 08:16:40.345616 | upnp] upnp_set_error: Playing failed (704)

settings: DAEMON_EXTRA_ARGS="--mime-filter audio --logfile /var/log/gmediarender.log --gstout-audiosink=pulsesink"

MG-Sky commented 1 year ago

ok i found the soultiuon, here: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/issues/565

it was to disable udev module to not access sound cart directly, now both work perfectly!

so what i did:

  1. installed: gstreamer1.0-pulseaudio , removed ..-alsa,
  2. changed default.pa with: load-module module-alsa-sink device=dmx:..... (apllay -L) load-module module-alsa-source device=dsnoop comment the: # load-module module-udev-detect and # load-module module-detect

the problem was with pulseaudio

mill1000 commented 1 year ago

Great. Glad you worked it out. Could you close this issue when you get a chance?