get rid of hardcoded TS packetsize
authorpieterg <pieterg@users.sourceforge.net>
Thu, 23 Jul 2015 18:56:58 +0000 (20:56 +0200)
committerpieterg <pieterg@users.sourceforge.net>
Thu, 23 Jul 2015 19:02:07 +0000 (21:02 +0200)
lib/base/filepush.cpp
lib/base/filepush.h
lib/dvb/dvb.cpp
lib/dvb/dvb.h
lib/dvb/tstools.cpp
lib/dvb/tstools.h
lib/service/servicedvbrecord.cpp

index 74708a3..0d473d5 100644 (file)
@@ -62,7 +62,7 @@ void eFilePushThread::thread()
        {
                if (m_sg && !current_span_remaining)
                {
-                       m_sg->getNextSourceSpan(m_current_position, bytes_read, current_span_offset, current_span_remaining);
+                       m_sg->getNextSourceSpan(m_current_position, bytes_read, current_span_offset, current_span_remaining, m_blocksize);
                        ASSERT(!(current_span_remaining % m_blocksize));
                        m_current_position = current_span_offset;
                        bytes_read = 0;
index 47ec4ed..22af20e 100644 (file)
@@ -11,7 +11,7 @@
 class iFilePushScatterGather
 {
 public:
-       virtual void getNextSourceSpan(off_t current_offset, size_t bytes_read, off_t &start, size_t &size)=0;
+       virtual void getNextSourceSpan(off_t current_offset, size_t bytes_read, off_t &start, size_t &size, int blocksize)=0;
        virtual ~iFilePushScatterGather() {}
 };
 
index ceff939..a90023f 100644 (file)
@@ -1646,9 +1646,8 @@ static size_t diff_upto(off_t high, off_t low, size_t max)
 }
 
        /* remember, this gets called from another thread. */
-void eDVBChannel::getNextSourceSpan(off_t current_offset, size_t bytes_read, off_t &start, size_t &size)
+void eDVBChannel::getNextSourceSpan(off_t current_offset, size_t bytes_read, off_t &start, size_t &size, int blocksize)
 {
-       const int blocksize = 188;
        unsigned int max = align(1024*1024*1024, blocksize);
        current_offset = align(current_offset, blocksize);
 
index fb63399..ad1060c 100644 (file)
@@ -331,7 +331,7 @@ private:
        int m_skipmode_m, m_skipmode_n, m_skipmode_frames, m_skipmode_frames_remainder;
 
        std::list<std::pair<off_t, off_t> > m_source_span;
-       void getNextSourceSpan(off_t current_offset, size_t bytes_read, off_t &start, size_t &size);
+       void getNextSourceSpan(off_t current_offset, size_t bytes_read, off_t &start, size_t &size, int blocksize);
        void flushPVR(iDVBDemux *decoding_demux=0);
 
        eSingleLock m_cuesheet_lock;
index 87fbfa3..4f61c26 100644 (file)
@@ -54,6 +54,7 @@ RESULT eTSFileSectionReader::connectRead(const Slot1<void,const uint8_t*> &r, eP
 
 eDVBTSTools::eDVBTSTools():
        m_pid(-1),
+       m_packet_size(188),
        m_begin_valid (0),
        m_end_valid(0),
        m_samples_taken(0),
@@ -65,6 +66,7 @@ eDVBTSTools::eDVBTSTools():
 void eDVBTSTools::closeSource()
 {
        m_source = NULL;
+       m_packet_size = 188;
 }
 
 eDVBTSTools::~eDVBTSTools()
@@ -97,6 +99,7 @@ void eDVBTSTools::setSource(ePtr<iTsSource> &source, const char *stream_info_fil
                m_streaminfo.load(stream_info_filename);
        }
        m_samples_taken = 0;
+       m_packet_size = m_source ? m_source->getPacketSize() : 188;
 }
 
        /* getPTS extracts a pts value from any PID at a given offset. */
@@ -145,21 +148,22 @@ int eDVBTSTools::getPTS(off_t &offset, pts_t &pts, int fixed)
        if (!m_source || !m_source->valid())
                return -1;
 
-       offset -= offset % 188;
+       offset -= offset % m_packet_size;
 
        int left = m_maxrange;
        int resync_failed_counter = 64;
 
-       while (left >= 188)
+       while (left >= m_packet_size)
        {
-               unsigned char packet[188];
-               if (m_source->read(offset, packet, 188) != 188)
+               unsigned char buffer[m_packet_size];
+               unsigned char *packet = &buffer[m_packet_size - 188];
+               if (m_source->read(offset, buffer, m_packet_size) != m_packet_size)
                {
                        eDebug("[eDVBTSTools] getPTS read error");
                        return -1;
                }
-               left -= 188;
-               offset += 188;
+               left -= m_packet_size;
+               offset += m_packet_size;
 
                if (packet[0] != 0x47)
                {
@@ -419,7 +423,7 @@ int eDVBTSTools::getOffset(off_t &offset, pts_t &pts, int marg)
 
                                offset = l->second;
                                offset += ((pts - l->first) * (pts_t)bitrate) / 8ULL / 90000ULL;
-                               offset -= offset % 188;
+                               offset -= offset % m_packet_size;
                                if (offset > m_offset_end)
                                {
                                        /*
@@ -466,7 +470,7 @@ int eDVBTSTools::getOffset(off_t &offset, pts_t &pts, int marg)
                int bitrate = calcBitrate();
                offset = pts * (pts_t)bitrate / 8ULL / 90000ULL;
                eDebug("[eDVBTSTools] getOffset fallback, bitrate=%d, results in %016llx", bitrate, offset);
-               offset -= offset % 188;
+               offset -= offset % m_packet_size;
                return 0;
        }
 }
@@ -645,7 +649,7 @@ void eDVBTSTools::takeSamples()
        if (bytes_per_sample < 40*1024*1024)
                bytes_per_sample = 40*1024*1024;
 
-       bytes_per_sample -= bytes_per_sample % 188;
+       bytes_per_sample -= bytes_per_sample % m_packet_size;
 
        eDebug("[eDVBTSTools] takeSamples step %lld, pts begin %llu, pts end %llu, offs begin %lld, offs end %lld:",
                bytes_per_sample, m_pts_begin, m_pts_end, m_offset_begin, m_offset_end);
@@ -715,16 +719,17 @@ int eDVBTSTools::findPMT(eDVBPMTParser::program &program)
        off_t position=0;
        m_pmtready = false;
 
-       for (int attempts_left = (5*1024*1024)/188; attempts_left != 0; --attempts_left)
+       for (int attempts_left = (5*1024*1024)/m_packet_size; attempts_left != 0; --attempts_left)
        {
-               unsigned char packet[188];
-               int ret = m_source->read(position, packet, 188);
-               if (ret != 188)
+               unsigned char buffer[m_packet_size];
+               unsigned char *packet = &buffer[m_packet_size - 188];
+               int ret = m_source->read(position, buffer, m_packet_size);
+               if (ret != m_packet_size)
                {
                        eDebug("[eDVBTSTools] findPMT read error");
                        break;
                }
-               position += 188;
+               position += m_packet_size;
 
                if (packet[0] != 0x47)
                {
index bf91a6a..51e83fa 100644 (file)
@@ -90,6 +90,7 @@ protected:
 
 private:
        int m_pid;
+       int m_packet_size;
 
        ePtr<iTsSource> m_source;
 
index 6f284de..e9486fb 100644 (file)
@@ -246,8 +246,18 @@ int eDVBServiceRecord::doPrepare()
                        else
                        {
                                /* re-record a recording */
+                               int packetsize = 188;
+                               eDVBMetaParser meta;
+                               if (!meta.parseFile(m_ref.path))
+                               {
+                                       std::string path = m_ref.path;
+                                       m_ref = meta.m_ref;
+                                       m_ref.path = path;
+                                       packetsize = meta.m_packet_size;
+                                       m_descramble = meta.m_scrambled;
+                               }
                                servicetype = eDVBServicePMTHandler::offline;
-                               eRawFile *f = new eRawFile();
+                               eRawFile *f = new eRawFile(packetsize);
                                f->open(m_ref.path.c_str());
                                source = ePtr<iTsSource>(f);
                        }