openATV enigma2
openATV is an open source SetTopBox Graphical user interface.
tstools.h
Go to the documentation of this file.
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 #include <lib/dvb/pmtparse.h>
9 #include <lib/dvb/idemux.h>
10 
11 /*
12  * Note: we're interested in PTS values, not STC values.
13  * thus we're evaluating PES headers, not adaption fields.
14  */
15 
16 typedef long long pts_t;
17 
18 class eTSFileSectionReader: public iDVBSectionReader, public sigc::trackable
19 {
20  DECLARE_REF(eTSFileSectionReader);
21  unsigned char sectionData[4096];
22  unsigned int sectionSize;
23  sigc::signal1<void, const uint8_t*> read;
24 
25 public:
27  virtual ~eTSFileSectionReader();
28  void data(unsigned char *packet, unsigned int size);
29  RESULT setBufferSize(int size) { return 0; }
30  RESULT start(const eDVBSectionFilterMask &mask);
31  RESULT stop();
32  RESULT connectRead(const sigc::slot1<void,const uint8_t*> &read, ePtr<eConnection> &conn);
33 };
34 
35 class eDVBTSTools : public eDVBPMTParser
36 {
37 public:
38  eDVBTSTools();
39  ~eDVBTSTools();
40 
41  void setSource(ePtr<iTsSource> &source, const char *streaminfo_filename=NULL);
42  int openFile(const char *filename, int nostreaminfo = 0);
43 
44  /* get (approximate) offset corresponding to PTS */
45  int getOffset(off_t &offset, pts_t &pts, int marg=0);
46  int getNextAccessPoint(pts_t &ts, const pts_t &start, int direction);
47  /* this fixes up PTS to end up in a [0..len) range.
48  discontinuities etc. are handled here.
49  input:
50  offset - approximate offset in file to resolve ambiguities
51  pts - video-pts (i.e. current STC of video decoder)
52  output:
53  pts - zero-based PTS value
54  */
55  int fixupPTS(const off_t &offset, pts_t &pts);
56  int calcLen(pts_t &len);
57  int calcBitrate(); /* in bits/sec */
58 
59  enum {
64  };
71  int findFrame(off_t &offset, size_t &len, int &direction, int frame_types = frametypeI);
72  int findNextPicture(off_t &offset, size_t &len, int &distance, int frame_types = frametypeAll);
73 
74  /* Retrieve PMT. Returns 0 on success. */
75  int findPMT(eDVBPMTParser::program &program);
76 
77 protected:
78  void closeSource();
79 
80  /* get first PTS *after* the given offset. */
81  /* pts values are zero-based. */
82  int getPTS(off_t &offset, pts_t &pts, int fixed=0);
83 
84  void calcBegin();
85  void calcEnd();
86  void calcBeginAndEnd();
87 
88  void takeSamples();
89  int takeSample(off_t off, pts_t &p);
90 
91 private:
92  int m_pid;
93  int m_packet_size;
94 
95  ePtr<iTsSource> m_source;
96 
97  int m_begin_valid, m_end_valid;
98  pts_t m_pts_begin, m_pts_end;
99  off_t m_offset_begin, m_offset_end;
100  pts_t m_pts_length;
101 
102  /* for simple linear interpolation */
103  std::map<pts_t, off_t> m_samples;
104  int m_samples_taken;
105 
106  eMPEGStreamInformation m_streaminfo;
107  off_t m_last_filelength;
108  int m_futile;
109  program m_program;
110  bool m_pmtready;
111 
112  void PMTready(int error);
113 };
114 
115 #endif
long long pts_t
Definition: cfile.h:7
Definition: pmtparse.h:14
Definition: tstools.h:36
int getPTS(off_t &offset, pts_t &pts, int fixed=0)
Definition: tstools.cpp:106
@ frametypeP
Definition: tstools.h:61
@ frametypeAll
Definition: tstools.h:63
@ frametypeI
Definition: tstools.h:60
@ frametypeB
Definition: tstools.h:62
void calcBeginAndEnd()
Definition: tstools.cpp:605
void calcEnd()
Definition: tstools.cpp:535
int getNextAccessPoint(pts_t &ts, const pts_t &start, int direction)
Definition: tstools.cpp:479
int getOffset(off_t &offset, pts_t &pts, int marg=0)
Definition: tstools.cpp:355
int calcLen(pts_t &len)
Definition: tstools.cpp:611
eDVBTSTools()
Definition: tstools.cpp:55
void closeSource()
Definition: tstools.cpp:66
int openFile(const char *filename, int nostreaminfo=0)
Definition: tstools.cpp:77
void calcBegin()
Definition: tstools.cpp:484
int calcBitrate()
Definition: tstools.cpp:620
int findPMT(eDVBPMTParser::program &program)
Definition: tstools.cpp:706
int fixupPTS(const off_t &offset, pts_t &pts)
Definition: tstools.cpp:322
void takeSamples()
Definition: tstools.cpp:638
int findNextPicture(off_t &offset, size_t &len, int &distance, int frame_types=frametypeAll)
Definition: tstools.cpp:911
int takeSample(off_t off, pts_t &p)
Definition: tstools.cpp:671
int findFrame(off_t &offset, size_t &len, int &direction, int frame_types=frametypeI)
Definition: tstools.cpp:790
void setSource(ePtr< iTsSource > &source, const char *streaminfo_filename=NULL)
Definition: tstools.cpp:92
~eDVBTSTools()
Definition: tstools.cpp:72
Definition: pvrparse.h:15
Definition: ebase.h:187
Definition: tstools.h:19
void data(unsigned char *packet, unsigned int size)
Definition: tstools.cpp:23
RESULT start(const eDVBSectionFilterMask &mask)
Definition: tstools.cpp:37
eTSFileSectionReader(eMainloop *context)
Definition: tstools.cpp:14
RESULT stop()
Definition: tstools.cpp:43
virtual ~eTSFileSectionReader()
Definition: tstools.cpp:19
RESULT connectRead(const sigc::slot1< void, const uint8_t * > &read, ePtr< eConnection > &conn)
Definition: tstools.cpp:49
RESULT setBufferSize(int size)
Definition: tstools.h:29
Definition: idemux.h:7
#define NULL
Definition: eerror.h:101
const char * filename
Definition: epng.h:36
size
Definition: Plugins/SystemPlugins/PositionerSetup/log.py:16
source
Definition: enigma_py_patcher.py:9
p
Definition: upgrade.py:63
int RESULT
Definition: object.h:12
Definition: pmtparse.h:71
Definition: idvb.h:24
long long pts_t
Definition: tstools.h:16