make filterRecordData argument unsigned char*
[enigma2.git] / lib / dvb / demux.cpp
index d7fcaccf31ae3db2518da3e12acdb36d1dcc7201..73e0443291772fee99c4d6ba025c48a30dcc6160 100644 (file)
@@ -1,4 +1,3 @@
-#include <config.h>
 #include <stdio.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
@@ -8,9 +7,21 @@
 
 #if HAVE_DVB_API_VERSION < 3
 #include <ost/dmx.h>
+
 #ifndef DMX_SET_NEGFILTER_MASK
        #define DMX_SET_NEGFILTER_MASK   _IOW('o',48,uint8_t *)
 #endif
+
+#ifndef DMX_GET_STC
+       struct dmx_stc
+       {
+               unsigned int num;       /* input : which STC? O..N */
+               unsigned int base;      /* output: divisor for stc to get 90 kHz clock */
+               unsigned long long stc; /* output: src in 'base'*90 kHz units */
+       };
+       #define DMX_GET_STC             _IOR('o', 50, struct dmx_stc)
+#endif
+
 #else
 #include <linux/dvb/dmx.h>
 #endif
@@ -23,6 +34,7 @@
 #include <lib/dvb/demux.h>
 #include <lib/dvb/esection.h>
 #include <lib/dvb/decoder.h>
+#include <lib/dvb/pvrparse.h>
 
 eDVBDemux::eDVBDemux(int adapter, int demux): adapter(adapter), demux(demux)
 {
@@ -96,7 +108,7 @@ RESULT eDVBDemux::getMPEGDecoder(ePtr<iTSMPEGDecoder> &decoder)
        return 0;
 }
 
-RESULT eDVBDemux::getSTC(pts_t &pts)
+RESULT eDVBDemux::getSTC(pts_t &pts, int num)
 {
        int fd = openDemux();
        
@@ -104,7 +116,7 @@ RESULT eDVBDemux::getSTC(pts_t &pts)
                return -ENODEV;
 
        struct dmx_stc stc;
-       stc.num = 0;
+       stc.num = num;
        stc.base = 1;
        
        if (ioctl(fd, DMX_GET_STC, &stc) < 0)
@@ -256,14 +268,45 @@ RESULT eDVBSectionReader::connectRead(const Slot1<void,const __u8*> &r, ePtr<eCo
        return 0;
 }
 
+class eDVBRecordFileThread: public eFilePushThread
+{
+public:
+       eDVBRecordFileThread();
+       void setTimingPID(int pid);
+protected:
+       void filterRecordData(const unsigned char *data, int len);
+private:
+       eMPEGStreamParserTS m_ts_parser;
+       eMPEGStreamInformation m_stream_info;
+       off_t m_current_offset;
+       int m_pid;
+};
+
+eDVBRecordFileThread::eDVBRecordFileThread()
+       : m_ts_parser(m_stream_info)
+{
+       m_current_offset = 0;
+}
+
+void eDVBRecordFileThread::setTimingPID(int pid)
+{
+       m_ts_parser.setPid(pid);
+}
+
+void eDVBRecordFileThread::filterRecordData(const unsigned char *data, int len)
+{
+       m_ts_parser.parseData(m_current_offset, data, len);
+       
+       m_current_offset += len;
+}
+
 DEFINE_REF(eDVBTSRecorder);
 
 eDVBTSRecorder::eDVBTSRecorder(eDVBDemux *demux): m_demux(demux)
 {
        m_running = 0;
-       m_format = 0;
        m_target_fd = -1;
-       m_thread = new eFilePushThread();
+       m_thread = new eDVBRecordFileThread();
        m_demux->m_dvr_busy = 1;
 }
 
@@ -328,11 +371,11 @@ RESULT eDVBTSRecorder::removePID(int pid)
        return 0;
 }
 
-RESULT eDVBTSRecorder::setFormat(int format)
+RESULT eDVBTSRecorder::setTimingPID(int pid)
 {
        if (m_running)
                return -1;
-       m_format = format;
+       m_thread->setTimingPID(pid);
        return 0;
 }
 
@@ -406,6 +449,7 @@ RESULT eDVBTSRecorder::startPID(int pid)
 
 void eDVBTSRecorder::stopPID(int pid)
 {
-       ::close(m_pids[pid]);
+       if (m_pids[pid] != -1)
+               ::close(m_pids[pid]);
        m_pids[pid] = -1;
 }