summaryrefslogtreecommitdiff
path: root/recording.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2015-01-17 15:03:01 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2015-01-17 15:03:01 +0100
commit0c2316b638020f4087a664525f9ce7004d506488 (patch)
tree350d8a043bc05e2ef0aebc054dfbd64b9f7583b2 /recording.c
parentf42cbac2375bfa320f9acdf87f80bc2fd70fed36 (diff)
downloadvdr-0c2316b638020f4087a664525f9ce7004d506488.tar.gz
vdr-0c2316b638020f4087a664525f9ce7004d506488.tar.bz2
Added the new command line option --updindex
Diffstat (limited to 'recording.c')
-rw-r--r--recording.c44
1 files changed, 33 insertions, 11 deletions
diff --git a/recording.c b/recording.c
index 669e8ffa..e9a6b169 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 3.20 2015/01/17 13:47:33 kls Exp $
+ * $Id: recording.c 3.21 2015/01/17 14:52:28 kls Exp $
*/
#include "recording.h"
@@ -2241,17 +2241,19 @@ void cRecordingUserCommand::InvokeCommand(const char *State, const char *Recordi
class cIndexFileGenerator : public cThread {
private:
cString recordingName;
+ bool update;
protected:
virtual void Action(void);
public:
- cIndexFileGenerator(const char *RecordingName);
+ cIndexFileGenerator(const char *RecordingName, bool Update = false);
~cIndexFileGenerator();
};
-cIndexFileGenerator::cIndexFileGenerator(const char *RecordingName)
+cIndexFileGenerator::cIndexFileGenerator(const char *RecordingName, bool Update)
:cThread("index file generator")
,recordingName(RecordingName)
{
+ update = Update;
Start();
}
@@ -2270,16 +2272,34 @@ void cIndexFileGenerator::Action(void)
cRingBufferLinear Buffer(IFG_BUFFER_SIZE, MIN_TS_PACKETS_FOR_FRAME_DETECTOR * TS_SIZE);
cPatPmtParser PatPmtParser;
cFrameDetector FrameDetector;
- cIndexFile IndexFile(recordingName, true);
+ cIndexFile IndexFile(recordingName, true, false, false, true);
int BufferChunks = KILOBYTE(1); // no need to read a lot at the beginning when parsing PAT/PMT
off_t FileSize = 0;
off_t FrameOffset = -1;
+ uint16_t FileNumber = 1;
+ off_t FileOffset = 0;
+ int Last = -1;
+ if (update) {
+ // Look for current index and position to end of it if present:
+ bool Independent;
+ int Length;
+ Last = IndexFile.Last();
+ if (Last >= 0 && !IndexFile.Get(Last, &FileNumber, &FileOffset, &Independent, &Length))
+ Last = -1; // reset Last if an error occurred
+ if (Last >= 0) {
+ Rewind = true;
+ isyslog("updating index file");
+ }
+ else
+ isyslog("generating index file");
+ }
Skins.QueueMessage(mtInfo, tr("Regenerating index file"));
bool Stuffed = false;
while (Running()) {
// Rewind input file:
if (Rewind) {
- ReplayFile = FileName.SetOffset(1);
+ ReplayFile = FileName.SetOffset(FileNumber, FileOffset);
+ FileSize = FileOffset;
Buffer.Clear();
Rewind = false;
}
@@ -2294,7 +2314,8 @@ void cIndexFileGenerator::Action(void)
int Processed = FrameDetector.Analyze(Data, Length);
if (Processed > 0) {
if (FrameDetector.NewFrame()) {
- IndexFile.Write(FrameDetector.IndependentFrame(), FileName.Number(), FrameOffset >= 0 ? FrameOffset : FileSize);
+ if (IndexFileWritten || Last < 0) // check for first frame and do not write if in update mode
+ IndexFile.Write(FrameDetector.IndependentFrame(), FileName.Number(), FrameOffset >= 0 ? FrameOffset : FileSize);
FrameOffset = -1;
IndexFileWritten = true;
}
@@ -2419,7 +2440,7 @@ struct tIndexTs {
#define INDEXFILECHECKINTERVAL 500 // ms between checks for existence of the regenerated index file
#define INDEXFILETESTINTERVAL 10 // ms between tests for the size of the index file in case of pausing live video
-cIndexFile::cIndexFile(const char *FileName, bool Record, bool IsPesRecording, bool PauseLive)
+cIndexFile::cIndexFile(const char *FileName, bool Record, bool IsPesRecording, bool PauseLive, bool Update)
:resumeFile(FileName, IsPesRecording)
{
f = -1;
@@ -2458,7 +2479,7 @@ cIndexFile::cIndexFile(const char *FileName, bool Record, bool IsPesRecording, b
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) {
+ if ((!Record || Update) && last >= 0) {
size = last + 1;
index = MALLOC(tIndexTs, size);
if (index) {
@@ -2746,15 +2767,16 @@ int cIndexFile::GetLength(const char *FileName, bool IsPesRecording)
return -1;
}
-bool GenerateIndex(const char *FileName)
+bool GenerateIndex(const char *FileName, bool Update)
{
if (DirectoryOk(FileName)) {
cRecording Recording(FileName);
if (Recording.Name()) {
if (!Recording.IsPesRecording()) {
cString IndexFileName = AddDirectory(FileName, INDEXFILESUFFIX);
- unlink(IndexFileName);
- cIndexFileGenerator *IndexFileGenerator = new cIndexFileGenerator(FileName);
+ if (!Update)
+ unlink(IndexFileName);
+ cIndexFileGenerator *IndexFileGenerator = new cIndexFileGenerator(FileName, Update);
while (IndexFileGenerator->Active())
cCondWait::SleepMs(INDEXFILECHECKINTERVAL);
if (access(IndexFileName, R_OK) == 0)