mirror of
https://github.com/vdr-projects/vdr.git
synced 2025-12-27 07:11:05 +01:00
Added renaming and moving recordings and folders, and editing a recording's priority and lifetime; added cutting queue
This commit is contained in:
96
cutter.c
96
cutter.c
@@ -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;
|
||||
|
||||
bool cCutter::Start(const char *FileName)
|
||||
cCutter::cCutter(const char *FileName)
|
||||
{
|
||||
cuttingThread = NULL;
|
||||
error = false;
|
||||
originalVersionName = FileName;
|
||||
}
|
||||
|
||||
cCutter::~cCutter()
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
bool cCutter::Start(void)
|
||||
{
|
||||
cMutexLock MutexLock(&mutex);
|
||||
if (!cuttingThread) {
|
||||
error = false;
|
||||
ended = false;
|
||||
originalVersionName = FileName;
|
||||
cRecording Recording(FileName);
|
||||
|
||||
cMarks FromMarks;
|
||||
FromMarks.Load(FileName, Recording.FramesPerSecond(), Recording.IsPesRecording());
|
||||
if (cMark *First = FromMarks.GetNextBegin())
|
||||
Recording.SetStartTime(Recording.Start() + (int(First->Position() / Recording.FramesPerSecond() + 30) / 60) * 60);
|
||||
|
||||
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;
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user