#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);
/* 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)
{
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);
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)
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)
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;
}
-
{
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);
/* 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;
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;
}
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;
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);