summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2011-08-21 13:47:07 +0200
committerKlaus Schmidinger <vdr@tvdr.de>2011-08-21 13:47:07 +0200
commitdac837d38d4a84d785fc11da7e276ffcc22ec331 (patch)
tree2a5a9e827536799f8efe40bede9b429c2106f543
parent97ad2fa95df2f03e4c1dff9d4ff2d5abcaad42d8 (diff)
downloadvdr-dac837d38d4a84d785fc11da7e276ffcc22ec331.tar.gz
vdr-dac837d38d4a84d785fc11da7e276ffcc22ec331.tar.bz2
Implemented cRecording::NumFrames() and cRecording::LengthInSeconds()
-rw-r--r--CONTRIBUTORS1
-rw-r--r--HISTORY3
-rw-r--r--recording.c28
-rw-r--r--recording.h8
4 files changed, 35 insertions, 5 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index b438dc6e..99337f58 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -743,6 +743,7 @@ Steffen Barszus <st_barszus@gmx.de>
for helping to debug a crash when using the --terminal option without having access
to the given terminal
for fixing following symbolic links in RemoveFileOrDir()
+ for suggesting to cache the length of a recording's index
Peter Seyringer <e9425234@student.tuwien.ac.at>
for reporting a bug in saving the polarization parameter of channels that have a
diff --git a/HISTORY b/HISTORY
index 06a1a359..3140377c 100644
--- a/HISTORY
+++ b/HISTORY
@@ -6715,3 +6715,6 @@ Video Disk Recorder Revision History
exposes these members, so that existing plugins will still compile. Comment out
this #define to check whether a particular plugin needs to be modified.
This #define may be removed in a future version.
+- The new functions cRecording::NumFrames() and cRecording::LengthInSeconds() return
+ the number of frames and length (in seconds) of a recording (suggested by Steffen
+ Barszus).
diff --git a/recording.c b/recording.c
index 5112ad69..0067e6fe 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.35 2011/08/21 11:19:55 kls Exp $
+ * $Id: recording.c 2.36 2011/08/21 13:43:03 kls Exp $
*/
#include "recording.h"
@@ -60,6 +60,7 @@
#define DISKCHECKDELTA 100 // seconds between checks for free disk space
#define REMOVELATENCY 10 // seconds to wait until next check after removing a file
#define MARKSUPDATEDELTA 10 // seconds between checks for updating editing marks
+#define MININDEXAGE 3600 // seconds before an index file is considered no longer to be written
#define MAX_SUBTITLE_LENGTH 40
@@ -617,6 +618,7 @@ cRecording::cRecording(cTimer *Timer, const cEvent *Event)
instanceId = InstanceId;
isPesRecording = false;
framesPerSecond = DEFAULTFRAMESPERSECOND;
+ numFrames = -1;
deleted = 0;
// set up the actual name:
const char *Title = Event ? Event->Title() : NULL;
@@ -676,6 +678,7 @@ cRecording::cRecording(const char *FileName)
lifetime = MAXLIFETIME;
isPesRecording = false;
framesPerSecond = DEFAULTFRAMESPERSECOND;
+ numFrames = -1;
deleted = 0;
titleBuffer = NULL;
sortBuffer = NULL;
@@ -1031,6 +1034,25 @@ void cRecording::ResetResume(void) const
resume = RESUME_NOT_INITIALIZED;
}
+int cRecording::NumFrames(void) const
+{
+ if (numFrames < 0) {
+ int nf = cIndexFile::GetLength(FileName(), IsPesRecording());
+ if (time(NULL) - LastModifiedTime(FileName()) < MININDEXAGE)
+ return nf; // check again later for ongoing recordings
+ numFrames = nf;
+ }
+ return numFrames;
+}
+
+int cRecording::LengthInSeconds(void) const
+{
+ int nf = NumFrames();
+ if (nf >= 0)
+ return int((nf / FramesPerSecond() + 30) / 60) * 60;
+ return -1;
+}
+
// --- cRecordings -----------------------------------------------------------
cRecordings Recordings;
@@ -1102,6 +1124,7 @@ void cRecordings::ScanVideoDir(const char *DirName, bool Foreground, int LinkLev
if (endswith(buffer, deleted ? DELEXT : RECEXT)) {
cRecording *r = new cRecording(buffer);
if (r->Name()) {
+ r->NumFrames(); // initializes the numFrames member
Lock();
Add(r);
ChangeState();
@@ -1514,9 +1537,6 @@ void cIndexFileGenerator::Action(void)
// 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
-
struct tIndexPes {
uint32_t offset;
uchar type;
diff --git a/recording.h b/recording.h
index 26223e69..37979ec6 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.24 2011/08/21 11:34:03 kls Exp $
+ * $Id: recording.h 2.25 2011/08/21 13:10:39 kls Exp $
*/
#ifndef __RECORDING_H
@@ -89,6 +89,7 @@ private:
mutable char *fileName;
mutable char *name;
mutable int fileSizeMB;
+ mutable int numFrames;
int channel;
int instanceId;
bool isPesRecording;
@@ -123,6 +124,11 @@ public:
int HierarchyLevels(void) const;
void ResetResume(void) const;
double FramesPerSecond(void) const { return framesPerSecond; }
+ int NumFrames(void) const;
+ ///< Returns the number of frames in this recording.
+ ///< If the number of frames is unknown, -1 will be returned.
+ int LengthInSeconds(void) const;
+ ///< Returns the length (in seconds) of this recording, or -1 in case of error.
bool IsNew(void) const { return GetResume() <= 0; }
bool IsEdited(void) const;
bool IsPesRecording(void) const { return isPesRecording; }