1 #ifndef __include_lib_dvb_pvrparse_h
2 #define __include_lib_dvb_pvrparse_h
4 #include <lib/dvb/idvb.h>
8 /* This module parses TS data and collects valuable information */
9 /* about it, like PTS<->offset correlations and sequence starts. */
11 /* At first, we define the collector class: */
12 class eMPEGStreamInformation
15 eMPEGStreamInformation();
16 ~eMPEGStreamInformation();
17 /* we order by off_t here, since the timestamp may */
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;
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;
28 int startSave(const char *filename);
30 int load(const char *filename);
32 /* recalculates timestampDeltas */
33 void fixupDiscontinuties();
35 /* get delta at specific offset */
36 pts_t getDelta(off_t offset);
38 /* fixup timestamp near offset, i.e. convert to zero-based */
39 int fixupPTS(const off_t &offset, pts_t &ts);
41 /* get PTS before offset */
42 int getPTS(off_t &offset, pts_t &pts);
44 /* inter/extrapolate timestamp from offset */
45 pts_t getInterpolated(off_t offset);
47 off_t getAccessPoint(pts_t ts, int marg=0);
49 int getNextAccessPoint(pts_t &ts, const pts_t &start, int direction);
53 typedef unsigned long long structure_data;
55 sc | (other_information << 8)
56 but is really specific to the used video encoder.
58 void writeStructureEntry(off_t offset, structure_data data);
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);
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;
71 /* Now we define the parser's state: */
72 class eMPEGStreamParserTS
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);
80 eMPEGStreamInformation &m_streaminfo;
81 unsigned char m_pkt[188];
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;