00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00048
00049
00050
00051
00052
00053
00054
00055
00057
00058
00059
00060 #ifndef __MX_MXPEGPARSER_H__
00061 #define __MX_MXPEGPARSER_H__
00062
00063
00064
00065 #define MX_MXPEGPARSER_ID "MxPEGParser"
00066
00067
00068
00069 #include <interfaces/IComponent.h>
00070 #include <interfaces/IComponentInvoker.h>
00071 #include <interfaces/IMxPEGParser.h>
00072 #include <interfaces/IErrorState.h>
00073
00074 #include <Framework/Framework.h>
00075
00076 #include <mxm/core/mxmUndecodedMxPEGFrameDescriptor.h>
00077 #include <mxm/core/mxmLocalEndian.h>
00078 #include <mxm/core/mxmObject.h>
00079 #include <mxm/core/mxmString.h>
00080 #include <mxm/core/mxmStringList.h>
00081
00082
00083
00084 namespace mx {
00085
00087
00094 class MxPEGParser : public mxmObject,
00095 public virtual IComponent,
00096 public virtual IMxPEGParser {
00097
00101 private:
00102 static mxm::smart<mxmStringList> _enumerateInterfaces() {
00103 return(new mxmStringList((mxmString(MX_MXPEGPARSER_ID),
00104 MX_ICOMPONENT_ID,
00105 MX_IMXPEGPARSER_ID,
00106 MX_IPROCESSESSTREAM_ID,
00107 MX_ISENDSUNDECODEDMXPEGFRAMES_ID,
00108 MX_IERRORSTATE_ID)));
00109 }
00110 static mxm::smart<mxmStringList> _enumerateCapabilities(
00111 const mxmString &interface) {
00112 if(interface == mx::Framework::IdHintKey)
00113 return(new mxmStringList(MX_MXPEGPARSER_ID));
00114 else
00115 return(new mxmStringList());
00116 }
00117 private:
00118 class Invoker : public mxmObject, public virtual IComponentInvoker {
00119 public:
00120 mxm::smart<mxmStringList> enumerateInterfaces() {
00121 return(_enumerateInterfaces());
00122 }
00123 mxm::smart<mxmStringList> enumerateCapabilities(
00124 const mxmString &interface) {
00125 return(_enumerateCapabilities(interface));
00126 }
00127 IComponent *newComponent() {
00128 return(new MxPEGParser());
00129 }
00130 };
00131 public:
00133 static IComponentInvoker *newInvoker() {
00134 return(new Invoker());
00135 }
00136
00137 public:
00138 enum DecoderState { AwaitMarker,
00139 StartOfImage,
00140 RecordStartOfImage,
00141 APP0,
00142 Comment,
00143 M1IMG,
00144 MxF,
00145 QuantizationTable,
00146 HuffmanTable,
00147 DefineRestartInterval,
00148 BitMap,
00149 StartOfFrame,
00150 StartOfScan,
00151 Scan,
00152 Audio,
00153 ReadPayloadAndReturn,
00154 NoGoodState
00155 };
00156
00157 private:
00158 IStreamSource *Source;
00159 IUndecodedMxPEGFrameReceiver *FrameReceiver;
00160 bool Active;
00161
00162
00163 DecoderState State;
00164 unsigned char *CurrentBytePtr;
00165 int BytesLeft;
00166 int AwaitMarkerStage;
00167 int ReadMarkerStage;
00168 unsigned char ReadMarkerFirstLenByte;
00169 int MarkerPayloadSize,
00170 MarkerBytesNeeded;
00171 int ScanStage;
00172 unsigned char *MarkerPayload;
00173
00174 mxmUndecodedMxPEGFrameDescriptor FrameDescriptor;
00175 int Width, Height;
00176
00177 unsigned char *PrefetchBuffer;
00178 int PrefetchBuffSize;
00179 int PrefetchedBytes;
00180
00181 bool Fresh;
00182 mxmLocalEndian LocalEndian;
00183
00184 bool ErrorEncountered;
00185
00186 public:
00187 MxPEGParser();
00188 ~MxPEGParser();
00189
00190 public:
00192 mxm::smart<mxmStringList> enumerateInterfaces();
00194 mxm::smart<mxmStringList> enumerateCapabilities(
00195 const mxmString &interface);
00196
00198 void setStreamSource(IStreamSource *stream_source);
00200 void setUndecodedMxPEGFrameReceiver(IUndecodedMxPEGFrameReceiver
00201 *frame_receiver);
00203 int processStreamBytes(int num);
00205 bool sourceStillUp();
00206
00208 bool errorState();
00210 void setErrorState();
00211
00212 private:
00215 void feedBytes(unsigned char *buffer, int num);
00217 bool awaitMarker(unsigned char *marker_type);
00219 bool readMarkerPayload(void);
00221 bool doScan(void);
00223 void activate();
00224 };
00225 };
00226
00227 #endif // __MX_MXPEGPARSER_H__