8 #if HAVE_DVB_API_VERSION < 3
11 #ifndef DMX_SET_NEGFILTER_MASK
12 #define DMX_SET_NEGFILTER_MASK _IOW('o',48,uint8_t *)
18 unsigned int num; /* input : which STC? O..N */
19 unsigned int base; /* output: divisor for stc to get 90 kHz clock */
20 unsigned long long stc; /* output: src in 'base'*90 kHz units */
22 #define DMX_GET_STC _IOR('o', 50, struct dmx_stc)
26 #include <linux/dvb/dmx.h>
31 #include <lib/base/eerror.h>
32 #include <lib/base/filepush.h>
33 #include <lib/dvb/idvb.h>
34 #include <lib/dvb/demux.h>
35 #include <lib/dvb/esection.h>
36 #include <lib/dvb/decoder.h>
38 eDVBDemux::eDVBDemux(int adapter, int demux): adapter(adapter), demux(demux)
43 eDVBDemux::~eDVBDemux()
47 int eDVBDemux::openDemux(void)
50 #if HAVE_DVB_API_VERSION < 3
51 snprintf(filename, 128, "/dev/dvb/card%d/demux%d", adapter, demux);
53 snprintf(filename, 128, "/dev/dvb/adapter%d/demux%d", adapter, demux);
55 return ::open(filename, O_RDWR);
60 RESULT eDVBDemux::setSourceFrontend(int fenum)
62 #if HAVE_DVB_API_VERSION >= 3
65 int n = DMX_SOURCE_FRONT0 + fenum;
66 int res = ::ioctl(fd, DMX_SET_SOURCE, &n);
68 eDebug("DMX_SET_SOURCE failed! - %m");
75 RESULT eDVBDemux::setSourcePVR(int pvrnum)
77 #if HAVE_DVB_API_VERSION >= 3
79 int n = DMX_SOURCE_DVR0 + pvrnum;
80 int res = ::ioctl(fd, DMX_SET_SOURCE, &n);
87 RESULT eDVBDemux::createSectionReader(eMainloop *context, ePtr<iDVBSectionReader> &reader)
90 reader = new eDVBSectionReader(this, context, res);
96 RESULT eDVBDemux::createTSRecorder(ePtr<iDVBTSRecorder> &recorder)
100 recorder = new eDVBTSRecorder(this);
104 RESULT eDVBDemux::getMPEGDecoder(ePtr<iTSMPEGDecoder> &decoder)
106 decoder = new eTSMPEGDecoder(this, 0);
110 RESULT eDVBDemux::getSTC(pts_t &pts, int num)
112 int fd = openDemux();
121 if (ioctl(fd, DMX_GET_STC, &stc) < 0)
133 RESULT eDVBDemux::flush()
135 // FIXME: implement flushing the PVR queue here.
141 RESULT eDVBDemux::connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &conn)
143 conn = new eConnection(this, m_event.connect(event));
147 void eDVBSectionReader::data(int)
149 __u8 data[4096]; // max. section size
151 r = ::read(fd, data, 4096);
154 eWarning("ERROR reading section - %m\n");
159 // this check should never happen unless the driver is crappy!
161 if ((c = crc32((unsigned)-1, data, r)))
163 eDebug("crc32 failed! is %x\n", c);
170 eDebug("data.. but not active");
173 eDVBSectionReader::eDVBSectionReader(eDVBDemux *demux, eMainloop *context, RESULT &res): demux(demux)
176 fd = demux->openDemux();
180 notifier=new eSocketNotifier(context, fd, eSocketNotifier::Read, false);
181 CONNECT(notifier->activated, eDVBSectionReader::data);
190 DEFINE_REF(eDVBSectionReader)
192 eDVBSectionReader::~eDVBSectionReader()
200 RESULT eDVBSectionReader::start(const eDVBSectionFilterMask &mask)
207 #if HAVE_DVB_API_VERSION < 3
208 dmxSctFilterParams sct;
210 dmx_sct_filter_params sct;
214 #if HAVE_DVB_API_VERSION < 3
217 sct.flags = DMX_IMMEDIATE_START;
219 if (mask.flags & eDVBSectionFilterMask::rfCRC)
221 sct.flags |= DMX_CHECK_CRC;
226 memcpy(sct.filter.filter, mask.data, DMX_FILTER_SIZE);
227 memcpy(sct.filter.mask, mask.mask, DMX_FILTER_SIZE);
228 #if HAVE_DVB_API_VERSION >= 3
229 memcpy(sct.filter.mode, mask.mode, DMX_FILTER_SIZE);
230 if (::ioctl(fd, DMX_SET_BUFFER_SIZE, 8192*8) < 0)
231 eDebug("DMX_SET_BUFFER_SIZE failed(%m)");
234 res = ::ioctl(fd, DMX_SET_FILTER, &sct);
237 #if HAVE_DVB_API_VERSION < 3
238 res = ::ioctl(fd, DMX_SET_NEGFILTER_MASK, mask.mode);
241 res = ::ioctl(fd, DMX_START, 0);
252 RESULT eDVBSectionReader::stop()
258 ::ioctl(fd, DMX_STOP);
264 RESULT eDVBSectionReader::connectRead(const Slot1<void,const __u8*> &r, ePtr<eConnection> &conn)
266 conn = new eConnection(this, read.connect(r));
270 DEFINE_REF(eDVBTSRecorder);
272 eDVBTSRecorder::eDVBTSRecorder(eDVBDemux *demux): m_demux(demux)
277 m_thread = new eFilePushThread();
278 m_demux->m_dvr_busy = 1;
281 eDVBTSRecorder::~eDVBTSRecorder()
285 m_demux->m_dvr_busy = 0;
288 RESULT eDVBTSRecorder::start()
293 if (m_target_fd == -1)
297 #if HAVE_DVB_API_VERSION < 3
298 snprintf(filename, 128, "/dev/dvb/card%d/dvr%d", m_demux->adapter, m_demux->demux);
300 snprintf(filename, 128, "/dev/dvb/adapter%d/dvr%d", m_demux->adapter, m_demux->demux);
302 m_source_fd = ::open(filename, O_RDONLY);
306 eDebug("FAILED to open dvr (%s) in ts recoder (%m)", filename);
310 m_thread->start(m_source_fd, m_target_fd);
313 for (std::map<int,int>::iterator i(m_pids.begin()); i != m_pids.end(); ++i)
319 RESULT eDVBTSRecorder::addPID(int pid)
321 if (m_pids.find(pid) != m_pids.end())
324 m_pids.insert(std::pair<int,int>(pid, -1));
330 RESULT eDVBTSRecorder::removePID(int pid)
332 if (m_pids.find(pid) == m_pids.end())
342 RESULT eDVBTSRecorder::setFormat(int format)
350 RESULT eDVBTSRecorder::setTargetFD(int fd)
356 RESULT eDVBTSRecorder::setBoundary(off_t max)
358 return -1; // not yet implemented
361 RESULT eDVBTSRecorder::stop()
363 for (std::map<int,int>::iterator i(m_pids.begin()); i != m_pids.end(); ++i)
375 RESULT eDVBTSRecorder::connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &conn)
377 conn = new eConnection(this, m_event.connect(event));
381 RESULT eDVBTSRecorder::startPID(int pid)
383 int fd = m_demux->openDemux();
386 eDebug("FAILED to open demux in ts recoder (%m)");
390 #if HAVE_DVB_API_VERSION < 3
391 dmxPesFilterParams flt;
393 flt.pesType = DMX_PES_OTHER;
395 dmx_pes_filter_params flt;
397 flt.pes_type = DMX_PES_OTHER;
401 flt.input = DMX_IN_FRONTEND;
402 flt.output = DMX_OUT_TS_TAP;
404 flt.flags = DMX_IMMEDIATE_START;
406 int res = ::ioctl(fd, DMX_SET_PES_FILTER, &flt);
409 eDebug("set pes filter failed!");
418 void eDVBTSRecorder::stopPID(int pid)
420 if (m_pids[pid] != -1)
421 ::close(m_pids[pid]);