diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2013-10-10 13:13:30 +0200 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2013-10-10 13:13:30 +0200 |
commit | 2bdb599fbcfea5bac49fcf5550cd0fd1bc328d4a (patch) | |
tree | 88e9d6c0b7505f1c4d9374c26a4c3ee27dd6ee90 /cutter.c | |
parent | 3971cc6e8845f2a70018b20706f4a30d71edd41d (diff) | |
download | vdr-2bdb599fbcfea5bac49fcf5550cd0fd1bc328d4a.tar.gz vdr-2bdb599fbcfea5bac49fcf5550cd0fd1bc328d4a.tar.bz2 |
Added renaming and moving recordings and folders, and editing a recording's priority and lifetime; added cutting queue
Diffstat (limited to 'cutter.c')
-rw-r--r-- | cutter.c | 92 |
1 files changed, 46 insertions, 46 deletions
@@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: cutter.c 3.3 2013/09/10 14:51:45 kls Exp $ + * $Id: cutter.c 3.4 2013/10/02 13:18:02 kls Exp $ */ #include "cutter.h" @@ -642,34 +642,47 @@ void cCuttingThread::Action(void) // --- cCutter --------------------------------------------------------------- -cMutex cCutter::mutex; -cString cCutter::originalVersionName; -cString cCutter::editedVersionName; -cCuttingThread *cCutter::cuttingThread = NULL; -bool cCutter::error = false; -bool cCutter::ended = false; +cCutter::cCutter(const char *FileName) +{ + cuttingThread = NULL; + error = false; + originalVersionName = FileName; +} -bool cCutter::Start(const char *FileName) +cCutter::~cCutter() { - cMutexLock MutexLock(&mutex); - if (!cuttingThread) { - error = false; - ended = false; - originalVersionName = FileName; - cRecording Recording(FileName); + Stop(); +} - cMarks FromMarks; - FromMarks.Load(FileName, Recording.FramesPerSecond(), Recording.IsPesRecording()); - if (cMark *First = FromMarks.GetNextBegin()) +cString cCutter::EditedFileName(const char *FileName) +{ + cRecording Recording(FileName); + cMarks Marks; + if (Marks.Load(FileName, Recording.FramesPerSecond(), Recording.IsPesRecording())) { + if (cMark *First = Marks.GetNextBegin()) Recording.SetStartTime(Recording.Start() + (int(First->Position() / Recording.FramesPerSecond() + 30) / 60) * 60); + return Recording.PrefixFileName('%'); + } + return NULL; +} - const char *evn = Recording.PrefixFileName('%'); - if (evn && cVideoDirectory::RemoveVideoFile(evn) && MakeDirs(evn, true)) { - editedVersionName = evn; - Recording.WriteInfo(); - Recordings.AddByName(editedVersionName, false); - cuttingThread = new cCuttingThread(FileName, editedVersionName); - return true; +bool cCutter::Start(void) +{ + if (!cuttingThread) { + error = false; + if (*originalVersionName) { + cRecording Recording(originalVersionName); + editedVersionName = EditedFileName(originalVersionName); + if (*editedVersionName) { + if (strcmp(originalVersionName, editedVersionName) != 0) { // names must be different! + if (cVideoDirectory::RemoveVideoFile(editedVersionName) && MakeDirs(editedVersionName, true)) { + Recording.WriteInfo(editedVersionName); + Recordings.AddByName(editedVersionName, false); + cuttingThread = new cCuttingThread(originalVersionName, editedVersionName); + return true; + } + } + } } } return false; @@ -677,7 +690,6 @@ bool cCutter::Start(const char *FileName) void cCutter::Stop(void) { - cMutexLock MutexLock(&mutex); bool Interrupted = cuttingThread && cuttingThread->Active(); const char *Error = cuttingThread ? cuttingThread->Error() : NULL; delete cuttingThread; @@ -694,37 +706,22 @@ void cCutter::Stop(void) } } -bool cCutter::Active(const char *FileName) +bool cCutter::Active(void) { - cMutexLock MutexLock(&mutex); if (cuttingThread) { if (cuttingThread->Active()) - return !FileName || strcmp(FileName, originalVersionName) == 0 || strcmp(FileName, editedVersionName) == 0; + return true; error = cuttingThread->Error(); Stop(); if (!error) cRecordingUserCommand::InvokeCommand(RUC_EDITEDRECORDING, editedVersionName, originalVersionName); - originalVersionName = NULL; - 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; + return error; } #define CUTTINGCHECKINTERVAL 500 // ms between checks for the active cutting process @@ -737,10 +734,13 @@ bool CutRecording(const char *FileName) cMarks Marks; if (Marks.Load(FileName, Recording.FramesPerSecond(), Recording.IsPesRecording()) && Marks.Count()) { if (Marks.GetNumSequences()) { - if (cCutter::Start(FileName)) { - while (cCutter::Active()) + cCutter Cutter(FileName); + if (Cutter.Start()) { + while (Cutter.Active()) cCondWait::SleepMs(CUTTINGCHECKINTERVAL); - return true; + if (!Cutter.Error()) + return true; + fprintf(stderr, "error while cutting\n"); } else fprintf(stderr, "can't start editing process\n"); |