[mythtv] Re: Re: Ticket #255: Improved scheduling of consecutive programs with pre-roll/overrecord

David Engel gigem at comcast.net
Sat Oct 1 02:25:52 UTC 2005


On Fri, Sep 30, 2005 at 11:26:09PM +1000, William Uther wrote:
> While I was trying to be complete, that is a lot of things to  
> consider.  Settings for all of them would be major featureitis.   

That's still an understatement!

> So, here is what I would do:
> 
> Separate pre/post-roll and soft time adjustments.  Each show gets  
> gets four settings: hard and soft, pre and post time adjustments.   
> There are also global defaults that get used as initial values for  
> these four settings for new shows.  There are also the following  
> global settings:
> 
>  1a) Reschedule higher priorities (boolean), or
>  1b) Later showing priority delta (integer)
>  2) Reschedule soft time adjustments (boolean)
>  3) Soft end time adjustment priority delta (integer)
>  4) Propagate soft time adjustments (boolean)
> [much more deleted]

Great.  When can we expect your patch? :) 

I'm only partly joking since I would dearly love to see how someone
else would approach the scheduling task and come up with working code.

My quick hack is attached.  It's admittedly going to be somewhat
inefficient due to its brute force nature.  However, it leverages the
existing scheduler logic by sticking with the concept of throwing all
combinations into the mix, assigning priorities (either explicitly or
implicitly) and seeing what comes out the other end.

For those that would like to try it, tweak the softstart* and softend*
assignements at the end of the patch.  For best results, keep
softendpri >= softstartpri and softendoffset >= softstartoffset.  

Please note that it breaks changing the end-time of in-progress
recordings, so that feature is disabled.  It can be fixed.  Also, the
heuristics used to break ties between equal priorities are
simple-minded.  They can be improved if needed.

David
-- 
David Engel
gigem at comcast.net
-------------- next part --------------
Index: programs/mythbackend/scheduler.cpp
===================================================================
--- programs/mythbackend/scheduler.cpp	(revision 7354)
+++ programs/mythbackend/scheduler.cpp	(working copy)
@@ -145,12 +145,12 @@
     return a->recordid < b->recordid;
 }
 
-static bool comp_recstart(ProgramInfo *a, ProgramInfo *b)
+static bool comp_redundant(ProgramInfo *a, ProgramInfo *b)
 {
-    if (a->recstartts != b->recstartts)
-        return a->recstartts < b->recstartts;
-    if (a->recendts != b->recendts)
-        return a->recendts < b->recendts;
+    if (a->startts != b->startts)
+        return a->startts < b->startts;
+    if (a->endts != b->endts)
+        return a->endts < b->endts;
 
     // Note: the PruneRedundants logic depends on the following
     if (a->title != b->title)
@@ -162,6 +162,17 @@
     return a->recstatus < b->recstatus;
 }
 
+static bool comp_recstart(ProgramInfo *a, ProgramInfo *b)
+{
+    if (a->recstartts != b->recstartts)
+        return a->recstartts < b->recstartts;
+    if (a->recendts != b->recendts)
+        return a->recendts < b->recendts;
+    if (a->chansign != b->chansign)
+        return a->chansign < b->chansign;
+    return a->recstatus < b->recstatus;
+}
+
 static QDateTime schedTime;
 static bool schedCardsFirst;
 
@@ -182,6 +193,12 @@
     if (apri != bpri)
         return apri < bpri;
 
+    int alen = a->recstartts.secsTo(a->recendts);
+    int blen = b->recstartts.secsTo(b->recendts);
+
+    if (alen != blen)
+        return alen > blen;
+
     if (a->recstartts != b->recstartts)
     {
         if (apast)
@@ -274,10 +291,13 @@
     ClearListMaps();
 
     VERBOSE(VB_SCHEDULE, "Sort by time...");
-    reclist.sort(comp_recstart);
+    reclist.sort(comp_redundant);
     VERBOSE(VB_SCHEDULE, "PruneRedundants...");
     PruneRedundants();
 
+    VERBOSE(VB_SCHEDULE, "Sort by time...");
+    reclist.sort(comp_recstart);
+
     return hasconflicts;
 }
 
@@ -685,19 +705,15 @@
         p->rectype == kFindWeeklyRecord)
         showinglist = recordidlistmap[p->recordid];
 
+    p->recstatus = rsLaterShowing;
+
     RecIter j = showinglist.begin();
     for ( ; j != showinglist.end(); j++)
     {
         ProgramInfo *q = *j;
         if (q == p)
-            break;
-    }
+            continue;
 
-    p->recstatus = rsLaterShowing;
-
-    for (j++; j != showinglist.end(); j++)
-    {
-        ProgramInfo *q = *j;
         if (q->recstatus != rsEarlierShowing &&
             q->recstatus != rsLaterShowing)
             continue;
@@ -2017,11 +2033,13 @@
             ProgramInfo *r = *rec;
             if (p->IsSameTimeslot(*r))
             {
+#if 0
                 if (r->inputid == p->inputid &&
                     r->recendts != p->recendts &&
                     (r->recordid == p->recordid ||
                      p->rectype == kOverrideRecord))
                     ChangeRecordingEnd(r, p);
+#endif
                 delete p;
                 p = NULL;
                 break;
@@ -2066,6 +2084,32 @@
             p->recstatus = rsMissed;
 
         tmpList.push_back(p);
+
+        // Add soft candidates
+        if (p->recstatus == rsUnknown)
+        {
+            int softstartpri = 0;
+            int softstartoffset = 3;
+            int softendpri = 0;
+            int softendoffset = 10;
+            ProgramInfo *softp;
+
+            softp = new ProgramInfo(*p);
+            softp->recpriority += softstartpri;
+            softp->recstartts = softp->recstartts.addSecs(-60 * softstartoffset + 1);
+            tmpList.push_back(softp);
+
+            softp = new ProgramInfo(*p);
+            softp->recpriority += softendpri;
+            softp->recendts = softp->recendts.addSecs(60 * softendoffset);
+            tmpList.push_back(softp);
+
+            softp = new ProgramInfo(*p);
+            softp->recpriority += softstartpri + softendpri;
+            softp->recstartts = softp->recstartts.addSecs(-60 * softstartoffset + 1);
+            softp->recendts = softp->recendts.addSecs(60 * softendoffset);
+            tmpList.push_back(softp);
+        }
     }
 
     VERBOSE(VB_SCHEDULE, " +-- Cleanup...");


More information about the mythtv-dev mailing list