[mythtv] [PATCH] fix auto-transcode for "find once" schedules

Chris Pinkham cpinkham at bc2va.org
Tue Jun 21 06:15:53 UTC 2005


> I could have sworn this was working way back when I initially
> submitted it (I remember this "find once" case giving me problems back
> then). It's possible that things were subtly busted between the time
> of initial submission and eventual commit (lots of things were
> changing).

Can you take a look at the attached patch and see if it looks like it
accomplishes the same thing you were going for.  I have had a couple
complaints about the same bug with commercial flagging and hadn't had a
chance to investigate yet.

The attached patch adds a integer autoRunJobs to replace the bool
autoTranscode.  autoRunJobs is set to JOB_NONE when a recording
starts.  If we are not watching LiveTV (this is not the "Live TV"
profile, I mean actual LiveTV), then autoRunJobs is filled in using
autoRunJobs = curRecording->GetAutoRunJobs().  Now, if the scheduled
recording is setup to autotranscode, the JOB_TRANSCODE bit will be
turned ON in the autoRunJobs mask so we check to see if we
should turn it off.  The code gets the profileAutoTranscode setting
and checks the value of that.  If the profileAutoTranscode setting can
not be retrieved or it is retrieved but is 0, then the JOB_TRANSCODE
bit is masked OUT of autoRunJobs to make sure we don't allow transcode
to run even if the scheduled recording said to run the transcoder.

If a semi-realtime commercial flagging job is queued, the JOB_COMMFLAG
bit is masked OUT of the autoRunJobs mask, so we don't reschedule another
flagging job when the recording finishes.

When the recording finishes, we check the autoRunJobs mask and call
JobQueue::QueueJobs() if necessary.

I think this makes the code a little cleaner and fixes the bug you were
trying to fix as well as the one I needed to fix. :)

I just coded this up but haven't had a chance to give it a good testing,
I'll have more time tomorrow night.  I wanted to verify with you if it
looks like it would solve the issue you were seeing as well.  It should be
the same bug for all Jobs with the "find once" recording schedules.  Now,
since we only call curRecording->GetAutoRunJobs() once at the beginning
when the recording first starts, we get the correct values in autoRunJobs
before the recording finishes and before ProgramInfo::FinishedRecording()
calls ScheduledRecording::DoneRecording() which in turn calls
ScheduledRecording::remove().

The patch is against current CVS as of 2am EST Tuesday.

-- 
Chris

-------------- next part --------------
Index: libs/libmythtv/jobqueue.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/jobqueue.h,v
retrieving revision 1.10
diff -u -r1.10 jobqueue.h
--- libs/libmythtv/jobqueue.h	5 Jun 2005 20:51:30 -0000	1.10
+++ libs/libmythtv/jobqueue.h	21 Jun 2005 06:11:32 -0000
@@ -76,6 +76,12 @@
     JOB_USERJOB4     = 0x0800
 };
 
+#define ClearJobMask(mask)               mask = JOB_NONE;
+#define JobIsInMask(job, mask)           ((bool)(job & mask))
+#define JobIsNotInMask(job, mask)        (!(JobIsInMask(job, mask)))
+#define AddJobsToMask(jobs, mask)        mask |= jobs;
+#define RemoveJobsFromMask(jobs, mask)   mask &= (~jobs);
+
 typedef struct jobqueueentry {
     int id;
     QString chanid;
@@ -198,3 +204,4 @@
 
 #endif
 
+/* vim: set expandtab tabstop=4 shiftwidth=4: */
Index: libs/libmythtv/tv_rec.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/tv_rec.cpp,v
retrieving revision 1.196
diff -u -r1.196 tv_rec.cpp
--- libs/libmythtv/tv_rec.cpp	20 Jun 2005 21:42:07 -0000	1.196
+++ libs/libmythtv/tv_rec.cpp	21 Jun 2005 06:11:32 -0000
@@ -103,7 +103,7 @@
       frameRate(-1.0f), overrecordseconds(0), 
       // Current recording info
       curRecording(NULL), profileName(""),
-      askAllowRecording(false), autoTranscode(false),
+      askAllowRecording(false), autoRunJobs(JOB_NONE),
       // Pending recording info
       pendingRecording(NULL), recordPending(false), cancelNextRecording(false),
       // RingBuffer info
@@ -660,11 +660,19 @@
         QString msg = QString("Using profile '%1' to record").arg(profileName);
         VERBOSE(VB_RECORD, msg);
 
-        // Determine whether to automatically run the transcoder or not
-        Setting *profileAutoTranscode = profile.byName("autotranscode");
-        autoTranscode = (profileAutoTranscode &&
-                         profileAutoTranscode->getValue().toInt() != 0) ?
-                         true : false;
+        ClearJobMask(autoRunJobs);
+        if ((tmpInternalState != kState_WatchingLiveTV) &&
+            (curRecording))
+        {
+            AddJobsToMask(curRecording->GetAutoRunJobs(), autoRunJobs);
+
+            // Make sure transcoding is OFF if the profile does not allow
+            // AutoTranscoding.
+            Setting *profileAutoTranscode = profile.byName("autotranscode");
+            if ((!profileAutoTranscode) ||
+                (profileAutoTranscode->getValue().toInt() == 0))
+                RemoveJobsFromMask(JOB_TRANSCODE, autoRunJobs);
+        }
 
         bool error = false;
 
@@ -705,16 +713,18 @@
             frameRate = recorder->GetFrameRate();
 
             if ((tmpInternalState != kState_WatchingLiveTV) &&
-                (!curRecording->chancommfree) &&
-                (curRecording->GetAutoRunJobs() & JOB_COMMFLAG) &&
-                (earlyCommFlag) &&
-                ((autoTranscode && !transcodeFirst) || (!autoTranscode)))
+                (curRecording) && (!curRecording->chancommfree) &&
+                (JobIsInMask(JOB_COMMFLAG, autoRunJobs)) && (earlyCommFlag) &&
+                ((JobIsNotInMask(JOB_TRANSCODE, autoRunJobs)) ||
+                 (JobIsInMask(JOB_TRANSCODE, autoRunJobs) && !transcodeFirst)))
             {
                 JobQueue::QueueJob(
                     JOB_COMMFLAG, curRecording->chanid,
                     curRecording->recstartts, "", "",
                     (runJobOnHostOnly) ? gContext->GetHostName() : "",
                     JOB_LIVE_REC);
+
+                RemoveJobsFromMask(JOB_COMMFLAG, autoRunJobs);
             }
         }
         else
@@ -875,8 +885,8 @@
  *
  *   A "RECORDING_LIST_CHANGE" message is dispatched.
  *
- *   Finally if there was a recording and it was not deleted
- *   commercial flagging and user jobs are scheduled.
+ *   Finally, if there was a recording and it was not deleted,
+ *   schedule any post-processing jobs.
  *
  *  \param killFile if true the recorded file is deleted.
  */
@@ -886,10 +896,6 @@
 
     int filelen = -1;
 
-    ProgramInfo *prevRecording = NULL;
-    if (curRecording)
-        prevRecording = new ProgramInfo(*curRecording);
-
     ispip = false;
 
     if (recorder)
@@ -929,44 +935,17 @@
 
     if (curRecording)
     {
+        if (autoRunJobs && !killFile && !prematurelystopped)
+            JobQueue::QueueJobs(
+                autoRunJobs, curRecording->chanid, curRecording->recstartts,
+                "", "", (runJobOnHostOnly) ? gContext->GetHostName() : "");
+
         delete curRecording;
         curRecording = NULL;
     }
 
     MythEvent me("RECORDING_LIST_CHANGE");
     gContext->dispatch(me);
-
-    if (prevRecording && !killFile)
-    {
-        if (!prematurelystopped)
-        {
-            int jobTypes = prevRecording->GetAutoRunJobs();
-
-            if ((prevRecording->chancommfree) ||
-                ((earlyCommFlag) &&
-                 ((!autoTranscode) || (autoTranscode && !transcodeFirst))))
-                jobTypes = jobTypes & (~JOB_COMMFLAG);
-
-            // Only auto-transcode if recording profile allows it.
-            if (!autoTranscode)
-                jobTypes &= ~JOB_TRANSCODE;
-
-            if (jobTypes)
-            {
-                QString jobHost = "";
-
-                if (runJobOnHostOnly)
-                    jobHost = gContext->GetHostName();
-
-                JobQueue::QueueJobs(jobTypes,
-                                    prevRecording->chanid,
-                                    prevRecording->recstartts, "", "", jobHost);
-            }
-        }
-    }
-
-    if (prevRecording)
-        delete prevRecording;
 }    
 
 /** \fn TVRec::GetScreenGrab(const ProgramInfo*,const QString&,int,int&,int&,int&)
Index: libs/libmythtv/tv_rec.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/tv_rec.h,v
retrieving revision 1.73
diff -u -r1.73 tv_rec.h
--- libs/libmythtv/tv_rec.h	20 Jun 2005 21:42:07 -0000	1.73
+++ libs/libmythtv/tv_rec.h	21 Jun 2005 06:11:32 -0000
@@ -260,7 +260,7 @@
     QDateTime    recordEndTime;
     QString      profileName;
     bool         askAllowRecording;
-    bool         autoTranscode;
+    int          autoRunJobs;
 
     // Pending recording info
     ProgramInfo *pendingRecording;


More information about the mythtv-dev mailing list