📄 mpegparser.h
字号:
//// Copyright (c) 2004 by Istv醤 V醨adi//// This file is part of dxr3Player, a DVD player written specifically // for the DXR3 (aka Hollywood+) decoder card, but now handles other// hardware as well.// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#ifndef DXR3PLAYER_MPEG_MPEGPARSER_H#define DXR3PLAYER_MPEG_MPEGPARSER_H//------------------------------------------------------------------------------#include "SequenceHeader.h"#include "GOPHeader.h"#include "PictureHeader.h"#include "dvd/packet/DataBlockPacket.h"#include "sched/Schedulable.h"#include "util/Reference.h"//------------------------------------------------------------------------------namespace dvd { namespace packet {class PacketQueue;} }//------------------------------------------------------------------------------namespace mpeg {//------------------------------------------------------------------------------class MPEGListener;//------------------------------------------------------------------------------/** * MPEG video parser. It expects dvd::packet::DataBlockPackets on its * input and will call an implementation of the MPEGListener interface * on the output with parsed but not decoded MPEG video data. */class MPEGParser : public sched::Schedulable{private: /** * The size of the slice buffer. */ static const size_t sliceBufferSize = 1024*1024; /** * Start code: picture */ static const unsigned STARTCODE_PICTURE = 0x00; /** * Start code: slice (1st) */ static const unsigned STARTCODE_SLICE_MIN = 0x01; /** * Start code: slice (last) */ static const unsigned STARTCODE_SLICE_MAX = 0xaf; /** * Start code: user data */ static const unsigned STARTCODE_USER_DATA = 0xb2; /** * Start code: sequence header. */ static const unsigned STARTCODE_SEQUENCE_HEADER = 0xb3; /** * Start code: sequence error */ static const unsigned STARTCODE_SEQUENCE_ERROR = 0xb4; /** * Start code: extension. */ static const unsigned STARTCODE_EXTENSION = 0xb5; /** * Start code: sequence end */ static const unsigned STARTCODE_SEQUENCE_END = 0xb7; /** * Start code: group start */ static const unsigned STARTCODE_GROUP_START = 0xb8; /** * Extension code: sequence extension */ static const unsigned EXTENSION_SEQUENCE = 0x01; /** * Extension code: sequence display extension */ static const unsigned EXTENSION_SEQUENCE_DISPLAY = 0x02; /** * Extension code: quant matrix */ static const unsigned EXTENSION_QUANT_MATRIX = 0x03; /** * Extension code: copyright */ static const unsigned EXTENSION_COPYRIGHT = 0x04; /** * Extension code: sequence scalable extension */ static const unsigned EXTENSION_SEQUENCE_SCALABLE = 0x05; /** * Extension code: picture display extension */ static const unsigned EXTENSION_PICTURE_DISPLAY = 0x07; /** * Extension code: picture coding extension */ static const unsigned EXTENSION_PICTURE_CODING = 0x08; /** * Extension code: picture spatial scalable extension */ static const unsigned EXTENSION_PICTURE_SPATIAL_SCALABLE = 0x09; /** * Extension code: picture temporal scalable extension */ static const unsigned EXTENSION_PICTURE_TEMPORAL_SCALABLE = 0x0a; /** * Aspect ratios. */ static const SequenceHeader::aspectRatio_t aspectRatios[16]; /** * Frame rate nominators. */ static const size_t frameRateNs[16]; /** * Frame rate denominators. */ static const size_t frameRateDs[16]; /** * Profiles. */ static const SequenceHeader::profile_t profiles[8]; /** * Levels. */ static const SequenceHeader::level_t levels[16]; /** * Chroma formatsa. */ static const SequenceHeader::chromaFormat_t chromaFormats[4]; /** * Picture coding types */ static const PictureHeader::codingType_t codingTypes[8]; /** * Picture structures. */ static const PictureHeader::pictureStructure_t pictureStructures[4]; /** * LIstener. */ MPEGListener& listener; /** * The current packet. */ Reference<dvd::packet::DataBlockPacket> currentPacket; /** * The data in the current packet. */ const unsigned char* data; /** * The length of the data in bytes. */ size_t dataLength; /** * The current byte. */ size_t currentByte; /** * The number of bits left in the current byte. */ size_t bitsLeft; /** * Current start code. */ unsigned currentStartCode; /** * The current sequence header. */ SequenceHeader sequenceHeader; /** * The current quantization matrix. */ QuantMatrix quantMatrix; /** * The current GOP header. */ GOPHeader gopHeader; /** * The current picture header. */ PictureHeader pictureHeader; /** * Buffer for the slice being parsed. */ unsigned char* sliceBuffer;public: /** * Construct the parser with the given input queue. */ MPEGParser(MPEGListener& listener); /** * Destroy the parser. */ ~MPEGParser(); /** * Do the parsing. */ virtual void run(); /** * Get the next packet. */ virtual Reference<dvd::packet::DataBlockPacket> getNextPacket() = 0; /** * Reset the parser. */ void reset();protected: /** * Parse the stream. */ void parse();private: /** * Read the next packet. */ void nextPacket(); /** * Skip the current byte. */ void skipByte(); /** * Read the given number of bits (at most 32). It automatically * handles the situation when a new block has to be read. If the * schedulable has been interrupted, nothing is read and 0 is * returned. This way one can simply write a series of reads and * check only afterwards. */ unsigned readBits(size_t numBits); /** * Read a single byte on a byte boundary. */ unsigned readByte(); /** * Read the next start code. */ unsigned nextStartCode(); /** * Parse a sequence header. * * @return if the full sequence header could be parsed together * with the extension. */ bool parseSequenceHeader(); /** * Parse extension and user data */ void parseExtensionAndUserData(unsigned i); /** * Parse extension data */ void parseExtensionData(unsigned i); /** * Parse user data */ void parseUserData(); /** * Parse a sequence display extension */ void parseSequenceDisplayExtension(); /** * Parse a sequence scalable extension */ void parseSequenceScalableExtension(); /** * Parse a quant matrix extension */ void parseQuantMatrixExtension(); /** * Parse a copyright extension */ void parseCopyrightExtension(); /** * Parse a picture display extension */ void parsePictureDisplayExtension(); /** * Parse a picture spatial scalable extension */ void parsePictureSpatialScalableExtension(); /** * Parse a picture temporal scalable extension */ void parsePictureTemporalScalableExtension(); /** * Parse a group of pictures header. */ void parseGOPHeader(); /** * Parse a picture header. */ void parsePictureHeader(); /** * Parse the picture data. */ void parsePictureData(); /** * Parse a slice data. */ void parseSlice();};//------------------------------------------------------------------------------} /* namespace mpeg *///------------------------------------------------------------------------------#endif // DXR3PLAYER_MPEG_MPEGPARSER_H// Local variables:// mode: c++// End:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -