LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 11-27-2017, 07:08 AM   #1
truthz03
LQ Newbie
 
Registered: Nov 2017
Posts: 2

Rep: Reputation: Disabled
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
 
Old 11-28-2017, 05:20 PM   #2
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,800

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
Can you not just add a suitable delay with the sleep command?
 
Old 11-29-2017, 06:30 AM   #3
truthz03
LQ Newbie
 
Registered: Nov 2017
Posts: 2

Original Poster
Rep: Reputation: Disabled
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
 
Old 11-29-2017, 12:35 PM   #4
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,800

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
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
 
Old 11-29-2017, 12:49 PM   #5
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,800

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
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.
 
Old 09-04-2019, 08:56 AM   #6
drfrutuoso
LQ Newbie
 
Registered: Sep 2019
Posts: 1

Rep: Reputation: Disabled
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Systemd service: AUTOSSH.service does not start at boot, how can I fix this? The_Linux_Machine Linux - Newbie 1 07-06-2016 12:00 PM
Can't access full journalctl from script via systemd service even though user is in systemd-journal group iwtbf Linux - Newbie 0 02-19-2016 02:44 PM
systemd service aagaag Linux - Newbie 1 01-18-2016 07:42 PM
Boot Delay 30min: systemd-analyze blame systemd-tmpfiles-setup.service BGHolmes Fedora 0 07-27-2011 09:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 07:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration