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()
37 int eDVBDemux::openDemux(void)
40 #if HAVE_DVB_API_VERSION < 3
41 snprintf(filename, 128, "/dev/dvb/card%d/demux%d", adapter, demux);
43 snprintf(filename, 128, "/dev/dvb/adapter%d/demux%d", adapter, demux);
45 return ::open(filename, O_RDWR);
50 RESULT eDVBDemux::setSourceFrontend(int fenum)
53 int res = ::ioctl(fd, DMX_SET_SOURCE, DMX_SOURCE_FRONT0 + fenum);
58 RESULT eDVBDemux::setSourcePVR(int pvrnum)
61 int res = ::ioctl(fd, DMX_SET_SOURCE, DMX_SOURCE_DVR0 + pvrnum);
66 RESULT eDVBDemux::createSectionReader(eMainloop *context, ePtr<iDVBSectionReader> &reader)
69 reader = new eDVBSectionReader(this, context, res);
75 RESULT eDVBDemux::createTSRecorder(ePtr<iDVBTSRecorder> &recorder)
79 recorder = new eDVBTSRecorder(this);
83 RESULT eDVBDemux::getMPEGDecoder(ePtr<iTSMPEGDecoder> &decoder)
85 decoder = new eTSMPEGDecoder(this, 0);
89 RESULT eDVBDemux::getSTC(pts_t &pts)
100 if (ioctl(fd, DMX_GET_STC, &stc) < 0)
112 RESULT eDVBDemux::flush()
114 // FIXME: implement flushing the PVR queue here.
120 RESULT eDVBDemux::connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &conn)
122 conn = new eConnection(this, m_event.connect(event));
126 void eDVBSectionReader::data(int)
128 __u8 data[4096]; // max. section size
130 r = ::read(fd, data, 4096);
133 eWarning("ERROR reading section - %m\n");
138 // this check should never happen unless the driver is crappy!
140 if ((c = crc32((unsigned)-1, data, r)))
142 eDebug("crc32 failed! is %x\n", c);
149 eDebug("data.. but not active");
152 eDVBSectionReader::eDVBSectionReader(eDVBDemux *demux, eMainloop *context, RESULT &res): demux(demux)
155 fd = demux->openDemux();
159 notifier=new eSocketNotifier(context, fd, eSocketNotifier::Read, false);
160 CONNECT(notifier->activated, eDVBSectionReader::data);
169 DEFINE_REF(eDVBSectionReader)
171 eDVBSectionReader::~eDVBSectionReader()
179 RESULT eDVBSectionReader::start(const eDVBSectionFilterMask &mask)
186 #if HAVE_DVB_API_VERSION < 3
187 dmxSctFilterParams sct;
189 dmx_sct_filter_params sct;
193 #if HAVE_DVB_API_VERSION < 3
196 sct.flags = DMX_IMMEDIATE_START;
198 if (mask.flags & eDVBSectionFilterMask::rfCRC)
200 sct.flags |= DMX_CHECK_CRC;
205 memcpy(sct.filter.filter, mask.data, DMX_FILTER_SIZE);
206 memcpy(sct.filter.mask, mask.mask, DMX_FILTER_SIZE);
207 #if HAVE_DVB_API_VERSION >= 3
208 memcpy(sct.filter.mode, mask.mode, DMX_FILTER_SIZE);
209 if (::ioctl(fd, DMX_SET_BUFFER_SIZE, 8192*8) < 0)
210 eDebug("DMX_SET_BUFFER_SIZE failed(%m)");
213 res = ::ioctl(fd, DMX_SET_FILTER, &sct);
216 #if HAVE_DVB_API_VERSION < 3
217 res = ::ioctl(fd, DMX_SET_NEGFILTER_MASK, mask.mode);
220 res = ::ioctl(fd, DMX_START, 0);
231 RESULT eDVBSectionReader::stop()
237 ::ioctl(fd, DMX_STOP);
243 RESULT eDVBSectionReader::connectRead(const Slot1<void,const __u8*> &r, ePtr<eConnection> &conn)
245 conn = new eConnection(this, read.connect(r));
249 DEFINE_REF(eDVBTSRecorder);
251 eDVBTSRecorder::eDVBTSRecorder(eDVBDemux *demux): m_demux(demux)
256 m_thread = new eFilePushThread();
257 m_demux->m_dvr_busy = 1;
260 eDVBTSRecorder::~eDVBTSRecorder()
264 m_demux->m_dvr_busy = 0;
267 RESULT eDVBTSRecorder::start()
272 if (m_target_fd == -1)
276 #if HAVE_DVB_API_VERSION < 3
277 snprintf(filename, 128, "/dev/dvb/card%d/dvr%d", m_demux->adapter, m_demux->demux);
279 snprintf(filename, 128, "/dev/dvb/adapter%d/dvr%d", m_demux->adapter, m_demux->demux);
281 m_source_fd = ::open(filename, O_RDONLY);
285 eDebug("FAILED to open dvr (%s) in ts recoder (%m)", filename);
289 m_thread->start(m_source_fd, m_target_fd);
292 for (std::map<int,int>::iterator i(m_pids.begin()); i != m_pids.end(); ++i)
298 RESULT eDVBTSRecorder::addPID(int pid)
300 if (m_pids.find(pid) != m_pids.end())
303 m_pids.insert(std::pair<int,int>(pid, -1));
309 RESULT eDVBTSRecorder::removePID(int pid)
311 if (m_pids.find(pid) == m_pids.end())
321 RESULT eDVBTSRecorder::setFormat(int format)
329 RESULT eDVBTSRecorder::setTargetFD(int fd)
335 RESULT eDVBTSRecorder::setBoundary(off_t max)
337 return -1; // not yet implemented
340 RESULT eDVBTSRecorder::stop()
342 for (std::map<int,int>::iterator i(m_pids.begin()); i != m_pids.end(); ++i)
354 RESULT eDVBTSRecorder::connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &conn)
356 conn = new eConnection(this, m_event.connect(event));
360 RESULT eDVBTSRecorder::startPID(int pid)
362 int fd = m_demux->openDemux();
365 eDebug("FAILED to open demux in ts recoder (%m)");
369 #if HAVE_DVB_API_VERSION < 3
370 dmxPesFilterParams flt;
372 flt.pesType = DMX_PES_OTHER;
374 dmx_pes_filter_params flt;
376 flt.pes_type = DMX_PES_OTHER;
380 flt.input = DMX_IN_FRONTEND;
381 flt.output = DMX_OUT_TS_TAP;
383 flt.flags = DMX_IMMEDIATE_START;
385 int res = ::ioctl(fd, DMX_SET_PES_FILTER, &flt);
388 eDebug("set pes filter failed!");
397 void eDVBTSRecorder::stopPID(int pid)
399 ::close(m_pids[pid]);