From dad56315986ec6620f2c59f0eb4227147199c88a Mon Sep 17 00:00:00 2001 From: Mark Calderbank Date: Sat, 29 Nov 2008 01:02:44 +0000 Subject: [PATCH] PES Packet object: dynamic sizing --- demuxer.cc | 37 +++++++++++++++++++------------------ demuxer.h | 36 +++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/demuxer.cc b/demuxer.cc index cdf9cac..b75d256 100644 --- a/demuxer.cc +++ b/demuxer.cc @@ -1,5 +1,5 @@ /* - Copyright 2005-2007 Mark Calderbank + Copyright 2005-2008 Mark Calderbank Copyright 2007 Marten Richter (AC3 support) This file is part of VOMP. @@ -15,8 +15,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "demuxer.h" @@ -30,24 +30,21 @@ // Statics const int Demuxer::FrameRates[9] = { 0, 23, 24, 25, 29, 30, 50, 59, 60 }; -const ULLONG PESPacket::PTS_INVALID = (1LL << 33); Demuxer* Demuxer::instance = NULL; // PESPacket methods PESPacket::PESPacket() { - data[0] = 0x00; - data[1] = 0x00; - data[2] = 0x01; init(0); + data[2] = 0x01; } void PESPacket::init(UCHAR type, UCHAR sub) { + data.resize(6); length = 0; size = 6; data[3] = type; - data[4] = data[5] = 0; packetType = type; substream = sub; seq_header = 1; // Unknown seq_header status @@ -58,10 +55,10 @@ void PESPacket::truncate() init(packetType,substream); } -int PESPacket::write(UCHAR *buf, int len) +int PESPacket::write(const UCHAR *buf, int len) { if (length + len > 0xFFFA) return 0; - memcpy(data+length+6, buf, len); + data.insert(data.end(), buf, buf+len); length += len; size += len; data[4] = (length >> 8); @@ -71,14 +68,17 @@ int PESPacket::write(UCHAR *buf, int len) return 1; } -ULLONG PESPacket::getPTS() +ULLONG PESPacket::getPTS() const { if ( ( (packetType >= Demuxer::PESTYPE_AUD0 && packetType <= Demuxer::PESTYPE_AUDMAX) || (packetType >= Demuxer::PESTYPE_VID0 && packetType <= Demuxer::PESTYPE_VIDMAX) - ) && size >= 14 && data[7] & 0x80) + || + packetType == Demuxer::PESTYPE_PRIVATE_1 + ) + && size >= 14 && data[7] & 0x80) { return ( (ULLONG)(data[ 9] & 0x0E) << 29) | ( (ULLONG)(data[10]) << 22 ) | @@ -89,7 +89,7 @@ ULLONG PESPacket::getPTS() else return PTS_INVALID; } -UCHAR PESPacket::operator[] (UINT index) +UCHAR PESPacket::operator[] (UINT index) const { if (index >= size) return 0; @@ -97,7 +97,7 @@ UCHAR PESPacket::operator[] (UINT index) return data[index]; } -UINT PESPacket::findPictureHeader() +UINT PESPacket::findPictureHeader() const { if (size < 12) return 0; UINT pattern = ( ((UINT)data[ 8] << 24) | @@ -113,7 +113,7 @@ UINT PESPacket::findPictureHeader() return pos-3; } -UINT PESPacket::findSeqHeader() +UINT PESPacket::findSeqHeader() const { if (seq_header != 1) return seq_header; if (size < 12) return 0; @@ -267,12 +267,13 @@ bool Demuxer::submitPacket(PESPacket& packet) { UINT sent = 0; UCHAR packet_type = packet.getPacketType(); + const std::vector& packetdata = packet.getData(); if (packet_type >= PESTYPE_VID0 && packet_type <= PESTYPE_VIDMAX) { if (video_current == -1) video_current = packet_type; if (video_current == packet_type && !vid_seeking) - sent = videostream.put(packet.getData(), packet.getSize(), MPTYPE_VIDEO); + sent = videostream.put(&packetdata[0], packet.getSize(), MPTYPE_VIDEO); else sent = packet.getSize(); } @@ -281,7 +282,7 @@ bool Demuxer::submitPacket(PESPacket& packet) if (audio_current == -1) audio_current = packet_type; avail_mpaudchan[packet_type - PESTYPE_AUD0] = true; if (audio_current == packet_type && !aud_seeking) - sent = audiostream.put(packet.getData(), packet.getSize(), MPTYPE_MPEG_AUDIO); + sent = audiostream.put(&packetdata[0], packet.getSize(), MPTYPE_MPEG_AUDIO); else sent = packet.getSize(); } @@ -292,7 +293,7 @@ bool Demuxer::submitPacket(PESPacket& packet) avail_ac3audchan[packet.getSubstream() - PESTYPE_SUBSTREAM_AC30] = true; if (packet.getSubstream() == audio_current) { - sent = audiostream.put(packet.getData(), packet.getSize(), (ispre_1_3_19)? MPTYPE_AC3_PRE13 : MPTYPE_AC3); + sent = audiostream.put(&packetdata[0], packet.getSize(), (ispre_1_3_19)? MPTYPE_AC3_PRE13 : MPTYPE_AC3); } else { diff --git a/demuxer.h b/demuxer.h index cda9853..7994b96 100644 --- a/demuxer.h +++ b/demuxer.h @@ -1,5 +1,5 @@ /* - Copyright 2005-2007 Mark Calderbank + Copyright 2005-2008 Mark Calderbank Copyright 2007 Marten Richter (AC3 support) This file is part of VOMP. @@ -15,8 +15,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* @@ -30,6 +30,7 @@ however, no code was copied verbatim. #ifndef DEMUXER_H #define DEMUXER_H +#include #include "stream.h" #include "defines.h" @@ -42,29 +43,30 @@ class PESPacket PESPacket(); void init(UCHAR type, UCHAR sub=0); void truncate(); - int write(UCHAR* buf, int len); + int write(const UCHAR* buf, int len); - UCHAR operator[] (UINT index); // return data[index] if in bounds, else 0 + UCHAR operator[] (UINT index) const; + // return data[index] if in bounds, else 0 // so no proper error condition but never mind for now - const UCHAR* getData() { return data; } - UINT getLength() { return length; } - UINT getSize() { return size; } - UCHAR getPacketType() { return packetType; } + const std::vector& getData() const { return data; } + UINT getLength() const { return length; } + UINT getSize() const { return size; } + UCHAR getPacketType() const { return packetType; } void setSubstream(UCHAR s) { substream = s; } - UCHAR getSubstream() { return substream; } - ULLONG getPTS(); - bool hasPTS() { return (getPTS() != PTS_INVALID); } + UCHAR getSubstream() const { return substream; } + ULLONG getPTS() const; + bool hasPTS() const { return (getPTS() != PTS_INVALID); } - UINT findPictureHeader(); - UINT findSeqHeader(); - static const ULLONG PTS_INVALID; + UINT findPictureHeader() const; + UINT findSeqHeader() const; + static const ULLONG PTS_INVALID = (1LL << 33); protected: - UCHAR data[0x10000]; + std::vector data; UINT length, size; UCHAR packetType; UCHAR substream; ULLONG pts; - UINT seq_header; // 0 = no, 1 = unknown, else = header offset + UINT mutable seq_header; // 0 = no, 1 = unknown, else = header offset }; class Demuxer -- 2.39.5