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
53 int res = ::ioctl(fd, DMX_SET_SOURCE, DMX_SOURCE_FRONT0 + fenum);
60 RESULT eDVBDemux::setSourcePVR(int pvrnum)
62 #if HAVE_DVB_API_VERSION >= 3
64 int res = ::ioctl(fd, DMX_SET_SOURCE, DMX_SOURCE_DVR0 + pvrnum);
71 RESULT eDVBDemux::createSectionReader(eMainloop *context, ePtr<iDVBSectionReader> &reader)
74 reader = new eDVBSectionReader(this, context, res);
80 RESULT eDVBDemux::createTSRecorder(ePtr<iDVBTSRecorder> &recorder)
84 recorder = new eDVBTSRecorder(this);
88 RESULT eDVBDemux::getMPEGDecoder(ePtr<iTSMPEGDecoder> &decoder)
90 decoder = new eTSMPEGDecoder(this, 0);
94 RESULT eDVBDemux::getSTC(pts_t &pts)
105 if (ioctl(fd, DMX_GET_STC, &stc) < 0)
117 RESULT eDVBDemux::flush()
119 // FIXME: implement flushing the PVR queue here.
125 RESULT eDVBDemux::connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &conn)
127 conn = new eConnection(this, m_event.connect(event));
131 void eDVBSectionReader::data(int)
133 __u8 data[4096]; // max. section size
135 r = ::read(fd, data, 4096);
138 eWarning("ERROR reading section - %m\n");
143 // this check should never happen unless the driver is crappy!
145 if ((c = crc32((unsigned)-1, data, r)))
147 eDebug("crc32 failed! is %x\n", c);
154 eDebug("data.. but not active");
157 eDVBSectionReader::eDVBSectionReader(eDVBDemux *demux, eMainloop *context, RESULT &res): demux(demux)
160 fd = demux->openDemux();
164 notifier=new eSocketNotifier(context, fd, eSocketNotifier::Read, false);
165 CONNECT(notifier->activated, eDVBSectionReader::data);
174 DEFINE_REF(eDVBSectionReader)
176 eDVBSectionReader::~eDVBSectionReader()
184 RESULT eDVBSectionReader::start(const eDVBSectionFilterMask &mask)
191 #if HAVE_DVB_API_VERSION < 3
192 dmxSctFilterParams sct;
194 dmx_sct_filter_params sct;
198 #if HAVE_DVB_API_VERSION < 3
201 sct.flags = DMX_IMMEDIATE_START;
203 if (mask.flags & eDVBSectionFilterMask::rfCRC)
205 sct.flags |= DMX_CHECK_CRC;
210 memcpy(sct.filter.filter, mask.data, DMX_FILTER_SIZE);
211 memcpy(sct.filter.mask, mask.mask, DMX_FILTER_SIZE);
212 #if HAVE_DVB_API_VERSION >= 3
213 memcpy(sct.filter.mode, mask.mode, DMX_FILTER_SIZE);
214 if (::ioctl(fd, DMX_SET_BUFFER_SIZE, 8192*8) < 0)
215 eDebug("DMX_SET_BUFFER_SIZE failed(%m)");
218 res = ::ioctl(fd, DMX_SET_FILTER, &sct);
221 #if HAVE_DVB_API_VERSION < 3
222 res = ::ioctl(fd, DMX_SET_NEGFILTER_MASK, mask.mode);
225 res = ::ioctl(fd, DMX_START, 0);
236 RESULT eDVBSectionReader::stop()
242 ::ioctl(fd, DMX_STOP);
248 RESULT eDVBSectionReader::connectRead(const Slot1<void,const __u8*> &r, ePtr<eConnection> &conn)
250 conn = new eConnection(this, read.connect(r));
254 DEFINE_REF(eDVBTSRecorder);
256 eDVBTSRecorder::eDVBTSRecorder(eDVBDemux *demux): m_demux(demux)
261 m_thread = new eFilePushThread();
262 m_demux->m_dvr_busy = 1;
265 eDVBTSRecorder::~eDVBTSRecorder()
269 m_demux->m_dvr_busy = 0;
272 RESULT eDVBTSRecorder::start()
277 if (m_target_fd == -1)
281 #if HAVE_DVB_API_VERSION < 3
282 snprintf(filename, 128, "/dev/dvb/card%d/dvr%d", m_demux->adapter, m_demux->demux);
284 snprintf(filename, 128, "/dev/dvb/adapter%d/dvr%d", m_demux->adapter, m_demux->demux);
286 m_source_fd = ::open(filename, O_RDONLY);
290 eDebug("FAILED to open dvr (%s) in ts recoder (%m)", filename);
294 m_thread->start(m_source_fd, m_target_fd);
297 for (std::map<int,int>::iterator i(m_pids.begin()); i != m_pids.end(); ++i)
303 RESULT eDVBTSRecorder::addPID(int pid)
305 if (m_pids.find(pid) != m_pids.end())
308 m_pids.insert(std::pair<int,int>(pid, -1));
314 RESULT eDVBTSRecorder::removePID(int pid)
316 if (m_pids.find(pid) == m_pids.end())
326 RESULT eDVBTSRecorder::setFormat(int format)
334 RESULT eDVBTSRecorder::setTargetFD(int fd)
340 RESULT eDVBTSRecorder::setBoundary(off_t max)
342 return -1; // not yet implemented
345 RESULT eDVBTSRecorder::stop()
347 for (std::map<int,int>::iterator i(m_pids.begin()); i != m_pids.end(); ++i)
359 RESULT eDVBTSRecorder::connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &conn)
361 conn = new eConnection(this, m_event.connect(event));
365 RESULT eDVBTSRecorder::startPID(int pid)
367 int fd = m_demux->openDemux();
370 eDebug("FAILED to open demux in ts recoder (%m)");
374 #if HAVE_DVB_API_VERSION < 3
375 dmxPesFilterParams flt;
377 flt.pesType = DMX_PES_OTHER;
379 dmx_pes_filter_params flt;
381 flt.pes_type = DMX_PES_OTHER;
385 flt.input = DMX_IN_FRONTEND;
386 flt.output = DMX_OUT_TS_TAP;
388 flt.flags = DMX_IMMEDIATE_START;
390 int res = ::ioctl(fd, DMX_SET_PES_FILTER, &flt);
393 eDebug("set pes filter failed!");
402 void eDVBTSRecorder::stopPID(int pid)
404 ::close(m_pids[pid]);