Index: libs/libmythtv/dvbchannel.h
===================================================================
--- libs/libmythtv/dvbchannel.h	(revision 8290)
+++ libs/libmythtv/dvbchannel.h	(working copy)
@@ -63,8 +63,7 @@
 
     // Commands
     bool SwitchToInput(const QString &inputname, const QString &chan);
-    bool SwitchToInput(int newcapchannel, bool setstarting)
-        { (void)newcapchannel; (void)setstarting; return false; }
+    bool SwitchToInput(int newcapchannel, bool setstarting);
     bool Tune(const dvb_channel_t& channel, bool force_reset=false);
 
     // Set/Get/Command just for SIScan/ScanWizardScanner
@@ -113,6 +112,8 @@
     int               currentTID;  ///< Stores mplexid from database
 
     bool              first_tune;  ///< Used to force hardware reset
+
+    int               nextcapchannel; ///< Signal an input change
 };
 
 #endif
Index: libs/libmythtv/dvbchannel.cpp
===================================================================
--- libs/libmythtv/dvbchannel.cpp	(revision 8290)
+++ libs/libmythtv/dvbchannel.cpp	(working copy)
@@ -132,10 +132,12 @@
 {
     channelnames.clear();
     inputChannel.clear();
+    inputTuneTo.clear();
     
     MSqlQuery query(MSqlQuery::InitCon());
     query.prepare(
         "SELECT cardinputid, inputname, "
+        "       if (tunechan='', 'Undefined', tunechan), "
         "       if (startchan, startchan, '') "
         "FROM cardinput "
         "WHERE cardid = :CARDID");
@@ -159,7 +161,8 @@
     {
         int inputNum              = query.value(0).toInt();
         channelnames[inputNum]    = query.value(1).toString();
-        inputChannel[inputNum]    = query.value(2).toString();
+        inputTuneTo[inputNum]     = query.value(2).toString();
+        inputChannel[inputNum]    = query.value(3).toString();
     }
 
     // print em
@@ -170,6 +173,7 @@
                 .arg(it.key()).arg(*it)
                 .arg(inputChannel[it.key()]));
     }
+    currentcapchannel = nextcapchannel = -1;
 }
 
 bool DVBChannel::Open()
@@ -284,6 +288,7 @@
     CHANNEL(QString("Tuned to frequency for channel %1.").arg(chan));
 
     currentcapchannel = chan_opts.input_id;
+    nextcapchannel = currentcapchannel;
     inputChannel[currentcapchannel] = curchannelname;
 
     return true;
@@ -300,13 +305,28 @@
 
 bool DVBChannel::SwitchToInput(const QString &input, const QString &chan)
 {
-    (void)input;
-    // TODO We should be switching the input even if chan exists on
-    // the current input, currently this will only work correctly if
-    // channum's are unique across inputs. -- dtk  Dec 15, 2005
+    if (input != channelnames[currentcapchannel])
+    {
+        nextcapchannel = GetInputByName(input);
+        if (nextcapchannel == -1)
+        {
+            VERBOSE(VB_IMPORTANT, QString("Failed to locate input %1").
+                    arg(input));
+            nextcapchannel = currentcapchannel;
+        }
+    }
     return SetChannelByString(chan);
 }
-
+bool DVBChannel::SwitchToInput(int newcapchannel, bool setstarting)
+{
+    (void)setstarting;
+    if(inputChannel[newcapchannel] != "")
+     {
+        nextcapchannel = newcapchannel;
+        return SetChannelByString(inputChannel[newcapchannel]);
+    }
+    return false;
+}
 /** \fn DVBChannel::GetChannelOptions(const QString&)
  *  \brief This function called when tuning to a specific stream.
  */
@@ -317,13 +337,12 @@
     int cardid = GetCardID();
 
     // Reset Channel data
-    inputChannel[currentcapchannel] = "";
     currentATSCMajorChannel = currentATSCMinorChannel = -1;
     currentProgramNum = -1;
     chan_opts.serviceID = 0;
 
     QString thequery =
-        QString("SELECT chanid, serviceid, mplexid, atscsrcid "
+        QString("SELECT chanid, serviceid, mplexid, atscsrcid, cardinputid "
                 "FROM channel, cardinput, capturecard "
                 "WHERE channel.channum='%1' AND "
                 "      cardinput.sourceid = channel.sourceid AND "
@@ -340,25 +359,32 @@
         return false;
     }
 
-    if (query.next())
+    bool found = false;
+    int mplexid;
+    while (query.next())
     {
-        // TODO: Fix structs to be more useful to new DB structure
-        currentProgramNum = chan_opts.serviceID = query.value(1).toInt();
-        if (query.value(3).toInt() > 256)
+        int this_inputid = query.value(4).toInt();
+        if (! found || this_inputid == nextcapchannel)
         {
-            currentATSCMajorChannel = query.value(3).toInt() >> 8;
-            currentATSCMinorChannel = query.value(3).toInt() & 0xff;
-            currentProgramNum = -1;
+            found = true;
+            mplexid = query.value(2).toInt();
+            // TODO: Fix structs to be more useful to new DB structure
+            currentProgramNum = chan_opts.serviceID = query.value(1).toInt();
+            if (query.value(3).toInt() > 256)
+            {
+                currentATSCMajorChannel = query.value(3).toInt() >> 8;
+                currentATSCMinorChannel = query.value(3).toInt() & 0xff;
+                currentProgramNum = -1;
+            }
+
         }
     }
-    else
+    if (! found)
     {
         ERROR("Unable to find channel in database.");
         return false;
     }
 
-    int mplexid = query.value(2).toInt();
-
     if (!GetTransportOptions(mplexid))
         return false;
 
