9 #if HAVE_DVB_API_VERSION < 3
11 #ifndef DMX_SET_NEGFILTER_MASK
12 #define DMX_SET_NEGFILTER_MASK _IOW('o',48,uint8_t *)
15 #include <linux/dvb/dmx.h>
20 #include <lib/base/eerror.h>
21 #include <lib/base/filepush.h>
22 #include <lib/dvb/idvb.h>
23 #include <lib/dvb/demux.h>
24 #include <lib/dvb/esection.h>
25 #include <lib/dvb/decoder.h>
27 eDVBDemux::eDVBDemux(int adapter, int demux): adapter(adapter), demux(demux)
32 eDVBDemux::~eDVBDemux()
36 int eDVBDemux::openDemux(void)
39 #if HAVE_DVB_API_VERSION < 3
40 snprintf(filename, 128, "/dev/dvb/card%d/demux%d", adapter, demux);
42 snprintf(filename, 128, "/dev/dvb/adapter%d/demux%d", adapter, demux);
44 return ::open(filename, O_RDWR);
49 RESULT eDVBDemux::setSourceFrontend(int fenum)
51 #if HAVE_DVB_API_VERSION >= 3
54 int n = DMX_SOURCE_FRONT0 + fenum;
55 int res = ::ioctl(fd, DMX_SET_SOURCE, &n);
57 eDebug("DMX_SET_SOURCE failed! - %m");
64 RESULT eDVBDemux::setSourcePVR(int pvrnum)
66 #if HAVE_DVB_API_VERSION >= 3
68 int n = DMX_SOURCE_DVR0 + pvrnum;
69 int res = ::ioctl(fd, DMX_SET_SOURCE, &n);
76 RESULT eDVBDemux::createSectionReader(eMainloop *context, ePtr<iDVBSectionReader> &reader)
79 reader = new eDVBSectionReader(this, context, res);
85 RESULT eDVBDemux::createTSRecorder(ePtr<iDVBTSRecorder> &recorder)
89 recorder = new eDVBTSRecorder(this);
93 RESULT eDVBDemux::getMPEGDecoder(ePtr<iTSMPEGDecoder> &decoder)
95 decoder = new eTSMPEGDecoder(this, 0);
99 RESULT eDVBDemux::getSTC(pts_t &pts, int num)
101 int fd = openDemux();
110 if (ioctl(fd, DMX_GET_STC, &stc) < 0)
122 RESULT eDVBDemux::flush()
124 // FIXME: implement flushing the PVR queue here.
130 RESULT eDVBDemux::connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &conn)
132 conn = new eConnection(this, m_event.connect(event));
136 void eDVBSectionReader::data(int)
138 __u8 data[4096]; // max. section size
140 r = ::read(fd, data, 4096);
143 eWarning("ERROR reading section - %m\n");
148 // this check should never happen unless the driver is crappy!
150 if ((c = crc32((unsigned)-1, data, r)))
152 eDebug("crc32 failed! is %x\n", c);
159 eDebug("data.. but not active");
162 eDVBSectionReader::eDVBSectionReader(eDVBDemux *demux, eMainloop *context, RESULT &res): demux(demux)
165 fd = demux->openDemux();
169 notifier=new eSocketNotifier(context, fd, eSocketNotifier::Read, false);
170 CONNECT(notifier->activated, eDVBSectionReader::data);
179 DEFINE_REF(eDVBSectionReader)
181 eDVBSectionReader::~eDVBSectionReader()
189 RESULT eDVBSectionReader::start(const eDVBSectionFilterMask &mask)
196 #if HAVE_DVB_API_VERSION < 3
197 dmxSctFilterParams sct;
199 dmx_sct_filter_params sct;
203 #if HAVE_DVB_API_VERSION < 3
206 sct.flags = DMX_IMMEDIATE_START;
208 if (mask.flags & eDVBSectionFilterMask::rfCRC)
210 sct.flags |= DMX_CHECK_CRC;
215 memcpy(sct.filter.filter, mask.data, DMX_FILTER_SIZE);
216 memcpy(sct.filter.mask, mask.mask, DMX_FILTER_SIZE);
217 #if HAVE_DVB_API_VERSION >= 3
218 memcpy(sct.filter.mode, mask.mode, DMX_FILTER_SIZE);
219 if (::ioctl(fd, DMX_SET_BUFFER_SIZE, 8192*8) < 0)
220 eDebug("DMX_SET_BUFFER_SIZE failed(%m)");
223 res = ::ioctl(fd, DMX_SET_FILTER, &sct);
226 #if HAVE_DVB_API_VERSION < 3
227 res = ::ioctl(fd, DMX_SET_NEGFILTER_MASK, mask.mode);
230 res = ::ioctl(fd, DMX_START, 0);
241 RESULT eDVBSectionReader::stop()
247 ::ioctl(fd, DMX_STOP);
253 RESULT eDVBSectionReader::connectRead(const Slot1<void,const __u8*> &r, ePtr<eConnection> &conn)
255 conn = new eConnection(this, read.connect(r));
259 DEFINE_REF(eDVBTSRecorder);
261 eDVBTSRecorder::eDVBTSRecorder(eDVBDemux *demux): m_demux(demux)
266 m_thread = new eFilePushThread();
267 m_demux->m_dvr_busy = 1;
270 eDVBTSRecorder::~eDVBTSRecorder()
274 m_demux->m_dvr_busy = 0;
277 RESULT eDVBTSRecorder::start()
282 if (m_target_fd == -1)
286 #if HAVE_DVB_API_VERSION < 3
287 snprintf(filename, 128, "/dev/dvb/card%d/dvr%d", m_demux->adapter, m_demux->demux);
289 snprintf(filename, 128, "/dev/dvb/adapter%d/dvr%d", m_demux->adapter, m_demux->demux);
291 m_source_fd = ::open(filename, O_RDONLY);
295 eDebug("FAILED to open dvr (%s) in ts recoder (%m)", filename);
299 m_thread->start(m_source_fd, m_target_fd);
302 for (std::map<int,int>::iterator i(m_pids.begin()); i != m_pids.end(); ++i)
308 RESULT eDVBTSRecorder::addPID(int pid)
310 if (m_pids.find(pid) != m_pids.end())
313 m_pids.insert(std::pair<int,int>(pid, -1));
319 RESULT eDVBTSRecorder::removePID(int pid)
321 if (m_pids.find(pid) == m_pids.end())
331 RESULT eDVBTSRecorder::setFormat(int format)
339 RESULT eDVBTSRecorder::setTargetFD(int fd)
345 RESULT eDVBTSRecorder::setBoundary(off_t max)
347 return -1; // not yet implemented
350 RESULT eDVBTSRecorder::stop()
352 for (std::map<int,int>::iterator i(m_pids.begin()); i != m_pids.end(); ++i)
364 RESULT eDVBTSRecorder::connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &conn)
366 conn = new eConnection(this, m_event.connect(event));
370 RESULT eDVBTSRecorder::startPID(int pid)
372 int fd = m_demux->openDemux();
375 eDebug("FAILED to open demux in ts recoder (%m)");
379 #if HAVE_DVB_API_VERSION < 3
380 dmxPesFilterParams flt;
382 flt.pesType = DMX_PES_OTHER;
384 dmx_pes_filter_params flt;
386 flt.pes_type = DMX_PES_OTHER;
390 flt.input = DMX_IN_FRONTEND;
391 flt.output = DMX_OUT_TS_TAP;
393 flt.flags = DMX_IMMEDIATE_START;
395 int res = ::ioctl(fd, DMX_SET_PES_FILTER, &flt);
398 eDebug("set pes filter failed!");
407 void eDVBTSRecorder::stopPID(int pid)
409 ::close(m_pids[pid]);