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