allow terminal control with standard input play
Brought to you by:
sobukus
Please allow terminal control (-C option) when playback from stdin - currently (1.29.3) an error is presented - "main: [src/mpg123.c:main():1342] error: no terminal control because standard input is being played".
The use case is quite simple - player for "cli streaming apps" like https://github.com/yne/dzr
it works even now but no control like pause/next etc.
Hm. It's not so much about allowing it, but about making it possible.
We read the keys for terminal control from stdin. If that's stuffed
with MPEG data, there might be the way to access /dev/pts/n instead, or
whatever stderr is still linked to. At least the tty command uses that
approach to figure out the controlling terminal. But that is not
terribly portable.
I tried a bit of hacking with hardcoding my current pty and so far
notice that select() on that doesn't work. We need that for interactive
use.
I might have gotten something wrong. But when we are limiting things to
certain platforms already … what about doing what in bash would be
? You can pass a file descriptor down to mpg123, not clogging stdin.
so the script is not in bash but in sh
how do you see the following rewritten to allow control ?
reference: https://github.com/yne/dzr/blob/3634e091417d94a89f3e56b0226a7215b0c79798/dzr#L33
thanks,
M
Am Tue, 03 May 2022 05:41:24 -0000
schrieb "maurer" maurer@users.sourceforge.net:
Plain sh doesn't do the <(command) trick, AFAIK (at least not all implementations).
Since you say that mpv
works just fine, I'll have to have a look how they do it / re-visit
hacking with re-opening the terminal for input. I guess I did something
wrong in my testing.
It's a bit funny that you come with such a request now, as I just added
code to mpg123 to do HTTPs streaming by calling wget or curl in a
separate process and reading the piped data, to replace the internal
code that does HTTP only. Terminal control is one reason, the other is
that you might want ICY metadata from HTTP streams, if it's web radio,
not a single streamed track. For that, the metadata interval needs to
be negotiated between client and server.
So mpg123 from current trunk (or https://mpg123.org/snapshot) does read
the data from a pipe and allows terminal control, because it starts the
pipe internally.
But: If mpv does allow control keys and stdin piping, I should check how
mpg123 could do it, too. Maybe you can read up (or strace) on what mpv
does to access terminal control keys and post some hints here? Is it
just opening /dev/pts/x after looking it up in /proc/self/fd/2?
Something else?
Last edit: Thomas Orgis 2022-05-03
I've tried to build and install (make) the snapshot code but it doesn't work:
main: [src/mpg123.c:check_fatal_output():331] error: out123 error 3: failure loading driver module
and about mpv as I'm not that advanced into C coding I can just reference what I think it's the control functions https://github.com/mpv-player/mpv/blob/master/input/input.c
Regarding the failure: You need to run src/mpg123-with-modules or simply give
--disable-shared
to configure to avoid the run-time linking issues.Edit: Or just do a
make install
and run from the installed prefix.Last edit: Thomas Orgis 2022-05-03
I did the following:
and indeed running the binary outputs the help (no more complains about missing binaries - previously fixed with
export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib
- FIXED the command with export - wrong copy/paste :) )but running it in the dzr script (
mpg123 -qvC -
) outputs the same error:main: [src/mpg123.c:check_fatal_output():331] error: out123 error 3: failure loading driver module
Last edit: maurer 2022-05-03
That doesn't make sense … or … hm … well, yes, you need to select the proper output module with
--disable-shared
. The one that works at runtime. If you install into a prefix and have that in PATH for dzr, then just keep the default config, just add --prefix. Then it should behave the same as your distro package — provided you got the development files installed for the output API you use!I fixed up the current snapshot to simply use
/dev/tty
orctermid()
for control keys. Simple. Can you test that (and figure out your installation issue)?thank you for the quick answer.
I'll need some help though to make get this dev version working in my env - ubuntu 20.04 as even if I try to add in the dzr script with the full path like
/home/user/mpg123-20220507022201/src/mpg123 -vqC -
I still get the error :(main: [src/mpg123.c:check_fatal_output():333] error: out123 error 3: failure loading driver module
in the bash console it works without issues
I suspect that you do not have the correct output module built for your setup (missing development package). Can you show the output of
mpg123 -vvv -n 1 testfile.mp3
for both your system-installed mpg123 and the self-built one?I am looking for such lines … also, the output of
mpg123 --list-modules
confirms the list of available outputs and a likely difference between your system one and the self-built one. Maybe you are missing pulse headers and only have OSS support built? When you use--disable-shared
, you need to specify the output module you want to build in using--with-audio=pulse
for example/.it looks like you're right - my compilation is botched :)
So you maybe just need to install something like
libasound2-dev
orlibpulse-dev
before compiling, depending on what sound system you use.If run a normal desktop with pulseaudio, using that directly is better than via alsa/asound, but both should work. Just check which backend is used with your system install of mpg123.
got it finally:
I can confirm that control works now via stdin - awesome job !!!
Looking forward to the next stable release !
PS - Any pointer to how to statically cross compile this for a low end system like raspberry pi ? - aka i just want to transfer 2-3 compiled files maximum to /usr/bin and use it ?
and a very big thank you for all your development and community support !
Cool. For a cross-build, you should be on the right track. Without shared stuff, mpg123 just links to libc and your audio backend. If the raspi also has libpulse, you only need the cross-dev files for that. Nothing special about mpg123 … it's GNU autoconf with standard support for cross builds. So having a toolchain and using the appropriate standard options should get you far.
thank you very much again !