Menu

#338 allow terminal control with standard input play

1.29.x
closed-fixed
nobody
2
2022-05-08
2022-05-02
maurer
No

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.

Discussion

  • Thomas Orgis

    Thomas Orgis - 2022-05-02

    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

    mpg123 -Cv <(some_program)
    

    ? You can pass a file descriptor down to mpg123, not clogging stdin.

     
  • maurer

    maurer - 2022-05-03

    so the script is not in bash but in sh
    how do you see the following rewritten to allow control ?

    play() { # receive /track/1,2,3 from stdin
            xargs basename | xargs $0-url | while read url id; do
    #               $FETCH "$url" | $0-dec $id | eval ${PLAYER:-'mpv -'} ; #mpv works just fine with stdin and cli commands
                   $FETCH "$url" | $0-dec $id | eval ${PLAYER:-'mpg123 -vqC -'} ;
            done
    }
    

    reference: https://github.com/yne/dzr/blob/3634e091417d94a89f3e56b0226a7215b0c79798/dzr#L33

    thanks,
    M

     
    • Thomas Orgis

      Thomas Orgis - 2022-05-03

      Am Tue, 03 May 2022 05:41:24 -0000
      schrieb "maurer" maurer@users.sourceforge.net:

      so the script is not in bash but in sh
      how do you see the following rewritten to allow control ?

      ~~~
      play() { # receive /track/1,2,3 from stdin
      xargs basename | xargs $0-url | while read url id; do

      $FETCH "$url" | $0-dec $id | eval ${PLAYER:-'mpv -'} ; #mpv works just fine with stdin and cli commands

                 $FETCH "$url" | $0-dec $id | eval ${PLAYER:-'mpg123 -vqC -'} ;
          done
      

      }
      ~~~

      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
  • maurer

    maurer - 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

     
  • Thomas Orgis

    Thomas Orgis - 2022-05-03

    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
  • maurer

    maurer - 2022-05-03

    I did the following:

    ./configure --disable-shared
    make
    sudo make install
    

    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
  • Thomas Orgis

    Thomas Orgis - 2022-05-04

    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!

     
  • Thomas Orgis

    Thomas Orgis - 2022-05-06

    I fixed up the current snapshot to simply use /dev/tty or ctermid() for control keys. Simple. Can you test that (and figure out your installation issue)?

     
  • maurer

    maurer - 2022-05-07

    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

     
  • Thomas Orgis

    Thomas Orgis - 2022-05-07

    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?

    Trying output module: alsa, device: <nil>
    Using default module dir: /usr/lib/x86_64-linux-gnu/mpg123
    Module dir: /usr/lib/x86_64-linux-gnu/mpg123
    Module path: /usr/lib/x86_64-linux-gnu/mpg123/output_alsa.so
    Chosen output module: alsa
    
    Audio driver: alsa
    Audio device: (null)
    Audio capabilities:
    (matrix of [S]tereo or [M]ono support for sample format and rate in Hz)
    

    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/.

     
  • maurer

    maurer - 2022-05-07

    it looks like you're right - my compilation is botched :)

    $ mpg123 -vvv -n 1 ./Downloads/file_example_MP3_700KB.mp3
    High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
        version 20220507022201; written and copyright by Michael Hipp and others
        free software (LGPL) without any warranty but with best wishes
    Decoder: x86-64 (SSE)
    Trying output module: oss, device: <nil>
    Note: oss is the last output option... showing you any error messages now.
    [src/libout123/modules/oss.c:open_oss():174] error: Can't open default sound device!
    [src/libout123/libout123.c:check_output_module():982] error: Module 'oss' device open failed.
    [src/libout123/libout123.c:out123_open():482] error: Found no driver out of [oss] working with device <default>.
    main: [src/mpg123.c:check_fatal_output():333] error: out123 error 3: failure loading driver module
    
     
  • Thomas Orgis

    Thomas Orgis - 2022-05-07

    So you maybe just need to install something like libasound2-dev or libpulse-dev before compiling, depending on what sound system you use.

     
  • Thomas Orgis

    Thomas Orgis - 2022-05-07

    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.

     
  • maurer

    maurer - 2022-05-07

    got it finally:

    sudo apt install libpulse-dev
    ./configure --with-audio=pulse --disable-shared
    

    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 ?

     
  • maurer

    maurer - 2022-05-07

    and a very big thank you for all your development and community support !

     
  • Thomas Orgis

    Thomas Orgis - 2022-05-07

    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.

     
  • maurer

    maurer - 2022-05-07

    thank you very much again !

     
  • Thomas Orgis

    Thomas Orgis - 2022-05-08
    • status: open --> closed-fixed
     

Log in to post a comment.