View Full Version : Testing triggers Kissdx version v0.14.0.b1 Cygwin/WinXP SP2
Hi,
I got quite excited abkout triggers until my cygwin/unix skills ran out. I figured that I could write a script to run as a pre-trigger to fork a flac->mp3 transcoder if a flac file was requested as a stream for example.
A few things I noticed though.
1.
the pretrigger is called multiple times in quick succession rather than when a stream is opened (if thats the right terminology). I was expecting it to be called only when a stream was requested - did I misunderstand? This could mean that an unnecessary transcoder process is forked. time and time again.
2.
the audio listing is sent to the kiss 1600 (as seen in the -v trace) correctly, but only one of the sent file names appears on the player menu list (oh and a few obscure kissdx-B2B files appear randomly too - maybe related to recently used?). I tried a hard power-cycle reboot on the 1600 and a reboot of the cygwin server - in case any weird caching was happening - no change there.
3. no matter what order I place new audio file extensions in kissdx.conf, only those that were as standard show up on my player - I blame caching again.
for anyone interested, I downloaded a bunch of codecs from subsonic at sourceforge and mangled the following pretrigger script (I think it needs a nohup in it perhaps?) I was relying on the player/stream server able to stream open files (as PC-Link can do) but not sure if thats correct.
=============================================
#!/usr/bin/bash
case "$1" in
*.flac)
# 1600 can't play flac just yet, so encode to mp3
OUT=$(mktemp)
(cat "$1" | /subsonic/flac -d -s -c - | /subsonic/lame -S -b 320 - - 2>/dev/nul | cat > "$OUT") &
echo "$OUT"
;;
*)
# No treatment for other file types...
echo "$1"
;;
esac
=============================================
Ideally would like to be able to transcode on the fly and stream the output straight back to the player - or am I being unrealistically enthusiastic?
1.
You are correct, the pretrigger is called each time the player requests the file - on SIZE, ACTION and the first GET command. This could be reduced to 1 call by some elaborate coding inside kissdx, but since we have not touched the trigger mechanism since the original kissd, that's how it is.
Your trigger script could perhaps add state awareness by converting into a permanent file (with a name based on $1) and checking if the file already exists to avoid multiple conversions? If you want to convert on-the-fly to stdout (is that what $(OUT) in the script means?) this won't work. Maybe use a named pipe? As you can see from my vague suggestions I have never delved into this myself but someone has. (http://www.mpcclub.com/modules.php?name=Forums&file=viewtopic&t=11155&postdays=0&postorder=asc&highlight=kissdx+triggers&start=0).
2.
The {kissdx-B2B} files are for back-to-back (gapless) playback. Select one and all the files in the folder play back-to-back as a single large audio file. I guess they could be presented in a better way...
2. and 3.
The player does not support the flac extension. Try setting renamefiletypes = flac:mp3,flc:mp3 in kissdx.conf. Note that you need to detect flac files in a different manner, since the player will ask for an mp3 file.
Vidar,
thanks for your information:
1.
You are correct, the pretrigger is called each time the player requests the file - on SIZE, ACTION and the first GET command. This could be reduced to 1 call by some elaborate coding inside kissdx, but since we have not touched the trigger mechanism since the original kissd, that's how it is.
Your trigger script could perhaps add state awareness by converting into a permanent file (with a name based on $1) and checking if the file already exists to avoid multiple conversions? If you want to convert on-the-fly to stdout (is that what $(OUT) in the script means?) this won't work. Maybe use a named pipe? As you can see from my vague suggestions I have never delved into this myself but someone has. (http://www.mpcclub.com/modules.php?name=Forums&file=viewtopic&t=11155&postdays=0&postorder=asc&highlight=kissdx+triggers&start=0).
2.
The {kissdx-B2B} files are for back-to-back (gapless) playback. Select one and all the files in the folder play back-to-back as a single large audio file. I guess they could be presented in a better way...
2. and 3.
The player does not support the flac extension. Try setting renamefiletypes = flac:mp3,flc:mp3 in kissdx.conf. Note that you need to detect flac files in a different manner, since the player will ask for an mp3 file.
-- Reading the post you link to is very interesting but too complex for what I was trying to achieve. Those posts refer to sending extra information into the trigger - such as if it is a SIZE/GET etc. That was in kissd I think - did you ever get round to doing that, and if so how is the command/function passed?
-- The transcoding works just fine when standalone, $OUT is a real file that is being written by the multi-pipe command, all codecs receive input from stdin and are told to write to stdout, finally, piped into cat > $OUT that results in a real file with a random name. I was assuming that kissdx would then (via the echo $OUT) instruct the player to request the new file and can read open files (as PC-Link can do). The transcoding of a 35Mb file takes typically 5 seconds on my server, which is fast enough so that the player/kissdx can start streaming and never catch up. My posttrigger just removes any of these temporary transcoded output files. Unfortunately, the posttrigger was getting called before the transcoding could complete - so I took that out!
-- Your last point: That was the reason for looking at triggers. I dont think the player knows the file is a flac - until it would try to play it of course - I was expecting that to add flac to audio extensions would make the file name appear in the audio listing on the player, then the trigger would return an mp3 converted file. However, I can't seem to add flac to the extensions list with any result. As I mentioned, the -v option shows that x.flac is sent back in list audio files function, but doesnt display in the selection list. I'm surprised that 1600 hard filters the file out. I would expect it to just crack up if told to do something with an unplayable file or unrecognised extension.
I will keep experimenting when I get time.
... As I mentioned, the -v option shows that x.flac is sent back in list audio files function, but doesnt display in the selection list. I'm surprised that 1600 hard filters the file out. I would expect it to just crack up if told to do something with an unplayable file or unrecognised extension.
All KiSS players filter out only known filetypes from the listing sent. The original kissd sent every file, but that caused some players to miss files even though they were of a known type (fimware bug). That's why I added the audiofileextensions setting etc. - to reduce the listing sent.
Try adding this to kissdx.conf:
renamefiletypes = flac:flac.mp3,flc:flac.mp3
Then you can test for files ending in ".flac.mp3" in your script.
Try adding this to kissdx.conf:
renamefiletypes = flac:flac.mp3,flc:flac.mp3
Then you can test for files ending in ".flac.mp3" in your script.
Ouch, that was not 100% correct, sorry. kissdx will transform the filename back to the real .flac name before presenting it to the trigger script. So your script must test for ".flac".
-- Reading the post you link to is very interesting but too complex for what I was trying to achieve. Those posts refer to sending extra information into the trigger - such as if it is a SIZE/GET etc. That was in kissd I think - did you ever get round to doing that, and if so how is the command/function passed?
I can't find that in older kissd source code, so I still believe it has always been the way it is now: Multiple calls per file and no way of telling SIZE and ACTION from GET.
Even if we modify kissdx to supply the operation in parameter $2 to the script, the script must present a properly converted file on return from all calls - you can not simply skip the ACTION and SIZE calls.
I am playing around with this today - will keep you posted. Did you make any progress yourself?
I got this working quite well, using the following script:
#! /bin/sh
case "$1" in
*.flac)
# DP-600/1600 can't play flac, so decode to wav
# NOTE: We also need specific settings in kissdx.conf:
# 1. Add flac to the list in audiofileextensions.
# 2. Add flac:mp3 to the list in renamefiletypes. Remove other *:mp3 entries.
OUTFILE=/var/tmp/kissdx-trigger-flac.wav
STATEFILE=/var/tmp/kissdx-trigger-flac.state
if [ -r "$STATEFILE" ]; then
previousfile=$(cat "$STATEFILE")
else
previousfile=""
fi
if [[ "$previousfile" != "$1" ]]; then
cat "$1" | flac -d -s -f -o "$OUTFILE" -
echo "$1" > $STATEFILE
fi
echo "$OUTFILE"
;;
*)
# No treatment for other file types...
echo "$1"
;;
esac
As the comments say:
1. Add flac to the list in audiofileextensions. Example:
audiofileextensions = mp3,ogg,wma,wav,flac,flc
2. Add flac:mp3 to the list in renamefiletypes. Remove other *:mp3 entries. Example:
renamefiletypes = ts:mpg,flac:mp3
Try it out! :-)
Vidar,
thanks ... that looks good. It will be the weekend before I am tinkering with this again and I will give it a try.
vBulletin® v3.8.4, Copyright ©2000-2013, Jelsoft Enterprises Ltd.