Req [Work around exists] Use HDMI audio sink capabilities
#1
As far as I understand, Kodi does not use information from HDMI audio sink in order to setup audio over HDMI.

I have a setup with pi -> HDMI -> Receiver -> HDMI -> TV.
My kids normally does not turn on the receiver when watching movies. The receiver is then in standby mode and the HDMI signal is just passed on to the TV, which is only capable of stereo input.
When receiver is in standby, Command "tvservice -a" returns:
PCM supported: Max channels: 2, Max samplerate: 48kHz, Max samplesize 24 bits.

When I watch a movie I normally have the receiver on, and of course I want 5.1-sound.
When receiver is on, Command "tvservice -a" returns:
PCM supported: Max channels: 8, Max samplerate: 192kHz, Max samplesize 24 bits.
AC3 supported: Max channels: 6, Max samplerate: 48kHz, Max rate 640 kb/s.
DTS supported: Max channels: 7, Max samplerate: 96kHz, Max rate 1536 kb/s.
DTS_HD supported: Max channels: 8, Max samplerate: 192kHz, Max rate 8 kb/s.

Currently, when I go to the audio setting I can choose between two modes:
1. I can set output to be 2.0 sound (with no passthrough). When receiver is in standby, the TV accepts the audio and I'll get sound from TV. However, when receiver in on, I'll only get 2.0 sound from my receiver, which is what I'll expect but not what I want.

2. I can set output to be 5.1 sound (either with multichannel PCM or with passthrough). When receiver is on, I'll get proper 5.1 sound. However, when receiver is in standby, Kodi will still send out 5.1 sound to TV, which is not able to decode, and I have no sound at all.

My proposal is to add support for "downmix audio to HDMI capabilities", meaning if audio is set to be 5.1 (multichannel PCM or passthrough), but HDMI sink is only capable of 2.0, Kodi sends out only 2.0 sound.
Reply
#2
I asked about something similar via hdmi cec. I'm currently using a script to automatically change audio settings based on whether my network avr is pingable, you could use the tvservice command


http://forum.xbmc.org/showthread.php?tid...pid1719887
Reply
#3
The official view of kodi devs is that EDID information is not to be trusted, and although many platform can query it, it is always ignored.
To be fair it often wrong, especially when using hdmi splitters, extractors, switches and TVs with optical out. (Although it is more often right than wrong).

It would be quite easy to query supported audio before opening the sink, and disable passthrough or multichannel if they are not currently supported.
But, that would mean someone with a TV that does actually support AC3 passthrough over optical, but doesn't report this capability in the EDID would never get passthough.

So the real question is how you can distinguish the two cases in the GUI settings without adding more confusion.
Reply
#4
If we'd support it, it probably should only be one setting called something like "autodetect device capabilities", while current audio settings will be used as fallback or limitation. If EDID is incorrect in your setup, then disable that one setting and apply what we have now.
Or we cache the device IDs and have a spinner to cycle through available devices where we allow to override the settings if required while default settings apply if an "custom settings for this device" option is not checked. Or maybe we could use the peripherals system for this.
Reply
#5
Thanks for the answers.

@da-anda: That´s a really good suggestion. I guess "autodetect device capabilities" would work for most setups and would give a very simple audio setup for basic users. I surely vote for such feature.

@teeedubb: I'll definitly will try this. If it works for me, I'll post my scripts & how I did it.
Reply
#6
looking forward to the scripts, want to use this aswell. Have the same situation. When my wife just wants to watch tv, she powerson the tv, not the receiver. The speakers of the TV are sufficient for wathcing just TV. When i want to watch a serie or movie or want to listen to music, i'll turn on the receiver.
Reply
#7
I've now got it almost working, running Gotham release with Raspbmc on a pi. However I can not get it to autostart (nor via upstart or via init.d), so I would really appreciate some help with this, details below.

This is my script, almost a copy from teeedubb:
Code:
#!/bin/bash
export DISPLAY=:0

echo starting loop...

while true ; do

# Wait until Webservice is running
until [[ $(nmap -p 80 localhost | grep -i open) ]] ; do
    sleep 2
    echo sleeping 2s, waiting for xbmc json-rpc
done

if [ "`tvservice -a | grep "Max channels: 8"`" ] ; then
    if [ -f /tmp/avr.on ] ; then
        echo avr on , avr.on exists
    else
        echo avr on, no avr.on
        #curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthroughdevice","value":"ALSA:hdmi:CARD=NVidia,DEV=1"},"id":1}' http://localhost:80/jsonrpc
        curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthrough","value":true},"id":1}' http://localhost:80/jsonrpc
        #audiooutput.channels 8 = 5.1 sound
        curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.channels","value":8},"id":1}' http://localhost:80/jsonrpc
        rm -f /tmp/avr.off
        touch /tmp/avr.on
        curl -v -H "Content-type: application/json" -X POST -d '{"id":1,"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"AUDIO OUTPUT","message":"Receiver","image":"/home/pi/.xbmc/userdata/speaker.png"}}' http://localhost:80/jsonrpc
    fi
else
    if [ -f /tmp/avr.off ] ; then
        echo avr off , avr.off exists
    else
        echo avr off, no avr.off
        curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthrough","value":false},"id":1}' http://localhost:80/jsonrpc
        curl -v -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.channels","value":1},"id":1}' http://localhost:80/jsonrpc
        rm -f /tmp/avr.on
        touch /tmp/avr.off
        curl -v -H "Content-type: application/json" -X POST -d '{"id":1,"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"AUDIO OUTPUT","message":"TV","image":"/home/pi/.xbmc/userdata/speaker.png"}}' http://localhost:80/jsonrpc
    fi
fi
echo end of script
echo sleeping 2s...
sleep 2

done
exit 0

And the upstart file:
Code:
# Auto audio switching
#

description     "Auto audio switching"
author          "DanielB"

start on started xbmc
stop on runlevel [!2345]


exec bash /home/pi/switch_audio.sh


For the script I needed to perform the following steps:
1. Install utilities (using ssh)
sudo apt-get upgrade
sudo apt-get install nmap
sudo apt-get install curl

2. When using windows to edit, get a proper editor
Notepad++
Don't forget to change EOL (End Of Line) to be Unix compliant

3. FTP over script (switch_audio.sh) & update file (switch_audio.conf) & speaker icon to pi

4. Move speaker icon to .xbmc/userdata folder
mv speaker* .xbmc/userdata/.

5. Test script
bash switch_audio.sh

6. Enable autostart with help of upstart
sudo mv switch_audio.conf /ect/init/.

7. Reboot
sudo reboot

8. See that script is running automatically
initctl status switch_audio

When running step 5, using bash from prompt, the script works perfectly and changes audio settings according to "tvservice -a".
However, when running automatically via upstart, the command "tvservice -a" seems to not work. I know that my script is running with "inictl status switch_audio" and I also tested to put some debug output and the script is running, but the "tvservice -a" command returns nothing (empty string).

Any ideas why tvservice does not work?
Reply
#8
(2014-08-12, 08:44)da-anda Wrote: If we'd support it, it probably should only be one setting called something like "autodetect device capabilities", while current audio settings will be used as fallback or limitation. If EDID is incorrect in your setup, then disable that one setting and apply what we have now.
Or we cache the device IDs and have a spinner to cycle through available devices where we allow to override the settings if required while default settings apply if an "custom settings for this device" option is not checked. Or maybe we could use the peripherals system for this.

Before anything can happen there all sinks are required to support the DeviceChange event, i.e. ALSA and Pi sink don't. Means that if user turns on AVR after having started XBMC, XBMC won't see the new configuration.
Reply
#9
Not sure why its not running and I dont have much experience with either method you have tried, but I start mine via /etc/rc.local with:

Code:
(sudo -u xbmc /usr/bin/.scripts/xbmc-switch-audio-output.sh)&

I know using upstart etc would be better so the script could be stopped etc, but the script has been rock solid and after initial setup I haven't needed to restart it.

Also in my example I linked to I forgot I was using nmap, which is over kill for this task, a simpler way is to ping xbmc's jsonrpc

Code:
until [[ $(curl -v -H "Content-type: application/json" -X POST -d '{ "jsonrpc": "2.0", "method": "JSONRPC.Ping", "id": 1 }' http://localhost:8080/jsonrpc | grep "pong") ]] ; do  sleep 1 ; echo sleeping 1s, waiting for xbmc json-rpc ; done
Reply
#10
I now got it working. The following will describe how to automatically switch audio output depending on HDMI capabilities.
It is tested on Raspbmc Gotham release.

The script:
Code:
#!/bin/bash
# Note! Nr of channels shall be set to 2.0 in GUI. This script will only enable / disable passthrough

export DISPLAY=:0

while true ; do
# Wait until Webservice is running
until [[ $(curl -H "Content-type: application/json" -X POST -d '{ "jsonrpc": "2.0", "method": "JSONRPC.Ping", "id": 1 }' http://localhost:80/jsonrpc | grep "pong") ]] ; do  
    sleep 2
    echo sleeping 2s, waiting for xbmc json-rpc
done

if [ "`/opt/vc/bin/tvservice -a | grep "Max channels: 8"`" ] ; then
    if [ -f /tmp/avr.on ] ; then
        echo avr on , avr.on exists
    else
        echo avr on, no avr.on
        curl -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthrough","value":true},"id":1}' http://localhost:80/jsonrpc
        rm -f /tmp/avr.off
        touch /tmp/avr.on
        curl -H "Content-type: application/json" -X POST -d '{"id":1,"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"AUDIO OUTPUT","message":"Receiver","image":"/home/pi/.xbmc/userdata/speaker.png","displaytime":7000}}' http://localhost:80/jsonrpc
    fi
else
    if [ -f /tmp/avr.off ] ; then
        echo avr off , avr.off exists
    else
        echo avr off, no avr.off
        curl -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthrough","value":false},"id":1}' http://localhost:80/jsonrpc
        rm -f /tmp/avr.on
        touch /tmp/avr.off
        curl -H "Content-type: application/json" -X POST -d '{"id":1,"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"AUDIO OUTPUT","message":"TV","image":"/home/pi/.xbmc/userdata/speaker.png","displaytime":7000}}' http://localhost:80/jsonrpc
    fi
fi
echo sleeping 2s...
sleep 2
done
exit 0

The upstart config file:
Code:
# Auto audio switching
#

description     "Auto audio switching"
author          "DanielB"

start on started xbmc
stop on runlevel [!2345]
exec bash /home/pi/switch_audio.sh

For the script I needed to perform the following steps:
1. Install utilities (using ssh)
sudo apt-get upgrade
sudo apt-get install curl

2. When using windows to edit, get a proper editor
Notepad++
Don't forget to change EOL (End Of Line) to be Unix compliant

3. FTP over script (switch_audio.sh) & update file (switch_audio.conf) & speaker icon to pi

4. Move speaker icon to .xbmc/userdata folder
mv speaker* .xbmc/userdata/.

5. Test script
bash switch_audio.sh

6. Enable autostart with help of upstart
sudo mv switch_audio.conf /ect/init/.

7. Reboot
sudo reboot

8. See that script is running automatically
initctl status switch_audio
Reply

Logout Mark Read Team Forum Stats Members Help
[Work around exists] Use HDMI audio sink capabilities0