10 #if HAVE_DVB_API_VERSION < 3
12 #ifndef DMX_SET_NEGFILTER_MASK
13 #define DMX_SET_NEGFILTER_MASK _IOW('o',48,uint8_t *)
16 #include <linux/dvb/dmx.h>
21 #include <lib/base/eerror.h>
22 #include <lib/base/filepush.h>
23 #include <lib/dvb/idvb.h>
24 #include <lib/dvb/demux.h>
25 #include <lib/dvb/esection.h>
26 #include <lib/dvb/decoder.h>
28 eDVBDemux::eDVBDemux(int adapter, int demux): adapter(adapter), demux(demux)
33 eDVBDemux::~eDVBDemux()
39 RESULT eDVBDemux::createSectionReader(eMainloop *context, ePtr<iDVBSectionReader> &reader)
42 reader = new eDVBSectionReader(this, context, res);
48 RESULT eDVBDemux::createTSRecorder(ePtr<iDVBTSRecorder> &recorder)
52 recorder = new eDVBTSRecorder(this);
56 RESULT eDVBDemux::getMPEGDecoder(ePtr<iTSMPEGDecoder> &decoder)
58 decoder = new eTSMPEGDecoder(this, 0);
62 void eDVBSectionReader::data(int)
64 __u8 data[4096]; // max. section size
66 r = ::read(fd, data, 4096);
69 eWarning("ERROR reading section - %m\n");
74 // this check should never happen unless the driver is crappy!
76 if ((c = crc32((unsigned)-1, data, r)))
78 eDebug("crc32 failed! is %x\n", c);
85 eDebug("data.. but not active");
88 eDVBSectionReader::eDVBSectionReader(eDVBDemux *demux, eMainloop *context, RESULT &res): demux(demux)
91 #if HAVE_DVB_API_VERSION < 3
92 sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
94 sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
96 fd = ::open(filename, O_RDWR);
98 eDebug("eDVBSectionReader has fd %d", fd);
102 notifier=new eSocketNotifier(context, fd, eSocketNotifier::Read);
103 CONNECT(notifier->activated, eDVBSectionReader::data);
112 DEFINE_REF(eDVBSectionReader)
114 eDVBSectionReader::~eDVBSectionReader()
122 RESULT eDVBSectionReader::start(const eDVBSectionFilterMask &mask)
128 #if HAVE_DVB_API_VERSION < 3
129 dmxSctFilterParams sct;
131 dmx_sct_filter_params sct;
135 #if HAVE_DVB_API_VERSION < 3
138 sct.flags = DMX_IMMEDIATE_START;
140 if (mask.flags & eDVBSectionFilterMask::rfCRC)
142 sct.flags |= DMX_CHECK_CRC;
147 memcpy(sct.filter.filter, mask.data, DMX_FILTER_SIZE);
148 memcpy(sct.filter.mask, mask.mask, DMX_FILTER_SIZE);
149 #if HAVE_DVB_API_VERSION >= 3
150 memcpy(sct.filter.mode, mask.mode, DMX_FILTER_SIZE);
153 res = ::ioctl(fd, DMX_SET_FILTER, &sct);
156 #if HAVE_DVB_API_VERSION < 3
157 res = ::ioctl(fd, DMX_SET_NEGFILTER_MASK, mask.mode);
160 res = ::ioctl(fd, DMX_START, 0);
171 RESULT eDVBSectionReader::stop()
177 ::ioctl(fd, DMX_STOP);
182 RESULT eDVBSectionReader::connectRead(const Slot1<void,const __u8*> &r, ePtr<eConnection> &conn)
184 conn = new eConnection(this, read.connect(r));
188 DEFINE_REF(eDVBTSRecorder);
190 eDVBTSRecorder::eDVBTSRecorder(eDVBDemux *demux): m_demux(demux)
195 m_thread = new eFilePushThread();
196 m_demux->m_dvr_busy = 1;
199 eDVBTSRecorder::~eDVBTSRecorder()
203 m_demux->m_dvr_busy = 0;
206 RESULT eDVBTSRecorder::start()
211 if (m_target_fd == -1)
215 #if HAVE_DVB_API_VERSION < 3
216 snprintf(filename, 128, "/dev/dvb/card%d/dvr%d", m_demux->adapter, m_demux->demux);
218 snprintf(filename, 128, "/dev/dvb/adapter%d/dvr%d", m_demux->adapter, m_demux->demux);
220 m_source_fd = ::open(filename, O_RDONLY);
224 eDebug("FAILED to open dvr (%s) in ts recoder (%m)", filename);
228 m_thread->start(m_source_fd, m_target_fd);
231 for (std::map<int,int>::iterator i(m_pids.begin()); i != m_pids.end(); ++i)
237 RESULT eDVBTSRecorder::addPID(int pid)
239 if (m_pids.find(pid) != m_pids.end())
242 m_pids.insert(std::pair<int,int>(pid, -1));
248 RESULT eDVBTSRecorder::removePID(int pid)
250 if (m_pids.find(pid) == m_pids.end())
260 RESULT eDVBTSRecorder::setFormat(int format)
268 RESULT eDVBTSRecorder::setTargetFD(int fd)
274 RESULT eDVBTSRecorder::setBoundary(off_t max)
276 return -1; // not yet implemented
279 RESULT eDVBTSRecorder::stop()
281 for (std::map<int,int>::iterator i(m_pids.begin()); i != m_pids.end(); ++i)
293 RESULT eDVBTSRecorder::connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &conn)
295 conn = new eConnection(this, m_event.connect(event));
299 RESULT eDVBTSRecorder::startPID(int pid)
302 #if HAVE_DVB_API_VERSION < 3
303 snprintf(filename, 128, "/dev/dvb/card%d/demux%d", m_demux->adapter, m_demux->demux);
305 snprintf(filename, 128, "/dev/dvb/adapter%d/demux%d", m_demux->adapter, m_demux->demux);
307 int fd = ::open(filename, O_RDWR);
310 eDebug("FAILED to open demux (%s) in ts recoder (%m)", filename);
314 #if HAVE_DVB_API_VERSION < 3
315 dmxPesFilterParams flt;
317 flt.pesType = DMX_PES_OTHER;
319 dmx_pes_filter_params flt;
321 flt.pes_type = DMX_PES_OTHER;
325 flt.input = DMX_IN_FRONTEND;
326 flt.output = DMX_OUT_TS_TAP;
328 flt.flags = DMX_IMMEDIATE_START;
330 int res = ::ioctl(fd, DMX_SET_PES_FILTER, &flt);
333 eDebug("set pes filter failed!");
342 void eDVBTSRecorder::stopPID(int pid)
344 ::close(m_pids[pid]);