SASC-NG
DVBSoftCAM

recording.h

Go to the documentation of this file.
00001 /*
00002  * recording.h: Recording file handling
00003  *
00004  * See the main source file 'vdr.c' for copyright information and
00005  * how to reach the author.
00006  *
00007  * $Id: recording.h 1.57 2007/06/17 12:53:05 kls Exp $
00008  */
00009 
00010 #ifndef __RECORDING_H
00011 #define __RECORDING_H
00012 
00013 #include <time.h>
00014 #include "channels.h"
00015 #include "config.h"
00016 #include "epg.h"
00017 #include "thread.h"
00018 #include "timers.h"
00019 #include "tools.h"
00020 
00021 extern bool VfatFileSystem;
00022 
00023 void RemoveDeletedRecordings(void);
00024 void AssertFreeDiskSpace(int Priority = 0, bool Force = false);
00029 
00030 class cResumeFile {
00031 private:
00032   char *fileName;
00033 public:
00034   cResumeFile(const char *FileName);
00035   ~cResumeFile();
00036   int Read(void);
00037   bool Save(int Index);
00038   void Delete(void);
00039   };
00040 
00041 class cRecordingInfo {
00042   friend class cRecording;
00043 private:
00044   tChannelID channelID;
00045   char *channelName;
00046   const cEvent *event;
00047   cEvent *ownEvent;
00048   char *aux;
00049   cRecordingInfo(const cChannel *Channel = NULL, const cEvent *Event = NULL);
00050   void SetData(const char *Title, const char *ShortText, const char *Description);
00051   void SetAux(const char *Aux);
00052 public:
00053   ~cRecordingInfo();
00054   tChannelID ChannelID(void) const { return channelID; }
00055   const char *ChannelName(void) const { return channelName; }
00056   const char *Title(void) const { return event->Title(); }
00057   const char *ShortText(void) const { return event->ShortText(); }
00058   const char *Description(void) const { return event->Description(); }
00059   const cComponents *Components(void) const { return event->Components(); }
00060   const char *Aux(void) const { return aux; }
00061   bool Read(FILE *f);
00062   bool Write(FILE *f, const char *Prefix = "") const;
00063   };
00064 
00065 class cRecording : public cListObject {
00066   friend class cRecordings;
00067 private:
00068   mutable int resume;
00069   mutable char *titleBuffer;
00070   mutable char *sortBuffer;
00071   mutable char *fileName;
00072   mutable char *name;
00073   mutable int fileSizeMB;
00074   cRecordingInfo *info;
00075   static char *StripEpisodeName(char *s);
00076   char *SortName(void) const;
00077   int GetResume(void) const;
00078 public:
00079   time_t start;
00080   int priority;
00081   int lifetime;
00082   time_t deleted;
00083   cRecording(cTimer *Timer, const cEvent *Event);
00084   cRecording(const char *FileName);
00085   virtual ~cRecording();
00086   virtual int Compare(const cListObject &ListObject) const;
00087   const char *Name(void) const { return name; }
00088   const char *FileName(void) const;
00089   const char *Title(char Delimiter = ' ', bool NewIndicator = false, int Level = -1) const;
00090   const cRecordingInfo *Info(void) const { return info; }
00091   const char *PrefixFileName(char Prefix);
00092   int HierarchyLevels(void) const;
00093   void ResetResume(void) const;
00094   bool IsNew(void) const { return GetResume() <= 0; }
00095   bool IsEdited(void) const;
00096   bool WriteInfo(void);
00097   bool Delete(void);
00098        // Changes the file name so that it will no longer be visible in the "Recordings" menu
00099        // Returns false in case of error
00100   bool Remove(void);
00101        // Actually removes the file from the disk
00102        // Returns false in case of error
00103   };
00104 
00105 class cRecordings : public cList<cRecording>, public cThread {
00106 private:
00107   static char *updateFileName;
00108   bool deleted;
00109   time_t lastUpdate;
00110   int state;
00111   const char *UpdateFileName(void);
00112   void Refresh(bool Foreground = false);
00113   void ScanVideoDir(const char *DirName, bool Foreground = false, int LinkLevel = 0);
00114 protected:
00115   void Action(void);
00116 public:
00117   cRecordings(bool Deleted = false);
00118   virtual ~cRecordings();
00119   bool Load(void) { return Update(true); }
00123   bool Update(bool Wait = false);
00129   void TouchUpdate(void);
00133   bool NeedsUpdate(void);
00134   void ChangeState(void) { state++; }
00135   bool StateChanged(int &State);
00136   void ResetResume(const char *ResumeFileName = NULL);
00137   cRecording *GetByName(const char *FileName);
00138   void AddByName(const char *FileName, bool TriggerUpdate = true);
00139   void DelByName(const char *FileName);
00140   int TotalFileSizeMB(void); 
00141   };
00142 
00143 extern cRecordings Recordings;
00144 extern cRecordings DeletedRecordings;
00145 
00146 class cMark : public cListObject {
00147 public:
00148   int position;
00149   char *comment;
00150   cMark(int Position = 0, const char *Comment = NULL);
00151   virtual ~cMark();
00152   cString ToText(void);
00153   bool Parse(const char *s);
00154   bool Save(FILE *f);
00155   };
00156 
00157 class cMarks : public cConfig<cMark> {
00158 public:
00159   bool Load(const char *RecordingFileName);
00160   void Sort(void);
00161   cMark *Add(int Position);
00162   cMark *Get(int Position);
00163   cMark *GetPrev(int Position);
00164   cMark *GetNext(int Position);
00165   };
00166 
00167 #define RUC_BEFORERECORDING "before"
00168 #define RUC_AFTERRECORDING  "after"
00169 #define RUC_EDITEDRECORDING "edited"
00170 
00171 class cRecordingUserCommand {
00172 private:
00173   static const char *command;
00174 public:
00175   static void SetCommand(const char *Command) { command = Command; }
00176   static void InvokeCommand(const char *State, const char *RecordingFileName);
00177   };
00178 
00179 //XXX+
00180 #define FRAMESPERSEC 25
00181 
00182 // The maximum size of a single frame (up to HDTV 1920x1080):
00183 #define MAXFRAMESIZE  KILOBYTE(512)
00184 
00185 // The maximum file size is limited by the range that can be covered
00186 // with 'int'. 4GB might be possible (if the range is considered
00187 // 'unsigned'), 2GB should be possible (even if the range is considered
00188 // 'signed'), so let's use 2000MB for absolute safety (the actual file size
00189 // may be slightly higher because we stop recording only before the next
00190 // 'I' frame, to have a complete Group Of Pictures):
00191 #define MAXVIDEOFILESIZE 2000 // MB
00192 #define MINVIDEOFILESIZE  100 // MB
00193 
00194 class cIndexFile {
00195 private:
00196   struct tIndex { int offset; uchar type; uchar number; short reserved; };
00197   int f;
00198   char *fileName;
00199   int size, last;
00200   tIndex *index;
00201   cResumeFile resumeFile;
00202   cMutex mutex;
00203   bool CatchUp(int Index = -1);
00204 public:
00205   cIndexFile(const char *FileName, bool Record);
00206   ~cIndexFile();
00207   bool Ok(void) { return index != NULL; }
00208   bool Write(uchar PictureType, uchar FileNumber, int FileOffset);
00209   bool Get(int Index, uchar *FileNumber, int *FileOffset, uchar *PictureType = NULL, int *Length = NULL);
00210   int GetNextIFrame(int Index, bool Forward, uchar *FileNumber = NULL, int *FileOffset = NULL, int *Length = NULL, bool StayOffEnd = false);
00211   int Get(uchar FileNumber, int FileOffset);
00212   int Last(void) { CatchUp(); return last; }
00213   int GetResume(void) { return resumeFile.Read(); }
00214   bool StoreResume(int Index) { return resumeFile.Save(Index); }
00215   bool IsStillRecording(void);
00216   };
00217 
00218 class cFileName {
00219 private:
00220   cUnbufferedFile *file;
00221   int fileNumber;
00222   char *fileName, *pFileNumber;
00223   bool record;
00224   bool blocking;
00225 public:
00226   cFileName(const char *FileName, bool Record, bool Blocking = false);
00227   ~cFileName();
00228   const char *Name(void) { return fileName; }
00229   int Number(void) { return fileNumber; }
00230   cUnbufferedFile *Open(void);
00231   void Close(void);
00232   cUnbufferedFile *SetOffset(int Number, int Offset = 0);
00233   cUnbufferedFile *NextFile(void);
00234   };
00235 
00236 cString IndexToHMSF(int Index, bool WithFrame = false);
00237       // Converts the given index to a string, optionally containing the frame number.
00238 int HMSFToIndex(const char *HMSF);
00239       // Converts the given string (format: "hh:mm:ss.ff") to an index.
00240 int SecondsToFrames(int Seconds); //XXX+ ->player???
00241       // Returns the number of frames corresponding to the given number of seconds.
00242 
00243 int ReadFrame(cUnbufferedFile *f, uchar *b, int Length, int Max);
00244 
00245 char *ExchangeChars(char *s, bool ToFileSystem);
00246       // Exchanges the characters in the given string to or from a file system
00247       // specific representation (depending on ToFileSystem). The given string will
00248       // be modified and may be reallocated if more space is needed. The return
00249       // value points to the resulting string, which may be different from s.
00250 
00251 #endif //__RECORDING_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines