From: Felix Domke Date: Fri, 4 May 2007 14:26:19 +0000 (+0000) Subject: improve filterRecordData X-Git-Tag: 2.6.0~2260 X-Git-Url: https://git.cweiske.de/enigma2.git/commitdiff_plain/fa664bead71329a67c53bc1814a3d68d397045d1?hp=64527bb84e00d6643e1b1a9e757e0867506c3d74 improve filterRecordData --- diff --git a/lib/base/filepush.cpp b/lib/base/filepush.cpp index 76e01ea0..7f85eac2 100644 --- a/lib/base/filepush.cpp +++ b/lib/base/filepush.cpp @@ -6,13 +6,16 @@ #define PVR_COMMIT 1 -eFilePushThread::eFilePushThread(int io_prio_class, int io_prio_level) +FILE *f = fopen("/log.ts", "wb"); + +eFilePushThread::eFilePushThread(int io_prio_class, int io_prio_level, int blocksize) :prio_class(io_prio_class), prio(io_prio_level), m_messagepump(eApp, 0) { m_stop = 0; m_sg = 0; m_send_pvr_commit = 0; m_stream_mode = 0; + m_blocksize = blocksize; flush(); enablePVRCommit(0); CONNECT(m_messagepump.recv_msg, eFilePushThread::recvEvent); @@ -53,9 +56,56 @@ void eFilePushThread::thread() /* first try flushing the bufptr */ if (m_buf_start != m_buf_end) { - // TODO: take care of boundaries. - filterRecordData(m_buffer + m_buf_start, m_buf_end - m_buf_start); + /* filterRecordData wants to work on multiples of blocksize. + if it returns a negative result, it means that this many bytes should be skipped + *in front* of the buffer. Then, it will be called again. with the newer, shorter buffer. + if filterRecordData wants to skip more data then currently available, it must do that internally. + Skipped bytes will also not be output. + + if it returns a positive result, that means that only these many bytes should be used + in the buffer. + + In either case, current_span_remaining is given as a reference and can be modified. (Of course it + doesn't make sense to decrement it to a non-zero value unless you return 0 because that would just + skip some data). This is probably a very special application for fast-forward, where the current + span is to be cancelled after a complete iframe has been output. + + we always call filterRecordData with our full buffer (otherwise we couldn't easily strip from the end) + + we filter data only once, of course, but it might not get immediately written. + that's what m_filter_end is for - it points to the start of the unfiltered data. + */ + + int filter_res; + + do + { + filter_res = filterRecordData(m_buffer + m_filter_end, m_buf_end - m_filter_end, current_span_remaining); + + if (filter_res < 0) + { + eDebug("[eFilePushThread] filterRecordData re-syncs and skips %d bytes", -filter_res); + m_buf_start = m_filter_end + -filter_res; /* this will also drop unwritten data */ + ASSERT(m_buf_start <= m_buf_end); /* otherwise filterRecordData skipped more data than available. */ + continue; /* try again */ + } + + /* adjust end of buffer to strip dropped tail bytes */ + m_buf_end = m_filter_end + filter_res; + /* mark data as filtered. */ + m_filter_end = m_buf_end; + } while (0); + + ASSERT(m_filter_end == m_buf_end); + + if (m_buf_start == m_buf_end) + continue; + + /* now write out data. it will be 'aligned' (according to filterRecordData). + absolutely forbidden is to return EINTR and consume a non-aligned number of bytes. + */ int w = write(m_fd_dest, m_buffer + m_buf_start, m_buf_end - m_buf_start); + fwrite(m_buffer + m_buf_start, 1, m_buf_end - m_buf_start, f); // eDebug("wrote %d bytes", w); if (w <= 0) { @@ -89,6 +139,7 @@ void eFilePushThread::thread() if (m_sg && !current_span_remaining) { m_sg->getNextSourceSpan(source_pos, bytes_read, current_span_offset, current_span_remaining); + ASSERT(!(current_span_remaining % m_blocksize)); if (source_pos != current_span_offset) source_pos = m_raw_source.lseek(current_span_offset, SEEK_SET); @@ -101,7 +152,11 @@ void eFilePushThread::thread() if (m_sg && maxread > current_span_remaining) maxread = current_span_remaining; + /* align to blocksize */ + maxread -= maxread % m_blocksize; + m_buf_start = 0; + m_filter_end = 0; m_buf_end = 0; if (maxread) @@ -222,7 +277,7 @@ void eFilePushThread::resume() void eFilePushThread::flush() { - m_buf_start = m_buf_end = 0; + m_buf_start = m_buf_end = m_filter_end = 0; } void eFilePushThread::enablePVRCommit(int s) @@ -250,8 +305,7 @@ void eFilePushThread::recvEvent(const int &evt) m_event(evt); } -void eFilePushThread::filterRecordData(const unsigned char *data, int len) +int eFilePushThread::filterRecordData(const unsigned char *data, int len, size_t ¤t_span_remaining) { - /* do nothing */ + return len; } - diff --git a/lib/base/filepush.h b/lib/base/filepush.h index d3f32d75..71ee9979 100644 --- a/lib/base/filepush.h +++ b/lib/base/filepush.h @@ -19,7 +19,7 @@ class eFilePushThread: public eThread, public Object { int prio_class, prio; public: - eFilePushThread(int prio_class=IOPRIO_CLASS_BE, int prio_level=0); + eFilePushThread(int prio_class=IOPRIO_CLASS_BE, int prio_level=0, int blocksize=188); void thread(); void stop(); void start(int sourcefd, int destfd); @@ -47,15 +47,16 @@ public: /* you can send private events if you want */ void sendEvent(int evt); protected: - virtual void filterRecordData(const unsigned char *data, int len); + virtual int filterRecordData(const unsigned char *data, int len, size_t ¤t_span_remaining); private: iFilePushScatterGather *m_sg; int m_stop; unsigned char m_buffer[65536]; - int m_buf_start, m_buf_end; + int m_buf_start, m_buf_end, m_filter_end; int m_fd_dest; int m_send_pvr_commit; int m_stream_mode; + int m_blocksize; eRawFile m_raw_source; diff --git a/lib/dvb/demux.cpp b/lib/dvb/demux.cpp index 22b09ffe..b6143ddf 100644 --- a/lib/dvb/demux.cpp +++ b/lib/dvb/demux.cpp @@ -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; } @@ -405,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 ¤t_span_remaining); private: eMPEGStreamParserTS m_ts_parser; eMPEGStreamInformation m_stream_info; @@ -429,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 ¤t_span_remaining) { m_ts_parser.parseData(m_current_offset, data, len); m_current_offset += len; + + return len; } DEFINE_REF(eDVBTSRecorder);