summaryrefslogtreecommitdiff
path: root/recording.c
diff options
context:
space:
mode:
Diffstat (limited to 'recording.c')
-rw-r--r--recording.c109
1 files changed, 79 insertions, 30 deletions
diff --git a/recording.c b/recording.c
index 96dc95f..02a6e61 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.23 2010/03/07 14:06:04 kls Exp $
+ * $Id: recording.c 2.26 2011/02/27 13:35:20 kls Exp $
*/
#include "recording.h"
@@ -57,6 +57,7 @@
#define DELETEDLIFETIME 300 // seconds after which a deleted recording will be actually removed
#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 MAX_SUBTITLE_LENGTH 40
@@ -548,13 +549,17 @@ char *ExchangeChars(char *s, bool ToFileSystem)
default:
if (strchr(InvalidChars, *p) || *p == '.' && (!*(p + 1) || *(p + 1) == FOLDERDELIMCHAR)) { // Windows can't handle '.' at the end of file/directory names
int l = p - s;
- s = (char *)realloc(s, strlen(s) + 10);
- p = s + l;
- char buf[4];
- sprintf(buf, "#%02X", (unsigned char)*p);
- memmove(p + 2, p, strlen(p) + 1);
- strncpy(p, buf, 3);
- p += 2;
+ if (char *NewBuffer = (char *)realloc(s, strlen(s) + 10)) {
+ s = NewBuffer;
+ p = s + l;
+ char buf[4];
+ sprintf(buf, "#%02X", (unsigned char)*p);
+ memmove(p + 2, p, strlen(p) + 1);
+ strncpy(p, buf, 3);
+ p += 2;
+ }
+ else
+ esyslog("ERROR: out of memory");
}
}
}
@@ -678,7 +683,7 @@ cRecording::cRecording(const char *FileName)
const char *p = strrchr(FileName, '/');
name = NULL;
- info = new cRecordingInfo;
+ info = new cRecordingInfo(fileName);
if (p) {
time_t now = time(NULL);
struct tm tm_r;
@@ -729,9 +734,13 @@ cRecording::cRecording(const char *FileName)
if (data[line]) {
int len = strlen(s);
len += strlen(data[line]) + 1;
- data[line] = (char *)realloc(data[line], len + 1);
- strcat(data[line], "\n");
- strcat(data[line], s);
+ if (char *NewBuffer = (char *)realloc(data[line], len + 1)) {
+ data[line] = NewBuffer;
+ strcat(data[line], "\n");
+ strcat(data[line], s);
+ }
+ else
+ esyslog("ERROR: out of memory");
}
else
data[line] = strdup(s);
@@ -750,12 +759,16 @@ cRecording::cRecording(const char *FileName)
// line 1 and line 2 to be the long text:
int len = strlen(data[1]);
if (len > 80) {
- data[1] = (char *)realloc(data[1], len + 1 + strlen(data[2]) + 1);
- strcat(data[1], "\n");
- strcat(data[1], data[2]);
- free(data[2]);
- data[2] = data[1];
- data[1] = NULL;
+ if (char *NewBuffer = (char *)realloc(data[1], len + 1 + strlen(data[2]) + 1)) {
+ data[1] = NewBuffer;
+ strcat(data[1], "\n");
+ strcat(data[1], data[2]);
+ free(data[2]);
+ data[2] = data[1];
+ data[1] = NULL;
+ }
+ else
+ esyslog("ERROR: out of memory");
}
}
info->SetData(data[0], data[1], data[2]);
@@ -921,6 +934,14 @@ bool cRecording::IsEdited(void) const
return *s == '%';
}
+void cRecording::ReadInfo(void)
+{
+ info->Read();
+ priority = info->priority;
+ lifetime = info->lifetime;
+ framesPerSecond = info->framesPerSecond;
+}
+
bool cRecording::WriteInfo(void)
{
cString InfoFileName = cString::sprintf("%s%s", fileName, isPesRecording ? INFOFILESUFFIX ".vdr" : INFOFILESUFFIX);
@@ -1172,6 +1193,14 @@ void cRecordings::DelByName(const char *FileName)
}
}
+void cRecordings::UpdateByName(const char *FileName)
+{
+ LOCK_THREAD;
+ cRecording *recording = GetByName(FileName);
+ if (recording)
+ recording->ReadInfo();
+}
+
int cRecordings::TotalFileSizeMB(void)
{
int size = 0;
@@ -1239,12 +1268,28 @@ bool cMark::Save(FILE *f)
bool cMarks::Load(const char *RecordingFileName, double FramesPerSecond, bool IsPesRecording)
{
- cMutexLock MutexLock(&MutexMarkFramesPerSecond);
+ fileName = AddDirectory(RecordingFileName, IsPesRecording ? MARKSFILESUFFIX ".vdr" : MARKSFILESUFFIX);
framesPerSecond = FramesPerSecond;
- MarkFramesPerSecond = framesPerSecond;
- if (cConfig<cMark>::Load(AddDirectory(RecordingFileName, IsPesRecording ? MARKSFILESUFFIX ".vdr" : MARKSFILESUFFIX))) {
- Sort();
- return true;
+ lastUpdate = 0;
+ lastFileTime = -1; // the first call to Load() must take place!
+ 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;
+ cMutexLock MutexLock(&MutexMarkFramesPerSecond);
+ MarkFramesPerSecond = framesPerSecond;
+ if (cConfig<cMark>::Load(fileName)) {
+ Sort();
+ return true;
+ }
+ }
}
return false;
}
@@ -1604,13 +1649,15 @@ bool cIndexFile::CatchUp(int Index)
}
int newLast = int(buf.st_size / sizeof(tIndexTs) - 1);
if (newLast > last) {
- if (size <= newLast) {
- size *= 2;
- if (size <= newLast)
- size = newLast + 1;
+ int NewSize = size;
+ if (NewSize <= newLast) {
+ NewSize *= 2;
+ if (NewSize <= newLast)
+ NewSize = newLast + 1;
}
- index = (tIndexTs *)realloc(index, size * sizeof(tIndexTs));
- if (index) {
+ if (tIndexTs *NewBuffer = (tIndexTs *)realloc(index, NewSize * sizeof(tIndexTs))) {
+ size = NewSize;
+ index = NewBuffer;
int offset = (last + 1) * sizeof(tIndexTs);
int delta = (newLast - last) * sizeof(tIndexTs);
if (lseek(f, offset, SEEK_SET) == offset) {
@@ -1629,8 +1676,10 @@ bool cIndexFile::CatchUp(int Index)
else
LOG_ERROR_STR(fileName);
}
- else
+ else {
esyslog("ERROR: can't realloc() index");
+ break;
+ }
}
}
else