9 #if HAVE_DVB_API_VERSION < 3
12 #ifndef DMX_SET_NEGFILTER_MASK
13 #define DMX_SET_NEGFILTER_MASK _IOW('o',48,uint8_t *)
19 unsigned int num; /* input : which STC? O..N */
20 unsigned int base; /* output: divisor for stc to get 90 kHz clock */
21 unsigned long long stc; /* output: src in 'base'*90 kHz units */
23 #define DMX_GET_STC _IOR('o', 50, struct dmx_stc)
27 #include <linux/dvb/dmx.h>
32 #include <lib/base/eerror.h>
33 #include <lib/base/filepush.h>
34 #include <lib/dvb/idvb.h>
35 #include <lib/dvb/demux.h>
36 #include <lib/dvb/esection.h>
37 #include <lib/dvb/decoder.h>
39 eDVBDemux::eDVBDemux(int adapter, int demux): adapter(adapter), demux(demux)
44 eDVBDemux::~eDVBDemux()
48 int eDVBDemux::openDemux(void)
51 #if HAVE_DVB_API_VERSION < 3
52 snprintf(filename, 128, "/dev/dvb/card%d/demux%d", adapter, demux);
54 snprintf(filename, 128, "/dev/dvb/adapter%d/demux%d", adapter, demux);
56 return ::open(filename, O_RDWR);
61 RESULT eDVBDemux::setSourceFrontend(int fenum)
63 #if HAVE_DVB_API_VERSION >= 3
66 int n = DMX_SOURCE_FRONT0 + fenum;
67 int res = ::ioctl(fd, DMX_SET_SOURCE, &n);
69 eDebug("DMX_SET_SOURCE failed! - %m");
76 RESULT eDVBDemux::setSourcePVR(int pvrnum)
78 #if HAVE_DVB_API_VERSION >= 3
80 int n = DMX_SOURCE_DVR0 + pvrnum;
81 int res = ::ioctl(fd, DMX_SET_SOURCE, &n);
88 RESULT eDVBDemux::createSectionReader(eMainloop *context, ePtr<iDVBSectionReader> &reader)
91 reader = new eDVBSectionReader(this, context, res);
97 RESULT eDVBDemux::createTSRecorder(ePtr<iDVBTSRecorder> &recorder)
101 recorder = new eDVBTSRecorder(this);
105 RESULT eDVBDemux::getMPEGDecoder(ePtr<iTSMPEGDecoder> &decoder)
107 decoder = new eTSMPEGDecoder(this, 0);
111 RESULT eDVBDemux::getSTC(pts_t &pts, int num)
113 int fd = openDemux();
122 if (ioctl(fd, DMX_GET_STC, &stc) < 0)
134 RESULT eDVBDemux::flush()
136 // FIXME: implement flushing the PVR queue here.
142 RESULT eDVBDemux::connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &conn)
144 conn = new eConnection(this, m_event.connect(event));
148 void eDVBSectionReader::data(int)
150 __u8 data[4096]; // max. section size
152 r = ::read(fd, data, 4096);
155 eWarning("ERROR reading section - %m\n");
160 // this check should never happen unless the driver is crappy!
162 if ((c = crc32((unsigned)-1, data, r)))
164 eDebug("crc32 failed! is %x\n", c);
171 eDebug("data.. but not active");
174 eDVBSectionReader::eDVBSectionReader(eDVBDemux *demux, eMainloop *context, RESULT &res): demux(demux)
177 fd = demux->openDemux();
181 notifier=new eSocketNotifier(context, fd, eSocketNotifier::Read, false);
182 CONNECT(notifier->activated, eDVBSectionReader::data);
191 DEFINE_REF(eDVBSectionReader)
193 eDVBSectionReader::~eDVBSectionReader()
201 RESULT eDVBSectionReader::start(const eDVBSectionFilterMask &mask)
208 #if HAVE_DVB_API_VERSION < 3
209 dmxSctFilterParams sct;
211 dmx_sct_filter_params sct;
215 #if HAVE_DVB_API_VERSION < 3
218 sct.flags = DMX_IMMEDIATE_START;
220 if (mask.flags & eDVBSectionFilterMask::rfCRC)
222 sct.flags |= DMX_CHECK_CRC;
227 memcpy(sct.filter.filter, mask.data, DMX_FILTER_SIZE);
228 memcpy(sct.filter.mask, mask.mask, DMX_FILTER_SIZE);
229 #if HAVE_DVB_API_VERSION >= 3
230 memcpy(sct.filter.mode, mask.mode, DMX_FILTER_SIZE);
231 if (::ioctl(fd, DMX_SET_BUFFER_SIZE, 8192*8) < 0)
232 eDebug("DMX_SET_BUFFER_SIZE failed(%m)");
235 res = ::ioctl(fd, DMX_SET_FILTER, &sct);
238 #if HAVE_DVB_API_VERSION < 3
239 res = ::ioctl(fd, DMX_SET_NEGFILTER_MASK, mask.mode);
242 res = ::ioctl(fd, DMX_START, 0);
253 RESULT eDVBSectionReader::stop()
259 ::ioctl(fd, DMX_STOP);
265 RESULT eDVBSectionReader::connectRead(const Slot1<void,const __u8*> &r, ePtr<eConnection> &conn)
267 conn = new eConnection(this, read.connect(r));
271 DEFINE_REF(eDVBTSRecorder);
273 eDVBTSRecorder::eDVBTSRecorder(eDVBDemux *demux): m_demux(demux)
278 m_thread = new eFilePushThread();
279 m_demux->m_dvr_busy = 1;
282 eDVBTSRecorder::~eDVBTSRecorder()
286 m_demux->m_dvr_busy = 0;
289 RESULT eDVBTSRecorder::start()
294 if (m_target_fd == -1)
298 #if HAVE_DVB_API_VERSION < 3
299 snprintf(filename, 128, "/dev/dvb/card%d/dvr%d", m_demux->adapter, m_demux->demux);
301 snprintf(filename, 128, "/dev/dvb/adapter%d/dvr%d", m_demux->adapter, m_demux->demux);
303 m_source_fd = ::open(filename, O_RDONLY);
307 eDebug("FAILED to open dvr (%s) in ts recoder (%m)", filename);
311 m_thread->start(m_source_fd, m_target_fd);
314 for (std::map<int,int>::iterator i(m_pids.begin()); i != m_pids.end(); ++i)
320 RESULT eDVBTSRecorder::addPID(int pid)
322 if (m_pids.find(pid) != m_pids.end())
325 m_pids.insert(std::pair<int,int>(pid, -1));
331 RESULT eDVBTSRecorder::removePID(int pid)
333 if (m_pids.find(pid) == m_pids.end())
343 RESULT eDVBTSRecorder::setFormat(int format)
351 RESULT eDVBTSRecorder::setTargetFD(int fd)
357 RESULT eDVBTSRecorder::setBoundary(off_t max)
359 return -1; // not yet implemented
362 RESULT eDVBTSRecorder::stop()
364 for (std::map<int,int>::iterator i(m_pids.begin()); i != m_pids.end(); ++i)
376 RESULT eDVBTSRecorder::connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &conn)
378 conn = new eConnection(this, m_event.connect(event));
382 RESULT eDVBTSRecorder::startPID(int pid)
384 int fd = m_demux->openDemux();
387 eDebug("FAILED to open demux in ts recoder (%m)");
391 #if HAVE_DVB_API_VERSION < 3
392 dmxPesFilterParams flt;
394 flt.pesType = DMX_PES_OTHER;
396 dmx_pes_filter_params flt;
398 flt.pes_type = DMX_PES_OTHER;
402 flt.input = DMX_IN_FRONTEND;
403 flt.output = DMX_OUT_TS_TAP;
405 flt.flags = DMX_IMMEDIATE_START;
407 int res = ::ioctl(fd, DMX_SET_PES_FILTER, &flt);
410 eDebug("set pes filter failed!");
419 void eDVBTSRecorder::stopPID(int pid)
421 if (m_pids[pid] != -1)
422 ::close(m_pids[pid]);