trunk 20080912
[gitenigma.git] / include / lib / dvb / record.h
blob840fc09c33cad61d235230a1b845931092e1b6f8
1 #ifndef DISABLE_FILE
3 #ifndef __record_h
4 #define __record_h
6 #include <libsig_comp.h>
7 #include <lib/dvb/dvb.h>
8 #include <lib/base/ebase.h>
9 #include <lib/base/message.h>
10 #include <lib/base/thread.h>
11 #include <lib/base/eerror.h>
12 #include <lib/base/estring.h>
13 #include <lib/base/buffer.h>
15 #include <set>
17 #define RECORD_TELETEXT
18 #define RECORD_SUBTITLES
20 /**
21 * \brief The DVBRecorder
23 * A class which can record a TS consisting of given pids. The
24 * recorder runs in a seperate thread and can be controlled
25 * asynchronously. Internally this is done with a \c eMessagePump.
26 * \todo Howto disable this warning?
29 class eDVBRecorder: private eThread, public Object
31 enum { stateRunning = 1, stateStopped = 0, stateError = 2 }state;
32 struct eDVBRecorderMessage
34 enum eCode
36 rWriteError // disk full etc.
37 } code;
38 union
40 const char *filename;
41 int pid;
42 struct
44 void *data;
45 int len;
46 } write;
48 eDVBRecorderMessage() { }
49 eDVBRecorderMessage(eCode code): code(code) { }
50 eDVBRecorderMessage(eCode code, const char *filename): code(code), filename(filename) { }
51 eDVBRecorderMessage(eCode code, int pid): code(code), pid(pid) { }
52 eDVBRecorderMessage(eCode code, void *data, int len): code(code) { write.data=data; write.len=len; }
54 struct pid_t
56 int pid;
57 int fd;
58 int flags;
59 bool operator < (const pid_t &p) const
61 return pid < p.pid;
65 std::set<pid_t> pids, newpids;
66 eFixedMessagePump<eDVBRecorderMessage> rmessagepump;
68 off64_t splitsize, size;
69 int splits, dvrfd, outfd;
71 eString filename;
73 char buf[524144];
74 int bufptr;
76 int written_since_last_sync;
77 void thread();
78 void gotBackMessage(const eDVBRecorderMessage &msg);
79 inline int flushBuffer();
80 int openFile(int suffix=0);
81 void PatPmtWrite();
82 __u8 *PmtData, *PatData;
83 unsigned int PmtCC, PatCC;
84 int pmtpid;
85 eAUTable<PMT> tPMT;
86 bool writePatPmt;
87 void PMTready(int error);
88 eLock splitlock;
89 public:
90 /// the constructor
91 eDVBRecorder(PMT *, PAT*);
92 /// the destructor
93 ~eDVBRecorder();
95 void setWritePatPmtFlag() { writePatPmt=true; }
97 eString getFilename() { return filename; }
99 /**
100 * \brief Opens a file
102 * This call will open a new filename. It will close open files.
103 * \param filename Pointer to a filename. Existing files will be deleted. (life is cruel)
105 void open(const char *filename);
108 * \brief Adds a PID.
110 * This call will add a PID to record. Recording doesn't start until using \c start().
111 * \sa eDVBRecorder::start
113 std::pair<std::set<eDVBRecorder::pid_t>::iterator,bool> addPID(int pid, int flags=0);
116 * \brief Removes a PID.
118 * This call will remove a PID.
120 void removePID(int pid);
123 * \brief Start recording.
125 * This call will start the recording. You can stop it with \c stop().
126 * \sa eDVBRecorder::stop
128 void start();
131 * \brief Stop recording.
133 * This call will pause the recording. You can restart it (and append data) with \c start again.
135 void stop();
138 * \brief Closes recording file.
140 * This will close the recorded file.
142 void close();
145 * \brief Writes a section into the stream.
147 * This will generate aligned ts packets and thus write a section to the stream. CRC must be calculated by caller.
148 * File must be already opened.
149 * Len will be fetched out of table.
151 void writeSection(void *data, int pid, unsigned int &cc);
154 * \brief Adds a PID to running recording.
156 * This call will add a new PID to a running record. After add all new PIDs .. \c validatePIDs() must be called.
157 * \sa eDVBRecorder::addNewPID
159 void addNewPID(int pid, int flags=0);
162 * \brief Validate all PIDs.
164 * This call will remove all PID they never contains in the pmt, and add all new PIDs. All PIDs must set with \c addNewPID before.
165 * \sa eDVBRecorder::validatePIDs
167 void validatePIDs();
169 enum { recWriteError };
170 Signal1<void,int> recMessage;
171 eServiceReferenceDVB recRef;
172 bool scrambled;
173 void SetSlice(int slice);
176 #endif
178 #endif //DISABLE_FILE