Merge branch 'master' of fraxinas@git.opendreambox.org:/git/enigma2
[vuplus_dvbapp] / lib / dvb / pvrparse.h
1 #ifndef __include_lib_dvb_pvrparse_h
2 #define __include_lib_dvb_pvrparse_h
3
4 #include <lib/dvb/idvb.h>
5 #include <map>
6 #include <set>
7
8         /* This module parses TS data and collects valuable information  */
9         /* about it, like PTS<->offset correlations and sequence starts. */
10
11         /* At first, we define the collector class: */
12 class eMPEGStreamInformation
13 {
14 public:
15         eMPEGStreamInformation();
16         ~eMPEGStreamInformation();
17                 /* we order by off_t here, since the timestamp may */
18                 /* wrap around. */
19                 /* we only record sequence start's pts values here. */
20         std::map<off_t, pts_t> m_access_points;
21                 /* timestampDelta is in fact the difference between */
22                 /* the PTS in the stream and a real PTS from 0..max */
23         std::map<off_t, pts_t> m_timestamp_deltas;
24
25                 /* these are non-fixed up pts value (like m_access_points), just used to accelerate stuff. */
26         std::multimap<pts_t, off_t> m_pts_to_offset; 
27
28         int startSave(const char *filename);
29         int stopSave(void);
30         int load(const char *filename);
31         
32                 /* recalculates timestampDeltas */
33         void fixupDiscontinuties();
34         
35                 /* get delta at specific offset */
36         pts_t getDelta(off_t offset);
37         
38                 /* fixup timestamp near offset, i.e. convert to zero-based */
39         int fixupPTS(const off_t &offset, pts_t &ts);
40
41                 /* get PTS before offset */     
42         int getPTS(off_t &offset, pts_t &pts);
43         
44                 /* inter/extrapolate timestamp from offset */
45         pts_t getInterpolated(off_t offset);
46         
47         off_t getAccessPoint(pts_t ts, int marg=0);
48         
49         int getNextAccessPoint(pts_t &ts, const pts_t &start, int direction);
50         
51         bool empty();
52         
53         typedef unsigned long long structure_data;
54                 /* this is usually:
55                         sc | (other_information << 8)
56                         but is really specific to the used video encoder.
57                 */
58         void writeStructureEntry(off_t offset, structure_data data);
59
60                 /* get a structure entry at given offset (or previous one, if no exact match was found).
61                    optionall, return next element. Offset will be returned. this allows you to easily 
62                    get previous and next structure elements. */
63         int getStructureEntry(off_t &offset, unsigned long long &data, int get_next);
64
65         std::string m_filename;
66         int m_structure_cache_valid;
67         unsigned long long m_structure_cache[1024];
68         FILE *m_structure_read, *m_structure_write;
69 };
70
71         /* Now we define the parser's state: */
72 class eMPEGStreamParserTS
73 {
74 public:
75         eMPEGStreamParserTS(eMPEGStreamInformation &streaminfo);
76         void parseData(off_t offset, const void *data, unsigned int len);
77         void setPid(int pid, int streamtype);
78         int getLastPTS(pts_t &last_pts);
79 private:
80         eMPEGStreamInformation &m_streaminfo;
81         unsigned char m_pkt[188];
82         int m_pktptr;
83         int processPacket(const unsigned char *pkt, off_t offset);
84         inline int wantPacket(const unsigned char *hdr) const;
85         int m_pid, m_streamtype;
86         int m_need_next_packet;
87         int m_skip;
88         int m_last_pts_valid;
89         pts_t m_last_pts;
90 };
91
92 #endif