improve filterRecordData
[enigma2.git] / lib / dvb / demux.cpp
index ca9736ce7048ddaf931f586b737a6934d5c6a3c1..b6143ddf438d24d93d9164601845061da0216b71 100644 (file)
@@ -144,12 +144,15 @@ RESULT eDVBDemux::getSTC(pts_t &pts, int num)
        
        if (ioctl(fd, DMX_GET_STC, &stc) < 0)
        {
+               eDebug("DMX_GET_STC failed!");
                ::close(fd);
                return -1;
        }
        
        pts = stc.stc;
        
+       eDebug("DMX_GET_STC - %lld", pts);
+       
        ::close(fd);
        return 0;
 }
@@ -295,18 +298,25 @@ void eDVBPESReader::data(int)
 {
        while (1)
        {
-               __u8 data[4096];
+               __u8 buffer[16384];
                int r;
-               r = ::read(m_fd, data, 4096);
+               r = ::read(m_fd, buffer, 16384);
                if (!r)
-                       break;
+                       return;
                if(r < 0)
                {
-                       eWarning("ERROR reading section - %m\n");
+                       if (errno == EAGAIN) /* ok */
+                               return;
+                       eWarning("ERROR reading PES (fd=%d) - %m", m_fd);
                        return;
                }
+
                if (m_active)
-                       m_read(data, r);
+                       m_read(buffer, r);
+               else
+                       eWarning("PES reader not active");
+               if (r != 16384)
+                       break;
        }
 }
 
@@ -317,6 +327,8 @@ eDVBPESReader::eDVBPESReader(eDVBDemux *demux, eMainloop *context, RESULT &res):
        
        if (m_fd >= 0)
        {
+               ::ioctl(m_fd, DMX_SET_BUFFER_SIZE, 64*1024);
+               ::fcntl(m_fd, F_SETFL, O_NONBLOCK);
                m_notifier = new eSocketNotifier(context, m_fd, eSocketNotifier::Read, false);
                CONNECT(m_notifier->activated, eDVBPESReader::data);
                res = 0;
@@ -362,6 +374,9 @@ RESULT eDVBPESReader::start(int pid)
        flt.flags   = DMX_IMMEDIATE_START;
 
        res = ::ioctl(m_fd, DMX_SET_PES_FILTER, &flt);
+       
+       if (res)
+               eWarning("PES filter: DMX_SET_PES_FILTER - %m");
        if (!res)
                m_active = 1;
        return res;
@@ -393,7 +408,7 @@ public:
        
        void saveTimingInformation(const std::string &filename);
 protected:
-       void filterRecordData(const unsigned char *data, int len);
+       int filterRecordData(const unsigned char *data, int len, size_t &current_span_remaining);
 private:
        eMPEGStreamParserTS m_ts_parser;
        eMPEGStreamInformation m_stream_info;
@@ -402,7 +417,7 @@ private:
 };
 
 eDVBRecordFileThread::eDVBRecordFileThread()
-       : m_ts_parser(m_stream_info)
+       :eFilePushThread(IOPRIO_CLASS_RT, 7), m_ts_parser(m_stream_info)
 {
        m_current_offset = 0;
 }
@@ -417,11 +432,13 @@ void eDVBRecordFileThread::saveTimingInformation(const std::string &filename)
        m_stream_info.save(filename.c_str());
 }
 
-void eDVBRecordFileThread::filterRecordData(const unsigned char *data, int len)
+int eDVBRecordFileThread::filterRecordData(const unsigned char *data, int len, size_t &current_span_remaining)
 {
        m_ts_parser.parseData(m_current_offset, data, len);
        
        m_current_offset += len;
+       
+       return len;
 }
 
 DEFINE_REF(eDVBTSRecorder);
@@ -431,6 +448,7 @@ eDVBTSRecorder::eDVBTSRecorder(eDVBDemux *demux): m_demux(demux)
        m_running = 0;
        m_target_fd = -1;
        m_thread = new eDVBRecordFileThread();
+  CONNECT(m_thread->m_event, eDVBTSRecorder::filepushEvent);
 #ifndef HAVE_ADD_PID
        m_demux->m_dvr_busy = 1;
 #endif
@@ -636,3 +654,13 @@ void eDVBTSRecorder::stopPID(int pid)
 #endif
        m_pids[pid] = -1;
 }
+
+void eDVBTSRecorder::filepushEvent(int event)
+{
+       switch (event)
+       {
+       case eFilePushThread::evtWriteError:
+               m_event(eventWriteError);
+               break;
+       }
+}