1 #include <lib/dvb/tstools.h>
7 eDVBTSTools::eDVBTSTools()
11 m_maxrange = 1*1024*1024;
17 eDVBTSTools::~eDVBTSTools()
22 int eDVBTSTools::openFile(const char *filename)
25 m_fd = ::open(filename, O_RDONLY);
31 void eDVBTSTools::closeFile()
37 void eDVBTSTools::setSyncPID(int pid)
42 void eDVBTSTools::setSearchRange(int maxrange)
44 m_maxrange = maxrange;
47 int eDVBTSTools::getPTS(off_t &offset, pts_t &pts)
52 offset -= offset % 188;
54 // TODO: multiple files!
55 if (lseek(m_fd, offset, SEEK_SET) < 0)
58 int left = m_maxrange;
62 unsigned char block[188];
63 if (read(m_fd, block, 188) != 188)
74 offset = lseek(m_fd, i - 188, SEEK_CUR);
78 int pid = ((block[1] << 8) | block[2]) & 0x1FFF;
79 int pusi = !!(block[1] & 0x40);
81 // printf("PID %04x, PUSI %d\n", pid, pusi);
89 /* ok, now we have a PES header */
92 /* check for adaption field */
94 pes = block + block[4] + 4 + 1;
98 /* somehow not a startcode. (this is invalid, since pusi was set.) ignore it. */
99 if (pes[0] || pes[1] || (pes[2] != 1))
102 if (pes[7] & 0x80) /* PTS */
104 pts = ((unsigned long long)(pes[ 9]&0xE)) << 29;
105 pts |= ((unsigned long long)(pes[10]&0xFF)) << 22;
106 pts |= ((unsigned long long)(pes[11]&0xFE)) << 14;
107 pts |= ((unsigned long long)(pes[12]&0xFF)) << 7;
108 pts |= ((unsigned long long)(pes[13]&0xFE)) >> 1;
117 void eDVBTSTools::calcBegin()
124 if (!getPTS(m_offset_begin, m_pts_begin))
129 void eDVBTSTools::calcEnd()
136 m_offset_end = lseek(m_fd, 0, SEEK_END) - m_maxrange;
137 if (!getPTS(m_offset_end, m_pts_end))
142 int eDVBTSTools::calcLen(pts_t &len)
144 calcBegin(); calcEnd();
145 if (!(m_begin_valid && m_end_valid))
147 len = m_pts_end - m_pts_begin;