mirror of
https://github.com/VDR4Arch/vdr.git
synced 2023-10-10 13:36:52 +02:00
Implemented static cIndexFile::IndexFileName()
This commit is contained in:
parent
67e7f93d29
commit
ef611229f3
3
HISTORY
3
HISTORY
@ -6650,7 +6650,7 @@ Video Disk Recorder Revision History
|
|||||||
- Added support for "content identifier descriptor" and "default authority descriptor"
|
- Added support for "content identifier descriptor" and "default authority descriptor"
|
||||||
to 'libsi' (thanks to Dave Pickles).
|
to 'libsi' (thanks to Dave Pickles).
|
||||||
|
|
||||||
2011-08-12: Version 1.7.20
|
2011-08-13: Version 1.7.20
|
||||||
|
|
||||||
- Added some missing 'const' to tChannelID (reported by Sundararaj Reel).
|
- Added some missing 'const' to tChannelID (reported by Sundararaj Reel).
|
||||||
- The isnumber() function now checks the given pointer for NULL (thanks to Holger
|
- The isnumber() function now checks the given pointer for NULL (thanks to Holger
|
||||||
@ -6678,3 +6678,4 @@ Video Disk Recorder Revision History
|
|||||||
case insensitive sorting (suggested by Sundararaj Reel).
|
case insensitive sorting (suggested by Sundararaj Reel).
|
||||||
- Now scanning new transponders before old ones, to make sure transponder changes
|
- Now scanning new transponders before old ones, to make sure transponder changes
|
||||||
are recognized (thanks to Reinhard Nissl).
|
are recognized (thanks to Reinhard Nissl).
|
||||||
|
- Implemented static cIndexFile::IndexFileName().
|
||||||
|
149
recording.c
149
recording.c
@ -4,7 +4,7 @@
|
|||||||
* See the main source file 'vdr.c' for copyright information and
|
* See the main source file 'vdr.c' for copyright information and
|
||||||
* how to reach the author.
|
* how to reach the author.
|
||||||
*
|
*
|
||||||
* $Id: recording.c 2.31 2011/06/12 13:04:28 kls Exp $
|
* $Id: recording.c 2.32 2011/08/13 10:59:32 kls Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "recording.h"
|
#include "recording.h"
|
||||||
@ -1540,84 +1540,75 @@ cIndexFile::cIndexFile(const char *FileName, bool Record, bool IsPesRecording)
|
|||||||
:resumeFile(FileName, IsPesRecording)
|
:resumeFile(FileName, IsPesRecording)
|
||||||
{
|
{
|
||||||
f = -1;
|
f = -1;
|
||||||
fileName = NULL;
|
|
||||||
size = 0;
|
size = 0;
|
||||||
last = -1;
|
last = -1;
|
||||||
index = NULL;
|
index = NULL;
|
||||||
isPesRecording = IsPesRecording;
|
isPesRecording = IsPesRecording;
|
||||||
indexFileGenerator = NULL;
|
indexFileGenerator = NULL;
|
||||||
if (FileName) {
|
if (FileName) {
|
||||||
const char *Suffix = isPesRecording ? INDEXFILESUFFIX ".vdr" : INDEXFILESUFFIX;
|
fileName = IndexFileName(FileName, isPesRecording);
|
||||||
fileName = MALLOC(char, strlen(FileName) + strlen(Suffix) + 1);
|
int delta = 0;
|
||||||
if (fileName) {
|
if (!Record && access(fileName, R_OK) != 0) {
|
||||||
strcpy(fileName, FileName);
|
// Index file doesn't exist, so try to regenerate it:
|
||||||
char *pFileExt = fileName + strlen(fileName);
|
if (!isPesRecording) { // sorry, can only do this for TS recordings
|
||||||
strcpy(pFileExt, Suffix);
|
resumeFile.Delete(); // just in case
|
||||||
int delta = 0;
|
indexFileGenerator = new cIndexFileGenerator(FileName);
|
||||||
if (!Record && access(fileName, R_OK) != 0) {
|
// Wait until the index file exists:
|
||||||
// Index file doesn't exist, so try to regenerate it:
|
time_t tmax = time(NULL) + MAXWAITFORINDEXFILE;
|
||||||
if (!isPesRecording) { // sorry, can only do this for TS recordings
|
do {
|
||||||
resumeFile.Delete(); // just in case
|
cCondWait::SleepMs(INDEXFILECHECKINTERVAL); // start with a sleep, to give it a head start
|
||||||
indexFileGenerator = new cIndexFileGenerator(FileName);
|
} while (access(fileName, R_OK) != 0 && time(NULL) < tmax);
|
||||||
// Wait until the index file exists:
|
|
||||||
time_t tmax = time(NULL) + MAXWAITFORINDEXFILE;
|
|
||||||
do {
|
|
||||||
cCondWait::SleepMs(INDEXFILECHECKINTERVAL); // start with a sleep, to give it a head start
|
|
||||||
} while (access(fileName, R_OK) != 0 && time(NULL) < tmax);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (access(fileName, R_OK) == 0) {
|
|
||||||
struct stat buf;
|
|
||||||
if (stat(fileName, &buf) == 0) {
|
|
||||||
delta = int(buf.st_size % sizeof(tIndexTs));
|
|
||||||
if (delta) {
|
|
||||||
delta = sizeof(tIndexTs) - delta;
|
|
||||||
esyslog("ERROR: invalid file size (%"PRId64") in '%s'", buf.st_size, fileName);
|
|
||||||
}
|
|
||||||
last = int((buf.st_size + delta) / sizeof(tIndexTs) - 1);
|
|
||||||
if (!Record && last >= 0) {
|
|
||||||
size = last + 1;
|
|
||||||
index = MALLOC(tIndexTs, size);
|
|
||||||
if (index) {
|
|
||||||
f = open(fileName, O_RDONLY);
|
|
||||||
if (f >= 0) {
|
|
||||||
if (safe_read(f, index, size_t(buf.st_size)) != buf.st_size) {
|
|
||||||
esyslog("ERROR: can't read from file '%s'", fileName);
|
|
||||||
free(index);
|
|
||||||
index = NULL;
|
|
||||||
close(f);
|
|
||||||
f = -1;
|
|
||||||
}
|
|
||||||
// we don't close f here, see CatchUp()!
|
|
||||||
else if (isPesRecording)
|
|
||||||
ConvertFromPes(index, size);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
LOG_ERROR_STR(fileName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
esyslog("ERROR: can't allocate %zd bytes for index '%s'", size * sizeof(tIndexTs), fileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
LOG_ERROR;
|
|
||||||
}
|
|
||||||
else if (!Record)
|
|
||||||
isyslog("missing index file %s", fileName);
|
|
||||||
if (Record) {
|
|
||||||
if ((f = open(fileName, O_WRONLY | O_CREAT | O_APPEND, DEFFILEMODE)) >= 0) {
|
|
||||||
if (delta) {
|
|
||||||
esyslog("ERROR: padding index file with %d '0' bytes", delta);
|
|
||||||
while (delta--)
|
|
||||||
writechar(f, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
LOG_ERROR_STR(fileName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
if (access(fileName, R_OK) == 0) {
|
||||||
esyslog("ERROR: can't copy file name '%s'", FileName);
|
struct stat buf;
|
||||||
|
if (stat(fileName, &buf) == 0) {
|
||||||
|
delta = int(buf.st_size % sizeof(tIndexTs));
|
||||||
|
if (delta) {
|
||||||
|
delta = sizeof(tIndexTs) - delta;
|
||||||
|
esyslog("ERROR: invalid file size (%"PRId64") in '%s'", buf.st_size, *fileName);
|
||||||
|
}
|
||||||
|
last = int((buf.st_size + delta) / sizeof(tIndexTs) - 1);
|
||||||
|
if (!Record && last >= 0) {
|
||||||
|
size = last + 1;
|
||||||
|
index = MALLOC(tIndexTs, size);
|
||||||
|
if (index) {
|
||||||
|
f = open(fileName, O_RDONLY);
|
||||||
|
if (f >= 0) {
|
||||||
|
if (safe_read(f, index, size_t(buf.st_size)) != buf.st_size) {
|
||||||
|
esyslog("ERROR: can't read from file '%s'", *fileName);
|
||||||
|
free(index);
|
||||||
|
index = NULL;
|
||||||
|
close(f);
|
||||||
|
f = -1;
|
||||||
|
}
|
||||||
|
// we don't close f here, see CatchUp()!
|
||||||
|
else if (isPesRecording)
|
||||||
|
ConvertFromPes(index, size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LOG_ERROR_STR(*fileName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
esyslog("ERROR: can't allocate %zd bytes for index '%s'", size * sizeof(tIndexTs), *fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LOG_ERROR;
|
||||||
|
}
|
||||||
|
else if (!Record)
|
||||||
|
isyslog("missing index file %s", *fileName);
|
||||||
|
if (Record) {
|
||||||
|
if ((f = open(fileName, O_WRONLY | O_CREAT | O_APPEND, DEFFILEMODE)) >= 0) {
|
||||||
|
if (delta) {
|
||||||
|
esyslog("ERROR: padding index file with %d '0' bytes", delta);
|
||||||
|
while (delta--)
|
||||||
|
writechar(f, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LOG_ERROR_STR(*fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1625,11 +1616,15 @@ cIndexFile::~cIndexFile()
|
|||||||
{
|
{
|
||||||
if (f >= 0)
|
if (f >= 0)
|
||||||
close(f);
|
close(f);
|
||||||
free(fileName);
|
|
||||||
free(index);
|
free(index);
|
||||||
delete indexFileGenerator;
|
delete indexFileGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cString cIndexFile::IndexFileName(const char *FileName, bool IsPesRecording)
|
||||||
|
{
|
||||||
|
return cString::sprintf("%s%s", FileName, IsPesRecording ? INDEXFILESUFFIX ".vdr" : INDEXFILESUFFIX);
|
||||||
|
}
|
||||||
|
|
||||||
void cIndexFile::ConvertFromPes(tIndexTs *IndexTs, int Count)
|
void cIndexFile::ConvertFromPes(tIndexTs *IndexTs, int Count)
|
||||||
{
|
{
|
||||||
tIndexPes IndexPes;
|
tIndexPes IndexPes;
|
||||||
@ -1696,7 +1691,7 @@ bool cIndexFile::CatchUp(int Index)
|
|||||||
last = newLast;
|
last = newLast;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LOG_ERROR_STR(fileName);
|
LOG_ERROR_STR(*fileName);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
esyslog("ERROR: can't realloc() index");
|
esyslog("ERROR: can't realloc() index");
|
||||||
@ -1705,7 +1700,7 @@ bool cIndexFile::CatchUp(int Index)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LOG_ERROR_STR(fileName);
|
LOG_ERROR_STR(*fileName);
|
||||||
if (Index < last - (i ? 2 * INDEXSAFETYLIMIT : 0) || Index > 10 * INDEXSAFETYLIMIT) // keep off the end in case of "Pause live video"
|
if (Index < last - (i ? 2 * INDEXSAFETYLIMIT : 0) || Index > 10 * INDEXSAFETYLIMIT) // keep off the end in case of "Pause live video"
|
||||||
break;
|
break;
|
||||||
cCondWait::SleepMs(1000);
|
cCondWait::SleepMs(1000);
|
||||||
@ -1721,7 +1716,7 @@ bool cIndexFile::Write(bool Independent, uint16_t FileNumber, off_t FileOffset)
|
|||||||
if (isPesRecording)
|
if (isPesRecording)
|
||||||
ConvertToPes(&i, 1);
|
ConvertToPes(&i, 1);
|
||||||
if (safe_write(f, &i, sizeof(i)) < 0) {
|
if (safe_write(f, &i, sizeof(i)) < 0) {
|
||||||
LOG_ERROR_STR(fileName);
|
LOG_ERROR_STR(*fileName);
|
||||||
close(f);
|
close(f);
|
||||||
f = -1;
|
f = -1;
|
||||||
return false;
|
return false;
|
||||||
@ -1811,8 +1806,8 @@ bool cIndexFile::IsStillRecording()
|
|||||||
|
|
||||||
void cIndexFile::Delete(void)
|
void cIndexFile::Delete(void)
|
||||||
{
|
{
|
||||||
if (fileName) {
|
if (*fileName) {
|
||||||
dsyslog("deleting index file '%s'", fileName);
|
dsyslog("deleting index file '%s'", *fileName);
|
||||||
if (f >= 0) {
|
if (f >= 0) {
|
||||||
close(f);
|
close(f);
|
||||||
f = -1;
|
f = -1;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* See the main source file 'vdr.c' for copyright information and
|
* See the main source file 'vdr.c' for copyright information and
|
||||||
* how to reach the author.
|
* how to reach the author.
|
||||||
*
|
*
|
||||||
* $Id: recording.h 2.19 2011/04/17 13:18:04 kls Exp $
|
* $Id: recording.h 2.20 2011/08/13 09:52:25 kls Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __RECORDING_H
|
#ifndef __RECORDING_H
|
||||||
@ -236,13 +236,14 @@ class cIndexFileGenerator;
|
|||||||
class cIndexFile {
|
class cIndexFile {
|
||||||
private:
|
private:
|
||||||
int f;
|
int f;
|
||||||
char *fileName;
|
cString fileName;
|
||||||
int size, last;
|
int size, last;
|
||||||
tIndexTs *index;
|
tIndexTs *index;
|
||||||
bool isPesRecording;
|
bool isPesRecording;
|
||||||
cResumeFile resumeFile;
|
cResumeFile resumeFile;
|
||||||
cIndexFileGenerator *indexFileGenerator;
|
cIndexFileGenerator *indexFileGenerator;
|
||||||
cMutex mutex;
|
cMutex mutex;
|
||||||
|
static cString IndexFileName(const char *FileName, bool IsPesRecording);
|
||||||
void ConvertFromPes(tIndexTs *IndexTs, int Count);
|
void ConvertFromPes(tIndexTs *IndexTs, int Count);
|
||||||
void ConvertToPes(tIndexTs *IndexTs, int Count);
|
void ConvertToPes(tIndexTs *IndexTs, int Count);
|
||||||
bool CatchUp(int Index = -1);
|
bool CatchUp(int Index = -1);
|
||||||
|
Loading…
Reference in New Issue
Block a user