Am 20.03.2011 13:31, schrieb Klaus Schmidinger:
> On 20.03.2011 12:46, Klaus Schmidinger wrote:
>> I have attached a patch that implements this.
>> Would this be ok?
> 
> Sorry, there was a line missing that makes sure the initial load
> takes place. Attached is a revised version of the patch.

You're too fast for me.... :D


I like the general idea, but I have some points about it:
- Disappearing marks or replacing marks by older versions is not detected.
- Double updates within one second may get lost.
- I don't think that it hurts to poll every 10 seconds, so IMHO we can
drop the 3600s check.
- When in pause mode with the progress bar on OSD, the OSD doesn't get
updated when the marks get reloaded.

After some iterations I've ended with the attached patch that fixes the
first two issues, and is less messy with lastFileTime. Any change of
file time will be detected, and the new lastChange covers cases where no
marks file is present. There's a small gap with the lastFileTime == t
check on NFS volumes with unsynced clocks, but thats another story.

The third point is a matter of taste, and the fourth is not that important.

Cheers,

Udo
diff -Naurp vdr-1.7.17-orig/recording.c vdr-1.7.17/recording.c
--- vdr-1.7.17-orig/recording.c	2011-02-27 14:35:20.000000000 +0100
+++ vdr-1.7.17/recording.c	2011-03-20 20:46:01.000000000 +0100
@@ -1270,19 +1270,30 @@ 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;
+     if (t - lastChange < 60)
+        nextUpdate = t + 1; // check frequently if the file has just been modified
+     else if (t - lastChange < 3600)
+        nextUpdate = t + 10; // older files are checked less frequently
+     else
+        nextUpdate = t + (t - lastChange)/360; // phase out checking for very old files
+   
+     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/recording.h
--- vdr-1.7.17-orig/recording.h	2011-02-27 13:48:21.000000000 +0100
+++ vdr-1.7.17/recording.h	2011-03-20 19:35:27.000000000 +0100
@@ -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);
_______________________________________________
vdr mailing list
vdr@linuxtv.org
http://www.linuxtv.org/cgi-bin/mailman/listinfo/vdr

Reply via email to