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>
37 #include <lib/dvb/pvrparse.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 class eDVBRecordFileThread: public eFilePushThread
274 eDVBRecordFileThread();
275 void setTimingPID(int pid);
277 void saveTimingInformation(const std::string &filename);
279 void filterRecordData(const unsigned char *data, int len);
281 eMPEGStreamParserTS m_ts_parser;
282 eMPEGStreamInformation m_stream_info;
283 off_t m_current_offset;
287 eDVBRecordFileThread::eDVBRecordFileThread()
288 : m_ts_parser(m_stream_info)
290 m_current_offset = 0;
293 void eDVBRecordFileThread::setTimingPID(int pid)
295 m_ts_parser.setPid(pid);
298 void eDVBRecordFileThread::saveTimingInformation(const std::string &filename)
300 m_stream_info.save(filename.c_str());
303 void eDVBRecordFileThread::filterRecordData(const unsigned char *data, int len)
305 m_ts_parser.parseData(m_current_offset, data, len);
307 m_current_offset += len;
310 DEFINE_REF(eDVBTSRecorder);
312 eDVBTSRecorder::eDVBTSRecorder(eDVBDemux *demux): m_demux(demux)
316 m_thread = new eDVBRecordFileThread();
317 m_demux->m_dvr_busy = 1;
320 eDVBTSRecorder::~eDVBTSRecorder()
324 m_demux->m_dvr_busy = 0;
327 RESULT eDVBTSRecorder::start()
332 if (m_target_fd == -1)
336 #if HAVE_DVB_API_VERSION < 3
337 snprintf(filename, 128, "/dev/dvb/card%d/dvr%d", m_demux->adapter, m_demux->demux);
339 snprintf(filename, 128, "/dev/dvb/adapter%d/dvr%d", m_demux->adapter, m_demux->demux);
341 m_source_fd = ::open(filename, O_RDONLY);
345 eDebug("FAILED to open dvr (%s) in ts recoder (%m)", filename);
349 m_thread->start(m_source_fd, m_target_fd);
352 for (std::map<int,int>::iterator i(m_pids.begin()); i != m_pids.end(); ++i)
358 RESULT eDVBTSRecorder::addPID(int pid)
360 if (m_pids.find(pid) != m_pids.end())
363 m_pids.insert(std::pair<int,int>(pid, -1));
369 RESULT eDVBTSRecorder::removePID(int pid)
371 if (m_pids.find(pid) == m_pids.end())
381 RESULT eDVBTSRecorder::setTimingPID(int pid)
385 m_thread->setTimingPID(pid);
389 RESULT eDVBTSRecorder::setTargetFD(int fd)
395 RESULT eDVBTSRecorder::setTargetFilename(const char *filename)
397 m_target_filename = filename;
400 RESULT eDVBTSRecorder::setBoundary(off_t max)
402 return -1; // not yet implemented
405 RESULT eDVBTSRecorder::stop()
407 for (std::map<int,int>::iterator i(m_pids.begin()); i != m_pids.end(); ++i)
416 if (m_target_filename != "")
417 m_thread->saveTimingInformation(m_target_filename + ".ap");
422 RESULT eDVBTSRecorder::connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &conn)
424 conn = new eConnection(this, m_event.connect(event));
428 RESULT eDVBTSRecorder::startPID(int pid)
430 int fd = m_demux->openDemux();
433 eDebug("FAILED to open demux in ts recoder (%m)");
437 #if HAVE_DVB_API_VERSION < 3
438 dmxPesFilterParams flt;
440 flt.pesType = DMX_PES_OTHER;
442 dmx_pes_filter_params flt;
444 flt.pes_type = DMX_PES_OTHER;
448 flt.input = DMX_IN_FRONTEND;
449 flt.output = DMX_OUT_TS_TAP;
451 flt.flags = DMX_IMMEDIATE_START;
453 int res = ::ioctl(fd, DMX_SET_PES_FILTER, &flt);
456 eDebug("set pes filter failed!");
465 void eDVBTSRecorder::stopPID(int pid)
467 if (m_pids[pid] != -1)
468 ::close(m_pids[pid]);