[mythtv] PATCH: manual recording

Chris Derossi chrismyth at derossi.com
Mon Mar 24 14:35:48 EST 2003


Here's a patch to provide a manual recording capability. The patch does
not make it available in the UI, but I've enclosed a modified tvmenu.xml
so you can try it and so you can see how to add it to a menu.

The screen allows you to view live TV, enter a title and subtitle for
the recording, and start the recording at the moment you choose. You can
then stop it manually (as long as you don't leave the manual record
screen), or have it stop automatically after recording for some number
of minutes.

As soon as recording starts, the recorded program is available for
watching as usual.

There is one huge hack here. Because recorded programs have to be listed
in the program table, a new entry has to be created for the manual show.
This entry has to be tied to a channelid. However, channelids are not
generally used, and I didn't want to make that big a change. On top of
that, my personal setup is composite input from DVDs and tapes.

So the hack is that the manual record uses a constant channelid of 1999,
which much exist in the channel table. You have to add it manually. Once
the UI exists for creating the appropriate entry to correspond to
external video sources, this needs to be changed. If someone wants to
suggest a way to allow the front end to utilize the appropriate channel
id for the channel being viewed on live tv, I'll be happy to make the
change. In general, though, I tried to keep direct database access out
of the front end stuff that I added.

Comments welcome.


-------------- next part --------------
? programs/mythfrontend/manualbox.cpp
? programs/mythfrontend/manualbox.h
Index: libs/libmythtv/XJ.cpp
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/XJ.cpp,v
retrieving revision 1.45
diff -u -r1.45 XJ.cpp
--- libs/libmythtv/XJ.cpp	8 Mar 2003 20:54:16 -0000	1.45
+++ libs/libmythtv/XJ.cpp	24 Mar 2003 20:16:42 -0000
@@ -64,6 +64,8 @@
     XJ_started = 0;
     xv_port = -1;
     scratchspace = NULL;
+
+    created_win = false;

     data = new XvData();
 }
@@ -257,6 +259,7 @@
                                            cury, curw, curh, 0,
                                            XJ_white, XJ_black);
         data->XJ_curwin = data->XJ_win;
+        created_win = true;

         if (!data->XJ_win)
         {
@@ -497,7 +500,10 @@
             }
         }

-        XDestroyWindow(data->XJ_disp, data->XJ_win);
+        if (created_win)
+        {
+            XDestroyWindow(data->XJ_disp, data->XJ_win);
+        }
         XCloseDisplay(data->XJ_disp);
     }
 }
@@ -587,6 +593,8 @@
     disphoff = disph = h;

     embedding = true;
+
+    MoveResize();

     pthread_mutex_unlock(&lock);
 }
Index: libs/libmythtv/XJ.h
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/XJ.h,v
retrieving revision 1.21
diff -u -r1.21 XJ.h
--- libs/libmythtv/XJ.h	5 Mar 2003 17:20:55 -0000	1.21
+++ libs/libmythtv/XJ.h	24 Mar 2003 20:16:42 -0000
@@ -52,6 +52,7 @@
     int dispx, dispy, dispw, disph;
     int olddispx, olddispy, olddispw, olddisph;
     bool embedding;
+    bool created_win;

     int xv_port;
     int colorid;
Index: libs/libmythtv/programinfo.cpp
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/programinfo.cpp,v
retrieving revision 1.37
diff -u -r1.37 programinfo.cpp
--- libs/libmythtv/programinfo.cpp	18 Mar 2003 04:54:48 -0000	1.37
+++ libs/libmythtv/programinfo.cpp	24 Mar 2003 20:16:43 -0000
@@ -89,6 +89,10 @@
         chanid = " ";
     if (chanstr == "")
         chanstr = " ";
+    if (chansign == "")
+        chansign = " ";
+    if (channame == "")
+        channame = " ";
     if (pathname == "")
         pathname = " ";

@@ -167,6 +171,44 @@
 int ProgramInfo::CalculateLength(void)
 {
     return startts.secsTo(endts);
+}
+
+void ProgramInfo::Save(void)
+{
+    QSqlQuery query;
+    QString querystr;
+    QString escaped_title;
+    QString escaped_subtitle;
+    QString escaped_description;
+    QString escaped_category;
+
+    escaped_title = title;
+    escaped_title.replace(QRegExp("\""), QString("\\\""));
+
+    escaped_subtitle = subtitle;
+    escaped_subtitle.replace(QRegExp("\""), QString("\\\""));
+
+    escaped_description = description;
+    escaped_description.replace(QRegExp("\""), QString("\\\""));
+
+    escaped_category = category;
+    escaped_category.replace(QRegExp("\""), QString("\\\""));
+
+    querystr.sprintf("INSERT INTO program (chanid,starttime,endtime,"
+                    "title,subtitle,description,category,airdate,"
+                    "stars) VALUES(%d,\"%s\",\"%s\",\"%s\",\"%s\", "
+                    "\"%s\",\"%s\",\"%s\",\"%s\");",
+                    chanid.toInt(),
+                    startts.toString("yyyyMMddhhmmss").ascii(),
+                    endts.toString("yyyyMMddhhmmss").ascii(),
+                    escaped_title.utf8().data(),
+                    escaped_subtitle.utf8().data(),
+                    escaped_description.utf8().data(),
+                    escaped_category.utf8().data(),
+                    "0",
+                    "0");
+
+    query.exec(querystr.utf8().data());
 }

 void ProgramInfo::GetProgramRangeDateTime(QPtrList<ProgramInfo> *proglist, QString channel,
Index: libs/libmythtv/programinfo.h
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/programinfo.h,v
retrieving revision 1.26
diff -u -r1.26 programinfo.h
--- libs/libmythtv/programinfo.h	18 Mar 2003 04:54:48 -0000	1.26
+++ libs/libmythtv/programinfo.h	24 Mar 2003 20:16:43 -0000
@@ -23,6 +23,8 @@

     bool IsSameProgram(const ProgramInfo& other) const;
     bool IsSameTimeslot(const ProgramInfo& other) const;
+
+    void Save(void);

     ScheduledRecording::RecordingType GetProgramRecordingStatus(QSqlDatabase *db);
     void ApplyRecordStateChange(QSqlDatabase *db,
Index: libs/libmythtv/remoteencoder.cpp
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/remoteencoder.cpp,v
retrieving revision 1.6
diff -u -r1.6 remoteencoder.cpp
--- libs/libmythtv/remoteencoder.cpp	21 Mar 2003 02:50:26 -0000	1.6
+++ libs/libmythtv/remoteencoder.cpp	24 Mar 2003 20:16:43 -0000
@@ -218,6 +218,14 @@
     SendReceiveStringList(strlist);
 }

+void RemoteEncoder::FinishRecording(void)
+{
+    QStringList strlist = QString("QUERY_RECORDER %1").arg(recordernum);
+    strlist << "FINISH_RECORDING";
+
+    SendReceiveStringList(strlist);
+}
+
 void RemoteEncoder::ToggleInputs(void)
 {
     QStringList strlist = QString("QUERY_RECORDER %1").arg(recordernum);
Index: libs/libmythtv/remoteencoder.h
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/remoteencoder.h,v
retrieving revision 1.7
diff -u -r1.7 remoteencoder.h
--- libs/libmythtv/remoteencoder.h	21 Mar 2003 02:50:26 -0000	1.7
+++ libs/libmythtv/remoteencoder.h	24 Mar 2003 20:16:43 -0000
@@ -30,6 +30,7 @@
     void SpawnLiveTV(void);
     void StopLiveTV(void);
     void Pause(void);
+    void FinishRecording(void);

     void ToggleInputs(void);
     int ChangeContrast(bool direction);
Index: libs/libmythtv/tv_play.cpp
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/tv_play.cpp,v
retrieving revision 1.39
diff -u -r1.39 tv_play.cpp
--- libs/libmythtv/tv_play.cpp	21 Mar 2003 17:05:37 -0000	1.39
+++ libs/libmythtv/tv_play.cpp	24 Mar 2003 20:16:44 -0000
@@ -97,6 +97,7 @@
     requestDelete = false;
     endOfRecording = false;
     volumeControl = NULL;
+    embedid = 0;

     gContext->addListener(this);
 }
@@ -189,6 +190,16 @@
     return retval;
 }

+void TV::FinishRecording(void)
+{
+    if (!IsRecording())
+    {
+        return;
+    }
+
+    activerecorder->FinishRecording();
+}
+
 int TV::AllowRecording(const QString &message, int timeuntil)
 {
     if (internalState != kState_WatchingLiveTV)
@@ -458,6 +469,10 @@
     else if (internalState == kState_WatchingRecording &&
              nextState == kState_WatchingLiveTV)
     {
+        recorder->SpawnLiveTV();
+
+        watchingLiveTV = true;
+
         internalState = nextState;
         changed = true;
     }
@@ -554,6 +569,11 @@
     }

     nvp->SetVideoFilters(filters);
+
+    if (embedid > 0)
+    {
+        nvp->EmbedInWidget(embedid, embx, emby, embw, embh);
+    }

     if (internalState == kState_WatchingRecording)
         nvp->SetWatchingRecording(true);
@@ -1481,6 +1501,11 @@

 void TV::EmbedOutput(unsigned long wid, int x, int y, int w, int h)
 {
+    embedid = wid;
+    embx = x;
+    emby = y;
+    embw = w;
+    embh = h;
     if (nvp)
         nvp->EmbedInWidget(wid, x, y, w, h);
 }
@@ -1489,6 +1514,7 @@
 {
     if (nvp)
         nvp->StopEmbedding();
+    embedid = 0;
 }

 void TV::doLoadMenu(void)
Index: libs/libmythtv/tv_play.h
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/tv_play.h,v
retrieving revision 1.22
diff -u -r1.22 tv_play.h
--- libs/libmythtv/tv_play.h	18 Mar 2003 04:54:48 -0000	1.22
+++ libs/libmythtv/tv_play.h	24 Mar 2003 20:16:44 -0000
@@ -25,6 +25,7 @@

     TVState LiveTV(void);
     void StopLiveTV(void) { exitPlayer = true; }
+    void FinishRecording(void);

     int AllowRecording(const QString &message, int timeuntil);

@@ -168,6 +169,9 @@
     QSqlDatabase *m_db;

     VolumeControl *volumeControl;
+
+    unsigned int embedid;
+    int embx, emby, embw, embh;
 };

 #endif
Index: libs/libmythtv/tv_rec.cpp
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/tv_rec.cpp,v
retrieving revision 1.52
diff -u -r1.52 tv_rec.cpp
--- libs/libmythtv/tv_rec.cpp	24 Mar 2003 15:39:31 -0000	1.52
+++ libs/libmythtv/tv_rec.cpp	24 Mar 2003 20:16:46 -0000
@@ -649,6 +649,7 @@

     runMainLoop = true;
     exitPlayer = false;
+    finishRecording = false;

     while (runMainLoop)
     {
@@ -659,7 +660,7 @@

         if (StateIsRecording(internalState))
         {
-            if (QDateTime::currentDateTime() > recordEndTime)
+            if (QDateTime::currentDateTime() > recordEndTime || finishRecording)
             {
                 if (!inoverrecord && overrecordseconds > 0)
                 {
@@ -678,6 +679,7 @@
                     nextState = RemoveRecording(internalState);
                     changeState = true;
                 }
+                finishRecording = false;
             }
         }

Index: libs/libmythtv/tv_rec.h
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/tv_rec.h,v
retrieving revision 1.26
diff -u -r1.26 tv_rec.h
--- libs/libmythtv/tv_rec.h	24 Mar 2003 15:39:31 -0000	1.26
+++ libs/libmythtv/tv_rec.h	24 Mar 2003 20:16:46 -0000
@@ -27,6 +27,7 @@

     void StartRecording(ProgramInfo *rcinfo);
     void StopRecording(void);
+    void FinishRecording(void) {finishRecording = true; }

     ProgramInfo *GetRecording(void) { return curRecording; }

@@ -141,6 +142,7 @@
     bool runMainLoop;
     bool exitPlayer;
     bool paused;
+    bool finishRecording;
     bool prematurelystopped;
     QDateTime recordEndTime;

Index: programs/mythbackend/encoderlink.cpp
===================================================================
RCS file: /var/lib/cvs/MC/programs/mythbackend/encoderlink.cpp,v
retrieving revision 1.16
diff -u -r1.16 encoderlink.cpp
--- programs/mythbackend/encoderlink.cpp	21 Mar 2003 02:50:26 -0000	1.16
+++ programs/mythbackend/encoderlink.cpp	24 Mar 2003 20:16:47 -0000
@@ -162,6 +162,19 @@
     }
 }

+void EncoderLink::FinishRecording(void)
+{
+    if (local)
+    {
+        tv->FinishRecording();
+        return;
+    }
+    else
+    {
+        endRecordingTime = QDateTime::currentDateTime().addDays(-2);
+    }
+}
+
 bool EncoderLink::IsReallyRecording(void)
 {
     if (local)
Index: programs/mythbackend/encoderlink.h
===================================================================
RCS file: /var/lib/cvs/MC/programs/mythbackend/encoderlink.h,v
retrieving revision 1.16
diff -u -r1.16 encoderlink.h
--- programs/mythbackend/encoderlink.h	21 Mar 2003 02:50:26 -0000	1.16
+++ programs/mythbackend/encoderlink.h	24 Mar 2003 20:16:47 -0000
@@ -34,6 +34,7 @@
     int AllowRecording(ProgramInfo *rec, int timeuntil);
     void StartRecording(ProgramInfo *rec);
     void StopRecording(void);
+    void FinishRecording(void);
     bool WouldConflict(ProgramInfo *rec);

     bool IsReallyRecording(void);
Index: programs/mythbackend/mainserver.cpp
===================================================================
RCS file: /var/lib/cvs/MC/programs/mythbackend/mainserver.cpp,v
retrieving revision 1.53
diff -u -r1.53 mainserver.cpp
--- programs/mythbackend/mainserver.cpp	21 Mar 2003 02:50:26 -0000	1.53
+++ programs/mythbackend/mainserver.cpp	24 Mar 2003 20:16:48 -0000
@@ -915,6 +915,11 @@
         enc->PauseRecorder();
         retlist << "ok";
     }
+    else if (command == "FINISH_RECORDING")
+    {
+        enc->FinishRecording();
+        retlist << "ok";
+    }
     else if (command == "TOGGLE_INPUTS")
     {
         enc->ToggleInputs();
Index: programs/mythfrontend/main.cpp
===================================================================
RCS file: /var/lib/cvs/MC/programs/mythfrontend/main.cpp,v
retrieving revision 1.82
diff -u -r1.82 main.cpp
--- programs/mythfrontend/main.cpp	21 Mar 2003 17:05:37 -0000	1.82
+++ programs/mythfrontend/main.cpp	24 Mar 2003 20:16:48 -0000
@@ -10,6 +10,7 @@
 using namespace std;

 #include "tv.h"
+#include "manualbox.h"
 #include "playbackbox.h"
 #include "viewscheduled.h"
 #include "globalsettings.h"
@@ -74,6 +75,18 @@
     return 0;
 }

+int startManual(void)
+{
+    ManualBox manbox;
+
+    manbox.Show();
+    qApp->unlock();
+    manbox.exec();
+    qApp->lock();
+
+    return 0;
+}
+
 void startTV(void)
 {
     QSqlDatabase *db = QSqlDatabase::database();
@@ -118,6 +131,8 @@
         startGuide();
     else if (sel == "tv_delete")
         startDelete();
+    else if (sel == "tv_manual")
+        startManual();
     else if (sel == "tv_fix_conflicts")
         startManaged();
     else if (sel == "settings appearance") {
Index: programs/mythfrontend/mythfrontend.pro
===================================================================
RCS file: /var/lib/cvs/MC/programs/mythfrontend/mythfrontend.pro,v
retrieving revision 1.34
diff -u -r1.34 mythfrontend.pro
--- programs/mythfrontend/mythfrontend.pro	31 Jan 2003 14:35:49 -0000	1.34
+++ programs/mythfrontend/mythfrontend.pro	24 Mar 2003 20:16:48 -0000
@@ -30,8 +30,8 @@
 TARGETDEPS += ../../libs/libvbitext/libvbitext.a

 # Input
-HEADERS += playbackbox.h programlistitem.h viewscheduled.h
+HEADERS += manualbox.h playbackbox.h programlistitem.h viewscheduled.h
 HEADERS += globalsettings.h setrectime.h

-SOURCES += main.cpp playbackbox.cpp programlistitem.cpp viewscheduled.cpp
+SOURCES += main.cpp manualbox.cpp playbackbox.cpp programlistitem.cpp viewscheduled.cpp
 SOURCES += globalsettings.cpp setrectime.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: manualbox.h
Type: text/x-c-header
Size: 900 bytes
Desc: not available
Url : /pipermail/attachments/20030324/e770b3a8/manualbox.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: manualbox.cpp
Type: text/x-c++
Size: 6840 bytes
Desc: not available
Url : /pipermail/attachments/20030324/e770b3a8/manualbox-0001.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tvmenu.xml
Type: text/xml
Size: 1001 bytes
Desc: not available
Url : /pipermail/attachments/20030324/e770b3a8/tvmenu.xml


More information about the mythtv-dev mailing list