00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
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
00064 public:
00065 CMpvDecoder();
00066 ~CMpvDecoder();
00067
00068
00069 protected:
00070 CLayerParser *pLayerParser[MAX_LAYER_NUM];
00071 CPicDecoder PicDecoder;
00072
00073 COMPRESSEDPIC *pCompressedPic;
00074
00075 DECODERINFO DecoderInfo;
00076
00077 GENFRAMEBUF GenFrameBuf;
00078
00079 private:
00080 const HEADERDATA *pHeaderData[MAX_LAYER_NUM];
00081 const PICTUREINFO *pCurPicInfo[MAX_LAYER_NUM];
00082
00083
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
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
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);
00108 inline int GetMaxFrameNum(long *plMaxFrameNum, LAYERTYPE LayerType=BASELAYER);
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
00123 inline int DecodePicture(void);
00124 inline int DecodeSpatPic(BYTE *pnLowLayerFrameData[3], WORD wYRowIncr, WORD wChromaRowIncr);
00125
00126
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
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
00141 inline int GetMBBlockPic(MBBLOCK *pOutMBBlockPic,WORD *pwOutWidth,WORD *pwOutHeight);
00142 COMPRESSEDPIC *PrepareCompressedPic(void);
00143 void FreeCompressedPic(void);
00144 inline int GetCompressedPic(void);
00145
00147
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
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
00160 int JumpToHeadingPicture(LAYERTYPE LayerType);
00161 int JumpToEndingPicture(LAYERTYPE LayerType);
00162 int JumpToFrame(DWORD dwFrameNum, LAYERTYPE LayerType);
00163
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
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)
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
00207 inline int CMpvDecoder::GetCurFrameNum(long *plCurFrameNum, LAYERTYPE LayerType)
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)
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;
00242 else
00243 return pLayerParser[LayerType]->UpdateGOPInfo();
00244 }
00245
00246
00247
00248
00249
00250 inline int CMpvDecoder::DecodePicture(void)
00251 {
00252
00253 return PicDecoder.DecodePicture();
00254 }
00255
00256
00257
00258
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 {
00265 DecoderInfo.iStatus=USE_ERROR;
00266 return UNSUCCESS;
00267 }
00268 #endif
00269
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
00330
00331
00332 inline int CMpvDecoder::GetMBBlockPic(MBBLOCK *pOutMBBlockPic,WORD *pwOutWidth,WORD *pwOutHeight)
00333 {
00334
00335 return PicDecoder.GetMBBlockPic(pOutMBBlockPic,pwOutWidth,pwOutHeight);
00336 }
00337
00338
00339
00340
00341 inline int CMpvDecoder::GetCompressedPic(void)
00342 {
00343
00344 return PicDecoder.GetCompressedPic(pCompressedPic);
00345 }
00346
00348
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