Difference between revisions of "User:Lwoggardner"

From MythTV Official Wiki
Jump to: navigation, search
(Useful config info)
(Configuration)
(28 intermediate revisions by the same user not shown)
Line 1: Line 1:
Let me just start by saying MythTV rocks.
 
 
I was keeping track of where I was at with Myth on my home wiki, but then figured I might as well share it here!
 
I was keeping track of where I was at with Myth on my home wiki, but then figured I might as well share it here!
  
== My Setup ==
+
= My Setup =
 +
 
 +
MythBuntu 12.04 with separated front-end/backend
 +
 
 +
* Live TV/TV recording Free to air HD/SD (from Sydney, Australia)
 +
* Multi-rec
 +
* DTS/AC3 passthrough including 5,1 surround digital out
 +
* VDPAU
 +
* [[MythMusic]]
 +
* [[MythGallery]]
 +
* [[MythVideo]]
 +
* Frontend Suspend to RAM + Wake On USB
 +
* Backend Suspend to RAM
 +
 
 +
== Backend ==
  
Combined FE/BE.
 
 
=== Hardware ===
 
=== Hardware ===
* AMD S754 Athlon 64 3700+
 
* Gigabyte S754 GA-K8VM800M
 
* 1GB Ram
 
* 320GB Western Digital 7200rpm 8M Serial ATA HDD
 
* <strike>Albatron FX5200LP 128M 8x Video Card with DVI output.</strike>
 
* Gigabyte FX5200 128M 8x Video Card with DVI output.
 
  
* DVICO FusionHDTV Hybrid Tuner
+
* HDDs totalling 1.2Tb
* DNTVLive LP Tuner
+
* Intel S775 Core 2 Q6600 Quad-Core CPU
 +
* Gigabyte S775 GA-G33M-S2 Motherboard
 +
* 4GB RAM
 +
* PCI Hauppauge Nova-T-500 MCE(OEM) Dual DVBT tuner
 +
* PCI Hauppauge Nova-TD 400 Dual DVBT tuner
 +
 
 +
=== Software ===
 +
 
 +
* MythBuntu 12.04
 +
* [[MythWeb]]
 +
* [http://svn.whuffy.com/index.fcgi/wiki Shepherd XMLTV grabber]
 +
 
 +
=== Configuration ===
 +
 
 +
* Channel 9, Gem, GO will not tune. The dtv_multiplex.network_id is null - set to 4114 seems to fix things.
 +
 
 +
==== Shepherd grabber ====
 +
 
 +
Standard install except cron job is disabled and allow mythtv to run mythfilldatabase. This is to allow mythtv to also be in control of suspend.
 +
 
 +
==== Suspend to RAM on idle ====
 +
 
 +
Why Suspend to RAM and not just a full shutdown that would "just work"?  Partly due to boot speed and partly just because.
 +
 
 +
'''Overview''':
 +
 
 +
* mythbackend controls idle detection, supported by a custom script to check other reasons to stay up, and sudo rules to allow passwordless root activity
 +
* suspend needs to unload dvb/usb modules which requires stopping mythbackend which means triggering suspend via upstart
 +
* wake up for recordings triggered by /sys/class/rtc as per [[ACPI_Wakeup]], hwlock-save update disabled via upstart override
 +
* wake up for daily processing (anacron) triggered by cron running on my (always on) DD-WRT enabled router issuing a WOL
 +
* wake up for serving adhoc web requests (mythweb et al) triggered by [[http://www.dd-wrt.com/wiki/index.php/Useful_Scripts#Web_Server_Wake-up|a custom router script]]
  
* DVICO FusionRemote
+
Settings (set via mythweb as server is basically headless)
  
 +
{| border=1 cellspacing=0 cellpadding=5
 +
| '''Name'''
 +
| '''Setting'''
 +
| '''Value'''
 +
| '''Why'''
 +
|-|
 +
| Pre ShutdownWakeUp Check Command
 +
| preSDWUCheckCommand
 +
| /home/mythtv/bin/check-idle.sh
 +
| check if i'm logged in, or machine is in use for some other reason
 +
|-
 +
| Block ShutdownWakeUp without client
 +
| blockSDWUwithoutClient
 +
| 0
 +
| because this is a backend only machine
 +
|-
 +
| Set Wakeup time command
 +
| SetWakeuptimeCommand
 +
| sudo /usr/local/sbin/set-wakeup.sh $time
 +
|-
 +
| Server Halt command
 +
| ServerHaltCommand
 +
| sudo /usr/local/sbin/emit-suspend.sh
 +
| can't suspend directly because we need to shutdown mythbackend during suspend
 +
|-
 +
| Wakeup time format
 +
| WakeupTimeFormat
 +
| time_t
 +
| as per [[ACPI_Wakeup|ACPI wakeup]] page to use /sys/class/rtc
 +
|-
 +
|}
 +
===== /home/mythtv/bin/check_idle.sh =====
 +
<pre>
 +
#!/bin/bash
 +
 +
ACCESS_LOG="/var/log/apache2/access.log"
 +
LOG_AGE="5 minutes ago"
 +
 +
check_frontend() {
 +
# Not this doesn't care about what the FE is doing, just that it is up
 +
expect - $1 <<'END_EXPECT'
 +
#exp_internal 1
 +
set timeout 2
 +
log_user 0
 +
set prompt "# "
 +
set cmd "query location\r"
 +
set frontend [lindex $argv 0]
 +
spawn netcat $frontend 6546
 +
  expect {
 +
        timeout { send_user "\nNo prompt\n"; exit 1 }
 +
        eof { send_user "\nNo output\n"; exit 1 }
 +
        $prompt
 +
  }
 +
 +
  send $cmd
 +
  expect  {
 +
      timeout { send_user "\nNo response\n"; exit 1 }
 +
      eof { send_user "\nPremature EOF\n"; exit 1 }
 +
      -re "query location\r\n(.*)\r\r\n# "
 +
  }     
 +
  set location $expect_out(1,string)
 +
  send "exit\r"
 +
  expect eof
 +
  send_user "MythTVLocation:$location\n"
 +
END_EXPECT
 +
 +
}
 +
 +
log() {
 +
  logger -s -t "mythtv-checkidle"
 +
}
 +
 +
# Regardless of WOL settings and going into standbymode the 0.25 front-end
 +
# simply cannot cope with the backend dropping out unexpectedly so we
 +
# keep the BE up until the FE suspends itself
 +
check_frontend mythion && {
 +
    echo "Frontend is still up" | log
 +
    exit 1
 +
}
 +
 +
# anacron is running daily, weekly or monthly jobs
 +
pgrep 'anacron' && {
 +
    echo "Anacron job is running" | log
 +
    exit 1
 +
}
 +
 +
# apache request in last 5 minutes
 +
if [ -f $ACCESS_LOG -a `stat -c %Y $ACCESS_LOG` -gt `date --date "$LOG_AGE" "+%s"` ] ; then
 +
    echo "Web server in use" | log
 +
    exit 1
 +
fi
 +
 +
# users are logged in
 +
if [ `who | wc -l` -gt 0 ] ; then
 +
    echo "Users logged in" | log
 +
    who | log
 +
    exit 1
 +
fi
 +
 +
/usr/bin/mythshutdown -v --check | log
 +
 +
exit ${PIPESTATUS[0]}
 +
</pre>
 +
 +
===== /etc/sudoers.d/mythtv =====
 +
<pre>
 +
#Enable mythtv to set the real time clock and emit the suspending event without a password prompt
 +
 +
%mythtv ALL = NOPASSWD: /usr/local/sbin/emit-suspend.sh, /usr/local/sbin/set-wakeup.sh
 +
</pre>
 +
 +
===== /usr/local/sbin/set-wakeup.sh =====
 +
<pre>
 +
#!/bin/sh
 +
#$1 is the first argument to the script. It is the time in seconds since 1970
 +
#this is defined in mythtv-setup with the time_t argument
 +
 +
echo 0 > /sys/class/rtc/rtc0/wakealarm      #this clears your alarm.
 +
echo $1 > /sys/class/rtc/rtc0/wakealarm    #this writes your alarm
 +
</pre>
 +
 +
===== /usr/local/sbin/emit-suspend.sh =====
 +
<pre>
 +
#!/bin/sh
 +
# Suspend via upstart
 +
initctl emit suspending
 +
</pre>
 +
 +
===== /etc/init/suspending.conf =====
 +
<pre>
 +
start on (suspending)
 +
 +
script
 +
  logger -t "suspending" "Suspending via upstart"
 +
  pm-suspend
 +
end script
 +
</pre>
 +
 +
===== /etc/pm/sleep.d/50_mythtv =====
 +
<pre>
 +
#!/bin/sh
 +
# The dvb modules need to be unloaded to allow suspend/resume to work
 +
# To unload the modules mythbackend needs to be stopped
 +
#
 +
# NOTE: Suspend cannot be executed in a child process of mythbackend itself (eg via server halt command)
 +
# since it will simply abort at the point we stop mythbackend below. If this is required use upstart or some
 +
# other means to decouple pm-suspend from the mythbackend process.
 +
#!/bin/bash
 +
 +
LOG=/var/log/mythtv/mythsuspend.log
 +
MODULE="dvb_usb_dib0700"
 +
 +
echo "Will now $1 mythtv" | tee -a $LOG
 +
 +
case $1 in
 +
  suspend|hibernate)
 +
       
 +
        stop mythtv-backend 2>&1 | tee -a $LOG
 +
     
 +
        while [ `lsmod | grep "^${MODULE}" | wc -l` -gt 0 ]
 +
        do
 +
            sleep 1
 +
            modprobe -r $MODULE 2>&1 | tee -a $LOG
 +
        done
 +
  ;;
 +
  resume|thaw)
 +
       
 +
        modprobe $MODULE
 +
        start mythtv-backend | tee -a $LOG
 +
  ;;
 +
esac
 +
 +
</pre>
 +
 +
== Frontend ==
 +
 +
=== Hardware ===
 +
* ZOTAC ionitx-d-e board, 2G memory
 +
* Szrealan E-2011 case (tiny!)
 +
* External DVD player
 +
* 1Tb external e-Sata drive
 
* BenQ PE8700 DLP Projector
 
* BenQ PE8700 DLP Projector
 +
* Sony Bravia TV over HDMI
 +
* CambridgeAudio AV receiver
 +
  
 
=== Software ===
 
=== Software ===
* Ubuntu Dapper (upgraded from Breezy server install)
+
* MythBuntu 12.04 64bit
* Kernel 2.6.15-27-amd64-k8
+
* [http://synergy2.sourceforge.net/ Synergy] to allow laptop to be the keyboard/mouse.
* v4l-dvb-0.9 drivers patched to handle vendor/device codes being the same between 2 different devices!!  (Many thanks to [http://www.itee.uq.edu.au/~chrisp/Linux-DVB/ Chris Pascoe] for getting the DVICO card going)
 
* [http://www.nvidia.com/object/unix.html NVidia amd64 version 8774]
 
* lirc version 0.8.0 (Dapper upgrade changed device from <code>/dev/usb/hiddev0</code> to <code>/dev/hiddev0</code>
 
* [[Ratpoison]] window manager
 
* MythTV 0.20.x fixes branch
 
  
 +
=== Configuration ===
  
 +
==== Enable Wake on USB ====
 +
We need to enable USB0 in /proc/acpi/wakeup
  
== What's working for me ==
+
Note if USB2 is also enabled, then the board immediately wakes up regardless, unsure if this is due to another USB device
  
* Live TV/TV recording Free to air HD/SD (from Sydney, Australia). Both tuner's simultaneously.
+
Seems to be enabled by default for Mythbuntu 12.04 but
* AC3 passthrough including 5,1 surround
+
Current cheap as Chinese remote does not send the wakeup signal from the power button unfortunately
* [http://www.cse.unsw.edu.au/~willu/xmltv/tv_grab_au_reg.html XMLTV grabber] from the OZTivo site
+
 
* XvMC but I'm not really sure if it helps
+
==== Auto-start X ====
* [[MythMusic]]
+
 
* [[MythGallery]]
+
* disabled lightdm in via upstart override (echo 'manual' > /etc/init/lightdm.override)  
* [[MythDVD]] using xine as an external player
+
* [[Frontend Auto Login|Simple mingetty startup]] with a tty definition and a startx script in the console
* [[MythWeb on Jetty]] rather than apache including the WAP version on the BlackBerry!
+
* user .xsession linked to /usr/share/mythbuntu/session.sh so we get the same xfce startup.
* Using irexec to restart Myth, including with a different Layout to switch between the Projector and TV
+
 
 +
===== /etc/init/tty7.conf =====
 +
<pre>
 +
# tty7 - mythtv
 +
#
 +
start on runlevel [23]
 +
stop on runlevel [!23]
 +
 
 +
respawn
 +
exec /sbin/mingetty --autologin=mythtv tty7
 +
</pre>
 +
 
 +
===== ~mythtv/.profile =====
 +
Appended to detect if we are on tty7, in which case we start-up X with an optional layout specified in ~/.mythrc
 +
 
 +
Note that when X is stopped we automatically logout and respawn
 +
 
 +
<pre>
 +
start-frontend() {
 +
MYTHRC="$HOME/.mythrc"
 +
if [ -r $MYTHRC ] ; then
 +
  . $MYTHRC
 +
fi
 +
 
 +
LAYOUT_SPEC=
 +
[ ! -z "$LAYOUT" ] && LAYOUT_SPEC="-layout $LAYOUT"
 +
 
 +
startx --  $LAYOUT_SPEC -logverbose 5
 +
logout
 +
}
  
== What's not ==
+
tty | grep tty7 && start-frontend
* The Gigabyte FX5200 card does not do PAL output properly, as it renders in B&W. Fortunately my TV autodetects NTSC colour.
+
</pre>
* The Albatron FX5200 card has been fingered as the cause of my DVI problems on my projector. Apparently it freaks out a PCB component causing the EDID data to become corrupt. (So far so good on the Gigabyte card since Aug 2006).
 
  
== What more do I want to do ==
+
===== xorg.conf =====
* I'd like MythMusic to use MythGallery as a visualisation!
+
For PE8700  Samsung LCD. See also the tips for the [[NVidiaProprietaryDriver]]
* More cleanup of MythGallery thumbnail code. (Thumbnail cache is unnecessary if EXIF thumbnails are available in the images themselves)
 
  
== Useful config info ==
+
The FX5200 cards were the cause of my DVI problems on my projector. Apparently they freak out a PCB component causing the EDID data to become corrupt.
xorg.conf for PE8700, Samsung LCD
+
(a Gigabyte card lasted from Aug 2006 to Dec 2007. Fortunately the new nvidia driver allow you to use a CustomEDID to load the data from a file.
  
Option ExactModeTimingsDVI is important for the projector.
+
Option ExactModeTimingsDVI is also important for the projector.
This is the main detail, the driver autodetects the connected display and will use the Projector (DFP) in preference to TV-Out.
 
  
Option "UseEDIDDpi" "false" is important for the Samsung television otherwise you get really small fonts!
+
Option "UseEDIDDpi" "false" or some equivalent control of DPI is important for the Samsung television otherwise you get really small fonts (fixed in 0.21)
  
 
There are two layouts, the default uses outputs via VGA to a Samsung LCD television, the second uses DVI to the PE8700 projector.
 
There are two layouts, the default uses outputs via VGA to a Samsung LCD television, the second uses DVI to the PE8700 projector.
Line 63: Line 307:
 
<pre>
 
<pre>
 
Section "ServerLayout"
 
Section "ServerLayout"
     Identifier    "Main" # PC VGA output to Samsung LCD television
+
     Identifier    "Main" # Output to Samsung LCD television
     Screen        0 "LCD[0]" 0 0
+
#LCD[0] VGA, LCD[1] HDMI
    InputDevice    "Generic Keyboard"
+
     Screen        0 "LCD[1]" 0 0
    InputDevice    "Configured Mouse"
 
 
     Option        "Xinerama" "off"
 
     Option        "Xinerama" "off"
 
EndSection
 
EndSection
Line 73: Line 316:
 
     Identifier    "Projector"
 
     Identifier    "Projector"
 
     Screen        0 "Projector[0]" 0 0
 
     Screen        0 "Projector[0]" 0 0
    InputDevice    "Generic Keyboard"
 
    InputDevice    "Configured Mouse"
 
 
     Option        "Xinerama" "off"
 
     Option        "Xinerama" "off"
 
EndSection
 
EndSection
 
   
 
   
# .... skipped Files, Modules, InputDevice ....
+
Section "Module"
 +
        Load    "glx"
 +
EndSection
  
 
Section "Device"
 
Section "Device"
     Identifier    "FX5200[0]"
+
     Identifier    "ION-GPU[0]"
 
     Driver        "nvidia"
 
     Driver        "nvidia"
     BusID          "PCI:1:0:0"
+
     BusID          "PCI:3:0:0"
 
     Screen        0
 
     Screen        0
     Option        "NvAGP" "3"
+
    #This prevents the cursor being displayed on resume from suspend
 +
     Option        "HWCursor" "off"
 +
EndSection
 +
 
 +
Section "Screen"
 +
    Identifier    "LCD[1]"
 +
    Device        "ION-GPU[0]"
 +
    Monitor        "AnyMonitor"
 +
    DefaultDepth    24
 +
    Option        "UseDisplayDevice" "DFP-1" # HDMI
 +
    Option        "ConnectedMonitor" "DFP-1"
 
EndSection
 
EndSection
  
 
Section "Screen"
 
Section "Screen"
 
     Identifier    "LCD[0]"
 
     Identifier    "LCD[0]"
     Device        "FX5200[0]"
+
     Device        "ION-GPU[0]"
 
     Monitor        "AnyMonitor"
 
     Monitor        "AnyMonitor"
 
     DefaultDepth    24
 
     DefaultDepth    24
 +
    Option        "ConnectedMonitor" "CRT-1"
 
     Option        "UseEDIDDpi" "FALSE" #Computed DPI values not so good for TV display
 
     Option        "UseEDIDDpi" "FALSE" #Computed DPI values not so good for TV display
     Option        "UseDisplayDevice" "CRT" # VGA out
+
     Option        "UseDisplayDevice" "CRT-1" # VGA out
 
     SubSection    "Display"
 
     SubSection    "Display"
 
         Depth      24
 
         Depth      24
Line 103: Line 357:
 
Section "Screen"
 
Section "Screen"
 
     Identifier    "Projector[0]"
 
     Identifier    "Projector[0]"
     Device        "FX5200[0]"
+
     Device        "ION-GPU[0]"
 
     Monitor        "AnyMonitor"
 
     Monitor        "AnyMonitor"
 +
    Option        "ConnectedMonitor" "DFP"
 
     Option        "UseDisplayDevice" "DFP" # DVI out
 
     Option        "UseDisplayDevice" "DFP" # DVI out
 +
    Option        "CustomEDID" "DFP-0:/etc/X11/benq-c.bin"
 +
 
     DefaultDepth    24
 
     DefaultDepth    24
 
     SubSection    "Display"
 
     SubSection    "Display"
Line 119: Line 376:
 
     Option      "RenderAccel" "true"
 
     Option      "RenderAccel" "true"
 
EndSection
 
EndSection
 
  
 
</pre>
 
</pre>
  
.asoundrc For ALSA digital audio out
+
===== ~mythtv/.mythtv/session =====
 
<pre>
 
<pre>
pcm.!default {
+
#!/bin/sh
type plug
+
LAPTOP=
slave {
+
 
pcm "spdif"
+
export | egrep "DBUS_SESSION_BUS_ADDRESS|DISPLAY" > ~/.xsession-export
rate 48000
+
#unclutter -root -idle 2 -display $DISPLAY &
format S16_LE
+
 
}
+
# Start a synergy client
}
+
synergyc $LAPTOP
 +
 
 +
# Start an idle detection loop
 +
idle_mythtv.sh &
 
</pre>
 
</pre>
  
/etc/inittab entry to auto login the mythtv user
+
===== ~mythtv/bin/idle_mythtv.sh =====
 
<pre>
 
<pre>
1:2345:respawn:/sbin/mingetty --autologin mythtv tty1
+
#!/bin/bash
</pre>
+
 
 +
WAIT_STARTUP=300
 +
WAIT_CHECK=60
 +
 
 +
# Don't idle immediately!
 +
sleep $WAIT_STARTUP
  
 +
while true
 +
do
 +
        if check_idle.sh ; then
 +
    suspend_mythtv.sh
 +
            # we only do this because although irexec responds fine, mythtv's
 +
            # lirc connection can't reset itself on resume from suspend
 +
            kill_mythtv.sh
  
.profile to start X from the auto login, also starts irexec.
+
    # if kill_mythtv above works then we'll be dead here
 +
            sleep $WAIT_STARTUP
 +
        else
 +
    sleep $WAIT_CHECK
 +
        fi
 +
done
 +
</pre>
 +
===== ~mythtv/bin/check_idle.sh =====
 
<pre>
 
<pre>
PATH=$PATH:$HOME/bin
+
#!/bin/bash
  
start-frontend() {
+
check_frontend() {
rm $HOME/.serverauth.*
 
irexec --daemon $HOME/.lircrc >> $HOME/irexec.log
 
  
MYTHRC="$HOME/.mythrc"
+
expect - $1 <<'END_EXPECT'
if [ -r $MYTHRC ] ; then
+
#exp_internal 1
  . $MYTHRC
+
set timeout 2
fi
+
log_user 0
 +
set prompt "# "
 +
set cmd "query location\r"
 +
set frontend [lindex $argv 0]
 +
spawn netcat $frontend 6546
 +
  expect {
 +
        timeout { send_user "\nNo prompt\n"; exit 1 }
 +
        eof { send_user "\nNo output\n"; exit 1 }
 +
        $prompt
 +
  }
  
LAYOUT_SPEC=
+
  send $cmd
[ ! -z "$LAYOUT" ] && LAYOUT_SPEC="-layout $LAYOUT"
+
  expect  {
 +
      timeout { send_user "\nNo response\n"; exit 1 }
 +
      eof { send_user "\nPremature EOF\n"; exit 1 }
 +
      -re "query location\r\n(.*)\r\r\n# "
 +
  }     
 +
  set location $expect_out(1,string)
 +
  send "exit\r"
 +
  expect eof
 +
  send_user "MythTVLocation:$location\n"
 +
END_EXPECT
  
startx --  $LAYOUT_SPEC -logverbose 5
 
 
}
 
}
  
tty | grep tty1 && start-frontend
+
# Is frontend in standbymode?
 +
check_frontend localhost | grep "standbymode"
 +
if [ ${PIPESTATUS[0]} -eq 0 -a ${PIPESTATUS[1]} -ne 0 ]; then
 +
  echo "Frontend is up and not in standbymode"
 +
  exit 1
 +
fi
 +
 
 +
OTHER_USERS=$(who | grep -v "mythtv" |  wc -l)
 +
if [ ${OTHER_USERS} -gt 0 ] ; then
 +
  who | grep -v "mythtv"
 +
  exit 1
 +
fi
  
 +
# Backups in progress
 +
if [ -f /var/local/backups/mythion_daily.inprogress ] ; then
 +
  echo "Jenix/Mythion backups in progress"
 +
  exit 1
 +
fi
  
 +
# anacron is running daily, weekly or monthly jobs
 +
pgrep 'anacron' && {
 +
    echo "Anacron job is running"
 +
    exit 1
 +
}
 +
exit 0
 
</pre>
 
</pre>
 
+
===== ~mythtv/bin/suspend_mythtv.sh =====
.xsession To start Ratpoison, mythtv-setup and mythfrontend
 
 
<pre>
 
<pre>
#Remove blue background... from TV-Out picture
+
#!/bin/sh
xvattr -a XV_COLORKEY -v 0
 
ratpoison &
 
echo $DISPLAY
 
  
if [ -r $HOME/.mythrc ] ; then
+
# We use dbus-send because it seems to block until resume which is what we want
    . $HOME/.mythrc
+
echo "Suspending"
    rm $HOME/.mythrc
 
fi
 
  
if [ ! -z "$MYTH_SETUP" ] ; then
+
dbus-send --system --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer \
  mythtv-setup
+
        org.freedesktop.Hal.Device.SystemPowerManagement.Suspend int32:2
fi
 
mythfrontend  -l mfe.log  $MYTH_ARGS
 
  
 +
echo "Resumed"
 
</pre>
 
</pre>
  
.ratpoisonrc
+
===== ~mythtv/bin/kill_mythtv.sh =====
 +
Clean restart of the front end
 +
 
 +
Kill mythtv and logout of xfce (respawn of tty causes immediate restart)
 
<pre>
 
<pre>
#Make escape (default C-t) not clash with mythTV key bindings
+
#!/bin/sh
escape C-r
+
 
#Banish the mouse cursor out of the way.
+
[ -f $HOME/.xsession-export ] && . $HOME/.xsession-export
addhook switchwin banish
+
echo "killing mythfrontend"
 +
pkill mythfrontend
 +
#pkill unclutter
 +
echo "xfce logout $DISPLAY"
 +
xfce4-session-logout --logout --fast
 
</pre>
 
</pre>
  
ir_mythtv.sh script to restart MythTV via irexec.
+
==== LIRC Remote Control ====
 +
 
 +
Standard mythbuntu setup for MCE remote.
 +
 
 +
power button is mapped vie irexec to kill_mythtv.sh
 +
 
 +
==== Sound ====
 +
 
 +
Onboard sound
 +
 
 +
=====~/.asoundrc=====
 +
 
 +
Could probably do better 48/44kHz switching on the analog output between music and video but if that is important we just go digital passthrough and let the receiver do the work.
 +
 
 +
In myth config, you can see that default sound device is ALSA:myth-video, the passthrough device is ALSA:myth-passthru, and mythmusic uses ALSA:myth-music. the AC3PassThru and DTSPassThru
 +
settings are managed by the ruby program
 +
 
 
<pre>
 
<pre>
#!/bin/bash
+
#First line comment
  
function log() {
+
pcm.myth-music {
  logger -t "mythtv" "$@"
+
  type copy
 +
  slave.pcm "default"
 
}
 
}
  
parseopts() {
+
ctl.myth-music {
    MYTH_SETUP=
+
  type hw
    LAYOUT=
+
  card 0
    MYTH_ARGS=
+
}
  
    while [ ! -z "$1" ]
+
pcm.myth-video {
    do
+
  type copy
        case "$1" in
+
  slave.pcm "default"
            -l|--layout)
+
}
                LAYOUT="$2"
 
                shift;;
 
            -s|--setup)
 
                MYTH_SETUP="y"
 
                ;;
 
            -m|--mythargs)
 
                MYTH_ARGS="$2"
 
                shift
 
                ;;
 
  
            *) break ;;
+
ctl.myth-video {
        esac
+
  type hw
        shift
+
  card 0
    done
 
 
}
 
}
  
 +
pcm.myth-passthru {
 +
  type copy
 +
  slave.pcm = "spdif"
 +
}
  
GETOPT=$(getopt -l "setup,layout:,mythargs:" -o "sl:m:" -- "$@")
+
ctl.myth-passthru {
 +
  type hw
 +
  card 0
 +
}
  
if [ $? -ne 0 ] ; then
+
</pre>
    exit 1
 
fi
 
  
eval parseopts $GETOPT
+
=== minimyth.conf ===
 +
TODO - Works nicely through the WRT310N router etc, but we have a hard drive have decided to stick with Mythbuntu for now.
  
OLDEST=$(pgrep -o -u $USER $(basename $0))
+
== Upgrades ==
if [ $OLDEST -ne $$ ] ; then
 
  log "Process $OLDEST is still running, so I ($$) will abort"
 
  exit 1
 
fi
 
  
log "Restarting on tty1 $USER $(basename $0)"
+
=== Mythbuntu 12.04 ===
  
cat - << EOF > $HOME/.mythrc
+
Reconfigured from scratch for no particular reason
LAYOUT=$LAYOUT
 
MYTH_SETUP="$MYTH_SETUP"
 
MYTH_ARGS="$MYTH_ARGS"
 
EOF
 
  
pkill -u mythtv irexec
+
=== Mythbuntu 10.10 ===
  
pkill -t tty1 -u mythtv mythfrontend
+
100% clean on server
sleep 2
 
pkill -t tty7
 
#Kill the login shell.
 
pkill -9 -t tty1 -u mythtv
 
  
 +
front end was missing non-versioned symlink for vdpau nvidia library
 +
<pre>
 +
ln -s /etc/alternatives/libvdpau_nvidia.so /usr/lib/libvdpau_nvidia.so
 
</pre>
 
</pre>
  
the .lircrc file (buttons as per the DVICO remote, which I think are now standard in the lirc distribution)
+
=== Mythbuntu 9.10 ===
<pre>
+
 
## irexec
+
100% clean on server
# Bounce this tty
+
 
begin
+
front end needed /etc/events.d/tty7 moved to /etc/init/tty7.conf
    button = power_onoff
 
    prog  = irexec
 
    config = /home/mythtv/bin/ir_mythtv.sh &
 
end
 
  
#Run myth-setup before running mythfrontend
+
=== Mythbuntu 8.10  ===
begin
 
    button = cpf
 
    prog  = irexec
 
    config = /home/mythtv/bin/ir_mythtv.sh --setup &
 
end
 
  
#Bounce the tty, use the Projector layout.
+
=== 0.21-fixes ===
begin
+
upgrade smooth
    button = tv_onoff
 
    prog  = irexec
 
    config = /home/mythtv/bin/ir_mythtv.sh --layout Projector &
 
end
 
</pre>
 
  
=== 0.19.x fixes info ===
+
[[Category:User_Systems]]
* MythTV 0.19.x fixes branch (had to move <code>/usr/lib/libdts_pic.a</code> to <code>/usr/lib/libdts.a</code> to compile)
 
* [http://xinehq.de Xine] external DVD/video player
 
* XvMC  ( with Bob de-interlacing for HD channels. Have to manually turn it off for SD stuff).
 

Revision as of 00:52, 2 February 2013

I was keeping track of where I was at with Myth on my home wiki, but then figured I might as well share it here!

My Setup

MythBuntu 12.04 with separated front-end/backend

  • Live TV/TV recording Free to air HD/SD (from Sydney, Australia)
  • Multi-rec
  • DTS/AC3 passthrough including 5,1 surround digital out
  • VDPAU
  • MythMusic
  • MythGallery
  • MythVideo
  • Frontend Suspend to RAM + Wake On USB
  • Backend Suspend to RAM

Backend

Hardware

  • HDDs totalling 1.2Tb
  • Intel S775 Core 2 Q6600 Quad-Core CPU
  • Gigabyte S775 GA-G33M-S2 Motherboard
  • 4GB RAM
  • PCI Hauppauge Nova-T-500 MCE(OEM) Dual DVBT tuner
  • PCI Hauppauge Nova-TD 400 Dual DVBT tuner

Software

Configuration

  • Channel 9, Gem, GO will not tune. The dtv_multiplex.network_id is null - set to 4114 seems to fix things.

Shepherd grabber

Standard install except cron job is disabled and allow mythtv to run mythfilldatabase. This is to allow mythtv to also be in control of suspend.

Suspend to RAM on idle

Why Suspend to RAM and not just a full shutdown that would "just work"? Partly due to boot speed and partly just because.

Overview:

  • mythbackend controls idle detection, supported by a custom script to check other reasons to stay up, and sudo rules to allow passwordless root activity
  • suspend needs to unload dvb/usb modules which requires stopping mythbackend which means triggering suspend via upstart
  • wake up for recordings triggered by /sys/class/rtc as per ACPI_Wakeup, hwlock-save update disabled via upstart override
  • wake up for daily processing (anacron) triggered by cron running on my (always on) DD-WRT enabled router issuing a WOL
  • wake up for serving adhoc web requests (mythweb et al) triggered by [custom router script]

Settings (set via mythweb as server is basically headless)

Name Setting Value Why
Pre ShutdownWakeUp Check Command preSDWUCheckCommand /home/mythtv/bin/check-idle.sh check if i'm logged in, or machine is in use for some other reason
Block ShutdownWakeUp without client blockSDWUwithoutClient 0 because this is a backend only machine
Set Wakeup time command SetWakeuptimeCommand sudo /usr/local/sbin/set-wakeup.sh $time
Server Halt command ServerHaltCommand sudo /usr/local/sbin/emit-suspend.sh can't suspend directly because we need to shutdown mythbackend during suspend
Wakeup time format WakeupTimeFormat time_t as per ACPI wakeup page to use /sys/class/rtc
/home/mythtv/bin/check_idle.sh
#!/bin/bash

ACCESS_LOG="/var/log/apache2/access.log"
LOG_AGE="5 minutes ago"

check_frontend() {
# Not this doesn't care about what the FE is doing, just that it is up
expect - $1 <<'END_EXPECT'
#exp_internal 1
set timeout 2
log_user 0
set prompt "# "
set cmd "query location\r"
set frontend [lindex $argv 0]
spawn netcat $frontend 6546
  expect {
        timeout { send_user "\nNo prompt\n"; exit 1 }
        eof { send_user "\nNo output\n"; exit 1 }
        $prompt
  }

  send $cmd
  expect  {
       timeout { send_user "\nNo response\n"; exit 1 } 
       eof { send_user "\nPremature EOF\n"; exit 1 }
       -re "query location\r\n(.*)\r\r\n# "
  }       
  set location $expect_out(1,string)
  send "exit\r"
  expect eof
  send_user "MythTVLocation:$location\n"
END_EXPECT

}

log() {
  logger -s -t "mythtv-checkidle"
}

# Regardless of WOL settings and going into standbymode the 0.25 front-end
# simply cannot cope with the backend dropping out unexpectedly so we
# keep the BE up until the FE suspends itself
check_frontend mythion && {
    echo "Frontend is still up" | log
    exit 1
}

# anacron is running daily, weekly or monthly jobs
pgrep 'anacron' && {
    echo "Anacron job is running" | log
    exit 1
}

# apache request in last 5 minutes
if [ -f $ACCESS_LOG -a `stat -c %Y $ACCESS_LOG` -gt `date --date "$LOG_AGE" "+%s"` ] ; then
    echo "Web server in use" | log
    exit 1
fi

# users are logged in
if [ `who | wc -l` -gt 0 ] ; then
    echo "Users logged in" | log
    who | log
    exit 1
fi

/usr/bin/mythshutdown -v --check | log

exit ${PIPESTATUS[0]}
/etc/sudoers.d/mythtv
#Enable mythtv to set the real time clock and emit the suspending event without a password prompt

%mythtv ALL = NOPASSWD: /usr/local/sbin/emit-suspend.sh, /usr/local/sbin/set-wakeup.sh
/usr/local/sbin/set-wakeup.sh
#!/bin/sh
#$1 is the first argument to the script. It is the time in seconds since 1970
#this is defined in mythtv-setup with the time_t argument

echo 0 > /sys/class/rtc/rtc0/wakealarm      #this clears your alarm.
echo $1 > /sys/class/rtc/rtc0/wakealarm     #this writes your alarm
/usr/local/sbin/emit-suspend.sh
#!/bin/sh
# Suspend via upstart
initctl emit suspending
/etc/init/suspending.conf
start on (suspending)

script
   logger -t "suspending" "Suspending via upstart" 
   pm-suspend
end script
/etc/pm/sleep.d/50_mythtv
#!/bin/sh
# The dvb modules need to be unloaded to allow suspend/resume to work
# To unload the modules mythbackend needs to be stopped
# 
# NOTE: Suspend cannot be executed in a child process of mythbackend itself (eg via server halt command)
# since it will simply abort at the point we stop mythbackend below. If this is required use upstart or some
# other means to decouple pm-suspend from the mythbackend process.
#!/bin/bash

LOG=/var/log/mythtv/mythsuspend.log
MODULE="dvb_usb_dib0700"

echo "Will now $1 mythtv" | tee -a $LOG

case $1 in
  suspend|hibernate)
        
        stop mythtv-backend 2>&1 | tee -a $LOG
      
        while [ `lsmod | grep "^${MODULE}" | wc -l` -gt 0 ]
        do 
            sleep 1
            modprobe -r $MODULE 2>&1 | tee -a $LOG 
        done
  ;;
  resume|thaw)
        
        modprobe $MODULE
        start mythtv-backend | tee -a $LOG
  ;;
esac

Frontend

Hardware

  • ZOTAC ionitx-d-e board, 2G memory
  • Szrealan E-2011 case (tiny!)
  • External DVD player
  • 1Tb external e-Sata drive
  • BenQ PE8700 DLP Projector
  • Sony Bravia TV over HDMI
  • CambridgeAudio AV receiver


Software

  • MythBuntu 12.04 64bit
  • Synergy to allow laptop to be the keyboard/mouse.

Configuration

Enable Wake on USB

We need to enable USB0 in /proc/acpi/wakeup

Note if USB2 is also enabled, then the board immediately wakes up regardless, unsure if this is due to another USB device

Seems to be enabled by default for Mythbuntu 12.04 but Current cheap as Chinese remote does not send the wakeup signal from the power button unfortunately

Auto-start X

  • disabled lightdm in via upstart override (echo 'manual' > /etc/init/lightdm.override)
  • Simple mingetty startup with a tty definition and a startx script in the console
  • user .xsession linked to /usr/share/mythbuntu/session.sh so we get the same xfce startup.
/etc/init/tty7.conf
# tty7 - mythtv
#
start on runlevel [23]
stop on runlevel [!23]

respawn
exec /sbin/mingetty --autologin=mythtv tty7
~mythtv/.profile

Appended to detect if we are on tty7, in which case we start-up X with an optional layout specified in ~/.mythrc

Note that when X is stopped we automatically logout and respawn

start-frontend() {
MYTHRC="$HOME/.mythrc"
if [ -r $MYTHRC ] ; then
   . $MYTHRC
fi

LAYOUT_SPEC=
[ ! -z "$LAYOUT" ] && LAYOUT_SPEC="-layout $LAYOUT"

startx --  $LAYOUT_SPEC -logverbose 5
logout
}

tty | grep tty7 && start-frontend
xorg.conf

For PE8700 Samsung LCD. See also the tips for the NVidiaProprietaryDriver

The FX5200 cards were the cause of my DVI problems on my projector. Apparently they freak out a PCB component causing the EDID data to become corrupt. (a Gigabyte card lasted from Aug 2006 to Dec 2007. Fortunately the new nvidia driver allow you to use a CustomEDID to load the data from a file.

Option ExactModeTimingsDVI is also important for the projector.

Option "UseEDIDDpi" "false" or some equivalent control of DPI is important for the Samsung television otherwise you get really small fonts (fixed in 0.21)

There are two layouts, the default uses outputs via VGA to a Samsung LCD television, the second uses DVI to the PE8700 projector.

Section "ServerLayout"
    Identifier     "Main" # Output to Samsung LCD television
#LCD[0] VGA, LCD[1] HDMI
    Screen         0 "LCD[1]" 0 0
    Option         "Xinerama" "off"
EndSection

Section "ServerLayout"
    Identifier     "Projector"
    Screen         0 "Projector[0]" 0 0
    Option         "Xinerama" "off"
EndSection
 
Section "Module"
        Load    "glx"
EndSection

Section "Device"
    Identifier     "ION-GPU[0]"
    Driver         "nvidia"
    BusID          "PCI:3:0:0"
    Screen         0
    #This prevents the cursor being displayed on resume from suspend
    Option         "HWCursor" "off"
EndSection

Section "Screen"
    Identifier     "LCD[1]"
    Device         "ION-GPU[0]"
    Monitor        "AnyMonitor"
    DefaultDepth    24
    Option         "UseDisplayDevice" "DFP-1" # HDMI
    Option         "ConnectedMonitor" "DFP-1"
EndSection

Section "Screen"
    Identifier     "LCD[0]"
    Device         "ION-GPU[0]"
    Monitor        "AnyMonitor"
    DefaultDepth    24
    Option         "ConnectedMonitor" "CRT-1"
    Option         "UseEDIDDpi" "FALSE" #Computed DPI values not so good for TV display
    Option         "UseDisplayDevice" "CRT-1" # VGA out
    SubSection     "Display"
        Depth       24
        Modes       "1360x768" "800x600"
    EndSubSection
EndSection

Section "Screen"
    Identifier     "Projector[0]"
    Device         "ION-GPU[0]"
    Monitor        "AnyMonitor"
    Option         "ConnectedMonitor" "DFP"
    Option         "UseDisplayDevice" "DFP" # DVI out
    Option         "CustomEDID" "DFP-0:/etc/X11/benq-c.bin"

    DefaultDepth    24
    SubSection     "Display"
        Depth       24
        Modes       "1280x720" "800x600"
    EndSubSection
EndSection

Section "Monitor"
    Identifier   "AnyMonitor"
    Option       "DPMS"
    Option       "ExactModeTimingsDVI" "true"
    Option       "RenderAccel" "true"
EndSection

~mythtv/.mythtv/session
#!/bin/sh
LAPTOP=

export | egrep "DBUS_SESSION_BUS_ADDRESS|DISPLAY" > ~/.xsession-export
#unclutter -root -idle 2 -display $DISPLAY &

# Start a synergy client
synergyc $LAPTOP

# Start an idle detection loop
idle_mythtv.sh & 
~mythtv/bin/idle_mythtv.sh
#!/bin/bash

WAIT_STARTUP=300
WAIT_CHECK=60

# Don't idle immediately!
sleep $WAIT_STARTUP 

while true
do
        if check_idle.sh ; then
	    suspend_mythtv.sh
            # we only do this because although irexec responds fine, mythtv's
            # lirc connection can't reset itself on resume from suspend
            kill_mythtv.sh

	    # if kill_mythtv above works then we'll be dead here
            sleep $WAIT_STARTUP
        else
	    sleep $WAIT_CHECK
        fi
done
~mythtv/bin/check_idle.sh
#!/bin/bash

check_frontend() {

expect - $1 <<'END_EXPECT'
#exp_internal 1
set timeout 2
log_user 0
set prompt "# "
set cmd "query location\r"
set frontend [lindex $argv 0]
spawn netcat $frontend 6546
  expect {
        timeout { send_user "\nNo prompt\n"; exit 1 }
        eof { send_user "\nNo output\n"; exit 1 }
        $prompt
  }

  send $cmd
  expect  {
       timeout { send_user "\nNo response\n"; exit 1 } 
       eof { send_user "\nPremature EOF\n"; exit 1 }
       -re "query location\r\n(.*)\r\r\n# "
  }       
  set location $expect_out(1,string)
  send "exit\r"
  expect eof
  send_user "MythTVLocation:$location\n"
END_EXPECT

}

# Is frontend in standbymode?
check_frontend localhost | grep "standbymode"
if [ ${PIPESTATUS[0]} -eq 0 -a ${PIPESTATUS[1]} -ne 0 ]; then
  echo "Frontend is up and not in standbymode"
  exit 1
fi

OTHER_USERS=$(who | grep -v "mythtv" |  wc -l)
if [ ${OTHER_USERS} -gt 0 ] ; then
  who | grep -v "mythtv"
  exit 1
fi

# Backups in progress
if [ -f /var/local/backups/mythion_daily.inprogress ] ; then
   echo "Jenix/Mythion backups in progress"
   exit 1
fi

# anacron is running daily, weekly or monthly jobs
pgrep 'anacron' && {
    echo "Anacron job is running"
    exit 1
}
exit 0
~mythtv/bin/suspend_mythtv.sh
#!/bin/sh

# We use dbus-send because it seems to block until resume which is what we want
echo "Suspending"

dbus-send --system --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer \
        org.freedesktop.Hal.Device.SystemPowerManagement.Suspend int32:2

echo "Resumed"
~mythtv/bin/kill_mythtv.sh

Clean restart of the front end

Kill mythtv and logout of xfce (respawn of tty causes immediate restart)

#!/bin/sh

[ -f $HOME/.xsession-export ] && . $HOME/.xsession-export
echo "killing mythfrontend"
pkill mythfrontend
#pkill unclutter
echo "xfce logout $DISPLAY"
xfce4-session-logout --logout --fast

LIRC Remote Control

Standard mythbuntu setup for MCE remote.

power button is mapped vie irexec to kill_mythtv.sh

Sound

Onboard sound

~/.asoundrc

Could probably do better 48/44kHz switching on the analog output between music and video but if that is important we just go digital passthrough and let the receiver do the work.

In myth config, you can see that default sound device is ALSA:myth-video, the passthrough device is ALSA:myth-passthru, and mythmusic uses ALSA:myth-music. the AC3PassThru and DTSPassThru settings are managed by the ruby program

#First line comment

pcm.myth-music {
  type copy
  slave.pcm "default"
}

ctl.myth-music {
  type hw
  card 0
}

pcm.myth-video {
  type copy 
  slave.pcm "default"
}

ctl.myth-video {
  type hw
  card 0
}

pcm.myth-passthru {
  type copy
  slave.pcm = "spdif"
}

ctl.myth-passthru {
  type hw
  card 0
}

minimyth.conf

TODO - Works nicely through the WRT310N router etc, but we have a hard drive have decided to stick with Mythbuntu for now.

Upgrades

Mythbuntu 12.04

Reconfigured from scratch for no particular reason

Mythbuntu 10.10

100% clean on server

front end was missing non-versioned symlink for vdpau nvidia library

ln -s /etc/alternatives/libvdpau_nvidia.so /usr/lib/libvdpau_nvidia.so

Mythbuntu 9.10

100% clean on server

front end needed /etc/events.d/tty7 moved to /etc/init/tty7.conf

Mythbuntu 8.10

0.21-fixes

upgrade smooth