[mythtv-users] livetv - switch cards ?

mian mythtv at mian.net.au
Sat Jan 31 10:18:03 EST 2004


Give this a try if you want, it adds a new command called ToggleRecorders
which is currently set to use the 'Y' key when using LiveTV (hard finding
a key -not- in use :)  It basically works the same as switch input, except
for switching actual cards, cycling right through and back again.

--
mian

>
> Thanks. I re-organized the database so that the digital card is the
> first one. If you want me to test your patches before release let me know.
>
> Reiner

-------------- next part --------------
--- work-copy/mythtv/programs/mythfrontend/main.cpp	2004-01-29 16:45:50.000000000 +1030
+++ work/mythtv/programs/mythfrontend/main.cpp	2004-01-29 22:14:15.000000000 +1030
@@ -261,7 +261,7 @@
             qApp->lock();
         }
 
-        if (tv->WantsToQuit())
+        if (tv->WantsToQuit() && !tv->IsTogglingRecorders())
             quitAll = true;
         else
         {
--- work-copy/mythtv/programs/mythbackend/mainserver.h	2004-01-29 16:45:50.000000000 +1030
+++ work/mythtv/programs/mythbackend/mainserver.h	2004-01-31 23:44:05.844443632 +1030
@@ -66,6 +66,8 @@
     void HandleGetScheduledRecordings(PlaybackSock *pbs);
     void HandleGetConflictingRecordings(QStringList &slist, QString purge, 
                                         PlaybackSock *pbs);
+    void HandleGetNextFreeRecorder(QStringList &slist, PlaybackSock *pbs);
+    void HandleGetRecorderForChanId(QStringList &slist, PlaybackSock *pbs);
     void HandleGetFreeRecorder(PlaybackSock *pbs);
     void HandleRecorderQuery(QStringList &slist, QStringList &commands,
                              PlaybackSock *pbs);
--- work-copy/mythtv/programs/mythbackend/mainserver.cpp	2004-01-29 16:45:50.000000000 +1030
+++ work/mythtv/programs/mythbackend/mainserver.cpp	2004-02-01 01:01:40.523824808 +1030
@@ -271,6 +271,14 @@
     {
         HandleGetFreeRecorder(pbs);
     }
+    else if (command == "GET_NEXT_FREE_RECORDER")
+    {
+        HandleGetNextFreeRecorder(listline, pbs);
+    }
+    else if (command == "GET_RECORDER_FOR_CHANID")
+    {
+        HandleGetRecorderForChanId(listline, pbs);
+    }
     else if (command == "QUERY_RECORDER")
     {
         if (tokens.size() != 2)
@@ -1491,6 +1499,166 @@
     SendResponse(pbssock, strlist);
 }
 
+void MainServer::HandleGetRecorderForChanId(QStringList &slist, PlaybackSock *pbs)
+{
+    QSocket *pbssock = pbs->getSocket();
+    QString pbshost = pbs->getHostname();
+
+    QStringList strlist;
+    int retval = -1;
+    QString recnum = slist[1];
+
+    EncoderLink *encoder = NULL;
+    QString enchost;
+
+    VERBOSE(VB_ALL, QString("Getting free recorder (not %1)").arg(recnum));
+
+    QMap<int, EncoderLink *>::Iterator iter = encoderList->begin();
+    for (; iter != encoderList->end(); ++iter)
+    {
+        EncoderLink *elink = iter.data();
+
+        if (elink->isLocal())
+            enchost = gContext->GetHostName();
+        else
+            enchost = elink->getHostname();
+
+        if ((enchost == pbshost) &&
+            (elink->isConnected()) &&
+            (!elink->IsBusy()) &&
+            (!elink->isTunerLocked()) &&
+            (iter.key() != recnum))
+        {
+            encoder = elink;
+            retval = iter.key();
+            break;
+        }
+        if ((retval == -1) &&
+            (elink->isConnected()) &&
+            (!elink->IsBusy()) &&
+            (!elink->isTunerLocked()) &&
+            (iter.key() != recnum))
+        {
+            encoder = elink;
+            retval = iter.key();
+        }
+    }
+
+    strlist << QString::number(retval);
+        
+    if (encoder)
+    {
+        if (encoder->isLocal())
+        {
+            strlist << gContext->GetSetting("BackendServerIP");
+            strlist << gContext->GetSetting("BackendServerPort");
+        }
+        else
+        {
+            strlist << gContext->GetSettingOnHost("BackendServerIP", 
+                                                  encoder->getHostname(),
+                                                  "nohostname");
+            strlist << gContext->GetSettingOnHost("BackendServerPort", 
+                                                  encoder->getHostname(), "-1");
+        }
+    }
+    else
+    {
+        strlist << "nohost";
+        strlist << "-1";
+    }
+
+    SendResponse(pbssock, strlist);
+}
+
+void MainServer::HandleGetNextFreeRecorder(QStringList &slist, PlaybackSock *pbs)
+{
+    QSocket *pbssock = pbs->getSocket();
+    QString pbshost = pbs->getHostname();
+
+    QStringList strlist;
+    int retval = -1;
+    int currrec = slist[1].toInt();
+
+    EncoderLink *encoder = NULL;
+    QString enchost;
+
+    VERBOSE(VB_ALL, QString("Getting next free recorder : %1").arg(currrec));
+
+    // find current recorder
+    QMap<int, EncoderLink *>::Iterator iter, curr = encoderList->find(currrec);
+    if (curr != encoderList->end())
+    {
+        // cycle through all recorders
+        for (iter = curr;;)
+        {
+            EncoderLink *elink = iter.data();
+
+            // last item? go back
+            if (++iter == encoderList->end())
+            {
+                iter = encoderList->begin();
+            }
+
+            if (elink->isLocal())
+                enchost = gContext->GetHostName();
+            else
+                enchost = elink->getHostname();
+
+            if ((enchost == pbshost) &&
+                (elink->isConnected()) &&
+                (!elink->IsBusy()) &&
+                (!elink->isTunerLocked()))
+            {
+                encoder = elink;
+                retval = iter.key(); 
+                break;
+            }
+            if ((retval == -1) &&
+                (elink->isConnected()) &&
+                (!elink->IsBusy()) &&
+                (!elink->isTunerLocked()))
+            {
+                encoder = elink;
+                retval = iter.key();
+            }
+
+            // cycled right through? no more available recorders
+            if (iter == curr) break;
+        }
+    } else {
+        HandleGetFreeRecorder(pbs);
+        return;
+    }
+
+
+    strlist << QString::number(retval);
+        
+    if (encoder)
+    {
+        if (encoder->isLocal())
+        {
+            strlist << gContext->GetSetting("BackendServerIP");
+            strlist << gContext->GetSetting("BackendServerPort");
+        }
+        else
+        {
+            strlist << gContext->GetSettingOnHost("BackendServerIP", 
+                                                  encoder->getHostname(),
+                                                  "nohostname");
+            strlist << gContext->GetSettingOnHost("BackendServerPort", 
+                                                  encoder->getHostname(), "-1");
+        }
+    }
+    else
+    {
+        strlist << "nohost";
+        strlist << "-1";
+    }
+
+    SendResponse(pbssock, strlist);
+}
+
 void MainServer::HandleRecorderQuery(QStringList &slist, QStringList &commands,
                                      PlaybackSock *pbs)
 {
--- work-copy/mythtv/libs/libmythtv/tv_play.h	2004-01-29 16:45:50.000000000 +1030
+++ work/mythtv/libs/libmythtv/tv_play.h	2004-01-29 21:46:19.000000000 +1030
@@ -54,6 +54,7 @@
     bool IsPlaying(void) { return StateIsPlaying(GetState()); }
     bool IsRecording(void) { return StateIsRecording(GetState()); }
     bool IsMenuRunning(void) { return menurunning; }
+    bool IsTogglingRecorders(void) { return toggleRecorder; }
 
     void GetNextProgram(RemoteEncoder *enc, int direction,
                         QMap<QString, QString> &infoMap);
@@ -127,6 +128,7 @@
     void ChannelCommit(void);
 
     void ToggleInputs(void); 
+    void ToggleRecorder(void);
 
     void DoInfo(void);
     void DoPause(void);
@@ -188,6 +190,7 @@
 
     TVState internalState;
 
+    bool toggleRecorder;
     bool runMainLoop;
     bool exitPlayer;
     bool paused;
--- work-copy/mythtv/libs/libmythtv/tv_play.cpp	2004-01-29 16:45:50.000000000 +1030
+++ work/mythtv/libs/libmythtv/tv_play.cpp	2004-02-01 00:14:32.638728688 +1030
@@ -91,6 +91,7 @@
     REG_KEY("TV Playback", "RWNDSTICKY", "Rewind (Sticky) or Rewind one frame "
             "while paused", ",,<");
     REG_KEY("TV Playback", "TOGGLEINPUTS", "Toggle Inputs", "C");
+    REG_KEY("TV Playback", "TOGGLERECORDER", "Toggle Recorder", "Y");
     REG_KEY("TV Playback", "SKIPCOMMERCIAL", "Skip Commercial", "Z,End");
     REG_KEY("TV Playback", "SKIPCOMMBACK", "Skip Commercial (Reverse)",
             "Q,Home");
@@ -147,6 +148,7 @@
 {
     m_db = db;
 
+    toggleRecorder = false;
     dialogname = "";
     playbackinfo = NULL;
     editmode = false;
@@ -289,7 +291,7 @@
 {
     if (internalState == kState_None)
     {
-        RemoteEncoder *testrec = RemoteRequestRecorder();
+        RemoteEncoder *testrec = RemoteRequestNextRecorder(lastRecorderNum);
 
         if (!testrec)
             return 0;
@@ -320,6 +322,7 @@
         lastRecorderNum = recorder->GetRecorderNumber();
         nextState = kState_WatchingLiveTV;
         changeState = true;
+        toggleRecorder = false;
     }
 
     return 1;
@@ -844,6 +847,7 @@
 
     runMainLoop = true;
     exitPlayer = false;
+    toggleRecorder = false;
 
     while (runMainLoop)
     {
@@ -1374,6 +1378,8 @@
                 ToggleChannelFavorite();
             else if (action == "TOGGLEINPUTS")
                 ToggleInputs();
+            else if (action == "TOGGLERECORDER")
+                ToggleRecorder();
             else if (action == "SELECT")
                 ChannelCommit();
             else if (action == "MENU")
@@ -1872,6 +1878,16 @@
         muteTimer->start(kMuteTimeout, true);
 }
 
+void TV::ToggleRecorder(void)
+{
+    if (internalState == kState_WatchingLiveTV)
+    {
+        toggleRecorder = true;
+        nextState = kState_None;
+        changeState = true;
+    }
+}
+
 void TV::ToggleInputs(void)
 {
     if (activenvp == nvp)
--- work-copy/mythtv/libs/libmythtv/remoteutil.cpp	2004-01-29 16:45:50.000000000 +1030
+++ work/mythtv/libs/libmythtv/remoteutil.cpp	2004-02-01 00:12:06.206989696 +1030
@@ -213,6 +213,36 @@
     return new RemoteEncoder(num, hostname, port);
 }
 
+RemoteEncoder *RemoteRequestNextRecorder(int currrec)
+{
+    QStringList strlist = "GET_NEXT_FREE_RECORDER";
+    strlist << QString("%1").arg(currrec);
+
+    if (!gContext->SendReceiveStringList(strlist, true))
+        return NULL;
+
+    int num = strlist[0].toInt();
+    QString hostname = strlist[1];
+    int port = strlist[2].toInt();
+
+    return new RemoteEncoder(num, hostname, port);
+}
+
+RemoteEncoder *RemoteRequestRecorderForChanId(QString chanid)
+{
+    QStringList strlist = "GET_RECORDER_FOR_CHANID";
+    strlist << QString("%1").arg(chanid);
+
+    if (!gContext->SendReceiveStringList(strlist, true))
+        return NULL;
+
+    int num = strlist[0].toInt();
+    QString hostname = strlist[1];
+    int port = strlist[2].toInt();
+
+    return new RemoteEncoder(num, hostname, port);
+}
+
 RemoteEncoder *RemoteGetExistingRecorder(ProgramInfo *pginfo)
 {
     QStringList strlist = "GET_RECORDER_NUM";
--- work-copy/mythtv/libs/libmythtv/remoteutil.h	2004-01-29 16:45:50.000000000 +1030
+++ work/mythtv/libs/libmythtv/remoteutil.h	2004-02-01 00:10:03.809596928 +1030
@@ -18,7 +18,11 @@
 vector<ProgramInfo *> *RemoteGetConflictList(ProgramInfo *pginfo,
                                              bool removenonplaying);
 void RemoteSendMessage(const QString &message);
+
+RemoteEncoder *RemoteRequestNextRecorder(int currrec);
+RemoteEncoder *RemoteRequestRecorderForChanId(QString chanid);
 RemoteEncoder *RemoteRequestRecorder(void);
+
 RemoteEncoder *RemoteGetExistingRecorder(ProgramInfo *pginfo);
 RemoteEncoder *RemoteGetExistingRecorder(int recordernum);
 void RemoteGeneratePreviewPixmap(ProgramInfo *pginfo);


More information about the mythtv-users mailing list