Add audio_output FIFO to mpd.conf

Raspberry Pi related support

Add audio_output FIFO to mpd.conf

Postby adrii » 19 Apr 2018, 09:16

I would like to add an audio_output FIFO to /etc/mpd.conf, but if I edit /etc/mpd.conf then my changes disappear on reboot.

I am preparing instructions for installing an OLED display program on RuneAudio, and it requires the MPD output FIFO to be set up. The forums mention making /etc/mpd.conf read-only, but if I have understood then this will unnecessarily break normal configuration. What are good general instructions for adding an audio_output section to /etc/mpd.conf?

Thanks

Adrian.
User avatar
adrii
 
Posts: 27
Joined: 17 Apr 2018, 11:03

Re: Add audio_output FIFO to mpd.conf

Postby janui » 20 Apr 2018, 11:31

Hi adrii,
You can do it this way…
First create a file containing the extra mpd output definition in a convenient directory, eg /home. In my example below the full file name is /home/your-extra-mpd.conf :
Code: Select all
nano /home/your-extra-mpd.conf
The contents will be something like this:
Code: Select all
#########################
## your-extra-mpd.conf ##
##         FiFo        ##
#########################

audio_output {
 type  "fifo"
 name  "my_fifo"
 path  "/tmp/mpd.fifo"
 enabled  "yes"
}

############################
## end your-exta-mpd.conf ##
############################
Then set the correct file protection:
Code: Select all
chmod 644 /home/your-extra-mpd.conf
Then you need to add one line to the file /srv/http/app/libs/runeaudio.php, you need to look for the function wrk_mpdconf. In this function (it’s a big one, so look carefully) you will find the following lines which will need to be modified:
Code: Select all
                // write mpd.conf file
                $fh = fopen('/etc/mpd.conf', 'w');
                fwrite($fh, $output);
                fclose($fh);
                // update hash
                $redis->set('mpdconfhash', md5_file('/etc/mpd.conf'));
            } else {
                runelog('mpd.conf advanced mode ON');
            }
            break;
So open the runeaudio.php file:
Code: Select all
nano /srv/http/app/libs/runeaudio.php
The extra line of code which you need to add is:
Code: Select all
 $output .= file_get_contents('/home/your-extra-mpd.conf');
Modify runeaudio.php so that it looks like this:
Code: Select all
                // write mpd.conf file
                $output .= file_get_contents('/home/your-extra-mpd.conf');
                $fh = fopen('/etc/mpd.conf', 'w');
                fwrite($fh, $output);
                fclose($fh);
                // update hash
                $redis->set('mpdconfhash', md5_file('/etc/mpd.conf'));
            } else {
                runelog('mpd.conf advanced mode ON');
            }
            break;
That should do it.
You will need to reboot and modify something (anything) in the MPD UI to activate it. You can check the results by looking at the Debug UI (you may need to refresh the browser a few times to see the actual content), the mpd.conf file is listed in full.
Note 1: You will not be able to select the added output device from the MPD UI, it is always there and therefore should always be ON. Switching the output ON is done with the ‘enabled’ clause. In theory MPD has no problems with multiple outputs which are ON, but with the less powerful PI models (Zero and B+) it may not work correctly.
Note 2: It only works with MPD. So, for Spotify, Airplay and UPnP/DLNA this modification has no effect.
Note 3: You need something to read the FiFo pipe. Reading it effectively empties it. Otherwise it will grow until it fills your file system.

janui
User avatar
janui
 
Posts: 682
Joined: 20 Dec 2014, 12:55
Location: Ollanda

Re: Add audio_output FIFO to mpd.conf

Postby adrii » 20 Apr 2018, 16:22

Hi Janui

Thanks for ypur help. This worked fine. I could implement the change as a patch to save people having to edit code.

For Notes 1, and 3, I have been using an MPD FIFO with a Pi Zero W, and it doesn't appear to contribute significantly to the system load. I have not seen any issues when the OLED software is not running so the FIFO is not being read. (I believe that the FIFO buffer size is limited and relatively small).

For Note 2, Thanks for the extra details. I can't test Spotify or Airplay, but I have been able to stream to RuneAudio with DLNA from an Ubuntu machine (with pulseaudio_dlna), and the audio appears to go through MPD as the OLED spectrum analyser (using the MPD FIFO) and volume indicator (using libmpdclient) were both working correctly.

Adrian.
User avatar
adrii
 
Posts: 27
Joined: 17 Apr 2018, 11:03

Re: Add audio_output FIFO to mpd.conf

Postby hondagx35 » 20 Apr 2018, 18:18

Hi Adrian,

I am preparing instructions for installing an OLED display program on RuneAudio, and it requires the MPD output FIFO to be set up.


Is the program driving the OLED running on the same Pi?
What is displayed on the display?
Metadata can be also accessed via a linux socket connection to MPD.

Frank
User avatar
hondagx35
 
Posts: 3041
Joined: 11 Sep 2014, 22:06
Location: Germany

Re: Add audio_output FIFO to mpd.conf

Postby adrii » 20 Apr 2018, 18:54

Hi Frank

This is project, and a demonstration video, it runs on the same machine as the music player

https://github.com/antiprism/vol_oled
https://youtu.be/6pgxGQIAX9s

I have successfully built it on RuneAudio, with some minor local changes (the Volumio volume is not the MPD volume), using Clang. It is working fine, (although I had to drop the framerate slightly from 20 to 15 FPS). I have been running it the last couple of hours as a test.

Adrian.
User avatar
adrii
 
Posts: 27
Joined: 17 Apr 2018, 11:03

Re: Add audio_output FIFO to mpd.conf

Postby adrii » 22 Apr 2018, 07:10

Hi

My current instructions for getting RuneAudio to regenerate /etc/mpd.conf and restart say: "Restart MPD by going to the RuneUI MPD Configuration page and clicking on 'SAVE AND APPLY' in the volume control section."

Is there a command line command to achieve the same result? (Alternatively, a few commands I could put in a script.)

Thanks

Adrian.
User avatar
adrii
 
Posts: 27
Joined: 17 Apr 2018, 11:03

Re: Add audio_output FIFO to mpd.conf

Postby janui » 22 Apr 2018, 15:09

Hi adrii,
There is no standard command line command to do this. It is a bit complicated, but you can do it like this...
Create a file, for example /home/mpdreset.php, with:
Code: Select all
nano /home/mpdreset.php
Put the following code in the file
Code: Select all
#!/usr/bin/php
<?php
include('/srv/http/app/libs/runeaudio.php');
$redis = new Redis();
$redis->connect('/run/redis.sock');
$mpd = openMpdSocket('/run/mpd.sock', 0);
sleep(3);
wrk_mpdconf($redis, 'reset');
wrk_mpdconf($redis, 'restart');
closeMpdSocket($mpd);
$redis->close();
Make the file executable with:
Code: Select all
chmod 744 /home/mpdreset.php
When you need to reset MPD you execute the command:
Code: Select all
php -f /home/mpdreset.php
You will get a couple of errors when you run it, but you can ignore these.
janui
User avatar
janui
 
Posts: 682
Joined: 20 Dec 2014, 12:55
Location: Ollanda

Re: Add audio_output FIFO to mpd.conf

Postby adrii » 22 Apr 2018, 19:34

Hi Janui

Thanks for the script. Unfortunately, I am not having success with it. MPD isn't being restarted (same PID) and /etc/mpd.conf isn't being regenerated. I am getting the following error
Code: Select all
[root@runeaudio vol_oled]# ps ax | grep "/usr/bin/mpd"
 3999 ?        Ssl    0:04 /usr/bin/mpd --no-daemon
11625 pts/0    S+     0:00 grep /usr/bin/mpd
[root@runeaudio vol_oled]# php -f mpdreset.php

Fatal error: Uncaught exception 'RedisException' with message 'Redis server went away' in /srv/http/app/libs/runeaudio.php:2053
Stack trace:
#0 /srv/http/app/libs/runeaudio.php(2053): Redis->set('mpdconf_advance...', 0)
#1 /root/proj/tmp/vol_oled/mpdreset.php(8): wrk_mpdconf(Object(Redis), 'reset')
#2 {main}
  thrown in /srv/http/app/libs/runeaudio.php on line 2053
[root@runeaudio vol_oled]# ps ax | grep "/usr/bin/mpd"
 3999 ?        Ssl    0:04 /usr/bin/mpd --no-daemon
11804 pts/0    S+     0:00 grep /usr/bin/mpd


After using RuneUI to save the Volume control
Code: Select all
[root@runeaudio vol_oled]# ps ax | grep "/usr/bin/mpd"
14478 ?        Ssl    0:02 /usr/bin/mpd --no-daemon
14617 pts/0    S+     0:00 grep /usr/bin/mpd


The reason for wanting a command is to keep the installation instructions on the command line. However, if it is difficult to provide the action through a script then the RuneUI approach will be fine.

Adrian.
User avatar
adrii
 
Posts: 27
Joined: 17 Apr 2018, 11:03

Re: Add audio_output FIFO to mpd.conf

Postby janui » 23 Apr 2018, 00:46

Hi adrii,
Sorry about this, I can't test on the Rune version which you are using at the moment.
Just check the location of the files /run/redis.sock and /run/mpd.sock with the commands:
Code: Select all
cd /
find -name redis.sock
find -name mpd.sock
It's possible that the scrip should be more like this:
Code: Select all
<?php
include('/srv/http/app/libs/runeaudio.php');
$redis = new Redis();
if (file_exists('/run/redis.sock')) {
   $redis->connect('/run/redis.sock');
} else if (file_exists('/tmp/redis.sock')) {
   $redis->connect('/tmp/redis.sock');
} else {
   exit('Cant find redis.sock');
}
if (file_exists('/run/mpd.sock')) {
   $mpd = openMpdSocket('/run/mpd.sock', 0);
} else if (file_exists('/tmp/mpd.sock')) {
   $mpd = openMpdSocket('/tmp/mpd.sock', 0);
} else {
   exit('Cant find mpd.sock');
}
sleep(3);
wrk_mpdconf($redis, 'reset');
wrk_mpdconf($redis, 'restart');
closeMpdSocket($mpd);
$redis->close();
In future releases the /run/ directory will be used, so keep it in your script (if it works).
If it still gives problems then use the UI referesh.
janui
User avatar
janui
 
Posts: 682
Joined: 20 Dec 2014, 12:55
Location: Ollanda

Re: Add audio_output FIFO to mpd.conf

Postby adrii » 23 Apr 2018, 07:58

Hi Janui

I am not sure what versions of RuneAudio people might realistically be running, or how they differ, but I would like to provide general installation instructions, and so it looks like the RuneUI method is the better option for now.

It also makes me wonder whether my patch will work on the current different RuneAudion versions. This is the patch
https://raw.githubusercontent.com/antiprism/vol_oled/config/runeaudio_mpd_fifo.patch

If you have time, could you try
Code: Select all
pacman -S patch
patch -d/ -p0 < runeaudio_mpd_fifo.patch

and see if the extra line gets added to runeaudio.php correctly.

If the patch succeeds, if you rerun the patch command it will give you the option to reverse the patch and return to the original runeaudio.php file
Code: Select all
patch -d/ -p0 < runeaudio_mpd_fifo.patch


Thanks

Adrian.
User avatar
adrii
 
Posts: 27
Joined: 17 Apr 2018, 11:03

support RuneAudio Donate with PayPal


Return to Raspberry Pi

Who is online

Users browsing this forum: Bing [Bot] and 3 guests