From d072cc6da2e109d0dc6b98375a1bab3a2ac83948 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Fri, 30 May 2003 18:00:00 +0200 Subject: =?UTF-8?q?Version=201.2.0pre1=20-=20Some=20corrections=20to=20the?= =?UTF-8?q?=20French=20OSD=20texts=20(thanks=20to=20Olivier=20Jacques).=20?= =?UTF-8?q?-=20Fixed=20some=20missing=20commas=20in=20i18n.c=20(thanks=20t?= =?UTF-8?q?o=20Dimitrios=20Dimitrakos=20for=20=20=20reporting=20this=20pro?= =?UTF-8?q?blem).=20-=20Some=20corrections=20to=20the=20Finnish=20OSD=20te?= =?UTF-8?q?xts=20(thanks=20to=20Niko=20Tarnanen=20and=20Rolf=20=20=20Ahren?= =?UTF-8?q?berg).=20-=20Completed=20the=20Italian=20OSD=20texts=20(thanks?= =?UTF-8?q?=20to=20Antonio=20Ospite).=20-=20Fixed=20breaking=20off=20repla?= =?UTF-8?q?y=20in=20case=20the=20user=20hits=20"Play"=20or=20"Pause"=20too?= =?UTF-8?q?=20soon=20after=20=20=20going=20into=20"Pause=20live=20video"?= =?UTF-8?q?=20mode=20(thanks=20to=20Karim=20Afifi=20for=20reporting=20ths?= =?UTF-8?q?=20one).=20-=20Some=20corrections=20to=20the=20Catalanian=20OSD?= =?UTF-8?q?=20texts=20(thanks=20to=20Jordi=20Vil=C3=A0).=20-=20Single=20ev?= =?UTF-8?q?ent=20timers=20are=20now=20deleted=20if=20the=20recording=20the?= =?UTF-8?q?y=20are=20doing=20is=20=20=20deleted=20before=20the=20timer=20e?= =?UTF-8?q?nds.=20-=20Fixed=20an=20uninitialized=20variable=20in=20cDispla?= =?UTF-8?q?yChannel=20(thanks=20to=20Stefan=20Huelswitt).=20-=20Fixed=20a?= =?UTF-8?q?=20possible=20access=20of=20invalid=20file=20handles=20in=20cSI?= =?UTF-8?q?Processor::Action()=20=20=20(thanks=20to=20Stefan=20Huelswitt).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- recording.c | 95 +++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 52 insertions(+), 43 deletions(-) (limited to 'recording.c') diff --git a/recording.c b/recording.c index 7e68a79..06f6325 100644 --- a/recording.c +++ b/recording.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: recording.c 1.79 2003/05/24 11:22:34 kls Exp $ + * $Id: recording.c 1.80 2003/05/30 13:23:54 kls Exp $ */ #include "recording.h" @@ -769,6 +769,12 @@ void cRecordingUserCommand::InvokeCommand(const char *State, const char *Recordi #define INDEXFILESUFFIX "/index.vdr" +// The number of frames to stay off the end in case of time shift: +#define INDEXSAFETYLIMIT 100 // frames + +// The maximum time to wait before giving up while catching up on an index file: +#define MAXINDEXCATCHUP 8 // seconds + // The minimum age of an index file for considering it no longer to be written: #define MININDEXAGE 3600 // seconds @@ -852,47 +858,50 @@ bool cIndexFile::CatchUp(int Index) { // returns true unless something really goes wrong, so that 'index' becomes NULL if (index && f >= 0) { - if (Index < 0 || Index >= last) { - struct stat buf; - if (fstat(f, &buf) == 0) { - if (time(NULL) - buf.st_mtime > MININDEXAGE) { - // apparently the index file is not being written any more - close(f); - f = -1; - return true; - } - int newLast = buf.st_size / sizeof(tIndex) - 1; - if (newLast > last) { - if (size <= newLast) { - size *= 2; - if (size <= newLast) - size = newLast + 1; - } - index = (tIndex *)realloc(index, size * sizeof(tIndex)); - if (index) { - int offset = (last + 1) * sizeof(tIndex); - int delta = (newLast - last) * sizeof(tIndex); - if (lseek(f, offset, SEEK_SET) == offset) { - if (safe_read(f, &index[last + 1], delta) != delta) { - esyslog("ERROR: can't read from index"); - free(index); - index = NULL; - close(f); - f = -1; - return true; - } - last = newLast; - } - else - LOG_ERROR_STR(fileName); - } - else - esyslog("ERROR: can't realloc() index"); - } - } - else - LOG_ERROR_STR(fileName); - } + for (int i = 0; i <= MAXINDEXCATCHUP && (Index < 0 || Index >= last); i++) { + struct stat buf; + if (fstat(f, &buf) == 0) { + if (time(NULL) - buf.st_mtime > MININDEXAGE) { + // apparently the index file is not being written any more + close(f); + f = -1; + break; + } + int newLast = buf.st_size / sizeof(tIndex) - 1; + if (newLast > last) { + if (size <= newLast) { + size *= 2; + if (size <= newLast) + size = newLast + 1; + } + index = (tIndex *)realloc(index, size * sizeof(tIndex)); + if (index) { + int offset = (last + 1) * sizeof(tIndex); + int delta = (newLast - last) * sizeof(tIndex); + if (lseek(f, offset, SEEK_SET) == offset) { + if (safe_read(f, &index[last + 1], delta) != delta) { + esyslog("ERROR: can't read from index"); + free(index); + index = NULL; + close(f); + f = -1; + break; + } + last = newLast; + } + else + LOG_ERROR_STR(fileName); + } + else + esyslog("ERROR: can't realloc() index"); + } + } + else + LOG_ERROR_STR(fileName); + if (Index < last - (i ? 2 * INDEXSAFETYLIMIT : 0) || Index > 10 * INDEXSAFETYLIMIT) // keep off the end in case of "Pause live video" + break; + sleep(1); + } } return index != NULL; } @@ -940,7 +949,7 @@ int cIndexFile::GetNextIFrame(int Index, bool Forward, uchar *FileNumber, int *F int d = Forward ? 1 : -1; for (;;) { Index += d; - if (Index >= 0 && Index < last - ((Forward && StayOffEnd) ? 100 : 0)) { + if (Index >= 0 && Index < last - ((Forward && StayOffEnd) ? INDEXSAFETYLIMIT : 0)) { if (index[Index].type == I_FRAME) { if (FileNumber) *FileNumber = index[Index].number; -- cgit v1.2.3