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()
39 RESULT eDVBDemux::createSectionReader(eMainloop *context, ePtr<iDVBSectionReader> &reader)
42 reader = new eDVBSectionReader(this, context, res);
48 RESULT eDVBDemux::createTSRecorder(ePtr<iDVBTSRecorder> &recorder)
52 recorder = new eDVBTSRecorder(this);
56 RESULT eDVBDemux::getMPEGDecoder(ePtr<iTSMPEGDecoder> &decoder)
58 decoder = new eTSMPEGDecoder(this, 0);
62 RESULT eDVBDemux::getSTC(pts_t &pts)
65 #if HAVE_DVB_API_VERSION < 3
66 sprintf(filename, "/dev/dvb/card%d/demux%d", adapter, demux);
68 sprintf(filename, "/dev/dvb/adapter%d/demux%d", adapter, demux);
70 int fd = ::open(filename, O_RDWR);
79 if (ioctl(fd, DMX_GET_STC, &stc) < 0)
91 RESULT eDVBDemux::flush()
93 // FIXME: implement flushing the PVR queue here.
99 RESULT eDVBDemux::connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &conn)
101 conn = new eConnection(this, m_event.connect(event));
105 void eDVBSectionReader::data(int)
107 __u8 data[4096]; // max. section size
109 r = ::read(fd, data, 4096);
112 eWarning("ERROR reading section - %m\n");
117 // this check should never happen unless the driver is crappy!
119 if ((c = crc32((unsigned)-1, data, r)))
121 eDebug("crc32 failed! is %x\n", c);
128 eDebug("data.. but not active");
131 eDVBSectionReader::eDVBSectionReader(eDVBDemux *demux, eMainloop *context, RESULT &res): demux(demux)
134 #if HAVE_DVB_API_VERSION < 3
135 sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
137 sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
139 fd = ::open(filename, O_RDWR);
141 eDebug("eDVBSectionReader has fd %d", fd);
145 notifier=new eSocketNotifier(context, fd, eSocketNotifier::Read, false);
146 CONNECT(notifier->activated, eDVBSectionReader::data);
155 DEFINE_REF(eDVBSectionReader)
157 eDVBSectionReader::~eDVBSectionReader()
165 RESULT eDVBSectionReader::start(const eDVBSectionFilterMask &mask)
172 #if HAVE_DVB_API_VERSION < 3
173 dmxSctFilterParams sct;
175 dmx_sct_filter_params sct;
179 #if HAVE_DVB_API_VERSION < 3
182 sct.flags = DMX_IMMEDIATE_START;
184 if (mask.flags & eDVBSectionFilterMask::rfCRC)
186 sct.flags |= DMX_CHECK_CRC;
191 memcpy(sct.filter.filter, mask.data, DMX_FILTER_SIZE);
192 memcpy(sct.filter.mask, mask.mask, DMX_FILTER_SIZE);
193 #if HAVE_DVB_API_VERSION >= 3
194 memcpy(sct.filter.mode, mask.mode, DMX_FILTER_SIZE);
197 res = ::ioctl(fd, DMX_SET_FILTER, &sct);
200 #if HAVE_DVB_API_VERSION < 3
201 res = ::ioctl(fd, DMX_SET_NEGFILTER_MASK, mask.mode);
204 res = ::ioctl(fd, DMX_START, 0);
215 RESULT eDVBSectionReader::stop()
221 ::ioctl(fd, DMX_STOP);
227 RESULT eDVBSectionReader::connectRead(const Slot1<void,const __u8*> &r, ePtr<eConnection> &conn)
229 conn = new eConnection(this, read.connect(r));
233 DEFINE_REF(eDVBTSRecorder);
235 eDVBTSRecorder::eDVBTSRecorder(eDVBDemux *demux): m_demux(demux)
240 m_thread = new eFilePushThread();
241 m_demux->m_dvr_busy = 1;
244 eDVBTSRecorder::~eDVBTSRecorder()
248 m_demux->m_dvr_busy = 0;
251 RESULT eDVBTSRecorder::start()
256 if (m_target_fd == -1)
260 #if HAVE_DVB_API_VERSION < 3
261 snprintf(filename, 128, "/dev/dvb/card%d/dvr%d", m_demux->adapter, m_demux->demux);
263 snprintf(filename, 128, "/dev/dvb/adapter%d/dvr%d", m_demux->adapter, m_demux->demux);
265 m_source_fd = ::open(filename, O_RDONLY);
269 eDebug("FAILED to open dvr (%s) in ts recoder (%m)", filename);
273 m_thread->start(m_source_fd, m_target_fd);
276 for (std::map<int,int>::iterator i(m_pids.begin()); i != m_pids.end(); ++i)
282 RESULT eDVBTSRecorder::addPID(int pid)
284 if (m_pids.find(pid) != m_pids.end())
287 m_pids.insert(std::pair<int,int>(pid, -1));
293 RESULT eDVBTSRecorder::removePID(int pid)
295 if (m_pids.find(pid) == m_pids.end())
305 RESULT eDVBTSRecorder::setFormat(int format)
313 RESULT eDVBTSRecorder::setTargetFD(int fd)
319 RESULT eDVBTSRecorder::setBoundary(off_t max)
321 return -1; // not yet implemented
324 RESULT eDVBTSRecorder::stop()
326 for (std::map<int,int>::iterator i(m_pids.begin()); i != m_pids.end(); ++i)
338 RESULT eDVBTSRecorder::connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &conn)
340 conn = new eConnection(this, m_event.connect(event));
344 RESULT eDVBTSRecorder::startPID(int pid)
347 #if HAVE_DVB_API_VERSION < 3
348 snprintf(filename, 128, "/dev/dvb/card%d/demux%d", m_demux->adapter, m_demux->demux);
350 snprintf(filename, 128, "/dev/dvb/adapter%d/demux%d", m_demux->adapter, m_demux->demux);
352 int fd = ::open(filename, O_RDWR);
355 eDebug("FAILED to open demux (%s) in ts recoder (%m)", filename);
359 #if HAVE_DVB_API_VERSION < 3
360 dmxPesFilterParams flt;
362 flt.pesType = DMX_PES_OTHER;
364 dmx_pes_filter_params flt;
366 flt.pes_type = DMX_PES_OTHER;
370 flt.input = DMX_IN_FRONTEND;
371 flt.output = DMX_OUT_TS_TAP;
373 flt.flags = DMX_IMMEDIATE_START;
375 int res = ::ioctl(fd, DMX_SET_PES_FILTER, &flt);
378 eDebug("set pes filter failed!");
387 void eDVBTSRecorder::stopPID(int pid)
389 ::close(m_pids[pid]);