1 #ifndef DMX_DMX_PS
2 #define DMX_DMX_PS
3 
4 
5 #include "ADM_coreDemuxerMpeg6_export.h"
6 #include "dmx_demuxer.h"
7 
8 #define MAX_PES_BUFFER (65*1024) // should be safe enough
9 #define MAX_PES_STREAM 50       // should be enough too :)
10 
11 #include "dmx_mpegstartcode.h"
12 /*
13         A bit of explanation here.
14         The demuxer will take each packet and lookup what it is
15         If it is the seeked pes,it will copy its content into _pesBuffer
16         If not it will keep statical info and continue
17 
18         The pid is like that :
19                 For simple pes-pid it is the pes_pid (0xC0, 0xE0,...)
20                 For data stored in private stream 1 (LPCM, AC3,...), the value is 0xFF00 + sub stream id
21                         with sub stream id : 0-8 for AC3, A0-A8 for LPCM,
22 
23 
24 */
25 class ADM_COREDEMUXER6_EXPORT dmx_demuxerPS: public dmx_demuxer
26  {
27           protected :
28                   uint64_t      stampAbs;
29                   uint32_t      consumed;
30                   fileParser    *parser;
31                   uint32_t       myPid;           // pid: high part =0xff if private stream, 00 if not
32 
33                   uint8_t       *_pesBuffer;
34 
35                   uint32_t      _pesBufferIndex; // current position in pesBuffer
36 
37                   uint64_t      _pesBufferStart;
38                   uint32_t      _pesBufferLen;
39                   uint64_t      _pesPTS;
40                   uint64_t      _pesDTS;
41 
42 
43                   uint64_t      _oldPesStart;    // Contains info for previous packet of same pid
44                   uint32_t      _oldPesLen;      // useful when need to go back (after video startcode)
45                   uint64_t      _oldPTS;
46                   uint64_t      _oldDTS;
47                   uint32_t      _probeSize;      // If not nul, we will only seek to this
48                   uint32_t      maxPid;
49 
50                   uint64_t      seen[256];
51                   uint64_t      trackPTS[256];
52                   uint8_t       mask[256];
53                   uint8_t       *tracked   ;
54                   uint32_t      nbTracked;
55 
56                   uint8_t       refill(void);
57                   uint8_t       getPacketInfo(uint8_t stream,uint8_t *substream,uint32_t *len,uint64_t *pts,uint64_t *dts);
58                   uint32_t      _multi;
59 
60           public:
61                            dmx_demuxerPS(uint32_t nb,MPEG_TRACK *tracks,uint32_t multi) ;
62                 virtual    ~dmx_demuxerPS();
63 
64                      uint8_t      open(const char *name);
65 
66 
67                   uint8_t         forward(uint32_t f);
68                   uint8_t         stamp(void);
69 
70                   uint64_t        elapsed(void);
forceRefill(uint8_t * outstream)71                   uint8_t         forceRefill(uint8_t *outstream) {return refillFull(outstream);}
72 
73                   uint8_t         getPos( uint64_t *abs,uint64_t *rel);
74                   uint8_t         setPos( uint64_t abs,uint64_t  rel);
75 
getSize(void)76                   uint64_t        getSize( void) { return _size;}
77                   uint8_t         setProbeSize(uint32_t probe);
78 
79                   uint32_t        read(uint8_t *w,uint32_t len);
80                   uint8_t         sync( uint8_t *stream,uint64_t *abs,uint64_t *r,uint64_t *pts, uint64_t *dts);
81 
hasAudio(void)82                   uint8_t         hasAudio(void) { return 1;} // MAYBE has audio
83                   uint8_t         getStats(uint64_t *stat);
84                   uint8_t         getAllPTS(uint64_t *stat);
85                   uint8_t         changePid(uint32_t newpid,uint32_t newpes);
86                   //************ Used for vobsub **************
87                   uint8_t         getPacketInfo(uint8_t **data, uint32_t *len, uint32_t *usableLen,uint64_t *pts);
88                   uint8_t         refillFull(uint8_t *outstream);
89 
90 // Inlined
read8i(void)91 uint8_t         read8i(void)
92 {
93         uint8_t r;
94 
95         if(_pesBufferIndex<_pesBufferLen)
96         {
97                 consumed++;
98                 r=_pesBuffer[_pesBufferIndex++];
99                 return r;
100         }
101 
102         read(&r,1);
103         return r;
104 }
read16i(void)105 uint16_t         read16i(void)
106 {
107  uint16_t r;
108 uint8_t p[2];
109 
110         if(_pesBufferIndex+2<=_pesBufferLen)
111         {
112                 consumed+=2;
113                 r=((_pesBuffer[_pesBufferIndex])<<8)+(_pesBuffer[_pesBufferIndex+1]);
114                 _pesBufferIndex+=2;
115                 return r;
116         }
117 
118         read(p,2);
119         r=(p[0]<<8)+p[1];
120         return r;
121 }
read32i(void)122 uint32_t         read32i(void)
123 {
124 uint32_t r;
125 uint8_t  *p;
126 uint8_t b[4];
127         if(_pesBufferIndex+4<=_pesBufferLen)
128         {
129                 consumed+=4;
130                 p=&(_pesBuffer[_pesBufferIndex]);
131                 _pesBufferIndex+=4;
132         }
133         else
134         {
135                 read(b,4);
136                 p=b;
137         }
138         r=(p[0]<<24)+(p[1]<<16)+(p[2]<<8)+(p[3]);
139         return r;
140 }
141 
142 
143 };
144 
145 
146 #endif
147