Support turbo2.
[vuplus_dvbapp] / lib / dvb / demux.h
1 #ifndef __dvb_demux_h
2 #define __dvb_demux_h
3
4 #include <lib/dvb/idvb.h>
5 #include <lib/dvb/idemux.h>
6 #include <lib/dvb/pvrparse.h>
7 #include <lib/base/filepush.h>
8
9 class eDVBDemux: public iDVBDemux
10 {
11         DECLARE_REF(eDVBDemux);
12 public:
13         enum {
14                 evtFlush
15         };
16         eDVBDemux(int adapter, int demux);
17         virtual ~eDVBDemux();
18         
19         RESULT setSourceFrontend(int fenum);
20         int getSource() { return source; }
21         RESULT setSourcePVR(int pvrnum);
22         
23         RESULT createSectionReader(eMainloop *context, ePtr<iDVBSectionReader> &reader);
24         RESULT createPESReader(eMainloop *context, ePtr<iDVBPESReader> &reader);
25         RESULT createTSRecorder(ePtr<iDVBTSRecorder> &recorder);
26         RESULT getMPEGDecoder(ePtr<iTSMPEGDecoder> &reader, int primary);
27         RESULT getSTC(pts_t &pts, int num);
28         RESULT getCADemuxID(uint8_t &id) { id = demux; return 0; }
29         RESULT flush();
30         RESULT connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &conn);
31         int openDVR(int flags);
32
33         int getRefCount() { return ref; }
34 private:
35         int adapter, demux, source;
36         
37         int m_dvr_busy;
38         friend class eDVBSectionReader;
39         friend class eDVBPESReader;
40         friend class eDVBAudio;
41         friend class eDVBVideo;
42         friend class eDVBPCR;
43         friend class eDVBTText;
44         friend class eDVBTSRecorder;
45         friend class eDVBCAService;
46         Signal1<void, int> m_event;
47         
48         int openDemux(void);
49 };
50
51 class eDVBSectionReader: public iDVBSectionReader, public Object
52 {
53         DECLARE_REF(eDVBSectionReader);
54         int fd;
55         Signal1<void, const __u8*> read;
56         ePtr<eDVBDemux> demux;
57         int active;
58         int checkcrc;
59         void data(int);
60         ePtr<eSocketNotifier> notifier;
61 public:
62         eDVBSectionReader(eDVBDemux *demux, eMainloop *context, RESULT &res);
63         virtual ~eDVBSectionReader();
64         RESULT setBufferSize(int size);
65         RESULT start(const eDVBSectionFilterMask &mask);
66         RESULT stop();
67         RESULT connectRead(const Slot1<void,const __u8*> &read, ePtr<eConnection> &conn);
68 };
69
70 class eDVBPESReader: public iDVBPESReader, public Object
71 {
72         DECLARE_REF(eDVBPESReader);
73         int m_fd;
74         Signal2<void, const __u8*, int> m_read;
75         ePtr<eDVBDemux> m_demux;
76         int m_active;
77         void data(int);
78         ePtr<eSocketNotifier> m_notifier;
79 public:
80         eDVBPESReader(eDVBDemux *demux, eMainloop *context, RESULT &res);
81         virtual ~eDVBPESReader();
82         RESULT setBufferSize(int size);
83         RESULT start(int pid);
84         RESULT stop();
85         RESULT connectRead(const Slot2<void,const __u8*, int> &read, ePtr<eConnection> &conn);
86 };
87
88 class eDVBRecordFileThread: public eFilePushThread
89 {
90 public:
91         eDVBRecordFileThread();
92         void setTimingPID(int pid, int type);
93         
94         void startSaveMetaInformation(const std::string &filename);
95         void stopSaveMetaInformation();
96         void enableAccessPoints(bool enable);
97         int getLastPTS(pts_t &pts);
98 protected:
99         int filterRecordData(const unsigned char *data, int len, size_t &current_span_remaining);
100 private:
101         eMPEGStreamParserTS m_ts_parser;
102         eMPEGStreamInformation m_stream_info;
103         off_t m_current_offset;
104         pts_t m_last_pcr; /* very approximate.. */
105         int m_pid;
106 };
107
108 class eDVBTSRecorder: public iDVBTSRecorder, public Object
109 {
110         DECLARE_REF(eDVBTSRecorder);
111 public:
112         eDVBTSRecorder(eDVBDemux *demux);
113         ~eDVBTSRecorder();
114
115         RESULT setBufferSize(int size);
116         RESULT start();
117         RESULT addPID(int pid);
118         RESULT removePID(int pid);
119         
120         RESULT setTimingPID(int pid, int type);
121         
122         RESULT setTargetFD(int fd);
123         RESULT setTargetFilename(const char *filename);
124         RESULT enableAccessPoints(bool enable);
125         RESULT setBoundary(off_t max);
126         RESULT setTimeshift(bool enable);
127         
128         RESULT stop();
129
130         RESULT getCurrentPCR(pts_t &pcr);
131
132         RESULT connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &conn);
133 private:
134         RESULT startPID(int pid);
135         void stopPID(int pid);
136         
137         eDVBRecordFileThread *m_thread;
138         void filepushEvent(int event);
139         
140         std::map<int,int> m_pids;
141         Signal1<void,int> m_event;
142         
143         ePtr<eDVBDemux> m_demux;
144         
145         int m_running, m_target_fd, m_source_fd;
146         std::string m_target_filename;
147 };
148
149 #endif