add preStart event and use it to load the cutlist
[enigma2.git] / lib / dvb / tstools.h
1 #ifndef __lib_dvb_tstools_h
2 #define __lib_dvb_tstools_h
3
4 #include <sys/types.h>
5 #include <lib/dvb/pvrparse.h>
6 #include <lib/base/rawfile.h>
7
8 /*
9  * Note: we're interested in PTS values, not STC values.
10  * thus we're evaluating PES headers, not adaption fields.
11  */
12
13 typedef long long pts_t;
14
15 class eDVBTSTools
16 {
17 public:
18         eDVBTSTools();
19         ~eDVBTSTools();
20
21         int openFile(const char *filename, int nostreaminfo = 0);
22         void closeFile();
23         
24         void setSyncPID(int pid);
25         void setSearchRange(int maxrange);
26         
27                 /* get first PTS *after* the given offset. */
28                 /* pts values are zero-based. */
29         int getPTS(off_t &offset, pts_t &pts, int fixed=0);
30         
31                 /* this fixes up PTS to end up in a [0..len) range.
32                    discontinuities etc. are handled here.
33                 
34                   input:        
35                     offset - approximate offset in file to resolve ambiguities
36                     pts - video-pts (i.e. current STC of video decoder)
37                   output:
38                     pts - zero-based PTS value
39                 */
40         int fixupPTS(const off_t &offset, pts_t &pts);
41         
42                 /* get (approximate) offset corresponding to PTS */
43         int getOffset(off_t &offset, pts_t &pts, int marg=0);
44         
45         int getNextAccessPoint(pts_t &ts, const pts_t &start, int direction);
46         
47         void calcBegin();
48         void calcEnd();
49         
50         int calcLen(pts_t &len);
51         
52         int calcBitrate(); /* in bits/sec */
53         
54         void takeSamples();
55         int takeSample(off_t off, pts_t &p);
56         
57         int findPMT(int &pmt_pid, int &service_id);
58         
59         enum { 
60                 frametypeI = 1, 
61                 frametypeP = 2, 
62                 frametypeB = 4, 
63                 frametypeAll = frametypeI | frametypeP | frametypeB
64         };
65         /** findFrame: finds a specific frame at a given position
66         
67         findFrame will look for the specified frame type starting at the given position, moving forward
68         (when direction is >0) or backward (when direction is <0). (direction=0 is a special case and also moves
69         forward, but starts with the last frame.)
70         
71         return values are the new offset, the length of the found frame (both unaligned), and the (signed) 
72         number of frames skipped. */
73         int findFrame(off_t &offset, size_t &len, int &direction, int frame_types = frametypeI);
74         int findNextPicture(off_t &offset, size_t &len, int &distance, int frame_types = frametypeAll);
75 private:
76         int m_pid;
77         int m_maxrange;
78         
79         eRawFile m_file;
80         
81         int m_begin_valid, m_end_valid;
82         pts_t m_pts_begin, m_pts_end;
83         off_t m_offset_begin, m_offset_end;
84         
85                 /* for simple linear interpolation */
86         std::map<pts_t, off_t> m_samples;
87         int m_samples_taken;
88         
89         eMPEGStreamInformation m_streaminfo;
90         int m_use_streaminfo;
91         off_t m_last_filelength;
92         int m_futile;
93 };
94
95 #endif