Horus Doc || C++ Reference || Class Overview   Pixels   Images   Detector   Geometry   Registry || Doxygen's quick Index  

clayerpa.h

00001 // clayerpa.h : interface of MPEG-2 and MPEG-1 video sequence
00002 //
00003 // This class provides a set of MPEG video (for one layer) sequence 
00004 // operation functions for sequence, GOP, and picture syntax parsing.
00005 //
00006 //*****************************************************************************
00007 // 
00008 //                  MPEG Developing Classes
00009 //
00010 // Copyright (C) 1998, Vision and Neural Networks Laboratory, Computer Science 
00011 // Department, Wayne State University, All Rights Reserved; 
00012 //
00013 //                  Disclaimer of Warranty
00014 //
00015 // MPEG Developing Classes, both binary and source (hereafter, Software)
00016 // is copyrighted by Vision and Neural Networks Laboratory, Computer Science 
00017 // Department, Wayne State University (WSU), and ownership remains with WSU.
00018 //
00019 // Permission is hereby granted, free of charge, to any person obtaining
00020 // a copy of this software and associated documentation files to use, copy,
00021 // and distribute the software, provided that no charge is associated with 
00022 // such copies and that the copyright notice and this statement appears on 
00023 // all copies.
00024 //
00025 // THE SOFTWARE IS AVAILABLE TO THE USER ON AN "AS IS" BASIS, WITHOUT WARRANTY
00026 // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, THE 
00027 // IMPLIED WARRANTIES OR MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00028 // IN NO EVENT SHALL THE COPYRIGHT-HOLDER BE LIABLE FOR ANY CLAIMS, DAMAGES, OR
00029 // OTHER LIABILITIES OF ANY KIND WHATSOEVER ARISING FROM, OUT OF OR IN CONNECTION
00030 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THIS 
00031 // DISCLAIMAER OF WARRANTY EXTENDS TO THE USER OF THIS SOFTWARE. ALSO THE WSU 
00032 // DOES NOT REPRESENT OR WARRANT THAT THE SOFTWARE FURNISHED HEREUNDER ARE FREE OF
00033 // INFRINGMENT OF ANY THIRD-PARTY PATENTS.
00034 //
00035 // Many patents of MPEG-1 and MPEG-2 are general enough such that commercial
00036 // implementations, including shareware, are unavoidable subject to royalty fees to
00037 // patent holders, regardless of implementation design.
00038 //
00039 //
00040 // Vision and Neural Networks Laboratory,
00041 // Computer Science Department,
00042 // Wayne State University,
00043 // Detroit, MI 48202.
00044 // Dongge Li(dil@cs.wayne.edu) and Ishwar K. Sethi(sethi@cs.wayne.edu).
00045 //
00047 
00048 #if !defined CLAYERPARSER_H
00049 #define CLAYERPARSER_H
00050 
00051 #include "datatype.h"
00052 #include "mpegdata.h"
00053 #include "cstrmbuf.h"
00054 #include "mpvdata.h"
00055 
00056 const GOPHEADER DEFAULT_GOP_HEADER={0,0,0,0,0,0,0};
00057 
00058 class CLayerParser
00059 {
00060 // constructor and destructor
00061 public:
00062     CLayerParser();
00063     ~CLayerParser();
00064 
00065 // attributes
00066 protected:
00067     FILE *pfFile;
00068     CStreamBuf StreamBuf;
00069     HEADERDATA HeaderData;
00070     // sequence related variables;
00071     long lMaxFrameNum;
00072     long lMinFrameNum;
00073     long lAvgPictureScale;
00074     long lMinPictureSize;
00075     double dfFrameRate; // variables derived from normative elements;
00076     // flags;
00077     bool bMpeg2;
00078     // status;
00079     VIDEOCHNUM VideoChNum;
00080     PICTUREINFO CurPicInfo;
00081     int iParserStatus;
00082 
00083 // operation
00084 public:
00085     int Initialize(const char *psFileName, VIDEOCHNUM ChannelNum, DWORD dwBufSize=VIDEO_STREAM_BUF_SIZE);
00086     int Initialize(const char *psFileName, bool bIsSystemStream, VIDEOCHNUM ChannelNum, DWORD dwBufSize=VIDEO_STREAM_BUF_SIZE);
00087     void Reset(void);
00088     int PrepareRandomAccess(void);
00089     int GetStatus(void) { return iParserStatus; };
00090     inline void ClearStatus(void);
00091     //sequential access;
00092     int MoveToNextPicture(void);
00093     int MoveToPreviousPicture(void);
00094     int ResetCurPicture(void);
00095     int MoveToNextFrame(void);
00096     int MoveToPreviousFrame(void);
00097     int ResetCurFrame(void);
00098     // random access;
00099     int JumpToHeadingPicture(void);
00100     int JumpToEndingPicture(void);
00101     int JumpToFrame(DWORD dwFrameNum); //use offset from its own layer's lMinFrameNum;
00102     int UpdateGOPInfo(void);
00103     inline int GetCurFrameNum(long *plCurFrameNum); //use offset from lMinFrameNum, different from GetFrameNum();
00104     inline int GetMaxFrameNum(long *plMaxFrameNum); //use offset from lMinFrameNum
00105     // picture record and restore;
00106     inline void RecordCurPicture(PICTURERECORD *pPicRecord);
00107     inline int RestorePicture(const PICTURERECORD *pPicRecord);
00108 
00109     // Get structured data from LayerParser;
00110     CStreamBuf *GetLayerParserBuf(void) { return &StreamBuf; };
00111     const HEADERDATA *GetHeaderData(void) { return &HeaderData; };
00112     const PICTUREINFO *GetCurPicInfo(void) { return &CurPicInfo; };
00113     //Get information of video stream;
00114     bool IsMpeg2(void) { return bMpeg2; };
00115     inline void GetProfileLevel(short *pshProfile, short *pshLevel);
00116     // for advanced user;
00117     inline int SetMinPicSize(long lNewMinPicSize);
00118 
00119 protected:
00120     void NextStartCode(void);
00121     void PreviousStartCode(void);
00122     void SetDefaultStatus(void); // only for constructor and reset
00123     inline void MarkerBit(void);
00124     int TestStream(bool *pbIsSystemStream);
00125     // sequence and GOP header parsers
00126     int ReadSequenceHeader(void);
00127     int ReadGOPHeader(void);
00128     int ReadExtensionAndUserDataV(void);
00129     int ReadSequenceExtension(void);
00130     int ReadSequenceDisplayExtension(void);
00131     int ReadSequenceScalableExtension(void);
00132     // picture header parsers
00133     int ReadPictureHeader(void);
00134     int ReadExtensionAndUserDataP(void);
00135     int ReadQuantMatrixExtension(void);
00136     int ReadPictureExtension(void);
00137     int ReadPictureDisplayExtension(void);
00138     int ReadPictureSpatialScalableExtension(void);
00139     int ReadPictureTemporalScalableExtension(void);
00140     int ReadCopyrightExtension(void);
00141     inline void ReadExtraBitInfo(void);
00142     inline void ReadUserData(void);
00143     // access operations
00144     int GetFrameNum(long *plCurFrameNum);
00145     int RestorePicture(const PACKETPOS &PictureBasePckPos, long lPictureBasePckOffset, char cFieldValue=-1);
00146     int LocateToNextPicture(char cDefaultField, bool bDefaultInvalidGOP, long lDefaultUnwrappedNum);
00147     void LocateToNextPicUpdate(bool bGOPChanged, char cDefaultField,
00148                                 bool bDefaultInvalidGOP, long lDefaultUnwrappedNum);
00149     int LocateCurrentPicture(char cDefaultField, bool bInvalidGOP, long lUnwrappedNum);
00150     void LocateCurrentPicUpdate(bool bGOPChanged, char cDefaultField,
00151                                 bool bInvalidGOP, long lUnwrappedNum);
00152     void MoveToNextPicUpdate(bool bGOPChanged, BYTE nPreviousPicStructure);
00153     void MoveToPreviousPicUpdate(bool bGOPChanged);
00154     int CurFrameGOPUpdate(void);
00155 };
00156 
00158 //inline public functions:
00159 
00160 inline void CLayerParser::ClearStatus(void)
00161 {
00162     if (iParserStatus!=NOT_USED)  // NOT_USED CAN NOT be erased;
00163     {
00164         iParserStatus=MDC_SUCCESS;
00165 //      StreamBuf.ClearStatus();
00166     }
00167 }
00168 
00169 inline void CLayerParser::GetProfileLevel(short *pshProfile, short *pshLevel)
00170 {
00171     // special case for 422 VideoStatus.iProfile & VideoStatus.iLevel must be made;
00172     if((HeaderData.SequenceExtension.nProfileAndLevelIndication>>7) & 1)
00173     { // escape bit of HeaderData.SequenceExtension.nProfileAndLevelIndication set;
00174         // 4:2:2 Profile @ Main Level;
00175         if((HeaderData.SequenceExtension.nProfileAndLevelIndication&15)==5)
00176         {
00177             *pshProfile=PROFILE_422;
00178             *pshLevel=MAIN_LEVEL;  
00179         }
00180         else
00181         {   //undefined;
00182             *pshProfile=0;
00183             *pshLevel=0;
00184         }
00185     }
00186     else //default value of nProfileAndLevelIndication (for MPEG-1) is 0;
00187     {
00188         *pshProfile=HeaderData.SequenceExtension.nProfileAndLevelIndication >> 4;// Profile is upper nibble;
00189         *pshLevel=HeaderData.SequenceExtension.nProfileAndLevelIndication & 0xF;// Level is lower nibble;
00190     }
00191 }
00192 
00193  // use offset from lMinFrameNum, different from GetFrameNum();
00194 inline int CLayerParser::GetCurFrameNum(long *plCurFrameNum)
00195 {
00196     int iStatus;
00197 
00198     StreamBuf.ClearStatus();
00199     iStatus=GetFrameNum(plCurFrameNum);
00200     if (iStatus!=MDC_SUCCESS)
00201     { // UNSUCCESS or ERROR;
00202         return iStatus;
00203     }
00204     *plCurFrameNum-=lMinFrameNum;
00205     if (*plCurFrameNum<0)
00206     {
00207         iParserStatus=STREAM_ERROR;
00208         return UNSUCCESS;
00209     }
00210     return MDC_SUCCESS;
00211 }
00212 
00213 // if random access can not be supported, lMaxFrameNum will be smaller than zero;
00214 inline int CLayerParser::GetMaxFrameNum(long *plMaxFrameNum)
00215 {
00216     int iStatus;
00217 
00218     if (lMaxFrameNum<0)
00219         iStatus=PrepareRandomAccess();
00220     *plMaxFrameNum=lMaxFrameNum-lMinFrameNum; // convert to offset;
00221     return iStatus;
00222 }
00223     
00224 // picture record and restore;
00225 inline void CLayerParser::RecordCurPicture(PICTURERECORD *pPicRecord)
00226 {
00227     pPicRecord->PicInfo=CurPicInfo;
00228     pPicRecord->bGOPValid=HeaderData.bGOPValid;
00229     if (HeaderData.bGOPValid)
00230         pPicRecord->GOPHeader=HeaderData.GOPHeader;
00231 }
00232 
00233 inline int CLayerParser::RestorePicture(const PICTURERECORD *pPicRecord)
00234 {
00235     int iStatus;
00236 
00237     iStatus=RestorePicture(pPicRecord->PicInfo.CurPicturePckPos,pPicRecord->PicInfo.lCurPicturePckOffset,
00238                     pPicRecord->PicInfo.bSecondField);
00239     if (iStatus!=MDC_SUCCESS)
00240         return iStatus;
00241     CurPicInfo.lUnwrappedFrameNum=pPicRecord->PicInfo.lUnwrappedFrameNum;
00242     HeaderData.bGOPValid=pPicRecord->bGOPValid;
00243     if (pPicRecord->bGOPValid)
00244         HeaderData.GOPHeader=pPicRecord->GOPHeader;
00245     return MDC_SUCCESS;
00246 }
00247 
00249 // advanced user facilities; (public functions)
00250 
00251 inline int CLayerParser::SetMinPicSize(long lNewMinPicSize)
00252 {
00253     if (lNewMinPicSize<MIN_GOP_HEADER_SIZE)
00254     { //lMinPictureSize must be not smaller than MIN_GOP_HEADER_SIZE;
00255         iParserStatus=USE_ERROR;
00256         return UNSUCCESS;
00257     }
00258     lMinPictureSize=lNewMinPicSize;
00259     return MDC_SUCCESS;
00260 }
00261 
00263 // inline protected functions:
00264 
00265 inline void CLayerParser::MarkerBit(void)
00266 {
00267 #ifdef ERR_INFO
00268     if (!StreamBuf.GetByteBits(1))  // must be 1;
00269     {
00270         iParserStatus=STREAM_ERROR;
00271     }
00272 #else
00273     StreamBuf.GetByteBits(1); //'1'
00274 #endif
00275 }
00276 
00277 // decode extra bit information, ISO/IEC 13818-2 section 6.2.3.4.
00278 inline void CLayerParser::ReadExtraBitInfo(void)
00279 {
00280     while (StreamBuf.GetByteBits(1))
00281         StreamBuf.GetByteBits(8);
00282 }
00283 
00284 // ISO/IEC 13818-2  sections 6.3.4.1 and 6.2.2.2.2;
00285 inline void CLayerParser::ReadUserData(void)
00286 {
00287     // skip ahead to the next start code;
00288     NextStartCode();
00289 }
00290 
00291 #endif //CLAYERPARSE_H

Generated on Mon Jan 27 15:48:40 2003 for C++Reference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001