1 #ifndef __include_lib_dvb_pvrparse_h
2 #define __include_lib_dvb_pvrparse_h
4 #include <lib/components/file_monitor.h>
5 #include <lib/dvb/idvb.h>
9 /* This module parses TS data and collects valuable information */
10 /* about it, like PTS<->offset correlations and sequence starts. */
14 /* At first, we define the collector class: */
15 class eMPEGStreamInformation
17 void fileWatchEventCB(eFileWatch *fw, eFileEvent evt);
19 eMPEGStreamInformation();
20 ~eMPEGStreamInformation();
24 /* we order by uint64_t here, since the timestamp may */
26 /* we only record sequence start's pts values here. */
27 std::map<uint64_t, pts_t> m_access_points;
28 /* timestampDelta is in fact the difference between */
29 /* the PTS in the stream and a real PTS from 0..max */
30 std::map<uint64_t, pts_t> m_timestamp_deltas;
32 /* these are non-fixed up pts value (like m_access_points), just used to accelerate stuff. */
33 std::multimap<pts_t, uint64_t> m_pts_to_offset;
35 int startSave(const char *filename);
37 int load(const char *filename);
39 /* recalculates timestampDeltas */
40 void fixupDiscontinuties();
42 /* get delta at specific offset */
43 pts_t getDelta(uint64_t offset);
45 /* fixup timestamp near offset, i.e. convert to zero-based */
46 int fixupPTS(const uint64_t &offset, pts_t &ts);
48 /* get PTS before offset */
49 int getPTS(uint64_t &offset, pts_t &pts);
51 /* inter/extrapolate timestamp from offset */
52 pts_t getInterpolated(uint64_t offset);
54 uint64_t getAccessPoint(pts_t ts, int marg=0);
56 int getNextAccessPoint(pts_t &ts, const pts_t &start, int direction);
58 bool AccessPointsAvail();
59 bool StructureCacheAvail();
61 typedef unsigned long long structure_data;
63 sc | (other_information << 8)
64 but is really specific to the used video encoder.
66 void writeStructureEntry(uint64_t offset, structure_data data);
68 /* get a structure entry at given offset (or previous one, if no exact match was found).
69 optionally, return next element. Offset will be returned. this allows you to easily
70 get previous and next structure elements. */
71 int getStructureEntry(uint64_t &offset, uint64_t &data, int get_next);
72 int update_structure_cache(uint64_t offset);
74 std::string m_filename;
77 int m_structure_cache_entries;
78 int m_structure_read_fd;
79 uint64_t *m_structure_read_mem;
80 off_t m_structure_read_size;
81 int m_structure_read_prev_result; // prev returned entry used for accel next search
82 eFileWatch *m_structure_file_watch;
83 bool m_structure_file_changed;
87 int m_structure_write_fd;
88 uint64_t *m_structure_write_mem;
91 /* Now we define the parser's state: */
92 class eMPEGStreamParserTS
95 eMPEGStreamParserTS(eMPEGStreamInformation &streaminfo);
96 void parseData(uint64_t offset, const void *data, unsigned int len);
97 void setPid(int pid, int streamtype);
98 int getLastPTS(pts_t &last_pts);
99 void setAccessPoints(bool on);
101 eMPEGStreamInformation &m_streaminfo;
102 unsigned char m_pkt[188];
104 int processPacket(const unsigned char *pkt, uint64_t offset);
105 inline int wantPacket(const unsigned char *hdr) const;
106 int m_pid, m_streamtype;
107 int m_need_next_packet;
108 int m_last_pts_valid;
110 bool m_collect_accesspoints;
111 unsigned char m_pkt2[188*2];
112 uint64_t m_last_sc_offset;
113 int m_last_sc_offset_valid;