2 Copyright 2005-2006 Mark Calderbank
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "demuxervdr.h"
24 DemuxerVDR::DemuxerVDR() {}
26 void DemuxerVDR::flush()
33 int DemuxerVDR::scan(UCHAR *buf, int len)
35 // Temporarily, just look for the lowest audio stream and return it
36 UCHAR HiByte = PESTYPE_AUDMAX;
41 UINT pattern = *(UINT*)buf;
44 #if __BYTE_ORDER == __BIG_ENDIAN
45 if (pattern < (UINT)(0x100 | PESTYPE_AUD0) ||
46 pattern > (UINT)(0x100 | HiByte)) continue;
47 HiByte = pattern & 0xFF;
49 if ((pattern & 0xFFFFFF) != 0x010000 ||
50 pattern < ((UINT)PESTYPE_AUD0 << 24) ||
51 pattern > ((UINT)HiByte << 24)) continue;
52 HiByte = pattern >> 24;
55 if (HiByte == PESTYPE_AUD0) break;
60 int DemuxerVDR::findVideoPTS(UCHAR* buf, int len, ULLONG* dest)
64 UINT pattern = *(UINT*)buf;
66 #if __BYTE_ORDER == __BIG_ENDIAN
67 if (pattern < (0x100 | PESTYPE_VID0) ||
68 pattern > (0x100 | PESTYPE_VIDMAX)) continue;
70 if ((pattern & 0xFFFFFF) != 0x010000 ||
71 pattern < ((UINT)PESTYPE_VID0 << 24) ||
72 pattern > ((UINT)PESTYPE_VIDMAX << 24)) continue;
74 if ((buf[5] & 0xC0) != 0x80) continue;
76 UINT packetlength = ((UINT)buf[3] << 8) | buf[4];
78 if ( buf[6] & 0x80 ) // PTS_DTS_flags indicate that PTS is present
80 if ( (buf[8] & 0x01) != 0x01 ||
81 (buf[10] & 0x01) != 0x01 ||
82 (buf[12] & 0x01) != 0x01) continue;
84 *dest = ( (ULLONG)(buf[8] & 0x0E) << 29 ) |
85 ( (ULLONG)(buf[9]) << 22 ) |
86 ( (ULLONG)(buf[10] & 0xFE) << 14 ) |
87 ( (ULLONG)(buf[11]) << 7 ) |
88 ( (ULLONG)(buf[12] & 0xFE) >> 1 );
93 buf += packetlength; len -= packetlength;
99 int DemuxerVDR::put(UCHAR* buf, int len)
101 int ret = 0; // return number of bytes consumed
105 if (packet.submit() == 0) // Still full!
111 if (state > 0) // We are half way through a PES packet.
113 if (len >= state) // The remainder of the packet is available.
115 packet.write(buf, state);
116 buf += state; len -= state; ret += state;
118 if (packet.submit() == 0) // Stream is full.
124 else // Write what we have, then exit.
126 packet.write(buf, len);
138 if (*buf == 0x00) state--; else state = 0;
141 if (*buf == 0x01) state--; else if (*buf != 0x00) state = 0;
144 if ((*buf >= PESTYPE_VID0 && *buf <= PESTYPE_VIDMAX) ||
145 (*buf >= PESTYPE_AUD0 && *buf <= PESTYPE_AUDMAX) ||
146 (*buf == PESTYPE_PRIVATE_1))
152 else if (*buf == 0x00)
158 packetLength = ((UINT)*buf) << 8;
162 packetLength += *buf;
169 if (state == -6) // Packet header complete
171 if (len >= packetLength) // The entire packet is available.
173 packet.write(buf, packetLength);
174 buf += packetLength; len -= packetLength; ret += packetLength;
176 if (packet.submit() == 0) // Stream is full.
182 else // Write what we have.
184 packet.write(buf, len);
185 state = packetLength - len;