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

cmpvdeco.h

00001 // cmpvdeco.h : interface of MPEG-2 and MPEG-1 video sequence
00002 //
00003 // CMpvDecoder provides a set of MPEG video operation functions to 
00004 // access, parse, and decode MPEG video sequence. Becuase CMpvDecoder 
00005 // can automatically choose to work on system layer or sequence layer,
00006 // most users will only need CMpvDecoder for MPEG video operations.
00007 //
00008 //*****************************************************************************
00009 // 
00010 //                  MPEG Developing Classes
00011 //
00012 // Copyright (C) 1998, Vision and Neural Networks Laboratory, Computer Science 
00013 // Department, Wayne State University, All Rights Reserved; 
00014 //
00015 //                  Disclaimer of Warranty
00016 //
00017 // MPEG Developing Classes, both binary and source (hereafter, Software)
00018 // is copyrighted by Vision and Neural Networks Laboratory, Computer Science 
00019 // Department, Wayne State University (WSU), and ownership remains with WSU.
00020 //
00021 // Permission is hereby granted, free of charge, to any person obtaining
00022 // a copy of this software and associated documentation files to use, copy,
00023 // and distribute the software, provided that no charge is associated with 
00024 // such copies and that the copyright notice and this statement appears on 
00025 // all copies.
00026 //
00027 // THE SOFTWARE IS AVAILABLE TO THE USER ON AN "AS IS" BASIS, WITHOUT WARRANTY
00028 // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, THE 
00029 // IMPLIED WARRANTIES OR MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00030 // IN NO EVENT SHALL THE COPYRIGHT-HOLDER BE LIABLE FOR ANY CLAIMS, DAMAGES, OR
00031 // OTHER LIABILITIES OF ANY KIND WHATSOEVER ARISING FROM, OUT OF OR IN CONNECTION
00032 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THIS 
00033 // DISCLAIMAER OF WARRANTY EXTENDS TO THE USER OF THIS SOFTWARE. ALSO THE WSU 
00034 // DOES NOT REPRESENT OR WARRANT THAT THE SOFTWARE FURNISHED HEREUNDER ARE FREE OF
00035 // INFRINGMENT OF ANY THIRD-PARTY PATENTS.
00036 //
00037 // Many patents of MPEG-1 and MPEG-2 are general enough such that commercial
00038 // implementations, including shareware, are unavoidable subject to royalty fees to
00039 // patent holders, regardless of implementation design.
00040 //
00041 //
00042 // Vision and Neural Networks Laboratory,
00043 // Computer Science Department,
00044 // Wayne State University,
00045 // Detroit, MI 48202.
00046 // Dongge Li(dil@cs.wayne.edu) and Ishwar K. Sethi(sethi@cs.wayne.edu).
00047 //
00049 
00050 #if !defined CMPVDECODER_H
00051 #define CMPVDECODER_H
00052 
00053 #include "clayerpa.h"
00054 #include "cpicdeco.h"
00055 #include "datatype.h"
00056 #include "mpegdata.h"
00057 #include "cstrmbuf.h"
00058 #include "mpvdata.h"
00059 #include "CMpvDisplayFrameBuffer.h"
00060 
00061 class CMpvDecoder
00062 {
00063 // constructor and destructor
00064 public:
00065     CMpvDecoder();
00066     ~CMpvDecoder();
00067 
00068 // attributes
00069 protected:
00070     CLayerParser *pLayerParser[MAX_LAYER_NUM];
00071     CPicDecoder PicDecoder; // for base layer and SNR, data partitioning scalability;
00072     // compressed picture output buffer pointer;
00073     COMPRESSEDPIC *pCompressedPic;
00074     // status data
00075     DECODERINFO DecoderInfo;
00076 
00077     GENFRAMEBUF GenFrameBuf;
00078 
00079 private: // just for speedup;
00080     const HEADERDATA *pHeaderData[MAX_LAYER_NUM];
00081     const PICTUREINFO *pCurPicInfo[MAX_LAYER_NUM];
00082 
00083 // operation
00084 public:
00085     int Initialize(const char *psBaseFileName, const char *psEnhanFileName=NULL,
00086                             VIDEOCHNUM BaseChannelNum=VIDEOCH0, VIDEOCHNUM EnhanChannelNum=VIDEOCH0,
00087                             DWORD dwBaseBufSize=VIDEO_STREAM_BUF_SIZE, DWORD dwEnhanBufSize=VIDEO_STREAM_BUF_SIZE);
00088     int Initialize(const char *psBaseFileName, const char *psEnhanFileName, bool bIsBaseSystemStream, bool bIsEnhanSystemStream,
00089                     VIDEOCHNUM BaseChannelNum, VIDEOCHNUM EnhanChannelNum,
00090                     DWORD dwBaseBufSizee=VIDEO_STREAM_BUF_SIZE, DWORD dwEnhanBufSizee=VIDEO_STREAM_BUF_SIZE);
00091     void Reset(void);
00092     inline DECODERSTATUS GetStatus(void);
00093     inline void ClearStatus(void);
00094     inline void SetSpeed(bool bIsHighSpeed);
00095     //sequential access;
00096     int MoveToNextPicture(void);
00097     int MoveToPreviousPicture(void);
00098     int ResetCurPicture(void);
00099     int MoveToNextFrame(void);
00100     int MoveToPreviousFrame(void);
00101     int ResetCurFrame(void);
00102     // random access;
00103     int PrepareRandomAccess(void);
00104     int JumpToHeadingPicture(void);
00105     int JumpToEndingPicture(void);
00106     int JumpToFrame(DWORD dwFrameNum);
00107     inline int GetCurFrameNum(long *plCurFrameNum, LAYERTYPE LayerType=BASELAYER); //use offset from lMinFrameNum;
00108     inline int GetMaxFrameNum(long *plMaxFrameNum, LAYERTYPE LayerType=BASELAYER); //use offset from lMinFrameNum;
00109     inline int UpdataGOPInfo(LAYERTYPE LayerType=BASELAYER);
00110 
00111     long InitializeGenDisplayBuffer(void);
00112     long DeleteGenDisplayBuffer(void);
00113     long ResetGenDisplayBuffer(BYTE outType);
00114     long GetBufferedFrame(BYTE *pnOutData,
00115                   WORD *pwOutPicWidth,
00116                   WORD *pwOutPicHeight,
00117                   BYTE nOutputType, 
00118                   DWORD dwFrameNum);
00119     WORD FrameWidth(void);
00120     WORD FrameHeight(void);
00121 
00122     // get deoded data;
00123     inline int DecodePicture(void);
00124     inline int DecodeSpatPic(BYTE *pnLowLayerFrameData[3], WORD wYRowIncr, WORD wChromaRowIncr);
00125 
00126     // Decoded Information Output Functions:
00127     inline long GetCurFrame(BYTE *pnOutData,WORD *pwOutPicWidth,WORD *pwOutPicHeight,BYTE nOutputType);
00128     inline long GetCurPic(BYTE *pnOutData,WORD *pwOutPicWidth,WORD *pwOutPicHeight,BYTE nOutputType);
00129     inline int StoreCurPic(const char *psOutFileName, BYTE nOutputType);
00130     inline int StoreCurFrame(const char *psOutFileName, BYTE nOutputType);
00131     inline int GetCurYUV(BYTE *pnOutData[3],WORD pwOutPicWidth[3],WORD pwOutPicHeight[3], bool bFrameOnly=false);
00132     inline int GetCurRGB(BYTE *pnOutData[3],WORD *pwOutPicWidth,WORD *pwOutPicHeight, bool bFrameOnly=false);
00133 
00134     //Get information of video stream;
00135     const HEADERDATA *GetMpvHeaders(LAYERTYPE LayerType=BASELAYER) { return pHeaderData[LayerType]; };
00136     inline void GetProfileLevel(short *pshProfile, short *pshLevel, LAYERTYPE LayerType=BASELAYER);
00137     void GetCodingPicPara(CODINGPICPARA *pCodingPicPara) { PicDecoder.GetCodingPicPara(pCodingPicPara); };
00138     inline bool IsMpeg2(LAYERTYPE LayerType=BASELAYER);
00139 
00140     //get compressed picture
00141     inline int GetMBBlockPic(MBBLOCK *pOutMBBlockPic,WORD *pwOutWidth,WORD *pwOutHeight);
00142     COMPRESSEDPIC *PrepareCompressedPic(void);
00143     void FreeCompressedPic(void); //reset and destructor will call it automatically;
00144     inline int GetCompressedPic(void);
00145 
00147     //for advance users;
00148     int SetMinPicSize(long lNewMinPicSize, LAYERTYPE LayerType=BASELAYER);
00149     BYTE *GetBackRefFrameBuf(BYTE nComponent) { return PicDecoder.GetBackRefFrameBuf(nComponent); };
00150     BYTE *GetFwdRefFrameBuf(BYTE nComponent) { return PicDecoder.GetFwdRefFrameBuf(nComponent); };
00151     BYTE *GetCurFrameBuf(BYTE nComponent) { return PicDecoder.GetCurFrameBuf(nComponent); };
00152     //sequential access for each layer;
00153     int MoveToNextPicture(LAYERTYPE LayerType);
00154     int MoveToPreviousPicture(LAYERTYPE LayerType);
00155     int ResetCurPicture(LAYERTYPE LayerType);
00156     int MoveToNextFrame(LAYERTYPE LayerType);
00157     int MoveToPreviousFrame(LAYERTYPE LayerType);
00158     int ResetCurFrame(LAYERTYPE LayerType);
00159     // random access for each layer;
00160     int JumpToHeadingPicture(LAYERTYPE LayerType);
00161     int JumpToEndingPicture(LAYERTYPE LayerType);
00162     int JumpToFrame(DWORD dwFrameNum, LAYERTYPE LayerType);
00163     // record and restore picture for each layer;
00164     void RecordCurPicture(PICTURERECORD *pCurPicRecord, LAYERTYPE LayerType);
00165     int RestorePicture(const PICTURERECORD *pPicRecord, LAYERTYPE LayerType);
00166 
00167 protected:
00168     int CompareTwoStreamInfo(void);
00169 };
00170 
00172 //inline public functions:
00173 
00174 inline DECODERSTATUS CMpvDecoder::GetStatus(void)
00175 {
00176     DECODERSTATUS DecoderStatus;
00177 
00178     DecoderStatus.iMpvDecoderStatus=DecoderInfo.iStatus;
00179     DecoderStatus.iBaseParserStatus=pLayerParser[BASELAYER]->GetStatus();
00180     if (DecoderInfo.bTwoStream)
00181         DecoderStatus.iEnhanParserStatus=pLayerParser[ENHANLAYER]->GetStatus();
00182     else
00183         DecoderStatus.iEnhanParserStatus=MDC_SUCCESS;
00184     DecoderStatus.iPicDecoderStatus=PicDecoder.GetStatus();
00185     return DecoderStatus;
00186 }
00187 
00188 inline void CMpvDecoder::ClearStatus(void)
00189 {
00190     if (DecoderInfo.iStatus!=NOT_USED)  // NOT_USED CAN NOT be erased;
00191     {
00192         DecoderInfo.iStatus=MDC_SUCCESS;
00193         pLayerParser[BASELAYER]->ClearStatus();
00194         if (DecoderInfo.bTwoStream)
00195             pLayerParser[ENHANLAYER]->ClearStatus();
00196         PicDecoder.ClearStatus();
00197     }
00198 }
00199 
00200 inline void CMpvDecoder::SetSpeed(bool bIsHighSpeed)
00201 {
00202     DecoderInfo.bSpeedFlag=bIsHighSpeed;
00203     PicDecoder.SetSpeed(bIsHighSpeed);
00204 }
00205 
00206 // get picture information in random access;
00207 inline int CMpvDecoder::GetCurFrameNum(long *plCurFrameNum, LAYERTYPE LayerType) //use offset from lMinFrameNum;
00208 {
00209 #ifdef DEBUG
00210     if (pLayerParser[LayerType]==NULL)
00211     {
00212         DecoderInfo.iStatus=USE_ERROR;
00213         return UNSUCCESS;
00214     }
00215 #endif      
00216     return pLayerParser[LayerType]->GetCurFrameNum(plCurFrameNum);
00217 }
00218 
00219 inline int CMpvDecoder::GetMaxFrameNum(long *plMaxFrameNum, LAYERTYPE LayerType) //use offset from lMinFrameNum;
00220 {
00221 #ifdef DEBUG
00222     if (pLayerParser[LayerType]==NULL)
00223     {
00224         DecoderInfo.iStatus=USE_ERROR;
00225         return UNSUCCESS;
00226     }
00227 #endif      
00228     return pLayerParser[LayerType]->GetMaxFrameNum(plMaxFrameNum);
00229 }
00230 
00231 inline int CMpvDecoder::UpdataGOPInfo(LAYERTYPE LayerType)
00232 {
00233 #ifdef DEBUG
00234     if (pLayerParser[LayerType]==NULL)
00235     {
00236         DecoderInfo.iStatus=USE_ERROR;
00237         return UNSUCCESS;
00238     }
00239 #endif      
00240     if (pHeaderData[LayerType]->bGOPValid)
00241         return MDC_SUCCESS; //already up-to-date;
00242     else
00243         return pLayerParser[LayerType]->UpdateGOPInfo();
00244 }
00245 
00246 
00247 // decode picture data;
00248 // even return value is MDC_SUCCESS, not fatal errors may still exist 
00249 // and can be reported by DecoderInfo.iStatus; 
00250 inline int CMpvDecoder::DecodePicture(void)
00251 {
00252     // decode picture;
00253     return PicDecoder.DecodePicture();
00254 }
00255 
00256 // decode picture data;
00257 // even return value is MDC_SUCCESS, not fatal errors may still exist 
00258 // and can be reported by DecoderInfo.iStatus; 
00259 inline int CMpvDecoder::DecodeSpatPic(BYTE *pnLowLayerFrameData[3], WORD wYRowIncr, WORD wChromaRowIncr)
00260 {
00261 #ifdef DEBUG
00262     if ( (wYRowIncr<pHeaderData[BASELAYER]->SequenceScalableExt.wLowerLayerPredHSize)
00263                 ||(wChromaRowIncr<(pHeaderData[BASELAYER]->SequenceScalableExt.wLowerLayerPredHSize>>1)) )
00264     { //spatial scalable layer is always the base layer;
00265         DecoderInfo.iStatus=USE_ERROR;
00266         return UNSUCCESS;
00267     }
00268 #endif
00269     // decode picture;
00270     return PicDecoder.DecodePicture(pnLowLayerFrameData,wYRowIncr,wChromaRowIncr);
00271 }
00272 
00273 inline long CMpvDecoder::GetCurFrame(BYTE *pnOutData,WORD *pwOutPicWidth,WORD *pwOutPicHeight,BYTE nOutputType)
00274 {
00275     return PicDecoder.GetCurFrame(pnOutData,pwOutPicWidth,pwOutPicHeight,nOutputType);
00276 }
00277 
00278 inline long CMpvDecoder::GetCurPic(BYTE *pnOutData,WORD *pwOutPicWidth,WORD *pwOutPicHeight,BYTE nOutputType)
00279 {
00280     return PicDecoder.GetCurPic(pnOutData,pwOutPicWidth,pwOutPicHeight,nOutputType);
00281 }
00282 
00283 inline int CMpvDecoder::StoreCurPic(const char *psOutFileName, BYTE nOutputType)
00284 {
00285     return PicDecoder.StoreCurPic(psOutFileName,nOutputType);
00286 }
00287 
00288 inline int CMpvDecoder::StoreCurFrame(const char *psOutFileName, BYTE nOutputType)
00289 {
00290     return PicDecoder.StoreCurFrame(psOutFileName,nOutputType);
00291 }
00292 
00293 inline int CMpvDecoder::GetCurYUV(BYTE *pnOutData[3],WORD pwOutPicWidth[3],WORD pwOutPicHeight[3], bool bFrameOnly)
00294 {
00295     return PicDecoder.GetCurYUV(pnOutData, pwOutPicWidth, pwOutPicHeight, bFrameOnly);
00296 }
00297 
00298 inline int CMpvDecoder::GetCurRGB(BYTE *pnOutData[3],WORD *pwOutPicWidth,WORD *pwOutPicHeight, bool bFrameOnly)
00299 {
00300     return PicDecoder.GetCurRGB(pnOutData, pwOutPicWidth, pwOutPicHeight, bFrameOnly);
00301 }
00302 
00303 inline void CMpvDecoder::GetProfileLevel(short *pshProfile, short *pshLevel, LAYERTYPE LayerType)
00304 {
00305 #ifdef DEBUG
00306     if (pLayerParser[LayerType]==NULL)
00307     {
00308         DecoderInfo.iStatus=USE_ERROR;
00309         *pshProfile=-1;
00310         *pshLevel=-1;
00311         return;
00312     }
00313 #endif      
00314     pLayerParser[LayerType]->GetProfileLevel(pshProfile, pshLevel);
00315 }
00316 
00317 inline bool CMpvDecoder::IsMpeg2(LAYERTYPE LayerType)
00318 {
00319 #ifdef DEBUG
00320     if (pLayerParser[LayerType]==NULL)
00321     {
00322         DecoderInfo.iStatus=USE_ERROR;
00323         return false;
00324     }
00325 #endif      
00326     return pLayerParser[LayerType]->IsMpeg2();
00327 }
00328 
00329 // get compressed picture;
00330 // even return value is MDC_SUCCESS, not fatal errors may still exist 
00331 // and can be reported by DecoderInfo.iStatus; 
00332 inline int CMpvDecoder::GetMBBlockPic(MBBLOCK *pOutMBBlockPic,WORD *pwOutWidth,WORD *pwOutHeight)
00333 {
00334     // parse picture;
00335     return PicDecoder.GetMBBlockPic(pOutMBBlockPic,pwOutWidth,pwOutHeight);
00336 }
00337 
00338 // get compressed picture;
00339 // even return value is MDC_SUCCESS, not fatal errors may still exist 
00340 // and can be reported by DecoderInfo.iStatus; 
00341 inline int CMpvDecoder::GetCompressedPic(void)
00342 {
00343     // parse picture;
00344     return PicDecoder.GetCompressedPic(pCompressedPic);
00345 }
00346 
00348 // advanced user facilities; (public functions)
00349 
00350 inline int CMpvDecoder::SetMinPicSize(long lNewMinPicSize, LAYERTYPE LayerType)
00351 {
00352     if (pLayerParser[LayerType]==NULL)
00353     {
00354         DecoderInfo.iStatus=USE_ERROR;
00355         return UNSUCCESS;
00356     }
00357     return pLayerParser[LayerType]->SetMinPicSize(lNewMinPicSize);
00358 }
00359 
00360 #endif  //CMPVDECODER_H

Generated on Tue Feb 3 14:18:31 2004 for C++Reference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001