Ticket #3291: preservepadding.patch

File preservepadding.patch, 8.2 KB (added by mythtv@…, 17 years ago)
  • scheduler.h

     
    8585    void BuildListMaps(void);
    8686    void ClearListMaps(void);
    8787    bool FindNextConflict(RecList &cardlist, ProgramInfo *p, RecIter &iter,
    88                           bool openEnd = false);
     88                          bool openEnd = false, bool padded = true);
    8989    void MarkOtherShowings(ProgramInfo *p);
    9090    void MarkShowingsList(RecList &showinglist, ProgramInfo *p);
    9191    void BackupRecStatus(void);
  • scheduler.cpp

     
    746746}
    747747
    748748bool Scheduler::FindNextConflict(RecList &cardlist, ProgramInfo *p, RecIter &j,
    749                                  bool openEnd)
     749                                 bool openEnd, bool padded)
    750750{
     751    int prepostroll = 0;
     752    if(padded){
     753        prepostroll +=(int)gContext->GetNumSetting("RecordPreRoll", 0);
     754        prepostroll += (int)gContext->GetNumSetting("RecordOverTime", 0);
     755    }
    751756    for ( ; j != cardlist.end(); j++)
    752757    {
    753758        ProgramInfo *q = *j;
     
    760765            continue;
    761766        if (openEnd && p->chanid != q->chanid)
    762767        {
    763             if (p->recendts < q->recstartts || p->recstartts > q->recendts)
     768            if (p->recendts.addSecs(prepostroll) < q->recstartts || p->recstartts > q->recendts.addSecs(prepostroll))
    764769                continue;
    765770        }
    766771        else
    767772        {
    768             if (p->recendts <= q->recstartts || p->recstartts >= q->recendts)
     773            if (p->recendts.addSecs(prepostroll)  <= q->recstartts || p->recstartts >= q->recendts.addSecs(prepostroll) )
    769774                continue;
    770775        }
    771776        if (p->inputid == q->inputid && p->shareable)
     
    862867    RecStatusType oldstatus = p->recstatus;
    863868    p->recstatus = rsLaterShowing;
    864869
    865     RecIter j = showinglist->begin();
    866     for ( ; j != showinglist->end(); j++)
    867     {
    868         ProgramInfo *q = *j;
    869         if (q == p)
    870             continue;
     870    bool padded = false;
     871    do{  // do 2 passes of the scheduler... first with padding, then resolve conflicts by doing it without
    871872
    872         if (q->recstatus != rsEarlierShowing &&
    873             q->recstatus != rsLaterShowing &&
    874             q->recstatus != rsUnknown)
    875             continue;
    876         if (!p->IsSameTimeslot(*q))
     873        padded = !padded;
     874   
     875        RecIter j = showinglist->begin();
     876        for ( ; j != showinglist->end(); j++)
    877877        {
    878             if (!p->IsSameProgram(*q))
     878            ProgramInfo *q = *j;
     879            if (q == p)
    879880                continue;
    880             if ((p->rectype == kSingleRecord ||
    881                  p->rectype == kOverrideRecord))
     881   
     882            if (q->recstatus != rsEarlierShowing &&
     883                q->recstatus != rsLaterShowing &&
     884                q->recstatus != rsUnknown)
    882885                continue;
    883             if (q->recstartts < schedTime && p->recstartts >= schedTime)
     886            if (!p->IsSameTimeslot(*q))
     887            {
     888                if (!p->IsSameProgram(*q))
     889                    continue;
     890                if ((p->rectype == kSingleRecord ||
     891                     p->rectype == kOverrideRecord))
     892                    continue;
     893                if (q->recstartts < schedTime && p->recstartts >= schedTime)
     894                    continue;
     895            }
     896   
     897            PrintRec(q, "     #");
     898            RecList &cardlist = cardlistmap[q->cardid];
     899            RecIter k = cardlist.begin();
     900            if (FindNextConflict(cardlist, q, k, false, padded))
     901            {
     902                PrintRec(*k, "        !");
    884903                continue;
     904            }
     905            padded = false; // Did it with padding no need to do second pass.
     906   
     907            q->recstatus = rsWillRecord;
     908            MarkOtherShowings(q);
     909            PrintRec(p, "     -");
     910            PrintRec(q, "     +");
     911            return true;
    885912        }
     913    }while(padded);
    886914
    887         PrintRec(q, "     #");
    888         RecList &cardlist = cardlistmap[q->cardid];
    889         RecIter k = cardlist.begin();
    890         if (FindNextConflict(cardlist, q, k))
    891         {
    892             PrintRec(*k, "        !");
    893             continue;
    894         }
    895 
    896         q->recstatus = rsWillRecord;
    897         MarkOtherShowings(q);
    898         PrintRec(p, "     -");
    899         PrintRec(q, "     +");
    900         return true;
    901     }
    902 
    903915    p->recstatus = oldstatus;
    904916    return false;
    905917}
     
    910922
    911923    bool openEnd = (bool)gContext->GetNumSetting("SchedOpenEnd", 0);
    912924
    913     RecIter i = worklist.begin();
    914     while (i != worklist.end())
    915     {
    916         ProgramInfo *p = *i;
    917         if (p->recstatus == rsRecording)
    918             MarkOtherShowings(p);
    919         else if (p->recstatus == rsUnknown)
     925    bool padded = false;
     926    do{  // do 2 passes of the scheduler... first with padding, then resolve conflicts by doing it wihtough
     927
     928        padded = !padded;
     929
     930        RecIter i = worklist.begin();
     931        while (i != worklist.end())
    920932        {
    921             RecList &cardlist = cardlistmap[p->cardid];
    922             RecIter k = cardlist.begin();
    923             if (!FindNextConflict(cardlist, p, k, openEnd))
     933            ProgramInfo *p = *i;
     934            if (p->recstatus == rsRecording)
     935                MarkOtherShowings(p);
     936            else if (p->recstatus == rsUnknown)
    924937            {
    925                 p->recstatus = rsWillRecord;
    926                 MarkOtherShowings(p);
    927                 PrintRec(p, "  +");
     938                RecList &cardlist = cardlistmap[p->cardid];
     939                RecIter k = cardlist.begin();
     940                if (!FindNextConflict(cardlist, p, k, openEnd, padded))
     941                {
     942                    p->recstatus = rsWillRecord;
     943                    MarkOtherShowings(p);
     944                    PrintRec(p, "  +");
     945                }
     946                else
     947                {
     948                    retrylist.push_front(p);
     949                    PrintRec(p, "  #");
     950                    PrintRec(*k, "     !");
     951                }
    928952            }
    929             else
     953   
     954            int lastpri = p->recpriority;
     955            i++;
     956            if (i == worklist.end() || lastpri != (*i)->recpriority)
    930957            {
    931                 retrylist.push_front(p);
    932                 PrintRec(p, "  #");
    933                 PrintRec(*k, "     !");
     958                MoveHigherRecords();
     959                retrylist.clear();
    934960            }
    935961        }
    936 
    937         int lastpri = p->recpriority;
    938         i++;
    939         if (i == worklist.end() || lastpri != (*i)->recpriority)
    940         {
    941             MoveHigherRecords();
    942             retrylist.clear();
    943         }
    944     }
     962    }while(padded);
    945963}
    946964
    947965void Scheduler::MoveHigherRecords(void)
     
    958976        if (TryAnotherShowing(p))
    959977            continue;
    960978
    961         BackupRecStatus();
    962         p->recstatus = rsWillRecord;
    963         MarkOtherShowings(p);
     979        bool padded = false;
     980        do{  // do 2 passes of the scheduler... first with padding, then resolve conflicts by doing it wihtough
     981   
     982            padded = !padded;
    964983
    965         RecList &cardlist = cardlistmap[p->cardid];
    966         RecIter k = cardlist.begin();
    967         for ( ; FindNextConflict(cardlist, p, k); k++)
    968         {
    969             if ((p->recpriority < (*k)->recpriority && !schedMoveHigher) ||
    970                 !TryAnotherShowing(*k))
     984            BackupRecStatus();
     985            p->recstatus = rsWillRecord;
     986            MarkOtherShowings(p);
     987
     988            RecList &cardlist = cardlistmap[p->cardid];
     989   
     990            RecIter k = cardlist.begin();
     991            for ( ; FindNextConflict(cardlist, p, k, false, padded); k++)
    971992            {
    972                 RestoreRecStatus();
    973                 break;
     993                if ((p->recpriority < (*k)->recpriority && !schedMoveHigher) ||
     994                    !TryAnotherShowing(*k))
     995                {
     996                    RestoreRecStatus();
     997                    break;
     998                }
    974999            }
    975         }
    976 
    977         if (p->recstatus == rsWillRecord)
    978             PrintRec(p, "  +");
     1000            if (p->recstatus == rsWillRecord)
     1001            {
     1002                PrintRec(p, "  +");
     1003                padded = false; // moving conflicts worked... no need to try second pass
     1004            }
     1005        }while(padded);
    9791006    }
    9801007}
    9811008