vdr  2.0.2
cutter.c
Go to the documentation of this file.
1 /*
2  * cutter.c: The video cutting facilities
3  *
4  * See the main source file 'vdr.c' for copyright information and
5  * how to reach the author.
6  *
7  * $Id: cutter.c 2.25.1.1 2013/05/02 09:21:18 kls Exp $
8  */
9 
10 #include "cutter.h"
11 #include "interface.h"
12 #include "menu.h"
13 #include "recording.h"
14 #include "remux.h"
15 #include "videodir.h"
16 
17 // --- cPacketBuffer ---------------------------------------------------------
18 
20 private:
22  int size;
23  int length;
24 public:
25  cPacketBuffer(void);
27  void Append(uchar *Data, int Length);
29  void Flush(uchar *Data, int &Length, int MaxLength);
34  };
35 
37 {
38  data = NULL;
39  size = length = 0;
40 }
41 
43 {
44  free(data);
45 }
46 
47 void cPacketBuffer::Append(uchar *Data, int Length)
48 {
49  if (length + Length >= size) {
50  int NewSize = (length + Length) * 3 / 2;
51  if (uchar *p = (uchar *)realloc(data, NewSize)) {
52  data = p;
53  size = NewSize;
54  }
55  else
56  return; // out of memory
57  }
58  memcpy(data + length, Data, Length);
59  length += Length;
60 }
61 
62 void cPacketBuffer::Flush(uchar *Data, int &Length, int MaxLength)
63 {
64  if (Data && length > 0 && Length + length <= MaxLength) {
65  memcpy(Data + Length, data, length);
66  Length += length;
67  }
68  length = 0;
69 }
70 
71 // --- cPacketStorage --------------------------------------------------------
72 
74 private:
76 public:
77  cPacketStorage(void);
79  void Append(int Pid, uchar *Data, int Length);
80  void Flush(int Pid, uchar *Data, int &Length, int MaxLength);
81  };
82 
84 {
85  for (int i = 0; i < MAXPID; i++)
86  buffers[i] = NULL;
87 }
88 
90 {
91  for (int i = 0; i < MAXPID; i++)
92  delete buffers[i];
93 }
94 
95 void cPacketStorage::Append(int Pid, uchar *Data, int Length)
96 {
97  if (!buffers[Pid])
98  buffers[Pid] = new cPacketBuffer;
99  buffers[Pid]->Append(Data, Length);
100 }
101 
102 void cPacketStorage::Flush(int Pid, uchar *Data, int &Length, int MaxLength)
103 {
104  if (buffers[Pid])
105  buffers[Pid]->Flush(Data, Length, MaxLength);
106 }
107 
108 // --- cMpeg2Fixer -----------------------------------------------------------
109 
110 class cMpeg2Fixer : private cTsPayload {
111 private:
112  bool FindHeader(uint32_t Code, const char *Header);
113 public:
114  cMpeg2Fixer(uchar *Data, int Length, int Vpid);
115  void SetBrokenLink(void);
116  void SetClosedGop(void);
117  int GetTref(void);
118  void AdjGopTime(int Offset, int FramesPerSecond);
119  void AdjTref(int TrefOffset);
120  };
121 
122 cMpeg2Fixer::cMpeg2Fixer(uchar *Data, int Length, int Vpid)
123 {
124  // Go to first video packet:
125  for (; Length > 0; Data += TS_SIZE, Length -= TS_SIZE) {
126  if (TsPid(Data) == Vpid) {
127  Setup(Data, Length, Vpid);
128  break;
129  }
130  }
131 }
132 
133 bool cMpeg2Fixer::FindHeader(uint32_t Code, const char *Header)
134 {
135  Reset();
136  if (Find(Code))
137  return true;
138  esyslog("ERROR: %s header not found!", Header);
139  return false;
140 }
141 
143 {
144  if (!FindHeader(0x000001B8, "GOP"))
145  return;
146  SkipBytes(3);
147  uchar b = GetByte();
148  if (!(b & 0x40)) { // GOP not closed
149  b |= 0x20;
150  SetByte(b, GetLastIndex());
151  }
152 }
153 
155 {
156  if (!FindHeader(0x000001B8, "GOP"))
157  return;
158  SkipBytes(3);
159  uchar b = GetByte();
160  b |= 0x40;
161  SetByte(b, GetLastIndex());
162 }
163 
165 {
166  if (!FindHeader(0x00000100, "picture"))
167  return 0;
168  int Tref = GetByte() << 2;
169  Tref |= GetByte() >> 6;
170  return Tref;
171 }
172 
173 void cMpeg2Fixer::AdjGopTime(int Offset, int FramesPerSecond)
174 {
175  if (!FindHeader(0x000001B8, "GOP"))
176  return;
177  uchar Byte1 = GetByte();
178  int Index1 = GetLastIndex();
179  uchar Byte2 = GetByte();
180  int Index2 = GetLastIndex();
181  uchar Byte3 = GetByte();
182  int Index3 = GetLastIndex();
183  uchar Byte4 = GetByte();
184  int Index4 = GetLastIndex();
185  uchar Frame = ((Byte3 & 0x1F) << 1) | (Byte4 >> 7);
186  uchar Sec = ((Byte2 & 0x07) << 3) | (Byte3 >> 5);
187  uchar Min = ((Byte1 & 0x03) << 4) | (Byte2 >> 4);
188  uchar Hour = ((Byte1 & 0x7C) >> 2);
189  int GopTime = ((Hour * 60 + Min) * 60 + Sec) * FramesPerSecond + Frame;
190  if (GopTime) { // do not fix when zero
191  GopTime += Offset;
192  if (GopTime < 0)
193  GopTime += 24 * 60 * 60 * FramesPerSecond;
194  Frame = GopTime % FramesPerSecond;
195  GopTime = GopTime / FramesPerSecond;
196  Sec = GopTime % 60;
197  GopTime = GopTime / 60;
198  Min = GopTime % 60;
199  GopTime = GopTime / 60;
200  Hour = GopTime % 24;
201  SetByte((Byte1 & 0x80) | (Hour << 2) | (Min >> 4), Index1);
202  SetByte(((Min & 0x0F) << 4) | 0x08 | (Sec >> 3), Index2);
203  SetByte(((Sec & 0x07) << 3) | (Frame >> 1), Index3);
204  SetByte((Byte4 & 0x7F) | ((Frame & 0x01) << 7), Index4);
205  }
206 }
207 
208 void cMpeg2Fixer::AdjTref(int TrefOffset)
209 {
210  if (!FindHeader(0x00000100, "picture"))
211  return;
212  int Tref = GetByte() << 2;
213  int Index1 = GetLastIndex();
214  uchar Byte2 = GetByte();
215  int Index2 = GetLastIndex();
216  Tref |= Byte2 >> 6;
217  Tref -= TrefOffset;
218  SetByte(Tref >> 2, Index1);
219  SetByte((Tref << 6) | (Byte2 & 0x3F), Index2);
220 }
221 
222 // --- cCuttingThread --------------------------------------------------------
223 
224 class cCuttingThread : public cThread {
225 private:
226  const char *error;
235  off_t fileSize;
237  int sequence; // cutting sequence
238  int delta; // time between two frames (PTS ticks)
239  int64_t lastVidPts; // the video PTS of the last frame (in display order)
240  bool multiFramePkt; // multiple frames within one PES packet
241  int64_t firstPts; // first valid PTS, for dangling packet stripping
242  int64_t offset; // offset to add to all timestamps
243  int tRefOffset; // number of stripped frames in GOP
244  uchar counter[MAXPID]; // the TS continuity counter for each PID
245  bool keepPkt[MAXPID]; // flag for each PID to keep packets, for dangling packet stripping
246  int numIFrames; // number of I-frames without pending packets
248  bool Throttled(void);
249  bool SwitchFile(bool Force = false);
250  bool LoadFrame(int Index, uchar *Buffer, bool &Independent, int &Length);
251  bool FramesAreEqual(int Index1, int Index2);
252  void GetPendingPackets(uchar *Buffer, int &Length, int Index);
253  // Gather all non-video TS packets from Index upward that either belong to
254  // payloads that started before Index, or have a PTS that is before lastVidPts,
255  // and add them to the end of the given Data.
256  bool FixFrame(uchar *Data, int &Length, bool Independent, int Index, bool CutIn, bool CutOut);
257  bool ProcessSequence(int LastEndIndex, int BeginIndex, int EndIndex, int NextBeginIndex);
258 protected:
259  virtual void Action(void);
260 public:
261  cCuttingThread(const char *FromFileName, const char *ToFileName);
262  virtual ~cCuttingThread();
263  const char *Error(void) { return error; }
264  };
265 
266 cCuttingThread::cCuttingThread(const char *FromFileName, const char *ToFileName)
267 :cThread("video cutting", true)
268 {
269  error = NULL;
270  fromFile = toFile = NULL;
271  fromFileName = toFileName = NULL;
272  fromIndex = toIndex = NULL;
273  cRecording Recording(FromFileName);
274  isPesRecording = Recording.IsPesRecording();
275  framesPerSecond = Recording.FramesPerSecond();
276  suspensionLogged = false;
277  fileSize = 0;
278  sequence = 0;
279  delta = int(round(PTSTICKS / framesPerSecond));
280  lastVidPts = -1;
281  multiFramePkt = false;
282  firstPts = -1;
283  offset = 0;
284  tRefOffset = 0;
285  memset(counter, 0x00, sizeof(counter));
286  numIFrames = 0;
287  if (fromMarks.Load(FromFileName, framesPerSecond, isPesRecording) && fromMarks.Count()) {
289  if (numSequences > 0) {
290  fromFileName = new cFileName(FromFileName, false, true, isPesRecording);
291  toFileName = new cFileName(ToFileName, true, true, isPesRecording);
292  fromIndex = new cIndexFile(FromFileName, false, isPesRecording);
293  toIndex = new cIndexFile(ToFileName, true, isPesRecording);
294  toMarks.Load(ToFileName, framesPerSecond, isPesRecording); // doesn't actually load marks, just sets the file name
298  Start();
299  }
300  else
301  esyslog("no editing sequences found for %s", FromFileName);
302  }
303  else
304  esyslog("no editing marks found for %s", FromFileName);
305 }
306 
308 {
309  Cancel(3);
310  delete fromFileName;
311  delete toFileName;
312  delete fromIndex;
313  delete toIndex;
314 }
315 
317 {
318  if (cIoThrottle::Engaged()) {
319  if (!suspensionLogged) {
320  dsyslog("suspending cutter thread");
321  suspensionLogged = true;
322  }
323  return true;
324  }
325  else if (suspensionLogged) {
326  dsyslog("resuming cutter thread");
327  suspensionLogged = false;
328  }
329  return false;
330 }
331 
332 bool cCuttingThread::LoadFrame(int Index, uchar *Buffer, bool &Independent, int &Length)
333 {
334  uint16_t FileNumber;
335  off_t FileOffset;
336  if (fromIndex->Get(Index, &FileNumber, &FileOffset, &Independent, &Length)) {
337  fromFile = fromFileName->SetOffset(FileNumber, FileOffset);
338  if (fromFile) {
340  int len = ReadFrame(fromFile, Buffer, Length, MAXFRAMESIZE);
341  if (len < 0)
342  error = "ReadFrame";
343  else if (len != Length)
344  Length = len;
345  return error == NULL;
346  }
347  else
348  error = "fromFile";
349  }
350  return false;
351 }
352 
354 {
355  if (fileSize > maxVideoFileSize || Force) {
357  if (!toFile) {
358  error = "toFile";
359  return false;
360  }
361  fileSize = 0;
362  }
363  return true;
364 }
365 
366 class cHeapBuffer {
367 private:
369 public:
370  cHeapBuffer(int Size) { buffer = MALLOC(uchar, Size); }
371  ~cHeapBuffer() { free(buffer); }
372  operator uchar * () { return buffer; }
373  };
374 
375 bool cCuttingThread::FramesAreEqual(int Index1, int Index2)
376 {
377  cHeapBuffer Buffer1(MAXFRAMESIZE);
378  cHeapBuffer Buffer2(MAXFRAMESIZE);
379  if (!Buffer1 || !Buffer2)
380  return false;
381  bool Independent;
382  int Length1;
383  int Length2;
384  if (LoadFrame(Index1, Buffer1, Independent, Length1) && LoadFrame(Index2, Buffer2, Independent, Length2)) {
385  if (Length1 == Length2) {
386  int Diffs = 0;
387  for (int i = 0; i < Length1; i++) {
388  if (Buffer1[i] != Buffer2[i]) {
389  if (Diffs++ > 10) // the continuity counters of the PAT/PMT packets may differ
390  return false;
391  }
392  }
393  return true;
394  }
395  }
396  return false;
397 }
398 
399 void cCuttingThread::GetPendingPackets(uchar *Data, int &Length, int Index)
400 {
401  cHeapBuffer Buffer(MAXFRAMESIZE);
402  if (!Buffer)
403  return;
404  bool Processed[MAXPID] = { false };
405  cPacketStorage PacketStorage;
406  int64_t LastPts = lastVidPts + delta;// adding one frame length to fully cover the very last frame
407  Processed[patPmtParser.Vpid()] = true; // we only want non-video packets
408  for (int NumIndependentFrames = 0; NumIndependentFrames < 2; Index++) {
409  bool Independent;
410  int len;
411  if (LoadFrame(Index, Buffer, Independent, len)) {
412  if (Independent)
413  NumIndependentFrames++;
414  for (uchar *p = Buffer; len >= TS_SIZE && *p == TS_SYNC_BYTE; len -= TS_SIZE, p += TS_SIZE) {
415  int Pid = TsPid(p);
416  if (Pid != PATPID && !patPmtParser.IsPmtPid(Pid) && !Processed[Pid]) {
417  int64_t Pts = TsGetPts(p, TS_SIZE);
418  if (Pts >= 0) {
419  int64_t d = PtsDiff(LastPts, Pts);
420  if (d < 0) // Pts is before LastPts
421  PacketStorage.Flush(Pid, Data, Length, MAXFRAMESIZE);
422  else { // Pts is at or after LastPts
423  NumIndependentFrames = 0; // we search until we find two consecutive I-frames without any more pending packets
424  Processed[Pid] = true;
425  }
426  }
427  if (!Processed[Pid])
428  PacketStorage.Append(Pid, p, TS_SIZE);
429  }
430  }
431  }
432  else
433  break;
434  }
435 }
436 
437 bool cCuttingThread::FixFrame(uchar *Data, int &Length, bool Independent, int Index, bool CutIn, bool CutOut)
438 {
439  if (!patPmtParser.Vpid()) {
440  if (!patPmtParser.ParsePatPmt(Data, Length))
441  return false;
442  }
443  if (CutIn) {
444  sequence++;
445  memset(keepPkt, false, sizeof(keepPkt));
446  numIFrames = 0;
447  firstPts = TsGetPts(Data, Length);
448  // Determine the PTS offset at the beginning of each sequence (except the first one):
449  if (sequence != 1) {
450  if (firstPts >= 0)
452  }
453  }
454  if (CutOut)
455  GetPendingPackets(Data, Length, Index + 1);
456  if (Independent) {
457  numIFrames++;
458  tRefOffset = 0;
459  }
460  // Fix MPEG-2:
461  if (patPmtParser.Vtype() == 2) {
462  cMpeg2Fixer Mpeg2fixer(Data, Length, patPmtParser.Vpid());
463  if (CutIn) {
464  if (sequence == 1 || multiFramePkt)
465  Mpeg2fixer.SetBrokenLink();
466  else {
467  Mpeg2fixer.SetClosedGop();
468  tRefOffset = Mpeg2fixer.GetTref();
469  }
470  }
471  if (tRefOffset)
472  Mpeg2fixer.AdjTref(tRefOffset);
473  if (sequence > 1 && Independent)
474  Mpeg2fixer.AdjGopTime((offset - MAX33BIT) / delta, round(framesPerSecond));
475  }
476  bool DeletedFrame = false;
477  bool GotVidPts = false;
478  bool StripVideo = sequence > 1 && tRefOffset;
479  uchar *p;
480  int len;
481  for (p = Data, len = Length; len >= TS_SIZE && *p == TS_SYNC_BYTE; p += TS_SIZE, len -= TS_SIZE) {
482  int Pid = TsPid(p);
483  // Strip dangling packets:
484  if (numIFrames < 2 && Pid != PATPID && !patPmtParser.IsPmtPid(Pid)) {
485  if (Pid != patPmtParser.Vpid() || StripVideo) {
486  int64_t Pts = TsGetPts(p, TS_SIZE);
487  if (Pts >= 0)
488  keepPkt[Pid] = PtsDiff(firstPts, Pts) >= 0; // Pts is at or after FirstPts
489  if (!keepPkt[Pid]) {
490  TsHidePayload(p);
491  numIFrames = 0; // we search until we find two consecutive I-frames without any more dangling packets
492  if (Pid == patPmtParser.Vpid())
493  DeletedFrame = true;
494  }
495  }
496  }
497  // Adjust the TS continuity counter:
498  if (sequence > 1) {
499  if (TsHasPayload(p))
500  counter[Pid] = (counter[Pid] + 1) & TS_CONT_CNT_MASK;
502  }
503  else
504  counter[Pid] = TsGetContinuityCounter(p); // collect initial counters
505  // Adjust PTS:
506  int64_t Pts = TsGetPts(p, TS_SIZE);
507  if (Pts >= 0) {
508  if (sequence > 1) {
509  Pts = PtsAdd(Pts, offset);
510  TsSetPts(p, TS_SIZE, Pts);
511  }
512  // Keep track of the highest video PTS - in case of multiple fields per frame, take the first one
513  if (!GotVidPts && Pid == patPmtParser.Vpid()) {
514  GotVidPts = true;
515  if (lastVidPts < 0 || PtsDiff(lastVidPts, Pts) > 0)
516  lastVidPts = Pts;
517  }
518  }
519  // Adjust DTS:
520  if (sequence > 1) {
521  int64_t Dts = TsGetDts(p, TS_SIZE);
522  if (Dts >= 0) {
523  Dts = PtsAdd(Dts, offset);
524  if (CutIn)
525  Dts = PtsAdd(Dts, tRefOffset * delta);
526  TsSetDts(p, TS_SIZE, Dts);
527  }
528  int64_t Pcr = TsGetPcr(p);
529  if (Pcr >= 0) {
530  Pcr = Pcr + offset * PCRFACTOR;
531  if (Pcr > MAX27MHZ)
532  Pcr -= MAX27MHZ + 1;
533  TsSetPcr(p, Pcr);
534  }
535  }
536  }
537  if (!DeletedFrame && !GotVidPts) {
538  // Adjust PTS for multiple frames within a single PES packet:
540  multiFramePkt = true;
541  }
542  return DeletedFrame;
543 }
544 
545 bool cCuttingThread::ProcessSequence(int LastEndIndex, int BeginIndex, int EndIndex, int NextBeginIndex)
546 {
547  // Check for seamless connections:
548  bool SeamlessBegin = LastEndIndex >= 0 && FramesAreEqual(LastEndIndex, BeginIndex);
549  bool SeamlessEnd = NextBeginIndex >= 0 && FramesAreEqual(EndIndex, NextBeginIndex);
550  // Process all frames from BeginIndex (included) to EndIndex (excluded):
551  cHeapBuffer Buffer(MAXFRAMESIZE);
552  if (!Buffer) {
553  error = "malloc";
554  return false;
555  }
556  for (int Index = BeginIndex; Running() && Index < EndIndex; Index++) {
557  bool Independent;
558  int Length;
559  if (LoadFrame(Index, Buffer, Independent, Length)) {
560  bool CutIn = !SeamlessBegin && Index == BeginIndex;
561  bool CutOut = !SeamlessEnd && Index == EndIndex - 1;
562  bool DeletedFrame = false;
563  if (!isPesRecording) {
564  DeletedFrame = FixFrame(Buffer, Length, Independent, Index, CutIn, CutOut);
565  }
566  else if (CutIn)
567  cRemux::SetBrokenLink(Buffer, Length);
568  // Every file shall start with an independent frame:
569  if (Independent) {
570  if (!SwitchFile())
571  return false;
572  }
573  // Write index:
574  if (!DeletedFrame && !toIndex->Write(Independent, toFileName->Number(), fileSize)) {
575  error = "toIndex";
576  return false;
577  }
578  // Write data:
579  if (toFile->Write(Buffer, Length) < 0) {
580  error = "safe_write";
581  return false;
582  }
583  fileSize += Length;
584  // Generate marks at the editing points in the edited recording:
585  if (numSequences > 1 && Index == BeginIndex) {
586  if (toMarks.Count() > 0)
587  toMarks.Add(toIndex->Last());
588  toMarks.Add(toIndex->Last());
589  toMarks.Save();
590  }
591  }
592  else
593  return false;
594  }
595  return true;
596 }
597 
599 {
600  if (cMark *BeginMark = fromMarks.GetNextBegin()) {
602  toFile = toFileName->Open();
603  if (!fromFile || !toFile)
604  return;
605  int LastEndIndex = -1;
606  while (BeginMark && Running()) {
607  // Suspend cutting if we have severe throughput problems:
608  if (Throttled()) {
609  cCondWait::SleepMs(100);
610  continue;
611  }
612  // Make sure there is enough disk space:
614  // Determine the actual begin and end marks, skipping any marks at the same position:
615  cMark *EndMark = fromMarks.GetNextEnd(BeginMark);
616  // Process the current sequence:
617  int EndIndex = EndMark ? EndMark->Position() : fromIndex->Last() + 1;
618  int NextBeginIndex = -1;
619  if (EndMark) {
620  if (cMark *NextBeginMark = fromMarks.GetNextBegin(EndMark))
621  NextBeginIndex = NextBeginMark->Position();
622  }
623  if (!ProcessSequence(LastEndIndex, BeginMark->Position(), EndIndex, NextBeginIndex))
624  break;
625  if (!EndMark)
626  break; // reached EOF
627  LastEndIndex = EndIndex;
628  // Switch to the next sequence:
629  BeginMark = fromMarks.GetNextBegin(EndMark);
630  if (BeginMark) {
631  // Split edited files:
632  if (Setup.SplitEditedFiles) {
633  if (!SwitchFile(true))
634  break;
635  }
636  }
637  }
639  }
640  else
641  esyslog("no editing marks found!");
642 }
643 
644 // --- cCutter ---------------------------------------------------------------
645 
650 bool cCutter::error = false;
651 bool cCutter::ended = false;
652 
653 bool cCutter::Start(const char *FileName, const char *TargetFileName, bool Overwrite)
654 {
655  cMutexLock MutexLock(&mutex);
656  if (!cuttingThread) {
657  error = false;
658  ended = false;
659  originalVersionName = FileName;
660  cRecording Recording(FileName);
661 
662  cMarks FromMarks;
663  FromMarks.Load(FileName, Recording.FramesPerSecond(), Recording.IsPesRecording());
664  if (cMark *First = FromMarks.GetNextBegin())
665  Recording.SetStartTime(Recording.Start() + (int(First->Position() / Recording.FramesPerSecond() + 30) / 60) * 60);
666 
667  cString evn = (TargetFileName && *TargetFileName) ? Recording.UpdateFileName(TargetFileName) : Recording.PrefixFileName('%');
668  if (!Overwrite && *evn && (access(*evn, F_OK) == 0) && !Interface->Confirm(tr("File already exists - overwrite?"))) {
669  do {
670  evn = PrefixVideoFileName(*evn, '%');
671  } while (*evn && (access(*evn, F_OK) == 0));
672  }
673  if (*evn && RemoveVideoFile(*evn) && MakeDirs(*evn, true)) {
674  // XXX this can be removed once RenameVideoFile() follows symlinks (see videodir.c)
675  // remove a possible deleted recording with the same name to avoid symlink mixups:
676  char *s = strdup(*evn);
677  char *e = strrchr(s, '.');
678  if (e) {
679  if (strcmp(e, ".rec") == 0) {
680  strcpy(e, ".del");
681  RemoveVideoFile(s);
682  }
683  }
684  free(s);
685  // XXX
686  editedVersionName = evn;
687  Recording.WriteInfo();
690  return true;
691  }
692  }
693  return false;
694 }
695 
696 void cCutter::Stop(void)
697 {
698  cMutexLock MutexLock(&mutex);
699  bool Interrupted = cuttingThread && cuttingThread->Active();
700  const char *Error = cuttingThread ? cuttingThread->Error() : NULL;
701  delete cuttingThread;
702  cuttingThread = NULL;
703  if ((Interrupted || Error) && *editedVersionName) {
704  if (Interrupted)
705  isyslog("editing process has been interrupted");
706  if (Error)
707  esyslog("ERROR: '%s' during editing process", Error);
712  }
713 }
714 
715 bool cCutter::Active(const char *FileName)
716 {
717  cMutexLock MutexLock(&mutex);
718  if (cuttingThread) {
719  if (cuttingThread->Active())
720  return !FileName || strcmp(FileName, originalVersionName) == 0 || strcmp(FileName, editedVersionName) == 0;
722  Stop();
723  if (!error)
725  originalVersionName = NULL;
726  editedVersionName = NULL;
727  ended = true;
728  }
729  return false;
730 }
731 
732 bool cCutter::Error(void)
733 {
734  cMutexLock MutexLock(&mutex);
735  bool result = error;
736  error = false;
737  return result;
738 }
739 
740 bool cCutter::Ended(void)
741 {
742  cMutexLock MutexLock(&mutex);
743  bool result = ended;
744  ended = false;
745  return result;
746 }
747 
748 #define CUTTINGCHECKINTERVAL 500 // ms between checks for the active cutting process
749 
750 bool CutRecording(const char *FileName)
751 {
752  if (DirectoryOk(FileName)) {
753  cRecording Recording(FileName);
754  if (Recording.Name()) {
755  cMarks Marks;
756  if (Marks.Load(FileName, Recording.FramesPerSecond(), Recording.IsPesRecording()) && Marks.Count()) {
757  if (Marks.GetNumSequences()) {
758  if (cCutter::Start(FileName)) {
759  while (cCutter::Active())
761  return true;
762  }
763  else
764  fprintf(stderr, "can't start editing process\n");
765  }
766  else
767  fprintf(stderr, "'%s' has no editing sequences\n", FileName);
768  }
769  else
770  fprintf(stderr, "'%s' has no editing marks\n", FileName);
771  }
772  else
773  fprintf(stderr, "'%s' is not a recording\n", FileName);
774  }
775  else
776  fprintf(stderr, "'%s' is not a directory\n", FileName);
777  return false;
778 }
779