openATV enigma2
openATV is an open source SetTopBox Graphical user interface.
pvrparse.h
Go to the documentation of this file.
1 #ifndef __include_lib_dvb_pvrparse_h
2 #define __include_lib_dvb_pvrparse_h
3 
4 #include <lib/dvb/idvb.h>
5 #include <lib/dvb/idemux.h>
6 #include <map>
7 #include <set>
8 #include <deque>
9 #include <aio.h>
10 
11  /* This module parses TS data and collects valuable information */
12  /* about it, like PTS<->offset correlations and sequence starts. */
13 
15 {
16 public:
19 
20  int load(const char *filename);
21 
22  /* fixup timestamp near offset, i.e. convert to zero-based */
23  int fixupPTS(const off_t &offset, pts_t &ts);
24 
25  /* get PTS before offset */
26  int getPTS(off_t &offset, pts_t &pts);
27 
28 
29  off_t getAccessPoint(pts_t ts, int marg=0);
30 
31  int getNextAccessPoint(pts_t &ts, const pts_t &start, int direction);
32 
33  bool hasAccessPoints() { return !m_access_points.empty(); }
34  bool hasStructure() { return m_structure_read_fd >= 0; }
35 
36  /* get a structure entry at given offset (or previous one, if no exact match was found).
37  optionally, return next element. Offset will be returned. this allows you to easily
38  get previous and next structure elements. */
39  int getStructureEntryFirst(off_t &offset, unsigned long long &data);
40  int getStructureEntryNext(off_t &offset, unsigned long long &data, int delta);
41 
42  // Get first or last PTS value and offset.
43  int getFirstFrame(off_t &offset, pts_t& pts);
44  int getLastFrame(off_t &offset, pts_t& pts);
45 
46 private:
47  void close();
48  int loadCache(int index);
49  int moveCache(int index);
50  /* inter/extrapolate timestamp from offset */
51  pts_t getInterpolated(off_t offset);
52  /* get delta at specific offset */
53  pts_t getDelta(off_t offset);
54  /* recalculates timestampDeltas */
55  void fixupDiscontinuties();
56  /* we order by off_t here, since the timestamp may */
57  /* wrap around. */
58  /* we only record sequence start's pts values here. */
59  std::map<off_t, pts_t> m_access_points;
60  /* timestampDelta is in fact the difference between */
61  /* the PTS in the stream and a real PTS from 0..max */
62  std::map<off_t, pts_t> m_timestamp_deltas;
63  /* these are non-fixed up pts value (like m_access_points), just used to accelerate stuff. */
64  std::multimap<pts_t, off_t> m_pts_to_offset;
65 
66  int m_structure_read_fd;
67  int m_cache_index; // Location of cache
68  int m_current_entry; // For getStructureEntryNext
69  int m_structure_cache_entries;
70  int m_structure_file_entries; // Also to detect changes to file
71  unsigned long long* m_structure_cache;
72  bool m_streamtime_accesspoints;
73 };
74 
76 {
77 public:
80  /* Used by parser */
81  int startSave(const std::string& filename);
82  int stopSave(void);
83  virtual void addAccessPoint(off_t offset, pts_t pts, bool streamtime);
84  void writeStructureEntry(off_t offset, unsigned long long data);
85  void commit();
86 private:
87  void close();
88  struct AccessPoint
89  {
90  off_t off;
91  pts_t pts;
92  AccessPoint(off_t o, pts_t p): off(o), pts(p) {}
93  };
94  std::deque<AccessPoint> m_access_points, m_streamtime_access_points;
95  struct PendingWrite
96  {
97  PendingWrite();
98  ~PendingWrite();
99  int start(int fd, off_t where, void* buffer, size_t buffer_size);
100  bool poll(); // releases resources when ready, returns true if released
101  int wait();
102  void* m_buffer;
103  struct aiocb m_aio;
104  };
105  std::deque<PendingWrite> m_pending_writes;
106  std::string m_filename;
107  int m_structure_write_fd;
108  off_t m_structure_pos;
109  void* m_write_buffer;
110  size_t m_buffer_filled;
111 };
112 
113 
115 {
116 public:
117  eMPEGStreamParserTS(int packetsize = 188);
118  void parseData(off_t offset, const void *data, unsigned int len);
119  void setPid(int pid, iDVBTSRecorder::timing_pid_type pidtype, int streamtype);
120  int getLastPTS(pts_t &last_pts);
121  int getFirstPTS(pts_t &first_pts);
122  void enableAccessPoints(bool enable) { m_enable_accesspoints = enable; }
123 private:
124  unsigned char m_pkt[192];
125  int m_pktptr;
126  int processPacket(const unsigned char *pkt, off_t offset);
127  inline int wantPacket(const unsigned char *pkt) const;
128  void addAccessPoint(off_t offset, pts_t pts, bool streamtime = false);
129  void addAccessPoint(off_t offset, pts_t pts, timespec &now, bool streamtime = false);
130  int m_pid;
131  int m_streamtype;
132  int m_need_next_packet;
133  int m_skip;
134  int m_last_pts_valid; /* m_last_pts contains a valid value */
135  pts_t m_last_pts; /* last pts value, either from mpeg stream, or measured in streamtime */
136  pts_t m_first_pts;
137  int m_packetsize;
138  int m_header_offset;
139  timespec m_last_access_point; /* timespec at which the previous access point was reported */
140  bool m_enable_accesspoints; /* set to false to prevent saving .ap files (e.g. timeshift) */
141  bool m_pts_found; /* 'real' mpeg pts has been found, no longer measuring streamtime */
142  bool m_has_accesspoints;
143 };
144 
145 #endif
long long pts_t
Definition: cfile.h:7
Definition: pvrparse.h:15
~eMPEGStreamInformation()
Definition: pvrparse.cpp:32
int getFirstFrame(off_t &offset, pts_t &pts)
Definition: pvrparse.cpp:517
bool hasStructure()
Definition: pvrparse.h:34
int getPTS(off_t &offset, pts_t &pts)
Definition: pvrparse.cpp:171
bool hasAccessPoints()
Definition: pvrparse.h:33
int getStructureEntryNext(off_t &offset, unsigned long long &data, int delta)
Definition: pvrparse.cpp:474
int fixupPTS(const off_t &offset, pts_t &ts)
Definition: pvrparse.cpp:135
int getLastFrame(off_t &offset, pts_t &pts)
Definition: pvrparse.cpp:552
int getStructureEntryFirst(off_t &offset, unsigned long long &data)
Definition: pvrparse.cpp:389
int load(const char *filename)
Definition: pvrparse.cpp:55
eMPEGStreamInformation()
Definition: pvrparse.cpp:21
int getNextAccessPoint(pts_t &ts, const pts_t &start, int direction)
Definition: pvrparse.cpp:254
off_t getAccessPoint(pts_t ts, int marg=0)
Definition: pvrparse.cpp:226
Definition: pvrparse.h:76
eMPEGStreamInformationWriter()
Definition: pvrparse.cpp:618
virtual void addAccessPoint(off_t offset, pts_t pts, bool streamtime)
Definition: pvrparse.cpp:681
int stopSave(void)
Definition: pvrparse.cpp:639
void commit()
Definition: pvrparse.cpp:791
~eMPEGStreamInformationWriter()
Definition: pvrparse.cpp:625
void writeStructureEntry(off_t offset, unsigned long long data)
Definition: pvrparse.cpp:698
int startSave(const std::string &filename)
Definition: pvrparse.cpp:630
Definition: pvrparse.h:115
void setPid(int pid, iDVBTSRecorder::timing_pid_type pidtype, int streamtype)
Definition: pvrparse.cpp:1204
eMPEGStreamParserTS(int packetsize=188)
Definition: pvrparse.cpp:836
void parseData(off_t offset, const void *data, unsigned int len)
Definition: pvrparse.cpp:1077
int getLastPTS(pts_t &last_pts)
Definition: pvrparse.cpp:1228
void enableAccessPoints(bool enable)
Definition: pvrparse.h:122
int getFirstPTS(pts_t &first_pts)
Definition: pvrparse.cpp:1239
timing_pid_type
Definition: idemux.h:36
const char * filename
Definition: epng.h:36
unsigned char data[256]
Definition: hdmi_cec.h:2
enable
Definition: Extensions/MiniTV/plugin.py:8
list where
Definition: newplugin.py:126
index
Definition: main.py:28
p
Definition: upgrade.py:63