[mythtv] [PATCH] Allow recording of shows that have already started

Jim Radford mythtv-dev@snowman.net
Fri, 18 Oct 2002 09:28:39 -0700


On Wed, Oct 16, 2002 at 11:21:53PM -0400, Isaac Richards wrote:
> On Wednesday 16 October 2002 05:29 am, Jim Radford wrote:
> > I like being able to record shows that have already started.
> > Sometimes I remember just a little too late and I can't see how it
> > hurts.  Plus is makes it easier to test the scheduler.  :-)

> I applied everything except the ability to record already started shows -- 
> like your FIXME says, there's a hole there where it could tell it to start 
> recording something when it already is..  If you fix that (and test it), I'll 
> be happy to have the rest in..  Should be just a matter of adding a check for 
> tv->IsRecording() before telling it to record something, but I may be 
> forgetting something.

Hi Isaac,

It turns out that StartRecording currently does nothing when it is
already recording.  There was a memory leak in that case, so I moved
the allocation to tv.cpp where the delete was anyway.  So with this
patch it does the right thing.  I also moved the sleep to a more
logical place and added continues so that we don't use nextRecording
when it's NULL.

Currently there are no

  recording -> recording 

transitions in tv.cpp so adding a second conflicting but higher
priority show for the current time will not change what is currently
recording.  If this is added then a special check for a noop when
transitioning to recording the "same" show needs to be added.

Would you accept a patch to save partially recorded shows?

> Thanks for the patch, btw =)

You're welcome. :-)

-Jim

Index: libs/libmythtv/tv.cpp
===================================================================
RCS file: /var/lib/cvs/MC/libs/libmythtv/tv.cpp,v
retrieving revision 1.82
diff -u -r1.82 tv.cpp
--- libs/libmythtv/tv.cpp	16 Oct 2002 02:58:32 -0000	1.82
+++ libs/libmythtv/tv.cpp	18 Oct 2002 16:06:48 -0000
@@ -241,7 +242,7 @@
     {
         outputFilename = rcinfo->GetRecordFilename(recprefix);
         recordEndTime = rcinfo->endts;
-        curRecording = rcinfo;
+        curRecording = new ProgramInfo(*rcinfo);
 
         if (internalState == kState_None)
             nextState = kState_RecordingOnly;
@@ -261,7 +262,7 @@
 
             outputFilename = rcinfo->GetRecordFilename(recprefix);
             recordEndTime = rcinfo->endts;
-            curRecording = rcinfo;
+            curRecording = new ProgramInfo(*rcinfo);
 
             nextState = kState_RecordingOnly;
             changeState = true;
@@ -270,7 +271,7 @@
         {
             outputFilename = rcinfo->GetRecordFilename(recprefix);
             recordEndTime = rcinfo->endts;
-            curRecording = rcinfo;
+            curRecording = new ProgramInfo(*rcinfo);
 
             nextState = kState_WatchingRecording;
             changeState = true;
Index: programs/mythfrontend/main.cpp
===================================================================
RCS file: /var/lib/cvs/MC/programs/mythfrontend/main.cpp,v
retrieving revision 1.38
diff -u -r1.38 main.cpp
--- programs/mythfrontend/main.cpp	17 Oct 2002 03:05:16 -0000	1.38
+++ programs/mythfrontend/main.cpp	18 Oct 2002 16:06:48 -0000
@@ -94,21 +94,6 @@
     }
 }
 
-void startRecording(TV *tv, ProgramInfo *rec)
-{
-    ProgramInfo *tvrec = new ProgramInfo(*rec);
-    tv->StartRecording(tvrec);
-}
-
-int askRecording(TV *tv, ProgramInfo *rec, int timeuntil)
-{
-    ProgramInfo *tvrec = new ProgramInfo(*rec);
-    int retval = tv->AllowRecording(tvrec, timeuntil);
-
-    delete tvrec;
-    return retval;
-}
-
 void *runScheduler(void *dummy)
 {
     dummy = dummy;
@@ -118,19 +103,15 @@
     Scheduler *sched = new Scheduler(db);
 
     bool asked = false;
-    int secsleft;
     TV *nexttv = NULL;
 
     ProgramInfo *nextRecording = NULL;
     QDateTime nextrectime;
-    QDateTime curtime;
     QDateTime lastupdate = QDateTime::currentDateTime().addDays(-1);
 
     while (1)
     {
-        sleep(1);
-
-        curtime = QDateTime::currentDateTime();
+        QDateTime curtime = QDateTime::currentDateTime();
 
         if (sched->CheckForChanges() || 
             (lastupdate.date().day() != curtime.date().day()))
@@ -161,7 +142,7 @@
 
         if (nextRecording)
         {
-            secsleft = curtime.secsTo(nextrectime);
+            int secsleft = curtime.secsTo(nextrectime);
 
             //cout << secsleft << " seconds until " << nextRecording->title 
             //     << endl;
@@ -170,26 +151,28 @@
                 secsleft <= 30 && !asked)
             {
                 asked = true;
-                int result = askRecording(nexttv, nextRecording, secsleft);
+                int result = nexttv->AllowRecording(nextRecording, secsleft);
 
                 if (result == 3)
                 {
                     //cout << "Skipping " << nextRecording->title << endl;
                     sched->RemoveFirstRecording();
                     nextRecording = NULL;
+                    continue;
                 }
             }
 
             if (secsleft <= -2)
             {
-                // don't record stuff that's already started..
-                if (secsleft > -30)
-                    startRecording(nexttv, nextRecording);
-
+                nexttv->StartRecording(nextRecording);
+                //cout << "Started recording " << nextRecording->title << endl;
                 sched->RemoveFirstRecording();
                 nextRecording = NULL;
+                continue;
             }
         }
+
+        sleep(1);
     }
     
     return NULL;
Index: programs/mythfrontend/scheduler.cpp
===================================================================
RCS file: /var/lib/cvs/MC/programs/mythfrontend/scheduler.cpp,v
retrieving revision 1.28
diff -u -r1.28 scheduler.cpp
--- programs/mythfrontend/scheduler.cpp	17 Oct 2002 20:35:13 -0000	1.28
+++ programs/mythfrontend/scheduler.cpp	18 Oct 2002 16:06:49 -0000
@@ -194,7 +194,7 @@
             if (proginfo->description == QString::null)
                 proginfo->description = "";
 
-            if (proginfo->startts < curDateTime)
+            if (proginfo->endts < curDateTime)
                 delete proginfo;
             else 
                 recordingList.push_back(proginfo);