00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __MXCPC_FRAMEWISEMXPEGDECODER_H__
00021 #define __MXCPC_FRAMEWISEMXPEGDECODER_H__
00022
00023
00024
00025 #include <mxcpcMxPEGDecoder.h>
00026
00027
00028
00029 class mxcpcFramewiseMxPEGScanDecoder;
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 class mxcpcFramewiseMxPEGDecoder : public mxcpcMxPEGDecoder {
00041
00042 public:
00043 class UndecodedFrameDescriptor {
00044
00045 public:
00046 int Width, Height;
00047 int TileNumX, TileNumY;
00048 unsigned char *ScanBytes;
00049 int ScanLength;
00050 unsigned char *TileBits;
00051
00052 public:
00053
00054 UndecodedFrameDescriptor() { reset(640, 480); }
00055
00056 void setResolution(int width, int height) {
00057
00058 if(width < 1) width = 640;
00059 if(height < 1) height = 480;
00060
00061 Width = width;
00062 Height = height;
00063
00064 TileNumX = width/16;
00065 if(width % 16) TileNumX++;
00066 TileNumY = height/16;
00067 if(height % 16) TileNumY++;
00068 }
00069
00070 void reset(int width, int height) {
00071
00072 setResolution(width, height);
00073
00074 ScanBytes = 0;
00075 ScanLength = 0;
00076
00077 TileBits = 0;
00078 }
00079 };
00080
00081 private:
00082 enum DecoderState { AwaitSOI,
00083 AwaitAPP0,
00084 APP0,
00085 Determine_FingerPrint_Or_FrameHeader,
00086 Determine_FingerPrint_Or_FrameHeader2,
00087 FingerPrint,
00088 AwaitFrameHeader,
00089 AwaitFrameHeader2,
00090 FrameHeader,
00091 BitMask_Or_Tables,
00092 QuantizationTable1,
00093 AwaitQuantizationTable2,
00094 QuantizationTable2,
00095 Huffman_Or_SOF,
00096 SOF,
00097 HuffmanTable,
00098 Huffman_Or_Scan,
00099 Scan,
00100 Scan2,
00101 BitMask,
00102 Tables_Or_Scan,
00103 Audio_Or_SOI,
00104 Audio,
00105 No_Good_State
00106 };
00107
00108 private:
00109
00110
00111 DecoderState State;
00112 unsigned char *CurrentBytePtr;
00113 int BytesLeft;
00114 int AwaitMarkerStage;
00115 int ReadMarkerStage;
00116 unsigned char ReadMarkerFirstLenByte;
00117 int MarkerBytesNeeded;
00118 int ScanStage;
00119 unsigned char *MarkerPayload;
00120
00121 UndecodedFrameDescriptor FrameDescriptor;
00122 int Width, Height;
00123 mxcpcFramewiseMxPEGScanDecoder *ScanDecoder;
00124
00125 unsigned char *PrefetchBuffer;
00126 int PrefetchBuffSize;
00127 int PrefetchedBytes;
00128
00129 public:
00130
00131 mxcpcFramewiseMxPEGDecoder(mxcpcStreamSource *source,
00132 mxcpcMxPEGDecoderBackEnd *backend,
00133 mxcpcFramewiseMxPEGScanDecoder *scan_decoder);
00134 ~mxcpcFramewiseMxPEGDecoder();
00135
00136 public:
00137
00138 int decode(int num);
00139
00140 private:
00141
00142
00143 void feedBytes(unsigned char *buffer, int num);
00144
00145 bool awaitMarker(unsigned char *marker_type);
00146
00147 bool readMarkerPayload(void);
00148
00149 bool doScan(void);
00150 };
00151
00152
00153
00154 #endif // __MXCPC_FRAMEWISEMXPEGDECODER_H__
00155