mirror of
https://github.com/vdr-projects/vdr.git
synced 2025-03-01 10:50:46 +00:00
Original announce message:
VDR developer version 1.7.21 is now available at
ftp://ftp.tvdr.de/vdr/Developer/vdr-1.7.21.tar.bz2
A 'diff' against the previous version is available at
ftp://ftp.tvdr.de/vdr/Developer/vdr-1.7.20-1.7.21.diff
MD5 checksums:
7300bfd997db1a848bd774fefe4aec80 vdr-1.7.21.tar.bz2
c4e745939f31543dd607b97d58fc86be vdr-1.7.20-1.7.21.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.
This version contains functions to determine the "signal strength"
and "signal quality" through cDevice. If you are using a DVB card that
contains an stb0899 frontend chip (like the TT-budget S2-3200) you may
want to apply the patches from
ftp://ftp.tvdr.de/vdr/Developer/Driver-Patches
to the LinuxDVB driver source in order to receive useful results from
that frontend.
From the HISTORY file:
- Fixed detecting frames for channels that split frames into several payloads
(reported by Derek Kelly).
- Now initializing Setup.InitialChannel to an empty string to avoid problems in
case there is no setup.conf.
- The start time of an edited recording is now set to the time of the first
editing mark (thanks to Udo Richter).
This obsoletes the CUTTIME patch.
- Direct access to the members start, priority, lifetime, and deleted of cRecording
as well as to position and comment of cMark is now deprecated. Plugin authors
should switch to the new access functions for these members. For now the macro
__RECORDING_H_DEPRECATED_DIRECT_MEMBER_ACCESS is defined in recording.h, which
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).
- The subtitle PIDs are now stored in the channels.conf file as an extension to the
TPID field (thanks to Rolf Ahrenberg).
- The new function cDevice::ProvidesEIT() is used to determine whether a device can
provide EIT data and will thus be used in cEITScanner::Process() to receive EIT
data from the channels it can receive (suggested by Rolf Ahrenberg). Note that by
default it is assumed that a device can't provide EIT data, and only the builtin
cDvbDevice returns true from this function.
- The Audio and Subtitles options are now available through the Green and Yellow
keys in the Setup/DVB menu (thanks to Rolf Ahrenberg). This is mainly for remote
controls that don't have dedicated keys for these functions.
- The SVDRP command HITK now accepts multiple keys (up to 31).
- The Recordings menu now displays the length (in hours:minutes) of each recording
(thanks to Rolf Ahrenberg). Note that the "new" indicator has been moved from the
recording time to the length column. This new format is also used by the SVDRP
command LSTR, so in case you have an application that parses the LSTR output,
you will need to adjust it to the new format.
- The dvbsddevice plugin now supports the new option --outputonly, which disables
receiving on SD FF devices and uses the device only for output (thanks to Udo
Richter).
- Fixed detecting frames on radio channels (reported by Chris Mayo).
- Revoked the changes to cFrameDetector that have been introduced in version 1.7.19.
Detecting frames in case the Picture Start Code or Access Unit Delimiter
extends over TS packet boundaries is now done by locally skipping TS packets
in cFrameDetector.
318 lines
9.5 KiB
C
318 lines
9.5 KiB
C
/*
|
|
* cutter.c: The video cutting facilities
|
|
*
|
|
* See the main source file 'vdr.c' for copyright information and
|
|
* how to reach the author.
|
|
*
|
|
* $Id: cutter.c 2.8 2011/08/21 11:08:08 kls Exp $
|
|
*/
|
|
|
|
#include "cutter.h"
|
|
#include "recording.h"
|
|
#include "remux.h"
|
|
#include "videodir.h"
|
|
|
|
// --- cCuttingThread --------------------------------------------------------
|
|
|
|
class cCuttingThread : public cThread {
|
|
private:
|
|
const char *error;
|
|
bool isPesRecording;
|
|
cUnbufferedFile *fromFile, *toFile;
|
|
cFileName *fromFileName, *toFileName;
|
|
cIndexFile *fromIndex, *toIndex;
|
|
cMarks fromMarks, toMarks;
|
|
off_t maxVideoFileSize;
|
|
protected:
|
|
virtual void Action(void);
|
|
public:
|
|
cCuttingThread(const char *FromFileName, const char *ToFileName);
|
|
virtual ~cCuttingThread();
|
|
const char *Error(void) { return error; }
|
|
};
|
|
|
|
cCuttingThread::cCuttingThread(const char *FromFileName, const char *ToFileName)
|
|
:cThread("video cutting")
|
|
{
|
|
error = NULL;
|
|
fromFile = toFile = NULL;
|
|
fromFileName = toFileName = NULL;
|
|
fromIndex = toIndex = NULL;
|
|
cRecording Recording(FromFileName);
|
|
isPesRecording = Recording.IsPesRecording();
|
|
if (fromMarks.Load(FromFileName, Recording.FramesPerSecond(), isPesRecording) && fromMarks.Count()) {
|
|
fromFileName = new cFileName(FromFileName, false, true, isPesRecording);
|
|
toFileName = new cFileName(ToFileName, true, true, isPesRecording);
|
|
fromIndex = new cIndexFile(FromFileName, false, isPesRecording);
|
|
toIndex = new cIndexFile(ToFileName, true, isPesRecording);
|
|
toMarks.Load(ToFileName, Recording.FramesPerSecond(), isPesRecording); // doesn't actually load marks, just sets the file name
|
|
maxVideoFileSize = MEGABYTE(Setup.MaxVideoFileSize);
|
|
if (isPesRecording && maxVideoFileSize > MEGABYTE(MAXVIDEOFILESIZEPES))
|
|
maxVideoFileSize = MEGABYTE(MAXVIDEOFILESIZEPES);
|
|
Start();
|
|
}
|
|
else
|
|
esyslog("no editing marks found for %s", FromFileName);
|
|
}
|
|
|
|
cCuttingThread::~cCuttingThread()
|
|
{
|
|
Cancel(3);
|
|
delete fromFileName;
|
|
delete toFileName;
|
|
delete fromIndex;
|
|
delete toIndex;
|
|
}
|
|
|
|
void cCuttingThread::Action(void)
|
|
{
|
|
cMark *Mark = fromMarks.First();
|
|
if (Mark) {
|
|
SetPriority(19);
|
|
SetIOPriority(7);
|
|
fromFile = fromFileName->Open();
|
|
toFile = toFileName->Open();
|
|
if (!fromFile || !toFile)
|
|
return;
|
|
fromFile->SetReadAhead(MEGABYTE(20));
|
|
int Index = Mark->Position();
|
|
Mark = fromMarks.Next(Mark);
|
|
off_t FileSize = 0;
|
|
int CurrentFileNumber = 0;
|
|
int LastIFrame = 0;
|
|
toMarks.Add(0);
|
|
toMarks.Save();
|
|
uchar buffer[MAXFRAMESIZE];
|
|
bool LastMark = false;
|
|
bool cutIn = true;
|
|
while (Running()) {
|
|
uint16_t FileNumber;
|
|
off_t FileOffset;
|
|
int Length;
|
|
bool Independent;
|
|
|
|
// Make sure there is enough disk space:
|
|
|
|
AssertFreeDiskSpace(-1);
|
|
|
|
// Read one frame:
|
|
|
|
if (fromIndex->Get(Index++, &FileNumber, &FileOffset, &Independent, &Length)) {
|
|
if (FileNumber != CurrentFileNumber) {
|
|
fromFile = fromFileName->SetOffset(FileNumber, FileOffset);
|
|
fromFile->SetReadAhead(MEGABYTE(20));
|
|
CurrentFileNumber = FileNumber;
|
|
}
|
|
if (fromFile) {
|
|
int len = ReadFrame(fromFile, buffer, Length, sizeof(buffer));
|
|
if (len < 0) {
|
|
error = "ReadFrame";
|
|
break;
|
|
}
|
|
if (len != Length) {
|
|
CurrentFileNumber = 0; // this re-syncs in case the frame was larger than the buffer
|
|
Length = len;
|
|
}
|
|
}
|
|
else {
|
|
error = "fromFile";
|
|
break;
|
|
}
|
|
}
|
|
else {
|
|
// Error, unless we're past the last cut-in and there's no cut-out
|
|
if (Mark || LastMark)
|
|
error = "index";
|
|
break;
|
|
}
|
|
|
|
// Write one frame:
|
|
|
|
if (Independent) { // every file shall start with an independent frame
|
|
if (LastMark) // edited version shall end before next I-frame
|
|
break;
|
|
if (FileSize > maxVideoFileSize) {
|
|
toFile = toFileName->NextFile();
|
|
if (!toFile) {
|
|
error = "toFile 1";
|
|
break;
|
|
}
|
|
FileSize = 0;
|
|
}
|
|
LastIFrame = 0;
|
|
|
|
if (cutIn) {
|
|
if (isPesRecording)
|
|
cRemux::SetBrokenLink(buffer, Length);
|
|
else
|
|
TsSetTeiOnBrokenPackets(buffer, Length);
|
|
cutIn = false;
|
|
}
|
|
}
|
|
if (toFile->Write(buffer, Length) < 0) {
|
|
error = "safe_write";
|
|
break;
|
|
}
|
|
if (!toIndex->Write(Independent, toFileName->Number(), FileSize)) {
|
|
error = "toIndex";
|
|
break;
|
|
}
|
|
FileSize += Length;
|
|
if (!LastIFrame)
|
|
LastIFrame = toIndex->Last();
|
|
|
|
// Check editing marks:
|
|
|
|
if (Mark && Index >= Mark->Position()) {
|
|
Mark = fromMarks.Next(Mark);
|
|
toMarks.Add(LastIFrame);
|
|
if (Mark)
|
|
toMarks.Add(toIndex->Last() + 1);
|
|
toMarks.Save();
|
|
if (Mark) {
|
|
Index = Mark->Position();
|
|
Mark = fromMarks.Next(Mark);
|
|
CurrentFileNumber = 0; // triggers SetOffset before reading next frame
|
|
cutIn = true;
|
|
if (Setup.SplitEditedFiles) {
|
|
toFile = toFileName->NextFile();
|
|
if (!toFile) {
|
|
error = "toFile 2";
|
|
break;
|
|
}
|
|
FileSize = 0;
|
|
}
|
|
}
|
|
else
|
|
LastMark = true;
|
|
}
|
|
}
|
|
Recordings.TouchUpdate();
|
|
}
|
|
else
|
|
esyslog("no editing marks found!");
|
|
}
|
|
|
|
// --- cCutter ---------------------------------------------------------------
|
|
|
|
cMutex cCutter::mutex;
|
|
char *cCutter::editedVersionName = NULL;
|
|
cCuttingThread *cCutter::cuttingThread = NULL;
|
|
bool cCutter::error = false;
|
|
bool cCutter::ended = false;
|
|
|
|
bool cCutter::Start(const char *FileName)
|
|
{
|
|
cMutexLock MutexLock(&mutex);
|
|
if (!cuttingThread) {
|
|
error = false;
|
|
ended = false;
|
|
cRecording Recording(FileName);
|
|
|
|
cMarks FromMarks;
|
|
FromMarks.Load(FileName);
|
|
if (cMark *First = FromMarks.First())
|
|
Recording.SetStartTime(Recording.Start() + (int(First->Position() / Recording.FramesPerSecond() + 30) / 60) * 60);
|
|
|
|
const char *evn = Recording.PrefixFileName('%');
|
|
if (evn && RemoveVideoFile(evn) && MakeDirs(evn, true)) {
|
|
// XXX this can be removed once RenameVideoFile() follows symlinks (see videodir.c)
|
|
// remove a possible deleted recording with the same name to avoid symlink mixups:
|
|
char *s = strdup(evn);
|
|
char *e = strrchr(s, '.');
|
|
if (e) {
|
|
if (strcmp(e, ".rec") == 0) {
|
|
strcpy(e, ".del");
|
|
RemoveVideoFile(s);
|
|
}
|
|
}
|
|
free(s);
|
|
// XXX
|
|
editedVersionName = strdup(evn);
|
|
Recording.WriteInfo();
|
|
Recordings.AddByName(editedVersionName, false);
|
|
cuttingThread = new cCuttingThread(FileName, editedVersionName);
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void cCutter::Stop(void)
|
|
{
|
|
cMutexLock MutexLock(&mutex);
|
|
bool Interrupted = cuttingThread && cuttingThread->Active();
|
|
const char *Error = cuttingThread ? cuttingThread->Error() : NULL;
|
|
delete cuttingThread;
|
|
cuttingThread = NULL;
|
|
if ((Interrupted || Error) && editedVersionName) {
|
|
if (Interrupted)
|
|
isyslog("editing process has been interrupted");
|
|
if (Error)
|
|
esyslog("ERROR: '%s' during editing process", Error);
|
|
RemoveVideoFile(editedVersionName); //XXX what if this file is currently being replayed?
|
|
Recordings.DelByName(editedVersionName);
|
|
}
|
|
}
|
|
|
|
bool cCutter::Active(void)
|
|
{
|
|
cMutexLock MutexLock(&mutex);
|
|
if (cuttingThread) {
|
|
if (cuttingThread->Active())
|
|
return true;
|
|
error = cuttingThread->Error();
|
|
Stop();
|
|
if (!error)
|
|
cRecordingUserCommand::InvokeCommand(RUC_EDITEDRECORDING, editedVersionName);
|
|
free(editedVersionName);
|
|
editedVersionName = NULL;
|
|
ended = true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool cCutter::Error(void)
|
|
{
|
|
cMutexLock MutexLock(&mutex);
|
|
bool result = error;
|
|
error = false;
|
|
return result;
|
|
}
|
|
|
|
bool cCutter::Ended(void)
|
|
{
|
|
cMutexLock MutexLock(&mutex);
|
|
bool result = ended;
|
|
ended = false;
|
|
return result;
|
|
}
|
|
|
|
#define CUTTINGCHECKINTERVAL 500 // ms between checks for the active cutting process
|
|
|
|
bool CutRecording(const char *FileName)
|
|
{
|
|
if (DirectoryOk(FileName)) {
|
|
cRecording Recording(FileName);
|
|
if (Recording.Name()) {
|
|
cMarks Marks;
|
|
if (Marks.Load(FileName, Recording.FramesPerSecond(), Recording.IsPesRecording()) && Marks.Count()) {
|
|
if (cCutter::Start(FileName)) {
|
|
while (cCutter::Active())
|
|
cCondWait::SleepMs(CUTTINGCHECKINTERVAL);
|
|
return true;
|
|
}
|
|
else
|
|
fprintf(stderr, "can't start editing process\n");
|
|
}
|
|
else
|
|
fprintf(stderr, "'%s' has no editing marks\n", FileName);
|
|
}
|
|
else
|
|
fprintf(stderr, "'%s' is not a recording\n", FileName);
|
|
}
|
|
else
|
|
fprintf(stderr, "'%s' is not a directory\n", FileName);
|
|
return false;
|
|
}
|