LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   Systemd service problem with sound card (https://www.linuxquestions.org/questions/linux-hardware-18/systemd-service-problem-with-sound-card-4175618458/)

truthz03 11-27-2017 07:08 AM

Systemd service problem with sound card
 
Hello,

I'm new here and need some help getting my systemd script running.

What I want to do:
Start a gstreamer pipeline on boot which redirects one alsa input device to one alsa output device

The problem:
The script works if I start it after boot but if the service will start at boot I get an "Device is busy" error

The problem seems to be my output device which is an audioinjector-octo-soundcard.
If I use the fakesink from gstreamer everithing is working.
I have also tried to delay the start of my script which also works but I need that service as fast as possible.

Is there any way to wait for my soundcard?

Here is my service script:
[Unit]
Description=Audio Mixer
After=syslog.target sound.target pulseaudio.service

[Service]
User=root
Group=root

Type=simple
ExecStartPre=/usr/bin/aplay -l
ExecStart=/usr/bin/gst-launch-1.0 -vvv alsasrc device=hw:Loopback,1 ! audio/x-raw, rate=48000 ! alsasink device=hw:audioinjectoroc
TimeoutStopSec=20
KillMode=process
Restart=always

[Install]
WantedBy=default.target


The error:
gst-launch-1.0[939]: Setting pipeline to PAUSED ...
gst-launch-1.0[939]: ERROR: Pipeline doesn't want to pause.
gst-launch-1.0[939]: ERROR: from element /GstPipeline:pipeline0/GstAlsaSink:alsasink0: Could not open audio device for playback. Device is being used by another application.
gst-launch-1.0[939]: Additional debug info:
gst-launch-1.0[939]: gstalsasink.c(858): gst_alsasink_open (): /GstPipeline:pipeline0/GstAlsaSink:alsasink0:
gst-launch-1.0[939]: Device 'hw:audioinjectoroc' is busy
gst-launch-1.0[939]: Setting pipeline to NULL ...
gst-launch-1.0[939]: Freeing pipeline ...

Thanks
Thomas

ferrari 11-28-2017 05:20 PM

Can you not just add a suitable delay with the sleep command?

truthz03 11-29-2017 06:30 AM

Sure. But the time for the delay is not constant and I don't want a too large delay because a short boot time is very important for my project

ferrari 11-29-2017 12:35 PM

I can only suggest enabling debug mode to get more info. (I know very little about gstreamer unfortunately.)

https://gstreamer.freedesktop.org/da...t-running.html

ferrari 11-29-2017 12:49 PM

If you can't make progress here, you might consider also posting to gstreamer mailing list. Nabble provides a web archive and gateway if preferred...
http://gstreamer-devel.966125.n4.nab...p?forum=966125
Good luck with this.

drfrutuoso 09-04-2019 08:56 AM

Similar issue
 
Hi, I'm sorry to reply on such an old post but I'm facing a similar issue and I'm also using a sound-card from AudioInjector, the stereo sound-card.

I'm developing an intercom based of a RPi and for that I'm using twinkle sip phone. Let me start by saying that everything is functional as long as I don't use a systemd service in order to run my script at boot, doing so also returns either device busy, or just not accessible at all, see errors below.

IMPORTANT: This issue only happens when I force CLI boot mode, if I use GUI boot mode I have no issues but I have no interest in having GUI interface.

Quote:

Sep 03 07:38:18 raspberrypi python[1029]: Critical: Opening ALSA driver failed: snd_pcm_hw_params_set_channels(1) failed: Invalid argument
Sep 03 07:38:18 raspberrypi python[1029]: Critical: Opening ALSA driver failed: snd_pcm_hw_params_set_channels(1) failed: Invalid argument
Sep 03 07:38:18 raspberrypi python[1029]: Critical: Opening ALSA driver failed: snd_pcm_hw_params failed: Invalid argument
Sep 03 07:38:18 raspberrypi python[1029]: Warning: Cannot access the ring tone device (ALSA: default).
Sep 03 07:38:18 raspberrypi python[1029]: Cannot access the speaker (ALSA: default).
Sep 03 07:38:18 raspberrypi python[1029]: Cannot access the microphone (ALSA: plughw:0,0).
I also tried changing the device to use, in the case of sysdefault the error was slightly different:

Quote:

Sep 03 07:42:55 raspberrypi python[1197]: Critical: Opening ALSA driver failed: snd_pcm_hw_params failed: Invalid argument
Sep 03 07:42:55 raspberrypi python[1197]: Critical: Opening ALSA driver failed: snd_pcm_hw_params failed: Invalid argument
Sep 03 07:42:55 raspberrypi python[1197]: Critical: Opening ALSA driver failed: snd_pcm_hw_params failed: Invalid argument
Sep 03 07:42:55 raspberrypi python[1197]: Warning: Cannot access the ring tone device (ALSA: sysdefault:0).
Sep 03 07:42:55 raspberrypi python[1197]: Cannot access the speaker (ALSA: sysdefault:0).
Sep 03 07:42:55 raspberrypi python[1197]: Cannot access the microphone (ALSA: sysdefault:0).
There's another "small" detail I noticed, if I start the script myself, it won't work the first time, second time does. This has something to do with pulseaudio, even tho my sound-card is fully recognized and setup at boot if I, for example, run 'amixer' and only then run my script it works flawlessly as if something related with pulseaudio was not initiated at boot. I searched and saw no pulseaudio.service is this normal?

My service config:
Quote:

[Unit]
Description=BUTTON SIP CALL
After=sound.target network.target
Requires=sound.target

[Service]
ExecStart=/usr/bin/python -u intercom.py
WorkingDirectory=/home/pi/Desktop
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi
#Environment=DISPLAY=:0

[Install]
WantedBy=multi-user.target
Any help is greatly appreciated.


All times are GMT -5. The time now is 03:42 AM.