1 #ifndef __lib_dvb_tstools_h
2 #define __lib_dvb_tstools_h
5 #include <lib/dvb/pvrparse.h>
6 #include <lib/base/itssource.h>
7 #include <lib/base/elock.h>
11 * Note: we're interested in PTS values, not STC values.
12 * thus we're evaluating PES headers, not adaption fields.
15 typedef long long pts_t;
23 void setSource(ePtr<iTsSource> &source, const char *streaminfo_filename=NULL);
26 int openFile(const char *filename, int nostreaminfo = 0);
29 void setSyncPID(int pid);
30 void setSearchRange(int maxrange);
32 /* get first PTS *after* the given offset. */
33 /* pts values are zero-based. */
34 int getPTS(uint64_t &offset, pts_t &pts, int fixed=0);
36 /* this fixes up PTS to end up in a [0..len) range.
37 discontinuities etc. are handled here.
40 offset - approximate offset in file to resolve ambiguities
41 pts - video-pts (i.e. current STC of video decoder)
43 pts - zero-based PTS value
45 int fixupPTS(const uint64_t &offset, pts_t &pts);
47 /* get (approximate) offset corresponding to PTS */
48 int getOffset(uint64_t &offset, pts_t &pts, int marg=0);
50 int getNextAccessPoint(pts_t &ts, const pts_t &start, int direction);
55 int calcLen(pts_t &len);
57 int calcBitrate(); /* in bits/sec */
60 int takeSample(uint64_t off, pts_t &p);
62 int findPMT(int &pmt_pid, int &service_id);
68 frametypeAll = frametypeI | frametypeP | frametypeB
70 /** findFrame: finds a specific frame at a given position
72 findFrame will look for the specified frame type starting at the given position, moving forward
73 (when direction is >0) or backward (when direction is <0). (direction=0 is a special case and also moves
74 forward, but starts with the last frame.)
76 return values are the new offset, the length of the found frame (both unaligned), and the (signed)
77 number of frames skipped. */
78 int findFrame(uint64_t &offset, size_t &len, int &direction, int frame_types = frametypeI);
79 int findNextPicture(uint64_t &offset, size_t &len, int &distance, int frame_types = frametypeAll);
81 /** search backwards from offset to the prev seq header
82 returns the number of frames skipped. */
83 int setSeqHeader(uint64_t &offset);
85 uint64_t byteLen() const { return m_last_filelength; }
91 ePtr<iTsSource> m_source;
93 int m_begin_valid, m_end_valid;
94 pts_t m_pts_begin, m_pts_end;
95 uint64_t m_offset_begin, m_offset_end;
97 /* for simple linear interpolation */
98 std::map<pts_t, uint64_t> m_samples;
101 eMPEGStreamInformation m_streaminfo;
102 uint64_t m_last_filelength;