Difference between revisions of "Running MythTV Dual Headed"

From MythTV Official Wiki
Jump to: navigation, search
(One X server, two displays (non-xinerama method))
(One X server, two displays (non-xinerama method))
Line 151: Line 151:
 
-- [[User:Mamoulian|Mamoulian]]
 
-- [[User:Mamoulian|Mamoulian]]
  
Well... is this just bragging?  You do not specify the changes needed.  I simply can not make this work because configuring X is such a black art.  Little chance of succeeding without seeing your xorg.conf.
+
Well, is this just bragging?  You do not specify the changes needed.  I simply can not make this work because configuring X is such a black art.  Little chance of succeeding without seeing your xorg.conf.
 +
Oh thank goodness, the post further down has the vital info, and works well. (PIP Display)
  
  

Revision as of 17:28, 25 January 2009

This little 'HowTo' lets you run two instances of Myth on the same machine.

There are many ways of using 2 screens - this just addresses one way - feel free to add more...

Why

I use this because I have a TV and a projector connected to my Myth box. It could work for people who want to play games on an accelerated VGA display and watch TV on a PVR350.

How (Two X servers, one active at a time)

Linux is a multi-user OS - so you simply create a second myth user and use it to run mythfrontend.

I end up with 1 instance of mythfrontend running through my PVR350 to my TV (accessed through Virtual Terminal 7) and another running through my NVidia card to my projector (on VT-8).

(Note: You can have X just clone to both displays at the same time, and just power up the projector when you want to use it, but that is outside the scope of this HowTo)

So first create a new user (I used mythbig)

Logging In

Here's the /etc/init.d/ script I use

#! /bin/sh
#
# Originally based on:
# Version:      @(#)skeleton  1.8  03-Mar-1998  miquels@cistron.nl
#
# Modified for projector David Greaves 12/Jul/04

set -e

PATH=/sbin:/bin:/usr/sbin:/usr/bin
PIDFILE=/var/run/gdm.pid

case "$1" in
  start)
        chvt 8
        nohup su - mythbig /home/mythbig/runx >>/var/log/projector.log 2>&1 &
  ;;
  stop)
  ;;
  reload)
  ;;
  restart|force-reload)
  ;;
**)
        echo "Usage: /etc/init.d/projector {start|stop}"
        exit 1
  ;;
esac

exit 0

(chvt is a fantastic command - possibly worth putting in your .lirc file)

Starting X

You'll notice it calls a script : runx it's only a 2 line script:

 export QT_XFT=1
 xinit  -- :1 -layout Projector

But notice it uses

:1 to create a new X display (as in the DISPLAY variable - the normal one is hostname:0.0 - this one will be hostname:1.0) and
-layout - this corresponds to a LayoutSection in your XF86Config-4 confg (see later)

Now we need an .xinitrc file. This is like a .profile for X and it contains commands that are run when X starts:

 xsetroot -solid black
 xhost +
 nvidia-settings -l --assign="[[Sync To V Blank]]=1"
 mythfrontend -v &
 ratpoison

When the last command finishes, X stops. I don't have this set to continually restart but you could easily do so.

Configuring X

OK, the infamous XF86Config-4...

This is a bit more complex but not a lot. You need to realise that this file contains lots of little sections. Not all of them are used all the time. Normally X looks for the first 'ServerLayout' and then looks to see what other sections are referred to. It keeps doing this down through Screens, Monitors, Devices, InputDevices etc etc. So here the first ServerLayout is used by default, the second (which refers to a different screen which in turn refers to the MonitorSection called Projector and the Nvidia Device) is what we specify by name back in runx:

Section "[[Server Layout]]"
       Identifier     "TV"
       Screen      0  "TV"
       [[Input Device]]    "Keyboard0" "[[Core Keyboard]]"
       [[Input Device]]    "PS/2 Mouse" "[[Core Pointer]]"
       Option "Xinerama" "off"
[[End Section]]

Section "[[Server Layout]]"
       Identifier     "Projector"
       Screen      0  "[[Proj Screen]]"
       Option          "Xinerama"      "off"
       Option          "[[Allow Mouse Open Fail]]"
       [[Input Device]]    "PS/2 Mouse" "[[Core Pointer]]"
       [[Input Device]]    "Keyboard0" "[[Core Keyboard]]"
[[End Section]]

Configuring Myth

Myth uses a .myth directory in the users home directory. In there is a file called mysql.txt which tells mythfrontend where to get all it's settings from. Now Myth stores this information on a per-hostname basis - so we need to tell a white lie. Here's what mine looks like:

[[D B Host Name]]=localhost
[[D B User Name]]=mythtv
DBPassword=mythtv
DBName=mythconverg

# Set the following if you want to use something other than the
# machine's real hostname for identifying settings in the database.
# This is useful if your hostname changes often, as otherwise
# you'll need to reconfigure mythtv (or futz with the DB) every time.
# TWO HOSTS MUST NOT USE THE SAME VALUE
#
[[Local Host Name]]=bao-projector

The 'LocalHostName' value is the one you care about, and as the comment says, it must be unique.

All Done

Now you can easily switch (ctrl-alt-F<x>) between TV and VGA screens.

On word of caution: you may have problems sharing the sound/dsp device if you switch whilst it's in use)

Hope this helps

--David Greaves

Lazy Man Commercial Solution

I run mythfrontend on a Groovix linux system. The main console is used by the family for day to day stuff (email etc.) The secondary console is used for mythtv. I'd say it works quite well and was a lot less work than setting it up myself.

-- Matt Welland


One X server, two displays (non-xinerama method)

I have a similar setup with TV and projector, but instead of running two X servers I run one X server with two displays. I only run one instance of mythfrontend at once and so don't need to create another user.

This has the advantage that both displays can be used at the same time - one will show myth's gui or video whilst the other can be used for other X applications at the same time. My usual scripts start up a cpu-temperature monitor (xsensors) and an xterm from which I can launch vncviewer, firefox etc. whilst mythtv is still doing its business on the other screen.
The mouse pointer moves across the two screens - although it can be hidden in myth's GUI so it doesn't get in the way.

This is done by specifying multiple screens in the ServerLayout section of the X config. I don't use xinerama (or 'twinview' as nVidia likes to call it) as I want two distinct displays - :0 and :1 - so that I can select which screen any application (myth, mplayer, xine, xterm etc) will appear on using the DISPLAY environment variable.

I have scripts set up to loop and toggle which display myth appears on - I can switch displays by using a button on the remote which LIRC picks up or a 'swap display' item I added to myth's main menu by editing the XML. The remote option is useful as the display can be switched without turning on the other device just to navigate to the 'swap display' GUI entry.


As a special bonus problem the TV and projector are different ratios - 4:3 vs 16:9. MPlayer needs to be told what the aspect ratio is (-monitoraspect) - this is done by setting an environment variable in the switching script and then using it on the commandline configured inside mythvideo - eg:

mplayer -monitoraspect $MONITORASPECT %S

-- Mamoulian

Well, is this just bragging? You do not specify the changes needed. I simply can not make this work because configuring X is such a black art. Little chance of succeeding without seeing your xorg.conf. Oh thank goodness, the post further down has the vital info, and works well. (PIP Display)


PVR-350 scripts

I run a similar setup, however one of my displays is going through a PVR-350 which requires changes to the settings to enable the 350 and setup the screen size & offsets. Here is a .sql file I use to set it up:

use mythconverg;
update settings set data="1" where hostname="mythtv" and value="PVR350OutputEnable";
update settings set data="635" where hostname="mythtv" and value="GuiWidth";
update settings set data="445" where hostname="mythtv" and value="GuiHeight";
update settings set data="40" where hostname="mythtv" and value="GuiOffsetX";
update settings set data="15" where hostname="mythtv" and value="GuiOffsetY";

And here's how I switch it back to using my nVidia output:

use mythconverg;
update settings set data="0" where hostname="mythtv" and value="PVR350OutputEnable";
update settings set data="0" where hostname="mythtv" and value="GuiWidth";
update settings set data="0" where hostname="mythtv" and value="GuiHeight";
update settings set data="0" where hostname="mythtv" and value="GuiOffsetX";
update settings set data="0" where hostname="mythtv" and value="GuiOffsetY";

I setup a small shell script to write out dummy files to a "swap" directory to store which configuration is active. It's a quick & dirty solution but it works. Feel free to improve it:

#!/bin/bash
killall mythfrontend
if [ -e "$HOME/swap/pvr350" ]; then
  rm $HOME/swap/pvr350
  touch $HOME/swap/nvidia
  export DISPLAY=:0.0
  mysql -umythtv -pmythtv < $HOME/swap/nvidia.sql
elif [ -e "$HOME/swap/nvidia" ]; then
  rm $HOME/swap/nvidia
  touch $HOME/swap/pvr350
  export DISPLAY=:0.1
  mysql -umythtv -pmythtv < $HOME/swap/pvr350.sql
fi
# Note this is specific to the MythDora distro...
/usr/share/mythdora/mythfrontend.sh

Xinerama (One X server, two displays)

Since X.org is pushing xinerama for multidisplay setups with the new xrandr, I chose to make a dual screen setup using xinerama.

Using xinerama means you'll have one big, rectangular virtual screen, and each display will show a subsection of this big virtual screen. I chose to set the two displays next to each other, but you might as well place them above one another or something completely different, just make sure that your physical displays doesn't overlap eachother (see xrandr for how to create a xinerama setup)

When using xinerama, each physical display is assigned a number and this can be used like the old $DISPLAY variable to determine where applications start.

To make mythfrontend start on the same xinerama screen every time, go to: "Setup->Apperance" and set the correct xinerama screen (mythtv may need to be compiled with xinerama support).

To make mplayer show videos on the correct screen as well when using mythvideo, go to: "Setup->Media Settings->Videos Settings->Player Settings" and append "-xineramascreen 1" if your mythfrontend is running on xineramascreen 1.

mplayer -xineramascreen 1 %S

Mplayer has to be compiled with xinerama support as well.

This solution has the following disadvantages:

  • The mouse moves over the entire virtual screen as in the non-xinerama method.
  • The focus is shared between mythfrontend/mplayer and the rest of the desktop. A possible solution to this is to use Xephyr to run another xserver on the second display, and run mythfrontend inside that xserver, but XV is not supported yet, so expect poor video performance.

PIP Display (One X Server, One display, Dual head video card with a desktop on each)

I created this xorg.conf from various bits on the internet to be able to view Mythtv in PIP while using my desktop to browse the web, etc on my Vizio GV42L LCD TV.

My video card is an onboard GeForce 7050 with both VGA and DVI outputs that go into the RGB and HDMI inputs on my TV respectively.

Section "ServerLayout"
        Identifier     "Multi-Head"
        Screen          0  "Desktop" 0 0
        Screen          1  "MythTV" RightOf "Desktop"
        InputDevice    "Keyboard"       "CoreKeyboard"
        InputDevice    "Mouse"          "CorePointer"
EndSection

Section "Files"
        ModulePath   "/usr/lib64/xorg/modules/extensions/nvidia"
        ModulePath   "/usr/lib64/xorg/modules/extensions"
        ModulePath   "/usr/lib64/xorg/modules"
EndSection

Section "Module"
        Load    "dbe"
        Load    "extmod"
        Load    "fbdevhw"
        Load    "glx"
        Load    "record"
        Load    "freetype"
        Load    "type1"
        Load    "v4l"
EndSection

Section "InputDevice"
        Identifier      "Keyboard"
        Driver          "kbd"
        Option          "XkbModel" "pc105"
        Option          "XkbLayout" "us+inet"
EndSection

Section "InputDevice"
        Identifier      "Mouse"
        Driver          "mouse"
EndSection

Section "ServerFlags"
        Option          "Xinerama" "0"
EndSection

Section "Device"
        Identifier      "GF7050_RGB"
        Driver          "nvidia"
        VendorName      "NVIDIA Corporation"
        BoardName       "GeForce 7050 PV / NVIDIA nForce 630a"
        BusID           "PCI:0:18:0"
        Option          "NvAGP"                 "2"
        Option          "UseEvents"             "True"
        Option          "AddARGBGLXVisuals"     "True"
        Option          "ModeValidation"        "NoWidthAlignmentCheck"  # Important!!! need this option to use nvidia card at 1366 x 768
        Option          "ExactModeTimingsDVI"   "True"
        Option          "ModeValidation"        "NoDFPNativeResolutionCheck"
        Screen          0
EndSection

Section "Device"
        Identifier      "GF7050_DFP"
        Driver          "nvidia"
        VendorName      "NVIDIA Corporation"
        BoardName       "GeForce 7050 PV / NVIDIA nForce 630a"
        BusID           "PCI:0:18:0"
        Option          "NvAGP"                 "2"
        Option          "UseEvents"             "True"
        Option          "AddARGBGLXVisuals"     "True"
        Option          "ModeValidation"        "NoWidthAlignmentCheck"  # Important!!! need this option to use nvidia card at 1366 x 768
        Option          "ExactModeTimingsDVI"   "True"
        Option          "ModeValidation"        "NoDFPNativeResolutionCheck"
        Screen          1
EndSection

Section "Monitor"
       Identifier       "GV42L"
       VendorName       "VIZIO"
       ModelName        "GV42L"

       HorizSync        31-70
       VertRefresh      50-85

       Modeline "1366x768@60.00"  85.5  1366 1494 1624 1798  768 770 776 795  -HSync +Vsync Interlace
       Modeline "768p@60.00"  85.5  1366 1494 1624 1798  768 770 776 795  -HSync +Vsync
EndSection

Section "Screen"
        Identifier      "Desktop"
        Device          "GF7050_RGB"
        Monitor         "GV42L"
        Option          "ConnectedMonitor"      "CRT-0,DFP-0" #Force the connected monitor since only one can be active at a time
        Option          "UseDisplayDevice"      "CRT-0"
        DefaultDepth    24
        SubSection "Display"
                Viewport        0 0
                Depth           24
                Modes           "1366x768@60.00"
        EndSubSection
EndSection

Section "Screen"
        Identifier      "MythTV"
        Device          "GF7050_DFP"
        Monitor         "GV42L"
        Option          "ConnectedMonitor"      "CRT-0,DFP-0" #Force the connected monitor since only one can be active at a time
        Option          "UseDisplayDevice"      "DFP-0"
        DefaultDepth    24
        SubSection "Display"
                Viewport        0 0
                Depth           24
                Modes           "768p@60.00"
        EndSubSection
EndSection

The advantage to this setup is that beyond having to configure mythtv to startup in the :0.1 display there is very little else to do. I use a program called Mouse Jail to lock my mouse cursor in the Desktop Screen. http://www.cs.kent.ac.uk/~sm244/Jail.tar.gz

Here is the script I use to start mythfrontend on the second screen:

#!/bin/zsh
#Lock cursor in main display
/usr/local/bin/Jail > /dev/null 2>&1 &
# Kill the kicker
kill -9 `ps -ef | grep kicker | grep -v grep | head -1 | awk '{print $2}'`
export DISPLAY=:0.1
mythfrontend > ~/mythfrontend.log &