Implemented cRecording::NumFrames() and cRecording::LengthInSeconds()

This commit is contained in:
Klaus Schmidinger 2011-08-21 13:47:07 +02:00
parent 97ad2fa95d
commit dac837d38d
4 changed files with 35 additions and 5 deletions

View File

@ -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

View File

@ -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).

View File

@ -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;

View File

@ -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; }