Ticket #10685: 10685-v1.patch

File 10685-v1.patch, 6.3 KB (added by danielk, 8 years ago)

Proof-of-Concept patch

  • mythtv/libs/libmythtv/tv_rec.cpp

    diff --git a/mythtv/libs/libmythtv/tv_rec.cpp b/mythtv/libs/libmythtv/tv_rec.cpp
    index 2ecbd5b..bf4ed21 100644
    a b TVRec::TVRec(int capturecardnum) 
    107107      switchingBuffer(false),
    108108      m_recStatus(rsUnknown),
    109109      // Current recording info
    110       curRecording(NULL), autoRunJobs(JOB_NONE),
     110      curRecording(NULL),
    111111      overrecordseconds(0),
    112112      // Pseudo LiveTV recording
    113113      pseudoLiveTVRecording(NULL),
    void TVRec::FinishedRecording(RecordingInfo *curRec, RecordingQuality *recq) 
    916916    curRec->FinishedRecording(!is_good || (recgrp == "LiveTV"));
    917917
    918918    // send out REC_FINISHED message
    919     SendMythSystemRecEvent("REC_FINISHED", curRecording);
     919    SendMythSystemRecEvent("REC_FINISHED", curRec);
    920920
    921921    // send out DONE_RECORDING message
    922922    int secsSince = curRec->GetRecordingStartTime()
    void TVRec::FinishedRecording(RecordingInfo *curRec, RecordingQuality *recq) 
    927927    gCoreContext->dispatch(me);
    928928
    929929    // Handle JobQueue
     930    QHash<QString,int>::iterator autoJob =
     931        autoRunJobs.find(curRec->MakeUniqueKey());
     932    if (autoJob == autoRunJobs.end())
     933    {
     934        AutoRunInitType t =
     935            (recgrp == "LiveTV") ? kAutoRunNone : kAutoRunProfile;
     936        InitAutoRunJobs(curRec, t, NULL, __LINE__);
     937        autoJob = autoRunJobs.find(curRec->MakeUniqueKey());
     938    }
     939    LOG(VB_GENERAL, LOG_INFO, QString("AutoRunJobs 0x%1")
     940        .arg(*autoJob,0,16));
     941
    930942    if ((recgrp == "LiveTV") || (fsize < 1000) ||
    931943        (curRec->GetRecordingStatus() != rsRecorded) ||
    932944        (curRec->GetRecordingStartTime().secsTo(
    933945            QDateTime::currentDateTime()) < 120))
    934946    {
    935         JobQueue::RemoveJobsFromMask(JOB_COMMFLAG,  autoRunJobs);
    936         JobQueue::RemoveJobsFromMask(JOB_TRANSCODE, autoRunJobs);
    937     }
    938     if (autoRunJobs)
    939     {
    940         JobQueue::QueueRecordingJobs(*curRec, autoRunJobs);
     947        JobQueue::RemoveJobsFromMask(JOB_COMMFLAG,  *autoJob);
     948        JobQueue::RemoveJobsFromMask(JOB_TRANSCODE, *autoJob);
    941949    }
     950    if (*autoJob != JOB_NONE)
     951        JobQueue::QueueRecordingJobs(*curRec, *autoJob);
     952    autoRunJobs.erase(autoJob);
    942953}
    943954
    944955#define TRANSITION(ASTATE,BSTATE) \
    void TVRec::NotifySchedulerOfRecording(RecordingInfo *rec) 
    26922703    ClearFlags(kFlagCancelNextRecording);
    26932704}
    26942705
     2706void TVRec::InitAutoRunJobs(RecordingInfo *rec, AutoRunInitType t,
     2707                            RecordingProfile *recpro, int line)
     2708{
     2709    if (kAutoRunProfile == t)
     2710    {
     2711        RecordingProfile profile;
     2712        if (!recpro)
     2713        {
     2714            load_profile(genOpt.cardtype, NULL, rec, profile);
     2715            recpro = &profile;
     2716        }
     2717        autoRunJobs[rec->MakeUniqueKey()] =
     2718            init_jobs(rec, *recpro, runJobOnHostOnly,
     2719                      transcodeFirst, earlyCommFlag);
     2720    }
     2721    else
     2722    {
     2723        autoRunJobs[rec->MakeUniqueKey()] = JOB_NONE;
     2724    }
     2725    LOG(VB_GENERAL, LOG_INFO,
     2726        QString("InitAutoRunJobs for %1, line %2 -> 0x%3")
     2727        .arg(rec->MakeUniqueKey()).arg(line)
     2728        .arg(autoRunJobs[rec->MakeUniqueKey()],0,16));
     2729}
     2730
    26952731/** \fn TVRec::SetLiveRecording(int)
    26962732 *  \brief Tells the Scheduler about changes to the recording status
    26972733 *         of the LiveTV recording.
    void TVRec::SetLiveRecording(int recording) 
    27202756        // cancel -- 'recording' should be 0 or -1
    27212757        SetFlags(kFlagCancelNextRecording);
    27222758        curRecording->SetRecordingGroup("LiveTV");
    2723         autoRunJobs = JOB_NONE;
     2759        InitAutoRunJobs(curRecording, kAutoRunNone, NULL, __LINE__);
    27242760    }
    27252761    else if (!was_rec && pseudoLiveTVRecording)
    27262762    {
    void TVRec::SetLiveRecording(int recording) 
    27342770        NotifySchedulerOfRecording(curRecording);
    27352771        recstat = curRecording->GetRecordingStatus();
    27362772        curRecording->SetRecordingGroup("Default");
    2737 
    2738         RecordingProfile profile;
    2739         load_profile(genOpt.cardtype, NULL, curRecording, profile);
    2740         autoRunJobs = init_jobs(curRecording, profile, runJobOnHostOnly,
    2741                                 transcodeFirst, earlyCommFlag);
     2773        InitAutoRunJobs(curRecording, kAutoRunProfile, NULL, __LINE__);
    27422774    }
    27432775
    27442776    MythEvent me(QString("UPDATE_RECORDING_STATUS %1 %2 %3 %4 %5")
    void TVRec::TuningNewRecorder(MPEGStreamData *streamData) 
    40734105
    40744106    SetFlags(kFlagRecorderRunning | kFlagRingBufferReady);
    40754107
    4076     if (!tvchain)
    4077         autoRunJobs = init_jobs(rec, profile, runJobOnHostOnly,
    4078                                 transcodeFirst, earlyCommFlag);
     4108    InitAutoRunJobs(rec, (tvchain) ? kAutoRunNone : kAutoRunProfile,
     4109                    &profile, __LINE__);
    40794110
    40804111    ClearFlags(kFlagNeedToStartRecorder);
    40814112    return;
    void TVRec::TuningRestartRecorder(void) 
    41474178        curRecording->ApplyRecordRecGroupChange(
    41484179            curRecording->GetRecordingRule()->m_recGroup);
    41494180
    4150         RecordingProfile profile;
    4151         QString profileName = load_profile(genOpt.cardtype, NULL,
    4152                                            curRecording, profile);
    4153         autoRunJobs = init_jobs(curRecording, profile, runJobOnHostOnly,
    4154                                 transcodeFirst, earlyCommFlag);
     4181        InitAutoRunJobs(curRecording, kAutoRunProfile, NULL, __LINE__);
    41554182    }
    41564183
    41574184    ClearFlags(kFlagNeedToStartRecorder);
  • mythtv/libs/libmythtv/tv_rec.h

    diff --git a/mythtv/libs/libmythtv/tv_rec.h b/mythtv/libs/libmythtv/tv_rec.h
    index ce54bff..576ed0f 100644
    a b class MTV_PUBLIC TVRec : public SignalMonitorListener, public QRunnable 
    312312    QDateTime GetRecordEndTime(const ProgramInfo*) const;
    313313    void CheckForRecGroupChange(void);
    314314    void NotifySchedulerOfRecording(RecordingInfo*);
     315    typedef enum { kAutoRunProfile, kAutoRunNone, } AutoRunInitType;
     316    void InitAutoRunJobs(RecordingInfo*, AutoRunInitType,
     317                         RecordingProfile *, int line);
    315318
    316319    void SetRecordingStatus(
    317320        RecStatusType new_status, int line, bool have_lock = false);
    class MTV_PUBLIC TVRec : public SignalMonitorListener, public QRunnable 
    372375    // Current recording info
    373376    RecordingInfo *curRecording;
    374377    QDateTime    recordEndTime;
    375     int          autoRunJobs;
     378    QHash<QString,int> autoRunJobs; // RecordingInfo->MakeUniqueKey()->autoRun
    376379    int          overrecordseconds;
    377380
    378381    // Pending recording info