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"
25 #define __LITTLE_ENDIAN 1234
26 #define __BIG_ENDIAN 4321
27 #define __BYTE_ORDER __LITTLE_ENDIAN
30 #if __BYTE_ORDER == __BIG_ENDIAN
31 #define DEMUXER_SEQ_HEAD 0x000001B3
33 #define DEMUXER_SEQ_HEAD 0xB3010000
36 DemuxerVDR::DemuxerVDR() {
37 } //MS Visual C++ needs the Bracket after the first line other it ignores the line
39 void DemuxerVDR::flush()
46 int DemuxerVDR::scan(UCHAR *buf, int len)
48 // Temporarily, just look for the lowest audio stream and return it
49 UCHAR HiByte = PESTYPE_AUDMAX;
54 UINT pattern = *(UINT*)buf;
57 #if __BYTE_ORDER == __BIG_ENDIAN
58 if (pattern < (UINT)(0x100 | PESTYPE_AUD0) ||
59 pattern > (UINT)(0x100 | HiByte)) continue;
60 HiByte = pattern & 0xFF;
62 if ((pattern & 0xFFFFFF) != 0x010000 ||
63 pattern < ((UINT)PESTYPE_AUD0 << 24) ||
64 pattern > ((UINT)HiByte << 24)) continue;
65 HiByte = pattern >> 24;
68 if (HiByte == PESTYPE_AUD0) break;
73 int DemuxerVDR::findVideoPTS(UCHAR* buf, int len, ULLONG* dest)
77 UINT pattern = *(UINT*)buf;
79 #if __BYTE_ORDER == __BIG_ENDIAN
80 if (pattern < (0x100 | PESTYPE_VID0) ||
81 pattern > (0x100 | PESTYPE_VIDMAX)) continue;
83 if ((pattern & 0xFFFFFF) != 0x010000 ||
84 pattern < ((UINT)PESTYPE_VID0 << 24) ||
85 pattern > ((UINT)PESTYPE_VIDMAX << 24)) continue;
87 if ((buf[5] & 0xC0) != 0x80) continue;
89 UINT packetlength = ((UINT)buf[3] << 8) | buf[4];
91 if ( buf[6] & 0x80 ) // PTS_DTS_flags indicate that PTS is present
93 if ( (buf[8] & 0x01) != 0x01 ||
94 (buf[10] & 0x01) != 0x01 ||
95 (buf[12] & 0x01) != 0x01) continue;
97 *dest = ( (ULLONG)(buf[8] & 0x0E) << 29 ) |
98 ( (ULLONG)(buf[9]) << 22 ) |
99 ( (ULLONG)(buf[10] & 0xFE) << 14 ) |
100 ( (ULLONG)(buf[11]) << 7 ) |
101 ( (ULLONG)(buf[12] & 0xFE) >> 1 );
106 buf += packetlength; len -= packetlength;
112 int DemuxerVDR::put(UCHAR* buf, int len)
114 int DemuxerVDR::put(UCHAR* buf, int len, ULLONG cur_pos)
117 int ret = 0; // return number of bytes consumed
120 ULLONG current_position = cur_pos;
126 if (packet.submit() == 0) // Still full!
128 if (packet.submit(current_position) == 0) // Still full!
135 if (state > 0) // We are half way through a PES packet.
137 if (len >= state) // The remainder of the packet is available.
139 packet.write(buf, state);
140 buf += state; len -= state; ret += state;
143 if (packet.submit() == 0) // Still full!
145 if (packet.submit(current_position) == 0) // Still full!
152 else // Write what we have, then exit.
154 packet.write(buf, len);
166 if (*buf == 0x00) state--; else state = 0;
170 if (*buf == 0x01) state--; else if (*buf != 0x00) state = 0;
174 if ((*buf >= PESTYPE_VID0 && *buf <= PESTYPE_VIDMAX) ||
175 (*buf >= PESTYPE_AUD0 && *buf <= PESTYPE_AUDMAX) ||
176 (*buf == PESTYPE_PRIVATE_1))
181 else if (*buf == 0x00)
188 packetLength = ((UINT)*buf) << 8;
193 packetLength += *buf;
203 if (state == -6) // Packet header complete
205 if (len >= packetLength) // The entire packet is available.
207 packet.write(buf, packetLength);
208 buf += packetLength; len -= packetLength; ret += packetLength;
210 current_position+=(ULLONG)packetLength;
214 if (packet.submit() == 0) // Still full!
216 if (packet.submit(current_position) == 0) // Still full!
223 else // Write what we have.
225 packet.write(buf, len);
226 state = packetLength - len;