Re: [ANNOUNCE] VDR developer version 1.7.17

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 27.03.2011 16:45, schrieb Klaus Schmidinger:
> Can you please rewrite your patch so that it keeps the original 'd'
> variable? I liked the fact that the 'nextUpdate' variable was incremented
> in *one* place, and not in several places. Made the whole thing more
> transparent to me. Besides, I could then see what you have *actually*
> changed ;-)

Another example on how coding style is a matter of taste. One of the
first things I changed was the removing of the d variable that is IMHO
superfluous, doesn't have an unique meaning (file age in seconds and
time to next check), and no descriptive name. ;)

Anyway, I've rewritten it to match your original patch more closely.
Actually I'm surprised how similar they got again, I had some evolution
steps that were completely different.

Attached is the rewritten patch as updatemarks-4, and for your
convenience a diff between updatemarks-2 and updatemarks-4 that shows
the differences more closely.

Cheers,

Udo
diff -Naurp vdr-1.7.17-orig/recording.c vdr-1.7.17-updatemarks-4/recording.c
--- vdr-1.7.17-orig/recording.c	2011-02-27 14:35:20.000000000 +0100
+++ vdr-1.7.17-updatemarks-4/recording.c	2011-04-03 15:05:16.000000000 +0200
@@ -1270,19 +1270,31 @@ bool cMarks::Load(const char *RecordingF
 {
   fileName = AddDirectory(RecordingFileName, IsPesRecording ? MARKSFILESUFFIX ".vdr" : MARKSFILESUFFIX);
   framesPerSecond = FramesPerSecond;
-  lastUpdate = 0;
+  nextUpdate = 0;
   lastFileTime = -1; // the first call to Load() must take place!
+  lastChange = 0;
   return Update();
 }
 
 bool cMarks::Update(void)
 {
   time_t t = time(NULL);
-  if (t - lastUpdate > MARKSUPDATEDELTA) {
-     lastUpdate = t;
-     t = LastModifiedTime(fileName);
-     if (t > lastFileTime) {
-        lastFileTime = t;
+  if (t > nextUpdate) {
+     time_t LastModified = LastModifiedTime(fileName);
+     if (LastModified != lastFileTime) // Change detected, or first run
+        lastChange = LastModified>0 ? LastModified : t;
+     int d = t - lastChange;
+     if (d < 60)
+        d = 1; // check frequently if the file has just been modified
+     else if (d < 3600)
+        d = 10; // older files are checked less frequently
+     else
+        d /= 360; // phase out checking for very old files
+     nextUpdate = t + d;
+     if (LastModified != lastFileTime) { // Change detected, or first run
+        lastFileTime = LastModified;
+        if (lastFileTime == t)
+           lastFileTime--; // Make sure we don't miss updates in the remaining second
         cMutexLock MutexLock(&MutexMarkFramesPerSecond);
         MarkFramesPerSecond = framesPerSecond;
         if (cConfig<cMark>::Load(fileName)) {
diff -Naurp vdr-1.7.17-orig/recording.h vdr-1.7.17-updatemarks-4/recording.h
--- vdr-1.7.17-orig/recording.h	2011-02-27 13:48:21.000000000 +0100
+++ vdr-1.7.17-updatemarks-4/recording.h	2011-04-03 14:57:20.000000000 +0200
@@ -192,8 +192,9 @@ class cMarks : public cConfig<cMark> {
 private:
   cString fileName;
   double framesPerSecond;
-  time_t lastUpdate;
+  time_t nextUpdate;
   time_t lastFileTime;
+  time_t lastChange;
 public:
   bool Load(const char *RecordingFileName, double FramesPerSecond = DEFAULTFRAMESPERSECOND, bool IsPesRecording = false);
   bool Update(void);
diff -Naurp vdr-1.7.17-updatemarks-2/recording.c vdr-1.7.17-updatemarks-4/recording.c
--- vdr-1.7.17-updatemarks-2/recording.c	2011-04-03 14:59:24.000000000 +0200
+++ vdr-1.7.17-updatemarks-4/recording.c	2011-04-03 15:05:16.000000000 +0200
@@ -1272,6 +1272,7 @@ bool cMarks::Load(const char *RecordingF
   framesPerSecond = FramesPerSecond;
   nextUpdate = 0;
   lastFileTime = -1; // the first call to Load() must take place!
+  lastChange = 0;
   return Update();
 }
 
@@ -1280,16 +1281,9 @@ bool cMarks::Update(void)
   time_t t = time(NULL);
   if (t > nextUpdate) {
      time_t LastModified = LastModifiedTime(fileName);
-     int d;
-     if (LastModified > 0) // the file exists
-        d = t - LastModified;
-     else { // the file doesn't exist
-        if (lastFileTime <= 0) {
-           lastFileTime = t - 2; // -2 makes sure we don't miss an update within the very same second
-           LastModified = t; // make sure we run into the actual Load() below
-           }
-        d = t - lastFileTime;
-        }
+     if (LastModified != lastFileTime) // Change detected, or first run
+        lastChange = LastModified>0 ? LastModified : t;
+     int d = t - lastChange;
      if (d < 60)
         d = 1; // check frequently if the file has just been modified
      else if (d < 3600)
@@ -1297,8 +1291,10 @@ bool cMarks::Update(void)
      else
         d /= 360; // phase out checking for very old files
      nextUpdate = t + d;
-     if (LastModified > lastFileTime) {
+     if (LastModified != lastFileTime) { // Change detected, or first run
         lastFileTime = LastModified;
+        if (lastFileTime == t)
+           lastFileTime--; // Make sure we don't miss updates in the remaining second
         cMutexLock MutexLock(&MutexMarkFramesPerSecond);
         MarkFramesPerSecond = framesPerSecond;
         if (cConfig<cMark>::Load(fileName)) {
diff -Naurp vdr-1.7.17-updatemarks-2/recording.h vdr-1.7.17-updatemarks-4/recording.h
--- vdr-1.7.17-updatemarks-2/recording.h	2011-04-03 14:59:24.000000000 +0200
+++ vdr-1.7.17-updatemarks-4/recording.h	2011-04-03 14:57:20.000000000 +0200
@@ -194,6 +194,7 @@ private:
   double framesPerSecond;
   time_t nextUpdate;
   time_t lastFileTime;
+  time_t lastChange;
 public:
   bool Load(const char *RecordingFileName, double FramesPerSecond = DEFAULTFRAMESPERSECOND, bool IsPesRecording = false);
   bool Update(void);
_______________________________________________
vdr mailing list
vdr@xxxxxxxxxxx
http://www.linuxtv.org/cgi-bin/mailman/listinfo/vdr

[Index of Archives]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Big List of Linux Books]     [Fedora Users]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux