mirror of
https://github.com/vdr-projects/vdr.git
synced 2025-03-01 10:50:46 +00:00
VDR developer version 2.1.5 is now available at ftp://ftp.tvdr.de/vdr/Developer/vdr-2.1.5.tar.bz2 A 'diff' against the previous version is available at ftp://ftp.tvdr.de/vdr/Developer/vdr-2.1.4-2.1.5.diff MD5 checksums: ce561eef64c13e24e4817f70a6d9d5b0 vdr-2.1.5.tar.bz2 f433e78d90bc414bd9d858ca6e58e539 vdr-2.1.4-2.1.5.diff WARNING: ======== This is a *developer* version. Even though *I* use it in my productive environment, I strongly recommend that you only use it under controlled conditions and for testing and debugging. From the HISTORY file: - Now checking whether the primary device actually has a decoder before retuning the current channel after a change in its parameters. This fixes broken recordings on the primary device on "headless" systems. - Increased MIN_TS_PACKETS_FOR_FRAME_DETECTOR to 100 and introduced counting the number of actual video TS packets in cTsPayload in order to be able to record channels that sometimes need even more than 10 TS packets for detecting frame borders (reported by Oliver Endriss). - Fixed sorting recordings by time in the Recordings menu if "Setup/OSD/Recording directories" is set to "no". - Fixed clearing non-editable members in the channel editor (thanks to Rolf Ahrenberg). - Updated the Estonian OSD texts (thanks to Arthur Konovalov). - Further clarified the semantics of cCamSlot::Decrypt(). - Fixed flickering if subtitles are active while the OSD demo is running. - Fixed numbering frames. Previously they were numbered starting from 1, while it is apparently standard to number them from 0. Any existing recordings with editing marks (which will now be off by one) can still be cut with all VDR versions from 1.7.32, because these will automatically adjust editing marks to I-frames. Users of stable releases shouldn't notice any problems. - Fixed a possible crash in the OSD demo (reported by Christopher Reimer). - Fixed some compiler warnings with Clang 3.4.1 (reported by Paul Menzel). - Added LinkageTypePremiere to libsi/si.h and eit.c to avoid a compiler warning with Clang 3.4.1 (suggested by Tony Houghten). - Replaced the NULL pointer assignment in ~cReceiver() to force a segfault with a call to abort() (suggested by Tony Houghten). - Fixed learning keyboard remote control codes (thanks to Lars Hanisch). - Improved PAT/PMT scanning to speed up initial tuning to encrypted channels on transponders with many PAT entries (reported by Mariusz Bialonczyk). - Fixed the replay progress display for very long recordings. - Fixed detecting broken video data streams when recording. - Fixed handling frame detection buffer length (reported by Eike Sauer).
177 lines
5.6 KiB
C
177 lines
5.6 KiB
C
/*
|
|
* recorder.c: The actual DVB recorder
|
|
*
|
|
* See the main source file 'vdr.c' for copyright information and
|
|
* how to reach the author.
|
|
*
|
|
* $Id: recorder.c 3.3 2014/02/21 09:19:52 kls Exp $
|
|
*/
|
|
|
|
#include "recorder.h"
|
|
#include "shutdown.h"
|
|
|
|
#define RECORDERBUFSIZE (MEGABYTE(20) / TS_SIZE * TS_SIZE) // multiple of TS_SIZE
|
|
|
|
// The maximum time we wait before assuming that a recorded video data stream
|
|
// is broken:
|
|
#define MAXBROKENTIMEOUT 30000 // milliseconds
|
|
|
|
#define MINFREEDISKSPACE (512) // MB
|
|
#define DISKCHECKINTERVAL 100 // seconds
|
|
|
|
// --- cRecorder -------------------------------------------------------------
|
|
|
|
cRecorder::cRecorder(const char *FileName, const cChannel *Channel, int Priority)
|
|
:cReceiver(Channel, Priority)
|
|
,cThread("recording")
|
|
{
|
|
recordingName = strdup(FileName);
|
|
|
|
// Make sure the disk is up and running:
|
|
|
|
SpinUpDisk(FileName);
|
|
|
|
ringBuffer = new cRingBufferLinear(RECORDERBUFSIZE, MIN_TS_PACKETS_FOR_FRAME_DETECTOR * TS_SIZE, true, "Recorder");
|
|
ringBuffer->SetTimeouts(0, 100);
|
|
ringBuffer->SetIoThrottle();
|
|
|
|
int Pid = Channel->Vpid();
|
|
int Type = Channel->Vtype();
|
|
if (!Pid && Channel->Apid(0)) {
|
|
Pid = Channel->Apid(0);
|
|
Type = 0x04;
|
|
}
|
|
if (!Pid && Channel->Dpid(0)) {
|
|
Pid = Channel->Dpid(0);
|
|
Type = 0x06;
|
|
}
|
|
frameDetector = new cFrameDetector(Pid, Type);
|
|
index = NULL;
|
|
fileSize = 0;
|
|
lastDiskSpaceCheck = time(NULL);
|
|
fileName = new cFileName(FileName, true);
|
|
int PatVersion, PmtVersion;
|
|
if (fileName->GetLastPatPmtVersions(PatVersion, PmtVersion))
|
|
patPmtGenerator.SetVersions(PatVersion + 1, PmtVersion + 1);
|
|
patPmtGenerator.SetChannel(Channel);
|
|
recordFile = fileName->Open();
|
|
if (!recordFile)
|
|
return;
|
|
// Create the index file:
|
|
index = new cIndexFile(FileName, true);
|
|
if (!index)
|
|
esyslog("ERROR: can't allocate index");
|
|
// let's continue without index, so we'll at least have the recording
|
|
}
|
|
|
|
cRecorder::~cRecorder()
|
|
{
|
|
Detach();
|
|
delete index;
|
|
delete fileName;
|
|
delete frameDetector;
|
|
delete ringBuffer;
|
|
free(recordingName);
|
|
}
|
|
|
|
bool cRecorder::RunningLowOnDiskSpace(void)
|
|
{
|
|
if (time(NULL) > lastDiskSpaceCheck + DISKCHECKINTERVAL) {
|
|
int Free = FreeDiskSpaceMB(fileName->Name());
|
|
lastDiskSpaceCheck = time(NULL);
|
|
if (Free < MINFREEDISKSPACE) {
|
|
dsyslog("low disk space (%d MB, limit is %d MB)", Free, MINFREEDISKSPACE);
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool cRecorder::NextFile(void)
|
|
{
|
|
if (recordFile && frameDetector->IndependentFrame()) { // every file shall start with an independent frame
|
|
if (fileSize > MEGABYTE(off_t(Setup.MaxVideoFileSize)) || RunningLowOnDiskSpace()) {
|
|
recordFile = fileName->NextFile();
|
|
fileSize = 0;
|
|
}
|
|
}
|
|
return recordFile != NULL;
|
|
}
|
|
|
|
void cRecorder::Activate(bool On)
|
|
{
|
|
if (On)
|
|
Start();
|
|
else
|
|
Cancel(3);
|
|
}
|
|
|
|
void cRecorder::Receive(uchar *Data, int Length)
|
|
{
|
|
if (Running()) {
|
|
int p = ringBuffer->Put(Data, Length);
|
|
if (p != Length && Running())
|
|
ringBuffer->ReportOverflow(Length - p);
|
|
}
|
|
}
|
|
|
|
void cRecorder::Action(void)
|
|
{
|
|
cTimeMs t(MAXBROKENTIMEOUT);
|
|
bool InfoWritten = false;
|
|
bool FirstIframeSeen = false;
|
|
while (Running()) {
|
|
int r;
|
|
uchar *b = ringBuffer->Get(r);
|
|
if (b) {
|
|
int Count = frameDetector->Analyze(b, r);
|
|
if (Count) {
|
|
if (!Running() && frameDetector->IndependentFrame()) // finish the recording before the next independent frame
|
|
break;
|
|
if (frameDetector->Synced()) {
|
|
if (!InfoWritten) {
|
|
cRecordingInfo RecordingInfo(recordingName);
|
|
if (RecordingInfo.Read()) {
|
|
if (frameDetector->FramesPerSecond() > 0 && DoubleEqual(RecordingInfo.FramesPerSecond(), DEFAULTFRAMESPERSECOND) && !DoubleEqual(RecordingInfo.FramesPerSecond(), frameDetector->FramesPerSecond())) {
|
|
RecordingInfo.SetFramesPerSecond(frameDetector->FramesPerSecond());
|
|
RecordingInfo.Write();
|
|
Recordings.UpdateByName(recordingName);
|
|
}
|
|
}
|
|
InfoWritten = true;
|
|
cRecordingUserCommand::InvokeCommand(RUC_STARTRECORDING, recordingName);
|
|
}
|
|
if (FirstIframeSeen || frameDetector->IndependentFrame()) {
|
|
FirstIframeSeen = true; // start recording with the first I-frame
|
|
if (!NextFile())
|
|
break;
|
|
if (index && frameDetector->NewFrame())
|
|
index->Write(frameDetector->IndependentFrame(), fileName->Number(), fileSize);
|
|
if (frameDetector->IndependentFrame()) {
|
|
recordFile->Write(patPmtGenerator.GetPat(), TS_SIZE);
|
|
fileSize += TS_SIZE;
|
|
int Index = 0;
|
|
while (uchar *pmt = patPmtGenerator.GetPmt(Index)) {
|
|
recordFile->Write(pmt, TS_SIZE);
|
|
fileSize += TS_SIZE;
|
|
}
|
|
t.Set(MAXBROKENTIMEOUT);
|
|
}
|
|
if (recordFile->Write(b, Count) < 0) {
|
|
LOG_ERROR_STR(fileName->Name());
|
|
break;
|
|
}
|
|
fileSize += Count;
|
|
}
|
|
}
|
|
ringBuffer->Del(Count);
|
|
}
|
|
}
|
|
if (t.TimedOut()) {
|
|
esyslog("ERROR: video data stream broken");
|
|
ShutdownHandler.RequestEmergencyExit();
|
|
t.Set(MAXBROKENTIMEOUT);
|
|
}
|
|
}
|
|
}
|