From 30009067158bc40f50469cb82234b4013ef14e9e Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sat, 13 Aug 2011 12:45:42 +0200 Subject: [PATCH] The length (as number of frames) of a recording's index file can now be determined by a call to cIndexFile::GetLength() --- CONTRIBUTORS | 2 ++ HISTORY | 2 ++ recording.c | 11 ++++++++++- recording.h | 5 ++++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index c8d777c9..38458790 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -2228,6 +2228,8 @@ Christoph Haubrich the same PID for adding HD stream content identifiers to vdr.5 for reporting that Setup.InitialChannel was dereferenced without checking for NULL + for suggesting to implement a function to determine the length of a recording's + index file Pekka Mauno for fixing cSchedule::GetFollowingEvent() in case there is currently no present diff --git a/HISTORY b/HISTORY index 7bb15071..e0d7dbed 100644 --- a/HISTORY +++ b/HISTORY @@ -6679,3 +6679,5 @@ Video Disk Recorder Revision History - Now scanning new transponders before old ones, to make sure transponder changes are recognized (thanks to Reinhard Nissl). - Implemented static cIndexFile::IndexFileName(). +- The length (as number of frames) of a recording's index file can now be determined + by a call to cIndexFile::GetLength() (suggested by Christoph Haubrich). diff --git a/recording.c b/recording.c index 317e6305..4456bddb 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 2.32 2011/08/13 10:59:32 kls Exp $ + * $Id: recording.c 2.33 2011/08/13 12:37:25 kls Exp $ */ #include "recording.h" @@ -1816,6 +1816,15 @@ void cIndexFile::Delete(void) } } +int cIndexFile::GetLength(const char *FileName, bool IsPesRecording) +{ + struct stat buf; + cString s = IndexFileName(FileName, IsPesRecording); + if (*s && stat(s, &buf) == 0) + return buf.st_size / (IsPesRecording ? sizeof(tIndexTs) : sizeof(tIndexPes)); + return -1; +} + bool GenerateIndex(const char *FileName) { if (DirectoryOk(FileName)) { diff --git a/recording.h b/recording.h index 4498ae9b..3a0ad570 100644 --- a/recording.h +++ b/recording.h @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: recording.h 2.20 2011/08/13 09:52:25 kls Exp $ + * $Id: recording.h 2.21 2011/08/13 12:36:54 kls Exp $ */ #ifndef __RECORDING_H @@ -260,6 +260,9 @@ public: bool StoreResume(int Index) { return resumeFile.Save(Index); } bool IsStillRecording(void); void Delete(void); + static int GetLength(const char *FileName, bool IsPesRecording = false); + ///< Calculates the recording length (numer of frames) without actually reading the index file. + ///< Returns -1 in case of error. }; class cFileName {